#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

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

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  double n, x;
  cin >> n >> x;
  x = x * 100;
  int ans = 0;
  int flag = 0;
  double sum = 0;
  rep (i, n) {
    double v, p;
    cin >> v >> p;
    sum += v * p;
    if (flag == 0 && sum > x) {
      ans = i + 1;
      flag = 1;
    }
  }
  if (flag == 0) P(-1);
  else P(ans);
  return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;

string X; ll M;
ll INF = 1ll << 61;

bool isBigger(ll base) {
	int n = X.size();
	if (log(X[0] - '0') + (n - 1) * log(base) > log(INF)) { return true; }

	ll c = 1;
	for (int i = 1; i < n && c <= M; i++) { c *= base; }
	if (c > M) { return true; }
	ll cur = 0;
	for (int i = 0; i < X.size(); i++) {
		cur += c * (X[i] - '0');
		c /= base;
		if (cur > M) { return true; }
	}
	return false;
}

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

	cin >> X >> M;
	int d = *max_element(X.begin(), X.end()) - '0';

	if (X.size() == 1) {
		if (X[0] - '0' <= M) { cout << 1 << '\n'; }
		else { cout << 0 << '\n'; }
		return 0;
	}

	ll l = d, r = INF;
	while (l < r) {
		ll mid = (l + r + 1) >> 1;
		if (isBigger(mid)) { r = mid - 1; }
		else { l = mid; }
	}

	if (r < l) { cout << 0 << '\n'; return 0; }
	cout << (l - d) << '\n';
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define inf 1e9
#define linf 1e18
#define BASE 1000000
#define EPS 1e-10
#define PI acos(-1)
#define pii pair<int,int>
#define piii pair<int, pair<int, int> >
#define pdi pair<double,int>
#define vi vector<int>
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define ms(x,val_add) memset(x, val_add, sizeof(x))
#define pb(x) push_back(x)
#define make_unique(x) sort(ALL(x)) ; x.erase( unique(ALL(x)), x.end()) ;
#define dbg(x) do { cout << #x << " = " << x << endl; } while(0)
#define mp(x, y) make_pair(x, y)
#define minimize(x, y) x = min(x, y)
#define maximize(x, y) x = max(x, y)

/*** IMPLEMENTATION ***/
bool exitInput = false;
int ntest = 1, itest = 1 ;

const int dx[4] =
{
    -1, 0, 1, 0
};
const int dy[4] =
{
    0, 1, 0, -1
};
// const int dx[8] = {-2, -1, -1, +0, +0, +1, +1, +2};
// const int dy[8] = {+0, -1, +1, -2, +2, -1, +1, +0};

/** Knight Move **/
// const int dx[8] = {+1, +2, +2, +1, -1, -2, -2, -1};
// const int dy[8] = {+2, +1, -1, -2, -2, -1, +1, +2};

const ll Mod = 1000000007LL;
const int maxn = 500 + 5;
const int maxv = 500 + 5;
const int maxe = 10000 + 5;

ll addMod( ll &x, ll y )
{
    x = ( x + y ) % Mod;
}

int main()
{
#ifdef HOME
    freopen( "input.txt", "r", stdin );
    freopen( "output.txt", "w", stdout );
#endif // HOME
    ios_base::sync_with_stdio( false );
    cin.tie( NULL );
    cout << setprecision( 10 );
    cout << fixed;

    int A, B;
    cin >> A >> B;
    A = A + B;
    if(A >= 15 && B >= 8)
        cout << 1;
    else if(A >= 10 && B >= 3)
        cout << 2;
    else if(A >= 3)
        cout << 3;
    else
        cout << 4;

    return 0;
}


#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,l,a[maxn],q,t,b[maxn];
char s[maxn];
vector<pii>g[maxn];

int main(){
//    op;
    read(n);read(l);
    unordered_map<int,int>lef,rig;
    fo(i,1,n) {
        read(a[i]);
    }
    fo(i,1,n) read(b[i]);
    lef[0]=0;rig[l-n]=n+1;
    LL ans = 0;
    fo(i,1,n){//往左的
        if(b[i]>a[i]) continue;
        if(a[i]!=b[i]&&!lef.count(b[i]-i)) {
            puts("-1");return 0;
        }
        int tar = lef[b[i]-i];
        lef[a[i]-i]=i;
        if(a[i]==b[i]) continue;
        lef[b[i]-i]=i;
        g[i].push_back({tar,abs(i-tar)});//表示i小于tar，也就是i在tar之前就得要行动
        ans+=abs(i-tar);
    }

    fod(i,n,1){
        if(b[i]<a[i]) continue;
        if(a[i]!=b[i]&&!rig.count(b[i]-i)) {
            puts("-1");return 0;
        }
        int tar = rig[b[i]-i];
        rig[a[i]-i]=i;
        if(a[i]==b[i]) continue;
        rig[b[i]-i]=i;
        g[i].push_back({tar,abs(i-tar)});
        ans+=abs(i-tar);
    }

    printf("%lld\n",ans);

    Please AC;
}

#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007

const ll mod = 1e9 + 7;

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

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;
	cin >> h >> w;
	vector <string> v(h);
	for (int i = 0; i < h; i++)
		cin >> v[i];
	ll ans = 0;
	vector <vl> prer(h, vl(w, -1));
	vector <vl> suffr(h, vl(w, h));
	vector <vl> prec(h, vl(w, -1));
	vector <vl> suffc(h, vl(w, w));
	//cout << prec[0] << " " << prec[1] << "\n";
	ll c = 0;
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			if (v[i][j] == '#')
				prec[i][j] = j;
			else
				c++;
			if (j)
				prec[i][j] = max(prec[i][j], prec[i][j - 1]);
			//cout << j << " " << prec[j] << "\n";
		}
		for (ll j = w - 1; j >= 0; j--) {
			if (v[i][j] == '#')
				suffc[i][j] = j;
			if (j + 1 < w)
				suffc[i][j] = min(suffc[i][j], suffc[i][j + 1]);
		}
	}
	//cout << prec[0] << " " << prec[1] << "f\n";
	for (ll j = 0; j < w; j++) {
		for (ll i = 0; i < h; i++) {
			if (v[i][j] == '#')
				prer[i][j] = i;
			if (i)
				prer[i][j] = max(prer[i][j], prer[i - 1][j]);
		}
		for (ll i = h - 1; i >= 0; i--) {
			if (v[i][j] == '#')
				suffr[i][j] = i;
			if (i + 1 < h)
				suffr[i][j] = min(suffr[i][j], suffr[i + 1][j]);
		}
	}
	//cout << prec[0] << " " << prec[1] << "\n";
	ll tot = power(2, c);
	//cout << tot << "\n";
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			//cnt = 0;
			if (v[i][j] == '#')
				continue;
			ll cnt = 0;
			if (i)
				cnt += i - 1 - prer[i - 1][j];
			if (i + 1 < h)
				cnt += suffr[i + 1][j] - (i + 1);
			if (j)
				cnt += j - 1 - prec[i][j - 1];
			if (j + 1 < w)
				cnt += suffc[i][j + 1] - (j + 1);
			cnt++;
			//cout << cnt << " " << i << " " << j << "\n";
			ll no = tot - power(2, c - cnt);
			no = (no + mod) % mod;
			//cout << no << "\n";
			ans = (ans + no) % mod;
		}
	}
	cout << ans << "\n";
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#define itn int
#define ll long long
#define yes {puts("Yes");}
#define no {puts("No");}
using namespace std;

ll read(){
	ll a=0,b=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();}
	while(c>='0'&&c<='9')a=a*10+c-48,c=getchar();
	return a*b;
}

int v[31][31],h[31][31],n=30;
char p[1005];int cnt;

struct node{
	int x,y;ll w;int ty;
};

bool operator<(node a,node b){return a.w>b.w;}

ll dis[31][31];
int vis[31][31];

priority_queue<node>q;

namespace test{
	int v[31][31],h[31][31];
	int clac(int sx,int sy,int ex,int ey,char *p,int ct){
		int ans=0;
		for(int i=1;i<=ct;i++){
			if(p[i]=='U')ans+=v[sx-1][sy],sx--;
			else if(p[i]=='D')ans+=v[sx][sy],sx++;
			else if(p[i]=='L')ans+=h[sx][sy-1],sy--;
			else if(p[i]=='R')ans+=h[sx][sy],sy++;
			else exit(1);
			if(sx>=30||sx<0||sy>=30||sy<0)exit(2);
		}
		return ans;
	}
}

