#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,(n)*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
unordered_map<int,bool> mp;
int t,n,x;
int main()
{
	read(t);
	while(t--) {
		read(n),mp.clear();
		rep(i,1,n) read(x),mp[x]^=1;
		if(n&1) {puts("Second");continue;}
		bool flag=false;
		for(auto &p:mp) if(p.second) flag=true;
		puts(flag?"First":"Second");
	}
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/

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

#include<cstdio>
#include<cstring>
#include<algorithm>

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

const int b = 8;
int A[100000];
int tmp[100001];
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
void okuri() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
	}
	else {
		ci += 8;
		tmp = *(ll*)ci;
		ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
	}
}

const int dm = 1 << 17;
char dn[dm], * di = dn;
const char f[10] = "First\n";
const char s[10] = "Second\n";

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

	int T = getint();

	int are = 1 << 14;
	int owa = are;
	rep(t, T) {
		int N = getint();

		if (N % 2) {
			rep(i, N) okuri();
			memcpy(di, s, 7);
			di += 7;
		}
		else {
			rep(i, N) A[i] = getint();
			if (N > 256) {
				rep(k, 4) {
					int kazu[1 << b] = {}, kazu2[1 << b] = {};
					rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
					rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
					for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
					k++;
					rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
					rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
					for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
				}
			}
			else sort(A, A + N);

			int mae = 0, k = 0;
			rep(i, N) {
				if (mae == A[i]) k++;
				else {
					if (k & 1) break;
					k = 1;
					mae = A[i];
				}
			}

			if (k & 1) {
				memcpy(di, f, 6);
				di += 6;
			}
			else {
				memcpy(di, s, 7);
				di += 7;
			}
		}
		if (t > owa) {
			owa += are;
			fwrite(dn, 1, di - dn, stdout);
			di = dn;
		}
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL << 60;

int main(){
    int h, w;
    cin >> h >> w;
    vector<int> a(h*w);
    int min_a = 100;
    rep(i, h*w){
        cin >> a[i];
        min_a = min(a[i], min_a);
    }
    int ans = 0;
    rep(i, h*w){
        ans += a[i] - min_a;
    }
    cout << ans << endl;

}

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

int main(){
   int h, v;
   cin>>h>>v;
   int counter  = h*v;
   int m;
   cin>>m;
   int sum = m;
   for(int i=1;i<counter;i++){
    int x;
    cin>>x;
    sum += x;
    if(m>x){
        m =x;
    }
   }
   int ans;
   ans = sum - m*counter;
   cout<<ans;
}


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

using ll = long long;
using que_type = tuple<int, pair<int, int>, vector<int>>;

void solve(long long si, long long sj, std::vector<std::vector<long long>> t, std::vector<std::vector<long long>> p){
    priority_queue<que_type, vector<que_type>, greater<que_type>> que;
    que.push(make_tuple(p[si][sj], make_pair(si, sj), vector<int>{(int)t[si][sj]}));

    int times = 1000;
    int beam = 10;

    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    int ans = 0;
    vector<int> ansv;

    while(times--){
        priority_queue<que_type, vector<que_type>, greater<que_type>> next_que;

        while(!que.empty()){
            que_type q = que.top();
            int score;
            pair<int, int> pos;
            vector<int> tiles;
            tie(score, pos, tiles) = q;

            que.pop();

            for(int i = 0;i < 4;i++){
                int nx = dx[i] + pos.first;
                int ny = dy[i] + pos.second;
                if(0 <= dx[i] + pos.first && dx[i] + pos.first < 50 && 0 <= dy[i] + pos.second && dy[i] + pos.second < 50){
                    bool f = false;
                    for(int x : tiles){
                        if(x == t[nx][ny]){
                            f = true;
                            break;
                        }
                    }
                    if(f == false){
                        tiles.push_back(t[nx][ny]);
                        next_que.push(make_tuple(score + p[nx][ny], make_pair(nx, ny), tiles));
                        tiles.pop_back();
                        if(score + p[nx][ny] > ans){
                            ans = score + p[nx][ny];
                            ansv = tiles;
                        }
                    }
                }
            }
        }
        while(next_que.size() > beam)
            next_que.pop();
        que = next_que;
        //cout<<que.size()<<endl;
        //cout<<ans<<endl;
    }

    int pi = si;
    int pj = sj;
    string ans_str;
    for(int i = 1;i < ansv.size();i++){
        bool f = false;
        //cout<<ansv[i]<<" ";
        for(int idx = 0;idx < 4;idx++){
            int nx = pi + dx[idx];
            int ny = pj + dy[idx];

            if(0 <= nx && nx < 50 && 0 <= ny && ny < 50){
                if(t[nx][ny] == ansv[i]){
                    //cout<<idx<<" ";
                    if(idx == 0){
                        ans_str.push_back('D');
                    }else
                    if(idx == 1){
                        ans_str.push_back('R');
                    }else
                    if(idx == 2){
                        ans_str.push_back('U');
                    }else
                    if(idx == 3){
                        ans_str.push_back('L');
                    }
                    f = true;
                }
            }
            if(f){
                pi = nx;
                pj = ny;
                break;
            }
        }
    }
    cout<<ans_str<<endl;
}

int main(){
    long long si;
    scanf("%lld",&si);
    long long sj;
    scanf("%lld",&sj);
    std::vector<std::vector<long long>> t(49+1, std::vector<long long>(49+1));
    for(int i = 0 ; i < 49+1 ; i++){
        for(int j = 0 ; j < 49+1 ; j++){
            scanf("%lld",&t[i][j]);
        }
    }
    std::vector<std::vector<long long>> p(49+1, std::vector<long long>(49+1));
    for(int i = 0 ; i < 49+1 ; i++){
        for(int j = 0 ; j < 49+1 ; j++){
            scanf("%lld",&p[i][j]);
        }
    }
    solve(si, sj, std::move(t), std::move(p));
    return 0;
}

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

#define hi {ios_base::sync_with_stdio(false);}
#define mani_jo {cin.tie(NULL);}

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
#define pp pair<ll,ll>
#define MAX 10000000
#define all(v)				((v).begin()), ((v).end())
#define sz(v)				((int)((v).size()))
#define clr(v, d)			memset(v, d, sizeof(v))
#define sp " "
#define line "\n"
const int MOD = 1e9+7;

/*
ll power(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1) res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
*/

void solve(ll tc = 0)
{
    ll n,q;
    cin>>n>>q;
    ll a[n];
    vi ans(n);
    for(ll i=0;i<n;i++) cin>>a[i];

    for(ll i=0;i<n;i++)
    {
       ans[i] = a[i] - (i+1);
    }
    while(q--)
    {
        ll k;
        cin>>k;

        const int idx = lower_bound(all(ans),k) - ans.begin();

        if(idx == n) cout<<a[n-1] +( k - ans[n-1])<<line;
        else cout<<a[idx] - (ans[idx] - k +1)<<line;
    }
}

int main()
{
    hi mani_jo

    ll T{1};
   // cin>>T;
    for(ll t=0;t<T;t++) solve(t);

    return 0;
}


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

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

int N, M, K;
int to[200001], ne[200001], he[100001];
int D[100001], C[20], Q[100001], q;
int DD[20][20];
int dp[1 << 17][17];

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

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

	N = getint();
	M = getint() * 2;
	rep1(i, M) {
		int a = getint(), b = getint();
		to[i] = b;
		ne[i] = he[a];
		he[a] = i++;
		to[i] = a;
		ne[i] = he[b];
		he[b] = i;
	}
	K = getint();
	rep(i, K) C[i] = getint();

	if (K == 1) {
		printf("1");
		return 0;
	}

	const int dekai = 1e8, choidekai = 5e6;
	for (int p = 1; p < K; p++) D[C[p]] = dekai + p;

	rep(k, K - 1) {

		int b = -choidekai * k;
		D[C[k]] = b - choidekai;

		int mada = 0;
		for (int i = K - 1; i > k; i--) mada |= (1 << i);
		int p = 0;
		q = 0;
		Q[q++] = C[k];
		while (mada && p < q) {
			int i = Q[p++];
			int d = D[i] + 1;
			for (int t = he[i]; t; t = ne[t]) {
				int T = to[t];
				if (D[T] >= b) {
					if (D[T] >= dekai) mada ^= 1 << (D[T] - dekai);
					D[T] = d;
					Q[q++] = T;
				}
			}
		}
		rep(p, K) {
			if (p > k) {
				DD[k][p] = D[C[p]] - b + choidekai;
				DD[p][k] = D[C[p]] - b + choidekai;
			}
			if (p > k + 1) D[C[p]] = dekai + p;
		}
	}
	rep(i, K) dp[1 << i][i] = 1 - choidekai;

	rep1(b, (1 << K) - 1) {
		int X[17], Y[17];
		auto x = X, y = Y;
		rep(i, K) {
			if (b >> i & 1) *x++ = i;
			else *y++ = i;
		}
		auto dp0 = dp[b];
		for (auto j = Y; j < y; j++) {
			int saishou = 0;
			for (auto i = X; i < x; i++) {
				if (saishou > dp0[*i] + DD[*j][*i]) saishou = dp0[*i] + DD[*j][*i];
			}
			dp[1 << *j | b][*j] = saishou;
		}
	}

	int kotae = 0;
	rep(i, K) chmin(kotae, dp[(1 << K) - 1][i]);

	if (kotae < 0) printf("%d", kotae + choidekai);
	else printf("-1");

	Would you please return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N, M;
  cin >> N >> M;
  vvi E0(N);
  REP(0, M, i) {
    i64 a, b;
    RI(a); RI(b);
    a--; b--;
    E0[a].pb(b);
    E0[b].pb(a);
  }

  i64 K;
  cin >> K;
  vi C(K); RVI(C);
  vi dists0(N, -1);
  vvi dists(K, vi(K, -1));
  REP(0, K, i) {
    C[i]--;
  }

  if(K == 1) {
    cout << 1 << endl;
    return 0;
  }

  REP(0, K, i) {
    fill(all(dists0), -1);
    queue<i64> q;
    dists0[C[i]] = 0;
    q.push(C[i]);
    while(!q.empty()) {
      i64 cur = q.front();
      q.pop();
      for(auto next: E0[cur]) {
        if(dists0[next] == -1) {
          dists0[next] = dists0[cur] + 1;
          q.push(next);
        }
      }
    }
    REP(0, K, j) {
      dists[i][j] = dists0[C[j]];
    }
  }

  /*
  REP(0, K, i) {
    REP(0, K, j) {
      assert(dists[i][j] == dists[j][i]);
    }
  }
  */

  i64 B = 1 << K;
  vvi ans(B, vi(K, -1));
  fill(all(ans[0]), 0);
  using ppi = pair<i64, pi>; // dist, {b, k}
  set<ppi> q;
  REP(0, K, i) {
    q.insert({0, {1<<i, i}});
  }

  while(!q.empty()) {
    auto t = *q.begin();
    q.erase(q.begin());
    i64 d = t.first, b = t.second.first, i = t.second.second;
    REP(0, K, j) {
      if(i != j && dists[i][j] != -1) {
        i64 bn = b | (1 << j);
        if(bn == b) {
          continue;
        }
        i64 dn = d + dists[i][j];
        if(ans[bn][j] == -1 || dn < ans[bn][j]) {
          auto it = q.find({ans[bn][j], {bn, j}});
          assert(ans[bn][j] == -1 || it != q.end());
          if(it != q.end()) {
            q.erase(it);
          }
          ans[bn][j] = dn;
          q.insert({ans[bn][j], {bn, j}});
        }
      }
    }
  }

  i64 res = -1;
  REP(0, K, i) {
    if(ans.back()[i] != -1) {
      if(res == -1) {
        res = ans.back()[i] + 1;
      }
      else {
        res = min(res, ans.back()[i] + 1);
      }
    }
  }
  printf("%lld\n", res);

  return 0;
}


// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll p = 1e9 + 7;
const ll nax = 55;

ll ps[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
ll dp[(1 << 20)];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll a, b, ans = 0;
	cin >> a >> b;
	vector<ll> ms;
	for (ll i = a; i <= b; ++i) {
		ll mask = 0;
		for (int j = 0; j < 20; ++j) {
			if (i % ps[j] == 0) {
				mask |= (1 << j);
			}
		}
		ms.push_back(mask);
	}
	dp[0] = 1;
	for (auto& x : ms) {
		for (int mask = 0; mask < (1 << 20); ++mask) {
			if ((mask & x) == x) {
				dp[mask] += dp[mask ^ x];
			}
		}
	}
	for (int mask = 0; mask < (1 << 20); ++mask) {
		ans += dp[mask];
	}
	cout << ans;
}

#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
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;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
template <class T> void takeUnique(vector<T> &v) {
  auto last = std::unique(v.begin(), v.end());
  v.erase(last, v.end());
}
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1};
// clang++ -std=c++11 -stdlib=libc++

int main() {
  ll B, C;
  cin >> B >> C;
  ll ans = 0;
  if (C == 1) {
    if (B == 0) {
      cout << 1 << endl;
    } else {
      cout << 2 << endl;
    }
    return 0;
  }
  if (B == 0) {
    ans = (2 * C - 1) / 2 + 1;
  } else if (B > 0) {
    if (B - C / 2 > (-B + (C - 1) / 2)) {
      ans = (C - 1) / 2 + (C - 1) / 2 + C / 2 + (C - 2) / 2 + 2;
    } else {
      ans = B + (C - 2) / 2 - (-B - (C - 1) / 2) + 1;
    }
  } else {
    if (-B - (C - 1) / 2 > B + (C - 2) / 2) {
      ans = (C - 1) / 2 + (C - 1) / 2 + C / 2 + (C - 2) / 2 + 2;
    } else {
      ans = (-B + (C - 1) / 2) - (B - C / 2) + 1;
    }
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define MAXN  2000005
#define ll long long
#define F first
#define S second
#define MOD 1000000007
#define ll long long

using namespace std;

ll a, b, c, d;

void solve()
{
    cin >> a >> b >> c >> d;
    ll ans = (b - 1ll*c * d);
    if(ans == 0)
    {
        cout << -1;
        return;
    }
    if(-a*1ll/ ans < 0)
    {
        cout << -1 ;
        return;
    }
    ans = -a / ans + ((a % ans) ? 1 : 0);
    cout << ans << "\n";
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie();
    cout.tie();
    if(fopen(".inp", "r"))
    {
        freopen(".inp", "r", stdin);
        freopen(".out", "w", stdout);
    }
    int t;
    t = 1;
    //cin >> t;
    while(t--)
    {
        //cerr << t << '\n';
        solve();
    }
    return 0;
}

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

using uli = unsigned long int;
using ll = long long;

#define rep(i, x) for (int i = 0; i < x; i++)
#define REP(i, x) for (int i = 1; i <= x; i++)

#define chmin(a, b) \
  if (a > b) a = b
#define chmax(a, b) \
  if (a < b) a = b

int main() {
  double V, T, S, D;
  cin >> V >> T >> S >> D;

  double t = D / V;
  if (t >= T && t <= S)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define int long long
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 998244353;

struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N, M, K; cin >> N >> M >> K;
	if (N == 1) {
		mint ans = mint(K).pow(M);
		cout << ans << endl; return 0;
	}
	if(M == 1){
		mint ans = mint(K).pow(N);
		cout << ans << endl; return 0;
	}
	mint ans = 0;
	for (int i = 1; i <= K; i++) {
		mint now = 0;
		now = mint(i).pow(N);
		now -= mint(i - 1).pow(N);

		mint now2 = 0;
		now2 = mint(K -i + 1).pow(M);

		now *= now2;
		ans += now;
	}
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
namespace Sakurajima_Mai{
    #define ms(a) memset(a,0,sizeof(a))
    #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
    #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
    #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
    #define ce(i,r) i==r?'\n':' '
    #define pb push_back
    #define all(x) x.begin(),x.end()
    #define gmn(a,b) a=min(a,b)
    #define gmx(a,b) a=max(a,b)
    #define fi first
    #define se second
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    const int infi=2e9;//infi较大，注意涉及inf相加时爆int
    const ll infl=4e18;
    inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
    inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
    //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Sakurajima_Mai;
namespace Fast_Read{
    inline int qi(){
        int f=0,fu=1; char c=getchar();
        while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
        while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
        return f*fu;
    }
    inline ll ql(){
        ll f=0;int fu=1; char c=getchar();
        while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
        while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
        return f*fu;
    }
    inline db qd(){
        char c=getchar();int flag=1;double ans=0;
        while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
        if(c=='-') flag=-1,c=getchar();
        while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
        if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
        return ans*flag;
    }
}
namespace Read{
    #define si(a) scanf("%d",&a)
    #define sl(a) scanf("%lld",&a)
    #define sd(a) scanf("%lf",&a)
    #define ss(a) scanf("%s",a)
    #define rai(x,a,b) repi(i,a,b) x[i]=qi()
    #define ral(x,a,b) repi(i,a,b) x[i]=ql()
}
namespace Out{
    #define pi(x) printf("%d",x)
    #define pl(x) printf("%lld",x)
    #define ps(x) printf("%s",x)
    #define pc(x) printf("%c",x)
    #define pe() puts("")
}
namespace DeBug{
    #define MARK false
    #define DB if(MARK)
    #define pr(x) cout<<#x<<": "<<x<<endl
    #define pra(x,a,b) cout<<#x<<": "<<endl; \
            repi(i,a,b) cout<<x[i]<<" ";     \
            puts("");
    #define FR(a) freopen(a,"r",stdin)
    #define FO(a) freopen(a,"w",stdout)
}
using namespace Fast_Read;
using namespace Read;
using namespace Out;
using namespace DeBug;
const int mod=998244353;
int qpow(int x,int n,int mod){ int res=1;while(n){ if(n&1) res=(1ll*res*x)%mod; x=1ll*x*x%mod,n>>=1; } return res; }
int main()
{
    int n=qi(),m=qi(),k=qi();
    if(n>m) swap(n,m);
    if(n==1){
        pi(qpow(k,m,mod)),pe();
        return 0;
    }
    int ans=0;
    repi(i,1,k){
        int a=(1ll*qpow(i,n,mod)-1ll*qpow(i-1,n,mod)+mod)%mod;
        int b=qpow(k-i+1,m,mod);
        ans=(1ll*ans+1ll*a*b%mod)%mod;
    }
    pl(pos_mod(ans,mod)),pe();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ ";
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ ";
  for(auto s:S) os<<s<<" ";  return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair
// inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;}
const int N = 2e5 + 100;

int P[N];
int idx[N];

int A[N];
int rev[N];

int main(){
  fio; cout<<fixed<<setprecision(25);
  int n; cin >> n;
  int x;
  for(int i = 1;i <= n ; ++i){
    cin >> x;
    A[i] = x;
    rev[A[i]] = i;
  }
  int lft = n-1;
  vi opr;
  for(int i = 1;i <= n ; ++i){
    if(A[i] == i)
      continue;
    int idx = rev[i];
    assert(idx > i);
    while(idx != i){
      opr.pb(idx-1);
      swap(A[idx],A[idx-1]);
      rev[A[idx]] = idx;
      rev[A[idx-1]] = idx-1;
      idx--;
    }
    if(opr.size() >= n)
      break;
  }
  if(opr.size() == n-1){
    for(auto it : opr)
      cout << it << endl;
    //cout << endl;
  }
  else
    cout << -1 << endl;
}

// #pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define fi first
#define se second
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)!=1)exit(0); return x;}
typedef double lf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)!=1)exit(0); return x;}
typedef pair<ll,ll> pii; template<typename T> vector<T> &operator<<(vector<T> &a,T b){a.push_back(b); return a;} template<typename T> T sqr(T x){return x*x;} void print(ll x,bool e=0){printf("%lld%c",x," \n"[e]);}
const int N=1010; const ll mod=(0?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;}
#define int ll
char s[10];
vector<int> a[N][26];
int dis[N][N];
queue<pii> q;
void Solve(){
	int n=read(),m=read();
	repeat(i,0,m){
		int x=read()-1,y=read()-1; scanf("%s",s);
		a[x][*s-'a'].push_back(y);
		a[y][*s-'a'].push_back(x);
	}
	mst(dis,-1);
	dis[0][n-1]=0;
	q.push(pii(0,n-1));
	repeat(c,0,26)
	for(auto px:a[0][c])if(px==n-1){
		print(1,1);
		return;
	}
	ll ans=inf;
	while(!q.empty()){
		int x=q.front().fi,y=q.front().se; q.pop();
		if(x==y){
			ans=min(ans,dis[x][y]);
		}
		repeat(c,0,26){
			for(auto px:a[x][c])
			for(auto py:a[y][c]){
				if(dis[px][py]==-1){
					dis[px][py]=dis[py][px]=dis[x][y]+2;
					q.push(pii(px,py));
				}
			}
			for(auto px:a[x][c])if(px==y){
				ans=min(ans,dis[x][y]+1);
			}
		}
	}
	if(ans==inf)print(-1,1); else print(ans,1);
}
signed main(){
	// freopen("data.txt","r",stdin);
	int T=1; // T=read();
	repeat(ca,1,T+1){
		Solve();
	}
	return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

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

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
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 (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N;
    cin >> N;
    V<ll> A(N), B(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    V<ll> C(N);
    REP(i, N) C[i] = B[i] - A[i];

    ll res = 0;
    REP(i, N){
        res += A[i];
    }

    V<ll> odd, even;
    REP(i, N){
        if(i&1) odd.push_back(C[i]);
        else even.push_back(C[i]);
    }

    sort(ALLR(odd));
    sort(ALLR(even));

    // dump(C)
    // dump(odd)
    // dump(even)

    REP(i, N/2){
        if(odd[i]+even[i]>0){
            res += odd[i]+even[i];
        }
    }

    cout << res << endl;

    return 0;
}

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=100005;
int n,a[N],b[N],c[N],d[N];
ll ans;
priority_queue<ll> q[2];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		ans+=a[i];
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
		b[i]-=a[i];
		if(i&1){
			c[i/2+1]=b[i];
		}else{
			d[i/2]=b[i];
		}
	}
	sort(c+1,c+n/2+1);
	sort(d+1,d+n/2+1);
	for(int i=n/2;c[i]+d[i]>0;i--){
		ans+=c[i]+d[i];
	}
	printf("%lld\n",ans);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <functional>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define REP(i,n) for (ll i = 1; i <= (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define fcout cout<<fixed<<setprecision(15)
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078160628620899
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
const ll NIL = -1;

ll N;

int main() {
	cin >> N;
	rep(i, N) {
		ll P; cin >> P;
		ll A = 0;
		while (P % 2 == 0) {
			P /= 2;
			A++;
		}
		if (A == 1) cout << "Same" << endl;
		else if (A == 0) cout << "Odd" << endl;
		else cout << "Even" << endl;
	}
	return 0;
}

/*   --------------------
    |       LOSER        |
    |     ~NOOBOSS~      |
     --------------------
*/
#include <bits/stdc++.h>
using namespace std;
#define      mxx                 1e18
#define      mnn                 -1e18
#define      Y()                 cout<< "YES" <<endl
#define      N()                 cout << "NO"<<endl
#define      endl                "\n"
#define      Ceil(x,y)           ((x+y-1)/y)
#define      sz(s)               (int)s.size()
#define      angle(x)            double(x * acos(-1) / 180.0)
#define      max_3(a,b,c)        max(a, max(b,c))
#define      min_3(a,b,c)        min(a, min(b,c))
#define      gcd(a,b)            __gcd(a,b)
#define      lcm(a,b)           (a*b)/gcd(a,b)
#define      loser               return 0
#define      ll                  long long
#define      PI                  acos(-1)
#define      mem(a,v)            memset(a,v,sizeof(a))
#define      SORT(v)             sort(v.begin(),v.end())
#define      REV(v)              reverse(v.begin(),v.end())
#define      B                   begin()
#define      E                   end()
#define      V                   vector
#define      F                   first
#define      S                   second
#define      PSB                 push_back
#define      MP                  make_pair
#define      flash               cout.flush()
#define      InTheNameOfGod      ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
constexpr ll MOD = 998244353;
constexpr ll mod = 1e9  + 7;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
/*-----*/
#define bug1(a)  cerr<<a<<endl;
#define bug2(a,b)  cerr<<a<<" "<<b<<endl;
#define bug3(a,b,c)  cerr<<a<<" "<<b<<" "<<c<<endl;
/*----*/
const ll N=3e6+5;
vector<ll> adj[N];
ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}}
ll modpow(ll a,ll b,ll m){ll ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;}
ll nsum(ll num){return (num*(num+1))/2;}
void edge (ll u,ll v) {adj[u].PSB(v) ;adj[v].PSB(u);}
/*------------------START---------------------*/

/*-----*/
void solve(){
   ll n;
   string s;
   cin>>n;
   if(n%2) cout<<"Odd"<<endl;
   else if(n%4==2) cout<<"Same"<<endl;
   else cout<<"Even"<<endl;

   //cout << fixed << setprecision(10);
}
/*-----*/
int main(){
   InTheNameOfGod

   ll Test=1;
   cin>>Test;
   while(Test--){
     solve();
    }
  loser;
}
///////   C O D I N G  I S  L I F E   ///////


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define Rep(i,n) for(ll i=0;i<ll(n);i++)
#define Repd(i,n) for(ll i=n-1;i>=0;i--)
#define For(i,a,b) for(ll i=a;i<=ll(b);i++)
#define Ford(i,a,b) for(ll i=a;i>=ll(b);i--)
#define Fora(i,I) for(const auto& i:I)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define pusb push_back
#define emb emplace_back
#define pob push_back
const int INF30 = 1<<30;
const ll INF60 = 1LL<<60;
const ll MOD = 1000000007;
const ll val = 0;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
template<typename T, typename U> inline bool chmax(T &a, U b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T, typename U> inline bool chmin(T &a, U b) { return ((a > b) ? (a = b, true) : (false)); }
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

int point(vvc &A, int y, int x){
	if(A.at(y).at(x) == '+')return 1;
	return -1;
}

int main(void) {
	int H,W;
	cin>>H>>W;
	vvc A(H, vc(W));
	Rep(i,H)Rep(j,W)cin>>A.at(i).at(j);
	vvi dp(H, vi(W));
	Ford(i,H-1,0)Ford(j,W-1,0){
		if(i == H - 1 && j == W - 1)continue;
		//cout<<i<<' '<<j<<endl;
		int tmp = 0;
		if((i + j)%2 == 0){
			tmp = -INF30;
			if(i + 1 < H)chmax(tmp,dp.at(i + 1).at(j) + point(A,i+1,j));
			if(j + 1 < W)chmax(tmp,dp.at(i).at(j + 1) + point(A,i,j+1));
		}else{
			tmp = INF30;
			if(i + 1 < H)chmin(tmp,dp.at(i + 1).at(j) - point(A,i+1,j));
			if(j + 1 < W)chmin(tmp,dp.at(i).at(j + 1) - point(A,i,j+1));
		}
		dp.at(i).at(j) = tmp;
		//cout<<'*'<<tmp<<endl;
	}
	if(dp.at(0).at(0) > 0)cout<<"Takahashi"<<endl;
	else if(dp.at(0).at(0) == 0)cout<<"Draw"<<endl;
	else cout<<"Aoki"<<endl;
}

// Code Written by Pinaki Bhattacharjee (pinakipb2)
#include<bits/stdc++.h>
using namespace std;

// typedef
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

// #define
#define LOCAL
#define endl "\n"
#define PI 2*acos(0.0)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mpr make_pair
#define all(x) (x).begin(),(x).end()
#define ppc __builtin_popcountll
void pinakipb2() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

// constants
const int MAX = 1e7 + 10;
const int MOD = (int) 1e9 + 7;

ll h,w;
ll a[2005][2005];
bool vis[2005][2005];
ll dp[2005][2005];

ll func(ll i, ll j)
{
    if(i==h-1 && j==w-1) return 0;
    if(vis[i][j]) return dp[i][j];
    vis[i][j] = true;
    ll ans = INT_MIN;
    if(j+1<w) ans = max(ans,a[i][j+1]-func(i,j+1));
    if(i+1<h) ans = max(ans,a[i+1][j]-func(i+1,j));
    return dp[i][j] = ans;
}

int main()
{
    pinakipb2();

    cin>>h>>w;
    vector<string> v(h);
    for(int i=0;i<h;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            a[i][j] = v[i][j]=='+' ? 1 : -1;
        }
    }
    ll ans = func(0,0);
    if(ans==0) cout<<"Draw"<<endl;
    else if(ans<0) cout<<"Aoki"<<endl;
    else cout<<"Takahashi"<<endl;

    return 0;
}


/**
  *  Author: dhruv_gheewala
  *  Problem: A - Hands
  *  Date:   28.11.2020
  *  Time:   18:31:28
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define fundri 108
    #define debug(...) 1729
#endif

#define endl '\n'
#define int int64_t

typedef pair<int, int> pii;
typedef vector<int> vi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.ff >> a.ss; return in;}

const int inf = 1e15;
const bool testcases = false;

void init_main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef DHRUV_GHEEWALA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

void solve(int tc)
{
    int a, b, x, y;
    cin >> a >> b >> x >> y;

    if(a == b) {
        cout << x << endl;
        return;
    }

    if(a > b) {
        // a, 0 -> b + 1, 0
        // b + 1, 0 -> b, 1
        cout << (a - b - 1) * min(y, 2 * x) + x << endl;
    } else {
        // a, 0 -> b, 0
        // b, 0 -> b, 1
        cout << (b - a) * min(y, 2 * x) + x << endl;
    }
}

int32_t main(int32_t argc, char **argv)
{
    init_main();

    int TC = 1;
    if(testcases)
        cin >> TC;

    for(int tc = 1; tc <= TC; ++tc) {
        solve(tc);
        fundri;
    }
    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>;

int main(int argc, char const *argv[])
{
	int a, b , c;
	cin >> a >> b >> c;
	a = 7-a;
	b = 7- b;
	c = 7-c;
	cout << a + b + c << endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#include <bitset>
#include <set>
#include <cmath>
#define LL long long
#define ull unsigned long long
#define mk(t1, t2) make_pair(t1, t2)
using namespace std;
const LL mo = 1e9 + 7;
const int MAXN = 5e5 + 5;
int n;
char s[MAXN];
LL a[MAXN], b[MAXN];
LL sta[MAXN], ans, top;

void push (int &pos) {
	while (pos <= n && b[pos] == 0) ++pos;
}

int main() {
#ifdef IN
	freopen ("x.in", "r", stdin);
	freopen ("x.out", "w", stdout);
#endif
	int i,j,k;
	scanf ("%d", &n);
	scanf ("%s", s + 1);
	for (i=1; i<=n; ++i) a[i] = s[i] - '0';
	scanf ("%s", s + 1);
	for (i=1; i<=n; ++i) b[i] = s[i] - '0';
	j = 1, push (j);
	for (i=1; i<=n; ++i) {
		if (a[i] == 1) {
			if (top) ans += i - sta[top--];
			else if (j <= i && j <= n) ans += i - j, ++j, push (j);
			else sta[++top] = i;
		}
	}
	if (j <= n || top) printf ("-1");
	else printf ("%lld", ans);
	return 0;
}

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace asl
{
    typedef long long i64;

}
#include <stdint.h>

#include <experimental/optional>

#include <utility>

#include <tuple>

#include <random>

#define endl '\n'

using namespace std;
using namespace asl;

void solve()
{
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;

    queue<int> q;
    int last = -1;

    i64 res = 0;

    for (int i = 0; i < n; ++i)
    {
        if (b[i] == '1')
            q.push(i);

        if (a[i] == '1')
        {
            if (last != -1)
            {
                res += i - last;

                last = -1;
            }
            else if (!q.empty())
            {
                res += i - q.front();

                q.pop();
            }
            else
            {

                last = i;
            }
        }
    }

    if (!q.empty() || last != -1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << res << endl;
    }
}

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

    int t = 1;

    for (int i = 1; i <= t; ++i)
    {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
#define arr array
#define pb push_back
#define fs first
#define sc second
#define eb emplace_back
#define vt vector
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long ll;
const int maxn=2e5;
const int MAXINT=1e9;
const ll MAXLL=1e18;

void solve(){
    int n;
    cin >> n;
    n*=2;
    vt<arr<int, 3>> a(n);
    rep(i, 0, n) cin >> a[i][0], a[i][1]=i;
    sort(a.begin(), a.end(), [&](arr<int, 3> x, arr<int, 3> y){
        return x[0]<y[0];
    });
    rep(i, 0, n/2) a[i][2]=1;
    rep(i, n/2, n) a[i][2]=0;
    sort(a.begin(), a.end(), [&](arr<int, 3> x, arr<int, 3> y){
        return x[1]<y[1];
    });

    //rep(i, 0, n) cout << a[i][2] << " "; cout << endl;
    vt<int> st;
    vt<char> ans(n);
    rep(i, 0, n){
        if (!st.empty()&&a[i][2]!=a[st.back()][2]) ans[st.back()]='(', ans[i]=')', st.pop_back();
        else st.pb(i);
    }
    rep(i, 0, n) cout << ans[i]; cout << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }
}

/**
 * author: BohaoWang (bj050323@gmail.com)
 * id:
 * tag:
 */
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <list>
#include <algorithm>
#include <climits>
#include <cassert>
#ifdef XDebug
#include "../../debug.h"
#endif
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;

#define INF 1e9
#define MAXN 100
#define all(A) A.begin(), A.end()

#ifndef XDebug
#define dumpArray(...) 42
#define dumpGraph(...) 42
#endif

// CODE HERE
ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

ll modeq(ll a, ll b, ll n) {
    ll e, i, d, x, y;
    d = extgcd(a, n, x, y);
    if (b % d > 0) {
        return -1;
    }
    else {
        ll mi = -1;
        e = (x * (b / d)) % n;
        ll super = ((e + n) % (n/d)) %n;
        return super;
    }
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    int n, t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        int s, k;
        cin >> n >> s >> k;
        cout << modeq(k,n-s,n) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n, k, m;
  cin >> n >> k >> m;
  vector <int> a(n - 1);
  int sum = 0;
  REP(i, n - 1) {
	cin >> a[i];
	sum += a[i];
  }
  if (m * n - sum <= k) {
	  cout << max(0, m * n - sum) << endl;
	} else {
	  cout << -1 << endl;
	}
  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  string S, X;
  cin >> N >> S >> X;
  vector<vector<bool>> dp(N + 1, vector<bool>(7, false));
  dp[N][0] = true;
  for (int i = N - 1; i >= 0; i--) {
    int s = (int)S[i] - 0x30;
    if (X[i] == 'A') {
      for (int j = 0; j < 7; j++) {
        int next1 = j * 10 % 7, next2 = (j * 10 + s) % 7;
        if (dp[i + 1][next1] && dp[i + 1][next2]) dp[i][j] = 1;
      }
    } else {
      for (int j = 0; j < 7; j++) {
        int next = j * 10 % 7;
        if (dp[i + 1][next]) dp[i][j] = 1;
        next = (j * 10 + s) % 7;
        if (dp[i + 1][next]) dp[i][j] = 1;
      }
    }
  }
  cout << (dp[0][0] ? "Takahashi" : "Aoki") << endl;
  return 0;
}


/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;}
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
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; }

