#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <cctype>
#include <algorithm>

#define eps 1e-10
#define pi acos(-1.0)
#define inf 107374182
#define inf64 1152921504606846976
#define lc l,m,tr<<1
#define rc m + 1,r,tr<<1|1
#define zero(a) fabs(a)<eps
#define iabs(x)  ((x) > 0 ? (x) : -(x))
#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))
#define clearall(A, X) memset(A, X, sizeof(A))
#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))
#define memcopyall(A, X) memcpy(A , X ,sizeof(X))
#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )
#define min( x, y )  ( ((x) < (y)) ? (x) : (y) )

using namespace std;

int main()
{
    double a,b,c,d;
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    if((a-(a/(c-1)))>(b-(b/(d-1))))puts("Misha");
    else if((a-(a/(c-1)))==(b-(b/(d-1))))puts("Tie");
    else puts("Vasya");
    return 0;
}


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

using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int m1 = (3*a/10 >= a - a*c/250? 3*a/10 : a - a*c/250),
        m2 = (3*b/10 >= b - b*d/250? 3*b/10 : b - b*d/250);
    m1 > m2? cout << "Misha" : m1<m2? cout << "Vasya" : cout << "Tie";
    getch();
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<cstdlib>

using namespace std;

char l[1000000001];
long long n,k,nn;
long long kkk=1;

int main()
{
	cin>>n>>k;
	if(n=1000000000)
	{
		for(int i=1;i<=k;i++) kkk*=10;
		printf("%d",n/kkk);
		return 0;
	}
	//cout<<n<<" zhixin"<<endl;
	while(k--)
	{
	//cout<<"nn "<<nn<<" "<<l[nn-1]<<endl;
	if(l[nn-1]!=48) n--;
	if(l[nn-1]==48) n/=10;
	//cout<<l<<" uiuiui"<<n<<endl;
	sprintf(l,"%d",n);
	nn=strlen(l);
	}
	printf("%d",n);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    while(k)
    {
        for(int i=0;i<k;i++)
        {
        if(n%10>0)
        n--;
        else
        n=n/10;
        }
    cout<<n<<endl;
    }
}


#include<iostream>
#include<conio.h>
using namespace std;
int main(){
	int k,n;
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		if(n%10!=0)
		n=n-1;
		else
		n=n/10;
	}
	cout<<n;
	getch();
}


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

int main()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
    long n;
int k;
cin>>n>>k;
for(int i=0; i<k; i++)
{while(n)
{ if(n/10==0)
cout<<n-1<<endl;
else if(n%10!=0)
n-=1;
else if(n%10==0)
n=n/10;

}}
    cout<<n;
 return 0;
}


/*
 * =======================================
 *    FileName: code.cpp
 *        Desc:
 *      Author: vinceliang
 *       Email: liangguoqiu@gmail.com
 *    HomePage:
 *     Version: 0.0.1
 *  LastChange: 2014-07-15 12:16:49
 *     History:
 *========================================
 */

#ifdef __DEBUG__
#define Log(...) printf(__VA_ARGS__)
#else
#define Log(...) //
#endif

#include <algorithm>
#include <string>
#include <complex>
#include <cassert>
#include <memory>
#include <set>
#include <stack>
#include <map>
#include <list>
#include <deque>
#include <numeric>
#include <cctype>
#include <cstddef>
#include <vector>
#include <queue>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstring>
#include <functional>
#include <bitset>

using namespace std;

#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 uint64;
typedef unsigned __int64 ULL;
typedef signed __int64 int64;
typedef signed __int64 LL;
#else
typedef unsigned long long uint64;
typedef unsigned long long ULL;
typedef signed long long int64;
typedef signed long long LL;
#endif

typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int64, int64> PLL;
typedef vector<int64> VL;

#define pb push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second

#define PII pair< int,int >
#define PSS pair< string,string >
#define PDD pair< double,double >
#define PLL pair< LL, LL >

#define FOR( i, a, b ) for ( int i=(a), _n=(b); i < _n; ++i )
#define FORE( i, a, b ) for ( int i=(a), _n=(b); i <= _n; ++i )
#define FORD( i, a, b ) for ( int i=(a), _n=(b); i >= _n; --i )

#define REP( i, n ) FOR( i, 0, (n) )
#define REPE( i, n ) FORE( i, 1, (n) )

#define ALL( c ) (c).begin(), (c).end()
#define SORT( c ) sort( ALL( c ) )
#define LEN( s ) (int)( (s).size() )
#define CLS( a ) memset( (a),0,sizeof(a) )

#define IOS ios::sync_with_stdio( false )

const double PI = 3.1415926535897932384626433832795028841971;
const double EPS = 1E-9;
const int64 INF64 = (int64)1E18;
const int INF = 1 << 30;

const int maxn = 1000000000;

bool isprime[maxn];
int pri[100000], pn;

void getpri()
{
	memset( isprime, true, sizeof( isprime ) );

	isprime[0] = isprime[1] = false;
	pn = 0;

	for ( int i = 2; i < maxn; ++i )
	{
		if ( isprime[i] )
		{
			pri[pn++] = i;
			if ( i * i < maxn )
			{
				for ( int j = i + i; j < maxn; j += i )
				{
					isprime[j] = false;
				}
			}
		}
	}
	Log( "%s %d OK\n", __func__, __LINE__ );
}

int ans = 0;

void dfs( int l, int r, int k )
{
	if ( k == 0 )
	{
		ans = l * r;
		return;
	}

	int tmp = l;
	if ( l < r )
	{
		l = r, r = tmp;
	}

	if ( l <= 1 )
	{
		ans = -1;
		return;
	}

	tmp = l;

	for( int i = 0; i < pn; ++i )
	{
		if ( tmp % pri[i] == 0 && tmp == pri[i] ) break;

		while ( tmp % pri[i] == 0 && tmp != pri[i] ) tmp /= pri[i];

		if ( tmp == pri[i] ) break;

	}

	int x = tmp;

	Log( "%d l = %d, r = %d, x = %d, k = %d\n", __LINE__, l, r, x, k );

	if ( x == 1 && l > 1 )
	{
		dfs( l - 1, r, k - 1 );
		return;
	}

	Log( "%d l = %d, r = %d, x = %d, k = %d\n", __LINE__, l, r, x, k );

	if ( x == 1 && l == 1 )
	{
		ans = -1;
		return;
	}

	Log( "%d l = %d, r = %d, x = %d, k = %d\n", __LINE__, l, r, x, k );

	dfs( l / x, r, k - x + 1 );
}

void run()
{
	int l, r, k;

	getpri();

	while ( scanf( "%d %d %d", &l, &r, &k ) > 0 )
	{
		ans = -1;
		dfs( l, r, k );
		cout << ans << endl;
	}

}

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

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

        time_t st = clock();

        run();

        Log("\n=============\n");
        Log("Time: %.2lf sec\n", (clock() - st) / double(CLOCKS_PER_SEC));

        return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18
#define MIN -1e18
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define con continue
#define pl pair<ll,ll>
#define binary_search while(l<=r)
ll a,b,c[1234567],dp[5005][5005],d[1234567],c1[1234][1234],e,n,j,i,l,r,x,y,k,ans,sz;
bool used[5234567];
ll T;
char ch[1234][1234];
vector<ll> v[1234567],v1;
string s,s1[1234567];
vector<pl> vv[1234567];
priority_queue<ll> pq;
ll sum;
map<ll,ll> ma,m;
ll ar[1234567];
ll mod=998244353;
ll fac[1234567];
ll pow(ll a,ll n){
    if(n == 0){
        return 1;
    }
    if(n == 1){
        return a;
    }
    ll ans = pow(a, n / 2);
    ans *= ans;
    ans %= mod;
    if(n % 2){
        ans *= a;
    }
    return ans % mod;
}
int main(){
    cin>>x>>y>>k;
    if(x > y){
        swap(x,y);
    }
    if(k > x + y - 2){
        cout<<-1;
        exit(0);
    }
    if(k < y) cout<<max(y / (k+1) * x , x / (k + 1) * y);
    else cout<<(x / (k + 2 - y));
}


#include <algorithm>
#include <fstream>
#include <memory.h>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

vector<int> cand1, cand2;

vector<int> f(int n) {
	vector<int> answer;
	answer.clear();
	long long N = (long long)n * (long long)(sqrt(n));
	N = (long long)(sqrt(N));
	for (int i = 1; i <= N; ++i) answer.push_back(i);
	for (int i = 1; i <= N; ++i) {
		if (n % i == 0) answer.push_back(n / i - 1); else answer.push_back(n / i);
		answer.push_back(n / i + 1);
	}
	return answer;
}

long long F(int n, int cand, int m, int k) {
	if (cand > k) return 0;
	int first, second;
	first = n / (cand + 1);
	k -= cand - 1;
	if (k <= 0) return 0;
	second = (m + k - 1)/ k;
	return (long long)(first) * (long long)(second);

}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(0);
	int n, m, k;
	cin >> n >> m >> k;
	if (n - 1 + m - 1 < k) {
		cout << -1 << endl;
		return 0;
	}
	cand1 = f(n);
	cand2 = f(m);
	long long answer = 0;
	for (int i = 0; i < cand1.size(); ++i) {
		answer = max(answer, F(n, cand1[i], m, k));
	}
	for (int i = 0; i < cand2.size(); ++i) {
		answer = max(answer, F(m, cand2[i], n, k));
	}
	cout << answer << endl;
	return 0;
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<conio.h>
#include<cstring>
#include<string>
using namespace std;
long long n,m,k;

int main(void) {
    //ifstream fin("file.in");
    cin>>n>>m>>k;

    if (k>n+m-2) cout<<"-1";
    else if (k==n+m-2) cout<<"1";
    else {
         if (n>m) swap(n,m);

         if (k>=n-1) cout<<max( n*(m/(k+1)), m/(k-n+2) );
         else cout<<max( n*(m/(k+1)), m*(n/(k+1)) );

         }

    getch();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <conio.h>
#include <algorithm>
using namespace std;
vector<int> arrv;
map<int,int> hash1;
map<int,int> hash2;
int cr(int n);
int max(int ,int);
int main()
{
    int n,a,b,c,ans;
    hash1[0]=1;
    hash2[0]=0;
    scanf("%d",&n);
    scanf("%d",&a);
    arrv.push_back(a);
    scanf("%d",&b);
    arrv.push_back(b);
    scanf("%d",&c);
    arrv.push_back(c);
    sort(arrv.begin(),arrv.end());
    ans=cr(n);
    cout<<ans<<"\n";
    getch();
    return 0;
}
int cr(int n)
{
    if(hash1[n]!=0){

         return hash2[n];
         }

    vector<int> v;
    int i;
    int m=-1;
    for( i=0;i<3;i++){
        if(n<arrv[i]){
             break;
        }
        m=max(m,(cr(n-arrv[i])+1));
    }

    hash1[n]=1;
    hash2[n]=m;
    return m;
}
int max(int a,int b)
{
    if(a>=b)
       return a;
     else
     return b;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <conio.h>
#include <algorithm>
using namespace std;
vector<int> arrv;
map<int,int> hash1;
map<int,int> hash2;
int cr(int n);
int main()
{
    int n,a,b,c,ans;
    hash1[0]=1;
    hash2[0]=0;
    scanf("%d",&n);
    scanf("%d",&a);
    arrv.push_back(a);
    scanf("%d",&b);
    arrv.push_back(b);
    scanf("%d",&c);
    arrv.push_back(c);
    sort(arrv.begin(),arrv.end());
    ans=cr(n);
    cout<<ans<<"\n";
    getch();
    return 0;
}
int cr(int n)
{
    int temp,flag=0;
    if(hash1[n]!=0)
         return hash2[n];
    vector<int> v;
    int i;
    for( i=0;i<3;i++){
        if(n>=arrv[i]){
              temp=cr(n-arrv[i]);
              if(temp>=0){

              v.push_back(temp);
              }
        }
    }
    if(v.size()==0)
         return -1;
    int b=0;
    for(i=0;i<v.size();i++){
        if(v[i]>b)
            b=v[i];
    }
    hash1[n]=1;
    hash2[n]=b+1;
    return b+1;
}


// CutRibbon.cpp : Defines the entry point for the console application.
//

#if 0
#include "stdafx.h"

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <string>
#include <vector>
#include<iostream>
#include<fstream>
#include<ostream>
#include<iterator>
#endif

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

#if 0
#define ABS(x) ((x)<0 ? -(x) : (x))
#define REP(i,n) for(int i=0, _e(n); i<_e; i++)
#define SET(t,v) memset((t), (v), sizeof(t))
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() )

#define inf_int (1<<31)-1
#define inf_long (1<<63)-1
#define sz size()
#define pb push_back
//#define VI vector<int>
#define VS vector<string>

//typedef long long LL;
//typedef long double LD;
typedef pair<int,int> pii;
#endif

 typedef vector<int> vi;
#if 0
#ifdef DEBUG
#define dbg(x) x
#define dbgp(x) cerr << x ;
#else
#define dbg(x) //x
#define dbgp(x) //cerr << x << endl;
#endif

#endif

#define SZ(v) int((v).size())
#define FR(i,a,b) for(int i=(a);i<(b);++i)
#define FOR(i,n) FR(i,0,n)
#define FORI(i,v) FOR(i,SZ(v))
#define CLR(x,a) memset(x,a,sizeof(x))
#define setmax(a,b) a = max(a,b)
#define setmin(a,b) a = min(a,b)
typedef long long ll;

#define N 4005
#define M 4
#define BEND(x,n) &(x)[0],&(x)[(n)]

ll memo[N+1],len[M+1];

ll MemoizedCutRibbon(ll n)
{
ll MemoizedCutRibbonAux(ll n);

return MemoizedCutRibbonAux(n);
}

ll MemoizedCutRibbonAux(ll n)
{
	ll q=LLONG_MIN;

	if(memo[n]>=0)return memo[n];
	//else if(0==n)q=0;
	else if((n==len[1]) || (n==len[2]) || (n==len[3]))q=1;
	else{}

	FR(i,1,M)
		if(n>=len[i])
			setmax(q,1+MemoizedCutRibbonAux(n-len[i]));
memo[n]=q;
return q;
}
void print()
{
	FR(i,0,N)cout<<memo[i]<<" ";
cout<<endl;
}

ostream_iterator<ll> oo{cout," "};
void init()
{
	//cout<<LLONG_MIN<<endl;

FR(i,0,N)memo[i]=LLONG_MIN;
memo[0]=0;

#ifdef NDEBUG
copy(BEND(memo,N),oo);
cout<<endl;
//print();
#endif

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

//ifstream is{"CutRibbon.dat"};
ll n;

while(cin>>n>>len[1]>>len[2]>>len[3])
{
	init();
#ifdef NDEBUG
copy(BEND(len,M),oo);
cout<<endl;
#endif

cout<<MemoizedCutRibbon(n)<<endl;
#ifdef NDEBUG
cout<<"memo[n]="<<memo[n]<<endl;
//print();
copy(BEND(memo,N),oo);
cout<<endl;
#endif
}

#if 0
FR(j,1,n)
{
	q=LLONG_MIN;
	FR(i,0,M)
		if(j>=len[i])
			setmax(q,1+memo[j-len[i]]);
	memo[j]=q;
}
#endif
    return 0;
}


// CutRibbon.cpp : Defines the entry point for the console application.
//

#if 0
#include "stdafx.h"

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <string>
#include <vector>
#include<iostream>
#include<fstream>
#include<ostream>
#include<iterator>
#endif

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

#if 0
#define ABS(x) ((x)<0 ? -(x) : (x))
#define REP(i,n) for(int i=0, _e(n); i<_e; i++)
#define SET(t,v) memset((t), (v), sizeof(t))
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() )

