#include <bits/stdc++.h>

#define int long long
#define x first
#define y second
using namespace std;

void solve()
{
    int N; cin>>N;

    int a[N];
    for(int i = 0; i<N; i++)
        cin>>a[i];

    int res = INT_MAX;
    for(int i = 0; i<1<<(N-1); i++){

        int ored = 0;
        int xored = 0;

        for(int j = 0; j<=N; j++){
            if(j<N){
                ored |=  a[j];
            }
            if(j==N || (i>>j) & 1){
                // if we are at the end or there is a
                // bar at the j-th position.
                xored ^= ored;
                ored = 0;
            }
        }
        res = min(res,xored);
    }
    cout<<res<<endl;
}
signed main(){
    int T=1; //cin>>T;
    while(T--){
        solve();
    }
}

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

int main(){
    int N;
    cin >> N;
    int n = 0;
    for (int i = 0; i < N; i++){
        int ai;
        cin >> ai;
        if (ai > 10){
            n += ai - 10;
        }
    }
    cout << n << endl;
}


#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

#define endl "\n"
#define INF 0x3f3f3f3f
#define eb emplace_back
#define mem(a, b) memset(a , b , sizeof(a))

// const ll mod = 998244353;
const ll mod = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1);
const double R = 0.57721566490153286060651209;

const int N = 4e5 + 10;

struct Edge {
    int v; ll w;
};

vector<Edge> g[N];
vector<ll> cnt(105), XOR(N);

void dfs(int u, int fa) {
    for(auto e : g[u]) {
        int v = e.v;
        if(v == fa) continue ;
        XOR[v] = XOR[u] ^ e.w;
        dfs(v, u);
    }
    for(int i = 0;i < 65; i++) if(XOR[u] & (1ll << i)) cnt[i + 1]++;
}

