#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
int main(){
     int n,m,k,i,j,a[100],b[100],t;
     while(scanf("%d%d%d",&n,&m,&k)!=EOF)
     {
         memset(b,0,sizeof(b));
         int counter=1,flag=0,temp;
         if(m>k)
         {
             temp=m;
             m=k;
             k=temp;
         }
         for(i=1;i<=n;i++)
         {
             a[i]=i;
         }
         for(j=1;j<=log2(n);j=j+1)
         {
             t=1;
             for(i=1;i<n;i=i+2)
             {
                 if(a[i]==m && a[i+1]==k)
                 {
                     flag=1;
                     break;
                 }
                 else if(a[i]==m || a[i+1]==m)
                 {
                     a[t]=m;
                 }
                 else if(a[i]==k || a[i+1]== k)
                 {
                     a[t]=k;
                 }
                 else
                 {
                     a[t]=a[i];
                 }
                 t++;
//                 printf("%d ",a[t]);
       //             printf("\n");
      }
             if(flag==1 && counter!=log2(n))
             {
                printf("%d\n",counter);
                break;
             }
             counter++;
         }
         if(j>log2(n))
            printf("Final!\n");
     }

}


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

const int INF = (int)1e9;

int n, m, s;

vector <vector <bool> > visited;
vector <int> compSize;

// L, R, U, D
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

bool valid (int a, int b) {
	return a >= 0 and a < n and b >= 0 and b < m;
}

void dfs (int x, int y, int parx, int pary, int comp) {
	visited[x][y] = true;
	compSize[comp]++;
	int u, v;
	for (int i = 0; i < 4; i++) {
		u = x + (s * dx[i]);
		v = y + (s * dy[i]);
		if (!valid(u, v))
			continue;
		if (u == parx and v == pary)
			continue;
		if (!visited[u][v])
			dfs(u, v, x, y, comp);
	}
	return;
}

void solve () {
	int k = 0;
	visited.assign(n, vector<bool>(m, false));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!visited[i][j]) {
				compSize.push_back(0);
				dfs(i, j, -INF, -INF, k);
				k++;
			}
		}
	}
	int dmax = -INF, pmax = 0;
	for (int i = 0; i < compSize.size(); i++) {
		dmax = max(dmax, compSize[i]);
	}
	for (int i = 0; i < compSize.size(); i++) {
		if (compSize[i] == dmax)
			pmax += compSize[i];
	}
	cout << pmax << "\n";
	return;
}

int main () {
	cin >> n >> m >> s;
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool b[92345];
long long bfs(int s,int d)
{
    queue<pair<long long,long long> > qu;
    qu.push(make_pair(s,0));
    long long depth,x;
    while(!qu.empty())
    {
        pair<int,int>p;
        p=qu.front();
        qu.pop();

        x=p.first;
        depth=p.second;

        if(x==d) break;

        if(x<=0||b[x]) continue;

        b[x]=1;

        qu.push(make_pair(x*2,depth+1));
        qu.push(make_pair(x-1,depth+1));

    }
    return depth;
}

int main()
{
    int n,m;
    cin>>n>>m;
    cout<<bfs(n,m)<<endl;
    return 0;
}


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

int main()
{
	int size, count1 = 0, count2 = 0;
	string holst;
	cin >> size >> holst;
	for (int j = 0; j < holst.size(); j++)
	{
		if (holst[j] == '?')
			count1++;
		if (j > 0 && (j < holst.size() - 1))
		{
			if (holst[j] == '?' && holst[j - 1] != '?' && holst[j + 1] != '?' && holst[j - 1] != holst[j + 1])
			{
				count2++;
			}
		}
	}
	if (count1 == count2)
	{
		return 1;
		exit(1);
	}
	for (int i = 0; i < holst.size(); i++)
	{

		if ( holst[i] == holst[i + 1] && (holst[i] != '?' && holst[i+1] != '?' ) )
		{

			cout << "No";
			break;
		}
		/*if (i > 0 && (i < holst.size() - 1))
		{
			if (holst[i] == '?' && holst[i + 1] != '?' && holst[i - 1] != '?' && holst[i - 1] != holst[i + 1])
			{
				cout << "No";
				break;
			}
		}*/

		if ( i + 1 == holst.size() )
			cout << "Yes";
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <utility>
using namespace std;
/*
double C(int n, int m)
{
	double ret=1.0;
	for(int i=1;i<=n;++i) ret*=i;
	for(int i=1;i<=m;++i) ret/=i;
	for(int i=1;i<=n-m;++i) ret/=i;
	return ret;
}
*/
void ins(vector<int> &A, int k)
{
	for(int i=2;i<=k;++i) A.push_back(i);
}

double Pr(int n, int m, int k)
{
	if (k>m || n-k>n*m-m) return 0;

	vector<int> A,B;
	ins(A,m);ins(A,n*m-m);ins(A,n);ins(A,n*m-n);
	ins(B,k);ins(B,m-k);ins(B,n-k);ins(B,n*m-m-n+k);ins(B,n*m);

	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	int i=0,j=0;
	while(i<A.size() && j<B.size())
	{
		if (A[i]==B[j]) {A.erase(A.begin()+i);B.erase(B.begin()+j);continue;}
		if (A[i]<B[j]) ++i; else ++j;
	}

    double ret=1.0;
	while (A.size()>0 && B.size()>0)
	{
		if (ret<1.0) {ret*=A.back();A.pop_back();} else
			{ret/=B.back();B.pop_back();}
	}

	for(int i=0;i<A.size();++i) ret*=A[i];
	for(int i=0;i<B.size();++i) ret/=B[i];

	return ret;
}

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

	double ret=0;
	for(int i=1;i<=n;++i)
		ret += i*i * Pr(n,m,i);

	ret /= n;

	printf("%.10lf",ret);

	return 0;
}


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

int main()
{
    while(1)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int sum = 0;
        int sum1= 0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        for(int i=0;i<n-1;i++)
        {
            if(a[i]>8)
            {
                a[i+1]+=a[i]-8;
                a[i]=8;
            }
        }
        int count  = 0;
        for(int i=0;i<n;i++)
        {
         if(i==n-1 && m>8)
            {
                cout<<"-1\n";
                return 0;
            }
            if(m!=0)
            {
                m-=a[i];
                count++;
            }

        }
        cout<< count << endl;

    }
}


//CF13A
#include<iostream>
using namespace std;
long long f(int n,int b)
{
	long long ans=0;
	while(n)
	{
		ans+=n%b;
		n=n/b;
	}
	return ans;
}
long long gcd(long long a,long long b)
{
	if (b==0)
	{
		return a;
	}
	else
	{
		return (b,a%b);
	}
}
int main()
{
	int n;
	long long ans=0;
	cin>>n;
	for (int i=2;i<n;i++)
	{
		ans+=f(n,i);
	}
	long long d;
	d=gcd(ans,n-2);
	cout<<ans/d<<"/"<<(n-2)/d<<endl;
}


#include <stdio.h>
#include <string.h>
int main()
{
	int i;
	char s[55];
	scanf("%s", s);
	int len = strlen(s);
	int vis = 1;
	for(i = 0 ; i < (len - 1) / 2; i++)
	{
		if(s[i] != s[len - 1 - i])vis = 0;
	}
	if(vis == 0)
	{
		printf("%d\n", len);
	}
	else
	{
		if(len == 1)
		{
			printf("1\n");
			return 0;
		}
		int count = 0;
		int eng[30];
		for(i = 0 ; i < len ;i++)
		{
			eng[s[i] - 'a' + 1] = 1;
		}
		for(i = 1 ; i <= 26 ;i++)
		{
			if(eng[i] == 1) count++;
		}
		if(count == 1)printf("0\n");
		else
		{
			printf("%d\n", len - 1);
		}
	}
}


#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <string.h>
#include <string>
#include <limits.h>
#include <algorithm>
#include <set>
#include <ctime>
using namespace std;
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i=a; i<(int)n; i++)
#define per(i,n,a) for (int i=n; i>=a; i--)
#define hk push_back
#define pk pop_back
#define mp make_pair
#define PI 3.141592653589793
#define clr(a) memset(a, 0, sizeof(a))
#define clr1(a) memset(a, -1, sizeof(a))
typedef vector<int> VI;
typedef vector< pair<int, int> > VIP;
typedef vector< pair<int, pair<int, double> > > VIPP;
typedef vector<string> VS;
typedef vector <double> VD;
typedef vector <bool> VB;
typedef long long ll;
#define MAX_V 1000
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
    ll res = 1; a %= mod; for (; b; b >>= 1){ if (b & 1)res = res*a%mod; a = a*a%mod; }return res;
}

ll n, K, S, maxFactorial, m;
vector<ll> nums;
int idxNoFactorial;
vector<ll> factorial;

map< pair< pair<int, ll>, pair<int, int> >, ll> cache;

ll comb[2005][2005];
ll calComb(int n, int k){
    if (n * k < 0) return 0;
    if (n == k || k == 0) return 1;
    if (n - k < k) return calComb(n, n - k);
    ll& ret = comb[n][k];
    if (ret) return ret;

    return ret = (calComb(n - 1, k) + calComb(n - 1, k - 1)) % mod;
}

ll dfs(int idx, ll sum, int searchMode, int kLeft) {
    if (kLeft < 0) return 0;
    if (sum > S) return 0;
    if (sum == S) return 1;
    if (idx >= nums.size()) return 0;
    ll& ret = cache[mp(mp(idx, sum), mp(searchMode, kLeft))];
    if (ret) return ret;

    int nextIdx = idx;
    while (nextIdx < nums.size()) {
        if (nums[nextIdx] != nums[idx]) break;
        nextIdx++;
    }

    if (searchMode == 1) {
        ll ret1 = 0;
        rep(i, 0, nextIdx - idx) {
            ll nextSum = sum + nums[idx] * (i + 1);
            ret1 += dfs(nextIdx, nextSum, 0, kLeft)  * calComb(nextIdx - idx, i + 1);
        }
        return ret = ret1;
    }
    else {
        ll ret1 = 0;
        if (idx < idxNoFactorial && kLeft) {
            rep(i, 0, nextIdx - idx) {
                ll nextSum = sum + factorial[nums[idx] - 1] * (i + 1);
                if (i == nextIdx - idx - 1)
                    ret1 += dfs(idx + (i + 1), nextSum, 0, kLeft - (i + 1));
                else {
                    if (nextSum == S) {
                        ret1 += calComb(nextIdx - idx, i + 1); break;
                    }
                    else {
                        ret1 += dfs(idx + (i + 1), nextSum, 1, kLeft - (i + 1))  * calComb(nextIdx - idx, i + 1);
                        ret1 += dfs(nextIdx, nextSum, 0, kLeft - (i + 1))  * calComb(nextIdx - idx, i + 1);
                    }
                }
                if (kLeft - (i + 1) == 0) break;
            }
        }
        ret1 += dfs(idx, sum, 1, kLeft);
        ret1 += dfs(nextIdx, sum, 0, kLeft);
        return ret = ret1;
    }
}

int main() {
    clr(comb);
    cin >> n >> K >> S;
    rep(i, 0, n) {
        cin >> m;
        nums.push_back(m);
    }
    sort(nums.begin(), nums.end());
    idxNoFactorial = 50;
    maxFactorial = 1;
    int k = 1;
    while (maxFactorial <= S) {
        maxFactorial *= k;
        factorial.push_back(maxFactorial);
        k++;
    }
    rep(i, 0, n) if (nums[i] >= k) { idxNoFactorial = i; break; }

    cout << dfs(0, 0, 0, K) << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<int,cmp> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
ll INF=1ll<<60;
const int maxn=1e5+10;
const int maxl=5e3+10;
const double PI=acos(-1.0);
const double eps=1e-8;
int n;
int ans;
int li;
ll cal(string&cur)
{
	ll w=atoi(cur.c_str());
	if(1+n>=w)return w>>1;
	int x=w-n;
	return (n-x+1)>>1;
}
void dfs(string cur)
{
	ll w=atoi(cur.c_str());
	if(w>li)return;
	ans+=cal(cur);
	for(char c='1';c<='8';++c)
	{
		string nx=c+cur;
		dfs(nx);
	}
}
int main()
{
	fast;string s;int c=0;
	cin>>n;li=2*n-1;
	while(1)
	{
		ll nx=(ll)c*10+9;
		if(nx>li)break;
		c=nx;s+='9';
	}
	if(!c)ans=n*(n-1)/2;
	else
	{
		dfs(s);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=1e5+5;
int ans,a1,a2,b1,b2,n,k,inv[N<<1],mod;

int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=x*x%mod) if(y&1) res=res*x%mod;
	return res;
}

void dico(int l,int r,int h){
	if(h==1||l==r){
		l=r-l+1;
		if(!a1) a1=l,b1=1;
		else if(a1==l) b1++;
		else a2=l,b2++;
		return ;
	}
	int mid=l+r>>1;
	dico(l,mid,h-1);
	dico(mid+1,r,h-1);
}

int calc(int n,int m){
	int res=0;
	for(int i=2;i<=n+m;i++) res=(res+inv[i]*min(i-1,n+m-i+1)%mod)%mod;
	return mod-res;
}

void init(int n){
	inv[1]=1;for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
}

signed main(){
	read(n,k,mod);ans=n*(n-1)/2*(mod+1>>1))%mod;
	init(n<<1);
	dico(1,n,k);
	ans=(ans+b1*(b1-1)/2*calc(a1,a1)%mod)%mod;
	if(a2){
		ans=(ans+b2*(b2-1)/2*calc(a2,a2)%mod)%mod;
		ans=(ans+b1*b2%mod*calc(a1,a2)%mod)%mod;
	}
	write(ans);
}


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

