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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)cin >> a[i];
  int ans = 1<<30;
  for(int i = 0; i < 1<<(n-1); i++){
    int orr = 0;
    int xorr = 0;
    for(int j = 0; j < n; j++){
      orr |= a[j];
      if(i>>j&1){
        xorr ^= orr;
        orr = 0;
      }
    }
    xorr ^= orr;
    ans = min(xorr,ans);
  }
  cout << ans << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    map<ll,ll> mp;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]%200]++;
    }
    ll ans=0;
    for(auto u: mp)
    {
        ans+=u.second*(u.second-1)/2;
    }
    cout<<ans;

    return 0;
}


#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;

    vector<int> res(n + 1, 1);
    for (int i = 1; i <= n; ++i) {
        for (int j = i + i; j <= n; j += i) {
            if (res[j] == res[i]) {
                ++res[j];
            }
        }
    }

    // for (int i = 1; i <= n; ++i) {
    //     for (int j = i + i; j <= n; j += i) {
    //         assert(res[j] != res[i]);
    //     }
    // }
    for (int i = 1; i <= n; ++i) {
        cout << res[i] << ' ';
    }
    cout << '\n';

    return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define per(i,a,b) for(ll i=(a);i>=(b);i--)
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)
#define next Cry_For_theMoon
#define il inline
#define pb(x) push_back(x)
#define mapit map<int,int>::iterator
#define vit vector<int>::iterator
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double db;
using namespace std;
const int MAXN=1e5+10;
int n,size[MAXN],ans;
int color[MAXN];
vector<int>v[MAXN];
int main(){
	cin>>n;
	rep(i,1,n){
		sort(v[i].begin(),v[i].end());
		color[i]=1;int pre=-1;
		for(vit it=v[i].begin();it!=v[i].end();it++){
			if(*it==pre)continue;
			pre=*it;
			if(color[i]==*it)color[i]++;
			else break;
		}
		rep(j,2,n){
			if(j*i>n)break;
			v[j*i].pb(color[i]);
		}
	}
	rep(i,1,n)printf("%d ",color[i]);
	return 0;
}


#include <bits/stdc++.h>

#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

using namespace std;
using ll = long long;
using pii = pair<int, int>;
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin>>a>>b;
    auto cal=[](int a) {
        int sum=0;
        while (a) {
            sum+=a%10;
            a/=10;
        }
        return sum;
    };
    cout<<max(cal(a), cal(b));
    return 0;
}

// check whether to use mod or not while using power
// if string is given initialise n with length
// cout << fixed << setprecision(12) << ans << endl;... to print decinmal values accurately

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define float long double
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define mem(v,x) memset(v,x,sizeof(v))
#define line cout<<endl;
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef set<ll> sll;
typedef priority_queue<ll> pqll;
typedef queue<ll> qll;

const ll mod = 1e9 + 7;
const ll inf = 1e16 + 7;
// const ll mxn = 1e3 + 7;
// vll adj[mxn];

ll power(ll a, ll b);
ll flcm(ll n, ll m);
ll fgcd(ll n, ll m);
ll modinv(ll x);

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS
	ll n, m, k, u, v, t = 1, temp, ans = 0, flag = 1, c = 0, min_el, max_el, sum_el;
	string s, s1, s2;
	// cin >> t;
	while (t--) {
		ans = 0;
		c = 0;
		flag = 1;
		sum_el = 0;
		cin >> n >> m;
		ll sum1 = 0, sum2 = 0;
		while (n != 0) {
			sum1 += (n % 10);
			n /= 10;
		}
		while (m != 0) {
			sum2 += (m % 10);
			m /= 10;
		}
		cout << max(sum1, sum2) << endl;

	}
	return 0;
}

ll power(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b % 2) {
			res = (res * a) % mod;
		}
		a = (a * a) % mod;
		b /= 2;
	}
	return res;
}

ll flcm(ll n, ll m) {

	ll temp = fgcd(n, m);
	return (n * m) / temp;
}

ll fgcd(ll n, ll m) {
	ll temp;
	while (m != 0) {
		temp = n;
		n = m;
		m = temp % m;
	}
	return n;
}

ll modinv(ll x) {
	return power(x, mod - 2);
}

// ctrl j to combine lines
// ctrl l to select line
// ctrl shift arrows for moving selected lines


#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " "
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int h, w, n, m, a, b, prv, ans=0;
	bool lt;
	vector< vector<int> > v;
	set<int> st;

	cin>> h >> w >> n >> m;
	v.resize(h+1);
	rep(i, h){
		v[i].resize(w+1);
		v[i][w]=-1;
	}
	v[h].resize(w+1, -1);

	rep(i, n){
		cin >> a >> b;
		v[a-1][b-1]=1;
	}
	rep(i, m){
		cin >> a >> b;
		v[a-1][b-1]=-1;
	}

	//rep(i, h+1) PV(v[i]);
	//cout<< endl;

	rep(i, h){
		prv=0;
		lt=false;
		rep(j, w+1){
			if(v[i][j]==1){
				lt=true;
			}
			if(v[i][j]==-1){
				if(lt){
					for(int k=prv;k<j;k++){
						if(v[i][k]!=1) v[i][k]=2;
					}
				}
				lt=false;
				prv=j+1;
			}
		}
	}

	//rep(i, h+1) PV(v[i]);
	//cout<< endl;

	rep(i, w){
		prv=0;
		lt=false;
		rep(j, h+1){
			//cout<< j << " " << i << " " << v[j][i] << " " << lt <<endl;
			if(v[j][i]==1){
				lt=true;
			}
			if(v[j][i]==-1){
				if(lt){
					for(int k=prv;k<j;k++){
						if(v[k][i]!=1) v[k][i]=2;
					}
				}
				lt=false;
				prv=j+1;
			}
		}
	}

	//rep(i, h+1) PV(v[i]);

	rep(i, h){
		rep(j, w){
			if(v[i][j]>0) ans++;
		}
	}

	cout<< ans <<endl;

	return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>

const ll mod = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> q[n];
    rep(i, m){
        int u, v, c;
        cin >> u >> v >> c;
        u--; v--;
        q[u].push_back(P(v, c));
        q[v].push_back(P(u, c));
    }
    vector<int> visited(n);
    vector<int> ans(n);
    visited[0] = 1;
    ans[0] = 1;
    queue<P> que;
    que.push(P(1, 0));
    while(que.size() > 0){
        P p = que.front();
        que.pop();
        int v = p.second;
        int num = p.first;
        rep(i, q[v].size()){
            int u = q[v][i].first;
            int nxt = q[v][i].second;
            if(visited[u] == 1) continue;
            if(ans[v] == nxt){
                if(nxt == 1) nxt++;
                else nxt--;
                visited[u] = 1;
                ans[u] = nxt;
                que.push(P(nxt, u));
            }else{
                ans[u] = nxt;
                visited[u] = 1;
                ans[u] = nxt;
                que.push(P(nxt, u));
            }
        }
    }
    rep(i, n){
        cout << ans[i] << endl;
    }
}


//Never stop trying
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

#define dbg(x) cerr << " - " << #x << " : " << x << endl;
#define dbgs(x,y) cerr << " - " << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << " - " << #v << " : " << endl << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;

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

int N,M;
int X[10][10];
int memo[10];

int solve(int i){
	if(memo[i]!=-1) return memo[i];
	int ans=0;
	FOR(j,i+1,N) ckmax(ans,solve(j)+X[i][j]);
	return memo[i]=ans;
}

int32_t main() {
	boost; IO();

	cin>>N>>M;
	vi w(N);
	FOR(i,0,N) cin>>w[i];
	sort(all(w));

	vpi vec;
	int mn_v=INF;
	FOR(i,0,M){
		int l,v; cin>>l>>v;
		ckmin(mn_v,v);
		vec.pb({v,l});
	}
	vec.pb({0,0});
	sort(all(vec));

	int mx[sz(vec)];
	FOR(i,0,sz(vec)){
		mx[i]=vec[i].se;
		if(i) ckmax(mx[i],mx[i-1]);
	}

	if(mn_v<w[N-1]){
		cout << -1 << endl;
		return 0;
	}

	int ans=INF;

	do{
		int pref[N];
		FOR(i,0,N){
			pref[i]=w[i];
			if(i) pref[i]+=pref[i-1];
		}

		FOR(i,0,N) FOR(j,i+1,N){
			int W=pref[j]; if(i) W-=pref[i-1];

			int idx; //max i such that vec[i].fi<W
			int l=0,r=sz(vec)-1;
			while(l<=r){
				int m=(l+r)/2;
				if(vec[m].fi<W){
					idx=m; l=m+1;
				}
				else r=m-1;
			}
			X[i][j]=mx[idx];
		}

		memset(memo,-1,sizeof(memo));
		ckmin(ans,solve(0));

	}while(next_permutation(all(w)));

	cout << ans << endl;

	return 0;
}