void solve() {
    int n; cin >> n;
    for(int i = 1;i < n; i++) {
        int u, v; ll w;
        cin >> u >> v >> w;
        g[u].push_back(Edge{v, w});
        g[v].push_back(Edge{u, w});
    }
    dfs(1, 0);
    ll ans = 0;
    vector<ll> bit(100);
    bit[1] = 1;
    for(int i = 2;i < 65; i++) bit[i] = bit[i - 1] * 2 % mod;
    for(int i = 1;i < 65; i++) {
        ans = (ans + bit[i] * (n - cnt[i]) % mod * cnt[i]) % mod;
    }
    cout << (ans % mod + mod) % mod << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    // cin.tie(nullptr);
    // cout.tie(nullptr);
#ifdef FZT_ACM_LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    signed test_index_for_debug = 1;
    char acm_local_for_debug = 0;
    do {
        if (acm_local_for_debug == '$') exit(0);
        if (test_index_for_debug > 20)
            throw runtime_error("Check the stdin!!!");
        auto start_clock_for_debug = clock();
        solve();
        auto end_clock_for_debug = clock();
        cout << "Test " << test_index_for_debug << " successful" << endl;
        cerr << "Test " << test_index_for_debug++ << " Run Time: "
             << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
    solve();
#endif
    return 0;
}

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

int main() {
    const long long mod = 1e9+7;

    int N;
    cin >> N;
    vector<vector<long long>> edge(N), weight(N);
    for(int i = 1; i < N; i++) {
        long long u, v, w;
        cin >> u >> v >> w;
        edge[--u].push_back(--v);
        edge[v].push_back(u);
        weight[u].push_back(w);
        weight[v].push_back(w);
    }

    vector<long long> dist(N, -1);
    queue<int> que;
    que.push(0);
    dist[0] = 0;

    while(!que.empty()) {
        int now = que.front();
        que.pop();

        for(int i = 0; i < edge[now].size(); i++) {
            int next = edge[now][i];
            long long sum = dist[now]^weight[now][i];
            if (dist[next] == -1) {
                dist[next] = sum;
                que.push(next);
            }
        }
    }

    long long ans = 0;
    for(int d = 0; d < 60; d++) {
        vector<int> cnt(2);
        for(int k = 0; k < N; k++) cnt[ (dist[k] >> d) & 1 ]++;
//        ans += ((1ll << d) % mod) * ((cnt[0]* cnt[1]) % mod);
        ans += (1ll<<d)%mod*cnt[0]%mod*cnt[1];

        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int>
#define all(v) v.begin(), v.end()
#define mt make_tuple
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
#define prev prev1
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R)
{
     int val = rng() % R;
     assert(val >= 0);
     return val;
}

const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
const int32_t MOD = MOD1;

using namespace std;

//-------------------DEBUGGING-------------------------
void my_debugger(string s, int LINE_NUM) { cerr << endl; }
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
     if (s.back() != ',')
     {
          s += ',';
          cerr << "LINE(" << LINE_NUM << "): ";
     }
     int i = s.find(',');
     cerr << s.substr(0, i) << " = " << x;
     s = s.substr(i + 1);
     if (!s.empty())
          cerr << ", ";
     my_debugger(s, LINE_NUM, y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#else
#define debug(...) ;
#endif

//-----------------------------------------------------

int gcd(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int x1, y1;
    int d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) {
    g = gcd(abs(a), abs(b), x0, y0);
    if (c % g) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}

int table[200005] = {0};
void update(int i, int delta)
{
     while (i <= 200003)
     {
          table[i] += delta;
          i += (i & -i);
     }
}
int pref_sum(int i)
{
     int sum = 0;
     while (i > 0)
     {
          sum += table[i];
          i -= i & -i;
     }
     return sum;
}
int sum(int l, int r)
{
     if (l > r)
          return 0;
     return pref_sum(r) - pref_sum(l - 1);
}

int32_t main()
{
     getFaster;
     //files_init();
     int tests = 1;
     //cin >> tests;
     rep(ii, 0, tests)
     {
          int n,m;
          cin>>n>>m;
          int obs;
          cin>>obs;
          vector<pii> vals(obs);
          vector<int> row(n+1,m+1),col(m+1,n+1);
          rep(i,0,obs)
          {
               cin>>vals[i].f>>vals[i].s;
               int r,c;
               tie(r,c)=mt(vals[i].f,vals[i].s);
               row[r]=min(row[r],c);
               col[c]=min(col[c],r);
          }

          vector<vector<int>> data(m+2);
          int ans=0;
          rep(i,1,col[1])
          {
               if(i>n)break;
               int extend=row[i]-1;
               ans+=extend;
               data[1].push_back(i);
               data[extend+1].push_back(-i);
          }

          for(int ind=1;ind<=m;ind++)
          {
                vector<int>& temp=data[ind];
                rep(i,0,temp.size())
                {
                     int val=temp[i];
                     if(val<0)
                     update(-val,-1);
                     else
                     update(val,1);
                }
                if(pref_sum(1)==0)break;
                int cur=col[ind]-1;
                ans-=pref_sum(cur);
                ans+=cur;
          }
          cout<<ans<<endl;
     }
     return 0;
}

#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <cfloat>
#include <iomanip>
using namespace std;
long long X[200000];
long long Y[200000];
long long min_X[200000];
long long min_Y[200000];

int sqrtN = 450;
struct SqrtDecomposition{
    int N, K;
    vector <long long> data;
    vector <long long> bucketSum;

    SqrtDecomposition(int n){
        N = n;
        K = (N + sqrtN - 1) / sqrtN;
        data.assign(N, 0);
        bucketSum.assign(K, 0);
    }

    void add(int x, int y){
        data[x] += y;
        bucketSum[x / sqrtN] += y;
    }

    long long getSum(int x, int y){
        long long ans = 0;
        if(y - x < sqrtN){
            for(int i = x; i < y; i++){
                ans += data[i];
            }
            return ans;
        }
        for(int i = x / sqrtN + 1; i < y / sqrtN; i++){
            ans += bucketSum[i];
        }

        for(int i = x; i < (x / sqrtN + 1) * sqrtN; i++){
            ans += data[i];
        }
        for(int i = y / sqrtN * sqrtN; i < y; i++){
            ans += data[i];
        }
        return ans;
    }

};

int main(){
  int H;
  int W;
  int M;
  cin >> H >> W >> M;

  for(int i = 0; i < M; i++){
    cin >> X[i] >> Y[i];
  }

  long long ans = 0;
  for(int i = 0; i < H; i++){
    min_Y[i] = W;
  }
  for(int i = 0; i < W; i++){
    min_X[i] = H;
  }
  for(int i = 0; i < M; i++){
    min_Y[X[i] - 1] = min(min_Y[X[i] - 1], Y[i] - 1);
    min_X[Y[i] - 1] = min(min_X[Y[i] - 1], X[i] - 1);
  }
  for(int i = 0; i < min_X[0]; i++){
    ans += min_Y[i];
  }

  SqrtDecomposition sq(H);
  for(int i = 0; i < min_X[0]; i++){
    sq.add(i, 1);
  }
  vector <pair<long long, long long> > YX_vec;
  for(int i = 0; i < min_X[0]; i++){
    YX_vec.push_back(make_pair(min_Y[i], i));
  }
  sort(YX_vec.begin(), YX_vec.end());
  int min_Y_vec_ind = 0;
  for(int i = 0; i < min_Y[0]; i++){
      while(min_Y_vec_ind < min_X[0] && YX_vec[min_Y_vec_ind].first <= i){
        if(YX_vec[min_Y_vec_ind].first == i){
          sq.add(YX_vec[min_Y_vec_ind].second, -1);
        }
        min_Y_vec_ind ++;
      }
      ans += min_X[i] - sq.getSum(0, min_X[i]);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
#include <unordered_map>
#define ull unsigned long long
#define int long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
#define INF 1e18
using namespace std;
typedef pair<int, int> pi;
const int MAX = 1e6 + 1;
// typedef vector<vector<ll>> matrix;
const ll PRIME = 1e9 + 7;
typedef pair<int,pair<int,int> >  ppi;
// const ll MAX = 1e6 + 1;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

int a[MAX];
int b[MAX];
vector<int>graph[MAX];
vector<bool>vis(MAX,0);
// vector<bool> connected(MAX,0);
pi dfs(int src)
{
    vis[src]=1;
    pi temp;
    temp.first+=a[src];
    temp.second+=b[src];
    for(int i: graph[src])
    {
        if(!vis[i])
        {
          pi tmp2=dfs(i);
        temp.first+=tmp2.first;
        temp.second+=tmp2.second;
        }
    }
    return temp;

}
void solve()
{
    int n,m;
    cin>>n>>m;
    // int a[n],b[n];
    int sum1=0,sum2=0;
    fr(i,n)
    {
        cin>>a[i];
        sum1+=a[i];
    }
    // int st;
    bool flag=0;
    fr(i,n)
    {
        cin>>b[i];
        sum2+=b[i];
        if(a[i]!=b[i])
        {   flag=1;
        }

    }

    int u,v;
    while(m--)
    {
        cin>>u>>v;
        u--,v--;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    if(sum1!=sum2)
    {
        cout<<"No\n";
        return;

    }
    if(flag==0)
    {cout<<"Yes\n";return;}
//  cout<<st;

    fr(i,n)
    {
        if(!vis[i])
        {
            pi temp=dfs(i);
            if(temp.first!=temp.second)
            {
                cout<<"No\n";
                return;
            }
        }
    }
    cout<<"Yes\n";

}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t;
    t = 1;
    // cin >> t;

    // int k=1;
    while (t--)
    {
        // cout << "Case " << k++ << ":\n";
        solve();
    }
}

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N];
ll a[N];
ll b[N];
ll vis[N];
ll p1=0,p2=0;
void dfs(ll v){
    vis[v]=1;
    p1+=a[v];
    p2+=b[v];
    for (auto u : g[v]){
        if (!vis[u]) dfs(u);
    }
    return ;
}
int32_t main(){
    ll n,m;
    cin >> n >> m;
    for (int i=1;i<=n;i++) cin >> a[i];
    for (int i=1;i<=n;i++) cin >> b[i];
    for (int i=0;i<m;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);

    }
    for (int i=1;i<=n;i++){
        if (!vis[i]){
            dfs(i);
            if (p1!=p2) kill("No");
        }
    }
    kill("Yes");

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<int,char>
#define Tp tuple<int,int,int>
using Graph = vector<vector<P>>;

int main(){
    int N; cin >> N;
    vector<ll> a; ll A;
    rep(i,N){
        cin >> A; a.push_back(A);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll m = 998244353;
    ll ans = 0; ll k = 0; ll pr = 0; ll n;
    rep(i,N){
        n = a[i]; k = (k*2-pr+n+m)%m;
        ans += (n*k)%m; ans %= m; pr = n;
        //cout <<ans << endl;
    }
    cout << ans  << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define int long long
#define sz(x) ((int)(x).size())
#define fill(x, value) memset(x, value, sizeof(x))
#define debug(x) cout << #x << " ------> " << x << "\n"
typedef pair<int, int> PII;

const int N = 3e3 + 3;
int arr[N], n, mod = 1e9 + 7, dp[N][N], nxt[N][N];

int ways(int i, int cur) {
    if (i == n + 1) return true;
    int sum = 0, tot = 0, onetime = 0;
    if (dp[i][cur] != -1) return dp[i][cur];
    if(nxt[i][cur] != -1) {
        onetime = 1;
        tot += ways(nxt[i][cur] + 1, cur + 1);
        tot += ways(nxt[i][cur] + 1, cur);
        tot %= mod;
    }
    return dp[i][cur] = onetime * tot % mod;
}

int powr(int a, int n, int m) {
    int res = 1;
    while (n) {
        if (n % 2) res = res * a % m;
        a = a * a % m;
        n /= 2;
    }
    return res;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) dp[i][j] = -1, nxt[i][j] = -1;
    }

    for(int i = 1; i <= n; i++){
        map<int, int> mp;
        int pf = 0;
        mp[0] = 0;
        for(int j = 1; j <= n; j++){
            pf += arr[j];
            pf %= i;
            if(mp.count(pf)) {
                nxt[mp[pf] + 1][i] = j;
            }
            mp[pf] = j;
        }
    }

    int ans = ways(1, 1) * powr(2, mod - 2, mod) % mod;
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++) {
        solve();
        // cout << solve() << '\n';
    }

    cerr << "\nTime: " << clock() << " ms";
}


#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;

#define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL);

#define lson (node<<1)
#define rson ((node<<1)|1)

const int mx = 2e5 + 9;

ll t[4 * mx];
vector <int> min_row[mx];

void turn_on(int node, int l, int r, int pos) {
    int mid = (l + r) / 2;
    if (l == r) {
        t[node] = 1;
        return;
    }

    if (pos <= mid) turn_on(lson, l, mid, pos);
    else turn_on(rson, mid + 1, r, pos);

    t[node] = t[lson] + t[rson];
}

ll query(int node, int l, int r, int L, int R) {
    int mid = (l + r) / 2;

    if (r < L or R < l) return 0;
    if (L <= l and r <= R) return t[node];

    ll q1 = query(lson, l, mid, L, R);
    ll q2 = query(rson, mid + 1, r, L, R);

    return q1 + q2;
}

int main() {
    FIO();

    int h, w, m;
    cin >> h >> w >> m;

    vector <int> row(h + 3, w + 1), col(w + 3, h + 1);

    while (m--) {
        int x, y;
        cin >> x >> y;

        row[x] = min(row[x], y);
        col[y] = min(col[y], x);
    }

    ll ans = 0;
    for (int i = 1; i <= w; i++) {
        if (i < row[1]) {
            ans += (col[i] - 1);
            min_row[col[i]].push_back(i);
        } else min_row[1].push_back(i);
    }

//    cout << ans << '\n';

    for (int i = 1; i < col[1]; i++) {
        for (int idx : min_row[i]) turn_on(1, 1, w, idx);
        if (row[i] == 1) continue;

        ll cnt = query(1, 1, w, 1, row[i] - 1);
        ans += cnt;

//        cout << i << " " << cnt << " " << row[i] << '\n';
    }

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

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

typedef long long ll;
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define F0R(i, a, b) for (int i=a; i<(b); i++)
#define F0Rd(i,a,b) for (int i = (b)-1; i >= a; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll M = 1e9 + 7;
const ll MM = 998244353;
const ll INF = 1e18;

void solve() {
	int N, K; cin >> N >> K;
	int cur = 0, yen = K;
	vector<pii> V(N);
	for(int i = 0; i < N; ++i) {
		cin >> V[i].F >> V[i].S;
	}
	sort(ALL(V));
	for(int i = 0; i < N; i++) {
		// D1(K);
		// D1(V[i].F);
		if(K >= V[i].F) K += V[i].S;
	}
	cout << K << '\n';
}

int32_t main() {
	_

	// tc(t)
	solve();
	// cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}


#include <bits/stdc++.h>

#define N (int) 3005
#define MOD 998244353

using namespace std;
int n, k;

int dp[N][N];
int main () {
    cin >> n >> k;

    dp[0][0] = 1;
    for (int i = 1; i <= n; i ++) {
        for (int j = i; j >= 1; j --) {
            dp[i][j] = (dp[i-1][j-1] + ((j<<1) <= i ? dp[i][j<<1] : 0)) % MOD;
        }
    }

    cout << dp[n][k] << endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct mint {
    int x;
    mint() : x(0) {}
    mint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    mint& operator+=(const mint& p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    mint& operator-=(const mint& p){
        if((x -= p.x) < 0)  x += mod;
        return *this;
    }
    mint& operator*=(const mint& p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    mint& operator/=(const mint& p){
        *this *= p.inverse();
        return *this;
    }
    mint operator-() const { return mint(-x); }
    mint operator+(const mint& p) const { return mint(*this) += p; }
    mint operator-(const mint& p) const { return mint(*this) -= p; }
    mint operator*(const mint& p) const { return mint(*this) *= p; }
    mint operator/(const mint& p) const { return mint(*this) /= p; }
    bool operator==(const mint& p) const { return x == p.x; }
    bool operator!=(const mint& p) const { return x != p.x; }
    mint pow(int64_t n) const {
        mint res = 1, mul = x;
        while(n > 0){
            if(n & 1)   res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    mint inverse() const { return pow(mod - 2); }
    friend ostream& operator<<(ostream& os, const mint& p){
        return os << p.x;
    }
    friend istream& operator>>(istream& is, mint& p){
        int64_t val;
        is >> val;
        p = mint(val);
        return is;
    }
};

template<typename T>
struct Combination{
    int sz;
    vector<T> fact_;
    vector<T> ifact_;
    vector<T> inv_;

    Combination(int n = 1e+7) : sz(n) {
        fact_.resize(sz + 1);
        ifact_.resize(sz + 1);
        inv_.resize(sz + 1);

        fact_[0] = ifact_[sz] = inv_[0] = 1;
        for(int i = 1; i <= sz; ++i)    fact_[i] = fact_[i - 1] * i;
        ifact_[sz] /= fact_[sz];
        for(int i = sz; i > 0; --i)     ifact_[i - 1] = ifact_[i] * i;
        for(int i = 1; i <= sz; ++i)    inv_[i] = ifact_[i] * fact_[i - 1];
    }

    inline T fact(int k) const {
        if(k < 0 || k > sz) return 0;
        return fact_[k];
    }
    inline T ifact(int k) const {
        if(k < 0 || k > sz) return 0;
        return ifact_[k];
    }
    inline T inv(int k) const {
        if(k < 0 || k > sz) return 0;
        return inv_[k];
    }

    T get_permutation(int n, int k){
        if(n < 0 || k < 0 || n < k)     return 0;
        return fact(n) * ifact(n - k);
    }

    T get_combination(int n, int k){
        if(n < 0 || k < 0 || n < k)     return 0;
        return fact(n) * ifact(k) * ifact(n - k);
    }
};

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

    int N, M, A;
    cin >> N >> M;
    ll S = 0;
    for(int i = 0; i < N; ++i){
        cin >> A;
        S += A;
    }
    if(M < S){
        cout << 0 << endl;
        return 0;
    }
    Combination<mint> C;
    mint ans = 1;
    M += N;
    for(int i = 1; i <= S + N; ++i) ans *= mint(M - i + 1) * C.inv(i);
    cout << ans << endl;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(int i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(int i=(r)-1;i>=(l);i--)
#define pb push_back
#define ins insert
#define se second
#define fi first
#define all(x) x.begin(),x.end()
using vi=vector<int>;
using vl=vector<ll>;
using vvi= vector<vector<int>>;
using vvl= vector<vector<ll>>;
using pii= pair<int,int>;
using pll= pair<ll,ll>;
const ll mod = INF;
const int dxn[9]={-1,0,1,-1,0,1,-1,0,1};
const int dyn[9]={-1,-1,-1,0,0,0,1,1,1};
const int dxf[4]={0,1,0,-1};
const int dyf[4]={-1,0,1,0};
const int maxn = 1000;

int main(){
    int n,m;
    ll a[maxn+1],b[maxn+1];
    ll dp[maxn+1][maxn+1]={0};

    cin >> n>>m;
    rep(i,n)cin >> a[i+1];
    rep(i,m)cin >> b[i+1];

    rep(i,m+1)dp[0][i]=i;
    rep(i,n+1)dp[i][0]=i;

    repl(i,1,n+1){
        repl(j,1,m+1){
            int p=1;
            if(a[i]==b[j])p=0;
            dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+p);
        }
    }

    cout << dp[n][m]<<endl;

    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define irreps(i, m, n) for (long long i = ((long long)(n)-1); i > (long long)(m); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) (long long)(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;
using ld = long double;

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; }

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

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

  int x,y; cin>>x>>y;
  if(abs(x-y)<3) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int,int> Pii;
#define reg register
#define mp make_pair
#define pb push_back
#define Mod1(x) ((x>=P)&&(x-=P))
#define Mod2(x) ((x<0)&&(x+=P))
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
template <class T> inline void cmin(T &a,T b){ ((a>b)&&(a=b)); }
template <class T> inline void cmax(T &a,T b){ ((a<b)&&(a=b)); }

char IO;
template <class T=int> T rd(){
	T s=0; int f=0;
	while(!isdigit(IO=getchar())) f|=IO=='-';
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=2e5+10,INF=1e9+10;

int n;
vector <int> G[N];
int F[N][20],D[N],E[N],L[N];
int ma=-1,id;
void dfs(int u,int f) {
	if(D[u]>ma) ma=D[u],id=u;
	F[u][0]=f,E[u]=D[u];
	rep(i,1,18) F[u][i]=F[F[u][i-1]][i-1];
	for(int v:G[u]) if(v!=f) D[v]=D[u]+1,dfs(v,u),cmax(E[u],E[v]);
	L[u]=G[u][0]==f?(G[u].size()==1?0:G[u][1]):G[u][0];
	sort(G[u].begin(),G[u].end(),[&](int x,int y){ return E[x]<E[y]; });
}
int LCA(int x,int y){
	if(D[x]<D[y]) swap(x,y);
	for(int del=D[x]-D[y],i=0;(1<<i)<=del;++i) if(del&(1<<i)) x=F[x][i];
	if(x==y) return x;
	drep(i,18,0) if(F[x][i]!=F[y][i]) x=F[x][i],y=F[y][i];
	return F[x][0];
}
int Dis(int x,int y){ return D[x]+D[y]-2*D[LCA(x,y)]; }

int lst;
ll Ans=1e18,A[N],M,B[N];
void dfs2(int u,int f) {
	//cout<<u<<' ';
	if(!lst) A[lst=u]=1;
	else A[u]=A[lst]+Dis(lst,u),lst=u;
	M=A[u];
	for(int v:G[u]) if(v!=f) dfs2(v,u);
}

void Work(int u){
	lst=0;
	dfs(u,0),dfs2(u,0);
	if(M<Ans) {
		Ans=M;
		rep(i,1,n) B[i]=A[i];
	}
	//puts("");
}

int main(){
	n=rd();
	rep(i,2,n) {
		int u=rd(),v=rd();
		G[u].pb(v),G[v].pb(u);
	}
	dfs(1,0),Work(id);
	int u=1;
	while(L[u]) u=L[u];
	Work(u);
	while(L[u]) u=L[u];
	Work(u);
	ll ans=0;
	rep(i,1,n) cmax(ans,B[i]);
	//printf("%lld\n",ans);
	rep(i,1,n) printf("%lld ",B[i]);
}

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

#define int long long
#define ll long long

const int nax = 2e5+5;
vector<int> edges[nax];
vector<int> value , d , par;
int cp = 1;

void dfs(int u , int p = -1 , int _d = 0){
	par[u] = p;
	d[u] = _d;
	for(auto x : edges[u]){
		if(x != p){
			dfs(x,u,_d+1);
		}
	}
}

void dfs1(int u , int p){
	value[u] = cp++;
	for(auto x : edges[u]){
		if(x != p){
			dfs1(x,u);
		}
	}
	cp++;
}

void test(){
	int n;
	cin >> n;
	for(int i = 0 ; i < n-1 ; i++){
		int x, y;
		cin >> x >> y;
		x-- , y-- ;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	value.resize(n);
	d.resize(n);
	par.resize(n);
	dfs(0);
	int st = max_element(d.begin(),d.end())-d.begin();
	dfs(st);
	int en = max_element(d.begin(),d.end())-d.begin();
	value[en] = cp++;
	while(par[en] != -1){
		int p = par[en];
		value[p] = cp++;
		for(auto x : edges[p]){
			if(x != par[p] && x != en){
				dfs1(x,p);
			}
		}
		en = p;
	}
	for(auto x : value)
		cout<<x<<" ";
}

int32_t main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	// cin >> T;
	while(T--){
		test();
	}
}

// 0 0 3


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef long long int i64;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 mod = 998'244'353ll;

const i64 inf = 1'000'000'000'000'000'000ll / 1'000'000'000ll;

const long double eps = 1e-8;

i64 gcd(i64 a, i64 b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    if (sizeof(i64) != sizeof(long long int)) {
        cerr << "i64 != long long int" << endl;
    }

    i64 R = 0;
    i64 n;
    string s;
    cin >> n >> s;

    i64 cnt = 0;
    stringstream ss;
    while (cnt < n) {
        ss << "110";
        cnt += 3;
    }
    ss << "110";
    string t = ss.str();

    for (i64 l = 0; l < 3; l++) {
        if (t.substr(l, s.size()) != s) {
            continue;
        }
        const i64 m = 30'000'000'000ll - n - l;
        R += m / 3 + 1;
    }

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class T, class U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<class T, class U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }

constexpr pair<long long, long long> inv_gcd(long long a, long long b) {
	a = a % b;
	if(a < 0) a += b;
	if(a == 0) return {b, 0};
	long long s = b, t = a;
	long long m0 = 0, m1 = 1;
	while(t){
		long long u = s / t;
		s -= t * u;
		m0 -= m1 * u;
		auto tmp = s;
		s = t;
		t = tmp;
		tmp = m0;
		m0 = m1;
		m1 = tmp;
	}
	if(m0 < 0) m0 += b / s;
	return {s, m0};
}

// (rem, mod)
// Requires inv_gcd
pair<long long, long long> chinese_remainder_theorem(const vector<long long> &r, const vector<long long> &m){
	assert(r.size() == m.size());
	int n = (int)r.size();
	long long r0 = 0, m0 = 1;
	for(int i = 0; i < n; ++ i){
		assert(1 <= m[i]);
		long long r1 = r[i] % m[i], m1 = m[i];
		if(r1 < 0) r1 += m[i];
		if(m0 < m1) swap(r0, r1), swap(m0, m1);
		if(m0 % m1 == 0){
			if(r0 % m1 != r1) return {0, 0};
			continue;
		}
		long long g, im;
		tie(g, im) = inv_gcd(m0, m1);
		long long u1 = (m1 / g);
		if ((r1 - r0) % g) return {0, 0};
		long long x = (r1 - r0) / g % u1 * im % u1;
		r0 += x * m0, m0 *= u1;  // -> lcm(m0, m1)
		if(r0 < 0) r0 += m0;
	}
	return {r0, m0};
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	auto __solve_tc = [&](int __tc_num){
		long long x, y, p, q;
		cin >> x >> y >> p >> q;
		long long res = numeric_limits<long long>::max();
		for(auto r0 = x; r0 < x + y; ++ r0){
			for(auto r1 = p; r1 < p + q; ++ r1){
				auto [t, lcm] = chinese_remainder_theorem({r0, r1}, {2 * x + 2 * y, p + q});
				if(lcm){
					ctmin(res, t);
				}
			}
		}
		if(res == numeric_limits<long long>::max()){
			cout << "infinity\n";
		}
		else{
			cout << res << "\n";
		}
		return 0;
	};
	int __tc_cnt;
	cin >> __tc_cnt;
	for(auto __tc_num = 0; __tc_num < __tc_cnt; ++ __tc_num){
		__solve_tc(__tc_num);
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
//                                   Coded by Aeren                                   //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////////

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <string>
#include <cassert>

using namespace std;

typedef long long llint;

const int INF = 0x3f3f3f3f;
const llint INFLL = 0x3f3f3f3f3f3f3f3fLL;

void print() { cout << "\n"; }

template <typename...T, typename X>
void print(X&& x, T... args) { cout << x << " "; print(args...); }
int input() { return 0; }

template <typename...T, typename X>
int input(X& x, T&... args) {
    if (!(cin >> x)) return 0;
    return input(args...) + 1;
}

llint exgcd(llint a, llint b, llint& x, llint& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    llint r = exgcd(b, a%b, x, y);
    llint t = y;
    y = x - (a / b) * y;
    x = t;
    return r;
}

llint fast_mul(llint a, llint b, llint p){
    llint res = 0;
    while (b) {
        if (b & 1) {
            res = (res + a) % p;
        }
        b >>= 1;
        a = (a + a) % p;
    }
    return (res % p + p) % p;
}

llint excrt(const vector<llint>& a, const vector<llint>& b) {
    const int n = a.size();
    assert(a.size() == b.size());
    llint a1 = a[0];
    llint b1 = b[0];
    for (int i = 1; i < n; i++) {
         llint a2 = a[i];
         llint b2 = b[i];

         llint k1,k2;
         llint d = exgcd(a1, a2, k1, k2);

         if ((b2 - b1) % d != 0) {
             return -1;
         }
         llint t = a2 / d;
         k1 = (k1 % t + t) % t;
         k1 = fast_mul((b2 - b1) / d, k1, t);
         b1 = k1 * a1 + b1;
         a1 = a1 / d * a2;
    }
    return b1;
}

llint solve(int x, int y, int p, int q) {
    llint res = INFLL;
    for (int yy = 0; yy < y; yy++) {
        for (int qq = 0; qq < q; qq++) {
            llint m1 = 2LL * x + 2LL * y;
            llint r1 = 1LL * x + yy;

            llint m2 = 1LL * p + q;
            llint r2 = 1LL * p + qq;

            llint cur = excrt({m1, m2}, {r1, r2});
            if (cur == -1) {
                continue;
            }
            res = min(res, cur);
        }
    }
    if (res >= INFLL) {
        return -1;
    }
    return res;
}

int main() {
    int T;
    input(T);
    while (T--) {
        int x, y, p, q;
        input(x, y, p, q);

        llint res = solve(x, y, p, q);

        if (res == -1) {
            puts("infinity");
        } else {
            printf("%lld\n", res);
        }
    }

    return 0;
}

/*

^^^TEST^^^
3
5 2 7 6
1 1 3 1
999999999 1 1000000000 1
-----
20
infinity
1000000000999999999
$$$TEST$$$

*/


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpi = vector<pii>;
using vpl = vector<pll>;

#define fi first
#define se second
#define pb push_back
#define mkpr make_pair
#define mktp make_tuple
#define rep2(i, s, n) for (ll i = (s); i < (ll) (n); i++)
#define rep(i, n) rep2(i, 0LL, n)
#define repit(itr, t) for (auto itr = (t).begin(); itr != (t).end(); ++itr)
#define all(c) begin(c), end(c)
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define biti(bit, i) ( (bit >> i) & 1 )
#define _GLIBCXX_DEBUG

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const ll VLMAX = 200010;
const ll MOD = 1000000007;
const ll INF = LONG_MAX;

int main() {
  ll N;
  cin >> N;
  vl v(N);
  cin >> v[0];
  vl sm(N);
  vl sum(N);
  sum[0] = v[0];
  sm[0] = max(v[0], 0LL);
  ll m = max(v[0], 0LL);
  rep (i, N - 1) {
    ll a;
    cin >> a;
    v[i + 1] = v[i] + a;
    m = max(m, v[i + 1]);
    sum[i + 1] = sum[i] + v[i + 1];
    sm[i + 1] = sum[i] + m;
  }

  cout << MAX(sm) << endl;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, k;
    cin >> n >> k;
    rep(i, k) {
        if(n % 200 == 0) {
            n = n / 200;
        }else {
            n = n * 1000 + 200;
        }
    }
    cout << n << endl;
    return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); (i)++)
#define per(i, n) for (ll i = n - 1; i >= 0; (i)--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define ROF(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define ALL(x) std::begin(x), std::end(x)
#define rALL(x) std::rbegin(x), std::rend(x)
#define fi first
#define se second
typedef long long ll;

inline ll cross(ll x1, ll y1, ll x2, ll y2) { return x1 * y2 - x2 * y1; } // (x1, y1)と(x2, y2)の外積, 1->2で反時計回りなら正
inline ll dot(ll x1, ll y1, ll x2, ll y2) { return x1 * x2 + y1 * y2; } // (x1, y1)と(x2, y2)の内積
inline ll norm2(ll x, ll y) { return x * x + y * y; } // ノルム二乗
inline ll cross(pair<ll, ll> a, pair<ll, ll> b) { return a.fi * b.se - a.se * b.fi; }
inline ll dot(pair<ll, ll> a, pair<ll, ll> b) { return a.fi * b.fi + a.se * b.se; }
inline ll norm2(pair<ll, ll> a) { return a.fi * a.fi + a.se * a.se; }

int main(){
    //input, initialize
    ll N; cin >> N;
    vector<ll> a(N), b(N), c(N), d(N);
    //solve
    if(N == 1){ cout << "Yes"; return 0; }
    rep(i, N) cin >> a[i] >> b[i];
    rep(i, N) cin >> c[i] >> d[i];
    rep(i, N) { a[i] *= N; b[i] *= N; c[i] *= N; d[i] *= N; }

    ll c1x, c1y, c2x, c2y; c1x = c1y = c2x = c2y = 0;
    rep(i, N) { c1x += a[i]; c1y += b[i]; c2x += c[i]; c2y += d[i]; }
    c1x /= N; c1y /= N; c2x /= N; c2y /= N;
    rep(i, N) { a[i] -= c1x; b[i] -= c1y; c[i] -= c2x; d[i] -= c2y; }

    if(a[0] == 0 && b[0] == 0){
        swap(a[0], a[1]); swap(b[0], b[1]);
    }
    set<pair<ll, ll>> p1, p2; // 外積, 内積の順
    rep(i, N){
        p1.insert(make_pair(cross(a[0], b[0], a[i], b[i]), dot(a[0], b[0], a[i], b[i])));
    }
    rep(i, N){
        p2 = {};
        if(c[i] == 0 && d[i] == 0) continue;
        rep(j, N){
            p2.insert(make_pair(cross(c[i], d[i], c[j], d[j]), dot(c[i], d[i], c[j], d[j])));
        }
        if(p1 == p2) {cout << "Yes" << '\n'; return 0;}
    }
    //output
    cout << "No\n";
    //debug
}

#include "bits/stdc++.h"
 #pragma GCC optimize "trapv"

#define int long long int
#define For(i,a,b) for(int  i=a;i<b;i++)

#define pb push_back
#define endl "\n"

#define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()

#define TEST_CASE int  t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);

using namespace std;
const int MOD = 1e9 + 7;

void print()  {    cout<<endl;  }
void printArray()  {    return;  }
void read() { return; }

template<typename T , typename... Args>  void print(T a , Args... arg)    {    cout << a << " " ;    print(arg...);    }

template<typename T , typename... Args> void read(T &a , Args&... arg) {   cin >> a;   read(arg...);   }

template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) {  for(auto &i : v)  cin>>i;  read(arg...);  }

template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) {   for(auto i : v)     cout<<i<<" ";   cout<<endl;  printArray(arg...);    }

int power(int a,int b) { int  res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; }

int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }

int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; }

int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }

int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }

void runCase_()
{
    int n;
    read(n);
    int x,y,ans = 0;
    while(n--)
    {
        read(x,y);
        int s = (y*(y+1))/2 - (x * (x - 1))/2;
        ans += s;
    }
    print(ans);
}

signed main()
{
    drink_boost;
//    TEST_CASE
    runCase_();
    return 0;
}

/** TEST CASES HERE **/
/*

*/


#include<iostream>
#include<iomanip>

using namespace std;

int sx,sy,gx,gy;

int main()
{
    cin >> sx >> sy >> gx >> gy;

    double d = (gx-sx)/(double)(-gy-sy);

    cout << fixed << setprecision(10) <<  - d * sy + sx << endl;

    return 0;
}


#include <bits/stdc++.h>

int mod = 998244353;

long long modinv(long long dividend, long long divisor, long long modnum){
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = divisor / b;
        divisor -= t * b; std::swap(divisor, b);
        u -= t * v; std::swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    long long ans = dividend * u % mod;
    return ans;
}

int main(){
    int N, K;
    std::cin >> N >> K;
    std::vector< long long > A(N);
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }

    std::vector< long long > calc_sigma_u(K+1, 0);
    std::vector< long long > calc_sigma_l(K+1);

    for(int i=0; i<N; i++){
        long long tmp = 1;
        for(int j=0; j<=K; j++){
            calc_sigma_u[j] = (calc_sigma_u[j] + tmp) % mod;
            tmp = (tmp * A[i]) % mod;
        }
    }
    long long tmpa = 1;
    calc_sigma_l[0] = 1;
    for(int i=1; i<=K; i++){
        tmpa = (tmpa * i) % mod;
        calc_sigma_l[i] = tmpa;
    }

    long long Factorial = 1;
    long long two = 1;
    for(int i=1; i<=K; i++){
        Factorial = (Factorial * i) % mod;
        long long ans = 0;
        for(int j=0; j<=i; j++){
            long long tmp = (Factorial * calc_sigma_u[j]) % mod;
            tmp = (tmp * calc_sigma_u[i-j]) % mod;
            tmp = modinv(tmp, calc_sigma_l[j], mod);
            tmp = modinv(tmp, calc_sigma_l[i-j], mod);
            //std::cout << i<< " " << j << " " <<tmp <<std::endl;
            ans = (ans + tmp) % mod;
        }

        two = (two * 2) % mod;
        long long Subtraction = (calc_sigma_u[i] * two) % mod;
        if(ans < Subtraction){
            ans = ans + mod - Subtraction;
        }else{
            ans = ans - Subtraction;
        }

        std::cout << modinv(ans, 2, mod) << std::endl;
    }

    return 0;
}

#include<iostream>
#include<vector>

using i64 = int64_t;
template<i64 MOD>
struct modint{
  i64 val;
  modint():val(0){}
  modint(i64 v):val(v<0?(-v)%MOD:v%MOD){}
  operator i64(){return val;}
  constexpr modint &operator += (modint other){this->val+=other.val;if(this->val>=MOD)this->val-=MOD;return *this;}
  constexpr modint &operator -= (modint other){this->val-=other.val;if(this->val<0)this->val+=MOD;return *this;}
  constexpr modint &operator *= (modint other){this->val*=other.val;if(this->val>=MOD)this->val%=MOD;return *this;}
  constexpr modint &operator /= (modint other){this->val*=other.inverse();if(this->val>=MOD)this->val%=MOD;return *this;}
  constexpr modint operator + (modint other)const{return modint(val)+=other;}
  constexpr modint operator - (modint other)const{return modint(val)-=other;}
  constexpr modint operator * (modint other)const{return modint(val)*=other;}
  constexpr modint operator / (modint other)const{return modint(val)/=other;}
  template<class T>modint operator + (T other)const{return modint(val)+=(modint)other;}
  template<class T>modint operator - (T other)const{return modint(val)-=(modint)other;}
  template<class T>modint operator * (T other)const{return modint(val)*=(modint)other;}
  template<class T>modint operator / (T other)const{return modint(val)/=(modint)other;}
  template<class T>
  modint mpow(T _n)const{
    i64 n = _n;
    modint res(1);
    modint base(val);
    while(n){
      if(n&1)res*=base;
      base *= base;
      n >>= 1;
    }
    return res;
  }
  template<class T,class U>
  static modint mpow(T t,U u){return modint(t).mpow(u);}
  modint inverse()const{return mpow(val,MOD-2);}
  friend std::ostream &operator << (std::ostream& os,modint mo){return os<<mo.val;}
  friend std::istream &operator >> (std::istream& is,modint& mo){return is>>mo.val;}
};
constexpr int MOD = 998244353;
using mint = modint<MOD>;
mint operator""_m(unsigned long long x){return (mint)x;}

#define rep(i,n) for(int i=0;i<(int)n;++i)
constexpr int64_t COM_MAX = (int64_t)1e6;

signed main(){

  int n,k;
  std::cin>>n>>k;
  std::vector<mint> a(n);
  for(auto& ai:a)std::cin>>ai;

  std::vector<mint> fac(k+1),inv(k+1),finv(k+1);
  fac[1]=inv[1]=finv[0]=finv[1]=1;
  for(int i=2;i<=k;++i){
    fac[i]=fac[i-1]*i;
    inv[i]=MOD-inv[MOD%i]*(MOD/i);
    finv[i]=finv[i-1]*inv[i];
  }
  std::vector<mint> ushi(k+1);
  rep(j,k+1)rep(i,n)ushi[j]+=(a[i]*2_m).mpow(j);
  std::vector<mint> tapu(k+1);
  rep(j,k+1)rep(i,n)tapu[j]+=a[i].mpow(j)*finv[j];

  auto solve = [&](i64 x){
    mint ans = 0;
    for(int k=0;k<=x;++k){
      ans += tapu[k]*tapu[x-k];
    }
    ans *= fac[x];
    ans -= ushi[x];
    ans /= 2;
    return ans;
  };
  for(int x=1;x<=k;++x)
    std::cout<<solve(x)<<'\n';

}


#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define per(i,a,b) for(register int i=(a);i>=(b);i--)
using namespace std;
const double eps=1e-14;

inline int read() {
    register int x=0, f=1; register char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') f=-1; c=getchar();}
    while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+c-48,c=getchar();}
    return x*f;
}

long double x,y,r;
int ans;

signed main() {
	cin>>x>>y>>r;
	r+=eps;
	rep(i,ceil(y-r),floor(y+r)) {
		long double dc=i-y;
		if(r*r-dc*dc<0) continue;
		long double dl=sqrt(r*r-dc*dc);
		long double l=x-dl, r=x+dl;
		int il=ceil(l-eps), ir=floor(r+eps);
		ans=ans+ir-il+1;
		//cout<<i<<" "<<l<<" "<<r<<" "<<il<<" "<<ir<<endl;
	}
	printf("%lld\n",ans);
	return 0;
}

//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <array>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>
#include<fstream>
#include<assert.h>

#include<stdio.h>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

int dec()
{
	string S;
	cin >> S;

	string res;

	int si = 0;
	while (si < SZ(S) && S[si] != '.')res += S[si++];
	if (si < SZ(S) && S[si] == '.')si++;
	rep(i, 0, 4)
	{
		if (si < SZ(S))res += S[si];
		else res += '0';
		si++;
	}

	return stoi(res);
}

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

	int X, Y, R;
	X = dec();
	Y = dec();
	R = dec();

	int lx = X - R, rx = X + R;
	while (lx % 10000 != 0)lx++;
	while (rx % 10000 != 0)rx--;

	int ans = 0;
	for (int x = lx; x <= rx; x += 10000)
	{
		int dx = abs(x - X);
		int l = Y, r = Y + R + 1;
		while (r - l > 1)
		{
			int mid = (l + r) / 2;
			int dy = abs(mid - Y);
			if (dx*dx + dy * dy <= R * R)
			{
				l = mid;
			}
			else
			{
				r = mid;
			}
		}
		l -= Y;
		int dy = Y - l;
		int uy = Y + l;
		if (uy > 0)uy /= 10000;
		else
		{
			uy = (uy - 9999) / 10000;
		}
		if (dy > 0)dy = (dy + 9999) / 10000;
		else dy /= 10000;
		ans += uy - dy + 1;
	}

	cout << ans << endl;

	return 0;
}


/*
			Saturday 13 March 2021 05:35:07 PM IST
					@uthor::astrainL3gi0N
*/

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

typedef long long int ll;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::pair<int,int> ii;
#define debg(x)	std::cerr<<(#x)<<" => "<<x<<'\n';
#define debgg(x,y)	std::cerr<<(#x)<<" => "<<x<<'\t'<<(#y)<<' '<<y<<'\n';
#define len(a) (int)(a).size()
#define all(x) x.begin(),x.end()
const int mod = 1'0000'0000'7;
//const int mod = 998244353;
//cout.unsetf(ios::floatfield);cout.precision(10);cout.setf(ios::fixed,ios::floatfield);

bool comp (int x, int y) {
    return x > y;
}
void printarr (int arr[], int n) {
    for(int i = 0; i < n; ++i)
        std::cerr<<arr[i]<<(i<n-1?' ':'\n');
}
template < typename T> void  printv (T &a) {
    for (auto it = a.begin(); it != a.end(); ++it)
        std::cerr<<*it<<' ';
    std::cerr<<'\n';
}

const int maxn = 200009;
//int t[510][510];
ll ans;
int arr[maxn];

void solve ()
{
    bool ok = false;
    int n,m,k,q;  std::cin>>m>>k;
    ans = 0;
    std::cout<<(k%m == 0?"Yes":"No");
    std::cout<<'\n';
}
void sol ()
{
    //test
}

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

#include <iostream>
using namespace std;
int main() {
  int m;
  while(cin>>m){
    int h;
    cin>>h;
    if(h%m){
      cout<<"No"<<endl;
    }
    else{
      cout<<"Yes"<<endl;
    }
  }
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
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;}
//vector<int> bucket[MAX_N/1000];
constexpr lint MOD=1000000007;
//constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/

int main(void){
    int N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N);
    lint sum[N+1]={};
    rep(i,N) sum[i+1]=sum[i]+A[i];
    double ans=LINF;
    rep(i,N){
        double use=(double)A[i]/2;
        use*=N;
        double over=(sum[N]-sum[i+1]);
        over-=(N-1-i)*A[i];
        ans=min(ans,use+over);
    }
    cout << ans/N << endl;
}

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

int main()
{
  int n;
  cin >> n;
  double a[n];
  for(int i=0;i<n;i++){
  	cin >> a[i];
  }
  sort(a,a+n);
  double x = a[n / 2] / 2;
  double exp=0;
  for(int i=0;i<n;i++){
    exp += a[i] - min(a[i], 2*x);
  }
  exp /= n;
  exp += x;
  cout << fixed << setprecision(10) << exp << endl;

  return 0;
}


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

////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
//#define mod 9999991
long mod=9999991;
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getline(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int,int> a,pair<int,int> b){
    double x=(double )a.first/a.second;
    double y=(double )b.first/b.second;
    return x<y;}
long Pow(long x, long y) {
    if(y == 0)return 1;
    long res=Pow(x,y/2)%mod;
    res=(res*res)%mod;
    if(y&1)res=(res*x)%mod;
    return res;
}
#define printcase(x)  cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a,b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
long t,n,m,f=0,ans,a,b,q;
long tmp;

struct point{
    double x,y;
    point(){x=y=0.0;}
    point(double _x,double _y):x(_x),y(_y){}
    bool operator==(point other) const {
        return (fabs(x-other.x)<esp && fabs(y-other.y)<esp);
    }
    bool operator<(point other) const {
        if(fabs(x-other.x)>esp){
            return x<other.x;
        }
        return y<other.y;
    }
};
struct vec{
    double x,y;
    vec(double _x, double _y) : x(_x), y(_y) {}
};
struct line{
    double a,b,c;
    line() {a=b=c=1.0;}
    line(double _a, double _b, double _c) : a(_a), b(_b), c(_c) {}
};
double distOfPoint(point p1,point p2){
    return hypot(p1.x-p2.x,p1.y-p2.y);
}
line pointToLine(point p1,point p2){
    line l;
    if(fabs(p1.x-p2.x)<esp){
        l.a=1.0;l.b=0.0;l.c=-p1.x;
    }
    else{
        l.a=-((double)(p1.y-p2.y)/(p1.x-p2.x));
        l.b=1.0;
        l.c=-(l.a*p1.x+p1.y);
    }
    return l;
}
vec toVec(point p1,point p2){
    return {p2.x-p1.x,p2.y-p1.y};
}
vec scale(vec v,double s){
    return {v.x*s,v.y*s};
}
point translate(point p,vec v){
    return {p.x+v.x,p.y+v.y};
}
double dot(vec v1,vec v2){
    return v1.x*v2.x+v1.y*v2.y;
}
double norm_sq(vec v){
    return v.x*v.x+v.y*v.y;
}

double distToLineSeg(point p1,point p2,point z,point &c){
    vec p1p2=toVec(p1,p2),p1z=toVec(p1,z);
    double u=dot(p1p2,p1z)/norm_sq(p1p2);
    if(u<0){
        c=p1;
        return distOfPoint(z,p1);
    }
    if(u>1){
        c=p2;
        return distOfPoint(z,p2);
    }
    c=translate(p1,scale(p1p2,u));
    return distOfPoint(z,c);
}

int main() {
///<editor-fold desc="ios">
    IOS
#ifdef _AD_
    filein //fileout
#endif
///</editor-fold>
    int in=1,o;
    long c,d,count=0;
    string s;
    cin>>n;
    for(int i = 1; ; ++i){
        s=to_string(i)+to_string(i);
        m=stoll(s);
        if(m<=n){
            count++;
            //cout<<m<<endl;
        }
        else{
            break;
        }
    }
    cout<<count<<endl;
}

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll loop = 1100000;
    ll ans = 0;
    repd(i, 1, loop) {
        string temp = to_string(i);
        temp += temp;
        ll num = stoll(temp);
        if (num <= n) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

template <class T>
T fp(T x, long long e) {
	T ans(1);
	for(; e > 0; e /= 2) {
		if(e & 1) ans = ans * x;
		x = x * x;
	}
	return ans;
}

const ll mod = round(1e9)+7;
struct mb {
	mb(int v = 0) : val(v < 0 ? v + mod : v) {}
	mb(ll v){ val = (v%mod+mod)%mod; }
	int val;

	void operator += (mb o) { *this = *this + o; }
	void operator -= (mb o) { *this = *this - o; }
	void operator *= (mb o) { *this = *this * o; }
	mb operator * (mb o) { return (int)((long long) val * o.val % mod); }
	//mb operator / (mb o) { return *this * fp(o, mod - 2); }
	//bool operator == (mb o) { return val==o.val; } //usar soh para hashes
	mb operator + (mb o) { return val + o.val >= mod ? val + o.val - mod : val + o.val; }
	mb operator - (mb o) { return val - o.val < 0 ? val - o.val + mod : val - o.val; }
};

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	set<int> st;
	cin >> n;
	fr(i,n){
		int x; cin >> x;
		st.emplace(x);
	}
	st.emplace(0);
	vector<int> v(all(st));

	mb ans = 1;
	fr(i,sz(v)-1){
		ans*=v[i+1]+1-v[i];
	}
	cout << ans.val << "\n";
}

#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#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;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); ++i)
#define F0R(a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; --i)
#define F0Rd(a) for (int i = (a)-1; ~i; --i)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main() {
    fast();
    cin >> n;
    F0R(n) cin >> a[i];
    int ans = 0;
    int mx = 0;
    for (int i = 2; i <= 1000; ++i) {
        int curr = 0;
        for (int j = 0; j < n; ++j) {
            if (a[j] % i == 0) ++curr;
        }
        if (curr > mx) {
            mx = curr;
            ans = i;
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#define mod 1000000007
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define T(a) ll a; cin >> a;
#define TT(t) T(t); while (t--)
#define pb push_back
#define mp make_pair

const int INF = 1 << 29;

typedef long long ll;
#define int long long
inline int two(int n)
{
    return 1 << n;
}
inline int test(int n, int b)
{
    return (n >> b) & 1;
}
inline void set_bit(int &n, int b)
{
    n |= two(b);
}
inline void unset_bit(int &n, int b)
{
    n &= ~two(b);
}
inline int last_bit(int n)
{
    return n & (-n);
}
inline int ones(int n)
{
    int res = 0;
    while (n && ++res)
        n -= n & (-n);
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0 || b == 0)
        return 0;
    if (a == b)
        return a;
    if (a > b)
        return gcd(a - b, b);
    return gcd(a, b - a);
}
ll lcm(ll a, ll b)
{
    return (a * b) / gcd(a, b);
}
ll max(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}
ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
ll powermod(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}
ll mulmod(ll a, ll b)
{
    ll res = 0;
    a %= mod;
    while (b)
    {
        if (b & 1)
            res = (res + a) % mod;
        a = (2 * a) % mod;
        b >>= 1;
    }
    return res;
}
bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
long double dist(ll x1, ll y1, ll x2, ll y2)
{
    return (long double)sqrt((long double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
}
ll squaredist(ll x1, ll y1, ll x2, ll y2)
{
    return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll nCr(ll n, ll r)
{
    if (r == 0)
        return 1;
    return (n * nCr(n - 1, r - 1)) / r;
}
ll countDivisors(ll n)
{
    ll cnt = 0;
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;
            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}
ll modulo(ll a, ll b)
{
    ll r = a % b;
    return r < 0 ? r + b : r;
}
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
using namespace std;
//using namespace boost::multiprecision;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int ns = 0;
    for(int i = 1; i <= n; i++)
    {
        int m = i;
        bool flag = true;
        while(m)
        {
            flag = flag && (m%10 != 7);
            m/=10;
        }
        m = i;
        while(m)
        {
            flag = flag && (m%8 != 7);
            m/=8;
        }
        // ns += flag;
        if(flag)
        {
            ns++;
        }
    }
    cout<<ns;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define int ll
#define ld long double
#define reps(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rep(i,n) reps(i,0,n)
#define rreps(i,s,n) for(int i=(int)(s-1);i>=n;i--)
#define rrep(i,n) rreps(i,n,0)
#define all(v) (v).begin(),(v).end()
#define mset(a,n) memset(a,n,sizeof(a))
#define eras(v,n) (v).erase(remove(all(v),n),(v).end())
#define uni(v) sort(all(v));(v).erase(unique(all(v)),(v).end())
#define bcnt(i)  __builtin_popcount(i)
#define fi first
#define se second
constexpr ll INF = 1e18;
constexpr ll MOD = 1000000007;
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 min(vector<T> &v) { return *min_element(v.begin(),v.end()); }
template<class T>T max(vector<T> &v) { return *max_element(v.begin(),v.end()); }
template<class T>T modpow(T a, T b, T m) { a %= m; T r = 1; while (b > 0) { if (b & 1) r = (r * a) % m; a = (a * a) % m; b >>= 1; } return r; }
ll modinv(ll a,ll m=MOD) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template<class T>string radixconv(T n, T k){ string s; while(n/k){ s=to_string(n%k)+s; n/=k; } s=to_string(n%k)+s; return s; }

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    string s;
    cin >> s;
    int n=s.size();
    string ans;
    if(n==1){
        if(s[0]=='8')ans="Yes";
        else ans="No";
    }else if(n==2){
        ans="No";
        reps(i,10,100)if(i%8==0){
            string a=to_string(i);
            vector<int> cnt(10,0);
            cnt[a[0]-'0']++;
            cnt[a[1]-'0']++;
            bool b=1;
            reps(j,0,10)if(count(all(s),(char)('0'+j))<cnt[j])b=0;
            if(b){
                ans="Yes";
            }
        }
    }else{
        ans="No";
        reps(i,100,1000)if(i%8==0){
            string a=to_string(i);
            vector<int> cnt(10,0);
            cnt[a[0]-'0']++;
            cnt[a[1]-'0']++;
            cnt[a[2]-'0']++;
            bool b=1;
            reps(j,0,10)if(count(all(s),(char)('0'+j))<cnt[j])b=0;
            if(b){
                ans="Yes";
            }
        }
    }
    cout << ans << endl;
    return 0;
}


//#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

typedef long long ll;
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 4e4;
const int M = 1234;
const int LOG = 18;

void solve(int TC) {
    int n;
    cin >> n;

    set<string> st;
    for (int i = 1; i <= n; i++){
        string s;
        cin >> s;
        string t = s;
        if (*t.begin() == '!') t.erase(t.begin()); else
            t = "!" + t;
        if (st.count(t)){
            cout << (*s.begin() != '!' ? s : t) << endl;
            return;
        }
        st.insert(s);
    }

    cout << "satisfiable";

}

int main() {
    startTime = clock();
    ios_base::sync_with_stdio(false);

    bool llololcal = false;
#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    llololcal = true;
#endif

    int TC = 1;
    //cin >> TC;

    for (int test = 1; test <= TC; test++) {
        debug(test);
        solve(test);
    }

    if (llololcal) cerr << endl << "Time: " << getCurrentTime() * 1000 << " ms" << endl;

    return 0;
}

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

ll INF = 1e18;

int main() {

  int n;
  cin >> n;
  vector<string> a;
  set<string> b;
  int count = 0;
  rep(i,n){
    string s;
    cin >> s;
    if(s[0] == '!'){
      b.insert(s);
    }
    else{
      a.push_back(s);
      count++;
    }
  }
  rep(i,count){
    if(b.count('!'+a[i])){
      cout << a[i] << endl;
      return 0;
    }
  }
  cout << "satisfiable" << endl;

  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i:x){cout << i << " ";} cout << endl;}
#define isin(x,l,r) ((l)<=(x) && (x)<(r))
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return true;} else return false;}
template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return true;} else return false;}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> B(N);
    rep(i, N) cin >> B[i];
    if (inner_product(A.begin(), A.end(), B.begin(), 0)) puts("No");
    else puts("Yes");
    return 0;
}

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

