// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
const long long INF=9e18;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long, long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1)%mod;
}
//素因数分解(mapで返す)
map<int,int> factor(long long p){
  ll p1=p;
  map<int, int>ret;
  for(int i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

//Union-Find木
struct UnionFind{
  //メンバ変数
  vector<long long>par; //par[i]:=頂点iの親
  vector<long long>s; //s[i]:=頂点iが属する集合の個数(iが根のとき)

  //コンストラクタ
  UnionFind(long long N):par(N),s(N){
    for(long long i=0;i<N;i++){
      par[i]=i; //最初はすべてが根として初期化
      s[i]=1;
    }
  }
  //メンバ関数
  //root(i):=頂点iの根
  long long root(long long i){
    if(par[i]==i) return i;
    par[i]=root(par[i]); //経路圧縮
    return root(par[i]); //再帰
  }
  //size[i]:=iが属する集合の個数
  long long size(long long i){
    return s[root(i)];
  }
  //same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか)
  bool same(long long x, long long y){
    return root(x)==root(y);
  }
  //unite(x,y) xの根をyの根に繋げる(集合を合併)
  void unite(long long x, long long y){
    if(!same(x,y)){
      long long rx=root(x);
      long long ry=root(y);
      par[rx]=par[ry];
      s[ry]=s[rx]+s[ry];
    }
  }
};

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////

ll s(int a, int b){
  ll n = b - a + 1;
  ll ret = (n * (n+1)) / 2 + n * (a - 1);
  return ret;
}
//メイン関数
int main(){
  cout<<fixed<<setprecision(14);

  int N; cin >> N;
  vector<pair<int, int>> p(N);
  rep(i, N) cin >> p[i].first >> p[i].second;

  bool OK = false;

  rep(i, N){
    for(int j = i + 1; j < N; j++){
      for(int k = j + 1; k < N; k++){
        int x1 = p[j].first - p[i].first;
        int y1 = p[j].second - p[i].second;
        int x2 = p[k].first - p[j].first;
        int y2 = p[k].second - p[j].second;

        if(x1 * y2 == x2 * y1) OK = true;
      }
    }
  }

  if(OK) cout << "Yes" << endl;
  else cout << "No" << endl;
}

#pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define N 200005
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (ll x) {  return x && (!(x&(x-1)));  }
ll Modular_Exponentiation(ll x, ll n, ll M)
{
    if(n==0) return 1;
    if(n%2) return (x*Modular_Exponentiation((x*x)%M,n/2,M))%M;
    else return (Modular_Exponentiation((x*x)%M,n/2,M))%M;
}
bool isprime(ll n)
{
    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+=6)
        if (n%i==0||n%(i+2)==0) return false;

    return true;
}
/********************************************************************************************/
void solve()
{
    ll n; cin>>n;
    vector<pair<ll,ll>> vp;
    ll c1=0, c2=0, c3=0;
    rep(i,0,n)
    {
        ll x,y; cin>>x>>y;
        vp.pb({x,y});
        if(!x) c1++;
        if(!y) c2++;
        if(x==y) c3++;
    }
    if(c1>=3 or c2>=3 or c3>=3) { cout<<"Yes"; return; }
    rep(i,0,n)
    {
        rep(j,i+1,n)
        {
            rep(k,j+1,n)
            {
                ll x1=vp[i].f, y1=vp[i].s;
                ll x2=vp[j].f, y2=vp[j].s;
                ll x3=vp[k].f, y3=vp[k].s;
                ll a=(y2-y1)*(x1-x3);
                ll b=(y1-y3)*(x2-x1);
                if(a==b)
                {
                    cout<<"Yes";
                    return;
                }
            }
        }
    }cout<<"No";

}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1; //cin>>T;
    rep(i,0,T)
    {
        solve();
    }
    cerr<<"Time taken : "<<fixed<<setprecision(5)<<((float)clock()/CLOCKS_PER_SEC)*1000<<" ms"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


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

int main() {
    int64_t n, m, k = 0, ans = 0;
    cin >> n >> m;
    vector<int64_t> a(m + 1, 0);
    map<int64_t, int> s;
    for (auto i = 0; i < m; i++) cin >> a[i];
    a.push_back(n + 1);
    sort(a.begin(), a.end());
    for (auto i = 0; i < (int)a.size() - 1; i++)
        if (a[i + 1] != a[i]) s[a[i + 1] - a[i] - 1]++;
    for (auto& elm : s) {
        if (elm.first == 0) continue;
        if (k == 0) k = elm.first, ans += elm.second;
        else
            ans += (elm.first / k +
                    ((elm.first % k) ? 1 : 0)) *
                   elm.second;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int p(int A,int B){
  if(!B)return 1;
  if(B&1)return p(A,B-1)*A%mod;
  int C=p(A,B/2);
  return C*C%mod;
}
signed main(){
  int H,W,cnt=0,ans=0;
  cin>>H>>W;
  vector<string> A(H);
  for(string &S:A)cin>>S;
  vector<vector<int>> B(H+1,vector<int>(W+1,-mod));
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      if(A[i][j]=='.')B[i][j]=1,cnt++;
  vector<vector<int>> C=B;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++){
      B[i][j+1]+=max(B[i][j],0LL);
      C[i+1][j]+=max(C[i][j],0LL);
    }
  vector<vector<int>> D(H,vector<int>(W,-1));
  for(int i=H-1;i>=0;i--)
    for(int j=W-1;j>=0;j--){
      if(B[i][j]>=0 && B[i][j+1]>=0)B[i][j]=B[i][j+1];
      if(C[i][j]>=0 && C[i+1][j]>=0)C[i][j]=C[i+1][j];
      if(B[i][j]>=0)D[i][j]+=B[i][j];
      if(C[i][j]>=0)D[i][j]+=C[i][j];
    }
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      if(D[i][j]>0)ans=(ans+p(2,cnt-D[i][j])*((p(2,D[i][j])-1+mod)%mod)%mod)%mod;
  cout<<ans<<endl;
}


#include<iostream>

using namespace std;

int main(void){
    int a,b,x,y;
    int ans;

    cin >> a >> b >> x >> y;
    ans = 0;
    if(a < b){
        if(x*2 < y){
            ans = (b - a + 1) * x + (b - a) * x;
        }
        else{
            ans = (b - a) * y + x;
        }
    }
    else if(a > b){
        if(x*2 < y){
            ans = (a - b - 1) * x + (a - b) * x;
        }
        else{
            ans = (a - b - 1) * y + x;
        }
    }
    else{
        ans = x;
    }

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

#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<pll> edge;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, X, Y;
    cin >> A >> B >> X >> Y;

    vector<Vertex> V(300);
    ll x = 100;
    REP(i, x) {
        V[i].edge.push_back(pll(i + x, X));
        V[i + x].edge.push_back(pll(i, X));
    }
    REP(i, x - 1) {
        V[i + 1].edge.push_back(pll(i + x, X));
        V[i + x].edge.push_back(pll(i + 1, X));
        V[i].edge.push_back(pll(i + 1, Y));
        V[i + 1].edge.push_back(pll(i, Y));
        V[i + x].edge.push_back(pll(i + x + 1, Y));
        V[i + x + 1].edge.push_back(pll(i + x, Y));
    }
    A--;
    B = B - 1 + x;

    vector<ll> d(3 * x, INF);
    d[A] = 0;
    priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; });
    q.push(pll(A, 0));
    while (!q.empty()) {
        pll t = q.top();
        q.pop();
        if (d[t.first] < t.second)
            continue;
        REP(i, V[t.first].edge.size()) {
            pll y = V[t.first].edge[i];
            ll nxt = y.first;
            ll cost = y.second + t.second;
            if (d[nxt] <= cost)
                continue;
            d[nxt] = cost;
            q.push(pll(nxt, cost));
        }
    }
    cout << d[B] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
vector<int> solve(vector<int> P) {
    int N = P.size();
    for (auto &p : P) p--;
    vector<int> ans;
    int pos = 0;
    auto op = [&](int n) {
        assert(ans.size() % 2 == n % 2);
        ans.push_back(n);
        swap(P[n], P[n + 1]);
        if (pos == n) pos++;
        else if (pos == n + 1) pos--;
    };
    for (int t = N - 1; t >= 3; t--) {
        pos = find(begin(P), end(P), t) - begin(P);
        if (pos == t) {
            continue;
        }
        while (pos != t && pos % 2 != ans.size() % 2) {
            if (ans.size() % 2 == 0) {
                if (pos == 1) {
                    op(2);
                } else {
                    op(0);
                }
            } else {
                if (t >= 4 && pos == 2) {
                    op(3);
                } else {
                    op(1);
                }
            }
        }
        while (pos != t) {
            op(pos);
        }
    }
    while (!is_sorted(begin(P), end(P))) {
        op(ans.size() % 2);
    }
    for (auto &a : ans) a++;
    return ans;
}
int main() {
    int T; cin >> T;
    while (T--) {
        int N; cin >> N;
        vector<int> P(N); for (auto &p : P) cin >> p;
        auto ans = solve(P);
        cout << ans.size() << '\n';
        for (auto a : ans) cout << a << ' ';
        cout << '\n';
    }
    return 0;
}

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

const int N=4e5+5;

int s[N],t,n;

struct node {
	int x,id;
	inline bool operator < (const node &a) const {return x!=a.x?x<a.x:id<a.id;}
}a[N];

bool tp[N];

int main() {
	scanf("%d",&n);
	for(int i=1,x ; i<=2*n ; ++i) scanf("%d",&x),a[i].x=x,a[i].id=i;
	sort(a+1,a+2*n+1);
	for(int i=n+1 ; i<=2*n ; ++i) tp[a[i].id]=1;
	for(int i=1 ; i<=2*n ; ++i) {
		if(!t) printf("("),s[++t]=i;
		else if(tp[s[t]]!=tp[i]) printf(")"),--t;
		else printf("("),s[++t]=i;
	}
	return 0;
}


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

long long a[105][105], k, b[105];
int n, m;
string st;

int main()
{
    for (int i = 1; i <= 60; i++) {a[0][i] = 1; a[i][0] = 1;}
    for (int i = 1; i <= 60; i++)
        for (int j = 1; j <= i; j++)
        {
            a[i][j] = a[i - 1][j] + a[i - 1][j - 1];
           // cout << a[i][j] << endl;
        }
    cin >> n >> m;
    cin >> k;
    int i = m, cntm = m;
    long long cnt = k;

    while (cntm)
    {
        if (a[i][cntm] > cnt)
            {
                b[n + m - i + 1] = 1;
                cnt -= a[i - 1][cntm];
                i = cntm - 2;
                cntm--;
                //cout <<i << 'c';
            }
        else if (a[i][cntm] == cnt)
        {
            int x = n + m - i + 1;
           // cout << cntm << ' ' << cnt << ' ' << i;
            for (int j = x; j <= x + cntm - 1; j++)
                b[j] = 1;
            for (int j = 1; j <= n + m; j++)
                if (b[j]) cout <<'b'; else cout << 'a';
                cout << endl;
            return 0;
        }
        i++;
    }
    for (int j = 1; j <= n + m; j++)
        if (b[j]) cout <<'b'; else cout << 'a';
        cout << endl;
    return 0;
}

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

long long ncr(long long a,long long b)
{
    long long m=1;
    for(int i=a;i>b;i--)
    {
        m*=i;
        m/=a-i+1;
    }
    return m;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535;
    string s1, s2;
    char moji;

   cin >> a >> b >> c;
   d=a+b;
   c--;
   for(int i=0;i<d;i++)
   {
       if(ncr(a+b-1,max(a-1,b))<=c)
       {
           c-=ncr(a+b-1,max(a-1,b));
           cout << 'b';
           b--;
       }
       else
       {
           if(a)
           {
               cout << 'a';
             a--;
           }
           else
           {
              cout << 'b';
             b--;
           }
       }
   }
   cout << endl;
    return 0;
}


//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators
//do not forget to change the sizes of arrays and value of contants and other things after debugging

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)