/* Careful!!!
	.Array bounds
	.Infinite loops
	.Uninitialized variables / empty containers
	.Order of input

   Some insights:
	.Binary search
	.Graph representation
	.Write brute force code
	.Change your approach
*/

#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define pb push_back
#define mk make_pair
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int n,m,i,j,k,g[105][105];
double ans;
int main()
{
	cin>>n;
	fz1(i,n){
		fz1(j,n){
			char c;
			cin>>c;
			g[i][j]=((i==j)||(c&1));
		}
	}
	fz1(k,n){
		fz1(i,n)fz1(j,n)g[i][j]|=(g[i][k]&g[k][j]);
	}
	fz1(i,n){
		int s=0;
		fz1(j,n)s+=g[j][i];
		ans+=1.0/s;
	}
	printf("%.12lf\n",ans);
	return 0;
}


#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 <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 2e5 + 5;
vector<int> adj[MAX];
int h[MAX], order[MAX], p[MAX];
bool covered[MAX];
int n, k;

void calc_h(int s) {
    for (int u : adj[s]) {
        if (u != p[s]) {
            h[u] = h[s] + 1;
            p[u] = s;
            calc_h(u);
        }
    }
}

void cover(int u, const int max_d, int cur_d = 0, int prev = -1) {
    covered[u] = true;
    if (cur_d == max_d) return;
    for (int v : adj[u]) {
        if (v == prev) continue;
        cover(v, max_d, cur_d + 1, u);
    }
}

bool ok(int d) {
    memset(covered, false, sizeof covered);
    int need = 0;
    fori (i, 0, n) {
        int u = order[i];
        if (covered[u]) continue;
        int y = u;
        while (y != 1 && h[u] - h[y] < d) {
            y = p[y];
        }
        cover(y, d);
        need++;
        if (need > k) return false;
    }
    return true;
}

void solve() {
    cin >> n >> k;
    fori (i, 0, n - 1) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    calc_h(1);

    iota(order, order + n, 1);
    sort(order, order + n, [&] (int lhs, int rhs) {
        return h[lhs] > h[rhs];
    });

    int left = 0, right = n;
    int ans = -1;
    while (left <= right) {
        int mid = (left + right) / 2;
        if (ok(mid)) {
            right = mid - 1;
            ans = mid;
        }
        else {
            left = mid + 1;
        }
    }
    assert(ans != -1);
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

#include<bits/stdc++.h>
#define N 200005
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cerr<<#x<<"="<<x<<endl;
#define db2(x,y) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int rd(){
    int res=0,c,f=0; while(!isdigit(c=getchar()))f=c=='-';
    do res=(res<<1)+(res<<3)+(c^48);
    while(isdigit(c=getchar()));
    return f?-res:res;
}
struct edge{int to,nxt;}e[N<<1];
int n,knum,head[N];
void link(int s,int t,int n){
    e[n]=(edge)<%t,head[s]%>;
    head[s]=n;
}
int v[N],dep[N];
struct cmp{bool operator ()(const int &a,const int &b){return dep[a]>dep[b];}};
int ffa[N][18];
void dfs(int x,int f,int d){
    ffa[x][0]=f,dep[x]=d;
    for(int i=1;1<<i<=n;i++)ffa[x][i]=ffa[ffa[x][i-1]][i-1];
    for(int i=head[x];i;i=e[i].nxt){
        int to=e[i].to;
        if(to==f)continue;
        dfs(to,x,d+1);
    }
}
int dis[N];
int Fa(int x,int d){
    for(int i=0;1<<i<=d;i++)if(1<<i&d)x=ffa[x][i];
    return !x?1:x;
}
void Mark(int x,int d){
    if(dis[x]==d)return;
    for(int i=head[x];i;i=e[i].nxt){
        int to=e[i].to;
        if(~dis[to]&&dis[to]<=dis[x]+1)continue;
        dis[to]=dis[x]+1,Mark(to,d);
    }
}
bool check(int k){
    int now=0;
    Ms(dis,-1);
    for(int i=1;i<=n;i++){
        int x=v[i];
        if(~dis[x])continue;
        ++now,x=Fa(x,k),dis[x]=0,Mark(x,k);
    }
    return now<=knum;
}
int main(){
    n=rd(),knum=rd();
    for(int i=1;i<n;i++){
        int s=rd(),t=rd();
        link(s,t,i<<1);
        link(t,s,i<<1|1);
    }
    dfs(1,0,1);
    for(int i=1;i<=n;i++)v[i]=i;
    sort(v+1,v+1+n,cmp());
    int l=1,r=n,res=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid))r=mid-1,res=mid;
        else l=mid+1;
    }
    printf("%d\n",res);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
//constexpr long long MOD = 1000000007;
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> C(n);
    rep(i, n){
        ll a; cin >> a; C[a]++;
    }
    vector<ll> box(k); ll last = k;
    rep(i, n){
        last = min(last, C[i]);
        rep(j, last)box[j] = i+1;
    }
    ll res = accumulate(all(box), 0LL);
    cout << res << ln;
}

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
map<ll,ll> mp;
ll a[maxn],f[maxn];
int main(){
	ll n,k;
	cin >> n >> k;
	ll cnt = 1;
	ll res=0,st=0;
	for(ll i=1;i<=n;i++){
		ll k;
		cin>>k;
		if(f[k]==0){
			a[cnt++] =k;
			f[k] =1;
		}
		mp[k]++;
	}
	sort(a+1,a+cnt);
	while(mp[0]){
		ll i=0;
		while(1){
			if(mp[i]!=0){
				mp[i]--;
			}
			else{
				res+=i;
				st++;
				break;
			}
			i++;
		}
		if(st == k) break;
	}
	cout << res;
	return 0;
}


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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int N;
	cin >> N;
    map<string, int> mp;
    rep(i,0,N){
        string s; cin >> s;
        if (s[0] == '!'){
            s = s.substr(1);
            mp[s] |= 1;
        }
        else
            mp[s] |= 2;
    }
    for(auto m:mp){
        if (m.second == 3){
            cout << m.first << endl;
            return 0;
        }
    }
    cout << "satisfiable\n";

}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll L[200200], R[200200];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	rep1(i, N) L[i] = 1e12;
	rep1(i, N) R[i] = -1e12;

	rep(i, N) {
		ll x, c;
		cin >> x >> c;
		chmin(L[c], x);
		chmax(R[c], x);
	}

	ll dp0 = 0, dp1 = 0;
	ll za0 = 0, za1 = 0;

	rep1(i, N) {
		if (L[i] > 1e10) continue;

		ll tugi0 = 1e18, tugi1 = 1e18;

		chmin(tugi1, dp0 + abs(L[i] - za0) + abs(L[i] - R[i]));
		chmin(tugi0, dp0 + abs(R[i] - za0) + abs(L[i] - R[i]));

		chmin(tugi1, dp1 + abs(L[i] - za1) + abs(L[i] - R[i]));
		chmin(tugi0, dp1 + abs(R[i] - za1) + abs(L[i] - R[i]));

		dp0 = tugi0;
		dp1 = tugi1;
		za0 = L[i];
		za1 = R[i];
	}

	co(min(dp0 + abs(za0), dp1 + abs(za1)));

	Would you please return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main ()
{
  int N;
  cin >> N;
  vector<int> data(N);
  rep(i, N)
  {
    cin >> data[i];
  }

  int ans = (1 << 30) + 1;
  for (int tmp = 0; tmp < (1 << N-1); tmp++)
  {
    bitset<20> S(tmp);
    S = (S << 1);
    vector<int> V(N);
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
      if (S.test(i))
      {
        cnt++;
      }
      V[cnt] |= data[i];
    }

    int XOR_V = 0;
    rep(i, N)
    {
      XOR_V ^= V[i];
    }

    ans = min(ans, XOR_V);
  }

  cout << ans << endl;
  return 0;
}

/*
    author : aryan57
    created : 27-June-2021 17:04:11 IST
*/
#include <bits/stdc++.h>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);

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

    vector <int> v(n+1);
    vector <int> pre(n+1);

    F(i,1,n)
    {
        cin>>v[i];
        pre[i]+=pre[i-1]+v[i];
    }
    vector< vector<int> > dp_sum(n+1,vector <int> (n));
    vector< vector<int> > dp(n+1,vector <int> (n+1));
    dp[1][1]=1;
    int ans=0;
    F(i,1,n)
    {
        F(j,1,n)
        {
            if(j==1)
            {
                dp[i][j]=1;
            }
            else
            {
                dp[i][j]=dp_sum[j-1][pre[i]%j];
            }

            if(i==n)
            {
                ans+=dp[i][j];
                ans%=M;
            }
        }

        F(j,1,n-1)
        {
            dp_sum[j][pre[i]%(j+1)]+=dp[i][j];
            dp_sum[j][pre[i]%(j+1)]%=M;
        }
    }

    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOG();
    }
    return 0;
}
//	parsed : 27-June-2021 17:03:51 IST


