#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf LONG_LONG_MAX
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    ll e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e2< b.e2;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

data a[105];
ll dp[3][(1<<20)+3];
int fnd;
int main()
{
    int t,tc=1;
	sf3(n,m,k);
	int z=k;
	for(int i=1;i<=n;i++){
		ll x,y;
		sfl2(x,y);
		sf1(k);
		int fnd=0;
		for(int i=1;i<=k;i++){
			int p;
			sf1(p);
			p--;
			fnd=fnd | (1<<p);
		}
		//printf("%d\n",fnd);
		a[i]=data(x,y,fnd);
	}
	sort(a+1,a+n+1);
	for(int i=n+1;i>=1;i--){
		for(int j=0;j<(1<<m);j++){
			if(j==(1<<m)-1) dp[i%2][j]=a[i-1].e2*z;
			else if(i==n+1){
				dp[i%2][j]=inf;
			}
			else{
				dp[i%2][j]=dp[(i+1)%2][j];
				dp[i%2][j]=min(dp[i%2][j],dp[(i+1)%2][ j|a[i].e3 ]+a[i].e1);
			}
		}
	}
	if(dp[1][0]==inf) dp[1][0]=-1;
	pf("%lld\n",dp[1][0]);
    return 0;
}

/*

*/


#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf 9999999999999ll
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    int e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e2< b.e2;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

data a[105];
ll dp[3][(1<<20)+3];
int fnd;
int main()
{
    int t,tc=1;
	sf3(n,m,k);
	int z=k;
	for(int i=1;i<=n;i++){
		int x,y;
		sf3(x,y,k);
		int fnd=0;
		for(int i=1;i<=k;i++){
			int p;
			sf1(p);
			p--;
			fnd=fnd | (1<<p);
		}
		//printf("%d\n",fnd);
		a[i]=data(x,y,fnd);
	}
	sort(a+1,a+n+1);
	for(int i=n+1;i>=1;i--){
		for(int j=0;j<(1<<m);j++){
			if(j==(1<<m)-1) dp[i%2][j]=a[i-1].e2*z;
			else if(i==n+1){
				dp[i%2][j]=inf;
			}
			else{
				dp[i%2][j]=dp[(i+1)%2][j];
				dp[i%2][j]=min(dp[i%2][j],dp[(i+1)%2][ j|a[i].e3 ]+a[i].e1);
			}
		}
	}
	if(dp[1][0]==inf) dp[1][0]=-1;
	pf("%lld\n",dp[1][0]);
    return 0;
}

/*

*/


#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf 3000000000000000000
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    ll e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e2< b.e2;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

data a[105];
ll dp[3][(1<<20)+3];
int fnd;
int main()
{
    int t,tc=1;
	sf3(n,m,k);
	int z=k;
	for(int i=1;i<=n;i++){
		ll x,y;
		sfl2(x,y);
		sf1(k);
		int fnd=0;
		for(int i=1;i<=k;i++){
			int p;
			sf1(p);
			p--;
			fnd=fnd | (1<<p);
		}
		//printf("%d\n",fnd);
		a[i]=data(x,y,fnd);
	}
	sort(a+1,a+n+1);
	for(int i=n+1;i>=1;i--){
		for(int j=0;j<(1<<m);j++){
			if(j==(1<<m)-1) dp[i%2][j]=a[i-1].e2*z;
			else if(i==n+1){
				dp[i%2][j]=inf;
			}
			else{
				dp[i%2][j]=dp[(i+1)%2][j];
				dp[i%2][j]=min(dp[i%2][j],dp[(i+1)%2][ j|a[i].e3 ]+a[i].e1);
			}
		}
	}
	if(dp[1][0]==inf) dp[1][0]=-1;
	pf("%lld\n",dp[1][0]);
    return 0;
}

/*

*/


#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf 1000000000000000000
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    ll e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e2< b.e2;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

data a[105];
ll dp[3][(1<<20)+3];
int fnd;
int main()
{
    int t,tc=1;
	sf3(n,m,k);
	int z=k;
	for(int i=1;i<=n;i++){
		ll x,y;
		sfl2(x,y);
		sf1(k);
		int fnd=0;
		for(int i=1;i<=k;i++){
			int p;
			sf1(p);
			p--;
			fnd=fnd | (1<<p);
		}
		//printf("%d\n",fnd);
		a[i]=data(x,y,fnd);
	}
	sort(a+1,a+n+1);
	for(int i=n+1;i>=1;i--){
		for(int j=0;j<(1<<m);j++){
			if(j==(1<<m)-1) dp[i%2][j]=a[i-1].e2*z;
			else if(i==n+1){
				dp[i%2][j]=inf;
			}
			else{
				dp[i%2][j]=dp[(i+1)%2][j];
				dp[i%2][j]=min(dp[i%2][j],dp[(i+1)%2][ j|a[i].e3 ]+a[i].e1);
			}
		}
	}
	if(dp[1][0]==inf) dp[1][0]=-1;
	pf("%lld\n",dp[1][0]);
    return 0;
}

/*

*/


#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf 99999999
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    int e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e1> b.e1;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

int a[20];
vector <int> ve[20],cost[20];
ll dp[(1<<18)+5];

ll sol(int mask){
	//pf("%d %d %d\n",m,mask,__builtin_popcount(mask));
	if(__builtin_popcount(mask)==m){
		return 0;
	}
	ll &ret=dp[mask];
	if(ret!=-1) return ret;
	ret=0;
	//bug;
	for(int i=0;i<n;i++){
		if((mask & (1<<i))==0)
		{
			ll cst=a[i];
			int z=cost[i].size();
			//pf("ff %d %lld %d\n",i,cst,z);
			for(int j=0;j<z;j++){
				int k=ve[i][j];
				int c=cost[i][j];
				//pf("d %d %d\n",k,c);
				int cc=(mask & (1<<k));
				//pf("%d\n",cc);
				if((mask & (1<<k))>0)
				{
					//bug;
					cst+=c;
				}
			}
			ret=max(ret,cst+sol((mask | (1<<i))));
		}
	}
	return ret;
}

int main()
{
    int t,tc=1;
	sf3(n,m,k);
	for(int i=0;i<n;i++){
		sf1(a[i]);
	}
	for(int i=1;i<=k;i++){
		int u,v,w;
		sf3(u,v,w);
		u--;
		v--;
		ve[v].pb(u);
		cost[v].pb(w);
	}
	//~ for(int i=0;i<n;i++){
		//~ pf("%d %d\n",i,ve[i].size());
	//~ }
	mem(dp,-1);
	ll ans=sol(0);
	pfl(ans);

    return 0;
}

/*

*/


#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf 9999999999999ll
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    ll e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e2< b.e2;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

data a[105];
ll dp[3][(1<<20)+3];
int fnd;
int main()
{
    int t,tc=1;
	sf3(n,m,k);
	int z=k;
	for(int i=1;i<=n;i++){
		ll x,y;
		sfl2(x,y);
		sf1(k);
		int fnd=0;
		for(int i=1;i<=k;i++){
			int p;
			sf1(p);
			p--;
			fnd=fnd | (1<<p);
		}
		//printf("%d\n",fnd);
		a[i]=data(x,y,fnd);
	}
	sort(a+1,a+n+1);
	for(int i=n+1;i>=1;i--){
		for(int j=0;j<(1<<m);j++){
			if(j==(1<<m)-1) dp[i%2][j]=a[i-1].e2*z;
			else if(i==n+1){
				dp[i%2][j]=inf;
			}
			else{
				dp[i%2][j]=dp[(i+1)%2][j];
				dp[i%2][j]=min(dp[i%2][j],dp[(i+1)%2][ j|a[i].e3 ]+a[i].e1);
			}
		}
	}
	if(dp[1][0]==inf) dp[1][0]=-1;
	pf("%lld\n",dp[1][0]);
    return 0;
}

/*

*/


#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf 99999999999999999ll
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    ll e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e2< b.e2;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

data a[105];
ll dp[3][(1<<20)+3];
int fnd;
int main()
{
    int t,tc=1;
	sf3(n,m,k);
	int z=k;
	for(int i=1;i<=n;i++){
		ll x,y;
		sfl2(x,y);
		sf1(k);
		int fnd=0;
		for(int i=1;i<=k;i++){
			int p;
			sf1(p);
			p--;
			fnd=fnd | (1<<p);
		}
		//printf("%d\n",fnd);
		a[i]=data(x,y,fnd);
	}
	sort(a+1,a+n+1);
	for(int i=n+1;i>=1;i--){
		for(int j=0;j<(1<<m);j++){
			if(j==(1<<m)-1) dp[i%2][j]=a[i-1].e2*z;
			else if(i==n+1){
				dp[i%2][j]=inf;
			}
			else{
				dp[i%2][j]=dp[(i+1)%2][j];
				dp[i%2][j]=min(dp[i%2][j],dp[(i+1)%2][ j|a[i].e3 ]+a[i].e1);
			}
		}
	}
	if(dp[1][0]==inf) dp[1][0]=-1;
	pf("%lld\n",dp[1][0]);
    return 0;
}

/*

*/


#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf LONG_MAX
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    ll e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e2< b.e2;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

