#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define int long long

const int N = (int) 2e6 + 7;
int n, k, a[N];
vector<int> p[N];

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

  cin >> n >> k;
  for (int i = 0; i <= n; i++) p[i].push_back(0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[a[i]].push_back(i);
  }
  for (int i = 0; i <= n; i++) p[i].push_back(n + 1);
  for (int x = 0; x <= n; x++) {
    for (int i = 0; i + 1 < (int) p[x].size(); i++) {
      int space = p[x][i + 1] - p[x][i] - 1;
      if (space >= k) {
        cout << x << "\n";
        return 0;
      }
    }
  }
  assert(0);

}

#include<bits/stdc++.h>

using namespace std;

#define gc c=getchar()
#define r(x) read(x)
#define ll long long
#define db double

template<typename T>
inline void read(T&x){
    x=0;T k=1;char gc;
    while(!isdigit(c)){if(c=='-')k=-1;gc;}
    while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
}

ll n,k;

inline ll calc(ll x){
    if(x<2||x>2*n)return 0;
    return min(n,x-1)-max(1ll,x-n)+1;
}

int main(){
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    r(n),r(k);
    ll ret=0;
    for(int i=2;i<=2*n;++i){
        ret+=calc(i)*calc(i-k);
    }
    printf("%lld\n",ret);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;
void YN(bool x){
  if(x) cout<<"Yes";
  else cout<<"No";
}
int main() {
  bool f=false;
  string S;cin>>S;
  int s=S.size();
  vector<int> C(10,0);
  rep(i,s) C[S[i]-'0']++;
  for(int i=0;i<=1000;i+=8){
    vector<int> t(10,0);
    t[i%10]++;
    t[(i/10)%10]++;
    t[(i/100)%10]++;
    bool k=true;
    rep(j,10){
      if(C[j]<t[j])k=false;
    }
    if(k)f=true;
  }
  if(s==1){
    if(S[0]=='8')f=true;
    else f=false;
  }
  if(s==2){
    int p=10*(S[0]-'0')+(S[1]-'0'),q=10*(S[1]-'0')+(S[0]-'0');
    if(p%8==0||q%8==0)f=true;
    else f=false;
  }
  YN(f);
}

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

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

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

const int MAX = 100000;
class shuturyoku_unko {
public:
	char C[MAX * 5];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 5) {
				C[i * 5 + 4 - j] = '0' + X % 10;
				X /= 10;
			}
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char dn[dm], * di = dn, * owad = dn + dm - 20;
void putint(ll A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int dig = 1;
	if (A >= 100000) {
		if (A >= 1000000000) dig = 5;
		else if (A >= 100000000) dig = 4;
		else if (A >= 10000000) dig = 3;
		else if (A >= 1000000) dig = 2;
		memcpy(di + dig, f.C + A % 100000 * 5, 5);
		A /= 100000;
		memcpy(di, f.C + A * 5 + 5 - dig, dig);
		di += 5 + dig;
	}
	else {
		if (A >= 10000) dig = 5;
		else if (A >= 1000) dig = 4;
		else if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, f.C + A * 5 + 5 - dig, dig);
		di += dig;
	}
	*di++ = '\n';
}
const int mod = 1e9 + 7;

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

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

		ll a = min(A, N - B + 1);
		ll b = min(A + B - 1, N - B + 1);

		ll are = (a + b) * (b - a + 1) + b * (N - A + 1 - (b - a + 1) * 2);
		ll atti = (N - A + 1) * (N - B + 1);

		ll kotae = (atti + are) % mod * ((atti - are) % mod) % mod;
		putint(kotae);
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first
#define se second
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
// ミント

const ll mod = //1e9+7 ;
  998244353;

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
  } ;

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

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }
///
template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
////
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};
mint dp[3005][3005] ;
mint rui[3005][3005] ;
int main(){
ll n,k ; cin>>n>>k ;
rep2(i,1,3000) dp[i][i]=1 ;
rep2(i,1,n-k){

  rep2(j,1,i-1){
    mint now=0ll ;
    //rep2(qq,1,min(2*j,i-j)) now+= dp[i-j][qq] ;
    now= rui[i-j][min(2*j,i-j)] ;
    dp[i][j]=now ;
  }
  rep2(ww,1,i) rui[i][ww]=rui[i][ww-1]+dp[i][ww] ;
}
mint ans= 0 ;
rep2(i,1,min(n-k,k)) ans+= dp[n-k][i] ;
if((n-k)==0) cout<<1<<endl ;
else cout<<ans<<endl ;
 return 0;
  }

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';