void solve(){
    ll N,K;
    cin >> N >> K;
    vector<vll> A(N, vll(N));
    rep(i,0,N){
        rep(j,0,N){
            cin >> A[i][j];
        }
    }
    ll lv = -1, rv = INF;
    while(rv - lv > 1){
        ll mid = (lv + rv) / 2;
        vector<vll> sum(N+1, vll(N+1, 0));
        rep(i,0,N){
            rep(j,0,N){
                if(A[i][j] <= mid) sum[i+1][j+1]++;
            }
        }
        rep(i,0,N+1){
            rep(j,0,N){
                sum[i][j+1] += sum[i][j];
            }
        }
        rep(j,0,N+1){
            rep(i,0,N){
                sum[i+1][j] += sum[i][j];
            }
        }
        bool ok = false;
        rep(i,0,N-K+1){
            rep(j,0,N-K+1){
                if(sum[i+K][j+K] - sum[i+K][j] - sum[i][j+K] + sum[i][j] >= (K*K+1)/2) ok = true;
            }
        }
        if(ok){
            rv = mid;
        }else{
            lv = mid;
        }
    }
    ll ans = rv;
    print(ans);

}

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


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

#define F                   first
#define S                   second
#define int                 long long int
#define pb                  push_back
#define mp                  make_pair
#define pii                 pair<int,int>
#define vi                  vector<int>
#define mii                 map<int,int>
#define pqb                 priority_queue<int>
#define pqs                 priority_queue<int,vi,greater<int> >
#define mod                 1000000007
#define endl                '\n'
#define rep(i,a,b)            for(int i=a;i<b;i++)
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
const int N = 2e5 + 10;
vi gr[N];
int ans = 0;
int st[N];
int et[N];
int tim = 0;
vi d[N];
void dfs(int cur, int depth) {
	st[cur] = tim ++;
	d[depth].pb(st[cur]);
	for (auto x : gr[cur]) {
		dfs(x, depth + 1);
	}
	et[cur] = tim;
}
void solve() {
	int n;
	cin >> n;
	rep(i, 2, n + 1) {
		int p;
		cin >> p;
		gr[p].pb(i);
	}
	dfs(1, 0);
	int q;
	cin >> q;
	while (q--) {
		int U, D;
		cin >> U >> D;
		int l = st[U];
		int r = et[U];

		int ans = lower_bound(d[D].begin(), d[D].end(), r) - lower_bound(d[D].begin(), d[D].end(), l);

		cout << ans << endl;
	}
}
int32_t main()
{
	c_p_c();
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

#include <bits/stdc++.h>

#define int long long

using namespace std;

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

    int N;
    cin >> N;

    set<int> st;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	st.insert(n);
    }

    while(1)
    {
    	if(st.size() == 1)break;

    	int may = *(--st.end());
    	int men = *(st.begin());

    	st.erase(may);
    	st.insert(may-men);
    }

    cout << *st.begin() << '\n';

    return 0;
}


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