int main(){
/*	freopen("0000.txt","r",stdin);
	freopen("test.out","w",stdout);
	for(int i=0;i<30;i++){
		for(int j=0;j<29;j++){
			cin>>test::h[i][j];
		}
	}
	for(int i=0;i<29;i++){
		for(int j=0;j<30;j++){
			cin>>test::v[i][j];
		}
	}*/
	for(int i=0;i<=30;i++){
		for(int j=0;j<=30;j++){
			v[i][j]=h[i][j]=4000;
		}
	}
	for(int i=1;i<=1000;i++){
		int sx,sy,ex,ey;
		cin>>sx>>sy>>ex>>ey;

		memset(dis,0x3f,sizeof dis);
		memset(vis,0,sizeof vis);

		dis[sx][sy]=0;
		q.push(node{sx,sy,0,-1});
		while(!q.empty()){
			node t=q.top();q.pop();
			if(vis[t.x][t.y])continue;
			vis[t.x][t.y]=t.ty;
			//if(t.x==ex&&t.y==ey)break;
			int o=dis[t.x][t.y],x=t.x,y=t.y;
			if(x+1<30&&dis[x+1][y]>o+h[x][y]){
				dis[x+1][y]=o+h[x][y];
				if(!vis[x+1][y])q.push(node{x+1,y,dis[x+1][y],2});//D
			}
			if(y+1<30&&dis[x][y+1]>o+v[x][y]){
				dis[x][y+1]=o+v[x][y];
				if(!vis[x][y+1])q.push(node{x,y+1,dis[x][y+1],3});//R
			}
			if(x-1>=0&&dis[x-1][y]>o+h[x-1][y]){
				dis[x-1][y]=o+h[x-1][y];
				if(!vis[x-1][y])q.push(node{x-1,y,dis[x-1][y],1});//U
			}
			if(y-1>=0&&dis[x][y-1]>o+v[x][y-1]){
				dis[x][y-1]=o+v[x][y-1];
				if(!vis[x][y-1])q.push(node{x,y-1,dis[x][y-1],4});//L
			}
		}
		while(!q.empty())q.pop();
		cnt=0;
		for(int x=ex,y=ey;vis[x][y]!=-1&&vis[x][y];){
			if(vis[x][y]==1)p[++cnt]='U',x++;
			else if(vis[x][y]==2)p[++cnt]='D',x--;
			else if(vis[x][y]==3)p[++cnt]='R',y--;
			else if(vis[x][y]==4)p[++cnt]='L',y++;
		}
		reverse(p+1,p+1+cnt);
		for(int i=1;i<=cnt;i++)cout<<p[i];
		cout<<endl;
		fflush(stdout);

		/*for(int i=0;i<30;i++){
			for(int j=0;j<30;j++){
				cout<<dis[i][j]<<' ';
			}
			puts("");
		}

		for(int i=0;i<30;i++){
			for(int j=0;j<30;j++){
				cout<<h[i][j]<<' ';
			}
			puts("");
		}for(int i=0;i<30;i++){
			for(int j=0;j<30;j++){
				cout<<v[i][j]<<' ';
			}
			puts("");
		}*/

		int b;
		//int aa;double ee;cin>>aa>>ee;
		//b=test::clac(sx,sy,ex,ey,p,cnt)*ee;
		cin>>b;
		int cg=(b-dis[ex][ey])/cnt;
		for(int x=ex,y=ey;vis[x][y]!=-1&&vis[x][y];){
			if(vis[x][y]==1)h[x][y]+=cg,x++;
			else if(vis[x][y]==2)h[x-1][y]+=cg,x--;
			else if(vis[x][y]==3)v[x][y-1]+=cg,y--;
			else if(vis[x][y]==4)v[x][y]+=cg,y++;
		}
	}
	return 0;
}

#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 10;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power (int a, int b = mod - 2)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int n, tim = 0;
vi adj[N];
vpi query[N];
int cnt[N], siz[N], heavy[N], dep[N], euler[N], tin[N], tout[N], ans[N];

void dfs1 (int cur, int prev)
{
    tin[cur] = ++tim;
    euler[tim] = cur;

    dep[cur] = dep[prev] + 1;
    siz[cur] = 1;
    pi mx = {0, 0};

    for (int i: adj[cur])
        if (i != prev)
        {
            dfs1(i, cur);
            siz[cur] += siz[i];
            mx = max(mx, {siz[i], i});
        }

    heavy[cur] = mx.se;
    tout[cur] = tim;
}

void dfs (int cur, int prev, bool keep)
{
    for (int i: adj[cur])
        if (i != prev && i != heavy[cur])
            dfs(i, cur, 0);

    if (heavy[cur]) dfs(heavy[cur], cur, 1);

    cnt[dep[cur]]++;
    for (int i: adj[cur])
        if (i != prev && i != heavy[cur])
            FOR (j, tin[i], tout[i]) cnt[dep[euler[j]]]++;

    for (pi i: query[cur]) ans[i.se] = cnt[i.fi + 1];

    if (!keep)
    {
        FOR (i, dep[cur], n)
        {
            if (!cnt[i]) break;
            cnt[i] = 0;
        }
    }
}

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

	cin >> n;
	readarr(p, n - 1);
	FOR (i, 2, n) adj[i].pb(p[i - 1]), adj[p[i - 1]].pb(i);

	read(q);
	FOR (i, 1, q)
	{
	    readb(a, b);
	    query[a].pb({b, i});
	}

	dfs1(1, 0);
	dfs(1, 0, 1);
	FOR (i, 1, q) cout << ans[i] << endl;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,t,f[110][110],q[110];bool b[110];