ll dp[100][200000 + 10];

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

    int n, K;
    ll m;
    cin >> n >> K >> m;

    int lim_sum = (n - 1) / 2;
    lim_sum = lim_sum * (lim_sum + 1) / 2 * K;

    dp[0][0] = 1;
    for (int i = 1; i < n; i++) {
        int max_sum = min((i - 1) * i / 2 * K, lim_sum);
        for (int j = 0; j <= max_sum; j++) {
            if (dp[i - 1][j] == 0) continue;
            for (int k = 0; k <= K; k++) {
                if (j + k * i > lim_sum) break;
                dp[i][j + k * i] += dp[i - 1][j];
                if (dp[i][j + k * i] >= m) dp[i][j + k * i] -= m;
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        int li = i - 1;
        int ri = n - i;
        int mini = min(li, ri);
        int max_sum = mini * (mini + 1) / 2 * K;

        ll ans = 0;
        for (int j = 0; j <= max_sum; j++) {
            (ans += dp[li][j] * dp[ri][j] % m);
            if (ans >= m) ans -= m;
        }
        ans = (ans * (K + 1) + m - 1) % m;
        cout << ans << newl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
struct qwe{
    int t,i;
}a[1005],b[1005];
int n;
bool cmp(qwe a,qwe b){
    return a.t<b.t;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i].t>>b[i].t,a[i].i=b[i].i=i;;
    sort(a,a+n,cmp);
    sort(b,b+n,cmp);
    if(a[0].i!=b[0].i) cout<<max(a[0].t,b[0].t);
    else cout<<min(min(max(a[1].t,b[0].t),max(a[0].t,b[1].t)),a[0].t+b[0].t);
}

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

#define endl "\n"
#define LL long long
#define ULL unsigned long long
const LL        INF = 1LL<<62;
const double    PI = 2.0 * acos(0.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

////// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
/////cout<<*X.find_by_order(1)<<endl;
/////cout<<X.order_of_key(-5)<<endl;
//
//typedef tree<
//LL,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ        freopen("in.txt","r",stdin)
#define WRITE       freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define sqr(x)      ( (x) * (x) )
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define deb(x)      cerr<<#x<<" :: "<<x<<"\n"
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),( (b+e) /2 )
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
int X[4]={0,0,-1,1};
int Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int BX[8]={0,0,1,-1,-1,1,1,-1};
//int BY[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

// Bit Operations
#define popcountL   __builtin_popcountll
#define popcount    __builtin_popcount
inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){ return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

inline LL modMul(LL a, LL b,LL mod){
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
inline LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}
inline LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return ((a/g) * b);
}

//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2234567;

int A[1005],B[1005];
void solve(){
    int n,m,k;
    int x = INT_MAX,y = INT_MAX,z = INT_MAX;
    cin>>n;
    FOR(i,n){
        int a,b;
        cin>>a>>b;
        A[i] = a;
        B[i] = b;
        z = min(a+b,z);
    }
    int ans = z;
    FOR(i,n){
        FOR(j,n){
            if(i==j)continue;
            ans = min(ans,max(A[i],B[j]));
        }
    }

    cout<<ans<<endl;

}

int main(){

    BOOST;
    #ifdef MujahidPC
        double start = clock();
//        READ;
//        WRITE;
    #endif
    int t;
    t = 1;
//    cin>>t;
    while(t--)solve();

    #ifdef MujahidPC
        double tim = (clock() - start)/CLOCKS_PER_SEC;
        cerr<<"Running Time : "<<tim<<" \n";
    #endif
    return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,a[20][20],ok[300000],dp[300000];

int main()
{
  cin>>n>>m;
  int x,y;
  rep(i,m)
  {
    scanf("%d%d",&x,&y);
    --x;
    --y;
    a[x][y]=a[y][x]=1;
  }
  rep(i,1<<n)
  {
    bool b=true;
    rep(j,n)
    {
      for(int k=j+1;k<n;k++)
      {
        if((i&(1<<j))==0||(i&(1<<k))==0) continue;
        if(a[j][k]==0)
        {
          b=false;
          break;
        }
      }
      if(!b) break;
    }
    ok[i]=(int)b;
  }
  rep(i,(1<<n)+5) dp[i]=1e9;
  dp[0]=0;
  rep(i,1<<n)
  {
    if(dp[i]==1e9) continue;
    int lft=(1<<n)-1-i;
    for(int sub=lft;sub>0;sub=(sub-1)&lft) if(ok[sub]==1) dp[i|sub]=min(dp[i|sub],dp[i]+1);
  }
  cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

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

const int N=0;

char win(char a,char b){
    if(a==b)return a;
    if(a=='R'){
        if(b=='P')return b;
        else return a;
    }
    if(a=='P'){
        if(b=='S')return b;
        else return a;
    }
    if(a=='S'){
        if(b=='R')return b;
        else return a;
    }
    return a;
}

void solve(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    for (int i = 0; i < k; ++i) {
        if(sz(s)%2){
            s+=s;
        }
        string t = "";
        for (int j = 0; j < sz(s); j+=2) {
            t+=win(s[j],s[j+1]);
        }
        s=t;
    }
    cout<<s[0];

}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
        sieve();
    #endif
    #ifdef NCR
        init();
    #endif
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Y cout<<"YES"<<endl;
#define N cout<<"NO"<<endl;
#define tc int t; cin>>t; while(t--)
#define eki int n; cin>>n;
#define loop for(int i=0; i<n; i++)
#define mem(a,b) memset(a, b, sizeof(a) )
const int mx=1e4+123;

 int main(){
     int a, b, c;
     cin>>a>>b>>c;
     if((a+c-2*b)==0 || (b+c-2*a)==0 || (a+b-2*c)==0)
     cout<<"Yes"<<endl;
     else cout<<"No"<<endl;
 }

/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/
#include <iostream>
using namespace std;
int main()
{
  int arr[3];
  for(int i=0; i<3; i++)
  {
    cin>>arr[i];
  }
  if(arr[0] == arr[1] && arr[1] == arr[2]){
    cout<<"Yes"<<endl;
    return 0;
  }
  if((arr[0]+arr[1] == 2*arr[2]) || (arr[0]+arr[2] == 2*arr[1]) || (arr[1]+arr[2] == 2*arr[0]))
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;

  return 0;
}


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

#define ll long long
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define pi pair<int,int>

ll mod = 1e9+7;
const int MAXM = 200050;

void solve(int test)
{
    string s;
    cin>>s;

    if(s[0] == s[1] && s[1] == s[2])
        cout<<"Won\n";
    else
        cout<<"Lost\n";
}

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

    int t;
    //cin>>t;
    t = 1;
    for(int i=1;i<=t;i++)
        solve(i);
}

#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(v) for (auto &e : v) { cin >> e; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
#pragma endregion

int main() {
  IN(int, X);
  IN(int, Y);
  int mi = min(X, Y);
  int ma = max(X, Y);
  if (mi + 3 > ma) yes();
  else no();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<x<<endl,exit(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second

const int N=2002;
char a[N][N];
int hor[N][N],ver[N][N],sum,mod=1e9+7,pwr[4000005];

int32_t main(){
   ios;
   int n,m;
   cin>>n>>m;

   pwr[0]=1;
   F(i,1,4000000) pwr[i]=pwr[i-1]*2%mod;

   F(i,1,n){
   	F(j,1,m){
   		cin>>a[i][j];
   		sum+=(a[i][j]=='.');
   	}
   }

   //precalculation
   F(i,1,n){
   	int prv=0;
   	F(j,1,m){
   		if(a[i][j]=='#') prv=j;
   		else hor[i][j]=j-prv-1;
   	}
   	prv=m+1;
   	R(j,m,1){
   		if(a[i][j]=='#') prv=j;
   		else hor[i][j]+=prv-j-1;
   	}
   }
   F(j,1,m){
   	int prv=0;
   	F(i,1,n){
   		if(a[i][j]=='#') prv=i;
   		else ver[i][j]=i-prv-1;
   	}
   	prv=n+1;
   	R(i,n,1){
   		if(a[i][j]=='#') prv=i;
   		else ver[i][j]+=prv-i-1;
   	}
   }

   //calculation
   int ans=0;
   F(i,1,n){
   	F(j,1,m){
   		if(a[i][j]=='#') continue;

   		int tol=hor[i][j]+ver[i][j]+1;
   		int aa=(pwr[tol]-1+mod)%mod;
   		int bb=pwr[sum-tol];

   		ans+=aa*bb%mod;
   		ans%=mod;
   	}
   }
   cout<<ans<<endl;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#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 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__) << "] "

const int MOD = 998244353;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y, int md = MOD){x += y; if(x >= md) x -= md;}
void sub_self(int &x, int y, int md = MOD){x -= y; if(x < 0) x += md;}
void mul_self(int &x, int y, int md = MOD){x = x * 1LL * y % md;}
inline int mul(int x, int y, int md = MOD){return x * 1LL * y % md;}
inline int add(int x, int y, int md = MOD){x += y; if(x >= md) x -= md; return x;}
inline int sub(int x, int y, int md = MOD){x -= y; if(x < 0) x += md; return x;}

const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};

int bp(int x, int exp){
	int res = 1;
	while(exp){
		if(exp & 1) mul_self(res, x);
		mul_self(x, x);
		exp >>= 1;
	}
	return res;
}

int inv(int x){
	return bp(x, MOD - 2);
}

void solve(){
	int n, m;
	cin >> n >> m;
	vector<int> vec(m);
	for(auto &x : vec) cin >> x;
	vec.push_back(0);
	vec.push_back(n + 1);
	sort(all(vec));
	int mn = n;
	vector<int> df;
	for(int i = 1; i < m + 2; ++i){
		int x = vec[i] - vec[i - 1] - 1;
		if(x > 0){
			mn = min(mn, x);
			df.push_back(x);
		}
	}
	assert(mn > 0);
	int res = 0;
	for(auto &x : df){
		res += (x + mn - 1) / mn;
	}
	cout << res << '\n';
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("tree.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": ";
		solve();
		// cout << '\n';
		// cout << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define range(i, a, b) for (ll i = (a); i < (b); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pri_b = priority_queue<T>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
ll mul(ll a, ll b) { return (a > INF / b ? INF : a * b); }
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T> void er(T a) { cout << a << '\n'; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }
template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

const int N = 200010;
vector<vector<int>> graph(N, vector<int>());
vector<int> xd(N), yd(N);

void dfs(int n, int p, int d, vector<int> &v) {
	v[n] = d;
	for (int i : graph[n]) {
		if (i != p) dfs(i, n, d + 1, v);
	}
}

vector<int> ans(N);

void tour(int n, int p, vector<int> &v) {
	v.pb(n);
	for (int i : graph[n]) {
		if (i != p && ans[i] == 0) {
			tour(i, n, v);
			v.pb(n);
		}
	}
}

int main() {
	int n;
	cin >> n;
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}
	dfs(0, -1, 0, xd);
	int ver = -1; int m = 0;
	rep(i, n) if (chmax(m, xd[i])) ver = i;
	dfs(ver, -1, 0, xd); int rver = 0; m = 0;
	rep(i, n) if (chmax(m, xd[i])) rver = i;
	dfs(rver, -1, 0, yd);
	rep(i, n) {
		int r = -1;
		vector<int> nv;
		for (int nxt : graph[i]) {
			if (yd[nxt] < yd[i]) {
				r = nxt;
			}
			else nv.pb(nxt);
		}
		if (r != -1) nv.pb(r);
		graph[i] = nv;
	}
	vector<int> vec;
	tour(ver, -1, vec);
	rep(i, vec.size()) {
		if (ans[vec[i]] == 0) ans[vec[i]] = i + 1;
	}
	rep(i, n) cout << ans[i] << ' ';
	cout << '\n';
}

//Shrey Dubey

#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<vector>
#include<set>
#include<list>
#include<iomanip>
#include<queue>
#include<stack>
#include <math.h>
#include<climits>
#include<bitset>
#include<cstring>
#include<numeric>
#include<array>

using namespace std;
typedef long long ll;
typedef long double ld;

#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define prDouble(x) cout<<fixed<<setprecision(10)<<x //to print decimal numbers
#define pb push_back
#define ff first
#define sec second
#define umap unordered_map
#define mp make_pair
#define KOBE ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fo(n) for(ll i = 0; i<n; i++)
#define fnd(stl, data) find(stl.begin(), stl.end(), data)
#define forn(x,n) for(ll x = 0; x<n; x++)
#define imax INT_MAX
#define lmax LLONG_MAX
#define imin INT_MIN
#define lmin LLONG_MIN
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<ll,ll> >
#define vb vector<bool>
#define pr(t) cout<<t<<"\n"
#define int long long
#define ql queue<ll>
#define qp queue<pair<ll,ll> >
#define endl "\n"
#define nl cout<<"\n"
#define re cin >>
#define pll pair<ll,ll>
#define FOR(a,b) for(ll i = a; i<=b; i++)
#define all(x) x.begin(),x.end()

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

ll mod = 1e9 + 7;

ll cl(ld a){
    if(a>(ll) a){
        return (ll)a+1;
    }
    else{
        return (ll)a;
    }
}

ll flr(ld a){
    if(a < 0.0){
        return (ll) a - 1;
    }
    return (ll) a;
}

ll mx = 1e18;

map<ll,ll> dp;

ll recur(ll x, ll y){
    if(x == y) return 0;
    if(x >= y) return x-y;
    if(dp.count(y)){
        return dp.at(y);
    }
    if(y == 1) return 1;
    // cout<<x<<"()"<<y<<"\n";
    ll ans;
    if(y%2 == 1){
        ans = 1 + min(recur(x,y+1),recur(x,y-1));
    }
    else{
        ans = 1 + min(recur(x,y/2),y-x-1);
    }
    dp[y] = ans;
    return ans;
}

//code starts here

void solve(){
    ll x,y; re x; re y;
    pr(recur(x,y));
}

int32_t main(){
    KOBE;
    ll t;
    t = 1;
    // re t;
    while(t--) solve();
}

//common errors
// row - n, col - m always and loop var
// see the freq of numbers carefully
// see if there's array overflow
// use map for large inputs

//problem ideas
//check piegonhole wherever possible
//there might be many instances of limited answers like 0,1,2 only
// see suffix and prefix
//don't be obsessed with binary search
// try to find repeating pattern in matrices


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

#define int long long
#define MS(x) memset((x), -1, sizeof((x)))
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 MOD 998244353

template<int64_t mod> struct Combination{
    vector<int64_t> f, rf;

    Combination(int max_n): f(max_n+1), rf(max_n+1){
        f[0] = 1;
        for(int i = 1;i <= max_n;i++) f[i] = f[i-1] * i % mod;
		int64_t a = f[max_n], inv = 1;
		for(int64_t b = mod-2;b > 0;b>>=1){
			if(b & 1) inv = inv*a % mod;
			a = a * a % mod;
		}
		for(int i = max_n;i >= 0;i--) inv = (rf[i] = inv) * i % mod;
    }

    int64_t operator()(int n, int r){
        return (r < 0 || n < r) ? 0 : f[n] * rf[r] % mod * rf[n-r] % mod;
    }
};

int n, m;
Combination<MOD> ncr(200010);

int memo[50][200010];

int dp(int i, int j){
	if(i > n) return 0;
	if(memo[i][j] != -1) return memo[i][j];
	int ans = ncr((n-i)+(i-1), i-1);
	for(int k = j*2;k <= m;k+=j){
		ans += dp(i+1, k);
		ans %= MOD;
	}
	return memo[i][j] = ans;
}

signed main(){
	cin >> n >> m;

	MS(memo);
	int ans = 0;
	for(int i = 1;i <= m;i++){
		ans += dp(1, i);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define gp  __gnu_pbds
#define iset(T) gp::tree<T,gp::null_type,less<T>,gp::rb_tree_tag,gp::tree_order_statistics_node_update>
using namespace std;

#define SQ(x) ((x)*(x))
#define u unsigned
#define ull unsigned long long
#define ll  long long
#define ld  long double
#define test(x) cout<<"here "<<x<<endl;
#define debug(x) cout<<(#x)<<": "<<(x)<<endl;
#define inputstl(v) for(auto& x:v) cin>>x;
#define input(arr,n) for(ull i=0;i<n;++i){cin>>arr[i];}
#define print(arr,n) for(ull i=0;i<n;++i){cout<<arr[i]<<" ";}cout<<'\n';
#define printall(x) for(auto y:x){cout<<y<<' ';}cout<<'\n';
#define printallpii(x) for(auto y:x){cout<<y.fi<<','<<y.se<<' ';}cout<<'\n';
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define mod (ll)(1e9+7)
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define SENSITIVITY 1e-9
#define EQUAL(x1,x2) [](auto x1,auto x2){double ep=0.0001;double pos=x1-x2;if(pos<0){pos=-pos;}double maxi=(x1>x2)?(x1):(x2);if(pos/(maxi*ep)<SENSITIVITY)return true;else return false;}(x1,x2)
bool isPrime(ll a)
{
    ll lim=sqrt(a);
    lim++;
    if(a==1)
        return false;
    for(ll i=2; i<=lim; ++i)
    {
        if(a%i==0)
        {
            return false;
        }
    }
    return true;
}
bool isPali(string s)
{
    int _size=(s.length())/2;
    for(int i=0; i<_size; ++i)
    {
        if(s.at(i)!=s.at(s.length()-1-i))
        {
            return false;
        }
    }
    return true;
}
int gcd(int a,int b)
{
    if(a==0)
    {
        return b;
    }
    else if(b==0)
    {
        return a;
    }
    else
    {
        int shift=__builtin_ctz(a|b);
        a>>=__builtin_ctz(a);
        do
        {
            b>>=__builtin_ctz(b);
            if(a>b)
            {
                a=a^b;
                b=a^b;
                a=a^b;
            }
            b-=a;
        }
        while(b);
        return a<<shift;
    }
}
ll gcdll(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else if(b==0)
    {
        return a;
    }
    else
    {
        ll shift=__builtin_ctzll(a|b);
        a>>=__builtin_ctzll(a);
        do
        {
            b>>=__builtin_ctzll(b);
            if(a>b)
            {
                a=a^b;
                b=a^b;
                a=a^b;
            }
            b-=a;
        }
        while(b);
        return a<<shift;
    }
}

ll power(ll a,ll b,ll _mod)
{
    ll temp=a;
    ll ans=1;
    int limit=63-__builtin_clzll(b);
    int index=0;
    while(index<=limit)
    {
        if(b&(1ll<<index))
        {
            ans=(ans*temp)%_mod;
        }
        ++index;
        temp=(temp*temp)%_mod;
    }
    return ans;
}

int main()
{
    fastio;
    int tt=1;
//    cin>>tt;
    while(tt--)
    {
        int n;
        cin>>n;
        vector<ll> a(n),b(n);
        inputstl(a);
        inputstl(b);
        ll sum=0;
        for(int i=0;i<n;++i)
        {
            sum+=(a[i]*b[i]);
        }
        if(sum==0)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }

    }
    return 0;
}

#include<iostream>
using namespace std;
int n,a[100020],b[100020],s=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
		s+=a[i]*b[i];
	}
	cout<<(s?"No":"Yes")<<endl;
	return 0;
}


//                              ______  ______  ______
// .-----..-----..-----..-----.|    __||__    ||  __  |
// |     ||  _  ||     ||  _  ||  __  ||    __||  __  |
// |__|__||___  ||__|__||___  ||______||______||______|
//        |_____|       |_____|
//
# include <bits/stdc++.h>
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define step(n) rep(_, n)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
# define contains(x,key) ((x).find(key) != (x).end())
# define cauto const auto
# define int long long
# define float long double
# define FI first
# define SE second
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using mii = map<int, int>;
using msi = map<string, int>;
template<class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T> istream& operator>>(istream& is, vector<vector<T>>& v) { for(auto& x : v) for(auto& y : x) is >> y; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.FI >> p.SE; }
template<class T> string join(const vector<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){ rep (i, len(v)) { if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); } return os; }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; print(args...);}
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){cerr << v; if(sizeof...(args))cerr << " "; eprint(args...);}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){ cout << p.FI << " " << p.SE; return os; }
template<class T> inline void Unique(T& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
template<class T> inline constexpr bool chmax(T &a, T b) { return a < b && (a = b, true); }
template<class T> inline constexpr bool chmin(T &a, T b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
const char* YesNo(bool b) { return b ? "Yes" : "No"; }
const char* YESNO(bool b) { return b ? "YES" : "NO"; }
const char* yesno(bool b) { return b ? "yes" : "no"; }
const char* yn(bool b) { return YesNo(b); }

int32_t main() {
  int n;
  cin >> n;
  vector<int> imos(1000000 + 1 + 1);
  rep (i, n) {
    int a, b;
    cin >> a >> b;
    imos[a]++;
    imos[b + 1]--;
  }

  rep (i, len(imos)) imos[i+1] += imos[i];
  int ans = 0;
  rep (i, len(imos)) ans += imos[i] * i;
  print(ans);

  return 0;
}

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void prince()
{
    #ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
}

int main() {
  prince();
 ll n;
            cin>>n;
            ll sum = 0;
            while(n--)
            {
                ll a,b;
                cin>>a>>b;

                a--;
                sum+=b*(b+1)/2-a*(a+1)/2;
            }
            cout<<sum<<endl;
            }


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n);
  vector<ll> sum(n+1);
  vector<ll> mx(n+1);
  rep(i, n) {
    cin >> A[i];
    sum[i+1] = sum[i] + A[i];
    mx[i+1] = max(sum[i+1], mx[i]);
  }
  ll tmp = 0;
  ll ans = 0;
  rep(i, n) {
    chmax(ans, tmp+mx[i+1]);
    tmp += sum[i+1];
  }
  cout << ans << endk;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long sum=0,sum2=0,maxx=0;
    for(int i=1;i<=n;i++)
    {
        long long x;
        cin >> x;
        sum+=x;
        sum2+=sum;
        maxx=max(maxx,x);
        cout << sum2+maxx*i << '\n';

    }
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()

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

	string x;
	long long m;

	cin >> x >> m;
	long long d = 0;
	for (char c : x) d = max<long long>(d, c - '0');

	if (x.size() == 1) {
		if (x[0] - '0' <= m)cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}

	long long lb = d, ub = m + 1;

	while (ub - lb > 1) {
		long long mid = (lb + ub) / 2;
		long long v = 0;
		for (char c : x) {
			if (v > (m + mid - 1) / mid) {
				v = -1;
				break;
			}
			v *= mid;
			v += c - '0';
		}
		if (v > m) {
			v = -1;
		}
		if (v == -1) ub = mid;
		else lb = mid;
	}
	cout << lb - d << endl;

	return 0;
}