#define SZ(x)  (ll)(x.size())

//comment the below if not required

/*

#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/

#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//cout<<"Case #"<<c<<": "<<ans<<"\n" ;

ld x,y,r;

ll xc,yc,rc,ans;

ll read() {
    ld x;
    cin>>x;
    return llround(x * 10000);
}

ll solve(ll X)
{
	ll l,r,m,L1=LLONG_MIN,val,R1=LLONG_MIN;

	l = yc , r = yc+rc ;

	while(l<=r)
	{
		m = (l+r)/2;

		val = (m-yc)*(m-yc)+(X-xc)*(X-xc);

		if(val<=(rc*rc))
		{
			R1 = m;
			l = m+1;
		}
		else
			r = m-1;
	}

	r = yc , l = yc-rc;

	while(l<=r)
	{
		m = (l+r)/2;

		val = (m-yc)*(m-yc)+(X-xc)*(X-xc);

		if(val<=(rc*rc))
		{
			L1 = m;
			r = m-1;
		}
		else
			l = m+1;
	}

	if(L1<=R1 && L1!=LLONG_MIN && R1!=LLONG_MIN)
		return (floor(((ld)R1)/1e4)-ceil(((ld)L1)/1e4)+1);
	else
		return 0;
}

int main()
{
	IOS;

	xc = read();
	yc = read();
	rc = read();

	ll i;

	i = floor(((xc+rc)/1e4))*1e4;

	for(;i>=(xc-rc);i-=1e4)
	{
		ans+=solve(i);
	}

	cout<<ans;

	return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define lld long double

using namespace std;

clock_t time_p=clock();
void Time() {
	time_p=clock()-time_p;
	cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int INF = 1e9 + 7;
lld pi=3.1415926535897932;
const long long INF64 = 9e18;
const long long mod = 998244353;

void solve() {
	ld x, y, r;
	cin >> x >> y >> r;
	r = nextafter(r, INFINITY);
	ll ans = 0;
	for(ll i = floor(x - r); i <= ceil(x + r); ++i) {
		ld left = r * r - (x - i) * (x - i);
		if(left >= 0) {
			ld range = sqrt(left);
			ld low = y - range, high = y + range;
			low = ceil(low); high = floor(high);
			ans += (high - low + 1);
			}
		}
		cout << ans << endl;
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(35);
	int t;
	solve();
	Time();
	return 0;
}


//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define IO (ios::sync_with_stdio(false), cin.tie(0), cout.tie(0))
#define inf 0x3f3f3f3f
#define ll long long
#define pii pair<int, int>
#define vs vector<int>
#define pk push_back
#define vss vector<vector<int> >
#define sz(x) (int)(x).size()
#define mk(a, b) make_pair(a, b)
#define rep(a, b, c) for(register int a = b; a <= c; ++ a)
#define per(a, b, c) for(register int a = b; a >= c; -- a)
using namespace std;

template<class T>
inline void read(T &x)
{
	x = 0; T f = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	x *= f;
}

template<class T>
inline void print(T x){
    if(x < 0) x = ~x + 1, putchar('-');
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

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

	n = n * 1.08;
	if(n < 206) puts("Yay!");
	else if(n == 206) puts("so-so");
	else puts(":(");

	return 0;
}

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

int main()
{
    string s;
    cin >> s;

    bool flag = true;
    for (int i = 0; 2*i <= s.length(); i++)
    {
        if (s[2*i] >= 65 && s[2*i] <= 90)
        {
            flag = false;
        }
    }

    for (int i = 0; 2*i+1 <= s.length(); i++)
    {
        if (s[2*i+1] >= 97 && s[2*i+1] <= 122)
        {
            flag = false;
        }
    }
    if (flag)
    {
        cout <<"Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


/* Be patient, things will be at their rightful place.
Everything happens for a reason.
It was meant to happen this way, accept it.
And now decide what you can do about it.
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second

#define fo(i,k,n) for(ll i=k;i<n;i++)
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

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

ll mex(ll x, ll y)
{
	ll res = 1;
	x = x % M;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
		res = (res*x) % M;
		y = y>>1;
		x = (x*x) % M;
	}
	return res;
}

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("Yes\n");
}

void no()
{
    printf("No\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);

	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}

ll n,m;
bool vis[hu]={0};
vii v;
  vii vec[hu];
void dfs(ll i)
{
    v.pb(i);
    vis[i] = 1;
    for(auto it:vec[i])
    {
    if(!vis[it]) dfs(it);

    }

}

void solve()
{

   sc(n);
   sc(m);
   ll a[n],b[n];
   ll s1=0,s2=0;
   fo(i,0,n)
   {
       sc(a[i]);

   }

   fo(i,0,n)
   {
       sc(b[i]);

   }

   fo(i,0,m)
   {
       ll x,y;
       sc(x);
       sc(y);
       vec[x].pb(y);
       vec[y].pb(x);
   }

   fo(i,1,n+1)
   {
       v.clear();
       if(!vis[i])
       {
           dfs(i);
       }
       ll s1 = 0;s2=0;
       for(auto it:v)
       {
           s1+=a[it-1];
           s2+=b[it-1];
       }
       if(s1!=s2)
       {
           no();
           return;
       }
   }

   yes();

}

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

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

const int maxH = 16;
const int maxW = 16;

int config[maxH][maxW];
int h,w,a,b;

long long find_ans(int r,int c,int rem)
{
	if(rem==0){
		return 1;
	}

	if(c == w)
		return 0;

	long long ans = 0;

	int i1=-1;

	for(int i=r;i<h;i++)
	{
		if(config[i][c] == 0)
		{
			i1 = i;
			break;
		}
	}

	if(i1 == -1)
		return find_ans(0,c+1,rem);

	if(i1+1<h && config[i1+1][c] == 0){
		ans += find_ans(i1+2,c,rem-1);
	}

	if(c != w-1)
	{
		config[i1][c+1] = 1;
		ans += find_ans(i1+1,c,rem-1);
		config[i1][c+1] = 0;
	}

	ans += find_ans(i1+1,c,rem);

	return ans;
}

int main()
{
	cin>>h>>w>>a>>b;

	cout<<find_ans(0,0,a)<<endl;

	return 0;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
//#include<bits/stdc++.h>
#include<tuple>
#include<queue>
#include<map>
#include<algorithm>
//#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// �e�[�u�������O����
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// �񍀌W���v�Z
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	ll n,p;
	cin>>n>>p;
	vector<ll> a(0);
	ll n1=n-1;
	while(n1>0){
		a.push_back(n1%2);
		n1/=2;
	}
	ll tmp=a.size();
	//rep(i,tmp)cout<<a[i]<<" ";
	//cout<<endl;
	ll ans=p-1;
	ll mod=1e9+7;
	ll x=p-2;
	rep(i,tmp){
		if(a[i]==1){
			ans*=x;
		}
		ans%=mod;
		x*=x;
		x%=mod;
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>

using ll = long long int;

ll mod_pow(ll n, ll r, ll mod) {
    ll ans = 1;
    ll pow = n;
    while (r > 0) {
        if (r & 1) {
            ans = (ans * pow) % mod;
        }
        pow = (pow * pow) % mod;
        r >>= 1;
    }
    return ans;
}

int main() {
    ll MOD = 1e9 + 7;
    ll N, P;
    std::cin >> N >> P;

    ll ans = (P - 1) * mod_pow(P - 2, N - 1, MOD) % MOD;
    std::cout << ans << std::endl;
}


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

//TEMPLATE
#define len(a)            (ll) a.size()
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)
#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)

#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cots(a)           cout << a << " "
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotcase(cs)       cout << "Case " << cs << ": "
#define yes               cout << "Yes\n"
#define no                cout << "No\n"
#define line              cout << "\n"

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)

#define ll                long long
#define pb                push_back
#define mp                make_pair
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second
#define pi                acos(-1.0)

#define bug(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << '\n'
void err(istringstream *iss) {}
template<typename T, typename... Args>
void err(istringstream *iss, const T a, const Args... args) {
    string _name;
    *iss >> _name;
    if (_name.back()==',') _name.pop_back();
    cerr << _name << " = " << fixed << setprecision(5) << a << "; ", err(iss, args...);
}

const ll INF = LLONG_MAX;
const ll SZ = 1e10;
const ll mod = 1e9+7;

string s, s1, s2;
ll n, k, ans = 0;

void add() {
    s += "110";
}

int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0;
//    ll a, b, d;
//    string s, s1, s2;

    cin2(n, s1);

    while(len(s) <= n) {
        add();
    }
    for1(i, 3) add();

    fora(i, 0, 2) {
        s2.clear();
        for(j = i, c = 1; c <= len(s1); j++, c++) {
            s2.pb(s[j]);
        }

        if(s1 == s2) {
            p = (j / 3) + (j%3 != 0);
            ans += (SZ - p + 1);
        }
    }

    cot1(ans);

    return 0;
}

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define all(v) (v).begin(),(v).end()
#define all_rev(v) (v).rbegin(),(v).rend()
#define debug(x) cout << #x << ": " << x << '\n';
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using PL = pair<ll, ll>;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  //cin.tie(0);ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
  string S;
  cin >> S;

  vector<string> A;
  for (int i = 8; to_string(i).size() < 4; i+=8) {
    if (to_string(i).size() == 3) A.push_back(to_string(i));
  }

  map<int, int> mp;

  if (S.size() > 2) {
    for (auto v : S) mp[v - '0']++;
    for (auto a : A) {
      bool ok = true;
      map<int, int> mp2 = mp;
      for (auto ch : a) {
	if (mp2[ch - '0'] > 0) mp2[ch - '0']--;
	else ok = false;
      }

      if (ok) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  } else {
    string S_rev = S;
    reverse(all(S_rev));

    if (stoll(S) % 8 == 0 || stoll(S_rev) % 8 == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }

  cout << "No" << endl;
  return 0;
}


#include <bits/stdc++.h>

#ifndef aly_local
#include <ext/rope>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<typename T>
#define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>
void __funxc();
#endif
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef aly_local
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

struct __time{
#ifdef aly_local
chrono::time_point<chrono::high_resolution_clock> start,end;
__time(){
start = chrono::high_resolution_clock::now();
}
~__time(){
end = chrono::high_resolution_clock::now();
chrono::duration<double,milli> duration = end-start;
cerr << "clock: " << duration.count() << " ms." << endl;
}
#endif
};

#define logit cerr << "i'm here" << endl;
#define invec(x) for(auto & __a : x) cin >> __a
#define outvec(x) for(auto & __a : x){cout << __a << " ";} cout << "\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define allp(x) x->begin(),x->end()
#define si(x) (int)x.size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define ll int64_t
#define ld long double

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> triplet;

#ifndef aly_local
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-funroll-loops")
#endif

template<typename T,typename Y>
inline void mint(T & x,Y y){
x = min<T>(x,y);}
template<typename T,typename Y>
inline void maxt(T & x,Y y){
x = max<T>(x,y);}
inline void local_input(){
#ifdef aly_local
freopen("in.txt","r",stdin);
#endif
}
constexpr int mod = (int) 998244353;
constexpr int maxn = (int) 10000;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

auto solve() -> decltype(auto) {
	int a,b;
	cin >> a >> b;

	for(int value = b;;value--){
		int range_multiples = (b/value) - ((a-1)/value);
		if(range_multiples >= 2){
			return void(cout << value << "\n");
		}
	}
	assert(false);
}

int32_t main(void){
	__time __x;
	fastio;local_input();
	uint32_t tcs = 1;
	// cin >> tcs;
	for(uint32_t i = 1;i <= tcs;i++) solve();
}

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define ROF(i, a, b) for (ll i = (b)-1; i >= (a); --i)
#define rep(a) for (ll i = 0; i < a; ++i)

#define fio                       \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0);
#define iio \
ios_base::sync_with_stdio(0);

#define tc     \
ll tc;     \
cin >> tc; \
rep(tc)
#define vi vector<int>
#define vl vector<ll>
#define nl "\n"
#define gp " "
#define pb push_back
#define pob pop_back
#define vin(a, n)     \
vector<int> a(n); \
rep(n) cin >> a[i];
#define vln(a, n)     \
vector<ll> a(n); \
rep(n) cin >> a[i];
#define min3(a, b, c) min(min(a, b), c);
#define min4(a, b, c, d) min(min(a, b), min(c, d));
#define max3(a, b, c) max(max(a, b), c);
#define max4(a, b, c, d) max(max(a, b), max(c, d));
#define ff first
#define ss second
#define mod1 = 1000000007;
#define i1(a) ll a;cin>>a;
#define i2(a,b) ll a,b;cin>>a>>b;
#define i3(a,b,c) ll a,b;cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b;cin>>a>>b>>c>>d;
#define i5(a,b,c,d,e) ll a,b;cin>>a>>b>>c>>d>>e;

void solve()
{
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
    fio;
    i2(n,q);
    vln(a,n);
    vln(quer,q);
    sort(a.begin(), a.end());
    vector<ll> b(n);
    b[0]=a[0]-1;
    FOR(i,1,n){
        b[i]=a[i]-i-1;
    }
    rep(q){
        if (quer[i]>b[n-1]){
            cout<<quer[i]+n<<nl;
        }else{
            ll j=lower_bound(b.begin(),b.end(),quer[i])-b.begin();
            cout<<a[j]-(b[j]-quer[i])-1<<nl;
        }
    }
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const ll N=18;
ll g[20][20];
ll dp[1<<N],dp1[1<<N],power[N];
vector<ll> arr[20];

ll fun1(vector<ll> &nodes){
      if(nodes.size()==0) return(0);
      ll flag=1;
      for(auto u:nodes){
            for(auto v:nodes){
                  if(u+1==v+1) continue;
                  if(g[u+1][v+1]==0){
                        flag=0;
                        break;
                  }
            }
            if(flag==0) break;
      }
      //for(auto x:nodes) cout<<x+1<<" ";
      //cout<<flag;
      //cout<<endl;
      return(flag);
}

void fun2(ll num,ll n){
      vector<ll> nodes;
      forn(i,n){
            if((num&(1<<i))!=0) nodes.pb(i);
      }
      dp1[num]=fun1(nodes);
}

void fun(ll n,ll num){

      for(ll i=num;i>0;i=((i-1)&num)){
            ll num2=i;
            ll num1=num2^num;
            if(dp1[num2]==0) continue;
            else dp[num]=min(dp1[num2]+dp[num1],dp[num]);
      }

}

int main(){
      sync
      ll n,m;
      cin>>n>>m;

      power[0]=1;
      for1(i,n) power[i]=2*power[i-1];

      forn(i,m){
            ll u,v;
            cin>>u>>v;
            g[u][v]=1;
            g[v][u]=1;
      }

      forn(i,1<<n){
            ll c=0,num=0,p=1;
            forn(j,n){
                  if((i&(1<<j))!=0){
                        num=num+p;
                        c++;
                  }
                  p*=2;
            }
            dp[num]=c;
            arr[c].pb(num);
            fun2(i,n);
      }

      dp[0]=0;

      forn(i,n+1){
            for(auto x:arr[i]){
                  fun(n,x);
            }
      }
      //forn(i,1<<n) cout<<dp[i]<<" ";
      cout<<dp[(1<<n)-1];
}

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <queue>

#define	INF   1010101010
#define INFLL 1010101010101010101

using namespace std;

int mod = 1000000007;

int main()
{
	int n;
	long long t;
	cin >> n >> t;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector<long long> b;
	int n2 = n / 2;
	int n3 = n - n2;
	for (int i = 0; i < (1 << n2); i++) {
		long long sum = 0;
		for (int j = 0; j < n2; j++) {
			if (((i >> j) & 1) == 1) {
				sum += a[j];
			}
		}
		if (sum <= t) {
			b.emplace_back(sum);
		}
	}
	sort(b.begin(), b.end());
	long long ans = 0;
	for (int i = 0; i < (1 << n3); i++) {
		long long sum = 0;
		for (int j = n / 2; j < n; j++) {
			if (((i >> (j - n / 2)) & 1) == 1) {
				sum += a[j];
			}
		}
		if (sum > t) continue;
		int u = upper_bound(b.begin(), b.end(), t - sum) - b.begin();
		u--;
		ans = max(ans, b[u] + sum);
	}
	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>
using  namespace std;
typedef  long long ll;
ll n;
int  k;
string  s;
int main(){

	cin>>s>>k;
	for(int i=0;i<k;i++){
	ll  a,b,ant;
		ant=1;
		a=0;
		b=0;
		string  st;
		sort(s.begin(),s.end());
		st=s;
		reverse(st.begin(),st.end());
		for(int i=s.size()-1;i>=0;i--){
			a+=(s[i]-'0')*ant;
			ant*=10;
		}
		ant=1;
		for(int i=st.size()-1;i>=0;i--){
			b+=(st[i]-'0')*ant;
			ant*=10;
		}
		b-=a;
		if(b==0){
			cout<<0;

			return 0;
		}
		stringstream ss;
   		ss<<b;
		ss>>s;
	}
	cout<<s;

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, k;

ll g1(ll x){
  if(x == 0) return 0;
  string S = to_string(x);
  vector<int> V;
  for(char s : S){
    int i = s-'0';
    V.push_back(i);
  }
  sort(V.begin(), V.end(), greater<int>());
  string R = "";
  for(int v : V) R += to_string(v);
  ll res = stoi(R);
  return res;
}

ll g2(ll x){
  if(x == 0) return 0;
  string S = to_string(x);
  vector<int> V;
  for(char s : S){
    int i = s-'0';
    if(i > 0) V.push_back(i);
  }
  sort(V.begin(), V.end());
  string R = "";
  for(int v : V) R += to_string(v);
  ll res = stoi(R);
  return res;
}

ll solve(int i, ll x){
  if(i == k) return x;
  ll calc = g1(x) - g2(x);
  return solve(i+1, calc);
}
int main(){
  cin >> n >> k;
  cout << solve(0, n) << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,i1,n) for(int i=(int)(i1);i<(int)(n);i++)
#define ll long long
#define vi vector<int>
#define vll vector<long long>
using graph = vector<vector<int>>;

int main() {
  string s;
  cin>>s;
  int count=0;

  rep(i,0,9){
    if(s.at(i)=='Z'&&s.at(i+1)=='O'&&s.at(i+2)=='N'&&s.at(i+3)=='e'){
      count++;
    }
  }
  cout<<count;
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n; cin >> n;
    int m = 5;
    vvi a(n, vi(m)); rep(i, n) rep(j, m) cin >> a[i][j];
    vi MX(m, 0);
    rep(i, n) rep(j, m) chmax(MX[j], a[i][j]);
    int ans = 0;
    rep(i, n) {
        rep(j, i) {
            vi mx(m); // i,jさんの最大値
            rep(k, 5) mx[k] = max(a[i][k], a[j][k]);
            int mn = 2e9, im = -1;
            rep(k, 5) if (chmin(mn, mx[k])) im = k;
            mx[im] = MX[im];
            int res = 2e9;
            rep(k, 5) chmin(res, mx[k]);
            chmax(ans, res);
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define int long long
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; }

#define M 1502

int a[M][M];
int b[M][M] = {};

signed main(){
	int h, w;
	cin >> h >> w;
	int n, m;
	cin >> n >> m;

	for(int i = 0;i < n;i++){
		int y, x;
		cin >> y >> x;
		y--; x--;
		a[y][x] = 1;
	}

	for(int i = 0;i < m;i++){
		int y, x;
		cin >> y >> x;
		y--; x--;
		a[y][x] = -1;
	}

	for(int i = 0;i < h;i++){
		int now = 0;
		for(int j = 0;j < w;j++){
			if(a[i][j] == 1){
				now = 1;
			}else if(a[i][j] == -1){
				now = 0;
			}
			b[i][j] += now;
		}
	}

	for(int i = 0;i < h;i++){
		int now = 0;
		for(int j = w-1;j >= 0;j--){
			if(a[i][j] == 1){
				now = 1;
			}else if(a[i][j] == -1){
				now = 0;
			}
			b[i][j] += now;
		}
	}

	for(int j = 0;j < w;j++){
		int now = 0;
		for(int i = 0;i < h;i++){
			if(a[i][j] == 1){
				now = 1;
			}else if(a[i][j] == -1){
				now = 0;
			}
			b[i][j] += now;
		}
	}

	for(int j = 0;j < w;j++){
		int now = 0;
		for(int i = h-1;i >= 0;i--){
			if(a[i][j] == 1){
				now = 1;
			}else if(a[i][j] == -1){
				now = 0;
			}
			b[i][j] += now;
		}
	}

	int ans = 0;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			ans += min(b[i][j], 1ll);
		}
	}

	cout << ans << endl;

	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int h, w, n, m, a[500010], b[500010], c[100010], d[100010];
bool bl[1510][1510][4];
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> h >> w >> n >> m;
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];
	for (int i = 0; i < m; i++)cin >> c[i] >> d[i];
	for (int i = 0; i < m; i++)for (int j = 0; j < 4; j++)bl[c[i]][d[i]][j] = true;
	queue<pair<pair<int, int>, int>> que;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 4; j++)que.push(make_pair(make_pair(a[i], b[i]), j)), bl[a[i]][b[i]][j] = true;
	}
	while (!que.empty()) {
		int x = que.front().first.first, y = que.front().first.second, k = que.front().second; que.pop();
		int tx = x + dx[k], ty = y + dy[k];
		if (tx < 1 || h < tx || ty < 1 || w < ty || bl[tx][ty][k])continue;
		bl[tx][ty][k] = true;
		que.push(make_pair(make_pair(tx, ty), k));
	}
	int ans = 0;
	for (int i = 1; i <= h; i++)for (int j = 1; j <= w; j++)if (bl[i][j][0] || bl[i][j][1] || bl[i][j][2] || bl[i][j][3])ans++;
	cout << ans - m << endl;
}


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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <std::ostream& os = std::cout>
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) { print(args...); }
        template <typename T>
        auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
            for (size_t i = 0; i < sz; i++)
                os << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        auto pmat(const T& mat, size_t h, size_t w) -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    os << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { os << term; }
        void print_rest() const { os << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints<> prints;
Prints<std::cerr> prints_err;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

using Graph = std::vector<std::vector<int>>;

void solve() {
    int N;
    cin >> N;
    Graph g(N);
    vector<Pii> edges(N - 1);
    for (ll i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        edges[i] = {a, b};
    }

    Vi ls(N), rs(N);
    {
        int idx = 0;
        auto dfs = [&](auto&& self, int u, int p) -> void {
            ls[u] = idx++;
            for (auto v : g[u]) {
                if (v != p) self(self, v, u);
            }
            rs[u] = idx;
        };
        dfs(dfs, 0, -1);
    }

    Vl imos(N + 1);

    int Q;
    cin >> Q;
    while (Q--) {
        ll t, e, x;
        cin >> t >> e >> x;
        --e;
        auto [a, b] = edges[e];
        if (t == 2) swap(a, b);
        if (ls[a] < ls[b]) {
            imos[0] += x;
            imos[N] -= x;
            imos[ls[b]] -= x;
            imos[rs[b]] += x;
        }
        else {
            imos[ls[a]] += x;
            imos[rs[a]] -= x;
        }
    }
    for (ll i = 0; i < N; i++) {
        imos[i + 1] += imos[i];
    }

    for (ll i = 0; i < N; i++) {
        prints()(imos[ls[i]]);
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

vector<pll> val;
vector<vector<ll>> memo(2, vector<ll>(200005, -INF));
ll rec(ll isright, ll i) {
    if (i == val.size()) {
        return (isright ? abs(val[i - 1].second) : abs(val[i - 1].first));
    }
    if (memo[isright][i] != -INF) return memo[isright][i];

    ll cur = 0;
    if (i > 0) {
        cur = (isright ? val[i - 1].second : val[i - 1].first);
    }

    return memo[isright][i] = min(
      abs(cur - val[i].second) + abs(val[i].second - val[i].first) + rec(0, i + 1),
      abs(cur - val[i].first) + abs(val[i].first - val[i].second) + rec(1, i + 1));
}
int main() {
    ll n;
    cin >> n;
    vector<vector<ll>> bkt(n + 1);
    for (ll i = 0; i < n; i++) {
        ll x, c;
        cin >> x >> c;
        bkt[c].push_back(x);
    }

    for(ll i = 0; i <= n; i++) {
      if(bkt[i].size()==0)continue;
      ll mx=-INF;
      ll mn=INF;
      for(auto e: bkt[i]){
        mx=max(mx,e);
        mn=min(mn,e);
      }
      val.push_back({mn,mx});
    }
    print(rec(0, 0));
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 70 * 70 ;
int dp[N][N];
const string s = "atcoder";
int main()
{
    cout.precision(15);
    ll n;
    ll ans1 = 0, ans2 = 0, ans3 = 0, x;
    cin >> n;
    for(int i=0;i<n;i++)cin >> x, ans1+=abs(x),ans2+=abs(x)*abs(x), ans3 = max(ans3, abs(x));
    cout << fixed << ans1 << ' ' << sqrt(1.0*ans2)<< ' ' << ans3 << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

    ll n; cin >> n;
    ll x[n]; zep(i, 0, n)cin >> x[i];

    ll a = 0;
    zep(i, 0, n)a += abs(x[i]);
    print(a)
    ll b = 0;
    zep(i, 0, n)b += x[i] * x[i];
    cout << fixed << setprecision(20) << sqrt(b) << endl;
    ll c = 0;
    zep(i, 0, n)c = max(c, abs(x[i]));
    print(c)

    return 0;
}


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

using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

// bitwise ops
// also see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { // assert(x >= 0); // make C++11 compatible until USACO updates ...
	return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }

ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }

tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(it); } // element that doesn't exist from (multi)set

void solve()
{
    int a,b; cin>>a>>b;
    int sum_a=0, sum_b=0;
    while(a)
    {
        sum_a  += a%10;
        a /= 10;
    }
    while(b)
    {
        sum_b  += b%10;
        b /= 10;
    }
    cout<<max(sum_a,sum_b);
}
int main()
{
    cin.tie(0)->sync_with_stdio(0);

    int ct=1;
    // cin>>ct;
    while(ct--)
    {
        solve();
    }

}

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

const long long INF = 1e18;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923;

#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define beg begin()
#define ll long long
#define vll vector <ll>
#define pb push_back
#define mkp make_pair
#define vb vector <bool>

void solve_it(){
    double n; cin>>n;
    double x0, y0, x, y;
    cin>>x0>>y0>>x>>y;
    x = (x + x0) / 2;
    y = (y + y0) / 2;
    x0 -= x;
    y0 -= y;
    double theta = (360 / n) * (pi / 180);
    cout<<x0 * cos(theta) - y0 * sin(theta) + x<<" ";
    cout<<x0 * sin(theta) + y0 * cos(theta) + y;
}

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


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

#define INF 1234567890
#define ll long long

int N;
string s;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	cin >> N >> s;
	if (s[0] != s.back()) { cout << "1\n"; return 0; }
	for(int i=1; i<N; i++)
		if (s[i-1] != s[0] && s[i] != s[0])
		{
			cout << "2\n";
			return 0;
		}
	cout << "-1\n";
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
template<typename T> ostream& operator<<(ostream& os,const vector<T>& v1){
    int n=v1.size();
    for(int i=0;i<n;i++){
        if(i)os<<" ";
        os<<v1[i];
    }
    return os;
}
template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    os<<p.first<<" "<<p.second;
    return os;
}
template<typename T> istream& operator>>(istream& is,vector<T>& v1){
    int n=v1.size();
    for(int i=0;i<n;i++)is>>v1[i];
    return is;
}
template<typename T1,typename T2> istream& operator>>(istream& is,pair<T1,T2>& p){
    is>>p.first>>p.second;
    return is;
}

namespace sol{
    void solve(){
        const int N=26;
        int n,m;
        int i,j,k;
        int a,b,c;
        string sa;
        cin>>n;
        cin>>sa;
        vector<int> dp(N,INF);
        for(i=0;i<N;i++){
            if(sa[0]-'a'==i)continue;
            dp[i]=0;
        }
        for(i=0;i<n;i++){
            a=sa[i]-'a';
            b=dp[a]+1;
            if(i==n-1)break;
            c=sa[i+1]-'a';
            for(j=0;j<N;j++){
                if(j==c)continue;
                dp[j]=min(dp[j],b);
            }
        }
        if(b>=INF)b=-1;
        cout<<b<<endl;
    }
}

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


#include<iostream>
#include<set>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
};

// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

struct node{
  int v;
  li w;
  node(int vv=0,li ww=1){v=vv; w=ww;}
};

struct graph{
  int n;
  int m;
  int weighted,origin,directed;
  li ma;

  vector<vector<node>> adj;
  vector<li> col,w;
  graph(int nn,int mm,int d_flag=0,int w_flag=0,int ori=1){
    ma=0;
    n=nn; m=mm;
    weighted=w_flag;
    directed=d_flag;
    origin=ori;
    if(df){
      print(origin,"-origin");
      if(weighted) print("weighted");
      if(directed) print("directed");
    }
    adj.resize(n);
    rep(i,m){
      int a,b; li w=1; cin >>a >>b; a-=origin; b-=origin;
      if(weighted) cin >>w;
      adj[a].push_back({b,w});
      if(not directed)
        adj[b].push_back({a,w});
      ma=max(ma,w);
    }
  }
  void add(int a,int b,li w=1){
      adj[a].push_back({b,w});
      if(not directed)
        adj[b].push_back({a,w});
      ma=max(ma,w);
  }
  li dijkstra(int a,int b);
  li dijkstra(int b=-1){
    if(b==-1) b=n-1;
    return dijkstra(0,b);
  };

};

std::ostream& operator<<(std::ostream& os,const node& n){
  printf("%d[%ld]",n.v,n.w);
  return os;
};
std::ostream& operator<<(std::ostream& os,const graph& g){
  if(g.weighted){
    rep(i,g.n){
      printf("%d :",i+g.origin);
      for(auto p:g.adj[i]){
        printf(" %d[%d]",p.v+g.origin,p.w);
      }
      print("");
    }
  }else{
    rep(i,g.n){
      printf("%d :",i+g.origin);
      for(auto p:g.adj[i]){
        printf(" %d",p.v+g.origin);
      }
      print("");
    }
  }
  return os;
};

li graph::dijkstra(int a,int b){
  set<pair<li,int>> que;
  que.insert({a,0});
  vector<li> seen(n,ma*n+1);
  while(!que.empty()){
    auto p=*que.begin(); que.erase(que.begin());
    li d=p.first,v=p.second;
    if(df)print(v);
    if(v==b) return d;
    for(auto x:adj[v]){
      int u=x.v; li d0=x.w;
      if(d+d0<seen[u]){
        que.erase({seen[u],u});
        seen[u]=d+d0;
        que.insert({seen[u],u});
      }
    }
    if(df)print("que",que);
  }
  return ma*n+1;
}

int main(){
  int r,c; cin >>r >>c;
  graph g(r*c*2,0,1,1,0);
  rep(i,r)rep(j,c-1){
    li a; cin >>a;
    g.add(i*c+j,i*c+j+1,a);
    g.add(i*c+j+1,i*c+j,a);
  }
  rep(i,r-1)rep(j,c){
    li b; cin >>b;
    g.add(i*c+j,(i+1)*c+j,b);
  }
  rep(i,r)rep(j,c){
    g.add(i*c+j,r*c+i*c+j,1);
    g.add(r*c+i*c+j,i*c+j,0);
  }
  rep(i,r-1) rep(j,c){
    g.add(r*c+(i+1)*c+j,r*c+i*c+j,1);
  }
  if(df)print(g);
  print(g.dijkstra(r*c-1));

}

#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;

int n, m;
int a[510][510];
int b[510][510];
long long dist[510][510];
priority_queue<pair<long long, pair<int, int>>, vector<pair<long long, pair<int, int>>>, greater<pair<long long, pair<int, int>>>> pq;

bool in_range(int x, int y)
{
	return x >= 1 && x <= n && y >= 1 && y <= m;
}

int main()
{
	int i, j;
	int x, y;
	long long d;
	int nx, ny;
	long long nd;

	cin >> n >> m;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	for (i = 1; i < n; i++)
	{
		for (j = 1; j <= m; j++)
		{
			cin >> b[i][j];
		}
	}

	memset(dist, 110, sizeof(dist));

	dist[1][1] = 0;
	pq.push(make_pair(0, make_pair(1, 1)));
	while (!pq.empty())
	{
		x = pq.top().second.first;
		y = pq.top().second.second;
		d = pq.top().first;
		pq.pop();

		if (dist[x][y] != d) continue;

		nx = x + 1;
		ny = y;
		if (in_range(nx, ny))
		{
			nd = d + b[x][y];
			if (dist[nx][ny] > nd)
			{
				dist[nx][ny] = nd;
				pq.push(make_pair(nd, make_pair(nx, ny)));
			}
		}

		nx = x;
		ny = y - 1;
		if (in_range(nx, ny))
		{
			nd = d + a[x][y - 1];
			if (dist[nx][ny] > nd)
			{
				dist[nx][ny] = nd;
				pq.push(make_pair(nd, make_pair(nx, ny)));
			}
		}

		nx = x;
		ny = y + 1;
		if (in_range(nx, ny))
		{
			nd = d + a[x][y];
			if (dist[nx][ny] > nd)
			{
				dist[nx][ny] = nd;
				pq.push(make_pair(nd, make_pair(nx, ny)));
			}
		}

		for (i = 1; i < x; i++)
		{
			nx = i;
			ny = y;
			nd = d + x - i + 1;
			if (dist[nx][ny] > nd)
			{
				dist[nx][ny] = nd;
				pq.push(make_pair(nd, make_pair(nx, ny)));
			}
		}
	}

	cout << dist[n][m];
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int x=0,flag=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			flag=0;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
    return (flag?x:~(x-1));
}
int n,x,v,p;
signed main()
{
	n=read();
	x=read()*100;
	for(int i=1;i<=n;i++)
	{
		v=read();
		p=read();
		x-=v*p;
		if(x<0)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
	return 0;
}

#include <iostream>

using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  int vsum = 0;
  x *= 100;
  for (int i = 0; i < n; ++i) {
    int v, p;
    cin >> v >> p;
    vsum += v * p;
    if (x < vsum) {
      cout << i + 1 << endl;
      break;
    }
  }

  if (vsum <= x)
    cout << -1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> fac;
ll p=1e9+7;
ll power(ll a, ll x) {
	ll ans=1;
	while(x) {
		if(x&1) {
			ans=(ans*a)%p;
		}
		x=x>>1;
		a=(a*a)%p;
	}
	return ans;
}
void pre(int n) {
	ll x=1;
	fac.push_back(x);
	for(ll i=1; i<=n; i++) {
		x=(x*i)%p;
		fac.push_back(x);
	}
	return;
}

bool win(vector<int> &a, vector<int> &b) {
    ll asum=0, bsum=0;
    for(ll i=1; i<10; i++) {
        asum+=i*power(10, a[i]);
        bsum+=i*power(10, b[i]);
    }
    return asum>bsum;
}

ll count(int &me, int &you, vector<int> original) {
    ll ans;
    ans=original[me];
    original[me]--;
    ans=ans*original[you];
    return ans;
}

void solve() {
    ll k;
    string s, t;
    cin>>k>>s>>t;
    vector<int> a(10), b(10), original(10);
    for(int i=0; i<4; i++) {
        a[s[i]-'0']++;
        b[t[i]-'0']++;
    }
    for(int i=1; i<10; i++) {
        original[i]=k-a[i]-b[i];
    }
    ll good=0, total=(9*k-8)*(9*k-9);
    for(int me=1; me<10; me++) {
        for(int you=1; you<10; you++) {
            a[me]++;
            b[you]++;
            if(a[me]+b[me]<=k && a[you]+b[you]<=k && win(a, b)) {
                good+=count(me, you, original);
            }
            a[me]--;
            b[you]--;
        }
    }
    double ans=(double)good/(double)total;
    cout<<ans<<endl;
    return;
}

int main() {
#ifdef bipinpathak
    (void)!freopen("input.txt", "r", stdin);
    (void)!freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}

#include<iostream>
#include<cmath>
long long func(double a,double b){
	long long hb,lb;
	if (b>=0||b<0&&((long long)b)-b==0) hb=(long long) b;else hb=(long long) b-1;
	if (a<=0||a>0&&((long long)a)-a==0) lb=(long long) a;else lb=(long long) a+1;
	return hb-lb+1;
}
using namespace std;
int main(){
	long double x,y,r;
	cin>>x>>y>>r;
	r+=1e-14;
	long long ans=0;
    long long lb=ceil(x-r);
    long long rb=floor(x+r);
    for (long long i=lb;i<=rb;i++){
    	long double hbb=y+sqrt(r*r-(x-i)*(x-i));
    	long double lbb=y-sqrt(r*r-(x-i)*(x-i));

    	ans=ans+floor(hbb)-ceil(lbb)+1;
    //	cout<<lbb<<' '<<hbb<<' '<<ans<<endl;
	}
	cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

# define deb_v(x) cerr << #x << " = ("; \
    for (auto item: x) cerr << a[i] << " "; \
    cerr << ")\n";

# define deb(x) cerr << #x << " = " << x << "\n";

void solve(int t) {

}

int main() {
    int x;
    scanf("%d", &x);
    if (x >= 0) {
        printf("%d\n", x);
    } else {
        printf("0\n");
    }
}

#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#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 REP(i, begin, end) for(int i = int(begin); i < int(end); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<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 int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x>=0) cout << x << endl;
    else cout << 0 << endl;

}


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

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

char cn[1200010];
char* ci = cn, * di = cn;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

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

	fread(cn, 1, 1200010, stdin);
	int T = getint();

	rep(t, T) {
		int N = getint();

		rep(i, N)* di++ = '0';
		rep(i, N)* di++ = '1';
		*di++ = '0';
		*di++ = '\n';
		ci += 6 * N + 3;
	}
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}

//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define up upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,m,a,b;
string grid[105];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n>>m>>a>>b;
	rep(x,0,n) cin>>grid[x];

	a--,b--;

	int ans=-3;
	int c;

	c=b;
	while (c<m) if (grid[a][c]=='.') ans++,c++; else break;
	c=b;
	while (0<=c) if (grid[a][c]=='.') ans++,c--; else break;

	c=a;
	while (c<n) if (grid[c][b]=='.') ans++,c++; else break;
	c=a;
	while (0<=c) if (grid[c][b]=='.') ans++,c--; else break;

	cout<<ans<<endl;
}


#include <algorithm>
// #include <atcoder/all>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <vector>
/*
cd $dir && g++ -std=c++17 -Wall -Wextra -O2 -DATCODERDEBUG
-I/mnt/d/MyProjects/atcoder/lib/ac-library $fileName && echo 'compilation ok!'
&&  ./a.out
*/
using namespace std;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
#define dame(a)        \
  {                    \
    cout << a << endl; \
    return 0;          \
  }
