/*
Priyanka Tanvani
priyanka_14
iit2012194
13.8.2014
codeforces virtual contest
B. Balls Game
*/
#include <iostream>
#include <vector>
using namespace std;

int main()
{
        int n, k, x, i, a, j, max, t, y;

        cin >> n >> k >> x;

        vector <int> v, temp;
        vector <int> :: iterator it, cni;

        for (i = 0; i < n; i++) {
                cin >> a;
                temp.push_back(a);
        }
        int flag = 0;
        max = 0;
        if (n >= 2) {
                for (y = 0; y < n - 1; y++) {
                        if (temp[y] == temp[y + 1] && temp[y] == x) {
                                v.clear();
                                v = temp;
                                it = v.begin();
                                j = y;
                                while (j--) {
                                        it++;
                                }
                                v.insert(it, x);
                                t = 0;
                                int c, cn;
                                while (v.size() > 0) {
                                        it = v.begin();
                                        cn = 0;
                                        for (i = 0; i < v.size() - 2; i++) {
                                                c = 1;
                                                for (j = i + 1; j < v.size(); j++) {
                                                        if (v[i] == v[j]) {
                                                                c++;
                                                        } else {
                                                                break;
                                                        }
                                                }
                                                if (c > 2) {
                                                        cni = it;
                                                        cn = c;
                                                        break;
                                                }
                                                it++;
                                        }
                                        if (cn > 2) {
                                                t = t + cn;
                                                v.erase(cni, cni + cn);
                                        } else {
                                                break;
                                        }
                                }
                                if (max < t) {
                                        max = t;
                                }
                        }
                }
        }
        if (max > 0) {
                max--;
        }
        cout << max << endl;
        //system("pause");
        return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void remplissage(vector<int>v,int x)
{
    for(int i = 0 ; i <v.size(); i++)
    {
        scanf("%d",&x);
        v.push_back(x);
    }
}
int main()
{
    int a,b,c,x;
    vector<int> v(a);
    remplissage(v,x);
    int s(0),tl(0),tr(0);
    int templeft = 0;
    int tempright = 0;
    cin>>a>>b>>c;
    int l(-1),r(-1),max(0);
    for(int i = 0; i < a;i++)
        {
            if(v[i] == v[i+1] && v[i] ==c)
                {
                    s += 2;
                    l = i - 1;
                    r = i + 2;
                    do{
                        if(v[l] == v[l-1])
                            {
                                tl = 2;
                            }
                        else
                            {
                                tl = 1;
                            }
                        if(v[r] == v[r+1])
                            {
                                tr = 2;
                            }
                        else
                            {
                                tr = 1;
                            }
                        if(tr + tl >=3 && v[l] == v[r])
                            {
                                l -= tl;
                                r += tr;
                                s += tr+tl;
                            }
                        else
                            {
                                break;
                            }
                    }while (true);
                    if(s > max)
                        {
                            max = s;
                        }
                    s = 0;
                    tl = -1;
                    tr = -1;
                }
        }
    printf("%d",max);
    return 0;
}


#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>
using namespace std;

int main()
{
    freopen("input.txt","r",stdin);
    int n,k,x,i;
    cin>>n>>k>>x;
    int num,c;
    int input[n+1];
    for(i=0;i<n;i++)
    cin>>input[i];
    vector< pair <int,int > >inp;
    int l=0;
    inp.push_back(make_pair(input[0],1));
    for(i=1;i<n;i++){
      if(input[i]==inp[l].first)
          inp[l].second++;
      else
      {
          inp.push_back(make_pair(input[i],1));
          l++;
      }

    }
    //cout<<"fwe";
    /*i=0;
    while(i<inp.size())
    {
        if(inp[i].first==inp[i+1].first)
           {inp[i].second+=inp[i+1].second;
            inp.erase(inp.begin()+i+1);
           }
           cout<<i;
         i++;
    }*/
    /*for(i=0;i<n-1;i++){
        cin>>c;
        cout<<i<<":"<<l;
        if(c==inp[l].first)
        inp[l].second++;
        else{
        inp.push_back(make_pair(c,1));l++;}
    }*/
    vector<int>posi;
    vector< pair <int,int > >test=inp;
    l=inp.size();
    for(i=0;i<l;i++)
    {
        //cout<<"   "<<inp[i].first<<","<<inp[i].second;
        //cout<<"   "<<test[i].first<<","<<test[i].second;
        if(inp[i].first==x && inp[i].second==2)
        posi.push_back(i);
    }
    int gmax=0,lmax=0;
    int p=posi.size(),pos,flag,j;
    for(i=0;i<p;i++)
    {
        //test=inp;
        for(j=0;j<l;j++)
             test[j]=inp[j];
        pos=posi[i];
        lmax=2;
        test.erase(test.begin()+pos);
        //cout<<"c";
        flag=0;
        /*cout<<"\n";
            for(j=0;j<test.size();j++)
             cout<<"   "<<test[j].first<<","<<test[j].second;/*/
        while(1)
        {
            flag=0;
            // for(j=0;j<test.size();j++)
             //cout<<"   "<<test[j].first<<","<<test[j].second;
            for(j=0;j<test.size()-1;j++)
            {
                if(test[j].first==test[j+1].first )
                {
                    test[j].second+=(test[j+1].second);
                    test.erase(test.begin()+j+1);
                }

            }
            //cout<<"\n";
              //   for(j=0;j<test.size();j++)
             //cout<<"   "<<test[j].first<<","<<test[j].second;
            for(j=0;j<test.size();j++)
            {
                //cout<<"a";
                if(test[j].second>=3)
                {
                    //cout<<test[j].second<<" ";
                    lmax+=test[j].second;
                    test.erase(test.begin()+j);
                    flag=1;
                    j--;
                }
                if(test.size()==0)
                    break;
            }
        if(flag==0 || test.size()==0)
        break;

    }
        gmax=max(gmax,lmax);
    }
    cout<<"\n"<<gmax;
     return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

const int nmax = 105;
const int inf = 1234567890;

int n, k, x, ans = 0;
int c[nmax];

void operate(vector<int> &cur);

int max(int x, int y){return x>y?x:y;}

int main()
{
   cin>>n>>k>>x;
   for(int i=0;i<n;i++)
        cin>>c[i];

   for(int i=0;i<n;i++)
   {
        vector<int> cur;
        for(int j=0;j<i;j++)
            cur.push_back(c[j]);
        cur.push_back(x);
        for(int j=i;j<n;j++)
            cur.push_back(c[j]);
        operate(cur);
        ans = max(ans, n - cur.size());
   }
   vector<int> cur;
   for(int j=0;j<n;j++)
        cur.push_back(c[j]);
   cur.push_back(x);
   operate(cur);
   ans = max(ans, n - cur.size());

   cout<<ans;

   return 0;
}

void operate(vector<int> &cur)
{
    if(cur.size()==0)
    	return;

    for(int i=0;i<cur.size() - 2;)
    {
        if(cur[i]==cur[i+1] && cur[i]==cur[i+2])
        {
            int j = i+2;
            while(j<cur.size() && cur[j]==cur[i])
                j++;
            vector<int> new_cur;
            for(int k=0;k<cur.size();k++)
            {
                if(k<i || k>=j)
                    new_cur.push_back(cur[k]);
            }
            cur.clear();
            for(int k=0;k<new_cur.size();k++)
                cur.push_back(new_cur[k]);
            new_cur.clear();
            operate(cur);
            return;
        }
        else i++;
    }
}

/* Sat Nov 23 2019 12:22:39 GMT+0300 (MSK) */


#include <bits/stdc++.h>
using namespace std;
const int maxn=1e8+7;
bool vis[maxn];
int prime[maxn],cnt;
vector<long long>g;
void f(int n)//�����1��n����������
{
    memset(vis,0,sizeof(vis));
    for(int i=2;i<=n;i++)
    {
        if(!vis[i])
            prime[cnt++] = i;
        for(int j=0;j<cnt && i*prime[j]<=n;j++)
        {
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)
                break;
        }
    }
}
int main()
{
    long long n; cin>>n;
    long long n1=n;
    f(maxn);
    for(int i=0;i<cnt;i++){
        int tmp=prime[i];
        if(n%tmp==0){
            g.push_back(tmp);
            while(n%tmp==0) n/=tmp;
        }
    }
    if(g.size()>1) cout<<n<<endl;
    else cout<<g[0]<<endl;
}


#include <bits/stdc++.h>
#define LL long long
const int N = 1e8;

int primee[N];//��i������
bool is_prime[N];//true��ʾi������

void init(){
    int n=10000000;
    int i, j, k;
    k = 0;
    memset(is_prime, true, sizeof(is_prime));
    is_prime[0] = is_prime[1] = false;//Ԥ����0��1,0��1��������
    for(i = 2; i <= n; i++){
        if(is_prime[i]){///��ǰi��һ�������������ı����Բ�������
            primee[k++] = i;//���������ĸ�����ͬʱ��¼��������
            for(j = 2*i; j <= n; j += i){//ɸ�������ı�������
                is_prime[j] = false;
            }
        }
    }
    return ;//����n���������ĸ���
}
LL in() {
    char ch;
    LL x = 0, f = 1;
    while (!isdigit(ch = getchar())) (ch == '-') && (f = -f);
    for (x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48))
        ;
    return x * f;
}
int prime[] = { 2, 3, 5, 7, 11, 61, 24251 };
LL msc(LL x, LL y, LL mod) {
    x %= mod;
    y %= mod;
    LL c = (long double)x / mod * y;
    LL d = x * y - c * mod;
    return ((d % mod) + mod) % mod;
}
LL ksm(LL x, LL y, LL mod) {
    LL re = 1LL;
    while (y) {
        if (y & 1)
            re = msc(re, x, mod);
        x = msc(x, x, mod);
        y >>= 1;
    }
    return (re + mod) % mod;
}
bool judge(LL a, LL p) {
    LL s = p - 1;
    while (!(s & 1)) s >>= 1;
    LL k = ksm(a, s, p);
    while (s != p - 1 && k != 1 && k != p - 1) k = msc(k, k, p), s <<= 1;
    return (k == p - 1) || ((s & 1));
}
bool judge(LL n) {
    if (n == 1)
        return false;
    for (int i = 0; i < 7; i++) {
        if (n == prime[i])
            return true;
        if (n % prime[i] == 0)
            return false;
        if (!judge(prime[i], n))
            return false;
    }
    for (int i = 1; i <= 10; i++)
        if (!judge(2 + rand() % (n - 2), n))
            return false;
    return true;
}