#include <bits/stdc++.h>
#include <string>

#define rep(i,n) for(int i=0;i < (n);i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
typedef unsigned long long ull;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

ll fact[MAX], fact_inv[MAX];

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

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

const int N=100;
char x[N];
long long int m,sans,len;
bool check(long long int i){
	long long int ans=0;
	for(int o=0;o<=len-1;o++){
		if(ans>m*1.0/i){break;}
		ans=ans*i+x[o]-'0';
		if(ans>m){break;}
		else if(o==len-1)return 1;
	}
	return 0;
}
int main(){
	cin>>x;
	len=strlen(x);
	scanf("%lld",&m);
	if(len==1){
		if(x[0]-'0'<=m)
		printf("1\n");
		else
		printf("0\n");

		return 0;
	}
	int maxn=1;
	for(int i=len-1;i>=0;i--){
		maxn=max(maxn,x[i]-'0'+1);
	}
	long long int l=maxn,r=m,mid,best=maxn-1;
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid)){
			best=mid;
			l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	while(check(best+1))best=best+1;
	printf("%lld\n",best-maxn+1);
	return 0;
}


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

using ll  = long long;
using ull = unsigned ll;
using ld  = long double;
using pi  = pair<int, int>;
using pii = pair<ll, ll>;
using vi  = vector<int>;
using vii = vector<ll>;
using vip = vector<pair<int, int>>;