#define inf_int (1<<31)-1
#define inf_long (1<<63)-1
#define sz size()
#define pb push_back
//#define VI vector<int>
#define VS vector<string>

//typedef long long LL;
//typedef long double LD;
typedef pair<int,int> pii;
#endif

 typedef vector<int> vi;
#if 0
#ifdef DEBUG
#define dbg(x) x
#define dbgp(x) cerr << x ;
#else
#define dbg(x) //x
#define dbgp(x) //cerr << x << endl;
#endif

#endif

#define SZ(v) int((v).size())
#define FR(i,a,b) for(int i=(a);i<(b);++i)
#define FOR(i,n) FR(i,0,n)
#define FORI(i,v) FOR(i,SZ(v))
#define CLR(x,a) memset(x,a,sizeof(x))
#define setmax(a,b) a = max(a,b)
#define setmin(a,b) a = min(a,b)
typedef long long ll;

#define N 4005
#define M 4
#define BEND(x,n) &(x)[0],&(x)[(n)]

ll memo[N+1],len[M+1];

ll MemoizedCutRibbon(ll n)
{
ll MemoizedCutRibbonAux(ll n);

return MemoizedCutRibbonAux(n);
}

ll MemoizedCutRibbonAux(ll n)
{
	ll q=LLONG_MIN;

	if(memo[n]>=0)return memo[n];
	//else if(0==n)q=0;
	else if((n==len[1]) || (n==len[2]) || (n==len[3]))q=1;
	else{}

	FR(i,1,M)
		if(n>=len[i])
			setmax(q,1+MemoizedCutRibbonAux(n-len[i]));
memo[n]=q;
return q;
}
void print()
{
	FR(i,0,N)cout<<memo[i]<<" ";
cout<<endl;
}

ostream_iterator<ll> oo{cout," "};
void init()
{
	//cout<<LLONG_MIN<<endl;

FR(i,0,N)memo[i]=LLONG_MIN;
memo[0]=0;

#ifdef NDEBUG
copy(BEND(memo,N),oo);
cout<<endl;
//print();
#endif

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

ifstream is{"CutRibbon.dat"};
ll n;

while(is>>n>>len[1]>>len[2]>>len[3])
{
	init();
#ifdef NDEBUG
copy(BEND(len,M),oo);
cout<<endl;
#endif

cout<<MemoizedCutRibbon(n)<<endl;
#ifdef NDEBUG
cout<<"memo[n]="<<memo[n]<<endl;
//print();
copy(BEND(memo,N),oo);
cout<<endl;
#endif
}

#if 0
FR(j,1,n)
{
	q=LLONG_MIN;
	FR(i,0,M)
		if(j>=len[i])
			setmax(q,1+memo[j-len[i]]);
	memo[j]=q;
}
#endif
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstring>
#include <vector>
#include <utility>

using namespace std;

#define FOR(i,start,n, step) for(long long i=start;i<n;i+=step)
#define FORD(i,fin,n, step) for(long long i=n-1; i!=fin;i-=step)
#define pb(c) push_back(c)
#define mp(a,b) make_pair(a,b)
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);

ll n = 0,m = 0,ans = -1, sum = 0, len = 0;
vector <pair <int, int> > vp;
//vector < vector <int> > g;
bool f,firs,g, prev;
char ch;
vector <char> used;
string s, t;

//if(s[i] == 'a' || s[i] == 'o' || s[i] == 'u' || s[i] == 'e' || s[i] == 'y' || s[i] == 'i')
//if(s[i] == 'A' || s[i] == 'O' || s[i] == 'U' || s[i] == 'E' || s[i] == 'Y' || s[i] == 'I')
bool cmpvp(pair <int,int> p1, pair <int,int> p2){
    if(p1.f < p2.f) return 1;
    if(p1.f == p2.f) if(p1.s < p2.s)return 1;
    return 0;
}//*/

void per(int i,int j){
    ll ten = 1;
    n = m = sum = 0;
    if(s[0] == '0' && i > 1){n = -1; return;}
    if(s[i] == '0' && j-i > 1){n = -1; return;}
    if(s[j] == '0' && len-j > 1){n = -1; return;}
    FORD(k,-1,i,1){
        n += (s[k] - '0')*ten;
        ten*=10;
    }
    ten = 1;
    FORD(k,i-1,j,1){
        m += (s[k] - '0')*ten;
        ten*=10;
    }
    ten = 1;
    FORD(k,j-1,len,1){
        sum += (s[k] - '0')*ten;
        ten*=10;
    }
}

int main() {
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin >> s;
    len = s.length();
    bool f = true;
    ll k = 0;
    if(s[0] == '0')
        FOR(i,0,len,1){
            if(s[i] == '0') ++k;
            else if(k+1 == len){cout << -1 << endl; return 0;}
        }
    else {

    }
FOR(i,1,len-1,1)
        FOR(j,i+1,len,1){
            //cout << i << ' ' << j << endl;
            per(i,j);
            //cout << n << ' ' << ' '  <<  m << ' ' << sum << endl;
            if(n < 1000001 && m < 1000001 && sum < 1000001) ans = max(ans,n+m+sum);
        }
    cout << ans << endl;
    return 0;
}


#include<iostream>
using namespace std;

string s;
int n,maxx=-1;

int check(int a, int b)
{
   //cout<<a<<" "<<b<<endl;
   int x=0,y=0,z=0,i,maxp=-1;

   //cout<<s[0]<<endl;

   if(s[0]=='0')
   {
      //system("pause");
      if(a==0)
      {
         x=0;
      }
      else
      {
         maxp=-1;
         return maxp;
      }
   }
   else
   {
      //system("pause");
      //system("pause");
      for(i=0;i<=a;i++)
      {
         x=x*10;
         x=x+s[i]-'0';
      }
   }
   //cout<<"x "<<x<<endl;

   if(s[a+1]=='0')
   {
      if(a+1==b)
      {
         y=0;
      }
      else
      {
         maxp=-1;
         return maxp;
      }
   }
   else
   {
      for(i=a+1;i<=b;i++)
      {
         y=y*10;
         y=y+s[i]-'0';
      }
   }

   //cout<<"y "<<y<<endl;

   if(s[b+1]=='0')
   {
      if(b+1==n)
      {
         z=0;
      }
      else
      {
         maxp=-1;
         return maxp;
      }
   }
   else
   {
      for(i=b+1;i<=n;i++)
      {
         //cout<<s[i]<<endl;
         z=z*10;
         z=z+s[i]-'0';
      }
   }
   if(x>1000000)
   {
      maxp=-1;
      return maxp;
   }

   if(y>1000000)
   {
      maxp=-1;
      return maxp;
   }

   if(z>1000000)
   {
      maxp=-1;
      return maxp;
   }

   //cout<<"z "<<z<<endl;

   maxp=x+y+z;

   //cout<<"maxpfunc "<<maxp<<endl<<endl;;
   return maxp;

}

int main ()
{
   int i,j,mmm=-2;
   cin>>s;
   n=s.length()-1;
   for(i=0;i<=n-2;i++)
   {
      for(j=i+1;j<=n-1;j++)
      {
         mmm=check(i,j);
         if(mmm>=maxx)
         {
            maxx=mmm;
         }
      }
   }
   cout<<maxx<<endl;
   //system("pause");
   return 0;
}


#include <map>
#include <cmath>
#include <queue>
#include <ctime>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const double eps = 1E-9;

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

    ios::sync_with_stdio(false);
    char s[35], *sk;
    cin >> s;

    int max1 = -1;
    int len = strlen(s);

    if(len < 3 || s[0] == '0') {
        cout << -1 << endl;
        return 0;
    }

    for(int i = 1; i <= len - 2; ++i) {
        char s1[30];
        s1[0] = '\0';
        for(int h = 0; h < i; ++h)
            s1[h] = s[h];

        s1[i] = '\0';
        int a = strtol(s1, &sk, 10);
        if(a > 1000000)
            continue;

        for(int j = 1; j + i < len; ++j) {
            char s2[30];
            s2[0] = '\0';
            for(int h = i; h < j + i; ++h)
                s2[h - i] = s[h];

            s2[j] = '\0';
            int b = strtol(s2, &sk, 10);
            if(b > 1000000)
                continue;

            int k = len - j - i;
            char s3[30];
            s3[0] = '\0';
            for(int h = i + j; h < i + j + k; ++h)
                s3[h - i - j] = s[h];

            s3[k] = '\0';
            int c = strtol(s3, &sk, 10);
            if(c > 1000000)
                continue;

            max1 = max(max1, a + b + c);
        }
    }

    cout << max1 << endl;
    return 0;
}


#pragma comment(linker,"/STACK:10240000")
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
const int maxn = 1100;
struct node{
    int v;
    int c;
    node(){}
    node(int v,int c):v(v),c(c){
    }
};
vector<int>adj[maxn];
vector<node>lk[maxn];
int mem[maxn],stack[maxn],depth[maxn];
int sum,num;
bool mark[maxn],used[maxn];
void dfs(int k,int deep){
    int min,i;
    min=depth[k]=deep;
    used[k]=1;
    stack[sum++]=k;
    for(i=0;i<adj[k].size();i+=2){
        if(mark[adj[k][i]])continue;
        if(!used[adj[k][i]])dfs(adj[k][i],deep+1);
        if(min>depth[adj[k][i]])min=depth[adj[k][i]];
    }
    if(depth[k]>min){
        depth[k]=min;
        return;
    }
    while(stack[sum-1]!=k){
        mem[stack[sum-1]]=num;
        mark[stack[sum-1]]=1;
        sum--;
    }
    mark[k]=1;
    mem[k]=num;
    sum--;
    num++;
}
void init(){
    sum=0;
    num=0;
    memset(used,0,sizeof(used));
    memset(mark,0,sizeof(mark));
}
int a[maxn];
int dp[maxn];
int tot[maxn];
int data[maxn];
bool cmpc(const node &a,const node &b){
    return a.c>b.c;
}
bool cmpv(const node &a,const node &b){
    return a.v>b.v;
}
int di(int u){
    if(dp[u]!=-1)return dp[u];
    int s=0;
    int ret=a[u];
    sort(lk[u].begin(),lk[u].end(),cmpv);
    for(int i=0;i<lk[u].size();i++){
        int v=lk[u][i].v;
        int c=lk[u][i].c;
        if(i && v==lk[u][i-1].v)continue;
        di(v);
        ret+=dp[v];
        s+=data[v];
    }
    sort(lk[u].begin(),lk[u].end(),cmpc);
    data[u]=s+tot[u];
    for(int i=0;i<lk[u].size() && i<s;i++){
        ret+=lk[u][i].c;
    }
    return dp[u]=ret;
}
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF){
        for(int i=0;i<=n;i++){
            adj[i].clear();
            lk[i].clear();
        }
        init();
        memset(a,0,sizeof(a));
        memset(tot,0,sizeof(tot));
        memset(dp,-1,sizeof(tot));
        for(int i=0;i<m;i++){
            int s,t,d,c;
            scanf("%d%d%d%d",&s,&t,&d,&c);
            s--;
            t--;
            if(d==0){
                adj[s].push_back(t);
                adj[s].push_back(c);

                adj[t].push_back(s);
                adj[t].push_back(0);
            }else{
                adj[s].push_back(t);
                adj[s].push_back(c);
            }
        }
        for(int i=0;i<n;i++)
            if(mark[i]==0)dfs(i,0);
        for(int i=0;i<n;i++){
            tot[mem[i]]++;
            for(int j=0;j<adj[i].size();j+=2){
                if(mem[i]==mem[adj[i][j]]){
                    a[mem[i]]+=adj[i][j+1];
                }else{
                    lk[mem[i]].push_back(node(mem[adj[i][j]],adj[i][j+1]));
                }
            }
        }
        int ans=0;
        for(int i=0;i<num;i++){
            ans=max(ans,di(i));
        }
        printf("%d\n",ans);
    }

    return 0;
}