typedef long long ll;

class dstream : public ostream {};

template <typename T>
dstream &operator<<(dstream &os, T v) {
#ifdef ATCODERDEBUG
  cout << "\033[1;31m" << v << "\033[0m";
#endif
  return os;
}

ostream &endd(std::ostream &out) {
#ifdef ATCODERDEBUG
  out << std::endl;
#endif
  return out;
}
dstream dout;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[ ";
  for (auto const &x : v) {
    os << x;
    if (&x != &v.back()) {
      os << " : ";
    }
  }
  os << " ]" << endl;
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  os << "[" << endl;
  for (auto const &x : v) {
    os << " ";
    os << x;
  }
  os << "]" << endl;
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
  os << "[ " << v.first << " " << v.second << " ]" << endl;
  return os;
}

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}

ll op(ll a, ll b) { return min(a, b); }

ll e() { return 1e17; }

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

  ll N, x, c;
  cin >> N;
  vector<vector<ll>> c2xs(N, vector<ll>());
  REP(i, N) {
    cin >> x;
    cin >> c;
    c2xs[c - 1].emplace_back(x);
  }

  REP(i, N) { sort(c2xs[i].begin(), c2xs[i].end()); }

  ll left = 0;
  ll right = 0;
  ll left_v = 0;
  ll right_v = 0;

  REP(c, N) {
    ll siz = c2xs[c].size();
    if (siz == 0) continue;

    ll minX = c2xs[c][0];
    ll maxX = c2xs[c][siz - 1];

    ll n_right_v = min(left_v + abs(left - minX), right_v + abs(right - minX)) +
                   (maxX - minX);
    ll n_left_v = min(right_v + abs(right - maxX), left_v + abs(left - maxX)) +
                  (maxX - minX);

    right_v = n_right_v;
    left_v = n_left_v;
    right = maxX;
    left = minX;

    dout << left << " " << left_v << " " << right << " " << right_v << endd;
  }

  ll ans = 1e17;
  chmin(ans, left_v + abs(left));
  chmin(ans, right_v + abs(right));

  cout << ans << endl;
  // cout << std::fixed << std::setprecision(15) << sqrt(ans) << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define per(i,n) for(int i=n-1; i>=0; i--)