data a[105];
ll dp[3][(1<<20)+3];
int fnd;
int main()
{
    int t,tc=1;
	sf3(n,m,k);
	int z=k;
	for(int i=1;i<=n;i++){
		ll x,y;
		sfl2(x,y);
		sf1(k);
		int fnd=0;
		for(int i=1;i<=k;i++){
			int p;
			sf1(p);
			p--;
			fnd=fnd | (1<<p);
		}
		//printf("%d\n",fnd);
		a[i]=data(x,y,fnd);
	}
	sort(a+1,a+n+1);
	for(int i=n+1;i>=1;i--){
		for(int j=0;j<(1<<m);j++){
			if(j==(1<<m)-1) dp[i%2][j]=a[i-1].e2*z;
			else if(i==n+1){
				dp[i%2][j]=inf;
			}
			else{
				dp[i%2][j]=dp[(i+1)%2][j];
				dp[i%2][j]=min(dp[i%2][j],dp[(i+1)%2][ j|a[i].e3 ]+a[i].e1);
			}
		}
	}
	if(dp[1][0]==inf) dp[1][0]=-1;
	pf("%lld\n",dp[1][0]);
    return 0;
}

/*

*/


#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define inf 999999999999999999ll
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val

struct data
{
    ll e1,e2,e3;
    data() {}
    data(int a,int b,int c)
    {
        e1=a,e2=b,e3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.e2< b.e2;// sort decreasingly but increasingly for priority_queue
    }
};

int n,m,k;
ll N,M,K;

data a[105];
ll dp[3][(1<<20)+3];
int fnd;
int main()
{
    int t,tc=1;
	sf3(n,m,k);
	int z=k;
	for(int i=1;i<=n;i++){
		ll x,y;
		sfl2(x,y);
		sf1(k);
		int fnd=0;
		for(int i=1;i<=k;i++){
			int p;
			sf1(p);
			p--;
			fnd=fnd | (1<<p);
		}
		//printf("%d\n",fnd);
		a[i]=data(x,y,fnd);
	}
	sort(a+1,a+n+1);
	for(int i=n+1;i>=1;i--){
		for(int j=0;j<(1<<m);j++){
			if(j==(1<<m)-1) dp[i%2][j]=a[i-1].e2*z;
			else if(i==n+1){
				dp[i%2][j]=inf;
			}
			else{
				dp[i%2][j]=dp[(i+1)%2][j];
				dp[i%2][j]=min(dp[i%2][j],dp[(i+1)%2][ j|a[i].e3 ]+a[i].e1);
			}
		}
	}
	if(dp[1][0]==inf) dp[1][0]=-1;
	pf("%lld\n",dp[1][0]);
    return 0;
}

/*

*/


#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
#include <iterator>
#include <algorithm>
#define ll long long
using namespace std;

ll dp[(1<<20)+2];

struct sst
{
    int p;
    int v;
    int k;
    bool operator < (const sst &b) const
    {
        return p<b.p;
    }
};

sst st[105];
set<int>s;
int ar[(1<<20)+2];
int ntv[105];
bool bi[105];
bool bbi[(1<<20)+2];

int main()
{

    int a,b,c,d,e,n,m,o,mtv;

    ll x,y,z,tv;

    scanf("%d %d %d",&n,&m,&o);

    tv=o;
    mtv=0;

    for(a=0;a<n;a++)
    {
        scanf("%d %d %d",&st[a].v,&st[a].k,&c);
        st[a].p=0;
        while(c--)
        {
            scanf("%d",&b);
            b--;
            st[a].p=st[a].p+(1<<b);
        }
        ntv[a]=st[a].k;
        //cout<<st[a].p<<endl;
    }

    sort(st,st+n);
    sort(ntv,ntv+n);

    ll hi,lo,mid;

    set<int>::iterator it;

    for(a=1;a<(1<<m);a++) dp[a]=-1;
    dp[0]=0;

    z=-1;
    s.clear();
    s.insert(0);
    bbi[0]=true;
    e=0;
    for(mid=0;mid<n;mid++)
    {
        //s.clear();
        lo=ntv[mid];
        if(mid)
        {
            if(ntv[mid]==ntv[mid-1]) continue;
        }
        //s.insert(0);
        //cout<<s.size()<<endl;

        for(a=0;a<n;a++)
        {
            if(st[a].k>lo) continue;
            if(bi[a]) continue;
            bi[a]=true;

            //cout<<"now at "<<st[a].p<<" "<<st[a].k<<" "<<st[a].v<<endl;
            it=s.end();
            it--;
            for(c=e;c>=0;c--)
            {
                if(!bbi[c]) continue;
                b=(c | st[a].p);
                if(dp[b]==-1 || dp[c]+st[a].v<dp[b])
                {
                    dp[b]=dp[c]+st[a].v;
                    bbi[b]=true;
                }
                e=max(e,b);
            }
            //for(b=0;b<e;b++) s.insert(ar[b]);
        }
        if(dp[(1<<m)-1]!=-1)
        {
            if(z==-1) z=lo*tv+dp[(1<<m)-1];
            else z=min(z,lo*tv+dp[(1<<m)-1]);
        }
        //for(it=s.begin();it!=s.end();it++) dp[*it]=-1;
        //dp[0]=0;
        //out<<endl;
    }
    cout<<z<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

// Thursday 3/12/20

// for arbitrary window use a segment tree

// note: monotonic queue: used to keep track of min in a window sliding down a array (or max) store ascending elements in the window

// C pipes: you can only go forward or a virtlicle transfer (which is determined by the type of pipe).
// say whether it is possible for water can ge

// B Illya and Queries : prefix sum and a adjacency pairs array for each entry in the adjacency array
// denotes that the terms are adjacent than use the prefix sum on the adjacency array.

// B fence: do a prefix sum and look ar position and k positions laft
// or a rolling sum where you add the right value and subtract the left most value

// Tuesday 3/10/20

int binarySearch(int arr[], int l, int r, int x)
{
	int mid = l + (r - l) / 2;
	if (l == r) {
		if (arr[l] < x) {
			return l;
		}
		else {
			return l - 1;
		}
	}
	if (r >= l) {
		if (arr[mid] >= x)
			return binarySearch(arr, l, mid - 1, x);
		return binarySearch(arr, mid + 1, r, x);
	}
	if (arr[mid] > x) {
		return mid - 1;
	}
	return mid;
}

int main() {
	int n, q; // n is the number of stores q is the number of days
	cin >> n;
	int* x = new int[n];
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	int* y = new int[n];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int money;
		cin >> money;
		int possible = binarySearch(x, 0, n, money);
		cout << possible + 1 << '\n';
	}

	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int binarySearch(int arr[], int l, int r, int x)
{
	int mid = l + (r - l) / 2;
	if (r >= l) {
		if (arr[mid] == x)
			return mid;
		if (arr[mid] > x)
			return binarySearch(arr, l, mid - 1, x);
		return binarySearch(arr, mid + 1, r, x);
	}
	return mid;
}

int main() {
	int n, q; // n is the number of stores q is the number of days
	cin >> n;
	int* x = new int[n];
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	int* y = new int[n];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int money;
		cin >> money;
		int possible = binarySearch(x, 0, n, money);
		if (possible > 1) {
			cout << possible + 1 << '\n';
		}
		else if (money > x[n-1]) {
			cout << n << '\n';
		}
		else if(money >= x[0]){
			cout << 1 << '\n';
		}
		else {
			cout << 0 << '\n';
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

// Thursday 3/12/20

// for arbitrary window use a segment tree

// note: monotonic queue: used to keep track of min in a window sliding down a array (or max) store ascending elements in the window

// C pipes: you can only go forward or a virtlicle transfer (which is determined by the type of pipe).
// say whether it is possible for water can ge

// B Illya and Queries : prefix sum and a adjacency pairs array for each entry in the adjacency array
// denotes that the terms are adjacent than use the prefix sum on the adjacency array.

// B fence: do a prefix sum and look ar position and k positions laft
// or a rolling sum where you add the right value and subtract the left most value

// Tuesday 3/10/20

int binarySearch(int arr[], int l, int r, int x)
{
	int mid = l + (r - l) / 2;
	if (r >= l) {
		if (arr[mid] >= x)
			return binarySearch(arr, l, mid - 1, x);
		return binarySearch(arr, mid + 1, r, x);
	}
	if (arr[mid] > x) {
		return mid - 1;
	}
	return mid;
}

int* linearSearch(int arr[], int size) {
	int* lookup = new int[100001];
	for (int i = 0; i <= 100000; ++i) {
		lookup[i] = 0;
	}
	for (int i = 0; i < size; ++i) {
		lookup[arr[i]] += 1;
	}
	int count = 0;
	for (int i = 0; i <= 100000; ++i) {
		count += lookup[i];
		lookup[i] = count;
	}
	return lookup;
}

int main() {
	int n, q; // n is the number of stores q is the number of days
	cin >> n;
	int* x = new int[n];
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	int* y = linearSearch(x, n);
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int money;
		cin >> money;
		if (money < 100000) {
			cout << y[money];
		}
		else {
			cout << n;
		}
	}
	/*sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int money;
		cin >> money;
		int possible = binarySearch(x, 0, n, money);
		cout << possible + 1 << '\n';
	}*/
	return 0;
}


#include <iostream>
#include <string>
#include <array>
using namespace std;

int q[100007];
int g[100007];
int main() {
	int n;
	cin >> n;
	int mxx = 0;
	//int* a = new int[n];
	for (int i = 0; i < n; i++) {
		//cin >> a[i];
		int tmp;
		cin >> tmp;
		mxx = max(mxx, tmp);
		q[tmp]++;
	}

	g[0] = 0;
	for (int i = 1; i < 100007;i++) {
		g[i] = q[i - 1] + g[i - 1];
	}

	cin >> n;
	while (n--) {
		int k;
		cin >> k;
		if (k >= 100000) {
			cout << g[100001] << endl;
		}
		else {
			cout << g[k + 1] << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
int main() {
	int n, t,a,i=0,q;
	cin >> n;
	vector<int >v(n);
	for (t = 0; t < n; t++)
		cin >> v[t];
	sort(v.begin(), v.end());

	int ar[100009] = { 0 };
	i = v[0];
	for (t = 1; t <n; t++) {

		for (; i < v[t]; i++)
			ar[i] = t;
	}

	for (; i <100009; i++)
		ar[i] = t;

	cin >> q;

	for (t = 0; t < q; t++) {
		cin >> a;
		if (a >= 100009)
			cout << n<<"\n";
		else
			cout << ar[a]<<"\n";

	}

}


#include<iostream>
#include<algorithm>
#include<vector>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define ll long long
#define vbe(v) ((v).begin()), ((v).end())
ll GCD(ll a, ll b) { return (a) ? GCD(b % a, a) : b; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
ll fastpow(ll b, ll p) { if (!p) return 1; ll ret = fastpow(b, p >> 1); ret *= ret; if (p & 1) ret *= b; return ret; }
string alpha = "abcdefghijklmnopqrstuvwxyz";
int divisor(int number)
{
    int i;
    for (i = 2; i <= sqrt(number); i++)
    {
        if (number % i == 0)
        {
            return number / i;
        }
    }
    return 1;
}
int myXOR(int x, int y)
{
    int res = 0; // Initialize result

    // Assuming 32-bit Integer
    for (int i = 31; i >= 0; i--)
    {
        // Find current bits in x and y
        bool b1 = x & (1 << i);
        bool b2 = y & (1 << i);

        // If both are 1 then 0 else xor is same as OR
        bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);

        // Update result
        res <<= 1;
        res |= xoredBit;
    }
    return res;
}
//std::getline(std::cin, a); //read string with spaces
void printDivisors(int n,vector<int>&v)
{
    // Note that this loop runs till square root
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            // If divisors are equal, print only one
            if (n / i == i&&i>1)
                v.push_back(i);

            else // Otherwise print both
            {
                if(i>1)
                    v.push_back(i);
                if(n/i>1)
                    v.push_back(n/i);
            }
        }
    }
}
int bin(vector<int>vec ,int val)
{
    int l = 0, r = vec.size() - 1, mid = r / 2;
    while (l<=r)
    {
        mid = (l + r) / 2;

        if (vec[mid]<val && vec[mid + 1]>val)
        {
            if(vec[mid + 1] == val)
                return mid+1;
            return mid ;

        }
        else if (vec[mid] > val)
        {
            r = mid - 1;
        }
        else if (vec[mid] < val)
        {
            l = mid + 1;
        }
        else if (vec[mid] == val)
            return mid;

    }
    return -1;
}
int main()
{

    int n;
    cin >> n;
    vector<int>vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec[i];
    }
    sort(vbe(vec));
    int q;
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        auto it = upper_bound(vbe(vec), x);
        cout << it - vec.begin() << '\n';

    }

}

/*
vector<bool>visited;
vector<vector<int>>gr;
int dfs(int node,int&c)
{
    visited[node] = true;

    for (size_t i = 0; i < gr[node].size(); i++)
    {
        int child = gr[node][i];
        if (!visited[child])
        {
            c += gr[node].size();
            return dfs(child, c);
        }
        else
            return child;
    }
}
void clear(int n)
{
    visited.clear();
    for(int i=0;i<n;i++)
        gr[i].clear();
    gr.clear();
}
*/


#include<iostream>
#include<algorithm>
#include<vector>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define ll long long
#define vbe(v) ((v).begin()), ((v).end())
ll GCD(ll a, ll b) { return (a) ? GCD(b % a, a) : b; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
ll fastpow(ll b, ll p) { if (!p) return 1; ll ret = fastpow(b, p >> 1); ret *= ret; if (p & 1) ret *= b; return ret; }
string alpha = "abcdefghijklmnopqrstuvwxyz";
int divisor(int number)
{
    int i;
    for (i = 2; i <= sqrt(number); i++)
    {
        if (number % i == 0)
        {
            return number / i;
        }
    }
    return 1;
}
int myXOR(int x, int y)
{
    int res = 0; // Initialize result

    // Assuming 32-bit Integer
    for (int i = 31; i >= 0; i--)
    {
        // Find current bits in x and y
        bool b1 = x & (1 << i);
        bool b2 = y & (1 << i);

        // If both are 1 then 0 else xor is same as OR
        bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);

        // Update result
        res <<= 1;
        res |= xoredBit;
    }
    return res;
}
//std::getline(std::cin, a); //read string with spaces
void printDivisors(int n,vector<int>&v)
{
    // Note that this loop runs till square root
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            // If divisors are equal, print only one
            if (n / i == i&&i>1)
                v.push_back(i);

            else // Otherwise print both
            {
                if(i>1)
                    v.push_back(i);
                if(n/i>1)
                    v.push_back(n/i);
            }
        }
    }
}
int bin(vector<int>vec ,int val)
{
    int l = 0, r = vec.size() - 1, mid = r / 2;
    while (l<=r)
    {
        mid = (l + r) / 2;

        if (vec[mid]<val && vec[mid + 1]>val)
        {
            if(vec[mid + 1] == val)
                return mid+1;
            return mid + 1;

        }
        else if (vec[mid] > val)
        {
            r = mid - 1;
        }
        else if (vec[mid] < val)
        {
            l = mid + 1;
        }
        else if (vec[mid] == val)
            return mid;

    }
    return -1;
}
int main()
{

    int n;
    cin >> n;
    vector<int>vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec[i];
    }
    sort(vbe(vec));
    int q;
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        cout << bin(vec,x)+1<<endl;
    }

}