int main()
{
long long  t,ans,x,y,i,even=0,odd=0;
 while(1){

  scanf("%lld %lld",&x,&y);
    ans=x+y;
    even=0,odd=0;

    for(i=1;i<=ans;i++)
    {
        if(i%2==0) even++;
        else odd++;
    }

 if(x==even && y==odd) printf("YES\n");

 else printf("NO\n");
}

    return 0;
}


//Template by karthik171998

#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wunused-result"

/*------------------------------------------------------------------------*/

#define iOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define For(i,a,b) for((i)=(a);(i)<(b);++(i))
#define Fore(i,a,b) for((i)=(a);(i)<=(b);++(i))
#define rof(i,a,b) for((i)=(a);(i)>=(b);--(i))
#define Fors(i,s) for((i)=s.begin();i!=s.end();i++)
#define Form(i,m) for((i)=m.begin();i!=m.end();i++)
#define inf (long long)4e18
#define xx first
#define yy second
#define pb push_back
#define PB pop_back()
#define mp make_pair
#define mod 1000000007
#define pi 3.1428571
#define sqr(a) (((a) * (a)))
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define endl "\n"
#define ub(a,e) upper_bond(a.begin(),a.end(),e)
#define lb(a,e) lower_bond(a.begin(),a.end(),e)
#define sortv(a) sort(a.begin(),a.end())
#define sortr(a) sort(a.rbegin(),a.rend())
#define accu(a,e) accumulate(a.begin(),a.end(),e)

/*---------------------------------------------------------------------------*/

typedef long long ll;
typedef vector< pair <ll,ll> >vect;
typedef pair<ll,ll> pa;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef map<string,ll> ms;
typedef map<ll,ll> ml;
typedef priority_queue <ll> pq;
typedef unsigned long long ull;
typedef long double ld;

/*---------------------------------------------------------------------------*/

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

/*----------------------------------------------------------------------------*/
//Variables and functions for graph
//Undirected graph

/*vi adj[1000000];
bool visited[1000000]={false};
void add_edge(ll a,ll b)
{
    adj[a].pb(b);
    adj[b].pb(a);
}
/*-----------------------------------------------------------------------------*/

//end of template.

ll i,j,n,t;

int main()
{
 	iOS;
 	cin>>n;
 	int f=0;
 	string a="312931303130313130313031";
 	string b="312831303130313130313031";
 	i=0;
 	while(i<=25)
 	a+=a,i++;
 	while(i>=0)
 	b+=b,i--;
 	string ans="";
 	For(i,0,n)
 	{
 		string c;
 		cin>>c;
 		ans+=c;
	 }
	 For(i,0,a.size())
	 {
	 	string d=a.substr(i,2*n);
	 	if(d==ans)
	 	{
		cout<<"YES";
		return 0;
		}
	 }
	 For(i,0,b.size())
	 {
	 	string d=b.substr(i,2*n);
	 	if(d==ans)
	 	{
	 	cout<<"YES";
		return 0;
		}
	 }
	 cout<<"NO";
	return 0;
}


//Jacker0031
//packages
#if __has_include("extra.cpp") && __has_include(<stdint.h>)
    #include "extra.cpp"
#else
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
#endif

// Data Type
#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double
// Loops
#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)
#define Bit                 bitset<32>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define firstone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcount(n))
#define trailzero(n)        (__builtin_ctz(n))
#define leadingzero(n)      (__builtin_clz(n))

// Stl
#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define mll                 map<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define get(tup,ind)        get<ind>(tup)
#define afterpoint(x)       fixed<<setprecision(x)
// Maths
const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define log(x,b)            (log(x)/log(b))
#define INF                 LLONG_MAX
// Big data
const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))
// Extra
#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          {for(auto &i:any) cout<<i<<" "; nl;}
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
inline void yes()           {std::cout<<"Yes\n";}
inline void no()            {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'
using namespace std;
////////////

//NOW CODE BEGIN.
//DHARMSINH DESAI UNIVERSITY.
vll pri;
vector<bool> sieve(ll n)
{
    vector<bool> prime(n,true);
    prime[0]=prime[1]=false;
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i]=false;

        }
    }
   for(ll i=2;i<=n;i++)
   {
    if(prime[i]==true)
      pri.pb(i);
   }
    return prime;
}

int main()
{
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifdef Jenish
  freopen("C:/Sublime Text 3/in.txt","r",stdin);
    freopen("C:/Sublime Text 3/out.txt","w",stdout);
    #endif
    ll ma=1000;
    vector<bool> prime=sieve(ma);

    ll s=pri.size();
    vll r(100000000);
    r[0]=0;
    for(ll i=0;i<s-1;i++)
    {
           ll u=pri[i]+pri[i+1]+1;
           if(prime[u])
           r[u]=1;

    }
    vll pre(ma);
    for(ll i=1;i<ma;i++)
    {
       pre[i]=pre[i-1]+r[i];
    }
    ll n,k;
    cin>>n>>k;
    if(pre[n]>=k)
    {
      cout<<"YES";
    }
    else
    {
      cout<<"NO";
    }

  }


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n=5,sm=0;
	while(n--){int a;cin>>a;sm+=a;}
	cout<<(sm%5==0? sm/5:-1);
}


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