const int MAX_N = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define PI           3.141592653589793238
#define fir          first
#define sec          second
#define all(x)       (x).begin(),(x).end()
#define rall(x)      (x).rbegin(),(x).rend()
#define pb           push_back
#define mp           make_pair
#define loop(i,n,x)  for(int i=n;i<x;i++)
#define sz(a)        ((int) (a).size())
#define For(n,x)     for(int i=1;i<=x;i++)
#define ite          iterator it
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test         ll t;cin>>t; while(t--){solve();}

void oj()
{

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

}

bool isPowerOfTwo(ll n)
{
	if (n == 0)
		return false;

	return (ceil(log2(n)) == floor(log2(n)));
}

void solve()
{

	int a, b;

	cin >> a >> b;
	a += b;
	if (a >= 15 && b >= 8)
		cout << "1" << endl;
	else  if ((a >= 10 ) && (b >= 3))
		cout << "2" << endl;
	else if ((a >= 3))
		cout << "3" << endl;
	else
		cout << "4" << endl;

}

int main()
{

	ios_base::sync_with_stdio(false); cin.tie(NULL);

	oj();

	//test;
	solve();

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define d(x) cout<<x<<" "
#define nl cout<<endl
#define rep(var,init_val,final_val) for(int var = init_val; var < final_val; ++var)
#define tt ll t;cin>>t;while(t--)
#define show(a,b) rep(i,0,b) d(a[i]);nl;
#define mod 1000000007
#define vi vector<int>
#define pii pair<int,int>
const int d4i[] = {-1,0,1,0};
const int d4j[] = {0,1,0,-1};

const int d8i[] = {-1,-1,-1,0,1,1,1,0};
const int d8j[] = {-1,0,1,1,1,0,-1,-1};
// #define ONLINE_JUDGE true

void solve(){
	int m , h;
	cin>>m>>h;

	if(h%m) cout<<"No";
	else cout<<"Yes";
}

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


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

const int N = 100 + 9;
const int N2 = 10000 + 9;

char s[N];

int a[N], b[N2][N];

bool check(int k, int n) {
    for (int i = 0; i <= n; ++i) {
        int p = a[i] / k, q = a[i] % k;
        for (int j = 1; j <= q; ++j) {
            b[j][i] = p + 1;
        }
        for (int j = q + 1; j <= k; ++j) {
            b[j][i] = p;
        }
    }
    bool f = true;
    for (int j = 1; j <= k; ++j) {
        for (int i = 1; i <= n; ++i) {
            if (s[i] == '<') {
                if (!(b[j][i - 1] < b[j][i])) f = false;
            }
            else {
                if (!(b[j][i - 1] > b[j][i])) f = false;
            }
        }
    }
    return f;
}

int main() {
    int n; scanf("%d", &n);
    scanf("%s", s + 1);
    for (int i = 0; i <= n; ++i) {
        scanf("%d", a + i);
    }
    int L = 1, R = N2 - 9;
    while (L < R) {
        int M = (L + R) >> 1;
        if (check(M + 1, n)) L = M + 1;
        else R = M;
    }
    check(L, n);
    printf("%d\n", L);
    for (int j = 1; j <= L; ++j) {
        for (int i = 0; i <= n; ++i) {
            printf("%d%c", b[j][i], i < n ? ' ' : '\n');
        }
    }
    return 0;
}

/*
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
*
* @author: Xingjian Bai
* @date: 2021-04-10 13:03:21
* @description:
*
*
* @notes:
* g++ -fsanitize=address -ftrapv
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  */
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define TIME (double)clock()/CLOCKS_PER_SEC
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int mod = 1000000007;
const ll oo = 1e18;
const ld eps = 1e-8;
#define debug(x) cerr << "(debug mod) " << #x << " = " << x << endl

int n;
string s;
int a[110];
int b[10010][110];

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> s;
    int mn = 1e9;
    for (int i = 0; i <= n; i ++) {
    	cin >> a[i];
    	if (i)
	    	mn = min (mn, abs(a[i] - a[i - 1]));
    }

    for (int i = 0; i <= n; i ++) {
    	for (int j = 1; j <= mn; j ++)
    		b[j][i] = a[i] / mn;
    	for (int j = 1; j <= a[i] - a[i] / mn * mn; j ++)
	    	b[j][i] ++;
    }

    cout << mn << endl;
    for (int i = 1; i <= mn; i ++) {
    	for (int j = 0; j <= n; j ++)
    		cout << b[i][j] << ' ';
    	cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

//累乗(繰り返し二乗法)
long long power(long long b,long long e){
  long long r=1;
  while(e){
      if(e&1){
          r=(r*b)%MOD;
      }
      b=(b*b)%MOD;
      e >>=1;
  }
  return r;
}

int main(void){
    ll H,W,K;
    vector<pair<pair<ll,ll>,char>> HWC;

    cin >> H >> W >> K;
    REP(i,K){
        ll h,w;
        char c;
        cin >> h >> w >> c;
        h--;w--;
        HWC.push_back({{h,w},c});
    }

    const ll MEM = 5100;
    ll S[MEM][MEM]={};
    REP(i,HWC.size()){
        if(HWC[i].second=='D')S[HWC[i].first.first][HWC[i].first.second]=1;
        if(HWC[i].second=='R')S[HWC[i].first.first][HWC[i].first.second]=2;
        if(HWC[i].second=='X')S[HWC[i].first.first][HWC[i].first.second]=3;
    }

    ll inv3 = power(3,MOD-2);
    ll tinv3 = 2*inv3;
    ll dp[MEM][MEM]={};
    dp[0][0]=1;

    REP(i,H){
        REP(j,W){

            ll d=0,r=0;
            if(i!=0 && S[i-1][j]!=2){
                d=dp[i-1][j];
            }
            if(i!=0 && S[i-1][j]==0){
                d=(d*tinv3)%MOD;
            }

            if(j!=0 && S[i][j-1]!=1){
                r=dp[i][j-1];
            }
            if(j!=0 && S[i][j-1]==0){
                r=(r*tinv3)%MOD;
            }

            dp[i][j]+=d+r;
            dp[i][j]%=MOD;

        }

        //REP(j,W){cout << (dp[i][j]*power(3,H*W-K))%MOD << " ";}cout << endl;
    }

    cout << (dp[H-1][W-1]*power(3,H*W-K))%MOD << endl;

    return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
#define maxn 3e5+50

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

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

const ll mod = 998244353;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    int h,w;cin >> h >> w;
    vector<vector<char>>s(h,vector<char>(w,'?'));
    ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    int k;cin >> k;
    for(int i = 0;i<k;i++){
        int x,y;cin >> x >> y;
        char c;cin >> c;
        x--;y--;
        s[x][y] = c;
    }
    dp[0][0] = 1;
    ll inv3 = modpow(3,mod-2,mod);
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            char c = s[i][j];
            if(c=='R'||c=='X') dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod;
            if(c=='D'||c=='X') dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod;
            if(c=='?'){
                dp[i][j+1] = (dp[i][j+1]+dp[i][j]*2*inv3%mod)%mod;
                dp[i+1][j] = (dp[i+1][j]+dp[i][j]*2*inv3%mod)%mod;
            }
        }
    }
    cout << dp[h-1][w-1]*modpow(3,h*w-k,mod)%mod;
}

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


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define 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;}

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,0LL);
    }

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

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

};