/*
vector<bool>visited;
vector<vector<int>>gr;
int dfs(int node,int&c)
{
    visited[node] = true;

    for (size_t i = 0; i < gr[node].size(); i++)
    {
        int child = gr[node][i];
        if (!visited[child])
        {
            c += gr[node].size();
            return dfs(child, c);
        }
        else
            return child;
    }
}
void clear(int n)
{
    visited.clear();
    for(int i=0;i<n;i++)
        gr[i].clear();
    gr.clear();
}
*/


#include<iostream>
#include<algorithm>
#include<vector>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define ll long long
#define vbe(v) ((v).begin()), ((v).end())
ll GCD(ll a, ll b) { return (a) ? GCD(b % a, a) : b; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
ll fastpow(ll b, ll p) { if (!p) return 1; ll ret = fastpow(b, p >> 1); ret *= ret; if (p & 1) ret *= b; return ret; }
string alpha = "abcdefghijklmnopqrstuvwxyz";
int divisor(int number)
{
    int i;
    for (i = 2; i <= sqrt(number); i++)
    {
        if (number % i == 0)
        {
            return number / i;
        }
    }
    return 1;
}
int myXOR(int x, int y)
{
    int res = 0; // Initialize result

    // Assuming 32-bit Integer
    for (int i = 31; i >= 0; i--)
    {
        // Find current bits in x and y
        bool b1 = x & (1 << i);
        bool b2 = y & (1 << i);

        // If both are 1 then 0 else xor is same as OR
        bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);

        // Update result
        res <<= 1;
        res |= xoredBit;
    }
    return res;
}
//std::getline(std::cin, a); //read string with spaces
void printDivisors(int n,vector<int>&v)
{
    // Note that this loop runs till square root
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            // If divisors are equal, print only one
            if (n / i == i&&i>1)
                v.push_back(i);

            else // Otherwise print both
            {
                if(i>1)
                    v.push_back(i);
                if(n/i>1)
                    v.push_back(n/i);
            }
        }
    }
}
int bin(vector<int>vec ,int val)
{
    int l = 0, r = vec.size() - 1, mid = r / 2;
    while (l<=r)
    {
        mid = (l + r) / 2;

        if (vec[mid]<val && vec[mid + 1]>val)
        {

            return mid;

        }
        else if (vec[mid] > val)
        {
            r = mid - 1;
        }
        else if (vec[mid] < val)
        {
            l = mid + 1;
        }
        else if (vec[mid] == val)
            return mid;

    }
    return -1;
}
int main()
{

    int n;
    cin >> n;
    vector<int>vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec[i];
    }
    sort(vbe(vec));
    int q;
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        cout << bin(vec,x)+1<<endl;
    }

}

/*
vector<bool>visited;
vector<vector<int>>gr;
int dfs(int node,int&c)
{
    visited[node] = true;

    for (size_t i = 0; i < gr[node].size(); i++)
    {
        int child = gr[node][i];
        if (!visited[child])
        {
            c += gr[node].size();
            return dfs(child, c);
        }
        else
            return child;
    }
}
void clear(int n)
{
    visited.clear();
    for(int i=0;i<n;i++)
        gr[i].clear();
    gr.clear();
}
*/


