#include <bits/stdc++.h>
using namespace std;
mt19937 rng(58);
typedef double db;
const int N = 10000;
bool sold[N][N];

struct rect{
	int lx, ly, rx, ry;
	rect(){}
	rect(int x, int y){
		lx = x; rx = x + 1;
		ly = y; ry = y + 1;
	}

	rect(int _lx, int _ly, int _rx, int _ry){
		lx = _lx; ly = _ly;
		rx = _rx; ry = _ry;
	}

	bool contains(int x, int y) const{
		return lx <= x && x < rx && ly <= y && y < ry;
	}

	int area() const{
		return (rx - lx) * (ry - ly);
	}

	bool intersects(const rect& other) const{
		return max(lx, other.lx) < min(rx, other.rx) && max(ly, other.ly) < min(ry, other.ry);
	}

	void write() const{
		cout << lx << ' ' << ly << ' ' << rx << ' ' << ry << endl;
	}
};

inline bool can_extend(rect& r, int dir){
	if (dir == 0){
		if (r.rx < N){
			for(int i = r.ly; i < r.ry; ++i){
				if (sold[r.rx][i]){
					return false;
				}
			}

			for(int i = r.ly; i < r.ry; ++i){
				sold[r.rx][i] = 1;
			}

			r.rx++;
			return true;
		}
	}else if (dir == 1){
		if (r.lx > 0){
			for(int i = r.ly; i < r.ry; ++i){
				if (sold[r.lx - 1][i]){
					return false;
				}
			}

			r.lx--;
			for(int i = r.ly; i < r.ry; ++i){
				sold[r.lx][i] = 1;
			}
			return true;
		}
	}else if (dir == 2){

		if (r.ry < N){
			for(int i = r.lx; i < r.rx; ++i){
				if (sold[i][r.ry]){
					return false;
				}
			}

			for(int i = r.lx; i < r.rx; ++i){
				sold[i][r.ry] = 1;
			}

			r.ry++;
			return true;
		}
	}else{
		if (r.ly > 0){
			for(int i = r.lx; i < r.rx; ++i){
				if (sold[i][r.ly - 1]){
					return false;
				}
			}

			r.ly--;
			for(int i = r.lx; i < r.rx; ++i){
				sold[i][r.ly] = 1;
			}

			return true;
		}
	}

	return false;
}

struct query{
	int x, y, r, id;
	void read(int _id){
		cin >> x >> y >> r;
		id = _id;
	}

	db score(rect R){
		if (!R.contains(x, y)) return 0;
		db val = min(r, R.area()) / (db) max(r, R.area());
		cerr << val << endl;
		return 1 - (1 - val) * (1 - val);
	}
};

int main(){
	int n; cin >> n;
	vector<query> queries(n);
	for(int i = 0; i < n; ++i){
		queries[i].read(i);
	}

	vector<rect> answer(n);
	for(int i = 0; i < n; ++i){
		answer[i] = rect(queries[i].x, queries[i].y);
		sold[queries[i].x][queries[i].y] = true;
	}

	vector<int> order(n);
	iota(order.begin(), order.end(), 0);
	sort(order.begin(), order.end(), [&](int u, int v) {return queries[u].r > queries[v].r;});

	for(int i: order){
		query q = queries[i];
		rect& answer_now = answer[i];
		vector<int> order_dir = {0, 1, 2, 3};
		while(answer_now.area() < q.r){
			shuffle(order_dir.begin(), order_dir.end(), rng);
			bool extended = false;
			for(int dir: order_dir){
				if (can_extend(answer_now, dir)){
					extended = true;
					break;
				}
			}

			if (!extended){
				break;
			}
		}
	}

	db score = 0;
	for(int i = 0; i < n; ++i){
		score += queries[i].score(answer[i]);
	}

	score /= n;
	score *= 1000000000;

	cerr << (int)score << endl;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < i; ++j){
			if (answer[i].intersects(answer[j])){
				assert(false);
			}
		}
	}

	for(int i = 0; i < n; ++i){
		answer[i].write();
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 200
#define W 10000
#define MULT 1e9

struct C {
    int x, y, r;
};

struct R {
    int a, b, c, d;
};

int per[N];
C c[N];
R ans[N];

bool cmp_xy(int l, int r)
{
    return c[l].x != c[r].x ? c[l].x < c[r].x : c[l].y < c[r].y;
}

bool cmp_yx(int l, int r)
{
    return c[l].y != c[r].y ? c[l].y < c[r].y : c[l].x < c[r].x;
}

bool cmp_r(int l, int r)
{
    return c[l].r < c[r].r;
}

bool inside(const C &com, const R &rec)
{
    return com.x >= rec.a && com.x < rec.c && com.y >= rec.b && com.y < rec.d;
}

double calc(const C &com, const R &rec)
{
    retif(!inside(com, rec)) 0.0;
    int s = (rec.c-rec.a)*(rec.d-rec.b);
    double t = 1.0-(double)min(com.r, s)/max(com.r, s);
    return 1.0-t*t;
}

double eval(int n)
{
    double res = 0.0;
    for (int i = 0; i < n; ++i) res += calc(c[i], ans[i]);
    return res*MULT/n;
}

void dumb_split(int b, int e, int xl = 0, int xh = W, int yl = 0, int yh = W)
{
    int m = -1, pos = -1;

    if (b+1 == e) {
        int u = per[b];
        ans[u] = {xl, yl, xh, yh};
        return;
    }

    sort(per+b, per+e, cmp_xy);
    for (int i = b+1; i < e; ++i) {
        int u = per[i-1], v = per[i];
        if (c[u].x != c[v].x) {
            pos = (c[u].x+c[v].x+1)/2;
            m = i;
            break;
        }
    }
    if (m >= 0) {
        dumb_split(b, m, xl, pos, yl, yh);
        dumb_split(m, e, pos, xh, yl, yh);
        return;
    }

    sort(per+b, per+e, cmp_yx);
    for (int i = b+1; i < e; ++i) {
        int u = per[i-1], v = per[i];
        if (c[u].y != c[v].y) {
            pos = (c[u].y+c[v].y+1)/2;
            m = i;
            break;
        }
    }
    assert(m >= 0);
    dumb_split(b, m, xl, xh, yl, pos);
    dumb_split(m, e, xl, xh, pos, yh);
}

int main()
{
    canhazfast();

    int n;

    /// in
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> c[i].x >> c[i].y >> c[i].r;
    iota(per, per+n, 0);

    /// 0
    /*for (int i = 0; i < n; ++i) {
        ans[i] = {c[i].x, c[i].y, c[i].x+1, c[i].y+1};
    }*/

    /// 1
    dumb_split(0, n);

    /// out
    for (int i = 0; i < n; ++i) cout << ans[i].a << ' ' << ans[i].b << ' ' << ans[i].c << ' ' << ans[i].d << '\n';
    cerr << eval(n) << '\n';

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
#include <typeinfo>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
//#define mod 1000000007LL
#define mod2 998244353LL
#define PI  3.14159265359
#define all(vec) vec.begin(),vec.end()
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
lli pmod(lli x,lli y,lli mod){lli res=1;while(y>0){if(y&1)res = ((res%mod)*(x%mod))%mod;y>>=1;x= ((x%mod)*(x%mod))%mod;}return res;}
lli power(lli x,lli y){lli res=1;while(y>0){if(y&1)res=res*x;y>>=1;x=x*x;}return res;}

lli gcd(lli a , lli b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}
lli cnt=0;

void solve(vector<vector<lli>> mat,lli a,lli b,lli row,lli col)
{

	lli x=-1,y=-1;
	fr(i,0,row)
	{fr(j,0,col)

		if(mat[i][j]==0)
			{x=i,y=j;break;}
		if(x!=-1)break;
	}
	if(x==-1){cnt++;

		return;}

	mat[x][y]=1;
	if(b>0)solve(mat,a,b-1,row,col);
	mat[x][y]=0;
	if(a>0 && x+1<row && mat[x+1][y]==0){
		mat[x][y]=2;
		mat[x+1][y]=2;solve(mat,a-1,b,row,col);
		mat[x+1][y]=0;
		mat[x][y]=0;
	}
	if(a>0 && y+1<col && mat[x][y+1]==0){
		mat[x][y]=3;
		mat[x][y+1]=3;
		solve(mat,a-1,b,row,col);
		mat[x][y]=0;
		mat[x][y+1]=0;

	}
	return;

}

int main()
{

    fio

    lli row,col,a,b;
    cin>>row>>col>>a>>b;
    vector<vector<lli>> mat(row,vector<lli>(col,0));
    solve(mat,a,b,row,col);
    cout<<cnt;

    return 0;}

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

int n, m;
bool visited[20][20];

int recur(int x, int y, int a, int b)
{
	int ret = 0;

	if (y == m)
	{
		x++;
		y = 0;
	}
	if (x == n)
	{
		return 1;
	}

	if (visited[x][y]) ret += recur(x, y + 1, a, b);
	else
	{
		if (a && y < m - 1 && !visited[x][y + 1])
		{
			visited[x][y] = true;
			visited[x][y + 1] = true;
			ret += recur(x, y + 1, a - 1, b);
			visited[x][y] = false;
			visited[x][y + 1] = false;
		}
		if (a && x < n - 1 && !visited[x + 1][y])
		{
			visited[x][y] = true;
			visited[x + 1][y] = true;
			ret += recur(x, y + 1, a - 1, b);
			visited[x][y] = false;
			visited[x + 1][y] = false;
		}
		if (b)
		{
			visited[x][y] = true;
			ret += recur(x, y + 1, a, b - 1);
			visited[x][y] = false;
		}
	}

	return ret;
}

int main()
{
	int a, b;

	cin >> n >> m >> a >> b;

	cout << recur(0, 0, a, b);
}


#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack>
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

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

ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
int r5 (int a){
    int x = a * a * a * a * a;
    return x;
}

struct  Edge {int to,id;};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v,int c = -1, int p = -1){
    int k = 1;
    REP(i,g[v].size()){
        int u = g[v][i].to, ei = g[v][i].id;
        if(u == p ) continue;
        if(c == k) k++;
        ans[ei] = k; k++;
        dfs(u,k-1,v);

    }
}

int main(){
    ll n,ans;
    string s;
    cin >> n >> s;

    vector<char> k;
    for(auto c :s){
        k.push_back(c);
        if(k.size() >= 3 && k[k.size()-3] =='f' && k[k.size()-2] == 'o' && k[k.size()-1] == 'x'){
            k.pop_back();
            k.pop_back();
            k.pop_back();
        }
    }
    cout << k.size() <<endl;
}

#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int mod=1e9+7;
const int mex=300005;
#define ll long long
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    stack<char> st;
    fo(i,0,sz(s))
    {
        if(sz(st)<2) st.push(s[i]);
        else if(s[i]=='x')
        {
            char y=st.top();
            st.pop();
            char y1=st.top();
            st.pop();
            if(y1=='f'&&y=='o') continue;
            else {
                st.push(y1);
                st.push(y);
                st.push(s[i]);
            }
        }
        else st.push(s[i]);
    }
    cout<<sz(st)<<endl;

}


