#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define FOR(i,a,b) for(i=a;i<=b; i++)
#define FOR2(i,n) FOR(i,0,n-1)
#define COMB(x) ( ( (x) * (x-1) ) / 2 )
#define f first
#define s second
#define BASE 1009ll
#define MAXN 100005
#define all(x) x.begin(),x.end()
using namespace std;
typedef pair < long long , int > pli;
class trial
{
	public:
		int f,s,x;
		trial() { f = s = x = 0; }
}P[MAXN];
inline trial make_trial(int a,int b,int c) { trial k; k.f = a; k.s = b; k.x = c; return k; }
pli ST[4*MAXN];
long long H[MAXN] , pow[MAXN];
int N,T;
int B[MAXN] , C[MAXN] , K[MAXN];
char A[MAXN];
inline bool cmp( const trial &a , const trial &b )
{
	if(a.f < b.f) return true;
	if(a.f > b.f) return false;
	return a.s < b.s;
}
bool numaralandir()
{
	int i,j,s(0);
	sort(P+1,P+N+1,cmp);
	FOR(i,1,N)
	{
		s++;
		j = i;
		while(i <= N && P[i].f == P[j].f && P[i].s == P[j].s) B[ P[i++].x ] = s;
		i--;
	}
	return s == N;
}
void suffix_array()
{
	int cnt(1),i;
	FOR(i,1,N) P[i] = make_trial( A[i] , A[i] , i );

	while(1)
	{
		if(numaralandir()) return;

		FOR(i,1,N)
			P[i] = make_trial( B[i] , ( (i+cnt <= N) ? B[i+cnt] : 0 ) , i );

		cnt <<= 1;
	}
}
long long get(int a,int b)
{
	return H[b] - H[a-1] * pow[b-a+1];
}
int getlcp(int a,int b)
{
	int i,res(0);
	for(i = T; i >= 0; i--)
	{
		if(a + (1<<i) - 1 > N) continue;
		if(b + (1<<i) - 1 > N) continue;
		if( get(a , a + (1<<i) - 1) == get(b , b + (1<<i) - 1) )
		{
			a += (1<<i);
			b += (1<<i);
			res += (1<<i);
		}
	}
	return res;
}
void LCP()
{
	int i;
	pow[0] = 1;
	FOR(i,1,N)
	{
		H[i] = H[i-1] * BASE + A[i];
		pow[i] = pow[i-1] * BASE;
	}

	FOR(i,1,N-1)
		C[i] = getlcp(K[i],K[i+1]) + 1;
	C[N] = 1;
}
pli init(int pos,int s,int e)
{
	if(s == e) return ST[pos] = make_pair( C[s] , s );
	int m = ( s + e ) >> 1;
	int sol = pos << 1;
	int sag = sol | 1;
	pli p1 = init(sol,s,m);
	pli p2 = init(sag,m+1,e);
	return ST[pos] = (p1.f < p2.f) ? p1 : p2;
}
pli find(int pos,int s,int e,int a,int b)
{
	if(a > e || b < s) return make_pair( 1000000000000ll , 0 );
	if(a <= s && e <= b) return ST[pos];
	int m = ( s + e ) >> 1;
	int sol = pos << 1;
	int sag = sol | 1;
	pli p1 = find(sol,s,m,a,b);
	pli p2 = find(sag,m+1,e,a,b);
	return (p1.f < p2.f) ? p1 : p2;
}
long long dq(int a,int b,int k)
{
	if(a > b) return 0;
	pli p = find(1,1,N,a,b);

	long long s = COMB(b-a+2) * (p.f - k);
	return s + dq(a , p.s-1 , p.f ) + dq(p.s+1 , b , p.f);

}
void solve()
{
	int i;
	scanf("%s",A+1);
	N = strlen(A+1);
	while( (1 << T) < N ) T++;
	T--;

	suffix_array();

	FOR(i,1,N) K[ B[i] ] = i;

	LCP();

	init(1,1,N);

	printf("%lld\n" , dq(1,N,0) ) ;

}
int main()
{
//	freopen(".gir","r",stdin);
//	freopen(".cik","w",stdout);
	solve();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define N (int)(1e5+10)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define inf mod
#define endl '\n'
#define sag (sol|1)
#define sol (root<<1)
#define ort ((bas+son)>>1)
#define bit(x,y) ((x>>y)&1)
#define K 17

#define int ll

ll St[4*N],L2[4*N],L[4*N];

int i,j,k,n,m,x,y,z,S[N][K+1];
int ans,wh[N];
pair< pii , int > v[N];
string str;

void push(int root,int bas,int son){
	if(bas==son)
		return;
	if(L[root]!=-1){
		L[sol]=L[sag]=L[root];
		L2[sol]=L2[sag]=0;
		St[sol]=(ort-bas+1)*L[root];
		St[sag]=(son-bas)*L[root];
		L[root]=-1;
	}
	if(L2[root]){
		L2[sol]+=L2[root];
		L2[sag]+=L2[root];
		St[sol]+=(ort-bas+1)*L2[root];
		St[sag]+=(son-bas)*L2[root];
		L2[root]=0;
	}
}

int que(int root,int bas,int son,int x,int y){
	if(bas > y or son < x)
		return 0;

	if(x <= bas and son <= y)
		return St[root];

	push(root,bas,son);

	return que(sol,bas,ort,x,y) + que(sag,ort+1,son,x,y);
}

int upd1(int root,int bas,int son,int x,int y,int t){
	if(bas > y or son < x)
		return St[root];

	if(x <= bas and son <= y){
		L[root]=t; L2[root] = 0;
		return St[root] = (son-bas+1)*t;
	}

	push(root,bas,son);

	return St[root] = upd1(sol,bas,ort,x,y,t) + upd1(sag,ort+1,son,x,y,t);
}

int upd2(int root,int bas,int son,int x,int y){
	if(bas > y or son < x)
		return St[root];

	push(root,bas,son);

	if(x <= bas and son <= y){
		L2[root]++;
		return St[root] += son-bas+1;
	}

	return St[root] = upd2(sol,bas,ort,x,y) + upd2(sag,ort+1,son,x,y);
}

int lp(int x,int y){
	int p=0;
	for(int i=K ; i>=0 ; i--)
		if(S[x][i] == S[y][i]){
			x += 1<<i;
			y += 1<<i;
			p += 1<<i;
		}

	return p;
}

 main(){

//	freopen("kob.gir","r",stdin);
// freopen("sex.cik","w",stdout);

	cin >> str;

	n = str.size();

	for(i=0 ; i<str.size() ; i++)
		S[i][0] = str[i];

	for(i=1 ; i<=K ; i++){

		for(j=0 ; j<str.size() ; j++)
			v[j]=(mp(mp(S[j][i-1] , S[min(n,j+(1<<i-1))][i-1]),j));

		sort(v,v+n);

		S[v[0].nd][i] = 1;

		for(j=1 ; j<str.size() ; j++)
			if(v[j].st != v[j-1].st)
				S[v[j].nd][i] = S[v[j-1].nd][i]+1;
			else
				S[v[j].nd][i] = S[v[j-1].nd][i];

	}

	for(i=0 ; i<str.size() ; i++){
		wh[S[i][K]] = i;
	}

	memset(L,-1,sizeof L);

	ll ans=0;

	for(i=1 ; i<=str.size() ; i++){
		int x = wh[i];

		int l=0;

		if(i!=1)
			l = lp(wh[i],wh[i-1]);

		upd1(1,1,n,l+1,n-x,1);
		upd1(1,1,n,n-x+1,n,0);
		upd2(1,1,n,1,l);
		ans += St[1];
	}

	cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define N (int)(1e5+10)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define inf mod
#define endl '\n'
#define sag (sol|1)
#define sol (root<<1)
#define ort ((bas+son)>>1)
#define bit(x,y) ((x>>y)&1)
#define K 17

ll St[4*N],L2[4*N],L[4*N];

int i,j,k,n,m,x,y,z,S[N][K+1];
int ans,wh[N];
pair< pii , int > v[N];
string str;

void push(int root,int bas,int son){
	if(bas==son)
		return;
	if(L[root]!=-1){
		L[sol]=L[sag]=L[root];
		L2[sol]=L2[sag]=0;
		St[sol]=(ort-bas+1)*L[root];
		St[sag]=(son-bas)*L[root];
		L[root]=-1;
	}
	if(L2[root]){
		L2[sol]+=L2[root];
		L2[sag]+=L2[root];
		St[sol]+=(ort-bas+1)*L2[root];
		St[sag]+=(son-bas)*L2[root];
		L2[root]=0;
	}
}

int que(int root,int bas,int son,int x,int y){
	if(bas > y or son < x)
		return 0;

	if(x <= bas and son <= y)
		return St[root];

	push(root,bas,son);

	return que(sol,bas,ort,x,y) + que(sag,ort+1,son,x,y);
}

int upd1(int root,int bas,int son,int x,int y,int t){
	if(bas > y or son < x)
		return St[root];

	push(root,bas,son);

	if(x <= bas and son <= y){
		L[root]=t; L2[root] = 0;
		return St[root] = (son-bas+1)*t;
	}

	return St[root] = upd1(sol,bas,ort,x,y,t) + upd1(sag,ort+1,son,x,y,t);
}

int upd2(int root,int bas,int son,int x,int y){
	if(bas > y or son < x)
		return St[root];

	push(root,bas,son);

	if(x <= bas and son <= y){
		L2[root]++;
		return St[root] += son-bas+1;
	}

	return St[root] = upd2(sol,bas,ort,x,y) + upd2(sag,ort+1,son,x,y);
}

int lp(int x,int y){
	int p=0;
	for(int i=K ; i>=0 ; i--)
		if(S[x][i] == S[y][i]){
			x += 1<<i;
			y += 1<<i;
			p += 1<<i;
		}

	return p;
}

int main(){

//	freopen("123d.gir","r",stdin);
//	freopen("123d.cik","w",stdout);

	cin >> str;

	n = str.size();

	for(i=0 ; i<str.size() ; i++)
		S[i][0] = str[i];

	for(i=1 ; i<=K ; i++){

		for(j=0 ; j<str.size() ; j++)
			v[j]=(mp(mp(S[j][i-1] , S[min(n,j+(1<<i-1))][i-1]),j));

		sort(v,v+n);

		S[v[0].nd][i] = 1;

		for(j=1 ; j<str.size() ; j++)
			if(v[j].st != v[j-1].st)
				S[v[j].nd][i] = S[v[j-1].nd][i]+1;
			else
				S[v[j].nd][i] = S[v[j-1].nd][i];

	}

	for(i=0 ; i<str.size() ; i++){
		wh[S[i][K]] = i;
	}

	memset(L,-1,sizeof L);

	ll ans=0;

	for(i=1 ; i<=str.size() ; i++){
		int x = wh[i];

		int l=0;

		if(i!=1)
			l = lp(wh[i],wh[i-1]);

		upd1(1,1,n,l+1,n-x,1);
		upd1(1,1,n,n-x+1,n,0);
		upd2(1,1,n,1,l);
		ans += St[1];
	}

	cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define N (int)(1e5+10)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define inf mod
#define endl '\n'
#define sag (sol|1)
#define sol (root<<1)
#define ort ((bas+son)>>1)
#define bit(x,y) ((x>>y)&1)
#define K 17

#define int ll

ll St[4*N],L2[4*N],L[4*N];

int i,j,k,n,m,x,y,z,S[N][K+1];
int ans,wh[N];
pair< pii , int > v[N];
string str;

void push(int root,int bas,int son){
	if(bas==son)
		return;
	if(L[root]!=-1){
		L[sol]=L[sag]=L[root];
		L2[sol]=L2[sag]=0;
		St[sol]=(ort-bas+1)*L[root];
		St[sag]=(son-bas)*L[root];
		L[root]=-1;
	}
	if(L2[root]){
		L2[sol]+=L2[root];
		L2[sag]+=L2[root];
		St[sol]+=(ort-bas+1)*L2[root];
		St[sag]+=(son-bas)*L2[root];
		L2[root]=0;
	}
}

int que(int root,int bas,int son,int x,int y){
	if(bas > y or son < x)
		return 0;

	if(x <= bas and son <= y)
		return St[root];

	push(root,bas,son);

	return que(sol,bas,ort,x,y) + que(sag,ort+1,son,x,y);
}

int upd1(int root,int bas,int son,int x,int y,int t){
	if(bas > y or son < x)
		return St[root];

	push(root,bas,son);

	if(x <= bas and son <= y){
		L[root]=t; L2[root] = 0;
		return St[root] = (son-bas+1)*t;
	}

	return St[root] = upd1(sol,bas,ort,x,y,t) + upd1(sag,ort+1,son,x,y,t);
}

int upd2(int root,int bas,int son,int x,int y){
	if(bas > y or son < x)
		return St[root];

	push(root,bas,son);

	if(x <= bas and son <= y){
		L2[root]++;
		return St[root] += son-bas+1;
	}

	return St[root] = upd2(sol,bas,ort,x,y) + upd2(sag,ort+1,son,x,y);
}

int lp(int x,int y){
	int p=0;
	for(int i=K ; i>=0 ; i--)
		if(S[x][i] == S[y][i]){
			x += 1<<i;
			y += 1<<i;
			p += 1<<i;
		}

	return p;
}

 main(){

	freopen("123d.gir","r",stdin);
	freopen("123d.cik","w",stdout);

	cin >> str;

	n = str.size();

	for(i=0 ; i<str.size() ; i++)
		S[i][0] = str[i];

	for(i=1 ; i<=K ; i++){

		for(j=0 ; j<str.size() ; j++)
			v[j]=(mp(mp(S[j][i-1] , S[min(n,j+(1<<i-1))][i-1]),j));

		sort(v,v+n);

		S[v[0].nd][i] = 1;

		for(j=1 ; j<str.size() ; j++)
			if(v[j].st != v[j-1].st)
				S[v[j].nd][i] = S[v[j-1].nd][i]+1;
			else
				S[v[j].nd][i] = S[v[j-1].nd][i];

	}

	for(i=0 ; i<str.size() ; i++){
		wh[S[i][K]] = i;
	}

	memset(L,-1,sizeof L);

	ll ans=0;

	for(i=1 ; i<=str.size() ; i++){
		int x = wh[i];

		int l=0;

		if(i!=1)
			l = lp(wh[i],wh[i-1]);

		upd1(1,1,n,l+1,n-x,1);
		upd1(1,1,n,n-x+1,n,0);
		upd2(1,1,n,1,l);
		ans += St[1];
	}

	cout << ans << endl;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;

const int MAX_N = 200010;

struct sa_comp {
  int h, *g;
  sa_comp(int h_, int *g_) : h(h_), g(g_) {}
  bool operator() (int a, int b) {
    return a == b ? false : g[a] != g[b] ? g[a] < g[b] : g[a + h] < g[b + h];
  }
};

int g[MAX_N], b[MAX_N];

void construct_sa(char *s, int n, int *sa) {
  for (int i = 0; i <= n; i++) {
    sa[i] = i;
    g[i] = s[i];
  }
  b[0] = 0;
  b[n] = 0;
  sort(sa, sa + n + 1, sa_comp(0, g));
  for (int h = 1; b[n] != n; h *= 2) {
    sa_comp cmp(h, g);
    sort(sa, sa + n + 1, cmp);
    for (int i = 0; i < n; i++) b[i + 1] = b[i] + cmp(sa[i], sa[i + 1]);
    for (int i = 0; i <= n; i++) g[sa[i]] = b[i];
  }
}

void construct_lcp(char *s, int n, int *sa, int *lcp) {
  int h = 0;
  for (int i = 0; i <= n; i++) b[sa[i]] = i;
  for (int i = 0; i <= n; i++) {
    if (b[i]) {
      for (int j = sa[b[i] - 1]; j + h < n && i + h < n && s[j + h] == s[i + h]; h++);
      lcp[b[i]] = h;
    }
    else lcp[b[i]] = -1;
    if (h > 0) h--;
  }
}

char S[100010];
int sa[100010];
int lcp[100010];

ll ans = 0;

void visit_st_nodes(int *sa, int *lcp, int n) {
  vector<int> h(2 * n + 1);
  for (int i = 1; i <= n; ++i) {
    h[i * 2 - 2] = lcp[i];
    h[i * 2 - 1] = n - sa[i];
  }

  static int stki[1000010], stkh[1000010];
  int stkp = 0;
  rep (i, h.size()) {
    int j = i;
    while (stkp > 0 && stkh[stkp - 1] >= h[i]) {
      j = stki[stkp - 1];
      // res = max(res, stkh[stkp - 1] * (i - j));
      if (stkh[stkp - 1] != h[i])  {
        // printf("%d: %d * %d\n", i, stkh[stkp - 1], (i - j));
        ll k = ((i - j) + 1) / 2;

        // if (stkp >= 2) d = stkh[stkp - 1] - max(stkh[stkp - 2], h[i]);
        // else d = stkh[stkp - 1] - h[i];
        ll d = stkh[stkp - 1];
        ll dd = d - (stkp >= 2 ? max(stkh[stkp - 2], h[i]) : h[i]);

        // ll d = stkh[stkp - 1] - a[i];
        // printf(" %d -> %d\n", stkh[stkp - 1], a[i]);
        // printf(" %lld %lld\n", d, k);
        ans += dd * (k + 1) * k / 2;
      }
      --stkp;
    }
    stki[stkp] = j;
    stkh[stkp] = h[i];
    ++stkp;
  }
}

int main() {
  while (cin >> S) {
    int N = strlen(S);
    construct_sa(S, N, sa);
    construct_lcp(S, N, sa, lcp);

    ans = 0;
    visit_st_nodes(sa, lcp, N);
    cout << ans << endl;
  }

  return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;

const int MAX_N = 200010;

struct sa_comp {
  int h, *g;
  sa_comp(int h_, int *g_) : h(h_), g(g_) {}
  bool operator() (int a, int b) {
    return a == b ? false : g[a] != g[b] ? g[a] < g[b] : g[a + h] < g[b + h];
  }
};

int g[MAX_N], b[MAX_N];

void construct_sa(char *s, int n, int *sa) {
  for (int i = 0; i <= n; i++) {
    sa[i] = i;
    g[i] = s[i];
  }
  b[0] = 0;
  b[n] = 0;
  sort(sa, sa + n + 1, sa_comp(0, g));
  for (int h = 1; b[n] != n; h *= 2) {
    sa_comp cmp(h, g);
    sort(sa, sa + n + 1, cmp);
    for (int i = 0; i < n; i++) b[i + 1] = b[i] + cmp(sa[i], sa[i + 1]);
    for (int i = 0; i <= n; i++) g[sa[i]] = b[i];
  }
}

void construct_lcp(char *s, int n, int *sa, int *lcp) {
  int h = 0;
  for (int i = 0; i <= n; i++) b[sa[i]] = i;
  for (int i = 0; i <= n; i++) {
    if (b[i]) {
      for (int j = sa[b[i] - 1]; j + h < n && i + h < n && s[j + h] == s[i + h]; h++);
      lcp[b[i]] = h;
    }
    else lcp[b[i]] = -1;
    if (h > 0) h--;
  }
}

char S[100010];
int sa[100010];
int lcp[100010];

ll ans = 0;

void visit_st_nodes(int *sa, int *lcp, int n) {
  vector<int> h(2 * n + 1);  // +1 for a sentinel
  for (int i = 1; i <= n; ++i) {
    h[i * 2 - 2] = lcp[i];
    h[i * 2 - 1] = n - sa[i];
  }

  static int stki[1000010], stkh[1000010];
  int stkp = 0;
  rep (i, h.size()) {
    int j = i;
    while (stkp > 0 && stkh[stkp - 1] >= h[i]) {
      j = stki[stkp - 1];
      if (stkh[stkp - 1] != h[i])  {
        int w = ((i - j) + 1) / 2;
        int d = stkh[stkp - 1];
        int dd = d - (stkp >= 2 ? max(stkh[stkp - 2], h[i]) : h[i]);

        ans += dd * ll(w + 1) * w / 2;
      }
      --stkp;
    }
    stki[stkp] = j;
    stkh[stkp] = h[i];
    ++stkp;
  }
}

int main() {
  while (cin >> S) {
    int N = strlen(S);
    construct_sa(S, N, sa);
    construct_lcp(S, N, sa, lcp);

    ans = 0;
    visit_st_nodes(sa, lcp, N);
    cout << ans << endl;
  }

  return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;

const int MAX_N = 200010;

struct sa_comp {
  int h, *g;
  sa_comp(int h_, int *g_) : h(h_), g(g_) {}
  bool operator() (int a, int b) {
    return a == b ? false : g[a] != g[b] ? g[a] < g[b] : g[a + h] < g[b + h];
  }
};

int g[MAX_N], b[MAX_N];

void construct_sa(char *s, int n, int *sa) {
  for (int i = 0; i <= n; i++) {
    sa[i] = i;
    g[i] = s[i];
  }
  b[0] = 0;
  b[n] = 0;
  sort(sa, sa + n + 1, sa_comp(0, g));
  for (int h = 1; b[n] != n; h *= 2) {
    sa_comp cmp(h, g);
    sort(sa, sa + n + 1, cmp);
    for (int i = 0; i < n; i++) b[i + 1] = b[i] + cmp(sa[i], sa[i + 1]);
    for (int i = 0; i <= n; i++) g[sa[i]] = b[i];
  }
}

void construct_lcp(char *s, int n, int *sa, int *lcp) {
  int h = 0;
  for (int i = 0; i <= n; i++) b[sa[i]] = i;
  for (int i = 0; i <= n; i++) {
    if (b[i]) {
      for (int j = sa[b[i] - 1]; j + h < n && i + h < n && s[j + h] == s[i + h]; h++);
      lcp[b[i]] = h;
    }
    else lcp[b[i]] = -1;
    if (h > 0) h--;
  }
}

char S[100010];
int sa[100010];
int lcp[100010];

int stki[1000010], stkh[1000010];
ll ans = 0;

int solve(const vector<int> &a) {
  // a.push_back(0);
  assert(a.back() == 0);  // a sentinel must be added

  int stkp = 0, res = 0;
  rep (i, a.size()) {
    int j = i;
    while (stkp > 0 && stkh[stkp - 1] >= a[i]) {
      j = stki[stkp - 1];
      // res = max(res, stkh[stkp - 1] * (i - j));
      if (stkh[stkp - 1] != a[i])  {
        // printf("%d: %d * %d\n", i, stkh[stkp - 1], (i - j));
        ll k = ((i - j) + 1) / 2;

        ll d;
        if (stkp >= 2) d = stkh[stkp - 1] - max(stkh[stkp - 2], a[i]);
        else d = stkh[stkp - 1] - a[i];
        // ll d = stkh[stkp - 1] - a[i];
        // printf(" %d -> %d\n", stkh[stkp - 1], a[i]);
        // printf(" %lld %lld\n", d, k);
        ans += d * (k + 1) * k / 2;
      }
      --stkp;
    }
    stki[stkp] = j;
    stkh[stkp] = a[i];
    ++stkp;
  }
  return res;
}

int main() {
  while (cin >> S) {
    int N = strlen(S);
    construct_sa(S, N, sa);
    construct_lcp(S, N, sa, lcp);

    lcp[0] = 0;
    vector<int> lcp2;
    for (int i = 0; i <= N; ++i) {
      lcp2.pb(lcp[i]);
      lcp2.pb(N - sa[i]);
      // printf(" %d\n %d\n", lcp[i], N - sa[i]);
    }
    lcp2.pb(0);

    ans = 0;
    solve(lcp2);
    cout << ans << endl;
  }

  return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;

const int MAX_N = 200010;

void count_buckets(const int *s, int n, int k, bool end, int *b) {
  for (int i = 0; i <= k; ++i) b[i] = 0;
  for (int i = 0; i < n; ++i) ++b[s[i]];
  int c = 0;
  for (int i = 0; i <= k; ++i) {
    c += b[i];
    b[i] = end ? c : c - b[i];
  }
}

void induce_sa(const int *s, int n, int k, const bool *t, int *sa, int *b) {
  // Induce L-type suffixes
  count_buckets(s, n, k, false, b);
  for (int i = 0; i < n; ++i) {
    int j = sa[i] - 1;
    if (j >= 0 && !t[j]) sa[b[s[j]]++] = j;
  }
  // Induce S-type suffixes
  count_buckets(s, n, k, true, b);
  for (int i = n - 1; i >= 0; --i) {
    int j = sa[i] - 1;
    if (j >= 0 && t[j]) sa[--b[s[j]]] = j;
  }
}

bool is_lms(int i, const bool *t) {
  return i > 0 && t[i] && !t[i - 1];
}

void construct_sa(const int *s, int n, int k, int *sa) {
  bool *t = new bool[n];
  t[n - 1] = true;
  t[n - 2] = false;
  for (int i = n - 3; i >= 0; --i) {
    t[i] = s[i] < s[i + 1] || (s[i] == s[i + 1] && t[i + 1]);
  }

  //
  // Stage 1: Sort the LMS-substrings & generate the sub-problem
  //
  int *b = new int[k + 10];
  count_buckets(s, n, k, true, b);
  for (int i = 0; i < n; ++i) sa[i] = -1;
  for (int i = 1; i < n; ++i) if (is_lms(i, t)) sa[--b[s[i]]] = i;
  induce_sa(s, n, k, t, sa, b);

  int n1 = 0;
  for (int i = 0; i < n; ++i) if (is_lms(sa[i], t)) sa[n1++] = sa[i];
  for (int i = n1; i < n; ++i) sa[i] = -1;
  int k1 = 0, prv = -1;
  for (int i = 0; i < n1; ++i) {
    int crr = sa[i];
    for (int j = 0; ; ++j) {
      if (prv == -1 || s[crr + j] != s[prv + j] || t[crr + j] != t[prv + j]) {
        ++k1;
        break;
      }
      else if (j > 0 && (is_lms(crr + j, t) || is_lms(prv + j, t))) break;
    }
    sa[n1 + crr / 2] = k1 - 1;  // reuse later part of the array...
    prv = crr;
  }
  for (int i = n - 1, j = n - 1; i >= n1; --i) {
    if (sa[i] >= 0) sa[j--] = sa[i];
  }

  //
  // Stage 2: Recurse and solve the sub-problem
  //
  int *sa1 = sa, *s1 = sa + n - n1;
  if (k1 < n1) {
    construct_sa(s1, n1, k1, sa1);
  } else {
    for (int i = 0; i < n1; ++i) sa1[s1[i]] = i;
  }

  //
  // Stage 3: Induced-sort and construct the SA
  //
  count_buckets(s, n, k, true, b);
  for (int i = 1, j = 0; i < n; ++i) {
    if (is_lms(i, t)) s1[j++] = i;
  }
  for (int i = 0; i < n1; ++i) sa[i] = s1[sa1[i]];
  for (int i = n1; i < n; ++i) sa[i] = -1;
  for (int i = n1 - 1; i >= 0; --i) {
    int j = sa[i];
    sa[i] = -1;
    sa[--b[s[j]]] = j;
  }
  induce_sa(s, n, k, t, sa, b);

  delete [] t;
  delete [] b;
}

void construct_sa(const unsigned char *s, int *sa) {
  int n = strlen((const char*)s);
  int *si = new int[n + 1];
  for (int i = 0; i <= n; ++i) si[i] = s[i];
  construct_sa(si, n + 1, 255, sa);
}

void construct_lcp(char *s, int n, int *sa, int *lcp) {
  static int b[1000010];

  int h = 0;
  for (int i = 0; i <= n; i++) b[sa[i]] = i;
  for (int i = 0; i <= n; i++) {
    if (b[i]) {
      for (int j = sa[b[i] - 1]; j + h < n && i + h < n && s[j + h] == s[i + h]; h++);
      lcp[b[i]] = h;
    }
    else lcp[b[i]] = -1;
    if (h > 0) h--;
  }
}

char S[100010];
int sa[100010];
int lcp[100010];

ll ans = 0;

void visit_st_nodes(int *sa, int *lcp, int n) {
  vector<int> h(2 * n + 1);  // +1 for a sentinel
  for (int i = 1; i <= n; ++i) {
    h[i * 2 - 2] = lcp[i];
    h[i * 2 - 1] = n - sa[i];
  }

  static int stki[1000010], stkh[1000010];
  int stkp = 0;
  rep (i, h.size()) {
    int j = i;
    while (stkp > 0 && stkh[stkp - 1] >= h[i]) {
      j = stki[stkp - 1];
      if (stkh[stkp - 1] != h[i])  {
        int w = ((i - j) + 1) / 2;
        int d = stkh[stkp - 1];
        int dd = d - (stkp >= 2 ? max(stkh[stkp - 2], h[i]) : h[i]);

        ans += dd * ll(w + 1) * w / 2;
      }
      --stkp;
    }
    stki[stkp] = j;
    stkh[stkp] = h[i];
    ++stkp;
  }
}

int main() {
  while (cin >> S) {
    int N = strlen(S);
    construct_sa((unsigned char*)S, sa);
    construct_lcp(S, N, sa, lcp);

    ans = 0;
    visit_st_nodes(sa, lcp, N);
    cout << ans << endl;
  }

  return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <utility>
#include <vector>
#include <set>
#include <map>

#define F first
#define S second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long LL;
typedef pair <LL, int> pii;

const int maxn = (int)1e6;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double eps = 1e-9;
const int K = 20;

pii A[maxn], B[maxn];
int n, C[maxn];

void compress(int st)
{
	int cnt = 0;

	for (int i = 0; i < n; ++i)
		C[A[i].S] = A[i].F;

	for (int i = 0; i < n; ++i)
		A[i].F = C[A[i].S] * 1ll * (n + 100) + C[(A[i].S + st / 2) % n];

	for (int i = 0; i < n; ++i)
	{
		if (!i || A[i].F == A[i - 1].F)
			B[i].F = cnt;
		else
			B[i].F = ++cnt;
		B[i].S = A[i].S;
		C[B[i].S] = B[i].F;
	}

	for (int i = 0; i < n; ++i)
		A[i] = B[i];
	return;
}

void make_array(int st)
{
	for (int i = 0; i < n; ++i)
		A[i].F = C[(A[i].S + st) % n];
	return;
}

int cnt[maxn], head[maxn];

void sort_()
{
	for (int i = 0; i < n; ++i)
		cnt[i] = 0;
	for (int i = 0; i < n; ++i)
		cnt[A[i].F]++;
	int my = 0;

	for (int i = 0; i < n; ++i)
	{
		head[i] = my;
		my += cnt[i];
	}

	for (int i = 0; i < n; ++i)
		B[head[A[i].F]++] = A[i];

	for (int i = 0; i < n; ++i)
		A[i] = B[i];
	return;
}

char s[maxn];

void suff_array(int *a)
{
	s[n++] = '#';

	for (int i = 0; i < n; ++i)
		A[i].F = s[i], A[i].S = i;

	sort(A, A + n);

	for (int it = 0; it < K; ++it)
	{
		compress(1 << it);

		make_array(1 << it);
		sort_();
		make_array(0);
		sort_();
	}
	n--;

	for (int i = 1; i <= n; ++i)
		a[i - 1] = A[i].S;

	return;
}

int pos[maxn], len[maxn], a[maxn], b[maxn];

void kasay()
{
	int v;
	for (int i = 0; i < n; ++i)
	{
		v = pos[i];
		if (i)
			b[v] = max(0, b[pos[i - 1]] - 1);
		while (v != n - 1 && b[v] < len[v] && b[v] < len[v + 1] && s[a[v] + b[v]] == s[a[v + 1] + b[v]])
			++b[v];
	}
	return;
}

int w[4 * maxn], t[4 * maxn];

void push(int v, int tl, int tr)
{
	if (!w[v])
		return;
	if (w[v] < 0)
		t[v] = -w[v] * (tr - tl + 1ll);
	if (w[v] > 0)
		t[v] += w[v] * (tr - tl + 1ll);

	if (tl != tr)
	{
		if (w[v] < 0)
		{
			w[v + v] = w[v + v + 1] = w[v];
		}
		else
		{
			if (w[v + v] < 0)
				w[v + v] -= w[v];
			else
				w[v + v] += w[v];
			if (w[v + v + 1] < 0)
				w[v + v + 1] -= w[v];
			else
				w[v + v + 1] += w[v];
		}
	}
	w[v] = 0;
	return;
}

void set_(int v, int tl, int tr, int l, int r, LL val)
{
	push(v, tl, tr);
	if (tl == l && tr == r)
	{
		w[v] = -val;
		return;
	}
	int mid = (tl + tr) / 2;
	if (l <= mid)
		set_(v + v, tl, mid, l, min(mid, r), val);
	if (r >= mid + 1)
		set_(v + v + 1, mid + 1, tr, max(mid + 1, l), r, val);
	push(v + v, tl, mid);
	push(v + v + 1, mid + 1, tr);
	t[v] = t[v + v] + t[v + v + 1];
	return;
}

void upd(int v, int tl, int tr, int l, int r, LL val)
{
	push(v, tl, tr);
	if (tl == l && tr == r)
	{
		w[v] = val;
		return;
	}
	int mid = (tl + tr) / 2;
	if (l <= mid)
		upd(v + v, tl, mid, l, min(mid, r), val);
	if (r >= mid + 1)
		upd(v + v + 1, mid + 1, tr, max(l, mid + 1), r, val);
	push(v + v, tl, mid);
	push(v + v + 1, mid + 1, tr);
	t[v] = t[v + v] + t[v + v + 1];
	return;
}

LL get(int v, int tl, int tr, int l, int r)
{
	if (l > r)
		return 0;
	push(v, tl, tr);
	if (tl == l && tr == r)
		return t[v];
	int mid = (tl + tr) / 2;
	return get(v + v, tl, mid, l, min(mid, r)) + get(v + v + 1, mid + 1, tr, max(mid + 1, l), r);
}

int main()
{
//    freopen("in", "r", stdin);

	scanf("%s", s);
	n = strlen(s);

	suff_array(a);
	for (int i = 0; i < n; ++i)
	{
		pos[a[i]] = i;
		len[i] = n - a[i];
	}
	kasay();

	LL ans = 0;

	for (int i = n - 1; i >= 0; --i)
	{
		set_(1, 1, n, b[i] + 1, len[i], 1);
		if (b[i])
			upd(1, 1, n, 1, b[i], 1);

		ans += get(1, 1, n, 1, len[i]);
	}

	cout << ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <utility>
#include <vector>
#include <set>
#include <map>

#define F first
#define S second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long LL;
typedef pair <LL, int> pii;

const int maxn = (int)1e6;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double eps = 1e-9;
const int K = 20;

pii A[maxn], B[maxn];
int n, C[maxn];

void compress(int st)
{
	int cnt = 0;

	for (int i = 0; i < n; ++i)
		C[A[i].S] = A[i].F;

	for (int i = 0; i < n; ++i)
		A[i].F = C[A[i].S] * 1ll * (n + 100) + C[(A[i].S + st / 2) % n];

	for (int i = 0; i < n; ++i)
	{
		if (!i || A[i].F == A[i - 1].F)
			B[i].F = cnt;
		else
			B[i].F = ++cnt;
		B[i].S = A[i].S;
		C[B[i].S] = B[i].F;
	}

	for (int i = 0; i < n; ++i)
		A[i] = B[i];
	return;
}

void make_array(int st)
{
	for (int i = 0; i < n; ++i)
		A[i].F = C[(A[i].S + st) % n];
	return;
}

int cnt[maxn], head[maxn];

void sort_()
{
	for (int i = 0; i < n; ++i)
		cnt[i] = 0;
	for (int i = 0; i < n; ++i)
		cnt[A[i].F]++;
	int my = 0;

	for (int i = 0; i < n; ++i)
	{
		head[i] = my;
		my += cnt[i];
	}

	for (int i = 0; i < n; ++i)
		B[head[A[i].F]++] = A[i];

	for (int i = 0; i < n; ++i)
		A[i] = B[i];
	return;
}

char s[maxn];

void suff_array(int *a)
{
	s[n++] = '#';

	for (int i = 0; i < n; ++i)
		A[i].F = s[i], A[i].S = i;

	sort(A, A + n);

	for (int it = 0; it < K; ++it)
	{
		compress(1 << it);

		make_array(1 << it);
		sort_();
		make_array(0);
		sort_();
	}
	n--;

	for (int i = 1; i <= n; ++i)
		a[i - 1] = A[i].S;

	return;
}

int pos[maxn], len[maxn], a[maxn], b[maxn];

void kasay()
{
	int v;
	for (int i = 0; i < n; ++i)
	{
		v = pos[i];
		if (i)
			b[v] = max(0, b[pos[i - 1]] - 1);
		while (v != n - 1 && b[v] < len[v] && b[v] < len[v + 1] && s[a[v] + b[v]] == s[a[v + 1] + b[v]])
			++b[v];
	}
	return;
}

LL w[4 * maxn], t[4 * maxn];

void push(int v, int tl, int tr)
{
	if (!w[v])
		return;
	if (w[v] < 0)
		t[v] = -w[v] * (tr - tl + 1ll);
	if (w[v] > 0)
		t[v] += w[v] * (tr - tl + 1ll);

	if (tl != tr)
	{
		if (w[v] < 0)
		{
			w[v + v] = w[v + v + 1] = w[v];
		}
		else
		{
			if (w[v + v] < 0)
				w[v + v] -= w[v];
			else
				w[v + v] += w[v];
			if (w[v + v + 1] < 0)
				w[v + v + 1] -= w[v];
			else
				w[v + v + 1] += w[v];
		}
	}
	w[v] = 0;
	return;
}

void set_(int v, int tl, int tr, int l, int r, LL val)
{
	push(v, tl, tr);
	if (tl == l && tr == r)
	{
		w[v] = -val;
		return;
	}
	int mid = (tl + tr) / 2;
	if (l <= mid)
		set_(v + v, tl, mid, l, min(mid, r), val);
	if (r >= mid + 1)
		set_(v + v + 1, mid + 1, tr, max(mid + 1, l), r, val);
	push(v + v, tl, mid);
	push(v + v + 1, mid + 1, tr);
	t[v] = t[v + v] + t[v + v + 1];
	return;
}

void upd(int v, int tl, int tr, int l, int r, LL val)
{
	push(v, tl, tr);
	if (tl == l && tr == r)
	{
		w[v] = val;
		return;
	}
	int mid = (tl + tr) / 2;
	if (l <= mid)
		upd(v + v, tl, mid, l, min(mid, r), val);
	if (r >= mid + 1)
		upd(v + v + 1, mid + 1, tr, max(l, mid + 1), r, val);
	push(v + v, tl, mid);
	push(v + v + 1, mid + 1, tr);
	t[v] = t[v + v] + t[v + v + 1];
	return;
}

LL get(int v, int tl, int tr, int l, int r)
{
	if (l > r)
		return 0;
	push(v, tl, tr);
	if (tl == l && tr == r)
		return t[v];
	int mid = (tl + tr) / 2;
	return get(v + v, tl, mid, l, min(mid, r)) + get(v + v + 1, mid + 1, tr, max(mid + 1, l), r);
}

int main()
{
//    freopen("in", "r", stdin);

	scanf("%s", s);
	n = strlen(s);

	suff_array(a);
	for (int i = 0; i < n; ++i)
	{
		pos[a[i]] = i;
		len[i] = n - a[i];
	}
	kasay();

	LL ans = 0;

	for (int i = n - 1; i >= 0; --i)
	{
		set_(1, 1, n, b[i] + 1, len[i], 1);
		if (b[i])
			upd(1, 1, n, 1, b[i], 1);

		ans += get(1, 1, n, 1, len[i]);
	}

	cout << ans;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	long int n, x[100001], q, m[100001], i, j, k, count, out[100001], low, mid, high;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	cin >> q;
	for(i=0; i<q; i++){
		cin >> m[i];
		low = 0;
		high = n - 1;
		mid = (low+high)/2;
		while(low <= high){
			if(m[i] > x[mid]){
				while(m[i] > x[mid]){
					mid++;
					if(mid == n){
						break;
					}
				}
				if(m[i] == x[mid]){
					mid++;
				}
				out[i] = mid;
				break;
			}
			else if(m[i] == x[mid]){
				out[i] = mid + 1;
				break;
			}
			else{
				high = mid - 1;
			}
			mid = (low+high)/2;
		}
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	long int n, x[100001], q, m[100001], i, j, k, count, out[100001], low, mid, high;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	cin >> q;
	for(i=0; i<q; i++){
		cin >> m[i];
		low = 0;
		high = n - 1;
		mid = (low+high)/2;
		while(low <= high){
			if(m[i] > x[mid]){
				low = mid + 1;
			}
			else if(m[i] == x[mid]){
				out[i] = mid + 1;
				break;
			}
			else{
				high = mid - 1;
			}
			mid = (low+high)/2;
		}
		if(low > high){
			out[i] = mid;
		}
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	long int n, x[100001], q, m[100001], i, j, k, count, out[100001], low, mid, high;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	cin >> q;
	for(i=0; i<q; i++){
		cin >> m[i];
		low = 0;
		high = n - 1;
		mid = (low+high)/2;
		while(low <= high){
			if(m[i] > x[mid]){
				while(m[i] > x[mid]){
					mid++;
				}
				mid++;
				out[i] = mid;
				break;
			}
			else if(m[i] == x[mid]){
				out[i] = mid + 1;
				break;
			}
			else{
				high = mid - 1;
			}
			mid = (low+high)/2;
		}
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	long int n, x[100001], q, m[100001], i, j, k, count, out[100001], low, mid, high;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	cin >> q;
	for(i=0; i<q; i++){
		count = 0;
		cin >> m[i];
		for(j=0; j<n; j++){
			if(m[i] >= x[j]){
				count++;
			}
		}
		out[i] = count;
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main(){
	int n, x[100000], q, m[100000], i, j, k, count, out[100000];
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	cin >> q;
	for(i=0; i<q; i++){
		count = 0;
		cin >> m[i];
		for(j=0; j<n; j++){
			if(m[i] >= x[j]){
				count++;
			}
		}
		out[i] = count;
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	long int n, x[100001], q, m[100001], i, j, k, count, out[100001], low, mid, high;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	cin >> q;
	for(i=0; i<q; i++){
		cin >> m[i];
		low = 0;
		high = n - 1;
		mid = (low+high)/2;
		while(low <= high){
			if(m[i] > x[mid]){
				low = mid + 1;
			}
			else if(m[i] == x[mid]){
				out[i] = mid + 1;
				break;
			}
			else{
				high = mid - 1;
			}
			mid = (low+high)/2;
		}
		if(low > high){
			if(m[i] < x[0]){
				mid--;
			}
			out[i] = mid + 1;
		}
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
long int out[100001], m[100001], x[100001];
using namespace std;
int main(){
	long int n, q, i, j, k, count, low, mid, high;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	cin >> q;
	for(i=0; i<q; i++){
		cin >> m[i];
		low = 0;
		high = n - 1;
		mid = (low+high)/2;
		while(low <= high){
			if(m[i] > x[mid]){
				low = mid + 1;
			}
			else if(m[i] == x[mid]){
				mid++;
				while(m[i] == x[mid] && i<=n-1){
					mid++;
				}
				out[i] = mid;
				break;
			}
			else{
				high = mid - 1;
			}
			mid = (low+high)/2;
		}
		if(low > high){
			if(m[i] < x[0]){
				mid--;
			}
			out[i] = mid + 1;
		}
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	long int n, x[100001], q, m[100001], i, j, k, count, out[100001], low, mid, high;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	cin >> q;
	for(i=0; i<q; i++){
		cin >> m[i];
		low = 0;
		high = n - 1;
		mid = (low+high)/2;
		while(low <= high){
			if(m[i] > x[mid]){
				low = mid + 1;
			}
			else if(m[i] == x[mid]){
				out[i] = mid + 1;
				break;
			}
			else{
				high = mid - 1;
			}
			mid = (low+high)/2;
		}
		if(low > high){
			if(m[i] < x[0]){
				mid--;
			}
			if(m[i] > x[n-1]){
				mid++;
			}
			out[i] = mid + 1;
		}
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	long int n, x[100001], q, m[100001], i, j, k, count, out[100001], low, mid, high;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	cin >> q;
	for(i=0; i<q; i++){
		cin >> m[i];
		low = 0;
		high = n - 1;
		mid = (low+high)/2;
		while(low <= high){
			if(m[i] > x[mid]){
				while(m[i] > x[mid]){
					mid++;
				}
				if(m[i] == x[mid]){
					mid++;
				}
				out[i] = mid;
				break;
			}
			else if(m[i] == x[mid]){
				out[i] = mid + 1;
				break;
			}
			else{
				high = mid - 1;
			}
			mid = (low+high)/2;
		}
	}
	for(i=0; i<q; i++){
		cout << out[i] << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100];

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>1){
        if(mb == a[z])
            return z+1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:1):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+1;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
       // memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100100];
int main()
{
    int i,j,k,m,n;
    while(cin>>n)
    {
        for(i=1;i<=n;i++) cin>>a[i];
        sort(a+1,a+n);
        //for(i=1;i<=n;i++) cout<<a[i]<<" ";
        cin>>k;
        for(i=1;i<=k;i++)
        {
            cin>>m;
            int l=1,r=n,mid;
            if(m<a[1]) {cout<<"0"<<endl;continue;}
            else if(m>=a[n]) {cout<<n<<endl;continue;}
            else
            while(l<r)
            {
                mid=(r-l)/2+l;
                if(m==a[mid]) {cout<<mid<<endl;break;}
                else if(m>a[mid]) {l=mid+1;}
                else if(m<a[mid]) {r=mid-1;}
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100];

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>1){
        if(mb == a[z])
            return z+1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:1):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+1;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100];

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>0){
        if(mb == a[z])
            return z+1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>=a[z]?(mb>=a[y]?y+1:1):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+1;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100100];
int main()
{
    int i,j,k,m,n;
    while(cin>>n)
    {
        for(i=1;i<=n;i++) cin>>a[i];
        sort(a+1,a+n);
        //for(i=1;i<=n;i++) cout<<a[i]<<" ";
        cin>>k;
        for(i=1;i<=k;i++)
        {
            cin>>m;
            int l=1,r=n,mid;
            if(m<a[1]) {cout<<"0"<<endl;continue;}
            else if(m>=a[n]) {cout<<n<<endl;continue;}
            else
            while(l<=r)
            {
                mid=(r-l)/2+l;
                if(m==a[mid]) {cout<<mid<<endl;break;}
                else if(m>a[mid]) {l=mid+1;}
                else if(m<a[mid]) {r=mid-1;}
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100];

int eff(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>0){
        if(mb == a[z])
            return z+1+10;
        else if(mb == a[y])
            return y+1+20;
        else

            return mb>a[z]?(mb>=a[y]?y+1+30:z+1+40):z+1+50;}
        else
            {
                if(mb == a[z])
            return 1+60;
        else if(mb == a[y])
            return y+1+70;
        else

            return mb>=a[z]?(mb>=a[y]?y+1+80:1):0+100;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+1+110;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>0){
        if(mb == a[z])
            return z+1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>=a[z]?(mb>=a[y]?y+1:1):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+1;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        if(q!=1000)
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
        else
        {
            for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<eff(0,i,e)<<endl;
        }
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,i,a[100001],q,x;
int main(){
    for(cin>>n;i<n;i++)cin>>a[i];
    sort(a,a+n);
    cin>>q;
    while(q--)cin>>x,cout<<upper_bound(a,a+n,x)-a<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100]={1,2,3,4,5,6,7,8,9};

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>1){
        if(mb == a[z])
            return z+1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:1):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+1;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        for(i = 0 ;i < q; i++ )
            cout<<a[i]<<" ";
        cout<<endl;
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,i,a[100001],q,x;
int main(){
    for(cin>>n;i<n;i++)cin>>a[i];
    sort(a,a+n);
    cin>>q;
    while(q--)cin>>x,cout<<upper_bound(a,a+n,x)<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100];

int eff(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>0){
        if(mb == a[z])
            return z+1+10;
        else if(mb == a[y])
            return y+1+20;
        else

            return mb>a[z]?(mb>=a[y]?y+1+30:z+1+40):z+1+50;}
        else
            {
                if(mb == a[z])
            return 1+60;
        else if(mb == a[y])
            return y+1+70;
        else

            return mb>=a[z]?(mb>=a[y]?y+1+80:1):0+100;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+2+110;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>0){
        if(mb == a[z])
            return z+1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>=a[z]?(mb>=a[y]?y+1:1):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+2;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        //if(q!=1000)
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
        /*else
        {
            for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<eff(0,i,e)<<endl;
        }
        }*/
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100];

int eff(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>0){
        if(mb == a[z])
            return z+1+10;
        else if(mb == a[y])
            return y+1+20;
        else

            return mb>a[z]?(mb>=a[y]?y+1+30:z+1+40):z+1+50;}
        else
            {
                if(mb == a[z])
            return 1+60;
        else if(mb == a[y])
            return y+1+70;
        else

            return mb>=a[z]?(mb>=a[y]?y+1+80:1):0+100;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+2;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>0){
        if(mb == a[z])
            return z+1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>=a[z]?(mb>=a[y]?y+1:1):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+1;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        //if(q!=1000)
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
        /*else
        {
            for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<eff(0,i,e)<<endl;
        }
        }*/
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100]={1,2,3,4,5,6,7,8,9};

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>1){
        if(mb == a[z])
            return z+1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y+1;
        else

            return mb>a[z]?(mb>=a[y]?y+1:1):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z+1;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100];

int ef(int z, int y, int mb)
{
    mm:
    if( z == y || z+1 == y)
    {
        if(z>0){
        if(mb == a[z])
            return z;
        else if(mb == a[y])
            return y;
        else

            return mb>a[z]?(mb>=a[y]?y:z):z;}
        else
            {
                if(mb == a[z])
            return 1;
        else if(mb == a[y])
            return y;
        else

            return mb>=a[z]?(mb>=a[y]?y:0):0;
            }
    }
   if(mb >= a[(y-z)/2+z] )
   {
       y=y,z=(y-z)/2+z;
       if(mb==a[z])
        return z;
       else
        goto mm;
   }
   else
   {
       z=z,y=(y-z)/2+z;
       goto mm;
   }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 1; i <= q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[100100];

int eff(int z, int y, int mb)
{
mm:
    if( z == y || z+1 == y)
    {
        if(z>0)
        {
            if(mb == a[z])
                return z+1+10;
            else if(mb == a[y])
                return y+1+20;
            else

                return mb>a[z]?(mb>=a[y]?y+1+30:z+1+40):z+1+50;
        }
        else
        {
            if(mb == a[z])
                return 1+60;
            else if(mb == a[y])
                return y+1+70;
            else

                return mb>=a[z]?(mb>=a[y]?y+1+80:1):0+100;
        }
    }
    if(mb >= a[(y-z)/2+z] )
    {
        y=y,z=(y-z)/2+z;
        if(mb==a[z])
            return z+2+110;
        else
            goto mm;
    }
    else
    {
        z=z,y=(y-z)/2+z;
        goto mm;
    }
}

int ef(int z, int y, int mb)
{
mm:
    if( z == y || z+1 == y)
    {
        if(z>0)
        {
            if(mb == a[z])
                return z+1;
            else if(mb == a[y])
                return y+1;
            else

                return mb>a[z]?(mb>=a[y]?y+1:z+1):z+1;
        }
        else
        {
            if(mb == a[z])
                return 1;
            else if(mb == a[y])
                return y+1;
            else

                return mb>=a[z]?(mb>=a[y]?y+1:1):0;
        }
    }
    if(mb >= a[(y-z)/2+z] )
    {
        y=y,z=(y-z)/2+z;
        if(mb==a[z])
            return z+2;
        else
            goto mm;
    }
    else
    {
        z=z,y=(y-z)/2+z;
        goto mm;
    }
}

int main()
{
    int q,w,e,i,j;
    while(cin>>q)
    {
        memset(a,0,sizeof(a));
        for( i = 0; i < q; i++ )
        {
            cin>>a[i];
        }
        i--;
        cin>>w;
        sort(a,a+q);
        //if(q!=1000)
        for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<ef(0,i,e)<<endl;
        }
        /*else
        {
            for( j = 0; j < w; j++ )
        {
            cin>>e;
            cout<<eff(0,i,e)<<endl;
        }
        }*/
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll n,i,j,shop[100001];

int main(){

    //ll n;///number of shops
    cin>>n;

    for(i=1;i<=n;i++)
        cin>>shop[i];

    sort(shop+1,shop+1+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=1;i<=q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];

    for(i=1;i<=q;i++){

        ll Start,End,Mid,ans=0,num;
        Start=0;
        End=n;
        num=coins[i];
        while(Start<=End){
                Mid=(int)((Start + End)/2);

                if(num>=shop[Mid]){
                    ans=Mid;
                    Start=Mid+1;
                }
                else
                    End=Mid-1;
        }
            cout<<ans<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;ll n;///number of shops

ll binary(ll arr[],ll num){

    ll Start,End,Mid,i,ans;
    Start=0;
    End=n-1;
    if(num<arr[0])
        return 0;
//     if(num>=arr[n-1])
//        return n;

    while(Start<=End){
            Mid=(int)((Start + End)/2);

            if(num>=arr[Mid]){
                ans=Mid;
                Start=Mid+1;
            }
            else
                End=End-1;
    }

        return ans+1;

}

int main(){

    //ll n;///number of shops
    cin>>n;
    ll i,j,shop[100001];
    for(i=0;i<n;i++)
        cin>>shop[i];

    sort(shop,shop+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=0;i<q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];
    for(i=0;i<q;i++){
        s=binary(shop,coins[i]);

        res[i]=s;

    }
    for(i=0;i<q;i++)
        cout<<res[i]<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll n,i,j,shop[100001];

ll binary(ll arr[],ll num){

    ll Start,End,Mid,ans=0;
    Start=0;
    End=n;

    while(Start<=End){
            Mid=(int)((Start + End)/2);

            if(num>=arr[Mid]){
                ans=Mid;
                Start=Mid+1;
            }
            else
                End=End-1;
    }

        return ans;

}

int main(){

    //ll n;///number of shops
    cin>>n;

    for(i=1;i<=n;i++)
        cin>>shop[i];

    sort(shop+1,shop+1+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=1;i<=q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];
    for(i=1;i<=q;i++){
        s=binary(shop,coins[i]);

        res[i]=s;

    }
    for(i=1;i<=q;i++)
        cout<<res[i]<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll n,i,j,shop[100001];

int main(){

    //ll n;///number of shops
    cin>>n;

    for(i=1;i<=n;i++)
        cin>>shop[i];

    sort(shop+1,shop+1+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=1;i<=q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];

    for(i=1;i<=q;i++){

        ll Start,End,Mid,ans=0,num;
        Start=0;
        End=n;
        num=coins[i];
        while(Start<=End){
                Mid=(int)((Start + End)/2);

                if(num>=shop[Mid]){
                    ans=Mid;
                    Start=Mid+1;
                }
                else
                    End=End-1;
        }
            res[i]=ans;

    }
    for(i=1;i<=q;i++)
        cout<<res[i]<<endl;

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int num_of_shops;

     cin>>num_of_shops;

     int arr[num_of_shops];

    for(int i=0;i<num_of_shops;i++)
        cin>>arr[i];

    int dys_wnt_2_by;

    cin>>dys_wnt_2_by;

    long long a[dys_wnt_2_by],result[dys_wnt_2_by];

    for(int j=0;j<dys_wnt_2_by;j++)
    {
        cin>>a[j];
        result[j]=0;
        for(int i=0;i<num_of_shops;i++)
        {
            if(a[j]>=arr[i])
                result[j]++;

        }

    }

    for(int j=0;j<dys_wnt_2_by;j++)
        cout<<result[j]<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;ll n;///number of shops

ll binary(ll arr[],ll num){

    ll Start,End,Mid,i,j,s;
    Start=0;
    End=n-1;
     if(num<arr[0])
        return 0;
     else if(num>=arr[n-1])
        return n;
    else{
        while(Start<=End){
            Mid=(int)((Start + End)/2);
            if(num==arr[Mid]){
                break;
            }
            if(num>arr[Mid])
                Start=Mid+1;
            else
                End=End-1;
    }

    if (num>=arr[Mid])
         s=Mid;
    else
         s=Mid-1;

    for(j=s;j<End;j++){
                if(arr[j]==arr[j+1])
                    s=s+1;
                else
                    break;
            }

     return s+1;

    }

}

int main(){

    //ll n;///number of shops
    cin>>n;
    ll i,j,shop[100001];
    for(i=0;i<n;i++)
        cin>>shop[i];

    sort(shop,shop+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=0;i<q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];
    for(i=0;i<q;i++){
        s=binary(shop,coins[i]);

        res[i]=s;
    }

    for(i=0;i<q;i++)
        cout<<res[i]<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;ll n;///number of shops

ll binary(ll arr[],ll num){

    ll Start,End,Mid,i;
    Start=0;
    End=n-1;

    while(Start<=End){
            Mid=(int)((Start + End)/2);
            if(num==arr[Mid]){
                break;
            }
            if(num>arr[Mid])
                Start=Mid+1;
            else
                End=End-1;
    }
     if(num<arr[0])
        return 0;
    else if (num==arr[Mid] || num>arr[Mid])
         return Mid+1;
    else
        return Mid;

}

int main(){

    //ll n;///number of shops
    cin>>n;
    ll i,shop[100001];
    for(i=0;i<n;i++)
        cin>>shop[i];

    sort(shop,shop+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=0;i<q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];
    for(i=0;i<q;i++){
        s=binary(shop,coins[i]);
        res[i]=s;
    }
    for(i=0;i<q;i++)
        cout<<res[i]<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;ll n;///number of shops

ll binary(ll arr[],ll num){

    ll Start,End,Mid,i,j,s;
    Start=0;
    End=n-1;
     if(num<arr[0])
        return 0;
     else if(num>=arr[n-1])
        return n;
    else{
        while(Start<=End){
            Mid=(int)((Start + End)/2);
            if(num==arr[Mid]){
                break;
            }
            if(num>arr[Mid])
                Start=Mid+1;
            else
                End=Mid-1;
    }

    if (num>=arr[Mid])
         s=Mid;
    else
         s=Mid-1;

    for(j=s;j<End;j++){
                if(arr[j]==arr[j+1])
                    s=s+1;
                else
                    break;
            }
     return s+1;

    }
}

int main(){

    //ll n;///number of shops
    cin>>n;
    ll i,j,shop[100001];
    for(i=0;i<n;i++)
        cin>>shop[i];

    sort(shop,shop+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];

    ll s;///how many shops;
    int res[100001];
     for(i=0;i<q;i++){
        cin>>coins[i];
        cout<<binary(shop,coins[i])<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;ll n;///number of shops

ll binary(ll arr[],ll num){

    ll Start,End,Mid,i;
    Start=0;
    End=n-1;
    if(num<arr[0])
        return 0;

    while(Start<=End){
            Mid=(int)((Start + End)/2);
            if(num==arr[Mid]){
                break;
            }
            if(num>arr[Mid])
                Start=Mid+1;
            else
                End=End-1;
    }
        return Mid+1;
}

int main(){

    //ll n;///number of shops
    cin>>n;
    ll i,shop[100001];
    for(i=0;i<n;i++)
        cin>>shop[i];

    sort(shop,shop+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=0;i<q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];
    for(i=0;i<q;i++){
        s=binary(shop,coins[i]);
        res[i]=s;
    }
    for(i=0;i<q;i++)
        cout<<res[i]<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;ll n;///number of shops

ll binary(ll arr[],ll num){

    ll Start,End,Mid,i;
    Start=0;
    End=n-1;

    while(Start<=End){
            Mid=(int)((Start + End)/2);
            if(num==arr[Mid]){
                break;
            }
            if(num>arr[Mid])
                Start=Mid+1;
            else
                End=End-1;
    }
     if(num<arr[0])
        return -1;
    else if (num>=arr[Mid])
         return Mid;
    else
        return Mid-1;

}

int main(){

    //ll n;///number of shops
    cin>>n;
    ll i,j,shop[100001];
    for(i=0;i<n;i++)
        cin>>shop[i];

    sort(shop,shop+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=0;i<q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];
    for(i=0;i<q;i++){
        s=binary(shop,coins[i]);
        if(s==-1)
            res[i]=0;
        else{
            for(j=s;j<n;j++){
                if(shop[j]==shop[j+1])
                    s=s+1;
                else
                    break;
            }
            res[i]=s+1;
        }
    }
    for(i=0;i<q;i++)
        cout<<res[i]<<endl;

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int num_of_shops;

     cin>>num_of_shops;

     int arr[num_of_shops];

    for(int i=0;i<num_of_shops;i++)
        cin>>arr[i];

    int dys_wnt_2_by;

    cin>>dys_wnt_2_by;

    long long a[dys_wnt_2_by];
    int result[dys_wnt_2_by];

    for(int j=0;j<dys_wnt_2_by;j++)
    {
        cin>>a[j];
        result[j]=0;
        for(int i=0;i<num_of_shops;i++)
        {
            if(a[j]>=arr[i])
                result[j]++;

        }
        cout<<result[j]<<endl;

    }

//    for(int j=0;j<dys_wnt_2_by;j++)
//        cout<<result[j]<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;ll n;///number of shops

ll binary(ll arr[],ll num){

    ll Start,End,Mid,i,j,s;
    Start=0;
    End=n-1;
     if(num<arr[0])
        return 0;
     else if(num>=arr[n-1])
        return n;
    else{
        while(Start<=End){
            Mid=(int)((Start + End)/2);
            if(num==arr[Mid]){
                break;
            }
            if(num>arr[Mid])
                Start=Mid+1;
            else
                End=Mid-1;
    }

    if (num>=arr[Mid])
         s=Mid;
    else
         s=Mid-1;

    for(j=s;j<End;j++){
                if(arr[j]==arr[j+1])
                    s=s+1;
                else
                    break;
            }

     return s+1;

    }

}

int main(){

    //ll n;///number of shops
    cin>>n;
    ll i,j,shop[100001];
    for(i=0;i<n;i++)
        cin>>shop[i];

    sort(shop,shop+n);

    ll q;///mumber of days
    cin>>q;
    ll coins[100001];
    for(i=0;i<q;i++)
        cin>>coins[i];
    ll s;///how many shops;
    int res[100001];
    for(i=0;i<q;i++){
        s=binary(shop,coins[i]);

        res[i]=s;
    }

    for(i=0;i<q;i++)
        cout<<res[i]<<endl;

    return 0;
}


#include <bits/stdc++.h>
#include <string>

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    //ostringstream ss;
    int n, q, i, j, x;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
        cin>>a[i];

    //int end = (n-1);
    cin>>q;
    sort(a, a+n);
    int b[q] = {0};
    for(i=0; i<q; i++)
    {
        int ans=0, start=0, end = n-1, mid;
        cin>>x;
        while(start != end)
        {
            mid = (start + end)/2;
            if(x > a[mid])
                start = mid+1;

            else
                end = mid - 1;

            if(x == a[mid])
            {
                b[i] = mid+1;
                break;
            }
            if(x < a[start])
            {
                b[i] = start;
                break;
            }
            if(start == end && a[start] == x)
            {
                b[i] = start + 1;
                break;
            }
            if(x > a[end])
            {
                b[i] = end + 1;
                break;
            }
        }
    }
    for(i=0; i<q; i++)
        cout<<b[i]<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);

    int n, q, i, ans=0, x;

    scanf("%d", &n);
    int a[100005] = {0};

    for(i=1; i<=n; i++)
    {
        scanf("%d", &x);
        a[x]++;
    }
    for(i=1; i<=100005; i++)
        a[i] += a[i-1];

    scanf("%d", &q);
    int b[q+2];
    for(i=1; i<=q; i++)
    {
        cin>>x;
        b[i] = a[x];
    }
    for(i=1; i<=q; i++)
        printf("%d\n", b[i]);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);

    int n, q, i, ans=0, x;

    scanf("%d", &n);
    int a[100005] = {0};

    for(i=1; i<=n; i++)
    {
        scanf("%d", &x);
        a[x]++;
    }
    for(i=1; i<=100005; i++)
        a[i] += a[i-1];

    scanf("%d", &q);
    for(i=1; i<=q; i++)
    {
        scanf("%d", &x);
        if(x > 100004)
            printf("%d\n", a[100004]);
        else
            printf("%d\n", a[x]);
    }
    return 0;
}


#include <bits/stdc++.h>
#include <string>

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    //ostringstream ss;
    int n, q, i, j, x;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
        cin>>a[i];

    //int end = (n-1);
    cin>>q;
    sort(a, a+n);
    int b[q] = {0};
    for(i=0; i<q; i++)
    {
        int start=0, end = n-1, mid;
        cin>>x;
        while(start != end)
        {
            mid = (start + end)/2;

            if(x == a[mid])
            {
                b[i] = mid+1;
                break;
            }
            if(x > a[end])
            {
                b[i] = end + 1;
                break;
            }

            if(x > a[mid])
                start = mid+1;

            else
                end = mid - 1;

            if(start == end && a[start] == x)
            {
                b[i] = start + 1;
                break;
            }
            if(start == end && x < a[n-1])
            {
                if(start == (n-1))
                {
                    b[i] = start;
                    break;
                }
                b[i] = start + 1;
                break;
            }
            if(x < a[start])
            {
                b[i] = start;
                break;
            }
        }
    }
    for(i=0; i<q; i++)
        cout<<b[i]<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);

    int n, q, i, ans=0, x;

    cin>>n;
    int a[100005] = {0};

    for(i=1; i<=n; i++)
    {
        scanf("%d", &x);
        a[x]++;
    }
    for(i=1; i<=100005; i++)
        a[i] += a[i-1];

    scanf("%d", &q);
    int b[q+2];
    for(i=1; i<=q; i++)
    {
        cin>>x;
        b[i] = a[x];
    }
    for(i=1; i<=q; i++)
        printf("%d\n", b[i]);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);

    int n, q, i, ans=0, x;

    scanf("%d", &n);
    int a[100005] = {0};

    for(i=1; i<=n; i++)
    {
        scanf("%d", &x);
        a[x]++;
    }
    for(i=1; i<=100005; i++)
        a[i] += a[i-1];

    scanf("%d", &q);
    int b[q+2];
    for(i=1; i<=q; i++)
    {
        scanf("%d", &x);
        b[i] = a[x];
    }
    for(i=1; i<=q; i++)
        printf("%d\n", b[i]);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);

    int n, q, i, ans=0, x;

    cin>>n;
    int a[100005] = {0};

    for(i=1; i<=n; i++)
    {
        scanf("%d", &x);
        a[x]++;
    }
    for(i=1; i<=100005; i++)
        a[i] += a[i-1];

    scanf("%d", &q);

    for(i=1; i<=q; i++)
    {
        cin>>x;
        printf("%d\n", a[x]);
    }

    return 0;
}


#include <bits/stdc++.h>
#include <string>

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    //ostringstream ss;
    int n, q, i, j, x;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
        cin>>a[i];

    cin>>q;
    sort(a, a+n);
    int b[q] = {0};
    for(i=0; i<q; i++)
    {
        int start=0, end = n-1, mid;
        cin>>x;
        if(x > a[end])
        {
            b[i] = end + 1;
            continue;
        }
        if(x < a[start])
        {
            b[i] = start;
            continue;
        }
        while(start != end)
        {
            mid = (start + end)/2;

            if(x == a[mid])
            {
                b[i] = mid+1;
                break;
            }

            if(x > a[mid])
                start = mid+1;

            else
                end = mid - 1;

            if(end - start == 1 && x < a[end] && x > a[start])
            {
                b[i] = start+1;
                break;
            }
            if(start == end && a[start] == x)
            {
                b[i] = start + 1;
                break;
            }
            if(start == end && x < a[n-1])
            {
                if(start == (n-1))
                {
                    b[i] = start;
                    break;
                }
                b[i] = start + 1;
                break;
            }
        }
    }

    for(i=0; i<q; i++)
        cout<<b[i]<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <string>

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    //ostringstream ss;
    int n, q, i, j, x;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
        cin>>a[i];

    cin>>q;
    sort(a, a+n);
    int b[q] = {0};
    for(i=0; i<q; i++)
    {
        //cout<<" i "<<i;
        int start=0, end = n-1, mid;
        cin>>x;
        if(x > a[end])
        {
            b[i] = end + 1;
            continue;
        }
        if(x < a[start])
        {
            b[i] = start;
            continue;
        }
        while(start != end)
        {
            mid = (start + end)/2;

            if(x == a[mid])
            {
                b[i] = mid+1;
                break;
            }

            if(x > a[mid])
                start = mid+1;

            else
                end = mid - 1;

            if(end - start == 1 && x < a[end] && x > a[start])
            {
                b[i] = start+1;
                break;
            }
            if(start == end && a[start] == x)
            {
                b[i] = start + 1;
                break;
            }
            if(x < a[start])
            {
                b[i] = start;
                break;
            }
            if(start == end && x < a[n-1])
            {
                if(start == (n-1))
                {
                    b[i] = start;
                    break;
                }
                b[i] = start + 1;
                break;
            }
        }
    }

    for(i=0; i<q; i++)
        cout<<b[i]<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <string>

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    //ostringstream ss;
    int n, q, i, j, x;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
        cin>>a[i];

    cin>>q;
    sort(a, a+n);
    int b[q];
    for(i=0; i<q; i++)
    {
        int ans=0;
        cin>>x;
        for(j=0; j<n; j++)
        {
            if(x >= a[j])
            {
                ++ans;
                b[i] = ans;
            }
            else
            {
                b[i] = ans;
                break;
            }
        }
    }
    for(i=0; i<q; i++)
        cout<<b[i]<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <string>

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    //ostringstream ss;
    int n, q, i, j, x;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
        cin>>a[i];

    //int end = (n-1);
    cin>>q;
    sort(a, a+n);
    int b[q] = {0};
    for(i=0; i<q; i++)
    {
        int start=0, end = n-1, mid;
        cin>>x;
        if(x > a[end])
        {
            b[i] = end + 1;
            continue;
        }
        if(x < a[start])
        {
            b[i] = start;
            continue;
        }
        while(start != end)
        {
            mid = (start + end)/2;

            if(x == a[mid])
            {
                b[i] = mid+1;
                break;
            }

            if(x > a[mid])
                start = mid+1;

            else
                end = mid - 1;

            if(start == end && a[start] == x)
            {
                b[i] = start + 1;
                break;
            }
            if(start == end && x < a[n-1])
            {
                if(start == (n-1))
                {
                    b[i] = start;
                    break;
                }
                b[i] = start + 1;
                break;
            }
        }
    }
    for(i=0; i<q; i++)
        cout<<b[i]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int q,n,i,x[100005],m;
main()
{
    scanf("%d",&n);
    for (i=1;i<=n;i++)
        scanf("%d",&x[i]);
    sort(x+1,x+1+n);
    scanf("%d",&q);
    while (q--)
    {
        scanf("%d",&m);
        int l=1,r=n;
        int ans=0;
        if (m<x[1])
            {
                printf("0\n");
                continue;
            }
        if (m>=x[n])
            {
                printf("%d\n",n);
                continue;
            }
        while (l<=r)
            {
                if (m>=(x[l]+x[r])/2)
                    l=(l+r)/2;
                if (m<=(x[l]+x[r])/2)
                    r=(l+r)/2;
                if (m==x[l])
                    {
                        ans=l;
                        break;
                    }
                if (m==x[r])
                    {
                        ans=r;
                        break;
                    }
            }
        printf("%d\n",ans);
    }
}


#include<bits/stdc++.h>
using namespace std;
int q,n,i,x[100005];
main()
{
    scanf("%d",&n);
    for (i=1;i<=n;i++)
        scanf("%d",&x[i]);
    sort(x+1,x+1+n);
    scanf("%d",&q);
    while (q--)
    {
        int m;
        scanf("%d",&m);
        int l=1;
        int r=n;
        if (m<x[1])
            {
                printf("0\n");
                continue;
            }
        if (m>=x[n])
            {
                printf("%d\n",n);
                continue;
            }
        while (l<r)
            {
                if (m>=(x[(l+r)/2]))
                    l=(l+r)/2;
                if (m<=(x[(l+r)/2]))
                    r=(l+r)/2;
                if (m>=x[l]&&m<x[l+1])
                    {
                    	printf("%d\n",l);
            	break;
                    }
                if (m>=x[r])
                    {
                    	int j=r;
                    	while (m>=x[j])
                    		j++;
                        printf("%d\n",j-1);
            	break;
                    }
            }
    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[1000000];//the number of coins Vasily can spent on ith day*/
int meg,temp;
int counter;
int middle;//to stoixeio sigkrisis
bool con=false;
int mik=1000000;
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    cin>>x[i];

	       if(mik > x[i])
	            mik = x[i];
	}

	cin>>q;
	for(int i =0;i<q;i++)
	{
	       cin>>m[i];
	}

	sort(x+0, x+n);//ta3inomisi pinaka sort apo 0 mexri N

    for(int i=0; i<n; ++i)
        cout<<x[i]<<" ";
    cout<<endl;

	for(int i=0;i<q;i++)
	{
	    if(m[i] < mik)
	    {
	        cout<<0<<endl;
	        continue;
	    }

		int Tbeg = 0, Tend = n-1;

		while(Tbeg < Tend)
		{
			middle = (Tbeg + Tend + 1) / 2;

			if(x[middle] <= m[i])
				Tbeg = middle;
			else
				Tend = middle - 1;
		}

		cout<<Tbeg+1<<endl;
	}

	return 0;
}


#include<iostream>
using namespace std;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[1000000];//the number of coins Vasily can spent on ith day*/
int meg,temp;
int counter;
int middle;//to stoixeio sigkrisis
bool con=false;
int mik=1000000;
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];

	for(int p=1;p<=n-1;p++)
	{
		for(int j=n-1;j>=p;j--)
		{
			if(x[j-1]>x[j])
			{
				temp=x[j-1];
				x[j-1]=x[j];
				x[j]=temp;
			}
		}
	}

	//process-output//
	for(int i=0;i<n;i++)
	{
		if(x[i]>meg)
			meg=x[i];
		if(x[i]<mik)
			mik=x[i];
	}
	for(int i=0;i<q;i++)
	{
		if(m[i]>=meg)
			cout<<n<<endl;
		if(m[i]<mik)
			cout<<"0"<<endl	;
		if(m[i]==mik)
			cout<<"1"<<endl;
		if(m[i]<meg&&m[i]>mik)
			con=true;
		if(con==true)
		{
			counter=0;
			con=false;

			/*for(int j=0;j<n;j++)
			{
				if(m[i]>=x[j])
					counter++;
			}
			cout<<counter<<endl;*/
			middle=n/2;
			if(m[i]>=x[middle])
			{
				counter=n/2;
				for(int j=middle;j<n;j++)
				{
					if(m[i]>=x[j])
					counter++;
				}
				cout<<counter<<endl;
			}
			else
			{

				for(int j=0;j<=middle;j++)
				{
					if(m[i]>=x[j])
						counter++;
				}
				cout<<counter<<endl;
			}

		}
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[1000000];//the number of coins Vasily can spent on ith day*/
int anti=1;//mia fora antimetathesi
int meg,temp;
int counter;
int middle;//to stoixeio sigkrisis
bool con=false;
int mik=1000000;
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//process-output//
	for(int i=0;i<n;i++)
	{
		if(x[i]>meg)
			meg=x[i];
		if(x[i]<mik)
			mik=x[i];
	}
	for(int i=0;i<q;i++)
	{
		if(m[i]>=meg)
			cout<<n<<endl;
		if(m[i]<mik)
			cout<<"0"<<endl	;
		if(m[i]==mik)
			cout<<"1"<<endl;
		if(m[i]<meg&&m[i]>mik)
			con=true;
		if(con==true)
		{
			counter=0;
			con=false;
			if(anti==1)//the beginning of antimetathesi
			{
				anti=0;
				for(int p=1;p<=n-1;p++)
				{
					for(int j=n-1;j>=p;j--)
					{
						if(x[j-1]>x[j])
						{
							temp=x[j-1];
							x[j-1]=x[j];
							x[j]=temp;
						}
					}
				}
			}//the ending of antimetathesi
			/*for(int j=0;j<n;j++)
			{
				if(m[i]>=x[j])
					counter++;
			}
			cout<<counter<<endl;*/
			middle=n/2;
			if(m[i]>=x[middle])
			{
				counter=n/2;
				for(int j=middle;j<n;j++)
				{
					if(m[i]>=x[j])
					counter++;
				}
				cout<<counter<<endl;
			}
			else
			{

				for(int j=0;j<=middle;j++)
				{
					if(m[i]>=x[j])
						counter++;
				}
				cout<<counter<<endl;
			}

		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[1000000];//the number of coins Vasily can spent on ith day*/
int meg,temp;
int counter;
int middle;//to stoixeio sigkrisis
bool con=false;
int mik=1000000;
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    cin>>x[i];

	       if(mik > x[i])
	            mik = x[i];
	}

	cin>>q;
	for(int i =0;i<q;i++)
	{
	       cin>>m[i];
	}

	sort(x+0, x+n);//ta3inomisi pinaka sort apo 0 mexri N

	for(int i=0;i<q;i++)
	{
	    if(m[i] < mik)
	    {
	        cout<<0<<endl;
	        continue;
	    }

		int Tbeg = 0, Tend = n-1;

		while(Tbeg < Tend)
		{
			middle = (Tbeg + Tend + 1) / 2;

			if(x[middle] <= m[i])
				Tbeg = middle;
			else
				Tend = middle - 1;
		}

		cout<<Tbeg+1<<endl;
	}

	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[1000000];//the number of coins Vasily can spent on ith day*/
int anti=1;//mia fora antimetathesi
int meg,temp;
int counter;
int middle;//to stoixeio sigkrisis
bool con=false;
int mik=1000000;
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//process-output//
	for(int i=0;i<n;i++)
	{
		if(x[i]>meg)
			meg=x[i];
		if(x[i]<mik)
			mik=x[i];
	}
	for(int i=0;i<q;i++)
	{
		if(m[i]>=meg)
			cout<<n<<endl;
		if(m[i]<mik)
			cout<<"0"<<endl	;
		if(m[i]==mik)
			cout<<"1"<<endl;
		if(m[i]<meg&&m[i]>mik)
			con=true;
		if(con==true)
		{
			counter=0;
			con=false;
			if(anti==1)//the beginning of antimetathesi
			{
				anti=0;
				for(int p=1;p<=n-1;p++)
				{
					for(int j=n-1;j>=p;j--)
					{
						if(x[j-1]>x[j])
						{
							temp=x[j-1];
							x[j-1]=x[j];
							x[j]=temp;
						}
					}
				}
			}//the ending of antimetathesi
			/*for(int j=0;j<n;j++)
			{
				if(m[i]>=x[j])
					counter++;
			}
			cout<<counter<<endl;*/
			middle=n/2;
			if(m[i]>=m[middle])
			{
				counter=n/2;
				for(int j=middle;j<n;j++)
				{
					if(m[i]>=x[j])
					counter++;
				}
				cout<<counter<<endl;
			}
			else
			{
				for(int j=0;j<=middle;j++)
				{
					if(m[i]>=x[j])
						counter++;
				}
				cout<<counter<<endl;
			}

		}
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int counter;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[10000000];//the number of coins Vasily can spent on ith day*/
int e[1000000];
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//output//
	for(int i=0;i<q;i++)
	{
		for(int j=0;j<n;j++)
			if(m[i]>=x[j])
				e[i]++;

		cout<<e[i]<<endl;
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int counter;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int   m[100000000];//the number of coins Vasily can spent on ith day*/
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//output//
	for(int i=0;i<q;i++)
	{
		counter=0;
		for(int j=0;j<n;j++)
			if(m[i]>=x[j])
				counter++;
		cout<<counter<<endl;
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int counter;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[100000000];//the number of coins Vasily can spent on ith day*/
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//output//
	for(int i=0;i<q;i++)
	{
		counter=0;
		for(int j=0;j<n;j++)
			if(m[i]>=x[j])
				counter++;
		cout<<counter<<endl;
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[1000000];//the number of coins Vasily can spent on ith day*/
int anti=1;//mia fora antimetathesi
int meg,temp;
int counter;
bool con=false;
int mik=1000000;
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//process-output//
	for(int i=0;i<n;i++)
	{
		if(x[i]>meg)
			meg=x[i];
		if(x[i]<mik)
			mik=x[i];
	}
	for(int i=0;i<q;i++)
	{
		if(m[i]>=meg)
			cout<<n<<endl;
		if(m[i]<mik)
			cout<<"0"<<endl	;
		if(m[i]==mik)
			cout<<"1"<<endl;
		if(m[i]<meg&&m[i]>mik)
			con=true;
		if(con==true)
		{
			counter=0;
			con=false;
			if(anti==1)
			{
				anti=0;
				for(int p=1;p<=n-1;p++)
				{
					for(int j=n-1;j>=p;j--)
					{
						if(x[j-1]>x[j])
						{
							temp=x[j-1];
							x[j-1]=x[j];
							x[j]=temp;
						}
					}
				}
			}
			for(int j=0;j<n;j++)
			{
				if(m[i]>=x[j])
					counter++;
			}
			cout<<counter<<endl;
		}
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int counter;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[100000000];//the number of coins Vasily can spent on ith day*/
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//output//

	for(int i=0;i<q;i++)
	{
		counter=0;
		for(int j=0;j<n;j++)
			if(m[i]>=x[j])
				counter++;
		cout<<counter<<endl;
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int counter;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[100000000];//the number of coins Vasily can spent on ith day*/
int e[1000000];
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//output//
	for(int i=0;i<q;i++)
	{
		for(int j=0;j<n;j++)
			if(m[i]>=x[j])
				e[i]++;

		cout<<e[i]<<endl;
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int counter;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[10000];//the number of coins Vasily can spent on ith day*/
int e[10000];
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//output//
	for(int i=0;i<q;i++)
	{
		for(int j=0;j<n;j++)
			if(m[i]>=x[j])
				e[i]++;

		cout<<e[i]<<endl;
	}
	return 0;
}


//http://codeforces.com/contest/706/problem/B
#include<iostream>
using namespace std;
int counter;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int   m[100000];//the number of coins Vasily can spent on ith day*/
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];
	//output//
	for(int i=0;i<q;i++)
	{
		counter=0;
		for(int j=0;j<n;j++)
			if(m[i]>=x[j])
				counter++;
		cout<<counter<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[1000000];//the number of coins Vasily can spent on ith day*/
int meg,temp;
int counter;
int middle;//to stoixeio sigkrisis
bool con=false;
int mik=1000000;
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i];
	cin>>q;
	for(int i =0;i<q;i++)
		cin>>m[i];

	sort(x+0, x+n);//ta3inomisi pinaka sort apo 0 mexri N

	for(int i=0;i<q;i++)
	{
		int Tbeg = 0, Tend = n-1;

		while(Tbeg < Tend)
		{
			middle = (Tbeg + Tend) / 2;

			if(m[i] > x[middle])
				Tbeg = middle + 1;
			else
				Tend = middle;
		}

		cout<<Tend+1<<endl;
	}

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n;//number of shops;
int x[1000000];//prices of the bottles of the drink in the i-th shop.
int q;//the number of days Vasily plans to buy his drink
int  m[1000000];//the number of coins Vasily can spent on ith day*/
int meg,temp;
int counter;
int middle;//to stoixeio sigkrisis
bool con=false;
int mik=1000000;
int main()
{
	//input//
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    cin>>x[i];

	       if(mik > x[i])
	            mik = x[i];
	}

	cin>>q;
	for(int i =0;i<q;i++)
	{
	       cin>>m[i];
	}

	sort(x+0, x+n);//ta3inomisi pinaka sort apo 0 mexri N

	for(int i=0;i<q;i++)
	{
	    if(m[i] < mik)
	    {
	        cout<<0<<endl;
	        continue;
	    }

		int Tbeg = 0, Tend = n-1;

		while(Tbeg < Tend)
		{
			middle = (Tbeg + Tend) / 2;

			if(m[i] > x[middle])
				Tbeg = middle + 1;
			else
				Tend = middle;
		}

		cout<<Tend+1<<endl;
	}

	return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
int n;
int q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int sorted[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
};
struct heap h;
int binarySearch2(int x,int l, int r)
{

    if (r >= l) {

        int mid = l + (r - l) / 2;

        // If the element is present at the middle

        // itself

        if (h.sorted[mid] == x)

            return mid;

        // If element is smaller than mid, then

        // it can only be present in left subarray

        if (h.sorted[mid] > x)

            return binarySearch2(x, l, mid - 1);

        // Else the element can only be present

        // in right subarray

        return binarySearch2(x,mid + 1, r);

    }

    // We reach here when element is not

    // present in array

    return -1;
}
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.sorted[mid] < e){
            init = mid  +1;
        }
        else if (h.sorted[mid]> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binarySearch2(query,0,n-1);
        if(h.sorted[result] >= query){
            cout << result + 1 << endl;
        }
        else
                cout << 0 <<endl;
    }
    return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
int sorted[MAX_SIZE];
int n;
long long q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
    int get(int e){
        return sorted[e];
    }
};
struct heap h;
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.get(mid) < e){
            init = mid  +1;
        }
        else if (h.get(mid)> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binary_search(query,0,n-1);
        if(h.get(result) >= query){
            cout << result + 1 << endl;
        }
        else{
            if(query>h.get(0))
                cout << h.sizeH <<endl;
            else
                cout << 0 <<endl;

        }
    }
    return 0;
}


#include <iostream>
#define MAXSIZE 1000002
using namespace std;

int cost[MAXSIZE];
int aux[MAXSIZE];
void merge(int init,int mid, int fin){
	int i = init, k = init , j =mid+1;
	while(i <= mid && j <= fin){
		if(cost[i] < cost[j])
			aux[k++] = cost[i++];
		else
			aux[k++] = cost[j++];
	}
	while(i <= mid)
		aux[k++] = cost[i++];
	while(j <= fin)
		aux[k++] = cost[j++];
	for(int p = init ; p <= fin ;++p)
		cost[p] = aux[p];
}
void mergeSort(int init,int fin){
	int mid = (init + fin)/2.0;
	if(init < fin){
		mergeSort(init,mid);
		mergeSort(mid+1,fin);
		merge(init,mid,fin);
	}
}
void search(int q,int l,int r){
	int paid;
	while(l<=r){
		int mid = l+r/2.0;
		if(cost[mid]<q){
			l = mid+1;
			paid = mid-1;
		}
		else if(cost[mid]>q){
			r = mid;
		}
		else{
			printf("%d\n",mid);
			break;
		}
	}
	printf("%d\n",paid);
}
int main (){
	int n,m,q;
	scanf("%d",&n);
	for(int i = 0 ; i<n; i++){
		scanf("%d",&cost[i]);
	}
	mergeSort(0,n-1);
	scanf("%d",&m);
	for(int i = 0 ; i<m; i++){
		scanf("%d",&q);
	if(q<cost[0])
		printf("0\n");
	else if(q==cost[0])
		printf("1\n");
	else if(q>=cost[n-1])
		printf("%d\n",n);
	else
		search(q,0,n);
	}
	return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
int n;
int q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int sorted[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
    int get(int e){
        return sorted[e];
    }
};
struct heap h;
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.get(mid) < e){
            init = mid  +1;
        }
        else if (h.get(mid)> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binary_search(query,0,n-1);
        if(h.get(result) >= query){
            cout << result + 1 << endl;
        }
        else{
            if(query>h.get(0))
                cout << h.sizeH <<endl;
            else
                cout << 0 <<endl;

        }
    }
    return 0;
}