#include<iostream>
#include<algorithm>
#include<vector>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define ll long long
#define vbe(v) ((v).begin()), ((v).end())
ll GCD(ll a, ll b) { return (a) ? GCD(b % a, a) : b; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
ll fastpow(ll b, ll p) { if (!p) return 1; ll ret = fastpow(b, p >> 1); ret *= ret; if (p & 1) ret *= b; return ret; }
string alpha = "abcdefghijklmnopqrstuvwxyz";
int divisor(int number)
{
    int i;
    for (i = 2; i <= sqrt(number); i++)
    {
        if (number % i == 0)
        {
            return number / i;
        }
    }
    return 1;
}
int myXOR(int x, int y)
{
    int res = 0; // Initialize result

    // Assuming 32-bit Integer
    for (int i = 31; i >= 0; i--)
    {
        // Find current bits in x and y
        bool b1 = x & (1 << i);
        bool b2 = y & (1 << i);

        // If both are 1 then 0 else xor is same as OR
        bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);

        // Update result
        res <<= 1;
        res |= xoredBit;
    }
    return res;
}
//std::getline(std::cin, a); //read string with spaces
void printDivisors(int n,vector<int>&v)
{
    // Note that this loop runs till square root
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            // If divisors are equal, print only one
            if (n / i == i&&i>1)
                v.push_back(i);

            else // Otherwise print both
            {
                if(i>1)
                    v.push_back(i);
                if(n/i>1)
                    v.push_back(n/i);
            }
        }
    }
}
int bin(vector<int>vec ,int val)
{
    int l = 0, r = vec.size() - 1, mid = r / 2;
    while (l<=r)
    {
        mid = (l + r) / 2;

        if (vec[mid] > val)
        {
            r = mid - 1;
        }
        else if (vec[mid] < val)
        {
            l = mid + 1;
        }
        else if (vec[mid] == val)
            return mid;
        else if (vec[mid]<val && vec[mid + 1]>val)
        {
            if (vec[mid] >= val && val < vec[mid] + 1)
                return mid;
            else if (vec[mid + 1] <= val)
                return mid + 1;
        }

    }
    return -1;
}
int main()
{

    int n;
    cin >> n;
    vector<int>vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec[i];
    }
    sort(vbe(vec));
    int q;
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        cout << bin(vec,x)+1<<endl;
    }

}

/*
vector<bool>visited;
vector<vector<int>>gr;
int dfs(int node,int&c)
{
    visited[node] = true;

    for (size_t i = 0; i < gr[node].size(); i++)
    {
        int child = gr[node][i];
        if (!visited[child])
        {
            c += gr[node].size();
            return dfs(child, c);
        }
        else
            return child;
    }
}
void clear(int n)
{
    visited.clear();
    for(int i=0;i<n;i++)
        gr[i].clear();
    gr.clear();
}
*/


#include<iostream>
#include<algorithm>
#include<vector>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define ll long long
#define vbe(v) ((v).begin()), ((v).end())
ll GCD(ll a, ll b) { return (a) ? GCD(b % a, a) : b; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
ll fastpow(ll b, ll p) { if (!p) return 1; ll ret = fastpow(b, p >> 1); ret *= ret; if (p & 1) ret *= b; return ret; }
string alpha = "abcdefghijklmnopqrstuvwxyz";
int divisor(int number)
{
    int i;
    for (i = 2; i <= sqrt(number); i++)
    {
        if (number % i == 0)
        {
            return number / i;
        }
    }
    return 1;
}
int myXOR(int x, int y)
{
    int res = 0; // Initialize result

    // Assuming 32-bit Integer
    for (int i = 31; i >= 0; i--)
    {
        // Find current bits in x and y
        bool b1 = x & (1 << i);
        bool b2 = y & (1 << i);

        // If both are 1 then 0 else xor is same as OR
        bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);

        // Update result
        res <<= 1;
        res |= xoredBit;
    }
    return res;
}
//std::getline(std::cin, a); //read string with spaces
void printDivisors(int n,vector<int>&v)
{
    // Note that this loop runs till square root
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            // If divisors are equal, print only one
            if (n / i == i&&i>1)
                v.push_back(i);

            else // Otherwise print both
            {
                if(i>1)
                    v.push_back(i);
                if(n/i>1)
                    v.push_back(n/i);
            }
        }
    }
}
int bin(vector<int>vec ,int val)
{
    int l = 0, r = vec.size() - 1, mid = r / 2;
    while (l<=r)
    {
        mid = (l + r) / 2;

        if (vec[mid]<val && vec[mid + 1]>val)
        {
            if(vec[mid + 1] == val)
                return mid+1;
            return mid ;

        }
        else if (vec[mid] > val)
        {
            r = mid - 1;
        }
        else if (vec[mid] < val)
        {
            l = mid + 1;
        }
        else if (vec[mid] == val)
            return mid;

    }
    return -1;
}
int main()
{

    int n;
    cin >> n;
    vector<int>vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec[i];
    }
    sort(vbe(vec));
    int q;
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        cout << bin(vec,x)+1<<endl;
    }

}