int nota(string S){
  rep(i,S.size()){
    if(S.at(i) != 'a'){
      return i;
    }
    if(i== (int) (S.size()-1) && S.at(i) == 'a'){
      return -10;
    }
  }
}

int main(){
  int t;
  cin >> t;

  rep(i,t){
    string s;
    cin >> s;
    if(s > "atcoder"){
      cout << 0 <<endl;;
    }
    else if(nota(s) >0){
        	if(s.at(nota(s)) > 't'){
            	cout << nota(s) -1 <<endl;
        	}
        	else{
          		cout << nota(s) <<endl;
        	}
    }

    else{
      cout << -1 << endl;
    }
  }
}

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

int main(){
    int n, ans = 0;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    rep(i, n){
        if(a[i] > 10){
            ans += a[i] - 10;
        }
    }

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


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi firstk
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a,b) memset(a,b,sizeof (a))
#define ios stkd::ios::sync_with_stkdio(false); stkd::cin.tie(0); stkd::cout.tie(0);
// ios  can not be used with scanf,printf.  IF  ios MUstk cin,cout.
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
const ll mod=1000000;
const int INF=0x3f3f3f3f;
ll ksm(ll a,ll b){ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

const int N=1510;
int n;
int fa[N];
double x[N],y[N];
int find(int x){
    if(fa[x]!=x){
        fa[x]=find(fa[x]);
    }
    return fa[x];
}
double dis(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
bool check(double r){
    for(int i=0;i<=n+1;i++)fa[i]=i;
    for(int i=1;i<=n;i++){
        if(100-y[i]<2*r)fa[find(i)]=find(0);
        if(abs(-100-y[i])<2*r)fa[find(i)]=find(n+1);
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int a=find(i),b=find(j);
            if(dis(x[i],y[i],x[j],y[j])<2*r){
                fa[b]=a;
            }
        }
    }
    return find(0)==find(n+1);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf%lf",&x[i],&y[i]);
    }
    double l=1,r=100;
    while(r-l>1e-5){
        double mid=(l+r)/2;
        if(check(mid))r=mid;
        else l=mid;
    }
    printf("%.4lf\n",r);
    return 0;
}

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

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

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N;
    cin >> N;
    vector<double> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];

    using T = tuple<double, int, int>;
    vector<T> es;
    for(int i=0; i<N; i++) for(int j=0; j<i; j++) es.emplace_back(hypot(X[i]-X[j], Y[i]-Y[j]), i, j);
    for(int i=0; i<N; i++){
        es.emplace_back(100-Y[i], i, N);
        es.emplace_back(Y[i]+100, i, N+1);
    }
    sort(es.begin(), es.end());

    UnionFind uf(N+2);
    for(auto& [d, a, b] : es){
        uf.unite(a, b);
        if(uf.same(N, N+1)){
            cout << fixed << setprecision(10) << d/2 << endl;
            return 0;
        }
    }

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for (int i = n-1; i >= 0; --i)
#define repA(i, a, n) for (int i = a; i <= n; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

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