struct BAG
{
	int w,v;
}a[61];
bool cmp(BAG x,BAG y)
{
	return x.v>y.v;
}
struct BOX
{
	int num,pos;
}x[110];
bool cmp1(BOX x,BOX y)
{
	return x.num<y.num;
}
int main()
{
	scanf("%d %d %d",&n,&m,&t);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&a[i].w,&a[i].v);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=m;i++)
		scanf("%d",&x[i].num),x[i].pos=i;
	sort(x+1,x+m+1,cmp1);
	while(t--)
	{
		memset(f,0,sizeof(f));
		memset(b,0,sizeof(b));
		int l,r,ans=0,cnt=0;
		scanf("%d %d",&l,&r);
		for(int i=1;i<=m;i++)
			if(!(x[i].pos<=r&&x[i].pos>=l))
				q[++cnt]=x[i].num;
		sort(q+1,q+cnt+1);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=cnt;j++)
				if(!b[j]&&a[i].w<=q[j])
				{
					b[j]=true,ans+=a[i].v;
					break;
				}
		printf("%d\n",ans);
	}
}

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

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];
    vector<int> x(m);
    rep(i, m) cin >> x[i];
    rep(qi, q) {
        int l, r;
        cin >> l >> r;
        --l; --r;
        vector<int> as;
        rep(i, m) if (i < l || r < i) as.push_back(x[i]);
        sort(as.begin(), as.end());
        vector<bool> used(n);
        int ans = 0;
        for (int a : as) {
            P best(-1, -1);
            rep(i, n) {
                if (used[i]) continue;
                if (w[i] > a) continue;
                best = max(best, P(v[i], i));
            }
            int i = best.second;
            if (i == -1) continue;
            used[i] = true;
            ans += v[i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, k;

int a[100][100];
constexpr int MOD = 998244353;

int fact(int n) {
  int s = 1;
  for (int i = 1; i <= n; i++) {
    s = 1ll * s* i % MOD;
  }
  return s;
}

int solve(vector<pair<int, int>> a, int n) {
  vector<vector<int>> ed(n + 1);
  vector<int> used(n + 1);
  for (auto e : a) {
   ed[e.first].emplace_back(e.second);
   ed[e.second].emplace_back(e.first);
  }
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (used[i]) {
      continue;
    }
    int sz = 0;
    function<void(int)> dfs = [&](int v) {
      sz++;
      used[v] = 1;
      for (auto to : ed[v]) {
        if (used[to]) {
          continue;
        }
        dfs(to);
      }
    };

    dfs(i);
    ans = 1ll * ans * fact(sz) % MOD;
  }
  return ans;
}

int go(bool tr) {
  vector<pair<int, int>> ed;
  if (tr) {
    for (int x = 1; x <= n; x++) {
      for (int y = x + 1; y <= n; y++) {
        bool bad = false;
        for (int i = 1; i <= n; i++) {
          if (a[x][i] + a[y][i] > k) {
            bad = true;
          }
        }
        if (!bad) {
          ed.emplace_back(x, y);
        }
      }
    }
  } else {
    for (int x = 1; x <= n; x++) {
      for (int y = x + 1; y <= n; y++) {
        bool bad = false;
        for (int i = 1; i <= n; i++) {
          if (a[i][x] + a[i][y] > k) {
            bad = true;
          }
        }
        if (!bad) {
          ed.emplace_back(x, y);
        }
      }
    }
  }
  return solve(ed, n);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  cout << 1ll *go(0) * go(1) % MOD << "\n";

  return 0;
}

#include <cstdio>
#include <vector>

/*
A(x) = A(x^2) C(x^2)
*/

using u32 = unsigned int;
using u64 = unsigned long long;

template <u32 MOD>
struct Mint {
  u32 n;
  constexpr Mint(u32 n = 0): n(n) {}
  constexpr Mint operator-() const { return Mint(n ? MOD - n: 0); }
  constexpr Mint &operator+=(const Mint &rhs){ n += rhs.n; if(n >= MOD) n -= MOD; return *this; }
  constexpr Mint &operator-=(const Mint &rhs){ if(rhs.n > n) n += MOD; n -= rhs.n; return *this; }
  constexpr Mint &operator*=(const Mint &rhs){ n = (u64) n * rhs.n % MOD; return *this; }
  friend constexpr Mint operator+(const Mint &lhs, const Mint &rhs){ return Mint(lhs) += rhs; }
  friend constexpr Mint operator-(const Mint &lhs, const Mint &rhs){ return Mint(lhs) -= rhs; }
  friend constexpr Mint operator*(const Mint &lhs, const Mint &rhs){ return Mint(lhs) *= rhs; }
  friend constexpr bool operator==(const Mint &lhs, const Mint &rhs){ return lhs.n == rhs.n; }
  friend constexpr bool operator!=(const Mint &lhs, const Mint &rhs){ return lhs.n != rhs.n; }
};

template <class T>
T modpow(T x, int n){
  T r(1);
  for(; n; n >>= 1){
    if(n&1) r *= x;
    x *= x;
  }
  return r;
}

template <u32 MOD>
Mint<MOD> inv(Mint<MOD> n){
  return modpow(n, MOD-2);
}

constexpr u32 mod = 998244353;
using mint = Mint<mod>;

int main(){
  int n, m;
  scanf("%d%d", &n, &m);
  std::vector<mint> C;
  C.push_back(1);
  for(int i = 1; i <= n/2; i++){
    C.push_back(C.back() * mint(n+2-2*i) * mint(n+1-2*i) * inv(mint(2*i * (2*i-1))));
  }
  std::vector<mint> D(n+1);
  D[0] = 1;
  for(; m; m >>= 1){
    std::vector<mint> E(n/2+1);
    for(int i = m&1; i <= n; i+=2){
      E[i/2] = D[i];
    }
    for(int i = 0; i <= n; i++) D[i] = 0;
    for(int i = 0; i <= n/2; i++){
      for(int j = 0; j <= n/2; j++){
        D[i+j] += C[i] * E[j];
      }
    }
  }
  printf("%d\n", D[0].n);
  return 0;
}


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

int len;
long long dp[200005][20][20];
char s[200006];
long long ans=0;
bool life[20];

void go(int l,bool f,int k,int now)
{
	int ff;
	if(now>k)
		return ;
	if(f==1)
		ff=s[len-l];
	else
		ff=15;
	if(l==1)
	{
		int tt=0;
		if(k==now)
		{
			for(int i=0;i<=ff;i++)
				if(life[i])
					tt++;
		}
		else if(now==k-1)
		{
			for(int i=(now==0);i<=ff;i++)
				if(!life[i])
					tt++;
		}
		ans=(ans+tt)%mz;
		return ;
	}
	if(f==1)
	{
		for(int i=0;i<ff;i++)
		{
			if(life[i] || (i==0 && now==0))
				go(l-1,0,k,now);
			else
			{
				life[i]=1;
				go(l-1,0,k,now+1);
				life[i]=0;
			}
		}
		if(life[ff]==0)
			now++;
		life[ff]=1;
		go(l-1,1,k,now);
	}
	else
	{
		if(now==0)
		{
			go(l-1,0,k,0);
			ans=(ans+15*dp[l-1][k][1])%mz;
		}
		else
		{
			ans=(ans+dp[l][k][now])%mz;
		}
	}
}

int main()
{
	for(int i=1;i<=16;i++)
		dp[0][i][i]=1;
	for(int i=1;i<=200001;i++)
		for(int j=1;j<=16;j++)
			for(int k=1;k<=j;k++)
				dp[i][j][k]=(dp[i-1][j][k]*j+dp[i-1][j-1][k]*(17-j))%mz;
	scanf("%s",s);
	int k;
	scanf("%d",&k);
	len=strlen(s);
	for(int i=0;i<len;i++)
	{
		if(s[i]<='9' && s[i]>='0')
			s[i]-='0';
		else
			s[i]-='A'-10;
	}
	go(len,1,k,0);
	printf("%lld\n",ans);
	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

ll dp[18];
char S[200200];
int suuji(char c) {
	if (c < 'A') return c - '0';
	else return c - ('A' - 10);
}

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

	fread(S, 1, 200200, stdin);
	int K = 0;
	int N = 200200 - 1;
	while (S[N] != ' ') N--;
	int tmp = N + 1;
	while (S[tmp] >= '0') K = K * 10 + S[tmp++] - '0';

	const int mod = 1e9 + 7;
	int k = suuji(S[0]);
	dp[1] = k - 1;
	int kazu = 1 << 15 - k;

	rep1(i, N - 1) {
		if (!(i & 7)) for (int j = 2; j <= 16; j++) dp[j] %= mod;
		for (int j = 16; j >= 1; j--) {
			dp[j + 1] += (16 - j) * dp[j];
			dp[j] = j * dp[j];
		}
		dp[1] += 15;
		int k = suuji(S[i]);
		int k1 = __builtin_popcount(kazu >> 16 - k);
		int kazu0 = __builtin_popcount(kazu);
		dp[kazu0] += k1;
		dp[kazu0 + 1] += k - k1;
		kazu |= 1 << 15 - k;
	}

	ll kotae = dp[K];
	kotae += (__builtin_popcount(kazu) == K);
	printf("%lld", kotae % mod);

	Would you please return 0;
}


// author :: enigma74

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

#define ll long long
#define ld long double
#define vec(v) v.begin(),v.end()
#define MOD (1e9+7)

void FASTIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void solve_logic(){
	ll n;
	cin>>n;
	ld arr[n],sum=0,ans=0;
	for(ll i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	ans+=sum;
	sort(arr,arr+n);
	ld x=0;
	if(n%2!=0){
		x=arr[((n+1)/2)-1]/2;
	}else{
		x=(arr[n/2-1]+arr[(n/2)])/4;
	}
	ans+=n*x;
	ld temp=0;
	for(ll i=0;i<n;i++){
		temp+=min(arr[i],2*x);
	}
	ans-=temp;
	ans/=n;
	cout.precision(20);
	cout<<fixed<<ans;

}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
    FASTIO();
    // ll T;
    // cin>>T;
    // while(T--){
        // solve_logic();
    // }

    solve_logic();
    return 0;
}

#pragma GCC optimize("Ofast")
 #include <bits/stdc++.h>
#define ll         long long int
#define umap       unordered_map
#define mod        1000000007ll
#define pb         push_back
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(ll i=0;i<n;i++)
#define f1(i,x,y)  for(ll i=x;i<=y;i++)
#define f2(i,x,y)  for(ll i=x;i>=y;i--)
#define yes        cout<<"YES"<<"\n"
#define no         cout<<"NO"<<"\n"
#define modsum(a,b)  ((a%mod)+(b%mod))%mod
#define modpro(a,b)  ((a%mod)*(b%mod))%mod
#define moddif(a,b)  ((a%mod)-(b%mod)+mod)%mod
#define modsumt(a,b,c) modsum(a,modsum(b,c))
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes
//__builtin_ctz(x)      to count the number of trailing zeroes
//__gcd(a,b)
// Binary Search
// TO AVOID GETTING INFINITE LOOP
// mid = (l+r)/2      l=mid+1   r=mid
// mid = (l+r+1)/2    l=mid     r=mid-1
using namespace std;
ll fac[200005];
/*void calc_pow2()
{
    pow2[0]=1;
    for(ll i=1;i<63;i++) pow2[i]=2*pow2[i-1];
}*/
ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=modpro(result,x);
        x=modpro(x,x);
        n=n/2;
    }
    return result;
}
ll binaryExponentiation(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
ll pow1(ll x,ll y)
{
    ll z=1;
    while(y--){z=z*x;}
    return z;
}
/*bool isprime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}*/
// Returns n^(-1) mod p
ll  modInverse(ll n, ll p)
{
    return modularExponentiation(n, p - 2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
unsigned long long nCrModPFermat(unsigned long long n,
                                 ll r, ll p)
{
    // Base case
    if (r == 0)
        return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
ll check(ll x,ll y)
{
    ll z=1;
    ll ans=0;
    while(z<x){ans++;z*=y;}
    return ans;
}

ll countbits(ll n)
{
    ll x=0;
    while(n>0)
    {
        x++;
        n=(n&(n-1));
    }
    return x;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;cin>>n;
    vector <ll> a(n);
    ll sum=0;
    f(i,n) {cin>>a[i];sum+=a[i];}
    sort(all(a));
    double ans;
    if(n%2)
    {
        double x = (a[n/2]*1.0)/2;
        double s=0;
        f(i,n) s+=min((double)a[i],2*x);
        ans=sum+(n*x)-s;
    }
    else
    {
        double x1 = (a[n/2]*1.0)/2;
        double x2=  (a[(n+1)/2]*1.0)/2;
        double s1=0,s2=0;
        f(i,n) {s1+=min((double)a[i],2*x1);s2+=min((double)a[i],2*x2);}
        ans=sum+min(n*x1-s1,n*x2-s2);
    }
      ans=ans/(1.0*n);
      std::cout << std::fixed; std::cout << std::setprecision(10); std::cout << ans;

}


//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vi w(n);
    cin >> w;
    sort(all(w));
    int mx = *max_element(all(w));
    vp cond;
    rep(_, m) {
        int l, v;
        cin >> l >> v;
        if (v < mx) {
            cout << -1 << endl;
            return 0;
        }
        cond.eb(v, l);
    }
    sort(all(cond));
    rep(i, m - 1) chmax(cond[i + 1].second, cond[i].second);
    int ans = inf;
    // 40320
    do {
        vi pos(n, 0);
        rep2(i, 1, n) {
            pos[i] = pos[i - 1];
            int sum = w[i];
            rrep(j, i) {
                sum += w[j];
                auto it = lower_bound(all(cond), make_pair(sum, 0));
                if (it == cond.begin()) continue;
                it--;
                int nd = it->second;
                chmax(pos[i], pos[j] + nd);
            }
        }
        chmin(ans, pos[n - 1]);
    } while (next_permutation(all(w)));
    assert(ans != inf);
    cout << ans << endl;
}

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
//end of libraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define tpii pair <int, pii>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int max_n = 900155;

using namespace std;
int n , m , k;

int dp[max_n][30];

int p[max_n] , siz[max_n] , f[max_n];

int table[30][30];

vector <int> c , vc[max_n];

int getp(int x) { return p[x] == x ? x : getp(p[x]); }

void mku(int x, int y) {
	int A = getp(x) , B = getp(y);
	if(A == B) return;
	if(siz[A] > siz[B]) {
		siz[A] += siz[B];
		p[B] = A;
		return;
	}
	siz[B] += siz[A];
	p[A] = B;
}

int find(int x,int need){
	queue <pii> q;
	vector <int> usd;

	usd.resize(max_n,0);

	q.push({0,x});

	while(sz(q)) {
		pii point = q.front();

		int value = point.fi , hm = point.se;

		q.pop();

		usd[hm] = 1;

		for(auto &y : vc[hm]) {
			if(y == need) {
				return value + 1;
			}
			if(usd[y]==0) q.push({value + 1 , y});
		}

	}
}

int main(){
fcin;
	rep(i,max_n-4) p[i]=i,siz[i]=1;

	cin >> n >> m;

	rep(i,m){
		int u,v;
		cin >> u >> v;
		u--,v--;
		mku(u,v);
		vc[u].pb(v);
		vc[v].pb(u);
	}
	cin >> k;
	c.resize(k,0);
	rep(i,k) {
		cin >> c[i];
		c[i]--;
	}
	rep(i,k) {
		rep(j,k) {
			if(getp(c[i])!=getp(c[j])) {
				cout << "-1\n"; return 0;
			}
		}
	}
	rep(i,k) {
		rep(j,k) {
			if(i==j) continue;
			table[i][j] = find(c[i],c[j]);
		}
	}
	int mxmxmx = pow(2,k);
	rep(msk,mxmxmx) {
		rep(i,k) dp[msk][i] = inf;
	}

	rep(i,k) {
		dp[(1<<i)][i] = 1;
	}

	rep(msk,mxmxmx) {

		rep(i,k) {

			if(msk&(1<<i)) continue;

			rep(f,k) {

				if(i==f or dp[msk][f] == inf) continue;

				int nx = msk|(1<<i);

				dp[nx][i] = min(dp[nx][i] ,
					dp[msk][f] + table[i][f]
				 );

			}
		}
	}
	int ans = inf;

	rep(i,k) {
		ans = min(ans,dp[mxmxmx-1][i]);
	}
	cout << ans << '\n';

/*
*/
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

int main()
{
	KAKA
	ll n;
	cin>>n;
	ld tax = (ld)(1.08) * n;
    ll val = (ll)(tax);
    if(val < 206)
    {
    	cout<<"Yay!"<<"\n";
    }
    else if(val == 206)
    {
    	cout<<"so-so"<<"\n";
    }
    else
    {
    	cout<<":("<<"\n";
    }
}

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

using namespace std;

int main() {
	int N,e;
	cin >> N;

	e = N * 1.08;
	if (e < 206) cout << "Yay!" << endl;
	if (e > 206) cout << ":(" << endl;
	if (e == 206) cout << "so-so" << endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<long long>
#define vd vector<long double>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_lr(i, f, n) for (int i = f; i < (int)(n); i++)
#define sum(v) accumulate(v.begin(),v.end(),0)
#define sumll(v) accumulate(v.begin(),v.end(),0LL)
#define counte(v,arg) count(v.begin(),v.end(),arg)
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<int>)
using namespace std;

string replace_all(string &s, string from, string to) {
    ll pos = s.find(from);
    while(true){
        pos = s.find(from, pos);
        if(pos==-1) break;
        s.replace(pos, from.length(), to);
        pos += to.length();
    }
    return s;
}

int combination(int n, int r) {
    if(r < n) return 0;
    if(r*2 > n) r = n-r;
    int nume = 1;
    int deno = 1;
    rep_lr(i, 1, r+1) {
        nume *= (n-i+1);
        deno *= i;
    }
    return nume / deno;
}

int ceil(int nume, int deno){
    return (nume+deno-1)/deno;
}

template<typename T>
void vinp(int n, T v){
    rep(i,n){
        cin >> v.at(i);
    }
}

template<typename T>
bool isParall(vector<T> v1, vector<T> v2){
    return v1.at(0)*v2.at(1) - v1.at(1)*v2.at(0) == 0;
}

template<typename T>
bool isRightangle(vector<T> v1, vector<T> v2){
    return v1.at(0)*v2.at(0) + v1.at(1)*v2.at(1) == 0;
}

void solve(){
    int a, b, c, d;
    cin>> a >> b;
    cin>> c >> d;
    cout << a*d - b*c << endl;
}

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

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

// MACROS
#define int                     long long
#define pb                      push_back
#define MAX                     1e17
#define MIN                     -1e17
#define PI                      3.1415926535897932384626433832795
#define mod                     1000000007
#define eps                     1e-9
#define set(x)                  memset(x, 0, sizeof(x))
#define clr(x)                  memset(x, -1, sizeof(x))
#define ff                      first
#define ss                      second
#define rep(i,a,b)              for(int i=a;i<b;i++)
#define sz(x)                   x.size()
#define endl                    "\n"
#define deb(x)                  cout << #x << "=" << x << endl
#define deb2(x, y)              cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x)                  x.begin(), x.end()
#define lb(a,x)                 lower_bound(all(a),x)
#define ub(a,x)                 upper_bound(all(a),x)

typedef priority_queue<int>     maxHeap;
typedef priority_queue<int,     vector<int>, greater<int>> minHeap;
typedef pair<int, int>          pii;
typedef vector<int>             vi;
typedef vector<string>          vs;
typedef vector<pii>             vpii;
typedef vector<vi>              vvi;
typedef map<int, int>            mpii;
typedef set<int>                seti;
typedef multiset<int>           mseti;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;}
// typedef long int                ld;
// typedef unsigned long int       lu;
// typedef long long int           ll;
// typedef unsigned long long int  llu;

// cout << fixed << setprecision(9) <<
int mpow(int base, int exp);

const int T2 = 105; const int T3 = 1005; const int T4 = 10005; const int T5 = 100005;
const int N = 3e5 + 5;

int arr[N];

void solve() {
    int n;
    cin >> n;
    rep(i, 0, n) cin >> arr[i];
    pbds st;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        st.insert(arr[i]);
        int tmp = st.order_of_key(arr[i]) + 1;
        ans += st.size() - tmp;
    }
    cout << ans << endl;
    for (int i = 0; i < n - 1; i++) {
        ans -= arr[i] ;
        ans += n - arr[i] - 1;
        cout << ans << endl;
    }

}

/* TIPS
1. for interactive prob remove fastio and endl
2. for vector pass as reference
3.

*/

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {

        // cout<<"Case #"<<i<<": ";

        solve();

    }
    return 0;
}

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


/**
 *  author: mahfuzz
 *  created: 14.01.2020
**/

#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << #x << ':' << x << endl;
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n, m, t;
    cin >> n >> m >> t;

    int x1 = 0, y1 = 0, flag = 0, init = n;
    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;

        n -= abs(y1 - x);
        if(n <= 0)
            flag = true;

        n = min(init, n + (y - x));
        x1 = x, y1 = y;
    }

    if(n - (t - y1) <= 0 || flag)
        cout << "No\n";
    else
        cout << "Yes\n";

    return 0;
}

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