/*
vector<bool>visited;
vector<vector<int>>gr;
int dfs(int node,int&c)
{
    visited[node] = true;

    for (size_t i = 0; i < gr[node].size(); i++)
    {
        int child = gr[node][i];
        if (!visited[child])
        {
            c += gr[node].size();
            return dfs(child, c);
        }
        else
            return child;
    }
}
void clear(int n)
{
    visited.clear();
    for(int i=0;i<n;i++)
        gr[i].clear();
    gr.clear();
}
*/


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> shops(100001);
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		shops[temp]++;
	}
	for (int i = 1; i < shops.size(); i++) {
		shops[i] = shops[i - 1] + shops[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int temp;
		cin >> temp;
		if (temp >= shops.size())
			cout << shops[shops.size() - 1];
		else
			cout << shops[temp] << "\n";
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> shops(100001);
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		shops[temp]++;
	}
	for (int i = 1; i < shops.size(); i++) {
		shops[i] = shops[i - 1] + shops[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int temp;
		cin >> temp;
		if (temp >= shops.size())
			cout << shops[shops.size() - 1];
		cout << shops[temp] << "\n";
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> shops(100001);
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		shops[temp]++;
	}
	for (int i = 1; i < shops.size(); i++) {
		shops[i] = shops[i - 1] + shops[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int temp;
		cin >> temp;
		if (temp >= shops.size())
			cout << shops[shops.size() - 1] << "\n";
		else
			cout << shops[temp] << "\n";
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> shops(100001);
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		shops[temp]++;
	}
	for (int i = 1; i < shops.size(); i++) {
		shops[i] = shops[i - 1] + shops[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int temp;
		cin >> temp;
		cout << shops[temp] << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <string>

using namespace std;

long long arr[100000];

int main(){
	int n, ma=0,q,mi = INT32_MAX, a;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		arr[a] += 1;
		ma = max(ma, a);
		mi = min(mi, a);
	}
	for (int i = mi+1; i <= ma; ++i) {
		arr[i] += arr[i - 1];
	}
	cin >> q;
	while (q--) {
		cin >> a;
		cout << arr[a] << '\n';
	}
	/*system("pause");*/
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <string>

using namespace std;

long long arr[100000];

int main(){
	int n, ma=0,q,mi = INT32_MAX, a;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		arr[a] += 1;
		ma = max(ma, a);
		mi = min(mi, a);
	}
	for (int i = mi+1; i <= ma; ++i) {
		arr[i] += arr[i - 1];
	}
	cin >> q;
	while (q--) {
		cin >> a;
		if (a > ma) cout << arr[ma] << '\n';
		else cout << arr[a] << '\n';
	}
	/*system("pause");*/
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <string>

using namespace std;

long long arr[100001];

int main() {
	int n, ma = 0, q, mi = INT32_MAX, a;
	cin >> n;
	while (n--) {
		cin >> a;
		arr[a] += 1;
		ma = max(ma, a);
		mi = min(mi, a);
	}
	for (int i = mi + 1; i <= ma; ++i) {
		arr[i] += arr[i - 1];
	}
	cin >> q;
	while (q--) {
		cin >> a;
		cout << arr[min(a, ma)] << '\n';
	}
	/*system("pause");*/
	return 0;
}


#include <algorithm>
#include <numeric>
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>

typedef std::pair<std::pair<int, int>, int> triplet;

unsigned gcd_recursive(unsigned a, unsigned b)
{
	if (b)
		return gcd_recursive(b, a % b);
	else
		return a;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int n;
	std::cin >> n;
	std::vector<int> x(n);
	for (int i = 0; i < n; i++) {
		std::cin >> x[i];
	}

	int q;
	std::cin >> q;
	std::vector<int> m(q);
	for (int i = 0; i < q; i++) {
		std::cin >> m[i];
	}
	std::sort(x.begin(), x.end());
	for (int i = 0; i < q; i++) {

		std::cout << std::upper_bound(x.begin(), x.end(), m[i]) - x.begin() << std::endl;
	}

	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, a[100000], q, x;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cin >> q;
	while (q--)
	{
		cin >> x;
		int j = 0;
		for (int i = 0; i < n; i++)
			j += a[i] <= x;
		cout << j << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n, a[100000], q, x;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	cin >> q;
	while (q--)
	{
		cin >> x;
		for (int i = 0; i < n; i++)
		{
			if (a[i] > x)
			{
				cout << i << endl;
				break;
			}
			else if (i == n - 1)
				cout << ++i << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int n, q, x;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	cin >> q;
	while (q--)
	{
		cin >> x;
		cout << upper_bound(a.begin(), a.end(), x) - a.begin() << endl;
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool cmp(int a, int b){
    return a>b;
}

int main() {

    int num;
    cin >> num;

    vector<int> shop;

    for(int i=0 ; i<num ; i++){
        int tem;
        cin >> tem;
        shop.push_back(tem);
    }

    sort(shop.begin() , shop.end());

    int d;
    cin >> d;

    while(d--){
        int k;
        bool f = 0;
        cin >> k;

        int a=0 , b=num-1;

        if(k>=shop[num-1]){
            cout << num << "\n";
            f = true;
        }else if(k<shop[0]){
            cout << 0 << "\n";
            f = true;
        }

        while(b>a && !f){

            if(k == shop[(a+b)/2]){
                cout << (a+b)/2 + 1 << "\n";
                f = !f;
                break;
            }else if(k > shop[(a+b)/2]){
                a = (a+b)/2;
            }else{
                b = (a+b)/2;
            }

        }

        if(!f){
            cout << a+1 << "\n";
        }

    }

}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool cmp(int a, int b){
    return a>b;
}

int main() {

    int num;
    cin >> num;

    vector<int> shop;

    for(int i=0 ; i<num ; i++){
        int tem;
        cin >> tem;
        shop.push_back(tem);
    }

    sort(shop.begin() , shop.end());

    int d;
    cin >> d;

    while(d--){
        int k;
        cin >> k;
        cout << upper_bound(shop.begin(), shop.end(), k) - shop.begin() << "\n";

    }

}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool cmp(int a, int b){
    return a>b;
}

int main() {

    int num;
    cin >> num;

    vector<int> shop;

    for(int i=0 ; i<num ; i++){
        int tem;
        cin >> tem;
        shop.push_back(tem);
    }

    sort(shop.begin() , shop.end());

    int d;
    cin >> d;

    while(d--){
        int k;
        bool f = 0;
        cin >> k;

        int a=0 , b=num-1;

        while(b-a>1){

            if(k>=shop[num-1]){
                cout << num << "\n";
                f = !f;
                break;
            }else if(k<shop[0]){
                cout << 0 << "\n";
                f = !f;
                break;
            }else if(k == shop[(a+b)/2]){
                cout << (a+b)/2 << "\n";
                f = !f;
                break;
            }else if(k > shop[(a+b)/2]){
                a = (a+b)/2+1;
            }else{
                b = (a+b)/2-1;
            }

        }

        if(!f){
            cout << a+1 << "\n";
        }

    }

}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool cmp(int a, int b){
    return a>b;
}

int main() {

    int num;
    cin >> num;

    vector<int> shop;

    for(int i=0 ; i<num ; i++){
        int tem;
        cin >> tem;
        shop.push_back(tem);
    }

    sort(shop.begin() , shop.end());

    int d;
    cin >> d;

    while(d--){
        int k;
        bool f = 0;
        cin >> k;

        int a=0 , b=num-1;

        while(b-a>1){

            if(k>=shop[num-1]){
                cout << num << "\n";
                f = !f;
                break;
            }else if(k<shop[0]){
                cout << 0 << "\n";
                f = !f;
                break;
            }else if(k == shop[(a+b)/2]){
                cout << (a+b)/2 << "\n";
                f = !f;
                break;
            }else if(k > shop[(a+b)/2]){
                a = (a+b)/2;
            }else{
                b = (a+b)/2;
            }

        }

        if(!f){
            cout << a+1 << "\n";
        }

    }

}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool cmp(int a, int b){
    return a>b;
}

int main() {

    int num;
    cin >> num;

    vector<int> shop;

    for(int i=0 ; i<num ; i++){
        int tem;
        cin >> tem;
        shop.push_back(tem);
    }

    sort(shop.begin() , shop.end());

    int d;
    cin >> d;

    while(d--){
        int k;
        bool f = 0;
        cin >> k;

        int a=0 , b=num-1;

        while(b-a>1){

            if(k>=shop[num-1]){
                cout << num << "\n";
                f = !f;
                break;
            }else if(k<shop[0]){
                cout << 0 << "\n";
                f = !f;
                break;
            }else if(k == shop[(a+b)/2]){
                cout << (a+b)/2 + 1 << "\n";
                f = !f;
                break;
            }else if(k > shop[(a+b)/2]){
                a = (a+b)/2;
            }else{
                b = (a+b)/2;
            }

        }

        if(!f){
            cout << a+1 << "\n";
        }

    }

}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int main() {

    int num;
    cin >> num;

    vector<int> shop;

    for(int i=0 ; i<num ; i++){
        int tem;
        cin >> tem;
        shop.push_back(tem);
    }

    int d;

    cin >> d;

    while(d--){
        int m , ans =0;
        cin >> m;

        for(int i=0 ; i<num ; i++){
            if(m>=shop[i]){
                ans++;
            }
        }

        cout << ans << "\n";
    }

}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool cmp(int a, int b){
    return a>b;
}

int main() {

    int num;
    cin >> num;

    vector<int> shop;

    for(int i=0 ; i<num ; i++){
        int tem;
        cin >> tem;
        shop.push_back(tem);
    }

    sort(shop.begin() , shop.end());

    int d;
    cin >> d;

    while(d--){
        int k;
        bool f = 0;
        cin >> k;

        int a=0 , b=num-1;

        if(k>=shop[num-1]){
            cout << num << "\n";
            f = true;
        }else if(k<shop[0]){
            cout << 0 << "\n";
            f = true;
        }

        while(b-a>1 && !f){

            if(k == shop[(a+b)/2]){
                cout << (a+b)/2 + 1 << "\n";
                f = !f;
                break;
            }else if(k > shop[(a+b)/2]){
                a = (a+b)/2;
            }else{
                b = (a+b)/2;
            }

        }

        if(!f){
            cout << a+1 << "\n";
        }

    }

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<unordered_set>
#include<stack>
using namespace std;
#define ll long long

void main() {
int n;
	cin >> n;

	vector<ll> prices(n);
	for (int i = 0; i < n; i++)
		cin >> prices[i];
	sort(prices.begin(), prices.end());
	int d;
	cin >> d;

	for (int i = 0; i < d; i++) {
		ll m;
		cin >> m;

		auto it = upper_bound(prices.begin(), prices.end(), m);
		cout << (it - prices.begin()) << endl;
	}

}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <assert.h>

using namespace std;

inline int read() {
	char c, _c; int x; for (c = _c = getchar(); !isdigit(c); c = getchar()) { _c = c; }
	for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return _c == '-' ? -x : x;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long int n;
	cin >> n;
	long int a[100000 + 1];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int q;
	cin >> q;
	for (int j = 0; j < q; j++)
	{
		int m;
		cin >> m;
		cout << upper_bound(a, a + n, m) - a << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <assert.h>

using namespace std;

inline int read() {
	char c, _c; int x; for (c = _c = getchar(); !isdigit(c); c = getchar()) { _c = c; }
	for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return _c == '-' ? -x : x;
}

#define M 100005

int binarySearch(long int arr[M], long int l, long int r, long int x)
{
	if (r >= l) {
		int mid = l + (r - l) / 2;

		if (arr[mid] == x)
			return mid;

		if (arr[mid] > x)
			return binarySearch(arr, l, mid - 1, x);

		return binarySearch(arr, mid + 1, r, x);
	}

	return -1;
}

int bigindex(long int arr[M], long int l, long int r, long int x)
{
	stack <int> s;
	int mid;
	mid = binarySearch(arr, l, r, x);
	while (mid != -1)
	{
		s.push(mid);
		mid = binarySearch(arr, mid + 1, r, x);
	}

	if (s.empty())
		return -1;

	mid = s.top();

	return mid;
}

long int mid;
int bsh(long int arr[M], long int l, long int r, long int x, long int n)
{
	if (r >= l) {
		mid = l + (r - l) / 2;

		if (arr[mid] == x)
		{
			/*
			while (arr[mid] == x)
				mid++;
			return mid - 1;
			*/
			return bigindex(arr, mid, r, x);
		}

		if (arr[mid] > x)
			return bsh(arr, l, mid - 1, x, n);

		return bsh(arr, mid + 1, r, x, n);
	}

	//cout << mid << "!" << endl;

	if (2 <= mid && mid <= n - 1)
	{
		if (arr[mid - 1] < x && x < arr[mid])
			return mid - 1;
		if (arr[mid] < x && x < arr[mid + 1])
			return mid;
	}
	if (mid == 1)
	{
		if (arr[mid] < x)
			return mid;

		if (arr[mid] > x)
			return mid - 1;
	}
	if (mid == n)
	{
		if (arr[mid] < x)
			return mid;

		if (arr[mid] > x)
			return mid - 1;
	}
	if (mid == n + 1)
		return n;

	return -1;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long int n;
	cin >> n;
	long int a[M];
	long int i;
	for (i = 1; i <= n; i++)
		a[i] = read();
	a[0] = -1;
	a[n + 1] = 100000 + 5;
	sort(a, a + n + 1);

	/*
	for (i = 1; i <= n; i++)
	cout << a[i] << " ";
	cout << endl;
	cout << a[0] << " " << a[n + 1] << endl;

	cout << bsh(a, 1, n, 909, n) << endl;
	*/

	long int q, m;
	cin >> q;
	for (i = 1; i <= q; i++)
	{
		m = read();
		cout << bsh(a, 1, n, m, n) << endl;
	}

	//cout << bigindex(a, 1, n, 7) << endl;

	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int size, vol;
	cin >> size;
	int*arr = new int[size];
	for (int i = 0; i < size; i++)

		cin >> arr[i];
	cin >> vol;
	sort(arr, arr + size);
	for (int i = 0; i < vol; i++)
	{
		int e;
		cin >> e;
		;

		int start = 0, end = size - 1, mid;

		int tt = 0;
		while (start <= end){
			mid = (start + end) / 2;
			if (arr[start] > e){
				tt = start;
			}
			else if (arr[end] < e){
				tt = end + 1;
			}

			if (arr[mid] == e){
				tt = mid + 1;
				start = mid + 1;

			}
			else if (arr[mid] > e){
				end = mid - 1;
			}
			else
				start = mid + 1;

		}
		cout << tt << endl;
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <stdlib.h>

using namespace std;

int n;
int q, m[100001];
int l[100001];
int freq[100001];
int max = 0, min = 0;
int ans;

int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x > max) max = x;
		if (x < min) min = x;
		freq[x]++;
	}
	for (int i = 0; i <= 100000; i++) {
		if (i == 0) l[i] = freq[i];
		else {
			l[i] = l[i - 1] + freq[i];
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int m;
		cin >> m;
		if (m >= max) cout << n <<endl;
		else if (m < min) cout << 0 <<endl;
		else {
			cout << l[m] << endl;
		}

	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int binarysearch(int a[],int key,int l,int r)
{
    int m;
    while(l<=r)
    {
        m=(l+r)/2;
        if(a[m]==key)
            return m;
        else if(key>a[m])
            l=m+1;
        else
            r=m-1;
    }
    return -1;
}

int main()
{
   int price[100000],day[100000],ans[100000];
   int n,q;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>price[i];
   }
   cin>>q;
   for(int i=0;i<q;i++)
   {
      cin>>day[i];
   }

   for(int j=0;j<n-2;j++)
   {
      for(int i=0;i<n-2-j;i++)
   {
       if(price[i]>price[i+1])
        swap(price[i],price[i+1]);
   }
   }

   int k;
   int as;
   for(int i=0;i<q;i++)
   {
        k=day[i];
        as=binarysearch(price,k,0,n-1);
       ans[i]=as+1;
   }
   for(int i=0;i<q;i++)
   {
       cout<<ans[i]<<endl;
   }
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
   int price[100000],day[100000];
   int ans[100000];
   int n,q;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>price[i];
   }
   cin>>q;
   for(int i=0;i<q;i++)
   {
      cin>>day[i];
   }

   /*for(int j=0;j<n-2;j++)
   {
      for(int i=0;i<n-2-j;i++)
   {
       if(price[i]>price[i+1])
        swap(price[i],price[i+1]);
   }
   }*/
   sort(price,price+n);
   int m;
   for(int i=0;i<q;i++)
   {
    int l=0,r=n-1,m=0;
    while(l<=r)
    {
        m=(l+r)/2;
        if(price[m]>day[i])
        {
            r=m-1;

        }

        else
        {

          l=m+1;
          ans[i]= m+1;

        }
    }

   }
   for(int i=0;i<q;i++)
   {
       cout<<ans[i]<<endl;
   }
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
   int price[100000],day[100000];
   int ans[100000];
   int n,q;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>price[i];
   }
   cin>>q;
   for(int i=0;i<q;i++)
   {
      cin>>day[i];
   }

   /*for(int j=0;j<n-2;j++)
   {
      for(int i=0;i<n-2-j;i++)
   {
       if(price[i]>price[i+1])
        swap(price[i],price[i+1]);
   }
   }*/
   sort(price,price+n);
   int m;
    int l=0,r=n-1;
   for(int i=0;i<q;i++)
   {
    while(l<=r)
    {
        m=(l+r)/2;
        if(price[m]>day[i])
        {
            r=m-1;

        }

        else
        {

          l=m+1;
          ans[i]= m+1;

        }
    }

   }
   for(int i=0;i<q;i++)
   {
       cout<<ans[i]<<endl;
   }
}


// program about interesting drink
#include <iostream>
using namespace std;

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	int x[100000];
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	int q;
	cin >> q;
	int m;
	// sort array of prices
	int j = 0;
	for (int i = 0;i < n;i++)
	{
		j = i;
		for (;j < n; ++j)
		{
			if (x[i] > x[j])
			{
				int obm = x[i];
				x[i] = x[j];
				x[j] = obm;
			}
		}
	}
	// search result and print
	int res = 0;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		j = 0;
		for (;j < n; j++)
		{
			if (m >= x[j])
			{
				res++;
			}
			else
			{
				break;
			}
		}
		cout << res << "\n";
		res = 0;
	}
	return 0;
}


    // program about interesting drink
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int x[100000];

    int main(int argc, char const* argv[])
    {
    	// enter number
    	int n;
    	cin >> n;
    	for (int i = 0; i < n; ++i)
    	{
    		cin >> x[i];
    	}
    	sort(x,x+n);
    	int q;
    	cin >> q;
    	int m;
    	// search result and print
    	int res = 0;
    	for (int i = 0; i < q; i++)
    	{
    		cin >> m;
    		for (int j = 0;j < n/2; j++)
    		{
                if(m >= x[n-j-1])
                {
                    res = n - j;
                    break;
                }
                if(m < x[j])
                {
                    res = j;
                    break;
                }
    		}
    		cout << res << "\n";
    		res = 0;
    	}
    	return 0;
    }


// program about interesting drink
#include <iostream>
//#include <stdlib.h>
#include <algorithm>
using namespace std;
int x[100000];

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	sort(x,x+n);
	int q;
	cin >> q;
	int m;
	// search result and print
	int res = 0;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		for (int j = 0;j < n; j++)
		{
			if (m >= x[j])
			{
				res++;
			}
			else
			{
				break;
			}
		}
		cout << res << "\n";
		res = 0;
	}
	return 0;
}


// program about interesting drink
#include <iostream>
//#include <stdlib.h>
#include <algorithm>
using namespace std;
int x[100000];

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	sort(x,x+n);
	int q;
	cin >> q;
	int m;
	// search result and print
	int res = 0;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		for (int j = 0;j < n; j++)
		{
			if (m < x[j])
			{
				res = j;
				break;
			}
		}
		if(res == 0)
		{
			res = n;
		}
		cout << res << "\n";
		res = 0;
	}
	return 0;
}


// program about interesting drink
#include <iostream>
//#include <stdlib.h>
#include <algorithm>
using namespace std;
int x[100000];

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	sort(x,x+n);
	int q;
	cin >> q;
	int m;
	// search result and print
	int res = 0;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		for (int j = 0;j < n; j++)
		{
			if (m < x[j])
			{
				res = j;
				break;
			}
		}
		cout << res << "\n";
		res = 0;
	}
	return 0;
}


// program about interesting drink
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	int* x;
	x = (int*)calloc(n,sizeof(int));
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	int q;
	cin >> q;
	int m;
	// sort array of prices
	int j = 0;
	for (int i = 0;i < n;i++)
	{
		j = i;
		for (;j < n; ++j)
		{
			if (x[i] > x[j])
			{
				int obm = x[i];
				x[i] = x[j];
				x[j] = obm;
			}
		}
	}
	// search result and print
	int res = 0;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		j = 0;
		for (;j < n; j++)
		{
			if (m >= x[j])
			{
				res++;
			}
			else
			{
				break;
			}
		}
		cout << res << "\n";
		res = 0;
	}
	return 0;
}


// program about interesting drink
#include <iostream>
#include <algorithm>
using namespace std;
int x[100000];

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	sort(x, x + n);
	int q;
	cin >> q;
	// search result and print
	for (int i = 0; i < q; i++)
	{
		int m;
		cin >> m;
		cout << upper_bound(x, x + n, m) - x << "\n";
	}
	return 0;
}


// program about interesting drink
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	int* x;
	x = (int*)calloc(n,sizeof(int));
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	int q;
	cin >> q;
	int m;
	int j = 0;
	// search result and print
	int res = 0;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		j = 0;
		for (;j < n; j++)
		{
			if (m >= x[j])
			{
				res++;
			}
		}
		cout << res << "\n";
		res = 0;
	}
	return 0;
}