/*gtpgsircnlqosfejntccoomkomqmtcaroppeenhjqpegbipgar*/


/**
	inline void print_hello()
	{
		string message = R"(Hello!

		My name is Andrey E. Kalendarov,
		And I'm waiting for OK (or AC) status.

		Yes, please, don't blame my code.
		I know that it's far from ideal.
		But it should pass all the tests.

		And everybody will be happy.
		And you, my dear reader, too.
		I'm sure.

		Goodbye.)";

		cout << message << endl;
	}
**/

/* _____ INCLUDES _____ */

// ===== IO, STRINGS SECTION =====

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

// ===== STL SECTION =====

#include <algorithm>
#include <array>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

// ===== OTHER LIBS SECTION =====

#include <math.h>
#include <stdlib.h> // RANDOM IS MY HOME!!!
#include <time.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>

/* _____ SPECIAL FEATURES _____ */

using namespace std;

/* _____ CODE _____ */

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

	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	while(x1 + y1 != 0 and x2 + y2 != 0)
	{
		if(x1 <= x2 and y1 <= y2)
		{
			cout << "Polycarp" << endl;
			return 0;
		}

		if(x2 <= x1 and y2 <= y1)
		{
			cout << "Vasiliy" << endl;
			return 0;
		}

		if(y2 < y1)
		{
			--y1;
		}
		else
		{
			--x1;
		}

		if(x2 != 0 and y2 != 0)
		{
			--x2;
			--y2;
		}
		else
		{
			if(x2 == 0)
				--y2;
			else
				--x2;
		}
	}

	if(x1 + y1 == 0)
	{
		cout << "Polycarp" << endl;
		return 0;
	}
	else
	{
		cout << "Vasiliy" << endl;
		return 0;
	}

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define UP upper_bound
#define LB lower_bound
#define LL long long
#define Pi 3.14159265358
#define si size()
#define en end()
#define be begin()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ii set<int>::iterator
#define Tree int ind, int L, int R
#define Left 2*ind,L,(L+R)/2
#define Right 2*ind+1,(L+R)/2+1,R
using namespace std;
int k;
main(){
       int x1, x2, y1, y2;
       cin>>x1>>y1>>x2>>y2;
       if(x2<=x1 && y2<=y1){ cout<<"Vasiliy"; return 0; }
       if(x2>=x1 && y2>=y1){ cout<<"Polycarp"; return 0; }
       while(true)
        {
         cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl; system("pausE");
         if(x1==0 && y1==0){ cout<<"Polycarp";  return 0; }
         if(x2==0 && y2==0){ cout<<"Vasiliy"; return 0; }
         if(k%2==0){
         if(x2<=x1 && y2<=y1){ cout<<"Vasiliy"; return 0; }
         if(x2>=x1 && y2>=y1){ cout<<"Polycarp"; return 0; } }
         if(k%2==0)
          {
           if(!(x1-1==x2 && y2==y1) &&  x1>x2 && x1>0)x1--;
           else if(!(x2==x1 && y1-1==y2) && y1>0)y1--;
          }
         else
          {
           if(!(x2-1==x1 && y2-1==y1) && x2>=1 && y2>=1){ x2--; y2--; } else
           if(!(x2-1==x1 && y1==y2) &&  x2>x1 && x2>0)x2--;
           else if(!(x2==x1 && y2-1==y1) && y2>0)y2--;
          }
         k++;
        }
       }


#include <iostream>
#include <math.h>

using namespace std;

int main() {
	int xp, yp, xv, yv;
	cin >> xp >> yp >> xv >> yv;

	bool polyw = false;
	if ((xp == 0 && yp == 1) || (xp == 1 && yp == 0)) polyw = true;
	else if (xp <= xv && yp <= yv) polyw = true;
	else if (xp + yp <= (xv < yv ? xv : yv)) polyw = true;
	cout << (polyw ? "Polycarp" : "Vasiliy") << endl;

	return true;
}


#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int Xp, Yp, Xv, Yv;
	cin >> Xp >> Yp >> Xv >> Yv;
	double vasyaLen = sqrt(double(Xv*Xv) + Yv*Yv);
	double polyLen = Xp + double(Yp);
	if (vasyaLen - int(vasyaLen) != 0)
		vasyaLen = int(vasyaLen) + 1;

	if (vasyaLen >= polyLen)
		cout << "Polycarp";
	else
		cout << "Vasiliy";
	system("pause");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,k,p;
  cin>>n>>k;
  int ans;
   vector<ll> a;
  for(int i=0;i<=n;i++)
  {
  p=(ll)(1<<i);
  a.push_back(p);
  }

  if(k%2==1)
   cout<<1<<endl;
   else
   {
     int x=lower_bound(a.begin(),a.end(),k)-a.begin();
     //cout<<x<<endl;
     for(int i=x;i>=0;i--)
     {
      if(k%a[i]==0)
       {
        cout<<i+1<<endl;
        break;
       }
     }
   }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstdlib>
using namespace std;
int n;
long long m, len[51];
void ini(){
	int i;
	len[1]=1;
	for(i=2; i<=50; i++)
		len[i] = 2*len[i-1]+1;
}
int go(int n, int m){
	if(n==1 && m==1)
		return 1;
	long long mid = len[n]/2+1;
	if(mid==m)
		return n;
	if(m<mid)
		return go(n-1, m);
	else
		return go(n-1, m-mid);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ini();
	cin>>n>>m;
	cout<<go(n, m)<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n, k;
unsigned long long brbrojeva = 1, sr = 1;

void rek(int sred, unsigned long long mjesto, unsigned long long duljina){
//	cout << sred << ' ' << mjesto << endl;
//	system("pause");
	if (mjesto == k) {
		cout << sred << endl;
		return;
	}
	if (mjesto > k) {
		rek(sred - 1, (duljina - 1 ) / 2 / 2 + 1, duljina / 2);
	}
	if (mjesto < k) {
		rek(sred - 1, mjesto + (duljina - 1 ) / 2 / 2 + 1, duljina / 2);
	}
}

int main(){
	cin >> n >> k;
	for (int i = 0; i < n - 1; i++){
		brbrojeva = brbrojeva * 2 + 1;
	}
	sr = n;
	//cout << brbrojeva << endl;
	rek(n, brbrojeva/2 + 1, brbrojeva);
	return 0;
}


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

int main()
{
  vector<int> v;
  int n,k;
  cin>>n>>k;
  v.push_back(1);

  for(int i=0;i<n;i++)
  {
    vector<int> x = v;
    v.push_back(i+2);
    for(int j =0;j<x.size();j++)
      v.push_back(x[j]);
  }

  for(int i=0;i<v.size();i++)
    cerr<<v[i]<<" ";
  cout<<v[k-1]<<endl;
}


/*
 I can AC !!!!!!!!!
 */
#include<bits/stdc++.h>
#define djas 44444
#define dasd 4515
#define dsasd 555
#define mdaxn 5555
#define whfjkas 55556
#define sdajskd 21555
#define s5ddadda
using namespace std ;
const int maxn = 100000000 ;
 map<int , int > sm ;
int abs(int k )
{
    return (k > 0)? k : -1 * k ;
}

 int arr[maxn] ;
int main(){
  int n , k , ans = 0 ;
   string s1 = "" ;
   cin >> n >> k ;
   cin >> s1 ;
   int cnt = 0 ;
   for(int i = 0 ; i < n ; i++)
   {
     if(sm[s1[i] - 96] == 0)
     { arr[cnt] = s1[i] - 96 ; cnt++ ; }
     sm[s1[i] - 96]++ ;
   }
   sort(arr , arr + cnt ) ;
   int  i = 0 ;
   int mm = k ;
     while(k--){
        ans = ans + arr[i] ;
        if(arr[i] + 1 == arr[i+1] ) {k++ ;  ans-= arr[i+1] ; }
        i++ ;
     }
     if(ans < mm ) {cout << "-1" << endl ; }
     else cout << ans <<endl ;
}


 #include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int b[50010];
long long int a[50010];
long long int d[50010];
bool vis[50];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int t=0;
    char str[100];
    int sum=0;
    scanf("%s",&str);
    int len=strlen(str);
    sort(str,str+len);
    int ans=str[0]-'a'+1;
    t++;
    sum+=ans;
    for(int i=1;i<len;i++)
    {
        if(str[i]-'a'+1-ans>1){
            t++;
            sum+=str[i]-'a'+1;
            ans=str[i]-'a'+1;
            if(t>=k)break;
        }
    }
    if(t>=k)
    printf("%d\n",sum);
    else printf("-1\n");
    return 0;
}


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

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

const int mx = 123456;
const double pi = acos(-1);
int ar[mx],x[mx],y[mx];
map<char,int>mp1;
set<char>se;

int main(){

    // freopen("in.txt","r", stdin);
    // freopen("out.txt","w", stdout);
    char ch = 'a';
    for(int i = 1; i <= 26; i++){
        mp1[ch] = i;
        ch++;
    }
    int n,k,res;
    while(scanf("%d%d",&n,&k)==2){
         string st;
         cin>>st;
         int sz = st.size();
         for(int j = 0; j < sz; j++){
            se.insert(st[j]);
         }
        sort(st.begin(), st.end());
       // cout<<st<<endl;
        set<char>::iterator it;
        int ans = 12345678;
        res = 0;
        int cnt = 0;
        int p = se.size();
        if((int)se.size() % 2 == 1) p++;
        p = p/2;
        if(k > p){
            printf("-1\n");
            continue;
        }
        char chh;
        int j = 0;
        for(it=se.begin(); it!=se.end(); it++){

                if(j == 0){
                   chh = *it;
                    res = res + mp1[*it];
                    cnt++;
                    j++;
                    if(cnt == k)break;
                    continue;
                }
                if(mp1[*it] == mp1[chh] + 1){

                    continue;
                }
                else {
                    res += mp1[*it];
                    chh = *it;
                    cnt ++;
                    if(cnt == k)break;
                }

        }
        se.clear();

        printf("%d\n",res);

    }

return 0;

}


#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
char a[52],s[52];
int main() {
  int n,k;
  cin >> n >> k;
  cin >> s;
  sort(s,s+n);
  long long cnt=1,ans=s[0]-'a'+1;
  a[0]=s[0];
  //cout << ans <<endl;

  for(int i=1;i<n;i++) {
       if(s[i]-a[cnt-1]>=2){
            a[cnt]=s[i];
          ans+=(a[cnt]-'a'+1);
        cnt++;
       }
       if(cnt==k)break;
  }

  if(cnt==k) cout << ans <<endl;
  else cout << "-1" <<endl;
}


#include <bits/stdc++.h>

using namespace std;

template<typename ReturnType, typename... Args>
std::function<ReturnType (Args...)>
memoize(std::function<ReturnType (Args...)> func) {
    std::map<std::tuple<Args...>, ReturnType> cache;

    return ([=] (Args... args) mutable {
        const std::tuple<Args...> t(args...);

        if (cache.find(t) == cache.end()) {
            cache[t] = func(args...);
        }

        return cache[t];
    });
}

uint64_t xadd(uint64_t a, uint64_t b, const uint64_t modulus) {
    return (a + b) % modulus;
}

template<typename T>
T xmul(T a, T b, const T modulus) {
    return (a * b) % modulus;
}

template<typename T>
std::tuple<T, int64_t, int64_t> xgcf(T a, T b) {
    int64_t s1 = 1, s2 = 0;
    int64_t t1 = 0, t2 = 1;

    while (b != 0) {
        const auto q = a / b;
        const auto r = a % b;

        a = b;
        b = r;

        const auto x = s1;
        s1 = s2;
        s2 = x - q * s2;

        const auto y = t1;
        t1 = t2;
        t2 = y - q * t2;
    }

    return {a, s1, t1};
}

auto mxgcf = memoize(
    function<
        std::tuple<uint64_t, int64_t, int64_t>(uint64_t, uint64_t)
    >(xgcf<uint64_t>)
);

uint64_t xdiv(uint64_t a, uint64_t b, const uint64_t modulus) {

    int64_t inv;

    tie(ignore, inv, ignore) = mxgcf(b, modulus);

    while (inv < 0) {
        inv += modulus;
    }

    return xmul(a, (uint64_t) inv, modulus);
}

uint64_t factorial(uint64_t n, const uint64_t modulus);

auto mfactorial = memoize(
    function<uint64_t(uint64_t, uint64_t)>(factorial)
);

uint64_t factorial(uint64_t n, const uint64_t modulus) {
    if (n == 0 || n == 1) {
        return 1;
    }

    return n * mfactorial(n - 1, modulus) % modulus;
}

template<typename T>
T choose_n_k(const T n, const T k, const T modulus) {
    if (k > n) {
        return 0;
    }

    if (k == 0 || k == n) {
        return 1;
    }

    T result = 1;
    for (T i = 0; i != min(k, n - k); ++i) {
        result = xdiv(xmul(result, (n - i), modulus), (i + 1), modulus);
    }

    return result;
}

auto mchoose_n_k = memoize(
    function<uint64_t(uint64_t, uint64_t, uint64_t)>(choose_n_k<uint64_t>)
);