#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define vs vector<string>
#define vd vector<double>
#define vb vector<bool>

#define vpii vector<pii>
#define vpll vector<pll>
#define vpdd vector<pdd>

#define mod 1000000007
#define ps(x,y) fixed << setprecision(y) << x
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

bool Solve(string s)
{
	if (s.length() == 1) {
		if (s == "8")
			return true;

		return false;
	}
	else if (s.length() == 2) {
		if (stoi(s) % 8 == 0) {
			return true;
		}

		swap(s[0], s[1]);

		if (stoi(s) % 8 == 0) {
			return true;
		}

		return false;
	}

	vi freq(10, 0);
	for (auto c : s) {
		freq[c - '0']++;
	}

	if (freq[0] >= 3) { // 000 (in last 3 digit) is always divisible by 8
		return true;
	}

	for (int i = 104; i < 1000; i += 8) {
		string temp = to_string(i);

		vi freq2(10, 0);
		for (auto c : temp) {
			freq2[c - '0']++;
		}

		bool flag = false;

		for (int j = 0; j < 10; j++) {
			if (freq[j] < freq2[j]) {
				flag = true;
			}
		}

		if (!flag) {
			return true;
		}
	}

	return false;
}

int main()
{
	fastio

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

	string s;
	cin >> s;

	if (Solve(s)) {
		cout << "Yes" << '\n';
	}
	else {
		cout << "No" << '\n';
	}

	return 0;
}


#define NDEBUG

#include <bits/stdc++.h>

using namespace std;

void dbg() {
    cerr << endl;
}

template <typename U, typename... Ts>
void dbg(U foo, Ts... bar) {
    cerr << ' ' << to_string(foo);
    dbg(bar...);
}

#ifndef NDEBUG
#define debug(...) cerr << '[' << #__VA_ARGS__ << "]: ", dbg(__VA_ARGS__)
#else
#define debug(...) ((void)0)
#endif

int greatestDigit(const string &x) {
    int res = 0;
    for (const auto &z : x) {
        res = max(res, z - '0');
    }
    return res;
}

long long baseN(const string &x, long long n) {
    long long res = 0;
    for (const auto &z : x) {
        if (res > (long double)(LLONG_MAX)/n) {
            return LLONG_MAX;
        }
        res = res * n;
        if (res > LLONG_MAX - (z - '0')) {
            return LLONG_MAX;
        }
        res += z - '0';
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string x;
    long long m;
    cin >> x >> m;
    if (x.length() == 1) {
        cout << (x[0] - '0' <= m) << '\n';
        return 0;
    }
    int d = greatestDigit(x);
    long long l = d + 1, r = m, mid = r / 2 + l / 2, res = -1;
    debug(l, r, mid);
    while (l <= r) {
        debug(l, r, mid, baseN(x, mid));
        if (baseN(x, mid) <= m) {
            res = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
        mid = r / 2 + l / 2;
        if (r % 2 == 1 && l % 2 == 1) {
            mid++;
        }
    }
    if (res == -1) {
        cout << 0 << '\n';
        return 0;
    }
    debug(res, d);
    cout << res - d << '\n';
    return 0;
}

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair

ll change(string x, ll k, ll m){
    ll rec = 0;
    rep(i, 0, x.size()){
        if((x[i] - '0')*pow(k, x.size()-1-i) > m) return -1;
        rec += (x[i] - '0')*pow(k, x.size()-1-i);
        if(rec > m) return -1;
    }
    return rec;
}

int main(){
    string x; cin >> x;
    ll m; cin >> m;

    if(x.size() == 1){
        if(x[0] - '0' <= m) cout << 1 << endl;
        else cout << 0 << endl;
    }
    else{
        ll d = 0;
        rep(i, 0, x.size()){
            if(x[i] - '0' > d) d = x[i] - '0';
        }

        ll left = 0;
        ll right = m+1;

        while(right - left > 1){
            ll mid = (right + left) / 2;
            ll p = change(x, mid, m);

            if(p == -1 || p > m) right = mid;
            else left = mid;
        }

        cout << max(left - d, 0LL) << endl;
    }
}


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

#define ll long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORe(i,a,b) for(int i=a;i<=b;i++)
#define FORr(i,a,b) for(int i=a;i>b;i--)
#define FORre(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

void solve(){
    ll n,x; cin >> n >> x;
    ll ans = x;
    vector<ll> a(n); rep(i,0,n) cin >> a[i];
    for(int k = 1; k <= n; k++){
        vector<vector<int> >dp(k+1,vector<int>(k,-1));
        dp[0][0] = 0;
        for(ll v : a){
            for(int c = k - 1; c >= 0; c--){
                for(int r = 0; r < k; r++){
                    if(dp[c][r] == -1) continue;
                    int next = dp[c][r] + v;
                    dp[c+1][next%k] = max(dp[c+1][next%k],next);
                }
            }
        }
        int start = dp[k][x%k];
        if(start == -1) continue;
        ans = min(ans,(x-start)/k);
    }
    cout << ans << endl;
}

int main(){
        ios::sync_with_stdio(0);
	    cin.tie(0);
        int t = 1;
        // cin >> t;
        while(t--){
            solve();
        }
        return 0;
}

#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
typedef int int_;
#define int long long
#define maxn 400010
const int inf=1e9+7;
queue<int> q;
inline int read(){
	int ret=0,ff=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') ff=-ff;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		ret=ret*10+ch-'0';
		ch=getchar();
	}
	return ret*ff;
}
struct Edge{
	int u,v,w,next;
}E[maxn<<1];
int ecnt=0,head[maxn];
int in[maxn];
void addedge(int u,int v){
	++in[v];
	E[++ecnt].u=u;
	E[ecnt].v=v;
	E[ecnt].next=head[u];
	head[u]=ecnt;
}
void Addedge(int u,int v){
	addedge(u,v);
	addedge(v,u);
}
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
int ksm(int a,int b,int p){
	int ret=1;
	while(b){
		if(b&1) ret=ret*a%p;
		a=a*a%p;
		b>>=1;
	}
	return ret%p;
}
bool cmp(int x,int y){
	return x>y;
}
int a[10010];
int G2(int x){
	int cnt=0;
	while(x){
		a[++cnt]=x%10;
		x/=10;
	}
	sort(a+1,a+1+cnt);
	int ret=0;
	for(int i=1;i<=cnt;++i) ret=ret*10+a[i];
	return ret;
}
int G1(int x){
	int cnt=0;
	while(x){
		a[++cnt]=x%10;
		x/=10;
	}
	sort(a+1,a+1+cnt,cmp);
	int ret=0;
	for(int i=1;i<=cnt;++i) ret=ret*10+a[i];
	return ret;
}
int F(int x){
	return G1(x)-G2(x);
}
char X[10010];
bool ck(int Mid,int len,int m){
	int sum=0,tmp=1;
	for(int j = len; j;--j){
		sum+=tmp*(X[j]-'0');
		tmp*=Mid;
	}
	return sum>m;
}
int dp[2][110][110][110];
int_ main(){
	int n=read(),x=read();
	for(int i=1;i<=n;++i) a[i]=read();
	memset(dp, -1, sizeof dp);
	for(int i=1;i<=n;i++) dp[0][i][0][0] = 0;
	for(int i=0;i<n;i++){
		int qwq=i&1;
		for(int j =1;j<=n;j++){
			for(int qaq =0;qaq<=i;qaq++){
				for(int res=0;res<j;res++){
					if(dp[qwq][j][qaq][res]==-1) continue;
					dp[qwq^1][j][qaq+1][(res+a[i+1])%j]=max(dp[qwq^1][j][qaq+1][(res+a[i+1])%j],dp[qwq][j][qaq][res]+a[i+1]);
					dp[qwq^1][j][qaq][res]=max(dp[qwq^1][j][qaq][res], dp[qwq][j][qaq][res]);
				}
			}
		}
	}
	int qwq=n&1,ans=x;
	for(int qaq=1;qaq<=n;qaq++){
		if(dp[qwq][qaq][qaq][x%qaq]>0&&x>=dp[qwq][qaq][qaq][x%qaq])ans=min(ans,(x-dp[qwq][qaq][qaq][x%qaq])/qaq);
	}
	printf("%lld",ans);
	return 0;
}
/*
1
6 3
*/
/*
111111111111111111111111111111111111111111111111111111111111
1000000000000000000

100000000000000000000000000000000000000000000000000000000000

1000000000000000000
2
1000000000000000000
*/


#include<bits/stdc++.h>

using namespace std;

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

const int N = 1e3 + 7;

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  int n, m; cin >> n >> m;
  vector <bool> a(N), b(N);
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    a[x] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int x; cin >> x;
    b[x] = 1;
  }
  for (int i = 1; i < N; ++i) {
    if (a[i] == 0 and b[i]) {
      cout << i;
    } else if (b[i] == 0 and a[i]) {
      cout << i;
    }
    cout << " ";
  }
  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>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