// program about interesting drink
#include <iostream>
#include <algorithm>
using namespace std;
int x[100000];

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	sort(x, x + n);
	int q;
	cin >> q;
	int m;
	// search result and print
	int res = 0;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		for (int j = 0;j < (n / 2 + n % 2); j++)
		{
			if (m >= x[n - j - 1])
			{
				res = n - j;
				break;
			}
			if (m < x[j])
			{
				res = j;
				break;
			}
		}
		cout << res << "\n";
		res = 0;
	}
	return 0;
}


// program about interesting drink
#include <iostream>
//#include <stdlib.h>
#include <algorithm>
using namespace std;
int x[100000];

int main(int argc, char const* argv[])
{
	// enter number
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	sort(x,x+n);
	int q;
	cin >> q;
	int m;
	// search result and print
	int res = 0;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		for (int j = 0;j < n; j++)
		{
			if (m < x[j])
			{
				res = j;
				break;
			}
			if(res == 0 && j+1 == n)
			{
				res = n;
			}
		}
		cout << res << "\n";
		res = 0;
	}
	return 0;
}


/*

╔══╗╔╗─╔╗╔════╗╔╗╔╗──╔══╗╔╗╔╗╔══╗
║╔╗║║╚═╝║╚═╗╔═╝║║║║──║╔═╝║║║║║╔═╝
║╚╝║║╔╗─║──║║──║╚╝║──║╚═╗║║║║║╚═╗
║╔╗║║║╚╗║──║║──╚═╗║──║╔═╝║║║║║╔═╝
║║║║║║─║║──║║───╔╝║──║║──║╚╝║║║
╚╝╚╝╚╝─╚╝──╚╝───╚═╝──╚╝──╚══╝╚╝

Sviatoslav Bidzilia 2019

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define inf 1e17
#define e 1e-7
#define PI acos(-1)
#define vi vector<int>
#define F first
#define S second

template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void update_max(T last, T& mx)
{
	mx = max(mx, last);
}
template<typename T>
void update_min(T last, T& mx)
{
	mx = min(mx, last);
}
template<typename T>
void update_sum(T last, T& mx)
{
	mx += last;
}
template<typename T>
void print_one(T a)
{
	cout << a << ' ';
}
template<typename T, typename... Args>
T max(Args&& ... args)
{
	T mx = -inf;
	T dummy[] = { 0, ((void)update_max(std::forward<Args>(args), mx),0)... };
	return mx;
}
template<typename T, typename... Args>
T min(Args&& ... args)
{
	T mx = inf;
	T dummy[] = { 0, ((void)update_min(std::forward<Args>(args), mx),0)... };
	return mx;
}
template<typename T, typename... Args>
T sum(Args&& ... args)
{
	T mx = 0;
	T dummy[] = { 0, ((void)update_sum(std::forward<Args>(args), mx),0)... };
	return mx;
}
template<typename... Args>
void print(Args&& ... args)
{
	int dummy[] = { 0, ((void)print_one(std::forward<Args>(args)),0)... };
	cout << '\n';
}
template<typename T>
void print(vector<T> a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(vector<T> a)
{
	T mx = -inf;
	for (auto i : a)
		mx = max(i, mx);

	return (T)mx;
}
template<typename T>
T min(vector<T> a)
{
	T mx = inf;
	for (auto i : a)
		mx = min(i, mx);

	return (T)mx;
}
template<typename T>
T sum(vector<T> a)
{
	T mx = 0;
	for (auto i : a)
		mx += i;
	return mx;
}
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto& i : a)
		cin >> i;
	SORT(a);
	int q;
	cin >> q;
	while (q--)
	{
		int k;
		cin >> k;
		cout << upper_bound(all(a), k) - a.begin()<< '\n';
	}
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e5 + 7;
int n, x[N], q, m[N], freq[N], j, a;
vector<int>v;
vector<int>::iterator ans;
/*
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 1;
		else if (num > arr[mid]) {

			return search(arr, num, mid + 1, R, true);
		}
		else {
			return search(arr, num, L, mid - 1, true);
		}
	}
	//cout << "L : " << L << " " << R << " " << mid << endl;
	if (L > -1 && num >= arr[L - 1]) {
		if (L > j)
			return L - 1;
		return L;
	}
	else if (R > -1 && num >= arr[R])
		return R;
	else
		return 0;
}*/
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];

	}sort(x , x + n);/*
	for (int i = 0; i < j; i++) {
		cout << x[i] << " " << freq[x[i]] << endl;;

	}

	for (int i = 0; i < n; i++) {
		if (!pair1.empty()) {
			if (pair1[pair1.size() - 1].first == x[i]) {
				pair1[pair1.size() - 1].second = i + 1;
				continue;
			}
			else {
				if(pair1[pair1.size() - 1].second < 2)
				pair1.pop_back();
			}
		}
		pair1.push_back({ x[i], i +1});
	}

	for (size_t i = 0; i < pair1.size(); i++)
	{
		cout << pair1[i].first << " " << pair1[i].second << endl;
	}*/
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		int ans = upper_bound(x, x+n, m[i]) - x;
		/*//cout << ans << endl;
		for (int i = 0; i < pair1.size(); i++)
		{
			if (x[ans-1] == pair1[i].first) {
				//cout << "pair : " << x[ans] << " " << pair1[i].first << " ";
				ans = pair1[i].second;
				break;
			}
			8
2 2 5 5 5 8 8 8
		}
		//cout << "ans2 : " << ans << "\n";
		for (int l = 0; l < j && j < n; l++)
		{
			if (m[i] >= x[l]) {
				if (freq[x[l]] > 1)
					ans += freq[x[l]] - 1;
				cout << "hu";
			}
			else
				break;

		}*/
		//else
		cout << (ans) << "\n";
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e5 + 7;
int n, x[N], q, m[N], freq[N], ans, j;
vector<pair<int, int>>pair1;
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 1;
		else if (num > arr[mid]) {

			return search(arr, num, mid + 1, R, true);
		}
		else {
			return search(arr, num, L, mid - 1, true);
		}
	}
	//cout << "ans : " << L << " " << R << " " << mid << endl;
	if (L > -1 && num >= arr[L - 1]) {
		if (L > j)
			return L - 1;
		return L;
	}
	else if (R > -1 && num >= arr[R])
		return R;
	else
		return 0;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x + n);
	for (int i = 0; i < n; i++) {
		if (!pair1.empty()) {
			if (pair1[pair1.size() - 1].first == x[i]) {
				pair1[pair1.size() - 1].second = i + 1;
				continue;
			}
			else {
				if(pair1[pair1.size() - 1].second < 2)
				pair1.pop_back();
			}
		}
		pair1.push_back({ x[i], i +1});
	}
	j = n;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		ans = search(x, m[i], 0, n);
		//cout << ans << endl;
		for (int i = 0; i < pair1.size(); i++)
		{
			if (x[ans-1] == pair1[i].first) {
				//cout << "pair : " << x[ans] << " " << pair1[i].first << " ";
				ans = pair1[i].second;
				break;
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e6 + 7;
template<class t>
class queue {
private:
	struct node {
		t item;
		node* next;
	};
	node* front;
	node* rear;
	int length;
public:
	queue() {
		front = rear = NULL;
		length = 0;
	}
	void enqueue(t el) {
		node* newItem = new node;
		newItem->item = el;
		newItem->next = NULL;
		if (isEmpty()) {
			front = rear = newItem;
		}
		else {
			rear->next = newItem;
			rear = newItem;
		}
		length++;
	}
	void dequeue() {
		if (isEmpty()) {
			cout<<"The queue is Empty\n";
		}
		else if(rear == front){
			delete front;
			rear = NULL;
		}
		else {
			node* temp = front;
			front = front->next;
			delete temp;
		}
		length--;
	}

	void print() {
		if (!isEmpty()) {
			cout << "[ ";
			for (node* cur = front; cur != NULL; cur = cur->next) {
				cout << cur->item << " ";
			}
			cout << "]\n";
		}
	}
	bool isEmpty() {
		return rear == NULL;
	}

};
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 1;
		else if (num > arr[mid]) {

			return search(arr, num, mid + 1, R, true);
		}
		else {
			if (mid > -1)
				if (num >= arr[mid - 1])
					return mid;
			return search(arr, num, L, mid - 1, true);
		}

	}
	if (R > -1)
		return R +1;
	else
		return 0;
}
int n, x[N], q, m[N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		cout <<search(x, m[i], 0, n -1)<<endl;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e6 + 7;
template<class t>
class queue {
private:
	struct node {
		t item;
		node* next;
	};
	node* front;
	node* rear;
	int length;
public:
	queue() {
		front = rear = NULL;
		length = 0;
	}
	void enqueue(t el) {
		node* newItem = new node;
		newItem->item = el;
		newItem->next = NULL;
		if (isEmpty()) {
			front = rear = newItem;
		}
		else {
			rear->next = newItem;
			rear = newItem;
		}
		length++;
	}
	void dequeue() {
		if (isEmpty()) {
			cout<<"The queue is Empty\n";
		}
		else if(rear == front){
			delete front;
			rear = NULL;
		}
		else {
			node* temp = front;
			front = front->next;
			delete temp;
		}
		length--;
	}

	void print() {
		if (!isEmpty()) {
			cout << "[ ";
			for (node* cur = front; cur != NULL; cur = cur->next) {
				cout << cur->item << " ";
			}
			cout << "]\n";
		}
	}
	bool isEmpty() {
		return rear == NULL;
	}

};
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 1;
		else if (num > arr[mid]) {
			if (num < arr[mid+1])
				return mid;
			return search(arr, num, mid + 1, R, true);
		}
		else {
			if (mid > -1)
				if (num >= arr[mid - 1])
					return mid +1;
			return search(arr, num, L, mid - 1, true);
		}

	}
	if (R > -1)
		return R +1;
	else
		return 0;
}
int n, x[N], q, m[N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		cout <<search(x, m[i], 0, n -1)<<endl;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e6 + 7;
template<class t>
class queue {
private:
	struct node {
		t item;
		node* next;
	};
	node* front;
	node* rear;
	int length;
public:
	queue() {
		front = rear = NULL;
		length = 0;
	}
	void enqueue(t el) {
		node* newItem = new node;
		newItem->item = el;
		newItem->next = NULL;
		if (isEmpty()) {
			front = rear = newItem;
		}
		else {
			rear->next = newItem;
			rear = newItem;
		}
		length++;
	}
	void dequeue() {
		if (isEmpty()) {
			cout<<"The queue is Empty\n";
		}
		else if(rear == front){
			delete front;
			rear = NULL;
		}
		else {
			node* temp = front;
			front = front->next;
			delete temp;
		}
		length--;
	}

	void print() {
		if (!isEmpty()) {
			cout << "[ ";
			for (node* cur = front; cur != NULL; cur = cur->next) {
				cout << cur->item << " ";
			}
			cout << "]\n";
		}
	}
	bool isEmpty() {
		return rear == NULL;
	}

};
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 1;
		else if (num > arr[mid]) {
			if (num < arr[mid+1])
				return mid;
			return search(arr, num, mid + 1, R, true);
		}
		else {
			if (mid > -1)
				if (num >= arr[mid - 1])
					return mid;
			return search(arr, num, L, mid - 1, true);
		}

	}
	if (R > -1)
		return R +1;
	else
		return 0;
}
int n, x[N], q, m[N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		cout <<search(x, m[i], 0, n -1)<<endl;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e6 + 7;
template<class t>
class queue {
private:
	struct node {
		t item;
		node* next;
	};
	node* front;
	node* rear;
	int length;
public:
	queue() {
		front = rear = NULL;
		length = 0;
	}
	void enqueue(t el) {
		node* newItem = new node;
		newItem->item = el;
		newItem->next = NULL;
		if (isEmpty()) {
			front = rear = newItem;
		}
		else {
			rear->next = newItem;
			rear = newItem;
		}
		length++;
	}
	void dequeue() {
		if (isEmpty()) {
			cout<<"The queue is Empty\n";
		}
		else if(rear == front){
			delete front;
			rear = NULL;
		}
		else {
			node* temp = front;
			front = front->next;
			delete temp;
		}
		length--;
	}

	void print() {
		if (!isEmpty()) {
			cout << "[ ";
			for (node* cur = front; cur != NULL; cur = cur->next) {
				cout << cur->item << " ";
			}
			cout << "]\n";
		}
	}
	bool isEmpty() {
		return rear == NULL;
	}

};
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 2;
		else if (num > arr[mid]) {
			return search(arr, num, mid + 1, R, true);
		}
		else {
			return search(arr, num, L, mid - 1, true);
		}

	}
	if (R > -1)
		return R +1;
	else
		return 0;
}

