/*
गिरते हैं शहसवार ही मैदान-ए-जंग में ।
वो तिफ़्ल क्या गिरे जो घुटनों के बल चले ।।
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int     long long int
#define ull     unsigned int
#define ld      long double
#define pb      push_back
#define pa      pair<int,int>
#define ppa     pair<pair<int,int>,int>
#define pap     pair<int,pair<int,int>>
#define v1d     vector<int>
#define v2d     vector<vector<int> >
#define vpa     vector<pair<int,int>>
#define M       1000000007
#define MN      LLONG_MIN
#define MX      LLONG_MAX
#define ff      first
#define ss      second
#define endl    "\n"
#define v1s     vector<string>
#define all(v)  v.begin(),v.end()
#define S(v)    sort(v.begin(),v.end())
#define RS(v)   sort(v.rbegin(),v.rend())
#define R(v)    reverse(v.begin(),v.end())
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define T       int tc;cin>>tc;while(tc--)
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)      for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)      for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define P1(v)       cout<<#v<<": "<<v<<endl;
#define sz(v)       (int)(v.size())
#define P2(a,b)     cout<<#a<<": "<<a<<" "<<#b<<": "<<b<<endl;
#define P3(a,b,c)   cout<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<endl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define qqq 400005
int n,m,x,y,a,b;
int fun(int k){
    if(a*k<=n&&b*k<=m)return 1;return 0;
}

void Weapons19(){
    cin>>n>>m>>x>>y>>a>>b;
    int g=__gcd(a,b);a/=g;b/=g;
    int s=1,e=1e9;
    while(s!=e){
        int k=(s+e+1)/2;
        if(fun(k))s=k;
        else e=k-1;

    }
    a*=s;b*=s;
    int x1,y1,x2,y2;
    x1=max(0ll,x-(a+1)/2);
    x2=x1+a;
    if(x2>n){
        x2=n;
        x1=n-a;
    }
    y1=max(0ll,y-(b+1)/2);
    y2=y1+b;
    if(y2>m){
        y2=m;
        y1=m-b;
    }
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2;

}

int32_t main(){

    /*
    त्यक्तवाधर्मं च लोभं च
    मोहंचो द्यमास्थिता।
    युद्ध्यध्वमनहंकारा
    यतो धर्मस्ततो जयः।।
    */

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

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

    Weapons19();

}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstdio>

using namespace std;

int n,m,k;

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	if(m<n||k<n) printf("No\n");
	else printf("Yes\n");
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A,sum=0,B;
	cin>>A;
	B=A;

	while(1)
	{

		while(B!=0)
		{
			sum+=	B%10;
			B=B/10;
		}
		if(sum%4==0)
		{
			cout<<A;
			break;
		}
		else
		{

			A=A+1;
			B=A;
			sum=0;
		}

	}

}


#include<iostream>
#include<string>
using namespace std;

int c[11], m[11], p[11];

void as(string t)
{
	if (t[1] == 's') c[t[0] - '0'] += 1;
	else if (t[1] == 'm')m[t[0] - '0'] += 1;
	else p[t[0] - '0'] += 1;
}

int ret()
{
	int i, j;
	for (i = 1; i <= 9; ++i)
	{
		if (c[i] == 3 || m[i] == 3 || p[i] == 3) return 0;
	}
	for (i = 1; i <= 9; ++i)
	{
		if (c[i] == 2 || m[i] == 2 || p[i] == 2) return 1;
	}

	int sign, flag = 0;
	for (i = 1; i <= 7; ++i)
	{
		sign = 0;
		if (c[i]) sign++;
		if (c[i+1]) sign++;
		if (c[i+2]) sign++;

		if (sign == 3) return 0;
		else if (sign == 2) flag = 1;
	}
	for (i = 1; i <= 7; ++i)
	{
		sign = 0;
		if (m[i]) sign++;
		if (m[i + 1]) sign++;
		if (m[i + 2]) sign++;

		if (sign == 3) return 0;
		else if (sign == 2) flag = 1;
	}
	for (i = 1; i <= 7; ++i)
	{
		sign = 0;
		if (p[i]) sign++;
		if (p[i + 1]) sign++;
		if (p[i + 2]) sign++;

		if (sign == 3) return 0;
		else if (sign == 2) flag = 1;
	}
	if (flag) return 1;
	else return 2;
}

int main()
{
	string word1, word2, word3;
	cin >> word1 >> word2 >> word3;
	as(word1);
	as(word2);
	as(word3);

	cout << ret();
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
char mp[30][30];
int n;
int a[50][26];
int dp[50][(1<<21)];
int dfs(int dep,int sta)
{
    int num=0;
    if(dp[dep][sta]!=inf /*|| dp[dep][sta]!=-inf*/)return dp[dep][sta];
    for(int i=0,k=dep;i<n;i++,k--)
    {
        if(sta>>i &1)
        {
            if(mp[k][i]=='a')num++;
            else if(mp[k][i]=='b')num--;
            break;
        }
    }
    if(dep>=2*n-2)return dp[dep][sta]=num;

    int &tmp=dp[dep][sta];
    if(dep%2!=0)
    {
        tmp=-inf;
        for(int i=0;i<26;i++)
        {
            int next=a[dep+1][i]&(sta|(sta<<1));
            if(next==0)continue;
            tmp=max(tmp,dfs(dep+1,next)+num);
        }
    }
    else
    {
        for(int i=0;i<26;i++)
        {
            int next=a[dep+1][i]&(sta|(sta<<1));
            if(next==0)continue;
            tmp=min(tmp,dfs(dep+1,next)+num);
        }
    }
    return tmp;
}

void pre()
{
    for(int i=0; i<2*n-1; i++)
    {
        int k=i;
        for(int j=0; j<n; j++)
        {
            if(k<0)break;
            a[i][mp[k][j]-'a']|=(1<<j);
            k--;
        }
    }

}
int main()
{
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>mp[i];
        }
        pre();
        for(int i=0;i<2*n;i++)
            for(int j=0;j<(1<<n);j++)
            {
                dp[i][j]=inf;
            }
        int res=dfs(0,1);
        if(res>0)
        {
            puts("FIRST");
            continue;
        }
        if(res<0)
        {
            puts("SECOND");
            continue;
        }
        puts("DRAW");

    }
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x)
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pl pair<ll,ll>
int main(){
	int n,m,x,y;
	ll k;
	sc(n);
	sc(m);
	scl(k);
	sc(x);
	sc(y);
	ll mini=1ll*mod*mod,maxi=-1,ser=1,a;
	if(n==1){
		a=m;
		mini=k/a;
		k=k%a;
		if(k!=0)
		maxi=mini+1;
		else
		maxi=mini;
		if(y<=k)
		ser=maxi;
		else
		ser=mini;
		cout<<maxi<<" "<<mini<<" "<<ser;
	}
	else{
		a=k/(2*(n-1)*m);
		k-=a*(2*(n-1)*m);
		ll ans[n][m];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++)
			ans[i][j]=0;
		}
		for(int i=0;i<n && k>0;i++){
			for(int j=0;j<m && k>0;j++){
				ans[i][j]++;
				k--;
			}
		}
		for(int i=n-2;i>=0 && k>0;i--){
			for(int j=0;j<m && k>0;j++){
				ans[i][j]++;
				k--;
			}
		}
		for(int i=1;i<=n-2;i++){
			for(int j=0;j<m;j++){
				ans[i][j]+=a*2;
			}
		}
		for(int j=0;j<m;j++){
			ans[0][j]+=a;
			ans[n-1][j]+=a;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				maxi=max(maxi,ans[i][j]);
				mini=min(mini,ans[i][j]);
			}
		}
		cout<<maxi<<" "<<mini<<" "<<ans[x-1][y-1];
	}
	return 0;
}


# include <iostream>
using namespace std;
long long n,i,t,ans,a,b,j,m;
int main()
{
   cin >> n;
   m = n;
   if(n % 2 != 0)
   {
     cout << 0;
     return 0;
   }
   if(n % 4 != 0)
   {
     cout << n / 4;
     return 0;
   }
   cout << n / 4 - 1;
   return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
    long long x,y,a,b;
    cin>>x>>y>>a>>b;
    cout<<setprecision(0)<<fixed<<max(abs(a-x),abs(b-y));
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double

const int MAXN = 1e6;
const int MOD = 1e9 + 7;

bool tree = true;
set<int> xs, ys;

int binpow(int a, int p) {
    if (p == 1)
        return a % MOD;

    if (!p)
        return 1;

    if (p & 1)
        return (binpow(a, p - 1) * a) % MOD;
    else
        return (binpow(a, p / 2) * binpow(a, p / 2)) % MOD;
}

vector<char> used(MAXN, false);

map<int, set<pair<int, int>>> x, y;
map<int, pair<int, int>> cbyid;

vector<vector<int>> g(MAXN);

void dfs(int v, int p = -1) {
    if (used[v]) {
        if (used[v] == 1) {
            tree = false;
        }
        used[v] = 2;
        return;
    }

    used[v] = true;
    auto coords = cbyid[v];
    xs.insert(coords.first);
    ys.insert(coords.second);

    for (auto i : g[v])
        if (i != p)
            dfs(i, v);

    used[v] = 2;
}

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

    int n, id = 0;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int xx, yy;
        cin >> xx >> yy;
        cbyid[id] = {xx, yy};
        x[xx].insert({yy, id});
        y[yy].insert({xx, id++});
    }

    for (auto i : y)
        for (set<pair<int, int>>::iterator j = i.second.begin(); j != (i.second.end()); ++j)
            if (next(j) != i.second.end())
                g[j->second].push_back(next(j)->second), g[next(j)->second].push_back(j->second);

     for (auto i : x)
        for (set<pair<int, int>>::iterator j = i.second.begin(); j != (i.second.end()); ++j)
            if (next(j) != i.second.end())
                g[j->second].push_back(next(j)->second), g[next(j)->second].push_back(j->second);

    int ans = 1;

    for (int i = 0; i <= id - 1; ++i) {
        dfs(i);

        //scout << xs.size() << ' ' << ys.size() << endl;

        ans *= max(1ll, (binpow(2, max(static_cast<size_t>(0), xs.size() + ys.size())) - tree)) % MOD;
        ans %= MOD;

        tree = true;
        xs.clear(), ys.clear();
    }

    cout << ans;

    return 0;
}


#include<bits/stdc++.h>

#define N 250005

#define fi first

#define sc second

using namespace std;

typedef pair<int , int> II;

int amount , moder;

int factor[N];

void prepare()
{

    factor[0] = 1;

    for(int i =1 ;i <= amount; i ++)

        factor[i] = (long long)factor[i-1]*i % moder;
}

void solve()
{

    prepare();

    int result = 0;

    for(int dist = 0 ; dist < amount; dist++){

        int choose = (long long)(amount-dist )*(amount - dist)%moder;

        int some = (long long)factor[dist+1] * factor[ amount - dist -1 ] %moder;

        result = ( result + (long long)choose*some%moder )%moder;
    }

    printf("%d", result );
}