int main() {

    LL n;
    scanf("%lld", &n);
    if(judge(n)){
        printf("%lld",n);
        return 0;
    }
    else {
        init();
        for(int i=0;1ll*prime[i]*primee[i]<=n;i++){
            if(n%primee[i]==0){
                printf("%d",primee[i]);
                break;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;
int main() {
//    freopen("input.txt", "rt", stdin);
  //  freopen("output.txt", "wt", stdout);
    long long n;
    cin >> n;
    if (n == 1) {
        cout << "1";
        return 0;
    }
    if (n == 2) {
        cout << "2";
        return 0;
    }
    vector <bool>  a1(n+1, true);
    vector <int> a;
    for (long long i = 2; i <= n; i++) {
        if (a1[i] == false) {
            continue;
        }
        a.push_back(i);
        for (long long j = i + i; j <= n; j = j + i) {
            a1[j] = false;
        }
    }

    int i = 0, x = -1;
    for (i = 0; i < a.size(); i++) {
        if (n % a[i] == 0) {
            if (x != -1) {
                cout << "1";
                return 0;
            }
            x = a[i];
        }
    }
    cout << x;
}


// Brijesh Panara (201601074)
// DAIICT (India)
#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> >

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"   "<<#y<<" : "<<y<<"  "<<#z<<" : "<<z<<endl;

#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define READ freopen("input.txt","r",stdin);
#define WRITE freopen("output.txt","w",stdout);
#define RANDOM srand(time(NULL));

#define MOD 1000000007
#define NAX 1000005
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

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

bool isprime[NAX];
void sieve()
{
    FOR(i,2,NAX)
    isprime[i]=true;

    for(ll i=2;i*i<NAX;i++)
    {
          if(isprime[i]==true)
          {
              for(ll j=i*i;j<NAX;j+=i)
              isprime[j]=false;
          }
    }
}

vector<ll> getprime()
{
    sieve();

    vector<ll> prime;
    FOR(i,0,NAX)
    if(isprime[i]==true)
    prime.pb(i);

    return prime;
}

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

ll solve()
{
    ll n;
    cin>>n;

    vector<ll> v = getprime();
    ll pos = 0;
    ll cnt = 0;
    ll val = -1;

    while(pos<v.size())
    {
        if(n%v[pos]==0)
        {
            cnt++;
            val = v[pos];
        }

        while(n%v[pos]==0)
            n = n/v[pos];

        pos++;
    }

    if(val==-1)
        cout<<n<<"\n";
    else if(cnt>1)
        cout<<1<<"\n";
    else
        cout<<val<<"\n";

    return 0;
}

int main()
{
    FAST;

    ll t=1;
    // cin>>t;

    while(t--!=0)
    {
        ll stat = solve();
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    int A[7];
    int n;
    cin>>n;
    for(int i=0;i<7;i++){
        cin>>A[i];
    }
    int i=0;
    for(;n>0;i++){
        n-=A[i%7];
    }
    cout<<i%7;
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int read[8];
    int sum=0;
    for(int i=1;i<=7;i++)
    {
    cin>>read[i];
    sum+=read[i];
    }
    if(sum==n)
    {
        cout<<"7"<<endl;return 0;
    }
    else
    {
        if(n>sum)
        n=n%sum;
        sum=0;
        for(int i=1;i<=7;i++)
        {
            sum+=read[i];
            if(sum>=n){cout<<i<<endl;return 0;}
        }
    }
}


#include<stdio.h>
#include<conio.h>
void main()
{
	int i,n,a[8],temp=0;
	scanf("%d",&n);
	for(i=1;i<=7;i++)
		scanf("%d",&a[i]);
	while(1)
		for(i=1;i<=7;i++)
		{
			temp+=a[i];
			if(temp>n)
			{
				printf("%d",i);
				goto sos;
			}
		}
		sos:
		getch();
}


#include <iostream>
#include <algorithm>
#include <conio.h>
#include <cmath>
using namespace std;

int main ()
 { long int n,i,a[7],s=0,k;
   cin>>n;
   for (i=0;i<7;i++) {cin>>a[i]; s+=a[i];}
      n=n%s;
      if (n==0) {for (i=6;i>=0;i--) if  (a[i]>0) {cout<<i+1; break;}}
      else {
   for (i=0;i<7;i++) {n-=a[i]; k=i; if (n<0) break;}
    cout<<k+1;}
    getch();
    return 0;
         }


#include <iostream>
#include <cstdio>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#define LL __int64

using namespace std;

int dp[108][100008], l[108], r[108], n, k;
const int maxn = 300;
int Qv[100008], Qid[100008], pos1, pos2;

void solve(int nown)
{
    //+0
    for(int i = 0; i <= n; i++)
        dp[nown][i] = dp[nown - 1][i];
    //+2
    pos1 = pos2 = 0;
    for(int i = 1; i <= r[nown]; i++) {
        while(pos2 > pos1 && dp[nown - 1][i - 1] <= Qv[pos2 - 1])
            --pos2;
        Qv[pos2] = dp[nown - 1][i - 1];
        Qid[pos2++] = i - 1;
        while(pos2 > pos1 && Qid[pos1] < i - (r[nown] - l[nown]))
            ++pos1;
        if(pos2 > pos1)
            dp[nown][i] = min(dp[nown][i], Qv[pos1] + 2);
    }
    //+1
    pos1 = pos2 = 0;
    for(int i = r[nown]; i >= 0; i--) {
        while(pos2 > pos1 && dp[nown - 1][r[nown] - i] <= Qv[pos2 - 1])
            --pos2;
        Qv[pos2] = dp[nown - 1][r[nown] - i];
        Qid[pos2++] = r[nown] - i;
        while(pos2 > pos1 && Qid[pos1] < l[nown] - i)
            ++pos1;
        if(pos2 > pos1)
            dp[nown][i] = min(dp[nown][i], Qv[pos1] + 1);
    }
}

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

    dp[0][0] = 0;
    for(int i = 1; i <= n; i++)
        dp[0][i] = maxn;
    for(int i = 1; i <= k; i++)
        solve(i);

    if(dp[k][n] ==  maxn)
        printf("Hungry");
    else
        printf("Full\n%d", dp[k][n]);
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
using namespace std;
int n,k,l,r,dp[2][200005],tail,head,Q[1000005];
bool flag;
int main(){
	scanf("%d%d",&n,&k);
	memset(dp[flag],0x3f,sizeof(dp[flag]));
	dp[0][0] = 0;
	while (k --){
		memcpy(dp[1 - flag],dp[flag],sizeof(dp[1 - flag]));
		scanf ("%d%d",&l,&r);
		head = 1,tail = 0;
		for (int i = 0;i <= min(n,r);i ++){
			while (head <= tail && dp[flag][Q[tail]] >= dp[flag][i])
				tail --;
			Q[++ tail] = i;
			while (head <= tail && head < i - (r - l))
				head ++;
			dp[1 - flag][i] = min(dp[1 - flag][i],dp[flag][Q[head]] + 2);
		}
		head = 1,tail = 0;
		for (int i = r;i >= 0;i --){
			while (head <= tail && dp[flag][Q[tail]] >= dp[flag][r - i])
				tail --;
			Q[++ tail] = r - i;
			while (head <= tail && Q[head] < l - i)
				head ++;
			dp[1 - flag][i] = min(dp[1 - flag][i],dp[flag][Q[head]] + 1);
		}
		flag = 1 - flag;
	}
	if (dp[flag][n] >= 0x3f3f3f3f - 100){
		printf("Hungry\n");
		return 0;
	}
	else {
		printf("Full\n");
		printf("%d\n",dp[flag][n]);
	}
}


#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002, K = 102;
int n,k,l[N],r[N],dp[K][N][2];
bool v[K][N][2];

int solve(int i, int rem, bool t, bool flip){
    if(rem < 0) return infi;
    if(i == k+1) return rem ? infi : 0;
    int &ret = dp[i][rem][t];
    if(v[i][rem][t]) return ret;
    v[i][rem][t] = true;

    ret = solve(i+1, rem - (l[i+1] - l[i]) * t, t, flip);
    if(i){
        ret = min(ret, 1 + solve(i+1, rem - (l[i+1] - l[i]) * (1 - t), !t, flip));
        ret = min(ret, 1 + solve(i+1, rem - (r[i] - l[i]) * t - (l[i+1] - r[i]) * (1 - t), !t, flip));
    }
    if(flip) lp(j,l[i],r[i]){
        ret = min(ret, 1 + solve(i+1, rem - (j - l[i]) * t - (l[i+1] - j) * (1 - t), !t, 0));
        ret = min(ret, 2 + solve(i+1, rem - (j - l[i]) * t - (r[i] - j) * (1 - t) - (l[i+1] - r[i]) * t, t, 0));
    }
    return ret;
}

int main(){
    read2i(n,k);
    lp(i,1,k) read2i(l[i], r[i]);
    l[k+1] = 2*n;

    if(solve(0, n, 0, 1) < infi) cout <<"Full\n" <<solve(0, n, 0, 1);
    else cout <<"Hungry";
}

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


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<string>
#include<algorithm>
#define ll unsigned long long
using namespace std;
const ll MAXN=3e7+5;
ll p[MAXN],c[MAXN];
ll cnt[MAXN];
ll m=0;
void divide(ll n)
{

    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0){
            p[++m]=i;c[m]=0;
            while(n%i==0){n/=i;c[m]++;}
        }
    }
    if(n>1){
        p[++m]=n,c[m]=1;
    }
//    for(ll i=1;i<=m;i++){
//        cout<<p[i]<<"^"<<c[i]<<endl;
//    }
}
int main()
{
    ll n,b;
    cin>>n>>b;
    divide(b);
    //ll l=0;
    for(ll i=1;i<=m;i++){
        ll now=p[i];
        ll biu=0;
        while(now<=n){
            biu+=(n/now);
            now=now*p[i];
        }
        cnt[i]=biu;
    }
   unsigned long long Max=18446744073709551614;
    for(ll i=1;i<=m;i++){
            //cout<<cnt[i]<<endl;
        if(cnt[i]==0){continue;}
        Max=min(Max,(ll)cnt[i]/c[i]);
    }
    cout<<Max<<endl;
}


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

#define ll long long

int cnt=0;
ll num[40000005];

void primeFactor(ll n)
{
    while(n % 2 == 0)
    {
        num[cnt++]=2;
        n /= 2;
    }
    for(ll i = 3; i <= sqrt(n); i += 2)
    {
        while(n % i == 0)
        {
            num[cnt++]=i;
            n /= i;
        }
    }
    if(n > 2)
        num[cnt++]=n;
}
int main()
{

	ll n,b;
	scanf("%lld%lld",&n,&b);
	primeFactor(b);
	ll s=0;
	ll k=1;
	ll minn=9999999;
    for(int t=0;t<cnt;t++)
    {
    	if(num[t]!=num[t+1])
    	{
    		s=0;
    		n/=k;
    		k=1;

    		while(n/num[t])
    		{
    			s+=(n/num[t]);

    			num[t]*=num[t];
			}
			minn=min(minn,s);
		}
		else
		{
			k++;
		}

	}
	cout<<minn<<endl;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_size=100000;//количество факториалов, которых посчитает прога

ll ans[100];
ll b,n,q;
void obs(){
    ans[0]=0;
	int i1=0;
	ll sz=1e18/q;
	while(ans[i1]<sz){
	    ans[i1+1]=ans[i1]*q+1;
	    i1++;
	}
}

ll funk(ll n){
    if(n==0) return 0;
    ll d=1;
    int i=0;
    while(d<=n){
        d*=q;
        i++;
    }
    i--;
    d/=q;
    return funk(n-d)+ans[i];
}
int main() {
	ios_base::sync_with_stdio(false);
	cin>>n>>b;
	ll b1=b;
	ll ss=sqrt(b)+7;
	ll mn=2e18;
	for(int i=2;i<min(ss,b1+1);i++){
	    if(b1%i==0){
	        q=i;
	        ll h=0;
	        while(b1%i==0){
	            b1/=i;
	            h++;
	        }
	        obs();
	        ll f=funk(n);
	        if(mn>f/h)mn=f/h;
	    }
	}
	if(b1!=1) q=b1;
	obs();
	ll f=funk(n);
	if(mn>f)mn=f;
	cout<<mn;
	return 0;
}


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

#define whatis(x) cerr<<#x<<" "<<x;
#define whatisn(x) cerr<<#x<<" "<<x<<endl;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

bool isPrime(ull n){
	for(ull i=2;i*i<=n;i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}

int main(){

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

  	ull n, b, f, c, t, ans, p;
  	map<ull, int> factor;

  	cin>>n>>b;
  	t = b;
  	if(isPrime(t)){
  		factor[t] = 1;
  	}else{
  		for(ull i=2;i*i<=t;i++){
	  		whatisn(t)
	  		if(t%i==0){
				whatisn(t/i);
				whatisn(i)
	  			if(isPrime(t/i)){
	  				p = t/i;
	  				while(t>0 && t%p==0){
	  					factor[p]++;
	  					t = t/p;
	  				}
	  			}
	  			if(isPrime(i)){
	  				p = i;
	  				while(t>0 && t%p==0){
	  					factor[p]++;
	  					t = t/p;
	  				}
	  			}
	  		}
	  	}
  	}

  	ull mn = n;

  	for(auto it : factor){
  		t = n;
  		ans = 0;
  		while(t>0){
	  		t = t/it.first;
	  		ans += t;
	  	}
	  	mn = min(mn, ans/it.second);
  	}

  	cout<<mn<<endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{
	int k, b, n, t;
	cin>>k>>b>>n>>t;
	int res = 0;
	if(t==1) {cout<<n<<endl; return 0;}
	long long x = 1;
	while(x<t)
	{
		x*=k;
		x+=b;
		res++;
	}
	cout<<max(0, n-res+1)<<endl;
	return 0;
}


#pragma comment(linker, "/STACK:128777216")

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <functional>
#include <numeric>
#include <iostream>
#include <sstream>
#include <ctime>

using namespace std;

typedef long long i64;
typedef unsigned int u32;
const double pi = acos(-1.0);

int main() {
#ifdef pperm
	freopen("input.txt", "r", stdin);
	//freopen("input.txt", "w", stdout);
	//freopen("output.txt", "w", stdout);
#endif
	int k, b, n, t;
	scanf("%d %d %d %d", &k, &b, &n, &t);
	if (k == 1) {
		int z = 1 + b * n;
		cout << max(((z - t + b - 1) / b), 0);
		return 0;
	}
	double res = n + (log(b + k - 1.0) - log(t * (k - 1.0) + b)) / log(k + 0.0);
	cout << max(int(res + 1), 0) << endl;
	return 0;
}


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

int main()
{
    int k,b,n,t;
    cin >>k >>b >>n >>t;

   long long  int dp[n+1];
    int i;
    dp[0]=1;

    for(i=1;i<=n;i++)
    {
        dp[i]=dp[i-1]*k +b;
    }
    int temp;
    vector<long long int>  ans;
    if(t>=dp[n])
    cout <<"0" <<endl;

    else
    {
    ans.push_back(t);

     for(i=1;;i++)
     {
         temp=ans[i-1]*k+b;
         if(temp>=dp[n])
         break;

         ans.push_back(temp);
     }

     cout <<i <<endl;
    }
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int grow(long long int k,long long int b,long long int n,long long int cnt){
    if(n){
        cnt=cnt*k+b;
        return grow(k,b,n-1,cnt);
    }
    return cnt;
}
void time(long long int k,long long int b,long long int t,long long int tmp,long long int cnt){
    if(t < tmp){
        t=t*k+b;
        return time(k,b,t,tmp,cnt+1);
    }
    printf("%I64d",cnt);
    return;
}
int main(void){
    long long int k, b, n, t, tmp;
    scanf("%lld%lld%lld%lld",&k,&b,&n,&t);
    //printf("grow : %d\n",grow(k,b,n,1));
    tmp=grow(k,b,n,1);
    time(k,b,t,tmp,0);
    return 0;
}


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

#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */

using namespace std;

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

	int ans = 0;
	int g = 1;
	for (int i = 1; i <= 1000; i++){
		for (int s = 1; s <= 1000; s++){

			if (n * i > z && m*s > z) {
				cout << ans;
				return 0;
			}

			if (n * i == m * s)
			{
				ans++;
				break;
			}
		}
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,j,m,z,ct=0,x,i;
    cin>>n>>m>>z;
    x=n*m;
    for(i=1;i<z;i++)
        {for(j=1;j<z;j++)
            if(n*i==m*j&&n*i<=z&&m*j<=z)ct++;
        }
    if(n==1&&m==1)ct++;
    cout<<ct;
}


#include <iostream>
#include<cstdio>
#include<string>

using namespace std;

int main()
{
    long    long    int i,l=0;
   long    long    int  j,k=0,n,m,z;
    cin>>n>>m>>z;
    //
    if(n==1&&m==1&&z==1)
       {

                cout<<"0";
       }
    else if(n==m)
    {
        cout<<(z/n);
    }
    else    if(n==1 )
    {
        l=z/m;
        l=l*n;
        cout<<l;
    }
    else
    {
        for(i=m;i<=z;i=i+m)
        {
           if(i%n==0)
                k=k+1;
        }
        cout<<k;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,z;

    cin >> n >> m >> z;

    long cnt=0,i,j;
    long arr[10000],arr1[10000];

    for(long i=1;arr[i]<=z;i++)
    {
        arr[i] = m*i;
    }
    for(long i=1;i*n<=z;i++)
    {
        arr1[i] = n*i;
    }
    for(i=1;i<=z;i++)
    {
        for(j=1;j<=z;j++)
        {
            if(arr[i]==arr1[j])
            {
                cnt++;
            }

        }
    }
    cout<<cnt<<" ";

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <sstream>

using namespace std;

vector<int> reader (int *total, int *days) {

    int iter = 0;
    int buffer;
    string line;
    vector<int> input;

    cin >> *days;
    cin >> *total;
    // clear it
    getline(cin, line);

    while (iter < *days) {
        getline(cin, line);
        stringstream s(line);
        while (s >> buffer) {
            input.push_back(buffer);
        }
        iter++;
    }

    return input;
}

int main () {

    vector<int> input;
    vector<int> output;
    vector<int>::iterator it;
    int total, days = 0;
    int minDex, maxDex, d = 0;
    int sum = 0;

    input = reader(&total, &days);
    it = input.begin();
    while ((it < input.end()) && d < days) {
        // Min value
        minDex = *it;
        it++;
        // Max value
        maxDex = *(it);
        if (d / (days - 1) < .5) {
            if ((maxDex + sum) <= total) {
                sum += maxDex;
                output.push_back(maxDex);
            }
        } else {
            if ((maxDex + sum) > total) {
                while ((maxDex >= minDex) && ((--maxDex + sum) != total));
                sum += maxDex;
                output.push_back(maxDex);
            } else {
                sum += minDex;
                output.push_back(minDex);
            }
        }

        it++;
        d++;
    }

    if (sum == total) {
        cout << "YES" << endl;
        for (it = output.begin(); it < output.end(); it++) {
            cout << *it << " ";
        }
        cout << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

struct str
{
    int mintime;
    int maxtime;
};

int main()
{
    int d, sumtime, sum1 = 0, n = 0;
    cin >> d >> sumtime;
    str* s = new str[d];
    int* rez = new int[d];
    for ( int j = 0; j < d; ++j )
        cin >> s[j].mintime >> s[j].maxtime;
    for ( int j = 0; j < d; ++j )
        sum1 += s[j].mintime;

    for ( int j = 0; j < d; ++j )
        rez[j] = s[j].mintime;

    if ( sum1 == sumtime )
    {
        cout << "YES" << endl;
        for ( int j = 0; j < d; ++j )
            cout << rez[j] << ' ';
    }
    else if ( sum1 < sumtime )
    {
        for ( int j = 0; j < d; ++j )
        {
            if ( sum1 == sumtime )
                break;
            for ( int i = s[j].mintime+1 ; i <= s[j].maxtime; ++i )
            {
                ++sum1;
                ++rez[j];
                if ( sum1 == sumtime )
                    break;
            }
        }
    }
    if ( sum1 != sumtime )
        cout << "NO";
    else
    {
        cout << "YES" << endl;
        for ( int j = 0; j < d; ++j )
            cout << rez[j] << ' ';
    }

    getch();
    return 0;
}


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

using namespace std;

int main()
{
int d, sum, min=0, max=0, i;
cin >> d >> sum;
int mint[d], maxt[d];
for(i=0;i<d;i++)
{
 cin >> mint[i] >> maxt[i];
 min+=mint[i];
 max+=maxt[i];
}
if(min<=sum&&max>=sum)
{
 for(i=0;i<d-1;i++)
  cout << mint[i] << ' ';
 cout << sum-(min-mint[d-1]);
}
else
 cout << "NO";
return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <cstdio>
using namespace std;
int n;
map<string,int> S;
typedef map<string,int>::iterator Iter;
int main(){
	scanf("%d",&n);
	string s;
	Iter it;
	for (int i=0;i<n;i++){
		cin>>s;
		it = S.find(s);
		if (it==S.end()){
			S.insert(make_pair(s,0));
			printf("OK");
			cout<<endl;
		}
		else{
			it->second++;
			stringstream sstr;
			sstr<<it->second;
			s+=sstr.str();
			S.insert(it,make_pair(s,0));
			cout<<s<<endl;
		}
	}
	return 0;
}


#include<cstdio>
#define ll long long
#define MOD 1000000007

using namespace std;

ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

ll ksm(ll a, ll b){
    ll res = 1;
    while (b){
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD, b >>= 1;
    }
    return res;
}

ll C(ll x, ll y){
    x %= MOD, y %= MOD;
    ll xx = 1, yy = 1;
    for (int i = 1; i <= y; ++i){
        xx = (xx * (x - (i % MOD) + 1)) % MOD;
        xx = (xx + MOD) % MOD;
        yy = yy * (i % MOD) % MOD;
    }
    return (((xx * ksm(yy, MOD - 2)) % MOD + MOD) % MOD);
}

int n;
ll s, a[25], ans;

int main(){
    while (true){
        ans = 0;
        n = read(), s = read();
        if (!(n || s)) break;
        for (int i = 1; i <= n; ++i) a[i] = read();
        int MAXI = (1 << n);
        for(int i = 0; i < MAXI; ++i){
            ll zf = 1, x = s;
            for(int j = 0; j < n; ++j){
                if(i & (1 << j)){
                    x -= a[j + 1] + 1;
                    zf *= -1;
                }
            }
            if(x < 0)
                continue;
            ans = ((ans + zf * C(x + n - 1, n - 1) % MOD) % MOD + MOD) % MOD;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


//珂朵莉保佑不UKE
#include<cstdio>
#define ll long long
const ll MOD = 1e9+7;

using namespace std;

ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

ll ksm(ll a, ll b){
    ll res = 1;
    while (b){
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD, b >>= 1;
    }
    return res;
}

ll cacC(ll x, ll y){
    x %= MOD, y %= MOD;
    ll xx = 1, yy = 1;
    for (int i = 1; i <= y; ++i){
        xx = (xx * (x - (i % MOD) + 1)) % MOD;
        xx = (xx + MOD) % MOD;
        yy = yy * (i % MOD) % MOD;
    }
    return (((xx * ksm(yy, MOD - 2)) % MOD + MOD) % MOD);
}

int n;
ll s, a[25], ans;

int main(){
    while (true){
        ans = 0;
        n = read(), s = read();
        if (!(n || s)) break;
        for (int i = 1; i <= n; ++i) a[i] = read();
        int MAXI = (1 << n);
        for(int i = 0; i < MAXI; ++i){
            ll zf = 1, x = s;
            for(int j = 0; j < n; ++j){
                if(i & (1 << j)){
                    x -= a[j + 1] + 1;
                    zf *= -1;
                }
            }
            if(x < 0)
                continue;
            ans = ((ans + zf * cacC(x + n - 1, n - 1) % MOD) % MOD + MOD) % MOD;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


//666
#include<iostream>
#include<cstdio>
#define ll long long
#define MOD 1000000007

using namespace std;

ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

ll ksm(ll a, ll b){
    ll res = 1;
    while (b){
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD, b >>= 1;
    }
    return res;
}

ll C(ll x, ll y){
    x %= MOD, y %= MOD;
    ll xx = 1, yy = 1;
    for (int i = 1; i <= y; ++i){
        xx = (xx * (x - (i % MOD) + 1)) % MOD;
        xx = (xx + MOD) % MOD;
        yy = yy * (i % MOD) % MOD;
    }
    return (((xx * ksm(yy, MOD - 2)) % MOD + MOD) % MOD);
}

int n;
ll s, a[25], ans;

int main(){
    while (true){
        ans = 0;
        n = read(), s = read();
        if (!(n || s)) break;
        for (int i = 1; i <= n; ++i) a[i] = read();
        int MAXI = (1 << n);
        for(int i = 0; i < MAXI; ++i){
            ll zf = 1, x = s;
            for(int j = 0; j < n; ++j){
                if(i & (1 << j)){
                    x -= a[j + 1] + 1;
                    zf *= -1;
                }
            }
            if(x < 0)
                continue;
            ans = ((ans + zf * C(x + n - 1, n - 1) % MOD) % MOD + MOD) % MOD;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


//UKE * 2
#include<cmath>
#include<cstdio>
#define ll long long
#define MOD 1000000007

using namespace std;

ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

ll ksm(ll a, ll b){
    ll res = 1;
    while (b){
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD, b >>= 1;
    }
    return res;
}

ll C(ll x, ll y){
    x %= MOD, y %= MOD;
    ll xx = 1, yy = 1;
    for (int i = 1; i <= y; ++i){
        xx = (xx * (x - (i % MOD) + 1)) % MOD;
        xx = (xx + MOD) % MOD;
        yy = yy * (i % MOD) % MOD;
    }
    return (((xx * ksm(yy, MOD - 2)) % MOD + MOD) % MOD);
}

int n;
ll s, a[25], ans;

int main(){
    while (true){
        ans = 0;
        n = read(), s = read();
        if (!(n || s)) break;
        for (int i = 1; i <= n; ++i) a[i] = read();
        int MAXI = (1 << n);
        for(int i = 0; i < MAXI; ++i){
            ll zf = 1, x = s;
            for(int j = 0; j < n; ++j){
                if(i & (1 << j)){
                    x -= a[j + 1] + 1;
                    zf *= -1;
                }
            }
            if(x < 0)
                continue;
            ans = ((ans + zf * C(x + n - 1, n - 1) % MOD) % MOD + MOD) % MOD;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
long long power(long long a, long long b,ll m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a%m;
        a = a * a%m;
        b >>= 1;
    }
    return res;
    }
  ll int binomial(ll int n, ll int k)
{
    ll int C[k+1];
    memset(C, 0, sizeof(C));

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

    for (ll int i = 1; i <= n; i++)
    {
        // Compute next row of pascal triangle using
        // the previous row
        for (int j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
  vector<int> pr;
  bool prime[10000000];
void Sieve(ll int n)
{
    memset(prime, true, sizeof(prime));
    prime[1]=false;

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}

//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}
void reverse(string& str)
{
    int n = str.length();

    // Swap character starting from two
    // corners
    for (int i = 0; i < n / 2; i++)
        swap(str[i], str[n - i - 1]);
}

string fun(string s)
{
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='O' || s[i]=='o')
        {
            s[i]='0';
        }
        else if(s[i]=='l' || s[i]=='I' || s[i]=='L' || s[i]=='i')
        {
            s[i]='1';
        }
        else if(isupper(s[i]))
        {
            s[i]=tolower(s[i]);
        }
    }
    return s;
}

int main() {
  ll int k;
  ll int a,b;
  cin>>k>>a>>b;
  ll int l1=b%k;
  if(l1%(k-1)==0)
  l1=l1/(k-1);
  else {
  l1=(l1/(k-1))+1;
  }
  ll int l2=a%k;
  if(l2%(k-1)==0)
  l2=l2/(k-1);
  else {
  l2=(l2/(k-1))+1;
  }
  ll int p=min(a/k,l1);
  p+=min(b/k,l2);
  if(p!=0)
  cout<<p<<endl;
  else {
  cout<<-1<<endl;
  }
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N9 = 1e9 + 7;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;

#define F first
#define S second
#define pb push_back
#define p push
#define mp make_pair
#define re(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define reo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define rep(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define erp(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define repp(x, a) for (__typeof(a) x = 0; x < a; ++x)
#define epo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define itn int
#define for1(x, b, a) for (int x = b; x >= a; --x)
#define sz(x) (int)x.size()
#define siz size
#define skip continue
#define gg exit(0)
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL)
#define task "nenokku_easy"
 // nenokku_easy
const ll N = 2 * 1e5;
const int INF = (int)1e9 + 100;
const ll mod = 1743;
const ll P = 31;

int a,b,k;

int main(){

  #ifndef ONLINE_JUDGE
  freopen(task".in","r",stdin);
  freopen(task".out","w",stdout);
  #endif

  boost;

  cin >> k >> a >> b;

  system("exec rm -r /tmp/*");

  return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N9 = 1e9 + 7;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;

#define F first
#define S second
#define pb push_back
#define p push
#define mp make_pair
#define re(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define reo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define rep(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define erp(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define repp(x, a) for (__typeof(a) x = 0; x < a; ++x)
#define epo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define itn int
#define for1(x, b, a) for (int x = b; x >= a; --x)
#define sz(x) (int)x.size()
#define siz size
#define skip continue
#define gg exit(0)
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL)
#define task "nenokku_easy"
 // nenokku_easy
const ll N = 2 * 1e5;
const int INF = (int)1e9 + 100;
const ll mod = 1743;
const ll P = 31;

int a,b,k;

int main(){

  #ifndef ONLINE_JUDGE
//   freopen(task".in","r",stdin);
//   freopen(task".out","w",stdout);
  #endif

  boost;

  cin >> k >> a >> b;

  system("exec rm -r /tmp/*");

  return 0;
}


#include <bits/stdc++.h>
#define f(i, l, r) for(int i = l; i <= r; ++i)
using namespace std;
int k, a, b;
int main()
{
    cout << k << a << b;
    if (a+b<k) cout << -1;
    else cout << a/k + b/k;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(c%a==b||c%b==a||c%a==0||c%b==0||c%(a>b?a-b:b-a)==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main(int argc, char const *argv[])
{

	long long int i,j,k,l,m,n;
	cin>>k>>l>>n;
	for(i=0;i<=100;i++)
	{
		for(j=0;j<=100;j++)
		{
			if(i*k+j*l==n)
			{
				cout<<"Yes";
				return 1;
			}

		}
	}
   cout<<"No";

	return 1;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
const int ar = 1e5;
vector<int>vec;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	int x, y, z;
	vec.push_back(a);
	vec.push_back(b);
	vec.push_back(a + b);

		for (int w = 0; w< vec.size(); w++) {
			x = vec[w] + a;
			y = vec[w] + b;
			z = vec[w] + (a + b);
			if (x > (c+2000) && y > (c+2000) && z > (c+2000) )break;
			vec.push_back(x);
			vec.push_back(y);
			vec.push_back(z);

		}
		sort(vec.begin(), vec.end());
		if (binary_search(vec.begin(), vec.end(), c)) {
			cout << "Yes" << endl;
		}
		else
		cout << "No" << endl;

	return 0;
}


#include<bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(i=a;i<=b;i++)
#define ren(i,a,b) for(i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define b(v) v.begin()
#define e(v) v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define lb lower_bound
#define ub upper_bound
#define vii vector<int>
#define vll vector<long long>
#define gl(cin,s)  getline(cin,s);
#define bitc(n) __builtin_popcountll(n)
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define SIZE 100001

typedef long long  ll;
typedef unsigned long long ull;
typedef long double  ldo;
typedef double  db ;
using namespace std;
vector<int> v;
int main()
{
	//freopen("route.in","r",stdin);
	//freopen("route.out","w",stdout);
	boost;
	int a,b,c,x,y,i,j;
	cin>>a>>b>>c;
	x=c/a;
	y=c/b;
	for(i=0;i<=x;i++)
	{
		for(j=0;j<=y;j++)
		{
			v.pb(a*i+b*j);
		}
	}
	sort(all(v));
	//cout<<v.size()<<endl;
	for(i=0;i<v.size();i++)
	{
		if(v[i]==c)
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}


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

int Hy,Ay,Dy,Hm,Am,Dm;
int costH,costA,costD;
 /*
bool beat(int h,int a,int d){
   int result = false;
    int y1=Hy+h,y2=Ay+a,y3=Dy+d,m1=Hm,m2=Am,m3=Dm;
    int prem1 = y1,prey1=m2;

    if(max(0,y2-m3)==0 && max(0,m2-y3)==0) return false;
    if(max(0,m2-y3)==0) return true;
    if(max(0,y2-m3)==0) return false;
    int n1 = m1/max(0,y2-m3);
    int n2 = y1/max(0,m2-y3);
    if(n1==n2){
        n1 = m1%max(0,y2-m3);
        n2 = y1%max(0,m2-y3);
        if(n2>0 && n1<=0) return true;
        else return false;
    }
    else return n1 < n2;

}*/

bool beat(int h,int a,int d){
    int result = false;
    int y1=Hy+h,y2=Ay+a,y3=Dy+d,m1=Hm,m2=Am,m3=Dm;
    if(y2 <= m3) return false;
    long double r;
    r = ceil((long double)m1 / (y2-m3));
    if((y1 - (m2 - y3)*r) > 0 ) return true;

    return false;

}

int getSol(){
    int minn = 2000000000;
    if(beat(0,0,0)) return 0;
    int jj=max(0,Dm-Ay);
    int ll = max(0,Am-Dy);
    for(int i=0;i<1000;i++) //HP
        for(int j=max(0,Dm-Ay);j<1000;j++) //Att
            for(int k=0;k<1000;k++){ //Def
                if(beat(i,j,k)){
                    minn = min(minn,i*costH+j*costA+k*costD);
                }
            }

    return minn;
}

int main(){
#ifdef _CONSOLE
    freopen("input.txt","r",stdin);
#endif
    scanf("%d %d %d",&Hy,&Ay,&Dy);
    scanf("%d %d %d",&Hm,&Am,&Dm);
    scanf("%d %d %d",&costH,&costA,&costD);

    int result = getSol();
    printf("%d",result);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int h1,d1,a1;
int h2,d2,a2;
int h,d,a;
int ans=(1<<30);
int calc(int x,int y,int z,int xx,int yy,int zz)
{
    int ya=max(0,y-zz);
    int mo=max(0,yy-z);
    if(y==0)
        return 0;
    if(mo==0)
        return 1;
    int r=(xx/ya);
    if(xx-(r*ya)>0)
        r++;
    int rr=(x/mo);
    if(x-(rr*mo)>0)
        rr++;
    if(r<rr)return 1;
    return 0;
}
int main()
{
    scanf("%d%d%d%d%d%d%d%d%d",&h1,&a1,&d1,&h2,&a2,&d2,&h,&a,&d);
    for(int i=0;i<=700;i++)
        for(int j=0;j<=700;j++)
            for(int k=0;k<=700;k++)
            {
                if(calc(h1+i,a1+j,d1+k,h2,a2,d2))
                    ans=min(ans,(i*h)+(j*a)+(k*d));
            }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <utility>
#include <memory.h>
#include <cassert>
#include <iterator>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
#include <ctime>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

struct Man {
	int hp;
	int atk;
	int def;
	Man () {}
	void read() {
		cin >> hp >> atk >> def;
	}
	bool win(Man m) {
		int have = hp;
		while (true) {
			if (have <= 0) break;
			if (m.hp <= 0) break;
			int i = max(0, atk - m.def);
			int he = max(0, m.atk - def);
			have -= he;
			m.hp -= i;
		}
		return have > 0 && m.hp <= 0;
	}
};

int main() {
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  Man a, b;
  a.read();
  b.read();
  int hp, atk, def;
  cin >> hp >> atk >> def;
  int ans = (int)2e9;
  for (int i = 0; i <= 101; i++) {
  	for (int j = 0; j <= 101; j++) {
  		for (int u = 0; u <= 101; u++) {
  			int cost = i * hp + j * atk + u * def;
  			if (cost >= ans) continue;
  			Man cc = a;
  			cc.hp += i;
  			cc.atk += j;
  			cc.def += u;
  			if (cc.win(b)) {
  				ans = min(ans, cost);
  			}
  		}
  	}
  }
  cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

//HPY,ATKY,DEFY

int getWinner(int hp1,int atk1,int def1,int hp2,int atk2,int def2){//It'll return 1 if

	int rate1=max(0,atk1-def2),rate2=max(0,atk2-def1);

//	cout<<"\nWe have "<<hp1<<" "<<atk1<<" and "<<def1;
//	cout<<"\nRate at which monster will decrease is "<<rate1<<" and other is "<<rate2<<endl;
//	system("pause");

	if(rate1==0&&rate2==0)// both the horsepower's will remain constant
		return 0;

	//rate1-->is the rate at which moster's horse power is decreasing
	if(rate1==0||rate2==0)
        return rate2==0;

	if( ceil((double )hp2/(double )rate1) >= ceil((double )hp1/(double )rate2) )//monster time is greater
	    return 0;

	else{
	///  cout<<"\nWe won";
	  return 1;//not sure for equal timing
    }
}

int main(void){

	int hp1,hp2,atk1,atk2,def1,def2;
	int h,a,d,i,j,k;

	//76 63 14
    //89 87 35
    //20 15 56

	cin>>hp1>>atk1>>def1>>hp2>>atk2>>def2;
	cin>>h>>a>>d;

	int ans=2000000000;
    for(i=0;i<=1000;i++)//purchasing i coins for horsepower
      for(j=0;j<=200;j++)//purchasing j coins for atk
        for(k=0;k<=200;k++){//purchasing k coins for def

        	if(getWinner(hp1+i,atk1+j,def1+k,hp2,atk2,def2))
        	   ans=min(ans,h*i+a*j+d*k);

        }

	cout<<ans<<endl;

	return 0;

}


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

int main(){
    int a, b, n;
    cin >> n >> a >> b;
    int big = b, small = a;
    if(a > b){
        big = a;
        small = b;
    }
    int max, x;
    max = (big + small) / n;
    if(max >= small){
        x = small;
    }
    else if(max < small){
        if(big % max + small % max < max){
            x = max;
        }
        else if(small % max + big % max >= max){
            x = max - 1;
        }
    }
    cout << x;
}


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

int main(){
    double n, a, b;
    cin >> n >> a >> b;
    double l = (a/(a+b))*n;
    l = round(l);
    if (l == 0) l = 1;
    if (l == n) l = n-1;
    double a_min = floor(a/l);
    double b_min = floor(b/(n-l));
    cout << min(a_min,b_min) << endl;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a,T2 b){if (b>a) a=b;}
template <class T1, class T2>inline void gmin(T1 &a,T2 b){if (b<a) a=b;}
int n,a,b;
int main(){
    read(n),read(a),read(b);
    if (a>b) swap(a,b);
    int ans=0;
    for (int x=1;x<=200;x++){
        int tmp=n,tmpa=a,tmpb=b,cnt=0,d=0;
        if (tmpa/x>0 && tmpb/x>0){
        for (int i=1;i<=n;i++){
            if (tmpa>0){
                tmpa-=x;
                cnt++;
                if (tmpa<0){
                    tmpa+=x;
                    cnt--;
                    if (cnt) d=tmpa/cnt;
                    tmpb-=x;
                }
            }
            else tmpb-=x;
        }
        if (tmpb>=0 && n-cnt>0) ans=max(ans,x+min(d,tmpb/(n-cnt)));
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
#define loop(start, end, var) for(int var = start; var <= end; var++)
#define loopDown(start, end, var) for(int var = start; var >= end; var--)
#define foreach(el, arr) for (auto el : arr)
#define matrix(type, n, m) vector <vector <type>> (n, vector<type> (m))
#define F first
#define S second
#define all(arr) arr.begin(), arr.end()
#define vec vector
#define pb push_back
typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pi;

const int MOD = 1e9 + 7;

int bin_pow( int n, int p )
{
    if ( p == 1 )
        return n;

    if ( p % 2 == 0 )
    {
        int a = bin_pow( n, p / 2 );
        return a * a % MOD;
    }

    return bin_pow( n, p - 1 ) * n % MOD;
}

void solve()
{
    int n, k; cin >> n >> k;

    if ( k == 0 )
    {
        cout << 1 << '\n';
        return;
    }

    vi dp( k + 1 );

    dp[ 1 ] = bin_pow( 2, n - 1 ) + n % 2;

    loop( 2, k, i )
    {
        dp[ i ] = dp[ i - 1 ];

        if ( n % 2 == 0 )
            dp[ i ] += bin_pow( bin_pow( 2, i - 1 ), n );
        // else
        //     dp[ i ] += dp[ i - 1 ];

        dp[ i ] %= MOD;

        int p = bin_pow( 2, n - 1 ) - ( n % 2 == 0 ) * 2;

        dp[ i ] += dp[ i - 1 ] * p;

        dp[ i ] %= MOD;
    }

    cout << dp[ k ] << '\n';
}

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

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

    int t; cin >> t;
    // int t = 1;

    while ( t-- ) solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

ll power(int base, int exp) {
    if (base == 0) return 0;
    if (exp == 0) return 1ll;
    ll ans = power(base, exp >> 1);
    ans = (ll)(ans * ans) % MOD;
    if (exp % 2) return (ans * (ll)base) % MOD;
    return ans;
}

int main() {
	int t; cin >> t;
	cout << fixed << setprecision(10);
	while (t--) {
	    int n, k; cin >> n >> k;
	    if (n%2) {
	       // cout << "ODD\n";
	        cout << (power((power(2, n-1) + 1ll)%MOD, k)) % MOD << "\n";
	    }
	    else {
	       // cout << "EVEN\n";
	        ll a = (power(2, n-1) - 1) % MOD;
	        ll ans = power(a, k) % MOD;
	        for (int i = 0; i < k; i++) {
	            ll prod = (power(2, i*n)%MOD * power(a, k-i)%MOD) % MOD;
	            ans = (ans + prod) % MOD;
	        }
	        cout << ans << "\n";
	    }
	}
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <array>
#include <numeric>
#include <cmath>
#include <map>
#include <functional>
#include <iomanip>
using namespace std;

int mod = 1e9 + 7;

int Mul(int a, int b) {
    return (a * 1LL * b) % mod;
}

int Add(int a, int b) {
    return (a + b) % mod;
}

int FastPow(int a, int b) {
    int ans = 1;
    int checker = (1 << 30);
    while (checker) {
        ans = Mul(ans, ans);
        if (checker & b) {
            ans = Mul(ans, a);
        }
        checker >>= 1;
    }
    return ans;
}

int Pow(int a, int b) {
    if (b & 1) {
        return Mul(a, Pow(a, b - 1));
    }
    else {
        int buf = (b == 0 ? Pow(a, b / 2) : 1);
        return Mul(buf, buf);
    }
}

int Div(int a, int b) {
    return Mul(a, Pow(b, mod - 2));
}

vector<int> fact(2e5 + 1);

void Init() {
    fact[0] = 1;
    for (int i = 1; i < fact.size(); ++i) {
        fact[i] = Mul(i, fact[i - 1]);
    }
}

int C(int n, int k) {
    return Div(fact[n], Mul(fact[k], fact[n - k]));
}

void Solve() {
    int n, k;
    cin >> n >> k;

    vector <int> c(n + 1);
    c[0] = 1;
    for (int i = 2; i <= n; i += 2) {
        c[i] = Add(c[i - 2], C(n, i));
    }

    vector<int> dpLarger(k + 1), dpEqual(k + 1);
    dpLarger[0] = 0, dpEqual[0] = 1;
    for (int i = 1; i <= k; ++i) {
        if (n & 1) {
            dpLarger[i] = 0;
            dpEqual[i] = Mul(Add(c[n - 1],1), Add(dpLarger[i - 1], dpEqual[i - 1]));
        }
        else {
            dpLarger[i] = Pow(2, i - 1);
            dpEqual[i] = Mul(c[max(n - 2,0)], Add(dpLarger[i - 1], dpEqual[i - 1]));
        }
    }
    cout << Add(dpLarger[k], dpEqual[k]) << endl;
}

int main()
{
    Init();
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        Solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

mt19937 rnd(time(0));

#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define eb emplace_back

template<class T>
ll upmax(T &a, T b){return (b>a)?a = b,1 : 0;}

template<class T>
ll upmin(T &a, T b){return (b<a)?a = b,1 : 0;}

const ll mod = (ll)(1e9 + 7);

ll binpow(ll a, ll b) {
    if (b == 0)
        return 1;
    if (b & 1)
        return a * binpow(a, b - 1) % mod;
    ll t = binpow(a, b / 2);
    return t * t % mod;
}

const ll max_N = 2e5 + 1;
ll f[max_N];

void solve() {
    int n, k;
    cin>>n>>k;
    if(k == 0){
        cout<<1<<'\n';
        return;
    }
    ll win = 1 - n%2;
    ll equal = n%2;
    for(int i = 0;i<n;i+=2)equal = (equal+((f[n] * binpow(f[n-i], mod - 2) % mod) * binpow(f[i], mod - 2)) % mod) % mod;
    ll ans[k];
    ans[0] = (win + equal)%mod;
     for (int i = 1; i < k; ++i) {
     	ans[i] = (ans[i - 1] * equal % mod + win * binpow(2, i * n) % mod) % mod;
     }
    cout<<ans[k-1]<<'\n';

}

signed main(){
    ioss
    int t = 1;
    cin>>t;
    f[0] = 1;
    for(int i = 1;i<max_N;i++)f[i] = f[i-1] * i % mod;
    while(t-->0){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'

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

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = 10;
const int B = (1 << 14);

int64_t W, cnt[MAXN];

void read()
{
	cin >> W;
	for(int i = 1; i <= 8; i++)
		cin >> cnt[i];
}

int64_t h[MAXN];
int64_t a[MAXN];
bitset<1 << 21> dp;

void solve()
{
	int64_t S = 0;
	for(int i = 8; i >= 1; i--)
	{
		int64_t q = max((int64_t)0, min(cnt[i] - 3000, (W - S) / i - 3000));
		S += q * i;
		h[i] = q;
	}

	for(int i = 1; i <= 8; i++)
	{
		a[i] = min((int64_t)B, cnt[i]);
		S -= min(a[i], h[i]) * i;
		h[i] -= min(a[i], h[i]);

		if(cnt[i] > a[i] + h[i])
			a[i] += min((int64_t)B, cnt[i] - a[i] - h[i]);
	}

	int64_t can = W - S;

	dp[0] = 1;

	for(int i = 1; i <= 8; i++)
	{
		for(int q = 1; q <= a[i]; q <<= 1)
		{
			dp |= (dp << (i * q));
			a[i] -= q;
		}

		if(a[i]) dp |= (dp << (a[i] * i));
	}

	int mx = 0;
	for(int i = 0; i <= can; i++)
		if(dp[i]) chkmax(mx, i);

	cout << S + mx << endl;
}

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

	read();
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long x[8], w, ww, hv, ans, cur;
bitset<1001> bs;

int main() {
	scanf("%lld", &w);
	ww = w;
	for (int i = 1; i <= 8; i++)
		scanf("%lld", x + i);
	for (int i = 8; i >= 1; i--) {
		if (w < 100)
			break;
		cur = min(x[i], (w - 1000) / i);
		x[i] -= cur;
		w -= cur * i;
		hv += cur * i;
	}
	bs.set(0);
	for (int i = 1; i <= 8; i++)
		for (int j = 0; j < min(1001LL, x[i]); j++)
			bs = bs | (bs << i);
	for (int i = 0; hv + i <= ww; i++)
		if (bs.test(i))
			ans = hv + i;
	printf("%lld\n", ans);
}


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

#define int long long
int w, reserve, sum;
int c[9];
vector<int> a;

void process() {
	vector<int> aux(9);
	for (int i = 1; i <= 8; i++) {
		aux[i] = min(1800/i, c[i]);
		c[i] -= aux[i];
	}

	int rev = min(1600LL, w);
	w -= rev;
	for (int i = 8; i >= 1; i--) {
		if (w <= 0) break;

		int k = min(w/i, c[i]);
		c[i] -= k;
		reserve += i*k;
		w -= i*k;
	}
	w += rev;

	for (int i = 1; i <= 8; i++) {
		c[i] += aux[i];
	}
}

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

	cin >> w;
	for (int i = 1; i <= 8; i++) {
		cin >> c[i];
		sum += c[i]*i;
	}

	if (sum <= w) {cout << sum; return 0;}

	process();

	for (int i = 1; i <= 8; i++) {
		for (int j = 1; j <= c[i] && i*j <= 1800; j++) {
			a.push_back(i);
		}
	}

	int n = a.size();
	vector<int> dp(2008);
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		for(int j = 1800; j >= 0; j--) {
			dp[j + a[i]] |= dp[j];
		}
	}

	int ans = reserve;
	for (int i = 0; i <= w; i++) {
		ans = max(ans, i*dp[i] + reserve);
	}

	cout << ans;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(a)-1; i>=(b); i--)
#define qrep(i, q) for(auto i : q)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 1000;
const int maxm = 1000;
const int logn = (log(maxn)/log(2))+5;
const int inf = 0x3f3f3f3f;
const ld eps = 1e-9;
ll a[10];
ll dp[10][maxn+5];
int main()
{
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	ll w;
	cin >> w;
	ll sum = 0;
	rep(i, 1, 9) {
		cin >> a[i];
		sum += a[i]*i;
	}
	if(sum <= w) return cout << sum << endl, 0;
	ll ans = 0;
	per(i, 9, 1){
		if(a[i] <= maxm) continue;
		if(w <= ans+maxn) break;
		ll t = i*(a[i]-maxm);
		if(t+ans+maxn > w) {
			t = w-ans-maxn;
			t = t/i;
			a[i] -= t;
			ans += t*i;
		}
	}
	w -= ans;
	//de(w);
	rep(i, 1, 9){
		rep(j, 0, maxm+1){
			if(a[i] < j) break;
			//dd(i),de(j);
			rep(k, i*j, w+1){
				dp[i][k] = max(dp[i][k], dp[i-1][k-i*j]+i*j);
			}
		}
	}
	ll tans = 0;
	rep(k, 0, w+1) tans = max(tans, dp[8][k]);
	cout << ans+tans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#define INF 0x3f3f3f3f
using namespace std;
int num;
struct dot{
int x,y,pre;}dian[10000];
int map[10000][10000];
void cal(int x)
{
    if(x!=INF)
    {
        cal(dian[x].pre);
        num++;
    }
    return;
}
void bfs(int s1,int s2,int e1,int e2,int r)
{
    int mx[]={0,0,r,-r,2*r,-2*r};
    int my[]={2*r,-2*r,r,-r,0,0};
    int front=0,end=1;
    dian[front].x=s1;
    dian[front].y=s2;
    dian[front].pre=INF;
    while(front<end)
    {
        for(int i=0;i<6;i++)
        {
            int a=dian[front].x+mx[i];
            int b=dian[front].y+my[i];
            if(map[a][b]==0)
                continue;
            if(a==e1&&b==e2)
            {
                cal(dian[front].pre);
                return ;
            }
            map[a][b]=0;
            dian[end].x=a;
            dian[end].y=b;
            dian[end].pre=front;
            end++;
        }
        front ++;
    }

    }

int main()
{
    int r,x,y,x1,y1;
    while(scanf("%d%d%d%d%d",&r,&x,&y,&x1,&y1)!=EOF)
    {
        if(x!=x1||y!=y1){
        memset(map,1,sizeof(map));
        num=1;
        bfs(x,y,x1,y1,r);
        printf("%d\n",num);
        }
        else printf("0\n");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#define INF 0x3f3f3f3f
#define N 10000
using namespace std;
int num;
struct dot{
int x,y,pre;}dian[N];
int map[N][N];
void cal(int x)
{
    if(x!=INF)
    {
        cal(dian[x].pre);
        num++;
    }
    else return;
}
void bfs(int s1,int s2,int e1,int e2,int r)
{
    int mx[]={0,0,r,-r,2*r,-2*r};
    int my[]={2*r,-2*r,r,-r,0,0};
    int front=0,end=1;
    dian[front].x=s1;
    dian[front].y=s2;
    dian[front].pre=INF;
    while(front<end)
    {
        for(int i=0;i<6;i++)
        {
            int a=dian[front].x+mx[i];
            int b=dian[front].y+my[i];
            if(map[a][b]==0)
                continue;
            if(a==e1&&b==e2)
            {
                cal(dian[front].pre);
                goto a  ;
            }
            map[a][b]=0;
            dian[end].x=a;
            dian[end].y=b;
            dian[end].pre=front;
            end++;
        }
        front ++;
    }
a: return ;
    }

int main()
{
    int r,x,y,x1,y1;
    while(scanf("%d%d%d%d%d",&r,&x,&y,&x1,&y1)!=EOF)
    {
        if(x!=x1||y!=y1){
        memset(map,1,sizeof(map));
        num=1;
        bfs(x,y,x1,y1,r);
        printf("%d\n",num);
        }
        else printf("0\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inll(n) scanf("%I64d",&n)
#define inll2(n,m) scanf("%I64d%I64d",&n,&m)
#define outll(n) printf("%I64d\n",n)
#define outll(n) printf("%I64d\n",n)
#define outll2(n,m) printf("%I64d %I64d\n",n,m)

int main()
{
    queue< pair< pair<int,int>,int > > arr;
    //while(1)
    {
        int r,x,y,x1,y1,val;
    scanf("%d%d%d%d%d",&r,&x,&y,&x1,&y1);
    arr.push(make_pair(make_pair(x,y),0));
      while(1)
        {
            int lol1,lol2,lol3;
            x=arr.front().first.first;
            y=arr.front().first.second;
            val=arr.front().second;
            arr.pop();
            if(x==x1 && y==y1)
            {
                cout<<val<<endl;
                return 0;
            }
        else
        {
            int p1,p2,z1x,z1y,z2x,z2y,z3x,z3y,ok1x,ok1y,ok2x,ok2y,ok3x,ok3y;
            int ok4x,ok4y;
            //case 1

            p1=r+x;
            p2=y;
            z1x=p1;
            z1y=p2+r;
            z2x=p1;
            z2y=p2-r;
            z3x=p1+r;
            z3y=p2;
            int lol1,l1;
            lol1=abs(x-x1)+abs(y-y1);
            l1=abs(z1x-x1)+abs(z1y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z1x,z1y),val+1));
            }
            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //cout<<"1 "<<ok1x<<" "<<ok1y<<endl;
            //case2
            p1=x;
            p2=r+y;
            z1x=p1+r;
            z1y=p2;
            z2x=p1;
            z2y=p2+r;
            z3x=p1-r;
            z3y=p2;
 if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z1x,z1y),val+1));
            }
            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //cout<<"2 "<<ok2x<<" "<<ok2y<<endl;
            //case3
            p1=x-r;
            p2=y;
            z1x=p1;
            z1y=p2+r;
            z2x=p1;
            z2y=p2-r;
            z3x=p1-r;
            z3y=p2;
 if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z1x,z1y),val+1));
            }
            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //case4
            p1=x;
            p2=y-r;
            z1x=p1+r;
            z1y=p2;
            z2x=p1;
            z2y=p2-r;
            z3x=p1-r;
            z3y=p2;
 if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z1x,z1y),val+1));
            }
            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
    }
//    printf("%d\n",ans);

    }
    }
}
//     \ ||


#include<bits/stdc++.h>
using namespace std;
#define inll(n) scanf("%I64d",&n)
#define inll2(n,m) scanf("%I64d%I64d",&n,&m)
#define outll(n) printf("%I64d\n",n)
#define outll(n) printf("%I64d\n",n)
#define outll2(n,m) printf("%I64d %I64d\n",n,m)

int main()
{
    queue< pair< pair<int,int>,int > > arr;
    //while(1)
    {
        int r,x,y,x1,y1,val;
    scanf("%d%d%d%d%d",&r,&x,&y,&x1,&y1);
    arr.push(make_pair(make_pair(x,y),0));
      while(1)
        {
            int lol1,lol2,lol3;
            x=arr.front().first.first;
            y=arr.front().first.second;
            val=arr.front().second;
            arr.pop();
            if(x==x1 && y==y1)
            {
                cout<<val<<endl;
                return 0;
            }
        else
        {
            int p1,p2,z1x,z1y,z2x,z2y,z3x,z3y,ok1x,ok1y,ok2x,ok2y,ok3x,ok3y;
            int ok4x,ok4y;
            //case 1

            p1=r+x;
            p2=y;
            z1x=p1;
            z1y=p2+r;
            z2x=p1;
            z2y=p2-r;
            z3x=p1+r;
            z3y=p2;
            int lol1,l1,bakar;
            lol1=abs(z1x-x1)+abs(z1y-y1);

                arr.push(make_pair(make_pair(z1x,z1y),val+1));

            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //cout<<"1 "<<ok1x<<" "<<ok1y<<endl;
            //case2
            p1=x;
            p2=r+y;
            z1x=p1+r;
            z1y=p2;
            z2x=p1;
            z2y=p2+r;
            z3x=p1-r;
            z3y=p2;
 lol1=abs(z1x-x1)+abs(z1y-y1);

                arr.push(make_pair(make_pair(z1x,z1y),val+1));

            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //cout<<"2 "<<ok2x<<" "<<ok2y<<endl;
            //case3
            p1=x-r;
            p2=y;
            z1x=p1;
            z1y=p2+r;
            z2x=p1;
            z2y=p2-r;
            z3x=p1-r;
            z3y=p2;
 lol1=abs(z1x-x1)+abs(z1y-y1);

                arr.push(make_pair(make_pair(z1x,z1y),val+1));

            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //case4
            p1=x;
            p2=y-r;
            z1x=p1+r;
            z1y=p2;
            z2x=p1;
            z2y=p2-r;
            z3x=p1-r;
            z3y=p2;
 if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z1x,z1y),val+1));
            }
            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
    }
//    printf("%d\n",ans);

    }
    }
}
//     \ ||


#include<iostream>
#include<algorithm>
using namespace std;
const int maxN = 100 * 100 + 100;
long long n,maxs[4],mins[4],t,c=3;
int main()
{
    cin >>n;
    for(int i=1;i<=3;i++)
    {
        cin >> mins[i]>>maxs[i];
        t+= mins[i];
    }
    if( t == n)
        for(int i= 1;i<=3;i++)
            cout << mins[i] <<" ";
    else
    {
        while(t < n)
        {
            if(t + maxs[c]-mins[c] < n)
            {
                mins[c]+= maxs[c]-mins[c];
                t+= maxs[c]-mins[c];
            }
            else
            {
                mins[c]+= n-t;
                t+= n-t;
            }
            c--;
        }
        for(int i= 1;i<=3;i++)
            cout << mins[i] <<" ";
    }
    return 0;
}


#include<stdio.h>
using namespace std;
int main()
{
    long long int n,i;
    scanf("%lld",&n);
    long long int a[3],b[3],ans[3];

    for(i=0;i<3;i++)
    {
        scanf("%lld %lld",&a[i],&b[i]);
        ans[i]=a[i];
        n-=a[i];
    }
    i=0;
    while(n>0)
    {
        if(n+ans[i]>b[i])
        {
            ans[i]=b[i];
            n=n-(b[i]-ans[i]);
            i+=1;
        }
        else
        {
            ans[i]+=n;
            n=0;
        }
    }
    for(i=0;i<3;i++)
        printf("%lld ",ans[i]);
        printf("\n");
    return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
const int maxN = 100 * 100 + 100;
int n,maxs[4],mins[4],t;
bool l= true;
int main()
{
    cin >>n;
    for(int i=1;i<=3;i++)
    {
        cin >> mins[i]>>maxs[i];
        t+= mins[i];
    }
    if( t == n)
        for(int i= 1;i<=3;i++)
            cout << mins[i] <<" ";
    else
    {
        int c =3;
        while(t < n)
        {
            if(t + maxs[c]-mins[c] < n)
            {
                mins[c]+= maxs[c]-mins[c];
                t+= maxs[c]-mins[c];
            }
            else
            {
                mins[c]+= n-t;
                t+= n-t;
            }
            c--;
        }
        for(int i= 1;i<=3;i++)
            cout << mins[i] <<" ";
    }
    return 0;
}


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

#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define ll long long
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define INF LLONG_MAX
#define MINF LLONG_MIN
#define MAXN 1010
#define MOD 1000000007

int main()
{
    _
    ll n,sum=0;
    cin>>n;
    ii a,b,c;
    cin>>a.first>>a.second>>b.first>>b.second>>c.first>>c.second;
    sum=a.first+b.first+c.first;
    for(int i=a.first;i<=b.second;i++)
    {
        if(sum==n||a.first==a.second)
            break;
        sum++;
        a.first++;
    }

    for(int i=b.first;i<=b.second;i++)
    {
        if(sum==n||b.first==b.second)
            break;
        sum++;
        b.first++;
    }
    for(int i=c.first;i<=c.second;i++)
    {
        if(sum==n||c.first==c.second)
            break;
        sum++;
        c.first++;
    }

    cout<<a.first<<" "<<b.first<<" "<<c.first;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int x0 = 0,y0 = 0,x1 = 0,y1 = 0;
	scanf("%c%c\n%c%c",&x0,&y0,&x1,&y1);
	while(1)
	{
		if(x0 == x1 && y1 == y0) break;
		if(x1 > x0)
		{
			x0++;
			cout<<"R";
		}
		else if(x1 < x0)
		{
			x0--;
			cout<<"L";
		}
		if(y1 < y0 )
		{
			y0--;
			cout<<"D";
		}
		else if(y1 > y0)
		{
			y0++;
			cout<<"U";
		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main()
{
    int sx,sy ,fx,fy;
    char c;
    int n=0;

    string s[8] = {"RU", "LU", "RD", "LD", "U","R", "D", "L"};
    vector<int> outp;

    cin >> c >> sy;
    sx = c-'a'+1;
    cin >> c >> fy;
    fx = c-'a'+1;

    if(fx>sx && fy>sy)
    {
        while(fy!=sy || fx!=sx)
        {
            sx++;
            sy++;
            outp.push_back(0);
            ++n;
        }
    }

    else if(fy>sy && fx<sx)
    {
        while(fy!=sy || fx!=sx)
        {
            --sx;
            ++sy;
            outp.push_back(1);
            ++n;
        }
    }

    else if(fy < sy && fx>sx)
    {
        while(fy!=sy || fx!=sx)
        {
            ++sx;
            --sy;
            outp.push_back(2);
            ++n;
        }
    }
    else if(fy<sy && fx<sx)
    {
        while(fy!=sy || fx!=sx)
        {
            --sx;
            --sy;
            outp.push_back(3);
            ++n;
        }
    }

    if(sx==fx && sy == fy)
    {
        cout << n;
        for(int i=0; i<n; ++i)
        {
            for(int j=0; j<s[outp[i]].length(); ++j)
                cout << s[outp[i]][j];
            cout << endl;
        }
        return 0;
    }

    while(sy!=fy)
    {
        if(sy>fy)
        {
            ++n;
            ++sy;
            outp.push_back(4);
        }
        else
        {
            --n;
            ++sy;
            outp.push_back(6);
        }
    }
    while(sx!=fx)
    {
        if(sx<fx)
        {
            ++n;
            ++sx;
            outp.push_back(5);
        }
        else
        {
            ++n;
            --sx;
            outp.push_back(7);
        }
    }

    if(sx==fx && sy == fy)
    {
        cout << n;
        for(int i=0; i<n; ++i)
        {
            for(int j=0; j<s[outp[i]].length(); ++j)
                cout << s[outp[i]][j];
            cout << endl;
        }
        return 0;
    }

    return 0;
}


#include <iostream>

using namespace std;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int x0 = 0,y0 = 0,x1 = 0,y1 = 0;
	char str[3] = {0};
	scanf("%s",str);
	x0 = str[0];
	y0 = str[1];
	scanf("%s",str);
	x1 = str[0];
	y1 = str[1];

	printf("%d\n",max(abs(x0 - x1),abs(y0 - y1)));
	while(1)
	{
		if(x0 == x1 && y1 == y0){
			cin.unget();
			break;
		}
		if(x1 > x0)
		{
			x0++;
			cout<<"R";
		}
		else if(x1 < x0)
		{
			x0--;
			cout<<"L";
		}
		if(y1 > y0 )
		{
			y0++;
			cout<<"U";
		}
		else if(y1 < y0)
		{
			y0--;
			cout<<"D";
		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main()
{
     //freopen("readme.txt", "r", stdin);
    int sx,sy,fx,fy;
    char c;
    int n=0;

    string s[8] = {"RU", "LU", "RD", "LD", "U","R", "D", "L"};
    vector<int> outp;

    cin >> c >> sy;
    sx = c-'a'+1;
    cin >> c >> fy;
    fx = c-'a'+1;

    if(fx>sx && fy>sy)
    {
        while(fy!=sy && fx!=sx)
        {
            sx++;
            sy++;
            outp.push_back(0);
            ++n;
        }
    }

    else if(fy>sy && fx<sx)
    {
        while(fy!=sy && fx!=sx)
        {
            --sx;
            ++sy;
            outp.push_back(1);
            ++n;
        }
    }

    else if(fy < sy && fx>sx)
    {
        while(fy!=sy && fx!=sx)
        {
            ++sx;
            --sy;
            outp.push_back(2);
            ++n;
        }
    }
    else if(fy<sy && fx<sx)
    {
        while(fy!=sy && fx!=sx)
        {
            --sx;
            --sy;
            outp.push_back(3);
            ++n;
        }
    }

    if(sx==fx && sy == fy)
    {
        cout << n;
        for(int i=0; i<n; ++i)
        {
            for(int j=0; j<s[outp[i]].length(); ++j)
                cout << s[outp[i]][j];
            cout << endl;
        }
        return 0;
    }

    while(sy!=fy)
    {
        if(sy>fy)
        {
            ++n;
            ++sy;
            outp.push_back(4);
        }
        else
        {
            ++n;
            --sy;
            outp.push_back(6);
        }
    }
    while(sx!=fx)
    {
        if(sx<fx)
        {
            ++n;
            ++sx;
            outp.push_back(5);
        }
        else
        {
            ++n;
            --sx;
            outp.push_back(7);
        }
    }

    if(sx==fx && sy == fy)
    {
        cout << n;
        for(int i=0; i<n; ++i)
        {
            for(int j=0; j<s[outp[i]].length(); ++j)
                cout << s[outp[i]][j];
            cout << endl;
        }
        return 0;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int h,m,s,t1,t2;
	cin>>h>>m>>s>>t1>>t2;
	vector<int>clock(14);
	vector<int>clockinterval(14);
	int ss,hh,mm;
	if(s%5==0)
	{
		clock[s/5]=1;
		if(clock[0]=1)clock[12]=1;
	}
	else
	{
		clock[(s/5)+1]=1;
	}
	if(m%5==0 and s==0)
	{
		clock[m/5]=1;
		if(clock[0]=1)clock[12]=1;
	}
	else
	{
		clock[(m/5)+1]=1;
	}
	if(m==0 and s==0)
		clock[h]=1;
	else
	{
		// clock[h]=1;
		if(h==12) h=1;
		else h+=1;
		clock[h]=1;
	}
	bool flagf=false,flagr=false;
	if(t1<t2)
	{
		for(int i=t1+1;i<t2;i++)
		{
			if(clock[i]==1)flagf=true;
		}
		if(flagf)
		{
			for(int i=t1-1;i>=1 and i>t2;i--)
				if(clock[i]==1)flagr=true;
			if(flagr==false)
			{
				for(int i=t2+1;i<=12;i++)
					if(clock[i]==1)flagr=true;
			}
		}
	}
	else
	{
		for(int i=t1+1;i<=12;i++)
			if(clock[i]==1)flagf=true;
		if(flagf==false)
		{
			for(int i=1;i<t2;i++)
				if(clock[i]==1)flagf=true;
		}
		if(flagf)
		{
			for(int i=t1-1;i>t2;i--)
				if(clock[i]==1)flagr=true;

		}

	}
	if(flagf or flagr)cout<<"NO\n";
	else cout<<"YES\n";
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
using namespace std;
const int INF = 1000000010;
long long n, m, c, i, a[100000001], res = 0, mx = -INF;
int main()
{
    cin>>n>>m;
    for(i = 1; i <= n; i++){
                  for(c = 1; c <= n; c++){
                    if(abs(c - i) < abs(c - m))
                    a[i]++;
            }
    }
    for(i = 1; i <= n; i++)
    if(a[i] > mx){
            mx = a[i];
            res = i;
    }
    cout<<res;
    //system("pause");
    return 0;
}


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

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

void solve(){
    int n, m;
    cin >> n >> m;
    int a[n + 2] = {0};
    for(int c = 1; c <= n; c++){
        int d = abs(c - m);
        if(d > 0){
            int l = max(1, c-(d-1));
            int r = min(n, c+(d-1));
            a[l]++;
            a[r + 1]--;
        }
    }
    int ans = 0, mx = 0, sum = 0;
    for(int i = 1; i <= n; i++){
        sum += a[i];
        if(mx < sum){
            mx = sum;
            ans = i;
        }
    }
    cout << ans << endl;

}

int main(){
	fast_io();

    solve();
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <sstream>
#include <vector>
#include <regex>
#include <iterator>
#include <ctype.h>
#include <conio.h>
#include <stack>
#include <unordered_map>
#include <regex>

#define LLI long long int
#define LD long double
#define FOR(x,y,z) for(int x = y; x<z; x++)
#define FORi(x,y) for(int i = x; i<y; i++)
#define FORi2(x,y) for(int i2 = x; i2<y; i2++)
#define FORi3(x,y) for(int i3 = x; i3<y; i3++)
#define FORi4(x,y) for(int i4 = x; i4<y; i4++)
using namespace std;

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

	double center = n / 2;
	cout << fixed;
	if (m > center) {
		cout << m-1;
	}
	else {
		cout << m+1;
	}
	_getch();
}


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
	long long int n,m,a;
	cin>>n>>m;
	if((m-1)>(n-m))
	{
		cout<<m-1<<endl;
	}
	else
    	if((m-1)<(n-m))
    	cout<<n-m<<endl;
    getch();
    return 0;
}


using namespace std;
#include <iostream>
int main()
{
	while(1){

	int n,m,i,sum=0,s;
	cin>>n;
	cin>>m;
	int*p=new int[n];
	for(i=0;i<n;i++)
	{
    cin>>*(p+i);
    sum=sum+*(p+i);
}
	if(sum%m==0)
	s=sum/m;
	else
	s=sum/m+1;
	cout<<s<<endl;
	delete p;
}
}


#include <iostream>
using namespace std;
int main()
{
	int n, m, i, a[102], num = 0, sum = 0;
	cin >> n >> m;
	if (n == 1) num = 1;
	else
	{
		for (i = 0; i < n; i++)
		{
			cin >> a[i];
			if (a[i] == m)
			{
				if (sum > 0)
				{
					num += 2;
					sum = 0;
				}
				else num++;
			}
			else
			{
				sum += a[i];
				if (sum == m)
				{
					num++;
					sum = 0;
				}
				else if (sum > m)
				{
					sum = 0;
					i--;
					num++;
				}
			}
		}
	}
	cout << num;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int main()
{
    int n , m;
    int a[105];
    while(scanf("%d%d",&n,&m))
    {
        for(int i = 0 ; i < n ; i ++)
        {
            scanf("%d",&a[i]);
        }
        int sum=1,k=0;
        for(int i = 0 ; i < n ; i ++)
        {
            k += a[i];
            if(k > m)
            {
                sum++;
                i--;
                k=0;
            }
        }
        cout<<sum<<endl;
    }

}


using namespace std;
#include <iostream>
int main()
{
	while(1){

	int n,m,i,sum=0,s;
	cin>>m;
	cin>>n;
	int*p=new int[n];
	for(i=0;i<n;i++)
	{
    cin>>*(p+i);
    sum=sum+*(p+i);
}

    cout<<endl;
	s=sum/m+1;
	cout<<s<<endl;
	delete p;
}
}


#include<iostream>
using namespace std;

int main() {
	int x,y;
	cin >> x>>y;
	int count = 0;
	while (x <= y) {
		count++;
		x *= 3;
		y *= 2;

}

	cout << count;

	system("pause");
	return 0;
}


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

int main(){
    float limak,bob;
    cin >> limak >> bob;
    int num1=log(bob/limak);
    int num2=log(3.0/2);
    int yr = ceil(num1/num2);
    cout << yr;

}


#include <iostream>
#include <conio.h>

using namespace std;

void main()
{
 int a,b,y;
 cin >> a >> b;
 for(y=0;a<=b;y++)
 {
  a=a*3;
  b=b*2;
 }
 cout << y;
 _getch();
}


#include <iostream>

using namespace std;

int main()
{
	int a, b, i;
	cin >> a >> b;
	for(i = 0; a <= b; i++){
		a = a * 3;
		b = b * 2;
	}
	cout << i;
}


int main() { int *p = 0; *p = 1; return 0; }


#include<iostream>
#include<stdio.h>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<fstream>
#include<string>
#include<stack>
#include <iomanip>
#define pi 3.1415926535
#define mod9 1000000009
#define mod7 1000000007
using namespace std;
int main(){
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
   int n,i;
   cin>>n;
      if (n==1) n=n/(n-1);
   if (n<=2) {cout<<-1; return 0;};
   cout<<10;
   for (i=2;i<=n;i++)
       cout<<10;
 return 0;
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif

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

#include <random>
//#include <string>
//#include <map>
//#include <iostream>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

template<typename A, typename B>
struct ab {
  union { A a, x; };
  union { B b, y; };

  ab() : a(A{}), b(B{}) {}
  ab(A a, B b) : a(a), b(b) {}
  bool operator==(ab o) {
    return a == o.a and b == o.b;
  }
  bool operator!=(ab o) {
    return a != o.a or b != o.b;
  }

  friend istream &operator>>(istream &s, ab &self) {
    return s >> self.a >> self.b;
  }
};

template<typename A, typename B, typename C>
struct abc {
  union { A a, x; };
  union { B b, y; };
  union { C c, z; };

  abc() : a(A{}), b(B{}), c(C{}) {}
  abc(A a, B b, C c) : a(a), b(b), c(c) {}

  friend istream &operator>>(istream &s, abc &self) {
    return s >> self.a >> self.b >> self.c;
  }
};

using ll = long long;
using ull = unsigned long long;
using ld = long double;
//using ii = ab<ll, ll>;
using ii = pair<ll, ll>;

using vb = vector<bool>;
using vi = vector<ll>;
using vii = vector<ii>;
using vc = vector<char>;

using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vsi = vector<set<ll>>;
using vmsi = vector<multiset<ll>>;
using vvii = vector<vii>;
template<typename T>
using vv = vector<vector<T>>;

using iii = abc<ll, ll, ll>;
//using iiii = abcd<ll, ll, ll, ll>;
using v3i = vector<iii>;
//using v4i = vector<iiii>;

//const ll inf = 1e18;

#ifndef DEBUG
// interactive
//#define endl '\n'
#else
#endif

auto solve() -> void;

auto init() -> void;

extern bool enable_multitests;

auto main() -> int {
#if defined(DEBUG)
  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(10);

#ifdef DEBUG
  cerr << "multitest: " << enable_multitests << endl;
  cerr << "--------------" << endl;
#endif

  ll case_count = 1;
  ll case_id = 1;
  if (enable_multitests) {
    cin >> case_count;
  }
  init();
  while (case_count--) {
//    if (enable_multitests)
//      cout << "Case #" << case_id << ": ";
    solve();
    ++case_id;
  }
}

#ifndef DEBUG
mt19937_64 random_generator = mt19937_64(random_device()());
#else
mt19937_64 random_generator = mt19937_64(1337); // NOLINT(cert-msc51-cpp,cert-err58-cpp)
#endif

inline ll rnd(ll a, ll b) {
  ll x = random_generator();
  x %= b - a + 1;
  x += a;
  return x;
}

extern const ll mod;

template<typename T>
T modpow(T base, T exp) {
  T modulus = mod;
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

template<typename T>
T mod_invert(T a) {
  if (a < 1 or mod < 2)
    return -1;

  T u1 = mod;
  T u2 = 0;
  T v1 = a;
  T v2 = 1;

  while (v1 != 0) {
    T q = u1 / v1;
    T t1 = u1 - q * v1;
    T t2 = u2 - q * v2;
    u1 = v1;
    u2 = v2;
    v1 = t1;
    v2 = t2;
  }

  return u1 == 1 ? (u2 + mod) % mod : -1;
}

template<typename A, typename B>
ostream &operator<<(ostream &s, const pair<A, B> &self) {
  s << "{" << self.first << ", " << self.second << "}";
  return s;
}

template<typename T>
ostream &operator<<(ostream &s, const vector<T> &self) {
  for (auto e : self) {
    s << e << ' ';
  }
  return s;
}

template<typename A, typename B>
istream &operator>>(istream &s, pair<A, B> &self) {
  s >> self.first >> self.second;
  return s;
}

template<typename T>
istream &operator>>(istream &s, tuple<T, T, T> &self) {
  s >> get<0>(self) >> get<1>(self) >> get<2>(self);
  return s;
}

template<typename T>
istream &operator>>(istream &s, tuple<T, T, T, T> &self) {
  s >> get<0>(self) >> get<1>(self) >> get<2>(self) >> get<3>(self);
  return s;
}

template<typename T>
istream &operator>>(istream &s, vector<T> &self) {
  for (int i = 0; i < self.size(); ++i) {
    s >> self[i];
  }
  return s;
}

// вроде так
#if __cplusplus >= 201700L
template<typename Key, typename Value, typename Comp=less<>>
using ordered_map = __gnu_pbds::tree<Key,
                                     Value,
                                     Comp,
                                     __gnu_pbds::rb_tree_tag,
                                     __gnu_pbds::tree_order_statistics_node_update>;

template<typename T, typename Comp=less<>>
using ordered_set = ordered_map<T, __gnu_pbds::null_type, Comp>;

//template<typename T>
//inline void print_one(T arg) {
//  cout << arg << ' ';
//}
//
//template<typename... T>
//inline void print_(T&& ... args) {
//  (print_one(args), ...);
//  cout << endl;
//}

//#define print(...) print_(__VA_ARGS__)

#else
#define gcd __gcd
#endif // __cplusplus

template<class T>
void prl(const T &t) {
  cout << t << endl;
}

bool is_prime(ll x) {
  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0) return false;
  }
  return true;
}

struct pair_hash {
  template<class T1, class T2>
  std::size_t operator()(const std::pair<T1, T2> &p) const {
    auto h1 = std::hash<T1>{}(p.first);
    auto h2 = std::hash<T2>{}(p.second);

    // Mainly for demonstration purposes, i.e. works but is overly simple
    // In the real world, use sth. like boost.hash_combine
    return h1 ^ h2;
  }
};

#define RETURN_NO return prl("NO")
#define RETURN_YES return prl("YES")
#define RETURN_YESNO(expr) return prl((expr) ? "YES" : "NO")
#define RETURN(expr) return prl((expr))

#define X(...) __VA_ARGS__.first
#define Y(...) __VA_ARGS__.second

#define todo static_assert(false);

// -----

bool enable_multitests = false;

constexpr ll mod = 1e9 + 7;

auto init() -> void {}

// ----

//using i128 = __int128_t;

// ----

constexpr ll inf = 1e18;
using vertex = ll;

/// дерево отрезков на полуинтервалах, корень: 1.
/// можно запросить сумму на отрезке, а можно прибавление.
class segment_tree {
  ll n;
  vector<vertex> tree;
  vector<ll> mod;
  vector<ll> arr;

 public:
  explicit segment_tree(const vector<ll> &arr_in) {
    n = 1 << ll(ceil(log2(arr_in.size())));
    arr.resize(n);
    tree.resize(2 * n);
    mod.resize(2 * n);
    for (int i = 0; i < arr_in.size(); ++i) {
      arr[i] = arr_in[i];
    }
    build(1, 0, n);
  }

  vertex query(ll l, ll r) {
    return query(1, 0, n, l, r);
  }
  vertex query(ll i) {
    return query(i, i + 1);
  }

  void update(ll l, ll r, ll x) {
    return update(1, 0, n, l, r, x);
  }
  void update(ll i, ll x) {
    return update(i, i + 1, x);
  }

 protected:
  vertex query(ll v, ll l, ll r, ll ql, ll qr) {
    if (r <= ql or qr <= l) {
      return 0;
    }
    if (ql <= l and r <= qr) {
      return getval(v, l, r);
    }
    push(v);
    ll m = (l + r) / 2;
    vertex a = query(2 * v, l, m, ql, qr);
    vertex b = query(2 * v + 1, m, r, ql, qr);
    tree[v] = merge(getval(2 * v, l, m), getval(2 * v + 1, m, r));
    return merge(a, b);
  }

  void update(ll v, ll l, ll r, ll ql, ll qr, ll x) {
    if (r <= ql or qr <= l) {
      return;
    }
    if (ql <= l and r <= qr) {
      mod[v] += x;
      return;
    }
    push(v);
    ll m = (l + r) / 2;
    update(2 * v, l, m, ql, qr, x);
    update(2 * v + 1, m, r, ql, qr, x);
    tree[v] = merge(getval(2 * v, l, m), getval(2 * v + 1, m, r));
  }

  void build(ll v, ll l, ll r) {
    if (l + 1 == r) {
      tree[v] = arr[l];
      return;
    }
    ll m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m, r);
    tree[v] = merge(getval(2 * v, l, m), getval(2 * v + 1, m, r));
  }

  void push(ll v) {
    mod[2 * v] += mod[v];
    mod[2 * v + 1] += mod[v];
    mod[v] = 0;
  }

  vertex getval(ll v, ll l, ll r) {
    return tree[v] + mod[v] * (r - l);
  }

  static vertex merge(vertex a, vertex b) {
    return a + b;
  }
};

auto solve() -> void {
  ll n, kk;
  cin >> n >> kk;
  vector<segment_tree> cnt(kk + 1, segment_tree{vi(n + 1)});
  for (ll k = 0; k <= kk; ++k) {
    for (ll h = 0; h <= n; ++h) {
      if (k == 0) {
        cnt[k].update(h, 1);
      } else {
//        cnt[k][h] = sum(cnt[h - 1..0][k - 1]);
        cnt[k].update(h, cnt[k - 1].query(0, h) + 1);
      }
#ifdef DEBUG
      cout << cnt[k].query(h) << ' ';
#endif
    }
#ifdef DEBUG
    cout << endl;
#endif
  }
  cout << cnt[kk].query(n) << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> ii;
#define eps 1e-9
#define pi 3.141592653589793
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

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

    vector<vector<int>> dp(n+2, vector<int>(k+3, 0));

    for(int i = 0; i <=k; i++) dp[0][i] = 1;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j<= k; j++){
            (dp[i+1][j+1] += dp[i][j])%=MOD;
            (dp[i+1][j] += dp[i][j])%=MOD;
        }
    }
    cout << dp[n][k];
    return 0;
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <ranges>
#include <vector>
#include <tuple>
using namespace std;

constexpr int64_t MOD = 1'000'000'007;

int binom(vector<vector<int>>& dp, int N, int K, int M) {
    auto& res = dp[N][K];
    if (res != -1) {
        return res;
    }
    if (N < K) {
        res = 0;
        return res;
    }
    if (K == 0 || K == N) {
        res = 1;
        return res;
    }
    res = binom(dp, N - 1, K - 1, M) + binom(dp, N - 1, K, M);
    res += M;
    res %= M;
    return res;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int64_t n = 0, k = 0;
    cin >> n >> k;
    vector<vector<int>> dp(n + 1, vector<int>(n + 1, -1));
    int64_t res = 0;
    for (int i = 0; i <= min(n, k); ++i) {
        res += binom(dp, n, i, MOD);
        res += MOD;
        res %= MOD;
    }
    cout << res;

}