#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cctype>
using namespace std;
int str[101],r[101];
int Find(int a[],int n,int num)//二分查找，查找字母
{
 int l=0,r=n,mid=0;
 while(l<r)
 {
  mid=(l+r)/2;
  if(num==a[mid]) {return mid;}
                           else if(num<a[mid]) {r=mid;}
                                          else if(num>a[mid]) {l=mid+1;}
 }
 return -1;
}
void Gb(int s,int t)//因为二分查找必须有序，所以我打算练练归并
{
 if(s==t) return;
 int mid=(s+t)/2;
 Gb(s,mid);
 Gb(mid+1,t);
 int i=s,j=mid+1,k=s;
 while((i<=mid)&&(j<=t))
  {
   if(str[i]<=str[j])
   {
    r[k]=str[i];k++;i++;
   }
   else
   {
    r[k]=str[j];k++;j++;
   }
  }
 while(i<=mid)
 {
  r[k]=str[i];k++;i++;
 }
 while(j<=t)
 {
  r[k]=str[j];k++;j++;
 }
 for(int i=s;i<=t;i++) str[i]=r[i];
}
int main()
{
 int n;
 char ch;
 cin>>n;
 if(n<26) {printf("NO");exit(0);}
 for(int i=0;i<n;i++) cin>>ch,str[i]=int(toupper(ch));//将字符转换成数字
 Gb(0,n-1);
 /* 以下用来判断，如果有的话，find会传回下标。 */
 /* 但可能传回下标0，所以+1，如果没有，传回-1。 */
 /* ∵-1+1=0，∴大功告成，不喜勿喷。我只是个蒟蒻 */
 if((Find(str,n,int('A'))+1)&&(Find(str,n,int('B'))+1)&&(Find(str,n,int('C'))+1)&&(Find(str,n,int('D'))+1)&&(Find(str,n,int('E'))+1)&&(Find(str,n,int('F'))+1)&&(Find(str,n,int('G'))+1)&&(Find(str,n,int('H'))+1)&&(Find(str,n,int('I'))+1)&&(Find(str,n,int('J'))+1)&&(Find(str,n,int('K'))+1)&&(Find(str,n,int('L'))+1)&&(Find(str,n,int('M'))+1)&&(Find(str,n,int('N'))+1)&&(Find(str,n,int('O'))+1)&&(Find(str,n,int('P'))+1)&&(Find(str,n,int('Q'))+1)&&(Find(str,n,int('R'))+1)&&(Find(str,n,int('S'))+1)&&(Find(str,n,int('T'))+1)&&(Find(str,n,int('U'))+1)&&(Find(str,n,int('V'))+1)&&(Find(str,n,int('W'))+1)&&(Find(str,n,int('X'))+1)&&(Find(str,n,int('Y'))+1)&&(Find(str,n,int('Z'))+1)) cout<<"YES";
                                                                                else cout<<"NO";
 return 0;
}


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

int Sort(int i, int j)
{
    return i < j;
}

int main()
{
    int N, M ,Temp , MinDif = 100000;
    vector<int> IntVec;
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> Temp;
        IntVec.push_back(Temp);
    }

    sort(IntVec.begin(), IntVec.end(), Sort);

    for (int i = 0; i < M - N + 1; i++)
    {
        int Sum = IntVec[i + N-1] - IntVec[i];
        if (Sum < MinDif)
            MinDif = Sum;
    }

    cout << MinDif << "\n";
    return 0;

}


    #include <iostream>
    using namespace std;
    int main(){
        int n,a[50];

        cin>>n;

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

        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                for (int k=0;k<n;k++){
                    if (a[i]==a[j]-1 && a[i]==a[k]-2){
                        cout <<"YES";
                        return 0;
                    }
                }
            }
        }
        cout <<"NO";
        return 0;
    }


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

int main()
{
    long long h,n;
    while(~scanf("%I64d%I64d",&h,&n))
    {
        long long cnt=0;
        n+=(1LL<<h)-1;
        for(long long i=1;i<=h;i++,n/=2)
        {
            long long flag=((n-(1LL<<(h-i+1))+1+1)/2)&1;
            if((n&1)^flag^(i==h)) cnt+=(1LL<<i);
            else cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


#include <iostream>
#include<vector>
using namespace std;
bool isprime(int x)
{
	for (int i = 2; i*i <= x; i++)
	if (x % i == 0)
		return false;
	return true;
}
int main()
{
	int n,j,k, counter = 0, between = 0;
	//int*vis = new int[n];
	//int*primes = new int[n];

	cin >> n >> k;
	vector<int> vis(n);
	vector<int>primes(n);
	for (int i = 0; i < n; i++)
		vis[i] = 0;
	vis[0] = vis[1] = 1;
	for (int i = 2; i <= n / 2; i++) //mark the non-primes with a 1
	{
		if (vis[i]) continue;
		for (int j = i + i; j < n; j += i)
			vis[j] = 1;
	}
	int p = 0;
	for (int i = 0; i < n; i++)
	{
		if (vis[i] == 0)
		{
			primes[p] = i;
			p++;
		}
	}

	//for (int i = 0; i < p; ++i)
	//	cout << primes[i] << endl;
	for (int i = 0; i < p - 1; i++)
	{
		j = primes[i] + primes[i + 1] + 1;
		if (j>2 && j <= n&&isprime(j))
		{
			counter++;
		}
	}
	if (counter >= k)
		cout << "YES";
	else cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

typedef long long ll;

template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (y < x) x = y; };
template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (y > x) x = y; };

void go(vector <int> &a, int v, int vl, int vr, int pos) {
    if (vl == vr) {
        a.pb(v);
        return;
    }

    a.pb(v);
    int vm = (vl + vr) / 2;
    if (pos <= vm)
        go(a, v + v, vl, vm, pos);
    else
        go(a, v + v + 1, vm + 1, vr, pos);

}

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

    int n, a, b;
    cin >> n >> a >> b;
    vector <int> ansa, ansb;
    go(ansa, 1, 0, n - 1, a - 1);
    go(ansb, 1, 0, n - 1, b - 1);

    int i;
    for (i = 0; i < n; ++i) {
        if (ansa[i] != ansb[i]) break;
    }

    if (i == 1)
        cout << "Final!" << endl;
    else
        cout << (int)log2(n) - i + 1 << endl;

    return 0;
}


/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !

*/
#include<bits/stdc++.h>
#define adelkhah main
#define pb push_back
//#define int long long
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
int32_t adelkhah()
{
    int n; cin >> n; int m = n; int ans = n;
    if(n < 10) return cout << 1,0;
    int d = 1; while(n) d *= 10,n/=10; d /= 10;
    m = m/d; cout << (m+1)*d - ans;
}
/**< WRITEN BY ALI ADELKHAH */


#include <iostream>
#include <string>

using namespace std;

__int64 p, d;
__int64 maxx = 0, ans;
__int64 a[30];

int main(){
    //freopen("input.txt", "rt", stdin);
  //  freopen("output.txt", "wt", stdout);
    cin >> p >> d;
    __int64 pp = p, ppp = p;
    //a[0] = (pp % 10 + 1) % 10;
    //pp -= a[0];
    //pp /= 10;
    int i = 1;
    __int64 pow = 10;
    __int64 maxpow = 1;
    while (maxpow < p){
        maxpow *= 10;
    }
    while (p - pp <= d){
        if (pow >= maxpow && pow != 10)
            break;
        __int64 dig = (pp % pow) / (pow / 10);
        __int64 cur = (dig + 1) % 10;
        //a[i] = a[i - 1] + cur * pow;
        //pp -= a[i];
        if (p - (pp - cur * pow / 10) > d){
            cout << pp;
            return 0;
        }
        pp -= cur * pow / 10;
        pow *= 10;
    }
    cout << pp;
}


#include <cstdio>

int main()
{
    char p[101];
    scanf("%s", p);
    int size(0);
    for (size_t i = 0; p[i] != 0; ++i)
    {
        size *= 16;
        switch (p[i])
        {
        case '>':
            size += 8;
            break;

        case '<':
            size += 9;
            break;

        case '+':
            size += 10;
            break;

        case '-':
            size += 11;
            break;

        case '.':
            size += 12;
            break;

        case ',':
            size += 13;
            break;

        case '[':
            size += 14;
            break;

        case ']':
            size += 15;
            break;

        default:
            break;
        }

        size %= 1000003;
    }
    printf("%d\n", size);
    return 0;
}


// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(lld i = 0; i < n; i+=1)
#define fod(i,n) for(lld i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
vector <lld> getfact (lld x)
{
      vector <lld> v;
	while (x%2==0){
            x/=2;
            v.push_back(2);
      }
      for(lld i = 3; i <= sqrt(x); i += 2){
            while (x%i==0){
                  x/=i;
                  v.push_back(i);
            }
      }
      if (x > 2){
            v.push_back(x);
      }
      return v;
}
lld gcd_ (lld a, lld b)
{
	lld max = a > b ? a : b;
	lld min = a < b ? a : b;
	while(min){
		lld rem = max%min;
		max = min;
		min = rem;
	}
	return max;
}
int main ()
{
      #ifndef ONLINE_JUDGE
      freopen("inputf.in",  "r",   stdin);
      freopen("outputf.in", "w",  stdout);
      #endif
      FastIO
      lld a, b;
      cin >> a >> b;
      lld g = gcd_(a, b);
      a/=g;
      b/=g;
      lld f = 1;
      map <lld, lld> count1, count2;
      vector <lld> v = getfact(a);
      vector <lld> w = getfact(b);
      for(lld i = 0; i < v.size(); i+= 1){
      	if (v[i] == 2 || v[i] == 3 || v[i] == 5){
      		count1[v[i]]+=1;
      	}
      	else{
      		f = 0;
      	}
      }
      for(lld i = 0; i < w.size(); i+= 1){
      	if (w[i] == 2 || w[i] == 3 || w[i] == 5){
      		count2[w[i]]+=1;
      	}
      	else{
      		f = 0;
      	}
      }
      if (f == 0){
      	cout << "-1";
      }
      else{
      	lld count = abs(count2[2]-count1[2]) + abs(count2[3]-count1[3]) + abs(count2[5]-count1[5]);
      	cout << count;
      }
      return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n;
  cin>>n;
  if(n%2==0)
     cout<<"Mahmoud";
  else
     cout<<"Ehab";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define dd double
#define ll long long int
#define light ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll recur(ll index,ll moves,ll cnt,string &s,string &t,vector<vector<vector<ll>>>&dp){
    if(index==s.length())
        return 0;
    if(dp[index][moves][cnt]!=-1)
        return dp[index][moves][cnt];
    if(!moves){
        if(s[index]==t[0])
            return dp[index][moves][cnt]=recur(index+1,moves,cnt+1,s,t,dp);
        if(s[index]==t[1])
            return dp[index][moves][cnt]=cnt+recur(index+1,moves,cnt,s,t,dp);
        return dp[index][moves][cnt]=recur(index+1,moves,cnt,s,t,dp);
    }
    if(s[index]==t[0])
        return dp[index][moves][cnt]=max(recur(index+1,moves,cnt+1,s,t,dp),cnt+recur(index+1,moves-1,cnt,s,t,dp));
    if(s[index]==t[1])
        return dp[index][moves][cnt]=max(recur(index+1,moves-1,cnt+1,s,t,dp),cnt+recur(index+1,moves,cnt,s,t,dp));
    return dp[index][moves][cnt]=max({recur(index+1,moves-1,cnt+1,s,t,dp),cnt+recur(index+1,moves-1,cnt,s,t,dp),recur(index+1,moves,cnt,s,t,dp)});
}
int main()
{
    light;
    ll n,k;
    string s,t;
    cin>>n>>k>>s>>t;
    if(t[0]!=t[1]){
        vector<vector<vector<ll>>>dp(n,vector<vector<ll>>(k+1,vector<ll>(n+1,-1)));
        cout<<recur(0,k,0,s,t,dp);
    }
    else{ll ans=k;
        for(ll i=0;i<s.length();i++){
            if(s[i]==t[0])
                ans++;
        }ans=min(n,ans);
        cout<<(ans*(ans-1))/2;
    }
}


#include "bits/stdc++.h"
using namespace std;
int main()
{
	int i;
	string s1,s2;
	cin>>s1;
	cin>>s2;

	int l=s1.length();
	int m=l-1;
	for(i=1;i<l;i++)
	{
			if(s1[i]>=s2[0])
			{
				m=i-1;
				break;
			}
	}
	for(i=0;i<=m;i++)
	 cout<<s1[i];
	cout<<s2[0];

  return 0;
}


/*
Author :: MD. Musfiqur Rahman Sanim
Aust cse 28th Batch
ID:11.02.04.097
*/

//{ Template
using namespace std;
//{ headers
#include<bits/stdc++.h>
//}
//{ Loops
#define forab(i,a,b) for (__typeof(b) i = (a); i <= (b); ++i)
#define rep(i,n) forab (i, 0, (n) - 1)
#define For(i,n) forab (i, 1, n)
#define rofba(i,a,b) for (__typeof(b) i = (b); i >= (a); --i)
#define per(i,n) rofba (i, 0, (n) - 1)
#define rof(i,n) rofba (i, 1, n)
#define forstl(i,s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
//}
//{ Floating-points
#define EPS 1e-7
#define abs(x) (((x) < 0) ? - (x) : (x))
#define zero(x) (abs (x) < EPS)
#define equal(a,b) (zero ((a) - (b)))
#define PI 2*acos (0.0)
//}
typedef long long int64;
typedef unsigned long long int64u;
#define memo(a,v) memset(a,v,sizeof(a))
#define all(a) a.begin(),a.end()
#define db double
#define pb push_back
#define eb emplace_back
#define pii pair<int ,int >
#define NL puts("")
#define ff first
#define ss second
//{
//Intput_Output
#define gc getchar
#define II ({ int a; read(a); a;})
#define IL ({ int64 a; read(a);  a;})
#define ID ({ db a; scanf("%lf",&a);  a;})
#define IC ({ char a; scanf("%c",&a);  a;})
#define IS ({ string a; cin >> a;  a;})
#define OC printf("Case %d:",cs);
//}
//}
#define _stl(x) {__stl_print__(x);}
#define __(args...) {dbg,args; cerr<<endl;}
template<class T>inline bool read(T &x){int c=gc();int sgn=1;while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=gc();}for(x=0;~c&&'0'<=c&&c<='9';c=gc())x=x*10+c-'0';x*=sgn;return ~c;}
struct debugger{template<typename T> debugger& operator , (const T& v){cerr<<v<<"    "; return *this; }}dbg;
template <class T> void __stl_print__ (T &x) { // for all STL containers
    cerr << "["; forstl (i, x) cerr << (i != x.begin () ? ", " : "") << *i; cerr << "]" << endl;
}
template <class T, class U> inline T max (T &a, U &b)
{
    return a > b ? a : b;
}
template <class T, class U> inline T min (T &a, U &b)
{
    return a < b ? a : b;
}
template <class T, class U> inline T swap (T &a, U &b)
{
    T tmp = a;
    a = b;
    b = tmp;
}
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 Direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