#define pers(i,n,s) for(int i=n-1; i>=s; i--)
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define lb(v,n) lower_bound(all(v),n)
#define lbi(v,n) lower_bound(all(v),n) - v.begin()
#define ub(v,n) upper_bound(all(v),n)
#define ubi(v,n) upper_bound(all(v),n) - v.begin()

#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000

#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define IN(n,m,v) rep(i,n) rep(j,m){cin >> v[i][j];}
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

int compress(vi& x1, vi& x2){

    int n = si(x1);
    vi a;
    rep(i,n){
        a.pb(x1[i]);
        a.pb(x2[i]);
    }
    sort(all(a));
    a.erase(unique(all(a)),a.end());

    rep(i,n){
        x1[i] = lbi(a,x1[i]);
        x2[i] = lbi(a,x2[i]);
    }

    return si(a);
}

template <typename T>
class BIT {
    ve<T> node;
    int n;

    T find(int m){
        T s = 0;
        while (m > 0) {
            s += node[m];
            m -= (m & (-m));
        }
        return s;
    }

public:
    BIT(int _n) : n(_n){
        node.assign(n+1,0);
    }

    T sum(int a, int b){
        T s_a = find(a);
        T s_b = find(b+1);
        return s_b - s_a;
    }

    void update(int m, T x){
        m++;
        while (m <= n) {
            node[m] += x;
            m += (m & (-m));
        }
    }

};