void solve(){

    int H,W,M;
    cin >> H >> W >> M;

    vl A(H,W),B(W,H);
    rep(i,M){
        ll h,w;
        cin >> h >> w;
        h--,w--;
        chmin(A[h],w);
        chmin(B[w],h);
    }
    ll ans = 1;
    reps(i,1,H) {
        if(A[i] == 0) break;
        ans += A[i];
    }
    reps(i,1,W){
        if(B[i] == 0) break;
        ans += B[i];
    }

    ve<pll> C;
    reps(i,1,H){
        if(A[i] == 0) break;
        C.pb({A[i],i});
    }
    sort(all(C));
    ll s = 1;

    BIT<ll> bi(H+10);
    rep(i,si(C)){
        pll p = C[i];
        if(p.fi == 0) continue;
        while (s < p.fi) {
            if(B[s] == 0) break;
            bi.update(B[s],1LL);
            s++;
        }
        //cout << p.fi csp p.se csp bi.sum(p.se,H+10) << endl;
        ans -= bi.sum(p.se,H+2);
    }

    cout << ans << endl;

}

int main(){

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

    solve();

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
int h,w,m;
int mh=9999999,ml=9999999;
int blockx[200001],blocky[200001];
int xw[200001],yw[200001];
int a[1000001];
struct node
{
	int val,pos;
}ww[200001];
void add(int x,int v)
{
	while(x<=200000)
	{
		a[x]+=v;
		x+=x&-x;
	}
}
int find(int x)
{
	int answw=0;
	while(x)
	{
		answw+=a[x];
		x-=x&-x;
	}
	return answw;
}
bool cmp(node x,node y)
{
	return x.val<y.val;
}
signed main()
{
	cin>>h>>w>>m;
	ml=w;mh=h;
	for(int i=1;i<=m;i++)
	{
		cin>>blockx[i]>>blocky[i];
		if(blockx[i]==1)
		{
			ml=min(ml,blocky[i]-1);
		}
		if(blocky[i]==1)
		{
			mh=min(mh,blockx[i]-1);
		}
	}
	//cout<<mh<<' '<<ml<<endl;
	for(int i=1;i<=ml;i++)
	{
		yw[i]=h+1;
	}
	for(int i=1;i<=mh;i++)
	{
		xw[i]=w+1;
	}
	for(int i=1;i<=m;i++)
	{
		yw[blocky[i]]=min(yw[blocky[i]],blockx[i]);
		xw[blockx[i]]=min(xw[blockx[i]],blocky[i]);
	}
	int ans=0;
	for(int i=1;i<=mh;i++)ans+=xw[i]-1;
	for(int i=1;i<=ml;i++)
	{
		//cout<<yw[i]<<' ';
		ans+=yw[i]-1;
		ww[i].pos=i,ww[i].val=yw[i];
		add(i,1);
	}
	int now=1;
	sort(ww+1,ww+1+ml,cmp);
	//cout<<ans<<endl;
	for(int i=1;i<=mh;i++)
	{
		while(now<=ml&&ww[now].val+1==i)add(ww[now].pos,-1),now++;
		ans-=find(xw[i]-1);
	}
	cout<<ans;
	return 0;
}
/*
3 4 3
1 3
3 3
2 2
*/


#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef __int128 ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
std::ostream&
operator<<( std::ostream& dest, __int128_t value )
{
    std::ostream::sentry s( dest );
    if ( s ) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[ 128 ];
        char* d = std::end( buffer );
        do
        {
            -- d;
            *d = "0123456789"[ tmp % 10 ];
            tmp /= 10;
        } while ( tmp != 0 );
        if ( value < 0 ) {
            -- d;
            *d = '-';
        }
        int len = std::end( buffer ) - d;
        if ( dest.rdbuf()->sputn( d, len ) != len ) {
            dest.setstate( std::ios_base::badbit );
        }
    }
    return dest;
}
ll f(string s,ll x,ll m){
	ll sum=0,p=1;
	for(ll i=0;i<sz(s);i++){
		ll val=(s[i]-'0');
		sum+=val*p;
		if(sum>m)
			return 0;
		p*=x;
		if(i<sz(s)-1&&p>m)
			return 0;
	}
	return 1;
}
void solve(){
	string s;
	long long int tr;
	cin>>s>>tr;
	ll m=tr;
	ll d=0;
	for(ll i=0;i<sz(s);i++)
		d=max(d,ll(s[i]-'0'));
	reverse(s.begin(),s.end());
	ll l0=d+1,r0=1000000000000000000;
	while(l0<=r0){
		ll m0=(l0+r0)/2;
		if(f(s,m0,m))
			l0=m0+1;
		else
			r0=m0-1;
	}
	ll res=max(ll(0),r0-d);
	if(sz(s)==1){
		res=min(res,ll(1));
	}
	cout<<(long long int)(res);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
    	solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
using ll = long long int;
using P = pair<int, int>;

int main(){
    string x;
    ll m;
    cin >> x;
    reverse(x.begin(), x.end());
    cin >> m;
    int basemin = 0;
    for(auto &p: x) basemin = max(basemin, p-'0');
    basemin++;

    if(x.length() == 1){
        if(x[0]-'0' <= m) cout << 1 << endl;
        else cout << 0 << endl;
    }else{
        ll ans = 0;
        ll ac = 2;
        ll wa = 1'000'000'000'000'000'000LL + 1LL;
        while(wa-ac > 1){
            ll mid = (wa+ac)/2;
            ll sum = 0;
            ll base = 1;
            if(mid < basemin){
                ac = mid;
                continue;
            }
            bool iswa = false;
            sum += x[0]-'0';
            if(sum > m) iswa = true;
            for(int i = 1; i < x.length(); i++){
                if(base > m/mid){
                    iswa = true;
                    break;
                }
                base *= mid;
                //sum += base*(x[i]-'0');
                if((x[i]-'0') <= (m-sum)/base){
                    sum += base*(x[i]-'0');
                }else{
                    iswa = true;
                    break;
                }
            }
            if(iswa) wa = (ll)mid;
            else ac = (ll)mid;
        }
        cout << max(0LL, ac-basemin+1) << endl;
    }

    return 0;
}


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

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

constexpr long long INFLL = 1e18;

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

int main() {
  ll x, y, a, b;
  cin >> x >> y >> a >> b;
  bool check = false;
  ll exp = 0;
  while (x < b) {
    if (x >= y) {
      x /= a;
      exp--;
      check = true;
      break;
    }
    x *= a;
    exp++;
  }
  if (check == false && x >= y) {
    x /= a;
    exp--;
  }
  if (check == false && y > x) {
    ll dif = y - x;
    ll count = dif / b;
    if (dif % b == 0 && count > 0) {
      count--;
    }
    exp += count;

    // x += b * count;
    /*
        while (x < y) {
          x += b;
          exp++;
        }
        x -= b;
        exp--;
        */
  }
  //   cout << x << endl;
  if (exp < 0) {
    exp = 0;
  }
  cout << exp << endl;
  return 0;
}

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

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

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define precise(x) fixed << setprecision(x)

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    if(a == 0) return 0;
    b %= (M - 1);  //M must be prime here

    int res = 1;

    while(b > 0)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }

    return res;
}

void solve()
{
   int n,m,q;
    cin >> n >> m >> q;

    pii a[n];
    f(i,n) cin >> a[i].S >> a[i].F;
    sort(a,a+n);
    reverse(a,a+n);

    int b[m];
    f(i,m) cin >> b[i];

    int l,r;

    while(q--)
    {
        cin >> l >> r;
        l--,r--;

        multiset<int> ms;

        for(int i=0;i<m;i++)
            if(i < l || i > r) ms.insert(b[i]);

        int res = 0;

        f(i,n)
        {
            if(ms.empty()) break;

            auto it = ms.lower_bound(a[i].S);

            if(it == ms.end()) continue;

            ms.erase(it);
            res += a[i].F;
        }

        cout << res << '\n';
    }

}

signed main()
{
    fast;

    int t = 1;

//    cin >> t;

    while(t--)

    solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
int a[N],b[N];
int c[N],d[N];
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n;++i)
		cin>>b[i];
	int sum=0,ans=0,m=(n>>1);
	for(int i=1;i<=n;++i){
		sum+=a[i];
		b[i]-=a[i];
		if(i&1) c[(i+1)/2]=b[i];
		else d[i/2]=b[i];
	}
	sort(c+1,c+m+1,greater<int>());
	sort(d+1,d+m+1,greater<int>());
	ans=sum;
	for(int i=1;i<=m;++i){
		sum+=c[i]+d[i];
		ans=max(ans,sum);
	}
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const int MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return (c>r||c<0) ? 0:fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

int main() {
    int n;
    scanf("%d", &n);

    map<int, int> ma;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int t;
        scanf("%d", &t);
        t %= 200;

        ans += ma[t]++;
    }

    printf("%lld", ans);
}

// author: rdd6584


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

typedef long long ll;
#define pb push_back