#include <bits/stdc++.h>

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

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    int T;
    cin >> T;

    rep(i, T) {
        // Input
        int L, R;
        cin >> L >> R;

        // Process
        ll x = max(R - L * 2 + 1, 0);
        ll ans = x * (x + 1) / 2;

        // Output
        cout << ans << endl;
    }

    return 0;
}

#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
long long a[200100],b[200100],ma,res;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++){
		ma=max(ma,a[i]);
		res=max(res,ma*b[i]);
		cout<<res<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

class Solver {
private:
    int sy, sx, gy, gx, result;
    string ans;
public:
    void input() {
        cin >> sy >> sx >> gy >> gx;
        ans = "";
    }

    void output() {
        cout << ans << endl;
    }

    void getResult() {
        cin >> result;
    }

    void solve() {
        if(sy < gy) for(int i = 0; i < gy - sy; i++) ans += "D";
        else for(int i = 0; i < sy - gy; i++) ans += "U";
        if(sx < gx) for(int i = 0; i < gx - sx; i++) ans += "R";
        else for(int i = 0; i < sx - gx; i++) ans += "L";
    }

    void play() {
        for(int i = 0; i < 1000; i++) {
            input();
            solve();
            output();
            getResult();
        }
    }
};

int main()
{
    Solver solver;
    solver.play();
    return 0;
}

//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)
#define debug printf("Running %s on line %d...\n",__FUNCTION__,__LINE__)
using namespace std;
typedef long long ll;
const int N = 1e5+5;

int n, ans; char s[N];
template<typename T> void chkmin(T &x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T &x, T y) {if(x < y) x = y;}

int main() {
	scanf("%d%s", &n, s+1);
	if(s[1] != s[n]) return puts("1")&0;
	rep(i, 1, n-1) if(s[1] != s[i] && s[i+1] != s[n]) return puts("2")&0;
	puts("-1");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
struct Two1 {
  lint idx, AB, BA;
  bool operator < (const Two1 &other) const { return AB > other.AB; }
};
struct Two2 {
  lint idx, AB, BA;
  bool operator < (const Two2 &other) const { return BA > other.BA; }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N;
  cin >> N;
  vector<lint> A(N), B(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  lint score = 0;
  vector<lint> AB;
  vector<lint> BA;
  for(int i=0; i<N; i+=2) {
    if(A[i]+A[i+1] >= B[i]+B[i+1]) {
      score += A[i]+A[i+1];
      AB.push_back(B[i+1]-A[i+1]);
      BA.push_back(B[i]-A[i]);
    } else {
      score += B[i]+B[i+1];
      AB.push_back(A[i]-B[i]);
      BA.push_back(A[i+1]-B[i+1]);
    }
  }
  sort(ALL(AB), greater<lint>());
  sort(ALL(BA), greater<lint>());
  lint ans = score;
  REP(i, AB.size()) {
    score += AB[i] + BA[i];
    chmax(ans, score);
  }
  cout << ans << endl;
}

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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define f first
#define s second
#define nl "\n"
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int MOD = 1e9+7;
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

int n, q;
ll a, mn, mx, d, t;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  mx=1e18;
  mn=-1e18;
  d=0;
  cin >> n;
  rep(i, 1, n){
    cin >> a >> t;
    if(t==1){
      d+=a;
      mn+=a;
      mx+=a;
    }
    else if(t==2){
      if(a>mx) mx=mn=a;
      else if(a>mn) mn=a;
    }
    else{
      if(a<mn) mx=mn=a;
      else if(a<mx) mx=a;
    }
  }

  cin >> q;
  rep(i, 1, q){
    cin >> a;
    cout << min(mx, max(mn, a+d)) << nl;
  }
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vui = vector<ui>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
template <typename T>
using vv = vector<vector<T>>;
template <typename T>
using vvv = vector<vector<vector<T>>>;

struct BIT
{
	vector<ll> Data;
	int N;
	ll Init;

	BIT(int n, ll init = 0)
	{
		N = n;
		Data.resize(N + 1, init);
		Init = init;
	}

	void add(int i, ll v)
	{
		while (i <= N)
		{
			Data[i] += v;
			i += i & -i;
		}
	}

	ll getSum(int i)
	{
		auto sum = 0ll;
		while (i > 0)
		{
			sum += Data[i];
			i -= i & -i;
		}
		return sum;
	}
};

ll calc(int X, int Y, vi& a, vi& b, vi& listA, vi& listB, BIT& cntA, BIT& cntB, BIT& sumA, BIT& sumB)
{
	auto ret = 0ll;
	auto oldB = lower_bound(listB.begin(), listB.end(), a[X]) - listB.begin();
	auto newB = lower_bound(listB.begin(), listB.end(), Y) - listB.begin();
	ret -= cntB.getSum(oldB) * a[X];
	ret += cntB.getSum(newB) * Y;
	ret -= sumB.getSum(newB);
	ret += sumB.getSum(oldB);

	auto oldA = lower_bound(listA.begin(), listA.end(), a[X]) - listA.begin();
	auto newA = lower_bound(listA.begin(), listA.end(), Y) - listA.begin();
	cntA.add(oldA + 1 , -1);
	cntA.add(newA + 1, 1);
	sumA.add(oldA + 1, -a[X]);
	sumA.add(newA + 1, Y);
	a[X] = Y;
	return ret;
}

int main()
{
	int N, M, Q;
	cin >> N >> M >> Q;

	set<int> sA;
	set<int> sB;
	struct query
	{
		int T;
		int X;
		int Y;
	};
	vector<query> q(Q);
	for (auto i = 0; i < Q; ++i)
	{
		cin >> q[i].T >> q[i].X >> q[i].Y;
		--q[i].X;
		if (q[i].T == 1)
		{
			sA.insert(q[i].Y);
		}
		else
		{
			sB.insert(q[i].Y);
		}
	}
	sA.insert(0);
	sB.insert(0);
	vi listA(sA.begin(), sA.end());
	vi listB(sB.begin(), sB.end());

	auto numA = (int)listA.size();
	auto numB = (int)listB.size();
	BIT cntA(numA);
	BIT cntB(numB);
	BIT sumA(numA);
	BIT sumB(numB);
	cntA.add(1, N);
	cntB.add(1, M);

	vi a(N);
	vi b(M);
	auto ans = 0ll;

	for (auto i = 0; i < Q; ++i)
	{
		if (q[i].T == 1)
		{
			ans += calc(q[i].X, q[i].Y, a, b, listA, listB, cntA, cntB, sumA, sumB);
		}
		else
		{
			ans += calc(q[i].X, q[i].Y, b, a, listB, listA, cntB, cntA, sumB, sumA);
		}
		cout << ans << endl;
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ull unsigned long long
#define ll long long
#define ui unsigned int
#define us unsigned short
#define inf_int 1e9
#define inf_ll 1e18
#define mod 1000000007
#define smod 998244353

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);

	int n;
	cin >> n;

	vector<pair<double, int>> v;
	for(int x=0;x<n;x++){
		int t;
		double l, r;
		cin >> t >> l >> r;

		if(t == 2){
			r -= 0.1;
		} else if(t == 3){
			l += 0.1;
		} else if(t == 4){
			l += 0.1;
			r -= 0.1;
		}

		if(l <= r){
			v.push_back({l, 1});
			v.push_back({r+0.01, -1});
		}
	}

	sort(v.begin(), v.end());

	ll ans = 0, cnt = 0;
	for(int x=0;x<v.size();x++){
		pair<double, int> p = v[x];
		if(p.second == 1){
			ans += cnt;
			cnt++;
		} else {
			cnt--;
		}
//		cout << p.first << " " << p.second << " -> " << ans << "\n";
	}
	cout << ans << "\n";
    return 0;
}


# pragma GCC optimize ("O3")
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define rep2(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define x first
#define y second
using namespace std;
using ll = long long;
using tl = tuple<ll, ll, ll, ll>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
using ld = long double;

const int MAX = 2001, INF = 1e9;
const int dx[] = {1, 0}, dy[] = {0, 1};
int H, W, dp[MAX][MAX];
string S[MAX];
inline bool valid(int x, int y){
    return 0 <= x && x < H && 0 <= y && y < W;
}
inline int f(char x){
    return x == '+' ? 1 : -1;
}
int main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    cin >> H >> W;
    rep(i, 0, H) cin >> S[i];
    rep2(i, 0, H) rep2(j, 0, W){
        if(i == H - 1 && j == W - 1) continue;
        int ans = -INF;
        rep(t, 0, 2){
            int x = i + dx[t], y = j + dy[t];
            if(!valid(x, y)) continue;
            ans = max(ans, -dp[x][y] + f(S[x][y]));
        }
        dp[i][j] = ans;
    }
    if(dp[0][0] == 0) cout << "Draw";
    else if(dp[0][0] > 0) cout << "Takahashi";
    else cout << "Aoki";
}

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

#define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); }
#define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__)
#define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i]
#define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i]
#define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j]

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } }

void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void yesno(bool b) { cout << (b ? "yes" : "no") << endl; }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;

void Main() {
	map<ll, ll> mp;
	cin(int, n);
	cin(ll, C);
	rep(i, n) {
		cin(ll, a, b, c);
		mp[a] += c;
		mp[b + 1] -= c;
	}
	ll ans = 0, now = 0, pre = 0;
	for(auto [k, v] : mp) {
		ans += min(now, C)*(k - pre);
		pre = k;
		now += v;
	}
	print(ans);
}

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

	Main();
}