int main(){
    long long N,ans;
    string yn;
    cin >> N;
    ans = 0;
    vector<int> A(N);
    vector<int> B(N);
    rep(i,N) cin >> A.at(i);
    rep(i,N) cin >> B.at(i);
    for(int j = 0; j < N; j++){
        ans += A[j] * B[j];
    }
    if(ans == 0) yn = "Yes";
    else yn = "No";
    cout << yn << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define N 2005
#define db double
const db eps=1e-3,pi=3.14159265358979323846264337328451;
int n,t,j,i,cnt,tot,a[N],b[N],ans,c[N],d[N];
db alp,ang,dis;
struct dot{db x,y;}dt[N],R[N];
inline bool eq(db aa,db bb){
	return aa<bb+eps&&bb<aa+eps;
}
inline bool cmp(dot aa,dot bb){
	if(eq(aa.x,bb.x))return aa.y<bb.y;
	return aa.x<bb.x;
}
bool check(db alp){
	int i;
	for(i=1;i<=n;++i){
		dis=sqrt((a[i]*a[i]+b[i]*b[i]));
		ang=atan2(b[i],a[i])+alp;
		dt[i].x=cos(ang)*dis;
		dt[i].y=sin(ang)*dis;
	}
	sort(dt+1,dt+n+1,cmp);
	db x=dt[1].x-R[1].x,y=dt[1].y-R[1].y;
	for(i=2;i<=n;++i){
		if(eq(dt[i].x-R[i].x,x)&&eq(dt[i].y-R[i].y,y))continue;
		else return 0;
	}
	return 1;
}
int main(){
	cin>>n;
	for(i=1;i<=n;++i){
		cin>>a[i]>>b[i];
	}
	for(i=1;i<=n;++i){
		cin>>c[i]>>d[i];
		R[i].x=c[i];R[i].y=d[i];
	}
	sort(R+1,R+n+1,cmp);
	for(i=-40;i<=40;++i){
		for(j=-40;j<=40;++j){
			if(check(atan2(j,i))){
				return cout<<"Yes",0;
			}
		}
	}
	cout<<"No";
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = b - 1; a <= i; i--)
ll MOD = 1000000007;
ll MOD2 = 998244353;

ll N;
vector<pair<ll, ll>> S, T;
vector<vector<vector<ll>>> rotation;

int main () {
  cin >> N;
  rep (i, 0, N) {
    ll x, y;
    cin >> x >> y;
    S.push_back(make_pair(x * N, y * N));
  }
  rep (i, 0, N) {
    ll x, y;
    cin >> x >> y;
    T.push_back(make_pair(x * N, y * N));
  }

  if (N == 1) {
    cout << "Yes";
    return 0;
  }

  {
    ll x0, y0;
    x0 = y0 = 0;
    rep (i, 0, N) {
      x0 += S[i].first;
      y0 += S[i].second;
    }
    x0 /= N, y0 /= N;
    rep (i, 0, N) {
      S[i].first -= x0;
      S[i].second -= y0;
    }

    x0 = y0 = 0;
    rep (i, 0, N) {
      x0 += T[i].first;
      y0 += T[i].second;
    }
    x0 /= N, y0 /= N;
    rep (i, 0, N) {
      T[i].first -= x0;
      T[i].second -= y0;
    }
  }
  sort(T.begin(), T.end());

  // cout << "S\n";
  // rep (i, 0, N) cout << S[i].first << " " << S[i].second << endl;
  // cout << "\nT\n";
  // rep (i, 0, N) cout << T[i].first << " " << T[i].second << endl;

  {
    ll k = -1, denom = 0;
    while (denom == 0) {
      k++;
      denom = T[k].first * T[k].first + T[k].second * T[k].second;
    }

    // cout << T[k].first << " " << T[k].second << " " << denom << endl;

    rep (i, 0, N) {
      ll denom2 = S[i].first * S[i].first + S[i].second * S[i].second;
      if (denom != denom2) continue;
      ll sin_nume, cos_nume;
      sin_nume = S[i].first * T[k].second - S[i].second * T[k].first;
      cos_nume = S[i].first * T[k].first + S[i].second * T[k].second;

      vector<vector<ll>> r = {
        {cos_nume, -sin_nume},
        {sin_nume, cos_nume},
        {denom}
      };
      rotation.push_back(r);
    }
  }

  // for (auto r : rotation) {
  //   cout << r[0][0] << " " << r[0][1] << " "<< r[1][0] << " "<< r[1][1] << " "<< r[2][0] << "\n";
  // }

  for (const auto& r : rotation) {
    vector<pair<ll, ll>> U;
    bool flag = 0;
    rep (i, 0, N) {
      auto [x1, y1] = S[i];
      ll x2 = x1 * r[0][0] + y1 * r[0][1];
      ll y2 = x1 * r[1][0] + y1 * r[1][1];

      if (x2 % r[2][0] != 0) flag = true;
      if (y2 % r[2][0] != 0) flag = true;
      if (flag) break;

      x2 /= r[2][0];
      y2 /= r[2][0];
      U.push_back(make_pair(x2, y2));
    }
    if (flag) {
      // cout << "coor in not an integer\n";
      continue;
    }
    sort(U.begin(), U.end());

    // cout << "\nU\n";
    // rep (i, 0, N) cout << U[i].first << " " << U[i].second << endl;

    rep (i, 0, N) {
      if (T[i] != U[i]) {
        flag = true;
        break;
      }
    }
    if (flag) {
      // cout << "coor dont match\n";
      continue;
    }
    else {
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";
  return 0;
}


#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;

long long gcd(long long a, long long b){
    while (a != 0 && b != 0){
        if (a >= b) a %= b;
        else b %= a;
    }
    return a + b;
}

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

signed main(){
    ll N;
    cin >> N;
    ll L = 1;
    for(ll i = 2; i <= N; i++) L = lcm(L, i);
    PRINT(L + 1);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ls rt<<1
#define rs rt<<1|1
const int N=1e2+5;
const int INF=0x3f3f3f3f;
const int mod=1e4+7;
const double eps=1e-9;
const double pi=acos(-1);
bool chk[N];
int cnt,p[N];
void prework(ll &ans){
    chk[1]=1;
    for(int i=2;i<N;++i){
        if(!chk[i]) p[cnt++]=i;
        for(int j=0;j<cnt&&i*p[j]<N;++j){
            chk[i*p[j]]=1;
            if(i%p[j]==0) break;
        }
    }
    ans=1;
    for(int i=0;i<cnt;++i){
        if(p[i]>30) break;
        ans*=p[i];
    }
    ans=ans*9*8*5+1;
}
int main(){
    ll ans;
    prework(ans);
    int n;scanf("%d",&n);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int main (){
  string s;
  cin >> s;
  char c = s.front();
  s.erase(0,1);
  s.insert(s.end(), c);
  cout << s;
  return 0;
}

#include<bits/stdc++.h>

#define fox(i,a,b) for(int i=a;i<=b;++i)
#define ll long long

using namespace std;

int _x, _f; char _c;
inline int rd() {
	_x = 0, _f = 1, _c = getchar();
	for (; !isdigit(_c); _c = getchar()) if (_c == '-') _f = 0;
	for (; isdigit(_c); _c = getchar()) _x = _x * 10 + _c - '0';
	return _f ? _x : -_x;
}

char s[10];

signed main() {
	scanf("%s", s + 1);
	cout << s[2] << s[3] << s[1] << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using P = pair<int64_t,int64_t>;
const int MAX = (1<<19);
int64_t dp[MAX];
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<P>> vec(N,vector<P>(0));
  for(int i=0; i<M; i++){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X--;
    vec[X].push_back(P(Y,Z));
  }
  dp[0] = 1;
  for(int i=0; i<(1<<N); i++){
    int c = 0;
    vector<int> sum(N);
    for(int j=0; j<N; j++){
      if(i & (1<<j)){
        c++;
        sum[j]++;
      }
      if(j != 0){
        sum[j] += sum[j-1];
      }
    }
    //何を追加するか？
    for(int j=0; j<N; j++){
      if(i & (1<<j)){
        continue;
      }
      bool flag = true;
      for(int k=0; k<vec[c].size(); k++){
        auto[y,z] = vec[c][k];
        if(j < y){
          z--;
        }
        if(sum[y-1] > z){
          flag = false;
          break;
        }
      }
      if(flag){
        dp[i|(1<<j)] += dp[i];
      }
    }
  }
  cout << dp[(1<<N)-1] << endl;
}

#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<(a)<<endl
#define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

int main(){
  cout<<setprecision(1000);
  ll N,M;
  cin>>N>>M;
  vector<ll> dp(1LL<<N);
  vector<vector<pll>> cond(N);
  REP(M){
    ll x,y,z;
    cin>>x>>y>>z;
    --x;--y;
    cond[x].push_back(pll(y,z));
  }
  auto f=[](ll num,ll y,ll z){
    ll mask=(1LL<<(y+1))-1;
    num&=mask;
    return __builtin_popcountll(num)<=z;
  };
  dp[0]=1;
  For(j,(1LL<<N)){
    ll n=__builtin_popcountll(j);
    if(n==N)continue;
    ll cur=1;
    REP(N){
      if((cur&j)==0){
        ll jj=(j|cur);
        ([&]() {
          FOR(cidx, n, N)
          {
            for (auto &&[y, z] : cond[cidx])
            {
              if (!f(jj, y, z))
              {
                return;
              }
            }
          }
          dp[jj]+=dp[j];
        })();
      }
      cur<<=1;
    }
  }
  dump(dp);
  cout<<dp[(1LL<<N)-1]<<endl;
  return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
// 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; }

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}

struct UnionFind {
  vector<ll> data;

  UnionFind(ll sz) { data.assign(sz, -1); }

  bool unite(ll x, ll y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  ll find(ll k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  ll size(ll k) { return (-data[find(k)]); }

  bool same(ll x, ll y) {
    int rx = find(x);
    int ry = find(y);
    return rx == ry;
  }
  // {1:[1,2,3], 4:[4,5]}
  map<ll, vll> groups() {
    map<ll, vll> m;
    rep(i, data.size()) {
      ll root = find(i);
      m[root].emplace_back(i);
    }
    return m;
  }

  map<ll, set<ll>> group_set() {
    map<ll, set<ll>> m;
    rep(i, data.size()) {
      ll root = find(i);
      m[root].insert(i);
    }
    return m;
  }
};

mll *classes[200050];

void merge_map(mll *m1, mll *m2) {
  auto ite = (*m2).begin();
  for (; ite != end(*m2); ite++) {
    ll key = (*ite).first;
    ll val = (*ite).second;
    // cout << key << ":" << val << endl;

    (*m1)[key] += (*m2)[key];
  }
}

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll N, Q;
  scanf("%lld %lld", &N, &Q);

  UnionFind uf(N);

  rep(s, N) {
    ll v;
    scanf("%lld", &v);

    v--;

    classes[s] = new mll();
    (*classes[s])[v] = 1;
  }

  rep(i, Q) {
    ll type, a, b;
    scanf("%lld %lld %lld", &type, &a, &b);

    a--;
    b--;

    ll group_a = uf.find(a);

    if (type == 1) {
      if (uf.same(a, b)) continue;

      ll group_b = uf.find(b);

      uf.unite(a, b);

      mll *m1 = classes[group_a];
      mll *m2 = classes[group_b];

      mll *src;
      mll *dest;

      if (m1->size() > m2->size()) {
        dest = m1;
        src = m2;
      } else {
        dest = m2;
        src = m1;
      }

      merge_map(dest, src);

      classes[group_a] = dest;
      classes[group_b] = dest;
    }

    if (type == 2) {
      //
      cout << ((*classes[group_a])[b]) << endl;
    }
  }

  ll ans = 0;

  // cout << ans << endl;
}

//Bismillahir Rahmanir Raheem
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
#define fr1(i,a) for(int i=1;i<=a;i++)
#define iter(x)  x.begin(),x.end()
#define Memset(a,x,n) for(int i=0;i<n;i++)a[i]=x;
#define fi first
#define si second
//std::string s=std::bitset<M>(n).to_string();  //number to binary string
//lower_bound returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’.
//upper_bound returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘val’.
//if mod is prime modInv(a,mod)==binExp(a,mod-2);
typedef pair<lli,lli>pll;
void solve()
{

}
int main()
{
    lli n,q;
    cin>>n>>q;
    vector<lli>a(n+1);
    a[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    lli p=0;
    vector<lli>l,r,e;
    for(int i=0;i<=n;i++)
    {
        if(i!=n and a[i+1]!=a[i]+1)
        {
            l.pb(p+1);
            p+=(a[i+1]-a[i]-1);
            r.pb(p);
            e.pb(a[i]+1);
        }
    }
    l.pb(p+1);
    r.pb(1e18+10);
    e.pb(a[n]+1);
    lli s;
//    frr(i,l.size())
//    {
//        cout<<l[i]<<" "<<r[i]<<" "<<e[i]<<endl;
//    }
    for(int i=0;i<q;i++)
    {
        cin>>s;
        lli x=lower_bound(l.begin(),l.end(),s)-l.begin();
        lli y=lower_bound(r.begin(),r.end(),s)-r.begin();
        if(x>y)
        {
            x--;
        }
        cout<<e[x]+(s-l[x])<<endl;
    }
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,obs_n;
const int N=2e5+5;
set<int>row[N],col[N];
int seg[4*N],a[N];

void update(int index,int data,int segindex,int l,int r)
{
    if(l==r){
        seg[segindex]=data;
        return ;
    }
    int mid=(l+r)/2;
    if(index<=mid){
        update(index,data,2*segindex+1,l,mid);
    }else{
        update(index,data,2*segindex+2,mid+1,r);
    }
    seg[segindex]=seg[2*segindex+1]+seg[2*segindex+2];
}

int query(int index,int l,int r,int ql,int qr)
{
    if(l>=ql && r<=qr)  return seg[index];
    if(l>qr || r<ql)    return 0;
    int mid=(l+r)/2;
    int q1=query(2*index+1,l,mid,ql,qr);
    int q2=query(2*index+2,mid+1,r,ql,qr);
    return q1+q2;
}

void buildtree(int l,int r,int index)
{
    if(l==r){
        seg[index]=a[l];
        return;
    }
    int mid=(l+r)/2;
    buildtree(l,mid,2*index+1);
    buildtree(mid+1,r,2*index+2);
    seg[index]=seg[2*index+1]+seg[2*index+2];
}

//1- based
void solve(){
	cin>>n>>m>>obs_n;
	for(int i=0;i<obs_n;i++){
		int u,v;cin>>u>>v;
		u--;v--;
		row[u].insert(v);
		col[v].insert(u);
	}
	int block_c=(row[0].empty()?m-1:(*row[0].begin()-1));
	for(int i=0;i<=block_c;i++)	a[i]=1;
	buildtree(0,m-1,0);

	int ans=block_c+1;
	int free_r=(col[0].empty()?n-1:(*col[0].begin()-1));
	for(auto x:row[0])	update(x,0,0,0,m-1);

	// cout<<ans<<"\n";
	for(int r=1;r<n;r++){
		for(auto x:row[r])	update(x,0,0,0,m-1);

		if(r<=free_r){
			int block_c=(row[r].empty()?m-1:(*row[r].begin()-1));
			// cout<<r<<" "<<block_c<<"\n";
			// cout<<query(0,0,m-1,block_c+1,m-1)<<"\n";
			if(block_c+1>m-1)	ans+=block_c+1;
			else				ans+=block_c+1+query(0,0,m-1,block_c+1,m-1);
		}else{
			ans+=query(0,0,m-1,0,m-1);
		}
		// cout<<ans<<"\n";

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

main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    solve();
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7
#define INF LONG_MAX/3
#define bit(n) (1LL<<(n))

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; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct segtree {
	vector<long long> data;
	long long n;
	segtree(long long nin){
		n = pow( 2, ceil( log(nin) / log(2) ) );
		long long size = 2 * n - 1;
		this->data.resize(size, 0);
	}

	//API for update val
	void update(long long idx, long long val){
		update(idx, val, 0, 0, n);
	}

	long long update(long long idx, long long val, long long node_id, long long left, long long right){
		//if query idx is within range return val
		if( !( left <= idx && idx < right ) ){
			return data[node_id];
		}
		if( left + 1 < right ) {
			//when node range is not 1, get update children val and update node data
			long long mid = (left + right) / 2 ;
			long long L = update(idx, val, 2 * node_id + 1, left, mid);
			long long R = update(idx, val, 2 * node_id + 2, mid, right);
			data[node_id] = L + R;
		} else {
			//when node range is 1, update node data
			data[node_id] = data[node_id] + val;
		}
		return data[node_id];
	}

	//API for get value of [l, r)
	long long get(long long l, long long r){
		return get(l, r, 0, 0, n);
	}

	/*
	 *internaly used function
	 *query_l: query left range
	 *query_r: query right range
	 *node_id: node id of
	 *node_l:  node left range
	 *node_r:  node right range
	 */
	long long get(long long query_l, long long query_r, long long node_id, long long node_l, long long node_r){
		//query range is outside of node range: return INF
		if( query_r <= node_l || node_r <= query_l ){
			return 0;
		}
		//query range is within node range: return node val
		if( query_l <= node_l && node_r <= query_r ){
			return data[node_id];
		}
		long long mid = (node_l + node_r) / 2;
		long long L = get(query_l, query_r, 2 * node_id + 1, node_l, mid);
		long long R = get(query_l, query_r, 2 * node_id + 2, mid, node_r);
		return L + R;
	}
};

vector<ll> yvec[200005];

int main(){
	ll H, W, M;
	cin >> H >> W >> M;
	vector<ll>X(M);
	vector<ll>Y(M);
	ll maxx = W;
	ll maxy = H;

	segtree ysg(H+5);;

	rep(i, M) cin >> Y[i] >> X[i];
	rep(i, M) X[i]--;
	rep(i, M) Y[i]--;

	rep(i, M) {
		yvec[X[i]].push_back(Y[i]);
		if(Y[i] == 0) chmin(maxx, X[i]);
		if(X[i] == 0) chmin(maxy, Y[i]);
	}
	rep(i, W) sort(yvec[i].begin(), yvec[i].end());

	set<ll> ngy;
	rep(i, maxy) ysg.update(i, 1);
	ll ans = 0;

	for(ll y = maxy; y < H; y++) ngy.insert(y);

	for(ll x = 0; x < W; x++) {
		ll miny = H;
		if(x >= maxx) miny = 0;
		for(ll y: yvec[x]) {
			chmin(miny, y);
			if(!ngy.count(y)) {
				ngy.insert(y);
				ysg.update(y, -1);
			}
		}
		//cout << "x = " << x << " uekara " << miny << " yokokara " << ysg.get(miny, H) << endl;
		//上からいけるやつ
		ans += miny;

		//上からいけなくて横からいけるやつ
		ans += ysg.get(miny, H);
	}

	cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, c, n) for (ll i = c; i < (n); ++i)
#define yn(ok, True, False) if (ok) { p(True) } else {p(False)};
//以下debug用
#define d(x) cout << #x << "; " << x << endl;
#define p(x) cout << x << endl;
#define f(x) for (long unsigned int i = 0; i < x.size(); i++) cout << #x << "[" << i << "]; " << x[i] << endl;

bool ok = false;
vector<int> datas;
const int inf = 1001001001;
const ll INF = 1LL << 60; //無限大

int main(){

  ll n,k;
  cin >> n >> k;
  rep(i,k){
    if (n%200 == 0){
      n = n/200;
    }else{
      n = (n*1000) + 200;
    }
    // d(n)
  }
  p(n)
  return 0;
}

#include <iostream>

int main()
{
  long long int N;
  int K;
  std::cin >> N >> K;
  for (int i = 0; i < K; i++)
  {
    if (N % 200 == 0)
    {
      N /= 200;
    }
    else
    {
      N *= 1000;
      N += 200;
    }
  }
  std::cout << N << std::endl;
}


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

const int N = 18;
int connect[N],f[1 << N];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for(int i = 0;i < n;++i)	connect[i] |= (1 << i);

	for(int i = 0;i < m;++i)
	{
		int u,v;scanf("%d%d",&u,&v);
		--u;--v;
		connect[u] |= (1 << v);
		connect[v] |= (1 << u);
	}

	f[0] = 0;
	for(int i = 1;i < (1 << n);++i)
	{
		f[i] = 1e5+7;
		bool indp = 1;
		for(int j = 0;j < n;++j)
			if((i >> j & 1) && ((connect[j] & i) != i))
				indp = 0;
		if(indp)	f[i] = 1;
		for(int s = i;s;s = (s - 1) & i)
			f[i] = min(f[i],f[s] + f[i - s]);
	}
	printf("%d",f[(1 << n) - 1]);
    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#define re register
#define ri register int
#define For(i,a,b) for(ri i=a;i<=b;++i)
#define iFor(i,a,b) for(ri i=a;i>=b;--i)
#define File(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
#define gtch() (_p1==_p2&&(_p2=(_p1=buf)+fread(buf,1,1<<22,stdin),_p1==_p2)?EOF:*_p1++)
using namespace std;
typedef long long ll;
char buf[1<<22],*_p1=buf,*_p2=buf;
inline ll fr(){
	re ll r=0;re char c=gtch();ri b=0;
	while(!isdigit(c))b=(c=='-'),c=gtch();
	while(isdigit(c))r=r*10+c-'0',c=gtch();
	return b?-r:r;
}
inline int fc(){
	re char c=gtch();
	while(c==' '||c=='\n')c=gtch();
	return c=='.';
}
const ll MOD=1e9+7;
const int MAXN=2005;
const ll INF=9e17+5;
int n,m;
int ar[MAXN][MAXN];
int up[MAXN][MAXN],dn[MAXN][MAXN],lt[MAXN][MAXN],rt[MAXN][MAXN];
ll p2[MAXN*MAXN];
int tot;
inline void input(){
	n=fr(),m=fr();
	For(i,1,n) For(j,1,m) ar[i][j]=fc(),tot+=ar[i][j];
	p2[0]=1;For(i,1,n*m) p2[i]=p2[i-1]*2%MOD;
	For(i,1,n) For(j,1,m) if(ar[i][j-1]) lt[i][j]=lt[i][j-1]+1;else lt[i][j]=0;
	For(i,1,n) iFor(j,m,1) if(ar[i][j+1]) rt[i][j]=rt[i][j+1]+1;else rt[i][j]=0;
	For(i,1,n) For(j,1,m) if(ar[i-1][j]) up[i][j]=up[i-1][j]+1;else up[i][j]=0;
	iFor(i,n,1) For(j,1,m) if(ar[i+1][j]) dn[i][j]=dn[i+1][j]+1;else dn[i][j]=0;
}
signed main(){
//	File("temp")
	input();
	ll ans=0;
	For(i,1,n) For(j,1,m){
		if(!ar[i][j]) continue;
		ll t=lt[i][j]+rt[i][j]+up[i][j]+dn[i][j]+1;
		ans+=(p2[t]-1)*p2[tot-t]%MOD;
		ans%=MOD;
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N;
string S, T;

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

    cin >> N >> S >> T;

    ll ans = 0;

    int pneed = 0;
    int par = (S[0] - '0') ^ (T[0] - '0');
    for (int i = 1; i < N; i++)
    {
        int ds = S[i] - '0', dt = T[i] - '0';

        int nneed;
        if (S[i-1] == '0')
            nneed = pneed;
        else
            nneed = max (0, pneed - 1);
        while (nneed % 2 != par) nneed++;
        ans += nneed;
        pneed = nneed;

        par ^= (ds ^ dt);
    }
    if (par || pneed > (S[N-1] - '0')) cout << "-1\n";
    else cout << ans << "\n";
}

#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repd(z, x, y) for(int z=x;z>=y;--z)
#define com bool operator<(const node &b)const
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 5e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;
char s[maxn], t[maxn];

void solve() {
    int n;
    queue<int> q;
    cin >> n >> (s + 1) >> (t + 1);
    rep(i, 1, n)if (s[i] == '1')q.push(i);
    int ans = 0;
    rep(i, 1, n) {
        if (s[i] != t[i]) {
            while (!q.empty() && q.front() <= i)q.pop();
            if (q.empty()) {
                cout << -1;
                return;
            }
            s[q.front()] = '0';
            ans += q.front() - i;
            q.pop();
        }
    }
    cout << ans;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <numeric>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits>
#include <limits.h>
#include <iomanip>
#include <algorithm>
using namespace std;

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long
#define ull unsigned long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define mkp make_pair
#define fi first
#define se second

struct node {
    int left, right;
};

void solve() {
    int N;
    cin >> N;
    vector<int> X(N), C(N);
    vector<struct node> pos(N+2), dp(N+2);

    for(int i = 0; i <= N+1; i++) {
        pos[i].left = INT_MAX;
        pos[i].right = INT_MIN;
    }

    unordered_set<int> st;
    for(int i = 0; i < N; i++) {
        cin >> X[i] >> C[i];
        st.insert(C[i]);
        pos[C[i]].left = min(pos[C[i]].left, X[i]);
        pos[C[i]].right = max(pos[C[i]].right, X[i]);
    }
    st.insert(N+1);

    pos[N+1].left = pos[N+1].right = 0;
    pos[0].left = pos[0].right = 0;
    dp[0].left = dp[0].right = 0;
    for(int i = 1; i <= N+1; i++) {
        if(st.find(i) == st.end()) {
            pos[i].left = pos[i-1].left;
            pos[i].right = pos[i-1].right;
            dp[i].left = dp[i-1].left;
            dp[i].right = dp[i-1].right;
            continue;
        }
        dp[i].left = min(dp[i-1].left + abs(pos[i-1].left - pos[i].right) + abs(pos[i].right - pos[i].left),
                        dp[i-1].right + abs(pos[i-1].right - pos[i].right) + abs(pos[i].right - pos[i].left));
        dp[i].right = min(dp[i-1].left + abs(pos[i-1].left - pos[i].left) + abs(pos[i].right - pos[i].left),
                        dp[i-1].right + abs(pos[i-1].right - pos[i].left) + abs(pos[i].right - pos[i].left));
        //cout << imie(pos[i-1].left)  imie(pos[i-1].right) << '\n';
        //cout << imie(dp[i].left)  imie(dp[i].right) << '\n';
    }
   // cout << min(abs(pos[N].left) + dp[N].left,
           //     abs(pos[N].right) + dp[N].right);
    cout << min(dp[N+1].left, dp[N+1].right);
}

int32_t main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    IOS;

    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define int ll
#define count_one(a) __builtin_popcountll(a)
#define is_power_of_2(a) (a) & (a - 1) == 0
#define exit return 0
const double eps = 1e-10;
const double pi = acos(-1.0);
#define endl "\n"
#define flush() cout << flush
#define IOS                                                                    \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);
using namespace std;
void dbg_out() {
    cout << endl;
}
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
    cout << ' ' << H;
    dbg_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...)                                                               \
    cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__), cout << endl
#else
#define dbg(...)
#endif

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

#define inf (int)2E5 + 1
int n;
// 0 - left end
// 1 - right end
int dp[inf][2];
vector<int> loc[inf];

int32_t main() {
    IOS;
    cin >> n;
    int x, c;
    for (int i = 0; i < n; i++) {
        cin >> x >> c;
        loc[c].push_back(x);
    }

    for (int i = 1; i <= n; i++) {
        sort(loc[i].begin(), loc[i].end());
    }

    int start;

    for (start = 1; start <= n; start++) {
        if (loc[start].size()) {
            break;
        }
    }

    int prev = start;
    int prevEnd = 0;
    int prevStart = 0;
    for (int i = start; i <= n; i++) {
        if (!loc[i].size()) {
            continue;
        }

        int currLen = loc[i].size();
        int currStart = loc[i][0];
        int currEnd = loc[i][currLen - 1];
        // left end
        dp[i][0] = min(
            {dp[prev][1] + (abs(prevEnd - currEnd) + abs(currEnd - currStart)),
             dp[prev][0] +
                 (abs(prevStart - currEnd) + abs(currEnd - currStart))});

        // right end
        dp[i][1] =
            min({dp[prev][1] +
                     (abs(prevEnd - currStart) + abs(currEnd - currStart)),
                 dp[prev][0] +
                     (abs(prevStart - currStart) + abs(currEnd - currStart))});
        dbg(i);
        dbg(dp[i][0]);
        dbg(dp[i][1]);
        prev = i;
        prevEnd = loc[i][currLen - 1];
        prevStart = loc[i][0];
    }

    int prevLen = loc[prev].size();

    int ans = min(dp[prev][0] + abs(prevStart), dp[prev][1] + abs(prevEnd));

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