void solve(){

    int N;
    cin >> N;
    vi A(N),B(N);
    in(N,A);
    in(N,B);
    ll sum = 0;
    rep(i,N) sum += A[i]-B[i];
    if(sum != 0){
        cout << -1 << endl;
        return;
    }

    rep(i,N) A[i] += i, B[i] += i;
    int m = compress(A,B);

    ve<set<int>> C(m+1);
    rep(i,N) C[A[i]].insert(i);

    BIT<ll> bi(N+10);

    ll ans = 0;
    rep(i,N){
        if(si(C[B[i]]) == 0){
            cout << -1 << endl;
            return;
        }

        int a = *C[B[i]].begin();
        C[B[i]].erase(a);
        //cout << a csp i csp bi.sum(0,a+1) << endl;
        ans += (ll)abs(a+bi.sum(0,a+1)-i);
        bi.update(0,1);
        bi.update(a+1,-1);
    }

    cout << ans << endl;

}

int main(){

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

    solve();

    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
#include <numeric>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int> >;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int> >; // クラスカル法とかで、{cost, {from,
                                      // to}}的に使う。
const ll LINF = 10010020030040056ll;
const int INF = 1001001001;
const double pi = acos(-1);

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

    ll MOD = 998244353;

    ll a,b,c;
    cin >> a >> b >> c;
    ll tmp1 = (a *(a+1)) / 2;
    ll tmp2 = (b * (b+1)) / 2;
    ll tmp3 = (c * (c+1)) / 2;
    tmp1 %=MOD;
    tmp2 %=MOD;
    tmp3 %=MOD;
    ll ans = ((tmp1 * tmp2) % MOD) * tmp3 % MOD;
    ans = (ans + MOD) % MOD;

    cout << ans << endl;

    return 0;
}

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

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    ll mod = 998244353;
    ll inv2 = (mod+1)/2;
    ll X = A*(A+1)%mod*inv2%mod;
    ll Y = B*(B+1)%mod*inv2%mod;
    ll Z = C*(C+1)%mod*inv2%mod;
    ll ans = X*Y%mod*Z%mod;
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 5005
#define lowbit(x) (x&-x)
#define reg register
#define mkpr make_pair
#define fir first
#define sec second
typedef long long LL;
typedef unsigned long long uLL;
const int INF=0x3f3f3f3f;
const int mo=998244353;
const LL jzm=2333;
const int iv2=499122177;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int n,m,fac[MAXN],inv[MAXN],f[MAXN],g[15][MAXN];
int add(int x,int y){return x+y<mo?x+y:x+y-mo;}
void init(){
	fac[0]=fac[1]=f[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=5000;i++){
		fac[i]=1ll*i*fac[i-1]%mo;
		f[i]=1ll*(mo-mo/i)*f[mo%i]%mo;
		inv[i]=1ll*f[i]*inv[i-1]%mo;
	}
}
int C(int x,int y){
	if(x<y||x<0||y<0)return 0;
	return 1ll*fac[x]*inv[y]%mo*inv[x-y]%mo;
}
signed main(){
	read(n);read(m);init();g[0][0]=1;
	for(int i=1;i<=13;i++){
		for(int j=0;j<=n&&1ll*j*(1<<i-1)<=m;j+=2)
			for(int k=m;k>=1ll*j*(1<<i-1);k--)
				g[i][k]=add(1ll*C(n,j)*g[i-1][k-1ll*j*(1<<i-1)]%mo,g[i][k]);
		//for(int j=0;j<=m;j++)printf("g%d %d:%d\n",i,j,g[i][j]);
	}
	printf("%d\n",g[13][m]);
	return 0;
}
/*

*/

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