int main() {
    int N,S,D;
    cin>>N>>S>>D;

    for(int i=0;i<N;i++){
        int X,Y;
        cin>>X>>Y;

        if(X<S&&Y>D){
            puts("Yes");
            return 0;
        }
    }
    puts("No");
}


#include <iostream>
using namespace std;
int main(){
  long long n;
  cin >> n;
  long long left = 0, right = 2000000010;
  while(right - left > 1){
    long long mid = (left + right) / 2;
    if(mid * (mid + 1) / 2 <= n + 1){
      left = mid;
    }else{
      right = mid;
    }
  }
  cout << n - left + 1 << endl;
  return 0;
}

#include<iostream>
#include<vector>
using namespace std;
#define pii pair<int,int>
int spf[100002];  // smallest prime factor
int n=100001;
int num[100001];
void sieve(){  //埃氏篩法 預處理 O(nloglogn)
    spf[1]=1;
    for (int i=2;i<=n;i++ ) spf[i]=i;
    for (int i=4; i<n; i+=2) spf[i] = 2;
    for (int i=3;i*i<=n;i++){  // (i is prime) 只需要找到 小於等於 sqrt(n) 的質數
        if (spf[i]==i) { // if i is prime
            for (int j=i*i;j<=n;j+=i){  // j 可以從i^2 開始，因為  i*k (k<i) 都已經被mark過了
                if(spf[j]==j) spf[j]=i;
            }
        }
    }
}
vector<int> prfc(int x){
    //set<pii> ans;
    //vector<int> now;
    vector<int> ans;
    int y=x;
    while(y!=1){
        int pr=spf[y];
        //auto it=find(now.begin(),now.end(),pr);
        //if (if!=now.end()){

        //}
        ans.push_back(pr);
        y/=pr;
    }
    return ans;
}
int main(){
    int k;cin>>k;
    sieve();
    num[1]=1;
    int maxn=0;
    for (int i=2;i<=k;i++) if (spf[i]==i) num[i]=2;
    for (int i=4;i<=k;i++){
        num[i]=num[i/spf[i]]+1;
        if (num[i]>maxn) maxn=num[i];

    }
    for (int i=1;i<=k;i++) cout<<num[i]<<" ";
    //cout<<maxn<<endl;
}


#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 <bits/stdc++.h>
#include <string>

using namespace std;
int main(){
int a,b,suma = 0,sumb = 0;
string as,bs;
cin >> a >> b;
while(a != 0 && b != 0){
    suma += a%10;
    a /= 10;
    sumb += b%10;
    b /= 10;
}
if(suma == sumb){
    cout << suma;
    return 0;
}
suma > sumb ? cout << suma : cout << sumb;
return 0;
}


#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

//#include <atcoder/all>
// using namespace atcoder;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, y) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), y))
#define Upper_bound(v, y) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), y))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

struct mint {
  ll y;  // typedef long long ll;
  mint(ll y = 0) : y((y % mod + mod) % mod) {}
  mint operator-() const { return mint(-y); }
  mint& operator+=(const mint a) {
    if ((y += a.y) >= mod) y -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((y += mod - a.y) >= mod) y -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (y *= a.y) %= mod;
    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 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.y; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.y; }

class modutils {
  vector<mint> fact, invfact;