const int INF = (int)1e9;
const ll INFL = (ll)1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    vector<int> ans;
    rep(i,n)
    {
        int a;
        cin >> a;
        mp[a]++;
    }
    rep(i,m)
    {
        int b;
        cin >> b;
        mp[b]++;
    }

    for (auto p : mp)
    {
        if (p.second == 1)
            ans.push_back(p.first);
    }
    sort(ans.begin(), ans.end());

    for (auto p : ans)
        cout << p << " ";
    cout << endl;
    return 0;
}


#include <iostream>
using namespace std;
struct point {
	int x, y;
}p[105];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i].x >> p[i].y;
	}
	int max = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			int cnt = 2;
			point vec1;
			vec1.x = p[j].x - p[i].x;
			vec1.y = p[j].y - p[i].y;
			for (int h = 0; h < n; h++) {
				if (h == i || h == j)
					continue;
				point vec2;
				vec2.x = p[h].x - p[i].x;
				vec2.y = p[h].y - p[i].y;
				if (vec1.x * vec2.y == vec1.y * vec2.x) {
					cnt++;
				}
			}
			if (cnt > max) max = cnt;
		}
	}
	if (max >= 3) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

#include <algorithm>
// #include <atcoder/all>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
constexpr double PI = 3.141592653589793;
constexpr int INF = 1e9 + 10;
constexpr ll INFL = 1e18 + 10;

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

template <typename T>
void dump(const std::vector<T> &ar) {
  for (T e : ar) {
    std::cout << e << "\n";
  }
}

template <typename T>
void dump(const std::set<T> &s) {
  for (T e : s) {
    std::cout << e << " ";
  }
  std::cout << "\n";
}

using namespace std;
// using namespace atcoder;
// cout << setprecision(20) << ans << "\n";

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

  int n, m;
  cin >> n;

  vector<int> x(n), y(n);
  REP(i, n) { cin >> x[i] >> y[i]; }

  REP(i, n) {
    REP(j, n) {
      if (i == j) {
        continue;
      }
      REP(k, n) {
        if (i == j || j == k || k == i) {
          continue;
        }
        int dx1 = x[i] - x[j];
        int dx2 = x[i] - x[k];
        int dy1 = y[i] - y[j];
        int dy2 = y[i] - y[k];
        int dx3 = x[j] - x[k];
        int dy3 = y[j] - y[k];

        int dis1 = dx1 * dx1 + dy1 * dy1;
        int dis2 = dx2 * dx2 + dy2 * dy2;
        int dis3 = dx3 * dx3 + dy3 * dy3;

        // if (dis1 + dis2 == dis3 || dis1 + dis3 == dis2 || dis2 + dis3 ==
        // dis1) {
        //   if (dis1 != 0 && &dis2 != 0 && dis3 != 0) {
        if (dx1 * dy2 == dx2 * dy1) {
          cout << "Yes"
               << "\n";
          return 0;
        }
        //   }
        // }
      }
    }
  }

  cout << "No"
       << "\n";

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << '\n'; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

template<ll MOD = 1000000007>
class ModInt {
    ll n;
    ModInt constexpr inverse() const {
        return ModInt::pow(*this, MOD - 2);
    }

public:
    ModInt() : n(0) {}
    ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {}
    ModInt operator+=(const ModInt &m) {
        n += m.n;
        if (n >= MOD) n -= MOD;
        return *this;
    }
    ModInt operator-=(const ModInt &m) {
        n -= m.n;
        if (n < 0) n += MOD;
        return *this;
    }
    ModInt operator*=(const ModInt &m) {
        n *= m.n;
        if (n >= MOD) n %= MOD;
        return *this;
    }
    ModInt operator/=(const ModInt &m) {
        (*this) *= m.inverse();
        return *this;
    }
    friend ModInt operator+(ModInt t, const ModInt &m) {
        return t += m;
    }
    friend ModInt operator-(ModInt t, const ModInt &m) {
        return t -= m;
    }
    friend ModInt operator*(ModInt t, const ModInt &m) {
        return t *= m;
    }
    friend ModInt operator/(ModInt t, const ModInt &m) {
        return t /= m;
    }
    ModInt operator=(const ll l) {
        n = l % MOD;
        if (n < 0) n += MOD;
        return *this;
    }
    friend ostream &operator<<(ostream &out, const ModInt &m) {
        out << m.n;
        return out;
    }
    friend istream &operator>>(istream &in, ModInt &m) {
        ll l;
        in >> l;
        m = l;
        return in;
    }
    static constexpr ModInt pow(const ModInt x, ll p) {
        ModInt<MOD> ans = 1;
        for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) {
            if (p % 2) ans *= m;
        }
        return ans;
    }
};
using mint = ModInt<>;
mint operator"" _m(unsigned long long m) {
    return mint(m);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin, n, m;
    int sum = 0;
    rep(i, 0, n) {
        int a;
        cin, a;
        sum += a;
    }
    if (m < sum) {
        print(0);
        return 0;
    }
    // C(m + n, sum + n) = (m + n)P(sum + n) / (sum + n)!;
    mint a = 1, b = 1;
    rep(i, 0, sum + n) {
        a *= (m + n - i);
        b *= (i + 1);
    }

    print(a / b);
    return 0;
}

#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, a[nsz + 5];
num pre[2][nsz + 5];