int solve()
{
    int h, w, di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
    char c;
    cin >> h >> w;
    vector<vector<pair<int, int>>> alphabet(26);
    vector<vector<char>> grid(h, vector<char>(w));
    vector<vector<bool>> vis(h, vector<bool>(w));
    pair<int, int> cur = {0, 0};
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> grid[i][j];
            if (grid[i][j] == 'S')
            {
                cur.first = i;
                cur.second = j;
            }
            else if (grid[i][j] >= 'a' && grid[i][j] <= 'z')
            {
                alphabet[grid[i][j] - 'a'].pb({i, j});
            }
        }
    }
    int time = 1;
    queue<pair<int, int>> q;
    q.push(cur);
    vis[cur.first][cur.second] = true;
    while (!q.empty())
    {
        int len = q.size();
        while (len-- > 0)
        {
            pair<int, int> from = q.front();
            q.pop();
            for (int dir = 0; dir < 4; dir++)
            {
                int i = from.first + di[dir], j = from.second + dj[dir];
                if (i >= 0 && i < h && j >= 0 && j < w && grid[i][j] != '#' && !vis[i][j])
                {
                    if (grid[i][j] == 'G')
                        return time;
                    vis[i][j] = true;
                    q.push({i, j});
                }
            }
            if (grid[from.first][from.second] >= 'a' && grid[from.first][from.second] <= 'z')
            {
                for (pair<int, int> tel : alphabet[grid[from.first][from.second] - 'a'])
                {
                    if (grid[tel.first][tel.second] == 'G')
                        return time;
                    if (vis[tel.first][tel.second])
                        continue;
                    vis[tel.first][tel.second] = true;
                    q.push(tel);
                }
            }
        }
        time++;
    }
    return -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << solve() << "\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = s; i < (int)(n); ++i)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
typedef string::const_iterator state; //構文解析
const double PI=acos(-1);
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
    if(x>y)return x;
    else return y;
}
ll min(ll x,ll y){
    if(x<y)return x;
    else return y;
}
ll expm(ll x,ll y,ll mod=big){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1,mod)*x)%mod;
    ll t=expm(x,y/2,mod);
    return (t*t)%mod;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}

struct edge{
    ll to,cost;
};

struct graph{
    vector<vector<edge>> g;
    vector<ll> d;

    graph(ll n) : g(n),d(n,INF){}

    void addedge(const ll s,const ll t,const ll cost){
        edge e;
        e.to=t;
        e.cost=cost;
        g[s].emplace_back(e);
    }
    //E+VlogV
    void dijkstra(ll s){//sからstartのdijkstra
        d[s]=0;
        queue<P> q1,q2;
        q1.push(P(0,s));
        while(!q1.empty() || !q2.empty()){
            if(!q1.empty()){
                P pa=q1.front();q1.pop();
                ll k=pa.second;
                if(d[k]<pa.first)continue;
                for(auto e:g[k]){
                    if(d[e.to]>d[k]+e.cost){
                        d[e.to]=d[k]+e.cost;
                        if(e.cost==1)q1.push(P(d[e.to],e.to));
                        else q2.push(P(d[e.to],e.to));
                    }
                }
            }
            else{
                P pa=q2.front();q2.pop();
                ll k=pa.second;
                if(d[k]<pa.first)continue;
                for(auto e:g[k]){
                    if(d[e.to]>d[k]+e.cost){
                        d[e.to]=d[k]+e.cost;
                        if(e.cost==1)q1.push(P(d[e.to],e.to));
                        else q2.push(P(d[e.to],e.to));
                    }
                }
            }
        }
    }
};
int h,w;
int point(int i,int j){
    return i*w+j;
}
pair<int,int> point_back(int k){
    return {k/w , k%w};
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout.precision(10);
    /*--------------------------------*/

    cin >> h >> w;
    vector<vector<char>> g(h,vector<char>(w));
    map<char,vector<int>> ma;
    int s,G;
    rep(i,h)rep(j,w){
        cin >> g[i][j];
        if('a'<=g[i][j] && g[i][j] <= 'z'){
            ma[g[i][j]].emplace_back(point(i,j));
        }
        if(g[i][j]=='S'){
            s=point(i,j);
        }if(g[i][j]=='G'){
            G=point(i,j);
        }
    }
    graph gra(h*w+26);
    //全部コストを2倍で計算.
    for(char c='a';c<='z';c++){
        rep(i,ma[c].size()){
            gra.addedge(ma[c][i] , c-'a' + h*w , 1);
            gra.addedge(c-'a' + h*w , ma[c][i],1);
        }
    }
    rep(i,h)rep(j,w){
        rep(k,4){
            int ni=i+dx[k];
            int nj=j+dy[k];
            if(ni<0 || ni>=h || nj<0 || nj>=w || g[ni][nj]=='#')continue;
            gra.addedge(point(i,j),point(ni,nj),2);
        }
    }
    gra.dijkstra(s);
    if(gra.d[G]>=INF)cout << -1 << endl;
    else cout << gra.d[G]/2 << endl;
}


#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF = __LONG_LONG_MAX__;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i

signed main()
{
   int n,m;
   cin>>n>>m;
   vector<int> H(n);
   vector<int> W(m);
   for(auto &h:H) cin>>h;
   for(auto &w:W) cin>>w;
   sort(H.begin(),H.end());
   vector<int> sum(n+1,0);
   for(int i=0;i<n;i++){
    if(i&1)
        sum[i+1]=sum[i]+H[i];
    else
        sum[i+1]=sum[i]-H[i];
    }
    int res=INF;
    for(auto w:W){
        int index=lower_bound(H.begin(),H.end(),w)-H.begin();
        if(index&1)
            index--;
        int mid=abs(H[index]-w);
        int top=(-1)*(sum[n]-sum[index+1]);
        int bottom=sum[index];
        res=min(res,top+mid+bottom);
    }
    cout<<res<<endl;
    return 0;
}

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

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

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

    return true;
}
ll check(ll x)
{
    ll y=1,z=0;
    while(x>y){y*=2;z++;}
    if(x!=y){z--;}
    return z;
}
// Returns n^(-1) mod p
unsigned long long modInverse(unsigned long long n, int p)
{
    return modularExponentiation(n, p - 2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
unsigned long long nCrModPFermat(unsigned long long n,
                                 int r, int p)
{
    // Base case
    if (r == 0)
        return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    unsigned long long fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
ll modInverse(ll A,ll M)
{
    return modularExponentiation(A,M-2,M);
}
bool cmp(pair<ll,ll> a, pair<ll,ll> b)
{
    if(a.F==b.F)
        return a.S<b.S;
    else
        return a.F<b.F;
}
int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 ll n,m;
 cin>>n>>m;
 vector <ll> a(n),b(m);
 f(i,n) cin>>a[i];
 f(i,m) cin>>b[i];

 sort(all(a));
 sort(all(b));

 ll mn=1e18;

 vector <ll> start(n),end(n);
 f(i,n)
 {
     if(i%2==1) start[i]=start[i-1]+abs(a[i]-a[i-1]);
     else
          {
              if(i==0) start[i]=0;
              else     start[i]=start[i-1];
          }
 }
 for(ll i=n-1;i>=0;i--)
 {
     ll j=n-1-i;
     if(j%2==1) end[i]=end[i+1]+abs(a[i]-a[i+1]);
     else
     {
         if(j==0) end[i]=0;
         else     end[i]=end[i+1];
     }
 }
 f(i,m)
 {
     ll y=(upper_bound(a.begin(),a.end(),b[i])-a.begin());
      //cout<<y<<"\n";
     if(y%2==1)
     {
         ll val=abs(b[i]-a[y-1]);
         if((y-2)>=0) val+=start[y-2];
         if(y<n)  val+=end[y];
         //cout<<i<<' '<<val<<"\n";
         mn=min(mn,val);
     }
     else
     {
         ll val=abs(b[i]-a[y]);
         if((y-1)>=0) val+=start[y-1];
         if((y+1)<n)  val+=end[y+1];
         //cout<<i<<' '<<val<<"\n";
         mn=min(mn,val);
     }
 }
 cout<<mn<<"\n";
}


#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ld> vld;
typedef pair<int,int> Pin;
typedef long long ll;

ll INF = 3e18;
int inf = 1e9;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

template <typename T>
void print(vector<T>& x) {
    int N = x.size();
    REP(i, N) {
        if (i > 0) cout << " ";
        cout << x[i];
    }
    cout << "\n";
}

/// unrolled extgcd.
/// Solve ax + by = gcd(a, b) and return gcd(a, b).
/// x and y are returned as given args.
/// Note that a^-1 mod n can be calculated by x of extgcd(a, n, x, y)
ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll u[] = {a, 1, 0}; ll v[] = {b, 0, 1};
    while(*v) {
        ll t = *u / *v;
        REP(i, 3) swap(u[i]-=t * v[i], v[i]);
    }
    x = u[1]; y = u[2];
    return u[0]; // return gcd of a and b
}

ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

/// solve x ≡ t_i mod m_i.
/// return {ans, lcm} if there is an answer.
/// Otherwise, return {0, -1}.
pair<ll, ll> crt(const vector<ll>& r, const vector<ll>& m) {
    assert(r.size() == m.size());
    ll r0 = 0, m0 = 1; // rem == ans, lcm
    REP(i, (int) r.size()) {
        assert(1 <= m[i]);
        ll r1 = mod(r[i], m[i]), m1 = m[i];

        if (m0 < m1) swap(m0, m1), swap(r0, r1);

        if (m0 % m1 == 0) {
            if (r0 % m1 != r1) return {0, -1};
            continue;
        }

        ll x, y;
        ll g = extgcd(m0, m1, x, y);
        if ((r1 - r0) % g) return {0, -1};

        ll u1 = m1 / g;
        ll tmp = (r1 - r0) / g % u1 * x % u1;
        r0 += m0 * tmp;
        m0 *= u1;
        if (r0 < 0) r0 += m0;
    }

    return {mod(r0, m0), m0}; // => {rem, lcm}
}

void solve() {
    ll x, y, p, q;
    cin >> x >> y >> p >> q;

    ll ans = -1;
    FOR(t1, p, p + q) {
        FOR(t2, x, x + y) {
            auto [t, lcm] = crt({t1, t2}, {p + q, 2 * (x + y)});
            if (lcm == -1) continue;
            if (ans == -1) ans = t;
            else ans = min(ans, t);
        }
    }

    if (ans == -1) print("infinity");
    else print(ans);

}

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

    int t; cin >> t;

    while(t--) solve();

}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define sz(x) ((ll)(x).size())
#define ceil(x, y) (((x)+(y)-1) / (y))
#define all(x) (x).begin(),(x).end()
#define outl(...) dump_func(__VA_ARGS__)
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<ll, ll> P;
bool exceed(ll x, ll y, ll m){return x >= m / y + 1;}