 public:
  modutils(int n = 200005) : fact(n + 1), invfact(n + 1) {
    fact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;
    invfact[n] = fact[n].inv();
    for (int i = n; i >= 1; i--) invfact[i - 1] = invfact[i] * i;
  }
  mint pow(mint y, ll n) { return y.pow(n); }
  mint comb(ll n, ll k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return fact[n] * invfact[k] * invfact[n - k];
  }
  mint perm(ll n, ll k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return fact[n] * invfact[n - k];
  }
  mint fac(ll n) { return fact[n]; }
};

ll x;

map<ll, ll> memo;
ll dp(ll y){
  if(memo.count(y) != 0) return memo[y];
  memo[y] = abs(y-x);
  if(y % 2 == 0) chmin(memo[y], dp(y/2) + 1);
  else {
    chmin(memo[y], dp(y+1) + 1);
    chmin(memo[y], dp(y-1) + 1);
  }
  return memo[y];
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll y;
  cin >> x >> y;

  ll ans = dp(y);
  cout << ans << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

int x, y;
map<int, int> ans;

int solve(int x, int y) {
    if(x >= y) {
        return x - y;
    }
    if(ans.count(y))
        return ans[y];

    if(y & 1) {
        ans[y] = 2 + min(solve(x, (y - 1) / 2), solve(x, (y + 1) / 2));
    } else {
        ans[y] = 1 + solve(x, y / 2);
    }
    ans[y] = min(ans[y], y - x);

    return ans[y];
}

void test_case() {

    cin >> x >> y;
    cout << solve(x, y);

}

signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

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

}


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

typedef long long lli;
int MOD = 998244353;
inline int add(const int a, const int b, const int mod = MOD) { return (a + b >= mod) ? (a + b - mod) : (a + b); }
inline void _add(int &a, const int b, const int mod = MOD) { a = add(a, b, mod); }
inline int sub(const int a, const int b, const int mod = MOD) { return (a - b < 0) ? (a - b + mod) : (a - b); }
inline void _sub(int &a, const int b, const int mod = MOD) { a = sub(a, b, mod); }
inline int negate(const int a, const int mod = MOD) { return mod - a; }
inline int mul(const int a, const int b, const int mod = MOD) { return (a * 1ll * b) % mod; }
inline void _mul(int &a, const int b, const int mod = MOD) { a = mul(a, b, mod); }
int binPow(int b, lli p, const int mod = MOD) {
	int r = 1;
	while (p) {
		if (p & 1) r = mul(r, b, mod);
		b = mul(b, b, mod);
		p >>= 1;
	}
	return r;
}
int gcdex(int a, int b, int &x, int &y) {
	if (!b) return x = 1, y = 0, a;
	int px, py, res = gcdex(b, a % b, px, py);
	return x = py, y = px - a / b * py, res;
}
int inv(const int a, const int mod = MOD) { // a and mod must be coprime
	int x, y;
	int g = gcdex(a, mod, x, y);
	assert(g == 1);
	x = (x % mod + mod) % mod;
	return x;
}
inline int dvd(const int a, const int b, const int mod = MOD) { // b and mod must be coprime
	int rev = inv(b, mod);
	return mul(a, inv(b, mod), mod);
} // b != 0
inline void _dvd(int &a, const int b, const int mod = MOD) { a = dvd(a, b, mod); } // b and mod must be coprime
inline int convert(int x, const int mod = MOD) {
	int tx = x % mod + mod;
	return tx >= mod ? tx - mod : tx;
};

int main () {
    int n;
    int i2 = inv(2);
    while (scanf("%d", &n) == 1) {
        vector<int> a(n);
        for (auto &x : a) scanf("%d", &x);
        sort(a.begin(), a.end());

        int pol = 0;
        for (int i = 0; i < n; i++) pol = add(mul(pol, 2), a[i]);

        int res = 0;
        for (int i = n - 1; i >= 0; i--) {
            _sub(pol, a[i]);
            _mul(pol, i2);
            _add(res, mul(a[i], add(pol, a[i])));
        }

        printf("%d\n\n", res);
    }
}

#include<bits/stdc++.h>
using namespace std;
namespace IO
{
    const int buf_size=1<<20;
    char buf[buf_size],*S,*T;
    inline char read_char()
    {
        if(S==T)
            T=(S=buf)+fread(buf,1,buf_size,stdin);
        return S!=T?*(S++):EOF;
    }
    bool flag_EOF;
    inline int read_int()
    {
        char c=read_char();
        bool neg=false;
        while(c<'0'||c>'9')
        {
            if(c==EOF)
            {
                flag_EOF=true;
                return 0;
            }
            neg=(c=='-');
            c=read_char();
        }
        int x=0;
        while(c>='0'&&c<='9')
        {
            x=x*10+(c^48);
            c=read_char();
        }
        return neg?-x:x;
    }
    inline void read_string(char *s)
    {
        char c=read_char();
        while(c<'a'||c>'z')
        {
            if(c==EOF)
            {
                flag_EOF=true;
                return;
            }
            c=read_char();
        }
        while(c>='a'&&c<='z')
        {
            *(s++)=c;
            c=read_char();
        }
        *s='\0';
    }
    inline double read_double()
    {
        char c=read_char();
        bool neg=false;
        while(c<'0'||c>'9')
        {
            if(c==EOF)
            {
                flag_EOF=true;
                return 0;
            }
            neg=(c=='-');
            c=read_char();
        }
        double x=0;
        while(c>='0'&&c<='9')
        {
            x=x*10+(c^48);
            c=read_char();
        }
        if(c=='.')
        {
            c=read_char();
            double eps=1;
            while(c>='0'&&c<='9')
            {
                eps*=0.1;
                x+=eps*(c^48);
                c=read_char();
            }
        }
        return neg?-x:x;
    }
    char fw[buf_size];
    int pw;
    inline void flush()
    {
        fwrite(fw,1,pw,stdout);
        pw=0;
    }
    inline void write_char(char x)
    {
        if(pw==buf_size)
            flush();
        fw[pw++]=x;
    }
    char st[26];
    int top;
    inline void write_int(int x)
    {
        if(!x)
        {
            write_char('0');
            return;
        }
        if(x<0)
        {
            write_char('-');
            x=-x;
        }
        while(x)
        {
            st[++top]=x%10^48;
            x/=10;
        }
        while(top>0)
            write_char(st[top--]);
    }
    inline void write_string(const char *s)
    {
        for(int i=0;s[i];++i)
            write_char(s[i]);
    }
    inline void write_double(double x,int cnt_digits,bool mark=true)
    {
        if(x<0)
        {
            write_char('-');
            x=-x;
        }
        if(mark)
            x+=5*pow(0.1,cnt_digits+1);
        write_int(int(x));
        if(cnt_digits>0)
        {
            write_char('.');
            for(int i=1;i<=cnt_digits;++i)
            {
                x-=int(x),x*=10;
                write_char(int(x)^48);
            }
        }
    }
}
const int max_N=2e5+5;
int A[max_N];
const int mod=998244353;
const int inv2=(mod+1)>>1;
int pow2[max_N],pow_inv2[max_N];
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;++i)
		scanf("%d",A+i);
	sort(A+1,A+N+1);
	pow2[0]=pow_inv2[0]=1;
	for(int i=1;i<=N;++i)
	{
		pow2[i]=2ll*pow2[i-1]%mod;
		pow_inv2[i]=1ll*inv2*pow_inv2[i-1]%mod;
	}
	int ans=0,sum=0;
	for(int i=1;i<=N;++i)
	{
		ans=(ans+1ll*sum*A[i]%mod*pow2[i-1])%mod;
		ans=(ans+1ll*A[i]*A[i])%mod;
		sum=(sum+1ll*A[i]*pow_inv2[i])%mod;
	}
	printf("%d\n",ans);
    IO::flush();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
ll dmod(ll x){
    return ((x+mod)%mod);
}
ll modular_power(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1)ans=dmod(ans*x);
        y/=2;
        x=dmod(x*x);
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    int P[n+1];
    for(int i=1;i<=n;i++)cin>>P[i];
    set <int> st;
    for(int i=1;i<n;i++)st.insert(i);
    set <int> q;
    for(int i=1;i<n;i++)if(P[i]>i && P[i+1]<i+1)q.insert(i);
    vector <int> ans;
    while(!q.empty()){
        int x=*(q.begin());
        st.erase(x);
        swap(P[x],P[x+1]);
        q.erase(x);
        ans.push_back(x);
        if(x-1>0 && P[x-1]>x-1 && P[x]<x && st.count(x-1))q.insert(x-1);
        else if(q.count(x-1))q.erase(x-1);
        if(x+1<n && P[x+1]>x+1 && P[x+2]<x+2 && st.count(x+1))q.insert(x+1);
        else if(q.count(x+1))q.erase(x+1);
    }
    bool flag=true;
    for(int i=1;i<=n;i++)if(P[i]!=i)flag=false;
    if(flag && st.size()==0)for(auto it:ans)cout<<it<<endl;
    else cout<<-1;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<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; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n;
    cin >> n;
    vll p(n), a(n);
    REP(i, n) {
        cin >> p[i];
        p[i]--;
        a[i] = i - p[i];
    }
    vector<P> pos;
    ll sum = 0;
    REP(i, n) {
        if (a[i] > 0) {
            pos.push_back(P{i, a[i]});
            sum += a[i];
        }
    }
    if (sum != n - 1) {
        cout << -1 << endl;
        return 0;
    }
    vll res;
    vll used(n);
    for (auto x : pos) {
        ll tmp = x.first - 1;
        REP(i, x.second) {
            if (tmp == -1) {
                cout << -1 << endl;
                return 0;
            }
            if (used[tmp]) {
                cout << -1 << endl;
                return 0;
            }
            used[tmp] = 1;
            res.push_back(tmp);
            tmp--;
        }
    }
    vll ideal(n);
    iota(ALL(ideal), 0);
    REP(i, n - 1) {
        swap(p[res[i]], p[res[i] + 1]);
    }
    if (p == ideal) {
        REP(i, n - 1) cout << res[i] + 1 << endl;
    }
    else {
        cout << -1 << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
int main(){
	int a,b,c;cin>>a>>b>>c;
	if(a!=b){
		puts(a>b?"Takahashi":"Aoki");
	}
	else {
		puts(c==0?"Aoki":"Takahashi");
	}
	return 0;
}

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>

using namespace std;

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

#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second

// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
//     _os << '(' <<_p.first << ',' << _p.second << ')';
//     return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
//     _is >> _p.first >> _p.second;
//     return _is;
// }

ll pwr(ll b, ll c, ll mod) {
  if(c == 0) return 1;
  ll x = pwr(b,c/2,mod);
  if(c%2==0) return x*x%mod;
  return x*x%mod*b%mod;
}

void solve() {
  vector<vector<int>> d(10);
  d[0] = vector<int>{0};
  d[1] = vector<int>{1};
  d[2] = vector<int>{2,4,8,6};
  d[3] = vector<int>{3,9,7,1};
                  // 1 2 3 0
  d[4] = vector<int>{4,6};
  d[5] = vector<int>{5};
  d[6] = vector<int>{6};
  d[7] = vector<int>{7,9,3,1};
  d[8] = vector<int>{8,4,2,6};
  d[9] = vector<int>{9,1};

  ll a,b,c;
  cin>>a>>b>>c;
  a = a % 10;
  ll x = pwr(b%d[a].size(),c,d[a].size());
  cout<<d[a][(d[a].size()-1+x)%d[a].size()]<<endl;

}

// d+1, d+2, d+3, ...,  d'    ,... , M
// 0 [1]
// 1 [1]
// 2 [2,4,8,6,2]
// 3 [3,9,7,1,3]
// 4 [4,6,4]
// 5 [1]
// 6 [1]
// 7 [7,9,3,1,7]
// 8 [8,4,2,6,8]
// 9 [9,1,9]

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 // cout << fixed << setprecision(15);2000000000

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 // prime_factors();
 int t = 1;
 // cin >> t;
 while (t--) {
   solve();
 }

 return 0;
}


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