#include <bits/stdc++.h>
using namespace std;
int n,m=INT_MAX,cnt;
vector<int>a;
set<int>d;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1,x;i<=n;i++)cin>>x,a.push_back(x);
	for(int i=0;i<a.size();i++){
		m=min(m,a[i]);
		for(int j=1;j*j<=a[i];j++)
			if(a[i]%j==0)d.insert(j),d.insert(a[i]/j);
	}
	for(set<int>::iterator it=d.begin();it!=d.end();it++){
		int i=*it;
		if(i<=m){
			int g=0;
			for(int j=0;j<a.size();j++)
				if(a[j]%i==0)g=__gcd(g,a[j]);
			if(g==i)cnt++;
		}
	}
	cout<<cnt<<endl;

	return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define repi(i, ini, N) for(int i = ini; i < N; i++)
#define chmax(i, j) i = max(i, j)
#define chmin(i, j) i = min(i, j)
typedef long long ll;

int N;

int main() {
    vector<pair<int, string> > v;
    cin >> N;
    rep(i, N){
        int T;
        string S;
        cin >> S >> T;

        v.push_back(make_pair(T, S));
    }

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

    cout << v[v.size()-2].second << endl;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;

//    vector<ll> A(N), B(N);
    vector<pair<ll, ll>> friends(N);
    for (int i = 0; i < N; ++i) {
        cin >> friends.at(i).first >> friends.at(i).second;
//        cin >> A.at(i) >> B.at(i);
    }

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

    ll money = K;

    ll pos = 0;

    for (int i = 0; i < N; ++i) {
//        if(pos + money < A.at(i)){
//            cout << pos + money << endl;
//            return 0;
//        }else{
//            money = money - (A.at(i) - pos) + B.at(i);
//            pos = A.at(i);
//        }

        if(pos + money < friends.at(i).first){
            cout << pos + money << endl;
            return 0;
        }else{
            money = money - (friends.at(i).first - pos) + friends.at(i).second;
            pos = friends.at(i).first;
        }
    }

    cout << pos + money << endl;
    return 0;
}

#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F(w,x,y) for(ll w=x; w<y; w++)
#define endl "\n"
#define mod 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

void play()
{
    ll n,k;
    cin>>n>>k;
    ll sum=k;
    vector <pair<ll,ll>> v(n);
    F(i,0,n)
    {
        cin>>v[i].first>>v[i].second;
    }
    sort(all(v));
    F(i,0,n)
    {
        if(sum<v[i].first)
            break;
        else
            sum+=v[i].second;
    }
    cout<<sum<<endl;
}