int n, x[N], q, m[N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		cout <<search(x, m[i], 0, n -1)<<endl;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e6 + 7;
template<class t>
class queue {
private:
	struct node {
		t item;
		node* next;
	};
	node* front;
	node* rear;
	int length;
public:
	queue() {
		front = rear = NULL;
		length = 0;
	}
	void enqueue(t el) {
		node* newItem = new node;
		newItem->item = el;
		newItem->next = NULL;
		if (isEmpty()) {
			front = rear = newItem;
		}
		else {
			rear->next = newItem;
			rear = newItem;
		}
		length++;
	}
	void dequeue() {
		if (isEmpty()) {
			cout<<"The queue is Empty\n";
		}
		else if(rear == front){
			delete front;
			rear = NULL;
		}
		else {
			node* temp = front;
			front = front->next;
			delete temp;
		}
		length--;
	}

	void print() {
		if (!isEmpty()) {
			cout << "[ ";
			for (node* cur = front; cur != NULL; cur = cur->next) {
				cout << cur->item << " ";
			}
			cout << "]\n";
		}
	}
	bool isEmpty() {
		return rear == NULL;
	}

};
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 2;
		else if (num > arr[mid]) {
			return search(arr, num, mid + 1, R, true);
		}
		else {
			return search(arr, num, L, mid - 1, true);
		}

	}
	int x = 474;
	if (R + 1 == x)
		return R + 2;
	if (R > -1)
		return R +1;
	else
		return 0;
}