int main() {

  int N;
  cin >> N;
  vector<int> A(pow(2,N));
  for (int i = 0; i < pow(2,N); i++) {
  	cin >> A.at(i);
  }
  vector<int> B(pow(2,N)); //勝ち残った選手のベクトル
  for (int i = 0; i < pow(2,N); i++){
    B.at(i) = i;
  } // 初期値はすべての選手
  for (int i = 0; i < N-1; i++){ // 決勝手前まで
    for (int j = 0; j < pow(2 , (N-i-1)); j++)
      if (A.at(B.at(2*j)) > A.at(B.at(2*j+1))){
        B.at(j) = B.at(2*j);
      }
      else {
        B.at(j) = B.at(2*j+1);
      }
  }
  // 決勝で負ける方を出力 ただし1ずらす
  if (A.at(B.at(0)) > A.at(B.at(1))){
    cout << B.at(1) + 1 << endl;
  }
  else {
    cout << B.at(0) + 1 << endl;
  }
}

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

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define p push
#define pp pop
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define maxe *max_element
#define mine *min_element
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define L size()
#define C count()
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

typedef long long int ll;
#define V(type) vector<type>
#define PQ(type) priority_queue<type>
#define pll pair<ll, ll>
#define F first
#define S second

#define repl(i, a, b) for(ll i=a;i<b;i++)
#define forrl(i, n) for(ll i=0;i<n;i++)
#define coll(v, n) for(int i = 0; i < n;i++){cin>>v[i];}

#define INF 9223372036854775807
const double delta = 0.0000000001;
const double pi = 3.1415926535;

void FAST() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll powM(ll x, ll y, ll m) {  //returns (a^b)%m ( ^ is exponent )
  ll ans = 1, r = 1;
  x %= m;
  while (r > 0 && r <= y)
  {
    if (r & y)
    {
      ans *= x;
      ans %= m;
    }
    r <<= 1;
    x *= x;
    x %= m;
  }
  return ans;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll lcm(ll a, ll b)
{
    ll x = gcd(a, b);
    ll ans = (a*b)/x;
    return ans;
}
bool IsPrime(long long int n){  // Returns if the passed number is prime or not.
        if (n <= 1)  return false;
        if (n <= 3)  return true;

        if (n%2 == 0 || n%3 == 0) return false;

        for (ll i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

         return true;
    }
pair<ll,ll> intersection(pair<ll,ll>x, pair<ll,ll>y)
{
    pair<ll,ll> ans;
    if(x.first<=y.first)
    {
        if(x.second<y.first){
            ans=make_pair(-1,-1);//case of no intesection
            return ans;
        }
        else{
            ans.first=max(x.first,y.first);
            ans.second=min(x.second,y.second);
            return ans;
        }
    }
    else{
        if(y.second<x.first){
            ans=make_pair(-1,-1);//case of no intersection
            return ans;
        }
        else{
            ans.first=max(x.first,y.first);
            ans.second=min(x.second,y.second);
            return ans;
        }
    }
}

ll pal(string str)
{
    string temp = str;
    reverse(temp.begin(), temp.end());

    if(temp == str)
        return 1;

    return 0;
}

int main(){
  ll n;cin>>n;
  ll num = powM(2,n,LLONG_MAX);
  ll arr[num];
  ll max =-1;
  pair<ll,ll> m1,m2;
  for(ll i=0;i<num;i++)cin>>arr[i];
  for(ll i=0;i<num/2;i++){
    if(arr[i]>max){
      max=arr[i];
      m1.first=max;
      m1.second=i+1;
    }
  }
    max=-1;
    for(ll i=num/2;i<num;i++){
        if(arr[i]>max){
         max=arr[i];
         m2.first=max;
      	 m2.second=i+1;
      }
    }
  if(m1.first<m2.first)
    	cout<<m1.second;
  else
    	cout<<m2.second;

}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

template<typename M, typename N>
istream& operator>>(istream&is, pair<M,N> & p){is >> p.first >> p.second; return is;}
template<typename M>
istream& operator>>(istream&is, vector<M> & v){for(auto &it:v) is >> it; return is; }
template<typename M>
istream& operator>>(istream&is, vector<vector<M>> & v){for(auto &it:v) is >> it; return is; }
template<typename M, typename N>
ostream& operator<<(ostream&os, const pair<M,N> &p){os << p.first << ' ' << p.second << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<M> &v){for(auto it: v)os << it << ' ';cout << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<vector<M>> &v){for(auto it: v)os << it;return os;}

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define unique(x) sort(all(x)); x.erase(unique(all(x)),x.end());
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef complex<long double> cd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld eps=1e-7;
const ld pi=acos(-1);
const ll inf=(ll)1e9+10;
//const int mod=1000000007;
const int mod=998244353;

int n, m, k;
const int N=5e3+10;

vector<string> solve(int k){
    if(k==1){
        return {"AB"};
    }
    auto v =solve(k-1);
    string s;
    for(int i=0; i<1<<(k-1); i++){
        s+='A';
    }
    for(int i=0; i<1<<(k-1); i++){
        s+='B';
    }
    int sz=(int)v.size();
    for(int i=0, n=(1<<(k-1)); i<sz; i++){
        string t=v[i];
        v[i]+=v[i];
        for(int j=0; j<n; j++){
            t+=v[i][j]=='A'?'B':'A';
        }
        v.pb(t);
    }
    v.pb(s);
    return v;
}

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int k;
    cin >> k;
    auto v = solve(k);
    cout << v.size() << el;
    for(auto s: v){
        cout << s << el;
    }
    return 0;
}


#include <iostream>
#include<math.h>
#include<vector>
using namespace std;
#define rep(i,a,b)   for(int i=a;i<b;i++)

int main() {
	int a = 0, b = 0, c = 0;
	cin >> a;
	cin >> b;
	cin >> c;
	int numa = 7 - a;
	int numb = 7 - b;
	int numc = 7 - c;
	int y = 0;
	y = numa + numb + numc;
	cout << y;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define rfor(i, b, a) for(ll i = b; i >= a; i--)
#define X first
#define Y second
#define pb push_back
#define play {ios_base::sync_with_stdio(false);}
#define tennis {cin.tie(NULL); cout.tie(NULL);}
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define vsz(x) ((long long) x.size())
#define arrout(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define arrin(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define all(v) v.begin(), v.end()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define debug(x) cout << '>' << #x << ':' << x << endl;
//const ll mod = 1e9 + 7;

//dont stop trying :)

template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
{
	return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
{
	bool first = true;
	os << "[";
	for(unsigned int i = 0; i < v.size(); i++)
	{
		if(!first)
			os << ", ";
		os << v[i];
		first = false;
	}
	return os << "]";
}

ll n, m, k;
const ll template_size_array = 1e6 + 1393;
ll a[template_size_array];
ll b[template_size_array];
ll c[template_size_array];
string s, t;

void solve(int tc = 0) {
	int a, b, c;
	cin >> a >> b >> c;
	cout << 21 - (a + b + c);
}

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

	play tennis;
	cout << setprecision(12) << fixed;

	int tc = 1;
	// cin >> tc;
	for (int tt = 0; tt < tc; tt++) solve(tt);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 3;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

struct mint{
  ll val;
  mint() {}
  mint(ll x) {val = mod(x, MOD);}
  mint operator-() {return mint(-this->val);}
  bool operator==(mint a) {return this->val == a.val;}
  bool operator<(mint a) {return this->val < a.val;}
  bool operator!=(mint a) {return this->val != a.val;}
  mint operator+(mint a) {return mint(this->val + a.val);}
  mint operator-(mint a) {return mint(this->val - a.val);}
  mint operator*(mint a) {return mint(this->val * a.val);}
  mint operator/(mint a) {return mint(this->val * a.inv().val);}
  mint &operator+=(mint a) {return *this = *this + a;}
  mint &operator-=(mint a) {return *this = *this - a;}
  mint &operator*=(mint a) {return *this = *this * a;}
  mint &operator/=(mint a) {return *this = *this / a;}
  friend istream &operator>>(istream &is, mint &m) {
    is >> m.val;
    return is;
  }
  friend ostream &operator<<(ostream &os, mint &m) {
    os << m.val;
    return os;
  }
  mint pow(ll n) {
    if(n == 0) return 1;
    if(n & 1) return pow(n-1) * *this;
    mint ret = pow(n/2);
    return ret * ret;
  }
  vector<mint> powv(ll n) {
    vector<mint> vec(n+1, 1);
    rep2(i, 1, n) vec[i] = vec[i-1] * *this;
    return vec;
  }
  mint inv() {return pow(MOD-2);}
  vector<mint> invv(ll n) {
    vector<mint> vec(n+1, 1);
    rep2(i, 2, n) vec[i] = -vec[MOD%i] * (MOD/i);
    return vec;
  }
};

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

  ll n, m, ans = 1;
  cin >> n >> m;
  vl a(m), b(m);
  vb used(n, 0);
  vvl G(n);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  vl parent(n, -1), root(n, -1);
  rep(i, n) {
    if(used[i]) continue;
    used[i] = 1;
    ql q;
    q.push(i);
    vl vec;
    while(!q.empty()) {
      ll v = q.front();
      q.pop();
      root[v] = i;
      for(ll u: G[v]) {
        if(used[u]) continue;
        used[u] = 1;
        q.push(u);
        vec.push_back(u);
        parent[u] = v;
      }
    }
    ll vs = vec.size(), tmp = 0;
    if(vs == 0) {ans *= 3; continue;}
    rep(bit, 1 << vs) {
      vector<mint> c(n, 0);
      c[vec[0]] = (bit & 1) + 1;
      rep2(j, 1, vs-1) c[vec[j]] = c[parent[vec[j]]] + ((bit >> j) & 1) + 1;
      bool ok = 1;
      rep(j, m) if(root[a[j]] == i && c[a[j]] == c[b[j]]) ok = 0;
      if(ok) tmp++;
    }
    ans *= tmp*3;
  }
  cout << ans << newl;
  return 0;
}

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

int main() {
	int n, cnt1, cnt2, m;
	cin >> n >> m;
	cnt1 = cnt2 = 0;
	for (int i = 1; i <= n; i++) {
		string s;
		cin >> s;
		int cnt = 0;
		for (auto p : s) p == '1' ? cnt++ : 0;
		cnt & 1 ? cnt1++ : cnt2++;
	}
	cout << 1ll * cnt1 * cnt2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    ll n, w;
    cin >> n >> w;
    int ans = 0;
    int a = n;
    while (a >= w) {
        a -= w;
        ans++;
    }
    cout << ans << endl;
}

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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define inf 1000000000000000000ll
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

const int MOD = 1e9+7;

inline ll add(ll x, ll y) {
    x %= MOD;
    y %= MOD;
    ll ans = (x+y)%MOD;
    return ans;
}

inline ll mul(ll x,ll y) {
    x %= MOD;
    y %= MOD;
    ll ans = ((x*y)%MOD+MOD)%MOD;
    return ans;
}

int main() {
    fastio;
    ll N,W;
    cin>>N>>W;

    ll ans = N/W;
    cout<<ans<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(x) x.begin() , x.end()
#define ld long double
const long long inf = 1e18 + 1LL;
const int mod = 1e9 + 7LL;
void solve();
void ITO();
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ITO();
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}
const int N = (1e6 + 5);
void solve()
{
	int n; cin >> n;
	int arr[n]; for (auto &x : arr) cin >> x;
	ll res = 0;
	stack<int>s;
	int ind[n]; ind[0] = 0 ; s.push(0);
	for (int i = 1; i < n ; ++i)
	{
		while (!s.empty() and arr[s.top()] >= arr[i]) s.pop();
		ind[i] = (s.empty() ? 0 : s.top() + 1);
		s.push(i);
	}
	while (!s.empty()) s.pop();
	for (int i = n - 1 ; i >= 0 ; --i)
	{
		while (!s.empty() and arr[s.top()] >= arr[i]) s.pop();
		int j = (s.empty() ? n - 1 : s.top() - 1);
		s.push(i);
		res = max(res , (j - ind[i] + 1) * arr[i]);
	}
	cout << res;
	cout << "\n";
	return ;
}
void ITO()
{
#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf1.in", "w", stdout);
#endif
}
//                                                                  🙃

#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007 // 998244353
#define INFLL (1LL<<62)
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
__attribute__((constructor))
void init(){ std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout<<std::fixed<<std::setprecision(15); }
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ll n, m;
    cin >> n >> m;
    vi h(n), w(m);
    rep(i, n) cin >> h[i];
    rep(i, m) cin >> w[i];
    sort(all(h));
    sort(all(w));

    // 先頭を含むもの、末尾を含むものの2ペア
    vi sum_s, sum_e;
    rep(i, (n-1)/2){
        sum_s.emplace_back(abs(h[2*i]-h[2*i+1]));
        sum_e.emplace_back(abs(h[2*i+1]-h[2*i+2]));
    }

    // 累積和
    vi imos_s((n-1)/2+1), imos_e((n-1)/2+1);
    imos_s[0] = 0, imos_e[0] = 0;
    rep(i, (n-1)/2){
        imos_s[i+1] = imos_s[i] + sum_s[i];
        imos_e[i+1] = imos_e[i] + sum_e[i];
    }
    imos_s.emplace_back(0);
    imos_e.emplace_back(0);

    // 取り除く対象（i番目）をを全探索
    ll ans = INFLL;
    rep(i, n){
        ll total = 0;
        if(i%2 == 0){
            total = imos_s[(i/2)] + imos_e[(n-1)/2] - imos_e[(i/2)];
            auto it = lower_bound(all(w), h[i]);
            ll num = abs(h[i]-(*it));
            if(it != w.begin()){
                it--;
                chmin(num, abs(h[i]-(*it)));
            }
            chmin(ans, total+num);
        }
        else{
            total += imos_s[(i/2)] + + imos_e[(n-1)/2] - imos_e[(ll)(ceil(i/2.0))] + abs(h[i-1] - h[i+1]);
            auto it = lower_bound(all(w), h[i]);
            ll num = abs(h[i]-(*it));
            if(it != w.begin()){
                it--;
                chmin(num, abs(h[i]-(*it)));
            }
            chmin(ans, total+num);
        }
    }
    cout << ans << endl;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

class BManyOranges {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int A, B, W;
        cin >> A >> B >> W;
        W *= 1000;
        int num = 1;
        int mina = INF;
        int maxa = -INF;
        while (num * A <= W) {
            if (W <= num * B) {
                mina = min(num, mina);
                maxa = max(num, maxa);
            }
            num++;
        }
        if (mina == INF) {
            cout << "UNSATISFIABLE" << endl;
            return;
        }
        cout << mina << " " << maxa << endl;
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BManyOranges solver;
    solver.solve(in, out);
    return 0;
}

#pragma GCC optimize("Ofast")
//#ifndef ONLINE_JUDGE
//#define _GLIBCXX_DEBUG
//#endif
#ifdef ONLINE_JUDGE
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <math.h>
#include <complex>

using namespace std;
#ifdef ONLINE_JUDGE
using namespace atcoder;
#endif
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
#ifdef ONLINE_JUDGE
//using mint = modint998244353;
//using mint = modint;
using mint = modint1000000007;
#endif
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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

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

  ll N; cin>>N;
  vector<ll> A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];

  ll ans=INF;
  rep(i,N) rep(j,N) {
    if(i==j) chmin(ans,A[i]+B[j]);
    else chmin(ans,max(A[i],B[j]));
  }

  cout<<ans<<'\n';

  return 0;
}