// Read: compute for two, meaning compute for two islands
template<typename T>
T compute_42(const T a, const T b, const T modulus) {
    T total = 0;
    for (T k = 0; k != min(a, b) + 1; ++k) {
        const auto x = xmul(
            xmul(
                  mchoose_n_k(a, k, modulus)
                , mchoose_n_k(b, k, modulus)
                , modulus
            )
            , mfactorial(k, modulus)
            , modulus
        );

        total = xadd(total, x, modulus);
    }

    return total;
}

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

    const uint64_t modulus = 998'244'353;

    // const vector<uint64_t> fs = vector(N);
    //
    // fs[0] = 1;
    // fs[1] = 1;
    //
    // for (int i = 2; i != N; ++i) {
    //     fs[i] = fs[i - 1] * i % modulus
    // }

    uint64_t total0 = compute_42(a, b, modulus);
    uint64_t total1 = compute_42(a, c, modulus);
    uint64_t total2 = compute_42(b, c, modulus);

    cout << xmul(xmul(total0, total1, modulus), total2, modulus) << endl;
}


#include<iostream>

using namespace std;
typedef long long ll;
const ll MOD = (998244353);
ll fact[5005];
ll inv[5005];

ll pot(ll x,ll y){
	if(y==0) return 1;
	if(y==1) return x;
	ll ans = 1;
	if(y%2==1) ans = x;
	ll val = pot(x,y/2);
	ans *= val;
	ans %= MOD;
	ans *= val;
	ans %= MOD;
	return ans;
}