int main()
{
    //freopen("milkvisits.in","r",stdin);
    //freopen("milkvisits.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //pre();
    ll t;
    t=1;
    //cin>>t;
    F(i,1,t+1)
    {
        //cout<<"Case #"<<i<<": ";
        play();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define For(i,a,b) for(register int i=a;i<=b;++i)
#define Down(i,a,b) for(register int i=a;i>=b;i--)
#define reg register
inline int min(int x,int y){return x<y?x:y;}
inline int max(int x,int y){return x>y?x:y;}
inline void swap(int &x,int &y){int t=x; x=y; y=t; return ;}
namespace yspm{
	inline int read(){
		int res=0,f=1; char k;
		while(!isdigit(k=getchar())) if(k=='-') f=-1;
		while(isdigit(k)) res=res*10+k-'0',k=getchar();
		return res*f;
	}
	int mod;
	int p[10]={1,1,4,4,2,1,1,4,4,2};
	int bas[10]={0,1,6,1,6,5,6,1,6,1};
	inline int ksm(int x,int y){
		int res=1%mod; x%=mod; for(;y;y>>=1,x=x*x%mod) if(y&1) res=res*x%mod;
		return res;
	}
	signed main(){
		int a=read()%10,b=read(),c=read();
		mod=p[a]; int ans=bas[a];
		int res=ksm(b,c);
		for(reg int i=1;i<=res;++i) ans=ans*a%10;
		cout<<ans<<endl;
		return 0;
	}
}
signed main(){return yspm::main();}

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

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 400005

int n;
int a[MAXN];
priority_queue<ii> pq;
char type[2];
bool impt[MAXN];
string ans;

int main() {
	scanf("%d", &n);
	REP (i, 0, n * 2) {
		scanf("%d", &a[i]);
		pq.push(MP(a[i], i));
	}
	REP (i, 0, n) {
		auto [_, id] = pq.top(); pq.pop();
		impt[id] = 1;
	}
	int cnt = 0;
	REP (i, 0, n * 2) {
		if (cnt == 0) {
			type[impt[i]] = '(';
			type[1 - impt[i]] = ')';
		}
		ans += type[impt[i]];
		if (type[impt[i]] == '(') {
			cnt++;
		} else {
			cnt--;
		}
	}
	printf("%s\n", ans.c_str());
	return 0;
}


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

#define rep(i,a,b) for(int i = a; i < (b);++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

typedef long long ll;

const int MAX_N = 1e5+1;

ll a[MAX_N];

int main(){
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    int n,q;
    cin>>n>>q;
    for (int i = 0; i < n; i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll k;
    for (int i = 0; i < q; i++){
        cin>>k;
        ll lb = 0;ll ub = 1e18+1e6;
        while (lb < ub -1){
            ll mid = (lb+ub)/2;
            ll d = lower_bound(a,a+n,mid) - a;
            if(mid - d > k){
                ub = mid;
            }else{
                lb = mid;
            }
        }
        cout<<lb<<endl;
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

using ll = long long;
using P = pair<int, int>;

void solve() {
    ll N, Q;
    cin >> N >> Q;
    vector<ll> A(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    vector<ll> exceptA(N);
    ll pre = 0;

    for (ll i = 0; i < N; i++)
    {
        exceptA[i] = A[i] - i - 1;
    }

    vector<ll> ans;
    for (size_t i = 0; i < Q; i++)
    {
        ll k;
        cin >> k;
        if (k < A[0]) {
            ans.emplace_back(k);
            continue;
        }
        ll index = lower_bound(exceptA.begin(), exceptA.end(), k) - exceptA.begin();
        ll plus = k - exceptA[index - 1];
        ll ex_num = A[index - 1] + plus;
        ans.emplace_back(ex_num);

    }
    for (auto v : ans)cout << v << endl;
    //return 0;
}

int main()
{
    solve();
    return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint v,t,s,d;
    cin >> v >> t >> s >> d;
    cout << (!(v*t<=d&&d<=v*s)?"Yes":"No") << "\n";
    return 0;
}

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

int V, T, S, D;

int main() {
	scanf("%d%d%d%d", &V, &T, &S, &D);
	printf(D < V * T || D > V * S ? "Yes" : "No");
	return 0;
}


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

using ll=long long;

int main(){
    ll N,C;
    cin >> N >> C;
    map<int,ll> P;
    for(int i=0;i<N;i++){
        int A,B,C;
        cin >> A >> B >> C;
        P[A]+=C;
        P[B+1]-=C;
    }
    ll S=0;
    ll ans=0;
    ll prev=0;
    for(auto it=P.begin();it!=P.end();it++){
        ll A=(*it).first;
        ll B=(*it).second;
        ans+=min(C,S)*(A-prev);
        prev=A;
        S+=B;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
#include <typeinfo>

//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int

//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long inf = 1000000000000000000;

using namespace std;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void init()
{

}

void solve()
{
    int n;
    cin>>n;
    ll c;
    cin>>c;
    map<int, ll> mm1, mm2;
    vi v1, v2;
    vector<pair<ll, ll>> v;
    // vecot v1;
    rep(i,n)
    {
        int x, y, z;
        cin>>x>>y>>z;
        if(mm1[x]==0)
            v1.pb(x);
        mm1[x]+=z;
        if(mm1[y+1]==0)
            v1.pb(y+1);
        mm1[y+1]-=z;
    }
    trav(x,v1)
    {
        v.pb(mp(x,mm1[x]));
    }
    sort(all(v));
    ll cost = v[0].se;
    ll ans = 0;
    repu(i,1,v.size()-1)
    {
        ans += (v[i].fi-v[i-1].fi)*min(cost,c);
        cost += v[i].se;
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    init();
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define rep3(i, x, y) for(ll i = x; i < y; i++)
#define rep4(i, x) for(ll i = x; i >= 0; i--)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	return gcd(b, a % b);
}
//ax + by = cが整数解をもつための必要十分条件は c が gcd(a,b) で割り切れること。
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y, ll m) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= m; }
		x = x * x % m; y /= 2;
	}
	return res;
}
ll kaijyo[600005];
void nCkinit(ll n, ll m) {
	ll cnt = 1; kaijyo[0] = 1;
	for (int h = 1; h <= n; h++) { cnt *= h; cnt %= m; kaijyo[h] = cnt; }
}
ll nCk(ll n, ll k, ll m) {
	/*ll a = 1, b = 1;
	for (int h = 1; h <= n; h++) { a *= h; a %= m; }
	for (int h = 1; h <= k; h++) { b *= h; b %= m; }
	for (int h = 1; h <= n - k; h++) { b *= h; b %= m; }*/
	ll a = kaijyo[n], b = kaijyo[k] * kaijyo[n - k] % m;
	return a * modpow(b, m - 2, m) % m;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <ll, string> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct Point {
	ll x, y;
};
bool operator<(const Point& a1, const Point& a2) {
	if (a1.x < a2.x) return true;
	if (a1.x > a2.x) return false;
	if (a1.y < a2.y) return true;
	return false;
}
struct status {
	ll cost;
	ll x;
	ll y;

	bool operator<(const status& rhs) const { return cost < rhs.cost; };
	bool operator>(const status& rhs) const { return cost > rhs.cost; };
};

int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	//cout << fixed << setprecision(15);

	ll a, b; cin >> a >> b;
	if (a == b) { cout << a << endl; }
	else { cout << 3 - a - b << endl; }
	return 0;
}

// Problem: D - Kth Excluded
// Contest: AtCoder - AtCoder Beginner Contest 205
// URL: https://atcoder.jp/contests/abc205/tasks/abc205_d
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)

/*
	███████╗██╗░░░██╗░█████╗░██╗░░██╗██╗███╗░░██╗  ███╗░░██╗░█████╗░██████╗░░█████╗░██████╗░██╗░░░██╗
	██╔════╝██║░░░██║██╔══██╗██║░██╔╝██║████╗░██║  ████╗░██║██╔══██╗██╔══██╗██╔══██╗██╔══██╗╚██╗░██╔╝
	█████╗░░██║░░░██║██║░░╚═╝█████═╝░██║██╔██╗██║  ██╔██╗██║██║░░██║██████╦╝██║░░██║██║░░██║░╚████╔╝░
	██╔══╝░░██║░░░██║██║░░██╗██╔═██╗░██║██║╚████║  ██║╚████║██║░░██║██╔══██╗██║░░██║██║░░██║░░╚██╔╝░░
	██║░░░░░╚██████╔╝╚█████╔╝██║░╚██╗██║██║░╚███║  ██║░╚███║╚█████╔╝██████╦╝╚█████╔╝██████╔╝░░░██║░░░
	╚═╝░░░░░░╚═════╝░░╚════╝░╚═╝░░╚═╝╚═╝╚═╝░░╚══╝  ╚═╝░░╚══╝░╚════╝░╚═════╝░░╚════╝░╚═════╝░░░░╚═╝░░░
*/

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(), v.end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void yes(bool t = 1) { cout << yesno[t] << endl; }

const int mod = 1e9+7;
const int mxN = 2e6 + 5;
int n,q,m;
int a[mxN],b[mxN];
string s,t;

void code()
{
    cin>>n>>q;

	// code goes here
	for(int i=0;i<n;i++) cin>>a[i];

	while(q--){
		cin>>m;
		int numbers = 0;
		int prev = 0;

		while(upper_bound(a,a+n,m+numbers)-a!=prev){
			prev = upper_bound(a,a+n,m+numbers)-a;
			numbers = prev;
		}

		cout<<m+prev<<endl;

	}

}

int32_t main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   int t=1;
   // cin>>t;
   while(t--) code();

}


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

bool chk(string &s,int index){
    int i=0;
    int j= index;
    while(j>=i){
        if(s[i] != s[j])
            return false;
        i++;
        j--;
    }

    return true;

}

int main() {
int n;
cin>>n;
string s = to_string(n);
if(chk(s, s.size()-1))
cout<<"Yes";
else{
    int i=s.size()-1;
    for(;i>=0;i--){
        if(s[i]!='0')
            break;
    }
    if(i == s.size()-1)
        cout<<"No";
    else{
        if(chk(s,i))
            cout<<"Yes";
        else
            cout<<"No";
    }
}

}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}

//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll N;
	cin>>N;
	vector<ll> fib={1,1};
	int k=1;
	while(fib[k]+fib[k-1]<=N){
		fib.push_back(fib[k]+fib[k-1]);
		k++;
	}
	int M=fib.size();
	vector<int> c(M);
	for(int i=M-1;i>0;i--){
		while(N>=fib[i]){
			c[i]++;
			N-=fib[i];
		}
	}
	vector<ll> ans;
	for(int i=1;i<M;i++){
		int a=1,b=4;
		if((M-i)%2==1){
			a=2;
			b=3;
		}
		rep(j,c[M-i]) ans.push_back(a);
		ans.push_back(b);
	}
	cout<<ans.size()<<"\n";
	rep(i,ans.size()){
		cout<<ans[i]<<"\n";
	}

	/*ll X=0,Y=0;
	rep(i,ans.size()){
		if(ans[i]==1) X++;
		if(ans[i]==2) Y++;
		if(ans[i]==3) X+=Y;
		if(ans[i]==4) Y+=X;
		cout<<X<<" "<<Y<<endl;
	}*/
}


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

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tt=1;
	//cin >> tt;
	while(tt--)
	{
		int n;
		cin >> n;
		int a[n],b[n];
		for(int i=0;i<n;i++)
			cin >> a[i];
		for(int i=0;i<n;i++)
			cin >> b[i];
		pair<int,int> odd[n/2], even[n/2];
		for(int i=0;i<n;i++)
		{
			if(i%2==0)
				even[i/2]={a[i]-b[i],i};
			else
				odd[i/2]={a[i]-b[i],i};
		}
		sort(even,even+n/2);
		sort(odd,odd+n/2);
		int ans=0;
		for(int i=n/2-1;i>=0;i--)
		{
			if(even[i].first+odd[i].first>=0)
			{
				ans+=a[even[i].second]+a[odd[i].second];
			}
			else
			{
				ans+=b[even[i].second]+b[odd[i].second];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
namespace Ruri{
    #define ms(a,b) memset(a,b,sizeof(a))
    #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
    #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
    #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
    #define ce(i,r) i==r?'\n':' '
    #define pb push_back
    #define all(x) x.begin(),x.end()
    #define gmn(a,b) a=min(a,b)
    #define gmx(a,b) a=max(a,b)
    #define fi first
    #define se second
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    const int infi=1e9;//infi较大，注意涉及inf相加时爆int
    const ll infl=4e18;
    inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
    inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
    //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Ruri;
namespace Read{
    #define ss(a) scanf("%s",a)
    inline int ri(){ int x; scanf("%d",&x); return x; }
    inline ll rl(){ ll x;  scanf("%lld",&x); return x; }
    inline db rd(){ db x; scanf("%lf",&x); return x; }
}
namespace DeBug{
    #define pr(x) cout<<#x<<": "<<(x)<<endl
    #define pra(x,a,b) cout<<#x<<": "<<endl; \
            repi(i,a,b) cout<<x[i]<<" ";     \
            puts("");
    #define FR(a) freopen(a,"r",stdin)
    #define FO(a) freopen(a,"w",stdout)
}
using namespace Read;
using namespace DeBug;
const int MAX_N=1e5+5;
int n;
ll a[MAX_N],b[MAX_N];
vector<ll> rec[2];
int main()
{
	n=ri();
	ll ans=0;
	repi(i,1,n) a[i]=ri();
	repi(i,1,n) b[i]=ri(),ans+=b[i];

	repi(i,1,n) rec[i&1].pb(a[i]-b[i]);
	sort(all(rec[0])),sort(all(rec[1]));
	repi(i,0,n/2-1) ans+=max(0ll,rec[0][i]+rec[1][i]);
	printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int main()
{
	cin>>n>>a>>b;
	cout<<n-a+b;
}

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

using ll = long long;
using ld = long double;

int sled0[500005];
int sled1[500005];
int mvs[500005];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string aa = s, bb = t;
    sort(aa.begin(), aa.end());
    sort(bb.begin(), bb.end());
    if(aa != bb){
        cout << -1;
        return 0;
    }
    vector <int> p;
    vector <int> d;
    for(int i=0; i<n; i++){
        if(s[i] == '0') p.push_back(i);
        if(t[i] == '0') d.push_back(i);
    }
    int res = 0;
    for(int i=0; i<p.size(); i++){
        if(p[i] != d[i]) res++;
    }
    cout << res;
    return 0;
}


//==================================================================//
#define _CRT_SECURE_NO_WARNINGS
//==================================================================//
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;
#define sz(s)               (int)s.size()
#define clr(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define RT(x)           return cout<<x,0;
#define endl                         '\n'
#define INF 0x3f3f3f3f3f3f3f3fLL
#define OO  0x3f3f3f3f
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define popcount(n) __builtin_popcount(n)
#pragma optimization_level 3
#define lft n<<1
#define ryt n<<1|1
#pragma GCC optimize("Ofast,no-stack-protector,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

//==================================================================//

//==================================================================//
const int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
template<typename T>
using Graph = vector<vector<T>>;
typedef long long ll;
typedef unsigned long long ull;
//==================================================================//

//==================================================================//
void printDouble(double f, int p) {
	cout << fixed;
	cout << setprecision(p) << f << endl;
}
int  Set(int N, int cur) { return N = N | (1 << cur); }
int  Reset(int N, int cur) { return N = N & ~(1 << cur); }
bool Check(int N, int cur) { return (bool)(N & (1 << cur)); }
ll   GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); }
ll   LCM(ll a, ll b) { return (a / GCD(a, b)) * b; }
ll   POW(ll a, ll p) {
	ll res = 1, x = a; while (p) {
		if (p & 1)
			res = (res * x); x = (x * x); p >>= 1;
	} return res;
}
//==================================================================//

//==================================================================//
void run() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#else
		//freopen("restore.in", "r", stdin);
#endif
}
#define rep(i, n) for (int i = 0; i < (n); ++i)

//==================================================================//
const int N = 1e5 + 5, M = 40, mod = 1e9 + 7;

int main() {
	run();
	double x,y;
	cin>>x>>y;
	double ans = x-y;
	ans/=x;
	cout<<fixed<<setprecision(3);
	cout<<ans*100.0;

}

// Author: wlzhouzhuan
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fir first
#define sec second
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, t) memset(s, t, sizeof(s))
#define mcpy(s, t) memcpy(s, t, sizeof(t))
template<typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; }
int read() {
  int x = 0, f = 0; char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
template<typename T> void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template<typename T> void print(T x, char let) {
  print(x), putchar(let);
}

vector<int> ans;

int main() {
  ans.pb(6), ans.pb(10), ans.pb(15);
  for (int i = 12; i <= 10000; i += 6) ans.pb(i);
  for (int i = 20; i <= 10000; i += 10) {
    if (i % 6 != 0) ans.pb(i);
  }
  for (int i = 30; i <= 10000; i += 15) {
    if (i % 6 != 0 && i % 10 != 0) {
      ans.pb(i);
    }
  }
  int n = read();
  for (int i = 0; i < n; i++) print(ans[i], ' ');
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

void get(ll i, ll arr[], ll n, ll xo, ll o, ll &ans)
{
    if(i == n)
    {
        ans = min(ans, xo^o);
        return;
    }

    get(i+1, arr, n, xo, o|arr[i], ans);
    get(i+1, arr, n, xo^o, arr[i], ans);
}

const ld PI = acos(-1);

int main()
{
  FAST/**/

  ll n;
  cin>>n;

  pii arr[n];
  rep(n)
        cin>>arr[i].ff>>arr[i].ss;
  vector<ll> hold[n+1];
  rep(n)
        hold[arr[i].ss].pb(arr[i].ff);
  rep(n+1)
        sort(hold[i].begin(), hold[i].end());
  hold[0].pb(0);
  map<ll,ll> ma[n+1];
  ma[0][0] = 0;
  map<ll, ll> prev = ma[0];
  for(ll i=1;i<=n;i++)
  {
      if(hold[i].size() == 0)
            continue;
      ll x1 = hold[i][0], y1 = hold[i].back();
      ma[i][x1] = ma[i][y1] = inf;
      autoit(prev, it)
      {
          //cout<<"for "<<i<<" , "<<it->ff<<" = "<<it->ss<<'\n';
          ll curr = it->ff, cd = it->ss;
          ma[i][x1] = min(ma[i][x1], cd + abs(curr-y1) + abs(y1-x1));
          ma[i][y1] = min(ma[i][y1], cd + abs(curr-x1) + abs(y1-x1));
      }

      prev = ma[i];
  }

  ll ans = inf;
  autoit(prev,it)
        ans = min(ans, it->ss + abs(it->ff));
  cout<<ans<<'\n';

  return 0;
}

#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>
#include <tuple>
//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long int;
// 任意長型
//namespace mp = boost::multiprecision;
//using Real = mp::number<mp::cpp_dec_float<128>>;
//using Bint = mp::cpp_int;

int main(int argc, char *argv[])
{
	//input
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	//calc
	while (1 <= k){
		string nextS;
		s = s + s;
		if (s.size() % 2){
			s = s + s;
		}

		for (unsigned int i = 0; i < s.size(); i += 2){
			if (s[i] == s[i + 1]){
				nextS.push_back(s[i]);
			}
			else if (s[i] == 'R' && s[i + 1] == 'S'){
				nextS.push_back('R');
			}
			else if (s[i] == 'P' && s[i + 1] == 'R'){
				nextS.push_back('P');
			}
			else if (s[i] == 'S' && s[i + 1] == 'P'){
				nextS.push_back('S');
			}
			else if (s[i] == 'S' && s[i + 1] == 'R'){
				nextS.push_back('R');
			}
			else if (s[i] == 'R' && s[i + 1] == 'P'){
				nextS.push_back('P');
			}
			else if (s[i] == 'P' && s[i + 1] == 'S'){
				nextS.push_back('S');
			}
		}
		s = nextS;

		k--;
	}

	//ans
	cout << s[0] << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,m;
    cin >> n >> k >> m;
    int sum = 0;
    for(int i = 0; i < n-1; ++i){
        int a;
        cin >> a;
        sum += a;
    }
    int ans = n*m-sum;
    if(ans > k){
        ans = -1;
    }else if(ans < 0){
        ans = 0;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds; // find_by_order(), order_of_key()
template<typename TK> using pbds_set = tree<TK, null_type, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename TK, typename TV> using pbds_map = tree<TK, TV, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
*/

int main()
{
    lint N;
    cin >> N;
    lint K;
    cin >> K;
    lint M;
    cin >> M;
    vector<lint> A(N - 1);
    cin >> A;
    lint ret = M * N - accumulate(ALL(A), 0LL);
    if (ret > K) puts("-1");
    else if (ret <= 0) puts("0");
    else cout << ret << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define setbit0(n, i) ((n) & (~(1LL << (i))))
#define setbit1(n, i) ((n) | (1LL << (i)))
#define togglebit(n, i) ((n) ^ (1LL << (i)))
#define lastone(n) ((n) & (-(n)))
char gap = 32;
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for (const auto &x : v) os << gap << x;
        return os << '}';
}
template<typename A, typename B>
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
#define mod 1000000007
long gcdExtended(long a, long b, long *x, long *y)
    {
        // Base Case
        if (a == 0)
        {
            *x = 0, *y = 1;
            return b;
        }

        long x1, y1; // To store results of recursive call
        long gcd = gcdExtended(b%a, a, &x1, &y1);

        *x = y1 - (b/a) * x1;
        *y = x1;

        return gcd;
    }
long modInverse(long a, long m)
    {
        long x, y;
        long g = gcdExtended(a, m, &x, &y);

            long res = (x%m + m) % m;
        return res;
    }
void solve(){
    ll i,j,k,l,n,m,s;
    cin>>n>>s>>k;
    ll kola = n-s;
    ll GCD=__gcd(__gcd(kola,k),n);
    kola/=GCD;
    k/=GCD;
    n/=GCD;
    if(__gcd(k,n)!=1){
        cout<<"-1\n";
        return;
    }
    ll ans = (kola*modInverse(k,n))%n;
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <set>
#include <functional>
#include <map>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
using Interval = pair<ll,ll>;
using Graph = vector<vector<ll> >;
#define fi first
#define se second

struct Edge{
    ll to;
    ll w;
    Edge(ll to, ll w):to(to),w(w){}
};

using wGraph = vector<vector<Edge> >;

template<class T> void chmax(T& a, T b){
    if (a < b){
        a=b;
    }
}

template<class T> void chmin(T& a, T b){
    if (a > b){
        a=b;
    }
}

template<class T> bool chmaxb(T& a, T b){
    if (a < b){
        a=b;
        return true;
    }
    return false;
}

template<class T> bool chminb(T& a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

const ll INF =  998244353;

string N;

int main(){
    cin >> N;
    ll add = 0;

    while(true){
        bool ok = true;
        rep(i,N.size()/2){
            if (N[i] != N[N.size()-1-i]){
                ok = false;
            }
        }
        if (ok){
            cout << "Yes" << endl;
            return 0;
        }
        else{
            N = "0"+N;
            add++;
        }
        if (add >= 15) break;
    }
    cout << "No" << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
const int N=2001;
ll n,m;
ll a[N];
vector<pair<ll,int> >pf;
vector<int>ans;
ll duh[100001];
ll mg[100001];
int d[31];
bool inc(int t){
	if(t==0) return true;
	d[pf.size()-1]++;
	int x=pf.size()-1;
	while(x>=0 && d[x]>pf[x].se){
		d[x]=0;
		x--;
		if(x<0) break;
		d[x]++;
	}
	return(x>=0);
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	//n=2000;
	for(int i=1; i<=n ;i++){
		cin >> a[i];
		//a[i]=2162160;
	}
	sort(a+1,a+n+1);
	if(a[1]==1){
		cout << "1\n";
		return 0;
	}
	int work=0;
	for(int i=1; i<=n ;i++){
		//if(i%100==0) cout << "doing " << i << ' '  << work << endl;
		ll z=a[i];
		pf.clear();
		for(int j=2; j*j<=a[i] ;j++){
			if(z%j!=0) continue;
			pf.push_back({j,0});
			while(z%j==0){
				pf.back().se++;
				z/=j;
				//work++;
			}
		}
		if(z!=1) pf.push_back({z,1});
		int mx=0;
		for(int k=0; inc(k) ;k++){
			duh[k]=0;
			mx=max(mx,k);
		}
		//cout << mx << endl;
		for(int j=1; j<=n ;j++){
			int y=0;
			int cnt=0;
			for(auto c:pf){
				ll z=c.fi;
				y*=(c.se+1);
				for(int p=1; p<=c.se ;p++){
					if(a[j]%z!=0) break;
					z=z*c.fi;y++;
					//work++;
					cnt++;
				}
			}
			//if(j==1) cout << i << ' ' << cnt << endl;
			duh[y]++;
		}/*
		cout << "doing " << i << ' ' << a[i] << endl;
		for(int k=0; inc(k) ;k++){
			cout << duh[k] << ' ' << d[0] << ' ' << d[1] << endl;

		}*/
		ll step=1;
		//cout << pf.size() << endl;
		for(int j=pf.size()-1; j>=0 ;j--){
			for(int k=0; inc(k) ;k++){
				work++;

				if(d[j]==0){
					if(j==pf.size()-1){
						for(int p=k+step*pf[j].se ;p>=k ;p-=step){
							mg[p]=1;
							//work++;
						}
					}
					for(int p=k+step; p<=k+step*pf[j].se ;p+=step){
						mg[p]=mg[p-step]*pf[j].fi;//work++;
					}
					for(int p=k+step*pf[j].se ;p>k ;p-=step){
						duh[p-step]+=duh[p];
						//work++;
					}
				}
			}
			step*=pf[j].se+1;
		}/*
		cout << endl;
		for(int k=0; inc(k) ;k++){
			cout << duh[k] << ' ' << d[0] << ' ' << d[1] << endl;

		}*/
		for(int k=0; inc(k) ;k++){
			ll step=1;
			bool ok=true;
			for(int j=pf.size()-1; j>=0 ;j--){
				work++;
				if(d[j]==pf[j].se){
					step*=pf[j].se+1;continue;
				}
				if(duh[k]==duh[k+step]) ok=false;
				step*=pf[j].se+1;
			}
			if(ok) ans.push_back(mg[k]);
		}
	}
	//cout << ans.size() << endl;
	sort(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());
	while(ans.back()>a[1]) ans.pop_back();
	cout << ans.size() << '\n';
}

#include <iostream>
#include <vector>
#include <limits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <algorithm>
#include <random>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <chrono>
#include <sstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii > vii;
typedef vector<vector<ll> > vvi;
typedef vector<vvi > vvvi;
typedef vector<vector<pair<ll, ll> > > vvii;
typedef ll func_ii_i(ll, ll);

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,s,e) for(ll i=(s);i<(e);++i)
#define repr(i,s,e) for(ll i=(e);i>(s);--i)
#define io do { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); } while (0)
#define endl '\n'
#define newl cout << '\n';

#define fill0(a) memset(a, 0, sizeof(a))
#define fill1(a) memset(a, -1, sizeof(a))

#define all(v) v.begin(), v.end()
#define bg begin()
#define ed end()
#define tr(it, v) for (auto it = v.bg; it != v.ed; it++)
#define prv(v) do { tr(it, v) { cout << *it << " "; }; cout << endl; } while (0)
#define prm(m) tr(it, m) { cout << it->first << " -> " << it->second << endl; }
#define scan(a, n) rep(i,0,n) cin >> a[i];
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define sumv(v) accumulate(all(v), 0ll)
#define ub(a, x) upper_bound(all(a), x)
#define lb(a, x) lower_bound(all(a), x)

#define tcT template<class T

ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }
ll mid3(ll a, ll b, ll c) { return a + b + c - min3(a, b, c) - max3(a, b, c); }
ll ceil1(ll x, ll y) { if(x % y) return (x + y) / y; else return x / y; }
tcT> void rmdup(vector<T> &v) { sort(all(v)); v.erase(unique(all(v)), v.ed); }
tcT> ll fst1(ll l, ll h, T f) {
	++h; // f is increasing
	while(l<h) {
		ll mi = l + ((h - l) >> 1);
		f(mi) ? h = mi : l = mi + 1;
	}
	return l;
}
tcT> ll lst1(ll l, ll h, T f) {
	--l; // f is decreasing
	while(l<h) {
		ll mi = l + ((h - l + 1) >> 1);
		f(mi) ? l = mi : h = mi - 1;
	}
	return l;
}

const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll TE3 = 1005;
const ll TE5 = 300005;
const ll dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const string YN[2] = {"NO", "YES"};

using namespace std;

void divisors(ll x,vi &u)
{
	if(x==1) {
		return;
	}
	for (ll d = 2; d * d <= x; ++d)
	{
		ll c = 0;
		if(x%d==0) {
			u.pb(d);
			if((d*d)!=x) {
				u.pb(x/d);
			}
		}
	}
}

// computes gcd(a,b)
ll gcd(ll a, ll b) {
	if(a<b)
		swap(a, b);
	while (b)
	{
		ll t = a % b;
		a = b;
		b = t;
	}
	return a;
}

int main()
{
	io;
	ll n;
	cin >> n;
	vi v(n);
	scan(v, n);
	sort(all(v));
	set<ll> ans;
	map<ll,ll> z;
	for (ll q: v) {
		vi u;
		divisors(q, u);
		u.pb(1);
		u.pb(q);
		rmdup(u);
		for(ll d: u) {
			if(z.count(d)) {
				z[d]=gcd(z[d], q);
			} else {
				z[d]=q;
			}
		}
	}
	for(auto it: z) {
		if(it.se && it.se<=v[0]) {
			ans.insert(it.se);
		}
	}
	cout<<ans.size()<<endl;
	// for(ll q: ans) {
	// 	cout<<q<<" ";
	// }
	// cout<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
typedef long long ll;
typedef std::vector<int> P;
typedef unsigned un;
ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return f*x;
}
using std::min;
using std::max;
template<typename T>bool umin(T& a,T t){if(a>t)return a=t,1;return 0;}
template<typename T>bool umax(T& a,T t){if(a<t)return a=t,1;return 0;}

const int MAXN = 111;
int a[MAXN],b[MAXN];
char s[MAXN];
int main()
{
	int n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n+1;++i)a[i]=read();
	for(int k=10000;k;--k)
	{
		bool fail=0;
		for(int i=1;i<=k&&!fail;++i)
		{
			b[1]=(a[1]/k+(i<=a[1]%k));
			for(int j=2;j<=n+1;++j)
			{
				b[j]=(a[j]/k+(i<=a[j]%k));
				if(s[j-1]=='>')fail|=b[j-1]<=b[j];
				else fail|=b[j-1]>=b[j];
			}
		}
		if(!fail)
		{
			printf("%d\n",k);
			for(int i=1;i<=k;puts(""),++i)
				for(int j=1;j<=n+1;++j)printf("%d ",a[j]/k+(i<=a[j]%k));
			return 0;
		}
	}
	puts("0");
	return 0;
}

/*
    author:  Maksim1744
    created: 10.04.2021 15:02:52
*/

#include "bits/stdc++.h"

using namespace std;

#define ll   long long
#define ld   long double

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

template<typename T>             vector<T>& operator--            (vector<T>& v){for (auto& i : v) --i;            return  v;}
template<typename T>             vector<T>& operator++            (vector<T>& v){for (auto& i : v) ++i;            return  v;}
template<typename T>             istream& operator>>(istream& is,  vector<T>& v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>& v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> pair<T,U>& operator--           (pair<T, U> &p){--p.first; --p.second;            return  p;}
template<typename T, typename U> pair<T,U>& operator++           (pair<T, U> &p){++p.first; ++p.second;            return  p;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}

#ifdef HOME
#define SHOW_COLORS
#include "C:/C++ libs/print.cpp"
#else
#define show(...)     42
#define mclock        42
#define shows         42
#define debug if (false)
#endif

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n;
    string s;
    cin >> n >> s;
    vector<int> a(n + 1);
    cin >> a;

    int k = 1e9;
    for (int i = 0; i < n; ++i)
        k = min(k, abs(a[i] - a[i + 1]));

    vector<vector<int>> b(k);
    for (int i = 0; i < k; ++i) {
        b[i].pb(a[0] / k);
    }
    for (int i = 0; i < a[0] % k; ++i) {
        b[i].back()++;
    }

    for (int i = 0; i < n; ++i) {
        if (a[i] < a[i + 1]) {
            int d = a[i + 1] - a[i];
            sort(b.begin(), b.end(), [&](const auto &a, const auto &b) {
                return a.back() < b.back();
            });
            for (int i = 0; i < k; ++i) {
                b[i].pb(b[i].back() + 1);
            }
            d -= k;
            for (int i = 0; i < d; ++i) {
                b[i % k].back()++;
            }
        } else {
            int d = a[i] - a[i + 1];
            sort(b.begin(), b.end(), [&](const auto &a, const auto &b) {
                return a.back() > b.back();
            });
            for (int i = 0; i < k; ++i) {
                b[i].pb(b[i].back() - 1);
            }
            d -= k;
            for (int i = 0; i < d; ++i) {
                b[i % k].back()--;
            }
        }
    }
    cout << k << '\n';
    for (auto v : b)
        cout << v << '\n';

    return 0;
}


#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")
#pragma GCC optimize("fast-math")
//#pragma GCC optimize("Ofast")
/*#pragma GCC optimize("section-anchors")
#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
#pragma GCC optimize("vpt")
#pragma GCC optimize("rename-registers")
#pragma GCC optimize("move-loop-invariants")
#pragma GCC optimize("unswitch-loops")
#pragma GCC optimize("function-sections")
#pragma GCC optimize("data-sections")
#pragma GCC optimize("branch-target-load-optimize")
#pragma GCC optimize("branch-target-load-optimize2")
#pragma GCC optimize("btr-bb-exclusive")*/
//#pragma GCC optimize("inline")
//#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <string>
#include <cstdint>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>//////////////
#include <ctime>
#include <climits>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define queuel queue<long long>
#define sqr(a) ((a) * (a))
#define lsqr(a) (ld(a) * a)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pin(p) cin >> p.first >> p.second;
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define rev(v) reverse(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL))
#define dab(v) for(auto i:v)cout<<i<<' ';
#define sp system("pause")
#define left left228
#define calc calc228
#define next next228
#define type type1337
#define right right228
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ld EPS = 1e-14	;
const ld EPS2 = 1e-12;
const ld PI = acos(-1);
int mod = (int)998244353;
const int MOD7 = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const ll INF = 1e18;
const int inf = 1e9;
mt19937 rnd(time(0));
const ll kekmod = 1791791791;
const ll bestmod = 1148822869;
const int MAXN = 101;
vector<int> rg[MAXN];
vector<int> used(MAXN);
int cnt = 0;
void dfs(int v)
{
	cnt++;
	used[v] = 1;
	for (int i : rg[v])
		if (!used[i]) dfs(i);
}
signed main()
{
	fastio();
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		for (int j = 0; j < n; ++j)
		{
			if (s[j] == '1')
			{
				rg[j].pbc(i);
			}
		}
	}
	ld ans = 0;
	for (int i = 0; i < n; ++i)
	{
		used.assign(MAXN, 0);
		cnt = 0;
		dfs(i);
		ans += (ld)1 / cnt;
	}
	cout << fixed << setprecision(20) << ans;
	sp;
}


//標準関数をすべてインクルードする。
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() {
    int A, B, W; cin >> A >> B >> W;
    int kW = W * 1000;

    int maxres =kW / A; int minres = (kW + (B - 1)) / B;

    if (maxres < minres) cout << "UNSATISFIABLE" << endl;
    else cout << minres << " " << maxres << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define inf 1e9
#define pi 3.1415926536
#define mod 1000000007
#define fr(i,a,b,in) for(int i=a;i<b;i+=in)
#define frn(i,a,b,dc) for(int i=a;i>=b;i-=dc)
#define test(t) int t; cin>>t; while(t--)
int main()
{
	fastio();
	int a,b;
	cin>>a>>b;
	int w;
	cin>>w;
	double w1=w*1000.0, a1=a*1.0, b1=b*1.0;
	int ans1=-1,ans2=1e8;
	// fr(i,a,b+1,1){
	// 	int m1=(w)/(i);
	// 	int n1=w%i;
	// 	double c1=(n1*1.0)/(m1*1.0);
	// 	if(double(i)+c1 <= double(b)){
	// 		ans1=max(ans1,int(m1));
	// 		ans2=min(ans2,int(m1));
	// 	}
	// }
	fr(i,1,1e6+1,1){
		double d=w1/double(i);
		if(d>=a1 && d<=b1){
			ans1=max(ans1,i);
			ans2=min(ans2,i);
		}
	}
	if(ans1==-1) cout<<"UNSATISFIABLE"<<endl;
	else cout<<ans2<<' '<<ans1<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define COUT(x) cout<<(x)<<endl
using vi = vector<int>;
using vvi = vector<vi>;
const int mod = 1e9+7;

int modPow(int a, int n) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % mod;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % mod;
  int t = modPow(a, n / 2);
  return (t * t) % mod;
}

signed main(){
    int L; cin >> L; L--;
    int N = L;
    int K = 11;

    vi comb(N+1);
    comb[0]=1;
    rep1(i,K+1){
        comb[i] = (comb[i-1]*(N-i+1)/i);
    }
    cout << comb[K] << endl;
    return 0;
}

#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>
#include <string.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

bool overflow_checker(long long int input_number1,long long int input_number2){
    if(5000000000000000000/input_number1<input_number2){
        return true;
    }else{
        return false;
    }
}

const long long int mod = 998244353;
const long long int INF = 2e18;
const long double PI=3.14159265358979323;
const long long int pl=1100;
const long double eps =0.00001;

long long int N,A[200200],B[200200],C;
long long int dp[402][402]={};

string S;
long long int mymin=INF,num=INF;
int main(){

    cout << fixed << setprecision(18);
    cin>>N;
    for (long long int i = 1; i < 300; i++)
    {
        dp[i][0]=1;
        dp[i][i]=1;
        for (long long int j = 1; j < i; j++)
        {
            dp[i][j]=dp[i-1][j]+dp[i-1][j-1];
        }

    }
    cout<<dp[N-1][11]<<endl;

}


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

using ll = long long;

class Edge{
public:
    int from, to;
    long long value;
    Edge(int a, int b, long long c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};

std::vector<long long> dijkstra(int s, int N, std::vector<Edge> E){
    std::vector<long long> ans(N, 1e18);
    std::vector<std::vector<Edge>> Edges(N);
    for(auto e : E){
        Edges.at(e.from).push_back(e);
    }
    std::priority_queue<std::pair<long long, int>, std::vector<std::pair<long long, int>>, std::greater<std::pair<long long, int>>> que;
    ans.at(s)= 0;
    que.push(std::make_pair(0, s));
    while(!que.empty()){
        std::pair<long long, int> p = que.top();
        que.pop();
        if(ans.at(p.second) < p.first)continue;
        for(int i = 0;i < Edges.at(p.second).size();i++){
                if(ans.at(p.second) + Edges.at(p.second).at(i).value < ans.at(Edges.at(p.second).at(i).to)){
                ans.at(Edges.at(p.second).at(i).to) = ans.at(p.second) + Edges.at(p.second).at(i).value;
                que.push(std::make_pair(ans.at(Edges.at(p.second).at(i).to),Edges.at(p.second).at(i).to));
            }
        }
    }
    return ans;
}

void solve(long long a, long long b, long long x, long long y){
    vector<Edge> Edges;
    for(int i = 0;i < 100;i++){
        Edges.push_back(Edge(i, i + 100, x));
    }
    for(int i = 0;i < 99;i++){
        Edges.push_back(Edge(i + 1, i + 100, x));
    }
    for(int i = 0;i < 99;i++){
        Edges.push_back(Edge(i, i + 1, y));
        Edges.push_back(Edge(i + 100, i + 100 + 1, y));
    }
    int q = Edges.size();
    for(int i = 0;i < q;i++){
        Edges.push_back(Edge(Edges[i].to, Edges[i].from, Edges[i].value));
    }
    vector<ll> dist = dijkstra(a - 1, 2 * 100, Edges);
    cout<<dist[(b - 1) + 100]<<endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long x;
    scanf("%lld",&x);
    long long y;
    scanf("%lld",&y);
    solve(a, b, x, y);
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>
#include <cassert>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
//const int mod = 998244353;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

LL N,K;

bool check(LL mid, const VVL& A){
    dump(mid)
    LL half = (K*K+1) / 2;
    VVL acc(N,VL(N));
    REP(i,N) REP(j,N){
        if(i == 0 && j == 0){
            if(A[0][0] <= mid) acc[i][j] = 1;
            else acc[i][j] = 0;
        }else if(i == 0){
            if(A[i][j] <= mid){
                acc[i][j] = acc[i][j-1] + 1;
            }else{
                acc[i][j] = acc[i][j-1];
            }
        }else if(j == 0){
            if(A[i][j] <= mid){
                acc[i][j] = acc[i-1][j] + 1;
            }else{
                acc[i][j] = acc[i-1][j];
            }

        }else{
            if(A[i][j] <= mid){
                acc[i][j] = acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1] + 1;
            }else{
                acc[i][j] = acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1];
            }

        }
    }

    //REP(i,N){
    //    REP(j,N){
    //        cerr << acc[i][j] << " ";
    //    }
    //    cerr << endl;
    //}

    REP(i,N) REP(j,N){
        if(i-K < -1 or j-K < -1) continue;
        LL tx,ty,tz;
        if(i-K == -1){
            tx = 0;
        }else{
            tx = acc[i-K][j];
        }

        if(j-K == -1){
            ty = 0;
        }else{
            ty = acc[i][j-K];
        }

        if(i-K == -1 or j-K == -1){
            tz = 0;
        }else{
            tz = acc[i-K][j-K];
        }

        //LL cnt = acc[i][j] - acc[i-K][j] - acc[i][j-K] + acc[i-K][j-K];
        LL cnt = acc[i][j] - tx - ty + tz;

        dump(cnt)
            dump(half)
        if(cnt >= half) {
            return true;
        }

    }
    return false;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    //LL N,K;
    cin >> N >> K;
    vector<VL> A(N,VL(N));

    REP(i,N) REP(j,N){
        cin >> A[i][j];
    }

    LL ok = INF;
    //LL ng = INF;
    LL ng = -1;

    while(abs(ok-ng) > 1){
        LL mid = (ok + ng) / 2;

        if(check(mid,A)){
            dump("ok")
            ok = mid;
        }else{
            dump("ng")
            ng = mid;
        }

    }
    cout << ok << endl;

}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
ll mod = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(), A.end());
    ll ans = A[0] + 1;
    rep(i,N-1) ans = (ans * (A[i + 1] - A[i] + 1)) % mod;
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}
#ifndef LOCAL
#define debug(...)
#endif

const int MaxA = 200;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	vector<ll> cnt(MaxA * 2 + 1);
	rep(i,n) ++(cnt[a[i] + MaxA]);
	ll ans = 0;
	for (int i = -MaxA; i <= MaxA; ++i) {
		for (int j = -MaxA; j < i; ++j) {
			ll x = i-j;
			ans += cnt[i+MaxA] * cnt[j+MaxA] * x * x;
		}
	}
	cout << ans << '\n';
}