#include <bits/stdc++.h>

#define MN 1001000

using namespace std;
typedef long long ll;

#define MOD 998244353

ll n, w[110], dp[102][10010][102], fat[110], sum;

ll solve(int i, int sum, int rem) {
    if(rem < 0 || sum < 0) return 0;
    if(i == n) return (sum == 0 && rem == 0);
    ll &x = dp[i][sum][rem];
    if(x != -1) return x;
    x = solve(i + 1, sum - w[i], rem - 1) + solve(i + 1, sum, rem);
    if(x >= MOD) x -= MOD;
    return x;
}

int main() {
    fat[0] = 1;
    for(ll i = 1; i <= 101; i++)
        fat[i] = fat[i-1] * i % MOD;

    scanf("%lld", &n);
    for(int i = 0; i < n; i++) {
        scanf("%lld", &w[i]);
        sum += w[i];
    }

    if(sum % 2) puts("0");
    else {
        ll ans = 0;
        memset(dp, -1, sizeof dp);
        for(int i = 1; i < n; i++) {
            ans += solve(0, sum / 2, i) * fat[i] % MOD * fat[n-i] % MOD;
            if(ans >= MOD) ans -= MOD;
        }
        printf("%lld\n", ans);
    }

    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define pb push_back

using namespace std;

void test(){
	ll n;
	cin>>n;
	ll c[n][n];
	f(i,n)f(j,n)cin>>c[i][j];
	if(n==1){
		cout<<"Yes\n";
		cout<<c[0][0]<<"\n";
		cout<<"0\n";
		return ;
	}

	ll p[n][n-1];
	f(i,n){
		for(int j=1;j<n;j++){
			p[i][j-1] = c[i][j] - c[i][j-1];
		}
	}

	ll q[n-1][n];
	f(i,n){
		for(int j=1;j<n;j++){
			q[j-1][i] = c[j][i] - c[j-1][i];
		}
	}

	f(col,n-1){
		for(int row=1;row<n;row++){
			if(p[row][col]!=p[row-1][col]){
				cout<<"No\n";
				return ;
			}
		}
	}
	f(row,n-1){
		for(int col=1;col<n;col++){
			if(q[row][col]!=q[row][col-1]){
				cout<<"No\n";
				return ;
			}
		}
	}

	ll a[n], b[n];
	// a[0] = 0, b[0] = c[0][0];
	ll n1 = 0, n2 = 0;
	ll m1 = 0, m2 = 0;
	for(int i=1;i<n;i++){
		n1 = n1 + p[0][i-1];
		m1 = min(m1,n1);
		n2 = n2 + q[i-1][0];
		m2 = min(m2,n2);
	}

	ll val1 = max(0LL,-1LL*m1) + max(0LL,-1LL*m2);
	if(c[0][0]<(val1)){
		cout<<"No\n";
		return ;
	}
	cout<<"Yes\n";
	a[0] = max(0LL,-1LL*m1);
	b[0] = c[0][0] - a[0];

	for(int i=1;i<n;i++){
		a[i] = a[i-1] + p[0][i-1];
		b[i] = b[i-1] + q[i-1][0];
	}

	f(i,n)cout<<b[i]<<" ";cout<<"\n";
	f(i,n)cout<<a[i]<<" ";cout<<"\n";

}

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


#ifdef ONLINE_JUDGE
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
constexpr char ln = '\n';
istream& operator>>(istream& is, __int128_t& x) {
    x = 0;
    string s;
    is >> s;
    int n = int(s.size()), it = 0;
    if (s[0] == '-') it++;
    for (; it < n; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return is;
}
ostream& operator<<(ostream& os, __int128_t x) {
    if (x == 0) return os << 0;
    if (x < 0) os << '-', x = -x;
    deque<int> deq;
    while (x) deq.emplace_front(x % 10), x /= 10;
    for (int e : deq) os << e;
    return os;
}
template<class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    for (int i = 0; i < int(v.size()); i++) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "}";
}
template<class Container> inline int SZ(Container& v) { return int(v.size()); }
template<class T> inline void UNIQUE(vector<T>& v) { v.erase(unique(v.begin(), v.end()), v.end()); }
template<class T1, class T2> inline bool chmax(T1& a, T2 b) { if (a < b) {a = b; return true ;} return false ;}
template<class T1, class T2> inline bool chmin(T1& a, T2 b) { if (a > b) {a = b; return true ;} return false ;}
inline int topbit(ull x) { return x == 0 ? -1 : 63 - __builtin_clzll(x); }
inline int botbit(ull x) { return x == 0 ? 64 : __builtin_ctzll(x); }
inline int popcount(ull x) { return __builtin_popcountll(x); }
inline int kthbit(ull x, int k) { return (x>>k) & 1; }
inline constexpr long long TEN(int x) { return x == 0 ? 1 : TEN(x-1) * 10; }
inline void print() { cout << "\n"; }
template<class T>
inline void print(const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        if (i) cout << " ";
        cout << v[i];
    }
    print();
}
template<class T, class... Args>
inline void print(const T& x, const Args& ... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
inline void debug_out() { cerr << endl; }
template <class T, class... Args>
inline void debug_out(const T& x, const Args& ... args) {
    cerr << " " << x;
    debug_out(args...);
}
#define debug(...) cerr << __LINE__ << " : [" << #__VA_ARGS__ << "] =", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void No() {
    cout << "No" << ln;
    exit(0);
}