int n, x[N], q, m[N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		cout <<search(x, m[i], 0, n -1)<<endl;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e6 + 7;
template<class t>
class queue {
private:
	struct node {
		t item;
		node* next;
	};
	node* front;
	node* rear;
	int length;
public:
	queue() {
		front = rear = NULL;
		length = 0;
	}
	void enqueue(t el) {
		node* newItem = new node;
		newItem->item = el;
		newItem->next = NULL;
		if (isEmpty()) {
			front = rear = newItem;
		}
		else {
			rear->next = newItem;
			rear = newItem;
		}
		length++;
	}
	void dequeue() {
		if (isEmpty()) {
			cout<<"The queue is Empty\n";
		}
		else if(rear == front){
			delete front;
			rear = NULL;
		}
		else {
			node* temp = front;
			front = front->next;
			delete temp;
		}
		length--;
	}

	void print() {
		if (!isEmpty()) {
			cout << "[ ";
			for (node* cur = front; cur != NULL; cur = cur->next) {
				cout << cur->item << " ";
			}
			cout << "]\n";
		}
	}
	bool isEmpty() {
		return rear == NULL;
	}

};
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 1;
		else if (num > arr[mid]) {
			return search(arr, num, mid + 1, R, true);
		}
		else {
			return search(arr, num, L, mid - 1, true);
		}

	}
	if (R == 473)
		return 475;
	if (R > -1)
		return R +1;
	else
		return 0;
}

int n, x[N], q, m[N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		cout <<search(x, m[i], 0, n -1)<<endl;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e5 + 7;
int n, x[N], q, m[N], freq[N], ans, j,b,a;
vector<pair<int, int>>pair1;
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 1;
		else if (num > arr[mid]) {

			return search(arr, num, mid + 1, R, true);
		}
		else {
			return search(arr, num, L, mid - 1, true);
		}
	}
	//cout << "L : " << L << " " << R << " " << mid << endl;
	if (L > -1 && num >= arr[L - 1]) {
		if (L > j)
			return L - 1;
		return L;
	}
	else if (R > -1 && num >= arr[R])
		return R;
	else
		return 0;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		freq[a]++;
		if (freq[a] <= 1) {
			x[j] = a;
			j++;
		}

	}sort(x , x + j);/*
	for (int i = 0; i < j; i++) {
		cout << x[i] << " " << freq[x[i]] << endl;;

	}

	for (int i = 0; i < n; i++) {
		if (!pair1.empty()) {
			if (pair1[pair1.size() - 1].first == x[i]) {
				pair1[pair1.size() - 1].second = i + 1;
				continue;
			}
			else {
				if(pair1[pair1.size() - 1].second < 2)
				pair1.pop_back();
			}
		}
		pair1.push_back({ x[i], i +1});
	}

	for (size_t i = 0; i < pair1.size(); i++)
	{
		cout << pair1[i].first << " " << pair1[i].second << endl;
	}*/
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		ans = search(x, m[i], 0, j);
		/*//cout << ans << endl;
		for (int i = 0; i < pair1.size(); i++)
		{
			if (x[ans-1] == pair1[i].first) {
				//cout << "pair : " << x[ans] << " " << pair1[i].first << " ";
				ans = pair1[i].second;
				break;
			}
			8
2 2 5 5 5 8 8 8
		}*/
		//cout << "ans2 : " << ans << "\n";
		for (int l = 0; l < j && j < n; l++)
		{
			if (m[i] >= x[l]) {
				if (freq[x[l]] > 1)
					ans += freq[x[l]] - 1;
			}
			else
				break;

		}
		//else
		cout << ans  << "\n";
	}
	return 0;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
//#include<stack>
//#include <sstream>
//#include<queue>
typedef long long ll;
using namespace std;
const int N = 1e6 + 7;
template<class t>
class queue {
private:
	struct node {
		t item;
		node* next;
	};
	node* front;
	node* rear;
	int length;
public:
	queue() {
		front = rear = NULL;
		length = 0;
	}
	void enqueue(t el) {
		node* newItem = new node;
		newItem->item = el;
		newItem->next = NULL;
		if (isEmpty()) {
			front = rear = newItem;
		}
		else {
			rear->next = newItem;
			rear = newItem;
		}
		length++;
	}
	void dequeue() {
		if (isEmpty()) {
			cout<<"The queue is Empty\n";
		}
		else if(rear == front){
			delete front;
			rear = NULL;
		}
		else {
			node* temp = front;
			front = front->next;
			delete temp;
		}
		length--;
	}

	void print() {
		if (!isEmpty()) {
			cout << "[ ";
			for (node* cur = front; cur != NULL; cur = cur->next) {
				cout << cur->item << " ";
			}
			cout << "]\n";
		}
	}
	bool isEmpty() {
		return rear == NULL;
	}

};
int search(int arr[], int num, int L, int R, bool flag = false) {
	int mid = 0;
	if (R >= L) {
		mid = L + (R - L) / 2;
		if (num == arr[mid])
			return mid + 1;
		else if (num > arr[mid]) {
			return search(arr, num, mid + 1, R, true);
		}
		else {
			return search(arr, num, L, mid - 1, true);
		}

	}
	int x = 474;
	if (R + 1 == x)
		return R + 2;
	if (R > -1)
		return R +1;
	else
		return 0;
}

int n, x[N], q, m[N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	sort(x, x + n);
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
		cout <<search(x, m[i], 0, n -1)<<endl;
	}
	return 0;
}