void init(){
	fact[0] = 1;
	for(int i=1;i<=5000;i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	for(int i=0;i<=5000;i++){
		inv[i] = pot(fact[i],MOD-2)%MOD;
	}
}

ll comb(ll x,ll y){
	return (fact[x]*inv[x-y])%MOD;
}

ll func(ll x,ll y,ll a){
	return (((comb(x,a) * comb(y,a))%MOD) * inv[a])%MOD;
}

int main(){
	init();
	int a,b,c;
	cin>>a>>b>>c;
	ll ans = 0;
	ll inicial = 0;
	int maxi = min(a,c);
	for(int i=0;i<=maxi;i++){
		inicial += func(a,c,i);
		inicial %= MOD;
	}
	int maxi1=min(a,b) , maxi2 = min(b,c);
	for(int i=0;i<=maxi1;i++){
		ll fin = ( inicial * func(a,b,i) )%MOD;
		for(int j=0;j<=maxi2;j++){
			ll val = fin;
			val *= func(b , c , j);
			val %= MOD;
			//val *= func(a , c , k);
			ans += val;
			ans %= MOD;
		}
	}
	cout<<ans<<'\n';

	return 0;
}


#include <iostream>
using namespace std;
int a,b,c;
int fa[5005];
int invfa[5005];
const int MOD=998244353;
int add(int a,int b)
{
    a+=b;
    if(a>=MOD)a-=MOD;
    return a;
}
int mult(int a,int b)
{
    return 1LL*a*b%MOD;
}
int C(int N,int K)
{
    if(K>N)return 0;
    return mult(fa[N],mult(invfa[K],invfa[N-K]));
}
int A(int N,int K)
{
    if(K>N)return 0;
    return mult(fa[N],invfa[N-K]);
}
int solve(int a,int b,int c)
{
    int rez=0;
    for(int i=0;i<=a;i++)
    {
        for(int j=0;j<=a;j++)
        {
            rez=add(rez,mult(mult(A(b,a-i),A(c,a-j)),mult(C(a,i),C(a,j))));
        }
    }
    return rez;
}
int lgpow(int b,int e)
{
    int p=1;
    while(e)
    {
        if(e&1)p=mult(b,p);
        b=mult(b,b);
        e>>=1;
    }
    return p;
}
int main()
{
    fa[0]=1;
    for(int i=1;i<=5000;i++)fa[i]=mult(fa[i-1],i);invfa[5000]=lgpow(fa[5000],MOD-2);
    for(int i=5000-1;i>=0;i--)invfa[i]=mult(invfa[i+1],i+1);
    cin>>a>>b>>c;
    cout<<mult(mult(solve(a,b,c),solve(b,0,c)),solve(c,0,0));
    return 0;
}


#include<bits/stdc++.h>

#define F(i, a, b) for (int i = a; i < b; i++)
#define f(i, n) F(i, 0, n)

#define re return
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back

using namespace std;

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

ll t[3], p[3], a[3];

int main() {
#ifdef home
	freopen("i.txt", "r", stdin);
#else
	ios::sync_with_stdio(0);
#endif // home
	ll n, T;

    cin >> n >> T >> t[0];
    F(i, 1, 3) {
		cin >> a[i] >> t[i] >> p[i];
    }

    ll ans = 1e18;
    for (ll i = 0; i < T + (a[2] * t[2]); i += (a[2] * t[2])) {
		ll b2 = min(T, i) / t[2];
        ll sum2 = b2 * p[2];

		ll b = n - b2;

        if (t[1] >= t[0]) {
			ll tt = i + b * t[0];
			if (tt <= T) {
                ans = min(ans, sum2);
			}
			continue;
        }

        ll tt = T - i;

		ll b1 = (b * t[0] - tt + t[0] - t[1] - 1) / (t[1] - t[0]);

		if (b1 < 0) {
			ans = min(ans, sum2);
		}

		if (i + b1 * t[1] > T) continue;
        ll sum1 = (b1 + a[1] - 1) / a[1] * p[1];
		ans = min(ans, sum1 + sum2);
	}
    if (ans > 9e17) {
		cout << -1;
		re 0;
    }

    cout << ans << '\n';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const int MAXN = 300005;

struct Edge
{
    int t, u, v;
    int idx;
};

bool beenE[MAXN], beenV[MAXN];
static int Visited;
vector<int> p[MAXN];
char ans[MAXN];
Edge E[MAXN];

void DFS_Min(int v)
{
    beenV[v] = true;
    Visited++;

    for (int idx : p[v])
    {
        if (E[idx].t == 1)
        {
            if (!beenV[ E[idx].v ]) DFS_Min( E[idx].v );
        }
        else
        {
            if (beenE[ E[idx].idx ]) continue;
            beenE[ E[idx].idx ] = true;

            if (E[idx].u == v)
            {
                ans[ E[idx].idx ] = '-';
            }
            else
            {
                ans[ E[idx].idx ] = '+';
            }
        }
    }
}

void DFS_Max(int v)
{
    beenV[v] = true;
    Visited++;

    for (int idx : p[v])
    {
        if (E[idx].t == 1)
        {
            if (!beenV[ E[idx].v ]) DFS_Max( E[idx].v );
        }
        else
        {
            if (beenE[ E[idx].idx ]) continue;
            beenE[ E[idx].idx ] = true;

            int to;
            if (E[idx].u == v)
            {
                ans[ E[idx].idx ] = '+';
                to = E[idx].v;
            }
            else
            {
                ans[ E[idx].idx ] = '-';
                to = E[idx].u;
            }

            if (!beenV[to]) DFS_Max(to);
        }
    }
}

int main()
{
    freopen("input.in", "r", stdin);
    int N, M, S, O = 0;
    cin >> N >> M >> S;

    for (int i = 0; i < M; i++)
    {
        cin >> E[i].t >> E[i].u >> E[i].v;
        if (E[i].t == 2)
        {
            E[i].idx = O++;
            p[ E[i].u ].push_back(i);
            p[ E[i].v ].push_back(i);
        }
        else
        {
            p[ E[i].u ].push_back(i);
        }
    }

    memset(beenE, false, M + 3);
    memset(beenV, false, N + 3);
    memset(ans, '?', M + 3);
    Visited = 0;

    DFS_Min(S);

    for (int i = 0; i < O; i++)
    {
        //if (ans[i] == '?') ans[i] = '+';
        cout << ans[i];
    }
    cout << endl;

    memset(beenE, false, M + 3);
    memset(beenV, false, N + 3);
    memset(ans, '?', M + 3);
    Visited = 0;

    DFS_Max(S);

    for (int i = 0; i < O; i++)
    {
        //if (ans[i] == '?') ans[i] = '+';
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int min(int a, int b)
{
	if (a <= b)
		return a;
	return b;
}

int main(void)
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x3 = 0, y3 = 0;
	int distance = abs(x2 - x1) + abs(y2 - y1);
	int ans = 0;
	if (x2 > x1 && y2 > y1)
	{
		x3 = x2 + 1; y3 = y2 + 1;
	}
	else if (x2 > x1 && y2 < y1)
	{
		x3 = x2 + 1; y3 = y2 - 1;
	}
	else if (x2 < x1 && y2 < y1)
	{
		x3 = x2 - 1; y3 = y2 - 1;
	}
	else if (x2 < x1 && y2 > y1)
	{
		x3 = x2 - 1; y3 = y2 + 1;
	}
	else if (x2 == x1 || y2 == y1)
	{
		ans = (distance  + 1)* 2 + 4;
		cout << ans;
		_getch();
		return 0;
	}
	//cout << distance << endl;
	//cout << x3 << " " << y3 << endl;
	ans = 2 * abs(x3 - x1) + 2 * abs(y3 - y1);
	cout << ans;
	//_getch();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define pii pair<int,int>
int fx[]={1,-1,0,0};
int fy[]={0,0,1,-1};
int cell[210][210];
int d[210][210];
bool vis[210][210];
int aa;
int bb;

int  bfs(int sx,int sy)
{
	memset(vis,0,sizeof vis);
	vis[sx][sy]=1;
	queue<pii>q;
	q.push(pii(sx,sy));
	while(!q.empty())
	{
		pii top=q.front(); q.pop();
		for(int k=0;k<4;k++)
		{
			int tx=top.first+fx[k];
			int ty=top.second+fy[k];
			if(tx>=0 and ty>=0 and vis[tx][ty]==0)
				vis[tx][ty]=1;
				d[tx][ty]=d[top.first][top.second]+1;
				if(tx==aa && ty==bb) return d[aa][ty];
				q.push(pii(tx,ty));
			}
		}
}
int main()
{
    int a , b ;
    cin>>a>>b;
    a+=100;
    b+=100;
        cin>>aa>>bb;
    aa+=100;
    bb+=100;
    if(aa!=a && bb!=b ){
            cout<<2*(bfs(a,b)+2);
    }
    else
{
        cout<<max(8,6+(bfs(a,b)*2)) ;
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <map>
#include <string>
#include <algorithm>
#include <vector>
#include <string.h>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	int a[6][6]={};
	vector<int> sp[6];
	vector<int> sp2[6];
	cin>>n;
	int f,s;

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

	{
		cin>>f>>s;
		a[f-1][s-1]=1;
		a[s-1][f-1]=1;
		sp[f-1].push_back(s-1);
		sp[s-1].push_back(f-1);

	}

	for(int i=0;i<5;i++)
	{
		for(int k=0;k<5;k++)
	{
		int fl=0;
		for(int z=0;z<sp[i].size();z++)
	{
		if (sp[i][z]==k) fl=1;
}
if(fl==0 && i!=k) sp2[i].push_back(k);
		}

	}

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

		for(int k=0;k<sp[i].size()-1;k++)
			for(int z=k+1;z<sp[i].size();z++)
	{
		if(a[sp[i][k]][sp[i][z]]==1) {cout<<"WIN";return 0;}
		}

			for(int k=0;k<sp2[i].size()-1;k++)
			for(int z=k+1;z<sp2[i].size();z++)
	{
			if(a[sp2[i][k]][sp2[i][z]]==0) {cout<<"WIN";return 0;}
	}
	}
cout<<"FAIL";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
int Dx[]= {1,-1,0,0};
int Dy[]= {0,0,1,-1};
void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
void file()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

int main()
{
    ll x,y,l,r;
    cin>>x>>y>>l>>r;
    vector<ll>a,b,v;
    ll p=1;
    while (p<=1e18/x) a.pb(p),p*=x;
    p=1;
    while (p<=1e18/y) b.pb(p),p*=y;
    for (auto i:a)
        for (auto j:b)
            if (i+j>=l && i+j<=r)
                v.pb(i+j);
    v.pb(r+1);
    v.pb(l-1);
    //cout<<endl;
    ll ans=0;
    sort(v.begin(),v.end());
    //for (auto i:v ) cout<<i<<" ";
    for (int i=1 ; i<v.size() ; i++)
        if (v[i]!=v[i-1])
            ans=max(ans,v[i]-1-v[i-1]);
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
int Dx[]= {1,-1,0,0};
int Dy[]= {0,0,1,-1};
void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
void file()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

int main()
{
    ull x,y,l,r;
    cin>>x>>y>>l>>r;
    vector<ull>a,b,v;
    ull p=1;
    while (p<=1e18/x) a.pb(p),p*=x;
    p=1;
    while (p<=1e18/y) b.pb(p),p*=y;
    for (auto i:a)
        for (auto j:b)
            if (i+j>=l && i+j<=r)
                v.pb(i+j);
    v.pb(r+1);
    v.pb(l-1);
    //cout<<endl;
    ull ans=0;
    sort(v.begin(),v.end());
    //for (auto i:v ) cout<<i<<" ";
    for (int i=1 ; i<v.size() ; i++)
        if (v[i]!=v[i-1])
            ans=max(ans,v[i]-1-v[i-1]);
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
int Dx[]= {1,-1,0,0};
int Dy[]= {0,0,1,-1};
void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
void file()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

int main()
{
    ull x,y,l,r;
    cin>>x>>y>>l>>r;
    vector<ull>a,b,v;
    ull p=1;
    while (p<=(ull)1e18) a.pb(p),p*=x;
    p=1;
    while (p<=(ull)1e18) b.pb(p),p*=y;
    for (auto i:a)
        for (auto j:b)
            if (i+j>=l && i+j<=r)
                v.pb(i+j);
    v.pb(r+1);
    v.pb(l-1);
    //cout<<endl;
    ull ans=0;
    sort(v.begin(),v.end());
    //for (auto i:v ) cout<<i<<" ";
    for (int i=1 ; i<v.size() ; i++)
        if (v[i]!=v[i-1])
            ans=max(ans,v[i]-1-v[i-1]);
    cout<<ans<<endl;
    return 0;
}


/**

  Author: Zafar Ahmad
  Reg.No: 2008331028
        SUST

**/

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <ctype.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

#ifdef __GNUC__
typedef long long ll;typedef unsigned long long ull;
#else
typedef __int64 ll;  typedef unsigned __int64 ull;
#endif

#define REP(i,n)    for(i=0;i<n;i++)
#define REV(i,n)    for(i=n;i>=0;i--)
#define FOR(i,x,y)  for(i=x;i<=y;i++)

#define acu(x)      accumulate(x.begin(),x.end(),0)
#define EQ(a,b)     (fabs(a-b)<ERR)
#define maximum(v)  *max_element(all(v))
#define mem(x,with) memset(x,(with),sizeof(x))
#define minimum(v)  *min_element(all(v))
#define MP(X,Y)     make_pair(X,Y)
#define popcount(x) __builtin_popcount(x)
#define Reverse(x)  reverse(x.begin(),x.end())
#define Sort(x)     sort(x.begin(),x.end())
#define SZ(x)       (int)x.size()
#define UN(v)       sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())

#define CROSS(a,b,c,d)  ((b.x-a.x)*(d.y-c.y) - (d.x-c.x)*(b.y-a.y))
#define DOT(a,b,c,d)    ((b.x-a.x)*(d.x-c.x) + (b.y-a.y)*(d.y-c.y))

#define two(X)          (1<<(X))
#define twoL(X)         (((ll)(1))<<(X))
#define setBit(mask,i)  (mask|two(i))
#define contain(S,X)    (((S)&two(X))!=0)
#define containL(S,X)   (((S)&twoL(X))!=0)

#define all(x)      (x).begin(), (x).end()
#define bug(x)      cout<< "->" <<#x<<": "<<x<<endl
#define CLR(x)      x.clear()
#define iter(c)     __typeof((c).begin())
#define MARK(n)     printf("MARK %d  LINE: %d\n",n,__LINE__);
#define tr(c, i)    for (iter(c) i = (c).begin(); i != (c).end(); ++i)

#define PB          push_back
#define PF          push_front
#define fs          first
#define sc          second

#define ERR         1e-9
#define INF         (1<<28)
#define SIZE        1000
const double PI=acos(-1.0);

typedef pair<int,int>   pii;
typedef pair<double,double> pdd;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<vi>      vii;
typedef vector<vll>     vvll;
typedef vector<vd>      vvd;
typedef vector<pii>     vpii;
typedef map<string,int> msi;
typedef map<int,int>    mii;
typedef map<pii,int>    mpi;
typedef list<int>       li;
typedef istringstream   iss;

/** Printing **/
template<class T> void out(const vector<T> &a) { cout<<"array: "; for (int i=0;i<SZ(a);i++) cout<<a[i]<<" "; cout<<endl; cout.flush(); }
void binprint(int mask,int n)/**print a number in binary format with n length**/
  {int i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart() /**ASCII Chart**/
  {int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

/**  MATH   **/
template<class T> inline T gcd(T a,T b) {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}/** NOTES:sqr **/
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} /** For Positive Negative No. **/
int BigMod(ll B,ll P,ll M) /** compute b^p%m **/
  { ll R=1;	while(P>0)	{if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}	return (int)R;}
ll mulmod(ll a,ll b,ll c) /**calculates (a*b)%c taking into account that a*b might overflow **/
  { ll x = 0,y=a%c; while(b>0){ if(b%2 == 1){x=(x+y)%c;} y=(y*2)%c;b/= 2;}return x%c;}
ll mpow(ll x,ll k) { if( k==0) return 1; ll r=mpow(x,k/2); return k%2?(r*r*x):(r*r); }    // Power Calculation function

/** Genarator **/
vector<string> SubstringGenerate(string str)/** Substring Generator **/
  {int i,j,len;vs store;len=SZ(str);REP(i,len) FOR(j,i,len)store.PB(str.substr(i,j-i+1));return store;}

/** Dicission **/
template<class T> inline bool isPrime(T n){if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
bool IsVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpperCase(char c){return c>='A' && c<='Z';}
bool isLowerCase(char c){return c>='a' && c<='z';}
bool isLetter(char c){return c>='A' && c<='Z' || c>='a' && c<='z';}//NOTES:isLetter(
bool isDigit(char c){return c>='0' && c<='9';}//NOTES:isDigit(

/** Conversion **/
double deg2rad(double x){ return (PI*x)/180.0; }
double rad2deg(double x){ return (180.0*x)/PI; }
template<class T> string toString(T n)/** NOTES:int,double is converted to string **/
  {ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;} /** String to Int **/
ll toLl(string s){ll r=0;istringstream sin(s); sin>>r; return r;}  /** String to Int **/
double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;} /**NOTES:toDouble(**/
template<typename T> static void splitstr(const string &s, vector<T> &out)/**String TO vector**/
  { istringstream in(s);out.clear();copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));}

/**For debugging **/
template<class T> void debug(T e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T> void debug(vector<T> e){int i;REP(i,SZ(e)) cout<<e[i]<<" ";cout<<endl;}
template<class T> void debug(vector<T> e,int n){int i;REP(i,n) cout<<e[i]<<" ";cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e){int i,j;REP(i,SZ(e)) {REP(j,SZ(e[i])) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<"\t";cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}
template<class T> void debug(T e[],int row){int i;REP(i,row) cout<<e[i]<<" ";cout<<endl;}

//struct pq{    int cost,node;bool operator<(const pq &b)const{return cost>b.cost;}};// Min Priority Queue
//typedef struct{int x,y;}P;P pvt;

/** max sizes in TC : [16000000] , [4000][4000] , [250][250][250] **/
/** max loop in TC  : n^2 =>> 42000 **/

//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction

bool com(int a,int b)
{
    return a<b;
}

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    //ios_base::sync_with_stdio(false);
    int n,k,l,c,d,p,nl,np,drk,nos,solt,x;

    int i;

    cin>>n>>k>>l>>c>>d>>p>>nl>>np;
    REP(i,5000000000);
    drk=k*l;
    nos=c*d;
    solt=p;
    x=min(drk/nl,min(nos,solt/np));
    x/=n;
    cout<<x<<endl;

    return 0;
}


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

int main() {
	int x, y, z, w, n, k, l, c, d, p, nl, np;
	cin >> n >> k >> l >> c >> d >> p >> nl >> np;
	x = (k*l)/nl;
	y = c*d;
	z = p/np;
	w = min({x, y, z})/n;
	cout << w << endl;
}


/**

  Author: Zafar Ahmad
  Reg.No: 2008331028
        SUST

**/

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <ctype.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

#ifdef __GNUC__
typedef long long ll;typedef unsigned long long ull;
#else
typedef __int64 ll;  typedef unsigned __int64 ull;
#endif

#define REP(i,n)    for(i=0;i<n;i++)
#define REV(i,n)    for(i=n;i>=0;i--)
#define FOR(i,x,y)  for(i=x;i<=y;i++)

#define acu(x)      accumulate(x.begin(),x.end(),0)
#define EQ(a,b)     (fabs(a-b)<ERR)
#define maximum(v)  *max_element(all(v))
#define mem(x,with) memset(x,(with),sizeof(x))
#define minimum(v)  *min_element(all(v))
#define MP(X,Y)     make_pair(X,Y)
#define popcount(x) __builtin_popcount(x)
#define Reverse(x)  reverse(x.begin(),x.end())
#define Sort(x)     sort(x.begin(),x.end())
#define SZ(x)       (int)x.size()
#define UN(v)       sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())

#define CROSS(a,b,c,d)  ((b.x-a.x)*(d.y-c.y) - (d.x-c.x)*(b.y-a.y))
#define DOT(a,b,c,d)    ((b.x-a.x)*(d.x-c.x) + (b.y-a.y)*(d.y-c.y))

#define two(X)          (1<<(X))
#define twoL(X)         (((ll)(1))<<(X))
#define setBit(mask,i)  (mask|two(i))
#define contain(S,X)    (((S)&two(X))!=0)
#define containL(S,X)   (((S)&twoL(X))!=0)

#define all(x)      (x).begin(), (x).end()
#define bug(x)      cout<< "->" <<#x<<": "<<x<<endl
#define CLR(x)      x.clear()
#define iter(c)     __typeof((c).begin())
#define MARK(n)     printf("MARK %d  LINE: %d\n",n,__LINE__);
#define tr(c, i)    for (iter(c) i = (c).begin(); i != (c).end(); ++i)

#define PB          push_back
#define PF          push_front
#define fs          first
#define sc          second

#define ERR         1e-9
#define INF         (1<<28)
#define SIZE        1000
const double PI=acos(-1.0);

typedef pair<int,int>   pii;
typedef pair<double,double> pdd;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<vi>      vii;
typedef vector<vll>     vvll;
typedef vector<vd>      vvd;
typedef vector<pii>     vpii;
typedef map<string,int> msi;
typedef map<int,int>    mii;
typedef map<pii,int>    mpi;
typedef list<int>       li;
typedef istringstream   iss;

/** Printing **/
template<class T> void out(const vector<T> &a) { cout<<"array: "; for (int i=0;i<SZ(a);i++) cout<<a[i]<<" "; cout<<endl; cout.flush(); }
void binprint(int mask,int n)/**print a number in binary format with n length**/
  {int i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart() /**ASCII Chart**/
  {int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

/**  MATH   **/
template<class T> inline T gcd(T a,T b) {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}/** NOTES:sqr **/
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} /** For Positive Negative No. **/
int BigMod(ll B,ll P,ll M) /** compute b^p%m **/
  { ll R=1;	while(P>0)	{if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}	return (int)R;}
ll mulmod(ll a,ll b,ll c) /**calculates (a*b)%c taking into account that a*b might overflow **/
  { ll x = 0,y=a%c; while(b>0){ if(b%2 == 1){x=(x+y)%c;} y=(y*2)%c;b/= 2;}return x%c;}
ll mpow(ll x,ll k) { if( k==0) return 1; ll r=mpow(x,k/2); return k%2?(r*r*x):(r*r); }    // Power Calculation function

/** Genarator **/
vector<string> SubstringGenerate(string str)/** Substring Generator **/
  {int i,j,len;vs store;len=SZ(str);REP(i,len) FOR(j,i,len)store.PB(str.substr(i,j-i+1));return store;}

/** Dicission **/
template<class T> inline bool isPrime(T n){if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
bool IsVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpperCase(char c){return c>='A' && c<='Z';}
bool isLowerCase(char c){return c>='a' && c<='z';}
bool isLetter(char c){return c>='A' && c<='Z' || c>='a' && c<='z';}//NOTES:isLetter(
bool isDigit(char c){return c>='0' && c<='9';}//NOTES:isDigit(

/** Conversion **/
double deg2rad(double x){ return (PI*x)/180.0; }
double rad2deg(double x){ return (180.0*x)/PI; }
template<class T> string toString(T n)/** NOTES:int,double is converted to string **/
  {ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;} /** String to Int **/
ll toLl(string s){ll r=0;istringstream sin(s); sin>>r; return r;}  /** String to Int **/
double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;} /**NOTES:toDouble(**/
template<typename T> static void splitstr(const string &s, vector<T> &out)/**String TO vector**/
  { istringstream in(s);out.clear();copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));}

/**For debugging **/
template<class T> void debug(T e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T> void debug(vector<T> e){int i;REP(i,SZ(e)) cout<<e[i]<<" ";cout<<endl;}
template<class T> void debug(vector<T> e,int n){int i;REP(i,n) cout<<e[i]<<" ";cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e){int i,j;REP(i,SZ(e)) {REP(j,SZ(e[i])) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<"\t";cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}
template<class T> void debug(T e[],int row){int i;REP(i,row) cout<<e[i]<<" ";cout<<endl;}

//struct pq{    int cost,node;bool operator<(const pq &b)const{return cost>b.cost;}};// Min Priority Queue
//typedef struct{int x,y;}P;P pvt;

/** max sizes in TC : [16000000] , [4000][4000] , [250][250][250] **/
/** max loop in TC  : n^2 =>> 42000 **/

//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction

bool com(int a,int b)
{
    return a<b;
}

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    //ios_base::sync_with_stdio(false);
    int n,k,l,c,d,p,nl,np,drk,nos,solt,x;

    int i;

    cin>>n>>k>>l>>c>>d>>p>>nl>>np;
    REP(i,10000000000);
    drk=k*l;
    nos=c*d;
    solt=p;
    x=min(drk/nl,min(nos,solt/np));
    x/=n;
    cout<<x<<endl;

    return 0;
}


#include<iostream>
#include <cstdio>
#include<cmath>
using namespace std;
int main(){

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

   for (;;)
  {
cin >> n >> l >> k >> c >> d >> p >> nl >> np  ;

 int m=k*l;     // number of miliis

 int s=c*d;     //number of slices

  m=m/nl;      //number of  possible toasts uisng drink

  p=p/np;     // number of posssible tpasts using salds

  // for n friends
  m=m/n;

  s=s/n;

  p=p/n;
int x=fmin(m,s);
int y=fmin(x,p);
cout<<y<<endl;

}
return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_map>

#define pb push_back

using namespace std;

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

const ll P=4111;
const ll MOD=1000000007;

int n, q;
int a[4097];
piii qy[100001];
int cnt;

unordered_map<int, int> topos;

set<int> curay;
set<int>:: iterator it;
vector<int> ay;

vector<pii> ans;
int anspos[100001];

ll powp[100001];

struct seg{
    struct node{
        int l, r;
    } seg[200001];

    pii query(int p, int l, int r)
    {
        if(l>r)
            return {0, 0};
        if(seg[p].l+1==seg[p].r){
            return {topos[seg[p].l], seg[p].l};
        }
        else{
            int targ=(seg[p].l+seg[p].r)/2-1;
            int lo=l, hi=r+1, m;
            while(lo<hi){
                m=(lo+hi)/2;
                if(ay[m-1]<=targ)
                    lo=m+1;
                else
                    hi=m;
            }
            lo--;
            pii fx=query(2*p, l, lo), fy=query(2*p+1, lo+1, r);
            int hash=ll(ll(fx.second)*ll(powp[r-lo])+ll(fy.second))%MOD;
            if(topos[hash]==0){
                cnt++;
                ans.pb({fx.first, fy.first});
                topos[hash]=cnt;
            }
            return {topos[hash], hash};
        }
    }

    void build(int p, int l, int r)
    {
        seg[p].l=l, seg[p].r=r;
        if(l+1<r){
            build(2*p, l, (l+r)/2);
            build(2*p+1, (l+r)/2, r);
        }
    }
} ds;

void ini()
{
    int i;

    powp[0]=1;
    for(i=1;i<=100000;i++)
        powp[i]=powp[i-1]*P, powp[i]%=MOD;
}

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

    int i, j;

    ini();

    cin >> n >> q, cnt=n;
    for(i=1;i<=n;i++)
        cin >> a[i], topos[a[i]]=i;
    for(i=1;i<=q;i++)
        cin >> qy[i].first.first >> qy[i].first.second, qy[i].second=i;
    sort(qy+1, qy+q+1);

    ds.build(1, 1, n+1);
    int cur=1;
    for(i=1;i<=n;i++){
        curay.clear();
        for(j=i;j<=n;j++){
            curay.insert(a[j]);
            while(cur<=q && qy[cur].first.first==i && qy[cur].first.second==j){
                ay.clear();
                it=curay.begin();
                while(it!=curay.end())
                    ay.pb(*it), it++;
                anspos[qy[cur].second]=ds.query(1, 1, ay.size()).first;
                cur++;
            }
        }
    }

    cout << cnt << endl;
    for(i=0;i<ans.size();i++)
        cout << ans[i].first << " " << ans[i].second << endl;
    for(i=1;i<q;i++)
        cout << anspos[i] << " ";
    cout << anspos[q] << endl;

    return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cassert>
using namespace std;
#define File(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
typedef long long ll;
namespace io {
  const int SIZE = (1 << 21) + 1;
  char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
  #define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
  char getc () {return gc();}
  inline void flush () {fwrite (obuf, 1, oS - obuf, stdout); oS = obuf;}
  inline void putc (char x) {*oS ++ = x; if (oS == oT) flush ();}
  template <class I> inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
  template <class I> inline void print (I x) {if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while (x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr --]);}
  struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi; using io :: putc; using io :: print; using io :: getc;
template<class T> void upmax(T &x, T y){x = x>y ? x : y;}
template<class T> void upmin(T &x, T y){x = x<y ? x : y;}

const int N = 1 << 12;
const unsigned long long P1 = 180143985094819841, P2 = 1945555039024054273;

template<>
struct std::hash<pair<int, int> >{
  unsigned long long operator()(pair<int, int> p) const{
    return (unsigned long long)p.first * P1 + (unsigned long long)p.second * P2;
  }
};
typedef unordered_map<pair<int, int>, int> d2;

int a[N], res[N], pos[N];
d2 tr[N << 2];
vector<int> p[N << 2], suml[N << 2];
pair<int, int> op[2200005];
int oc = 0, cnt;

// all ranges are [l, r)
void build(int x, int l, int r){
  if(l + 1 == r) return;
  int mid = (l + r) >> 1;
  suml[x].resize(r - l);
  p[x << 1].reserve(mid - l), p[x << 1 | 1].reserve(r - mid);
  suml[x][0] = p[x][0] < mid;
  if(p[x][0] < mid) p[x << 1].push_back(p[x][0]);
  else p[x << 1 | 1].push_back(p[x][0]);
  for(int i=1; i<r-l; i++){
    suml[x][i] = suml[x][i - 1] + int(p[x][i] < mid);
    if(p[x][i] < mid) p[x << 1].push_back(p[x][i]);
    else p[x << 1 | 1].push_back(p[x][i]);
  }
  build(x << 1, l, mid);
  build(x << 1 | 1, mid, r);
}
int query(int x, int l, int r, int ql, int qr){
  if(l + 1 == r) return pos[p[x][0]];
  int &res = tr[x][{ql, qr}];
  assert(ql < r - l && qr <= r - l);
  if(res) return res;
  int mid = (l + r) >> 1;
  int l0 = ql == 0 ? 0 : suml[x][ql - 1], r0 = suml[x][qr - 1];
  int l1 = ql == 0 ? 0 : ql - suml[x][ql - 1], r1 = qr - suml[x][qr - 1];
  if(l0 == r0) return query(x << 1 | 1, mid, r, l1, r1);
  if(l1 == r1) return query(x << 1, l, mid, l0, r0);
  op[++oc] = {query(x << 1, l, mid, l0, r0), query(x << 1 | 1, mid, r, l1, r1)};
  return res = ++cnt;
}

int main(){
  // File("cf1375h");
  int n, q;
  gi(n); gi(q);
  for(int i=0; i<n; i++) gi(a[i]), --a[i], pos[a[i]] = i + 1;
  p[1].resize(n);
  copy(a, a + n, p[1].begin());
  build(1, 0, n);
  cnt = n;
  for(int i=0; i<q; i++){
    int l, r;
    gi(l); gi(r); --l;
    res[i] = query(1, 0, n, l, r);
  }
  print(oc + n); putc('\n');
  for(int i=1; i<=oc; i++) print(op[i].first), putc(' '), print(op[i].second), putc('\n');
  for(int i=0; i<q; i++) print(res[i]), putc(' ');
  putc('\n');
  return 0;
}


#include <bits/stdc++.h>
#define maxn 5005
#define maxq 100005
using namespace std;

int n, q;

vector<int> blocks[maxn];
map< pair<int,int>, int> pos[maxn];

vector< pair<int,int> > ops;
int a[maxn], id[maxn];
int ret[maxq];

struct Partition {
	map< pair<int,int>, int > ranges;

	Partition () {

	}
};

int cnt;

Partition construct(int block, int low, int high, vector<int>& order) {
	if (low > high) {
		return Partition();
	}
	if (low == high) {
		Partition ps;
		ps.ranges[make_pair(0, 0)] = id[low];
		return ps;
	}

	int mid = (low + high) >> 1;
	vector<int> la, ra;
	for (int x : order) {
		if (x <= mid) {
			la.push_back(x);
		} else {
			ra.push_back(x);
		}
	}

	auto ls = construct(block, low, mid, la);
	auto rs = construct(block, mid + 1, high, ra);

	Partition ps;
	int i = 0;
	int lowx = 0, lowy = 0, highx = 0, highy = 0;
	while (i < order.size()) {
		if (i > 0) {
			if (order[i - 1] <= mid) {
				lowx++;
			} else {
				highx++;
			}
		}

		lowy = lowx - 1;
		highy = highx - 1;
		for (int j = i; j < order.size(); j++) {
			if (order[j] <= mid) {
				lowy++;
			} else {
				highy++;
			}

			int lindex = ls.ranges[make_pair(lowx, lowy)];
			int rindex = rs.ranges[make_pair(highx, highy)];
			if (lowx <= lowy && highx <= highy) {  // merge
				/*if (lindex == 0 || rindex == 0) {
					for (auto x : order) cout << x << ' ';
					cout << endl;
					cout << lowx << ' ' << lowy << ' ' << highx << ' ' << highy << endl;
				} */
				assert(lindex > 0 && rindex > 0);
				ps.ranges[make_pair(i, j)] = ++cnt;
				ops.push_back(make_pair(lindex, rindex));
			} else if (lowx <= lowy) {
				assert(lindex > 0);
				ps.ranges[make_pair(i, j)] = lindex;
			} else {
				if (rindex == 0) {
					// cout << lowx << ' ' << lowy << ' ' << highx << ' ' << highy << endl;
				}
				assert(rindex > 0);
				ps.ranges[make_pair(i, j)] = rindex;
			}
		}

		i++;
	}

	return ps;
}

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

	int S = sqrt(q);
	cnt = n;
	for (int low = 1, block = 0; low <= n; low += S, block++) {
		int high = min(n, low + S - 1);
		for (int i = 1; i <= n; i++) if (a[i] >= low && a[i] <= high) {
			blocks[block].push_back(a[i]);
		}
		auto ps = construct(block, low, high, blocks[block]);
		for (int i = 0; i < blocks[block].size(); i++) {
			for (int j = i; j < blocks[block].size(); j++) {
				pos[block][make_pair(i, j)] = ps.ranges[make_pair(i, j)];
			}
		}
	}

	for (int it = 0; it < q; it++) {
		int l, r;
		scanf("%d %d", &l, &r);

		ret[it] = -1;
		for (int low = 1, block = 0; low <= n; low += S, block++) {
			int high = min(n, low + S - 1);
			int lx = 0, rx = -1;
			for (int i = 1; i <= r; i++) if (a[i] >= low && a[i] <= high) {
				if (i < l) {
					lx++;
					rx++;
				} else {
					rx++;
				}
			}

			if (lx > rx) {
				continue;
			}

			int lindex = pos[block][make_pair(lx, rx)];
			if (ret[it] < 0) {
				ret[it] = lindex;
			} else {
				assert(ret[it] > 0 && lindex > 0);
				ops.push_back(make_pair(ret[it], lindex));
				ret[it] = ++cnt;
			}
		}
	}

	printf("%d\n", cnt);
	for (auto op : ops) {
		printf("%d %d\n", op.first, op.second);
	}
	for (int i = 0; i < q; i++) {
		printf("%d ", ret[i]);
	}
	printf("\n");
	return 0;
}


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

vector<pair<int,int>> merges;
vector<pair<vector<int>, map<pair<int, int>,int>>> st; //elements to set mapping in each node of st
vector<int> arr,arr2;
int cnt;

void combine(int root){
	vector<int> &v1 = st[2*root].first;
	vector<int> &v2 = st[2*root+1].first;
	vector<int> &v = st[root].first;
	v.resize((int)v1.size() + (int)v2.size());
	merge(v1.begin(), v1.end(), v2.begin(), v2.end(), v.begin());
}

void build(int root, int sl, int sr){
	if (sl == sr){
		st[root].first.push_back(arr[sl]);
		return;
	}
	int mid = (sl+sr)/2;
	build(2*root, sl, mid);
	build(2*root+1, mid+1, sr);
	combine(root);
}

int query(int root, int l, int r){
	vector<int> &v1 = st[root].first;
	int x = lower_bound(v1.begin(), v1.end(), l) - v1.begin();
	int y = upper_bound(v1.begin(), v1.end(), r) - v1.begin();
	if(y == x+1){
		return v1[x];
	}
	if(x == (int)v1.size() || (x>=y)){
		return -1;
	}
	map<pair<int,int>, int> &m = st[root].second;
	if(m.find({x,y}) == m.end()){
		int s1 = query(2*root, l, r);
		int s2 = query(2*root+1, l,r);
		if(s1 != -1 && s2 != -1){
			merges.push_back({s1,s2});
			m[{x,y}] = cnt+1;
			cnt += 1;
		}
		else{
			m[{x,y}] = max(s1,s2);
		}
	}
	return m[{x,y}];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,q;
	cin >> n >> q;
	cnt = n;
	st.clear();
	arr.clear();
	arr2.clear();
	merges.clear();
	st.resize(4*n + 5);
	arr.resize(n+1,-1);
	arr2.resize(n+1,-1);
	for(int i = 0;i < n; ++i){
		int a;
		cin >> a;
		arr[a] = i+1;
		arr2[i+1] = a;
	}
	build(1,1,n);
	vector<int> res;
	while(q){
		q -= 1;
		int l,r;
		cin >> l >> r;
		res.push_back(query(1,l,r));
	}
	cout << cnt << endl;
	for(auto x : merges){
		cout << x.first << " " << x.second << endl;
	}
	for(int x : res){
		cout << x << " ";
	}
	cout << endl;

}


#include <iostream>
#include<cstdio>
#include<cstdlib>
#include <fstream>
#include<sstream>
#include <string>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

typedef long long LL;

int main()
{
    LL l, r;
    cin>>l>>r;
    if(abs(r-l)<2)
       {
           cout<<-1;
           return 0;
       }

    LL x=l;
    if(x%2!=0)
        x++;

    cout<<x<<' '<<x+1<<' '<<x+2;

}


#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream f("cf.in");
int main()
{
    long long l, r;
    cin>>l>>r;
    if(l%2==0){
        if(r == l+1)
            cout<<-1;
        else
            cout<<l<<' '<<l+1<<' '<<l+2;
    }
    else{
        if(r-l <= 2)
            cout<<-1;
        else
            cout<<l+1<<' '<<l+2<<' '<<l+3;
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
ll l,r,a,b,c;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>l>>r;
    a=b=c=0;
    for(ll i=l;i<=r;i++)
    {
        if(i%2==0 && i%4!=0 &&i+2<=r)
        {
            a=i;
            b=++i;
            c=++i;
            break;
        }
    }
    if(a!=0)cout<<a<<" "<<b<<" "<<c<<endl;
    else
    cout<<"-1"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int l,r;
cin>>l>>r;
if(l!=1)
{
if(r-l<=1)
cout<<-1<<endl;
else
{
if(l%2==0)
cout<<l<<" "<<l+1<<" "<<l+2<<endl;
else
cout<<l+1<<" "<<l+2<<" "<<l+3<<endl;
}
}
else
{
                if(r-l<=2)
                cout<<-1<<endl;
                else
                cout<<l+1<<" "<<l+2<<" "<<l+3<<endl;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
char a;
int ans=0,rec=0,i=0;
int main()
{
	cin>>s;
	while(i<=s.size())
	{
		if(i==s.size()-1)break;
		a=s[i];
		for(int j=i;j<s.size();j++)
		{
			if(s[j]==a) rec++;
			else
			{
				i=j;
				break;
			}
		}
		if(rec%2==0) {ans++;}
		rec=0;
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
template<typename T>inline void read(T&x)
{
	T ll=1;
    T res=0;
	char ch=getchar();
    while(!isdigit(ch))
    {
		if(ch=='-')
		ll=-1;
		ch=getchar();
	}
    while(isdigit(ch))
	res=(res<<3)+(res<<1)+ch-'0',ch=getchar();
    x=res*ll;
}
template<typename T>void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x<10)
    putchar(x+'0');
    else
    {
        print(x/10);
        putchar(x%10+'0');
    }
}
int main()
{
    cin>>s;
    int len=s.length();
    int ans=0,curlen=1;
    for(int i=0;i<len;)
    {
    	for(int j=i+1;j<len;j++)
    	{
    		if(s[i]==s[j])
    		curlen++;
    		else
    		{
    			if(curlen%2==0)
    			ans++;
    			curlen=1;
    			i=j;
			}
		}
	}
	print(ans);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a=1,k=0,l;
	string s;
    cin>>s;
    l=s.size();
    for(int i=0;i<l;i++)
    {
        for(int j=1;j<l;j++)
        {
            if(s[i]==s[j]){a++;continue;}
            if(a%2==0)k++;
            a=1;
            i=j;
		}
	}
    printf("%d",k);
}


#include<bits/stdc++.h>
#define nl printf("\n");
#define N 200001
#define MP pair<ll,ll>
#define sf(n) scanf("%d", &n)
#define sff(n, m) scanf("%d %d",&n,&m)
#define sfl(n) scanf("%lld", &n)
#define sfu(n) scanf("%llu", &n)
#define sffl(n, m) scanf("%lld %lld",&n,&m)
#define pfn(n) printf("%d\n",n)
#define pf(n) printf("%d ",n)
#define pfl(n) printf("%lld ",n)
#define pfln(n) printf("%lld\n",n)
#define pfu(n) printf("%llu\n",n)
#define pfs(s) printf("%s",s)
#define YES printf("YES\n")
#define YES printf("NO\n")
#define PB push_back
#define PI 3.1415926536
#define VST(v) sort(v.begin(),v.end())
#define fori(n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
vector<ll>v,v2,v3;
vector<ll> :: iterator it1,it2;
int main()
{
    ///freopen("input.txt","r",stdin);
    ll tcase=1;
    //sf(tcase);
    while(tcase--)
    {
        int left=0,right=0,cnt=0;
        string s;
        cin>>s;
        int len=s.size();
        while(1){
            if(s[left]==s[right]){
                    if(right<len-1)
                right++;
            }
            else{
                cnt+=((right-left)%2==0);left=right;
            }
            if(left==len-1){
                break;
            }
        }

        printf("%d\n",cnt);
    }
///*****************************  ALHAMDULILLAH  *****************************/
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n, c, l, t1=0, t2=0, sum1=0,sum2=0;
	vector <int> p,t;
	cin >> n >> c;
	for (int i = 0; i < n; i++)
	{
		cin >> l;
		p.push_back(l);
	}
	for (int i = 0; i < n; i++)
	{
		cin >> l;
		t.push_back(l);
	}
	for (int i = 0; i < n; i++)
	{
		t1 += t[i];

		if (p[i] - (t1*c)>0)
			sum1 += p[i] - t1*c;;
	}
	for (int i = n-1; i >= 0; i--)
	{
		t2 += t[i];
		if (p[i] - (t2*c)>0)
			sum2+= p[i] - t2*c;
	}
	if (sum1 > sum2) cout << "Limak" << endl;
	else if (sum1 < sum2) cout << "Radewoosh" << endl;
	else cout << "Tie" << endl;
	system("pause");
	return 0;
}


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

#define forn(n) for (int i=0;i<n;i++)
#define pb push_back
#define rev(n,p)    forn(n/2) {int tmp = p[i];p[i] = p[n - i - 1];p[n - i - 1] = tmp;}//переворот массива

//Console out
#define cline cout<<endl
#define line   <<endl
#define qm <<" "<<
#define vi vector <int>
#define vs vector <string>
#define out cout<<

int answer(int n,int c,int *p,int *t)
{
   int timeafterstart=0,answer=0;
   forn(n)
	{
	   timeafterstart+=t[i];
	   answer+=max(p[i]-c*timeafterstart,0);
	   //cout<<answer line;
	}
	return answer;
}

int main()
{
   int n,c;
   cin>>n>>c;
	int f,s;
	f=s=0;
	int *p=new int [n];
	int *t=new int [c];

	forn(n)   cin>>p[i];
	forn(n)   cin>>t[i];
   f=answer( n, c, p, t);
   //forn(n) out p[i]  line;
   rev(n,p)
   rev(n,t)
   //forn(n) out p[i]  line;
   s=answer( n, c, p, t);
   //out f qm s line;

   (f>s)?out"Limak":f<s?out"Radewoosh":out"Tie";

	return 0;
}


#include<stdio.h>
#include<conio.h>

int max(int a,int b)
{
	if (a>b)
		return a;
	else return b;
}

int main()
{
	int c,n=0;
	int t[51]={};
	int p[51]={};
	int limsum=0;
	int radsum=0;
	int time=0;
	scanf("%d",&n);
	scanf("%d",&c);
	for(int i=0;i<n;i++)
		scanf("%d",&p[i]);
	for (int i=0;i<n;i++)
		scanf("%d",&t[i]);
	for(int i=0;i<n;i++)
	{
		time=time+t[i];
		limsum=limsum+max(p[i]-c*time,0);
	}
	time=0;
	for(int i=n-1;i>=0;i--)
	{
		time=time+t[i];
		radsum=radsum+max(0,p[i]-c*time);
	}
	if(limsum>radsum)
		printf("Limak");
	else if(limsum==radsum)
		printf("Tie");
	else
		printf("Radewoosh");

	_getch();

	return 0;
}


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

using namespace std;
int max(int a,int b)
{
	if (a>b)
		return a;
	else return b;
}

int main()
{
	int c,n=0;
	int t[51]={};
	int p[51]={};
	int limsum=0;
	int radsum=0;
	int time=0;
	cin>>n;
	cin>>c;
	for(int i=0;i<n;i++)
		cin>>p[i];
	for (int i=0;i<n;i++)
		cin>>t[i];
	for(int i=0;i<n;i++)
	{
		time=time+t[i];
		limsum=limsum+max(p[i]-c*time,0);
	}
	time=0;
	for(int i=n-1;i>=0;i--)
	{
		time=time+t[i];
		radsum=radsum+max(0,p[i]-c*time);
	}
	if(limsum>radsum)
		cout<<"Limak";
	else if(limsum==radsum)
		cout<<"Tie";
	else
		cout<<("Radewoosh");

	_getch();

	return 0;
}


//#pragma GCC optimize(3)
#include <random>
#include <stdio.h>
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<int, int> pii;
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
#define Return(x) { x; return; }
#define P2(x) ((x) * (x))
#define lowbit(x) ((x) & -(x))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MEM(x, y) memset((x), (y), sizeof(x))
#define MEN(x, y, z) memset((x), (y), sizeof((x)[0]) * (z))
#define Diz(x) (lower_bound(dz.begin(), dz.end(), (x)) - dz.begin())
#define DISCRETE(x) (x).push_back(INT_MIN), sort((x).begin(), (x).end()), (x).erase(unique((x).begin(), (x).end()), (x).end())
#ifdef LOCAL
#define DEBUG(...) cout << ">> " << #__VA_ARGS__ << " =", PRT(__VA_ARGS__), cout << endl;
#define DEBUGS(...) cout << ">> " << #__VA_ARGS__ << " =", PRTS(__VA_ARGS__), cout << endl;
void PRT() {} template <typename S, typename... T> void PRT(S x, T ... y){ cout << " " << x; PRT(y...); }
void PRTS() {} template <typename S> void PRTS(S x) { for (auto v : x) cout << " " << v; }
#define TIME cout << "RunTime: " << clock() << "ms\n", 0
#define __int128_t long long
#else
#define DEBUG(...) ;
#define DEBUGS(...) ;
#define TIME 0
#endif

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
template<typename S, typename T> inline bool Min(S &a, const T &b){ return a > b ? a = b, true : false; }
template<typename S, typename T> inline bool Max(S &a, const T &b){ return a < b ? a = b, true : false; }
template<typename S, typename T> inline void Adm(S &a, const T &b){ a = (a + b) % MOD; if (a < 0) a += MOD; }
template<typename S, typename T> inline void Mum(S &a, const T &b){ a = 1LL * a * b % MOD; }
template<typename T> inline bool IsPri(T x) { if (x < 2) return false; for (T i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; }
template<typename T> inline T Gcd(T a, T b){ while (b){ T t = b; b = a % b; a = t; } return a; }
template<typename T> inline int BitCnt(T x){ int cnt = 0; while (x)++cnt, x &= x - 1; return cnt; }
template<typename T> inline T MDis(T x1, T y1, T x2, T y2){ return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> inline T MDis(T x1, T y1, T z1, T x2, T y2, T z2){ return abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2); }
inline double EDis(double x1, double y1, double x2, double y2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
inline double EDis(double x1, double y1, double z1, double x2, double y2, double z2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); }
inline ll Pow(ll a, ll n) { ll t = 1; a %= MOD; while (n > 0) { if (n & 1) t = t * a % MOD; a = a * a % MOD, n >>= 1; } return t % MOD; }
#define gc p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
inline int read(){ static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = gc; register bool sgn = false; while (ch != '-' && (ch < '0' || ch > '9')) ch = gc; if (ch == '-') sgn = true, ch = gc; while (ch >= '0'&& ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc; return sgn ? -x : x; }
//emplace unordered 能ll就开 函数内判非法+

set<vector<int>> st;
vector<int> rotate(vector<int> v, vector<int> p) //p当前该放什么
{
	vector<int> res;
	for (int i = 0; i <= 24; ++i)
		res.push_back(v[p[i]]);
	return res;
}
int cnt = 0;
void DFS(vector<int> v)
{
	if (cnt > 5000)
		puts("NO"), exit(0);
	if (!st.insert(v).second)
		return;
	int flag = 1;
	for (int i = 1; i <= 24 && flag; i += 4)
		if (v[i] != v[i + 1] || v[i + 1] != v[i + 2] || v[i + 2] != v[i + 3])
			flag = 0;
	if (flag)
		puts("YES"), exit(0);
	vector<int> &&a = rotate(v, { 0, 2, 4, 1, 3, 13, 14, 7, 8, 9, 10, 11, 12, 21, 22, 15, 16, 5, 6, 19, 20, 17, 18, 23, 24 });
	DFS(a);
	vector<int> &&b = rotate(v, { 0, 1, 2, 3, 4, 5, 6, 19, 20, 10, 12, 9, 11, 13, 14, 7, 8, 17, 18, 23, 24, 21, 22, 15, 16 });
	DFS(b);
	vector<int> &&c = rotate(v, { 0, 24, 2, 22, 4, 1, 6, 3, 8, 5, 10, 7, 12, 15, 13, 16, 14, 17, 18, 19, 20, 21, 9, 23, 11 });
	DFS(c);
	vector<int> &&d = rotate(v, { 0, 1, 6, 3, 8, 5, 10, 7, 12, 9, 23, 11, 21, 13, 14, 15, 16, 19, 17, 20, 18, 4, 22, 2, 24 });
	DFS(d);
}
int main()
{
#ifdef LOCAL
	freopen("C:/input.txt", "r", stdin);
	//freopen("C:/output.txt", "w", stdout);
#endif
	vector<int> v(1);
	for (int i = 0; i < 24; ++i)
	{
		int x;
		scanf("%d", &x);
		v.push_back(x);
	}
	DFS(v);
	puts("NO");

	return TIME;
}


//In the name of God
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <fstream>
#include <string>
#include <cstring>
#include <cassert>
#include <complex>
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;
int a[20],n;
bool g(int x,int y)
{
    for(int i=0;i<20;i++)
        a[i]=0;
    for(;x>0;)
    {
        a[x%10]++;
        x/=10;
    }
    for(;y>0;)
    {
        a[(y%10)+10]++;
        y/=10;
    }
    for(int i=0;i<10;i++)
            if(a[i]&&a[i+10])
                return true;
    return 0;
}
bool b[1000*1000*1000];
int main()
{
    int cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++)
	{
		if(!b[i])
		{
			if((!(n%i))&&(g(n,i)))
				cnt++;
		}
		else
			for(int j=2;(j*i)<=1e9;j++)
				b[i*j]=1;
	}
    cout<<cnt;
    return 0;
}


/*
Algorithm&&Data Structure:Implementation
Source: Codeforces Round #136 (Div. 2) Little Elephant and Numbers
*/
#define _CRT_SECURE_NO_WARNINGS
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<string>
#include<vector>
using namespace std;
#define maxn 200010
int N;
string a = "";
char isshow[256];
bool is[1000000010];
void tostr(int i)
{
    if (i >= 0 && i < 10)
    {
        a = i + '0';
        return;
    }
    tostr(i / 10);
    a += (i % 10 + '0');
}
int main()
{
    cin >> N;
    tostr(N);
    string Nt = a;
    for (int i = 0; i < Nt.length(); i++)
        isshow[Nt[i]] = true;
    string t = "";
    int ans = 1;
    if (N == 1)
        cout << 1 << endl;
    else
    {
        if (isshow['1'])
            ans++;
        for (int i = 2; i <= sqrt(N*1.0); i++)
        {
            for (int j = i; j <= N / 2; j += i)
            {
                if (N%j == 0&&!is[j])
                {
                    is[j] = true;
                    a = "";
                    tostr(j);
                    int len = a.length();
                    for (int k = 0; k < len; k++)
                    {
                        if (isshow[a[k]])
                        {
                            ans++;
                            break;
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<ctime>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)

using namespace std;

#define pb push_back
#define pf push_front
#define p_f pop_front
#define p_b pop_back
#define LL __int64
#define LD long double
#define MP make_pair
#define fi first
#define se second
#define sc scanf
#define pr printf
#define str strlen
LL a,b,i,j,k,n,m,d[100001]={0},gh=0;
LL c[1010000]={0},cnt=0,fl=1,a2,a3=-1000000,used[100000001]={0},i1,ans=0,maxv=0,us[20];
main()
{
    //input;
    //output;
    sc("%I64d",&n);
    if(n==1){pr("1\n");return 0;}
    for(i=1;i<=sqrt(n);i++)
    {
        if(n%i==0&&used[i]==0){ used[i]=1;c[cnt]=i;cnt++;
        if(used[(n/i)]==0){ c[cnt]=(n/i);cnt++;used[n/i]=1; }}
    }
    while(n>0)
    {
        us[n%10]=1;
        n/=10;
    }
    for(i=0;i<cnt;i++)
    {
        while(c[i]>0)
        {
            if(us[c[i]%10]==1){ gh++; break; }
            c[i]/=10;
        }
        //pr("%I64d ",c[i]);
    }
    pr("%I64d\n",gh);
    return 0;
}


#include<stdio.h>
#include<conio.h>
int main()
{
    int n;
    int sum=1;
    int data[12];
    for(int i=0;i<10;i++)data[i]=0;
    scanf("%d",&n);
    if(n==1)
    {
        printf("1");return 0;
    }
    for(int i=n;i>0;i/=10)
    {
        data[i%10]=1;
    }
    int i=3;
    if(n%2==0)i=2;
    for(;i<n;i++)
    {
        if(n%i==0)
        {
            int j;
            for(j=i;j>0;j/=10)
            {
                if(data[j%10]==1)break;
            }
            if(j>0)
            {
                sum++;
                //printf("%d\n",i);
                //getch();
            }
        }
    }
    if(data[1]==1)sum++;
    printf("%d",sum);
    getch();
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

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

typedef long long ll;
const ll mod = 1e9 + 7;
ll N; int K;

struct MAT {
  int m[31][31];
  MAT operator *(const MAT& o) const {
    MAT ret = {0,};
    for(int i = 0; i <= K; i++) {
      for(int j = 0; j <= K; j++) {
        ret.m[i][j] = 0;
        for(int k = 0; k <= K; k++)
          ret.m[i][j] = (ret.m[i][j] + (ll)m[i][k] * o.m[k][j]) % mod;
      }
    } return ret;
  }
};
MAT A[65][30];
MAT P[65][30];
MAT S[65][30];
MAT res;

int main() {
  //freopen("a.in", "r", stdin);
  //freopen("a.out", "w", stdout);
  scanf("%lld%d", &N, &K);
  vector<int> base_K;
  while(N) base_K.push_back(N % K), N /= K;
  for(int i = 0; i < K; i++) {
    for(int j = 0; j <= K; j++) A[0][i].m[j][j] = 1;
    for(int j = 0; j <= K; j++) A[0][i].m[i][j] = 1;
  }
  for(int i = 1; i < sz(base_K); i++) {
    P[i - 1][0] = A[i - 1][0];
    for(int j = 1; j < K; j++)
      P[i - 1][j] = P[i - 1][j - 1] * A[i - 1][j];
    S[i - 1][K - 1] = A[i - 1][K - 1];
    for(int j = K - 1; j--; )
      S[i - 1][j] = A[i - 1][j] * S[i - 1][j + 1];
    for(int j = 0; j < K; j++) {
      A[i][j] = S[i - 1][j];
      if(j) A[i][j] = A[i][j] * P[i - 1][j - 1];
    }
  }
  int x = 0;
  for(int i = 0; i <= K; i++) res.m[i][i] = 1;
  for(int i = sz(base_K); i--; ) {
    for(int j = 0; j < base_K[i]; j++) {
      res = res * A[i][x];
      x = (x + 1) % K;
    }
  }
  int ans = 0;
  for(int i = 0; i <= K; i++)
    ans = (ans + res.m[i][K]) % mod;
  printf("%d\n", ans);
  return ans;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int Mod=1e9+7;
int n,m,K,sum,now,a[110];
void ADD(int &x,int y){
	x+=y; if (x>=Mod) x-=Mod;
}
struct Matrix{
	int v[110][110];
	Matrix(){ memset(v,0,sizeof(v));}
	Matrix operator*(const Matrix &a) const{
		Matrix res;
		for (int k=0;k<=K;k++)
			for (int i=0;i<=K;i++)
				if (v[i][k])
					for (int j=0;j<=K;j++)
						if (a.v[k][j])
							res.v[i][j]=(1ll*v[i][k]*a.v[k][j]+res.v[i][j])%Mod;
		return res;
	}
} ans,/*hanhan,*/s[75][35],pre[75][35],suf[75][35];
void work(int n){
	int tmp=n;
	while (tmp){
		a[++m]=tmp%K;
		tmp/=K;
	}
	reverse(a+1,a+m+1);
}
int main(){
	scanf("%d%d",&n,&K);
//	n++;
	work(n);
	for (int i=0;i<K;i++){
		for (int j=0;j<=K;j++) s[0][i].v[j][j]=1;
		for (int j=0;j<=K;j++) s[0][i].v[i][j]=1;
	}
//	hanhan=s[0][0]*s[0][1]*s[0][2]*s[0][3]*s[0][4]*s[0][5]*s[0][6];
	for (int i=1;i<=m;i++){
		pre[i-1][0]=s[i-1][0]; suf[i-1][K-1]=s[i-1][K-1];
		for (int j=1;j<K;j++) pre[i-1][j]=pre[i-1][j-1]*s[i-1][j];
		for (int j=K-2;j>=0;j--) suf[i-1][j]=s[i-1][j]*suf[i-1][j+1];
		for (int j=0;j<K;j++)
			if (j) s[i][j]=suf[i-1][j]*pre[i-1][j-1];
			else s[i][j]=suf[i-1][j];
	}
	for (int i=0;i<=K;i++)
		for (int j=0;j<=K;j++)
			ans.v[i][j]=(i==j);
	now=0;
	for (int i=1;i<=m;i++){
		//now+0,now+1,...,now+a[i]-1
		if (a[i]){
			if (now+a[i]-1>=K){
				for (int j=now;j<K;j++) ans=ans*s[m-i][j];
				for (int j=0;j<=(now+a[i]-1)-K;j++) ans=ans*s[m-i][j];
			} else
				for (int j=now;j<=now+a[i]-1;j++) ans=ans*s[m-i][j];
			now+=a[i];
		}
	}
	for (int i=0;i<=K;i++) ADD(sum,ans.v[i][K]);
	printf("%d\n",sum);
	return 0;
}


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

const int N = 70;

const int mod = 1e9 + 7;
const long long MOD = 1LL * mod * mod;

int k, len;
long long n, C[N][N];

struct Mat {
	int A[N][N];
	void init() {
		memset(A, 0, sizeof(A));
	}
}ind, T[N][N], pre[N][N], suf[N][N], start;

Mat operator * (Mat a, Mat b) {
	memset(C, 0, sizeof(C));
	for(int i = 0; i <= len; ++ i) {
		for(int k = 0; k <= len; ++ k) {
			for(int j = 0;  j <= len; ++ j) {
				C[i][j] += 1LL * a.A[i][k] * b.A[k][j];
				if(C[i][j] >= MOD) C[i][j] -= MOD;
			}
		}
	}
	for(int i = 0; i <= len; ++ i) {
		for(int j = 0; j <= len; ++ j)
		ind.A[i][j] = C[i][j] % mod;
	}
	return ind;
}

namespace {
	int add(int x) {return (x >= mod) ? x - mod : x;}
	int sub(int x) {return (x < 0) ? x + mod : x;}
	void Add(int &x, int y) {x = add(x + y);}
	void Sub(int &x, int y) {x = sub(x - y);}
	int Mul(int x, int y) {return (1LL * x * y) % mod;}
	int Pow(int x, int y = mod - 2) {
		int res = 1;
		for(; y; y >>= 1, x = 1LL * x * x % mod) {
			if(y & 1) {
				res = 1LL * res * x % mod;
			}
		}
		return res;
	}
}

vector <int> calc(long long n, int k) {
	vector <int> ans;
	ans.clear();
	while(n) {
		ans.push_back(n % k);
		n /= k;
	}
	return ans;
}

void build(int x) {
	for(int i = 0; i < len; ++ i)  T[0][x].A[i][i] = 1;
	T[0][x].A[x][x] = 0;
	T[0][x].A[k + 1][x] = 1;
	T[0][x].A[x][k + 1] = mod - 1;
	T[0][x].A[k + 1][k + 1] = 2;
}

void make(int x) {
	pre[x][0] = T[x][0];
	for(int i = 1; i < k; ++ i)
	pre[x][i] = pre[x][i - 1] * T[x][i];
	suf[x][k - 1] = T[x][k - 1];
	for(int i = k - 2; i >= 0; -- i)
	suf[x][i] = T[x][i] * suf[x][i + 1];
}

int main() {
	cin >> n >> k;
	-- n;
	vector <int> ex = calc(n, k);
	if(!ex.size()) ex.resize(1);
	len = k + 1;
	for(int i = 0; i < k; ++ i) build(i);
	start.init();
	start.A[0][k] = start.A[0][k + 1] = 1;
	for(int i = 1; i < (int) ex.size(); ++ i) {
		make(i - 1);
		for(int j = 0; j < k; ++ j) {
			if(j == 0) T[i][j] = pre[i - 1][k - 1];
			else
			T[i][j] = suf[i - 1][j] * pre[i - 1][(j + k - 1) % k];
		}
	}
	int bef = 0;
	for(int i = ex.size() - 1; i >= 0; -- i) {
		for(int j = 0; j < (int)ex[i] + (i == 0); ++ j) {
			start = start * T[i][(j + bef) % k];
		}
		bef += ex[i];
	}
	cout << start.A[0][k + 1] << endl;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 100
#define M 35
#define mmod 1000000007
#define LL long long
using namespace std;
int n,m,a[N];
struct mat{
	int a[M][M];
	mat() {memset(a,0,sizeof(a));}
	friend mat operator *(mat a,mat b)
	{
		mat c;
		for(int i=0;i<=m;i++)
			for(int j=0;j<=m;j++)
				for(int k=0;k<=m;k++)
					c.a[i][j]=(c.a[i][j]+1ll*a.a[i][k]*b.a[k][j]%mmod)%mmod;
		return c;
	}
}f,g,tmp,t,I,A;
void solve(int now)
{
	if(now==1)
	{
		for(int i=0;i<m;i++) A.a[i][i]=1;
		tmp=I;
		for(int i=0;i<m;i++)
		{
			t=I;
			for(int j=0;j<=m;j++) if(j!=i) t.a[i][j]++;
			tmp=tmp*t;
			if(i==a[now]) f=tmp;
		}
		g=tmp;
	}
	else
	{
		solve(now-1);
		tmp=I;
		for(int i=0;i<a[now];i++)
		{
			for(int j=0;j<=m;j++)
				for(int k=0;k<=m;k++)
					t.a[j][k]=0;
			for(int j=0;j<m;j++)
				for(int k=0;k<m;k++)
					t.a[(j+i)%m][(k+i)%m]=g.a[j][k];
			for(int j=0;j<m;j++) t.a[(j+i)%m][m]=g.a[j][m];
			t.a[m][m]=g.a[m][m];
			tmp=tmp*t;
		}
		for(int j=0;j<=m;j++)
			for(int k=0;k<=m;k++)
				t.a[j][k]=0;
		for(int j=0;j<m;j++)
			for(int k=0;k<m;k++)
				t.a[(j+a[now])%m][(k+a[now])%m]=f.a[j][k];
		for(int j=0;j<m;j++) t.a[(j+a[now])%m][m]=f.a[j][m];
		t.a[m][m]=g.a[m][m];
		tmp=tmp*t;
		f=tmp;

		tmp=I;
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<=m;j++)
				for(int k=0;k<=m;k++)
					t.a[j][k]=0;
			for(int j=0;j<m;j++)
				for(int k=0;k<m;k++)
					t.a[(j+i)%m][(k+i)%m]=g.a[j][k];
			for(int j=0;j<m;j++) t.a[(j+i)%m][m]=g.a[j][m];
			t.a[m][m]=g.a[m][m];
			tmp=tmp*t;
		}
		g=tmp;
	}
}
int main()
{
	LL t;scanf("%lld%d",&t,&m);
	t--;
	while(t) {a[++n]=t%m;t/=m;}
	for(int i=0;i<=m;i++) I.a[i][i]=1;
	solve(n);
	int ans=1;
	for(int i=0;i<m;i++) ans=(ans+f.a[i][m])%mmod;
	printf("%d\n",ans);
	return 0;
}