const int maxn=210;

int n;
unsigned long long C[maxn][maxn];

int main() // C(n-1,11)
{
	cin>>n;n--;

	for(int i=0;i<=n;i++) C[i][0]=1;
	for(int i=1;i<=n;i++) for(int j=1;j<=12;j++) C[i][j]=C[i-1][j]+C[i-1][j-1];

	cout<<C[n][11];

	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807ll
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define N  100005

void solve()
{
    ll n,m;
    cin>>n>>m;
    if(m==0)
    {
        rep(i,1,n+1)
        {
            cout<<2*i<<" "<<2*i+1<<endl;
        }
        return;
    }
    if(m<0||m>n-2)
    {
        cout<<-1<<endl;
    }
    else
    {
        ll rem=n-m-1;
        ll l=1,r=1e9;
        rep(i,0,rem)
        {
            cout<<l<<" "<<r<<endl;
            l++;
            r--;
        }
        ll pre=rem+1;
        rep(i,0,m+1)
        {
            cout<<pre<<" "<<pre+1<<endl;
            pre+=2;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}

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

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

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

const int INF = (1<<30)-1;
const int MOD = 1e9+7;
const ll LINF = (1ll<<62)-1;

#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"
#define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n";

int main(){
    //input
   cin.tie(nullptr);
   ll n,a;cin >> n;
   unordered_map<int,ll>mp;
   REP(i,n){
       cin >> a;
       mp[a]++;
   }
   //map
   ll ans = n*(n-1)/2;
   for(auto &p:mp){
       ans -= (p.second-1)*p.second/2;
   }
   //output
   COUT(ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=18,M=205;
long long dp[(1<<N)+5];
int n,m,x[M],y[M],z[M];
vector<pair<int,int> >g[N+5];
int main(){
    cin>>n>>m;

    for(int i=1;i<=m;++i) cin>>x[i]>>y[i]>>z[i],g[x[i]].push_back(make_pair(y[i],z[i]));
    for(int i=0;i<=n;++i) sort(g[i].begin(),g[i].end());
    dp[0]=1;
    for(int S=0;S<(1<<n);++S){
        const int bitc=__builtin_popcount(S);
        for(int j=0;j<n;++j) if(!(S>>j&1)){
            vector<int> v;
            for(int k=0;k<n;++k) if((S|(1<<j))>>k&1) v.push_back(k+1);
            sort(v.begin(),v.end(),greater<int>());
            int cnt=0,f=1;
            for(auto e:g[bitc+1]){
                while(!v.empty()&&v.back()<=e.first) v.pop_back(),++cnt;
                f&=(cnt<=e.second);
            }
            if(f) dp[S|(1<<j)]+=dp[S];
        }
    }
    cout<<dp[(1<<n)-1]<<'\n';
    return 0;
}

#include <bits/stdc++.h>

const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>

typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
    x %= MOD;
    x += MOD;
    x %= MOD;
}

ll solve(ll x, vl &a) {
    ll ans = 0;
    return ans;
}

void Main() {
    CIN(N, T);
    vl A(N);
    VECCIN(A);
    vl B, C, D, E;
    for(ll i = 0; i < N; i++) {
        if(i%2) {
            B.push_back(A.at(i));
        } else {
            C.push_back(A.at(i));
        }
    }
    D.push_back(0);
    for(ll i = 0; i < N/2; i++) {
        for(ll j = 0; j < (ll)pow(2,i); j++) {
            D.push_back(D.at(j) + B.at(i));
        }
    }
    sort(D.begin(),D.end());
//    VECCOUT(D);
    E.push_back(0);
    for(ll i = 0; i < N - N/2; i++) {
        for(ll j = 0; j < (ll)pow(2,i); j++) {
            E.push_back(E.at(j) + C.at(i));
        }
    }
//    VECCOUT(E);
    ll ans = 0;
    for(ll i = 0; i < E.size(); i++) {
//        ans = max(ans, solve(E.at(i), D));
        if(E.at(i) > T) continue;
        ans = max(ans, *(upper_bound(D.begin(), D.end(), T - E.at(i)) - 1) + E.at(i));
//        cout << ans << endl;
    }
    cout << ans << endl;

}

int main() {
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll unsigned long long

int main() {
    //入力
    int n;
    cin >> n;

    //処理
    if (n % 2 == 0)
        cout << "White" << endl;
    else
        cout << "Black" << endl;

    //出力
//    cout << ans << endl;

    return 0;
}

#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    if (n%2 == 0) {
        cout << "White" << endl;
    } else {
        cout << "Black" << endl;
    }
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include <functional>
#include <iomanip>
#include<cmath>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int GetDigit(ll num) {

	int a = 0;
	while (num) {
		num /= 10;
		a++;
	}
	return a;
}

ll Get_keta_num(ll num) {
	ll z = 0;
	while (num) {
		z += num % 10;
		num /= 10;
	}
	return z;
}

void print(set<int> s) {
	for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
		cout << *it << " ";
	}
	cout << endl;
}

ll count_num_2(ll num) {
	ll data = 0;
	while (true) {
		ll m = num % 1000;
		ll k = num % 100;
		if ((m % 8) == 0) {
			data += 3;
			num /= 8;
			continue;
		}
		else if ((k % 4) == 0) {
			data += 2;
			num /= 4;
			continue;
		}
		else if ((k % 2) == 0) {
			data++;
			num /= 2;
			continue;
		}
		break;
	}
	return data;
}
ll facctorialMethod(int k) {
	ll sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
//" "

ll Get_num_in_string(string s) {
	int n = s.length(), z;
	ll sur = 0;
	for (int i = 0; i < n; i++) {
		z = int(s[i] - '0');
		if (z < 10) {
			sur *= 10;
			sur += z;
		}
	}
	return sur;
}

ll ll_pow(int num, int zyousuu) {
	ll ans = 1;
	for (int i = 0; i < zyousuu; i++) {
		ans *= num;
	}

	return ans;
}
string substrBack(std::string str, size_t pos, size_t len) {
	const size_t strLen = str.length();

	return str.substr(strLen - pos, len);
}

ll ll_gcd(ll x, ll y) {
	if (x < y) {
		ll a = x;
		x = y;
		y = a;
	}

	while (y > 0) {
		ll r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main() {
	ll a, b, c; cin >> a >> b >> c;
	ll a_num = (a + 1) * a / 2;
	a_num %= 998244353;
	ll c_num = (c + 1) * c / 2;
	ll b_num = (b + 1) * b / 2;
	c_num %= 998244353;
	b_num %= 998244353;

	a_num = (a_num * b_num) % 998244353;
	a_num= (a_num * c_num) % 998244353;
	cout << a_num << endl;

	return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.5f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll n;
    double D, H;
    cin >> n >> D >> H;

    double ans = 0.0;
    rep(i, n) {
        double d, h;
        cin >> d >> h;
        double k = (H - h) / (D - d);
        chmax(ans, h - k * d);
    }

    exout(ans);
    re0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define per1(i, n) for (int i = n; i >= 1; i--)
using namespace std;
typedef long long int ll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
/*--------------------------------------------------*/

/*--------------------------------------------------*/
ll f(ll n) {
    return n * (n + 1) / 2;
}

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

    int T;
    cin >> T;
    rep(i, T) {
        int L, R;
        cin >> L >> R;
        if (2 * L <= R) {
            cout << f(R - 2 * L + 1) << "\n";
        } else {
            cout << 0 << "\n";
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

lint fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }

    int main(){
        lint x,y,a,b;
        cin>>x>>y>>a>>b;
        --y;
        lint ans=0;
        lint c=x;
        while(c<b/a){
            c*=a;
            if(c>y)break;
            ans++;
        }
        lint add=max(0LL,(y-c)/b);
        ans+=add;
        cout<<ans<<endl;

    }


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep0(i, n) for (ll i = 0; i <= (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define rrep0(i, n) for (ll i = (n); i >= 0; --i)
#define srep(i, s, t) for (ll i = s; i < t; ++i)
#define srep1(i, s, t) for (ll 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) cerr << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
constexpr ll MAX = 200002;

int main()
{
    ll n;
    cin >> n;
    vl a(MAX, 0);
    ll b = 0, maxb = 0, sum = 0, ans = 0;
    rep1(i, n) cin >> a[i];
    rep1(i, n)
    {
        b += a[i];
        maxb = max(maxb, b);
        ans = max(ans, sum + maxb);
        sum += b;
    }
    cout << ans << endl;
    return 0;
}

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
int main()
{
   ll n,m,i,j,t,a,b,c,p,k,kk;
   cin>>n;
   for(i=1;i<=n;i++) scanf("%lld",&d[i]);
   for(i=1;i<=n;i++)
   {
   	  num[i]=num[i-1]+d[i];
   }
    ll ans=0; p=0; ll sum=0;
   for(i=1;i<=n;i++)
   {
   	   ans+=num[i];
   	   if(ans>=sum)
   	   {
   	    sum=ans; p=i;
	   }
   }
   if(p==0)
   {
   	 printf("0\n");
   }
   else
   {
   	  ll sum1=sum; ll o=0; o=max(o,sum);
   	  if(p!=1)
   	  {
   	   for(i=p;i>=1;i--)
   	   {
   	      if(d[i]>=0)
			 {
			    sum1-=d[i];
			 }
			 else sum1-=d[i];
			 o=max(o,sum1);
	   }
	   o=max(o,sum1);
       }
	    sum1=sum;
//	    cout<<sum1<<endl;
       if(p!=n)
       {
	   for(i=1;i<=p;i++)
	   {
   	      if(d[i]<=0)
			 {
			    sum1+=d[i];
			 }
			 else sum1+=d[i];
			 o=max(o,sum1);
			 //cout<<sum1<<endl;
	   }
	   o=max(o,sum1);
       }
	   cout<<o<<endl;
   }

}