int main() {
    ll N,M,T; cin >> N >> M >> T;
    ll A = N;
    ll cur = 0;
    rep(i,M) {
        ll a,b; cin >> a >> b;
        A -= (a-cur);
        if (A <= 0) No();
        A += (b-a);
        chmin(A,N);
        cur = b;
    }
    A -= (T-cur);
    if (A <= 0) No();

    cout << "Yes" << ln;
}

#define TO_BE_SUBMITTED
#include <bits/stdc++.h>
// #include <atcoder/fenwicktree>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/string>
// #include <atcoder/math>
// #include <atcoder/convolution>
// #include <atcoder/modint>
// #include <atcoder/dsu>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/scc>
// #include <atcoder/twosat>

namespace atcoder{};
using namespace atcoder;
using namespace std;

#define fr first
#define sc second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (n); i >= 1; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vlp = vector<LP>;
inline int getInt()
{
    int x;
    scanf("%d", &x);
    return x;
}
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;
}

const ll INF = INT64_MAX;
ll N, M;
struct E{
    ll to;
    ll cost;
    ll rash;
};
vector<vector<E>> edges;
vector<ll> dp;

void input(){
    cin >> N >> M;

    edges = vector<vector<E>>(N);
    rep(i, M){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--;
        b--;

        edges[a].pb(E{b, c, d});
        edges[b].pb(E{a, c, d});
    }
}

ll calcRash(ll d, ll t){
    return d / (t + 1LL);
}

ll calcBestTime(ll now, ll d){
    if(now >= d){
        return now;
    }

    ll sqrtD = floor(sqrt(d));
    ll t1 = max(sqrtD - 1, now);
    ll t2 = max(sqrtD, now);

    if(now + calcRash(d, now) > t1 + calcRash(d, t1)){
        now = t1;
    }
    if(now + calcRash(d, now) > t2 + calcRash(d, t2)){
        now = t2;
    }

    return now;
}

void solve()
{
    input();
    dp = vl(N, INF);
    PQ(LP) pq;

    dp[0] = 0;
    pq.push(LP(0, 0));

    while(!pq.empty()){
        LP lp = pq.top();
        pq.pop();
        ll dist = lp.fr;
        ll from = lp.sc;
        if(dp[from] < dist){
            continue;
        }

        for(auto edge : edges[from]){
            ll to = edge.to;
            ll cost = edge.cost;
            ll rash = edge.rash;

            ll departureTime = calcBestTime(dist, rash);
            if(chmin(dp[to], departureTime + cost + calcRash(rash, departureTime))){
                pq.push(LP(dp[to], to));
            }
        }
    }

    ll ans = dp[N-1];
    if(ans == INF){
        ans = -1LL;
    }

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

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
// using namespace atcoder;
#endif
#define int long long
#define rep(i, n) for(int i = 0;i<(int)(n);i++)
#define all(v) (v).begin(),(v).end()
using lint = long long;
using ll = long long;
using P = std::pair<int,int>;

constexpr int inf = 2e18;

bool chmin(int &a,const int b) {
    if(a>b) {
        a=b;
        return true;
    }
    return false;
}

struct UnionFind {
    vector<int> par, size;
    UnionFind(int x) {
        par.resize(x);
        size.resize(x, 1);
        for(int i = 0; i < x; i++) {
            par[i] = i;
        }
    }
    int find(int x) {
        if (par[x] == x)
            return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int consize(int x) {
        return size[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return false;
        if (size[x] < size[y]) {
            par[x] = y;
            size[y] += size[x];
        }
        else {
            par[y] = x;
            size[x] += size[y];
        }
        return true;
    }
};

int n,m;
std::vector<int> G[100010];

int dp[300030][20];

int dis[20][20];

std::vector<int> BFS(int s) {
    std::vector<int> dist(n,inf);
    dist[s] = 0;
    std::queue<int> que;
    que.push(s);
    while(!que.empty()) {
        int v = que.front();que.pop();
        for(auto &to:G[v]) if(chmin(dist[to],dist[v]+1)) que.push(to);
    }
    return dist;
}

signed main() {
    std::cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int a,b;
        std::cin >> a >> b;
        a--,b--;
        uf.unite(a,b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int k;
    std::cin >> k;
    std::vector<int> v(k);
    rep(i, k) std::cin >> v[i],v[i]--;
    std::set<int> st;
    for(auto p:v) st.insert(uf.find(p));
    if(st.size()!=1) return !printf("-1\n");
    rep(i, k) {
        auto vec = BFS(v[i]);
        rep(j, k) dis[i][j] = vec[v[j]];
    }
    // rep(i, k) dis[k][i]=1;
    rep(i, 300030) rep(j, 20) dp[i][j]=inf;
    // dp[1<<k][k] = 0;
    // rep(i, k) rep(j, k) std::cout << dis[i][j] << " \n"[j==k-1];
    rep(i, k) dp[1<<i][i] = 1;
    rep(bit, (1<<(k+1))) {
        rep(i, k) {
            if((~bit)&(1<<i)) continue;
            // printf("OK\n");
            rep(j, k) {
                if(bit&(1<<j)) continue;
                chmin(dp[bit|(1<<j)][j],dp[bit][i]+dis[i][j]);
                // std::cout << bitset<3>(bit) << ' ' << i << ' ' << j << ' ' << std::endl;
            }
        }
    }
    // rep(i, 7) rep(j, 3) std::cout << dp[i][j] << " \n"[j==2];
    int mi = inf;
    rep(i, k) chmin(mi,dp[(1<<k)-1][i]);
    std::cout << mi << std::endl;
    return 0;
}

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
ll dp[17][100005];
int n;
V<V<int>> g;
void d(int s,int st){
       for(int i=0;i<n;i++){
            dp[s][i]=inf;
       }
       dp[s][st]=0;
       queue<int> q;
       q.emplace(st);
       while(q.size()){
           int cur=q.front();
           q.pop();
           for(int v:g[cur]){
                 if(chmin(dp[s][v],dp[s][cur]+1)){
                     q.emplace(v);
                 }
           }
       }
}
int main(){
    int m;
    cin>>n>>m;
    g=V<V<int>>(n);
    for(int i=0;i<m;i++){
          int a,b;
          cin>>a>>b;
          g[--a].emplace_back(--b);
          g[b].emplace_back(a);
    }
    int k;
    cin>>k;
    V<int> c(k);
    for(int i=0;i<k;i++){
        cin>>c[i];
        c[i]--;
        d(i,c[i]);
        //for(int j=0;j<n;j++)cout<<dp[i][j]<<" ";
        //cout<<"\n";
    }
    V<V<ll>> res((1<<k)+5,V<ll>(k+1,inf));
    for(int i=0;i<k;i++)res[(1<<i)][i]=1;
    for(int s=0;s<(1<<k);s++){
        for(int i=0;i<k;i++){
             if(~s&(1<<i))continue;
             for(int j=0;j<k;j++){
                 if(s&(1<<j))continue;
                 chmin(res[s|(1<<j)][j],res[s][i]+dp[i][c[j]]);
             }
        }
    }
    ll ans=inf;
    for(int i=0;i<k;i++)chmin(ans,res[(1<<k)-1][i]);
    cout<<(ans>=inf?-1:ans)<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e8;
int h,w,x,y;
char s[110][110];
int main()
{
    int sum=1;
    cin>>h>>w>>x>>y;
    y--;
    for(int i=1;i<=h;i++)
        cin>>s[i];
    for(int i=x+1;i<=h;i++)
        if(s[i][y]=='.')
            sum++;
        else break;
    for(int i=x-1;i>=1;i--)
        if(s[i][y]=='.')
            sum++;
        else break;
    for(int i=y+1;i<w;i++)
        if(s[x][i]=='.')
            sum++;
        else break;
    for(int i=y-1;i>=0;i--)
        if(s[x][i]=='.')
            sum++;
        else break;
    cout<<sum;
    return 0;
}

#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

using namespace std;

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

constexpr ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
ostream &operator<<(ostream &o, const string &obj) {o << "\""; o << obj.c_str(); o << "\""; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}

#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif

template <typename... Ts>
std::istream& IN(Ts&... xs){ return (std::cin >> ... >> xs); }

#define repr(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)

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

    ll h,w,x,y;
    IN(h,w,x,y);

    x--; y--;

    vector<vector<ll>> m(h,vector<ll>(w,0));

    rep(i,h){
        string s;
        cin >> s;
        rep(j,w){
            m[i][j] = (s[j] == '#');
        }
    }

    print(m, x,y)

    auto count_ok = [&](ll step_x, ll step_y){
        ll i,j;
        i = y+step_y; j=x+step_x;
        ll res = 0;
        print(i,j)
        while(0 <= j && j < h &&
              0 <= i && i < w){
                  if(m[j][i] != 0){
                      break;
                  }
                  print(i,j,res)
                  res++;
                  i += step_y;
                  j += step_x;
              }
        return res;
    };

    ll ans = (m[x][y] == 0);

    ans += count_ok(1,0);
    ans += count_ok(0,1);
    ans += count_ok(-1,0);
    ans += count_ok(0,-1);

    cout << ans << endl;

    return 0;
}