int main()
{int l,w,h,a1,a2,a3,s;
cin>>a1>>a2>>a3;
s=(a1/a2)*a3;
    l=sqrt(s);
    w=a3/l;
    h=a2/w;
    cout<<4*l+4*h+4*w<<endl;

    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int a, b,c, m = 0, n = 0; cin >> a >> b;
    for(int i = 1; i <= a; i++){ if(a%i==0) ++m;}
    c = a + 1;
    for(int i = 1; i <= c; i++){
        if(c % i == 0) ++n;
        if(i == c and n != 2){i = 0; ++c; n == 0;}
    }
    cout << (m == 2 and c == b ? "YES" : "NO");
return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <map>
#include <algorithm>
#include "print.hpp"

using namespace std;

int inf = 1000000;

pair<int, int> grundy(int n){
  if(n == 1) return make_pair(0, 1);
  vector<int> nums;
  int ret = inf;
  for(int i = 2;i*(i+1)/2 <= n;i++){
    if( (n - i*(i+1)/2 ) % i != 0 ) continue;
    int xorval = 0;
    int base = (n - i*(i+1)/2) / i + 1;
    for(int j = 0; j < i;j++){
      pair<int, int> grundyval =  grundy(base + j);
      xorval ^= grundyval.first;
    }
    nums.push_back(xorval);
    if(xorval == 0){
      ret = min(ret, i);
    }
  }

  if(nums.empty()) return make_pair(0, n);
  sort(nums.begin(), nums.end());

  //  cout << n << endl;
  //  print(nums);

  if(nums[0] > 0) return make_pair(0, ret);
  for(int i = 1; i< nums.size();i++){
    if(nums[i] - nums[i-1] > 1){
      return make_pair(nums[i] + 1, ret);
    }
  }
  return make_pair(nums[nums.size() - 1] + 1, ret);
}

int main(){
  int n;
  while(cin >> n){
    pair<int, int> ans = grundy(n);
    if(ans.first != 0){
      cout << ans.second << endl;
    }else{
      cout << -1 << endl;
    }

  }
}


#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int s[10234];
int sg[101234],pre[101234];

int dfs(int n){
    if(n<3)sg[n]=0;
    if(~sg[n])return sg[n];
    vector<int>t;t.clear();
    for(int i=2;s[i]<=n;i++){
        if((n-s[i])%i)continue;
        int b=(n-s[i])/i;
        int res=0;
        for(int j=0;j<i;j++){
            int v=b+j+1;
            res^=sg[v];
        }
        if(!res&&pre[n]==-1)pre[n]=i;
        t.push_back(res);
    }
    sort(t.begin(),t.end());
    t.erase(unique(t.begin(),t.end()),t.end());

    int a=t.size();
    for(int i=0;i<a;i++)
        if(t[i]!=i){
            a=i;break;
        }
    sg[n]=a;
    return sg[n];
}

int main(){
    int n;scanf("%d",&n);
    s[0]=0;
    for(int i=1;i<10234;i++)
        s[i]=s[i-1]+i;
    memset(sg,-1,sizeof sg);
    memset(pre,-1,sizeof pre);
    dfs(n);
    if(~pre[n]) printf("%d\n",pre[n]);
    else printf("-1\n");

    return 0;
}


/*
 * A.cpp
 *
 *  Created on: 29.10.2011
 *      Author: Altus
 */

#include<stdio.h>

const int ARRAY_LEN = 20000000;
int d[ARRAY_LEN];

int main()
{
	int cm, in, ft;
	int j;

	scanf("%d", &cm);

	in = (cm + 1) / 3;
	ft = in / 12;
	in = in % 12;

	for(int i = 0; i < 1000000000; i++)
	{
		j = (i + 4096) % ARRAY_LEN;
		d[j] = d[i % ARRAY_LEN];
	}

	d[0] = ft;
	printf("%d %d\n", d[0], in);
	return 0;
}


/*
 * A.cpp
 *
 *  Created on: 29.10.2011
 *      Author: Altus
 */

#include<stdio.h>

const int ARRAY_LEN = 60000000;
int d[ARRAY_LEN];

int main()
{
	int cm, in, ft, tmp;

	scanf("%d", &cm);

	in = (cm + 1) / 3;
	ft = in / 12;
	in = in % 12;

	for(int i = 0, j = 1021; i < 500000000; i++, j++)
	{

//		if(j >= ARRAY_LEN) j -= ARRAY_LEN;
		j = j - j / ARRAY_LEN * ARRAY_LEN;
		tmp = i - i / ARRAY_LEN * ARRAY_LEN;
		d[j] = d[tmp];
//		d[tmp] = d[i % ARRAY_LEN];
	}

	d[0] = ft;
	printf("%d %d\n", d[0], in);
	return 0;
}


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

const int maxn = 6;
int In[maxn];
int l[maxn][maxn];
int h[maxn][maxn];
int a[maxn][maxn];
int n , ans;

void dfs(int s,int t,int sum) {
	if (t == n) {
		if (s != n - 2 && In[s] != 0) return ;
		s ++;
		t = s + 1;
	}
	if (s == n - 1) {
		if (ans < sum) ans = sum;
		return ;
	}
	for (int i = l[s][t] ; i <= h[s][t] ; i ++) {
		if (In[s] < i) continue;
		In[s] -= i;
		In[t] += i;
		dfs(s , t + 1 , sum + (i ? a[s][t] : 0) + i * i);
		In[t] -= i;
		In[s] += i;
	}
}

int main() {
	scanf("%d",&n);
	int m = n * (n - 1) / 2;
	int minf = 0 , maxf = 0;
	while (m --) {
		int s , f;
		scanf("%d%d",&s,&f);
		s -- , f --;
		scanf("%d%d",&l[s][f] , &h[s][f]);
		scanf("%d",&a[s][f]);
		if (s == 0) {
			minf += l[s][f];
			maxf += h[s][f];
		}
	}
	ans = -1;
	memset(In , 0 , sizeof(In));
	for (int i = minf ; i <= maxf ; i ++) {
		In[0] = i;
		dfs(0 , 1 , 0);
		if (ans != -1) break;
	}
	if (ans == -1) In[0] = -1;
	printf("%d %d\n",In[0] , ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 15;
int l[maxn][maxn],h[maxn][maxn],a[maxn][maxn];
int flow[maxn],n,Max,Min;
void dfs(int x,int y,int cost){
    cout<<x<<" "<<y<<" "<<cost<<endl;
    if(x==n){
        Max = max(cost,Max);
        return;
    }
    if(y>n){
        if(flag[x]==0)dfs(x+1,x+2,cost);
        return;
    }
    for(int i=l[x][y];i<=h[x][y];i++){
        if(flow[x]<i)return;
        int ncost = cost;
        if(i!=0)ncost+=a[x][y]+i*i;
        flow[x]-=i;flow[y]+=i;
        dfs(x,y+1,ncost);
        flow[x]+=i;flow[y]-=i;
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++){
        int A,B;scanf("%d%d",&A,&B);
        scanf("%d%d%d",&l[A][B],&h[A][B],&a[A][B]);
    }
    Max = -1,Min = -1;
    for(Min=0;Min<=26;Min++){
        cout<<Min<<endl;
        flow[1]=Min;
        dfs(1,2,0);
        if(Max!=-1)break;
    }
    if(Max==-1)cout<<"-1 -1"<<endl;
    else cout<<Min<<" "<<Max<<endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stdio.h>
#include <fstream>
#include <map>
#include <set>
#include <cstdlib>
#include <queue>
#include <math.h>
#include <cmath>
#include <cstring>
#include <stdlib.h>
#include <stack>
#include <iomanip>
#define ll long long
#define endl '\n'
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pll pair<ll,ll>
#define pull pair<ull,ull>
ll MOD=1000000007;
ll inf=1e18;
using namespace std;

vector<string> L;
map< vector<string> , bool > Mem;

bool Solve()
{
    int i,j,x,y,a,b,z;
    if(Mem.find(L)!=Mem.end()){return Mem[L];}
    for(i=0;i<L.size();i++)
    {
        for(j=0;j<L[i].size();j++)
        {
            if(L[i][j]=='.'){continue;}
            // move right
            x=j;
            while(x<L[i].size() && L[i][x]=='O')
            {
                L[i][x]='.';
                if(Solve()==false)
                {
                    for(z=j;z<=x;z+=2){L[i][z]='O';}
                    Mem[L]=true;
                    return true;
                }
                x+=2;
            }
            for(z=j;z<x;z+=2){L[i][z]='O';}

            // move down right
            x=i;y=j;
            while(x<L.size() && y<L[x].size() && L[x][y]=='O')
            {
                L[x][y]='.';
                if(Solve()==false)
                {
                    for(a=i,b=j;a<=x;a++,b++){L[a][b]='O';}
                    Mem[L]=true;
                    return true;
                }
                x++;y++;
            }
            for(a=i,b=j;a<x;a++,b++){L[a][b]='O';}

            // move down left
            x=i;y=j;
            while(x<L.size() && y>=0 && L[x][y]=='O')
            {
                L[x][y]='.';
                if(Solve()==false)
                {
                    for(a=i,b=j;a<=x;a++,b--){L[a][b]='O';}
                    Mem[L]=true;
                    return true;
                }
                x++;y--;
            }
            for(a=i,b=j;a<x;a++,b--){L[a][b]='O';}
        }
    }
    Mem[L]=false;
    return false;
}

int main()
{
    ios::sync_with_stdio(0);
    int i,j;
    string s;
    for(i=0;i<5;i++)
    {
        getline(cin,s);
        for(j=0;j<s.size();j++)
        {
            if(s[j]!='O')
            {
                s[j]='.';
            }
        }
        L.pb(s);
    }
    if(Solve())
    {
        cout<<"Karlsson";
    }
    else
    {
        cout<<"Lillebror";
    }

    return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

void Find_size(int v);
void Build(int root, vector<int> &values);
void Solve();

ll RAND(ll n) {
  return abs((rand() << 15) + rand()) % n;
}

int n;
vector<vector<int>> g;
vector<vector<int>> edges;
vector<bool> used;
vector<int> size;

int Find_centroid(int v, int sz) {
  used[v] = true;
  Find_size(v);
  int max_size = -1;
  for (auto to:g[v]) {
    if (!used[to] && size[to] > sz / 2 && (max_size == -1 || size[to] > size[max_size])) {
      max_size = to;
    }
  }
  int ans;
  if (max_size == -1) {
    ans = v;
  } else {
    ans = Find_centroid(max_size, sz);
  }
  used[v] = false;
  return ans;
}

void Find_size(int v) {
  size[v] = 1;
  used[v] = true;
  for (auto to:g[v]) {
    if (!used[to]) {
      Find_size(to);
      size[v] += size[to];
    }
  }
  used[v] = false;
}

void Build(int root, vector<int> &values) {
  vector<int> val(values.size() + 1, 0);
  int cur_ind = 0;
  used[root] = true;
  queue<int> q;
  q.push(root);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (auto to:g[cur]) {
      if (!used[to]) {
        used[to] = true;
        q.push(to);
        edges[cur][to] = values[cur_ind++] - val[cur];
        edges[to][cur] = edges[cur][to];
        val[to] = val[cur] + edges[cur][to];
      }
    }
  }
}

vector<int> parent;
vector<int> cap;

void make_set(int x) {
  parent[x] = x;
  cap[x] = size[x];
}

int find_set(int x) {
  if (x == parent[x])
    return x;
  return parent[x] = parent[find_set(parent[x])];
}

void union_sets(int x, int y) {
  int a = find_set(x);
  int b = find_set(y);
  if (a != b) {
    if (cap[a] < cap[b])
      swap(a, b);
    parent[b] = a;
    cap[a] += cap[b];
  }
}

void Solve() {
  int c = Find_centroid(0, n);
  Find_size(c);

  auto compare = [](int lhs, int rhs) {
    return cap[lhs] > cap[rhs];
  };
  std::priority_queue<int, std::vector<int>, decltype(compare)> q(compare);

  for (int i = 0; i < n; ++i) {
    if (i == c) {
      continue;
    }
    make_set(i);
    q.push(i);
  }

  while (q.size() > 2) {
    int x = q.top();
    q.pop();
    int y = q.top();
    q.pop();
    union_sets(x, y);
    q.push(find_set(x));
  }
  int x = q.top();
  q.pop();
  int y = q.top();
  q.pop();
  vector<int> gr1(cap[find_set(x)]);
  vector<int> gr2(cap[find_set(y)]);
  for (int i = 0; i < (int) gr1.size(); ++i) {
    gr1[i] = i + 1;
  }
  for (int i = 0; i < (int) gr2.size(); ++i) {
    gr2[i] = (i + 1) * gr1.size();
  }
  for (auto i:g[c]) {
    if (find_set(i) == y) {
      used[i] = true;
    }
  }
  Build(c, gr1);
  for (auto i:g[c]) {
    if (find_set(i) == y) {
      used[i] = false;
    }
  }
  Build(c, gr2);
  for (int i = 0; i < n; ++i) {
    used[i] = false;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  g.resize(n);
  used.resize(n);
  edges.resize(n, vector<int>(n, -1));
  size.resize(n);
  parent.resize(n);
  cap.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  Solve();
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (edges[i][j] >= 0) {
        cout << i + 1 << ' ' << j + 1 << ' ' << edges[i][j] << endl;
      }
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
//{
    #ifdef lawfung
    #define debug(...) do {\
        fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
        _DO(__VA_ARGS__);\
    }while(0)
    template<typename I> void _DO(I&&x) {cerr << x << '\n';}
    template<typename I, typename ...T> void _DO(I&&x,T&&...tail) {cerr << x << ", "; _DO(tail...);}
    #else
    #define debug(...)
    #endif
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;
    typedef pair<double,double> pdd;
    typedef long double ld;
    #define F first
    #define S second
    #define ALL(x)  (x).begin(),(x).end()
    #define SZ(x)   (ll)x.size()
    #define pb push_back
    #define eb emplace_back
    #define stp setprecision(30)<<fixed
    #define YES cout<<"YES\n"
    #define Yes cout<<"Yes\n"
    #define NO cout<<"NO\n"
    #define No cout<<"No\n"
    const int NF = 0x3f3f3f3f;
    const ll INF = 0x3f3f3f3f3f3f3f3f;
    const ll MO7 = 1e9 + 7;
    const ll MO9 = 1e9 + 9;
    const ll MO87 = 1e9 + 87;
    const ll MO93 = 1e9 + 93;
    const ll MO53 = 998244353;
    const ld PI = 3.14159265358979323846264338327950288;
    const ld eps = 1e-7;
//}
const ll MAX = 1e6 + 5 ,Mlg = __lg(MAX) + 2;
ll n, m;
vector<int> adj[MAX];
int sz[MAX];
int mma[MAX];
void dfs(int u, int v) {
    sz[u] = 1;
    int ma = 0;
    for(int i : adj[u]) {
        if(i == v)  continue;
        dfs(i, u);
        ma = max(ma, sz[i]);
        sz[u] += sz[i];
    }
    ma = max(ma, n - sz[u]);
    mma[u] = ma;
}
int findg() {
    for(int i = 1; i <= n; ++ i) {
        if(mma[i] * 2 <= n )
            return i;
    }
    assert(0);
}
pll gg(vector<pll> v) {
    if(n < 3)
        return pll(0, 0);
    ll now = 0;
    for(int i = 0;; ++ i) {
        now += v[i].F;
        if( (now + 1) * ( n - now ) - 1 >= 2 * n * n / 9) {
            return pll(i + 1, now);
        }
    }
    assert(0);
}
ll st, mp;
void D(int u, int v, ll now = 0) {
    ll tt = st - now;
    cout << u << ' ' << v << ' ' << tt * mp <<  '\n';
    ++st;
    for(int i : adj[u]) {
        if(i == v)  continue;
        D(i, u, now + tt);
    }
    return;
}
int main() {
    //ios_base::sync_with_stdio(0);   cin.tie(0);
    cin >> n;
    for(int i = 1; i < n; ++ i) {
        int a, b;
        cin >> a >> b;
        adj[a].eb(b);
        adj[b].eb(a);
    }
    int g = findg();
    dfs(g, g);
    ll all = n - 1;
    vector<pll> v;
    for(int i : adj[g] ) {
        v.eb(sz[i], i);
    }
    sort(ALL(v));
    pll c = gg(v);
    st = 1;
    mp = 1;
    for(int i = 0; i < c.F; ++ i ) {
        D(v[i].S, g);
    }
    st = 1;
    mp = c.S + 1;
    for(int i = c.F; i < SZ(v); ++ i) {
        D(v[i].S, g);
    }
    return 0;
}


/*
ID : moreda
PROG : contest 281 B
LANG : C++
*/
/*
{I'm just a step away
I'm just a breath away
Losing my faith today
(Falling off the edge today)
I am just a man
Not superhuman
(I'm not superhuman)
Someone save me from the hate!

It's just another war
Just another family torn
(Falling from my faith today)
Just a step from the edge
Just another day in the world we live

I need a hero to save me now
I need a hero
(Save me now)

I need a hero to save my life
A hero'll save me
(Just in time)

I gotta fight today
To live another day
Speaking my mind today
(My voice will be heard today)
I've gotta make a stand
But I am just a man
(I'm not superhuman)
My voice will be heard today!

It's just another war
Just another family ton
(My voice will be heard today)
It's just another kill
The countdown begins to destroy ourselves

I need a hero to save me now
I need a hero
(Save me now)
I need a hero to save my life
A hero will save me
(just in time)

I need a hero to save my life
I need a hero
Just in time!
Save me just in time
Save me just in time

Who's gonna fight for what's right
Who's gonna help us survive
We're in the fight of our lives
(And we're not ready to die)

Who's gonna fight for the weak
Who's gonna make 'em believe
I've got a hero
(I've got a hero)
Living in me

I'm gonna fight for what's right
Today I'm speaking my mind
And if it kills me tonight
(I will be ready to die)

A hero's not afraid to give his life
A hero's gonna save me just in time

I need a hero to save me now
I need a hero
(Save me now)
I need a hero to save my life
A hero will save me
(Just in time)
I need a hero!

Who's gonna fight for what's right
Who's gonna help us survive

I need a hero!

Who's gonna fight for the weak
Who's honna make 'em believe

I need a hero!
I need a hero!

A hero's gonna save me just in in time!!!}*/
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define ll        long long
#define ii        pair<int, int>
#define vi        vector<int>
#define vs        vector<string>
#define pb        push_back
#define fo(i,a,b) for(int i=a; i<b; ++i)
#define fr(i,a,b) for(int i=b-1; i>=a; --i)
#define mp(a,b)   make_pair(a,b)
#define fi        first
#define se        second
#define pi        3.141592653589793
#define ee        2.71828
#define BE(a)     a.begin(),a.end()
#define rev(a)    reverse(BE(a))
#define ss(a)     stable_sort(BE(a))
#define st(a)     sort(BE(a))
#define point     complex <long double>
#define X         real()
#define Y         imag()
#define lb(a,b,c) lower_bound(a,b,c)

using namespace std;
struct num
{
	double z;
	int x;
	int y;
};
struct nam
{
	int y;
	double z;
	int x;
};
const int maxN = 1 * 100000 + 10, mod = (int) 1e9 + 7;
const double ep = 1e-16;

vector<num> v;vector<nam> w;
num nn;
int n;

bool cmp1 (num s1, num s2)
{
	if(s1.z == s2.z)
	{
		if(s1.y < s2.y)
			return 1;
		else
			return 0;
	}
	else if(s1.z < s2.z)
		return 1;
	else
		return 0;
}
bool cmp2 (nam s1, nam s2)
{
	if(s1.y == s2.y)
	{
		if(s1.x < s2.x)
			return 1;
		else
			return 0;
	}
	else if(s1.y < s2.y)
		return 1;
	else
		return 0;
}
int main(void)
{
	//ifstream cin("input.txt");
    ios_base::sync_with_stdio (0);
	double h;
	double h2,tel = 0;
	cin >> nn.x >> nn.y >> n;
	nn.z = 0;
	num t;
	nam sw;
	double dd = (double)nn.x / nn.y;
	fo(i,1,n+1)
	{
		 h = floor((double)dd * i);
		 h2= abs(((double)h / i) - dd);
		 t.x=(int)h;
		 t.y=i;
		 t.z=h2;
		 v.pb(t);
		 h = ceil((double)dd* i);
		 h2= abs(((double)h / i) - dd);
		 t.x=(int)h;
		 t.y=i;
		 t.z=h2;
		 v.pb(t);
	}
	sort(v.begin(),v.end(),cmp1);
	int hh = 0;
	while(abs(tel) < ep && hh < v.size())
	{
		sw.x=v[hh].x;
		sw.y=v[hh].y;
		sw.z=v[hh].z;
		w.pb(sw);
		hh++;
		if(hh <v.size())
			tel = v[0].z - v[hh].z;
	}
	sort(w.begin(),w.end(),cmp2);
	cout << w[0].x << '/' << w[0].y;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define M 1000000007
using namespace std;
typedef long long LL;
const int maxn = 100005;
LL n,m,g;
LL C,dp[maxn];

void extend_gcd(LL a, LL b, LL &x, LL &y, LL d=1)
{
    if (b == 0)
    {
        d = a, x = 1, y = 0;
    }
    else
    {
        extend_gcd(b, a%b, y, x, d);
        y -= a/b*x;
    }
}

LL ni(LL x)
{
    LL p,q;
    extend_gcd(x,M,p,q);
    return p;
}

int main()
{
    while(cin>>m>>n>>g)
    {
        if(g == 1)
        {
            if(m == 0)
            {
                puts("0"); continue;
            }
            else
            {
                m--;
                g = 0;
            }
        }
        if(n == 0)
        {
            if(m % 2 == 1 - g) puts("1");
            else puts("0");
            continue;
        }

        if(m == 0)
        {
            if(n == 1) cout << g << endl;
            else
              cout << 1-g << endl;
            continue;
        }
        m -= g;
        C = n + 1;  // C[n+1][1]
        if(n == 1) dp[1] = 2;
        else dp[1] = n;

        for(int i=2; i<=m; i++)
        {
            C = C * (n + i) % M;
            C = C * ni(i) % M;
            C %= M;

            dp[i] = (C - dp[i-1]) % M;
            dp[i] = (dp[i] + M) % M;
        }
        cout << dp[m] << endl;
    }
    return 0;
}


#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
const int N=500005;
int n, ans, m, p[N];
set <pair<int, int> > s;

bool check(int x)
{
    for (auto p:s)
	{
        int u=(p.first+x)%n, v=(p.second+x)%n;
        if (u>v) swap(u, v);
        if (s.find(make_pair(u, v))==s.end()) return 0;
    }
    return 1;
}

inline int read()
{
 	int x=0,f=1;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*f;
}

int main()
{
    for (int i=2; i<N; i++) if (!p[i])
        for (int j=2; j*i<N; j++) p[i*j]=1;
    n=read(); m=read();
    while (m--)
	{
        int u=read()-1, v=read()-1;
        if (u>v) swap(u,v);
        s.insert(make_pair(u,v));
    }
    for (int i=2; i<N; i++) if (!p[i] && !(n%i))
        if (check(n/i)) {puts("Yes"); return 0;}
    puts("No");
    return 0;
}


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

using namespace std;

deque<int> a,b,aa,bb;
int n,k1,k2;

int fn(int cnt)
{
    if(a.empty()) return cnt;
    if(b.empty()) return -cnt;

    if(cnt)
    {
        bool bo=1;
        for(int i = 0 ; i < k1 && bo; i++)
        {
            if(a[i]!=aa[i]) bo=0;
        }
        for(int i = 0 ; i < k2 && bo; i++)
        {
            if(b[i]!=bb[i]) bo=0;
        }
        if(bo) return 0;
    }

    int x=a.front(),y=b.front();
    a.pop_front();
    b.pop_front();
    if(x>y){a.push_back(y);a.push_back(x);}
    else if(y>x){b.push_back(x);b.push_back(y);}

    return fn(cnt+1);
}

int main()
{
    int x,y;
    cin >> n;
    cin >> k1;
    for(int i = 0 ; i < k1 ; i++) {cin >> x; a.push_back(x);}
    cin >> k2;
    for(int i = 0 ; i < k2 ; i++) {cin >> y; b.push_back(y);}

    aa=a; bb=b;
    int cnt=fn(0);

    if(cnt==0) cout << "-1";
    else if(cnt>0) cout << cnt << ' ' << 2;
    else if(cnt<0) cout << -cnt << ' ' << 1;

    return 0;
}


#include <cstdio>
#include <vector>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <sstream>
#include<string.h>
#include <set>
#include <cassert>
#include <map>
#include <set>
#include<limits.h>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
#define in(a) scanf("%lld",&a)
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD (ll)3046201

/*#define gc getchar_unlocked

void in(ll &x)
{
    register ll c = gc();
    x = 0;
    for(;(c<48 || c>57);c = gc());
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
}
*/
ll exp(ll a,ll b){

    if(b==0)
    return 1;

    if(b&1)
    return a*exp(a,b-1);

    else{
        ll ans=exp(a,b/2);
        return ans*ans;
    }

    }

int main(){
    ll k,b,n,t,arr[1000001];
    cin>>k>>b>>n>>t;

    ll expo;

    if(k!=1){
        ll part1=log(b+k*t-t);
        ll part2=log(b+k-1);
        ll part3=floor( ( part1-part2) / (ll)log(k) );
        cout<<n-part3;

        //cout<<max((ll)0,(ll)(n-part3));

    }

    else {

    F(i,0,n)
    {arr[i]= t + i*b ;
    }

    ll z= 1 + n*b;

    ll ans=distance(arr,upper_bound (arr, arr+1+n, z));
    if(ans!=0 && arr[ans-1]==z)
    ans-=1;

    cout<<ans;

    }

return 0;}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <string>
#include <ctime>
#include <queue>
#include <map>
#include <set>

#ifdef WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif // WIN32

#define next(x) (x + ((x) & (-x)))
#define prev(x) (x - ((x) & (-x)))
#define N 1000000
#define md 10000007
#define sqr(x) ((x) * (x))
#define INF (1 << 30)
#define EPS 0.00000001

using namespace std;

long long f(long long x) {
    long long res = 1ll * 4 * x + 1ll * 3 * x * x - 1ll * 3 * x;
    return res / 2;
}

int main() {
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif // DEBUG
    srand(time(NULL));
    long long n;
    cin >> n;
    long long l = 0;
    long long r = 10000000001ll;
    while (l < r) {
        long long mid = (l + r + 1) / 2;
        if (f(mid) > n) {
            r = mid - 1;
        } else {
            l = mid;
        }
    }

    while ((n - f(l)) % 3 != 0) {
        l--;
    }
    cout << 1 + (l - 1) / 3 << endl;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

#include<vector>
using namespace std;
int a[233];
vector<int> v;
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        int sum=0;
        for(int j=i,k=0;j<n&&k<m&&a[j]<=a[i]+m;j++,k++){
            sum++;
        }
        v.push_back(n-sum);
    }
    sort(v.begin(),v.end());
    cout<<v[0]<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <bitset>
#include <ctime>
#include <cmath>
#include <cassert>
#include <algorithm>
using namespace std;

#define pb(p) push_back(p)
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frd(i,a,b) for(int i=a; i>=b i--)
#define PI 2*acos(0.0)
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

int MIN (int a, int b) {
  int x= (b>a)?a:b;
  return x;
}

int MAX(int a, int b) {
  int x= (b<a)?a:b;
  return x;
}

#define maxn 10000000

/*vector<int>prime;
__int64 count[maxn+10];
bool visit[maxn+10];

void make_prime(){
    int i,j;
    int pos1=sqrt((double)maxn)+1;
	visit[1]=true;
	visit[4]=true;
	visit[6]=true;
	visit[8]=true;
    for(i=3;i<=pos1;i++)
	{
		if(visit[i]==false)
		{
			for(j=i*i;j<=maxn;j=j+i+i)
			visit[j]=true;
		}
	}
    prime.push_back(2);
    for(j=3;j<=maxn;j+=2)
        if( visit[j]==false )prime.push_back(j);
}
*/
typedef long long ll;
const int size = 1000007;
const ll modulo = 1000000007;
const ll inf = 1e18;
const double eps = 1e-6;
ll t,n,p,m,b[4000],k,n25,n50,n100;
bool flg[1000][1000];
int a[100009];

int main()
{
	while(cin>>n>>m)
	{
		ll ase = n*100+m*10;

		ll cnt  = 0;

		while(ase>=220)
		{
			if(cnt%2==0)
			{
				if(n>=2)
				{
					n--;n--;
					if(m>=2)
					{
						m-=2;
					}
					cnt++;
				}
				else
				{
					int less = 220- (n*100);
					int j = less/m;
					n=0;
					m = m-j;
					cnt++;
				}
				ase-=220;
			}
			else
			{
				if(m>=22)
				{
					m-=22;
					cnt++;
				}
				else
				{
					if(m>=12)
					{
						m-=12;
						n--;
						cnt++;
					}
					else if(m>=2)
					{
						m-=2;
						n-=2;
						cnt++;
					}

					ase-=220;
				}
			}
		}

		if(cnt%2==0)
			cout<<"Hanako\n";
		else cout<<"Ciel\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define Need_for_speed 	ios_base::sync_with_stdio(0);
int main(){
	Need_for_speed;
	int n;
	cin>>n;
	if(n == 1){
		cout<<"0 1";
		return 0;
	}
	int m=n,sum=0,num=0;
	while(n > 0){
		if(n > 1){
			sum+=2;
			n-=7;
		}
		else{
			sum+=n;
		}
	}
	while(m > 0){
		m-=5;
		if(m > 1){
			num+=2;
			m-=2;
		}
		else if(m == 1){
			num++;
			m--;
		}
	}
	cout<<num<<" "<<sum;
}


#include<iostream>
#include<algorithm>
#include<array>
using namespace std;
typedef long long ll;
typedef array<int,10> a10;
string l,r;
ll ans=0;
int f(char c){
	return c-48;
}
int c[101][101];
void tmw(){
	c[0][0]=1;
	for(int i=1; i<=100 ;i++){
		c[i][0]=1;
		for(int j=1; j<=i ;j++) c[i][j]=c[i-1][j-1]+c[i-1][j];
	}
}
int g(int mk,int len,a10 rem){
	for(int i=0; i<10 ;i++) len-=rem[i];
	int cnt=0;
	for(int i=0; i<10 ;i++) cnt+=((mk&(1<<i))!=0);
	//cout << mk << ' ' << len << ' ' << cnt << endl;
	if(len<0) return 0;
	if(len==0) return 1;
	if(cnt==0) return 0;

	return c[len+cnt-1][len];
}
struct rem{
	a10 x;
	int y;
};
vector<rem>v;
a10 iu,zero;
int main(){
	ios::sync_with_stdio(false);tmw();
	cin >> l >> r;
	reverse(l.begin(),l.end());reverse(r.begin(),r.end());
	while(l.size()<r.size()) l.push_back(48);
	while(!l.empty() && l.back()==r.back()) l.pop_back(),r.pop_back();
	if(l.empty()){
		cout << "1\n";
		return 0;
	}
	reverse(l.begin(),l.end());reverse(r.begin(),r.end());
	int mk=1023;
	for(int i=f(l[0])+1; i<f(r[0]) ;i++){
		ans+=g(mk,l.size()-1,zero);
		mk^=(1<<i);
	}
	iu[f(l[0])]++;
	v.push_back({zero,mk^(1<<f(l[0]))});
	bool ok=true;
	for(int i=1; i<l.size() ;i++){
		int cur=f(l[i]);
		for(int j=cur+1; j<10 ;j++){
			if((mk&(1<<j))==0) continue;
			ans+=g(mk,l.size()-i-1,zero);
			mk^=(1<<j);
		}
		v.push_back({iu,mk&(1023^(1<<cur))});
		if((mk&(1<<cur))==0){
			ok=false;
			break;
		}
		iu[cur]++;
	}
	if(ok) ans++;
	//cout << "fucked" << endl;
	for(auto tzuyu:v){
		a10 cx=tzuyu.x;
		int mk=tzuyu.y;
		if(cx[f(r[0])]!=0) cx[f(r[0])]--;
		else if(mk&(1<<f(r[0])));
		else continue;
		bool ok=true;
		for(int i=1; i<r.size() ;i++){
			int cur=f(r[i]);
			bool fk=false;
			for(int j=0; j<cur ;j++){
				if(cx[j]!=0){
					cx[j]--;
					ans+=g(mk,r.size()-i-1,cx);
					cx[j]++;
					fk=true;
					break;
				}
				if((mk&(1<<j))==0) continue;
				ans+=g(mk,r.size()-i-1,cx);
				mk^=(1<<j);
			}
			if(fk) break;
			if(cx[cur]!=0) cx[cur]--;
			else if(mk&(1<<cur));
			else{
				ok=false;
				break;
			}
		}
		if(ok) ans++;
	}
	cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))

using namespace std;

char SG[1100000000];
bool pd[100005];
int n;
int getsg(int S)
{
	if(SG[S]!=-1) return SG[S];
	bool hash[32]={0};
	for(int i=1; i<=30; i++)
	if(S&(1<<(i-1)))
	{
		int tmS=S;
		for(int j=i; j<=30; j+=i)
			if(tmS&(1<<(j-1))) tmS-=1<<(j-1);
		hash[getsg(tmS)]=1;
	}
	for(int i=0; i<=30; i++)
	if(!hash[i])
		return SG[S]=i;
}
int main()
{
	memset(SG,-1,sizeof(SG));
	SG[0]=0;
	getsg((1<<30)-1);
	scanf("%d",&n);
	int ans=1;
	memset(pd,0,sizeof(pd));
	int i,cut=0;
	for(i=2; i<=floor(sqrt(n)); i++)
	if(!pd[i])
	{
		int num=0;
		for(int j=i; j<=n; j*=i)
		{
			if(j<=floor(sqrt(n))) pd[j]=1;
			else cut++;
			++num;
		}
		ans^=SG[(1<<num)-1];
	}
	ans^=(n-i+1-cut)&1;
	if(ans==0)
		printf("Petya\n");
	else
		printf("Vasya\n");
	return 0;
}


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

    double x,y,z;
    cin>>x>>y>>z;
    double ninf = -1 * numeric_limits<double>::max();

    double a=ninf,b=ninf,c=ninf,d=ninf,e=ninf,f=ninf,g=ninf,h=ninf,i=ninf;
    double m;
    string res;

    assert(log(x)!=0);
    assert(log(y)!=0);
    assert(log(z)!=0);

    if(log(x)<0 && log(y)<0 && log(z)<0){

        a = z*log(y)+log(-log(x));
        b = y*log(z)+log(-log(x));
        c = log(y*z*-log(x));

        d = z*log(x)+log(-log(y));
        e = x*log(z)+log(-log(y));
        f = log(x*z*-log(y));

        g = y*log(x)+log(-log(z));
        h = x*log(y)+log(-log(z));
        i = log(x*y*-log(z));

        m = a;  res = "x^y^z";
        if(b<m)m = b,res = "x^z^y";
        if(c<m)m = c,res = "(x^y)^z";

        if(d<m)m = d,res = "y^x^z";
        if(e<m)m = e,res = "y^z^x";
        if(f<m)m = f,res = "(y^x)^z";

        if(g<m)m = g,res = "z^x^y";
        if(h<m)m = h,res = "z^y^x";
        if(i<m)m = i,res = "(z^x)^y";

        printf("%s\n",res.c_str());
    }
    else {

        if(log(x)>0){
            a = z*log(y)+log(log(x));
            b = y*log(z)+log(log(x));
            c = log(y*z*log(x));
        }

        if(log(y)>0){
            d = z*log(x)+log(log(y));
            e = x*log(z)+log(log(y));
            f = log(x*z*log(y));
        }

        if(log(z)>0){
            g = y*log(x)+log(log(z));
            h = x*log(y)+log(log(z));
            i = log(x*y*log(z));
        }

        m = a;  res = "x^y^z";
        if(b>m)m = b,res = "x^z^y";
        if(c>m)m = c,res = "(x^y)^z";

        if(d>m)m = d,res = "y^x^z";
        if(e>m)m = e,res = "y^z^x";
        if(f>m)m = f,res = "(y^x)^z";

        if(g>m)m = g,res = "z^x^y";
        if(h>m)m = h,res = "z^y^x";
        if(i>m)m = i,res = "(z^x)^y";

        printf("%s\n",res.c_str());
    }
}


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

using namespace std;

long long n, res = 0;

vector <int> v(2);

int main()
{
	cin >> n;
	v[0] = 1;
	v[1] = 6;
	for (int i = 2; i <= n; i++)
	{
		v.push_back(v[i - 1] + 6);
	}
	for (int i = 0; i <= n; i++)
	{
		res += v[i];
	}
	cout << res;

	return 0;
}


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

const int modbase = 1000000007;
int n, a, b, k;
int sqmat[5001][5001], res[5001][5001], temp[5001][5001];

void mul(int A[5001][5001], int B[5001][5001]) {
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=n; ++j) {
			temp[i][j] = 0;
			for (int k=1; k<=n; ++k)
				temp[i][j] = (temp[i][j] + (long long)A[i][k]*B[k][j])%modbase;
		}

	for (int i=1; i<=n; ++i)
		for (int j=1; j<=n; ++j)
			A[i][j] = temp[i][j];
}

int main() {
	cin >> n >> a >> b >> k;
	for (int i=1; i<=n; ++i) {
		for (int j=1; j<=n; ++j) {
			res[i][j] = 0;
			sqmat[i][j] = 0;
		}

		for (int j=max(1,2*i-b+1); j<b; ++j)
			sqmat[i][j] = 1;
		for (int j=b+1; j<=min(n,2*i-b-1); ++j)
			sqmat[i][j] = 1;
		sqmat[i][i] = 0;
		res[i][i] = 1;
	}

	for (int shift=0; (k>>shift)!=0; ++shift) {
		mul(sqmat,sqmat);
		if ((k>>shift)&1)
			mul(res,sqmat);
	}

	int sum = 0;
	for (int i=1; i<=n; ++i)
		sum = (sum+res[a][i])%modbase;
	cout << sum << endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000007
#define pb push_back
using namespace std;
typedef pair<int,int>p;
map<int,int> mp;
vector<int>v[200005];
int visited[200005];
vector<p>v1;
int total;
int ma;
int main()
{
ll int n,a,d,b,c,p,q;
std::ios::sync_with_stdio(false);cin.tie(0);
cin>>n;
cin>>a>>b>>c;
if(a<=b-c){
	cout<<n/a;
	}
else{
d=(n-c)/(b-c);
p=n-b*d;
q=p/a;
cout<<q+d;
}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a1[n],a2[n];
    for(int i=0;i<n;++i)
    {
        cin>>a1[i]>>a2[i];
    }
    int count=0;
    for(int i=0;i<n;++i)
    {
        for(int j=(i+1)%n;j!=i;(j+1)%n)
        {
            if(a1[i]==a2[j]){count++;}
        }
    }
    cout<<count;
}


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

int main()
{
    long long int num,k;
    cin>>num>>k;
    num = (num%2)? num/2 : (num+1)/2;
    cout << ((k<=num)? (2*k-1) : (k-num)*2);
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define maxn 10010
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int n,m,anses[maxn],a[maxn][maxn],R,pi[10],ptr;
map<pii,int>st;
int qpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)ans=1ll*ans*a%mod;
	return ans;
}
int main(){
	scanf("%d",&R);
	int sum=0;
	for(int i=0;i<4;++i)scanf("%d",&pi[i]),sum=(sum+pi[i])%mod;
	sum=qpow(sum,mod-2);
	for(int i=0;i<4;++i)pi[i]=(ll)pi[i]*sum%mod;
	for(int i=-R;i<=R;++i)
		for(int j=-R;j<=R;++j)
			if(i*i+j*j<=R*R)st[pii(i,j)]=++ptr;
	for(auto p:st){
		a[p.second][p.second]++;
		for(int i=0;i<4;++i){
			int px=p.first.first+dx[i];
			int py=p.first.second+dy[i];
			if(st.find(pii(px,py))==st.end())continue;
			a[p.second][st[pii(px,py)]]=mod-pi[i];
		}
		a[p.second][ptr+1]++;
	}
	for(int i=1,j=1;i<=ptr;++i){
		for(j=i;j<=ptr&&!a[j][i];++j);
		if(j==ptr+1)continue;
		for(int k=i;k<=ptr+1;++k)swap(a[j][k],a[i][k]);
		int iv=qpow(a[i][i],mod-2);
		vector<int>f;
		for(int k=i;k<=ptr+1;++k)if(a[i][k])f.push_back(k);
		for(int k=i;k<=ptr;++k)if(i!=k&&a[k][i]){
			int t=1ll*a[k][i]*iv%mod;
			for(auto p:f)a[k][p]=(a[k][p]-(ll)t*a[i][p]%mod+mod)%mod;
		}
	}
	int z=st[pii(0,0)];
	for(int i=ptr;i>=z;--i){
		int b=a[i][ptr+1];
		for(int j=ptr;j>=i;--j)
			if(a[i][j])b=(b-(ll)a[i][j]*anses[j]%mod+mod)%mod;
		anses[i]=(ll)b*qpow(a[i][i],mod-2)%mod;
	}
	printf("%d",anses[z]);
}


#include <iostream>
using namespace std;

int correctSub(int n, int k);

int main() {
  int n, k;

  cin >> n >> k;

  return correctSub(n, k);
}

int correctSub(int n, int k){
  int i = 0;
    while(i < k) {
      if(n%10 == 0){
        while(n%10 == 0){
          n /= 10;
          i++;
        }
      }
      else {
        n--;
        i++;
      }
    }
  return n;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string arr[3];
    int r=0, sc=0, p=0;
    cin >> arr[0] >> arr[1] >> arr[2];
    for (int i = 0; i < 3; i++)
    {
        if (arr[i] == "paper")
            p++;
        else if (arr[i] == "rock")
            r++;
        else if (arr[i] == "scissors")
            sc++;
    }
    if (r == 1 && sc == 2)
    {
        if (arr[0] == "rock")
            cout << "F";
        else if ((arr[1] == "rock"))
            cout << "M";
        else cout << "S";
    }
    else if (sc = 1 && p == 2)
    {
        if (arr[0] == "scissors")
            cout << "F";
        else if ((arr[1] == "scissors"))
            cout << "M";
        else cout << "S";
    }
    else if (p == 1 && r == 2)
    {
        if (arr[0] == "paper")
            cout << "F";
        else if ((arr[1] == "paper"))
            cout << "M";
        else cout << "S";

    }
    else cout << "?" ;

    return 0;

}


#include<iostream>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
//#pragma comment(linker, "/STACK:102400000")
#define LL long long
#define mod 1000000007
#define maxn 100005
#define eps 1e-10
//LL L,b,f,q;
//LL len[109],x,y,lenq[109];
//LL num[maxn*4],ll[maxn*4],rr[maxn*4],mm[maxn*4],setv[maxn*4],
//sr[maxn*4];
//void build(LL o,LL l,LL r)
//{
//	ll[o]=rr[o]=num[o]=mm[o]=r-l;
//	sr[o]=l;
//	if(r-l==1)return;
//	LL m=(l+r)/2;
//	build(o*2,l,m);
//	build(o*2+1,m,r);
//}
//LL query(LL len,LL o,LL l,LL r)
//{
//	if(num[o]<len+b+f)return -1;
//	if(ll[o]>=len+b+f)
//		return l;
//	if(r-l==1)return -1;
//	LL m=(l+r)/2;
//	LL q1=query(len,o*2,l,m);
//	if(q1!=-1)return q1;
//	LL q2=query(len,o*2+1,m,r);
//	if(rr[o*2]+ll[o*2+1]>=len+b+f)
//		return sr[o*2];
//	return q2;
//}
//void pushdown(LL o,LL l,LL r)
//{
//	if(setv[o]!=-1)
//	{
//		LL m=(l+r)/2;setv[o*2]=setv[o*2+1]=setv[o];
//		if(!setv[o])
//		{
//			num[o*2]=ll[o*2]=rr[o*2]=m-l;
//			sr[o*2]=l;
//			num[o*2+1]=ll[o*2+1]=rr[o*2+1]=r-m;
//			sr[o*2+1]=m;
//		}
//		else
//		{
//			num[o*2]=ll[o*2]=rr[o*2]=
//				num[o*2+1]=ll[o*2+1]=rr[o*2+1]=0;
//		}setv[o]=-1;
//	}
//}
//void maLLain(LL o,LL l,LL r)
//{
//	LL m=(l+r)/2;
//	num[o]=max(num[o*2],num[o*2]+1);
//	num[o]=max(num[o],rr[o*2]+ll[o*2+1]);
//	if(ll[o*2]==num[o*2])
//		ll[o]=ll[o*2]+ll[o*2+1];
//	else ll[o]=ll[o*2];
//	if(rr[o*2+1]==num[o*2+1])
//		rr[o]=rr[o*2]+rr[o*2+1],sr[o]=sr[o*2];
//	else rr[o]=rr[o*2+1],sr[o]=sr[o*2+1];
//}
//void update(LL L,LL R,LL o,LL l,LL r)
//{
//	if(L<=l&&r<=R)
//	{
//		setv[o]=1;
//		num[o]=ll[o]=rr[o]=0;
//		return;
//	}
//	if(L>=r||l>=R)return;
//	pushdown(o,l,r);
//	LL m=(l+r)/2;
//	if(L<=m)update(L,R,o*2,l,m);
//	if(m<R)update(L,R,o*2+1,m+1,r);
//	maLLain(o,l,r);
//}
//void del(LL L,LL R,LL o,LL l,LL r)
//{
//	if(L<=l&&r<=R)
//	{
//		setv[o]=0;
//		num[o]=ll[o]=rr[o]=r-l;
//		return;
//	}
//	if(L>=r||l>=R)return;
//	pushdown(o,l,r);
//	LL m=(l+r)/2;
//	if(L<=m)update(L,R,o*2,l,m);
//	if(m<R)update(L,R,o*2+1,m+1,r);
//	maLLain(o,l,r);
//}
//LL main()
//{
//	while(scanf("%d%d%d%d",&L,&b,&f,&q)!=EOF)
//	{
//		LL n=0;
//		build(1,0,L);
//		for(LL i=1;i<=q;i++)
//		{
//			scanf("%d%d",&x,&y);
//			if(x==1){
//				len[++n]=y;
//				LL qq=query(y,1,0,L);
//				if(qq==-1)prLLf("-1\n");
//				else
//				{
//					prLLf("%d\n",qq+f);
//					update(qq+f,qq+y+f,1,0,L);
//					lenq[n]=qq;
//				}
//			}
//			else
//			{
//				LL qq=lenq[y];
//				del(qq+f,qq+y+f,1,0,L);
//			}
//		}
//	}
//}
int n;
struct node
{int x,p;};
queue<node>q;
bool vis[1000009];
int p[10],pp;
void cnt(int x)
{
	pp=0;
	if(x==0)return ;
	while(x)
	{
		p[++pp]=x%10;
		x/=10;
	}
}
int main()
{
	memset(vis,0,sizeof(vis));
	cin>>n;
	vis[n]=1;
	while(!q.empty())q.pop();
	node nd;nd.x=n;nd.p=0;
	q.push(nd);
	while(!q.empty())
	{
		nd=q.front();q.pop();
		cnt(nd.x);
		if(pp==0){cout<<nd.p<<endl;return 0;}
		for(int i=1;i<=pp;i++)
		{
			int y=nd.x-p[i];
			node t;t.p=nd.p+1;t.x=y;
			if(!vis[t.x])
				q.push(t);
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
int b[5005], cnt, pr[800], f[800][5001], n, op[1000005];
long long ans;
vector<int> vec[1000005], ss, tmp;
int main()
{
    for (int i = 2; i <= 5000; i++) {
        if (b[i]) continue;
        for (int j = 2; j * i <= 5000; j++) b[i * j] = 1;
    }
    for (int i = 2; i <= 5000; i++)
        if (b[i] == 0) pr[++cnt] = i;
    for (int i = 1; i <= cnt; i++) {
        for (int j = 1; j <= 5000; j++) {
            if (j >= pr[i]) f[i][j] = j / pr[i] + f[i][j / pr[i]];
        }
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", op + i);
        if (op[i] == 0) op[i] = 1;
        for (int j = 1; j <= cnt; j++) ans += f[j][op[i]];
    }
    for (int i = 1; i <= n; i++) {
        vec[i].push_back(0);
        for (int j = 1; j <= cnt; j++) vec[i].push_back(f[j][op[i]]);
    }
    for (int i = 1; i <= n; i++) ss.push_back(i);
    for (int i = cnt; i >= 1;) {
        int s = 0, minn = 0x7fffffff;
        tmp.clear();
        for (int a : ss) {
            if (vec[a][i]) ++s, minn = min(minn, vec[a][i]);
        }
        if (s > n - s) {
            ans -= 1ll * minn * (s - n + s);
            for (int a : ss) {
                if (vec[a][i]) vec[a][i] -= minn, tmp.push_back(a);
            }
            ss.clear();
            for (int a : tmp) ss.push_back(a);
        }
        else if (n - s > s) {
            for (int a : ss) {
                if (!vec[a][i]) tmp.push_back(a);
            }
            ss.clear();
            for (int a : tmp) ss.push_back(a);
            --i;
        }
        else {
            break;
        }
    }
    printf("%lld", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> mem[5001];

vector<int> Fact(int x) {
    if (!mem[x].empty()) {
        return mem[x];
    }

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

    return mem[x] = res;
}

vector<int> F(int x) {
    vector<int> res;
    for (int i = 2; i <= x; ++i) {
        auto f = Fact(i);
        res.insert(res.end(), f.begin(), f.end());
    }
    sort(res.begin(), res.end());
    reverse(res.begin(), res.end());

    return res;
}

vector<int> cnt(1);
vector<unordered_map<int, int>> nxt(1);

int64_t ans = 0;

void Add(const vector<int>& data, int delta) {
    int v = 0;
    ans += 1LL * data.size() * delta;
    for (int x : data) {
        if (!nxt[v].count(x)) {
            nxt[v][x] = nxt.size();
            nxt.emplace_back();
            cnt.emplace_back();
        }
        v = nxt[v][x];
        cnt[v] += delta;
    }
}

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

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

    for (size_t i = 0; i < cnt.size(); ++i) {
        Add(F(i), cnt[i]);
    }

    int v = 0;
    for (bool flag = false; flag; flag = false) {
        for (auto x : nxt[v]) {
            if (cnt[x.second] > n - cnt[x.second]) {
                ans -= cnt[x.second];
                ans += n - cnt[x.second];
                v = x.second;
                flag = true;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
    char s[100011];
    scanf("%s",s+1);
    int len=strlen(s+1);
    int cnt=0;
    for(int i=len;i>=0;i++)
    {
        if(s[i]=='0')
        {
            cnt++;
        }
    }
    if(cnt>6)
    {
        puts("yes");
    }
    else
    {
        puts("no");
    }
    return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
#define ll long long
#define ld long double
#define fir first
#define sec second
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, k, M;
    cin >> n >> k >> M;
    vector <int> T(k+1,0);
    for(int i=0; i<k; i++)
        cin >> T[i];
    int ans=-1, t, cur; vector <int> V(n,-1);
    pair < pair <int,int> , vector <int> > r; priority_queue < pair < pair <int,int> , vector <int> > > Q;
    Q.push({{0,0},V});
    while(!Q.empty())
        {
            r=Q.top(), Q.pop();
            if(r.fir.sec>=ans)
                {
                    ans=r.fir.sec, t=(-1)*r.fir.fir, cur=k;
                    for(int i=0; i<n; i++)
                        if(r.sec[i]+1<=cur && t+T[r.sec[i]+1]<=M){
                            r.sec[i]++;
                            r.fir.fir-=T[r.sec[i]];
                            r.fir.sec++;
                            Q.push(r);
                            r.fir.sec--;
                            r.fir.fir+=T[r.sec[i]];
                            r.sec[i]--;
                            cur=min(cur,r.sec[i]);
                        }
                }
        }
    cout << ans <<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<bitset>
#include<iomanip>
#include<iostream>
#include<cmath>
using namespace std;
#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define REP(i,x,y) for(int i=(x);i<=(y);i++)
#define _REP(i,x,y) for(int i=(x);i>=(y);i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define pb push_back
#define IN insert
#define ER erase
#define BE begin()
#define ED end()
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
inline char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int ms=255;
const int up=256;
int x,k,p0,i;ld p;
int get(int x){return(x&1)?0:get(x/2)+1;}

bool v[202][256][2][250];
ld   f[202][256][2][250];
int cc[10000];

ld dp(int i,int S,int la,int cnt)
{
    if(i>k)
    {
        if(S==0)return 8+(la==0)*cnt;
        else return cc[S];
    }

    ld&ans=f[i][S][la][cnt];
    if(v[i][S][la][cnt])return ans;
    v[i][S][la][cnt]=1;

    if(S==ms)ans+=(1-p)*dp(i+1,0,1-la,(la==0)?1:cnt);
    else ans+=(1-p)*dp(i+1,S+1,la,cnt);

    int w=(S<<1)&up,cnt2;

    if(cnt)cnt2=(la==w)?cnt+1:1;else cnt2=(w==1)?1:0;

    ans+=p*dp(i+1,(S<<1)&ms,w,cnt2);

    return ans;
}

int main()
{
    //freopen("1.in","r",stdin);freopen("1.out","w",stdout);
    rep(i,1,ms)if(i&1)cc[i]=0;else cc[i]=cc[i/2]+1;

    read(x,k,p0);p=1.0*p0/100;

    int x0=x/256,t,cnt;

    t=x0&1;cnt=0;
    while(x0>0&&(x0&1)==t)x0/=2,cnt++;

    cout<<fixed<<setprecision(10)<<dp(1,x&ms,t,cnt)<<endl;

    scanf("\n");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }
int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

long double prob;
long double cprob;

int cnt_last_zeros(int x) {
    if (x == 0) return 8;
    int res = 0;
    while (~x & 1) {
        x >>= 1;
        res++;
    }
    return res;
}

map<int, int> aa;
const int mask8 = (1 << 8) - 1;

int nleadc, nlead, xx;
void mul2(int leadcnt, int lead, int x) {
    xx = (x << 1) & mask8;
    int c = (x >> 7) & 1;
    if (lead == c) {
        nlead = lead, nleadc = leadcnt + 1;
    } else {
        nlead = c, nleadc = 1;
    }
}

int add1(int leadcnt, int lead, int x) {
    x = x + 1;
    xx = x & mask8;
    int c = (x >> 8) & 1;
    if (lead == c) {
        nlead = lead, nleadc = leadcnt + 1;
    } else {
        nlead = c, nleadc = 1;
    }
}

long double cache[222][222][2][1 << 8];
long double solve(int rest, int leadcnt, int lead, int x) {
    long double & res = cache[rest][leadcnt][lead][x];
    if (res > -0.5) return res;
    if (rest == 0) {
        int k = cnt_last_zeros(x);
        if (k == 8) {
            if (lead == 0) k += leadcnt;
        }
        res = k;
        return k;
    }
    res = 0;
    mul2(leadcnt, lead, x);
    res += solve(rest - 1, nleadc, nlead, xx) * prob;
    add1(leadcnt, lead, x);
    res += solve(rest - 1, nleadc, nlead, xx) * cprob;
    return res;
}

int main () {
    int i, j, tcc, tc = 1 << 28;
    for (tcc = 0; tcc < tc; tcc++) {
        int x = getint();
        int k = getint();
        int pint = getint();
        prob = pint / 100.0;
        cprob = 1 - prob;
        for (i = 0; i < 222; i++) for (j = 0; j < 222; j++) {
            for (int h = 0; h < 1 << 8; h++) {
                cache[i][j][0][h] = cache[i][j][1][h] = -1;
            }
        }
        int l8 = x & mask8;
        x >>= 8;
        int c = x & 1, d = 0;
        while (x and c == (x & 1)) { x >>= 1, d++; }
        long double res = solve(k, d, c, l8);
        cout.precision(15);
        cout << res << endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>

using namespace std;
const int MAXN = 200010;
const int MOD = 1e9+7;
#define INF 0x3f3f3f3f
#define LL long long

int cnt;
int mx = -INF, mn = INF;
int TT, T, n, m;

int dp[2][100001];

int main()
{
    int i, j, k, kk, l, r;

	int cur = 0;
	cnt = 1;
	int pre = cur ^ 1;
//	cin >> T;
	int q[100010];
	int h, d;
	T = 1;
	while(T--)
	{
		scanf("%d %d", &n, &k);

		memset(dp, INF, sizeof(dp));
		dp[cur][0] = 0;
		for(i = 1; i <= k; i++)
		{
			pre = cur;
			cur ^= 1;
			scanf("%d %d", &l, &r);

			h = 1, d = 0;
			for(j = 0; j <= r; j++)
			{
				if(j <= n){
					while(h <= d && dp[pre][j] <= dp[pre][q[d]]) d--;
					q[++d] = j;
				}
				while(h <= d && (q[h] < j - r + l))
					h++;
				dp[cur][j] = min(dp[pre][j], dp[pre][q[h]] + 2);
			}

			h = 1, d = 0;
			for(j = r; j >= 0; j--)
			{
				if(r - j <= n){
					while(h <= d && dp[pre][r - j] <= dp[pre][q[d]]) d--;
					q[++d] = r - j;
				}

				while(h <= d && (q[h] < l - j))
					h++;
				dp[cur][j] = min(dp[cur][j], dp[pre][q[h]] + 1);
			}

		}
		if(dp[cur][n] >= INF)
			puts("Hungry");
		else printf("Full\n%d\n", dp[cur][n]);
	}
	return 0;

}


By Asm.Def, contest: Codeforces Round #431 (Div. 1), problem: (D) Shake It!, Accepted, #

#include <bits/stdc++.h>
using namespace std;
const int maxn = 52, mod = 1000000007;
typedef long long LL;
int N, M, F[maxn][maxn], G[maxn][maxn], inv[maxn];

void init()
{
    scanf("%d%d", &N, &M);
    inv[1] = 1;
    for(int i = 2;i < maxn;++i)
        inv[i] = LL(mod-mod/i) * inv[mod%i] % mod;
}
void work()
{
    F[0][1] = 1;
    for(int i = 1;i <= N;++i) for(int j = 1;j < maxn;++j)
    {
        for(int a = 0;a < i;++a)
        {
            G[i][j] = (G[i][j] + (LL) F[a][j] * F[i-1-a][j]) % mod;
            for(int b = j+1;b <= i+1 && b < maxn;++b)
            {
                G[i][j] = (G[i][j] + (LL) F[a][b] * F[i-1-a][j]) % mod;
                G[i][j] = (G[i][j] + (LL) F[a][j] * F[i-1-a][b]) % mod;
            }
        }
        //get G[i][j]
        for(int x = N-1;x >= 0;--x) for(int y = 1;y < maxn;++y) if(F[x][y])
        {
            int C = 1;
            for(int t = 1;x+t*i <= N && y+t*j < maxn;++t)
            {
                C = (LL) C * (G[i][j]-1+t) % mod * inv[t] % mod;
                F[x+t*i][y+t*j] = (F[x+t*i][y+t*j] + (LL) F[x][y] * C) % mod;
            }
        }
    }
    printf("%d\n", F[N][M]);
}
int main()
{
    init();
    work();
    return 0;
}

动态规划


#include<bits/stdc++.h>

typedef long long int ll;
#define pp pair<ll,ll>
#define ppp pair<ll,pp>
#define dbg printf("x");
#define inf 1000000000000
#define max2(a,b) ((a<b)?b:a)
#define max3(a,b,c) max2(max2(a,b),c)
#define min2(a,b) ((a>b)?b:a)
#define min3(a,b,c) min2(min2(a,b),c)

using namespace std;

int main()
{
    freopen("in.txt","r",stdin);
    int i,j,k;
    int n,l;

    cin>>n>>l;
    int a[n],b[n];

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

    for(i=0;i<n;i++)
        cin>>b[i];

    queue<int > ds;
    queue<int>  kf;

    for(i=1;i<n;i++)
    {
        ds.push(a[i]-a[i-1]);
    }

    ds.push(l-a[n-1]+a[0]);

    for(i=1;i<n;i++)
    {
        kf.push(b[i]-b[i-1]);
    }

    kf.push(l-b[n-1]+b[0]);

    while(n)
    {
        if(ds==kf)
        {
            cout<<"YES";
            return 0;
        }

        i=ds.front();ds.pop();ds.push(i);n--;
    }

    cout<<"NO";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll sum (ll x) {
	ll ans = 0;
	while (x) {
		ans += (x % 10ll);
		x /= 10;
	}
	return ans;
}
ll mx, ans;

int main () {

	//freopen ("in", "r", stdin);
	//freopen ("slow.out", "w", stdout);
	ll x;
	cin >> x;
	for (ll i = 1;i <= x;i ++) {
		ll cnt = sum (i);
		if (cnt >= mx) {
			mx = cnt;
			ans = i;
		}
	}
	cout << ans;

return 0;
}


#include <bits/stdc++.h>
#define task "1"
using namespace std;
int n,m,d,k;
string s;
main(){
//    freopen(task".INP","r",stdin);
//    freopen(task".OUT","w",stdout);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> s[i];
        if(s[i] == '8') d++;
    }
    k=n/10;
    cout << min(d,k);
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int i=0,n,count=0;
    cin >> n;
    char s[n+1];
    cin >> s;
    while(s[i]!=0)
    {
        if(s[i]=='8')
        {
            count++;
        }
        i++;
    }
    while(count--)
    {
        if(n%count==0)
        {
            cout << count;
            return 0;
        }
    }
    cout << "0";
    return 0;
}


#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int maxn=5e4+2;
const int maxm=20+2;
const int B=200+2;
int cnt=1;
bitset<B> a[maxn];
int nxt[maxm][maxn];
bool vis[maxm][maxn];
map<bitset<B>,int> mp;
LL dp[maxm][maxm][maxn];
void DP(){
	for (int i=1;i<=cnt;i++){
		int j=0;
		for (;j<10;j++) if (a[i][j]) break;
		for (;j<10;j++) dp[0][j][i]=1;
	}
	for (int i=1;i<maxm-1;i++)
		for (int j=1;j<=cnt;j++)
			if (vis[maxm-1-i][j])
				for (int k=0;k<10;k++)
					for (int l=0;l<10;l++)
						dp[i][l][j]+=dp[i-1][l][nxt[j][k]];
}
int bit[maxm];
LL solve(LL x,int k){
	if (x==0) return 1;
	int len=0;
	while (x){
		bit[len++]=x%10;
		x/=10;
	}
	int u=1;
	LL ret=0;
	for (int i=len-1;i>=0;i--){
		for (int j=0;j<bit[i]+(i==0);j++)
			ret+=dp[i][k][nxt[u][j]];
		u=nxt[u][bit[i]];
	}
	return ret;
}
int main(){
	bitset<B> Bit;
	Bit.set(0);
	mp[Bit]=1;
	a[1]=Bit;
	vis[0][1]=true;
	for (int i=1;i<maxm;i++)
		for (int u=1;u<=cnt;u++)
			if (vis[i-1][u])
				for (int j=0;j<10;j++){
					if (!nxt[u][j])
						if (!j) nxt[u][j]=u;
						else{
							Bit.reset();
							for (int k=j;k<B;k++)
								if (a[u][k]) Bit[k-j]=1;
							for (int k=0;k<B-j;k++)
								if (a[u][k]) Bit[k+j]=1;
							for (int k=1;k<j;k++)
								if (a[u][k]) Bit[j-k]=1;
							if (mp.count(Bit)) nxt[u][j]=mp[Bit];
							else{
								nxt[u][j]=mp[Bit]=++cnt;
								a[cnt]=Bit;
							}
						}
					vis[i][nxt[u][j]]=true;
				}
	DP();
	int kase;
	scanf("%d",&kase);
	while (kase--){
		LL l,r;
		int k;
		scanf("%I64d%I64d%d",&l,&r,&k);
		printf("%I64d\n",solve(r,k)-solve(l-1,k));
	}
	return 0;
}


#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int maxn=5e4+2;
const int maxm=20+2;
const int B=200+2;
int cnt=1;
bitset<B> a[maxn];
int to[maxm][maxn];
bool vis[maxm][maxn];
map<bitset<B>,int> mp;
LL dp[maxm][maxm][maxn];
void DP(){
	for (int i=1;i<maxm-1;i++){
		int j=0;
		for (;j<10;j++) if (a[i][j]) break;
		for (;j<10;j++) dp[0][i][j]=1;
	}
	for (int i=1;i<maxm-1;i++)
		for (int j=1;j<=cnt;j++)
			if (vis[maxm-1-i][j])
				for (int k=0;k<10;k++)
					for (int l=0;l<10;l++)
						dp[i][l][j]+=dp[i-1][l][to[j][k]];
}
int bit[maxm];
LL solve(LL x,int k){
	if (x==0) return 1;
	int len=0;
	while (x){
		bit[len++]=x%10;
		x/=10;
	}
	int u=1;
	LL ret=0;
	for (int i=len-1;i>=0;i--){
		for (int j=0;j<bit[i]+(i==0);j++) ret+=dp[i][k][to[u][j]];
		u=to[u][bit[i]];
	}
	return ret;
}
int main(){
	bitset<B> Bit;
	Bit.set(0);
	mp[Bit]=1;
	a[1]=Bit;
	vis[0][1]=1;
	for (int i=1;i<maxm;i++)
		for (int u=1;u<=cnt;u++)
			if (vis[i-1][u])
				for (int j=0;j<10;j++){
					if (!to[u][j])
						if (!j) to[u][j]=u;
						else{
							Bit.reset();
							for (int k=0;k<B;k++)
								if (a[u][k]) Bit[k-j]=1;
							for (int k=0;k<B-j;k++)
								if (a[u][k]) Bit[k+j]=1;
							for (int k=1;k<j;k++)
								if (a[u][k]) Bit[j-k]=1;
							if (mp.count(Bit)) to[u][j]=mp[Bit];
							else{
								to[u][j]=mp[Bit]=++cnt;
								a[cnt]=Bit;
							}
						}
					vis[i][to[u][j]]=true;
				}
	DP();
	int kase;
	scanf("%d",&kase);
	while (kase--){
		LL l,r;
		int k;
		scanf("%I64d%I64d%d",&l,&r,&k);
		printf("%I64d\n",solve(r,k)-solve(l-1,k));
	}
	return 0;
}


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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        while(1)
        {
            int n,k1,k2;
            cin>>n;
            n*=1000;
            queue<int> a,b;
            cin>>k1;
            while(k1--)
            {
                cin>>k2;
                a.push(k2);
            }
            cin>>k2;
            while(k2--)
            {
                cin>>k1;
                b.push(k1);
            }
            int ans=0,q=0;
            while(!a.empty() and !b.empty() and n--)
            {
                if(a.front()<b.front()) b.push(a.front()),b.push(b.front());
                if(a.front()>b.front()) a.push(b.front()),a.push(a.front());
                a.pop();
                b.pop();
                ans++;
            }
            if(!a.empty() and !b.empty()) cout<<-1;
            else
            {
                if(!a.empty()) cout<<ans<<' '<<1;
                else cout<<ans<<' '<<2;
            }
        }

    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int middle(vector<int> city,int ind,int num)
{
    ind--;
    int criminal=0;
    for(int i=ind+1;i<num;i++)
    {
        static int r=ind-1;
        if(city[i]==city[r]&&city[i]==1)
        {
            criminal+=2;
        }
        r--;
    }
    if(city[ind]==1){criminal++;}
    return criminal;
}
int small(vector<int> city,int ind,int num)
{
    ind--;
    int criminal=0;
    if(ind==0)
    {
        for(int i=0;i<num;i++)
        {
            if(city[i]==1)
            {
                criminal++;
            }
        }
    }
    else
    {
        int f;
        for(int i=ind+1;i<num;i++)
        {
            static int r=ind-1;
            if(city[i]==city[r]&&city[i]==1)
            {
                criminal+=2;
            }
            r--;
            if(r<0)
            {
                f=i+1;
                break;
            }
        }
        for(int i=f;i<num;i++)
        {
            if(city[i]==1)
            {
                criminal++;
            }
        }
        if(city[ind]==1){criminal++;}
    }
    return criminal;
}
int bigger(vector<int> city,int ind,int num)
{
    ind--;
    int criminal=0;
    if(ind==num-1)
    {
        for(int r=ind;r>0;r--)
        {
            if(city[r]==1)
            {
                criminal++;
            }
        }
    }
    else
    {
        int f;
        for(int i=ind+1;i<num;i++)
        {
            static int r=ind-1;
            if(city[i]==city[r]&&city[i]==1)
            {
                criminal+=2;
            }
            r--;
            if(i==num-1)
            {
                f=r;
                break;
            }
            for(int r=f;r>0;r--)
            {
                if(city[r]==1)
                {
                    criminal++;
                }
            }
        }
        if(city[ind]==1){criminal++;}
    }
    return criminal;
}
int main()
{
    int num,ind,criminal=0,ele;
    vector<int>city;
    cin>>num>>ind;
    for(int i=0;i<num;i++)
    {
        cin>>ele;
        city.push_back(ele);
    }
    if(ind==(num/2)+1)
    {
        criminal=middle(city,ind,num);
    }
    else
    {
        if(ind<=num/2)
        {
            criminal=small(city,ind,num);
        }
        else
        {
            criminal=bigger(city,ind,num);
        }
    }
    cout<<criminal;
    return 0;
}


//Cok tavsanin pesinde kosan hicbrini yakalmaz!
#include<bits/stdc++.h>
#define MAXN 100009
#define INF 1000000007
#define LLINF 1000000000000000007
#define mp(x,y) make_pair(x,y)
#define wr cout<<"Continue Debugging!!!"<<endl;
#define ff first
#define ss second
#define lg(x) ceil(log2(x))
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define tr(i, c) for(typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
template<class T> bool umin(T& a, T b) { if(a > b){ a = b;return 1;}return 0;}
template<class T> bool umax(T& a, T b) { if(a < b){ a = b;return 1;}return 0;}
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
ll arr[21],m,a,dp[(1<<10)+9][1009];
string n;
ll rec(ll mask,ll val){
	if(__builtin_popcount(mask)==a)
		return (!val);
	ll ret=dp[mask][val];
	if(ret!=-1)
		return ret;
	ret=0;
	for(ll i=0;i<a;i++){
		if(!mask and !arr[i])
			continue;
		if(mask&(1<<i))
			continue;
		ret+=rec((mask|(1<<i)),(val*10+arr[i])%m);
		while(arr[i]==arr[i+1])
			i++;
	}
	return ret;
}
 main(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	a=n.size();
	for(ll i=0;i<a;i++)
		arr[i]=n[i]-'0';
	sort(arr,arr+a);
	cout<<rec(0,0)<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int a=0,b=0;
	string s;
	cin>>s;
	for (int i=0; i<s.size(); i++)
	   {
	   	  if (s[i]=='o')
	   	     a++;
	   	   else
	   	     b++;
	   }
	if (b==0)
	{
	  cout<<"YES";
	  return 0;
    }
	if (a==b or b%a==0)
	     cout<<"YES";
	else
	     cout<<"NO";

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>
#include <limits>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf(" %c", &n)
#define SS(n) scanf(" %s", n)
#define FR(i, n) for (int i = 0; i < n; i++)
#define RFR(i, n) for (int i = n - 1; i >= 0; i--)
#define FR1(i, n) for (int i = 1; i <= n; i++)
#define RFR1(i, n) for (int i = n; i >= 1; i--)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const double EPS = numeric_limits<double>::epsilon();
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int main() {
    int n; SI(n);
    VL a;
    FR(i, n) SL(a[i]);
    FR(i, n - 1) {
        if ((a[i + 1] - a[i]) * (a[i] - a[0]) < 0) {
            printf("3\n1 %d %d", i + 1, i + 2);
            return 0;
        }
    }
    printf("0\n");
    return 0;
}


/* Copyright 2016 AcrossTheSky */
#include <iostream>
#include <cstdio>
#include <utility>
#include <cassert>
#include <map>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sstream>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define PER(i, a, b) for (int i = (a); i >= (b); --i)
#define RVC(i, c) fot (int i = 0; i < (c).size(); ++i)
#define RED(k, u) for (int k = head[(u)]; k; k = edge[k].next)
#define lowbit(x) ((x) & (-(x)))
#define CL(x, v) memset(x, v, sizeof x)
#define MP std::make_pair
#define PB push_back
#define FR first
#define SC second
#define rank rankk
#define next nextt
#define link linkk
#define index indexx
#define abs(x) ((x) > 0 ? (x) : (-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

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

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

template<class T> inline
void read(T *a) {
    char c;
    while (isspace(c = getchar())) {}
    bool flag = 0;
    if (c == '-') flag = 1, *a = 0;
    else
        *a = c - 48;
    while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
    if (flag) *a = -*a;
}
const int mo = 1000000007;
template<class T>
T pow(T a, T b, int c = mo) {
    T res = 1;
    for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c) if (b & i) res = 1LL * res * a % c;
    return res;
}
/*======================= TEMPLATE =======================*/
const int N = 1000;
char s[N];
int n, a, b;
bool check(int a, int b, int c, int d) {
	if (!c && a) return 0;
	if (c && a % c) return 0;
	if (!d && b) return 0;
	if (d && b % d) return 0;
	int ta = 19981103, tb = 19981103;
	if (c) ta = a / c;
	if (d) tb = b / d;
	if (ta < 0 || tb < 0) return 0;
	if (ta == 19981103 || tb == 19981103) return 1;
	return ta == tb;
}
int main() {
	cin >> a >> b;
	int x = 0, y = 0;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	REP(i, 1, n)
		if (s[i] == 'R') ++x;
		else if (s[i] == 'U') ++y;
		else if (s[i] == 'L') --x;
		else --y;
	int tx = 0, ty = 0;
	REP(i, 1, n) {
		if (s[i] == 'R') ++tx;
		else if (s[i] == 'U') ++ty;
		else if (s[i] == 'L') --tx;
		else --ty;
		if (check(a - tx, b - ty, x, y)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#define pii pair<int,int>
#define lol long long
using namespace std;
int main()
{
    lol arr[3];
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr,arr+3);
    lol ans=0;
    ans+=arr[0];
    arr[1]-=arr[0]; arr[2]-=arr[0];
    if(arr[1]>1)
    ans+=arr[1];
    else
    {
        if(arr[1]==1&&arr[2]>1) ans+=1;
    }
    cout << ans <<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
long long base=1e9+7,f[100001];
int main(){
    cin>>n;
    f[1]=1;
    f[2]=3;
    for(int i=3;i<=n;i++){
        f[i]=((f[i-1]*2)-(f[i-3])+base)%base;
    }
    cout<<f[n]%base;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
using namespace std;
ll n;
ll dp[100005];
bool visited[100005];

ll fun(ll idx)
{
	ll i;
	ll mod=1000000007;
	if(idx>n)
	return 0;
	if(visited[idx])
		return dp[idx];
	visited[idx]=true;
	for(i=1;i<n;i++)
	{
		if(idx+i<=n)
		dp[idx]=dp[idx]+(1+fun(idx+i));
		cout<<idx<<" "<<dp[idx]<<"\n";
	}
	return dp[idx];

}

int main()
{
	for(ll i=0;i<100005;i++)
	{
		dp[i]=0;
		visited[i]=false;
	}
	cin>>n;
		ll mod=1000000007;
	//ll ans=fun(1);
	dp[1]=1;
	dp[2]=3;

	for(ll i=3;i<=n;i++)
	{
		dp[i]=(dp[i-1]+dp[i-2]+2)%mod;
	}
	cout<<dp[n];
}


#include<bits/stdc++.h>
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
#define INF 0x3f3f3f3f
#define SIEVELIM 10000000+10
#define EPS 1e-7
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
inline int nextint(){ int temporary; scanf("%d",&temporary); return temporary; }
inline ll nextll(){ ll temporary; scanf("%lld",&temporary); return temporary; }
inline double nextdouble(){double temporary; scanf("%lf",&temporary); return temporary;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll leftChild(ll p ){return p<<1;}
ll rightChild(ll p ){return (p<<1)+1;}
inline ll mid(ll l, ll r){ return (l+r)/2;}
const ll MOD = 1000000007;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define deb(x )     cerr << #x << " here "<< x;
#define endl    "\n"
#define pb push_back
#define mp make_pair
#define all(cc) (cc).begin(),(cc).end()

template<typename T > void modulize(T & a, const T & b) { if (a >= b) { a %= b; } }
ll mulmod(ll a, ll b, ll m) { ll q = (ll)(((ld)a*(ld)b) / (ld)m); ll r = a*b - q*m; if (r>m)r %= m; if (r<0)r += m; return r; }
template <typename T, typename S>T expo(T e, S n) { T x = 1, p = e; while (n) { if (n & 1)x = x*p; p = p*p; n >>= 1; }return x; }
template <typename T>T power(T e, T n, T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mod(x*p, m); p = mod(p*p, m); n >>= 1; }return x; }
template <typename T>T powerL(T e, T n, T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; }return x; }
template <typename T> T InverseEuler(T a, T & m) { return (a == 1 ? 1 : power(a, m - 2, m)); }
/*----------------------------------------------------------------------*/

//dp table
ll dp[16][160][2];

void getDigits(long long x, vector <int> &digit)
{
    while (x)
    {
        digit.push_back(x%10);
        x /= 10;
    }
}

long long value(int idx, int first , int recent , bool tight,
                          vector <int> &digit)
{
	if (digit.size()==1)
	{
		return digit[0];
	}

    // base case
    if (idx == -1)
       return first==recent;

    // if (dp[idx][sum][tight] != -1 and !tight)
    //     return dp[idx][sum][tight];

    long long ret = 0;

    // calculating range value
    int k = (tight)? digit[idx] : 9;

    F(i,0,k+1)
    {
        // caclulating newTight value for next state
        int newTight = (digit[idx] == i)? tight : 0;
 		int newFirst = first;

        if (i && first<0)
        {
        	newFirst = i;
        }

        // fetching answer from next state
        ret += value(idx-1,newFirst,i, newTight, digit);
    }

    // if (!tight)
    //   dp[idx][sum][tight] = ret;

    return ret;
}

ll rangeValue(ll left, ll right){

	//initialise dp table
	// memset(dp,-1,sizeof(dp));

	vi digitLeft;
	getDigits(left-1, digitLeft);

	ll ans1 = value(digitLeft.size()-1,-1,-1,true,digitLeft);
	if (left<=1)
	{
		ans1 = 0;
	}

	vi digitRight;
	getDigits(right,digitRight);

	ll ans2 = value(digitRight.size()-1, -1,-1 ,true, digitRight);
	if (right<=1)
	{
		ans2 = 0;
	}

	return ans2 - ans1;
}

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

    ll l,r;
    cin>>l>>r;
    cout<<rangeValue(l,r)<<endl;
	return 0;
}


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

int main()
{
int x ,y ,ma , mi ,c=0;
cin>>x >>y >>mi >>ma ;
int b[y];

for(int i=0  ;i<y ;i++)cin>>b[i];

sort(b,b+x);
if(b[0]>mi)c++;
else if(b[0]<mi){cout<<"Incorrect"<<endl; return 0;}
if(b[y-1]<ma)c++;
else if(b[y-1]>ma){cout<<"Incorrect"<<endl; return 0;}

int k=x-y;
if(k>=c)cout<<"Correct"<<endl;
else cout<<"Incorrect"<<endl;

   return 0;
}


#include <iostream>
#include <cstdio>

#include <utility>

#include <cassert>
#include <ctime>
#include <iomanip>

using namespace std;

const int MAXN = 1e5 + 100;

typedef long long ll;
#define tll(x) static_cast<ll>(x)

typedef pair<int, int> pii;
#define mp make_pair
#define ff first
#define ss second

int N, root;

const int MAXS = MAXN * 800;
struct PBT {
public:
  int c[MAXS][2], v[MAXS], sz[MAXS], h[MAXS];
  int NXT;
  PBT() : NXT(1) {v[0] = -1, sz[0] = 0, h[0] = 0;};
  int upd(int n) {
    if(not(0 < n)) return n;
    sz[n] = sz[c[n][0]] + sz[c[n][1]] + 1;
    h[n] = max(h[c[n][0]], h[c[n][1]]) + 1;
    assert(n != c[n][0] and n != c[n][1]);
    return n;
  }
  int gsz(int n) {
    if(n == 0) return 0;
    return gsz(c[n][0]) + gsz(c[n][1]) + 1;
  }
  void asst(int n) {assert(gsz(n) == sz[n]);}
  int nn(const int& n = -1) {
    assert(NXT < MAXS);
    if(n == 0) return 0;
    if(0 < n) {
      for(int i = 0;i < 2;i++) c[NXT][i] = c[n][i];
      v[NXT] = v[n];
    } else {
      for(int i = 0;i < 2;i++) c[NXT][i] = 0;
      v[NXT] = -1;
    }
    upd(NXT);
    return NXT++;
  }
  int nnr(const int& q) {
    int n = nn();
    v[n] = q;
    return n;
  }
  int L(int& n, int p = 0) {
    assert(c[n][1]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][1]); else n = c[n][1];
    c[o][1] = c[n][0];
    upd(c[n][0] = o);
    return upd(n);
  }
  int R(int& n, int p = 0) {
    assert(c[n][0]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][0]); else n = c[n][0];
    c[o][0] = c[n][1];
    upd(c[n][1] = o);
    return upd(n);
  }
  bool bal(int& n, bool p = false) {   //here, we assume that n is already a copy
    int q = NXT;
    int b = h[c[n][0]] - h[c[n][1]], s, o = n;
    if(b < -1) {
      assert(s = c[n][1]);
      if(h[c[s][1]] + 1 == h[s]) {
        L(n, p ? 1 : 0);
      } else if(h[c[s][0]] + 1 == h[s]) {
        R(c[n][1], p ? 2 : 0);
        L(n, 0);
      } else assert(false);
    }
    else if(b > 1) {
      assert(s = c[n][0]);
      if(h[c[s][0]] + 1 == h[s]) {
        R(n, p ? 1 : 0);
      } else if (h[c[s][1]] + 1 == h[s]) {
        L(c[n][0], p ? 2 : 0);
        R(n, 0);
      } else assert(false);
    }
    else return false;
    return true;
  }
  int join(int a, int b, bool p = true) {  //here we assume a and b are already copies
    if(a == 0 or b == 0) return a ? a : b;
    if(h[a] < h[b]) {
      c[b][0] = join(a, p ? nn(c[b][0]) : c[b][0], p);
      upd(b);
      bal(b, p);
      return b;
    } else {
      c[a][1] = join(p ? nn(c[a][1]) : c[a][1], b, p);
      upd(a);
      bal(a, p);
      return a;
    }
  }
  int join2(int l, int m, int r) {    //assume all are copies, merges L and R at M
    if(h[l] + 1 < h[r]) {c[r][0] = join2(l, m, nn(c[r][0])); return upd(r);}
    if(h[r] + 1 < h[l]) {c[l][1] = join2(nn(c[l][1]), m, r); return upd(l);}
    c[m][1] = r;
    c[m][0] = l;
    upd(m);
    bal(m, 1);
    return m;
  }
  pii split(int a, int k) {   //always create new nodes, assume a is NOT a copy
    if(k == 0) return mp(0, nn(a));
    assert(0 < k);
    if(sz[c[a][0]] < k) {
      pii q = split(c[a][1], k - sz[c[a][0]] - 1);
      int r = join2(nn(c[a][0]), nnr(v[a]), q.ff);
      return mp(r, q.ss);
    } else {
      pii q = split(c[a][0], k);
      int r = join2(q.ss, nnr(v[a]), nn(c[a][1]));
      return mp(q.ff, r);
    }
  }
  int get(int l, int r) {   //inclusive - exclusive
    while(not(l < N)) l -= N, r -= N;
    while(l < 0) l += N, r += N;

    if(r > N) return join(get(l, N), get(N, r));
    pii f1 = split(root, r);
    pii f2 = split(f1.ff, l);

    return f2.ss;
  }
  void fill(int n, int * a, int * t = new int(0)) {
    if(n == 0) return;
    fill(c[n][0], a, t);
    a[(*t)++] = v[n];
    fill(c[n][1], a, t);
  }
  void pout(int n = root) {
    if(n == 0) return;
    pout(c[n][0]);
    cerr << v[n] << " ";
    pout(c[n][1]);
    if(n == root) cerr << "\n\n";
  }
} pbt;

int M, S;
ll T;

int to[40][MAXN];

void gen() {
  root = 0;
  for(int i = 0;i < N;i++) root = pbt.join(root, pbt.nnr(i), 0);
  for(int i = 1;i < N;i++) {
    int a = pbt.get(i, i + M);
    int b = pbt.get(M - i, N - i);
    assert(pbt.sz[a] == M and pbt.sz[b] == N - M);
    root = pbt.join(a, b);
    //pbt.pout();
    assert(pbt.sz[root] == N);
  }
  pbt.fill(root, to[0]);
}

void run() {
  for(int i = 1;i < 40;i++) {
    for(int j = 0;j < N;j++) {
      to[i][j] = to[i-1][to[i-1][j]];
    }
  }
}

void brute() {
  int q = static_cast<int>(T%N);
  for(;q;q--,T--) {
    if(S < M) S = (S + q)%N;
    else S = (S - q + N)%N;
  }
  assert(T%N == 0);
}

void solve() {
  scanf("%d%lld", &S, &T);
  --S;
  brute();
  int k = T/N;
  for(int i = 0;1 << i < k;i++) {
    if(k&(1<<i)) S = to[i][S];
  }
  printf("%d\n", S + 1);
}

int main() {
  clock_t timer = clock();
  cerr << setprecision(6);

  scanf("%d%d", &N, &M);
  gen();
  run();
  //for(int i = 0;i < N;i++) printf("%d\n", to[0][i]);
  solve();

  cerr << "Time Elapsed: " << static_cast<double>(clock() - timer)/CLOCKS_PER_SEC << "\n";

  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	string s, samo("aeiouy");
	cin>>n>>s;
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<6;j++)
		{
			if(find(samo.begin(), samo.end(), s[i]) != samo.end())
			{
				while(find(samo.begin(), samo.end(), s[++i]) != samo.end())
				{
					if(s[i-1]>=s[i])
					s.erase(s.begin()+i-1);
					else
					s.erase(s.begin()+i);
					i--;
				}
				i-=2;
			}
		}
	}
	cout<<s;
	return 0;
}