#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (v).size()
#define INT(...)                                                               \
    int __VA_ARGS__;                                                           \
    read(__VA_ARGS__)
#define LL(...)                                                                \
    ll __VA_ARGS__;                                                            \
    read(__VA_ARGS__)
#define DOUBLE(...)                                                            \
    double __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define CHAR(...)                                                              \
    char __VA_ARGS__;                                                          \
    read(__VA_ARGS__)
#define STRING(...)                                                            \
    string __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
    vector<type> name(size);                                                   \
    read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <class T> inline vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}

void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T> inline void read(vector<T> &v) {
    for(auto &a : v)
        read(a);
}
template <class T, class S> inline void read(pair<T, S> &p) {
    read(p.first), read(p.second);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    read(head), read(tail...);
}
template <class T> inline void chmax(T &a, T &b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T &b) { (a > b ? a = b : a); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    INT(N, W);
    cout << N / W << endl;
}

#include<string>
using namespace std;
#include<bits/stdc++.h>
#define lli long long int
#define mods 1000000007
#define pb push_back
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
int main(){
			lli n,w;
			cin>>n>>w;
            cout<<n/w;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 1000000007;
ll INF = 1000000000;

ll power(ll base, ll n){
	if (n == 0) return 1;
	if (n == 1) return base;
	ll halfn = power(base, n/2);
	if (n % 2 == 0) return (halfn * halfn) % MOD;
	return (((halfn * halfn) % MOD) * base) % MOD;
}

ll inverse(ll n){
	return power(n, MOD-2);
}

ll add(ll a, ll b){
	return (a+b) % MOD;
}

ll mul(ll a, ll b){
	return (a*b) % MOD;
}

ll gcd(ll a, ll b){
	if (a == 0) return b;
	if (a == 1) return 1;
	return gcd(b%a, a);
}

int main(){
    ios::sync_with_stdio(false);
    int a1, a2, a3; cin >> a1 >> a2 >> a3;
    int a = min(a1, min(a2, a3)), b = max(a1, max(a2, a3));
    if (3 * (a+b) == 2*(a1 + a2 + a3)){
    	cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	return 0;
}

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

int main() {

int A1,A2,A3;
cin>>A1>>A2>>A3;
if( A3-A2==A2-A1 || A3-A1==A1-A2 ||A2-A1==A1-A3 ||A2-A3==A3-A1 ||A1-A2==A2-A3 ||A1-A3==A3-A2 )
{
    cout<<"Yes"<<endl;
}
else
{
     cout<<"No"<<endl;
}
return 0;
}


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

int main(){
	string s; cin>>s;
	ll cnt=0;
	for(int k=0; k<10000; k++){
		bool ans=true;
		string r=to_string(k);
		if(r.size()<4) r=string(4-r.size(),'0')+r;
		for(int i=0; i<10; i++){
			if(s[i]=='o'){
				bool flg=false;
				for(int j=0; j<4; j++){
					if(r[j]-'0'==i) flg=true;
				}
				if(!flg) ans=false;
			}else if(s[i]=='x'){
				bool flg=true;
				for(int j=0; j<4; j++){
					if(r[j]-'0'==i) flg=false;
				}
				if(!flg) ans=false;
			}
		}
		if(ans) cnt++;
	}
	cout<<cnt<<endl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

vector<int> Fact(11);

int ncr(int n, int r){
    return (Fact[n] / (Fact[n - r] * Fact[r]));
}

void solve()
{
    string s;
    cin >> s;
    int o_c = 0, q_c = 0;
    for(char c: s){
        o_c += (c == 'o');
        q_c += (c == '?');
    }
    int ans=0;
    F(int, i, 0, 9, 1){
        if(s[i] == 'x')
            continue;
        F(int, j, 0, 9, 1){
            if(s[j] == 'x')
                continue;
            F(int, k, 0, 9, 1){
                if(s[k] == 'x')
                    continue;
                F(int, l, 0, 9, 1){
                    if(s[l] == 'x')
                        continue;
                    set<int> st;
                    st.insert(i);
                    st.insert(j);
                    st.insert(k);
                    st.insert(l);
                    int ps_g = o_c;
                    for(int x: st)
                        ps_g = ps_g - (s[x] == 'o');
                    if(ps_g > 0)
                        continue;
                    ans ++;
                }
            }
        }
    }
    cout << ans << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        // freopen("Debug.txt", "w", stderr);
    #else
    #endif
    Fact[0] = 1;
    F(int, i, 1, 10, 1){
        Fact[i] = Fact[i - 1] * i;
    }
    // cout << fixed << setprecision(10);
    // int _t;
    // cin>>_t;
    // F(int, i, 1, _t, 1){
        // cout << "Case #" << i << ": ";
        solve();
    // }
}


#include <iostream>

using namespace std;

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

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

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

int main(){
  int N;
  cin >> N;
  if(N%2 == 0){
    cout << "White" << endl;
  }
  else{
    cout << "Black" <<endl;
  }
}


#include <iostream>
using namespace std;

int main() {
    int n, w;
    cin >> n >> w;
    cout << n/w << endl;

    return 0;
}

#include <iostream>

using namespace std;

//ios::sync_with_stdio(0);
//cin.tie(0);

int main() {
    int a, b;
    cin >> a >> b;
    int mn = min(a, b);
    int mx = max(a, b);
    string ans = mn + 3 > mx ? "Yes" : "No";
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll             long long int
#define vll            vector<ll>
#define mod            1e9+7
#define endl            "\n"
#define fast           ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb             push_back
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define all(v)         v.begin(),v.end()
#define allr(v)        v.rbegin(),v.rend()
#define sz             size()
#define oup(v,n)     {for(int i=0;i<n;i++){cout <<  v[i] << " "  ;} cout << endl;
using namespace std;
int main()
{
int t=1;
//cin>>t;
while(t--)
{  ll n,m,i;
   cin>>n;
   ll ans;
    vll v;
     for(i=1;i*i<=2*n;i++)
     { if(2*n%i==0)
         {  v.pb(i);
            ans=2*n/i;
            if(i==ans)
                continue;
                else v.pb((2*n)/i);

         }
     }

     ll cnt=0;
    for(i=0;i<v.size();i++)
    {
          ans=(2*n)/v[i];
        ll chk=v[i]-1;
         if((ans-chk)%2==0)
             cnt++;
         else continue;

    }
    cout<<cnt<<endl;

}
return 0;
}

#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <cmath>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
// constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const char eol = '\n';
// --------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  N *= 2;
  int ans = 0;
  for(ll i=1; i*i<=N; i++){
    if(N%i == 0){
      ll A = N/i;
      ll B = i;
      if(A > B) swap(A,B);
      // A < B
      if((A+B-1)%2) continue;
      if((B-A-1)%2) continue;
      ll X = (A+B-1)/2;
      ll Y = (B-A-1)/2;
      if(X>Y && X>0 && Y>=0){
        ans += 2;
      }
    }
  }
  cout << ans << eol;
  return 0;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T>
inline bool dpmin(T& a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool dpmax(T& a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C) {
    if (A * A + B * B < C*C) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

// Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the
// default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    std::scanf("%lld", &A);
    long long B;
    std::scanf("%lld", &B);
    long long C;
    std::scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<iomanip>
#include<iterator>
#include<sstream>
using namespace std;
const long long mod=1000000007;
int main()
{
    long long n,m,t,a,b,k=0,h=0,r;
    cin>>n>>m>>t;
    r=n;
    while(m--)
    {
        cin>>a>>b;
        n-=(a-k);
        if(n<=0)
        {
            h++;
        }
        n+=(b-a);
        if(n>r)
        {
            n=r;
        }
        k=b;
    }
    n-=(t-k);
    if(n<=0)
    {
        h++;
    }
    if(h)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


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

signed main()
{
	int V,T,S,D;
	cin>>V>>T>>S>>D;
	if(D*1.0/V>=T&&D*1.0/V<=S) cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}

#include <bits/stdc++.h>
#ifdef local
#define debug(args...) qqbx(#args, args)
template <typename ...T> void qqbx(const char *s, T ...args) {
    int cnt = sizeof...(T);
    ((std::cerr << "(" << s << ") = (") , ... , (std::cerr << args << (--cnt ? ", " : ")\n")));
}
#else
#define debug(...) ((void)0)
#endif // local
#define pb emplace_back
#define all(v) begin(v),end(v)
#define endl '\n'
#define F first
#define S second
#define int long long
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define VI vector<int>
#define rep(i,m,n) for(int i = m;i<=n;++i)
#define res(i,m,n) for(int i = m;i>=n;--i)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define Case() int _;cin>>_;for(int Case = 1;Case<=_;++Case)
using namespace std;
signed main(){
	IOS;
	double v,t,s,d;
	cin>>v>>t>>s>>d;
	double a = d/v;

	cout<<(string)(t<=a and a<=s?"No\n":"Yes\n");
}


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

#define FOR(i,a,b) for(size_t i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

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

const ll MOD=1000000007;

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

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

	ll sum=0,s=0;

	NREP(i,n){
		sum+=i;
		if(sum>(n+1)){
			s=i;
			break;
		}
	}

	cout << n-s+2 << endl;

}

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

int main()
{
    int n;
    vector<string> s;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string temp;
        cin>>temp;
        s.push_back(temp);
    }
    long long int power[60];
    power[0] = 1;
    for(int i=1;i<=60;i++)
        power[i] = power[i-1] * 2;
    int length = s.size()-1;
    long long int ttl = 0;
    for(int i=length;i>=0;i--)
    {
        if(s[i][0] == 'O')
            ttl += power[i+1];
    }
    cout<<ttl+1<<"\n";
}


#include<stdio.h>
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=(c==45),c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x%10+48);}
static inline long Min(long a,long b){return a<b?a:b;}
static inline long Max(long a,long b){return a>b?a:b;}
int main(void)
{
  int N=IN(),A=0,T=0,Q=0,X=0;long mn=-5e18,mx=5e18,sum=0;
  while(N--)
  {
    A=IN(),T=IN();
    if(T==1){sum+=A;mn+=A;mx+=A;}
    else if(T==2){if(mn<A){mn=A;}if(mx<A){mx=A;}}
    else{if(mn>A){mn=A;}if(mx>A){mx=A;}}
  }
  Q=IN();while(Q--){X=IN();OUT(Min(Max(X+sum,mn),mx));puts("");}
}

#include<bits/stdc++.h>
#define maxn 200010
 #define int long long
// #define maxn
// #define mod
using namespace std;
const long long INF=1ll<<60;
// template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
// struct Edge{int to,next;}a[maxn];
// int h[maxn],cnt;
// void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
struct Xi{int vl,nm;}X[maxn];
bool cmp(Xi x,Xi y) {return x.vl<y.vl;}
int A[maxn],T[maxn],n,Q,pr[maxn];
int ABS(int x) {return x<0?-x:x;}
signed main()
{
//	freopen("pai.in","r",stdin);
//	freopen("pai2.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) A[i]=read(),T[i]=read();
	Q=read();
	for(int i=1;i<=Q;i++) X[i]=(Xi){read(),i};
	sort(X+1,X+1+Q,cmp);
	int l=1,r=Q,tt=0,wl=INF,wr=INF;
	for(int i=1;i<=n;i++)
		if(T[i]==1) tt+=A[i],wl+=A[i],wr+=A[i];
		else if(T[i]==2)
		{
//			cerr<<wl<<' '<<wr<<'\n';
			while(l<=Q&&l<r+1&&X[l].vl+tt<A[i]) X[l].vl=A[i]-tt,++l;
			wl=(ABS(wl-INF)<1e16?A[i]:max(A[i],wl));
			if(ABS(wr-INF)>1e16) wr=max(wr,A[i]);
//			cerr<<wl<<'?'<<wr<<'\n';
		}
		else if(T[i]==3)
		{
//			cerr<<wl<<' '<<wr<<'\n';
			while(r&&r>l-1&&X[r].vl+tt>A[i]) X[r].vl=A[i]-tt,--r;
			wr=(ABS(wr-INF)<1e16?A[i]:min(wr,A[i]));
			if(ABS(wl-INF)>1e16) wl=min(wl,A[i]);
//			cerr<<wl<<' '<<wr<<'\n';
		}
		else assert(0);
	for(int i=1;i<=l-1;i++) pr[X[i].nm]=wl;
	for(int i=r+1;i<=Q;i++) pr[X[i].nm]=wr;
	for(int i=l;i<=r;i++) pr[X[i].nm]=X[i].vl+tt;
	for(int i=1;i<=Q;i++) cout<<pr[i]<<'\n';
	return 0;
}
//			if(l-1>=r+1)
//			{
//				tt=A[i];
//				for(int j=i+1;j<=n;j++)
//					if(T[j]==1) tt+=A[j];
//					else if(T[j]==2) tt=max(tt,A[j]);
//					else if(T[j]==3) tt=min(tt,A[j]);
//					else assert(0);
//				for(int j=1;j<=Q;j++) cout<<tt<<'\n';
//				return 0;
//			}


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

using ll = long long;

bool comp(const pair<ll, ll> a, const pair<ll, ll> b) {
    if (a.first == b.first) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ll Kth(vector<pair<ll, ll>>& B, ll K) {
    auto l = lower_bound(B.begin(), B.end(), make_pair(K, INT64_MIN), comp);
    ll ans;
    if (l != B.end()) {
        ans = l->second - (l->first - K + 1);
    } else {
        l--;
        ans = l->second + (K - l->first);
    }

    return ans;
}

void Main() {
    // input
    ll N, Q;
    cin >> N >> Q;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<ll> K(Q);
    for (ll i = 0; i < Q; i++) {
        cin >> K[i];
    }

    // process
    vector<pair<ll, ll>> B(N);
    ll before = 0;
    ll count = 0;
    for (ll i = 0; i < N; i++) {
        count += A[i] - before - 1;
        before = A[i];
        B[i] = make_pair(count, A[i]);
    }

    // output
    for (ll i = 0; i < Q; i++) {
        ll ans = Kth(B, K[i]);
        cout << ans << endl;
    }

}

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

/*
 * Author: Moon-light
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define sz(x) ((int)x.size())
#define fr(x) freopen(x,'r',stdin)
#define fw(x) freopen(x,'w',stdout)
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define rep(i,a,b) for(int i = (a);i<=(b); ++i)
#define per(i,a,b) for(int i = (a);i>=(b); --i)
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VB;
typedef double db;

template <class T> void clear(T& a) { T().swap(a);}
template <class T,class S>
inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;}
template <class T,class S>
inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;}

//fast read(improved by fread)
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
inline int redi() {
    int ret = 0,f = 0;char ch = getc();
    while (!isdigit (ch)) {
        if (ch == '-') f = 1;
        ch = getc();
    }
    while (isdigit (ch)) {
        ret = ret * 10 + ch - 48;
        ch = getc();
    }
    return f?-ret:ret;
}

//global variable
const int N = 1;
const int mod = 1e9+7;

//functions
LL qmi(LL a,LL k,LL mod){
    LL res = 1;
    while(k){
        if(k&1) res = res*a%mod;
        k >>= 1;
        a = a*a%mod;
    }
    return mod;
}
int gcd(int a,int b) {
    return b==0? a:gcd(b,a%b);
}
//

//code from here! Come on! Have a pleasant experience~
int main()
{
    IO;
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    cout<<min(a,min(b,min(c,d)))<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
const int MAXN=10;
const ll MOD=1e9+7;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){if(n<k)return 0;return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
template <int _MOD> struct Mint
{
    int v = 0;
    Mint() {}
    Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {}
    Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {}
    Mint operator = (const int &_v) { return *this = Mint(_v); }
    Mint operator = (const long long &_v) { return *this = Mint(_v); }
    bool operator ! () const { return !this->v; }
    bool operator < (const Mint &b) const { return v < b.v; }
    bool operator > (const Mint &b) const { return v > b.v; }
    bool operator == (const Mint &b) const { return v == b.v; }
    bool operator != (const Mint &b) const { return v != b.v; }
    bool operator <= (const Mint &b) const { return v < b.v || v == b.v; }
    bool operator >= (const Mint &b) const { return v > b.v || v == b.v; }
    Mint operator + (const Mint &b) const { return Mint(v+b.v); }
    Mint operator - (const Mint &b) const { return Mint(v-b.v); }
    Mint operator * (const Mint &b) const { return Mint(1ll*v*b.v); }
    Mint operator / (const Mint &b) const { return Mint(b.inv()*v); }
    Mint& operator += (const Mint &b) { return *this = *this+b; }
    Mint& operator -= (const Mint &b) { return *this = *this-b; }
    Mint& operator *= (const Mint &b) { return *this = *this*b; }
    Mint& operator /= (const Mint &b) { return *this = *this/b; }
    Mint operator - () const { return Mint(-v); }
    Mint& operator ++ () { return *this += 1; }
    Mint& operator -- () { return *this -= 1; }
    Mint operator ++ (int) { Mint tmp = *this; *this += 1; return tmp; }
    Mint operator -- (int) { Mint tmp = *this; *this -= 1; return tmp; }
    Mint pow(int p) const {
        Mint res(1), x(*this);
        while (p) {
            if (p&1) res = res*x;
            x *= x;
            p >>= 1;
        }
        return res;
    }
    Mint inv() const { return pow(_MOD-2); }
    friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v; }
    friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; }
};
using mint = Mint<MOD>;
void solve(){
    int t;
    cin>>t;
    while(t--){
        ll n,a,b;
        cin>>n>>a>>b;
        if(a+b>n){
            cout<<0<<"\n";continue;
        }
        mint x=n-a+1,
        y=n-b+1,z=n-a-b+1;
        z=z*(z+1);
        z=x*y-z;
        cout<<x*x*y*y-z*z<<"\n";
    }
}
// #define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

#include <bits/stdc++.h>
constexpr int DEBUG = 0;
using namespace std;
using int64 = long long;
#define REPEAT(i, l, r) for (int i = (int)(l); i < (int)(r); i++)

using Complex = complex<double>;

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

  int n; cin >> n;
  double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
  Complex c1(x1, y1);
  Complex c2(x2, y2);
  Complex c0 = (c1 + c2) * 0.5;
  Complex c3 = (c1 - c0) * Complex(cos(M_PI * 2.0 / n), sin(M_PI * 2.0 / n)) + c0;
  cout << c3.real() << " " << c3.imag() << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100
#define INF 1000000005
#define INFLL (ll)1e17
#define ER 1e-10
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = (1<<20);
const int MOD = 998244353;

//ダイクストラ法
struct edge{int to,cost;};
vector<edge>G1[MAX],G2[MAX];
int d1[MAX],d2[MAX];
int prever[MAX];

void dijkstra(int s,int V,int d[MAX],vector<edge>G[MAX]){
    priority_queue<P,vector<P>,greater<P>>que;
    for(int i=0;i<V;i++){
        d[i]=INF;
        prever[i]=-1;
    }
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                prever[e.to]=v;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    int p=n;
    REP(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        if(a==b){
            G1[a].push_back({n,0});
            G1[n].push_back({a,c});
            G2[a].push_back({n,c});
            G2[n].push_back({a,0});
            n++;

        }else{
            G1[a].push_back({b,c});
            G2[b].push_back({a,c});
        }
    }
    REP(i,p){
        dijkstra(i,n,d1,G1);
        dijkstra(i,n,d2,G2);
        int tmp=INF;
        REP(j,n){
            if(i==j||d1[j]==INF||d2[j]==INF)continue;
            tmp=min(tmp,d1[j]+d2[j]);
        }
        if(tmp==INF)OUT(-1);
        else OUT(tmp);

    }
}
int main(){
    solve();
    return 0;
}

#include <bits/stdc++.h>
#define fir first
#define sec second
#define PB push_back
#define MP make_pair

using namespace std;

#define REP(i, _a, _b) for (int (i) = (int)(_a); (i) < (int)(_b); (i)++)
#define REV(i, _b, _a) for (int (i) = (int)(_b) - 1; (i) >= (int)(_a); (i)--)

template <class T> void chkmax(T& x, T y) { x = (x > y ? x : y); }
template <class T> void chkmin(T& x, T y) { x = (x < y ? x : y); }

typedef long long LL;
typedef pair <int, int> pi;

const int N = 2e5 + 5;

int n, m;

void bad() { printf("-1\n"); exit(0); }

int main(){
    scanf("%d%d", &n, &m);
    if (m < 0) bad();
    if (m == 0){
        REP(i, 0, n) printf("%d %d\n", 2 * i + 1, 2 * i + 2);
        return 0;
    }

    if (n < m + 2) bad();

    int l = 1, r = 2 * n;
    for (int i = 1; i <= n - m - 1; i++, l++, r--) printf("%d %d\n", l, r);
    l--, r++;
    for (int i = 0; i < m + 1; i++) printf("%d %d\n", 2 * i + 1 + l, 2 * i + 2 + l);

    return 0;
}


#include<bits/stdc++.h>                   /*--------------->Logic%2==0---------------->*/
#define CASE(t)                 printf("Case %d: ",t)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define PI                      2*acos(0.0)
#define ll                      long long int
#define endl                    '\n'
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll a[4];
cin>>a[0]>>a[1]>>a[2]>>a[3];
sort(a,a+4);

if(a[0]+a[2]==a[1]+a[3])
{
    cout<<"Yes"<<endl;
}
else if(a[0]+a[3]==a[1]+a[2])
{
    cout<<"Yes"<<endl;
}
else if(a[0]+a[1]+a[2]==a[3])
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}
/*---------->HaPpY CoDiNg----------->*/
return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define rREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define rFOR(i, a, b) for (int i = a; i >= b; --i)
#define aFOR(i, V) for (auto i : V)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
#define INF 1'000'000'007 // 10^9 + 7
#define MOD 1'000'000'007 // 10^9 + 7
#define lINF 1'000'000'000'000'000'007 // 10^18 + 7
void printv(vector<int> v) {
    REP(i, v.size() - 1) cout << v[i] << " ";
    cout << v[v.size() - 1] << endl;
}
void printv(vector<char> v) {
    REP(i, v.size() - 1) cout << v[i] << " ";
    cout << v[v.size() - 1] << endl;
}
void printv(vector<vector<int>> v) {
    aFOR(v2, v) {
        REP(i, v2.size() - 1) cout << v2[i] << " ";
        cout << v2[v2.size() - 1] << endl;
    }
}
void printv(vector<vector<char>> v) {
    aFOR(v2, v) {
        REP(i, v2.size() - 1) cout << v2[i] << " ";
        cout << v2[v2.size() - 1] << endl;
    }
}
void printv(vector<string> v) {
    aFOR(i, v) {
        cout << i << endl;
    }
}
// ------------------------------

int main() {
    vector<int> vec(4);
    int sum = 0;
    REP(i, 4) {
        cin >> vec[i];
        sum += vec[i];
    }
    int flag = 0;
    REP(i, 1 << 4) {
        int tmp1 = 0;
        int tmp2 = sum;
        REP(j, 4) {
            if (i & (1 << j)) {
                tmp1 += vec[j];
                tmp2 -= vec[j];
            }
        }
        if (tmp1 == tmp2) flag = 1;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

typedef long long          ll;
typedef long double        ld;
typedef unsigned long long ull;
typedef vector<ll>         vl;
typedef vector<vl>         vvl;
typedef pair<ll,ll>        pll;
typedef vector<pll>        vpll;

#define ff          first
#define ss          second
#define pb          push_back
#define eb          emplace_back
#define fr(i,n)     for(ll i = 0; i < n; ++i)
#define frs(i,s,n)  for(ll i = s; i < n; ++i)
#define frb(i,s,e)  for(ll i = s; i <= e; ++i)
#define rfr(i,n)    for(ll i = n-1; i >= 0; i--)
#define frbr(i,e,s) for(ll i = e; i >= s; i--)
#define all(x)      (x).begin(), (x).end()
#define sz(x)       ((ll)(x).size())

#ifdef LOCAL
#include <debugger.h>
#else
#define dbg(x...)      {}
#define dbg_arr(a,n)   {}
#define dbg_mat(m,r,c) {}
#define dbg_time()     {}
#endif

const ll MOD  = 1e9+7; // 998244353;
const ll INF  = 1e18;
const ll MAX  = 100100;

void pre()
{
  // factorizer::sieve();
  // prepare_factorials();
}

void solve()
{
  ll a, b; cin >> a >> b;
  ll s1 = 0, s2 = 0;
  while(a > 0)
  {
    s1 += (a % 10);
    a /= 10;
  }
  while(b > 0)
  {
    s2 += (b % 10);
    b /= 10;
  }
  cout << max(s1, s2) << "\n";
}

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

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

  // cout << fixed << setprecision(15);

  pre();

  ll _t = 1;
  // cin >> _t;
  frb(CASE, 1, _t)
  {
    // cout << "Case #" << CASE << ": ";
    // dbg(CASE);
    solve();
  }

  dbg_time();

  return 0;
}

#include <bits/stdc++.h>

using ll = long long;

using namespace std;

int sum(int d)
{
    int sum = 0;
    while (d > 0)
    {
        sum += d % 10;
        d /= 10;
    }
    return sum;
}

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

    cout << max(sum(a), sum(b)) << endl;
}

int main()
{
    int t = 1;
    //cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <limits.h>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll T;cin >> T;
  rep(QQQ,T){
    ll N;cin >> N;
    map<ll,ll> M;
    rep(i,N){
      ll X;cin >> X;
      M[X]++;
    }
    if(N%2==1){
      cout << "Second" << endl;
      continue;
    }
    ll Z=0;
    for (auto P : M){
      if(P.sc%2==1){
        Z=1;
      }
    }
    if(Z){
      cout << "First"<<  endl;
    }
    else{
      cout << "Second" << endl;
    }
  }
}

#include <iostream>
#include <vector>
#include <numeric>
#include <queue>
#include <iomanip>
using namespace std;
typedef double ld;

vector<pair<int, int>> v; int n;

struct DSU {
	vector<int> rank, parent;

	DSU(int _n) : rank(_n, 1), parent(_n) {
		iota(parent.begin(), parent.end(), 0);
	}

	int find(const int& u) { return parent[u] == u ? u : (parent[u] = find(parent[u])); }
	int size(int u) { return rank[find(u)]; }

	bool merge(int u, int v) {
		u = find(u); v = find(v);
		if (u == v) { return false; }
		if (rank[u] < rank[v]) { swap(u, v); }
		rank[u] += rank[v];	parent[v] = u;
		return true;
	}
};

bool intersect(int x1, int y1, int x2, int y2, ld r) {
	int dx = x1 - x2; dx *= dx;
	int dy = y1 - y2; dy *= dy;
	return dx + dy < 4 * r * r;
}

bool check(ld r) {
	DSU dsu(n + 2);
	for (int i = 0; i < n; i++) {
		int& xi = v[i].first, & yi = v[i].second;
		if (yi + r > 100 - r) { dsu.merge(i, n); }
		if (yi - r < -100 + r) { dsu.merge(i, n + 1); }
		for (int j = i + 1; j < n; j++) {
			int& xj = v[j].first, & yj = v[j].second;
			if (intersect(xi, yi, xj, yj, r)) dsu.merge(i, j);
		}
	}
	return dsu.find(n) != dsu.find(n + 1);
}

ld findMaxRadius() {
	ld l = 0.0, r = 100.0;
	while (r - l > 1e-6) {
		ld mid = (r + l) / 2;
		check(mid) ? l = mid : r = mid;
	}
	return l;
}

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

	cin >> n; v.resize(n);
	for (auto& x : v) cin >> x.first >> x.second;
	cout << fixed << setprecision(10) << findMaxRadius() << '\n';

	cin.ignore(2); return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<cstring>
#include<string>
typedef long long ll;
using namespace std;
const int MAX=0x3f3f3f;
const int MIN=-0x3f3f3f;
const int N=3e5+5;
ll a[N];
ll cnt[N];

int main()
{
	int n,k;
	cin >> n >> k;
	ll minc=MAX;
	ll maxc=MIN;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		cnt[a[i]]++;
		//maxc=max(maxc,cnt[a[i]]);
		//minc=min(minc,cnt[a[i]]);
	}
	ll res=0;
	if(cnt[0]!=0){
		while(k--){
			int i=0;
			while(cnt[i]){
				cnt[i]--;
				i++;
			}
			if(i){
				res=res+i;
			}
		}
	}
	cout << res <<endl;
	return 0;
 }

#include <bits/stdc++.h>

using namespace std;
enum Direction{
  	BACKWARD,
  	FORWARD,
  	UNDIRECTED
};
struct Edge{
  	int v, u, direction;
  	int other(int x){
      if(x == u)
        return v;
       return u;
    }
  	void set_source(int x){
    	if(x == u)
          direction = FORWARD;
      	else
          direction = BACKWARD;
    }
};

void dfs(int node, vector<bool>& vis, vector<vector<int>>& adj, vector<Edge>& edges, vector<int>& c){
  vis[node] = true;
  for(auto out : adj[node]){
    int ne = edges[out].other(node);
    if(c[node] == c[ne]){
      if(edges[out].direction == UNDIRECTED)
        edges[out].set_source(node);
      if(!vis[ne]){ // forward edge
        dfs(ne, vis, adj, edges, c);
      }
    }
  }
}

void solve(vector<vector<int>>& adj, vector<Edge>& edges, vector<int>& c){
	int n = adj.size();
  	for(auto &edge : edges){
    	if(c[edge.v] < c[edge.u])
        	edge.direction = FORWARD;
     	else if(c[edge.v] > c[edge.u])
         	edge.direction = BACKWARD;
    }
  	vector<bool> vis(n);
  	for(int i = 0;i < (int)adj.size();i++){
      if(!vis[i])
	      dfs(i, vis, adj, edges, c);
    }
}

int main(){
	int n, m;
  	cin >> n >> m;
  	vector<vector<int>> adj(n);
  	vector<Edge> edges(m);
  	vector<int> c(n);
  	for(int i = 0;i < m;i++){
      cin >> edges[i].u >> edges[i].v;
      edges[i].u -= 1;
      edges[i].v -= 1;
      edges[i].direction = UNDIRECTED;
      adj[edges[i].u].push_back(i);
      adj[edges[i].v].push_back(i);
    }
  	for(int i = 0;i < n;i++){
    	cin >> c[i];
    }
  	solve(adj, edges, c);
  	for(int i = 0;i < (int)edges.size();i++){
      if(edges[i].direction == FORWARD)
        cout << "->\n";
      else if(edges[i].direction == BACKWARD)
        cout << "<-\n";
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1002003004005006007ll;

void solve(){
  int n;cin >> n;
  ll k; cin >> k;
  vector<pair<ll,ll> > a(n);
  ll aa,bb;
  rep(i,n){
    cin >> aa >> bb;
    a[i]=make_pair(aa,bb);
  }
  sort(all(a));
  ll inde = 0;
  rep(i,n){
    if((k-(a[i].first-inde))<0){
      cout << k + inde << endl;
      return;
    }
    else {
      k -= a[i].first-inde;
      k += a[i].second;
      inde = a[i].first;
    }
  }
  cout << inde + k << endl;
  return;
}

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

  solve();
    return 0;
}

// E - Count Descendants
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
using vvi = vec<vi>;
using ll = int64_t;
using PR = pair<ll,ll>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define sz(a) int(a.size())
#define rep(i,e) for(int i=0;i<(e);++i)

vec<vi> adj, T;
vi I, O;

int dfs(int d, int p, int t){
	T[d].push_back(t);
	I[p] = t;
	for(int&c:adj[p]) t = dfs(d+1, c, t+1) + 1;
	O[p] = t;
	return t;
}

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

	adj.resize(n);
	rep(i, n-1){
		int p; cin>>p;
		adj[p-1].push_back(i+1);
	}

	T.resize(n);
	I.resize(n);
	O.resize(n);
	dfs(0, 0, 0);

	int q; cin>>q;
	while(q--){
		int u, d; cin>>u>>d;
		int r = upper_bound(all(T[d]), O[u-1]) - T[d].begin();
		int l = lower_bound(all(T[d]), I[u-1]) - T[d].begin();
		cout<< r - l <<endl;
	}
}


#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n; cin >> n;
    ll ans = n;
    for(int b=0; b<=62; b++){
        ll B = 1LL<<b;
        if(n < B) break;
        ll a = n / B;
        ll c = n - a*B;
        chmin(ans,a+b+c);
    }
    cout << ans << endl;
}

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

#define fr(i,n) for(int i = 0; i<n; i++)
typedef long long ll;
#define rmin(a,b) a = min<ll>(a,b)

//solves https://atcoder.jp/contests/abc193/tasks/abc193_e

ll div(ll a, ll b, bool ceil){
	ll ans = abs(a/b);
	bool pos = (a<0)==(b<0);
	if(a%b and ceil==pos) ans++;
	if(!pos) ans*=-1;
	return ans;
}

ll gcd_ext(ll a, ll b, ll &xo, ll &yo){
	if(b==0){
		xo = 1, yo = 0;
		return a;
	}
	ll x1, y1;
	ll g = gcd_ext(b,a%b,x1,y1);
	xo = y1;
	yo = x1-(a/b)*y1;
	return g;
}

/*
Retorna qual o menor x positivo que satisfaz
a*x + b*y = c (obviamente o y correspondente eh negativo)
(ou -1 se nao existe)

Util em CRT para achar menor r positivo que
	r = ra (mod a)
	r = rb (mod b)
	->
	a*x-b*y = rb-ra
	r = a*x + ra
*/
ll qual_sol(ll a, ll b, ll c){
	ll xo, yo;
	ll g = gcd_ext(a,b,xo,yo);
	if(c%g!=0) return -1;
	c/=g, a/=g,b/=g;
	xo*=c,yo*=c;

	ll k = div(-xo,b,b>0);

	return xo+k*b;
}

/*
	Return minimun r such that:
		r = ra (mod a)
		r = rb (mod b)
	Or -1 if no such r
*/
ll solve_crt(ll ra, ll a, ll rb, ll b){
	ll minx = qual_sol(a,-b,rb-ra);
	if(minx==-1) return minx;
	return a*minx+ra;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll t; cin >> t;
	fr(tt,t){
		ll X, Y, P, Q; cin >> X >> Y >> P >> Q;

		ll t1 = P+Q, t2 = 2*X+2*Y;
		ll ans = LLONG_MAX;
		fr(i,Q) fr(j,Y){
			ll cand = solve_crt(P+i,t1,X+j,t2);
			if(cand!=-1) rmin(ans,cand);
		}
		if(ans<LLONG_MAX){
			cout << ans << "\n";
		} else{
			cout << "infinity\n";
		}
	}
}


#include <iostream>
#include <string>
using namespace std;
using ll = long long;
int main() {
    ll N;
    cin >> N;
    for (ll i = 1; ; i++) if (stoll(to_string(i) + to_string(i)) > N) {
        cout << i - 1 << endl;
        return 0;
    }
}

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

int main() {

    long long n;
    scanf("%lld", &n);

    int ans = 0;

    for(int i = 1; ; i++) {

        string s = to_string(i);

        s += s;

        if(stoll(s) <= n) {
            ans++;
        }
        else break;
    }

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


#include <cstdio>
#include <cstring>
#include <string>
#define min(a, b) ((a) < (b) ? (a) : (b))
using namespace std;

static constexpr int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;

inline char getcha() {
	if (ci - cn == cm) {
		fread(cn, 1, cm, stdin);
		ci = cn;
	}
	return *ci++;
}

inline int getint() {
	int A = 0;
	while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	return A;
}

static struct FastOutput {
	static constexpr int BUF_SIZE = 1 << 20;
	char buf[BUF_SIZE];
	size_t buf_pos = 0;
	static constexpr int TMP_SIZE = 1 << 20;
	char tmp[TMP_SIZE];
	FILE* out = stdout;

	inline void put_char(char c) {
		buf[buf_pos++] = c;
		if (buf_pos == BUF_SIZE) {
			fwrite(buf, 1, buf_pos, out);
			buf_pos = 0;
		}
	}

	~FastOutput() { fwrite(buf, 1, buf_pos, out); }

	inline FastOutput& operator<<(char c) {
		put_char(c);
		return *this;
	}

	inline FastOutput& operator<<(const char* s) {
		while (*s) {
			put_char(*s++);
		}
		return *this;
	}

	inline FastOutput& operator<<(const string& s) {
		for (int i = 0; i < (int)s.size(); i++) {
			put_char(s[i]);
		}
		return *this;
	}

	template <typename T>
	inline char* integer_to_string(T n) {
		// beware of TMP_SIZE
		char* p = tmp + TMP_SIZE - 1;
		if (n == 0) {
			*--p = '0';
		} else {
			bool is_negative = false;
			if (n < 0) {
				is_negative = true;
				n = -n;
			}
			while (n > 0) {
				*--p = (char)('0' + n % 10);
				n /= 10;
			}
			if (is_negative) {
				*--p = '-';
			}
		}
		return p;
	}

	template <typename T>
	inline typename enable_if<is_integral<T>::value, char*>::type stringify(T n) {
		return integer_to_string(n);
	}

#if !defined(_WIN32) || defined(_WIN64)
	inline char* stringify(__int128 n) { return integer_to_string(n); }
#endif

	template <typename T>
	inline typename enable_if<is_floating_point<T>::value, char*>::type stringify(T n) {
		sprintf(tmp, "%.17f", n);
		return tmp;
	}

	template <typename T>
	inline FastOutput& operator<<(const T& n) {
		auto p = stringify(n);
		for (; *p != 0; p++) {
			put_char(*p);
		}
		return *this;
	}
} fast_output;

#define cout fast_output

static constexpr int mx = 400000;
int p[mx], cnt[mx], siz[mx];

inline int get(int x) { return p[x] == -1 ? x : p[x] = get(p[x]); }

int main() {
	int n = getint();
	memset(p, -1, sizeof(p));
	while (n--) {
		int a = get(getint() - 1), b = get(getint() - 1);
		if (a != b) {
			p[b] = a;
			cnt[a] += cnt[b];
		}
		cnt[a]++;
	}
	for (int i = 0; i < mx; i++) {
		siz[get(i)]++;
	}
	int ans = 0;
	for (int i = 0; i < mx; i++) {
		if (get(i) == i) {
			ans += min(cnt[i], siz[i]);
		}
	}
	cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
const int mod = 1e9+7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll s=0;
  rep(i,n) s+=a[i];
  modint ans = 1;
  rep(i,n+s){
    ans *= m+n-i;
    ans /= (i+1);
  }
  cout << ans << endl;

  return 0;

}


#include <iostream>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include <cstring>
#include<queue>
#include<set>
#include<stack>
#include <numeric>
using namespace std;
typedef long long ll;
ll x, y, a, b;
int main()
{
	cin >> x >> y >> a >> b;
ll ans = 0;
	while ((a - 1) * x <= b&&a*x<y&& (double)a * x <= 2e18)
	{
		x *= a;
		ans++;
	}

	cout << ans + (y - 1 - x) / b << endl;
}

// Problem : D - Takahashi Unevolved
// Contest : AtCoder - AtCoder Beginner Contest 180
// URL : https://atcoder.jp/contests/abc180/tasks/abc180_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

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

#define bug(x) cout<<#x<<"="<<x<<endl;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const ld pii=3.14159265359;
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy

int main()
{
	//binary search lag skta kya?
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll X,Y,A,B;
	cin>>X>>Y>>A>>B;
	ll ans=0;
	while(X<Y)
	{
		if(X<B/(A-1))
			X*=A,ans++;
		else
			break;
	}
	if(X>=Y)
	{
		cout<<ans-1;
		return 0;
	}
	ll val=(Y-X+B-1)/B;
	ans+=val-1;
	X+=val*B;
	cout<<ans<<nl;
	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e9+7;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        string s1, s2, s3;
        cin>>s1>>s2>>s3;
        string ans;
        for(ll i=0;i<n;i++) ans+='1';
        for(ll i=0;i<n;i++) ans+='0';
        ans+='1';
        cout<<ans<<"\n";
    }

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define REP(i,x,n) for(ll i = (x); i < (n); ++i)
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

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

int main(void)
{
    ll n, ans = 0, sum = 0, pos = 0, m = 0;
    cin >> n;
    rep(i,n){
        ll a;
        cin >> a;
        sum += a;
        m = max(sum, m);
        ans = max(ans, pos + m);
        pos += sum;
    }
    cout << ans << endl;
    return 0;
}


/**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
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; }

void solve() {
    int n; cin >> n;
    vector<int> a(n), b(n), p(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    vector<int> rp(n);
    rep(i, n) {
        cin >> p[i]; -- p[i];
        rp[p[i]] = i;
    }
    vector<bool> ok(n, 0);
    rep(i, n) {
        if(p[i] != i and a[i] <= b[p[i]]) {
            cout << -1 << "\n";
            return;
        }
        if(p[i] == i) ok[i] = 1;
    }
    vector<int> ids(n);
    iota(all(ids), 0);
    sort(all(ids), [&](int i, int j){ return b[i] > b[j];});
    vector<P> ans;
    auto f = [&](int i, int j) {
        ans.push_back({i, j});
        int pi = p[i], pj = p[j];
        p[i] = pj, p[j] =  pi;
        rp[pj] = i, rp[pi] = j;
    };
    rep(i, n) {
        int id = ids[i];
        if(rp[id] == id) continue;
        f(rp[id], id);
    }
    // rep(i, n) cerr << p[i] << " \n"[i == n - 1];
    cout << (int)ans.size() << "\n";
    rep(i, (int)ans.size()) {
        cout << ans[i].fr + 1 << " " << ans[i].sc + 1 << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

#define M1 1000000007
#define M2 998244353
#define INF 1e18
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<int>
#define vlli vector <long long>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)

/********************************************************************/
const double pi = 3.1415926535;
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/********************************************************************/
int main()
{
  FAST();

ll int n,p; cin>>n>>p;
ll int ans=p-1;
ll ans2=1;

//calculate (p-2)^(n-1)
ll int x=n-1;
ll temp=p-2;
while (x>0)
{
  if (x&1)
  {
    ans*=temp;
    ans%=M1;
  }
  temp= temp*temp;
  temp%=M1;
  x/=2;
}
cout<<ans<<endl;

}


#define _USE_MA_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

int OFFSET = 10000;

//---------- にぶたん[f,f,f,f,'t',t,t,t] ----------
template <typename BSFunc>
int binary_search(int l, int r, BSFunc isOK)
{
	int left = l - 1;
	int right = r;
	while ((right - left) > 1)
	{
		int mid = left + (right - left) / 2;
		if (isOK(mid))
			right = mid;
		else
			left = mid;
	}
	return right;
}

int func(double Xf, double Yf, double Rf)
{
	int Xd, Yd, Rd;
	Xd = llround(Xf * OFFSET);
	Yd = llround(Yf * OFFSET);
	Rd = llround(Rf * OFFSET);

	int rx = floor(Xf + Rf);
	int lx = ceil(Xf - Rf);

	int ans = 0;
	for (int x = lx; x <= rx; x++)
	{
		int target_x = Xd - (x * OFFSET);

		int sy = ceil(Yf);
		int ty = binary_search(sy, 300000LL, [&](int index)
		{
			if ((index * OFFSET - Yd) * (index * OFFSET - Yd) > Rd * Rd - target_x * target_x)
			{
				return true;
			}
			return false;
		});
		ty--;
		if ((Yd - ty * OFFSET) * (Yd - ty * OFFSET) <= Rd * Rd - target_x * target_x)
		{
			int by = binary_search(-300000LL, ty, [&](int index)
			{
				if ((Yd - index * OFFSET) * (Yd - index * OFFSET) <= Rd * Rd - target_x * target_x)
				{
					return true;
				}
				return false;
			});
			ans += (int)(ty - by) + 1;
		}
	}
	return ans;
}

signed main()
{
	long double Xf, Yf, Rf;
	cin >> Xf >> Yf >> Rf;
	cout << func(Xf, Yf, Rf);
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 k,n,m;
  cin >> k >> n >> m;
  vector<int64> a(k);
  REP(i,k)cin >> a[i];

  priority_queue<pll> que;
  vector<int64> b(k);
  int64 s = 0;
  REP(i,k){
    b[i] = m * a[i] / n;
    s += b[i];
    que.emplace(m * a[i] % n, i);
  }
  REP(i,m-s){
    b[que.top().se]++;
    que.pop();
  }
  REP(i,k){
    if(i != 0)cout << " ";
    cout << b[i];
  }
  cout << endl;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;
using int64 = long long;
// const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

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

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, M;
  cin >> N >> M;
  int x = 0;
  for(int i = 0; i < N; i++) {
    string s;
    cin >> s;
    x += count(begin(s), end(s), '1') % 2;
  }
  cout << 1LL * (N - x) * x << "\n";
}

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mkp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define sz(v) (int)v.size()
typedef long long LL;
typedef double db;
template<class T>bool ckmax(T&x,T y){return x<y?x=y,1:0;}
template<class T>bool ckmin(T&x,T y){return x>y?x=y,1:0;}
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define per(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
#define mod 998244353
inline void fmod(int&x){x-=mod,x+=x>>31&mod;}
inline int qpow(int n,int k){
	int res=1;
	for(;k;k>>=1,n=1ll*n*n%mod)
		if(k&1)res=1ll*n*res%mod;
	return res;
}
const int N=200005;
int n,m,cnt[25],fac[N],ifc[N],ans,dp[N][25],f[N];
int dfs(int val,int num){
	if(num>n)return 0;
	if(dp[val][num])return dp[val][num];
	int res=0;
	fmod(res+=f[num]);
	rep(i,!num?1:2,m){
		if(val*i>m)break;
		fmod(res+=dfs(val*i,num+1));
	}
	return dp[val][num]=res;
}
void initfac(const int&n=N-1){
	fac[0]=1;
	rep(i,1,n)fac[i]=1ll*i*fac[i-1]%mod;
	ifc[n]=qpow(fac[n],mod-2);
	per(i,n-1,0)ifc[i]=1ll*(i+1)*ifc[i+1]%mod;
}
inline int comb(int n,int m){return n<m?0:1ll*fac[n]*ifc[m]%mod*ifc[n-m]%mod;}
signed main(){
	cin>>n>>m;
	initfac();
	rep(i,1,20)f[i]=comb(n-1,i-1);
	cout<<dfs(1,0)<<'\n';
}


/*
你指尖跃动的电光，是我此生不变的信仰，唯我超电磁炮永世长存！
君指先跃动の光は、私の一生不変の信仰に、唯私の超電磁砲永世生き！

唯我超电磁炮永世长存
我心所属依旧超电磁炮
超凡入圣吾炮任可再战
电闪雷鸣炮姐征战天下
磁轨炮学园最强电击使
炮姐震古烁今吾炮赛高
永无止境炮党头顶青天
世人皆知唯我哔哩哔哩
长驱直入最强电击公主
存二次元此生无悔入炮

我炮还能再战100年
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1000005;
struct IO_Tp {
    const static int _I_Buffer_Size = 2 << 22;
    char _I_Buffer[_I_Buffer_Size], *_I_pos = _I_Buffer;

    const static int _O_Buffer_Size = 2 << 22;
    char _O_Buffer[_O_Buffer_Size], *_O_pos = _O_Buffer;

    IO_Tp() { fread(_I_Buffer, 1, _I_Buffer_Size, stdin); }
    ~IO_Tp() { fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout); }

    IO_Tp &operator>>(ll &res) {
    	ll f=1;
        while (!isdigit(*_I_pos)&&(*_I_pos)!='-') ++_I_pos;
        if(*_I_pos=='-')f=-1,++_I_pos;
        res = *_I_pos++ - '0';
        while (isdigit(*_I_pos)) res = res * 10 + (*_I_pos++ - '0');
        res*=f;
        return *this;
    }

    IO_Tp &operator<<(ll n) {
    	if(n<0)*_O_pos++='-',n=-n;
        static char _buf[10];
        char *_pos = _buf;
        do
            *_pos++ = '0' + n % 10;
        while (n /= 10);
        while (_pos != _buf) *_O_pos++ = *--_pos;
        return *this;
    }

    IO_Tp &operator<<(char ch) {
        *_O_pos++ = ch;
        return *this;
    }
} IO;
ll n,k,cnt[3*N],cnt2[3*N],cnt3[3*N];
int main(){
	IO>>n>>k;
	for(ll i=1;i<=n;i++)cnt[i]=1;
	for(ll i=1,sum=0;i<=n*2;i++){
		cnt2[i]+=sum;
		if(i<=n)sum+=cnt[i];
		else sum-=cnt[i-n];
	}
	for(ll i=1,sum=0;i<=n*3;i++){
		cnt3[i]+=sum;
		if(i<=2*n)sum+=cnt2[i];
		if(i>n)sum-=cnt2[i-n];
	}
	for(ll i=3;i<=n*3;i++)if(k<=cnt3[i]){
		for(ll j=1;j<=i-2;j++)if(k<=cnt2[i-j]){
			ll a=j;
			for(ll t=1;t<=i-j-1;t++){
				ll b=t,c=i-a-b;
				if(c<=n)k--;
				if(!k){IO<<a<<' '<<b<<' '<<c<<'\n';return 0;}
			}
		}else k-=cnt2[i-j];
	}else k-=cnt3[i];
	return 0;
}

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<limits.h>
#define IL inline
#define re register
#define LL long long
#define ULL unsigned long long
#ifdef TH
#define debug printf("Now is %d\n",__LINE__);
#else
#define debug
#endif
using namespace std;
const int N=1005;
int k;
int que[N],len;
long long n,a,b;
IL bool cmp(int x,int y){return x>y;}
IL void work(LL &x)
{
	len=a=b=0;
	re int mid=x;
	for(;mid;mid/=10)
		que[++len]=mid%10;
	sort(que+1,que+len+1);
	for(int i=1;i<=len;i++) a=a*10+que[i];
	for(int i=len;i>0;i--) b=b*10+que[i];
	x=b-a;
}
int main()
{
	cin>>n>>k;
	while(k--) work(n);
	cout<<n;
	return 0;
}


//#pragma GCC optimize ("O2")
//#pragma GCC optimize ("Ofast")
// IN THE NAME OF GOD
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;

template <typename Head>
inline void dout(Head in) {
  cerr << in << '\n';
}

int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int> (n));
  vector<int> tmp(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    bool ok = true;
    tmp = a[i];
    for (int j = 0; j < n; j++) {
      int cnt = 0;
      for (int k = 0; k < n; k++) {
        cnt += tmp[j] <= a[k][j];
      }
      ok &= cnt == n;
    }
    if (ok) {
      break;
    }
  }
//  cout << "tmp: ";
//  for (int i = 0; i < n; i++) {
//    cout << tmp[i] << ' ';
//  }
  bool exist = true;
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    int ith = a[i][0] - tmp[0];
    bool ok = true;
    for (int j = 1; j < n; j++) {
      if (a[i][j] - tmp[j] != ith) {
        ok = false;
      }
    }
    if (ok) {
      ans[i] = ith;
    }
    else {
      exist = false;
      break;
    }
  }
  if (exist) {
    cout << "Yes\n";
    for (int i = 0; i < n; i++) {
      cout << ans[i] << ' ';
    }
    cout << '\n';
    for (int i = 0; i < n; i++) {
      cout << tmp[i] << ' ';
    }
  }
  else {
    cout << "No";
  }
  return 0;
}

#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

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

const int N = 200005;

int A[N], B[N];
map<int, vi > idx;
map<int, vi >::iterator it;

class BinaryIndexTree {
  vector<int > BIT;
  int sz;

public:

  BinaryIndexTree(int _sz) {
    sz = _sz;
    BIT.resize(_sz+1, 0);
  }

  void update(int idx, int val) {
    for(int i = idx; i < sz; i += i & -i) {
      BIT[i] += val;
    }
  }

  int query(int idx) {
    int res = 0;
    for(int i = idx; i; i -= i & -i) {
      res += BIT[i];
    }
    return res;
  }

};

BinaryIndexTree bit(N);

int main() {
  int n;
  S(n);
  rep(i,0,n) {
    S(A[i]);
    A[i] += i;
    idx[A[i]].pb(i + 1);
  }

  for(it = idx.begin(); it != idx.end(); it++) {
    reverse(all(it->SS));
  }
  LL ans = 0;
  rep(i,0,n) {
    S(B[i]);
    B[i] += i;
    if(idx.find(B[i]) == idx.end() || idx[B[i]].size() == 0) {
      P(-1);
      return 0;
    }
    int num = idx[B[i]].back();
    idx[B[i]].pop_back();
    ans += i - bit.query(num);
    bit.update(num, 1);
  }
  cout << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>>xy(n);
  rep(i,n)cin >> xy[i].first >> xy[i].second;
  rep(i,n)REP(j,i + 1,n)REP(k,j + 1,n){
    auto [x1,y1] = xy[i];
    auto [x2,y2] = xy[j];
    auto [x3,y3] = xy[k];
    x1 -= x3;
    x2 -= x3;
    y1 -= y3;
    y2 -= y3;
    if(x1 * y2 == x2 * y1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

// CTRL+ALT+M
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define int long long int
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vpi vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define inf 1e18
#define ff first
#define ss  second
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(x) x.begin(),x.end()
#define endl "\n"
const int maxn=1e5;
//*! look for binary search see if dp can fit or dp with bs
//*? Set or Priority_queue
//*! Number is upto 10^5 check if a[maxn] gives something
//*? Graph Question depedencies Topo sort
//todo For a Tree its shortest Path in  dfs is same as in bfs if it is acyclic
// *! Bridge Detection:: From Backedge we take low[u]=min(low[u],tin[x])
// *! Bridge Detection:: From Child we take low[u]=min(low[u],low[x])
// *! Bridge Detection:: this is a bridge if(low[x]>tin[u])
// vi adj[maxn];
// int visited[maxn];
bool good(pii a,pii b,pii c)
{
  if((a.ff==b.ff && c.ff==b.ff)||(a.ss==b.ss && b.ss==c.ss))
  {
    return true;
  }
  int a1=b.ss-a.ss;
  int a2=b.ff-a.ff;
  int b1=c.ss-b.ss;
  int b2=c.ff-b.ff;
  if(a1*b2==a2*b1)
  {
    return true;
  }
  return false;
}
void runcases(int T)
{

  int n;
  cin>> n;
  vpi v(n);
  for(int i=0;i<n;i++){
    cin>>v[i].ff;
    cin>>v[i].ss;
  }
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      for(int k=j+1;k<n;k++)
      {
          bool f= good(v[i],v[j],v[k]);
          if(f)
          {
            cout<<"Yes\n";
            return;
          }
      }
    }
  }
  cout<<"No\n";
  return;

  //cout<<"Case #"<<T<<": ";
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    //cin >> T;
    for (int t=1;t<=T; t++) {
        runcases(t);
    }

    return 0;
}