#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
void ast(ll x,ll l,ll r){assert(x>=l&&x<=r);}
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
int rdint(int l,int r){return uniform_int_distribution<int>(l,r)(gen);}
const int N=5e5+5,mod=998244353;
#define inf 0x3f3f3f3f
int f(int n){int ans=0;while(n) ans+=n%10,n/=10;return ans;}
bool cmp(pair<int,int>&x,pair<int,int>&y)
{
  if(x.first+x.second==y.first+y.second) return x.first<y.first;
  return x.first+x.second<y.first+y.second;
}
int main()
{
  // freopen("1.in","r",stdin);
  int n;sc(n);out(2-n*n);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=30;
int n,d[MAXN],a,b,ans,maxn;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=s*10+(ch-'0'),ch=getchar();
	return s*w;
}
int main()
{
	n=read();
	for(register int i=1;i<=n;i++) d[i]=read(),maxn=max(maxn,d[i]);
	a=maxn,b=d[n],ans=a^b;
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
// Library for Ordered set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#include<time.h>
#define llu unsigned long long int
#define bs binary_search
#define pb push_back
#define f first
#define s second
#define ld long double
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define MOD (ll)(1e9+7)
#define ppb pop_back
#define max3(a,b,c) max(max(a,b),c)
#define min4(a,b,c,d) min(min3(a,b,c),d)
#define M (ll)(1e6)
#define rep(n) for(ll i=0;i<n;i++)
// To find nth smallest in an ordered set use st.find_by_order(n-1)
// To find the number of elements strictly less than k in ordered set use st.order_of_key(k)
using namespace std;
/*void build_tree(vector<ll> &tree,vector<ll> &v,ll start,ll end,ll node)
{
	if(start==end)
	tree[node]=v[start];
	else
	{
		ll mid=(start+end)/2;
		build_tree(tree,v,start,mid,2*node+1);
		build_tree(tree,v,mid+1,end,2*node+2);
		tree[node]=tree[2*node+1]+tree[2*node+2];
	}
}
ll get_sum(vector<ll> &tree,ll ss,ll se,ll qs,ll qe,ll i)
{
	if((qs)<=ss&&(qe)>=se)
		return tree[i];
	if((qe)<ss||(qs)>se)
		return 0;
	ll mid=(ss+se)/2;
	return(get_sum(tree,ss,mid,qs,qe,i*2+1)+get_sum(tree,mid+1,se,qs,qe,i*2+2));
}
void update_sum(vector<ll> &tree,ll ss,ll se,ll i,ll diff,ll si)
{
	if(i<ss||i>se)
		return;
	tree[si]=tree[si]+diff;
	if(ss!=se)
	{
		ll mid=(ss+se)/2;
		update_sum(tree,ss,mid,i,diff,2*si+1);
		update_sum(tree,mid+1,se,i,diff,2*si+2);
	}
}*/
ll find_pow(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
			res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
ll find_ans(ll a,ll b)
{
	ll ans=1;
	ll cnt=0,x1=a;
	while(a>0&&b>=a)
	{
		ll y1=(b/a);
		cnt+=y1;
		if(y1<x1)
			break;
		//cout<<a<<" "<<b<<" "<<y<<endl;
		//cout<<y<<endl;
		//cout<<y<<endl;
		//for(ll j=1;j<=y;j++)
			//ans=ans*x1;
		//ans=(ans*find_pow(x1,y))%MOD;
		a=a*x1;
	}
	//cout<<cnt<<endl;
	ans=find_pow(x1,cnt);
	return ans;
}
bool isPrime(ll n)
{
	if(n==1)
		return 0;
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
			return 0;
	}
	return 1;
}
void solve()
{
	//cout<<"Anup\n";
	ll x,n;
	cin>>x>>n;
	//cout<<n<<endl;
	vector<ll> p;
	for(ll i=1;i*i<=x;i++)
	{
		if(x%i==0)
		{
			if(isPrime(i))
			p.pb(i);
			if(x!=(i*i)&&isPrime(x/i))
				p.pb(x/i);
		}
	}
	ll ans=1;
	for(ll i=0;i<p.size();i++)
	{
		ll x1=find_ans(p[i],n);
		ans=(ans*x1)%MOD;
	}
	cout<<ans<<endl;
	p.clear();
}
int main(void)
{
	IOS;
	solve();
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main() {
    int n,at,sum=0,o=-1;
    cin>>n>>at;
    int arr[n];

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

    for(int i=0; i<n ;i++){sum=sum+arr[i];}

    if(sum+5+(10*(n-1))<=at){o=(at-sum)/5;}
    else if(sum+(10*(n-1))<=at){o=(at-sum)/5;}

    cout<<o<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ii pair<int, int>
#define il pair<int, ull>
#define pll pair<ll, ll>
#define iii pair<int , ii>
#define LOG(x) cout << x <<" ";
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 1; i <= n ; i++) { for (int j = 1; j <= m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  for( int i = 1; i <= n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(int i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * (x))
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vll vector <pll>
#define vil vector <il>
#define viii vector <iii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinc char c; cin>>c
#define cinxl ll x; cin>>x
#define scan(TYPE,VALUE) TYPE VALUE;cin>>VALUE
#define sout cout<<endl
#define nbit(x) __builtin_popcount((ull)x)
#define ret(x) return cout<<x<<endl,0

const int maxn = 300 +  5;
const int inf = (1e9) + 10;
const ld eps = 1e-12;

struct rib {
    int b, u, c, f , back;
};
int dx[] = {1 , -1 , 0 , 0};
int dy[] = {0 , 0 , 1 , -1};
vector <rib> g[maxn];
int n , m;
int s , t;
int V;
void add_rib (int a, int b, int u, int c) {
    // u = capacity
    // c = cost per flow (maybe double)
    // add edge between a and b
    rib r1 = { b, u, c, 0, (int)g[b].size() };
    rib r2 = { a, 0, -c, 0, (int)g[a].size() };
    g[a].push_back (r1);
    g[b].push_back (r2);
}
int mcmf(){
	int flow = 0,  cost = 0;
    while (flow < inf) {
        vector<int> id (V, 0);
        vector<int> d (V, inf);
        vector<int> q (V);
        vector<int> p (V);
        vector<int> p_rib (V);
        int qh=0, qt=0;
        q[qt++] = s;
        d[s] = 0;
        while (qh != qt) {
            int v = q[qh++];
            id[v] = 2;
            if (qh == V)  qh = 0;
            for (int i=0; i<g[v].size(); ++i) {
                rib & r = g[v][i];
                if (r.f < r.u && d[v] + r.c < d[r.b]) {
                    d[r.b] = d[v] + r.c;
                    if (id[r.b] == 0) {
                        q[qt++] = r.b;
                        if (qt == V)  qt = 0;
                    }
                    else if (id[r.b] == 2) {
                        if (--qh == -1)  qh = V-1;
                        q[qh] = r.b;
                    }
                    id[r.b] = 1;
                    p[r.b] = v;
                    p_rib[r.b] = i;
                }
            }
        }
        if (d[t] == inf)  break;
        int addflow = inf - flow;
        for (int v=t; v!=s; v=p[v]) {
            int pv = p[v];  int pr = p_rib[v];
            addflow = min (addflow, g[pv][pr].u - g[pv][pr].f);
        }
        for (int v=t; v!=s; v=p[v]) {
            int pv = p[v];  int pr = p_rib[v],  r = g[pv][pr].back;
            g[pv][pr].f += addflow;
            g[v][r].f -= addflow;
            cost += g[pv][pr].c * addflow;
        }
        flow += addflow;
    }
    return cost;
}

int grid[maxn][maxn];
bool valid(int i , int j){
	if (i < 1 || j < 1 || i > n || j > m)
		return false;
	return true;
}
int main()
{
	fastio;
	cin>>n >> m;
	fore(i,1,n){
		fore(j,1,m){
			cin>>grid[i][j];
		}
	}
	s = 0;
	t = n * m +1;
	V = t + 1;
	fore(i,1,n){
		fore(j,1,m){
			if ((i + j)%2){
				add_rib((i-1)*m + j , t, 1 , 0);
			}
			else{
				add_rib(s , (i-1)*m + j , 1 , 0);
				fore(k,0,3){
					int tx = i + dx[k];
					int ty = j + dy[k];
					if (!valid(tx , ty))
						continue;
					add_rib((i-1)*m + j , (tx-1)*m + ty , 1 , grid[i][j] != grid[tx][ty]);
				}
			}
		}
	}
	cout<<mcmf()<<endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:100000000")
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <fstream>
#include <iostream>
#include <ctime>
#include <fstream>
using namespace std;
const int N=100;
int a[N], d[N];
int main()
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; scanf("%d", &a[i]), i++);
	int s=0;
	for(int i=n-1; i>=0; i--)
	{
		d[i]=max(d[i+1], a[i]+s-d[i+1]);
		s+=a[i];
	}
	printf("%d %d\n", s-d[0], d[0]);
	return 0;
}


#include<cmath>
#include<cstring>
#include<cassert>
#include<cstdlib>
#include<climits>
#include<cfloat>

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

#include<hash_set>
#include<hash_map>
using namespace __gnu_cxx;

// skrocone typy
typedef long long ll;

typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned char uchar;
typedef unsigned long long ull;

// int pairs
typedef pair<int,int> pii;typedef pair<uint,uint> puiui;typedef pair<int,uint> piui;typedef pair<uint,int> puii;
// long long pairs
typedef pair< ll,ll> pllll;typedef pair<ull,ull> pullull;typedef pair<ull, ll> pullll;typedef pair<ll, ull> pllull;
// char pairs
typedef pair<char,char> pcc;typedef pair<char,uchar> pcuc;typedef pair<uchar,char> pucc;typedef pair<uchar,uchar> pucuc;
// long long x int pairs
typedef pair<int,ll> pill;typedef pair<ll,int> plli;typedef pair<uint,ll> puill;typedef pair<ll,uint> pllui;typedef pair<ull,int> pulli;typedef pair<int,ull> piull;typedef pair<uint,ull> puiull; typedef pair<ull,uint> pullui;
// long long x char pairs
typedef pair<char,ll> pcll;typedef pair<ll,char> pllc;typedef pair<uchar,ll> pucll;typedef pair<ll,uchar> plluc;typedef pair<ull,char> pullc;typedef pair<char,ull> pcull;typedef pair<uchar,ull> pucull; typedef pair<ull,uchar> pulluc;
// int x char pairs
typedef pair<char,int> pci;typedef pair<int,char> pic;typedef pair<uchar,int> puci;typedef pair<int,uchar> piuc;typedef pair<uint,char> puic;typedef pair<char,uint> pcui;typedef pair<uchar,uint> pucui; typedef pair<uint,uchar> puiuc;

#define mp make_pair
#define fi first
#define se second

#define pb push_back
#define pf push_front
#define ins insert
#define era erase

#define it iterator

#define type(x) __typeof(x)

#define foreach(itr,cont) for(__typeof(cont.begin()) itr = cont.begin(); itr != cont.end(); ++itr)
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=(n)-1; i>=0; --i)
#define fo(i,a,b) for(int i=(a); i<(b); ++i)
#define of(i,a,b) for(int i=(b)-1; i>=(a); --i)

#define sz(c) (int)(c).size()

struct llhash {size_t operator()(ll  x)const {return (int)x ^ (int)(x>>32);}};
struct piihash{size_t operator()(pii x)const {return x.fi^x.se;}};

int x00,y00,n,d;

vector<pii> vecs;

char pos[2][2][410][410];
const int win=1;
const int loss=2;

inline int dist2(int x, int y)
{
    x-=205;
    y-=205;
    return x*x + y*y;
}

void tc()
{
    cin>>x00>>y00>>n>>d;
    vecs.resize(n);
    rep(i,n)cin>>vecs[i].fi>>vecs[i].se;

    rep(g1,2)rep(g2,2)rep(x,410)rep(y,410)if(dist2(x,y)>d*d)pos[g1][g2][x][y]=win;

    of(diag,0,819)fo(x,0,410)
    {
        int y = diag-x;
        if(y<0 || y>=410)continue;
        if(pos[1][1][x][y])continue;
        // probujemy dojsc do przegrywajacej
        bool ok = false;
        rep(i,sz(vecs))
        {
            int nx = x+vecs[i].fi;
            int ny = y+vecs[i].se;
            if(nx>=410 || ny>=410)continue;
            if(pos[1][1][nx][ny]==loss)ok=true;
        }
        pos[1][1][x][y] = ok?win:loss;
    }

    of(diag,0,819)fo(x,0,410)
    {
        int y = diag-x;
        if(y<0 || y>=410)continue;
        if(pos[1][0][x][y]==0)
        {
            // probujemy dojsc do przegrywajacej
            bool ok = false;
            rep(i,sz(vecs))
            {
                int nx = x+vecs[i].fi;
                int ny = y+vecs[i].se;
                if(nx>=410 || ny>=410)continue;
                if(pos[0][1][nx][ny]==loss)ok=true;
            }
            pos[1][0][x][y] = ok?win:loss;
        }

        if(pos[0][1][x][y]==0)
        {
            bool ok = false;
            rep(i,sz(vecs))
            {
                int nx = x+vecs[i].fi;
                int ny = y+vecs[i].se;
                if(nx>=410 || ny>=410)continue;
                if(pos[1][0][nx][ny]==loss)ok=true;
            }
            if(pos[1][1][y][x]==loss)ok=true;
            pos[0][1][x][y] = ok?win:loss;
        }
    }

    of(diag,0,819)fo(x,0,410)
    {
        int y = diag-x;
        if(y<0 || y>=410)continue;
        if(pos[0][0][x][y])continue;
        // probujemy dojsc do przegrywajacej
        bool ok = false;
        rep(i,sz(vecs))
        {
            int nx = x+vecs[i].fi;
            int ny = y+vecs[i].se;
            if(nx>=410 || ny>=410)continue;
            if(pos[0][0][nx][ny]==loss)ok=true;
        }
        if(pos[0][1][y][x]==loss)ok=true;
        pos[0][0][x][y] = ok?win:loss;
    }

    cout<<(pos[0][0][x00+205][y00+205]==win?"Anton":"Dasha")<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cout.precision(40);
    cout.setf(ios::fixed, ios::floatfield);
    int nz=1;
    //cin >> nz;

    for(int i=0; i<nz; ++i)
    {
        tc();
    }

    return 0;
}


#include <iostream>

using namespace std;

int y, b, r;

int main()
{
    cin >> y >> b >> r;
    if (b>=r)    b=r-1;
    if (y>=b)    y=b-1;
    if (b-1>y)   b=y+1;
    if (r-1>b)   r=b+1;
    if (y+1>b)   y=b-1;
    cout << b + y + r;
}


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

const int MAX = 1e6 + 10;
const int OO = 0x3f3f3f3f;
const double EPS = 1e-9;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
//#define gc getchar_unlocked

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

bool isCopri(int a, int b)
{
    FOR(i, 2, min(a, b)+1)
        if(a%i == 0 and b%i == 0)
            return false;
    return true;
}

int main()
{
    int n, a, b;
    cin >> n;
    if(n & 1)
        a = n / 2, b = n - (n / 2);
    else
        a = (n / 2) - 1, b = n - ((n / 2) - 1);

    while(a > 1)
        if(isCopri(a, b))
            cout << a << ' ' << b << '\n', a = 0;
        else
            a--, b++;
    if(a)
        cout << a << ' ' << b << '\n', a = 0;

	return 0;
}
// 1513969660211


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll p, q;
  cin >> p >> q;
  if (__gcd(p,q) > 1) {
    cout << "Impossible" << endl;
    return 0;
  }
  vector<pair<char,ll>> ans;
  while (p != 1 || q != 1) {
    if (p >= q) {
      ll k = (p-1)/q;
      ans.push_back({'A',k});
      p -= q*k;
    } else {
      ll k = (q-1)/p;
      ans.push_back({'B',k});
      q -= p*k;
    }
  }
  for (auto p : ans) {
    cout << p.second << p.first;
  }
  cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
using  ll=long long;
const int N=5e3+9,mod=1e9+7;
ll lcm(ll a,ll b){
    return a*b/__gcd(a,b);
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 ll n,a,b,p,q; cin>>n>>a>>b>>p>>q;
 ll red=n/a; ll blue=n/b,in=n/lcm(a,b);
 if(p>q)
     blue-=in;
 else
     red-=in;
 cout<<red*p+blue*q;
}


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

int main()
{
    ios::sync_with_stdio(0);
    ll n,x,y,x1,y1,x2,y2,x3,y3;
    ll ans;
    multiset<pair<ll,ll> >ms;
    cin >> n;
    for(ll i=0;i<n;i++)
    {
        cin >> x >> y;
        ms.insert(make_pair(x,y));
    }
    multiset<pair<ll,ll> >::iterator c;
    if(n==1)
        cout << "-1";
    else if(n==2)
    {
        c = ms.begin();
        x1 = (*c).first;
        y1 = (*c).second;
        if(x1==x && y1==y){
            c++;
            x1 = (*c).first;
            y1 = (*c).second;
        }
        if(x1!=x && y1!=y)
        {
            ans = abs(x1-x)*abs(y1-y);
            cout << ans;
        }
        else
            cout << "-1";
    }
    else if(n==3)
    {
        c = ms.begin();
        x1 = (*c).first;
        y1 = (*c).second;
        c++;
        x2 = (*c).first;
        y2 = (*c).second;
        c++;
        x3 = (*c).first;
        y3 = (*c).second;
        if(x1!=x3 && y1!=y3)
            ans = abs(x1-x3)*abs(y1-y3);
        else if(x1!=x2 && y1!=y2)
            ans = abs(x1-x2)*abs(y1-y2);
        else if(x2!=x3 && y2!=y3)
            ans = abs(x2-x3)*abs(y2-y3);
        cout << ans;
    }
    else if(n==4)
    {
        c = ms.begin();
        x1 = (*c).first;
        y1 = (*c).second;
        c = ms.end();
        c--;
        x2 = (*c).first;
        y2 = (*c).second;
        ans = abs(x1-x2)*abs(y1-y2);
        cout << ans;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int b,g,n;
	cin >> b;
	cin >> g;
	cin >> n;
	int ans = 0;

	for(int i = 0; i <= b; i++)
	{
		for (int j = 0; j <= g; j++)
		{
			if((i+j) == n)
				ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
#define SIZE(a) ((int) (a.size()))

using namespace std;

#define MAXN 6010
const int mod = 1000000007;

int n;

long long int dynamic[MAXN] , dynamic2[MAXN];

int main(){

	string sozdizisi;
	cin >> sozdizisi;

	string sozdizisi2;
	cin >> sozdizisi2;

	n = SIZE(sozdizisi2);

	long long int res=0;

	for(int i=0;i<SIZE(sozdizisi);i++)
	{
		for(int j=0;j<SIZE(sozdizisi2);j++)
		{
			if(sozdizisi2[j]==sozdizisi[i])
				dynamic2[j]=(dynamic2[j]+dynamic[j-1]+1)%mod;
			dynamic2[j+1]=(dynamic2[j+1]+dynamic2[j])%mod;
		}
		res=(res+dynamic2[n])%mod;
		for(int j=0;j<SIZE(sozdizisi2);j++)
			dynamic[j]=dynamic2[j];
		memset(dynamic2,0,sizeof(dynamic2));
	}
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,k, ans, d, l, j;
int main (){
    scanf("%d%d%d", &n, &m, &k);
    if(n == 1) {
        printf("%d", m);
        return 0;
    }
    ans = 1;
    d = m-n;
    j = k;
    l = 1;
    while(d >= l){
        d -= l;
        ans++;
        k --;
        j++;
        if(k >= 1) l++;
        if(j <= n) l++;
        if(k < 1 && j > n) break;
    }
    ans += (d/n);
    printf("%d", ans);
    return 0;
}


// ConsoleApplication15.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

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

long long nod(long long a, long long b)
{
	while (b > 0)
	{
		long long r = a % b;
		a = b;
		b = r;
	}
	return a;

}

long long nok(long long a, long long b)
{
	return a / nod(a, b)*b;
}

int main()
{
	long long a, b;
	cin >> a >> b;
	if (b < a) swap(a, b);
	if (b%a == 0) { cout << 0; return 0; }
	long long d = b - a;
	long long kres = 1000000000,lcmr=1e18;

	for (int i = 1; i*i <= d; i++)
	{
		if (d%i == 0)
		{
			long long k = i - a % i;
			if (a%i == 0) k = 0;
			long long lcm = nok((a + k), (b + k)); // / i;
			if (lcm < lcmr)
			{
				lcmr = lcm;
				kres = k;
			}
			else
				if (lcm == lcmr && k < kres) kres = k;
			k = d/i - a % (d/i);
			if (a%(d/i) == 0) k = 0;
			lcm = nok((a + k), (b + k)); // / (d / i);
			if (lcm < lcmr)
			{
				lcmr = lcm;
				kres = k;
			}
			else
				if (lcm == lcmr && k < kres) kres = k;

		}
	}

	cout << kres;

    //std::cout << "Hello World!\n";
}

// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"

// Советы по началу работы
//   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
//   2. В окне Team Explorer можно подключиться к системе управления версиями.
//   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
//   4. В окне "Список ошибок" можно просматривать ошибки.
//   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
//   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.


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

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define MOD 1000000007ULL
#define INF 1000000000ULL
const int N = 1e5 + 5;
#define FAST ios_base::sync_with_stdio(false)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

inline ll power(ll a, ll b, ll mod){
	ll x = 1;
	a = a%mod;
	while(b){
		if(b & 1) x = (x*a)%mod;
		a = (a*a)%mod;
		b >>= 1;
	}
	return x;
}

ll gcd(ll a, ll b){ return a?gcd(b%a,a):b;}
ll modInverse(ll a, ll mod)
{
    int m0 = mod;
    int y = 0, x = 1;

    if (mod == 1)
      return 0;

    while (a > 1)
    {
        // q is quotient
        int q = a / mod;
        int t = mod;

        // m is remainder now, process same as
        // Euclid's algo
        mod = a % mod, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
       x += m0;

 	 return x;
}

ll m;
ll h1,h2,a1,a2,x1,x2,yy1,y2;

int main()
{
	cin>>m;
	cin>>h1>>a1;
	cin>>x1>>yy1;
	cin>>h2>>a2;
	cin>>x2>>y2;

	ll tmp = 0;
	ll tmp1 = h1;
	ll ans1=-1,ans2=-1;
	while(tmp<m+1 && tmp1 != a1){
		tmp++;
		tmp1 = (tmp1*x1 + yy1)%m;
	}
	if(tmp == m+1 && tmp1 != a1){
		cout<<"-1\n";
		return 0;
	}
	ans1 = tmp;

	tmp = 0;
	tmp1 = h2;
	while(tmp < m+1 && tmp1 != a2){
		tmp++;
		tmp1 = (tmp1*x2 + y2)%m;
	}

	if(tmp == m+1 && tmp1 != a2){
		cout<<"-1\n";
		return 0;
	}
	ans2 = tmp;

	if(ans1 == ans2)
	{
		cout<<ans1<<endl;
		return 0;
	}

	ll rep1=-1,rep2=-1;
	tmp = 1;
	tmp1 = (a1*x1 + yy1)%m;

	while(tmp<m+1 && tmp1 != a1){
		tmp++;
		tmp1 = (tmp1*x1 + yy1)%m;
	}
	if(tmp1 != a1)
		rep1 = -1;
	else
		rep1 = tmp;

	tmp = 1;
	tmp1 = (a2*x2 + y2)%m;
	while(tmp < m+1 && tmp1 != a2){
		tmp++;
		tmp1 = (tmp1*x2 + y2)%m;
	}

	if(tmp1 != a2)
		rep2 = -1;
	else
		rep2 = tmp;

	if(rep1 == -1 && rep2 == -1){
		cout<<"-1\n";
		return 0;
	}
	else if(rep1 == -1){
		ll diff = ans1-ans2;
		if(diff < 0){
			cout<<"-1\n";
			return 0;
		}
		else if(diff%rep2)
		{
			cout<<"-1\n";
			return 0;
		}
		else{
			cout<<ans1<<endl;
			return 0;
		}
	}
	else if(rep2 == -1){
		ll diff = ans2-ans1;
		if(diff < 0){
			cout<<"-1\n";
			return 0;
		}
		else if(diff%rep1)
		{
			cout<<"-1\n";
			return 0;
		}
		else{
			cout<<ans2<<endl;
			return 0;
		}
	}
	else{

		if(ans1>ans2){
			ll ch = rep2,i;
			for(i=0;i<=ch;i++){
				if( (ans1-ans2+rep1*i)%rep2 == 0)
					break;
			}
			if(i == ch+1)
			{
				cout<<"-1\n";
			}
			else{
				cout<<ans1+rep1*i<<endl;
			}
			return 0;
		}
		else{
			ll ch = rep1,i;
			for(i=0;i<=ch;i++){
				if( (ans2-ans1+rep2*i)%rep1 == 0)
					break;
			}
			if(i == ch+1)
			{
				cout<<"-1\n";
			}
			else{
				cout<<ans2+rep2*i<<endl;
			}
			return 0;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

const int N = 1009;
int T = 0, cst[N * N];

void build(int b, int w, int x) {
	int bb = b, tot = 0;
	while (bb != b || !T) {
		if (bb >= x)
			bb -= x;
		else
			++tot, bb += (w - x);
		cst[T++] = tot;
	}
}

ll calc(ll a, ll t) {
	return a - cst[T - 1] * (t / T) - cst[t % T];
}

ll bs(ll a, ll c) {
	if (c <= a)
		return 0;
	ll st = 1, ed = (1LL << 62);
	while (st < ed) {
		ll md = (st + ed) / 2LL;
		if (c - md > calc(a, md - 1))
			st = md + 1;
		else
			ed = md;
	}
	return st;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif
	fastInOut();
	int b, w, x;
	ll a, c;
	cin >> a >> b >> w >> x >> c;
	build(b, w, x), cout << bs(a, c);
	return 0;
}

void fastInOut() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n;
long long a[9];
int s[9];
int ans=1e9;
void solve(int x,vector<long long>v,int res,bool f)
{
	if(x>n)
	{
		if(f)res++;
		ans=min(ans,res);
		return;
	}
	for(int i=0;i<v.size();i++)
	{
		if(v[i]%a[x]==0LL)
		{
			vector<long long>vt=v;
			vt[i]/=a[x];
			vt.push_back(a[x]);
			solve(x+1,vt,res+(s[x]!=1),f);
		}
	}
	vector<long long>vt=v;
	vt.push_back(a[x]);
	solve(x+1,vt,res+s[x],true);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",a+i);
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		long long t=a[i];
		for(long long j=2LL;j*j<=t;j++)
		{
			while(t%j==0LL)
			{
				t/=j;
				s[i]++;
			}
		}
		if(t!=1)s[i]++;
		if(s[i]>1)s[i]++;
	}
	vector<long long>v;
	v.push_back(a[1]);
	solve(2,v,s[1],false);
	printf("%d",ans);
	return 0;
}


#pragma optimize("", on)
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int maxn = (int)2e6 + 10;
const int mod = (int)1e9 + 9;
const int inf = (1<<30) - 1;
int n, w, b;
ll fact[4040];
int c[4040][4040];
void solve() {
    cin >> n >> w >> b;
    fact[0] = 1;
    for(int i = 1; i < 4040; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    for(int i = 0; i < 4040; i++) {
        for(int j = 1; j < i; j++) {
            c[i][j] = (c[i - 1][j - 1] + c[i-1][j]) % mod;
        }
        c[i][0] = c[i][i] = 1;
    }
    ll ans = 0;
    for(int x = 1; x < n; x++) {
        int y = n - x;
        for(int k = 2; k <= 2; k++) {
            ll cur = c[w-1][x-1] *1ll* c[x - 1][k-1] % mod;
            ll cur2 = 0;
            if(k > 1) {
                cur2 = (cur2 + c[b-1][y-1] *1ll* c[y-1][k-2]) % mod;
            }
            //cout << x << " " << k << " " << cur << " "<<cur2 << "\n";
            ans =(ans + cur * cur2) % mod;
        }
    }
    ans = (ans * fact[w]) % mod;
    ans = (ans * fact[b]) % mod;

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

int main() {
    ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //srand(time(0));
    int t = 1;
    //scanf("%d", &t);
    //cin >> t;
    for(int i = 1; i <= t; i++) {
        //printf("Case %d: ", i);
        solve();
    }
    return 0;
}


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

int map[256];

int main(){
    char ch;
    char str1[3],str2[3];
    map['6']=1; map['7']=2; map['8']=3; map['9']=4; //用常量表简化代码
    map['T']=5; map['J']=6; map['Q']=7; map['K']=8; map['A']=9;
    while(~scanf("%c",&ch)){
        getchar();//吸收回车
        scanf("%s",str1);
        scanf("%s",str2);
        getchar();//吸收回车
        if(str1[1]==str2[1]){
            if(map[str1[0]]>map[str2[0]])
                printf("YES\n");
            else
                printf("NO\n");
        }
        else{
            if(str1[1]!=ch)
                printf("NO\n");
            else
                printf("YES\n");
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;

typedef long long Long;

Long pow2(Long base,Long exp)
{
   if(exp*log10(base) > 12)return 10000000000000LL;
   if(exp==0)return 1;
   Long sq = pow2(base,exp>>1);
   sq = sq*sq;
   if(exp&1)sq = sq*base;
   return sq;
}

bool memo[100000][50];
bool cat[100000][50];
bool f = 0;
Long canwin(Long A,Long B,Long N)
{

   if(B==1 && A >= 70000)
   {
      return (N-A)%2 == 0;
   }
   if(A==1 && B >= 40)
   {
      f = true;
      return false;
   }
   if( pow2(A,B) >= N )return true;
   bool w = false;
   if(cat[A][B])return memo[A][B];
   if(!canwin(A+1,B,N) || !canwin(A,B+1,N))w = true;
   cat[A][B] = true;
   return memo[A][B] = w;
}

int main()
{
   memset(cat,false,sizeof(cat));
   Long A,B,N;
   cin>>A>>B>>N;
   if(canwin(A,B,N) && !f)cout<<"Masha"<<endl;
   else if(!f)cout<<"Stas"<<endl;
   else cout<<"Missing"<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum(ll x) {
	ll res = 0;
	while(x) {
		res += x%10;
		x /= 10;
	}
	return res;
}
int main(int args, const char * argv[]) {
	ll n, s;
	cin >> n >> s;
	ll l = 1, r = 1000000000000000000ll, ans = 2000000000000000000ll;
	while(l <= r) {
		ll mid = (l+r) >> 1;
		if(abs(sum(mid)-mid) >= s) {
			r = mid-1;
			ans = mid;
		}
		else l = mid+1;
	}
	cout << max(0ll, n-ans+1) << endl;
	return 0;
}


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


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

LL dp[105][maxn], sum[maxn];

int main()
{
    int a,b,k,t;
    scanf("%d%d%d%d",&a,&b,&k,&t);

    dp[0][0] = 1;
    for(int i = 1; i<=t; i++)
    {
        for(int j = 0; j<maxn; j++)
            sum[j] = ( (j-1>=0?sum[j-1]:0) + dp[i-1][j] )%mod;

        for(int j = 0; j<maxn; j++)
            dp[i][j] = ( sum[j] - (j-2*k-1>=0?sum[j-2*k-1]:0) + mod )%mod;
    }

    for(int j = 0; j<maxn; j++)
            sum[j] = ( (j>0?sum[j-1]:0) + dp[t][j] )%mod;

    LL ans = 0;
    for(int i = 0; i<=2*k*t; i++)
        ans += ( 1LL*dp[t][i] * (i+a-b-1>=0?sum[i+a-b-1]:0) )%mod, ans %= mod;
    printf("%lld\n",ans);

}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <memory.h>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define Forn(i, n) for (int i = 0; i < (n); i++)
#define Fornr(i, n) for (int i = (n) - 1; i > -1; i--)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define Forr(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define fill(a, b) memset((a), (b), sizeof((a)))
#define pb push_back
#define inf 2147483647
#define F first
#define S second
#define N 1000010

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

int n;
char p[N];

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

int main()
{
#ifdef LocalHost
    freopen("in", "r", stdin);
//    freopen("out", "w", stdout);
#endif
    scanf("%d", &n);
    ll ans = 1;
    For(i, n - 310, n)
        For(j, i, n + 1)
            For(e, j + 1, n + 1)
            if (i > 0)
            {
                ans = max(nok(e, nok(i, j)), ans);
            }
/*    fill(p, 1);
    For(i, 2, n)
        if (p[i])
            for (int j = i + i; j <= n; j += i)
                p[j] = 0;
    int k = 0;
    ll c = 1;
    Fornr(i, n + 1)
        if (p[i])
        {
            c *= i;
            k++;
            if (k == 1 && n - i > 2)
                ans = max(ans, i * 1ll * n * (n - 1) / __gcd(n, n - 1));
            if (k == 2)
                break;
        }
    Fornr(i, n + 1)
        if (!p[i])
        {
            c *= i;
            k++;
            if (k == 3)
                break;
        }*/
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b){
	while(b != 0){
		a %= b;
		swap(a, b);
	}
	return a;
}

int main(){
	ll n, k; cin >> n >> k;
	ll multiple = n*k;
	ll x, y; cin >> x >> y;
	ll mn = 100000000000, mx = 0;

	for(ll i = abs(y - x); i <= multiple; i+= k){
		if(i == 0)
			continue;
		ll value = gcd(multiple, i);
		mn = min(mn, value);
		mx = max(mx, value);
	}
	for(ll i = k - y - x; i <= multiple; i+= k){
		if(i == 0)
			continue;
		ll value = gcd(multiple, i);
		mn = min(mn, value);
		mx = max(mx, value);
	}
	cout << multiple/mx << " " << multiple/mn << endl;
}


/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Tarikul Islam
            Department of CSE, City University, Bangladesh.

***/

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

#define sf          scanf
#define pf          printf
#define ssf         sscanf
#define spf         sprintf
#define fsf         fscanf
#define fpf         fprintf
#define fast        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define scase       sf ("%d",&tc)
#define sn          sf ("%d",&n)
#define whilecase   while (tc--)
#define eof         while (cin >> n)
#define forcase     for(kase=1; kase<=tc; kase++)
#define arrayloop   for(i=0; i<n; i++)
#define cinstr      cin >> str
#define getstr      getline (cin,str)
#define pcase       pf ("Case %d: ",kase)
#define pii         pair <int,int>
#define pb          push_back
#define in          insert
#define llu         unsigned long long
#define lld         long long
#define U           unsigned int
#define endl        "\n"
#define TarikulCSE  int main()
#define signoff     return 0

TarikulCSE
{

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

    */

    lld n;

    cin>>n;

    if(n%2 == 0)
    {
        if((n/2)%2 == 0)
            cout<<"0"<<endl;
        else
            cout<<"1"<<endl;
    }
    else
    {
        lld result = ((n*(n+1))/2)%2;
        cout<<result<<endl;

    }

    signoff;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <iostream>
using namespace std;

int a, b, n, mod = 1000000007;

int mas[1000], sz = 0;
int cnk[1000006];

int binpow(int a, int k)
{
    int ans = 1;
    while(k)
    {
        if(k & 1)
            ans = (1ll*ans*a)%mod;
        a = (1ll*a*a)%mod;
        k /= 2;
    }
    return ans;
}

int main()
{
    cin >> a >> b >> n;
    int s = b*n;

    for(int i = 1; i <= 7; ++i)
    {
        for(int j = (1 << i)-1; j >= 0; --j)
        {
            int num = 0;
            for(int k = 0; k < i; ++k)
            {
                num *= 10;
                num += (j & (1 << k)) ? a : b;
            }
            if(num <= s)
                mas[sz++] = num;
        }
    }

    cnk[0] = 1;
    cnk[1] = n;
    long long tm = n;
    for(int i = 2; i <= n; ++i)
    {
        tm = (tm*(n-i+1))%mod;
        tm = (tm*binpow(i, mod-2))%mod;
        cnk[i] = tm;
    }

    long long ans = 0;
    for(int i = 0; i < sz; ++i)
    {
        if((mas[i]-n*b) % (a-b) == 0)
        {
            int q = (mas[i]-n*b) / (a-b);
            if(q >= 0 && q <= n)
            {
                ans += cnk[q];
                ans %= mod;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
int main()
{
    char sum[3][100],s1[100],s2[100],s3[100];
    strcpy(sum[0],"qwertyuiop");
    strcpy(sum[1],"asdfghjkl;");
    strcpy(sum[2],"zxcvbnm,./");
    char m,s[1000],b[1000];
    while(cin>>m)
    {
        getchar();
        gets(s);
        memset(b,'\0',sizeof(b));
        if(m=='R')
        {
            for(int i=0;i<3;i++)
            {
                for(int j=0;sum[i][j]!='\0';j++)
                {
                    for(int k=0;s[k]!='\0';k++)
                    {
                        if(s[k]==sum[i][j])b[k]=sum[i][j-1];
                    }
                }
            }
        }
        else if(m=='L')
        {
            for(int i=0;i<3;i++)
            {
                for(int j=0;sum[i][j]!='\0';j++)
                {
                    for(int k=0;s[k]!='\0';k++)
                    {
                        if(s[k]==sum[i][j])b[k]=sum[i][j+1];

                    }
                }
            }
        }
        puts(b);

    }
    return 0;

}


// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

int n;
set<int>st;

int lca(int a,int b){
    if(__builtin_clz(a)>__builtin_clz(b)) swap(a,b);
    while(__builtin_clz(a)<__builtin_clz(b)) a>>=1;
    while(a!=b) a>>=1,b>>=1;
    return a;
}
inline bool papa(int a,int b){// a!=b
    if(b<=a) return 0;
    int dif=__builtin_clz(a)-__builtin_clz(b);
    return a==(b>>dif);
}
int Size(int a){
    int x=1,ans=0;
    while(a<=n){
	ans+=min(x,n-a+1);
	x<<=1,a<<=1;
    }
    return ans;
}
int Size(int a,set<int>&s){
    int ans=Size(a);
    vector<int>vv;
    for(int x:s){
	if(x<a) continue;
	bool bl1=papa(a,x),bl2=0;
	for(int y:vv) bl2|=papa(y,x);
	if(bl1 && !bl2) vv.PB(x),ans-=Size(x);
    }
    return ans;
}
int solve(int a,int b){
    set<int>st2;
    int ans=0;
    for(int A=a;A>0;A>>=1){
	st2=st;
	for(int B=b;B>0;B>>=1){
	    ans=(1ll*ans+1ll*Size(A,st2)*Size(B,st2))%mod;
	    if(st2.count(B>>1)) break;
	    st2.insert(B>>1);
	}
	if(st.count(A>>1)) break;
	st.insert(A>>1);
    }
    return ans;
}

int CNT=0;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int m;cin>>n>>m;
    vector<pii>vv(m),vv2;
    for(int i=0;i<m;i++){
	cin>>vv[i].F>>vv[i].S;
    }
    ll ans=(1ll*n*n)%mod;
    for(int msk=1;msk<(1<<m);msk++){
	vv2.clear();
	for(int i=0;i<m;i++){
	    if(bit(msk,i))
		vv2.PB(vv[i]);
	}
	vector<int>perm(sz(vv2));
	for(int i=0;i<sz(vv2);i++)
	    perm[i]=i;
	do{
	    vector<pii>vv3(sz(vv2));
	    for(int i=0;i<sz(vv2);i++)
		vv3[i]=vv2[perm[i]];
	    //	    for(pii pp:vv3) cout<<pp.F<<" "<<pp.S<<" || ";
	    //	    cout<<endl;

	    int lst=-1,frst=-1;
	    for(int msk2=0;msk2<(1<<sz(vv2));msk2++){
		st.clear();
		frst=vv3[0].F,lst=vv3[0].S;
		if(bit(msk2,0)) swap(frst,lst);
		st.insert(frst);

		//		cout<<"START    "<<frst<<" "<<lst<<" ";

		for(int i=1;i<sz(vv3);i++){
		    pii p=vv3[i];
		    if(bit(msk2,i)) swap(p.F,p.S);

		    //		    cout<<p.F<<" "<<p.S<<" ";

		    int A=lst,B=p.F,C=lca(A,B);
		    while(A!=C){
			if(st.count(A)) goto Hell;
			st.insert(A);
			A>>=1;
		    }
		    while(B!=C){
			if(st.count(B)) goto Hell;
			st.insert(B);
			B>>=1;
		    }
		    if(st.count(C)) goto Hell;
		    st.insert(C);

		    lst=p.S;
		}
		if(st.count(lst))
		    goto Hell;
		st.insert(lst);
		ans=(ans+solve(frst,lst))%mod;
	    Hell:;
	    }
	}while(next_permutation(perm.begin(),perm.end()));
    }
    return cout<<ans<<endl,0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    string str;
     bool f=true;
    for (int i = 0; i < 8; i++)
    {
        cin >> str;
        for (int j = 1; j < str.length(); j++)
        {
            if (str[j] == str[j-1])
            {
                f = false;
            }
        }
    }
    if (f)
        cout<< "YES";

    else
        cout<< "NO";

        return 0 ;

}


#include <vector>
#include<iostream>
#include<cstring>
#include <queue>
#include <utility>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#define pb push_back
#define mp make_pair
#define MAX 55
#define MAXN 2005
#define ll int
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >

using namespace std;

const ll mod = 1e9 + 7;

ll n,s,k;

ll inp[MAX];

string str;

vector<piii > arr;

ll dp[MAX][MAXN][MAX];

ll brr[MAX];

ll solve(ll idx,ll rem,ll prev)
{
    if(rem <= 0)
        return 0;
    if(idx == n + 1)
        return 1e9;
    if(dp[idx][rem][prev] != -1)
        return dp[idx][rem][prev];
    ll ans = 1e9;
    ans = min(ans,solve(idx + 1,rem,prev));
    if(arr[idx].first > arr[prev].first && arr[idx].second.second != arr[prev].second.second)
        ans = min(ans,solve(idx + 1,rem - arr[idx].first ,idx) + abs(arr[idx].second.first - arr[prev].second.first));
    return dp[idx][rem][prev] = ans;
}

int main()
{
    cin>>n>>s>>k;
    ll i,j;
    for(i = 0;i < n;i++)
        cin>>inp[i];
    cin>>str;
    ll len = str.length();
    arr.pb(mp(0,mp(s,0)));
    for(i = 0;i < len;i++)
    {
        if(str[i] == 'R')
            brr[i] = 1;
        else if(str[i] == 'G')
            brr[i] = 2;
        else
            brr[i] = 3;
        arr.pb(mp(inp[i],mp(i + 1,brr[i])));
    }
    sort(arr.begin(),arr.end());
        //for(i = 0;i < arr.size();i++)
        //cout<<arr[i].first<<" "<<arr[i].second.first<<" "<<arr[i].second.second<<endl;;
    memset(dp,-1,sizeof(dp));
    ll ans = solve(1,k,0);
    if(ans >= 1e9)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#define PI acos(-1.0)
using namespace std;
const int N = 1000;
typedef long long ll;
int n,m;//coffee数量，作业数
int a[N];
bool cmp(int x,int y){
	return x > y;
}
bool check(int x){
	//时间偏大返回true
	ll summ = 0;
	int t = 0;
	for(int i = 0;i<n;i++){
		if(a[i] - t>0)
			summ += a[i] - t;
		else break;
//思考一下为什么这里用我写的就过不了！！！！！！！！！！！！！
// 在使用函数对数据进行操作得到时候一定要注意，千万不要改变某个值！！！
//		summ += a[i] - t;
		if((i+1)%x==0) t++;
//		if(a[i] - t <= 0) break;
	}
	 return summ >= m;
}
int main(){
	ll sum = 0;
	cin>>n>>m;
	for(int i = 0;i<n;i++){
		scanf("%d",&a[i]);
		sum += a[i];
	}
	if(sum < m){
		cout<<-1<<endl;
		return 0;
	}
	else if(sum == m){
		cout<<n<<endl;
		return 0;
	}
	sort(a,a+n,cmp);
	int l = 1, r = n + 1,mid;//左闭右开
	while(l < r){
		mid = (l + r - 1) >> 1;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	cout<<r<<endl;
	return 0;
}


/*
 * Created by: Son Dinh
 */
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sqr(x) (x)*(x)
#define sz(X) (int)(X).size()
#define all(x) x.begin(),x.end()
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

const int mod = 1e9+7;

string s,t;
int res,l[200005],r[200005];
int32_t main(){
    cin >> s >> t;
    int n = sz(s), m = sz(t), len = 0;
    for(int i = 0; i < n && len < m; ++i){
        if(s[i] == t[len]){
            l[len++] = i;
        }
    }
    len = m - 1;
    for(int i = n-1; i >= 0 && len >= 0; --i){
        if(s[i] == t[len]){
            r[len--] = i;
        }
    }
    res = max(max(0LL,r[0]), n - l[m-1] - 1);
    for(int i = 1; i < m; ++i){
        res = max(res, r[i] - l[i-1] - 1);
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int n,m;
bool judge(int x)
{
    int base=1;
    bool flg=true;
    for (int i = 2; i*i <= x; ++i) {
        if(x%i==0) {
            base=i;
            flg=false;
            break;
        }
    }
    if(flg)
        return true;
    else return base>n;
}
int main()
{
    while(cin>>n>>m)
    {
        int num=0;
        int ans=-1;
        for (int i = m; i > n; --i) {
            if(judge(i))
            {
                ans=i;
                break;
            }
            num++;
            if(num>456)
            {
                break;
            }
        }
        cout<<ans<<endl;

    }
}


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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    while (a + b + c - 3 > k) {
        if (a >= b && a >= c)
            a--;
        else if (b >= a && b >= c)
            b--;
        else
            c--;
    }

    cout << 1ll * a * b * c << '\n';
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <cmath>
using namespace std;
#define MOD 1000000007
int main(){
    int n;
    cin >> n;
    long long a = 0, b = 0, ans = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            ans = (ans + a + 1) % MOD;
            b = (a + b + 1) % MOD;
        }
        else {
            ans = (ans + b + 1) % MOD;
            a = (a + b + 1) % MOD;
        }
    }
    cout << ans << endl;
}


#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=210;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
LL f[N][N][2];
LL calc (int a,int b,LL s,int c)//s=p+q,c=cntp+cntq
{
    int m=max (max (a-1,b),(int)log2 (s)+1);
    for (int i=0; i<=m; i++)
        for (int j=0; j<=c; j++)
            f[i][j][0]=f[i][j][1]=0;
    for (int x=0; x<=1; x++)
        for (int y=0; y<=1; y++)
        {
            if (b==1&&!y) continue;
            if (((x+y)&1)!=(s&1)) continue;
            if (a<=1&&x) continue;
            if (b<=0&&y) continue;
            ++f[0][x+y][x&&y];
        }
    for (int i=0; i< m; i++)
    {
        LL d=s>>(i+1)&1;
        for (int j=0; j<=c; j++)
            for (int t=0; t<=1; t++) if (f[i][j][t])
                for (int x=0; x<=1; x++)
                    for (int y=0; y<=1; y++)
                    {
                        int g=x+y+t;
                        if (i+1==b-1&&!y) continue;
                        if ((g&1)!=d) continue;
                        if (i+1> a-2&&x) continue;
                        if (i+1> b-1&&y) continue;
                        f[i+1][j+x+y][g>=2]+=f[i][j][t];
                    }
    }
    return f[m][c][0];
}
LL calc (LL x)
{
    LL ans=x<<1;
    while (x) ans-=x&1,x>>=1;
    return ans;
}
int a[N],b[N];
LL lca (LL x,LL y)
{
    int n=0,m=0;
    while (x) a[n++]=x&1,x>>=1; reverse (a,a+n);
    while (y) b[m++]=y&1,y>>=1; reverse (b,b+m);
    chkmin (n,m);
    LL z=0;
    for (int i=0; i< n; i++)
        if (a[i]==b[i]) z=z<<1|a[i];
        else break;
    return z;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
    LL s; sc(s);
    LL ans=0;
    for (int a=0; a< 50; a++)
        for (int b=0; b< 50; b++)
        {
            LL v=((1LL<<(a+1))+(1LL<<(b+1))-3),z=s/v;
            if (!z) continue;
            if ((int)log2 (z)+1+max (a,b)> 50) continue;
            LL k=s-v*z;
            for (int c=0; c<=a+b; c++)//cntp+cntq
                if (!((k+c)&1)) ans+=calc (a,b,(k+c)>>1,c);
        }
    pr(ans);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    long long a,b,x,y;

    cin>>a>>b>>x>>y;

    long long g=__gcd(x,y);

    x=x/g;
    y=y/g;

    long long r=a%x;
    a=a-r;

    while(1){
        if(a<=0){
            cout<<0<<" "<<0<<endl;
            break;
        }

        long long temp=(a/x)*y;

        if(temp<=b&&temp>0){
            cout<<a<<" "<<temp<<endl;
            break;
        }

        else if(temp<=0){
            cout<<0<<" "<<0<<endl;
            break;
        }

        else{
            a=(b*x)/y;
            a=a-(a%x);
        }

        }

    return 0;
}


/*qrev*/
#include <iostream>
#include <string>
using namespace std;
string s;
int dp[110] = { 0 };
int state[110] = { 0 };
int cur = 0;
int main(int argc, const char * argv[]) {
	cin >> s;
	int length = s.size();
	if (length == 1)
	{
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i<length; i++)
	{
		if (s[i] == 'V'&&s[i + 1] == 'K')
		{
			state[i] = state[i + 1] = 3;
			i++;
			cur++;
		}
		else if (s[i] == 'V')
			state[i] = 1;
		else  if (s[i] == 'K')
			state[i] = 2;
	}
	int flag = 0;
	for (int i = 0; i<length; i++)
	{
		if ((state[i] == state[i + 1]) && state[i] != 3)
			flag = 1;
	}
	cout << cur + flag << endl;
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <assert.h>
#include <bitset>
#include <string>
#include <cstdio>
#include <math.h>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
using namespace std;

#define int64 long long
#define mp make_pair

#ifdef _DEBUG
	const int N = 210;
#else
	const int N = 210;
#endif

int n;
string s;
bool used[N][N][N];

void dfs(int b, int g, int r)
{
	if (used[b][g][r]) return;
	used[b][g][r] = true;
	if (b >= 1 && g >= 1) dfs(b - 1, g - 1, r + 1);
	if (b >= 1 && r >= 1) dfs(b - 1, g + 1, r - 1);
	if (g >= 1 && r >= 1) dfs(b + 1, g - 1, r - 1);
	if (b >= 2) dfs(b - 1, g, r);
	if (g >= 2) dfs(b, g - 1, r);
	if (r >= 2) dfs(b, g, r - 1);
}

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	scanf("%d\n", &n);
	cin >> s;
	int b = 0, g = 0, r = 0;
	for (int i = 0; i < n; i++)
		if (s[i] == 'B') b++;
		else if (s[i] == 'G') g++;
		else r++;
	memset(used, false, sizeof(used));
	dfs(b, g, r);
	if (used[1][0][0]) cout << 'B';
	if (used[0][1][0]) cout << 'G';
	if (used[0][0][1]) cout << 'R';
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int d[21][21][1<<8][1<<8];
int B[21],C[21];
int a[21];
char s[21][21];
int cx[10],cy[10],bx[10],by[10];
int n,m,cnt,bcnt;
struct node
{
    int x,y,s1,s2;
};
bool in(int x,int y)
{
    return x>=0&&x<n&&y>=0&&y<m;
}
bool check(int x,int y,int nx,int ny,int gx,int gy)
{
    if(x==gx&&gy<y)
    {
        if(nx>x)
            return 1;
    }
    if(nx==gx&&gy<ny)
    {
        if(x>nx)
            return 1;
    }
    return 0;
}
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
void bfs(int sx,int sy)
{
    queue<node>q;
    d[sx][sy][0][0]=0;
    node tmp;tmp.x=sx;tmp.y=sy;tmp.s1=0;tmp.s2=0;
    q.push(tmp);
    while(!q.empty())
    {
        node now=q.front();
        q.pop();
        int x=now.x;
        int y=now.y;
        int s1=now.s1;
        int s2=now.s2;
        int nx,ny,ns1,ns2;
        for(int k=0;k<4;k++)
        {
            int nx=x+dx[k];
            int ny=y+dy[k];
            ns1=s1;ns2=s2;
            if(!in(nx,ny)||s[nx][ny]!='.')
                continue;
            for(int i=0;i<cnt;i++)
            {
                if(check(x,y,nx,ny,cx[i],cy[i]))
                    ns1^=(1<<i);
            }
            for(int i=0;i<bcnt;i++)
            {
                if(check(x,y,nx,ny,bx[i],by[i]))
                    ns2^=(1<<i);
            }
            if(d[nx][ny][ns1][ns2]==-1)
            {
                d[nx][ny][ns1][ns2]=d[x][y][s1][s2]+1;
                tmp.x=nx;tmp.y=ny;tmp.s1=ns1;tmp.s2=ns2;
                q.push(tmp);
            }
        }
    }
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",s[i]);
    int sx,sy;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j]>='1'&&s[i][j]<='8')
            {
                cx[s[i][j]-'1']=i;
                cy[s[i][j]-'1']=j;
                cnt++;
            }
            else if(s[i][j]=='B')
            {
                bx[bcnt]=i;
                by[bcnt]=j;
                bcnt++;
            }
            else if(s[i][j]=='S')
            {
                sx=i;sy=j;
            }
        }
    }
    for(int i=0;i<cnt;i++)
        scanf("%d",&a[i]);
    memset(d,-1,sizeof(d));
    s[sx][sy]='.';
    bfs(sx,sy);
    int ans=0;
    for(int i=0;i<(1<<cnt);i++)
    {
        int cur=0;
        if(d[sx][sy][i][0]==-1)
            continue;
        for(int j=0;j<cnt;j++)
        {
            if(i&(1<<j))
                cur+=a[j];
        }
        ans=max(ans,cur-d[sx][sy][i][0]);
    }
    printf("%d",ans);
}


#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
	int M,n, a, b, c;
    cin.tie(0);
    cin >> n >> a >> b >> c;
    M =min(min(a, b), c);
	if (n == 1)
	{
		cout << 0;
	}
	if (M == c && n!=1)
	{
		cout << (min(a, b) + c * (n - 2));
	}
	else if(n!=1 && M!=c )
	{
		cout << (min(a, b)*(n - 1));
	}
}


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

#define FIO                     ios::sync_with_stdio(false); cin.tie(nullptr)
#define TC(t)                   int t; cin >> t; for(int i = 1; i <= t; i++)
#define ll                      long long int
#define ull                     unsigned long long int
#define lll                     __int128
#define lld                     long double
#define loop(i, a, b)           for(ll i = a; i <= b; i++)
#define loop2(i, b, a)          for(ll i = b; i >= a; i--)
#define ini(x, y)               memset(x, y, sizeof(x))
#define all(x)                  x.begin(), x.end()
#define all2(x)                 x.rbegin(), x.rend()
#define sz(x)                   (ll)x.size()
#define pb                      push_back
#define ppb                     pop_back
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define M                       1000000007
#define endl                    '\n'
#define bits(x)                 __builtin_popcountll(x)
#define zrbits(x)               __builtin_ctzll(x)
#define vl                      vector<ll>
#define pll                     pair<ll,ll>
#define vpll                    vector<pll>
#define uni(x)                  x.erase(unique(all(x)), x.end())
#define ordered_set             tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define multi_ordered_set       tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define mxheap                  priority_queue<ll>
#define mnheap                  priority_queue<ll, vector<ll>, greater<ll>>
#define mxheap2                 priority_queue<pair<ll,ll>>
#define mnheap2                 priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>>

const int N = 2e5 + 5;
const int L = 20;
const int MX = 1e9 + 10;
const ll INF = 1e18;

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

using namespace std;
using namespace __gnu_pbds;

inline ll uceil(ll a,ll b) {return (a % b ? a / b + 1 : a / b);}
inline ll mod(ll x) {return ( (x % M + M) % M );}
ll ulog(ll val, ll base) {ll cnt = 0; val /= base; while(val) {cnt++; val /= base;} return cnt;}
ll power(ll a, ll b) {ll res = 1; while (b) {if (b & 1) res = res * a; a = a * a; b >>= 1;} return res;}
ll modpow(ll a, ll b) {ll res = 1; while (b) {if (b & 1) res = res * a % M; a = a * a % M; b >>= 1;} return res;}

#ifndef ONLINE_JUDGE
#define deb(x)                  cerr << #x << " = " << x << endl;
#define deb2(x, y)              cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define deb3(x, y, z)           cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define deb4()                  cerr << endl;
#define done                    cerr << "Line " << __LINE__ << " is done" << endl;
#else
#define deb(x)
#define deb2(x, y)
#define deb3(x, y, z)
#define deb4()
#define done
#endif

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {for(auto& x : v) os << x << " "; return os;}
template<typename T> ostream& operator<<(ostream& os, const set<T>& v) {for(auto& x : v) os << x << " "; return os;}
template<typename T, typename S> ostream& operator<<(ostream& os, const pair<T, S>& p) {os << p.first << ' ' << p.second; return os;}
template<typename... T> void in(T&... args) {((cin >> args), ...);}
template<typename... T> void out(T&&... args) {((cout << args << endl), ...);}
template<typename... T> void out2(T&&... args) {((cout << args << " "), ...);}
template<typename... T> void out3(T&&... args) {((cout << args << " "), ...); cout << endl;}

ll fact[N], invfact[N];

void precompute() {
        fact[0] = invfact[0] = 1;
        for (int i = 1; i < N; i++) {
                fact[i] = fact[i - 1] * i % M;
        }
        invfact[N - 1] = modpow(fact[N - 1], M - 2);
        for(int i = N - 2; i >= 0; i--) {
                invfact[i] = invfact[i + 1] * (i + 1) % M;
        }
}

ll nCr(ll n, ll r) {
        if (r < 0 || n < 0 || r > n) return 0;
        return fact[n] * invfact[r] % M * invfact[n - r] % M;
}

void solve() {
        ll n, k;
        cin >> n >> k;
        ll ans = 0;
        loop(i, 0, min(k, n)) {
                ans += nCr(n, i);
                ans %= M;
        }
        cout << ans << endl;
}

signed main () {
        precompute();
        #ifndef ONLINE_JUDGE
                freopen("input.txt", "r", stdin);
                freopen("output.txt", "w", stdout);
        #endif
        FIO;
        // TC(t)
        solve();
        return 0;
}


#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int a, b, c, d, e, f, s = 0;

    cin >> a >> b >> c >> d >> e >> f;

    switch(e > f){
    case true:
        while(a > 0 && d > 0){
            a--;
            d--;
            s+= e;
        }
        while(b > 0 && c > 0 && d > 0){
            b--;
            c--;
            d--;
            s+= f;
        }
    case false:
        while(b > 0 && c > 0 && d > 0){
            b--;
            c--;
            d--;
            s+= f;
        }
        while(a > 0 && d > 0){
            a--;
            d--;
            s+= e;
        }
    }

    cout << s;

    return 0;
}


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

#define ll long long

vector <ll> v;
vector <ll> vv;
set <ll> st;

ll x,y,z;
string s,s1,s2;

void memset_ll(ll a[], ll v, ll n)
{
    for(ll i=0; i<n; i++)
        a[i]=v;
}
void memset_s(char a[], char v, ll n)
{
    for(ll i=0; i<n; i++)
        a[i]=v;
}

int compare(const void * a, const void * b)
{
    return ( *(ll*)a - *(ll*)b );
}
void q_sort(ll a[], ll n)
{
    qsort(a, n, sizeof(ll), compare);
}

static int compare1 (const void * a, const void * b)
{
    if (*(double*)a > *(double*)b)
        return 1;
    else if (*(double*)a < *(double*)b)
        return -1;
    else
        return 0;
}
void q_sort_d(double a[], ll n)
{
    qsort(a, n, sizeof(double), compare1);
}

ll sum(ll n)
{
    ll i=0,a[6],j,k=0;
    while(n>0)
    {
        a[i]=n%10;
        n/=10;
        i++;
    }
    for(j=0; j<i; j++)
        k+=a[j];
    return k;
}

string trans_upper(string ss)
{
    transform(ss.begin(),ss.end(),ss.begin(), ::toupper);
    return ss;
}

ll power(ll a, ll b)
{
    ll pow = 1;
    while ( b )
    {
        if ( b & 1 )
        {
            pow = pow * a;
            --b;
        }
        a = a*a;
        b = b/2;
    }
    return pow;
}

ll fact(ll n)
{
    ll f=1,i;
    for(i=1; i<=n; i++)
        f=f*i;
    return f;
}

ll is_prime(ll n)
{
    ll i,j,k=1;
    for(i=2; i<=n/2; i++)
    {
        if(n%i==0)
        {
            k=0;
            break;
        }
    }
    return k;
}

int main()
{
    ll t,l,p,q,n,m,o=0,r,i,j,h,k,e=0,d=0,f=0,g=0;
    ll temp=0,nl,np;
    double p1,p2=0.0,p3=0.0,p4,p5,p6,pp,ppp;
    p1=3.1415926536;
    string ss,s3[7];
    cin>>s;
    cin>>ss;
    s3[0]="saturday";
    s3[1]="sunday";
    s3[2]="monday";
    s3[3]="tuesday";
    s3[4]="wednesday";
    s3[5]="thursday";
    s3[6]="friday";
    for(i=0;i<7;i++)
    {
        t=s.compare(s3[i]);
        if(t==0)
            p=i;
        t=ss.compare(s3[i]);
        if(t==0)
            q=i;
    }
    if(q<p)
        q+=7;
    r=q-p;
    if(r==0||r==3||r==2)
    {
        cout<<"YES";
        return 0;
    }
    cout<<"NO";

    return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
//#define int long long
using namespace std;
typedef long long ll;
typedef long double ldb;
const int Mod=1e9+7;
const int blo=32767;
const ldb Pi=acos(-1.0);
struct complex{
	ldb x,y;
	complex (ldb xx=0,ldb yy=0){ x=xx; y=yy;}
};
ll n; int m,bit,len,rev[550000];
ll fac[1100000],inv[1100000],invfac[1100000];
ll A[550000],B[550000],aa[550000],bb[550000];
complex a[550000],b[550000],c[550000],d[550000],
		e[550000],f[550000],g[550000],h[550000];
complex operator+(complex a,complex b){ return complex(a.x+b.x,a.y+b.y);}
complex operator-(complex a,complex b){ return complex(a.x-b.x,a.y-b.y);}
complex operator*(complex a,complex b){ return complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}

void FFT(complex *A,int type){
	for (int i=0;i<len;i++)
		if (i<rev[i]) swap(A[i],A[rev[i]]);
	for (int mid=1;mid<len;mid<<=1){
		complex Wn(cos(Pi/mid),type*sin(Pi/mid));
		for (int R=mid<<1,j=0;j<len;j+=R){
			complex w(1,0);
			for (int k=0;k<mid;k++,w=w*Wn){
				complex x=A[j+k],y=w*A[j+mid+k];
				A[j+k]=x+y; A[j+mid+k]=x-y;
			}
		}
	}
}
void MTT(ll *A,ll *B,ll *res){
	memset(a,0,sizeof(a)); memset(b,0,sizeof(b));
	memset(c,0,sizeof(c)); memset(d,0,sizeof(d));
	memset(e,0,sizeof(e)); memset(f,0,sizeof(f));
	memset(g,0,sizeof(g)); memset(h,0,sizeof(h));
	for(int i=0;i<=m;i++) a[i].x=A[i]/blo,b[i].x=A[i]%blo;
	for(int i=0;i<=m;i++) c[i].x=B[i]/blo,d[i].x=B[i]%blo;
	FFT(a,1); FFT(b,1);
	FFT(c,1); FFT(d,1);
	for(int i=0;i<len;i++){
		e[i]=a[i]*c[i]; f[i]=a[i]*d[i];
		g[i]=b[i]*c[i]; h[i]=b[i]*d[i];
	}
	FFT(e,-1); FFT(f,-1);
	FFT(g,-1); FFT(h,-1);
	for (int i=0;i<=m;i++) res[i]=((ll)(e[i].x/len+0.5)%Mod*blo%Mod*blo%Mod+
									(ll)(f[i].x/len+0.5)%Mod*blo%Mod+
									(ll)(g[i].x/len+0.5)%Mod*blo%Mod+
									(ll)(h[i].x/len+0.5)%Mod)%Mod;
}
void mult(ll *A,ll *B,ll x){
    ll tmp=1;
    for (int i=0;i<=m;i++) bb[i]=B[i]*tmp%Mod,tmp=tmp*x%Mod;
    for (int i=0;i<=m;i++) aa[i]=A[i];
    MTT(aa,bb,B);
}
ll C(int n,int m){
	if (n<m) return 0;
	return fac[n]*invfac[m]%Mod*invfac[n-m]%Mod;
}
int main(){
	scanf("%lld%d",&n,&m);
	if (n>m){ puts("0"); return 0;}
	fac[0]=1; for (int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%Mod;
	inv[1]=1; for (int i=2;i<=1000000;i++) inv[i]=(Mod-Mod/i)*inv[Mod%i]%Mod;
	invfac[0]=1; for (int i=1;i<=1000000;i++) invfac[i]=invfac[i-1]*inv[i]%Mod;

	len=1; bit=0; while (len<=m+m) len<<=1,bit++;
	for (int i=0;i<len;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));

    B[0]=1;
    for (int i=1;i<=m;i++) A[i]=invfac[i];
	ll t=2;
	while (n){
		if (n&1) mult(A,B,t);
		mult(A,A,t);
		t=t*t%Mod; n>>=1;
	}
    ll ans=0;
    for (int i=0;i<=m;i++) ans=(ans+B[i]*fac[i]%Mod*C(m,i)%Mod)%Mod;
    printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int x,y,z;
	cin>>x>>y;
	z=sqrt(x*x*1.0+y*y*1.0);
	if(z==sqrt(x*x*1.0+y*y*1.0))
	{
		cout<<"black";
		return 0;}
	if(z%2==0)
		if((x>=0&&y>=0 )|| (x<=0 &&y<=0))
			cout<<"black";
		else cout<<"white";
	else
		if((x>=0&&y>=0 )|| (x<=0 &&y<=0))
			cout<<"white";
		else cout<<"black";

	return 0;

}


//
//  main.cpp
//  irinasolves
//
//  Created by Irina Korneeva on 02/08/16.
//  Copyright © 2016 Irina. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
struct el {
    long long x, y;
};
using namespace std;
int main(int argc, const char * argv[]) {
    long long d, k, a, b, t;
    cin >> d >> k >> a >> b >> t;
    if(k > d) {
        cout << d * a;
        return 0;
    }
    if(a  >= b ) {
        cout << b * d;
        //cout << "ir";
    } else {
            long long n = d/k;
            long long ans =  n * a * k + (n - 1) * t;
            if(t + k * a > k * b) {
                    cout << k * a + (d - k) * b;
                   // cout << "ir";
            } else if(d % k) {
                ans += t + (d - n * k) * a;
                cout << min(ans, n * a * k + (n - 1) * t +  (d - n * k) * b);
            } else {
                cout << ans;
            }
    }
}


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

struct matrix
{
    ll v[7][7];
};
matrix bin,ans;
ll mod,x,y,sp_x,sp_y,t;

matrix mult(matrix a,matrix b)
{
    matrix temp;
    for(int i=0;i<6;i++)
        for(int j=0;j<6;j++)
        {
            temp.v[i][j]=0;
            for(int k=0;k<6;k++)
                temp.v[i][j]=(temp.v[i][j]+a.v[i][k]*b.v[k][j]-1)%mod+1;
        }
    return temp;
}

matrix quick(matrix a,matrix b,ll n)
{
    while(n)
    {
        if(n&1)
            a=mult(a,b);
        b=mult(b,b);
        n>>=1;
    }
    return a;
}

void init()
{
    memset(ans.v,0,sizeof(ans.v));
    ans.v[0][0]=x;
    ans.v[0][1]=y;
    ans.v[0][2]=sp_x;
    ans.v[0][3]=sp_y;
    ans.v[0][4]=0;
    ans.v[0][5]=1;

    memset(bin.v,0,sizeof(bin.v));
    for(int i=0;i<4;i++)
        bin.v[0][i]=bin.v[1][i]=1;
    bin.v[0][0]=bin.v[1][1]=2;

    bin.v[2][0]=bin.v[2][2]=1;
    bin.v[3][1]=bin.v[3][3]=1;
    bin.v[5][5]=bin.v[5][4]=1;
    for(int i=0;i<5;i++)
        bin.v[4][i]=1;
}

//void debug(const matrix &a)
//{
//    cout<<"**********"<<endl;
//    for(int i=0;i<6;i++)
//    {
//        for(int j=0;j<6;j++)
//            cout<<a.v[i][j]<<' ';
//        cout<<endl;
//    }
//    cout<<"**********"<<endl;
//}

int main()
{
//    freopen("in.txt","r",stdin);
    cin>>mod>>x>>y>>sp_x>>sp_y>>t;
    init();
//    debug(ans);
    ans=quick(ans,bin,t);
//    debug(ans);
//    debug(bin);
    cout<<(ans.v[0][0]%mod-1+mod)%mod+1<<" "<<(ans.v[0][1]%mod-1+mod)%mod+1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
const int N=1e5+5;
const int mod=1e9+7;
int add(int x, int y){ x+=y;if(x>=mod) x-=mod;return x;}
int sub(int x, int y){ x-=y;if(x<0) x+=mod;return x;}
int mul(int x, int y){ x=(ll)x*y%mod;return x;}
int powmod(int x, int k){ int ans=1;for(;k;k>>=1,x=mul(x,x)) if(k&1) ans=mul(ans,x);return ans;}
int inv(int x){ return powmod(x,mod-2);}
int dv(int x, int y){ x=(ll)x*inv(y)%mod; return x;}
int mu[N],prime[N];
vector<int>primes;
void precalc(){
    //sieve with mobius function
    forn(i,2,N-1){
        prime[i]=1;
        mu[i]=1;
    }
    forn(i,2,N-1){
        if(prime[i]){
            for(int j=i;j<N;j+=i){
                prime[j]=false;
                mu[j]*=-1;
            }
            for(ll j=(ll)i*i;j<N;j+=(ll)i*i){
                mu[j]=0;
            }
        }
    }
}
int main()
{

    precalc();
    int n;
    scanf("%d",&n);
    int ans=1;
    forn(i,2,n){
        int f=n/i;
        if(mu[i]==1){
            ans=sub(ans,mul(f,inv(n-f)));
        }
        if(mu[i]==-1){
            ans=add(ans,mul(f,inv(n-f)));
        }
    }
    printf("%d\n",ans);
    return 0;
}


// https://codeforces.com/contest/1271/problem/E

/*

Mistake -
1 : The approach that if we cannot make cnt >= k using mid ; then we can never make cnt >= k using any mid greater
than mid is wrong

Reason :
Let say mid = 3 ; and maxx = 11
we can make only cnt = 3 using current mid ( 3 , 6 , 7 ).

But for a greater mid - mid = 4 ; we are allowed to use the odd term after it ( 5 ) too ; and we can unfold its
recursion tree too.
Hence using that ; f(4) = 6.

So at this point - there is a conflict.
Should we reject the binary search or should we modify it.

This time ; this binary search can be modified.
Reason - the best candidate that gives us a greater f(mid) near to mid is mid + 1 ( in case mid is odd ).
This is because mid + 1 is even ; and thus we may use recursion tree of mid+2 also to increase our count !

SO we can check for mid-1 ; mid ; and mid+1.
if f(mid + delta) < k ; then we can say that we need to move left ; and do hi = mid - 1.
Else we may say we can move right and do lo = mid + 1.

*/

/*

Mistake 2 - TLE on test case 16.
Earlier ; I was trying to go on every node ; and I was doing f ( node*2 ) ; and f(2*node + 1) ;

But if we unfold the recursion tree ; we will see that it is a binary tree.
We can easily see that height of tree is logarithmic ; and for n <= 1e18 ; height <= 64.

But ; then what will be the number of nodes in the binary tree ?
It will be (1 << max_height) - 1 ( heights are taken 0 based ).

SO since max height can be upto 64 ; hence number of nodes >= 1e18 ( easily ). So we will get a TLE.

What can we do -
Observation : the nodes in the binary tree are consecutive at every level.
Hence ; if we keep a track of the level ; we will know the number of nodes in that level = (1 << level).

And we can see from the highest node will this entire block is <= maxx. If yes ; we may add 1 << level to answer.
Else ; we can find upto which index this holds true ; and we may add those many nodes !

Thus by maintaining only the max node of any level ; we will do only max_height number of iterations !
And thus we may solve function f() in log(1e18) time.

*/

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

ll maxx ;
ll cnt = 0 ;

void f ( ll n , ll lev )
{
    if ( n > maxx )
    {
        ll values_this_level = (1LL << lev) ;
        n = n - values_this_level + 1 ;

        cnt += max ( 0LL , maxx - n + 1 ) ;
        return ;
    }

    cnt += (1LL << lev) ;
    f ( n*2 + 1 , lev + 1 ) ;
}

void solve ( int test_case )
{
    cin >> maxx ;
    ll k ; cin >> k ;

    ll ans = 1 ;
    for ( ll lo = 1 , hi = maxx ; lo <= hi ; )
    {
        ll mid = lo + (hi-lo)/2 ;
        bool found = false ;

        for ( int del_mid = -1 ; del_mid <= 1 ; del_mid ++ )
        {
            ll temp = mid + del_mid ;
            if ( temp < 1 ) C ;
            if ( temp > maxx ) C ;

            cnt = 0 ;
            if ( temp % 2 == 0 )
                f ( temp , 0 ) , f ( temp+1 , 0 ) ;
            else
                f ( temp , 0 ) ;

            if ( cnt >= k )
            {
                ans = max ( ans , temp ) ;
                found = true ;
            }
        }

        if ( found )
            lo = mid + 1 ;
        else
            hi = mid - 1 ;
    }

    cout << ans ; line
}

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

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int m, n, i=0;
	bool k = 0;
	vector <int> a(0);
	cin >> m >> n;
	a.push_back(n);
	while (n > 0)
	{
		if (n % 2 == 0)
		{
			n /= 2;
			a.push_back(n);
		}
		if (n == m)
		{
			k = true;
			break;
		}
		if(n<m)
		{
			k = false;
			break;
		}
		if (n % 10 == 1)
		{
			n /= 10;
			a.push_back(n);
		}
		if (n == m)
		{
			k = true;
			break;
		}
		if (n<m)
		{
			k = false;
			break;
		}
		if(n % 10 != 1 && n % 2!=0 && n!=m)
		{
			k = false;
			break;
		}
	}
	if (k == true)
	{
		cout << "YES" << endl;
		cout << a.size() << endl;
		for (i = a.size() - 1;i >= 0;i--)
			cout << a[i] << " ";
		cout << endl;
	}
	else
		cout << "NO" << endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stack>
#include <map>
#include <sstream>
#include <set>
#include <queue>
#define MAXN 100010
#define pi 3.14159265358979323846
using namespace std;
int n,m;
int main(){
    scanf("%d %d",&n,&m);
    int mx1= n*2,mx2= m*3;
    map<int,int>mp;
    for(int i =2;i<=n*2;i+=2){
        mp[i]++;
    }
    for(int j=3;j<=m*3;j+=3){
        mp[j]++;
    }
    for(int i =1;i<=max(mx1,mx2);i++){
        if(mp[i]>1){
            if(mx1+2<mx2+3){
                mx1+=2;
                mp[mx1]++;
            }else{
                mx2+=3;
                mp[mx2]++;
            }
        }
    }
    printf("%d\n",max(mx1,mx2));
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double v,r,s,f;
const double pi=3.1415926535897932384626433832795;
const double eps=1e-15;
int n;
int main()
{
	scanf("%d %lf %lf",&n,&r,&v);
	while(n--)
	{
		scanf("%lf %lf",&s,&f);
		double dis=f-s;
		double yu=fmod(dis,2*pi*r);
		int t=floor(dis/(2*pi*r));
		double lo=0,up=2*pi;
		while(lo+eps<up)
		{
			double m=(lo+up)/2;
			if(2*sin(m/2)*r+m*r<yu)
			{
				lo=m;
			}
			else
			{
				up=m;
			}
		}
		double len=(t*(2*pi*r)+up*r);
		printf("%.12f\n",len/v);
	}
}


#include <bits\stdc++.h>
#include <ext\rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
//const long double pi = M_PI;
long double eps = 1e-13;

typedef tree<int, pair<int, int>, less<int>, rb_tree_tag,
tree_order_statistics_node_update> Tree;

inline void putint(int x)
{
    char s[9];
    int l = 0;
    while (x)
        s[l++] = '0' + (x % 10), x /= 10;
    while (l--)
        putc(s[l], stdout);
    putc(' ', stdout);
}

inline int getint()
{
    char ch;

    while (ch = getchar(), ch < '0' || ch > '9');

    int x = ch - '0';
    while (ch = getchar(), ch >= '0' && ch <= '9')
    {
        x *= 10;
        x += ch - '0';
    }
    return x;
}

void solve(int n)
{
    int m;
    int x, y;
    m = getint();

    Tree Car;

    for (int i = 1; i <= n; i++)
        Car.insert(mp(i, mp(0, i)));

    set<int> used;
    for (int i = 1; i <= n; i++)
        used.insert(i);

    for (int i = 0; i < m; i++)
    {
        x = getint();
        y = getint();
        used.erase(x);
        y--;

        Tree::iterator it = Car.find_by_order(y);
        if ((it -> second).first != 0 && (it -> second).first != x)
        {
            printf("-1\n");
            return;
        }
        Car.insert(mp(-i, mp(x, (it -> second).second)));
        Car.erase(it);
    }

    for (Tree::iterator it = Car.begin(); it != Car.end(); it++)
        if ((it -> second).first == 0)
            (it -> second).first = *used.begin(),
            used.erase(used.begin());

    vector<int> ans(n + 1, 0);
    vector<char> Used(n + 1, 0);

    for (Tree::iterator it = Car.begin(); it != Car.end(); it++)
        ans[(it -> second).second] = (it -> second).first;

    for (int i = 1; i <= n; i++)
        Used[ans[i]] = 1;
    bool ok = true;
    for (int i = 1; i <= n; i++)
        ok &= Used[i];
    if (!ok)
    {
        printf("-1\n");
        return;
    }

    for (int i = 1; i <= n; i++)
        putint(ans[i]);
    printf("\n");
}

int main()
{
    int i, j;

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

    int n, m;
    cin >> n;
    solve(n);
}


#include <cstdio>
#include <algorithm>
using namespace std;

#define mod 1000000009

int pfix(int x) { return x>=mod ? x-mod : x; }
int dfix(int x) { return x<0 ? x+mod : x; }

int ti[1000005];
int fi[1000005];

int main()
{
	int n;
	scanf("%d",&n);
	int dans = min(6,(n-1)*2);
	int btopn = (n-4)>>1;
	register int f = 1;
	register int t = 4;
	for(int i=1; i<=btopn; ++i)
	{
		t = pfix(t<<1);
		f = 1LL*f*dfix(t-3) % mod;
		dans = (dans + 1LL*f*4) % mod;
	}
	if(n>4 && n&1)
	{
		f = 1LL*f*(2*btopn+3) % mod;
		dans = (dans + 1LL*f*2) % mod;
	}

	printf("%lld\n",(2LL*dans*dans+2)%mod);
}


#include <iostream>
#include <fstream>
#include <memory.h>
#include <math.h>
#include <iomanip>
#include <string.h>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <cctype>

using namespace std;

int main()
{
    int n,m,i,j,a,b;
    cin>>n>>m>>i>>j>>a>>b;
    if ((i==1) && (j==1)) cout<<0<<endl;
    else
    {
        if ((i==1) && (j==m)) cout<<0<<endl;
        else
        {
            if ((i==n) && (j==1)) cout<<0<<endl;
            else
            {
                if ((i==n) && (j==m)) cout<<0<<endl;
                else
                {
                    if ((a>=n) || (b>=m)) cout<<"Poor Inna and pony!"<<endl;
                    else
                    {
                        if ((i%a!=1%a) && (i%a!=n%a)) cout<<"Poor Inna and pony!"<<endl;
    else
    {
        if ((j%b!=1%b) && (j%b!=m%b)) cout<<"Poor Inna and pony!"<<endl;
        else
        {
            int rez1=10000000,rez2=10000000,rez3=10000000,rez4=10000000;
            if ((i%a==1%a) && (j%b==1%b))
            {
                int x=(i-1)/a;
                int y=(j-1)/b;
                if (x%2==y%2) rez1=max(x,y);
            }
            if ((i%a==1%a) && (j%b==m%b))
            {
                int x=(i-1)/a;
                int y=(m-j)/b;
                if (x%2==y%2) rez2=max(x,y);
            }
            if ((i%a==n%a) && (j%b==1%b))
            {
                int x=(n-i)/a;
                int y=(j-1)/b;
                if (x%2==y%2) rez3=max(x,y);
            }
            if ((i%a==n%a) && (j%b==m%b))
            {
                int x=(n-i)/a;
                int y=(m-j)/b;
                if (x%2==y%2) rez4=max(x,y);
            }
            int rez=min(min(rez1,rez2),min(rez3,rez4));
            if (rez==10000000) cout<<"Poor Inna and pony!"<<endl;
            else cout<<rez<<endl;
        }
    }
                    }
                }
            }
        }
    }
    return 0;
}


#include <cstdio>
#include <cmath>

int sumOfDigits(long long input){
    int output(0);
    while(input > 0){output += input % 10; input /= 10;}
    return output;
}

int main(){

    long long n(0); scanf("%lld", &n);
    long long minTest = sqrt(n) - 9 * 10; if(minTest < 1){minTest = 1;}
    long long maxTest = sqrt(n);

    long long output(-1);
    for(long long test = minTest; test <= maxTest; test++){
        if(n % test == 0 && sumOfDigits(test) == n/test - test){output = test; break;}
    }

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

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,n[30],i;
char k;
int main(){
    cin>>a>>b;
    while(a--){
        cin>>k;
        n[k-'a']++;
    }
    for(i=0;i<26;i++){
        if(n[i]>b) {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

#define dbg(x) cerr << (#x) << " --> " << (x) << nl;
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

#define _9day ""

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree < pair <int, int>, null_type, less < pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2e6 + 7, inf = 1e9 + 7, mod = 1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int sum(int x, int y) {
  add(x, y);
  return x;
}
int mult(int x, int y) {
  return (x * 1ll * y) % mod;
}

ll f, w, h;
int fact[N], rev[N];

int pw(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = mult(res, x);
    x = mult(x, x), y >>= 1;
  }
  return res;
}
void precalc() {
  fact[0] = fact[1] = rev[1] = rev[0] = 1;
  rep(i, 2, N - 1) {
    fact[i] = mult(fact[i - 1], i);
    rev[i] = pw(fact[i], mod - 2);
  }
}
int C(ll n, ll k) {
  if (n < k) return 0;
  return mult(mult(fact[n], rev[n - k]), rev[k]);
  int res = 1;
  rep(i, n - k + 1, n)
    res = mult(res, i);
  rep(i, 2, k)
    res = mult(res, pw(i, mod - 2));
  return res;
}

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

  cin >> f >> w >> h;
  precalc();

  if (!f) {
    if (w > h) cout << 1;
    else cout << 0;
    ioi
  }
  if (!w) {
    cout << 1;
    ioi
  }

  int ptr = 0, good = 0, total = 0;
  int n = min(f, w) * 2 + (max(f, w) != min(f, w));
  rep(i, 1, f + w) {
    {
      ///W
      //if (i == n && f > w) continue;
      int W = (i + 1) / 2, F = i - W;
      add(good, mult(C(w - h * W - 1,W - 1), C(f - 1, F - 1)));
      add(total, mult(C(w - 1, W - 1), C(f - 1, F - 1)));
    }
    {
      ///F
      //if (i == n && f < w) continue;
      int F = (i + 1) / 2, W = i - F;
      add(good, mult(C(w - h * W - 1, W - 1), C(f - 1, F - 1)));
      add(total, mult(C(w - 1, W - 1), C(f - 1, F - 1)));
    }
  }

  cout << mult(good, pw(total, mod - 2));
  ioi
}


#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while (t>0)
    {
        int maze[2][2];
        int sum=0;
        for(int i=0;i<2;i++)
        {
            for(int j=0;j<2;j++)
            {
                cin>>maze[i][j];
                if(maze[i][j]==1)
                {
                    sum++;
                }
            }
        }
        if(sum==0)
        {
            cout<<0<<endl;
        }
        if(sum<=3&&sum>0)
        {
            cout<<1<<endl;
        }
        if(sum==4)
        {
            cout<<2<<endl;
        }
        t--;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=unsigned long long;
ll mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define inf INT_MAX
#define ninf INT_MIN
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    string s,p;
    m=n;
    ll a[10]={0};
    j=0;
    while(m!=0)
    {
        k=m%10;
        s+=(k+'0');
        m/=10;
        a[k]=1;
        if(k==0)
        ++j;
    }
    reverse(s.begin(),s.end());
    m=0;
    if(j>=2 || (a[2]==1 && a[5]==1) || (a[5]==1 && a[0]==1) || (a[7]==1 && a[5]==1))
    m=1;
    if(m==0)
    {
        cout<<-1;
        return 0;
    }
    else if(n%25==0)
    {
        cout<<0;
        return 0;
    }
    ll ans=inf;
    p=s;
    ll roh=0;
    if(j>=2)
    {
        ll x=s.rfind('0');
        for(i=x;i<s.length()-1;i++)swap(s[i],s[i+1]),roh++;
        x=s.rfind('0',x-1);
        for(i=x;i<s.size()-2;i++)swap(s[i],s[i+1]),roh++;
        k=0;
        for(i=0;i<s.length();i++)
       { if(s[i]=='0')++k;else break;}
        //if(s.length()-2>=2*k)
        ans=min(ans,roh+k);
    }
    s=p;
    roh=0;
    k=0;
    if(a[2]==1 && a[5]==1)
    {
        ll x=s.rfind('5');
        for(i=x;i<s.length()-1;i++)swap(s[i],s[i+1]),roh++;
        x=s.rfind('2');
        for(i=x;i<s.size()-2;i++)swap(s[i],s[i+1]),roh++;
        k=0;
        for(i=0;i<s.length();i++)
       { if(s[i]=='0')++k;else break;}
        //if(s.length()-2>=2*k)
        ans=min(ans,roh+k);
    }
    s=p;
    roh=0;
    k=0;
    if(a[5]==1 && a[0]==1)
    {
        ll x=s.rfind('0');
        for(i=x;i<s.length()-1;i++)swap(s[i],s[i+1]),roh++;
        x=s.rfind('5');
        for(i=x;i<s.size()-2;i++)swap(s[i],s[i+1]),roh++;
        k=0;
        for(i=0;i<s.length();i++)
       { if(s[i]=='0')++k;else break;}
        //if(s.length()-2>=2*k)
        ans=min(ans,roh+k);
    }

    s=p;
    roh=0;
    k=0;
    if(a[7]==1 && a[5]==1)
    {
        ll x=s.rfind('5');
        for(i=x;i<s.length()-1;i++)swap(s[i],s[i+1]),roh++;
        x=s.rfind('7');
        for(i=x;i<s.size()-2;i++)swap(s[i],s[i+1]),roh++;
        k=0;
        for(i=0;i<s.length();i++)
       { if(s[i]=='0')++k;else break;}
        //if(s.length()-2>=2*k)
        ans=min(ans,roh+k);
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
int n, p, a[55];
ll f[55][2][2][2], er[55], ans;//f[i][j][k][l]:到第i个点，路径条数奇偶性为k，是否存在奇黑，是否存在奇白
void add(ll &a, ll b) {a = (a + b) % mod; }
int main() {
	scanf("%d%d", &n, &p);
	er[0] = 1;
	for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]), er[i] = (er[i-1] << 1) % mod;
	f[0][0][0][0] = 1;
	for (int i = 1; i <= n; i ++ )
		for (int j = 0; j < 2; j ++ )
			for (int k = 0; k < 2; k ++ )
				for (int l = 0; l < 2; l ++ ) {
					int t = f[i - 1][j][k][l];
					if (a[i] != 0) { //白点
						if (k) //存在奇黑，我们可以挑出一个奇黑点来控制奇偶性，即这个白点作为奇白和偶白的方案数各为2^(i-2)
							add(f[i][j][k][l], 1ll * t * er[i - 2] % mod),
							add(f[i][j ^ 1][k][l|1], 1ll * t * er[i - 2] % mod);
						else add(f[i][j ^ 1][k][l|1], 1ll * t * er[i - 1] % mod);
					}
					if (a[i] != 1) {
						if (l)
							add(f[i][j][k][l], 1ll * t * er[i - 2] % mod),
							add(f[i][j ^ 1][k|1][l], 1ll * t * er[i - 2] % mod);
						else add(f[i][j ^ 1][k|1][l], 1ll * t * er[i - 1] % mod);
					}
				}
	for (int i = 0; i < 2; i ++ )
		for (int j = 0; j < 2; j ++ )
			add(ans,f[n][p][i][j]);
	printf("%lld\n", ans);
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int a, b, c, d, e, s;
    cin >> a >> b >> c >> d >> e;

    s = a + b + c + d + e;

    if(s > 0 && s % 5 == 0)
        cout << (s / 5) << endl;
    else
        cout << -1 << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const int mxN = 200001;
ll fact[mxN], power[mxN], two[mxN];
int n;
ll k;
int h[mxN];
ll binpow(ll x, ll y) {
    ll res = 1;
    x = x%MOD;
    while(y>0) {
        if(y%2==1) {
            res= (res*x)%MOD;
        }
        y=y>>1;
        x = (x*x)%MOD;
    }
    return res;
}
ll modInv(ll n, ll p) {
    return binpow(n, p-2);
}
ll divide(ll a, ll b) {
    return (a%MOD)*(binpow(b, MOD-2))%MOD;
}
ll nCr(int n, int r) {
    if(r==0)return 1;
    return (fact[n]*modInv(fact[r],MOD)%MOD*modInv(fact[n-r],MOD)%MOD)%MOD;
}

int main()
{
    cin>>n>>k;
    int bad = 0;
    for(int i=0; i<n; ++i) {
        cin>>h[i];
        if(i>0&&h[i-1]==h[i])bad++;
    }
    if(h[n-1]==h[0])bad++;
    int tot = n-bad;
    fact[0] = 1;
    power[0] = 1;
    two[0] = 1;
    for(int i=1; i<mxN; ++i) {
        power[i] = (power[i-1]*(k-2))%MOD;
        two[i] = (two[i-1]*2)%MOD;
        fact[i] = (fact[i-1]*i)%MOD;
    }
    ll ans = 0;
    for(int i=0; i<tot; ++i) {
        ll curr = (power[i]*nCr(tot,i))%MOD;
        if((tot-i)%2==1) {
            curr = (curr*two[tot-i-1])%MOD;
        }else {
            ll mult = (two[tot-i]-nCr(tot-i, (tot-i)/2)+MOD)%MOD;
            mult = divide(mult,2);
            curr = (curr*mult)%MOD;
        }
        ans = (ans+curr)%MOD;
    }
    ans = (ans*binpow(k,bad))%MOD;
    cout<<ans<<"\n";
    return 0;
}


# include <cstdio>
# include <iostream>
using namespace std;
const int N=1000+10;

int n,m;
double f[N][N];
bool v[N][N];

void init()
{
    cin>>n>>m;
}

double dfs(int n,int m)
{
    if(v[n][m])return f[n][m];
    v[n][m]=1;
    if(n*m==0)
    {
        if(n>0)f[n][m]=1.0000;
        else f[n][m]=1.0000/(m+1);
        return f[n][m];
    }
    double A=1.0000;
    double B=1.0000-dfs(m,n-1);
    double C=double(m)/(m+1)*(1.0000-dfs(m-1,n));
    double D=double(m)/(m+1)*(1.0000-dfs(m-1,n))+1.0000/(m+1);
    //A * P + B * (1 - P) = C * P + D * (1 - P)
    //AP + BP - CP + DP = D - B
    double P=(D-B)/(A-B-C+D);
    return f[n][m]=P*A+(1-P)*B;
}

void solve()
{
    double ans=dfs(n,m);
    printf("%.10f %.10f\n",ans,1-ans);
}

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


#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define inf 0x3f3f3f3f
#define mod 1000000007
#define sq(x) ((x)*(x))
#define bit(x, y) (((x)>>(y))&1)
#define bctz(x) (__builtin_ctz(x))
#define bclz(x) (__builtin_clz(x))
#define bclzl(x) (__builtin_clzll(x))
#define bctzl(x) (__builtin_ctzl(x))
#define bpt(x) (__builtin_popcount(x))
#define bptl(x) (__builtin_popcountll(x))
#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;
typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;
typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}
template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}
template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}
template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2, x3), gn(x4);}
template <class T1, class T2, class T3, class T4, class T5> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {gn(x1, x2, x3, x4), gn(x5);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}
template <class T> inline void println(T x) {print(x); putchar('\n');}
template <class T> inline void printsp(T x) {print(x); putchar(' ');}
template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}
template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}
template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}
template <class T1, class T2, class T3, class T4, class T5> inline void print(T1 x1, T2 x2, T3 x3, T4 x4, T5 x5) {printsp(x1), printsp(x2), printsp(x3), printsp(x4), println(x5);}

int power(int a, int b, int m, int ans=1) {
	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;
	return ans;
}
#define NN 110
int a[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n, k;
	gn(n, k);
	for(int i=1; i<=n; i++) gn(a[i]);
	int ans = 0;
	for(int i=0; i<k; i++) {
		int e = 0;
		int s = 0;
		for(int j=1; j<=n; j++) if(j % k != i) {
			if(a[j] > 0) e++;
			else s++;
		}
		smax(ans, abs(e-s));
	}
	println(ans);

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define FOREACH(container, it) \
   for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
#define EXP(i, s) for (int i = (s); i; i = qn[i])
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define LCM 360360
#define MAXN 8405400

using namespace std;

int ed;
int l[LCM+1], qd[MAXN+1], qn[MAXN+1];
int q[LCM+1];

void bd(int x, int y){
	qd[++ed] = y; qn[ed] = l[x]; l[x] = ed;
}

inline void bfs(int st, LL v[]){
	FOR(i, 0, LCM+1) v[i] = -1;
	v[st] = 0;
	q[0] = st;
	for (int i = 0, j = 0; i <= j ; i++){
		EXP(k, l[q[i]]) if (v[qd[k]] == -1){
		  v[qd[k]] = v[q[i]] + 1;
		  q[++j] = qd[k];
    }
  }
}

int main(int argc, char **argv){
  LL A, B, K;
  cin >> A >> B >> K;
  FOR(i, 0, LCM+1){
  	if (i) bd(i, i-1);
  	FOR(j, 2, K+1) bd(i, i - (i % j));
  }
  LL s[LCM+1], t[LCM+1];
  bfs(A%LCM, s);
  bfs(LCM, t);
  if (A/LCM == B/LCM) cout << s[B%LCM];
  else cout << (s[0] + t[0] * (A/LCM - B/LCM - (B%LCM != 0)) + t[B%LCM]);
  return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,a,c=0;
	cin>>n>>a;
	int *arr=new int[n];
	for (int i = 0; i < n; i++)
	{
		cin>>arr[i];
	}
	if(arr[a-1])
		c++;
	int k=a-2,j=a;
	while(k>=0&&j<n)
	{
		if(arr[k]==1&&arr[j]==1)
			c+=2;
		k--;
		j++;
	}
	if(k<0&&j<n)
	{
		for(j;j<n;j++)
			if(arr[j]==1)
				c++;
	}
	if(k>=0&&j>=n)
	{
		for(k;k>=0;k--)
			if(arr[k]==1)
				c++;
	}
	cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r,c;
	cin>>r>>c;
	char a[r][c];
	int visited[r][c];
	for(int i=0;i<r;i++)
	{
		for(int j=0;j<c;j++)
		{
			cin>>a[i][j];
			visited[i][j]=0;;
		}
	}
	int x=0,count=0;
	for(int i=0;i<r;i++)
	{count=0;
		for(int j=0;j<c;j++)
		{
			if(a[i][j]=='S')
			{count=0;
				break;
			}
			else
			{
				count++;
			}
		}
		if(count!=0)
		{
			for(int j=0;j<c;j++)
		{
		visited[i][j]=1;
		}

	}
}
	int y=0;
	for(int i=0;i<c;i++)
	{count=0;
		for(int j=0;j<r;j++)
		{
			if(a[j][i]=='S')
			{count=0;
				break;
			}
			else
			{
				count++;
			}
		}
		if(count!=0)
		{
				for(int j=0;j<r;j++)
		{
		visited[j][i]=1;
		}

		}
	}
	count=0;
	for(int i=0;i<r;i++)
	{

				for(int j=0;j<c;j++)
		{
		if(visited[i][j]==1)
		{
			count++;
		}

		}
	}

cout<<count;
}


#include <bits/stdc++.h>

using namespace std;

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

    string a;
    int b = 0;

    int i = 0;
    while (s[i] != '.') i++;
    i++;
    while (s[i] != 'e') a += s[i++];
    i++;
    while (i < s.size()) b = b*10 + (s[i++] - '0');

    if (a == "0") a.clear();

    string ans;
    ans += s[0];

    i = b;
    int j = 0;
    while (i && j < a.size()) {
        ans += a[j];
        i--, j++;
    }

    while (i) {
        ans += '0';
        i--;
    }

    if (j < a.size()) {
        ans += '.';
        while (j < a.size()) {
            ans += a[j];
            j++;
        }
    }

    cout << ans << endl;

    return 0;
}