int main()
{
    //freopen("main.inp", "r", stdin );

    scanf("%d %d", &amount , &moder );

    solve();
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
int power(int a, int b, int c=mod) {
	int ans=1;
	for(; b; b>>=1, a=(LL)a*a%c) {
		if(b&1) ans=(LL)ans*a%c;
	}
	return ans;
}
int a[111];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n, k, x;
	cin>>n>>k>>x;
	for(int i=1; i<=n; i++) scanf("%d", a+i);
	reverse(a+1, a+n+1);
	for(int i=1; i<=min(n, k); i++) a[i] = min(a[i], x);
	int ans = 0;
	for(int i=1; i<=n; i++) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(int len,string s){
    unordered_map<string,int> u;
    for(int i=0;i<s.length() - len + 1;i++){

        u[s.substr(i,len)]++;
        // for(auto i = u.begin();i != u.end();i++){
        //     cout<<i->first<<" "<<i->second<<endl;
        // }
        if(u[s.substr(i,len)] > 1)return true;
    }

    // cout<<u.size();
    return false;

}
int main(){
    string s;
    cin>>s;
    int n = s.length();
    // unordered_map<string,int> u;
    int l = 0,r = n-1;
    int len = 0;
    int ans = 0;
    while(l <= r){
        len = (l+r)/2;
        if(check(len,s)){
            l = len + 1;
            ans = max(ans,len);
        }
        else r = len - 1;

    }

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


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
LL N = 10000001;

LL* primes = new LL[N];
LL* primecounts = new LL[N];
LL* smallprime = new LL[N];
LL* mobiusval = new LL[N];
LL* divisorcounts = new LL[N];
LL* divisortotals = new LL[N];

LL mobius(LL n, LL p)
{
    if(n==1)
        return -1;
    else
    {
        if(smallprime[n]==p)
            return 0;
        else
            return -1*mobius(n/smallprime[n], smallprime[n]);
    }
}

int main()
{

    for(LL i=0; i<N; i++)
    {
        primes[i] = 1;
        smallprime[i] = 0;
        divisorcounts[i] = 0;
    }

    primes[0] = 0;
    primes[1] = 0;
    for(LL i=2; i< 4000; i++)
    {
        LL c = 0 ;
        while(c<N)
        {
            if(i!=c)
                primes[c] = 0;
            if(smallprime[c]==0)
                smallprime[c]=i;
            c += i;
        }
    }
    for(LL i=2; i<N; i++)
    {
        if (smallprime[i]==0)
            smallprime[i] = i;
    }

    mobiusval[0] = 0;
    primecounts[0] = 0;
    for(LL i=1; i<N; i++)
    {
        primecounts[i] = primecounts[i-1]+primes[i];
        mobiusval[i] = mobius(i,10000001);
    }

    LL n;
    cin>>n;
    LL ans = 0;

    for(LL i=2; i<n+1; i++)
        ans += mobiusval[i]*(n/i)*(n/i);
    ans -= (n-1);
    ans = ans/2;

    LL m = LL( pow((n+ 0.5), 0.5) );

    for(LL i=2; i<n+1; i++)
        divisorcounts[smallprime[i]]++;

    divisortotals[0] = 0;
    for(LL i=1; i<n+1; i++)
    {
        divisortotals[i] = divisortotals[i-1]+divisorcounts[i];
    }

    LL dis3=0,dis2;
    for(LL i=m+1; i<=n; i++)
    {
        if(primes[i]==1)
        {
            dis3+=(divisortotals[i-1] - divisortotals[n/i])*divisorcounts[i];
        }
    }

    LL a = primecounts[n] - primecounts[n/2];
    dis2 = (n-1)*(n-2)/2 - dis3 - ans;
    dis3 -= ((a)*(n-1 - a) + a*(a-1)/2);
    ans += (dis2*2+dis3*3);
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define INT long long
using namespace std;
const int NN = 5100;
INT dp[NN], t[2];
int p[2];
int main() {
	for(int i = 0; i < 2; i ++) cin >> p[i] >> t[i];
	int h, s;
	cin >> h >> s;
	for(int i = 1; i <= h; i ++) {
		dp[i] = 1e18;
		for(int j = 1; j <= h; j ++) {
			for(int k = 0; k < 2; k ++) {
				INT T = t[k] * j;
				if(T < t[k ^ 1]) continue;
				INT tmp = min(5000ll, (T - t[k^1]) / t[k^1]) * (p[k^1] - s);
				tmp += (j - 1) * (p[k] - s);
				tmp += (p[1] + p[0] - s);
				dp[i] = min(dp[i], T + dp[max(0ll, i - tmp)]);
			}
		}
		INT st = 0, ed = 1LL * 5001 * min(t[1], t[0]);
		while(st + 1 < ed) {
			INT md = (st + ed) >> 1;
			INT tmp = 0;
			for(int k = 0; k < 2; k ++) {
				tmp += (md / t[k]) * (p[k] - s);
			}
			if(tmp >= i) ed = md;
			else st = md;
		}
		dp[i] = min(dp[i], ed);
	}
	cout << dp[h] << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>

using namespace std;

int md = 1000000007;
//long long binpow(long long a, long long n) {
//	long long res = 1;
//	while (n) {
//		if (n & 1)
//		{
//			res = (res * a) % md;
//			//res %= md;
//		}
//		a = (a * a) % md;
//		//a %= md;
//		n >>= 1;
//	}
//	return res;// % md;
//}

//int gcd(int a, int b) {
//	return b ? gcd(b, a % b) : a;
//}
//int lcm(int a, int b) {
//	return a / gcd(a, b) * b;
//}
int gcd(int a, int b, int& x, int& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
bool find_any_solution(int a, int b, int c, int& x0, int& y0, int& g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
//
//void shift_solution(int& x, int& y, int a, int b, int cnt) {
//	x += cnt * b;
//	y -= cnt * a;
//}
//
//int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) {
//	int x, y, g;
//	if (!find_any_solution(a, b, c, x, y, g))
//		return 0;
//	a /= g;  b /= g;
//
//	int sign_a = a > 0 ? +1 : -1;
//	int sign_b = b > 0 ? +1 : -1;
//
//	shift_solution(x, y, a, b, (minx - x) / b);
//	if (x < minx)
//		shift_solution(x, y, a, b, sign_b);
//	if (x > maxx)
//		return 0;
//	int lx1 = x;
//
//	shift_solution(x, y, a, b, (maxx - x) / b);
//	if (x > maxx)
//		shift_solution(x, y, a, b, -sign_b);
//	int rx1 = x;
//
//	shift_solution(x, y, a, b, -(miny - y) / a);
//	if (y < miny)
//		shift_solution(x, y, a, b, -sign_a);
//	if (y > maxy)
//		return 0;
//	int lx2 = x;
//
//	shift_solution(x, y, a, b, -(maxy - y) / a);
//	if (y > maxy)
//		shift_solution(x, y, a, b, sign_a);
//	int rx2 = x;
//
//	if (lx2 > rx2)
//		swap(lx2, rx2);
//	int lx = max(lx1, lx2);
//	int rx = min(rx1, rx2);
//
//	return (rx - lx) / abs(b) + 1;
//}
const int mod = 998244353;

      // int md = 1000000007;
long long binpow(long long a, long long n)
{
	if (n == 0)return 1;
	if (n % 2 == 0)
	{
		long long b = (binpow(a, n / 2))%mod;
		return b * b%mod;
	}
	else
		return (binpow(a, n - 1) * a)%mod;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rmq.in", "r", stdin);
	//freopen("rmq.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int n;
	cin >> n;
	vector<int > v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	vector<int>ans;
	bool na = false;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (v[i] == 1 && na)
		{
			if(cnt!=0)
			ans.push_back(cnt);
			cnt = 0;
		}
		if (v[i] == 1)
		{
			na = true;
			cnt = 0;
		}
		else cnt++;

	}
	if (ans.size() == 0)
	{
		if (na)
			cout << 1;
		else cout << 0;
		return 0;
	}
	long long an = 1;
	for (int i = 0; i < ans.size(); i++)
		an*= (ans[i] + 1);
	cout << an;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
static struct IO {
	char tmp[1 << 10];
	// fast input routines - http://ideone.com/fOK6CW
	char cur;
	inline char nextChar ( )
	{
		return cur = getc (stdin);
	}
	inline char peekChar ( )
	{
		return cur;
	}
	inline operator bool ( )
	{
		return 0 != peekChar ( );
	}
	inline static bool isBlank (char c)
	{
		return (c < '-' && c);
	}
	inline bool skipBlanks ( )
	{
		while (isBlank (nextChar ( ))); return peekChar ( ) != 0;
	}
	inline IO& operator >> (char & c)
	{
		c = nextChar ( ); return *this;
	}
	inline IO& operator >> (char * buf)
	{
		if (skipBlanks ( )) {
			if (peekChar ( )) {
				*(buf++) = peekChar ( );
				while (!isBlank (nextChar ( ))) *(buf++) = peekChar ( );
			} *(buf++) = 0;
		} return *this;
	}
	inline IO& operator >> (string & s)
	{
		if (skipBlanks ( )) {
			s.clear ( ); s += peekChar ( );
			while (!isBlank (nextChar ( ))) s += peekChar ( );
		}
		return *this;
	}
	inline IO& operator >> (double & d)
	{
		if ((*this) >> tmp) sscanf (tmp, "%lf", &d); return *this;
	}
#define defineInFor(intType) \
	inline IO& operator >>(intType & n) { \
		if (skipBlanks()) { \
			int sign = +1; \
			if (peekChar() == '-') { \
				sign = -1; \
				n = nextChar() - '0'; \
			} else \
				n = peekChar() - '0'; \
			while (!isBlank(nextChar())) { \
				n += n + (n << 3) + peekChar() - 48; \
			} \
			n *= sign; \
		} \
		return *this; \
	}
	defineInFor (int)
		defineInFor (unsigned int)
		defineInFor (long long)
		defineInFor (unsigned long long)

		// fast output routines
		inline void putChar (char c)
	{
		putc (c, stdout);
	}
	inline IO& operator << (char c)
	{
		putChar (c); return *this;
	}
	inline IO& operator << (const char * s)
	{
		while (*s) putChar (*s++); return *this;
	}
	inline IO& operator << (const string & s)
	{
		for (int i = 0; i < (int) s.size ( ); ++i) putChar (s[i]); return *this;
	}
	char * toString (double d)
	{
		sprintf (tmp, "%lf%c", d, '\0'); return tmp;
	}
	inline IO& operator << (double d)
	{
		return (*this) << toString (d);
	}
#define defineOutFor(intType) \
	inline char * toString(intType n) { \
		char * p = (tmp + 30); \
		if (n) { \
			bool isNeg = 0; \
			if (n < 0) isNeg = 1, n = -n; \
			while (n) \
				*--p = (n % 10) + '0', n /= 10; \
			if (isNeg) *--p = '-'; \
		} else *--p = '0'; \
		return p; \
	} \
	inline IO& operator << (intType n) { return (*this) << toString(n); }
	defineOutFor (int)
		defineOutFor (long long)
		//defineOutFor (unsigned long long)
#define endl ('\n')
#define cout __io__
#define cin __io__
} __io__;
class TimeTracker {
	clock_t start, end;
public:
	TimeTracker ( )
	{
		start = clock ( );
	}
	~TimeTracker ( )
	{
		end = clock ( );
		fprintf (stderr, "%.3lf s\n", (double) (end - start) / CLOCKS_PER_SEC);
	}
};
template<class T> inline T mypow (T x, int n)
{
	if (n == 0)
		return 1;
	T y = 1;
	while (n > 1) {
		if (n % 2 == 0) {
			x = x*x;
			n = n / 2;
		}
		else {
			y = x*y;
			x = x*x;
			n = (n - 1) / 2;
		}
	}
	return x*y;
}
int main ( )
{
	long long nines = 9999999999LL, ans = 1LL;
	long long l, r;
	cin >> l >> r;
	TimeTracker tt;
	long long upper = mypow (10LL, (int) log10 (r) + 1);
	long long lower = mypow (10LL, (int) log10 (l) + 1);
	if (r >= upper / 2) {
		if (l <= upper / 2) {
			ans = (nines % (mypow (10LL, ((int) log10 (upper / 2) + 1))) - upper / 2)*(upper / 2);
		}
		else {
			ans = (nines % (mypow (10LL, ((int) log10 (upper / 2) + 1))) - l)*l;
		}
	}
	else {
		ans = (nines % (mypow (10LL, ((int) log10 (upper / 2) + 1))) - r)*r;
	}
	cout << ans << endl;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    long long n, m, s;
    scanf("%lld %lld %lld", &n, &m, &s);
    if (n < m)
        swap(n, m);
    if (s >= n)
        printf("%lld\n", n * m);
    else if (s >= m)
        printf("%lld\n", ((n - 1) % s + 1) * ((n - 1) / s + 1) * m);
    else
        printf("%lld\n", ((n - 1) % s + 1) * ((n - 1) / s + 1) * ((m - 1) % s + 1) * ((m - 1) / s + 1));
    return 0;
};


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if(n%4 == 1%4)cout <<8;
    else if(n%4 == 2%4)cout << 4;
    else if(n%4 == 3%4)cout << 2;
    else if(n == 0)cout << 1;
    else cout << 6;
    return 0;
}


/**
 * 生死の去来するは、ほうとうの傀儡たり。
 * 一線弛る時、落々磊々。
*/

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

#define inl inline
template <typename T> inl bool read (T &x) {
	x = 0; int f = 1; char c = getchar ();
	for (; c != EOF && !isdigit (c); c = getchar ())
		if (c == '-') f = -1;
	if (c == EOF) return 0;
	for (; c != EOF && isdigit (c); c = getchar ())
		x = (x<<1) + (x<<3) + (c^48);
	x *= f; return 1;
}
template <typename T, typename... Targs>
inl bool read (T &x, Targs&... args) {
	return read (x) && read (args...); }
template <typename T> void print (T x) {
	if (x < 0) putchar ('-'), x = -x;
	if (x > 9) print (x / 10);
	putchar ('0' + x % 10);
}
template <typename T, typename... Targs>
inl void print (T x, Targs... args) {
	print (x), putchar (' '), print (args...); }

#define reint register int
#define newl putchar('\n')
typedef long long ll;
// typedef unsigned long long ull;
// typedef __int128 lll;
// typedef long double llf;
typedef pair <int, int> pint;
#define fst first
#define scd second
#define all(p) begin (p), end (p)
using vint = vector <int>;

constexpr int N = 1<<19, P = 998244353,
	gen = 3, INF = 0x3f3f3f3f;
int n, k, m, _f; vint f, g;

inl ll fpow (ll a, ll b) {
	ll res = 1; a %= P;
	for (; b; b >>= 1) {
		if (b & 1) res = res * a % P;
		a = a * a % P;
	}
	return res;
}
inl void henkan (vint &f, int l) {
	static int tr[N], lst = tr[0] = 0;
	if (lst != l) { lst = l;
		for (int i = 1; i < 1<<l; ++i)
			tr[i] = tr[i>>1]>>1|((1<<l-1) * (i & 1)); }
	for (int i = 1; i < 1<<l; ++i)
		if (tr[i] < i) swap (f[tr[i]], f[i]);
}
#define clog2(x) ceil (log2 (x))
inl void NTT (vint &f, int l, bool rev) {
	f.resize (1<<l, 0); henkan (f, l);
	for (int len = 2; len <= 1<<l; len <<= 1) {
		const int w_n = fpow (gen, (P-1)/len);
		ll w = 1, g, h;
		for (int st = 0; st < 1<<l; st += len, w = 1)
			for (int i = st; i < st + len/2; ++i, (w *= w_n) %= P)
				g = f[i], h = f[i + len/2] * w % P,
				f[i] = (g + h) % P,
				f[i + len/2] = (P + g - h) % P;
	}
	if (!rev) return;
	const ll invl = fpow (1<<l, P - 2);
	for (int i = 0; i < 1<<l; ++i)
		f[i] = f[i] * invl % P;
	reverse (begin (f) + 1, end (f));
}

inl void pow2 (vint &f, int mod = INF) {
	int len = f.size () * 2 - 1, l = clog2 (len);
	NTT (f, l, 0);
	for (int i = 0; i < 1<<l; ++i)
		f[i] = (ll) f[i] * f[i] % P;
	NTT (f, l, 1);
	f.resize (mod < INF ? mod : len, 0);
}

int main () {
	/*  */
	read (n, k, m); f.resize (k + 1, 1);
	for (int i = n - 1; i; --i) {
		pow2 (f);
		ll sum = accumulate (begin (f) + k + 1, end (f), 0ll);
		for (int j = k; ~j; --j)
			_f = (sum + (k - j + 1ll) * f[j]) % P,
			sum += f[j], f[j] = _f;
		f.resize (k + 1);
	}
	pow2 (f); print (m < f.size () ? f[m] : 0);

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int a=max(n,m);
	int b=min(n,m);

	if(a==0||b==0){

		cout<<'0'<<endl;
		return 0;
	}

	if(a/b>=2){
		cout<<b<<endl;
	}
	else
	cout<<(a+b)/3<<endl;

}


/*
ID: lxc9021
PROG: runround
LANG: C++
*/
/** @author starLeo
 *  Standard C++ Header File For Contests
 */
//niubi
#include <iostream>
#include <fstream>
//#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <utility> //pair
#include <map>
//#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstring>
#include <climits>
//#include <malloc.h>
using namespace std;
#define R(x) scanf("%d",&(x)) //read int
#define RS(x) scanf("%s",(x)) //read string
#define PL(x) printf("%d\n",(x)) //println int
#define REP(i,n) for(int i(0),_n(n);i<_n;++i)
#define FOR(i,l,h) for(int i(l),_h(h);i<=_h;++i)
#define FORD(i,h,l) for(int i(h),_l(l);i>=_l;--i)
#define RESET(a,b) memset((a),b,sizeof(a))
#define DEBUG(exp) (cout<<(#exp)<<" = "<<(exp)<<endl)
//#define oo (1234567890LL) // 64bits
#define oo (1<<30) // 32bits
//#define oo 9999999999.0 // Double
#define eps 1e-7
typedef long long Int;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;

const int N = 33;
const int LCM = 2520;

int d[N],n;
int id[LCM+1];
Int dp[N][50][LCM+1];

Int dfs(int pos,int lcm,int sum,bool UP) {
    if(pos==-1) return sum%lcm==0? 1 : 0;
    Int& ans=dp[pos][id[lcm]][sum];
    if(UP==false && ans!=-1) return ans;
    Int ret=0;
    FOR(i,0,UP? d[pos] : 9) {
        int tlcm= i==0? lcm : lcm/__gcd(lcm,i)*i;
        int tsum= (sum*10+i)%LCM;
        ret+= dfs(pos-1,tlcm,tsum,UP&&i==d[pos]);
    }
    if(UP==false) ans=ret;
    return ret;
}

Int calc(Int x) {
    n=0;
    while(x) {
        d[n++]=x%10;
        x/=10;
    }
    return dfs(n-1,1,0,true);
}

void init() {
    int cnt=0;
    FOR(i,1,LCM) {
        if(LCM%i==0) id[i]=cnt++;
    }
    RESET(dp,-1);
}

int main() {
#ifndef StarLeo_DEBUG
//    freopen("runround.in","r",stdin);
//    freopen("runround.out","w",stdout);
#endif

    int T;
    cin>>T;
    init();
    while(T--) {
        Int a,b;
        cin>>a>>b;
        cout<< calc(b)-calc(a-1) <<endl;
    }

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 1000005
#define ll long long
#define mod 1000000007
int fac[N],inv[N],n,m,maxn,ans;
int q_pow(int x,int n){int ret=1;for(;n;n>>=1,x=(ll)x*x%mod)if(n&1)ret=(ll)ret*x%mod;return ret;}
int C(int n,int m){return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	scanf("%d%d%*d%*d",&n,&m);maxn=max(n,m);fac[0]=1;
	for(int i=1;i<=maxn;i++)fac[i]=fac[i-1]*(ll)i%mod;inv[maxn]=q_pow(fac[maxn],mod-2);
	for(int i=maxn;i;i--)inv[i-1]=(ll)i*inv[i]%mod;
	for(int i=1;i<n;i++)if(i<=m)
	{
		int tmp=(ll)C(m-1,i-1)*fac[n-2]%mod*inv[n-i-1]%mod*q_pow(m,n-i-1)%mod;
		if(i!=n-1)tmp=(ll)tmp*(i+1)%mod*q_pow(n,n-i-2)%mod;(ans+=tmp)%=mod;
	}
	printf("%d\n",ans);
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
#define maxn 200
using namespace std;
int getmaxnum(int x)//找一个数字中最大数位
{
    int max=0;
    while(x)
    {
        int s=x%10;
        if(s>max) max=s;
        x/=10;
    }
    return max;
}
int change(int x,int base)//10进制转base进制
{
    int s=0,p=1;
    while(x)
    {
        s+=x%10*p;
        x/=10;
        p*=base;
    }
    return s;
}
int main()
{
    int a,b;
    cin>>a>>b;
    int base=max(getmaxnum(a),getmaxnum(b))+1;//求基数
    int sum=change(a,base)+change(b,base);//在base进制下两数相加，求十进制结果
    int j=0;
    while(sum)//求其位数
    {
        int s=sum%base;
        sum/=base;
        j++;
    }
    cout<<j<<endl;
    return 0;
}


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

using namespace std;
using namespace chrono;
//using namespace __gnu_pbds;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define repr(i,k,n) for (int i = k; i >= n; --i)
#define mod 1000000007
#define mod1 998244353
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define vd(x) vector <x>
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define nline "\n"
#define INF 1e18
#define vll vector <long long int>
#define pii pair<int,int>
#define vii vector <int>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif

typedef long long int ll;
typedef unsigned long long ull;
typedef long double lld;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
// use less equal if you want to use as multiset
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

//modular template
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

//void _print(pbds v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
// char alf[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',

//                 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
//                };
// char alpha[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'
//                  ,'U','V','W','X'.'Y','Z'};

bool chk(string x, string y)
{
  if (y.size() < x.size())
    return false;
  else
  {
    int n1 = x.size();
    int n2 = y.size();
    int diff = n2 - n1;
    for (int i = 0; i <= diff; i++)
    {
      string sa(diff - i, '1'); string sb(i, '1');
      string temp = sa + x + sb;
      if (temp == y) return true;
    }
    return false;
  }

}

void solve() {
  ll n, m;
  cin >> n >> m;
  if (n == m)
  {
    cout << "YES\n"; return;
  }
  string a;
  string b;
  while (n > 0)
  {
    a.pb(n % 2 + '0');
    n /= 2;
  }
  while (m > 0)
  {
    b.pb(m % 2 + '0');
    m /= 2;
  }
  reverse(all(a));
  reverse(all(b));
  debug(a);
  debug(b);
  string a1 = a; a1.pb('1');
  string a2 = a;
  while (!a2.empty())
  {
    if (a2.back() == '0') a2.pop_back();
    else break;
  }
  bool ans = false;
  ans = ans | chk(a2, b); debug(ans);
  ans = ans | chk(a1, b); debug(ans);
  reverse(all(a1)); reverse(all(a2));
  ans = ans | chk(a2, b); debug(ans);
  ans = ans | chk(a1, b); debug(ans);
  ans == true ? cout << "YES\n" : cout << "NO\n";

}

int main() {
#ifndef ONLINE_JUDGE
  freopen("error.txt", "w", stderr);
#endif
  fastio();
  auto start1 = high_resolution_clock::now();
  // seive();
  int tcase; tcase = 1;
  //cin >> tcase;
  rep(tc, 0, tcase) {
    debug(tc);
    //cout << "Case #" << tc + 1 << ":" << " ";
    //debug(tc);
    solve();

  }
  auto stop1 = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop1 - start1);
#ifndef ONLINE_JUDGE
  cerr << "Time: " << duration . count() / 1000 << endl;
#endif
  return 0;
}


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

#ifdef DEBUG
#include "/home/lucas/Topcoder/debug.h"
#define dbg(args...) do {cerr << #args << ": "; debug,args; cerr << endl;} while(0)
#else
#define dbg(args...)
#endif

#define MAX 89

ll fib[MAX];

ll n, k;
ll sol[MAX];

int main() {
  ios :: sync_with_stdio(0);

  fib[0] = fib[1] = 1;
  for(int i=2; i<MAX; i++) {
    fib[i] = fib[i-1] + fib[i-2];
  }

  while (cin >> n >> k) {
    k --;

    for(int i=1; i<=n; i++) {
      if (n-i+1 >= 1 && fib[n-i+1 - 1] <= k) {
        sol[i] = i+1;
        sol[i+1] = i;
        k -= fib[n-i+1-1];
        i++;
      } else {
        sol[i] = i;
      }
    }

    for(int i=1; i<=n; i++) {
      cout << sol[i] << " \n"[i==n];
    }

  }

  return 0;
}


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

ll solve(ll a,ull b,ll p)
{
	ll res = 1;
	a=a%p;

	while(b>0)
	{

		if(b&1)
		{
			res=(res*a)%p;
		}
		b=b>>1;
		a=((a%p)*(a%p))%p;
//		a=(a*a)%p;
	}
	return res;

}

int main()
{
	ll n,m;
	cin>>n>>m;
	ll ans = solve(3,n,m);
	if(ans==0)
	{
		cout<<m-1;
		return 0;
	}
	cout<<(ans%m)-(1%m);
	return 0;

}


#include <iostream>

using namespace std;

int main(){
    long long n, k, a, b;

	cin >> n >> k;
	if(k > (n + n-1)){
	  cout << 0;
	  return 0 ;
	}
	if(k == (n + n-1) && n > 1){
	    cout << 1;
	    return 0;
	}
	if(k<=n){
		a=abs(k-n);
		b=(n-a-1)/2;
	}else{
		a=k-n;
		b=((n-a)+1)/2;
	}
	cout<<" "<<b<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define FOR(i,x,y) for(int i=x; i<=y; i++)

const int mod=int(1e9+7),MAXN=int(1e3+50);

int n,s[MAXN],br,raz,z[MAXN];
vi v[MAXN];
vector <pair<pii,int>> rez;

void dfs(int i, int ot)
{
    s[i]=1;
    for (auto j:v[i])
        if (j!=ot)
        {
            dfs(j,i);
            s[i]+=s[j];
        }
}

int centroid()
{
    dfs(1,-1);
    int c=1,ot=-1;
    while(1)
    {
        int br=1;
        for (auto j:v[c])
            if (j!=ot && 2*s[j]>=n)
            {
                br=0;
                ot=c;
                c=j;
                break;
            }
        if (br)
            break;
    }
    return c;
}

void dfs2(int i, int ot)
{
    br+=raz;
    z[i]=br;
    rez.pb({{i,ot},z[i]-z[ot]});
    for (auto j:v[i])
        if (j!=ot)
            dfs2(j,i);
}

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

    cin >> n;

    FOR(i,1,n-1)
    {
        int p,q;
        cin >> p >> q;
        v[p].pb(q);
        v[q].pb(p);
    }

    if (n==1)
    {
        exit(0);
    }
    if (n==2)
    {
        printf("1 2 1\n");
        exit(0);
    }

    int c=centroid();

    dfs(c,-1);

    vector<pii> v2,g1,g2;

    multiset<pair <int, vector<int> > > sv;

    for (auto i:v[c])
    {
        vector<int> vv{i};
        sv.insert({s[i],vv});
    }

    while (sv.size()>2)
    {
        auto pom1=*sv.begin();
        sv.erase(sv.begin());
        auto pom2=*sv.begin();
        sv.erase(sv.begin());

        vector<int> vu;
        for (auto i:pom1.sc)
            vu.pb(i);
        for (auto i:pom2.sc)
            vu.pb(i);

        sv.insert({pom1.fr+pom2.fr,vu});
    }

    auto a=*sv.begin();
    sv.erase(sv.begin());
    auto b=*sv.begin();
    sv.erase(sv.begin());

    z[c]=0;
    br=0;
    raz=1;
    for (auto i:a.sc)
        dfs2(i,c);

    br=0;
    raz=a.fr+1;

    for (auto i:b.sc)
        dfs2(i,c);

    for (auto i:rez)
        printf("%d %d %d\n",i.fr.fr,i.fr.sc,i.sc);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <chrono>
#include <climits>
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define MOD 998244353  //(1000*1000*1000+7)
#define inf1 2e9
#define inf2 2e18

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

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {
	return binPow(a, MOD - 2);
}

ll ceil_int(ll a, ll b) {
	return a / b + (a%b != 0);
}

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

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

int main() {

	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] > '0' && k>0) {
			if (i > 0 || n==1) {
				s[i] = '0';
				k--;
			}
			else if(s[i]!='1'){
				s[i] = '1';
			    k--;

			}

		}
	}
	cout << s;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,c,ans2;
    cin >> a >> b >> c;

    ll d = a, e = b , f = c;

    ll ans = min(a,min(b,c));
    a -= ans , b -= ans , c -= ans;
    ans += (a/3)+(b/3)+(c/3);
    a %= 3 , b %= 3 , c %= 3;

    if(min(f,min(d,e))>0 && (a+b+c) == 4)
        ans++;
    cout << ans << endl;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	string c;
	int flag,des,des1,len,pos;
	while(cin >> c)
	{

		flag =0;
		len = c.size ();
		des = c.find("C");
		if(des != -1)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("ODEFORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 9== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 1)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CO");
		if(des!= -1 && flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("DEFORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 8== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 2)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("COD");
		if(des != -1 && flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("EFORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 7== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 3)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODE");
		if(des != -1 && flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("FORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 6 == len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 4)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEF");
		if(des != -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("ORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 5== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 5)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFO");
		if(des != -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("RCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 4 == len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 6)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFOR");
		if(des != -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("CES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 3== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 7)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFORC");
		if(des!= -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("ES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 2== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 8)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFORCE");
		if(des!= -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("S",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 1== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 9)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFORCES");
		if(des == 0)
		{
			flag = 1;
		}
		if(flag == 1)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
using namespace std;
int x,y,z,xx,yy,zz,a[6],ans=0;
int main(){
    cin>>x>>y>>z;
    cin>>xx>>yy>>zz;
    for(int i=0;i<6;i++)cin>>a[i];
    if(y<0)ans+=a[0];
    else if(y>yy)ans+=a[1];
    if(z<0)ans+=a[2];
    else if(z>zz)ans+=a[3];
    if(x<0)ans+=a[4];
    else if(x>xx)ans+=a[5];
    cout<<ans;
}


#include<stdio.h>
int main()
{
	int n, k, a, t = 0, count = 0;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n && k > 0; i++) {
		scanf("%d", &a);
		t += a;
		if (t >= 8) {
			k -= 8;
			t -= 8;
		}

		else {
			k -= t;
			t -= t;
		}
		count++;
	}
	if (k > 0 && n > 0)
		printf("-1");

	else
		printf("%d", count);
}


#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <functional>
#include <map>
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef vector<int, int> vipi;
typedef pair<pii,double> pid;
typedef pair<pii,int> piii;
typedef pair<double,double> pdd;
typedef pair<pdd,pdd> pddpdd;
typedef pair<pdd,double> pddd;
typedef pair<pddpdd,double> ppddpddd;
typedef pair<pii, pdd > ppid;
const static int INF = 1000000000;

int n,m;
int total = 0;
int p=0,v=0,p1=0,v1=0;
int sebelum=-1;
int ctr = 0;
int main(){
    scanf("%d%d",&n,&m);
    int a=n,b=m;
    while(n || m){
        if(sebelum == -1){
            sebelum = 2;
            m--;
        }else if(sebelum == 1){
            if(ctr%2){
                if(m > 0){
                    v++;
                    sebelum = 2;
                    m--;
                }else{
                    p++;
                    n--;
                }
            }else{
                if(n > 0){
                    p++;
                    n--;
                }else{
                    v++;
                    sebelum = 2;
                    m--;
                }
            }
        }else if(sebelum == 2){
            if(ctr%2){
                if(n > 0){
                    v++;
                    sebelum = 1;
                    n--;
                }else{
                    p++;
                    sebelum = 2;
                    m--;
                }
            }else{
                if(m > 0){
                    p++;
                    sebelum = 2;
                    m--;
                }else{
                    sebelum = 1;
                    v++;
                    n--;
                }
            }
        }
        ctr++;
    }
    ctr =0;
    sebelum = -1;
    while(a || b){
        if(sebelum == -1){
            sebelum = 1;
            a--;
        }else if(sebelum == 1){
            if(ctr%2){
                if(b > 0){
                    v1++;
                    sebelum = 2;
                    b--;
                }else{
                    p1++;
                    a--;
                }
            }else{
                if(a > 0){
                    p1++;
                    a--;
                }else{
                    v1++;
                    sebelum = 2;
                    b--;
                }
            }
        }else if(sebelum == 2){
            if(ctr%2){
                if(a > 0){
                    v1++;
                    sebelum = 1;
                    a--;
                }else{
                    p1++;
                    b--;
                }
            }else{
                if(b > 0){
                    p1++;
                    b--;
                }else{
                    sebelum = 1;
                    v1++;
                    a--;
                }
            }
        }
        ctr++;
    }
    if(p > p1){
        printf("%d %d\n",p,v);
    }else
        printf("%d %d\n",p1,v1);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

map<char,int> data;

int convertion(string number,int base){
	int ans = 1*data[number[number.size()-1]];
	int pot = base;
	for (int i = number.size()-2; i >= 0; --i)
	{
		ans += pot*data[number[i]];
		pot *= base;
	}
	return ans;
}
int main(){
	data['0'] = 0;
	data['1'] = 1;
	data['2'] = 2;
	data['3'] = 3;
	data['4'] = 4;
	data['5'] = 5;
	data['6'] = 6;
	data['7'] = 7;
	data['8'] = 8;
	data['9'] = 9;
	data['A'] = 10;
	data['B'] = 11;
	data['C'] = 12;
	data['D'] = 13;
	data['E'] = 14;
	data['F'] = 15;
	data['G'] = 16;
	data['H'] = 17;
	data['I'] = 18;
	data['J'] = 19;
	data['K'] = 20;
	data['L'] = 21;
	data['M'] = 22;
	data['N'] = 23;
	data['O'] = 24;
	data['P'] = 25;
	data['Q'] = 26;
	data['R'] = 27;
	data['S'] = 28;
	data['T'] = 29;
	data['U'] = 30;
	data['V'] = 31;
	data['W'] = 32;
	data['X'] = 33;
	data['Y'] = 34;
	data['Z'] = 35;
	string x;
	int y;
	cin >> x;
	int ini = INT_MAX;
	int end = -1;
	string hour = "";
	string minute = "";
	bool sw = false;
	for (int i = 0; i < x.size(); ++i)
	{
		if(x[i]==':'){
			sw = true; continue;
		}
		if(!sw) hour += x[i];
		else minute += x[i];
	}
	for (int i = 0; i < x.size(); ++i)
		end = max(end,data[x[i]]);
	vector<int> ans;
	for (int i = end+1; i <= 60; ++i)
	{
		int h = convertion(hour,i);
		int m = convertion(minute,i);
		if(h < 24 and m < 60) ans.push_back(i);
	}

	if(ans.size() == 0) cout << 0;
	else if(ans[ans.size()-1] == 60) cout << -1;
	else{
		for (int i = 0; i < ans.size(); ++i)
			cout << ans[i] << " ";

	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int inf = 0x3f3f3f3f;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,k,ans,a[7],b[7],c[7][7],dp[20000][7][7][5];
struct node {int a[7];node() {memset(a,0,sizeof a);} };
int get(node s)
{
	int x=0;
	for(int i=1;i<=n;i++) x=x*5+s.a[i];
	return x;
}
node back(int x)
{
	node s;
	for(int i=n;i>=1;i--) s.a[i]=x%5,x/=5;
	return s;
}
int check(node s)
{
	for(int i=1;i<=n;i++)
		if(s.a[i]<a[i]) return 0;
	return 1;
}
signed main()
{
	n=read();m=read();k=1;
	for(int i=1;i<=n;i++)
		a[i]=read(),k*=5;
	for(int i=1;i<=m;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			c[i][j]=read();
	memset(dp,0x3f,sizeof dp);
	ans=inf;dp[0][1][1][0]=0;
	for(int s=0;s<k;s++)
	{
		node t=back(s);int f=1;
		for(int i=1;i<=n;i++)
			if(t.a[i]>a[i]) f=0;
		if(!f) continue;//this state is illegal
		for(int j=1;j<=m;j++)
			for(int i=1;i<=n;i++)
				for(int r=0;r<5;r++)
				{
					if(r>b[j]) break;
					for(int f=0;f<5;f++)
					{
						if(r+f>b[j] || t.a[i]+f>a[i]) break;
						node tt=t;tt.a[i]+=f;
						int ts=get(tt),ti=i+1,tj=j,tr=r+f,ad=f?c[i][j]:0;
						if(ti>n) ti=1,tj++,tr=0;
						if(check(tt)) ans=min(ans,dp[s][i][j][r]+ad);
						if(tj<=m)
							dp[ts][ti][tj][tr]=min(dp[ts][ti][tj][tr],dp[s][i][j][r]+ad);
					}
				}
	}
	if(ans>=inf) puts("-1");
	else printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,k;
   // top:
    cin>>n>>m>>k;
    int x=1,y=1;
    if(k<n)
    {
        cout<<x+k<<" "<<y<<endl;//goto top;
        return 0;
    }
    if(k==(n*m)-1)
    {
        cout<<1<<" "<<2<<endl;//goto top;
        return 0;
    }
    k=k-n;
    if(k%(m-1)==0)
    {
        k=k/(m-1);
        if(k%2==0)
            y=2;
        else
            y=m;
        x=n-k;
    }
    else
    {
        int t=k%(m-1);
        if((k/(m-1))%2==0)
            y=2+t;
        else
            y=m-t;
        k=k/(m-1);
        x=n-k;
    }
    cout<<x<<" "<<y<<endl;
    //goto top;
    return 0;
}


#include<stdio.h>
int main(){
int a,b,c,n,f=0;
scanf("%d%d%d%d",&a,&b,&c,&n);
if(a>=c&&b>=c){
f=n-((a+b)-c);}
if(f>0){
    printf("%d",f);
}else
printf("-1");
return 0;}


#pragma comment(linker,"/STACK:64000000")
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
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<ll> vl;
typedef vector<vl> vvl;
#define mp make_pair
#define pb push_back
#define eps (double)(1e-2)
#define MOD (ll)(1e9 + 7)

const int maxlen = 1e7 + 10;
const int length_double = 100;
const int base = 10;
#define PI 3.14159265358979323846
#define name "floor"

vector<int> A;
int main()
{
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	/*#else
	freopen(name".in", "rt", stdin);
	freopen(name".out", "wt", stdout);*/
#endif
	int n;
	int i;
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		int x;
		scanf("%d", &x);
		A.push_back(x);
	}
	sort(A.begin(), A.end());
	printf("%d", A[n / 2]);
	return 0;
}


#include <cstdio>
#include <algorithm>
#define MAXN 103
using namespace std;

int a[MAXN];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	sort(a + 1,a + 1 + n);
	printf("%d\n",a[(n + 1) / 2]);
	return 0;
}


 #include <bits/stdc++.h>
 using namespace std;
 int main()
 {
    int x;
    cin>>x;
    int a[x];
    for (int i = 0; i < x; ++i)
    {
        cin>>a[i];
    }
    sort(a,a+x);
    if(x==1)
    {
        cout<<a[0]<<endl;;
    }
    else
    {
       if(x%2==0)
       {
            cout<<a[x%2-1]<<endl;
       }
       else if(x==5)
       {
            cout<<a[(x%2)+1]<<endl;
       }
       else
       {
            cout<<a[x%2]<<endl;
       }
    }
    return 0 ;
 }


#include<bits/stdc++.h>

using namespace std;

int a[9];
set <int> st;
main()
{
    int n;
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> a[i];
        st.insert(a[i]);
    }
    sort(a+1,a+n+1);
    cout << a[(n+1)/2];

}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	cout << a[n / 2] << endl;

	return 0;
}


#include<iostream>

using namespace std;

int main(){
    int n, res = 0;
    cin >> n;
    for(int i = 0, a; i < n; i++){
        cin >> a;
        res += a;
    }
    cout << res / n;
    return 0;
}


#include <iostream>

using std::cin;
using std::cout;

int a[5];
int main()
{
	int n = 0;
	int s = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		s += a[i];
	}
	cout << (s / n);
	return 0;
}


#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<sstream>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
#define INF 1000000007
#define MOD 1000000007
#define INF_LONG 1e18
#define MOD_LONG 1e18
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define mp make_pair
#define all(x) (x).begin(), (x).end()
const int dr[4] = { 0,0,-1,1 }, dc[4] = { -1,1,0,0 };
class Dijkstra {
	int N;
	vector<vector<pair<int, int> > > E;
public:
	Dijkstra(int n) {
		N = n;
		E = vector<vector<pair<int, int> > >(N + 1);
	}
	void insert(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
	}
	vector<int> dijkstra(int start, int end) {
		vector<int> dist(N + 1, INF);
		dist[start] = 0;
		priority_queue<pair<int, int> > pq;
		pq.push(make_pair(0, start));
		while (!pq.empty()) {
			int w = -pq.top().first;
			int u = pq.top().second;
			if (u == end) return dist;
			pq.pop();
			if (dist[u] < w) continue;
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first;
				int w2 = w + E[u][i].second;
				if (dist[v] > w2) {
					dist[v] = w2;
					pq.push(make_pair(-w2, v));
				}
			}
		}
		return dist;
	}
	void g() {
		int i, n, e, s, u, v, w; vector<int> ans;
		scanf("%d%d", &n, &e);
		Dijkstra dk(n);
		scanf("%d", &s);
		for (i = 0; i < e; i++) {
			scanf("%d%d%d", &u, &v, &w);
			dk.insert(u, v, w);
		}
		ans = dk.dijkstra(s, N);
		for (i = 1; i <= n; i++) {
			if (ans[i] >= INF) printf("INF\n");
			else printf("%d\n", ans[i]);
		}
	}
};
class Prim {
	int N;
	vector<vector<pair<int, int> > > E;
public:
	Prim(int n) {
		N = n;
		E = vector<vector<pair<int, int> > >(N + 1);
	}
	void insert(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
	}
	vector<int> execute(ll &cost) {
		int k;
		vector<int> dist(N + 1, INF);
		vector<bool> selected(N + 1, false);
		dist[1] = 0; cost = 0;
		priority_queue<pair<int, int> > pq;
		pq.push(make_pair(0, 1));
		for (k = 0; k < N; k++) {
			int w = -pq.top().first;
			int u = pq.top().second;
			pq.pop();
			if (selected[u] == true) {
				k--; continue;
			}
			cost += w; selected[u] = true;
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first;
				int w2 = E[u][i].second;
				if (selected[v] == true) continue;
				if (dist[v] > w2) {
					dist[v] = w2;
					pq.push(make_pair(-w2, v));
				}
			}
		}
		return dist;
	}
	void g() {
		int i, n, e, s, u, v, w; ll cost; vector<int> ans;
		scanf("%d%d", &n, &e);
		Prim pm(n);
		scanf("%d", &s);
		for (i = 0; i < e; i++) {
			scanf("%d%d%d", &u, &v, &w);
			pm.insert(u, v, w);
		}
		ans = pm.execute(cost);
		printf("%d", cost);
	}
};
class Floyd {
	int N;
	vector<vector<int> > E;
public:
	Floyd(int n) {
		N = n;
		E = vector<vector<int> >(N + 1, vector<int>(N + 1, INF));
	}
	void setRC(int r, int c, int w) {
		E[r][c] = w;
	}
	int getRC(int r, int c) {
		return E[r][c];
	}
	void execute() {
		int i, j, k;
		for (i = 1; i <= N; ++i) E[i][i] = 0;
		for (k = 1; k <= N; ++k) for (i = 1; i <= N; ++i) for (j = 1; j <= N; ++j)
			E[i][j] = min(E[i][j], E[i][k] + E[k][j]);
	}
};
class DFS_Graph {
	vector<vector<pair<int, int> > > E; vector<int> A;
	int N;
public:
	DFS_Graph(int n) {
		N = n;
		E = vector<vector<pair<int, int> > >(N + 1);
		A = vector<int>(N + 1);
	}
	void insert(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
	}
	void insert_fb(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
		E[v].push_back(make_pair(u, w));
	}
	int dfsAll(int start, int end) {
		vector<bool> visited = vector<bool>(N + 1, false);
		return dfs(start, end, visited);
	}
	int dfs(int start, int end, vector<bool> &visited) {
		if (start == end) return 1;
		visited[start] = true;
		for (int i = 0; i < E[start].size(); i++) {
			int v = E[start][i].first, c = E[start][i].second;
			if (!visited[v]) {
				if (dfs(v, end, visited)) return 1;
			}
		}
		return 0;
	}
	void setA(int a, int b) {
		A[a] = b;
	}
	int dfsAll2() {
		vector<int> visited(N + 1, 0);
		int i, j, seq = 0, ret = 0, a;
		for (i = 1; i <= N; i++) dfs2(i, visited, ++seq);
		for (i = 1; i <= N; i++) {
			for (j = a = 0; j < E[i].size(); j++) {
				a += E[i][j].second;
			}
			if (ret < a) ret = a;
		}
		return ret;
	}
	int dfs2(int start, vector<int> &visited, ll seq) {
		visited[start] = seq;
		int ret = A[start];
		for (int i = 0; i < E[start].size(); i++) {
			int v = E[start][i].first; ll c = E[start][i].second;
			if (visited[v] < seq) {
				if (E[start][i].second == -1) E[start][i].second = dfs2(v, visited, seq);
				if (ret < E[start][i].second) ret = E[start][i].second;
			}

		}
		return ret;
	}
	void g() {
		int i, j, N, m, a, b, c, a2, b2, c2, lo, hi, mid, tmp, start, end;
		scanf("%d%d", &N, &m);
		DFS_Graph dg(N);
		for (i = 0; i < m; i++) {
			scanf("%d%d", &a, &b);
			dg.insert(a, b, 0);
		}
		scanf("%d", &m);
		for (i = 0; i < m; i++) {
			scanf("%d%d", &a, &b);
			if (dg.dfsAll(a, b)) c = -1;
			else if (dg.dfsAll(b, a)) c = 1;
			else c = 0;
			printf("%d\n", c);
		}
	}
};
class DFS_Map {
	vector<vector<int> > E;
	int R, C;
public:
	DFS_Map(int r, int c) {
		R = r; C = c;
		E = vector<vector<int> >(R + 2, vector<int>(C + 2, 0));
	}
	void setRC(int r, int c, int w) {
		E[r][c] = w;
	}
	int getRC(int r, int c) {
		return E[r][c];
	}
	void dfs(int rr, int cc, vector<vector<bool> > &visited) {
		int i, r, c, v;
		visited[rr][cc] = true;
		for (i = 0; i < 4; i++) {
			r = rr + dr[i]; c = cc + dc[i];
			if (E[r][c] && !visited[r][c]) {
				dfs(r, c, visited);
			}
		}
	}
	void dfsAll() {
		vector<vector<bool> > visited = vector<vector<bool> >(R + 2, vector<bool>(C + 2, 0));
		int r, c;
		for (r = 1; r <= R; r++) for (c = 1; c <= C; c++) if (!visited[r][c]) dfs(r, c, visited);
	}
};
class BFS_Graph {
	vector<vector<pair<int, int> > > E; vector<int> IN;
	int N;
public:
	int is_cycle() { // topologicalSort() 수행후 IN[v]>0인 node가 존재하면 cycle이 존재한다고 볼수있다
		for (int i = 1; i <= N; i++) if (IN[i]>0) return 1;
		return 0;
	}
	BFS_Graph(int n) {
		N = n;
		E.clear(); IN.clear();
		E = vector<vector<pair<int, int> > >(N + 1);
		IN = vector<int>(N + 1, 0);
	}
	void insert(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
		IN[v]++;
	}
	void insert_fb(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
		E[v].push_back(make_pair(u, w));
	}
	vector<ll> bfs(int start, int end, int min_weight) {
		vector<bool> visited = vector<bool>(N + 1, false);
		vector<ll> weight(N + 1, INF_LONG);
		queue<int> Q;
		visited[start] = true; weight[start] = 0;
		Q.push(start);
		while (!Q.empty()) {
			int u = Q.front(), w = weight[u]; if (u == end) break;
			Q.pop();
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first, c = E[u][i].second;
				if (c >= min_weight && !visited[v]) {
					Q.push(v); weight[v] = w + c;
					visited[v] = true;
				}
			}
		}
		return weight;
	}
	vector<int> topologicalSort() {
		vector<int> order;
		queue<int> Q;
		for (int i = 1; i <= N; i++) if (!IN[i]) Q.push(i);
		while (!Q.empty()) {
			int u = Q.front();
			Q.pop(); order.push_back(u);
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first;
				if (IN[v]>0) {
					IN[v]--;
					if (!IN[v]) Q.push(v);
				}
			}
		}
		return order;
	}
	vector<int> topologicalSortPQ() {
		vector<int> order;
		priority_queue<int> pq;
		for (int i = 1; i <= N; i++) if (!IN[i]) pq.push(-i);
		while (!pq.empty()) {
			int u = -pq.top();
			pq.pop(); order.push_back(-u);
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first;
				if (IN[v]>0) {
					IN[v]--;
					if (!IN[v]) pq.push(-v);
				}
			}
		}
		return order;
	}
	int f() {
		int v, u, i; vector<int> IN2;
		for (u = 1; u <= N; u++) {
			for (i = 0; i<E[u].size(); i++) {
				v = E[u][i].first;
				if (IN[v] == 1) {
					IN2 = IN;
					IN[v]--;
					topologicalSort();
					if (!is_cycle()) return 1;
					IN = IN2;
				}
			}
		}
		return 0;
	}
	void g() {
		int i, j, N, m, a, b, c, a2, b2, c2, lo, hi, mid, tmp, start, end;
		vector <tuple<int, int, int> > X; vector<ll> y;
		scanf("%d%d", &N, &m);
		BFS_Graph bg(N); X.reserve(m);
		for (i = 0; i < m; i++) {
			scanf("%d%d%d", &a, &b, &c);
			if (a > b) tmp = a, a = b, b = tmp;
			X.push_back(make_tuple(a, b, -c));
		}
		scanf("%d%d", &start, &end);
		sort(X.begin(), X.end());
		bg.insert_fb(get<0>(X[0]), get<1>(X[0]), -get<2>(X[0]));
		for (i = 1; i < m; i++) {
			a = get<0>(X[i - 1]); b = get<1>(X[i - 1]); c = get<2>(X[i - 1]);
			a2 = get<0>(X[i]); b2 = get<1>(X[i]); c2 = get<2>(X[i]);
			if (a == a2 && b == b2) continue;
			bg.insert_fb(a2, b2, -c2);
		}
		lo = 1; hi = INF;
		while (lo < hi) {
			mid = (lo + hi + 1) / 2;
			y = bg.bfs(start, end, mid);
			if (y[end] < INF_LONG) {
				lo = mid;
			}
			else {
				hi = mid - 1;
			}
		}
		printf("%d", lo);
	}
};
class BFSMap {
	vector<vector<int> > E;
	int R, C;
public:
	BFSMap(int r, int c) {
		R = r; C = c;
		E = vector<vector<int> >(R + 2, vector<int>(C + 2, 0));
	}
	void setRC(int r, int c, int w) {
		E[r][c] = w;
	}
	int getRC(int r, int c) {
		return E[r][c];
	}
	int bfsAll() {
		int r, c, ret = 0;
		vector<vector<int> > visited = vector<vector<int> >(R + 2, vector<int>(C + 2, 0));
		for (r = 1; r <= R; r++) {
			for (c = 1; c <= C; c++) {
				if (E[r][c] && !visited[r][c]) {
					ret++; bfs(r, c, visited);
				}
			}
		}
		return ret;
	}
	int bfsAll(vector<pair<int, int> > &Q) {
		int i, r, c, ret = 0;
		vector<vector<int> > visited = vector<vector<int> >(R + 2, vector<int>(C + 2, 0));
		for (i = 0; i < Q.size(); i++) {
			r = Q[i].first; c = Q[i].second;
			if (!visited[r][c]) {
				ret++; bfs(r, c, visited);
			}
		}
		return ret;
	}
	void bfs(int rr, int cc, vector<vector<int> > &visited) {
		int i, r, c, r2, c2;
		queue<pair<int, int> > Q;
		Q.push(make_pair(rr, cc)); visited[rr][cc] = 1;
		while (!Q.empty()) {
			r = Q.front().first;
			c = Q.front().second;
			Q.pop();
			for (i = 0; i < 4; i++) {
				r2 = r + dr[i]; c2 = c + dc[i];
				if (E[r2][c2] && !visited[r2][c2]) {
					Q.push(make_pair(r2, c2)); visited[r2][c2] = visited[r][c] + 1;
				}
			}
		}
	}
	void g() {
		int i, j, r, c, r2, c2, R, C, a, ans = 0, idx = 0; vector <pair<int, int> > Q[2]; vector<int> X;
		scanf("%d%d", &R, &C);
		BFSMap bm(R, C);
		X.reserve(10004); Q[0].reserve(10004); Q[1].reserve(10004);
		for (r = 1; r <= R; r++) for (c = 1; c <= C; c++) {
			scanf("%d", &a); bm.setRC(r, c, a); if (a) Q[0].push_back(make_pair(r, c));
		}
		while (1) {
			a = bm.bfsAll(Q[idx]);
			if (a > 1) break;
			else if (a == 0) {
				ans = 0; break;
			}
			ans++; X.resize(0); Q[1 - idx].resize(0);
			for (i = 0; i < Q[idx].size(); i++) {
				r = Q[idx][i].first; c = Q[idx][i].second; a = 0;
				for (j = 0; j < 4; j++) {
					r2 = r + dr[j]; c2 = c + dc[j];
					if (bm.getRC(r2, c2) == 0) a++;
				}
				X.push_back(a);
			}
			for (i = 0; i < Q[idx].size(); i++) {
				r = Q[idx][i].first; c = Q[idx][i].second; a = bm.getRC(r, c) - X[i];
				if (a <= 0) {
					a = 0;
				}
				else {
					Q[1 - idx].push_back(make_pair(r, c));
				}
				bm.setRC(r, c, a);
			}
			idx = 1 - idx;
		}
		printf("%d", ans);
	}
};
class Number {
public:
	Number() {

	}
	int getDigitNum(ll xx) {
		ll x; int ret = 0;
		for (x = 1; x < xx; x *= 10, ret++);
		return ret;
	}
	int getDigitSum(int xx) {
		int x, a = 0;
		for (x = xx; x; x /= 10) a += (x % 10);
		return a;
	}
	int getMSB(ll xx) {
		int i;
		for (i = 0; (1ll << i) <= xx; i++);
		return i - 1;
	}
	ll convertBinaryToBase(ll x, int base) {
		if (x == 0) return 0;
		return base * convertBinaryToBase(x / 2, base) + (x % 2);
	}
	ll findFactor(ll k) {
		for (ll d = 2; d * d <= k; d++) if (k % d == 0) return d;
		return 0;
	}
};
class Palindrome {
public:
	Palindrome() {

	}
	int isPalindrome(ll xx) {
		ll x; int i, n; vector <int> v;
		for (x = xx; x > 0; x /= 10) {
			v.push_back(x % 10);
		}
		n = v.size();
		for (i = 0; i < n / 2; i++) {
			if (v[i] != v[n - i - 1]) return 0;
		}
		return 1;
	}
};
class BigNumber {
public:
	BigNumber() {

	}
	string add(string &s1, string &s2) {
		int i, j, k, n1, n2, a; string s3; vector<int> v;
		n1 = s1.size();
		n2 = s2.size();
		v.reserve(max(n1, n2) + 1);
		for (i = n1 - 1, j = n2 - 1; i >= 0 && j >= 0; i--, j--) {
			a = s1[i] - '0' + s2[j] - '0';
			v.push_back(a);
		}
		while (i >= 0) {
			a = s1[i] - '0';
			v.push_back(a);
			i--;
		}
		while (j >= 0) {
			a = s2[j] - '0';
			v.push_back(a);
			j--;
		}
		for (i = 0, a = 0; i < v.size(); i++) {
			a += v[i];
			if (a >= 10) {
				v[i] = a - 10;
				a = 1;
			}
			else {
				v[i] = a;
				a = 0;
			}
		}
		if (a) v.push_back(a);
		s3.reserve(v.size());
		for (i = v.size() - 1; i >= 0; i--) s3 += (char)(v[i] + '0');
		s3 += '\n';
		return s3;
	}
};
class PrimeNumber {
	int N; vector<int> NP, P;
	ll _powmod(ll a, ll b) {
		if (b == 0) return 1;
		if (b & 1) return a * _powmod(a, b - 1) % MOD;
		return _powmod(a * a % MOD, b / 2);
	}
public:
	PrimeNumber() {

	}
	PrimeNumber(int n) {
		N = n;
		NP.reserve(N + 4);
		P.reserve(N / 4);
		for (int i = 2; i*i <= N; i++) {
			if (NP[i]) continue;
			for (int j = i*i; j <= N; j += i) NP[i] = 1;
		}
		for (int i = 2; i <= N; i++) if (!NP[i]) P.push_back(i);
	}

	ll gcd(ll x, ll y) {
		ll z;
		while (x) {
			z = y%x;
			y = x;
			x = z;
		}
		return y;
	}

	ll powermod(ll p, ll q) {
		ll g = gcd(p, q);
		p /= g; q /= g;
		return p * _powmod(q, MOD - 2) % MOD;
	}

	vector<int> factorization(int x) {
		vector<int> ret; int i;
		if (x == 1) {
			ret.push_back(1);
			return ret;
		}
		ret.push_back(1); ret.push_back(x);
		for (i = 2; i*i < x; i++) {
			if (x%i == 0) {
				ret.push_back(i);
				ret.push_back(x / i);
			}
		}
		if (i*i == x) ret.push_back(i);
		return ret;
	}

	int factorization2(int x) {
		int ret = 0, i;
		if (x == 1) {
			return 1;
		}
		ret = 2;
		for (i = 2; i*i < x; i++) {
			if (x%i == 0) {
				ret += 2;
			}
		}
		if (i*i == x) ret++;
		return ret;
	}
};
class BitOperation {
public:
	BitOperation() {

	}
	int getOneBitNum(int xx) {
		int a = 0, x;
		for (x = xx; x; x = x&(x - 1)) a++;
		return a;
	}
};
class Comb {
	vector<vector<ll> > C; vector<ll> F; int N;
#define MOD_COMB MOD
public:
	Comb() {

	}
	Comb(int n) {
		init(n);
	}
	void init(int n) {
		N = n;
		C.resize(N + 1);
		for (int i = 0; i <= N; i++) C[i].resize(i + 1);
		for (int i = 0; i <= N; i++) C[i][i] = C[i][0] = 1;
		for (int i = 1; i <= N; i++) for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD_COMB;
		F.resize(N + 1);
		F[0] = F[1] = 1;
		for (int i = 1; i <= n; i++) F[i] = (F[i - 1] * i) % MOD_COMB;
	}
	ll getC(int n, int r) {
		return C[n][r];
	}
	ll getF(int n) {
		return F[n];
	}
	ll get_comb(int n, int r) {
		if (n == r || r == 0) return 1;
		if (n <= 1000) return getC(n, r);
		ll ret = 1; int i;
		if (r > n / 2) r = n - r;
		for (i = n; i > n - r; i--) ret *= i;
		for (i = 2; i <= r; i++) ret /= i;
		return ret;
	}
};
class Sort {
	vector<int> tmp;
	int N;
public:
	Sort(int n) {
		N = n;
		tmp.reserve(n + 4);
	}
	void merge_sort(vector<int> &x, int lo, int hi) {
		if (lo >= hi) return;
		int i, j, k, mid = (lo + hi) / 2;
		merge_sort(x, lo, mid); merge_sort(x, mid + 1, hi);
		for (i = lo, j = mid + 1, k = lo; i <= mid && j <= hi; k++) {
			if (x[i]<x[j]) tmp[k] = x[i++]; else tmp[k] = x[j++];
		}
		if (i <= mid) {
			for (; i <= mid; i++, k++) tmp[k] = x[i];
		}
		if (j <= hi) {
			for (; j <= hi; j++, k++) tmp[k] = x[j];
		}
		for (i = lo; i <= hi; i++) x[i] = tmp[i];
	}
};
class PSum {
	PSum() {

	}
	vector<int> makeSum(const vector<int> &a, int n) {
		vector<int> ret(a.size());
		ret[0] = a[0];
		for (int i = 1; i < a.size(); ++i)
			ret[i] = ret[i - 1] + a[i];
		return ret;
	}
	vector<vector<int> > makeSum(const vector<vector<int> > &a, int n, int m) {
		vector<vector<int> > ret(n, vector<int>(m));
		int i, j;
		for (i = 0; i < n; i++) ret[i][0] = a[i][0];
		for (i = 0; i < n; i++) {
			for (j = 1; j < m; j++) {
				ret[i][j] = ret[i][j - 1] + a[i][j];
			}
		}
	}
	int getSum(const vector<int>& psum, int a, int b) {
		if (a == 0) return psum[b];
		return psum[b] - psum[a - 1];
	}
	int getSum(const vector<vector<int> >&psum, int r1, int c1, int r2, int c2) {
		int ret = psum[r2][c2];
		if (r1 > 0) ret -= psum[r1 - 1][c2];
		if (c1 > 0) ret -= psum[r2][c1 - 1];
		if (r1 > 0 && c1 > 0) ret += psum[r1 - 1][c1 - 1];
		return ret;
	}
};
class DisjointSet {
	int N;
	vector<int> P, R, A;
public:
	DisjointSet(int n) {
		N = n;
		P = vector<int>(n + 1);
		R = vector<int>(n + 1);
		A = vector<int>(n + 1);
		for (int i = 1; i <= n; i++) P[i] = i, R[i] = 0, A[i] = 1;
	}
	int getA(int x) {
		return A[x];
	}
	int find_set(int x) {
		if (P[x] == x) return x;
		int pa = find_set(P[x]);
		return P[x] = pa;
	}
	int union_set(int x, int y) {
		int px, py;
		px = find_set(x); py = find_set(y);
		if (px == py) return px;
		if (R[px]>R[py]) {
			P[py] = px;
			A[px] += A[py];
			return px;
		}
		else {
			P[px] = py;
			A[py] += A[px];
			if (R[px] == R[py]) R[py]++;
			return py;
		}
	}
};
class LIS { // 0-based index
	int N, BI;
public:
	LIS(int n) {
		N = n;
	}
	int execute(vector<int> &A) { // nlogn
		int i, lo, hi, x, vi;
		vector<int> v = vector<int>(N, 0);
		vi = -1;
		v[++vi] = A[0];
		for (i = 1; i < N; i++) {
			if (A[i] > v[vi]) {
				v[++vi] = A[i];
				continue;
			}
			for (lo = 0, hi = vi; lo < hi; ) {
				if (v[(lo + hi) / 2] >= A[i]) hi = (lo + hi) / 2;
				else lo = (lo + hi) / 2 + 1;
			}
			v[hi] = A[i];
		}
		return vi + 1;
	}

	vector<int> execute2(vector<int> &A, int &len) { // nlogn
		vector<int> v, v1, p, ret; int i, j; // 0-based index
		v.push_back(A[0]); v1.push_back(0);
		p = vector<int>(N, -1);
		for (int i = 1; i < A.size(); i++) {
			if (v.back() < A[i]) {
				p[i] = v1.back();
				v.push_back(A[i]);
				v1.push_back(i);
			}
			else {
				vector<int>::iterator itr = lower_bound(v.begin(), v.end(), A[i]);
				*itr = A[i];
				int idx = itr - v.begin();
				if (idx != 0) {
					p[i] = v1[idx - 1];
				}
				v1[idx] = i;
			}
		}
		len = v1.size();
		ret = vector<int>(len);
		for (i = v1.back(), j = len - 1; i != -1; i = p[i], j--) ret[j] = A[i];
		return ret;
	}

	int execute3(vector<int> &A) { // n^2
		int i, j, ret = 0;
		vector<int> v = vector<int>(N, 0);
		for (i = 0; i<A.size(); i++) {
			for (j = 0; j<i; j++) if (A[j]<A[i] && v[i]<v[j]) v[i] = v[j];
			v[i]++;
		}
		for (i = 0; i<v.size(); i++) if (v[i]>ret) ret = v[i];
		return ret;
	}
};
class SegmentTreeSum {
	vector<ll> ST; vector<int> A; int N;

	ll _init(vector<int>&a, int left, int right, int node) {
		if (left == right) return ST[node] = a[left];
		int mid = (left + right) / 2;
		ll lv = _init(a, left, mid, node * 2), rv = _init(a, mid + 1, right, node * 2 + 1);
		return ST[node] = lv + rv;
	}

	ll _query(int left, int right, int node, int nodeLeft, int nodeRight) {
		if (right<nodeLeft || nodeRight<left) return 0;
		if (left <= nodeLeft && nodeRight <= right) return ST[node];
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _query(left, right, node * 2, nodeLeft, mid), rv = _query(left, right, node * 2 + 1, mid + 1, nodeRight);
		return lv + rv;
	}

	ll _update(int index, int newValue, int node, int nodeLeft, int nodeRight) {
		if (index<nodeLeft || nodeRight<index) return ST[node];
		if (nodeLeft == nodeRight) return ST[node] = newValue;
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _update(index, newValue, node * 2, nodeLeft, mid), rv = _update(index, newValue, node * 2 + 1, mid + 1, nodeRight);
		return ST[node] = lv + rv;
	}

public:
	SegmentTreeSum(int n) {
		N = n;
		ST = vector<ll>(n * 4 + 4);
		A = vector<int>(n + 4);
	}

	void setA(int x, int y) {
		A[x] = y;
	}

	void init() {
		_init(A, 1, N, 1);
	}

	ll query(int left, int right) {
		return _query(left, right, 1, 1, N);
	}

	ll update(int index, int newValue) {
		return _update(index, newValue, 1, 1, N);
	}
};
class SegmentTreeMin {
	vector<ll> ST; vector<int> A; int N;

	ll _init(vector<int>&a, int left, int right, int node) {
		if (left == right) return ST[node] = a[left];
		int mid = (left + right) / 2;
		ll lv = _init(a, left, mid, node * 2), rv = _init(a, mid + 1, right, node * 2 + 1);
		return ST[node] = min(lv, rv);
	}

	ll _query(int left, int right, int node, int nodeLeft, int nodeRight) {
		if (right<nodeLeft || nodeRight<left) return INF;
		if (left <= nodeLeft && nodeRight <= right) return ST[node];
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _query(left, right, node * 2, nodeLeft, mid), rv = _query(left, right, node * 2 + 1, mid + 1, nodeRight);
		return min(lv, rv);
	}

	ll _update(int index, int newValue, int node, int nodeLeft, int nodeRight) {
		if (index<nodeLeft || nodeRight<index) return ST[node];
		if (nodeLeft == nodeRight) return ST[node] = newValue;
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _update(index, newValue, node * 2, nodeLeft, mid), rv = _update(index, newValue, node * 2 + 1, mid + 1, nodeRight);
		return ST[node] = min(lv, rv);
	}

public:
	SegmentTreeMin(int n) {
		N = n;
		ST = vector<ll>(n * 4 + 4);
		A = vector<int>(n + 4);
	}

	void setA(int x, int y) {
		A[x] = y;
	}

	void init() {
		_init(A, 1, N, 1);
	}

	ll query(int left, int right) {
		return _query(left, right, 1, 1, N);
	}

	ll update(int index, int newValue) {
		return _update(index, newValue, 1, 1, N);
	}
};
class SegmentTreeMax {
	vector<ll> ST; vector<int> A; int N;

	ll _init(vector<int>&a, int left, int right, int node) {
		if (left == right) return ST[node] = a[left];
		int mid = (left + right) / 2;
		ll lv = _init(a, left, mid, node * 2), rv = _init(a, mid + 1, right, node * 2 + 1);
		return ST[node] = max(lv, rv);
	}

	ll _query(int left, int right, int node, int nodeLeft, int nodeRight) {
		if (right<nodeLeft || nodeRight<left) return 0;
		if (left <= nodeLeft && nodeRight <= right) return ST[node];
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _query(left, right, node * 2, nodeLeft, mid), rv = _query(left, right, node * 2 + 1, mid + 1, nodeRight);
		return max(lv, rv);
	}

	ll _update(int index, int newValue, int node, int nodeLeft, int nodeRight) {
		if (index<nodeLeft || nodeRight<index) return ST[node];
		if (nodeLeft == nodeRight) return ST[node] = newValue;
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _update(index, newValue, node * 2, nodeLeft, mid), rv = _update(index, newValue, node * 2 + 1, mid + 1, nodeRight);
		return ST[node] = max(lv, rv);
	}

public:
	SegmentTreeMax(int n) {
		N = n;
		ST = vector<ll>(n * 4 + 4);
		A = vector<int>(n + 4);
	}

	void setA(int x, int y) {
		A[x] = y;
	}

	void init() {
		_init(A, 1, N, 1);
	}

	ll query(int left, int right) {
		return _query(left, right, 1, 1, N);
	}

	ll update(int index, int newValue) {
		return _update(index, newValue, 1, 1, N);
	}
};
struct Point {
	int x, y, mx;
	Point() {}
	Point(int x, int y, int mx) : x(x), y(y), mx(mx) {}
	bool operator < (const Point& other) const {
		return mx < other.mx;
	}
};
class SegmentTree2D { // 2D Segment Tree node
	vector<vector<int> > P; // container for 2D grid
	int N, M;
	vector<Point> T;

public:
	SegmentTree2D(int n, int m) {
		N = n; M = m;
		P = vector<vector<int> >(n + 1, vector<int>(m + 1));
		T = vector<Point>(n * m * 2);
		init();
		build(1, 1, 1, n, m);
	}
	void init() {
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= M; j++)
				scanf("%d", &P[i][j]);
	}
	// build a 2D segment tree from data [ (a1, b1), (a2, b2) ], O(n logn)
	Point build(int node, int a1, int b1, int a2, int b2) {
		if (a1 > a2 || b1 > b2) // out of range
			return def();

		// if it is only a single index, assign value to node
		if (a1 == a2 && b1 == b2)
			return T[node] = Point(a1, b1, P[a1][b1]);

		// split the tree into four segments
		T[node] = def();
		T[node] = maxNode(T[node], build(4 * node - 2, a1, b1, (a1 + a2) / 2, (b1 + b2) / 2));
		T[node] = maxNode(T[node], build(4 * node - 1, (a1 + a2) / 2 + 1, b1, a2, (b1 + b2) / 2));
		T[node] = maxNode(T[node], build(4 * node + 0, a1, (b1 + b2) / 2 + 1, (a1 + a2) / 2, b2));
		T[node] = maxNode(T[node], build(4 * node + 1, (a1 + a2) / 2 + 1, (b1 + b2) / 2 + 1, a2, b2));
		return T[node];
	}
	// query from range [ (x1, y1), (x2, y2) ], Time: O(logn)
	Point query(int x1, int y1, int x2, int y2) {
		return _query(1, 1, 1, N, M, x1, y1, x2, y2);
	}
	// helper function for query(int, int, int, int);
	Point _query(int node, int a1, int b1, int a2, int b2, int x1, int y1, int x2, int y2) {
		// if we out of range, return dummy
		if (x1 > a2 || y1 > b2 || x2 < a1 || y2 < b1 || a1 > a2 || b1 > b2)
			return def();

		// if it is within range, return the node
		if (x1 <= a1 && y1 <= b1 && a2 <= x2 && b2 <= y2)
			return T[node];

		// split into four segments
		Point mx = def();
		mx = maxNode(mx, _query(4 * node - 2, a1, b1, (a1 + a2) / 2, (b1 + b2) / 2, x1, y1, x2, y2));
		mx = maxNode(mx, _query(4 * node - 1, (a1 + a2) / 2 + 1, b1, a2, (b1 + b2) / 2, x1, y1, x2, y2));
		mx = maxNode(mx, _query(4 * node + 0, a1, (b1 + b2) / 2 + 1, (a1 + a2) / 2, b2, x1, y1, x2, y2));
		mx = maxNode(mx, _query(4 * node + 1, (a1 + a2) / 2 + 1, (b1 + b2) / 2 + 1, a2, b2, x1, y1, x2, y2));

		// return the maximum value
		return mx;
	}
	// helper function for update(int, int, int);
	Point _update(int node, int a1, int b1, int a2, int b2, int x, int y, int value) {
		if (a1 > a2 || b1 > b2)
			return def();

		if (x > a2 || y > b2 || x < a1 || y < b1)
			return T[node];

		if (x == a1 && y == b1 && x == a2 && y == b2)
			return T[node] = Point(x, y, value);

		Point mx = def();
		mx = maxNode(mx, _update(4 * node - 2, a1, b1, (a1 + a2) / 2, (b1 + b2) / 2, x, y, value));
		mx = maxNode(mx, _update(4 * node - 1, (a1 + a2) / 2 + 1, b1, a2, (b1 + b2) / 2, x, y, value));
		mx = maxNode(mx, _update(4 * node + 0, a1, (b1 + b2) / 2 + 1, (a1 + a2) / 2, b2, x, y, value));
		mx = maxNode(mx, _update(4 * node + 1, (a1 + a2) / 2 + 1, (b1 + b2) / 2 + 1, a2, b2, x, y, value));
		return T[node] = mx;
	}

	// update the value of (x, y) index to 'value', O(logn)
	Point update(int x, int y, int value) {
		return _update(1, 1, 1, N, M, x, y, value);
	}

	// utility functions; these functions are virtual because they will be overridden in child class
	virtual Point maxNode(Point a, Point b) {
		return max(a, b);
	}

	// dummy node
	virtual Point def() {
		return Point(0, 0, -INF);
	}

	void g() {
		int n, m;
		scanf("%d %d", &n, &m);

		SegmentTree2D Tmax(n, m);

		// query
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		printf("(%d,%d,%d,%d)=%d\n", x1, y1, x2, y2, Tmax.query(x1, y1, x2, y2).mx);

		// update
		int x, y, v;
		scanf("%d %d %d", &x, &y, &v);
		Tmax.update(x, y, v);

		// query
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		printf("(%d,%d,%d,%d)=%d\n", x1, y1, x2, y2, Tmax.query(x1, y1, x2, y2).mx);
	}
};
class TreeFromExpression {
public:
	TreeFromExpression() {

	}
	// http://codeforces.com/contest/935/problem/E
	// for example, str="((1?(5?7))?((6?2)?7))"
	vector<pair<int, int> > make(char *str, int &root) {
		int i, cur = 1;
		vector<pair<int, int> > E(10000);
		stack<int> S;
		for (i = 0; str[i]; i++) {
			char cc = str[i];
			if (cc >= '1' && cc <= '9') {
				E[cur].first = cc - '0';
				E[cur].second = 0;
				S.push(cur);
				cur++;
			}
			else if (cc == ')') {
				int a, b;
				a = S.top(); S.pop();
				b = S.top(); S.pop();
				E[cur].first = a; E[cur].second = b;
				S.push(cur);
				cur++;
			}
		}
		root = cur - 1;
		return E;
	}
};

int main() {
	int i, j, n;
	scanf("%d", &n); vector<int> V(n);
	for (i = 0; i < n; i++) scanf("%d", &V[i]);
	sort(V.begin(), V.end());
	printf("%d", V[n / 2]);
}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 9999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int a[N];
int main(){
fcin;
	int n;
	cin>>n;
	for(int i = 0 ; i < n ;i++) cin>>a[i];
		sort(a,a+n);
	cout<<a[n/2];
}


#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int solve(int n,vector<int> &v)
{
    int result = 0;
    for(auto &i: v)
    {
        result += i;
    }
    result /= n;
    return result;
}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    cout<<solve(n,v);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,f[1000100];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>f[i];
	sort(f+1,f+n+1);
	cout<<f[(n+1)/2]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{   int n,i;
    cin>>n;
	int arr[n];
	for(i=0;i<n;i++)
	{
	    scanf("%d",&arr[i]);
	}
	sort(arr,arr+n);
	printf("%d\n",arr[n/2]);

}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],sum=0,i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum=sum+a[i];
	}
	cout<<(sum/n)<<endl;
	return 0;

}


#include<bits/stdc++.h>

using namespace std;
int main()
{
    int n,i;
    cin >> n;

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

    sort(a,a+n);

    int x = n/2;

    for(i=0;i<n;i++){

            if(i==x)
           printf("%d",a[i]);
           else
            continue;

    }

    return 0;
}


#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <map>
#include <time.h>
#include <string>
#include <algorithm>
#include <queue>
#include <assert.h>
#include <math.h>
#include <iostream>

using namespace std;

int main() {
#pragma warning(disable : 4996)
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	if (n == 1){
		int x;
		cin >> x;
		cout << x;
		return 0;
	}
	vector<int> s;
	for (int i = 0; i < n; i++){
		int h;
		cin >> h;
		s.push_back(h);
	}
	sort(s.begin(), s.end());
	cout << s[(n - 1) / 2 ];
	return 0;
}


#include<iostream>

using namespace std;

int n, x, a, b;

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> x;
		if (i==0) {
			a=b=x;
		} else {
			a=min(a, x);
			b=max(b, x);
		}
	}
	cout << (a+b)/2;
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}
int main()
{
	int n,i;
	scanf("%d",&n);
	int * a = (int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	mergeSort(a,0,n-1);
	if(n==1)
		printf("%d\n",a[0] );
	else
	{
		int mid = n/2;
		printf("%d\n", a[mid]);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( v , be , n ) for( int v = be ; v < n ; v++ )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

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

void File_input( string pathIn ){
    freopen( pathIn.c_str() , "r", stdin ) ;
}

void File_output( string pathOut ){
    freopen( pathOut.c_str() , "w", stdout ) ;
}

int msg(){
    srand( time( 0 ) ) ;
    vector < string > st = {
            "Wish everyone high ratings!",
            "Good luck!",
            "Have fun!",
            "Please, read all the problems!",
            "Go Go fight!" } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

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

int n , v , sm ;

int main(){
   cin >> n ;
   forn( i , 0 , n ){
     cin >> v ;
      sm += v ;
   }

   cout << sm / n ;

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
main(){
cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
cout<<a[(n-1)/2];
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define INF INT_MAX
#define vl vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define ml map<ll,ll>
#define mi map<int,int>
#define m(a,b) map<a,b>
#define rep(i,n) for(int i=1;i<=n;i++)
#define YesNo(f) if(f){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;continue;}
#define setval(a,val) memset(a,val,sizeof(a))
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int main()
{
    fastIO;
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int t=1;
    // cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        cout<<a[n/2]<<endl;
    }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > matrix;
#define PB push_back
#define F first
#define S second
#define loop(i,a,b) for (int i=a; i<b; i++)
#define endl '\n'
#define ends ' '
const int MOD = 1000000007;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	int t=1;
    // cin>>t;
	while(t--) {
		int n;
        cin>>n;
        vi vec(n);
        loop(i,0,n) cin>>vec[i];
        sort(vec.begin(), vec.end());
        cout<<vec[(n/2)]<<endl;
	}
}


	/* Template By Mayank Sharma
	fight_till_end  */
	#include<bits/stdc++.h>
	using namespace std;

	#define jadu ios_base::sync_with_stdio(false);
	#define REP(i,a,b) for (ll i = a; i <= b; i++)
	#define F first
	#define S second

	#define PB push_back
	#define MP make_pair
	typedef long long ll;
	typedef vector<int> vi;
	typedef pair<int,int> pi;

    const int mod = 1000000007;
	const int maxi =1005;

	int arr[maxi];
//	int brr[maxi];
//	int crr[maxi];
//	int n,m,k;

	int main()
	{
		int n;
		cin>>n;
		for(int i=0;i<n;i++) cin>>arr[i];
		sort(arr,arr+n);
		if(n>=2)
		cout<<arr[n/2];
		else cout<<arr[0];
	}


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

int main ()
{
    int n, tem, high, low;
    cin >> n;
    int arr[n];
    for (int i=0; i<n; i++)
        cin >> arr[i];
    sort(arr,arr+n);
    cout << arr[n/2];
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, a[6];
    while(cin>>n){
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);
        cout<<a[n/2]<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[5];
int main(){
    ios::sync_with_stdio(false);
  	int n , i , mx , mn , k;
  	cin >> n;
		mx = 2000 ;
		mn = 2200;
		for ( i = 0 ; i < n ; ++ i )
		{
			cin >> a[i];
			if ( a[i] > mx )
			{
				mx = a[i];
			}
			if ( a[i] < mn )
			{
				mn = a[i];
			}
		}
		k = (mx - mn) / 2;
	cout << mx - k;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[10],n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    cout<<a[(n+1)/2]<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <queue>
using namespace std;

int n,k,l,i;
int main() {
	cin>>n;
	k=0;
	for (i=0;i<n;i++){
		cin>>l;
		k+=l;
	}
	cout<<k/n<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
int a[10];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    cout << a[n / 2 + n % 2] << '\n';
}


#include <bits/stdc++.h>

using namespace std;

int a[6];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	sort(a, a + n);
	n >>= 1;
	printf("%d\n", a[n]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,min=9999,k;
	cin>>n;
	int kn[n];
	for(int i=1;i<=n;i++){
		cin>>kn[i];
	}
	//选择
	for(int i=1;i<=n-1;i++) {
		k=i ;
		min = kn[i] ;
		for(int j=i+1;j<=n;j++){
			if(kn[j]<min){
				min=kn[j];
				k=j;
			}
		}
		swap(kn[k],kn[i]);
	}
	cout<<kn[(1+n)/2];
	return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n+2];
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    sort(a+1, a+n+1);
    cout<<a[n/2+1];
}


#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define TIME ios_base::sync_with_stdio(0)
using namespace std;
ll a,b,c,s,d,e,m,cnt,ans,l,r;
vector<int>v,vv;
string g;
set<int>st;
int main()
{
    TIME;
    cin>>a;
    for(int i=0; i<a; i++)
    {
        cin>>b;
        v.pb(b);
        sort(v.begin(),v.end());
    }
        cout<<v[v.size()/2];
}


#include <iostream>
#include <vector>

using namespace std;

int YearUniversityAdmission (int n, vector<int> &array){
    int summ = 0;
    for (int i = 0; i < n; ++i) {
        summ += array[i];
    }
    return summ/n;
}

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

    int n;
    cin >> n;

    vector<int> years(n);
    for (int i = 0; i < n; i++){
        cin >> years[i];
    }

    cout << YearUniversityAdmission(n, years) << endl;

    return 0;
}


#include <iostream>

int main(int argc, char const *argv[]) {
	size_t n, sum = 0, y;
	std::cin >> n;
	for (size_t i = 0; i < n; ++i) {
		std::cin >> y;
		sum += y;
	}

	std::cout << sum / n;

	return 0;
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
/* CF handle: haleyk100198*/
#include <bits/stdc++.h>

#define MOD 1000000007
#define LINF (1LL<<60)
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))

using namespace std;

string itos(int x){
	stringstream ss;
	ss << x;
	return ss.str();
}

int n, a[5];

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a+n);
	cout << a[n/2] << endl;
	//Not sure if a[] is unique...
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
const ll N = 1005;
void go() {
    ll n, sum, i, x, b, j, cur, k, res;
    cin >> n;
    vector <ll> a(n);
    for(auto &x: a)
        cin >> x;
    sort(a.begin(), a.end());
    cout << a[n / 2] << "\n";
    return;
}
int main() {
	ll t = 1;
	while(t--)
        go();
	return 0;
}


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

#define inf (1<<30)-1
#define INF (1LL<<62)-1
#define MOD 1000000007LL
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define PI acos(-1)
#define MEM(x,y) memset(x,y,sizeof (x))
#define debug cout<<"A"<<'\n'
#define REP(i,a,b) for (int i=(a); i<=(b); i++)
#define PER(i,a,b) for (int i=(a); i>=(b); i--)
#define REPL(i,a,b) for (LL i=(a); i<=(b); i++)
#define PERL(i,a,b) for (LL i=(a); i>=(b); i--)
#define print(x) cout<<x<<'\n'
#define dprint(a,x) cout<<setprecision(x)<<fixed<<a<<'\n'
#define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int>PII;
typedef pair<LL,LL>PLL;
typedef set<int> SI;
typedef set<LL> SL;
typedef set<string> SS;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef map<int,int> MII;
typedef map<LL,LL> MLL;
typedef queue<int> QI;

/* Direction Array */

// int fx[]={1,-1,0,0};
// int fy[]={0,0,1,-1};
// int fx[]={0,0,1,-1,-1,1,-1,1};
// int fy[]={-1,1,0,0,1,1,-1,-1};

template <class T> inline T bigmod(T p,T e,T M)
{
    T ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}

template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}

inline LL power(LL a, LL b)
{
    LL multiply=1;
    REP(i,1,b)
    {
        multiply*=a;
    }
    return multiply;
}
inline LL ABS(LL a){return (a>=0)?a:-a;}

/*end of header*/

struct Matrix
{
	LL mat[2][2];

	Matrix(){}

	void init()
	{
		MEM(mat,0);
		for(int i=0; i<2; i++) mat[i][i]=1;
	}
} aux;

inline void matMult(Matrix &m, Matrix &m1, Matrix &m2)
{
	REP(i,0,1)
	{
		REP(j,0,1)
		{
			m.mat[i][j]=0;
			REP(k,0,1)
			{
				m.mat[i][j]=(m.mat[i][j]+m1.mat[i][k]*m2.mat[k][j]);
			}
		}
	}
}

inline Matrix expo(Matrix &M, LL n)
{
	Matrix ret;
	ret.init();

	if(n==0) return ret;
	if(n==1) return M;

	Matrix P=M;

	while(n!=0)
	{
		if(n&1)
		{
			aux=ret;
			matMult(ret,aux,P);
		}

		n>>=1;

		aux=P; matMult(P,aux,aux);
	}

	return ret;
}

LL findfib(LL n)
{
    if(n==0)return 1;
    if(n==1)return 2;
    Matrix M;
    M.mat[0][0]=1;
    M.mat[0][1]=1;
    M.mat[1][0]=1;
    M.mat[1][1]=0;
    Matrix res=expo(M,n-1);
    return res.mat[0][0]*2+res.mat[0][1];
}

int main()
{
    //freopen("input_file_name.in","r",stdin);
    //freopen("output_file_name.out","w",stdout);
    LL n;
    scanf("%lld",&n);
    LL lo=0,hi=90,mid,best;
    while(hi>=lo)
    {
        mid=(hi+lo)/2;
        if(findfib(mid)<=n)
        {
            best=mid;
            lo=mid+1;
        }
        else hi=mid-1;
    }
    printf("%lld\n",best);
    return 0;
}


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

const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;

int n,k,ans = INF;
int a[MAXN],cnt[MAXN],res[MAXN];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);

	sort(a + 1,a + 1 + n);

	for(int i = 1;i <= n;i++)
	{
		int t = a[i],x = 0;
		while(t != 0)
		{
			cnt[t]++;
			res[t] += x;
			x++;
			if(cnt[t] == k)
			    ans = min(ans,res[t]);
			t /= 2;
		}
	}

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


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>

using namespace std;

int main(int argc, char** argv) {

    ios::sync_with_stdio(false);
    int a, b, mod;
    cin >> a >> b >> mod;

    for(int i = 1; i <= min(a, mod); ++i) {
        int rem = (mod - i * (long long)1e9 % mod) % mod;
        if(b < rem) {
            cout << "1 " << setw(9) << setfill('0') << i << endl;
            return 0;
        }
    }

    cout << 2 << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
const ll zero = 0LL;
const int N = 2e3+10;
const ll oo = 1e5;
const double pi = acos(-1);
const int md = 1e9+7;

int n, dp[N][1010][2];
int calc(int idx, int open, bool canTake)
{

	if(idx == n*2)
		return 0;

	if(dp[idx][open][canTake]!=-1)
		return dp[idx][open][canTake];

	int ret = 0;
	bool canOpen = (open+1) <= (n*2-idx-1);
	bool canClose =  open>0;

	if(canOpen && canClose)
	{

		if(canTake)
		{

			int takeRight = calc(idx+1, open+1, 1) + calc(idx+1, open-1, 0);
			int takeLeft = calc(idx+1, open+1, 0) + calc(idx+1, open-1, 1);
			ret = 1 + max(takeRight, takeLeft);

		}else{

			ret = calc(idx+1, open+1, 1) + calc(idx+1, open-1, 1);

		}

	}else if(canOpen){

		ret = canTake+calc(idx+1, open+1, !canTake);

	}else if(canClose){

		ret = canTake+calc(idx+1, open-1, !canTake);

	}
	return dp[idx][open][canTake] = ret % md;
}
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("a.txt","r",stdin);
		freopen("b.txt","w",stdout);
	#endif
	scanf("%d", &n);
	memset(dp, -1, sizeof dp);
	printf("%d", calc(0, 0, 1));
	return 0;
}