struct edge{
	ll to, cost;
	edge(){}
	edge(ll a, ll b){
		to = a, cost = b;
	}
};

template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for(int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
	for(typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end(); itr++) {
		os << "(" << itr->first << ", " << itr->second << ")";
		itr++;
		if(itr != map_var.end()) os << ",";
		itr--;
	}
	return os;
}
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
	for(typename set<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) {
		os << *itr;
		++itr;
		if(itr != set_var.end()) os << " ";
		itr--;
	}
	return os;
}
void dump_func() {cout << endl;}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    cout << head;
    if(sizeof...(Tail) > 0) cout << " ";
    dump_func(std::move(tail)...);
}

ll n;
string s, x;
ll dp[200005][7];

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

	cin >> n >> s >> x;
	s = "#" + s, x = "#" + x;

	dp[n][0] = 1;
	rep(i, 1, 6) dp[n][i] = -1;

	for(int i = n-1; i >= 0; i--){
		rep(j, 0, 6){
			if(x[i+1] == 'T') dp[i][j] = max(dp[i+1][j*10%7], dp[i+1][(j*10+s[i+1]-'0')%7]);
			if(x[i+1] == 'A') dp[i][j] = min(dp[i+1][j*10%7], dp[i+1][(j*10+s[i+1]-'0')%7]);
		}
	}

	if(dp[0][0] > 0) outl("Takahashi");
	if(dp[0][0] < 0) outl("Aoki");

	return 0;
}


#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define _roverload(_a1, _a2, _a3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _roverload(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i)
#define rrep(...) _roverload(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << '\n'; }
template <class T>
void print(const vector<T>& v) {
    bool f = false;
    for (const auto& e : v) {
        if (f) cout << ' ';
        cout << e;
        f = true;
    }
    cout << '\n';
}
template <class... T>
void print(const T&... args) {
    bool f = false;
    for (const auto& e : {args...}) {
        if (f) cout << ' ';
        cout << e;
        f = true;
    }
    cout << '\n';
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
const int MOD = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    bool operator==(const mint a) const {
        return x == a.x;
    }
    bool operator!=(const mint a) const {
        return x != a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& value) {
        os << value.x;
        return os;
    }
    friend istream& operator>>(istream& is, mint& value) {
        ll t;
        is >> t;
        value = mint(t);
        return is;
    }
};

#pragma endregion library

int main() {
    int n, m;
    cin >> n >> m;
    mint mm = m;
    mint ans = mm.pow(n) * n;
    vector<mint> mpow(n + 1);
    mpow[0] = 1;
    rep(i, n) {
        mpow[i + 1] = mpow[i] * m;
    }
    rep(v, 1, m + 1) {
        vll vs(n);
        vs[0] = 1;
        mint now = 1;
        mint mv = 1;
        rep(i, 1, n) {
            ans -= now * mpow[n - i - 1];
            now *= m;
            mv *= m - v;
            now += mv;
        }
    }
    print(ans);
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    int a,b;
    a=(x+y)/2;
    b=(x-y)/2;
    cout<<a<<" "<<b<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define y1 orzkcz
using namespace std;
const int N=500005;
int n,L,a[N],b[N],p[N];
int main(){
	scanf("%d%d",&n,&L);
	For(i,1,n) scanf("%d",&a[i]);
	For(i,1,n) scanf("%d",&b[i]);
	a[n+1]=b[n+1]=L+1;
	For(i,1,n+1) a[i]-=i,b[i]-=i;
	For(i,1,n+1){
		p[i]=lower_bound(a,a+n+2,b[i])-a;
		if (a[p[i]]!=b[i]) return puts("-1"),0;
		//cout<<p[i]<<' '; cout<<endl;
	}
	ll ans=0;
	For(i,1,n+1) if (b[i]!=b[i-1]){
		int pp=p[i-1],v=max(i-1-pp,0);
		for (;a[pp+1]==a[pp];++pp) v=min(v,max(0,i-1-(pp+1)));
		ans+=v+max(p[i]-i,0);
	}
	cout<<ans<<endl;
}

/*input
10 1000000000
65110170 68805223 123016442 275946481 661490312 760727752 764540566 929355340 930658577 947099792
1 2 123016442 661490311 929355337 930658574 999999997 999999998 999999999 1000000000

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll a[maxn],b[maxn];

vector<ll> A, B;

ll ans = 0;
int main(){
	IOS;
	int n;
	ll L;
	cin>>n>>L;
	REP(i,n) cin>>a[i+1];
	REP(i,n) cin>>b[i+1];
	a[n+1] = b[n+1] = L+1;

	for(int i=0;i<n+1;i++){
		A.pb(a[i+1]-a[i]-1);
	}
	for(int i=0;i<n+1;i++){
		B.pb(b[i+1]-b[i]-1);
	}
	// cout<<A<<'\n';
	// cout<<B<<'\n';
	int pt = 0;

	REP(i,SZ(B)) if(B[i]){
		ll left = B[i];
		int first_non_zero = -1;
		while(pt<SZ(A)&&left>0){
			left -= A[pt];
			if(A[pt]!=0&& first_non_zero == -1) first_non_zero = pt;
			pt++;
		}
		if(left<0){
			cout<<"-1\n";
			return 0;
		}
		if(first_non_zero <= i && i <= pt-1){
			ans+=pt-1-first_non_zero;
		}
		else if(first_non_zero > i){
			ans += pt-1-i;
		}
		else ans += i-first_non_zero;
		// cout<<i<<' '<<first_non_zero<<' '<<pt-1<<'\n';
	}
	cout<<ans<<'\n';

	return 0;
}


/**
   Bismillahir Rahmanir Raheem
   Author:Refatul Fahad
   Bangabandhu Sheikh Mujibur Rahman Science & Technology University, Gopalganj-8100.
**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define grv(v) sort(v.begin(),v.end(),greater<int>())
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define el "\n"
#define IOS  ios_base::sync_with_stdio(false),cin.tie(NULL)
#define pr(x) cerr << #x << " ** " << x << endl;

const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const ll inf=(ll)1e18;
const double pi=2*acos(0.0);
const double esp=1e-9;

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

int main() {

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

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<a*d-b*c<<el;
    }
    return 0;
}

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

int main(){
  vector<int> A(3);
  for(int i=0;i<3;i++) cin >> A.at(i);

  sort(A.begin(),A.end());
  if(A.at(2) - A.at(1) == A.at(1) - A.at(0)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  //cout << A.at(1) << endl;
}


#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 MOD=998244353;
const lint MAX = 4000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#pragma GCC optimize("Ofast")
#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 n,d,h;
        cin>>n>>d>>h;
        P p[n];
     double ans=0;
        rep(i,n){
            lint a,b;
            cin>>a>>b;
            long double kata=(double)(h-b)/(d-a);
            ans=max(ans, double(h-kata*d));

        }

    printf("%.12f\n",ans);

        }

///Bishmillahir Rahmanir Rahim,In the name of Almighty Allah(swt)
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lop(i,n) for(i=0;i<n;i++)
#define lop1(i,n) for(i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265358979323846
#define smile ios_base::sync_with_stdio(false);	cin.tie(NULL);
//void file();
//void error();

int main()
{
	smile        //file();

	int t;
//	cin >> t;
//	for (int z = 1; z <= t; z++) {

	int n, i, j;
	int a[2][2];
	lop(i, 2) {
		lop(j, 2)
		cin >> a[i][j];
	}

	int b,c;
	b = a[0][0]*a[1][1];
	c = a[0][1]*a[1][0];
cout<<b-c<<endl;

//	}

//error();
	return 0;
}

/*
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
void error()
{
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}

*/


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

int main() {
  // 与えられた値を記録する
  // Xは18桁を超えるのでstring型としておく
  // Mは9桁を超え、18桁を超えないのでint64_t型としておく
  string X; cin >> X; int64_t M; cin >> M;
  // Xが1桁の場合は概算時に面倒なので先に算出してしまう(面倒な理由は後述)
  if (X.size() == 1) {
    // Xが1桁の場合は得られる値がXの数字そのものとなる('8'の場合8)
    // これは、Xが何進数であろうとも変わらない
    // そのため、得られる値がM超過であった場合は何進数であろうともMを超える
    // 例：X = '8', M = 7 => 得られる値は常に8なのでM以下の場合は存在しない => 0種類
    // 得られる値がM以下であった場合、何進数であろうともM以下となる
    // なので、n進数のnは無限に存在することになるが、
    // 「得られる値のうち、M以下であるようなものは"何種類"」と聞かれているので
    // 1種類ということになる
    // 例：X = '8', M = 9 => 得られる値は常に8なのでM以下は8の1種類 => 1種類
    cout << (stoll(X) <= M) << endl; return 0;
  }
  // Xに含まれる最も大きい数字dを探索する
  int64_t d = 0;
  rep(i, X.size()) if (d < stoi(string(1, X.at(i)))) {
    d = stoi(string(1, X.at(i)));
  }
  int64_t ans = (int64_t)pow(M / stoi(string(1, X.at(0))), 1 / (double)(X.size() - 1));
  ans = max(d, ans - 1);
  while (true) {
    int64_t temp = 0;
    rep(i, X.size()) {
      if (temp != 0 && temp >= LLONG_MAX / ans) goto BREAK;
      temp = temp * ans + stoi(string(1, X.at(i)));
    }
    if (temp > M) goto BREAK;
    ans++;
  }
BREAK:
  ans = max((int64_t)0, ans - d - 1);
  cout << ans << endl;
}

#include<bits/stdc++.h>

using namespace std;

#define pb push_back
const int maxN = 1e6 + 10;
int n;
string s;
int a[maxN];
vector<int> v[maxN];
unsigned long long m;

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

	assert(s[0]  > '0');

	if (s.size() == 1)
	{
		if (s[0] -'0' <= m) printf("1\n"); else
		printf("0\n");
		return 0;
	}

    unsigned long long lo = 0;
    unsigned long long ro = 2e18 + 10;
	for (int i : s)
		if (lo < i - '0') lo = i - '0';

    unsigned long long d = lo;

	while(lo < ro - 1)
	{
		unsigned long long mid = (lo + ro ) / 2;

       unsigned long long xi = 0;

       int bad = 0;
       for (int i : s)
       {
          if (m/mid < xi) {
          	 bad = 1;
          	 break;
          }
       	  xi *= mid;
       	  xi += (i-'0');
       }
       if (bad) ro = mid; else
       if (xi <= m) lo = mid; else ro = mid;
	}

	cout<<lo - d<<endl;
	return 0;
}


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