int main() {
	scanf("%d", &n);
	cont (i, n) scanf("%d", &a[i]);
	int mx = 0;
	cont (i, n) {
		mx = max(mx, a[i]);
		pre[0][i] = pre[0][i - 1] + a[i];
		pre[1][i] = pre[1][i - 1] + pre[0][i];
		printf("%lld\n", pre[1][i] + (num) mx * i);
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define PI 3.14159265359
#define mod 1000000007
#define ALL(a)  (a).begin(),(a).end()

int main(){
    ll a,b;
    cin >> a >> b;
    int ans = 1;
    for(int i = 1; i <= 200000; i++){
        if(a % i != 0){
            if(a <= i * (a / i + 1) && i * (a / i + 1) <= b){
                if(a <= i * (a / i + 2) && i * (a / i + 2) <= b){
                    ans = max(ans,i);
                }
            }
        }
        else{
            if(a <= i * (a / i + 1) && i * (a / i + 1) <= b){
                ans = max(ans,i);
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int a,b;
    cin >> a >> b;
    //cout<<__gcd(a,b)<<endl;
    int dis = b-a;

    for(int i=dis;i>=1;i--)
    {
        int n = b/i;
       // cout<<i<<" "<<n<<endl;
        if((n+1)*i <=b && (n+1)*i>=a)
        {
            cout<<i<<endl;
            return 0;
        }
        else if((n-1)*i <=b && (n-1)*i >= a)
        {
            cout<<i<<endl;
            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=2e5+5;
const ll REQ=1e13;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
ll quick(ll a,int n){
	ll re=1;
	while(n){
		if(n&1) re=(re*a)%mod;
		a=(a*a)%mod;
		n>>=1;
	}
	return re;
}
ll inv(ll a){return quick(a,mod-2);}
ll C(int n,int m){		//n里选m
	m=min(m,n-m);
	ll r1=1,r2=1;
	for(int i=n;i>n-m;--i) r1=(r1*i)%mod;
	for(int i=2;i<=m;++i) r2=(r2*i)%mod;
	return r1*inv(r2)%mod;
}
int main(){
	int n,m;scanf("%d%d",&n,&m);
	int sum=0;
	for(int i=1;i<=n;++i){
		int a;scanf("%d",&a);
		sum+=a;
	}
	if(m<sum) puts("0");
	else printf("%lld\n",C(n+m,n+sum));
	return 0;
}

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

const int N=2e3+100,mod=1e9+7;
int n,m,a[N];

inline int read(){
    int sum=0,sign=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
       if(ch=='-') sign=-1;
       ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        sum=(sum<<1)+(sum<<3)+(ch^48);
        ch=getchar();
    }
    return sum*sign;
}

inline int Qpower(long long base, long long power) {
    int result = 1;
    base%=mod;
    while (power > 0) {
        if (power & 1) {
            result = result * base%mod;
        }
        power >>= 1;
        base = (base * base)%mod;
    }
    return result;
}

signed main(){
	scanf("%lld%lld",&n,&m);
	int sum=0;
	for(rei i=1;i<=n;++i) sum+=read();
	if(m<sum){
		printf("0\n");
		return 0;
	}
	//ans=(∑Ai+N)
	//    (M+N   )
	m+=n,sum+=n;
	int ans=1;
	for(rei i=1;i<=sum;++i){
		ans=ans*Qpower(i,mod-2)%mod *(m-i+1) %mod;
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W;
string S[10];

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	int ret=0;

	FOR(y,H-1) FOR(x,W-1) {
		if(S[y][x]=='#'&&S[y+1][x]=='.'&&S[y][x+1]=='.') ret++;
		if(S[y][x+1]=='#'&&S[y+1][x+1]=='.'&&S[y][x]=='.') ret++;
		if(S[y+1][x]=='#'&&S[y][x]=='.'&&S[y+1][x+1]=='.') ret++;
		if(S[y+1][x+1]=='#'&&S[y][x+1]=='.'&&S[y+1][x]=='.') ret++;
		if((S[y][x]=='#')+(S[y][x+1]=='#')+(S[y+1][x]=='#')+(S[y+1][x+1]=='#')==3) ret++;
	}
	cout<<ret<<endl;

}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<iomanip>
using namespace std;
#define N 300009
#define LL long long
#define INF 0x3f3f3f3f
#define mymin(x,y) (x>=y?y:x)
#define mymax(x,y) (x>=y?x:y)
int tong[N];
int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
    int n, k; cin >> n >> k;
    for(int i = 1; i <= n; i++){
        int a; cin >> a;
        tong[a]++;
    }
    int num = INF, res;
    LL ans = 0;
    for(int i = 0; i < n; i++){
        num = min(num, tong[i]);
        res = max(k - num, 0);
        //cout << i << " " << num << " " << res << "\n";
        k -= res;
        ans += (i * res);
        if(k == 0) break;
    }
    cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define ps(x,y)           fixed<<setprecision(y)<<x
#define sz                size();
#define p_sieve           10000007
const int                 maxn = 1e3 + 5;
const int                 modulo = 1000000007;
#define mod               1000000009;
const double              pi = 3.14159;
#define INF               1000001000
#define imx                9999999999999999
#define imi               -9999999999999999
//check n==1 and base cases//

//********************************---------always check array boundness-----------****************
// factorial ncr
// int printNcR(int n, int r)
// {
//     if(n<r)return 0;
//     long long p = 1, k = 1;
//     if (n - r < r)
//         r = n - r;
//     if (r != 0) {
//         while (r) {
//             p *= n;
//             k *= r;
//             long long m = __gcd(p, k);
//             p /= m;
//             k /= m;

//             n--;
//             r--;
//         }
//     }
//     else p = 1;
//     return p;
// }

// int power(int x, unsigned int y)
// {
//     int res = 1;
//     x = x % modulo;
//     if (x == 0) return 0;
//     while (y > 0)
//     {
//         if (y & 1) res = (res*x);
//         y = y>>1;
//         x = (x*x);
//     }
//     return res;
// }
const int N=300005;
vector<int>v[N];
void solve()
{
  int n,m;cin>>n>>m;
  int a[n];
  FOR(i,0,n)cin>>a[i];
  int maxi=1;
  sort(a,a+n);
  int cn=0,i=0;
  while(a[i]==0 and i<n)v[maxi].pb(0),i++,maxi++;
  cn++;
  FOR(j,i,n)
  {
  	int k=j;
  	int tt=1;
  	while(a[k]==cn and k<n)
  	{
  		if(v[tt].size()>0)if(v[tt].back()==cn-1 and tt<maxi)v[tt].pb(cn),tt++;
  		k++;
	}
	j=k;
	j--;
	cn++;
  }
  int ans=0;
  for(int i=1;i<=m;i++)
  {
  	if(v[i].size()>0)ans+=(v[i].back()+1);
  }
  cout<<ans;

}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//prime_sieve();
	//w(t)
	solve();
}


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

#define co(n) cout<<n<<endl;
const double eps=1e-10,pi=3.1415926535898;
const int mod=998244353,maxn=5e3+10;
int T,n,m,q,k;
long long x,y,a[maxn][maxn];

long long qpow(long long x, int k) {
	long long cnt=1;
	while (k) {
		if (k&1) cnt = cnt*x%mod;
		x = x*x%mod;
		k >>= 1;
	}
	return cnt;
}

int main(int argc, char const *argv[]) {
	for (int i=0;i<maxn;++i) {
		a[i][0] = 1;
	}
	for (int i=0;i<maxn;++i) {
		for (int j=1;j<maxn;++j) {
			a[i][j] = a[i][j-1]*i%mod;
		}
	}
	scanf("%d %d", &n, &m);
	long long ans=qpow(m, n)*n%mod;
	for (int i=1;i<=m;++i) {
		for (int j=0;j<=n-2;++j) {
			ans += mod-a[m][n-j-2]*a[m-i][j]%mod*(n-j-1)%mod;
		}
	}
	printf("%lld\n", ans%mod);
	return 0;
}

#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) int(x.size())
#define fk cerr<<"fk"<<endl
#define db(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9)
//2.runtime error
//3.boundary condition
string origin,t;
int n;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
	origin="";
	forn(i, 2*(int)1e5+100){
		origin+="110";
	}
	cin>>n;
	cin>>t;
	if(t=="1"){
		cout<<2*(i64)1e10<<'\n';
		return 0;
	}
	i64 minn=INT_MAX;
	for(int i=0; i<3; ++i){
		i64 now=i-1;
		bool ok=true;
		forn(j,n){
			++now;
			if(origin[now]!=t[j]){
				ok=false;
				break;
			}
		}
		if(ok) uin(minn,(now+3)/3);
	}
	if(minn==INT_MAX) cout<<0<<'\n';
	else	cout<<(i64)1e10-minn+1<<'\n';
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); x = 0; int f = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    if (f) x = -x;
} const int N = 1e5 + 5, mod = 1e9 + 7;
int n, a[N], f[N];
signed main() {
    read (n);
    for (int i = 1; i <= n; ++i) read (a[i]);
    f[1] = 2, f[0] = 1;
    for (int i = 2; i <= n; ++i)
        f[i] = (f[i - 1] + f[i - 2]) % mod;
    int res = a[1] * f[n - 1];
    for (int i = 2; i <= n; ++i) {
        (res += a[i] * f[i - 2] % mod * f[n - i]) %= mod;
        int A = i == 2 ? 1 : f[i - 3], B = i == n ? 1 : f[n - i - 1];
        (res -= a[i] * A % mod * B) %= mod;
    }
    res = (res % mod + mod) % mod;
    printf ("%lld\n", res);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll mem[3005][3005];
ll dp(int n, int k){
    if (k > n) return 0;
    if (n == 0) return (k == 0);
    if (k <= 0) return 0;
    //printf("%d %d\n",n,k);
    if (mem[n][k] != -1) return mem[n][k];
    int ans1 = 0;
    if (k >= 1) ans1 = dp(n-1,k-1);
    int ans2 = dp(n,2*k);
    return mem[n][k] = (ans1+ans2)%mod;

}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    memset(mem,-1,sizeof(mem));
    printf("%lld\n",dp(n,k));
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100 + 5;
const ll mod = 1e9 + 7;
int n, m, k, b[maxn][maxn];
ll powMod(ll a, ll k) { ll ret = 1; while(k) { if(k & 1) ret = ret * a % mod; a = a * a % mod; k >>= 1;} return ret;}
ll getinv(ll x) { return powMod(x, mod - 2);}
struct Mat
{
	int r, c;
	ll a[maxn][maxn];
	Mat (const int & _r, const int & _c) : r(_r), c(_c) { memset(a, 0, sizeof a);}
	void setone()
	{
		assert(r == c);
		memset(a, 0, sizeof a);
		for(int i = 0; i < r; ++i) a[i][i] = 1;
	}
	Mat operator * (const Mat & rhs) const
	{
		Mat ret(r, rhs.c);
		for(int i = 0; i < r; ++i)
			for(int j = 0; j < c; ++j)
			{
				ll tmp = a[i][j];
				for(int k = 0; k < rhs.c; ++k)
					ret.a[i][k] = (ret.a[i][k] + tmp * rhs.a[j][k] % mod) % mod;
			}
		return ret;
	}
};
Mat powMod(Mat a, ll k)
{
	assert(a.r == a.c);
	Mat ret(a.r, a.r);
	ret.setone();
	while(k)
	{
		if(k & 1) ret = ret * a;
		a = a * a; k >>= 1;
	}
	return ret;
}
int main()
{
	scanf("%d%d%d", &n, &m, &k);
	const ll inv2m = getinv(2 * m);
	Mat v(n, 1);
	for(int i = 0; i < n; ++i) scanf("%lld", &v.a[i][0]);
	for(int i = 0; i < m; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		--u, --v;
		++b[u][v];
		++b[v][u];
	}
	Mat A(n, n);
	A.setone();
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
		{
			if(i == j) continue;
			A.a[i][j] = b[i][j] * inv2m % mod;
			A.a[i][i] = (A.a[i][i] + mod - A.a[i][j]) % mod;
		}
	v = powMod(A, k) * v;
	for(int i = 0; i < n; ++i) printf("%lld\n", v.a[i][0]);
	return 0;
}

#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<set>
using namespace std;

#define NDEBUG
#include<cassert>

namespace Elaina{
    #define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i)
    #define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i)
    #define fi first
    #define se second
    #define mp(a, b) make_pair(a, b)
    #define Endl putchar('\n')
    #define mmset(a, b) memset(a, b, sizeof a)
    #define siz(a) ((int)(a).size())
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef pair<ll, ll> pll;
    template<class T>inline T fab(T x){ return x<0? -x: x; }
    template<class T>inline void getmin(T& x, const T rhs){ x=min(x, rhs); }
    template<class T>inline void getmax(T& x, const T rhs){ x=max(x, rhs); }
    template<class T>inline T readin(T x){
        x=0; int f=0; char c;
        while((c=getchar())<'0' || '9'<c) if(c=='-') f=1;
        for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48));
        return f? -x: x;
    }
    template<class T>inline void writc(T x, char s='\n'){
        static int fwri_sta[1005], fwri_ed=0;
        if(x<0) putchar('-'), x=-x;
        do fwri_sta[++fwri_ed]=x%10, x/=10; while(x);
        while(putchar(fwri_sta[fwri_ed--]^48), fwri_ed);
        putchar(s);
    }
}
using namespace Elaina;

const int maxm=2e5;

pii pawn[maxm+5];

int n, m;

inline void input(){
    n=readin(1), m=readin(1);
    rep(i, 1, m)
        pawn[i].fi=readin(1), pawn[i].se=readin(1);
    sort(pawn+1, pawn+m+1);
}

set<int>avai;
vector<int>rem, ins;
inline int saya(int x){
    auto it=avai.find(x);
    if(it!=avai.end() && (*it)==x) return 1;
    return 0;
}

signed main()
{
    input();
    avai.insert(n);
    for(int l=1, r; l<=m; l=r+1){
        for(r=l; r<=m && pawn[r+1].fi==pawn[l].fi; ++r);
        rep(i, l, r) rem.push_back(pawn[i].se);
        rep(i, l, r){
            if(saya(pawn[i].se-1) || saya(pawn[i].se+1))
                ins.push_back(pawn[i].se);
        }
        while(!rem.empty()) avai.erase(rem.back()), rem.pop_back();
        while(!ins.empty()) avai.insert(ins.back()), ins.pop_back();
    }
    writc(siz(avai));
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
int H, W;
int pt(char c){
    if(c == '+') return 1;
    else return -1;
}
bool inarea(int y, int x){
    if(0 <= y && y < H && 0 <= x && x < W) return true;
    else return false;
}
int toint(int y, int x){
    return y * W + x;
}
pair<int, int> topair(int N){
    int x = N % W;
    int y = (N - x) / W;
    return make_pair(y, x);
}
int main(){
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char> (W));
    rep(i, H) rep(j, W){
        cin >> A[i][j];
    }
    int dp[4000000];
    rep(i, H * W - 1){
        int y = topair(i).first;
        int x = topair(i).second;
        if((y + x) % 2 == 0) dp[i] = -1e9;
        else dp[i] = 1e9;
    }
    dp[H * W - 1] = 0;
    dp[H*W-1] = 0;
    int dy[2] = {1, 0};
    int dx[2] = {0, 1};
    queue<int> todo;
    todo.push(H * W - 1);
    vector<bool> seen(H * W, false);
    seen[H * W - 1] = true;
    while(!todo.empty()){
        int v = todo.front();
        todo.pop();
        int y = topair(v).first;
        int x = topair(v).second;
        rep(i, 2){
            int ny = y - dy[i];
            int nx = x - dx[i];
            if(!inarea(ny, nx)) continue;
            if(seen[toint(ny, nx)]) continue;
            seen[toint(ny, nx)]  = true;
            todo.push(toint(ny, nx));
            rep(j, 2){
                int nny = ny + dy[j];
                int nnx = nx + dx[j];
                if(!inarea(nny, nnx)) continue;
                if((ny + nx) % 2 == 1){
                    dp[toint(ny, nx)] = min(-pt(A[nny][nnx]) + dp[toint(nny, nnx)], dp[toint(ny, nx)]);
                }
                else{
                    dp[toint(ny, nx)] = max(pt(A[nny][nnx]) + dp[toint(nny, nnx)], dp[toint(ny, nx)]);
                }
            }
        }
    }
    if(dp[0] > 0) cout << "Takahashi" << endl;
    else if(dp[0] < 0) cout << "Aoki" << endl;
    else cout << "Draw" << endl;
}

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

lnt MOD = 998244353;
struct mint
{
	lnt v;
	mint():v(0){}
	mint(lnt v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
	static std::vector<mint> construct_comb(int n) {
		std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
	}
	static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }

int main() {
	int n,k;
	lnt m;
	std::cin >> n >> k >> m;
	MOD=m;
	lnt N=n*(n+1)/2;
	V<V<mint> > pre(n+1,V<mint>(N*k+1,0));
	{ // precompute
		pre[0][0]=1;
		for(int i=1;i<=n;i++) {
			rep(j,N*k+1) {
				if(j==0) pre[i][j]=1;
				else {
					if(j-i<0) pre[i][j]=pre[i-1][j];
					else pre[i][j]=pre[i][j-i]+pre[i-1][j];
				}
			}
			for(int j=N*k;j>=0;j--) {
				if(j-(k+1)*i<0) break;
				pre[i][j]-=pre[i][j-(k+1)*i];
			}
		}
	}
	for(int x=1;x<=n;x++) {
		mint ans=0;
		// up to n-x and up to x-1
		rep(i,N*k+1) {
			ans+=pre[x-1][i]*pre[n-x][i]*mint(k+1);
		}
		print(ans-1);
	}
}


/*
   om namah shivay
*/
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define REP(i,a,b) for(i=a;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
int mpow(int base, int exp);

const int mod = 1'000'000'007;

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

void solve()
{
   ll int m,h;
   cin>>m>>h;
   if(h%m==0)
   cout<<"Yes"<<endl;
   else
   {
       cout<<"No"<<endl;
   }

}

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

ll int mpow(ll int base,ll int exp)
{
  base %= mod;
  ll int result = 1;
  while (exp > 0)
  {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

// clang++ -std=c++14 probA.cpp
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <limits>
#include <string>
#include <cassert>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> pii;
#define forup(i,a,b) for(int i=a; i<b; ++i)
#define fordn(i,a,b) for(int i=a; i>b; --i)

#define rep(i,a) for(int i=0; i<a; ++i)

#define dforup(i,a,b) for(i=a; i<b; ++i)
#define dfordn(i,a,b) for(i=a; i>b; --i)
#define drep(i,a) for(i=0; i<a; ++i)

// #define slenn(s,n) for(n=0; s[n]!=13 and s[n]!=0; ++n);s[n]=0

#define gi(x) scanf("%d",&x)
#define gl(x) cin>>x
#define gd(x) scanf("%lf",&x)
#define gs(x) scanf("%s",x)

#define pis(x) printf("%d ",x)
#define pin(x) printf("%d\n",x)
#define pls(x) cout<<x<<" "
#define pln(x) cout<<x<<"\n"
#define pds(x) printf("%.12f ",x)
#define pdn(x) printf("%.12f\n",x)
#define pnl() printf("\n")
#define vec vector<int>
#define fs first
#define sc second

#define pb push_back

const int inv=1000000000;
const int minv=-inv;

const int max_n=200000+5;

int n,r;
int b[max_n];
vector<int> chl[max_n];

int depth[max_n];
LL res;
vector<int> sol;
vector<pii> q;
bool used[max_n];
set<pii,greater<pii> > Sdec;
set<pii,greater<pii> >::iterator it;

// #include <algorithm>
// int bin_sea .rc
// vector<int> travel {0,1};

bool cmp(const vector<int> &a,const vector<int> &b)
{
    if (a[0] == b[0])
        return a[1]>b[1];
	return a[0]<b[0];
}

vector<int> visited(2*(100000)+2, -1);
vector<int> ans(2*(1000000)+2, -1);

void solve(){
    vector<int> arr;
    for (int i = 0;i<4;i++){
        int x;
        gi(x);
        arr.push_back(x);
    }
    sort(arr.begin(),arr.end());
    if (arr[0] + arr[1] +arr[2] == arr[3]){
        cout<<"Yes"<<endl;
    }
    else if (arr[0] + arr[3] == arr[1] +arr[2] )
         cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return;

}

int main()
{
    ll test = 1;
   for (int i = 0;i<test;i++){
       solve();
   }

}