//#include <atcoder/math>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define INF_LL 100000000000000000LL
#define INF 2000000000
#define MOD 998244353
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};
typedef vector<vector<edge>> graph;

// using mint = modint998244353;

char inv(char c){
    if(c == 'A') return 'B';
    return 'A';
}

vector<string> solve(int n){
    if(n == 1){
        return {"AB"};
    }
    vector<string> t = solve(n - 1);
    vector<string> res(t.size() * 2 + 1);
    rep(i, t.size()){
        rep(j, t[i].size()){
            res[i * 2] += t[i][j];
            res[i * 2] += t[i][j];
            res[i * 2 + 1] += t[i][j];
            res[i * 2 + 1] += inv(t[i][j]);
        }
    }
    rep(i, t.size() * 2 + 2){
        int cnt = 0;
        rep(j, res.size() - 1){
            if(res[j][i] == 'A') cnt++;
        }
        if(cnt != t.size()){
            res[res.size()-1]+='A';
        }else{
            res[res.size()-1]+='B';
        }
    }
    return res;
}

int main() {
    ll n;
    cin >> n;
    vector<string> ans = solve(n);
    int k = ans.size();
    vector<vector<int>> c(ans[0].size(), vector<int>(ans[0].size()));
    cout << k << endl;
    rep(i, k){
        string res = ans[i];
        cout << res << endl;
        rep(i, res.size()) REP(j, i + 1, res.size()) {if(res[i] == res[j])c[i][j]++;}
    }
    // int t = c[0][1];
    // rep(i, n) REP(j, i + 1, n) {
    //     if(c[i][j] != t){
    //         cout << i << " " << j << " " << c[i][j] << endl;
    //     }
    // }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
vector<string> gao(int n)
{
	vector<string> res;
	string s = string(1<<(n-1), 'A') + string(1<<(n-1), 'B');
	res.push_back(s);
	if(n==1) return res;
	auto tmp = gao(n-1);
	for(auto s : tmp)
	{
		res.push_back(s+s);
		string t = s;
		for(auto &c : t) c = char('B' - c + 'A');
		res.push_back(s+t);
	}
	return res;
}
int main()
{
	int n;
	scanf("%d", &n);
	auto res = gao(n);
	printf("%d\n", (int)res.size());
	for(auto s : res) printf("%s\n", s.c_str());
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

template <typename T> T gcd(T a, T b) {if(b == 0) return a;return gcd(b,a%b);}
template <typename T> T lcm(T a, T b) {return a*b/gcd(a,b);}
template <typename T> T extgcd(T a, T b, T& x, T& y){
    T d = a;
    if(b != 0){
        d = extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else x=1,y=0;
    return d;
}
template <typename T> T modpow(T x, T n, T m) {
    if(n==0) return 1;
    T resp = modpow(x*x%m,n/2,m);
    if(n&1) resp = resp*x%m;
    return resp;
}
template <typename T> T modinverse(T a, T m) {
    T x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}
struct combination {
    ll M = mod;
    vector<ll> fact,ifact;
    combination(ll n):fact(n+1),ifact(n+1){
        fact[0]=1;ifact[0]=1;
        for (ll i = 0; i<n; i++) {
            fact[i+1] = fact[i]*(i+1) % M;
            ifact[i+1] = ifact[i]*modpow(i+1, M-2, M) % M;
        }
    }
    ll com(ll a, ll b){
        if(a == 0 && b == 0)return 1;
        if(a < b || a < 0)return 0;
        ll tmp = ifact[a-b] * ifact[b] % M;
        return tmp * fact[a] % M;
    }
};

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N,M;
    cin >> N >> M;

    ll c = modpow<ll>(10LL,N,M*M);
    ll b = modpow<ll>(10LL,N,M);

    cout << (c-b)/M << endl;

    return 0;
}

#include <bits/stdc++.h>
struct __fastio__ { __fastio__ () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } __fast_io__;
template<class T, class U> bool chmin (T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> void print(const T &value) { std::cout << value << '\n'; }
template<class T, class... Args> void print(const T &value, Args... args) { std::cout << value << ' '; print(args...); }
template<class T> using martix = std::vector<std::vector<T>>;
using i32 = std::int_fast32_t;
using u32 = std::uint_fast32_t;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

int main() {
	int h, w;
	std::cin >> h >> w;
	std::vector<std::string> s(h);
	for (auto &e : s) std::cin >> e;

	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i + 1 < h) {
				if (s[i][j] == '.' and s[i + 1][j] == '.') ans++;
			}
			if (j + 1 < w) {
				if (s[i][j] == '.' and s[i][j + 1] == '.') ans++;
			}
		}
	}

	std::cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> dp(n, -LINF);
    vector<vector<int>> from(n);
    int x, y;
    rep(i,m) {
        cin >> x >> y;
        x--; y--;
        dp[x] = 0;
        from[y].push_back(x);
    }
    rep(i,n) {
        for (int j: from[i]) {
            dp[i] = max(dp[i], dp[j]+a[i]-a[j]);
        }
    }
    ll ans = -LINF;
    rep(i,n) {
        // cout << dp[i] << endl;
        if (from[i].size()>0) ans = max(ans, dp[i]);
    }
    cout << ans << endl;
	return 0;
}

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

#define  int               long long int
#define  ld                long double
#define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)           for(int i = n; i >= j; i--)
#define  all(container)       container.begin() , container.end()
#define  sz(container)        (int)container.size()
#define  ff                first
#define  ss                second
#define  pii               pair <int , int>
#define  sp(x)              setprecision(x)
#define  mod              1000000007
#define  endl            "\n"
#define  pb              push_back
#define  mp             make_pair
#define  T             int ttt; cin >> ttt; while(ttt--)
#define fast           ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int a[200005],b[200005],ans=-1e18;
bool vis[200005];
vector<int>v[200005];
void dfs(int r){
    vis[r]=1;
    for(auto i : v[r]){
        if(!vis[i])
            dfs(i);
        b[r]=max(b[r],b[i]);
        b[r]=max(b[r],a[i]);
    }
}

int32_t main()
{
    fast
    int n,m,x,y;    cin>>n>>m;
    f(i,1,n)    cin>>a[i];
    f(i,1,n)    b[i]=-1e16;
    f(i,1,m){
        cin>>x>>y;
        v[x].pb(y);
    }
    f(i,1,n)
        if(!vis[i])
            dfs(i);
    f(i,1,n)
        ans=max(ans,b[i]-a[i]);
    cout<<ans;
}