const int64 INF = (1ll)<<50;
const int mx = 1e5 + 7;
const int mod = 1000000007 ;
const db pi = PI;
int EQ(double d) {
    if ( fabs(d) < EPS ) return 0;
    return d > EPS ? 1 : -1 ;
}

char ch[12];

int64 call(int64 a,int len){
    int arr[12]= {0},cnt = 0;
    while(a){
        arr[cnt++] = a%2;
        a /= 2;
    }
    int64 num = 0;
    per(i,len){
        if(arr[i]) num = num*10 + 7;
        else num = num*10 + 4;
    }
    return num;
}

int64 bs(int64 len,int64 num){
    int64 low = 0,high = (1ll<<len) - 1;
    int64 ans = -1;
    while(low<=high){
        int64 mid = (low+high)>>1;
        int64 tmp = call(mid,len);
        if(tmp >= num){
            high = mid - 1;
            ans = mid;
        }else low = mid + 1;
    }
    return ans;
}

int main() {
#ifdef Sanim
	//geting WA check int64 & int64u
    freopen ("in.txt", "r", stdin);
    // freopen ("output.txt", "w", stdout);
#endif
    int64 lf = IL,rt = IL;
    sprintf(ch,"%lld",lf);
    int l1 = strlen(ch);
    int64 a = bs(l1,lf);
    if(a == -1) {a = 0; ++l1;}
    sprintf(ch ,"%lld",rt);
    int l2 = strlen(ch);
    int64 b = bs(l2,rt);
    if(b == -1) {b = 0; ++l2;}
    int64 high = call(b,l2);
    int64 num = call(a,l1);

    int64 ans = 0,left = lf,tmp = (1ll<<l1)-1;
    while(num <= high){
        ans += (min(num,rt)-lf+1)*num;
        lf = num+1;
        if(a == tmp){
            a = 0;
            l1++;
            tmp = (1ll<<l1)-1;
        }else a++;
        num = call(a,l1);
    }
    cout << ans << endl;
}


#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <vector>
#include <string>
using namespace std;

//typedef ll long long;
//typedef ld long double;

//const int maxn = 10000;
//bool v[maxn];

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, a, b, c;
	cin >> n >> a >> b >> c;

	int ans = 0;

	long long tmp;
	for (long long i1 = 0; i1 <= a; i1++)
	{
		for (long long i2 = 0; i2 <= b; i2++)
		{
			tmp = i1 + 2 * i2;

			if ((2 * n - tmp) >= 0 && (2 * n - tmp) % 4 == 0 && (2 * n - tmp) / 4 <= c)
				ans++;
		}
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, k, l, c, d, p, nl, np;

	int m[100];

	scanf("%d%d%d%d%d%d%d%d", &n, &k, &l, &c, &d, &p, &nl, &np);

	m[0]=(k*l)/nl;

	m[1]=c*d;

	m[2]=p/np;

	sort(m, m+3);

	printf("%d\n", m[0]/n);

	return 0;

}


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

int main()
{
    string s;
    cin>>s;
    int n=0;
    sort(s.begin(),s.end());
    for(int x=1;x<s.length();x++)
    {
        if(s[x]!=s[x-1])
        {
            n++;
        }
    }
    if((n+1)%2==0)
    {
        cout<<"CHAT WITH HER!"<<endl;
    }
    else{
        cout<<"IGNORE HIM!"<<endl;
    }
    return 0;
}


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

int main()
{
  int n,m,a,b,nn,c1=0,c2=0,c3,c4;
  cin>>n>>m>>a>>b;
  nn=n;
  while(n-m>0)
  {
      c1=c1+b;
      n=n-m;
  }
  if(n>0)
  {
      c3=c1+(n*a);
      c4=c1+b;
      if(c3<c4)
       c1=c3;
      else
       c1=c4;
  }
  c2=nn*a;
  if(c2>c1)
    c1=c1;
  else
    c1=c2;
cout<<c1;
  return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, m, mcopy, maximum, minimum, a[100];
    int i, j;

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

    for (i = n - 1; i > 0; i--)
        for (j = 0; j < i; j++)
        {
            if (a[j] > a[j+1])
            {
                a[j] = a[j] + a[j+1];
                a[j+1] = a[j] - a[j+1];
                a[j] = a[j] - a[j+1];
            }
        }

    maximum = a[n-1];

    for (mcopy = m, i = 0; mcopy > 0 && i < n - 1;)
    {
        if (a[i] < a[n-1])
        {
            a[i]++;
            mcopy--;
        }
        else
            i++;
    }

    if (mcopy != 0)
    {
        if (mcopy % n == 0)
            cout << maximum + mcopy / n << ' ';
        else
            cout << maximum + 1 + mcopy / n << ' ';
    }
    else
    {
        minimum = a[0];
        for (i = 1; i < n; i++)
            if (a[i] > minimum)
                minimum = a[i];
        cout << minimum << ' ';
    }

    cout << maximum + m;

    return 0;
}


#include<bits/stdc++.h>
//#define REP(1,n) for(int i=1;i<=n;i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
//#define lli long long int
#define inf 1000000000

using namespace std;

int main()
{
	int n,i;
	cin>>n;
	int A[n];
	vector<int>v;
	for(int i=0;i<n;i++)
	{
		cin>>A[i];
		if(i!=0)
		{
			v.push_back(A[i]-A[i-1]);
		}
	}
	int m=*max_element(v.begin(),v.end());
	int a=INT_MAX;
	for(int i=1;i<n-1;i++)
	{
		a=max(m,min(a,v[i]+v[i-1]));

	}
	cout<<a;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>

using namespace std;

#define s(n)					scanf("%d",&n)
#define sf(n) 					scanf("%lf",&n)
#define ss(n) 					scanf("%s",n)
#define maX(a,b)				((a)>(b)?(a):(b))
#define miN(a,b)				((a)<(b)?(a):(b))
#define abS(x)					((x)<0?-(x):(x))
#define pb						push_back
#define mp	 					make_pair
#define EPS						1e-9
#define fill(a,v) 				memset(a, v, sizeof(a))
#define SZ(v)					((int)(v.size()))
#define all(x)					x.begin(), x.end()
#define foreach(v,c)            for( typeof((c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define INDEX(arr,ind)			(lower_bound(all(arr),ind)-arr.begin())
#define FF						first
#define SS						second
#define T(t)           			int t;scanf ("%d",&t);while (t--)
#define INF						(int)1e9
#define LINF					(long long)1e18
#define FOR(i,a,b)				for(int i=a;i<b;i++)
#define REP(i,n)				FOR(i,1,n)
#define debug(args...)			{dbg,args; cerr<<endl;}

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr<<v<<" ";
		return *this;
	}
} dbg;

void debugarr(int * arr,int n)
{
	cout<<"[";
	for(int i=0;i<n;i++)
		cout<<arr[i]<<" ";
	cout<<"]"<<endl;
}

void debugvec(vector <int> arr)
{
	cout<<"[";
	for(int i=0;i<SZ(arr);i++)
		cout<<arr[i]<<" ";
	cout<<"]"<<endl;
}

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long LL;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<pair<int,int> > VPII;
typedef pair<double,double> PDD;

