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

int main()
{
   long long int n,k,ans,i,j;

    scanf("%lld%lld",&n,&k);

    if(k==0){
        printf("%lld\n",n);

    }
    else if(k==1)
    {
        ans=0;
        for(i=1; ;i++){
            ans+=10;
            if(ans%n==0){
                printf("%lld\n",ans);
                return 0;
            }
        }
    }

    else if(k==2)
     {
        ans=0;
        for(i=1; ;i++){
            ans+=100;
            if(ans%n==0){
                printf("%lld\n",ans);
                return 0;
            }
        }
    }
    else if(k==3)
         {
        ans=0;
        for(i=1; ;i++){
            ans+=1000;
            if(ans%n==0){
                printf("%lld\n",ans);
                return 0;
            }
        }
    }
    else if(k==4)
         {
        ans=0;
        for(i=1; ;i++){
            ans+=10000;
            if(ans%n==0){
                printf("%lld\n",ans);
                return 0;
            }
        }
    }
        else if(k==5)
         {
        ans=0;
        for(i=1; ;i++){
            ans+=100000;
            if(ans%n==0){
                printf("%lld\n",ans);
                return 0;
            }
        }
    }
    else if(k==6)
         {
        ans=0;
        for(i=1; ;i++){
            ans+=1000000;
            if(ans%n==0){
                printf("%lld\n",ans);
                return 0;
            }
        }
    }
    else if(k==7)
         {
        ans=0;
        for(i=1; ;i++){
            ans+=10000000;
            if(ans%n==0){
                printf("%lld\n",ans);
                return 0;
            }
        }
    }
    else if(k==8)
         {
        ans=0;
        for(i=1; ;i++){
            ans+=100000000;
            if(ans%n==0){
                printf("%lld\n",ans);
                return 0;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int x;
  int n = 0;
  int a = 0;
  cin >> x;
  int g[x];

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

  	if (i%2 != 0)
	  {
	  	 a += 1;
	  	g[i] = a;
	  }
  	else if (i%2 == 0)
  	{
  		a += 1;
  		g[i] = -a;
	  }n += g[i];

  }

   cout << n;

  return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000009
#define MAX_N 4096
using namespace std;
typedef long long ll;
int n, w, b;
ll fact[MAX_N], inv[MAX_N];
ll quick_pow(ll a, int k)
{
    int ans = 1;
    while (k > 0)
    {
          if (k & 1)
             ans = (ans * a) % MOD;
          k >>= 1;
          a = (a * a) % MOD;
    }
    return ans % MOD;
}
void init()
{
    fact[0] = 1;
    inv[0] = 1;
    for (int i = 1; i <= MAX_N; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = quick_pow(fact[i], MOD - 2);
    }
}
ll C(ll M, ll N)
{
    if (M < N)
        return 1;
    return inv[M] * fact[N] % MOD * fact[M - N] % MOD;
}
void work()
{
    ll ans = 0;
    for (int i = 2; i < n; i++)
    {
        for (int j = i; j < n; j++)
        {
            ans = (ans + C(j - i + 1, b) * C(n - (j - i + 1), w) % MOD) % MOD;
        }
    }
    cout << ans * fact[w] % MOD * fact[b] % MOD << endl;
}
int main()
{
    ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
    freopen("306C.in", "r", stdin);
#endif
    cin >> n >> w >> b;
    init();
    work();
    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define dl long long double
#define SIZE 100000001
#define INF 0x7fffffff
#define MOD1 1000000009
#define MOD2 1000000007
#define TEST(t) ll t; cin>>t; while(t--)
#define MINV(v) *min_element(v.begin(),v.end())
#define MAXV(v) *max_element(v.begin(),v.end())
#define MINA(a,n) *min_element(a,a+n)
#define MAXA(a,n) *max_element(a,a+n)
#define rep(i,a,b) for(int i=a;i<b;++i)
#define deb(x) cout<<#x<<"="<<x<<"\n";
#define deb2(x,y) cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<"\n";
#define sortv(a) sort(a.begin(),a.end())
#define sorta(a,n) sort(a,a+n)

using namespace std;

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
char arr[4][4];
rep(i,1,5)
 rep(j,1,5) arr[i][j]=getchar();

rep(i,2,4)
 rep(j,2,4)
 {
     if(arr[i][j]==arr[i+1][j] && arr[i][j]==arr[i][j-1] || arr[i][j]==arr[i+1][j] && arr[i][j]==arr[i][j+1] )
       {puts("YES"); return 0; }
    if(arr[i][j]==arr[i+1][j] && arr[i+1][j]==arr[i+1][j+1] || arr[i][j]==arr[i+1][j] && arr[i+1][j]==arr[i+1][j-1])
      {puts("YES"); return 0;}
 }
puts("NO");
return 0;
}


//==================================================================================================
// Name        : Autori.cpp
// Author      : lotus.eater086
// Copyright   : If you're reading this then this warning is for you. Every word you read of this
//               useless fine print is another second of your life. Don't you've other things to do?
//               Is your life so empty that you honestly can't think of a better way to spend these
//               moments ? Or are you so impressed with authority that you give respect and
//               credence to all who claim it ? Do you read everything you're supposed to read ? Do
//               you think everything you're supposed to think ? Buy what you're told you should
//               want ? Get out of your apartment . Meet a member of the opposite sex. Stop the
//               excessive shopping and self-improvement . Quit your boring job.
//               Start a fight. Prove you're alive. If you don't claim your humanity you'll become a
//               statistic. You've been warned !

// Description :
// Date        : 2019-05-09 , Thursday
// Time        : 21:04:50
// Directory   : e:\Practise\VS_Code\stl_practise_code
// FilePath    : e:\Practise\VS_Code\stl_practise_code\Autori.cpp
//==================================================================================================

#include <bits/stdc++.h>
#define LL long long
#define endl "\n"

using namespace std ;

//
template < typename T >

inline T read( T &x )
{

    x = 0 ;

    int f = 0 ;

    char ch = getchar() ;

    while( ch < '0' || ch > '9' )  {

        f |= ( ch == '-' ) , ch = getchar() ;

    }

    while( ch >= '0' && ch <= '9' )  {

        x = ( x << 1 ) + ( x << 3 ) + ch - '0' , ch = getchar() ;

    }

    return x = f ? -x:x ;

}
//

int main( void )

{

    //ios_base::sync_with_stdio( false ) ;  cin.tie( NULL ) ;  cout.tie( NULL ) ;

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

    int n , m ;

    cin >> n >> m ;

    if(m==0)  cout << 1 << '\n' ;

  else  if( m < n/2 )  cout << m << endl ;

    else cout << (n-m) << endl ;

    #ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << " sec\n" ;
    #endif

    return 0 ;

}


#include <iostream>

using namespace std;

int main()
{
    int n,m; cin >> n >> m;
    int sum = 0;
    int f = m;

    while(n--){
        int tmp; cin >> tmp;
        f = f-tmp;
        if(f < 0){

            sum+=1;
            f = m-tmp;
        }
        else if(f == 0){

            sum+=1;
            f = m;
        }
        if(n == 0 && f == m-tmp)
            sum++;

    }

    cout << sum;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
/*
#include <fstream>

#include <set>

#include <stack>
#include <iomanip>
#include <utility>

*/

//#pragma warning(disable:4786)
//#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair

/*
typedef tuple<int, int, int> t3;

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

int MOD = 1000000007;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

 */
#define Se second
#define Fi first
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i=0;i<n;i++)
typedef long long ll;
const int INF = 0x3f3f3f3f;

/*
ll gcd(ll x,ll y)
{
    while(x!=y)
    {
        if(x>y) x = x-y;
        else y=y-x;

    }
    return x;
}
*/

int main()
{

    ll n,d,m,l,pos;
    cin>>n>>d>>m>>l;
    ll k=1; //板子
    ll c=1; //步数

    while(true)
    {
        if(k<n)
        {
            if(d*c>(k-1)*m+l && d*c<k*m)
            {
                // fall down
                cout<<c*d;
                return 0;
            }
            else if(d*c>=(k-1)*m && d*c<=(k-1)*m+l)
            {
                c+= ((k-1)*m+l-d*c)/d+1;
            }
            if(d*c>=k*m)
            {
                k+= (d*c-k*m)/m+1;
            }
        }
        else
        {
            if(d*c>(k-1)*m+l)
            {
                cout<<c*d;
                return 0;
            }
            else
            {
                c+= ((k-1)*m+l-d*c)/d+1;
            }
        }

    }

}


#include<cstdio>
using namespace std;
char now,fst=0;
int g=1,ans=0;
int main()
{
    now=getchar();
    while(now=='A'||now=='T'||now=='G'||now=='C')
    {
        if(now==fst) ++g;
        else {if(g%2==0) ++ans;g=1;fst=now;}
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define lld I64d
int main()
{
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    int n;
    scanf("%d",&n);
    char a[201];
    scanf(" %s",a);
    int r=0,g=0,b=0,i;
    for(i=0;i<n;i++) if(a[i]=='R') r++; else if(a[i]=='G') g++; else if(a[i]=='B') b++;
    if(b and g and r) printf("BGR");
    else if((b>=2 and g>=2)or(b>=2 and r>=2)or(r>=2 and g>=2)) printf("BGR");
    else if(b==0 and g==0) printf("R");
    else if(b==0 and r==0) printf("G");
    else if(g==0 and r==0) printf("B");

    else if(b==1 and g>=2) printf("BR");
    else if(g==1 and b>=2) printf("GR");
    else if(b==1 and r>=2) printf("BG");
    else if(r==1 and b>=2) printf("GR");
    else if(g==1 and r>=2) printf("BG");
    else if(r==1 and g>=2) printf("BR");

    else if(b==1 and g==1) printf("R");
    else if(b==1 and r==1) printf("G");
    else if(g==1 and r==1) printf("B");
    return 0;
}


#include<bits/stdc++.h>
#define int         int long long
#define pb          push_back
#define pii         pair<int,int>
#define vi	        vector<int>
#define mii        map<int,int>
#define fs           first
#define sc          second
#define  M        1000000001
#define f(i,a,b) for(int i=a;i<b;i++)
#define fm(i,a,b) for(int i=a;i>b;i--)

using namespace std;
bool c[M];

signed main()
{	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int test=1;
    int n;
    cin>>n;
    for(int i=0;i*i<=n;i++){
    	int j=i,s=0;
    	while(j){
    		s+=j%10;
    		j/=10;
    	}
    	if(i*i+s*i==n) {
    		cout<<i;
    		return 0;
    	}
    }
    cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll power(ll a,ll n){
    ll ans = 1;
    while(n){
        if(n&1) ans = ans * a;
        a = a*a;
        n>>=1;
    }
    return ans ;
}
int main(){
    ll n,ans;
    cin>>n;
    ans = 2*3*4*power(4,n-3)+3*3*4*power(4,n-4);
    return cout<<ans,0;
}


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

int main()
{
    int n,m,k;
    while(~scanf("%d%d%d",&n,&m,&k)!=EOF)
    {
        if(n<=m && n<=k)
        {
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
    return 0;
}


//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
//#define ls l,m,rt<<1
//#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;

const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100+10,maxn=1000000+10,inf=0x3f3f3f3f;

int dcmp(double x) {
    if(fabs(x) < eps) return 0;
    else return x < 0 ? -1 : 1;
}

struct Point {
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) {}
};

typedef Point Vector;

struct Circle {
    Point c;
    double r;
    Circle(){}
    Circle(Point c, double r):c(c),r(r){}
    Point point(double a){
        return Point{c.x+cos(a)*r,c.y+sin(a)*r};
    }
};
Point operator + (Vector A, Vector B) {return Point(A.x + B.x, A.y + B.y);}
Point operator - (Vector A, Vector B) {return Point(A.x - B.x, A.y - B.y);}
Point operator * (Vector A, double p) {return Point(A.x * p, A.y * p);}
Point operator / (Vector A, double p) {return Point(A.x / p, A.y / p);}
bool operator < (const Vector &A, const Vector &B) {return A.y < B.y || (A.y == B.y && A.x < B.x);}
bool operator == (const Vector &A, const Point &B) {return dcmp(A.x - B.x) == 0 && dcmp(A.y - B.y) == 0;}
double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;}
double Length(Vector A) {return sqrt(Dot(A, A));}
double Angle(Vector A, Vector B) {return acos(Dot(A, B)/Length(A)/Length(B));}
double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;}
double Area2(Point A, Point B, Point C) {return Cross(B-A, C-A);}
double angle(Vector v){return atan2(v.y,v.x);}
int getCircleCircleIntersection(Circle C1,Circle C2,vector<Point>&sol)
{
    double d = Length(C1.c-C2.c);
    if(dcmp(d)==0){
        if(dcmp(C1.r-C2.r)==0)return 1;//重合
        return 0;
    }
    if(dcmp(C1.r+C2.r-d)<0)return 0;
    if(dcmp(fabs(C1.r-C2.r)-d)>0)return 0;
    double a = angle(C2.c-C1.c);
    double da = acos((C1.r*C1.r+d*d-C2.r*C2.r)/(2*C1.r*d));
    Point p1=C1.point(a-da),p2=C1.point(a+da);
    sol.push_back(p1);
    if(p1==p2)return 1;
    sol.push_back(p2);
    return 2;
}
int fa[N];
inline int Find(int x){return fa[x]==x?x:fa[x]=Find(fa[x]);}
int main()
{
    Circle c[3];
    vector<Point>v[3],te;
    int n;scanf("%d",&n);
    if(n==1)return 0*puts("2");
    if(n==2)
    {
        scanf("%lf%lf%lf",c[0].c.x,c[0].c.y,c[0].r);
        scanf("%lf%lf%lf",c[1].c.x,c[1].c.y,c[1].r);
        getCircleCircleIntersection(c[0],c[1],te);
        if(te.size()==2)puts("4");
        else puts("3");
        return 0;
    }
    for(int i=0;i<3;i++)scanf("%lf%lf%lf",&c[i].c.x,&c[i].c.y,&c[i].r),fa[i+1]=i+1;
    for(int i=0;i<3;i++)for(int j=i+1;j<3;j++)
    {
        te.clear();
        getCircleCircleIntersection(c[i],c[j],te);
        for(auto x:te)v[i].pb(x),v[j].pb(x);
        if(te.size()!=0)
        {
            int a=Find(i+1),b=Find(j+1);
            if(a!=b)fa[a]=b;
        }
    }
    te.clear();
    int C=0,V=0,E=0;
    for(int i=0;i<3;i++)
    {
        sort(v[i].begin(),v[i].end());
        v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());
        for(auto x:v[i])te.pb(x);
        if(fa[i+1]==i+1)C++;
        if(v[i].size()!=0)E+=v[i].size();
    }
    sort(te.begin(),te.end());
    te.erase(unique(te.begin(),te.end()),te.end());
    V=te.size();
    printf("%d\n",C+1-V+E);
    return 0;
}
/********************

********************/


#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cassert>
#include <stack>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include <complex>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<algorithm>
#include <cassert>
#include <stack>
#include<cstring>
#include <cmath>
#include <complex>
#include <sstream>
#include<cstring>
#include <complex>
#include<cstdlib>
#include <set>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include <cstdio>
#include<map>
#include <vector>
#include <iostream>
using namespace std;

#define start          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nl            endl;
#define end            system("pause");
#define sz(v)            ((int)((v).size()))
#define sc(x)            scanf("%d",&x)
#define sc2(x,y)         scanf("%d%d",&x,&y)
#define sc3(x,y,z)       scanf("%d%d%d",&x,&y,&z)
#define sc4(x,y,z,a)     scanf("%d%d%d%d",&x,&y,&z,&a)
#define sc5(x,y,z,a,b)   scanf("%d%d%d%d%d",&x,&y,&z,&a,&b)
#define sc6(x,y,z,a,b,c) scanf("%d%d%d%d%d%d",&x,&y,&z,&a,&b,&c)
#define scl(x)           scanf("%lld",&x)
#define lp(i,n)        for(int i=0;i<n;i++)
#define lp1(i,f,l)     for(int i=f;i<l;i++)
#define R_(s)         freopen(s, "r", stdin)
#define W_(s)        freopen(s, "w", stdout)
#define R_W R_("input.txt"),W_("output.txt")
#define PI           acos(-1)
#define INF             1<<30
typedef string            S;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<S, int>     si;
typedef pair<int, S>     is;
typedef pair<char, int>  chi;
typedef pair<S, S>       SS;
typedef vector<ii>        vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<S>        vs;
typedef vector<ll>       vll;
typedef vector<vll>     vvll;

ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll gcd(ll a, ll b)  { return (b == 0 ? a : gcd(b, a % b)); }
ll sd(ll x)  { return x<10 ? x : x % 10 + sd(x / 10); }
ll lcm(ll a, ll b){ return ((a*b) / gcd(a, b)); }
char g[10000][10000];
int vis[10000][10000];
int dx[8]={1 , -1,-1 ,1 , 0 , 0 , 1 , -1 };
int dy[8]={1 , -1 ,1, -1 , -1, 1 , 0 , 0 };
int k=INT_MAX;
set<pair<int, int> > pts;
void dfs(int x1,int y1,int x2,int y2,int n)
{
	if(x1==x2&&y1==y2)
	{
		k=min(k,n);
		return;
	}
	if(vis[x1][y1]==1)
		return;
	vis[x1][y1]=1;
	for(int i=0;i<8;i++)
	{
		int cx=x1+dx[i];
		int cy=y1+dy[i];
		if(cx<=100000&&cy<=100000&&cx>=0&&cy>=0&&g[cx][cy]=='x')
				dfs(cx,cy,x2,y2,n+1);
	}
	return;
}
int m[1000001],m1[1000001],m2[1000001];
int main()
{
	//start;
	int n;
	cin>>n;
	int k=n,k1=n-1,k2=n-2,h=2;
	while(k>1)
	{
		if(k%h==0)
		{
			m[h]++;
			k/=h;
			h=2;
		}
		else
			h++;
	}
	h=2;
	while(k1>1)
	{
		if(k1%h==0)
		{
			if(m[h]>0)
				m[h]--;
			else
				m1[h]++;
			k1/=h;
			h=2;
		}
		else
			h++;
	}
	h=2;
	while(k2>1)
	{
		if(k2%h==0)
		{
			if(m[h]>0)
				m[h]--;
			else if(m1[h]>0)
				m1[h]--;
			else
				m2[h]++;
			k2/=h;
			h=2;
		}
		else
			h++;
	}
	long long ans=1;
	for(int i=2;i<n+1;i++)
	{
		if(m[i]>0)
			ans*=(pow((double)i,m[i]));
		if(m1[i]>0)
			ans*=(pow((double)i,m1[i]));
		if(m2[i]>0)
			ans*=(pow((double)i,m2[i]));
	}
	cout<<ans<<endl;
	//end;
}


#include <iostream>

using namespace std;

int main()
{
    int n ;
    int min , max ;
    cin >> n ;
    int num = n ;
    int x = 2 ;
    int y = 1 ;
    while (num > 0){
        if (x % 2 == 0){
        max += 2 ;
        num -= 2 ;
        }
        else {
            num -= 5 ;
        }
        x++ ;
    }
    while (n > 0){
        if (y % 2 == 0){
        min += 2 ;
        num -= 2 ;
        }
        else {
            num -= 5 ;
        }
        y++ ;
    }
    if (num < 0){
        if (x % 2 == 0){
            if (num += 2 == 0)
                max -= 2 ;
            else
                max -= 1 ;
        }
    }
    if (n < 0){
        if (y % 2 != 0){
            if (n+=2 == 0)
                min -= 2 ;
            else
                min -= 1 ;
        }
    }
    cout << min << " " << max << endl ;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int solve(int n){
 	int ans=0;
 	int i=1;
 	while(true){
 		if(pow(5,i)>n){
 		 	break;
 		}
 	 	ans+=n/pow(5,i);
 	 	i++;
 	}
 	return ans;
}
int main()
{
	int n;
	cin>>n;
	bool f=false;
	vector<int> v;
	if(n==5){
	 	cout<<0;
	 	return 0;
	}
	for(int i=1;true;i++){
	 	if(solve(i)==n){
	 	 	v.push_back(i);
	 	 	f=true;
	 	}
	 	else if(solve(i)!=n&&f){
	 	 	  break;
	 	}
	 	if (i==1000000){
	 	 	cout<<0;
	 	 	return 0;
	 	}
	}
	cout<<v.size()<<'\n';
	for(auto&p:v)cout<<p<<" ";
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define f first
#define s second
#define inp(a) cin >> a
#define out(a) cout<<a<<endl
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000007
int main()
{
	    while(1)
	    {
	    	cout <<" ";
	    }
}


#include<stdio.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include<string.h>
#include<iostream>
#include<map>
#include<set>
#include<vector>
using namespace std;
int main()
{
    long long a;
    char s[1000], d[1000];
    scanf("%s", &s);
    strcpy(d, "9223372036854775807");
    if(strlen(s)==19)
    {
        for(int i=0;i<=18;i++)
        {
            if(s[i]<d[i]) break;
            if(s[i]==d[i]) continue;
            printf("BigInteger");
            return 0;
        }
        printf("long");
        return 0;
    }
    if(strlen(s)>19)
    {
        printf("BigInteger");
        return 0;
    }
    else
    {
        sscanf(s, "%lld", &a);
        printf("%lld", a);
        for(;;);
        if(a<=127)
        {
             printf("byte");
             return 0;
        }
        if(a<=32767)
        {
            printf("short");
            return 0;
        }
        if(a<=2147483647)
        {
            printf("int");
            return 0;
        }
        printf("long");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
const int mod=1000000007;
int n;
long long a[maxn],b[maxn],num[maxn];
void init()
{
    a[1]=27;
    b[1]=7;
    num[1]=20;
    for(int i=2;i<maxn;i++)
    {
        a[i]=a[i-1]*27;
        b[i]=b[i-1]*7;
        num[i]=(a[i]-b[i])%mod;
        a[i]=a[i]%mod;
        b[i]=b[i]%mod;
    }
}
int main()
{
    init();
    while(~scanf("%d",&n))
    {
        printf("%I64d\n",num[n]);
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <sstream>
#include <utility>
#include <queue>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <stack>
#define LinkStart int main
#define mp make_pair
#define endl "\n"
#define INF 1e9
#define X first
#define Y second
#define forn(i , n) for(int i = 0 ;i < n ;  ++i)
const long long MOD = (long long)1e9+7;
using namespace std;

// sorry for that ...
#define MAX_N 501
long long power(long long a , long long b){
    if (b == 0) return 1;
    //    if (b % 2 == 0) return 1LL * power(a,b/2) * power(a,b/2);
    if (b % 2 == 0)
    {
        long long f = 1LL *power(a,b/2);
        return 1LL * f * f ;
    }
    b--;
    return 1LL * power(a,b) * a;

}
int left(int i )  { return 2 * i ; }
int right(int i ) {return 2*i + 1 ;}

vector<vector<pair<int,int>>> graph(MAX_N);
struct Node
{
private:
    int x , dist , prev;
public:
    Node(int a , int b , int c) {x = a , dist = b , prev = c;}
    Node(int a) {x = a , dist = 0 , prev = a;}
    Node(int a , int b) {x = a , dist = b ; }
    int getDist() {return dist ;}
    int getX() {return x ;}
    int getPrev() {return prev ;}
};
struct cmp
{
    bool operator()(Node &a,Node &b)
    {
        return a.getDist() < b.getDist(); // saving the maximum at top
    }
};
void addEdge(int u , int v , int w)
{
    graph[u].push_back(mp(v,w));
    graph[v].push_back(mp(u,w));
}

map<pair<int,pair<int,int>>,bool> vis;
int a , b , c , x , y , z;
void dfs(int f , int s , int t)
{
    if (vis[mp(f,mp(s,t))])
        return;
    vis[mp(f,mp(s,t))] = true;
    if (f >= x && y <= s && z <= t)
    {
        cout << "Yes" << endl;
        exit(0);
    }
    if (f >= 2){
        if (s < y)
        dfs(f-2,s+1,t);
        if (t < z)
        dfs(f-2,s,t+1);
    }
    if (s >= 2)
    {
        if (f < x)
        dfs(f+1,s-2,t);
        if (t < z)
        dfs(f,s-2,t+1);
    }
    if (t >= 2)
    {
        if (f < x)
        dfs(f+1,s,t-2);
        if (s < y)
        dfs(f,s+1,t-2);
    }
}

LinkStart()
{
    cin >> a >> b >> c >> x >> y >> z;
    dfs(a,b,c);
    cout << "No" << endl;
}


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

string s;

bool check(char c)
{
	return (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' || c == 'Y');
}

int main()
{
	cin >> s;
	int maxlen = 0;
	int cnt = 0;
	int len = s.length();
	int i = 0;
	while (len > 0) {
		cnt = 1;
		if (check(s[i])) {
			++i;
			--len;
			while (!check(s[i]) && len > 0) ++cnt, ++i, --len;
		}
		else while(!check(s[i] && len > 0)){
			++i;
			--len;
			++cnt;
		}
		if (cnt > maxlen) maxlen = cnt;
	}

	cout << maxlen << endl;

	return 0;
}


// Written by Na2a

#include <bits/stdc++.h>

#define llong long long

#define pb push_back
#define mp make_pair

#define F first
#define S second

using namespace std;

const int INF = (int) 1e9 + 7;
const int MXN = (int) 1e5 + 7;

const double EPS = (double) 1e-9;

int n;

int main() {
	#define FNAME ""

	#ifdef LOCAL
	freopen(FNAME".in", "r", stdin);
	freopen(FNAME".out", "w", stdout);
	#endif

	scanf("%d", &n);

	assert(n!=4);
	int cnt = 0;
	while (n) {
		cnt += (n & 1);
		n >>= 1;
	}
	if (cnt > 1) puts("black");
	else {
		printf("white\n%d %d", 1, 2);
	}
	return 0;
}


/*
ID: wanjunl1
PROG: socdist2
LANG: C++11
*/
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

ofstream fout("socdist2.out");
ifstream fin("socdist2.in");

int main() {
	ios::sync_with_stdio(false);
	fin.tie(0);

	int n, i, j, k, r, x, s, ans;

	fin >> n;
	vector<pair<int, int>> cow(n), sick;
	for (i = 0; i < n; i++) {
		fin >> x >> s;
		cow[i] = { x, s };
		if (s == 1) sick.push_back({ x, s });
	}

	sort(cow.begin(), cow.end());
	r = 1E9;
	for (i = 1; i < n; i++) {
		if (cow[i].second + cow[i - 1].second == 1) r = min(r, cow[i].first - cow[i - 1].first - 1);
	}

	ans = 0;
	sort(sick.begin(), sick.end());
	if (!sick.empty()) {
		ans = 1;

		for (i = 1; i < sick.size(); i++) {
			if (sick[i].first - sick[i - 1].first > r) ans++;
		}
	}

	fout << ans << "\n";

	return 0;
}


#include<cstdio>
#include<string>
using namespace std;
int c = 2000, k, a[1010], dp[100010], fr[100010];
char t = 'a';
string res;
int main() {
    scanf("%d", &k);
    if (!k) {
        puts("a");
        return 0;
    }
    for (int i = 2; i <= c; i++) a[i] = i*(i - 1) / 2;
    for (int i = 1; i <= k; i++) {
        dp[i] = 1e9;
        for (int j = 2; a[j] <= i; j++) if (dp[i] > dp[i - a[j]] + 1) {
            dp[i] = dp[i - a[j]] + 1;
            fr[i] = j;
        }
    }
    int i = k;
    while (i) {
        for (int j = 0; j < fr[i]; j++) res += t;
        t++;
        i -= a[fr[i]];
    }
    printf("%s", res.c_str());
    return 0;
}


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

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

using namespace std;

#define FOR(i,a,b) for (int i = (int)(a); i < (int)(b); ++i)
#define FORD(i,a,b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define REP(i,n) FOR(i,0,n)
#define REPD(i,a) FORD(i,a,0)
#define SQR(a) (a)*(a)
#define MP make_pair
#define PB push_back
#define FILL(a) memset(a,0,sizeof(a));
#define SIZE(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define LL long long
#define LD long double
const double PI = 2*acos(0.0);
const double EPS = 1e-8;
const int INF = 1000000000;

int a1, b1, c1, a2, b2, c2;
int main(){
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
	cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;
	if (a1==0&&b1==0 || a2==0&&b2==0){
		printf ("-1");
		return 0;
	};
	if (a1*b2 != a2*b1) printf ("1");
	else if (a1 != 0){
		if (c1*a2 != c2*a1) printf ("0");
		else printf ("-1");
	}else{
		if (c1*b2 != c2*b1) printf ("0");
		else printf ("-1");
	};
	return 0;
};


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=100005;
const int BASE[2]={223,233};
const int MOD[2]={1000000007,1000000009};
int pw[MAXN][2];
void build()
{
    for(int i=(pw[0][0]=pw[0][1]=1);i<MAXN;i++)
        for(int j=0;j<2;j++)pw[i][j]=1LL*pw[i-1][j]*BASE[j]%MOD[j];
}
struct info
{
    int v[2],sz;
    info operator + (const info &r)const
    {
        int tv[2];
        for(int j=0;j<2;j++)
            tv[j]=(1LL*pw[r.sz][j]*v[j]+r.v[j])%MOD[j];
        return info{tv[0],tv[1],sz+r.sz};
    }
    bool operator < (const info &r)const
    {
        return v[0]==r.v[0] ? (v[1]==r.v[1] ? sz<r.sz : v[1]<r.v[1]) : v[0]<r.v[0];
    }
    bool operator == (const info &r)const
    {
        return v[0]==r.v[0] && v[1]==r.v[1] && sz==r.sz;
    }
};
vector<int>e[MAXN];
info dp[MAXN],all[MAXN];
void dfs1(int u,int fa)
{
    vector<info>nxt;
    for(int i=0;i<(int)e[u].size();i++)
    {
        int v=e[u][i];
        if(v==fa)continue;
        dfs1(v,u);
        nxt.push_back(dp[v]);
    }
    dp[u]=info{'(','(',1};
    sort(nxt.begin(),nxt.end());
    for(int i=0;i<(int)nxt.size();i++)
        dp[u]=dp[u]+nxt[i];
    dp[u]=dp[u]+info{')',')',1};
}
void dfs2(int u,int fa,info o)
{
    vector<pair<info,int> >nxt;
    for(int i=0;i<(int)e[u].size();i++)
    {
        int v=e[u][i];
        if(v==fa)nxt.push_back(make_pair(o,v));
        else nxt.push_back(make_pair(dp[v],v));
    }
    all[u]=info{'(','(',1};
    sort(nxt.begin(),nxt.end());
    for(int i=0;i<(int)nxt.size();i++)
        all[u]=all[u]+nxt[i].first;
    all[u]=all[u]+info{')',')',1};
    vector<info>pre(nxt.size()),suf(nxt.size());
    pre.front()=suf.back()=info{0,0,0};
    for(int i=0;i<(int)nxt.size()-1;i++)
        pre[i+1]=pre[i]+nxt[i].first;
    for(int i=(int)nxt.size()-1;i>=1;i--)
        suf[i-1]=nxt[i].first+suf[i];
    for(int i=0;i<(int)nxt.size();i++)
    {
        int v=nxt[i].second;
        if(v!=fa)dfs2(v,u,info{'(','(',1}+pre[i]+suf[i]+info{')',')',1});
    }
}
int main()
{
    build();
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs1(1,0);
    dfs2(1,0,info{0,0,0});
    vector<info>tmp;
    for(int i=1;i<=n;i++)
        if((int)e[i].size()<4)tmp.push_back(all[i]);
    sort(tmp.begin(),tmp.end());
    int res=unique(tmp.begin(),tmp.end())-tmp.begin();
    return 0*printf("%d",res);
}


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

int main()
{
    int y,i,len;
    int a=0,b=0,c=0;
    char arr[100];
    cin>>arr;
    cout<<arr;
    len=strlen(arr);
   for( i=0;i<len;i++)
   {
        y=arr[i];
        cout<<y;
        if(y >=48 && y<=57)
        {
                a++;
         }
         if(y >=65 && y <= 90)
        {
                 b++;
         }
         if(y >= 97 && y <= 122)
        {
                 c++;
         }
   }
    if(len>5 && a>0 && b>0 && c>0)
         {
                      cout<<"Correct";
         }
         else
         {
             cout<<"Too weak";
             }

    getch();
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
	long long n, a, b, c, minx = 1000000007;
	while (scanf("%lld%lld%lld%lld", &n, &a, &b, &c))
	{
		if (n % 4 == 0){
			puts("0");
		}
		else{
			n %= 4;
			if (n == 1){
				minx = min(3 * a, minx);
				minx = min(minx, c);
			}
			else if (n == 2){
				minx = min(2 * a, minx);
				minx = min(b, minx);
				minx = min(3 * c, minx);
			}
			else{
				minx = min(a, minx);
				minx = min(minx, 3 * c);
			}
			printf("%lld\n", minx);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename F, typename S>
using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define pf printf
#define sf scanf
#define left __left
#define right __right
#define tree __tree

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

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

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

int ans = 0;

void solve(int lim) {
	queue<int> bfs;
	if (4 <= lim)
		bfs.push(4);
	if (7 <= lim)
		bfs.push(7);
	while (!bfs.empty()) {
		int u = bfs.front();
		bfs.pop();
		++ans;
		int v = u * 10 + 4;
		if (v <= lim)
			bfs.push(v);
		v = u * 10 + 7;
		if (v <= lim)
			bfs.push(v);
	}
}

bool lucky(int num) {
	while (num > 0) {
		int lol = num % 10;
		if (lol != 4 && lol != 7)
			return false;
		num /= 10;
	}
	return true;
}

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

	--k;

	vi store;

	for (int i = 1; k > 0; ++i) {
		store.PB(k % i);
		k /= i;
		dbg(i, k);
	}

	if (store.size() > n) {
		cout << -1 << endl;
		return 0;
	}

	dbg(store, n - store.size());

	solve(n - store.size());

	set<int> yo;

	for (int i = n; i > n - store.size(); --i) {
		yo.insert(i);
	}

	dbg(yo);
	dbg(ans);

	for (int i = n - store.size() + 1, j = store.size() - 1; i <= n; ++i, --j) {
		auto it = yo.begin();
		for (int l = 0; l < store[j]; ++l)
			++it;
		int it2 = *it;
		yo.erase(it2);
		dbg(i, it2);
		if (lucky(i) && lucky(it2))
			++ans;
	}

	cout << ans << endl;
}


#include <stdio.h>
const int N=5e2+10;
const int INF=1e8+10;
int f[N][N],n;
int dis(int a,int b){return a>b?n-a+b:b-a;}
int min(int a,int b){return a>b?b:a;}
void add(int &a){a=(a%n)+1;}
int dp(int l,int r){
//	printf("%d %d\n",l,r);
	if(dis(l,r)<2)return 0;
	if(dis(l,r)==2){
		r*=l;
		add(l);
		return l*r;
	}
	if(f[l][r]!=-1)return f[l][r];
	int ans=INF;
	for(int i=(l%n)+1;i!=r;add(i))for(int j=i+1;j!=r;add(j))ans=min(ans,dp(l,i)+dp(i,j)+dp(j,r)+l*i*j);
	return f[l][r]=ans;
}
int main(){
	int ans=INF;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[i][j]=-1;
	for(int i=2;i<n;i++)for(int j=i+1;j<=n;j++)ans=min(ans,dp(1,i)+dp(i,j)+dp(j,1)+i*j);
	printf("%d\n",ans);
}


#include <iostream>

using namespace std;
class node
{
 public: int matchbox , matchs ;
};
int main()
{
     int burg , container , counter=0;
     node  tmp ;

     cin>>burg >> container ;
     node array1[container] ;
   for(int i=0 ; i<container ; i++)
     {

       cin>> array1[i].matchbox>> array1[i].matchs ;
     }

  for(int i=0;i<container;i++ )
  {
   for(int j=0 ; j<container;j++)
   {
     if(array1[j].matchs < array1[j-1].matchs)
     {
     tmp = array1[j];
     array1[j] = array1[j-1];
     array1[j-1] = tmp;
     }
   }
  }

for(int i = container-1 ; i>=0&& burg>0 ; i--)
{
if(burg>array1[i].matchbox)
{
      counter=counter + (array1[i].matchbox*array1[i].matchs) ;
      burg = burg-array1[i].matchbox;
}
else
{
    counter=counter+array1[i].matchs*burg;
    burg=0;
}
}
cout<<counter<<endl;

   return counter;
    return 0;
}


#include <bits/extc++.h>
#define INF 0x3f3f3f3f
using namespace std;

struct node{
	int x, y, step;
};
int cnt, head[305], v[1005], w[1005], c[1005], _next[1005];
int n, m, a[11][11], b[105][2], dx[] = {-1, -2, -2, -1, 1, 2, 2, 1},
							 dy[] = {2, 1, -1, -2, -2, -1, 1, 2};
int dis[305], cost[305];
int front, back, q[3005];
bool h[305], g[15][15];

inline void Addedge(int x, int y, int z, int t) {
	v[++cnt] = y, w[cnt] = z, c[cnt] = t;
	_next[cnt] = head[x], head[x] = cnt;
}
int Bfs(int k, int x1, int y1, int x2, int y2) {
	if(k == 2)
		return (x1 != x2) + (y1 != y2);
	if(k == 1)
		return 1 + (x1 - x2 != y1 - y2);
	if(n < 3)
		return INF;
	memset(g, 0, sizeof(g)), g[x1][y1] = true;
	for(int i = 0; i <= m + 1; ++i)
		g[i][0] = g[i][m + 1] = true;
	for(int j = 1; j <= m; ++j)
		g[0][j] = g[m + 1][j] = true;
	deque<node> q;
	q.push_back({x1, y1, 0});
	while(!q.empty()) {
		node x = q.front();q.pop_front();
		if(x.step == 5)
			break;
		for(int i = 0; i < 8; ++i)
			if(!g[x.x + dx[i]][x.y + dy[i]]) {
				if(x.x + dx[i] == x2 && x.y + dy[i] == y2)
					return x.step + 1;
				g[x.x + dx[i]][x.y + dy[i]] = true;
				q.push_back({x.x + dx[i], x.y + dy[i], x.step + 1});
			}
	}
	return INF;
}
void Build() {
	for(int i = 1; i < n; ++i)
		for(int k = 0; k < 3; ++k) {
			Addedge(i + k * n, i + 1 + k * n,
					Bfs(k, b[i][0], b[i][1], b[i + 1][0], b[i + 1][1]), 0);
			Addedge(i + k * n, i + (k ? 3 - k : 1) * n, 1, 1);
			Addedge(i + (k ? 3 - k : 1) * n, i + k * n, 1, 1);
			Addedge(i + k * n, i + (k ? 0 : 2) * n, 1, 1);
			Addedge(i + (k ? 0 : 2) * n, i + k * n, 1, 1);
		}
	Addedge(0, 1, 0, 0), Addedge(0, 1 + n, 0, 0), Addedge(0, 1 + n * 2, 0, 0);
	Addedge(n, 3 * n + 1, 0, 0), Addedge(n * 2, 3 * n + 1, 0, 0), Addedge(n * 3, 3 * n + 1, 0, 0);
}
void Spfa() {
	memset(dis, 0x3f, sizeof(dis)), dis[0] = 0;
	memset(cost, 0x3f, sizeof(cost)), cost[0] = 0;
	memset(h, 0, sizeof(h));
	front = back = 0;
	q[back++] = 0, h[0] = 1;
	while(front < back) {
		int x = q[front++];h[x] = false;
		for(int i = head[x]; i; i = _next[i])
			if(dis[v[i]] > dis[x] + w[i] ||
				(dis[v[i]] == dis[x] + w[i] && cost[v[i]] > cost[x] + c[i])) {
				dis[v[i]] = dis[x] + w[i], cost[v[i]] = cost[x] + c[i];
				if(!h[v[i]])
					q[back++] = v[i], h[v[i]] = true;
			}
	}
	printf("%d %d\n", dis[3 * n + 1], cost[3 * n + 1]);
}
void Init() {
	scanf("%d", &n), m = n, n *= n;
	for(int i = 1; i <= m; ++i)
		for(int j = 1; j <= m; ++j)
			scanf("%d", a[i] + j), b[a[i][j]][0] = i, b[a[i][j]][1] = j;
}
int main() {
	Init();
	Build();
	Spfa();
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <string>
#include <cstring>
#include <string.h>
#include <iostream>
#include <ctime>
#include <random>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

ll n, a, b, c, k, t;

int main()
{
//	freopen("INPUT.TXT", "r", stdin);
//	freopen("OUTPUT.TXT", "w", stdout);
	cin >> n >> a >> b >> c;
	if (a <= b - c){
		cout << n / a;
		return 0;
	}
	if (b <= a){
		while (n / b != 0){
			t = n / b;
			n -= t * b;
			k += t;
			n += t * c;
		}
		cout << k;
		return 0;
	}
	while (n >= min(a, b)){
		if (n / b != 0){
			t = n / b;
			n -= t * b;
			k += t;
			n += t * c;
		}
		else{
			k += n / a;
			break;
		}
	}
	cout << k;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll bin_pow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1) res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}
ll n, k;
ll s;
ll mas[35];
ll fact[35];
ll a[35];
vector<ll> ans[35];
vector<ll> merg(vector<ll>  &f, vector<ll>  s){
    vector<ll> ans;

    ll i = 0;
    ll j = 0;
    while(i < f.size() && j < s.size()){
        if(f[i] < s[j]){
            ans.push_back(f[i ++]);
        }
        else{
            ans.push_back(s[j++]);
        }
    }
    while(i < f.size()){
        ans.push_back(f[i ++]);
    }
    while(j < s.size()){
        ans.push_back(s[j ++]);
    }
    return ans;
}
int main(){
    cin >> n >> k >> s;
    for(ll i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a, a + n);
    ll cr = bin_pow(3, min(n, (ll)14));
    for(ll i = 0; i <= 30; ++i){
        mas[i] = bin_pow(3, i);
    }
    fact[0] = 1;
    for(ll i = 1; i <= 30; ++i){
        fact[i] = fact[i - 1] * i;
    }
    //cout << fact[18] << endl;
    ll res = 0;
    for(ll mask = 0; mask < cr; ++mask){
        ll msk = mask;
        ll sum = s;
        ll fl = 0;
        ll cnt = 0;
        for(ll i = min(n, (ll)14) - 1; i >= 0; --i){
            if(2 * mas[i] <= msk){
                if(a[i] <= 18){
                    msk -= 2 * mas[i];
                    sum -= fact[a[i]];
                    cnt++;
                }
                else{
                    fl = 1;
                }
            }
            else if(mas[i] <= msk){
                msk -= mas[i];
                sum -= a[i];
            }
            else{

            }
        }
        if(!fl) ans[cnt].push_back(sum);
    }
    //cout << res << endl;
    for(ll i = 0; i <= k; ++i)
        sort(ans[i].begin(), ans[i].end());
    for(ll i = 0; i < k; ++i){
        ans[i + 1] = merg(ans[i], ans[i + 1]);
    }
    //cout << upper_bound(ans[25].begin(), ans[25].end(), 0) - lower_bound(ans[25].begin(), ans[25].end(), 0) << endl;
    /*for(ll i = 0; i < ans.size(); ++i){
        cout << ans[i] << endl;
    }*/
    cr = bin_pow(3, max(n - 14, (ll)0));
    for(ll mask = 0; mask < cr; ++mask){
        ll msk = mask;
        ll sum = 0;
        ll fl = 0;
        ll cnt = 0;
        for(ll i = max(n - 14, (ll)0) - 1; i >= 0; --i){
            if(2 * mas[i] <= msk){
                if(a[i + 14] <= 18){
                    msk -= 2 * mas[i];
                    sum += fact[a[i + (ll)14]];
                    cnt++;
                }
                else{
                    fl = 1;
                }
            }
            else if(mas[i] <= msk){
                msk -= mas[i];
                sum += a[i + 14];
            }
            else{

            }
        }
        if(!fl){
            ll dop = k - cnt;
            if(dop >= 0)
                res += upper_bound(ans[dop].begin(), ans[dop].end(), sum) - lower_bound(ans[dop].begin(), ans[dop].end(), sum);
        }
    }
    cout << res << endl;
    return 0;
}


        // "It does not matter how slowly you go as long as you do not stop." - Confucius
#include <bits/stdc++.h>

using namespace std;

/*
author : Roshan_Mehta
motto : Time Management,Consistency,Patience!!
*/

#define int long long

#ifdef Local_Debug

#define debug(x) cout<<#x <<" "<<x<<"  "
#define debug1(a) cout <<#a<<" " <<a << endl
#define debug2(a, b) cout <<#a<<" "<< a << " "<<#b<<" " << b << endl
#define debug3(a, b, c) cout <<#a<<" "<<a << " "<<#b<<" " << b << " "<<#c<<" " << c << endl
#define debug4(a, b, c, d) cout << #a<<" "<<a << " " <<#b<<" "<< b << " "<<#c<<" " << c << " "<<#d<<" "<< d << endl
void show(vector<int> &a)
{for (int i = 0; i < a.size(); i++)
{cout << a[i] << " ";}cout << endl;}
void show(vector<vector<int>> &a)
{
    for(int i=0;i<a.size();i++)
    {
        for(int j=0;j<a[i].size();j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
}
void show(vector<pair<int,int>> &a)
{
    for (int i = 0; i < (int)a.size(); i++)
    {
        cout<<a[i].first<<" "<<a[i].second<<endl;
    }

}
void printTime(clock_t begin)
{
    printf("%.3lf seconds\n", (double) (clock() - begin) / CLOCKS_PER_SEC);

}
#else
#define debug(x)
#define debug1(x)
#define debug2(x,y)
#define debug3(x,y,z)
#define debug4(x,y,z,a)
void show(vector<int> &a){return;}
void show(vector<vector<int>> &a){return;}
void show(vector<pair<int,int>> &a){return ;}
void printTime()
{return;}
#endif

#define M1 1000000007
#define M2 998244353
#define G(a,b) get<a>(b)
#define ll long long
#define pb push_back
#define mt make_tuple
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rsort(x) sort(x,greater<int> ())
#define rall(x) rbegin(x), rend(x) //useful in sorting
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd(a,b)
#define deci(n) fixed << setprecision(n)
#define test() int test_case;cin >> test_case;while (test_case--)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define sp " "
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define clz(x) __builtin_clz(x)
#define clzll(x) __builtin_clzll(x)
#define ctz(x) __builtin_ctz(x)
#define ctzll(x) __builtin_ctzll(x)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define max5(a,b,c,d,e) max(max4(a,b,c,d),e)
#define min5(a,b,c,d,e) min(min4(a,b,c,d),e)
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define pie 3.141592653589793238462643383279

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef pair<int,pi> tri;
typedef pair<pi,int> rtri;
typedef pair<ll, ll> pl;
typedef pair<double, double> pd;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
typedef set<int> si;
#define input(n,k) int n,k;cin>>n;cin>>k;vi arr(n,0);loop(i,0,n){cin>>arr[i];}

const int MOD = 1e9 + 7;
int md=MOD;

int Power(int n, int x) {int ans = 1;while (x > 0) {if (x & 1) ans = (ans * n) % md;
n = (n * n) % md;x = x >> 1;}return ans;}

vl fact, inv;

void inverse(ll n)
{if(n>=inv.size()){ll size=inv.size();size=size==0? 1:size;
inv.resize(n + 1);inv[0] = 1;
for (ll i = size; i <= n; i++)inv[i] = Power(fact[i], md - 2);}}

void factorial(ll n)
{if(n>=fact.size()){ll size=fact.size();size=size==0? 1:size;
fact.resize(n + 1);fact[0] = 1;for (ll i = size; i <= n; i++)
fact[i] = (fact[i - 1] * i) % md;
}}

ll ncr(ll n, ll r) { return (((fact[n] * inv[r]) % md) * inv[n - r]) % md; }

vl SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {if (prime[p] == true){for (int i=p*p; i<=n; i += p)
    prime[i] = false;}}

    vl ans;for (int p=2; p<=n; p++)if (prime[p])ans.pb(p);return ans;
}
vi primeFactors(int n)
{
    vi ans;
    while (n % 2 == 0) {ans.pb(2);n = n / 2;}
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {ans.pb(i);n = n / i;}}
    if (n > 2)ans.pb(n);return ans;
}
bool isprime(ll n)
{
    if(n<2)
        return false;
    for(ll x:{2,3,5,7,11,13,17,19,23,29,31,37})
    {
        if(n==x)
            return true;
        bool flag=true;
        ll r=1;
        ll t=1;
        while(r<=((n-1)>>__builtin_ctzll(n-1)))
        {
            if(r&((n-1)>>__builtin_ctzll(n-1)))
                t=((__int128)t*x)%n;
            x=((__int128)x*x)%n;
            r<<=1;
        }
        if(t==1||t==n-1)
            flag=false;
        for(r=0;r<__builtin_ctzll(n-1);r++)
        {
            t=((__int128)t*t)%n;
            if(t==n-1)
                flag=false;
        }
        if(flag)
            return false;
    }
    return true;
}

ll NcR(int n, int r)
{long long p = 1, k = 1;if (n - r < r)r = n - r;if (r != 0) {while (r) {p *= n;k *= r;
long long m = gcd(p, k);p /= m;k /= m;n--;r--;}
}else p = 1;return p;// cout << p << endl;
}
bool sortasc(const rtri a,const rtri b) //Ascending ... change the argument accordingwise;
{
    return a.second<b.second;
}
bool sortdesc(const int a,const int b) //Descending... change the argument accordingwise;a
{
    return a>b;
}
int myceil(int num,int den)
{
    return num%den == 0 ? num/den : num/den + 1;
}
int myfloor(int num,int den)
{
    return num%den == 0 ? num/den : num/den - 1;
}
int midofthree(int a,int b,int c)
{
    if((a<=b and a>=c) or (a<=c and a>=b))
        return a;
    else if((b>=a and b<=c) or (b<=a and b>=c))
        return b;
    return c;
}
string to_str(char c) {
	return string(1, c);
}
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {ll q=a/m;ll t=m;m=a%m;a=t;t=y;y=x-q*y;x=t;
    }
    if(x<0) x+=m0;
    return x;
}
#define pow10(n) stoll("1"+string(n,'0'))

// 2-D vector with both size--> vector<vector<int> > a(n, vector<int>(m));

void q1();void q2();void q3();void q4();void q5();void q6();
//********************THE END OF TEMPLATES*******************//

const int N = 2e5 + 5;
int n,m,k;
vi arr,brr,crr;
vi primes={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};
vi numPrime(60);
vvi dp;
vvi table;

int solve(int pos,int mask)
{
    if(pos==n or pos<0) return 0;
    if(dp[pos][mask]!=-1) return dp[pos][mask];
    int a=solve(pos+1,mask) + abs(arr[pos]-1);
    int val=1;
    for (int i = 2; i < 60; i++)
    {
        int num=i+1;
        if(((numPrime[i-1]&mask))!=numPrime[i-1])continue;
        num=(numPrime[i-1]^mask);
        int ans=solve(pos+1,num)+abs(arr[pos]-i);
        if(ans<a)
        {
            val=i;
            a=ans;
        }

    }
    dp[pos][mask]=a;
    table[pos][mask]=val;
    return a;

}

int32_t main()
{
    clock_t begin = clock();
    fast();
    // test()
    {
        cin>>n;
        arr=vi(n);
        dp=vvi(n,vi(1<<17+2,-1));
        table=vvi(n,vi(1<<17+2,-1));
        for (int i = 0; i < n; i++)
        {
            cin>>arr[i];
        }
        numPrime=vi(60);
        for (int i = 0; i < 60; i++)
        {
            for (int j = 0; j < 17; j++)
            {
                if((i+1)%primes[j]==0)
                {
                    numPrime[i]+=(1<<j);
                }
            }
        }
        show(numPrime);
        int a=solve(0,(1<<17)-1);
        int x=(1<<17)-1;
        REP(i,0,n)
        {
            cout<<table[i][x]<<sp;
            x=(x^numPrime[table[i][x]-1]);
        }
        cout<<endl;

        // for (int i = 0; i < n; i++)
        // {
        //     for(int j=0;j<100;j++)
        //         cout<<dp[i][j]<<sp;
        //     cout<<"............ "<<endl;
        // }

    }

    return 0;
}


#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <map>
#include <cstring>
#include <climits>
#include <deque>
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <array>
#include <queue>

using namespace std;

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

#define FV(i,v) for(int i=0; i<(int)(v).size(); i++)
#define FI(i,v) for(typeof(v.begin()) i = v.begin(); i != v.end(); ++i)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
#define FOR(i, st, en) for(int i=(st); i<(int)(en); i++)

void do_nothing() {}

ll n, m, k;

ll go(ll nch)
{
    int k1 = nch-1;
    int k2 = k - k1;
    int mch = k2+1;
    if (mch > m || k1 > k)
        return -1;
    return (n / nch) * (m / mch);
}

void solve()
{
    cin >> n >> m >> k;
    if (n > m) swap(n, m);
    ll ans = -1;

    for (int i = 1; i <= sqrt(n); ++i) {
        ans = max(ans, go(i));
        ans = max(ans, go(n/i));
    }

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

#ifdef ONLINE_JUDGE
int main() { solve(); return 0; }
#else
void perform_testing(void (*solve)(), string problem, int itest);
int main() { perform_testing(solve, "A", -1); return 0; }
#endif // ONLINE_JUDGE


#include <bits/stdc++.h>
using namespace std;
#define raftaar ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define in freopen("input.txt","r",stdin);
#define out freopen("out.txt","w",stdout);
#define sublime in out
#define int int64_t
#define rep(i,a,b) for (int i = a; i <= b; ++i)
typedef long double ld;
typedef vector<int> vi;
#define F first
#define S second
#define PB push_back
#define LB lower_bound
#define mp make_pair
typedef pair<int,int> PII;
typedef vector<PII> VII;
#define all(c) (c).begin(),(c).end()
#define sz(a) ((int)(a).size())
bool isprime(int n){for(int i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
int factorial(int n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}
int max(int a,int b){int sol=a>b?a:b;return sol;}
int min(int a,int b){int sol=a<b?a:b;return sol;}
int power(int x,int y){int ans=1;while(y > 0){ if(y & 1){ans*=x;}y>>=1LL; x*=x;}return ans;}
int mod=1000000007;
int mn[100010]={0};
inline int solve(){

  int n,m,s;
  cin>>n>>m>>s;
  int a[n],b[m];
  rep(i,0,n-1){
    cin>>a[i];
  }
  rep(i,0,m-1){
    cin>>b[i];
  }
  sort(a,a+n);
  sort(b,b+n);
  reverse(b,b+n);
  int i=0,cnt=0;
  int ans=0,res=s;
  while(s>0){
    if((s-(s/a[i])*a[i])>=0)
      cnt+=s/a[i];
    s-=(s/a[i])*a[i];
    if(s==1 && a[i]>1){
      ans++;
      break;
    }
  }
  cout<<max(res,ans+cnt*b[0]);

  return 0;
}

signed main(){

    //sublime;
    raftaar;

    solve();

}


#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  freopen("chat.txt","r",stdin);
  freopen("chat2.txt","w",stdout);
  char a[8][8];
  int count=0;
  int t;
  for(int i=0;i<8;i++){
   for(int j=0;j<8;j++){
    cin>>a[i][j];
    }
  }
  for(int i=0;i<8;i++){
   if(a[i][0]=='B'){ count++; }
   else{ t=i; }
  }
  if(count<8){
   for(int i=0;i<8;i++){
    if(a[t][i]=='B'){ count++; }
   }
  }
  cout<<count;
  return 0;
}


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

int main(void)
{
    int n,l=0,b,c;
    scanf("%d %d",&n,&b);
    c=n;
    while (n>=b)
    {
        l++;
        n=n-b+1;
    }

    printf("%d",c+l);

    getch();
    return 0;
        }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
     ll u,v;
     cin>>u>>v;
     if(v-u<=1)
          cout<<"-1"<<endl;
     else
     {
     unordered_map<ll,vector<ll>> um;
     for(ll i=u;i<=v;i++)
     {
          for(int j=2;j<=i/2;i++)
          {
               if(i%j==0)
               um[i].emplace_back(j);
          }
          um[i].emplace_back(i);
     }
     for(auto i:um)
     {
          cout<<i.first<<"-->";
          for(auto j:i.second)
          cout<<j<<",";
          cout<<endl;
     }
     }
     return 0;
}


#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
#define int long long

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

const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 5e2 + 11;
const int X = 1e6;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

//ifstream in(".in");
//ofstream out(".out");

int n, k, dp[N][N][N];

void solve(){

    cin >> n >> k;

    string s, t;

    cin >> s >> t;

    //s = '.' + s + '.';

    char a = t[0], b = t[1];

    if(a == b){
        int x = 0;
        for(int i = 1; i <= n; i++)x += (s[i] == a);
        x = min(n, x + k);
        cout << x * (x - 1) / 2 << '\n';
        return;
    }

    memset(dp, -1, sizeof(dp));

    dp[0][0][0] = 0;

    int ans = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= k; j++){
            for(int cnt = 0; cnt <= i; cnt++){
                if(dp[i][j][cnt] == -1)continue;
                dp[i + 1][j + 1][cnt + 1] = max(dp[i + 1][j + 1][cnt + 1], dp[i][j][cnt]);
                dp[i + 1][j + 1][cnt] = max(dp[i + 1][j + 1][cnt], dp[i][j][cnt] + cnt);
                dp[i + 1][j][cnt + (s[i] == a)] = max(dp[i + 1][j][cnt + (s[i] == a)], dp[i][j][cnt] + (s[i] == b)*cnt);
            }
        }
    }

    for(int j = 0; j <= k; j++){
        for(int cnt = 0; cnt <= n; cnt++){
            ans = max(ans, dp[n][j][cnt]);
        }
    }

    cout << ans << '\n';

}

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

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

    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
}


#include<iostream>
using namespace std;
int n,a[10000000],t,b[100000000];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
            cin>>a[i]>>b[i];
    }
    for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                    if(i!=j){
                            t++;
                    }
            }
    }
    cout<<t;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t,ans="";
    int i=0;
    cin>>s>>t;
    while(s[i]==t[i]&&i<s.size())
    {
        ans+=s[i];
        i++;
    }
    if(t[i]-s[i]==1)
        ans+=s[i++];
    else
        ans+=s[i++]+1;
    while(i<s.size())
        if(s[i]<'z')
            ans+=s[i]+1;
        else
            ans+=s[i];
    if(ans>s&&ans<t)
        cout<<ans<<endl;
    else
        cout<<"No such string"<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(ll I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

ll d,k,a,b,t;
vector<ll> tr;
inline ll check(ll x){
	if(x<0||x>=d)return linf;
	return x*a+(x-1)/k*t+(d-x)*b;
}

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>d>>k>>a>>b>>t;
	ll l=0,r=d/k+1;

	FOR(i,l,r){
		if(i*k<=d){
			tr.push_back(i*k);
			if((i+1)*k>d){
				FOR(j,i*k+1,d+1){
					tr.push_back(j);
				}
			}
		}
	}
	l=0,r=tr.size();
	while(l<r-1){
		ll mid=l+r>>1;
		if(mid==0){
			if(check(tr[0])<check(tr[1])){
				l=0;
				break;
			}
			else {
				l=1;
				break;
			}
		}
		if(mid==tr.size()-1){
			if(check(tr[mid])<check(tr[mid-1])){
				l=mid;
				break;
			}
			else {
				l=mid-1;
				break;
			}
		}
		if(check(tr[mid-1])<check(tr[mid])&&check(tr[mid])<check(tr[mid+1])){
			r=mid;
		}
		else if(check(tr[mid-1])>check(tr[mid])&&check(tr[mid])>check(tr[mid+1])){
			l=mid+1;
		}
		else if(check(tr[mid-1])>check(tr[mid])&&check(tr[mid])<check(tr[mid+1])){
			l=mid;
			break;
		}
		else {
			if(check(tr[0])<check(tr[tr.size()-1])){
				l=0;
				break;
			}
			else {
				r=0;
				break;
			}
		}
	}
	ll ans=linf;
	FOR(i,-k,k+1){
		Umin(ans,check(tr[l]+i));
	}
	Tone(ans);

	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;

ll n,ans,tmp[2];
void dfs(ll num)
{
	if(num>=n and tmp[0]==tmp[1]) ans=min(ans,num);
	tmp[0]++;
	dfs(num*10+4);
	tmp[0]--;
	tmp[1]++;
	dfs(num*10+7);
	tmp[1]--;
}

int main()
{
	ans=1e9+100000;
	cin>>n;
	dfs(0);
	cout<<ans<<endl;
	return 0;
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
vector< pair<int,int> > nineless,ans,extra,Zero;
vector< pair< pair<int,int> ,int> > ten,nine;
string st;
int vis1[10],vis2[10],tvis1[10],tvis2[10],arr[2][100],No[10][10];
int main()
{

    cin>>st;
    for(int i=0;i<sz(st);i++)
    {
        int val=st[i]-'0';
        vis1[val]++;
        vis2[val]++;
        tvis1[val]++;
        tvis2[val]++;
    }

    for(int i=0,j=9;i<=4;i++,j--)
    {
        if(vis1[i]>0&&vis2[j]>0)
        {
            int V=min(vis1[i],vis2[j]);
            vis1[i]-=V;
            vis2[j]-=V;
            while(V--)
                nine.pb(mp(mp(i,j),1)),arr[0][i]++,arr[1][j]++;

        }

        if(vis2[i]>0&&vis1[j]>0)
        {
            int V=min(vis2[i],vis1[j]);
             vis2[i]-=V;
            vis1[j]-=V;
            while(V--)
                nine.pb(mp(mp(j,i),1)),arr[0][j]++,arr[1][i]++;

        }
    }
    int fl=0,F,S;
    for(int i=1,j=9;i<=5&&!fl&&sz(nine)>0;i++,j--)
    {
        if(vis1[i]>0&&vis2[j]>0)
        {
            fl=1;
            F=i;
            S=j;
            vis1[i]--;
            vis2[j]--;
        }
        else if(vis2[i]>0&&vis1[j]>0)
        {
             fl=1;
            F=j;
            S=i;
            vis2[i]--;
            vis1[j]--;
        }
    }

    if(!fl)
    {
        int cnt=3,oth;
        for(int i=1,j=9;i<=5&&cnt>1&&sz(nine)>1;i++,j--)
        {
             if(tvis1[i]==0||tvis1[j]==0)
                continue;
            if((arr[0][i]||arr[1][i])&&(arr[0][j]||arr[1][j]))
            {
                 F=i;
                 S=j;
                 cnt=2;
            }
            else
            {
                cnt=1;
                F=i;
                S=j;

                if(arr[0][i])
                {
                    oth=9-i;
                    vis2[oth]++;
                    vis2[j]--;
                    No[i][oth]=1;
                }
                else if(arr[1][i])
                {
                    oth=9-i;
                    vis1[oth]++;
                    vis1[j]--;
                    No[oth][i]=1;
                }

                else if(arr[0][j])
                {
                    oth=9-j;
                    vis2[oth]++;
                    vis2[i]--;
                    No[j][oth]=1;
                }
                else if(arr[1][j])
                {
                    oth=9-j;
                    vis1[oth]++;
                    vis1[i]--;
                    No[oth][j]=1;
                }

            }

        }
        if(cnt==1&&sz(nine)>1)
            fl=1;
        if(cnt>1&&sz(nine)>2)
        {
            fl=1;
              if(arr[0][F])
                {
                    oth=9-F;
                    vis2[oth]++;
                    vis2[S]--;
                    No[F][oth]=1;
                }
                else if(arr[1][F])
                {
                    oth=9-F;
                    vis1[oth]++;
                    vis1[S]--;
                    No[oth][F]=1;
                }

                if(arr[0][S])
                {
                    oth=9-S;
                    vis2[oth]++;
                    vis2[F]--;
                    No[S][oth]=1;
                }
                else if(arr[1][S])
                {
                    oth=9-S;
                    vis1[oth]++;
                    vis1[F]--;
                    No[oth][S]=1;
                }
        }

    }

    if(fl)
    {
        ans.pb(mp(F,S));
        for(int i=0;i<sz(nine);i++)
        {
            if(No[nine[i].first.first][nine[i].first.second])
                continue;
             ans.pb(mp(nine[i].first.first,nine[i].first.second));
        }

        for(int i=1,j=9;i<=5;i++,j--)
       {
           if(vis1[i]>0&&vis2[j]>0)
          {

              int V=min(vis1[i],vis2[j]);

              vis1[i]-=V;
              vis2[j]-=V;
              while(V--)
                ten.pb(mp(mp(i,j),1));

          }
       }

      if(vis1[0]>0&&vis2[0]>0)
      {
          int V=min(vis1[0],vis2[0]);
          vis1[0]-=V;
          vis2[0]-=V;
          while(V--)
            Zero.pb(mp(0,0));

      }

        for(int i=0;i<=9;i++)
        {
            for(int j=0;j<=9;j++)
            {
                int V=min(vis1[i],vis2[j]);
                vis1[i]-=V;
                vis2[j]-=V;
                 while(V--)
                ans.pb(mp(i,j));
            }
        }

        for(int i=sz(ans)-1;i>=0;i--)
            cout<<ans[i].first;

        for(int i=0;i<sz(Zero);i++)
          cout<<"0";
        cout<<endl;
        for(int i=sz(ans)-1;i>=0;i--)
            cout<<ans[i].second;

        for(int i=0;i<sz(Zero);i++)
          cout<<"0";
        cout<<endl;
        return 0;
    }
// ----------------------------------------------------------------------------------------

    for(int i=1,j=9;i<=5;i++,j--)
    {
        if(tvis1[i]>0&&tvis2[j]>0)
        {
            int V=min(tvis1[i],tvis2[j]);

            tvis1[i]-=V; tvis2[j]-=V;
            while(V--)
                ten.pb(mp(mp(i,j),1));
        }
        if(tvis1[j]>0&&tvis2[i]>0)
        {
            int V=min(tvis1[j],tvis2[i]);

            tvis1[j]-=V; tvis2[i]-=V;
            while(V--)
                ten.pb(mp(mp(j,i),1));
        }

    }

      if(tvis1[0]>0&&tvis2[0]>0)
      {
          int V=min(tvis1[0],tvis2[0]);
          tvis1[0]-=V;
          tvis2[0]-=V;
          while(V--)
            Zero.pb(mp(0,0));

      }

       int sizezero=sz(Zero);

       int id=0;

      for(int i=0;i<sz(ten);i++)
       ans.pb(mp(ten[i].first.first,ten[i].first.second));

        for(int i=0;i<=9;i++)
        {
            for(int j=0;j<=9;j++)
            {
                int V=min(tvis1[i],tvis2[j]);
                tvis1[i]-=V;
                tvis2[j]-=V;
                 while(V--)
                ans.pb(mp(i,j));

            }
        }

        for(int i=sz(ans)-1;i>=0;i--)
            cout<<ans[i].first;

        for(int i=0;i<sizezero;i++)
          cout<<"0";
        cout<<endl;
        for(int i=sz(ans)-1;i>=0;i--)
            cout<<ans[i].second;

        for(int i=0;i<sizezero;i++)
          cout<<"0";
        cout<<endl;
        return 0;

}


#include <bits/stdc++.h>

#define sc second
#define fr first
#define ll long long
#define pii pair <int, int>
#define piii pair <pii, int>

using namespace std;

set <pii> ans;

ll vec_prod(pii a, pii b) {
    return a.fr * b.sc - a.sc * b.fr;
}

vector <int> pr(pii x, pii y) {
    return  {x.sc - y.sc, y.fr - x.fr, x.fr * y.sc - y.fr * x.sc};
}

pii ser(pii a, pii b) {
    return {(a.fr + b.fr) / 2, (a.sc + b.sc) / 2};
}

void new_p (pii x, pii y, pii z) {
    vector <int> a = pr(x, z);
    vector <int> b = pr(y, ser(x, z));
    a[2] *= -1; b[2] *= -1;
    ll det = vec_prod({a[0], a[1]}, {b[0], b[1]});
    ll det_a = vec_prod({a[2], a[1]}, {b[2], b[1]});
    ll det_b = vec_prod({a[0], a[2]}, {b[0], b[2]});
    ans.insert({2 * det_a / det - y.fr, 2 * det_b / det - y.sc});
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    vector <pii> p(3);
    for (int i = 0; i < 3; i++) cin >> p[i].fr >> p[i].sc, p[i].fr *= 2, p[i].sc *= 2;
    new_p(p[0], p[1], p[2]);
    new_p(p[0], p[2], p[1]);
    new_p(p[1], p[0], p[2]);
    for (auto i : ans) {
        if (i.fr % 2 != 0 || i.sc % 2 != 0) ans.erase(i);
    }
    cout << ans.size() << '\n';
    for (auto i : ans) cout << i.fr / 2 << " " << i.sc / 2 << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define pn cout<<endl

const ll mod=1000000007ll;
const ll Mod=1000000009ll;
const ll maxn=100005;

using namespace std;

int main(){

	int a,b,x;
	cin>>a>>b>>x;
	int A=a,B=b,X=x;

	if( x==1 ){
		string ans="";
		while(a--)ans+='0';
		while(b--)ans+='1';
		cout<<ans<<endl;
		return 0;
	}

	string ans="";

	if( a==1 ){
		ans+="10";b--;a--;
		while( b-- ) ans+='1';
		cout<<ans<<endl;return 0;
	}else if( b==1 ){
		ans+="01";b--;a--;
		while( a-- ) ans+='0';
		cout<<ans<<endl;return 0;
	}

	ans="0";a--;

	char c='1';
	while( x>1 && a>0 && b>0 ){
		ans+=c;
		if( c=='1' ){
			b--;
			c='0';
		}else{
			a--;
			c='1';
		}
		x--;
	}

	char l=ans[ans.size()-1];
	if(l=='0'){
		while(a>0){
			ans+='0';
			a--;
		}
	}else{
		while(b>0){
			ans+='1';
			b--;
		}
	}

	while(a>0){
		ans+='0';
		a--;
	}
	while(b>0){
		ans+='1';
		b--;
	}

	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main (void){
	long long n, m, a, b;
	cin >> n >> m >> a >> b;
	if(n % m == 0 && n >= m){
		printf("0");
	}else{
		if(n >= m){
			printf("%lld",min((m*2-n)*a, (n - m) * b));
		}else {
			printf("%lld",min(b*n,(m-n)*a));
		}
	}

	return 0;
}


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

using namespace std;

#define X first
#define Y second
#define pb push_back

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

const int M = 2000000;

bool F[50][50][20][20];
ll a1, b1, a2, b2;
ii can2[M], can3[M], qu[M];
int s2x, s3x, s2y, s3y, fr, re;

int chia2(ll x) {
    int res = 0;
    for (;x%2==0;x/=2) res++;
    return res;
}

int chia3(ll x) {
    int res = 0;
    for (;x%3==0;x/=3) res++;
    return res;
}

int main() {
    //freopen("input.txt","r",stdin);
    scanf("%I64d%I64d",&a1,&b1);
    scanf("%I64d%I64d",&a2,&b2);
    ll x = a1*b1, y = a2*b2;
    can2[1].X = chia2(x);
    can3[1].X = chia3(x);
    can2[1].Y = chia2(y);
    can3[1].Y = chia3(y);
    s2x = can2[1].X; s3x = can3[1].X;
    s2y = can2[1].Y; s3y = can3[1].Y;
    fr = re = 1;
    qu[1].X = x, qu[1].Y = y;
    F[can2[1].X][can2[1].Y][can3[1].X][can3[1].Y] = true;
    while (fr <= re) {
        int u = fr++;
        if (qu[u].X == qu[u].Y) {
            int chia3x = s3x-can3[u].X;
            int chia3y = s3y-can3[u].Y;
            int chia2x = chia3x + s2x - can2[u].X;
            int chia2y = chia3y + s2y - can2[u].Y;
            printf("%d\n",chia2x+chia3x+chia2y+chia3y);
            while (a1%3==0 && chia3x != 0) {
                chia3x--;
                a1=a1/3;
                a1*=2;
            }
            while (b1%3==0 && chia3x != 0) {
                chia3x--;
                b1=b1/3;
                b1*=2;
            }
            while (a1%2==0 && chia2x != 0) {
                chia2x--;
                a1/=2;
            }
            while (b1%2==0 && chia2x != 0) {
                chia2x--;
                b1/=2;
            }
            printf("%I64d %I64d\n",a1,b1);
            while (a2%3==0 && chia3y != 0) {
                chia3y--;
                a2=a2/3;
                a2*=2;
            }
            while (b2%3==0 && chia3y != 0) {
                chia3y--;
                b2=b2/3;
                b2*=2;
            }
            while (a2%2==0 && chia2y != 0) {
                chia2y--;
                a2/=2;
            }
            while (b2%2==0 && chia2y != 0) {
                chia2y--;
                b2/=2;
            }
            printf("%I64d %I64d\n",a2,b2);
            return 0;
        }
        if (can3[u].X > 0) {
            int p1 = can2[u].X+1, p2 = can2[u].Y, p3 = can3[u].X-1, p4 = can3[u].Y;
            if (!F[p1][p2][p3][p4]) {
                re++;
                qu[re].X = (qu[u].X/3)*2;
                qu[re].Y = qu[u].Y;
                can2[re].X = p1;
                can3[re].X = p3;
                can2[re].Y = p2;
                can3[re].Y = p4;
                F[p1][p2][p3][p4] = true;
            }
        }
        if (can3[u].Y > 0) {
            int p1 = can2[u].X, p2 = can2[u].Y+1, p3 = can3[u].X, p4 = can3[u].Y-1;
            if (!F[p1][p2][p3][p4]) {
                re++;
                qu[re].Y = (qu[u].Y/3)*2;
                qu[re].X = qu[u].X;
                can2[re].Y = p2;
                can3[re].Y = p4;
                can2[re].X = p1;
                can3[re].X = p3;
                F[p1][p2][p3][p4] = true;
            }
        }
        if (can2[u].X > 0) {
            int p1 = can2[u].X-1, p2 = can2[u].Y, p3 = can3[u].X, p4 = can3[u].Y;
            if (!F[p1][p2][p3][p4]) {
                re++;
                qu[re].X = qu[u].X/2;
                qu[re].Y = qu[u].Y;
                can2[re].X = p1;
                can2[re].Y = p2;
                can3[re].X = p3;
                can3[re].Y = p4;
                F[p1][p2][p3][p4] = true;
            }
        }
        if (can2[u].Y > 0) {
            int p1 = can2[u].X, p2 = can2[u].Y-1, p3 = can3[u].X, p4 = can3[u].Y;
            if (!F[p1][p2][p3][p4]) {
                re++;
                qu[re].Y = qu[u].Y/2;
                qu[re].X = qu[u].X;
                can2[re].Y = p2;
                can2[re].X = p1;
                can3[re].X = p3;
                can3[re].Y = p4;
                F[p1][p2][p3][p4] = true;
            }
        }
    }
    printf("-1\n");
    return 0;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define mp make_pair
#define ll long long
#define pb push_back
#define MAX (10 << 8)

using namespace std;

int recurse(vector<int> a) {
	int count = 0, value;
	for(int i=0; i<6; i++) {
		if(a[i] != 0) {
			count++;
			value = a[i];
		}
	}
	if(count == 0)
		return 0;
	if(count == 3) {
		return value*value;
	}
	int ans = 0;
	for(int i=0; i<6; i++) {
		ans += a[i] + a[i] - 1;
		a[i]--;
	}
	return ans + recurse(a);
}

int main() {
	vector<int> a(6,0);
	for(int i=0; i<6; i++)
		cin >> a[i];
	cout << recurse(a) << endl;
}


#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <cmath>

//#define dat cin
//#define sol cout

using namespace std;

long long ans=0,n,h,D[36][36][36]={0};

long long rec(long l,long r,int curh)
{
	if (D[l][r][curh]!=-1) return D[l][r][curh];
	if (l==r)
	{
		if (curh==1)
		{
			D[l][r][curh]=1;
			return 1;
		}
		D[l][r][curh]=0;
		return 0;
	}
	D[l][r][curh]=0;
	for(int i=l;i<=r;i++)
	{
		long long a=0,b=0;
		for(int j=1;j<=curh-1;j++)
		{
			if (D[l][i-1][j]==-1)
			{
				D[l][i-1][j]=rec(l,i-1,j);
			}
			if (j<=i-l) a+=D[l][i-1][j];
		}
		for(int j=1;j<=curh-1;j++)
		{
			if (D[i+1][r][j]==-1)
			{
				D[i+1][r][j]=rec(i+1,r,j);
			}
			if (j<=r-i) b+=D[i+1][r][j];
		}
		if (i==l) a=1;
		if (i==r) b=1;
		D[l][r][curh]+=a*D[i+1][r][curh-1]+b*D[l][i-1][curh-1]-D[i+1][r][curh-1]*D[l][i-1][curh-1];
		//if (a!=0&&b!=0) D[l][r][curh]-=D[i+1][r][curh-1]*D[l][i-1][curh-1];
	}
	return D[l][r][curh];
}

long long F[35][35]={{1LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,2LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,1LL,4LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,6LL,8LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,6LL,20LL,16LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,4LL,40LL,56LL,32LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,1LL,68LL,152LL,144LL,64LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,94LL,376LL,480LL,352LL,128LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,114LL,844LL,1440LL,1376LL,832LL,256LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,116LL,1744LL,4056LL,4736LL,3712LL,1920LL,512LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,94LL,3340LL,10856LL,15248LL,14272LL,9600LL,4352LL,1024LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,60LL,5976LL,27672LL,47104LL,50784LL,40576LL,24064LL,9728LL,2048LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,28LL,10040LL,67616LL,140640LL,172640LL,156864LL,110592LL,58880LL,21504LL,4096LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,8LL,15856LL,159184LL,407360LL,568832LL,575104LL,459648LL,291840LL,141312LL,47104LL,8192LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,1LL,23460LL,362280LL,1148560LL,1828832LL,2036416LL,1797504LL,1294592LL,750592LL,333824LL,102400LL,16384LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,32398LL,798616LL,3162016LL,5757088LL,7034624LL,6753920LL,5362176LL,3534336LL,1890304LL,778240LL,221184LL,32768LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,41658LL,1707996LL,8519936LL,17787296LL,23837888LL,24680192LL,21221888LL,15428096LL,9407488LL,4677632LL,1794048LL,475136LL,65536LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,49700LL,3549264LL,22509880LL,54043904LL,79490560LL,88356224LL,81360896LL,64001024LL,43114496LL,24516608LL,11403264LL,4096000LL,1015808LL,131072LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,54746LL,7173268LL,58398904LL,161750576LL,261375872LL,311302912LL,304774656LL,256124416LL,186805248LL,117606400LL,62754816LL,27443200LL,9273344LL,2162688LL,262144LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,55308LL,14106912LL,148944824LL,477548320LL,848747360LL,1082465792LL,1121787392LL,998363136LL,777627648LL,530757632LL,314294272LL,158162944LL,65306624LL,20840448LL,4587520LL,524288LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,50788LL,26998408LL,373795392LL,1392370816LL,2725177888LL,3721705408LL,4072178176LL,3815017472LL,3142885376LL,2292318208LL,1474125824LL,825221120LL,393265152LL,153878528LL,46530560LL,9699328LL,1048576LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,41944LL,50281552LL,923759632LL,4012903040LL,8661019648LL,12669134336LL,14615585664LL,14354835456LL,12420958208LL,9581846528LL,6592151552LL,4015030272LL,2133557248LL,966230016LL,359399424LL,103284736LL,20447232LL,2097152LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,30782LL,91112332LL,2249452664LL,11440852656LL,27269918496LL,42744083520LL,51955447936LL,53350881536LL,48241517568LL,39063693312LL,28443553792LL,18559721472LL,10750836736LL,5441552384LL,2348875776LL,832831488LL,228065280LL,42991616LL,4194304LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,19788LL,160598072LL,5400350424LL,32287286016LL,85125888544LL,143051618688LL,183151769216LL,196283898880LL,184792143360LL,156180760576LL,119395450880LL,82536128512LL,51298041856LL,28357197824LL,13711048704LL,5655887872LL,1916272640LL,501219328LL,90177536LL,8388608LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,10948LL,275265768LL,12787646784LL,90243346464LL,263617541856LL,475228604864LL,640858237696LL,716008943616LL,699971274240LL,614815341568LL,490462109696LL,356201177088LL,234820550656LL,139496587264LL,73801007104LL,34173222912LL,13502251008LL,4380950528LL,1096810496LL,188743680LL,16777216LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,5096LL,458586336LL,29877438160LL,249927387520LL,810312196608LL,1568071256960LL,2227424574336LL,2592694947840LL,2626954982400LL,2390075516928LL,1980265936896LL,1501270507520LL,1040692576256LL,656580444160LL,373878685696LL,189771022336LL,84338016256LL,31983140864LL,9957277696LL,2390753280LL,394264576LL,33554432LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,1932LL,742177352LL,68898173680LL,686127464032LL,2473393675136LL,5141691166976LL,7694767520256LL,9327552546304LL,9782061866496LL,9195996838912LL,7884207302656LL,6208112537600LL,4495161327616LL,2985240625152LL,1807710945280LL,989100113920LL,482685485056LL,206286880768LL,75221696512LL,22510829568LL,5192548352LL,822083584LL,67108864LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,568LL,1166066448LL,156849466192LL,1867851876096LL,7500108043840LL,16761612319488LL,26433778739200LL,33363089296384LL,36181838540800LL,35078982944768LL,31030590838784LL,25277194321920LL,19017559433216LL,13202668716032LL,8424692121600LL,4908421742592LL,2585999704064LL,1215598952448LL,500455964672LL,175764406272LL,50642026496LL,11240734720LL,1711276032LL,134217728LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,120LL,1777171440LL,352570167936LL,5043847399104LL,22600810802240LL,54345284324480LL,90340503396352LL,118709900792832LL,133045544290304LL,132839481270272LL,120963998351360LL,101612199141376LL,79102034927616LL,57095292567552LL,38120347402240LL,23430019940352LL,13161271394304LL,6688855818240LL,3033712820224LL,1205029830656LL,408235802624LL,113413980160LL,24259854336LL,3556769792LL,268435456LL,0LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,16LL,2625062112LL,782623399584LL,13513955130240LL,67700773955328LL,175302921200384LL,307275775120640LL,420365978662912LL,486683936452608LL,499900635516928LL,467746877538304LL,404139588091904LL,324423182778368LL,242397568991232LL,168386998272000LL,108392826273792LL,64304262938624LL,34888446115840LL,17131806654464LL,7508190035968LL,2881528791040LL,942938259456LL,252933308416LL,52210696192LL,7381975040LL,536870912LL,0LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,1LL,3754272036LL,1715723058440LL,35934333358224LL,201647244166816LL,562761689886528LL,1040492448400000LL,1482023117715712LL,1771986588376576LL,1870965641665536LL,1796268406929408LL,1592991482097664LL,1314995990913024LL,1013433629458432LL,729174527803392LL,488758779641856LL,303969566195712LL,174367827296256LL,91518602838016LL,43483421212672LL,18439615807488LL,6846471471104LL,2166827778048LL,561902518272LL,112071802880LL,15300820992LL,1073741824LL,0LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,0LL,5193067630LL,3714994326360LL,94849945630240LL,597342327594016LL,1798373079328256LL,3508642043646336LL,5203702330254848LL,6424333256475136LL,6968690921414656LL,6857228086724608LL,6231223188594688LL,5277388855599104LL,4182811782807552LL,3105639601963008LL,2157544686092288LL,1398391260971008LL,841747403374592LL,467616541966336LL,237761774747648LL,109449138143232LL,44964591435776LL,16170719641600LL,4955553398784LL,1243795685376LL,239981297664LL,31675383808LL,2147483648LL,0LL,0LL,0LL},
{0LL,0LL,0LL,0LL,0LL,6939692682LL,7945186001532LL,248569783531200LL,1760269402680864LL,5722083018161088LL,11785244795234048LL,18202227167442432LL,23200959301821952LL,25844220535682048LL,26041922768232448LL,24214697889644544LL,21000745022742528LL,17076599438589952LL,13043643454783488LL,9356039778336768LL,6289521148821504LL,3948863553273856LL,2304162062663680LL,1241334511828992LL,612202855792640LL,273358612594688LL,108920672616448LL,37982979489792LL,11283080413184LL,2743947231232LL,512711720960LL,65498251264LL,4294967296LL,0LL,0LL},
{0LL,0LL,0LL,0LL,0LL,8948546308LL,16783915117392LL,646870549233400LL,5161109260829184LL,18131601082249472LL,39439812680305024LL,63445462889276416LL,83488430778133504LL,95473991137787904LL,98449033815943168LL,93564352628391936LL,82964072871657472LL,69069422904213504LL,54135865717456896LL,39965333680553984LL,27756093541974016LL,18088027970600960LL,11017971345915904LL,6240488478736384LL,3264328706818048LL,1563319366320128LL,677827309469696LL,262220168560640LL,88757646655488LL,25583375351808LL,6034429050880LL,1093069176832LL,135291469824LL,8589934592LL,0LL},
{0LL,0LL,0LL,0LL,0LL,11120136162LL,35020715240292LL,1671898254430936LL,15058793149816432LL,57227564427440384LL,131526812341598720LL,220412997379239936LL,299435238940948992LL,351453101812474880LL,370664906188462080LL,359730660499795968LL,325694063753740288LL,277131902941757440LL,222407522986819584LL,168537354356785152LL,120531245843742720LL,81201156965269504LL,51377939762642944LL,30403767642882048LL,16735649902100480LL,8509345889255424LL,3961376951238656LL,1669476437196800LL,627643636514816LL,206406598787072LL,57782610952192LL,13231720497152LL,2325724790784LL,279172874240LL,17179869184LL}
};

int main()
{
	ifstream dat("input.txt");
	ofstream sol("output.txt");
	dat >> n >> h;
/*	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int t=1;t<=n;t++)
				D[i][j][t]=-1;
	for(int i=1;i<=35;i++)
	{
		sol << "{";
		for(int j=1;j<=35;j++)
		{
			sol << rec(1,i,j) << "LL";
			if (j!=35) sol << ",";
		}
		sol << "}," << endl;
	}
*/	for(int i=h;i<=n;i++)
		ans+=F[n-1][i-1];
	sol << ans << endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define For(i,x,y) for(int i=(int)x;i<=(int)y;i++)
#define pb push_back
#define mk make_pair
#define fi fisrt
#define se second
inline int read()
{
	int x=0,c=getchar(),f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	return f?-x:x;
}
inline void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
typedef vector<int> vi;
const int N=100000+10;
int n,m,cnt=1,head[N],du[N],layer[N],leader[N],q[N];
bool vis1[N],vis2[N],vis3[N*2];
vector<vi>ans;
vi tmp,_;
vector<pair<int,int> >comp;
struct edge{int to,nxt;}e[N*4];
void addedge(int u,int v)
{
	e[++cnt]=(edge){v,head[u]};head[u]=cnt;
	e[++cnt]=(edge){u,head[v]};head[v]=cnt;
	du[u]++;du[v]++;
}
void dfs(int u,int fa,int lineid)
{
	vis1[u]=1;
	vis2[layer[u]]=1;
	tmp.pb(u);
	for(int i=head[u],v;i;i=e[i].nxt)if((i>>1)!=lineid)
	{
		if(!vis1[v=e[i].to])
		{
			dfs(v,u,i>>1);
			tmp.pb(u);
			for(;cnt>=0&&vis2[comp[cnt].se];cnt--);
			if(cnt>=0)
			{
				vis3[i>>1]=1;
				v=leader[comp[cnt].se];
				ans.pb(tmp);tmp.clear();
				_.clear();_.pb(i>>1);_.pb(u);_.pb(v);
				ans.pb(_);
				dfs(v,u,i>>1);
				tmp.pb(u);
			}
		}else
		{
			if(vis3[i>>1])continue;
			for(;cnt>=0&&vis2[comp[cnt].se];cnt--);
			if(cnt>=0)
			{
				vis3[i>>1]=1;
				v=leader[comp[cnt].se];
				ans.pb(tmp);tmp.clear();
				_.clear();_.pb(i>>1);_.pb(u);_.pb(v);
				ans.pb(_);
				dfs(v,u,i>>1);
				tmp.pb(u);
			}
		}
	}
}
void print()
{
	puts("YES");write(ans.size()/2);puts("");
	For(i,0,ans.size()-1)
	{
		if(i&1)write(ans[i][0]),putchar(' '),write(ans[i][1]),putchar(' '),write(ans[i][2]),puts("");else
		{
			write(ans[i].size());
			For(j,0,ans[i].size()-1)putchar(' '),write(ans[i][j]);
			puts("");
		}
	}
}
int findbridge()
{
	For(i,1,n)vis1[i]=0;
	For(i,1,m)vis3[i]=0;
	For(i,2,n)if(!vis1[i])
	{
		q[*q]=i;vis1[i]=1;
		For(j,1,*q)
		{
			int u=q[j];
			for(int k=head[u],v;k;k=e[k].nxt)if(!vis3[k>>1])
			{
				vis3[k>>1]=1;
				if(vis1[v=e[k].to])return k>>1;else vis1[v]=1,q[++*q]=v;
			}
		}
	}
	return 0;
}
int getblo(int l,int r)
{
	For(i,l,r)vis1[i]=0;
	int blo=0;
	comp.clear();
	For(i,l,r)if(!vis1[i])
	{
		++blo;
		q[*q=1]=i;vis1[i]=1;
		For(j,1,*q)
		{
			int u=q[j];
			for(int k=head[u],v;k;k=e[k].nxt)if(!vis1[v=e[k].to])vis1[v]=1,q[++*q]=v;
		}
		For(j,1,*q)layer[q[j]]=blo;
		leader[blo]=q[1];
		comp.pb(mk(*q,blo));
	}
	sort(comp.begin(),comp.end());
	return blo;
}
void go(int id)
{
	int u=1;
	For(i,2,n)
	{
		for(int j=head[i],pre;j;pre=j,j=e[j].nxt)if((j>>1)==id)
	 	{
			if(du[i]>1)u=i;
			du[i]--;
			if(j==head[i])head[i]=e[j].nxt;else e[pre].nxt=e[j].nxt;
			break;
	 	}
	}
	getblo(2,n);
	cnt=comp.size()-1;
	For(i,1,n)vis1[i]=vis2[i]=0;
	For(i,1,m)vis3[i]=0;
	vis1[1]=1;
	_.clear();_.pb(1);ans.pb(_);
	_.clear();_.pb(id);_.pb(1);_.pb(u);ans.pb(_);
	dfs(u,1,0);
	if(tmp.size())ans.pb(tmp),tmp.clear();
	print();
}
int main()
{
	n=read(),m=read();
	For(i,1,m)addedge(read(),read());
	if(n==1)return puts("YES\n0\n1 1\n"),0;
	int blo=getblo(1,n);
	if(m<blo-1)return puts("NO"),0;
	if(du[1])
	{
		For(i,1,n)vis1[i]=vis2[i]=0;
		For(i,1,m)vis3[i]=0;
		cnt=comp.size()-1;
		dfs(1,0,0);
		if(tmp.size())ans.pb(tmp),tmp.clear();
		print();
	}else
	{
		int id=findbridge();
		if(id)go(id);else
		{
			if(m<blo)puts("NO");else
			{
				For(i,2,n)if(du[i]>1){id=head[i]/2;break;}
				if(id)go(id);else puts("NO");
			}
		}
	}
}


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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) (int)x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-7

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(str) scanf("%s",str)
#define pi(x) printf("%d",x)
//#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define NL printf("\n")
#define Max 1000005
#define INF 1e18
#define un(x) x.erase(unique( x.begin() , x.end() ), x.end())
#define mod 1000000007

#define FI freopen("z.txt","r",stdin)

#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDD(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
#define all(x) x.begin(),x.end()
#define prntvctr(x) for(int i = 0; i < x.size(); i++) printf("%d%c", x[i], i + 1 == x.size() ? '\n' : ' ' );
#define pc(x) __builtin_popcount(x)

typedef long long LL;
typedef unsigned long long ULL;

const double PI = acos(-1.0);

using namespace std;

int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(LL n,LL pos)
{
    return (bool)(n & (1ll << pos));
}

LL bigmod(LL b,LL p,LL m)
{
    if( p == 0 ) return 1;
    LL ret = bigmod(b,p/2,m);
    ret = ( ret * ret ) % m;
    if( p & 1 ) ret = ( ret * b ) % m;
    return ret;
}

vector <LL> v;
LL ara[] = {1,5,10,50};
LL n;
LL ans[] = {0,4,10,20,35,56,83,116,155,198,244,292,341,390,439,488,537,586,635,684,733,782,831,880,929,978,1027,1076,1125,1174,1223,1272,1321,1370,1419,1468,1517,1566,1615,1664,1713,1762,1811,1860,1909,1958,2007,2056,2105,2154,2203,2252,2301,2350,2399,2448,2497,2546,2595,2644,2693,2742,2791,2840,2889,2938,2987,3036,3085,3134,3183,3232,3281,3330,3379,3428,3477,3526,3575,3624,3673,3722,3771,3820,3869,3918,3967,4016,4065,4114,4163,4212,4261,4310,4359,4408,4457,4506,4555,4604,4653};

bool visit[5005][250005];
LL F(LL cur, LL sum)
{
	if( visit[cur][sum] ) return 0;
	visit[cur][sum] = 1;
	if( cur == 0 ) return 1;
	LL ret = 0;
	for(int i = 0; i < 4; i++) ret += F( cur - 1, sum + ara[i] );
	return ret;
}

void brute()
{
	LL ret = F(n,0);
	D(ret);
}

int main()
{
	sl(n);
	if( n <= 100 ) printf("%lld\n", ans[n]);
	else
	{
		LL ret = ans[100] + (n - 100) * 49;
		printf("%lld\n", ret);
	}
	//brute();
	return 0;
}