inline int read()
{
	int w=1,x=0;char f=getchar();
	while(!isdigit(f) && f!='-') f=getchar();
	if(f=='-') {w=-1;f=getchar();}
	while(isdigit(f)) {x=(x<<3)+(x<<1)+f-48;f=getchar();}
	return w*x;
}

int a,b,ans;
int main()
{
	a=read();b=read();
	ans=2*a+100-b;
	printf("%d\n",ans);
	return 0;
}

#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

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

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        map<ll,set<ll>> s;
        vector<ll> a(n), b(n);
        for(i = 0; i < n; i++){
            cin >> a[i];
            s[a[i] + i].insert(i);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        indexed_set st;
        ll ans = 0;
        for(i = 0; i < n; i++){
            ll sum = b[i] + i;
            if(s[sum].empty()){
                cout << -1 << endl;
                return 0;
            }
            ll pos = *s[sum].begin();
            ll posi = st.order_of_key(pos);
            ans += pos - posi;
            s[sum].erase(s[sum].begin());
            st.insert(pos);
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main() {

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

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

	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		--a; --b; g[a].push_back(b);
	}

	int ans = 0;
	vector<int> vis(n, 0);
	auto dfs = [&](int b, const auto & self) -> int {
		int c = 1;
		vis[b] = 1;
		for (auto i : g[b]) {
			if (!vis[i]) {
				c += self(i, self);
			}
		}
		return c;
	};

	for (int i = 0; i < n; i++) {
		vis.assign(n, 0);
		ans += dfs(i, dfs);
	}

	cout << ans << "\n";

	return 0;
}

#include <iostream>
#include <bitset>
#define REP(i, n) for (int i = 0; i < (n); i++)

std::bitset<2000>   d[2000];
int n, m, a, b, res;

int main() {
    std::cin >> n >> m;
    REP(i, n)
        d[i][i] = 1;
    REP(i, m) {
        std::cin >> a >> b;
        d[--a][--b] = 1;
    }
    REP(i, n) REP(j, n) if (d[j][i])
        d[j] |= d[i];
    REP(i, n)
        res += d[i].count();
    std::cout << res << std::endl;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	typedef tuple<int, int, int, int> T;
	vector<T> a( n );
	for( int i = 0; i < n; i++ ) {
		int x, y, r;
		cin >> x >> y >> r;
		a[i] = T( x, y, r, i );
	}

	sort( a.begin(), a.end() );
	vector<T> ans( n );
	for( int i = 0; i < n; i++ ) {
		int x, y, r, j;
		tie( x, y, r, j ) = a[i];
		if( i == 0 ) {
			int mi = INT32_MAX;
			int x0 = 0;
			int y0 = 0;
			for( int k = 0; k <= x; k++ ) {
				for( int l = 0; l <= y; l++ ) {
					int d = abs((x + 1 - k) * (y + 1 - l) - r);
					if( d < mi ) {
						mi = d;
						x0 = k;
						y0 = l;
					}
				}
			}
			ans[j] = T( x0, y0, x + 1, y + 1 );
		}
		else if( i == n - 1 ) {
			int mi = INT32_MAX;
			int x0 = 0;
			int y0 = 0;
			for( int k = 10000; k > x; k-- ) {
				for( int l = 10000; l > y; l-- ) {
					int d = abs((k - x) * (l - y) - r);
					if( d < mi ) {
						mi = d;
						x0 = k;
						y0 = l;
					}
				}
			}
			ans[j] = T( x, y, x0, y0 );
		}
		else {
			int x1, y1, r1, j1;
			tie( x1, y1, r1, j1 ) = a[i + 1];
			int x2, y2, r2, j2;
			tie( x2, y2, r2, j2 ) = a[i - 1];
			if( x == x1 || x == x2 ) {
				for( int k = i + 1; k < n; k++ ) {
					tie( x2, y2, r2, j2 ) = a[k];
					if( x2 > x ) break;
				}
				int mi = INT32_MAX;
				int x0 = -1;
				int y0 = -1;
				for( int l = y + 1; l <= y1; l++ ) {
					for( int k = x + 1; k <= x2; k++ ) {
						int d = abs((k - x) * (l - y) - r);
						if( d < mi ) {
							mi = d;
							x0 = k;
							y0 = l;
						}
					}
				}
				if( y0 < 0 ) {
					x0 = x + 1;
					y0 = y + 1;
				}
				ans[j] = T( x, y, x0, y0 );
			}
			else {
				int mi = INT32_MAX;
				int x0 = -1;
				int ll = 0;
				for( int l = 1; l <= 10000; l++ ) {
					for( int k = x + 1; k <= x1; k++ ) {
						int d = abs((k - x) * l - r);
						if( d < mi ) {
							mi = d;
							ll = l;
							x0 = k;
						}
					}
				}
				if( x0 < 0 ) {
					x0 = x + 1;
					ll = 1;
				}
				int y0 = y;
				int y2 = y + ll;
				if( y2 > 10000 ) {
					y0 = y - (y2 - 10000);
					y2 = 10000;
				}
				ans[j] = T( x, y0, x0, y2 );
			}
		}
	}
	for( int i = 0; i < n; i++ ) {
		int x, y, x1, y1;
		tie( x, y, x1, y1 ) = ans[i];
		cout << x << " " << y << " " << x1 << " " << y1 << endl;
	}
}

#include<bits/stdc++.h>
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

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

    vector<int> a(n), b(n), r(n);
    rep(i, n) cin >> a[i] >> b[i] >> r[i];

    vector<int> a_, b_, c_, d_;
    rep(i,n) {
        a_.push_back(a[i]);
        b_.push_back(b[i]);
        c_.push_back(a[i] + 1);
        d_.push_back(b[i] + 1);
    }
    rep(i, n){
        cout << a_[i] << " " << b_[i] << " " << c_[i] << " " << d_[i] << endl;
    }
    return 0;
}