int main()
{
	int r1,r2,c1,c2,d1,d2;
	cin >> r1 >> r2 >>c1 >>c2 >> d1 >> d2;
	bool found  = false;
	REP(i,10)
	{
		REP(j,10)
		{
			REP(k,10)
			{
				REP(l,10)
				{
					if(i==j||i==k||i==l||j==k||j==l||k==l) continue;
					if(i+j==r1&&k+l==r2&&i+k==c1&&j+l==c2&&i+l==d1&&j+k==d2)
					{
						cout << i << " " << j << endl <<k << " " << l <<endl;
						return 0;
					}
				}
			}
		}
	}
	cout << "-1" <<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
 int k , n , w;
 cin >> k >> n >> w;
 long long sum = 0 ;
 for (int i = 1; i <= w; i++)
 {
     sum += i * k;
 }
 cout << max(0LL,sum - n) << endl;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<map>
#include<string>
#include<cstdio>
#include<cstdlib>
using namespace std;
unsigned long long int n,k,a[111111],ans,j = 2;
int main()
{
	cin >> n >> k;
	/*if(n/2 <= k)
	{
		double x = (n-1)/2;
		cout << x*n;
		return 0;
	}*/
	for(int i = 1; i <= n; i++)
	{
		a[i] = i;
	}
	for(int i = 1 ; i <= k; i++)
	{
		if(i < n+1-i)
		{
			swap(a[i],a[n+1-i]);
		}
		else
		{
			break;
		}
	}
	int x = 0;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] > a[i+1])
		{
			ans += n-i;
			x++;
		}
		else
		{
			ans += x;
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <memory.h>
#include <vector>
#include <queue>
#include <stack>

#define INF 1e+7
#define ll long long

int check(char b[]){
    if(!strcmp(b,"ABC") || !strcmp(b,"ACB") || !strcmp(b,"BAC") || !strcmp(b,"BCA")
        || !strcmp(b,"CAB") || !strcmp(b,"CBA"))
            return 1;
    return 0;
}

int main(){
    char a[205],b[5],c[205],x = 0;
    gets(a);
    int i = 0;

    if(strlen(a) <= 3){
        if(check(a))//ԭ�����������
            printf("Yes");
        else{
            printf("No");
        }
    }else{
        i = 0;
        while(a[i+2] != '\0'){
            if(a[i] != '.'){
                b[0] = a[i],b[1] = a[i+1],b[2] = a[i+2],b[3] = '\0';
                if(check(b)){
                    printf("Yes");
                    x = -1;
                    break;
                }
            }
            i++;
        }
        if(x != -1){
            printf("No");
        }
    }

    return 0;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 11
#define MOD 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi 3.14159265358979323846

int main(){

    fast;

    ll i,n;
    cin >> n;
    ll n1 = n;

    ll tmp = 1;
    ll ans = 0;
    for(i=2;i*i<=n1;i++){
        while((n1%i)==0){
            tmp = n1/i;
            ans = ans + tmp;
            n1 = n1/i;
        }
    }

    if(n1>1){
        ans++;
    }

    ans = ans + n;

    cout << ans << endl;
}

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


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

int main()
{
    int x, y, z,p =0, m =0, u =0, up =0, down =0;
    cin >> x >> y >> z;

    up = x + z;
    down = y + z;
    for (int i=0; i < 3; i++)
    {
        if (up == down)
        {
            p++;
            m++;
        }
        if (up > down)
        {
            p++;
        }
        if (down > up)
        {
            m++;
        }
    }
    if (z == 0 && p == m)
    {
        cout << "0\n";
    }

    else if ((up > y && down > x) || (down == x || up == y))
    {
        cout << "?\n";
    }
    else if (p > m)
    {
        cout << "+\n";
    }
    else if (p < m)
    {
        cout << "-\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    string binary{};
    cin >> binary;
    int bin = binary.size()/2, size = binary.size(), i{};
    if((size-1)%2==0){
        for(i=1; i<size; i++){
            if(binary[i] == '1'){
                bin++;
                break;
            }
        }
    }   cout<<bin;
    return 0;
}//@luisrdev


//#Rohitpratap311
//#Keep Calm And Stay Happy

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solveCP311()
{
    ll n;
    cin>>n;
    string str;
    cin>>str;
    char arr1[n],arr2[n];
    ll j=0;
    for(ll i=0;i<n;i++)
    {
        arr1[i]=str[j];
        j++;
    }
    for(ll i=0;i<n;i++)
    {
        arr2[i]=str[j];
        j++;
    }
    sort(arr1,arr1+n);
    sort(arr2,arr2+n);
    bool flag1=true;
    for(ll i=0;i<n;i++)
    {
        //cout<<arr1[i]<<" "<<arr2[i]<<endl;
        if(arr2[i]<=arr1[i])
        {
            flag1=false;
            break;
        }
    }
    bool flag2=true;
    for(ll i=0;i<n;i++)
    {
        //cout<<arr1[i]<<" "<<arr2[i]<<endl;
        if(arr2[i]>=arr1[i])
        {
            flag2=false;
            break;
        }
    }
    if(flag1||flag2) { cout<<"YES"; } else { cout<<"NO"; }
}

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

    ll t=1;
    //cin>>t;
    while(t--)
    {
    	solveCP311();
    }
    //cout<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" sec"<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DEBUG_ON 0

#define INF 0x3f3f3f3f
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)
#define R(x) scanf(" %d",&x)
#define RR(x,y) scanf(" %d %d",&x,&y)
#define DBG(x) if(DEBUG_ON) cout << #x << " == " << x << endl

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

#define MAXN 10010
#define MAXL 35

double pd[MAXL][MAXN][6][6];
bool vis[MAXL][MAXN][6][6];
int l[MAXN], r[MAXN];
double p[MAXN];

// probabilidade de equal iguais a need e o resto menor
double solve(int mask, int need, int equal, int ind) {
  if (equal < 0) return 0.0;

  if (mask == 0) {
    if (equal == 0) return 1.0;
    else return 0.0;
  }

  double &ans = pd[mask][need][equal][ind];
  if (vis[mask][need][equal][ind]) return ans;
  vis[mask][need][equal][ind] = true;

  if (mask & (1 << ind)) {
    if (r[ind] < need) {
      return ans = solve(mask ^ (1 << ind), need, equal, ind);
    } else {
      double pe = 1.0/double(r[ind] - l[ind] + 1);
      double pl = double(need - l[ind])/double(r[ind] - l[ind] + 1);
      return ans = pe*solve(mask ^ (1 << ind), need, equal - 1, ind+1) + pl*solve(mask ^ (1 << ind), need, equal, ind+1);
    }
  } else {
    return ans = solve(mask, need, equal, ind+1);
  }
}

int main() {
  int n; R(n);
  REP(i,n) scanf(" %d %d", &l[i], &r[i]);
  memset(vis,0,sizeof(vis));

  int all = (1 << n) - 1;
  REP(i,n) {
    for (int j = 1; j <= r[i]; j++) {
      if (r[i] < j) continue;

      bool ok = true;
      REP(k, 5) {
        if (k == i) continue;
        if (l[k] > j) ok = false;
      }
      if (!ok) continue;
      double ans = 0;
      for (int win = 1; win < n; win++) {
        if (l[i] > j) {
          ans += solve(all ^ (1 << i), j, win, 0);
        } else {
          double x = solve(all ^ (1 << i), j, win, 0);
          double pe = 1.0/double(r[i] - l[i] + 1);
          double pg = double(r[i] - (j+1) +1)/double(r[i] - l[i] + 1);
          ans += pe*x/double(win + 1.0) + pg*x;
        }
      }
      p[j] += ans;
    }
  }

  double ans = 0;
  for (int i = 1; i <= 10000; i++) {
    ans += double(i)*p[i];
  }
  printf("%.10lf\n",ans);
  return 0;
}


#include <bits/stdc++.h>
#define r_0 return 0;
#define ll long long
#define ld  long double
#define pb push_back
#define fr first
#define se second
#define in freopen("input.txt","r",stdin);
#define out freopen("output.txt","w", stdout);
#define TIME ios_base::sync_with_stdio(NULL);
#define tcn cin.tie(NULL);
#define tct cout.tie(NULL);
using namespace std;

const ll N = 1e7 + 7;
ll n,m,a,k,cnt,mx,b;
string s;
int main()
{
cin >> n >> m;
cnt=min(n-m,m-1);
cout<<3*n+cnt;
}


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

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

const int N = 300010;
const int MOD = 998244353;

int a1, a2;

int main() {
    cin >> a1 >> a2;
    int ans = 0;
    while (a1 > 0 && a2 > 0) {
        if (a1 > a2) swap(a1, a2);
        a1++;
        a2 -= 2;
        if (a2 >= 0) ans++;
    }
    cout << ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ppb pop_back
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;

char a[10][10];
bool m[10][10][101];

int main() {
    for(int i = 0; i < 8; i++)
        gets(a[i]);
    queue<pair<pii, int> > Q;
    Q.push(mp(mp(7, 0), 0));
    m[7][0][0] = 1;
    while(!Q.empty()) {
        int x = Q.front().X.X;
        int y = Q.front().X.Y;
        int t = Q.front().Y;
        Q.pop();
        if(!x && y == 7) {
            puts("WIN");
            return 0;
        }
        if(t >= 100) continue;
        for(int dx = -1; dx <= 1; dx++)
            for(int dy = -1; dy <= 1; dy++) {
                int xx = x+dx;
                int yy = y+dy;
                if(xx < 0 || xx > 7 || yy < 0 || yy > 7) continue;
                if(xx - t >= 0 && a[xx-t][yy] == 'S') continue;
                if(xx - t - 1 >= 0 && a[xx-t-1][yy] == 'S') continue;
                if(m[xx][yy][t+1]) continue;
                m[xx][yy][t+1] = 1;
                Q.push(mp(mp(xx, yy), t+1));
            }
    }
    puts("LOSE");
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int n;
int main()
{
	cin>>n;
	for(int i=1;i*(i+1)/2<=n;i++)
	{
		if(i*(i+1)/2==n)
		{
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


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

string s;
int n;
int change;int res=0;
int moved=0;
int dp[101][55][202]; //makes sure this state is visited

void go(int pos, int change, int moved)
{
    //Base Case
    if(pos == n)
    {
        res = max(res, abs(moved) - (change&1));
        return;
    }

    if(dp[pos][change][moved])
        return;

    dp[pos][change][moved] = 1;
    if(s[pos] == 'F')
    {
        go(pos+1, change, moved+1);
        if(change)
        {
            go(pos+1, change-1, -moved);
        }
    }
    else
    {
        go(pos+1, change, -moved);
        if(change)
        {
            go(pos+1, change-1, moved+1);
        }
    }
}

void solve()
{
    memset(dp, 0, sizeof dp);
    cin>>s;
    n = (int)s.size();
    cin>>change;
    go(0, change, 0);
    cout<<res<<endl;

}

signed main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
const int INF_int=100000000;
const ll INF_ll=1000000000000000;
#define pb push_back
#define FILE "nenokku_easy"
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m,k;
	cin >> n >> m>>k;
	/*if(k==n*m)
    {
        cout << k;
        return 0;
    }
    if(n==1 || m==1)
    {
        cout << k;
        return 0;
    }*/
	ll l=1,r=m*n;
	int e=0;
	ll ans=0;
	while(r>=l)
    {
        ll mid=(l+r)/2;
        ll x=0;
        ll d=0;
        for(ll i=1;i<=n;i++)
        {

            if(mid%i==0)
            {
                if(mid/i>m)
                {
                    x+=m;
                }
                else
                {
                    x+=mid/i-1;
                    d++;
                }

            }
            else
            {
                x+=min(mid/i,m);
               // if(mid==8)
              //  cout << min(mid/i,m)<< " ";
            }

           /* if(mid==8)
            cout << mid<<": " << i << " "<< x << " "<< d <<endl;*/

        }
       // cout << mid << " "<< x<<" "<<d<<" ";
        if(x<k)
        {
            ans=mid;
            l=mid+1;

        }
        else
        {
            r=mid-1;
        }
      //  cout << r << " "<< l <<endl;
        /*e++;
        if(e==5)
            break;*/
        /*if(l==r)
            break;*/

    }
    cout << ans;

}


#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define fi first
#define se second
#define prout(x) cout.precision(x)
using namespace std;
int a[5];
int g[303][303];
int cal(int x, int y){
    int &ret=g[x][y];
    if(g[x][y]!=-1)return g[x][y];
    ret=0;
    for(int i=1;i<=min(x, y);i++)ret|= !cal(x-i, y-i);
    for(int i=1;i<=x;i++)ret|=!cal(x-i, y);
    for(int i=1;i<=y;i++)ret|=!cal(x, y-i);
    return ret;
}
int main(){
    int n;
    /*
    memset(g,-1,sizeof g);
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            for(int k=0;k<=100;k++){
                int x=cal(i, j, k);
                int z=(i^j);
                z^=k;
                if(x==0)cout<<i<<" "<<j<<" "<<k<<" "<<z<<endl;
                if(z==0 && x>0)cout<<"dssdf\n";
            }
        }
    }
    return 0;
    */
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    if(n==1){
        if(a[0]>0)cout<<"BitLGM"<<endl;
        else cout<<"BitAryo"<<endl;
        return 0;
    }
    if(n==2){
        memset(g,-1,sizeof g);
        if(cal(a[0], a[1])==0)cout<<"BitAryo"<<endl;
        else cout<<"BitLGM"<<endl;
        return 0;
    }
    int x=(a[0]^a[1]);
    x^=a[2];
    if(x==0)cout<<"BitAryo"<<endl;
    else cout<<"BitLGM"<<endl;
}


#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
#define eps 0.0001
int x,y,xc,yc,r;
double dist;
int step;

int main()
{
    scanf("%d%d%d%d%d",&r,&x,&y,&xc,&yc);

    dist=sqrt((long double)((long long)xc-x)*(xc-x)+((long long)yc-y)*(yc-y));

    step=dist/(r<<1);

    if(step*(r<<1)<dist)step++;

    printf("%d",step);

    return 0;
}


// LUOGU_RID: 94451081
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int i,j,n,m,k,l,o,p,mo;
inline int read()
{
	int f(1),x(0);
	char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f*=-1;ch=getchar();}
	while (isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}
int f[205][205][205];
bool vis[205][205][205];
int ny[205],jc;
int dfs(int num,int sum,int now)
{
	int rt(0);
	if (vis[num][sum][now]) return f[num][sum][now];
	vis[num][sum][now]=1;
	if (now<=i-1&&num<now) return 0;
	if (now==i) {if (num==n) return 0; else return f[num][sum][now]=ny[n-num];}
	for (int x=0;x+num<=n&&(i-now)*x+sum<=n+1-i;x++)
	{
		rt=(rt+dfs(num+x,sum+(i-now)*x,now+1)*1ll*ny[x]%mo)%mo;
	}
	return f[num][sum][now]=rt;
}
inline LL ksm(LL w,int cs)
{
	LL v(1);
	while (cs)
	{
		if (cs&1) v=v*w%mo;
		w=w*w%mo,cs>>=1;
	}
	return v;
}
int main()
{
	n=read(),mo=read();
	int ans(0);
	for (i=1,ny[0]=1;i<=n;i++) ny[i]=ny[i-1]*1ll*i%mo;
	for (i=1,jc=ny[n];i<=n;i++) ny[i]=ksm(ny[i],mo-2);
	for (i=0;i<=min(32,n);i++)
	{
		memset(vis,0,sizeof vis);
		ans=(ans+dfs(0,0,0))%mo;
	}
	printf("%d",1ll*ans*jc%mo);
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <complex>
#include <numeric>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <deque>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(a)      (a).begin(),(a).end()
#define sqr(x)      ((x) * (x))
#define sz(a)       int((a).size())
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define REP(i,n)    FOR(i,0,n)
#define UN(v)       sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a)       memset(a,0,sizeof a)
#define pb          push_back
#define X           first
#define Y           second
#define MP(a,b) make_pair(a, b)
#define Fopen(file) freopen(file, "r", stdin)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
#define eps 1e-8

const int maxn = 105;

int main()
{
    int yy1,yy2, mm1,mm2, dd1,dd2;
    scanf("%d:%d:%d", &yy1, &mm1, &dd1);
    scanf("%d:%d:%d", &yy2, &mm2, &dd2);

    int ans1 = 0;
    for(int i = 1900; i < yy1; ++i)
    {
        if(!(i % 4) &&( (i % 100) || !(i % 400) ))
            ans1 += 366;
        else
            ans1 += 365;
    }
    for(int i = 1; i < mm1; ++i)
    {
        if(i == 2)
        {
            if(!(yy1 % 4) &&( (yy1 % 100) || !(yy1 % 400) ))
               ans1 += 29;
            else
                ans1 += 28;
        }else if(i == 4 || i == 6 || i == 9 || i == 11)
            ans1 += 30;
        else
            ans1 += 31;
    }
    ans1 += dd1;

    int ans2 = 0;
    for(int i = 1900; i < yy2; ++i)
    {
        if(!(i % 4) &&( (i % 100) || !(i % 400) ))
            ans2 += 366;
        else
            ans2 += 365;
    }
    for(int i = 1; i < mm2; ++i)
    {
        if(i == 2)
        {
            if(!(yy2 % 4) &&( (yy2 % 100) || !(yy2 % 400) ))
               ans2 += 29;
            else
                ans2 += 28;
        }else if(i == 4 || i == 6 || i == 9 || i == 11)
            ans2 += 30;
        else
            ans2 += 31;
    }
    ans2 += dd2;

    cout << abs(ans1 - ans2);
    return 0;
}


#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:16777216")
#include <bits/stdc++.h>

using namespace std;
using matrix = vector<vector<long long>>;

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

#define all(x) (x).begin(), (x).end()
//#define int ll

void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifdef _offline
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // _offline
}

const int MAXN = 220;
const ll mod = 1e9 + 7;
ll dp[MAXN][MAXN], dp2[MAXN][MAXN];
int z[MAXN];
int n;
string s;

ll solve(int pos) {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i <= 2 * n; ++i) {
        for (int j = 0; j <= i; ++j) {
            if (pos <= i && pos + s.length() - 1 >= i) {
                if (s[i - pos] == '(') {
                    dp[i][j] = (dp[i][j] + (j ? dp[i - 1][j - 1] : 0)) % mod;
                }
                else {
                    dp[i][j] = (dp[i][j] + dp[i - 1][j + 1]) % mod;
                }
                if (pos + s.length() - 1 > i && z[s.length() - (i - pos) - 1] == i - pos + 1) {
                    dp[i][j] = (dp[i][j] - dp2[i][j] + mod) % mod;
                }
                if (pos + s.length() - 1 == i) {
                    dp2[i][j] = dp[i][j];
                }
            }
            else {
                dp[i][j] = (dp[i][j] + (j ? dp[i - 1][j - 1] : 0)) % mod;
                dp[i][j] = (dp[i][j] + dp[i - 1][j + 1]) % mod;
                if (pos + s.length() - 1 > i) {
                    dp[i][j] = (dp[i][j] - dp2[i][j] + mod) % mod;
                }
            }
        }
    }
    return dp[2 * n][0];
}

signed main() {
    FAST_IO();
    cin >> n >> s;
    if (s.length() > 2 * n) {
        cout << 0;
        return 0;
    }
    int l = 0, r = 0;
    z[0] = 0;
    for (int i = 1; i < s.length(); ++i) {
        z[i] = max(0, min(z[i - l], r - i));
        while (s[z[i]] == s[i + z[i]]) {
            z[i]++;
        }
        if (i + z[i] > r) {
            l = i;
            r = i + z[i];
        }
    }
    ll ans = 0;
    for (int pos = 1; pos <= 2 * n - s.length() + 1; ++pos) {
        ans = (ans + solve(pos)) % mod;
    }
    cout << ans;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <map>
#include <set>
using namespace std;

int main()
{
    int n;
    long long mod=1000000007;
    cin>>n;
    long long p=3, pow=3;
    if (n==1) {
        cout<<0<<endl;
        return 0;
    }
    for (int i=2; i<n; ++i) {
        pow=pow*3;
        if (pow>=mod) pow%=mod;
        p=pow-p;
        if (p<0) p=(p+mod)%mod;
    }
    cout<<p;

}


#include <bits/stdc++.h>

using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;
	char steps[n];
	cin >> steps;
	int LR = 0, UD = 0;
	for(int i = 0; i < n; i++)
	{
		switch( steps[i]) {
			case 'L':
				LR--;
				break;
			case 'U':
				UD++;
				break;
			case 'D':
				UD--;
				break;
			case 'R':
				LR++;
				break;
		}
	}
	cout << n -abs(LR) -abs( UD);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <sstream>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <stack>
#include <fstream>
#include <cassert>
#ifdef HOME_PC
#include <ctime>
#endif
using namespace std;

#pragma comment(linker,"/stack:16000000")
#pragma warning (disable : 4996)

#define ALL(v) v.begin(),v.end()
#define SZ(v) (int)v.size()
#define mset(A,x) memset((A),(x),sizeof(A))
#define FOR(i,start,N) for(int i=(start);i<(N);++i)
#define FORSZ(i,start,v) FOR(i,start,SZ(v))
#define REPSZ(i,v) FORSZ(i,0,v)
#define FORE(i,start,N) FOR(i,start,N+1)
#define make_unique(v) v.resize(unique(ALL(v))-v.begin())
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define adebug(A,N) FOR(i,0,N) cout<<#A<<"["<<i<<"] = "<<A[i]<<endl;
#define adebug2d(a,n,m) FOR(i,0,n) { FOR(j,0,m) { cout<<a[i][j]<<" ";} cout<<endl;}
#define vdebug(v) REPSZ(i,v) cout<<#v<<"["<<i<<"] = "<<v[i]<<endl;
#define selfx(x,f,a) x = f(x,a)
#define sqr(x) ((x)*(x))

typedef pair<int,int> pii;
typedef long long i64;
typedef vector<int> VI; typedef vector< vector<int> > VVI;
typedef vector<string> VS;

const int inf = 1<<25;
const double eps = 1e-9;

struct Matrix
{
    static const int mod = 1000000007;
    static const int N = 8;

    int a[N][N];

    Matrix() { mset(a,0); }
    Matrix& I()
    {
        mset(a,0);
        FOR(i,0,N) a[i][i] = 1;
        return *this;
    }

    Matrix operator+(const Matrix& A) const
    {
        Matrix ret;
        FOR(i,0,N)
            FOR(j,0,N)
                ret(i,j) = (a[i][j] + A(i,j))%mod;
        return ret;
    }

    Matrix operator*(const Matrix& A) const
    {
        Matrix ret;

        FOR(k,0,N) FOR(i,0,N) FOR(j,0,N)
            ret(i,j) = (ret(i,j) + (i64)(a[i][k])*A(k,j)) % mod;
        return ret;
    }

    Matrix operator^(int n) const
    {
        Matrix ret;
        ret.I();
        Matrix A(*this);
        while(n)
        {
            if(n&1)
                ret = ret*A;
            A = A*A;
            n >>= 1;
        }
        return ret;
    }

    int sum() const
    {
        int ret = 0;
        FOR(i,0,N)
            FOR(j,0,N)
                ret = (ret+a[i][j]) % mod;
        return ret;
    }

    int& operator()(int i,int j)
    {
        return a[i][j];
    }

    const int& operator()(int i,int j) const
    {
        return a[i][j];
    }

};

Matrix calcGeom(const Matrix& A,int n)
{
    Matrix ret;
    if(n == 0)
        return ret.I();
    if(n%2 == 0)
        ret = A^n, n--;

    int mid = (n+1)/2;
    return ret +  (Matrix().I() + (A^mid))*calcGeom(A,mid-1);

}

int g(const Matrix& A,int L,int R)
{

    int ret = 0;
    if(L<1)
        throw 0;
    if(L<2)
        ++L, ret = 4;
    if(L > R)
        return ret;
    L-=2, R-=2;

    Matrix X = (A^L)*calcGeom(A,R-L);
    return (ret + X.sum())%Matrix::mod;
}

i64 fastPow(i64 a,i64 n,i64 mod)
{
    i64 ret = 1;
    while(n>0)
    {
        if(n&1)
            ret*=a, ret%=mod;
        a*=a, a%=mod;
        n>>=1;
    }
    return ret%mod;
}

int f(const Matrix& A,int L,int R)
{
    if(L == 1 && R == 1)
        return 4;

    int ans = 0;
    if(L == 1)
        ++L, ans = 4;

    int all = g(A,L,R);
    if(L%2 == 0) ++L;
    if(R%2 == 0) --R;
    int pals = L<=R ? g(A,(L+1)/2,(R+1)/2):0;
    ans += ((i64)all+pals)%Matrix::mod * fastPow(2,Matrix::mod-2,Matrix::mod) % Matrix::mod;
    ans += Matrix::mod;
    ans %= Matrix::mod;
    return ans;
}

enum COLOR{WHITE,BLACK,RED,YELLOW};

bool allowed[4][4];

int main()
{
#ifdef HOME_PC
    //freopen ("input.txt","r",stdin);
    //freopen ("in.txt","r",stdin);
    //freopen ("output.txt","w",stdout);
#endif

    int L,R;
    cin>>L>>R;

    Matrix A;

//  cout<<f(A,1,1000000000)<<endl;

    mset(allowed,true);
    FOR(i,0,4)
        allowed[i][i] = false;
    allowed[WHITE][YELLOW] = allowed[YELLOW][WHITE] = false;
    allowed[RED][BLACK] = allowed[BLACK][RED] = false;

    int row = -1;
    FOR(a,0,4)
        FOR(b,0,4)
            if(allowed[a][b])
            {
                ++row;
                int col = -1;
                FOR(c,0,4)
                    FOR(d,0,4)
                        if(allowed[c][d])
                        {
                            ++col;
                            if(d!=a)
                                continue;
                            if(d == WHITE && (c == BLACK && b == RED || c == RED && b == BLACK ))
                                continue;
                            A(row,col) = 1;
                        }

            }

    /*Matrix B;
    B.I();
    FOR(i,0,100)
    {
        B = B*A;
        cout<<B.sum()<< " "<<(A^(i+1)).sum() <<endl;
    }*/

    int z = 0;
    //cout<<g(A,L,R)<<endl;
    cout<<f(A,L,R)<<endl;

    /*int dp[100];
    FOR(i,1,100)
        dp[i] = f(A,i,i);
    FOR(i,1,100)
        FOR(j,i,100)
    {
        int sum = 0;
        FORE(k,i,j)
            sum = (sum + dp[k])%Matrix::mod;
        assert(sum == f(A,i,j));
    }*/

#ifdef HOME_PC
    cerr<<endl<<"Execution time = "<<clock()<<" ms"<<endl;
#endif
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define MAX (ll)1000000
#define mp make_pair

using namespace std;

int a,b,c,d;
bool f[10000000],s[10000000];

int main()
{
    cin>>a>>b>>c>>d;
    for(int i=0;i<=10000;i++)
    {
        f[b+i*a]=true;
        s[d+i*c]=true;
    }
    for(int i=0;i<10000000;i++){
        if(f[i]==true && s[i]==true) {cout<<i;
    return 0;;}
}
cout<<-1;
    return 0;
}


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

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define all(x)  x.begin(),x.end()
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
/*
think fast
think simple
*/
int n, k;
bool check(int now)
{
	int lines = 0;
	while (now)
	{
		lines += now;
		now /= k;
	}
	return lines >= n;
}
void mysol()
{
	cin >> n >> k;
	int l = 0;
	int r = 1e9 + 9;
	while (l < r)
	{
		int mid = (l + r) >> 1;
		if (check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << l << endl;
}

int32_t main()
{
	fast();
	// w(t)
	{
		mysol();
	}
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<iterator>
#include <cstdio>
#include <vector>
#include <string>
#include <regex>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include<utility>
#include<random>
#include<bitset>
#include<list>
#include<functional>
using namespace std;
template<class T, typename A = allocator<T>>
class Vector : public vector<T, A>
{
public:
	using vector<T, A>::vector;
	Vector& operator()(size_t dummy_n) // additional init_val needs its own specification for Vector<string>
	{
		return *this;
	}
};
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef Vector<int> vi; // Vector
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pdd> vpdd;
typedef vector<string> vs;
typedef set<int> si;
typedef multiset<int> Si;
typedef map<int, int> mi;
typedef multimap<int, int> Mi;
template <typename Int = int>
Int read()
{
	Int flag = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == '-') flag = -1, c = getchar();
	Int init = c & 15;
	while ((c = getchar()) >= '0' && c <= '9') init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}
void read(char& a) { do scanf("%c", &a); while (isspace(a)); }
void write(const char& a) { printf("%c", a); }
char BUF[1234560];
void read(string& a) { scanf("%s", BUF); a = string(BUF); }
void write(const string& a) { printf("%s", a.c_str()); }
inline void read(int& a) { /*scanf("%d", &a);*/a = read(); }
void write(const int& a) { printf("%d", a); }
//void write(const size_t& a) { printf("%u", a); }
void read(ll& a) { scanf("%I64d", &a); }
void write(const ll& a) { printf("%I64d", a); }
void read(double& a) { scanf("%lf", &a); }
void write(const double& a) { printf("%lf", a); }
void read(ld& a) { scanf("%Lf", &a); }
void write(const ld& a) { printf("%Lf", a); }
void read(pair<int, int>& a) { scanf("%d%d", &a.first, &a.second); }
void write(const pair<int, int>& a) { printf("%d %d", a.first, a.second); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void read(C<T>& a) { for (auto i = a.begin(); i != a.end(); ++i) read(*i); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void write(const C<T>& a) { int sz = a.size(); if (sz != 0) write(a[0]); for (int i = 1; i < sz; ++i) { write(' '); write(a[i]); } }
template<typename T1, typename T2>
void read(T1& t1, T2& t2) { read(t1); read(t2); }
template<typename T1, typename T2>
void write(const T1& t1, const T2& t2) { write(t1); write(' '); write(t2); }
template<typename T1, typename T2, typename T3>
void read(T1& t1, T2& t2, T3& t3) { read(t1); read(t2); read(t3); }
template<typename T1, typename T2, typename T3, typename T4>
void read(T1& t1, T2& t2, T3& t3, T4& t4) { read(t1); read(t2); read(t3); read(t4); }
template<typename T1, typename T2, typename T3>
void write(const T1& t1, const T2& t2, const T3& t3) { write(t1); write(' '); write(t2); write(' '); write(t3); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void sort(C<T>& a) { sort(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template<template<typename T, typename A = allocator<T> > class C, class T>
void rsort(C<T>& a) { sort(a.rbegin(), a.rend()); }
void rsort(string& a) { sort(a.rbegin(), a.rend()); }
template<typename T>
int sz(const T& a) { return int(a.size()); }
#define MX 1000000000
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define T(n) for(int _VARIABLE{(n) + 1}; --_VARIABLE;)
#define F(b,e,i) for(auto i = (b); i != (e); (b) < decltype(b)(e) ? ++i : --i)
#define G(f,l,i) for(auto i = (f) + ((f) < decltype(f)(l) ? -1 : 1); ((f) < decltype(f)(l) ? i++ : i--) != (l) ;)
#define M(f,l,i,j) for(auto i = (f) , j = decltype(f)(l) ; i < j; ++i, --j)
#define r(...) read(__VA_ARGS__)
#define R(type, ...) type __VA_ARGS__; r(__VA_ARGS__)
#define w(...) write(__VA_ARGS__)
#define W(...) write(__VA_ARGS__), write('\n')
#define bgn begin()
#define rbgn rbegin()
#define nd end()
#define rnd rend()
#define pb push_back
#define fnt front()
#define bck back()
#define x first
#define y second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	R(int, t);
	T(t) {
		R(int, n, k, d);
		R(vi, a(n));
		vi st(k + 1);
		int st_sz{}, i{}, mn_sz{ d };
		for (; i < d; ++i)
			if (st[a[i]]++ == 0)
				++st_sz;
		for (--i;;) {
			if (st_sz < mn_sz)
				mn_sz = st_sz;
			if (++i >= n)
				break;
			if (!--st[a[i - d]])// erase from set
				--st_sz;// update set size
			if (!st[a[i]]++)// insert into set
				++st_sz;// update set size;
		}
		W(mn_sz);
	}
}
//
// ArtemParkhomets
//


// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

	long long n;
	cin >> n;

	auto is_prime = [](long long x) -> bool {
		if(x <= 1) return false;
		for(long long i = 2; i * i <= x; i++) if(x % i == 0) return false;
		return true;
	};

	if(is_prime(n)) {
		cout << 1;
		exit(0);
	}

	int primes[] = {2, 3, 5, 7, 11, 13, 17, 19};

	if(n % 2 == 0) cout << 2;
	else {
		if(is_prime(n - 2)) {
			cout << 2;
			exit(0);
		}
		cout << 3;
	}

	return 0;
}


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

const int mod = 1e9 + 7;
#define ll long long
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define _FOR(i,a,b) for(int i = a;i >= b;--i)

template<typename T>void read(T &x)
{
  x = 0;int f = 1;
  char c = getchar();
  for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
  for(;isdigit(c);c = getchar()) x = x * 10 + c - '0';
  x *= f;
}

map<int,int> ans;
int x,y;
ll a[100010];
int t;

int poww(ll a,ll b)
{
	ll ans = 1ll;
	while(b > 0)
	{
		if(b & 1) ans = ans * a % (1ll * mod);
		b /= 2ll;
		a = a * a % mod;
	}
	return ans;
}

int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
	read(x),read(y);
	if(y % x) {puts("0");return 0;}
	for(int i = 1; i * i <= y / x; ++i)
		if((y / x) % i == 0)
		{
			a[++t] = i;
			if(i * i != (y / x)) a[++t] = (y / x) / i;
		}
	sort(a + 1,a + 1 + t);
	_FOR(i,t,1)
	{
		ans[i] = poww(2,y / (x * a[i]) - 1);
		FOR(j,i + 1,t)
			if(a[j] % a[i] == 0)
				ans[i] = (ans[i] - ans[j] + mod) % mod;
	}
	printf("%d\n",ans[1]);
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    if (n%2==0) cout<<n/2-1;
    else cout<<n/2;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,ans = 0;
void dfs(int cur) {
	if(cur>n) return;
	else ans++;
	dfs(cur*10+1);
	dfs(cur*10);
}
int main() {
	cin>>n;
	dfs(1);
    cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll p[]={a,1,0},q[]={b,0,1};
		while(*q){
			ll t=*p/ *q;
			rep(i,3) swap(p[i]-=t*q[i],q[i]);
		}
		if(p[0]<0) rep(i,3) p[i]=-p[i];
		x=p[1],y=p[2];
		return p[0];
	}
	ModInt inv() const {
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<998244353>;

int bsr(int x) { return 31 - __builtin_clz(x); }
using D = double;
const D pi = acos(-1);
using Pc = complex<D>;

void fft(bool type, vector<Pc> &c){	//multiply : false -> mult -> true
	static vector<Pc> buf[30];
	int N = c.size();
	int s = bsr(N);
	assert(1<<s == N);
	if(buf[s].empty()){
		buf[s]=vector<Pc>(N);
		rep(i,N) buf[s][i] = polar<D>(1,i*2*pi/N);
	}
	vector<Pc> a(N),b(N);
	copy(begin(c),end(c),begin(a));
	rep1(i,s){
		int W = 1<<(s-i);
		for(int y=0;y<N/2;y+=W){
			Pc now = buf[s][y];
			if(type) now = conj(now);
			rep(x,W){
				auto l =       a[y<<1 | x];
				auto r = now * a[y<<1 | x | W];
				b[y | x]        = l+r;
				b[y | x | N>>1] = l-r;
			}
		}
		swap(a,b);
	}
	copy(begin(a),end(a),begin(c));
}
template<class Mint>
vector<Mint> multiply_fft2(const vector<Mint>& x,const vector<Mint>& y){
	const int B = 15;
	int S = x.size()+y.size()-1;
	int N = 2<<bsr(S-1);
	vector<Pc> a[2],b[2];
	rep(t,2){
		a[t] = vector<Pc>(N);
		b[t] = vector<Pc>(N);
		rep(i,x.size()) a[t][i] = Pc( (x[i].v >> (t*B)) & ((1<<B)-1) , 0 );
		rep(i,y.size()) b[t][i] = Pc( (y[i].v >> (t*B)) & ((1<<B)-1) , 0 );
		fft(false,a[t]);
		fft(false,b[t]);
	}
	vector<Mint> z(S);
	vector<Pc> c(N);
	Mint base = 1;
	rep(t,3){
		fill_n(begin(c),N,Pc(0,0));
		for(int xt = max(t-1,0); xt<=min(1,t); xt++){
			int yt = t-xt;
			rep(i,N) c[i] += a[xt][i]*b[yt][i];
		}
		fft(true,c);
		rep(i,S){
			c[i] *= 1.0/N;
			z[i] += Mint(ll(round(c[i].real()))) * base;
		}
		base *= 1<<B;
	}
	return z;
}
template<class Mint>
vector<Mint> multiply_fft(const vector<Mint>& x,const vector<Mint>& y){
	return multiply_fft2(x,y);
}

template<class D>
struct Poly{
	vector<D> v;
	int size() const{ return v.size();}	//deg+1
	Poly(int N=0) : v(vector<D>(N)){}
	Poly(vector<D> v) : v(v){shrink();}

	Poly& shrink(){
		while(!v.empty()&&v.back()==D(0)) v.pop_back();	//double? iszeroをglobalに用意したほうがいいかな
		return *this;
	}
	D at(int i) const{
		return (i<size())?v[i]:D(0);
	}
	void set(int i,const D& x){		//v[i] := x
		if(i>=size() && !x) return;
		while(i>=size()) v.push_back(D(0));
		v[i]=x;
		shrink();
		return;
	}

	Poly operator+(const Poly &r) const{
		int N=max(size(),r.size());
		vector<D> ret(N);
		rep(i,N) ret[i]=at(i)+r.at(i);
		return Poly(ret);
	}
	Poly operator-(const Poly &r) const{
		int N=max(size(),r.size());
		vector<D> ret(N);
		rep(i,N) ret[i]=at(i)-r.at(i);
		return Poly(ret);
	}
	Poly operator-() const{
		int N=size();
		vector<D> ret(N);
		rep(i,N) ret[i] = -at(i);
		return Poly(ret);
	}
	Poly operator*(const Poly &r) const{
		if(size()==0||r.size()==0) return Poly();
		return mul_fft(r);
	}
	Poly operator*(const D &r) const{
		int N=size();
		vector<D> ret(N);
		rep(i,N) ret[i]=v[i]*r;
		return Poly(ret);
	}
	Poly operator/(const Poly &y) const{
		return div_fast(y);
	}
	Poly operator%(const Poly &y) const{
		return rem_fast(y);
//		return rem_naive(y);
	}
	Poly operator<<(const int &n) const{	// *=x^n
		assert(n>=0);
		int N=size();
		vector<D> ret(N+n);
		rep(i,N) ret[i+n]=v[i];
		return Poly(ret);
	}
	Poly operator>>(const int &n) const{	// /=x^n
		assert(n>=0);
		int N=size();
		if(N<=n) return Poly();
		vector<D> ret(N-n);
		rep(i,N-n) ret[i]=v[i+n];
		return Poly(ret);
	}
	bool operator==(const Poly &y) const{
		return v==y.v;
	}
	bool operator!=(const Poly &y) const{
		return v!=y.v;
	}

	Poly& operator+=(const Poly &r) {return *this = *this+r;}
	Poly& operator-=(const Poly &r) {return *this = *this-r;}
	Poly& operator*=(const Poly &r) {return *this = *this*r;}
	Poly& operator*=(const D &r) {return *this = *this*r;}
	Poly& operator%=(const Poly &y) {return *this = *this%y;}
	Poly& operator<<=(const int &n) {return *this = *this<<n;}
	Poly& operator>>=(const int &n) {return *this = *this>>n;}

	Poly mul_naive(const Poly &r) const{
		int N=size(),M=r.size();
		vector<D> ret(N+M-1);
		rep(i,N) rep(j,M) ret[i+j]+=at(i)*r.at(j);
		return Poly(ret);
	}
	Poly mul_ntt(const Poly &r) const{
		return Poly(multiply_ntt(this->v,r.v));
	}
	Poly mul_fft(const Poly &r) const{
		vector<D> ret = multiply_fft(v,r.v);
		return Poly(ret);
	}

	Poly div_fast_with_inv(const Poly &inv, int B) const {
		return (*this * inv)>>(B-1);
	}
	Poly div_fast(const Poly &y) const{
		if(size()<y.size()) return Poly();
		int n = size();
		return div_fast_with_inv(y.inv(n),n);
	}
	Poly rem_naive(const Poly &y) const{
		Poly x = *this;
		while(y.size()<=x.size()){
			int N=x.size(),M=y.size();
			D coef = x.v[N-1]/y.v[M-1];
			x -= (y<<(N-M))*coef;
		}
		return x;
	}
	Poly rem_fast(const Poly &y) const{
		return *this - y * div_fast(y);
	}
	Poly strip(int n) const {	//ignore x^n , x^n+1,...
		vector<D> res = v;
		res.resize(min(n,size()));
		return Poly(res);
	}
	Poly rev(int n = -1) const {	//ignore x^n ~  ->  return x^(n-1) * f(1/x)
		vector<D> res = v;
		if(n!=-1) res.resize(n);
		reverse(all(res));
		return Poly(res);
	}
	Poly inv(int n) const{		// f * f.inv() = x^B + r(x) (B>=n)
		int N = size();
		assert(N>=1);		//f : non0
		assert(n>=N-1);		//f = .. + c_{N-1}x^{N-1}
		D coef = D(1)/at(N-1);
		Poly a = rev();
		Poly g(vector<D>(1,coef));
		for(int i=1; i+N-2<n; i*=2){		//need to strip!!
			g *= (Poly(vector<D>{2})-a*g).strip(2*i);
		}
		return g.rev(n+1-N);
	}

	friend ostream& operator<<(ostream &o,const Poly& x){
		if(x.size()==0) return o<<0;
		rep(i,x.size()) if(x.v[i]!=D(0)){
			o<<x.v[i]<<"x^"<<i;
			if(i!=x.size()-1) o<<" + ";
		}
		return o;
	}
};
V<mint> fact,ifact;
mint Choose(int a,int b){
	if(b<0 || a<b) return 0;
	return fact[a] * ifact[b] * ifact[a-b];
}
void InitFact(int N){
	fact.resize(N);
	ifact.resize(N);
	fact[0] = 1;
	rep1(i,N-1) fact[i] = fact[i-1] * i;
	ifact[N-1] = fact[N-1].inv();
	for(int i=N-2;i>=0;i--) ifact[i] = ifact[i+1] * (i+1);
}

template<class D>
Poly<D> berlekamp_massey(const vector<D> &u){
	int N = u.size();
	vector<D> b = {D(-1)}, c = {D(-1)};
	D y = D(1);
	rep1(n,N){
		int L = c.size(), M = b.size();
		D x = 0;
		rep(i,L) x += c[i]*u[n-L+i];
		b.pb(0);
		M++;
		if(!x) continue;
		D coef = x/y;
		if(L<M){
			auto tmp = c;
			c.insert(begin(c),M-L,D(0));
			rep(i,M) c[M-1-i] -= coef*b[M-1-i];
			b=tmp;
			y=x;
		}else{
			rep(i,M) c[L-1-i] -= coef*b[M-1-i];
		}
	}
	return Poly<D>(c);
}

vector<mint> extended(int n, const vector< vector<mint> >& coeffs, const vector<mint>& terms) {

	vector<mint> ret(max<int>(n + 1, terms.size()));
	copy(terms.begin(), terms.end(), ret.begin());
	const int order = coeffs.size() - 1;
	const int deg = coeffs[0].size() - 1;
	assert((int) terms.size() >= order);
	for (int m = terms.size(); m <= n; ++m) {
		mint s = 0;
		for (int i = 1; i <= order; ++i) {
			int k = m - i;
			mint t = ret[k];
			for (int d = 0; d <= deg; ++d) {
				s += t * coeffs[i][d];
				t *= k;
			}
		}
		mint denom = 0, mpow = 1;
		for (int d = 0; d <= deg; ++d) {
			denom += mpow * coeffs[0][d];
			mpow *= m;
		}
		ret[m] = -s/denom;
	}
	return ret;
}

vector< vector<mint> > find_recurrence_relation(vector<mint> terms, int deg, int ord = -1, bool verify=true) {

	if(ord != -1){		//given order
		int n = (deg+1)*(ord+1)+ord-1;
		while((int)terms.size()>n) terms.pop_back();
	}

	const int n = terms.size();
	const int B = (n + 2) / (deg + 2); // number of blocks
	const int C = B * (deg + 1); // number of columns
	const int R = n - (B - 1); // number of rows
	assert(B >= 2); assert(R >= C - 1);

	auto error = [] (int order, int deg) {
		fprintf(stderr,
			"Error: Could not find a recurrence relation "
			"of order <= %d and degree <= %d.\n\n",
			order, deg);
		assert(0);
	};

	vector< vector<mint> > mat(R, vector<mint>(C));
	for (int y = 0; y < R; ++y) {
		for (int b = 0; b < B; ++b) {
			mint v = terms[y+b];
			for (int d = 0; d <= deg; ++d) {
				mat[y][b * (deg + 1) + d] = v;
				v *= y+b;
			}
		}
	}

	int rank = 0;
	for (int x = 0; x < C; ++x) {
		int pivot = -1;
		for (int y = rank; y < R; ++y) if (mat[y][x] != 0) {
			pivot = y; break;
		}
		if (pivot < 0) break;
		if (pivot != rank) swap(mat[rank], mat[pivot]);
		mint inv = mat[rank][x].inv();
		for (int x2 = x; x2 < C; ++x2) mat[rank][x2] *= inv;
		for (int y = rank + 1; y < R; ++y) if (mat[y][x]) {
			mint c = -mat[y][x];
			for (int x2 = x; x2 < C; ++x2) {
				mat[y][x2] += c * mat[rank][x2];
			}
		}
		++rank;
	}

	if (rank == C) error(B - 1, deg);

	for (int y = rank - 1; y >= 0; --y) if (mat[y][rank]) {
		assert(mat[y][y] == 1);
		mint c = -mat[y][rank];
		for (int y2 = 0; y2 < y; ++y2) {
			mat[y2][rank] += c * mat[y2][y];
		}
	}

	int order = rank / (deg + 1);

	vector< vector<mint> > ret(order + 1, vector<mint>(deg + 1));
	ret[0][rank % (deg + 1)] = 1;
	for (int y = rank - 1; y >= 0; --y) {
		int k = order - y / (deg + 1), d = y % (deg + 1);
		ret[k][d] = -mat[y][rank];
	}

	if (verify) {
		auto extended_terms = extended(n - 1, ret,
				vector<mint>(terms.begin(), terms.begin() + order));
		for (int i = 0; i < (int) terms.size(); ++i) {
			if (terms[i] != extended_terms[i]) error(B - 1, deg);
		}
	}

	auto verbose = [&] {
		int last = verify ? n - 1 : order + R - 1;
		fprintf(stderr,
			"[ Found a recurrence relation ]\n"
			"- order %d\n"
			"- degree %d\n"
			"- verified up to a(%d) (number of non-trivial terms: %d)\n",
			order, deg, last, (last + 1) - ((deg + 2) * (order + 1) - 2)
		);
		fprintf(stderr, "{\n");
		for (int k = 0; k <= order; ++k) {
			fprintf(stderr, "  {");
			for (int d = 0; d <= deg; ++d) {
				if (d) fprintf(stderr, ", ");
				fprintf(stderr, "%d", ret[k][d].v);
			}
			fprintf(stderr, "}%s\n", k == order ? "" : ",");
		}
		fprintf(stderr, "}\n\n");
	};
	verbose();

	return ret;
}

void show_extended_sequence(int n, const vector<mint>& terms, int degree, int order = -1) {
	auto coeffs = find_recurrence_relation(terms, degree, order);
	auto extended_terms = extended(n, coeffs, terms);
	for (int i = 0; i < (int) extended_terms.size(); ++i) {
		printf("%d %d\n", i, extended_terms[i].v);
	}
	puts("");
}
V<mint> get_extended_sequence(int n, const vector<mint>& terms, int degree, int order = -1) {
	auto coeffs = find_recurrence_relation(terms, degree, order);
	return extended(n, coeffs, terms);
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	InitFact(2000010);

	auto brute = [&](int N){
		mint res = 0;
		rep(i_,N+1) rep(j_,N+1){
			int i = i_, j = j_; if(i>j) swap(i,j);
			if(j == 0){
				continue;
			}
			if(i == 0){
				res += mint(-1).pow(i+j) * Choose(N,j) * mint(3).pow(j + N*(N-j));
			}else{
				res += mint(-1).pow(i+j) * Choose(N,i) * Choose(N,j) * 3 * mint(3).pow((N-i)*(N-j));
			}
		}
		return -res;
	};
	auto solve = [&](ll N){
		mint res = 0;
		rep(i,N+1){
			if(i == 0){
				rep1(j,N){
					res += mint(-1).pow(i+j) * Choose(N,j) * mint(3).pow(j + N*(N-j));
				}
			}else{
				res += mint(-1).pow(i) * Choose(N,i) * (( mint(3).pow(N-i) - 1 ).pow(N) - mint(3).pow((N-i)*N)) * 3;
				res += mint(-1).pow(i) * Choose(N,i) * mint(3).pow(i + N*(N-i));
			}
		}
		return -res;
	};
	int N; cin >> N;
	cout << solve(N) << endl;
//	show(brute(N));
}


#include<bits/stdc++.h>

#define ll long long
#define re register int
#define For(i,a,b) for(ll i=(a); i<=(b); i++)
const int INF=1<<30;
const int mod=1e9+3;
using namespace std;
template <typename T>
inline void read(T &x) {
    x = 0;
    ll f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
            ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + (ch ^ 48);
        ch = getchar();
    }
    x *= f;
    return;
}
template <typename T>
inline void write(T x){
    if(x < 0) {
        putchar('-');
        x = -x;
    }
    if(x > 9)
        write(x/10);
    putchar(x % 10 + '0');
    return;
}
inline ll qpow(ll a,ll b){
    ll x=1,y=a;
    while(b>=1){
        if(b%2==1) x=x*y%mod;
        y=y*y%mod;
        b/=2;
    }
    return x;
}

const int N = 5;

bool v[N][N][50];
ll val[N][N], best[N][N], dp[N][N][50];

ll solve(int l, int r, int n) {
    if (v[l][r][n]) return dp[l][r][n];

    v[l][r][n] = 1;
    ll& ans = dp[l][r][n];
    int x = 6 - l - r;

    if (n == 1) return ans = best[l][r];
    ans = solve(l, x, n-1) + solve(x, r, n-1) + val[l][r];
    ll k = solve(l, r, n-1) * 2 + solve(r, l, n-1) + val[l][x]+ val[x][r];
    ans = min(ans, k);
    return ans;
}

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

    memset(v, 0, sizeof(v));
    for (int i = 1; i <= 3; i++)
        for (int j = 1; j <= 3; j++) {
            cin >> val[i][j];
            best[i][j] = val[i][j];
        }

    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 3; j++) {
            if (i == j) continue;
            for (int k = 1; k <= 3; k++) if (k != i && k != j) {
                best[i][j] = min(best[i][j], best[i][k] + best[k][j]);
            }
        }
    }
    int n;
    scanf("%d", &n);
    cout << solve(1, 3, n) << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
string s;
int flag;
int main(){
	cin>>s;
	for (int i=0;i<=s.length()-1;i++)
		if (s[i]=='h')
			for (int j=i+1;j<=s.length()-1;j++)
				if (s[j]=='e')
					for (int l=j+1;l<=s.length()-1;l++)
						if (s[l]=='l')
							for (int k=l+1;k<=s.length()-1;k++)
								if (s[k]=='l')
									for (int p=k+1;p<=s.length()-1;p++)
										if (s[p]=='o')
										{
											flag=1;
											cout<<"YES";
											return 0;
										}
	if (flag==0)
	{
		cout<<"NO";
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;

int main(){

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

int x , y;
bool flag = true;
cin >> x >> y;

while(1){
if(flag){
    if(x >= 2){
        x-=2;
        if(y >= 2){
            y-=2;
        }
        else{
           cout << "Hanako" << endl;
           return 0;
        }
    }
    else
    if(x > 0){
        x--;
        if(y>=12){
            y-=12;
        }
        else{
            cout << "Hanako" << endl;
            return 0;
        }
    }
    else
    if(y>=22){
        y-=22;
    }
    else{
        cout << "Hanako" << endl;
        return 0;
    }

}
else{

    if(y >= 22){
        y-=22;
    }
    else
    if(y >= 12){
        y-=12;
        if(x>=1){
            x--;
        }
        else{
            cout << "Ciel" << endl;
            return 0;
        }
    }
    else
    if(y>=2){
        y-=2;
        if(x >= 2){
            x-=2;
        }
        else{
            cout << "Ciel" << endl;
            return 0;
        }
    }
    else{
        cout << "Ciel" << endl;
        return 0;
    }

}

flag = !flag;
}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,pos,l,r,ans;
    while(cin>>n>>pos>>l>>r)
    {
        ans=0;
        if(l==1&&r==n)
            ans=0;
        else if(pos<=l&&r==n)
            ans+=l-pos+1;
        else if(pos>l&&r==n)
            ans+=pos-l+1;
        else if(pos>=r&&l==1)
            ans+=pos-r+1;
        else if(pos<r&&l==1)
            ans+=r-pos+1;
        else
            ans+=min(abs(l-pos)+r-l,abs(pos-r)+(r-l))+2;
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

int checkString(string str)
{
    if (str == "January") return 1;
    else if (str == "February") return 2;
    else if (str == "March") return 3;
    else if (str == "April") return 4;
    else if (str == "May") return 5;
    else if (str == "June") return 6;
    else if (str == "July") return 7;
    else if (str == "August") return 8;
    else if (str == "September") return 9;
    else if (str == "October") return 10;
    else if (str == "November") return 11;
    else if (str == "December") return 12;
    else return 13;
}

string toString(int n)
{
    switch(n)
    {
        case 1 : return "January";
        case 2 : return "February";
        case 3 : return "March";
        case 4 : return "April";
        case 5 : return "May";
        case 6 : return "June";
        case 7 : return "July";
        case 8 : return "August";
        case 9 : return "September";
        case 10 : return "October";
        case 11 : return "November";
        case 12 : return "December";
    }
    return "x";
}

int main()
{
    string tmp;
    cin >> tmp;
    int now = checkString(tmp);
    int plus;
    cin >> plus;
    now = (now + plus) % 12;
    if (now == 0) now = 12;
    cout << toString(now) << endl;
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
/*--------------------------------#defines------------------------------------------*/
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
/*-------------------------------CODE START-----------------------------------------*/
priority_queue< pair<long long int,int> >pq;
vector< pair<int,int> >vp;
map<long long int,int>mp,m;
const int N=1e5+6;
int dp[N];
typedef long long int ll;
vector<long long int>v,v1;
stack<int>s,s1;
int visit[N];
struct domingo{
int val,left,right;
}o[N];
long long int n,BIT[N]={};
int main()
{

	/*
	string s;
	cin>>s;

	while(next_permutation(s.begin(),s.end()))
	{
		cout<<s<<endl;
	}
*/
	int n,a,b;
	cin>>n>>a>>b;
	int c[6]={a, a, a, a, b, b};
	if(a*4+2*b<=n)
		return cout<<1, 0;
		int mi=1e5+5;
		sort(c,c+6);
		if(c[0]==c[5])
		{
			int sum=0,ct=1;
		for(int i=0;i<6;i++){
			if((sum+c[i])<=n)
			{
				sum+=c[i];
			}
			else
			{
				ct++;
				sum=c[i];
			}
		}
		return cout<<ct, 0;
		}
	while(next_permutation(c,c+6))
	{
		int sum=0,ct=1;
		for(int i=0;i<6;i++){
			if((sum+c[i])<=n)
			{
				sum+=c[i];
			}
			else
			{
				ct++;
				sum=c[i];
			}
		}
		mi=min(mi,ct);
	}
	cout<<mi;
}


#include<bits/stdc++.h>
using namespace std;
int c[2];
int main()
{
    string a;
    cin>>a;
    int i,n=a.size();
    for(i=0;i<n;i++)
    {
        if(a[i]>='a'&&a[i]<='z')c[1]++;
        else c[0]++;
    }
    if(c[0]>c[1])
	{
        for(i=0;i<n;i++)
		{
            a[i]=toupper(a[i]);
        }
    }
    else
	{
        for(i=0;i<n;i++)
		{
            a[i]=tolower(a[i]);
        }
    }
    cout<<a;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long C, hr, hb, wr, wb;

long long lcm(long long a, long long b) {
    for(int i = 1; ; ++i) {
        if (i%a == 0 && i%b == 0)
            return i;
    }
}

long long bruteForce(long long C, long long hr, long long hb, long long wr, long long wb) {
    long long ans = 0;
    for(int i = 0; i <= C / wb; ++i) {
        long long j = (C - i * wb) / wr;
        long long sum = hb * i + hr * j;
        ans = max(ans, sum);
    }
    return ans;
}

int main() {
    cin >> C >> hr >> hb >> wr >> wb;

    if (wr > wb) {
        swap(hr, hb);
        swap(wr, wb);
    }

    if (wb >= 10) {
        cout << bruteForce(C, hr, hb, wr, wb) << endl;
    } else {
        long long d = lcm(wr, wb);
        long long ans = 0;
        for(int i = 0; i < wb; ++i) {
            for(int j = 0; j < wr; ++j) {
                long long sumH = hr * i + hb * j;
                long long sumW = wr * i + wb * j;
                if (sumW > C)
                    continue;
                long long sumRemain = (C - sumW) / d * max(d/wr*hr, d/wb*hb);
                ans = max(ans, sumH + sumRemain);
            }
        }
        cout << ans << endl;
    }

    return 0;
}


// 519A
// Author: REET

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

typedef long long ll;

int main() {
    char tmp;
    int sum1 = 0;
    int sum2 = 0;
    vector<vector<char>> v(8);
    for(int i=0; i<8; i++) {
        for(int j=0; j<8; j++) {
            cin >> tmp;
            v[i].push_back(tmp);
        }
    }
    for(int i=0; i<8; i++) {
        for(int j=0; j<8; j++) {
            switch (v[i][j]) {
                case 'Q':
                    sum1 += 9;
                    break;
                case 'R':
                    sum1 += 5;
                    break;
                case 'B':
                    sum1 += 3;
                    break;
                case 'N':
                    sum1 += 3;
                    break;
                case 'P':
                    sum1 += 1;
                    break;
                default:
                    break;
            }
            switch (v[i][j]) {
                case 'q':
                    sum2 += 9;
                    break;
                case 'r':
                    sum2 += 5;
                    break;
                case 'b':
                    sum2 += 3;
                    break;
                case 'n':
                    sum2 += 3;
                    break;
                case 'p':
                    sum2 += 1;
                    break;
                default:
                    break;
            }
        }
    }
    if(sum1 == sum2) {
        cout << "Draw" << endl;
        return 0;
    }
    sum1 > sum2 ? cout << "White" << endl : cout << "Black" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,true,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000000000000007
#define pii 3.14159265358979
int main()
{
	    // freopen("in.txt","r",stdin);
	    // freopen("out","w",stdout);
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	    ll t;t=1;
	    // cin >> t;
	    while(t--)
		{
			ll n; cin >>n;
			string s; cin >>s;
			ll sum = 0;
			rep(i,0,n)sum+=s[i]-'0';
			debug(sum);
			ll flag=0,ans=0;
			ll kum = 0;
			rep(i,2,n+1)
			{
				if(sum%i==0)
				{
					debug(i);
					ll j =0;
					kum=0;
					while(j<n)
					{

						debug(flag);
						kum+=s[j]-'0';
						j++;
						debug(kum);
						if(kum==sum/i)
						{
							flag++;
							kum = 0;
						}
					}
					if(flag==i)ans = 1;
					debug(flag);
				}
			}
			if(sum==0)cout<<"YES";
			else
			{
				if(ans)cout<<"YES";
				else
				cout<<"NO";
			}
        }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
string s;
int n,a[1001];
int main(){
	cin>>n>>s;
	for(int i=0;i<n;i++) a[s[i]-'0']++;
	if((((a[3]||a[6]||a[9])&&(a[1]||a[4]||a[7]))||a[0])&&(a[7]||a[9]||a[0])&&(a[1]||a[2]||a[3])) cout<<"YES";
	else cout<<"NO";
	return 0;
}


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

	long long int res=0;
	if(n==1 )
	{
		if(s==1)
		res++;
	}
	else if(s==1)
	{
		res++;
	}
	else if(s<=n*n)
	{
	long long int p=sqrt(s);
     if(s<=n)
     {
     	res=res+2;
	 }
	for(long long int i=2;i<=p;i++)
	{

		if(s%i==0 )
		{
			if(i*i==s)
			res++;
			else if((s/i)<=n)
			{
				res=res+2;
			}
		}
	}
}
	cout<<res<<endl;
}


#include<cstdio>
#include<iostream>
using namespace std;
 int a[1000005];
int main()
{
    int n,cnt=0,i,j,k;
    while(~scanf("%d",&n))
    {
        cnt=0;
        for(i=0;i<=n;i++)
                a[i]=i*i;
        for(i=2;i<=n;i++)
        {
                for(j=i-1,k=1;k<j;)
                {
                        if(a[k]+a[j]==a[i])
                            cnt++;
                        if(a[k]+a[j]<a[i])
                            k++;
                        else
                            j--;
                }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


#include <iostream>
using namespace std;
int counts = 0;
int main(){
    int n;
    cin >> n;
    int rest = n;
    int z = 1;
    int count = 0;
    while (rest >0){
        while (rest>=z)
        {
            z *= 2;
        }
        rest -= z /2;
        count++;
        z = 1;
    }
    cout << count;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <fstream>
#include <list>
#include <set>
#include <climits>
#include <map>
#include <stack>
#include <queue>
#include <complex>
#include <cmath>
#include <sstream>
#include <deque>
#include <utility>
#include <bitset>
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832
#define MOD 1000000007
using namespace std;
string to(int a )
{
    string s ="";
    while(a!=0)
    {
        s+=char(a%10+'0');
        a/=10;
    }
    string t = "";
    for(int i = s.size()-1; i>=0; i--)
    {
        t+=s[i];
    }
    return t;

}
/*

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

    }

*/
vector<int> b;
vector<vector<int> > a;

void solve(){
    a[1][0]+=1;
for(int i = 1;i<=10;i++){
    bool is = true;
    for(int j = 0;j<a[i].size();j++){
        if(a[i][j]>pow(2,i-1)){
                int k = a[i][j]-pow(2,i-1);
            a[i][j]=pow(2,i-1);

            a[i+1][j]+=k;
            a[i+1][j+1]+=k;
            is = false;
        }

    }
    if(is)return;

}

}

int main(){

    ll n,t;
    cin>>n>>t;
a.push_back(b);

for(int i = 0;i<=11;i++){
    b.push_back(0);
    a.push_back(b);

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

}
int cou = 0;
for(int i = 1;i<=n;i++){
    for(int j = 0;j<a[i].size();j++){
        if(a[i][j]==pow(2,i-1))cou++;
    }
}

 cout<<cou;
}


#include<iostream>
#include<vector>

using namespace std;

void solu(vector<int>n, int m) {
	for (int i = 0; i < m ; i++) {
		if (n[i] + 15 < n[i + 1]) {
			cout << n[i] + 15;
			return;
		}

	}
	cout << 90 << endl;
}

int main()
{
	int size, n,a,b;
	cin >> size;
	vector<int>v;
	v.push_back(0);
	for (int i = 0; i <size; i++) {
		cin >> n;
		v.push_back(n);
	}
	v.push_back(90);

	solu(v, size+1);

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9')if(ch=='-')f=-1,ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
const ll mod=1000000007;
int main()
{
	ll a=read(),b=read();
	ll val=((b*(b-1))/2)%mod,ans=0;
	for(ll i=1;i<=a;++i){ll tmp=(1LL+1LL*i*b)%mod;ans=(ans+(val*tmp)%mod)%mod;}
	printf("%lld\n",ans);
	return 0;
}


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

int k, r, ans, tmp;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt" , "r", stdin );
    //freopen("output.txt", "w", stdout);
    cin >> k >> r;
    for (tmp = k , ans = 1; tmp%10!=r && tmp%10!=0; tmp += k, ans++);
    cout << ans << '\n';
    return 0;
}


#include <cstdio>
#include <cstring>

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    if(n==0&&m !=0){
        printf("Impossible\n");
        return 0;
    }
    int maxn = n+m-1;
    if(m == 0) maxn++;
    int minn= 0;
    if(m <= n) minn = n;
    else minn = m;
    printf("%d %d\n",minn,maxn);
}


#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
using namespace std;

typedef long long ll;

const int maxn = 2e2 + 10;
const int INF = 0x3f3f3f3f;
const int eps = 1e-8;

struct node {
	int id;
	int s;
	int d;
	int c;
}a[maxn];
int n, m;
int ans[maxn];

int cmp(node x, node y)
{
	return x.d < y.d;
}

int main()
{
	while (cin >> n >> m)
	{
		memset(ans, 0, sizeof(ans));
		int flag = 1;
		for (int i = 0; i < m; ++i)
		{
			cin >> a[i].s >> a[i].d >> a[i].c;
			a[i].id = i + 1;
			if (ans[a[i].d])
			{
				flag = 0;
			}
			ans[a[i].d] = m + 1;
		}
		if (!flag)
		{
			printf("-1\n");
			continue;
		}
		/*for (int i = 1; i <= n; ++i)
		{
			if (i != 1) printf(" ");
			printf("%d", ans[i]);
		}*/
		//printf("\n");
		sort(a, a + m, cmp);
		flag = 1;
		for (int i = 1; i <= n; ++i)
		{
			if (ans[i]) continue;
			int j;
			for (j = 0; j < m; ++j)
			{
				if (a[j].s <= i&&a[j].d > i)
				{
					//cout << (a[j].s < i) << endl;
					if (a[j].c)
					{
						a[j].c--;
						ans[i] = a[j].id;
						//cout << a[j].s << " " << i << " " << a[j].id << endl;
						break;
					}
				}
			}
		}
		for (int i = 0; i < m; ++i)
		{
			if (a[i].c)
			{
				flag = 0;
				break;
			}
		}
		if (!flag)
		{
			printf("-1\n");
		}
		else
		{
			for (int i = 1; i <= n; ++i)
			{
				if (i!=1) printf(" ");
				printf("%d", ans[i]);
			}
			printf("\n");
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

int remainders[100001]={0};

int main()
{
    int A, M, N = 0;
    bool existe = false;
    cin >> A >> M;
    remainders[N] = (A % M);
    N++;
    while( ((A % M) != 0) && !existe)
    {
        A = A + (A % M);
        existe = false;
        for(int i = 0 ; i < N ; ++i)
        {
            if(remainders[i] == (A%M))
            {
                existe = true;
                break;
            }
        }
        if(!existe)
        {
            remainders[N] = (A % M);
            N++;
        }
    }
    if(existe)
    {
        printf("No");
    }
    else
    {
        printf("Yes");
    }
    return 0;
}


 #include<bits/stdc++.h>
using namespace std;
int a[100];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
#endif
	 int n;
	 scanf("%d",&n);
	 for (int i=0;i<n;i++)scanf("%d",&a[i]);
	 sort(a,a+n);
	 printf("%d ",a[n-1]);
	 for (int i=1;i<n-1;i++)printf("%d ",a[i]);
	 printf("%d",a[0]);
	return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int med[4];
    int cup[4];
    int n;
    scanf("%d %d %d", &med[0], &med[1], &med[2]);

    scanf("%d %d %d", &cup[0], &cup[1], &cup[2]);

    scanf("%d", &n);

    med[3]=med[0]+med[1]+med[2];
    cup[3]=cup[0]+cup[1]+cup[2];

    int m=med[3]/5;
    if(med[3]%5!=0) m++;

    n=n-m;

    m=cup[3]/10;
    if(cup[3]%10!=0)m++;

    n=n-m;

    if(n<0)cout<<"NO";
    else cout<<"YES";

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(int i = 0; i < n; ++i)
#define RREP(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, x, y) for(ll i = x; i <= y; ++i)
#define RFOR(i, x, y) for(int i = x; i >= y; --i)
#define SZ(a) (ll)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define CLEAR(x) memset(x,0,sizeof x);
#define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define sqr(x) (x)*(x)
#define X first
#define Y second
#define y1 Y1
#define y2 Y2
const long double pi=acos(-1.0);
const long double eps = 1e-9;
const int MAXN = 1010111;
const int INF = 1000000000;
const ll MOD = 1000000003;

int n, m, mx, mn;
int a[100000];

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    cin >> n >> m >> mn >> mx;
    bool f = true;
    REP(i, m)
    {
        cin >> a[i];
    }
    sort(a, a + m);
    if (a[0] < mn) f = false;
    if (mx < a[m - 1]) f = false;
    int d = (mn < a[0]) + (a[m - 1] < mx);
    if (d > n - m) f = false;
    cout << (f ? "Correct" : "Incorrect") << endl;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int main()
{
#ifdef _DEBUG
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
#endif
	int n;
	cin>>n;
	vector<int> A(n,0);
	vector<int> B(n,0);
	for(int i=0;i<n;i++)
	cin>>A[i];
	int k1=-1;
	int k2=-1;
	for(int i=0;i<n;i++)
	{
		if(A[i]==1)
		{
			k1=i;
		}
		if(A[i]==n)
		{
			k2=i;
		}
	}
	cout<<max(max(k1,k2),n-min(k1,k2)-1);
int h;
}


#include <stdio.h>

int main(void){
	int n,m;
	int sum;
	scanf("%d%d",&n,&m);
	if (n%2==0)
		sum=m*n/2;
	else if(m%2==0)
		sum=n*m/2;
	else
		sum=n*(m-1)/2+(n+1)/2-1;
	printf("%d",sum);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<ctime>
using namespace std;
#define rep(i,l,r) for (int i=l; i<=r; i++)
#define drep(i,r,l) for (int i=r; i>=l; i--)
typedef long long ll;
const int N = 3000000, INF = 0x7fffffff, limit = 100;
int C[N], L, R, p, tot, dp[N], f[N], ans, P[30], len;
bool flag[108];
void dfs(ll cur, int last)
{
	if (cur > R) return;
	C[++tot] = cur;
	rep(i, last, len) dfs(cur * P[i], i);
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    scanf("%d%d%d", &L, &R, &p);
    rep(i, 2, limit)
    if (!flag[i])
    {
    	P[++len] = i;
        for (int j = i * i; j <= limit; j += i) flag[j] = 1;
    }
    dfs(1, 1);
    sort(C + 1, C + tot + 1);
    dp[1] = 0, f[1] = 2;
    rep(i, 2, tot) dp[i] = INF, f[i] = INF;
    rep(Max, 2, p)
    {
    	int i = 1, j;
    	for (j = 1; j <= tot; j++)
    	if (dp[j] < INF)
    	{
    	    if ((ll)C[j] * Max > R) break;
            while (C[i] < C[j] * Max) i++;
            dp[i] = min(dp[i], dp[j] + 1);
            f[i] = min(f[i], dp[i] + Max);
        }
    }
    rep(i, 1, tot)
    if (C[i] >= L && f[i] <= p) ans++;
    printf("%d\n", ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}


//bitw
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <utility>
#include <queue>
#include <stack>
#include <iomanip>
#include <cassert>
#include <deque>
#include <set>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(a+(b*c) , max(a*(b+c) , max(a*b*c , max((a+b)*c , max(a+b+c , (a*b) + c)))))<<endl;
    return 0;
}


#include<stdio.h>
int n;
char s[101];
int main(){
	scanf("%d", &n);
	scanf("%s", s);
	if (n == 1 && s[0] == '0'){
		printf("0\n");
		return 0;
	}
	int cnt = 0;
	for (int i = 0; i < n; i++)if (s[i] == '1')cnt++;
	printf("1");
	for (int i = 0; i < n - cnt; i++)printf("0");
	printf("\n");
	return 0;
}


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

LL n, K, l, r, mid;

LL calc(LL len, LL x) {
	if (len <= 2*x) return 0;
	LL cnt[2] = {1, 0}, a[2] = {len, len-1};
	LL res = 0, tmp;
	while (a[0] >= 2*x+1) {
		res += cnt[0]; res += (a[1] >= 2*x+1) * cnt[1];
		tmp = a[0] / 2;
		if (a[0]&1) cnt[0] = cnt[0] * 2 + cnt[1];
		else cnt[1] = cnt[1] * 2 + cnt[0];
		a[0] = tmp; a[1] = tmp - 1;
	}
	return res;
}

LL solve(LL l, LL r, LL limit, LL K) {
	LL mid = (l + r) >> 1, tmp, tmp2;
	if (K == 1) return mid;
	tmp = calc(mid-l, limit);
	tmp2 = calc(r-mid, limit + 1);
	if (K <= tmp + tmp2 + 1) return solve(l, mid-1, limit, K-tmp2-1);
	return solve(mid+1, r, limit, K-tmp-1);
}

int main() {
	scanf("%I64d%I64d", &n, &K);
	if (K == 1) return puts("1"), 0;
	if (K == 2) return printf("%I64d\n", n), 0;
	n -= 2; K -= 2;
	l = 0; r = (n + 1) / 2;
	while (l < r) {
		mid = (l + r + 1) >> 1;
		if (calc(n, mid) >= K) l = mid;
		else r = mid - 1;
	}
	printf("%I64d\n", solve(1, n, l, K) + 1);
	return 0;
}


//Jay Shree Krishna
#include"bits/stdc++.h"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long int
#define inf 1e18
#define sr string
#define mod 1000000007
#define start int t;cin>>t;while(t--)
#define db(x) cout<<#x<<"="<<x<<"\n"
#define db2(a,b)cout<<#a<<": "<<a<<" , "<<#b<<": "<<b<< endl;
#define db3(a,b,c)cout<<#a<<": "<<a<<" , "<<#b<<": "<<b<<" , "<<#c<<": "<<c<<endl;
#define forr(i,n) for (int i = 0; i < n; i++)
#define fr(i,n) for (int i = 1; i <= n; i++)
#define rep(i,j,k) for(int i = j; i < k; i++)
#define rp(i,j,k) for(int i = j; i <=k; i++)
#define nn "\n"
#define en "\n"
#define vvi vector<vector<int>>
#define vi vector<int>
#define si set<int>
#define mlsi multiset<int>
#define vc vector<char>
#define vs vector<string>
#define vli vector<long long int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define mci map<char,int>
#define mpiii map<pair<int,int>,int>
#define um unordered_map
#define umii unordered_map<int,int>
#define umsi unordered_map<string,int>
#define umci unordered_map<char,int>
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sortv(x) sort(x.begin(),x.end())
#define sorta(x,n) sort(x,x+n)
#define sorted(x) is_sorted(x.begin(),x.end())
#define print_all(x) for(auto t:x) cout<<t<<" ";cout<<en;
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define go(x) for(auto &[u,v]:x)
#define in(x) cin>>x
#define in2(x,y) cin>>x>>y
#define in3(x,y,z) cin>>x>>y>>z
#define in4(x,y,z,v) cin>>x>>y>>z>>v
#define oo(x) cout<<x<<endl
#define oo2(x,y) cout<<x<<" "<<y<<endl
#define oo3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define ood(n,x) cout<<fixed<<setprecision(n)<<x<<"\n"
#define sz(x) x.size()
#define ff first
#define ss second
#define ooy cout<<"YES\n"
#define oon cout<<"NO\n"
#define rr return
#define cc continue

using namespace std;

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

void read(vli &a,int n){
    a.resize(n);
    forr(i,n) cin>>a[i];
}

bool fine=0;
vli a;
ll n,m;
void solve(){

    in2(n,m);
    vector<pair<int,int>> a(m);
    forr(i,m){
        cin>>a[i].ff>>a[i].ss;
        swap(a[i].ff,a[i].ss);
    }
    sortv(a);
    reverse(all(a));
    ll ans=0;
    forr(i,m){
        if(n>=a[i].ss){
            ans+=a[i].ff*a[i].ss;
            n-=a[i].ss;
        }
        else{
            ans+=n*a[i].ff;
            oo(ans);
            rr;
        }
    }
    oo(ans);
    rr;

}

int main(){
     #ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
   freopen("output1.txt", "w", stdout);
    #endif
    fast;
   if(fine){
        start{
            solve();
        }
   }
   else solve();
    return 0;
}


#include <stdio.h>
#include <cstring>

long long int min(long long int a, long long int b) {
	return a < b ? a : b;
}

long long int nCr(long long int n, long long int k) {
    long long C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;  // nC0 is 1

    for (long long i = 1; i <= n; i++)
    {
        // Compute next row of pascal triangle using
        // the previous row
        for (long long j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}

int main(void) {
	long long int n, m, t;
	scanf("%lld%lld%lld", &n, &m, &t);
	long long int sum = 0;
	long long int z = min(m, t-4);
	for(long long int i = 1; i <= z; i++) {
		sum += nCr(m, i)*nCr(n, t-i);
	}
	printf("%lld", sum);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string s;
int n,k,a[100009],ans;
int main(){
    cin>>n>>k>>s;
    if(s[0]!='1' || s[n-1]!='1'){
        cout<<-1;
        return 0;
    }
    for(int i=0;i<n;i++){
        if(s[i]=='1')a[i]=i;
        else a[i]=a[i-1];
    }
    int j=0;
    while(a[j]!=a[j+k] && j<n-1){
        ans++;
        j=a[j+k];
        if(!j)j=n;
    }
    if(j>=n-1)cout<<ans<<endl;
    else cout<<-1<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define leep(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
using namespace std;
const ll INF = 1000000007;
const ll M=1e9+7;
const ll SIZ=200005;
ll isPal(ll a,ll b){
	if((a%10==b/10)&&(b%10==a/10))
		return 1;
	else
		return 0;
}

int main() {
	string ss;
	cin>>ss;
	string s="";
	s=s+ss[0]+ss[1];
	ll a=stoi(s);
	s="";
	s=s+ss[3]+ss[4];
	ll b=stoi(s);
	ll sum=0;
	ll mod1=60;
	ll mod2=24;
	while(!isPal(a,b)){
		sum++;
		b++;
		a+=b/60;
		a=a%24;
		b=b%60;
	}
	cout<<sum<<endl;

	return 0;
}


#include<iostream>
using namespace std;
long long int n;
long long int e;
long long int ans = 0;
void p(long long int x)
{
	for(long long int i=3;i*i<=x;i++)
	{
		if(x%i==0)
		{
			ans=i;
			return;
		}
	}
	ans=x;
	return;
}
int main()
{
	cin>>n;
	if(n%2==0) cout<<n/2;
	else {
		p(n);
		cout << (n-ans)/2+1 << endl;
	}
	return 0;
}


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


#include <bits/stdc++.h>
using namespace std;
string tostring(int i){
    string s ="";
    while(i>0){
        s+= i%10 + '0';
        i/=10;
    }
    reverse(s.begin(),s.end());
    return s;
}
main()
{
    int a, b, j=0;
    string a1="",a2 = "", b1 = "";
    cin >> a >> b;
    a++;
    while(1){
        a1 = tostring(a); b1=tostring(b);
        j = 0; a2 = "";
        for(int i=0; i<a1.length(); i++){
            if(a1[i]=='4'||a1[i]=='7'){
                a2+=a1[i];
            }
        }
        if(a2==b1){
            cout << a1;
            break;
        }
        else{
            a++;
        }
    }
}