#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<memory.h>
#include<assert.h>
#include<ctype.h>

typedef long long ll;

#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define abs(k) (((k)>0)?(k):(-(k)))
int modint(int a,int b) {return(((a)>=0)?((a)-(b)*((a)/(b))):((a)-(b)*((a)/(b)+1)));}
ll modll(ll a,ll b) {return(((a)>=0)?((a)-(b)*((a)/(b))):((a)-(b)*((a)/(b)+1)));}
#define mod(a,b) a=modint(a,b)
#define llmod(a,b) a=modll(a,b)
#define mset(a) memset(a,0,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
#define inf (1e9)
#define linf (1e18)
#define pi 3.14159265358979323846

void fileio_in_out()
{
     freopen(".in","r",stdin);
     freopen(".out","w",stdout);
}

void fileio_txt()
{
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
}

//==================================================

#define modnum (inf+9)

int n,h,x,y,z,ww,xx,yy,zz;
int i,j,k,l;
ll dp[33][33][33][2][2],ans=0,t;

int main()
{
    //fileio_in_out();
    //fileio_txt();

    scanf("%d%d",&n,&h);

    mset(dp);
    dp[0][0][0][0][1]=1;
    for(k=0;k<n;k++)
      for(x=0;x<=h;x++)
        for(y=0;y<=h;y++)
          for(z=0;z<=h;z++)
            for(j=0;j<=1;j++)
              {
                i=k%2;
                t=dp[x][y][z][i][j];
                llmod(t,modnum);
                dp[x][y][z][i][j]=0;

                i^=1;
                xx=min(x+1,h);
                yy=min(y+1,h);
                zz=min(z+1,h);
                ww=j?1:h;

                dp[xx][yy][zz][i][j]+=t;
                dp[yy][zz][ww][i][(x<h)]+=t;
                dp[xx][zz][ww][i][(y<h)]+=t;
                dp[xx][yy][ww][i][(z<h)]+=t;
              }

    i=n%2;
    for(x=0;x<=h;x++)
      for(y=0;y<=h;y++)
        for(z=0;z<=h;z++)
          for(j=0;j<=1;j++)
            if(x<h||y<h||z<h||j)
              {
                ans+=dp[x][y][z][i][j];
                llmod(ans,modnum);
              }

    printf("%I64d\n",ans);

    //system("pause");
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define ll long long
int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}

int main(){
  int i,j,k,l,m,n;
  int t1,t2,x1,x2,t0;
  double opt, tmp;
  int r1, r2;
  ll y1, y2, yy1, yy2;

  while(scanf("%d%d%d%d%d",&t1,&t2,&x1,&x2,&t0)==5){
    opt = 1e100;

    if(t1==t0 && t2==t0){
      printf("%d %d\n",x1,x2);
      continue;
    }
    if(t1==t0){
      printf("%d 0\n",x1);
      continue;
    }
    if(t2==t0){
      printf("0 %d\n",x2);
      continue;
    }

    y2 = 1;
    REP(y1,0,x1+1){
      while(t1*y1+t2*y2 < t0*(y1+y2)){
        y2++;
        if(y2 > x2) break;
      }
      if(y2 > x2) break;

      k = GCD(y1, y2);
      if(k>1) continue;

      tmp = (t1*y1+t2*y2) / (double)(y1+y2);
      if(opt > tmp){
        opt = tmp;

        k = 1000000000;
        if(y1 && k > x1 / y1) k = x1 / y1;
        if(y2 && k > x2 / y2) k = x2 / y2;

        r1 = y1 * k;
        r2 = y2 * k;
      }
    }

    printf("%d %d\n",r1,r2);
  }

  return 0;
}


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

#define N	200000
#define K	447	/* K = floor(sqrt(N)) */

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

int main() {
	static int aa[N], *ii[N], kk[N], ii1[N + 1], ii2[K + 2], ll[N], ll_[N];
	int n, i, k, a, a_, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]), aa[i]--;
		kk[aa[i]]++;
	}
	for (a = 0; a < n; a++)
		ii[a] = (int *) malloc(kk[a] * sizeof *ii[a]), kk[a] = 0;
	memset(ii1, -1, (K + 2) * sizeof *ii1), memset(ii2, -1, (K + 2) * sizeof *ii2);
	ans = 0, a_ = -1;
	for (i = 0; i < n; i++) {
		a = aa[i];
		ii[a][kk[a]++] = i;
		if (a_ == -1 || kk[a_] < kk[a])
			a_ = a;
		for (k = 1; k <= kk[a] && k <= K + 1; k++)
			if (ii1[k] < ii[a][kk[a] - k])
				ii2[k] = ii1[k], ii1[k] = ii[a][kk[a] - k];
			else if (ii2[k] < ii[a][kk[a] - k])
				ii2[k] = ii[a][kk[a] - k];
		for (k = 1; k <= K; k++)
			if (ii2[k] > ii1[k + 1])
				ans = max(ans, i - ii1[k + 1]);
		ll[i] = ii1[K + 1];
	}
	for (i = 0; i < n; i++)
		ll_[i] = i + 1;
	for (a = 0; a < n; a++)
		if (a != a_ && kk[a] > K) {
			int d;

			memset(ii1, -1, (n + 1) * sizeof *ii1), ii1[0] = 0;
			d = 0;
			for (i = 0; i < n; i++) {
				if (aa[i] == a_)
					d++;
				else if (aa[i] == a)
					d--;
				if (d >= 0) {
					if (ii1[d] == -1)
						ii1[d] = i + 1;
					ll_[i] = min(ll_[i], ii1[d]);
				}
			}
		}
	for (i = n - 1; i >= 0; i--) {
		if (ll_[i] <= ll[i])
			ans = max(ans, i - ll_[i] + 1);
		if (ll_[i] == 0)
			break;
	}
	printf("%d\n", ans);
	return 0;
}


#include"stdio.h"
#include"string.h"
#include"math.h"
#include"stdlib.h"
#include"ctype.h"
#include"limits.h"
#include"time.h"

int main()
{
	clock_t lnh=clock();
	int n,m,x=1,c;
	scanf("%d%d",&n,&m);
	int a[100]={0},d[100]={0},ac[100]={0},i,j,l[m];
	for(i=0;i<m;scanf("%d",&l[i++]));

	for(i=0;i<m-1;i++)
	{
		c=l[i+1]-l[i]+n*(l[i]>=l[i+1]);
		d[c-1]=1;
		if(a[l[i]-1]!=c && a[l[i]-1])
		x=0;
		else
		a[l[i]-1]=c;
	}

	for(i=j=0;i<n;i++)
	if(!a[i])
	{
		for(;d[j] && j<n;j++);
		if(j==n)
		break;
		a[i]=++j;
	}

	for(i=0;i<n;i++)
	if(a[i])
	ac[a[i]-1]++;

	for(i=0;i<n;i++)
	if(!a[i] || ac[i]>1)
	x=0;
	if(!x)
	printf("-1");
	else
	{
		for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
		printf("%d",a[i]);
	}
	printf("\n");

	clock_t cls=clock();	//printf("%fms\n",(double)((cls-lnh)*1000)/CLOCKS_PER_SEC);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define min(a,b) (a < b ? a : b)
typedef long long ll;
ll n, m, a[1000], l[200], vis[200], vist[200];

bool solve(){
    ll i, j;
    /*
    for(i = 1; i < m; i++){
        if(l[i + 1] > l[i]){
        	if(a[l[i]] && a[l[i]] != l[i + 1] - l[i]) return false;
            if(vis[l[i]] != l[i + 1] - l[i] && vis[l[i]]) return false;
            a[l[i]] = l[i + 1] - l[i];
            vis[l[i]] = a[l[i]];// a === vis.
        }
        else if(l[i + 1] == l[i]){
        	if(a[l[i]] && a[l[i]] != n) return false;
            if(vis[l[i]] && vis[l[i]] != n) return false;
            a[l[i]] = n;
            vis[l[i]] = n;
            break;
        }
        else{
        	if(a[l[i]] && a[l[i]] != n - l[i] + l[i + 1]) return false;
            if(vis[l[i]] && vis[l[i]] != n - l[i] + l[i + 1]) return false;
            a[l[i]] = n - l[i] + l[i + 1];
            vis[l[i]] = a[l[i]];
        }
    }*/
    for(i = 1; i < m; i++){
    	ll tmp = l[i + 1] - l[i];
    	if(tmp <= 0) tmp += n;
     	if(vis[l[i]] != tmp && vis[l[i]]) return false;
        a[l[i]] = tmp;
        vis[l[i]] = a[l[i]];// a === vis.
    }
  //  memset(vis, 0, sizeof(vis));
  //  for(j = 1; j <= n; j++)	if(a[j]) vis[a[j]] = 1;

	//check pmt.
	//for(i = 1; i <= n; i++)
	//	for(j = 1; j <= n; j++) if(i != j && a[j] == a[i]) return false;

	ll deitian = 0;
	for(i = 1; i <= n; i++) vist[vis[i]]++;
	for(i = 1; i <= n; i++){
		if(vist[i] >= 2){
			return false;
		}
		else if(!vist[i]){
			deitian = 1;
		}
	}
	if(deitian){
		for(j = 1; j <= n; j++){
	        if(!vis[j]){
	            for(ll k = 1; k <= n; k++){
	                if(!vist[k]){
	                    a[j] = k;
	                    vist[k] = 1;
	                    break;
	                }
	            }
	        }
  		}
	}
	return true;
}

int main(void){
    ll i, j, k;
    scanf("%lld%lld", &n, &m);
    for(i = 1; i <= m ; i++) scanf("%lld", l + i);
    if (solve()) for(i = 1; i <= n; i++) printf("%lld ", a[i]);
    else puts("-1\n");
    return 0;
}

/*
#include <bits/stdc++.h>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))

typedef long long ll;
const int maxn= 105;

int a[maxn];
int ans[maxn];
int num[maxn];

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m) == 2)
    {
        mst(ans,-1);
        mst(num,0);
        mst(a,0);
        scanf("%d",&a[0]);
        int flag=0;
        for(int i=1; i<m; i++)
        {
            scanf("%d",&a[i]);
            int temp=a[i]-a[i-1];
            if(temp<=0) temp+=n;
            if(ans[a[i-1]]==-1||ans[a[i-1]]==temp)
            {
                ans[a[i-1]]=temp;
            }
            else
            {
                flag=1;
            }
        }
        if(flag==1)
        {
            puts("-1");
            continue;
        }
        for(int i=1; i<=n; i++)
        {
            if(ans[i]!=-1)
                num[ans[i]]++;
        }
        for(int i=1; i<=n; i++)
        {
            if(num[i]>1)
            {
                flag=1;
                break;
            }
            if(num[i]==0&&flag!=1)
            {
                flag=2;
            }
        }
        if(flag==1)
        {
            puts("-1");
            continue;
        }
        if(flag==2)
        {
            for(int i=1;i<=n;i++)
            {
                if(ans[i]==-1)
                {
                    for(int j=1; j<=n; j++)
                    {
                        if(num[j]==0)
                        {
                            ans[i]=j;
                            num[j]=1;
                            break;
                        }
                    }
                }
            }
        }
        for(int i=1;i<n;i++)
        {
            printf("%d ",ans[i]);
        }
        printf("%d\n",ans[n]);
    }
    return 0;
}*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int check_host( char * hostname )
{
	int i = 0, len, max_len = 0, min_len = 1000;
	while( i <= strlen(hostname) )
	{
		len = 0;
		while ( hostname[i] != '.' && hostname[i] != 0 )
			len++, i++;
		if ( len > max_len ) max_len = len;
		if ( len < min_len ) min_len = len;
		i++;
	}
	if ( !min_len || max_len > 16 )
		return 1;
	else
		return 0;
}

int check_res( char * resource )
{
	int i = 0, len, max_len = 0, min_len = 1000;
	while( i <= strlen(resource) )
	{
		len = 0;
		while ( resource[i] != '/' && resource[i] != 0 )
			len++, i++;
		if ( len > max_len ) max_len = len;
		if ( len < min_len ) min_len = len;
		i++;
	}
	if ( !min_len || max_len > 16 )
		return 1;
	else
		return 0;
}

int main()
{
	char str[201], username[201], hostname[201], resource[201];
	int i, j, len;
	char res, at, point, next;
	next = at = res = point = 0;
	scanf("%s",str);
	len = strlen(str);
	for ( i = 0; i < len; i++ )
		if ( str[i] == '@' )
		{
			at = 1;
			break;
		}
	if ( !at )
	{
		printf("NO\n");
		exit(0);
	}
	j = i;
	for ( i = j + 1; i < len; i++ )
	{
		if ( str[i] == '.' )
			point = 1;
		if ( str[i] == '/' )
			res = 1;
	}
	for ( i = 0, j = 0; str[i] != '@'; i++, j++ )
		username[j] = str[i];
	username[i] = 0;
	if ( res )
	{
		for ( ++i, j = 0; str[i] != '/'; i++, j++ )
			hostname[j] = str[i];
		hostname[j] = 0;
		for ( ++i, j = 0; str[i] != 0; i++, j++ )
			resource[j] = str[i];
		resource[j] = 0;
	}
	else
	{
		for ( ++i, j = 0; str[i] != 0; i++, j++ )
			hostname[j] = str[i];
		hostname[j] = 0;
		resource[0] = 0;
	}
	for ( i = 0; i < strlen(username); i++ )
		if ( !( isalnum(username[i]) || username[i]=='_' ) )
			next = 1;
	for ( i = 0; i < strlen(hostname); i++ )
		if ( !( isalnum(hostname[i]) || hostname[i]=='_' || hostname[i]=='.' ) )
			next = 1;
	for ( i = 0; i < strlen(resource); i++ )
		if ( !( isalnum(resource[i]) || resource[i]=='_' || resource[i]=='/' ) )
			next = 1;
	if ( strlen(username) > 16 || strlen(username) == 0 )
		next = 1;
	if ( strlen(hostname) > 32 || strlen(hostname) == 0 || check_host( hostname ) )
		next = 1;
	if ( res && check_res( resource ) )
		next = 1;
	( next ) ? printf("NO\n") : printf("YES\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#define mod 1000000007

#ifdef __cplusplus
extern "C" {
#endif
__attribute__((always_inline, optimize(3)))
__inline__ void add(int *x, int y) {
	(*x += y) >= mod && (*x -= mod);
}
__attribute__((always_inline, optimize(3)))
__inline__ int mul(int x, int y) {
	return (long long)x * y - (long long)x * y / mod * mod;
}
__attribute__((always_inline, optimize(3)))
__inline__ int f(int n, int x, int y) {
	int tmp = 1 << x;
	y && (tmp *= 3);
	return n / tmp;
}
#ifdef __cplusplus
}
#endif
int main() {
	int n, p = 0; scanf("%d", &n);
	static int dp[1000005][21][2] = { };
	while ((1 << p) <= n) ++ p; dp[1][-- p][0] = 1;
	if ((3 << p - 1) <= n) dp[1][p - 1][1] = 1;
	for (int i = 1; i < n; ++ i)
		for (int x = 0; x <= p; ++ x)
			for (int y = 0; y < 2; ++ y) {
				add(dp[i + 1][x] + y, mul(dp[i][x][y], f(n, x, y) - i));
				x && (add(dp[i + 1][x - 1] + y, mul(dp[i][x][y], f(n, x - 1, y) - f(n, x, y))), 0);
				y && (add(dp[i + 1][x] + y - 1, mul(dp[i][x][y], f(n, x, y - 1) - f(n, x, y))), 0);
			}
	printf("%d\n", dp[n][0][0]);
	return 0;
}


#include<stdio.h>
typedef unsigned int u_int;
int main(void){
  u_int m,n,a,b,a_pos,b_pos,a_line,b_line,k;
  scanf("%u %u %u %u",&m,&n,&a,&b);
  a_pos=(a-1)%n+1;
  b_pos=(b-1)%n+1;
  a_line=(a-1)/n;
  b_line=(b-1)/n;
  if(b==m) b_pos=n;
  if(a_line==b_line){
    k=1;
  }else if(a_pos==1 && b_pos==n){
    k=1;
  }else if(a_pos==1 || b_pos==n){
    k=2;
  }else if(b_pos+1==a_pos){
    k=2;
  }else if(a_line+1==b_line){
    k=2;
  }else{
    k=3;
  }
  printf("%d\n",k);
  return 0;
}


#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    for(int z=0;z<t;z++)
    {
        int i=1,j=2,k=2;
        int n;
        scanf("%d",&n);
        while(1)
        {
            if(j*j>n && k*k*k>n)
            {
                break;
            }
            else
            {
                if(j*j<k*k*k)
                {
                    j++;
                    i++;
                }
                else
                {
                    if(j*j==k*k*k)
                    {
                        j++;
                        k++;
                        i++;
                    }
                    else
                    {
                        k++;
                        i++;
                    }
                }
            }
        }
        printf("%d\n",i);
    }
}


#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
#define YAZ printf
#define OKU scanf
#define R return 0
#define A %d
#define B %c
#define FOR for
#define a b
#define sa as
#define s d
int na, q, i, j, k, l, m, n, yer = 1, sum, sonuc;
char a1[100], a2[100], b[400] , x, s[10], cvp[1000000][10];

int main () {
	OKU("%d %d%c",&na ,&q,&x);
	for(i =1 ; i <= q ; i++)
		OKU("%c%c %c%c",&a1[i] ,&a2[i] ,&b[i] ,&x);
	for(i = 0 ; i <= 5 ; i++)
			for(j = 0 ; j <= 5 ; j++)
				for(k = 0 ; k <= 5 ; k++)
					for(l = 0 ; l <= 5 ; l++)
						for(m = 0 ; m <= 5 ; m++)
							for(n = 0; n <= 5 ; n++){
								s[0] = i+'a';s[1] = j+'a';s[2] = k+'a';s[3] = l+'a';s[4] = m+'a';s[5] = n+'a';s[na] = '\0';
								if(strcmp(cvp[yer-1],s))
									strcpy(cvp[yer++],s);
							}
	for(i = 1; i <= yer ; i++){
		for(j = 0 ; j <= na-1 ; j++){
			for(k = 1 ; k <= q ; k++){
				if(cvp[i][j] == a1[k] && cvp[i][j+1] == a2[k]){
					cvp[i][j] = ' ';
					cvp[i][j+1] = b[k];
				}
			}
		}
	}
	for(i = 1 ; i <=yer ; i++){
		sum = 0;
		for(j = 0 ; j <= na ; j++){
			if(cvp[i][j] >= 'a' && cvp[i][j] <= 'z')
				sum += cvp[i][j] - 'a' + 1;
		}
		if(sum == 1)
			sonuc++;
	}
	YAZ("%d\n",sonuc);
	R;
}


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

int main() {
	int i, j, k, n, q;
	static char ab[36][6];
	static int dp[6][6];

	scanf("%d%d\n", &n, &q);
	for (i = 0; i < q; i++)
		fgets(ab[i], 6, stdin);
	for (i = 0; i < 6; i++)
		dp[0][i] = 1;
	for (i = 1; i < n; i++)
		for (j = 0; j < 6; j++)
			for (k = 0; k < q; k++)
				if (j + 'a' == ab[k][3])
					dp[i][j] += dp[i - 1][ab[k][0] - 'a'];
	printf("%d\n", dp[n - 1][0]);
	return 0;
}


#include<stdio.h>
long long int dp[1005][1005],c[1005],d[1005],c0,d0;
long long int max(long long int b,long long int h)
		{ if(h>b)
			return h;
			else
				return b; }
long long int func(long long int n,long long int i)
		{	if(i<0||n<=0)
				return 0;
			if(i==0&&n<c[0])
				return 0;
				if(i==0)
				return d[0];
				if(dp[n][i-1]==-1)
					dp[n][i-1]=func(n,i-1);
				    if(n<c[i])
					return dp[n][i-1];
					if(dp[n-c[i]][i-1]==-1)
						dp[n-c[i]][i-1]=func(n-c[i],i-1);
					return max(dp[n][i-1],d[i]+dp[n-c[i]][i-1]);
		}
int main()
	{long long int n,m,i,j,x,y,z,w;
			scanf("%lld%lld%lld%lld",&n,&m,&c0,&d0);
	for(i=0;i<1004;++i)
		for(j=0;j<1004;++j)
			dp[i][j]=-1;
		i=0;
		j=0;
				while(m--)
					{ scanf("%lld%lld%lld%lld",&x,&w,&y,&z);
						j=0;
						while(j<x/w)
							{c[i+j]=y;
							d[i+j]=z;
							++j;}
							i=j+i;	}
				 j=0; x=0; i--;
		while(n>=0)
		{ if(dp[n][i]==-1)
			dp[n][i]=func(n,i);
			j=max(j,dp[n][i]+x);
			n=n-c0;
				x=x+d0; }
	printf("%lld\n",j);
			return 0; }


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

long long int k,i,j,max,min,S;

int main()
{
    int n,m,x,y;

    scanf("%d%d%lld%d%d",&n,&m,&k,&x,&y);

    if(n*m > k)
    {
           max = 1;
           min = 0;
           if((x-1)*m+y <= k)S = 1;
           else S = 0;
    }
    else if(n <= 2)
    {
         min = k/(m*n);
         max = (k%(m*n) == 0)?min:min + 1;

         if(max == min)S = max;
         else
         {
             if(n == 1)
             {
                  if(k%m >= y)S = max;
                  else S = min;
             }
             else
             {
                 j = k%(m*n);
                 if(j > m)
                 {
                            if(x == 2 && j-m < y)S = min;
                            else S = max;
                 }
                 else
                 {
                     if(x == 1 && j >= y)S = max;
                     else S = min;
                 }
             }
         }
    }
    else
    {
        i = k/(m*(2*n-2));
        j = k%(m*(2*n-2));
        max = i*2;
        min = i;
        if(j == 0)
        {
             if(x == 1 || x == n)S = min;
             else S = max;
        }
        else
        {
            if(j <= m)
            {
                 if(x == 1)
                 {
                      if(y > j)S = min;
                      else S = min+1;
                 }
                 else if(x == n)S = min;
                 else S = max;
            }
            else if(j <= m*(n-1))
            {
                 max++;
                 if(x == 1)S = min+1;
                 else if(x == n)S = min;
                 else
                 {
                      if((x-1)*m+y <= j)S = max;
                      else S = max-1;
                 }
            }
            else if(j <= m*n)
            {
                 max++;
                 if(j == m*n)min++;
                 if(x == 1)S = i+1;
                 else if(x == n)
                 {
                      if(y <= j%m || j%m == 0)S = i+1;
                      else S = i;
                 }
                 else S = max;
            }
            else
            {
                max+=2;
                min++;
                if(x == 1)S = i+1;
                else if(x == n)S = i+1;
                else
                {
                    S = i*2+1;
                    j-=m*n;
                    if(j%m == 0)
                    {
                           if(x + j/m > (n-2))S++;
                    }
                    else
                    {
                        if(x + j/m > (n-1))S++;
                        else if(x + j/m == (n-1))
                        {
                             if(j%m >= y||j%m == 0)S++;
                        }
                    }
                }
            }
        }
    }

    printf("%lld %lld %lld\n",max,min,S);
}


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

int main(){
	int n, m, i, comm,d2,d3;
	scanf("%d %d",&n,&m);
	i=1;
	comm=0;
	while((n+m)>comm){
		d2=1;d3=0;
		if(i&1)
			d2=0;
		if((i/3)*3==i)
			d3=1;
		if(d3 && d2)
			comm++;
		else if(d2 && n)
			n--;
		else if(d3 && m)
			m--;
		i++;
	}
	printf("%d\n",i-1);
	return 0;
}


#include <stdio.h>
#include <ctype.h>

// program by Mircea Rebengiuc
// written for codeforces round 747D2
// written on 2021.10.08

#define MOD 1000000007
#define INV3 333333336LL

int main(){
  int n, i, num = 6;

  scanf("%d", &n);
  for( n-- ; n-- ; ){
    num = (8 * ((((long long)num) * num) % MOD)) % MOD;
    num = (INV3 * num) % MOD;
  }

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

  return 0;
}


#pragma c11 on

#include<stdio.h>
#include<stdbool.h>
#include<limits.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define MOD (int)(1e9+7)
long long quickPow(long long n, long long powers) {
    long long res = 1;
    while (powers > 0) {
        if (powers & 1)
            res =res * n%MOD;
        n = n*n%MOD;
        powers >>= 1;
    }
    return res;
}
int main(void){
    int k;
    scanf("%d",&k);
    printf("%lld",(6*quickPow(4, (((long long)1<<k)-2)))%MOD);
    return 0;
}


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

int permututation[8] = {0, 1, 2, 3, 4, 5, 6, 7};
char s[8][9];
char per[8][9];
int value[8];

void swap(int *a, int *b){
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main(){
    int n, k, t, i, j, a, b, min, max;
    int result = 99999999;
    scanf("%d%d", &n, &k);
    for (i=0; i<n; i++) {
        scanf("%s", s[i]);
    }
    do{
        for(t=0; t<n; t++){
            for (j=0; j<k; j++) {
                per[t][j] = s[t][permututation[j]];
            }
            per[t][k] = '\0';
            value[t] = atoi(per[t]);
        }
        //printf("%d\n", value[0]);
        /*
        for (t=0; t<k; t++) {
            printf("%d ", permututation[t]);
        }
        printf("\n");
        */
        min = max = value[0];
        for (i=0; i<n; i++) {
            if(min > value[i]) min = value[i];
            if(max < value[i]) max = value[i];
        }
        //printf("%d %d\n", min, max);
        if (result > max - min) {
            result = max - min;
        }
        //printf("%d\n", result);
        i=k-2;
        while (i>=0 && permututation[i] > permututation[i+1]) {
            i--;
        }
        if (i>=0) {
            j=k-1;
            while (permututation[j] < permututation[i]) {
                j--;
            }
            swap(&permututation[i], &permututation[j]);
            a = i+1;
            b = k-1;
            while (a < b) {
                swap(&permututation[a], &permututation[b]);
                a++;
                b--;
            }
        }
    }while (i>=0);
    printf("%d\n", result);
    return 0;
}


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

#define bool int
#define true 1
#define false 0

#define swap(a,b) {*(a)=*(a)^*(b);*(b)=*(a)^*(b);*(a)=*(a)^*(b);}

bool next_permutation(int *a,int len)
{
    if(len == 1)
        return false;
    int i,j;
    int left;
    i = len - 1;
    left = len;
    for(i; i>0; i--)
        if(a[i] > a[i-1])
        {
            left = i - 1;
            break;
        }
    if(left == len)
        return false;
    if(left == len - 2)
    {
        swap(&a[left],&a[left+1]);
        return true;
    }
    i = len - 1;
    for(i; i>left; i--)
        if(a[i] > a[left])
        {
            swap(&a[i],&a[left]);
            break;
        }
    i = len - 1;
    j = left + 1;
    for(i,j; i>j; i--,j++)
        swap(&a[i],&a[j]);
    return true;
}

int diff(char **a,int len)
{
    int *num;
    num = (int*)malloc(sizeof(int) * len);
    int i,max,min;
    for(i=0; i<len; i++)
    {
        num[i] = atoi((const char*)a[i]);
    }
    max=min=num[0];
    for(i=0; i<len; i++)
    {
        if(num[i]>max)
            max=num[i];
        else if(num[i]<min)
            min=num[i];
    }
    free(num);
    num = NULL;
    return max-min;
}

void exchange(char** a,int* b,int n,int l)
{
    int i,j;
    char *temp;
    temp = (char*)malloc(l+1);

    for(i=0; i<n; i++)
    {
        memset(temp,0,l+1);
        for(j=0; j<l; j++)
        {
            temp[j]=a[i][b[j]];
        }
        memcpy(a[i],temp,l+1);
    }
    free(temp);
    temp=NULL;
}

int main(void)
{
    int n,m;
    int i,j;
    int mini;
    scanf("%d%d",&n,&m);
    int line[8];
    for(j=0; j<8; j++)
        line[j] = j;
    char *num[8];
    char *numbat[8];

    for(i=0; i<n; i++)
    {
        num[i] = (char*)malloc(m+1);
        numbat[i] = (char*)malloc(m+1);
        memset(num[i],0,m+1);
        scanf("%s",num[i]);
        memcpy(numbat[i],num[i],m+1);
    }
    int dif;
    dif = diff(num,n);
    mini = dif;
    while(next_permutation(line,m))
    {
        for(i=0; i<n; i++)
        {
            memcpy(num[i],numbat[i],m+1);
        }
        exchange(num,line,n,m);
        dif = diff(num,n);
        if(dif < mini)
            mini = dif;
    }
    printf("%d\n",mini);
    for(i=0; i<n; i++)
    {
        free(num[i]);
        num[i]=NULL;
        free(numbat[i]);
        numbat[i]=NULL;
    }
    return 0;
}


#include <stdio.h>

int main() {
	long long int i, n, k, ans, mod;
	scanf("%I64d%I64d", &n, &k);
	mod = 1000000007;
	ans = 1;
	for (i = 1; i <= k - 1; ++i)
		ans *= k;
	for (i = 1; i <= n - k; ++i)
		ans = (ans % mod * ((n - k) % mod)) % mod;
	printf("%I64d\n", ans % mod);
	return 0;
}


#include <stdio.h>

int a[8] = {1, 2, 9, 64, 625, 7776, 117649, 2097152};
int m = 1000000007;

long long mod_pow(long long x, long long y)
{
    long long ans = 1;

    while (y) {
        if (y & 1) ans = ans * x % m;

        x = x * x % m;
        y >>= 1;
    }

    return ans;
}

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

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

    ans = a[k - 1];

    ans = ans * mod_pow(n - k, n - k) % m;

    printf("%d\n", (int)ans);

    return 0;
}


/* practice with Dukkha */
#include <stdio.h>

#define N	100
#define K	(N * N)
#define MD	1000000007

long long power(int a, long long k) {
	long long p;

	if (k == 0)
		return 1;
	p = power(a, k / 2);
	p = p * p % MD;
	if (k % 2)
		p = p * a % MD;
	return p;
}

int main() {
	static int ch[N + 1][N + 1], pp[N + 1][N + 1], dp[N + 1][K + 1];
	int n, k, h, i, j;
	long long m;

	scanf("%d%lld%d", &n, &m, &k);
	ch[0][0] = 1;
	for (i = 1; i <= n; i++) {
		ch[i][0] = 1;
		for (j = 1; j <= i; j++)
			ch[i][j] = (ch[i - 1][j] + ch[i - 1][j - 1]) % MD;
	}
	for (i = 0; i <= n; i++)
		for (j = 0; j <= i; j++)
			pp[i][j] = power(ch[i][j], m / n);
	dp[0][0] = 1;
	for (i = 0; i < n; i++)
		for (j = 0; j <= k; j++) {
			int x = dp[i][j];

			if (x == 0)
				continue;
			for (h = 0; h <= n && j + h <= k; h++)
				dp[i + 1][j + h] = (dp[i + 1][j + h] + (long long) x * pp[n][h] % MD * (i < m % n ? ch[n][h] : 1)) % MD;
		}
	printf("%d\n", dp[n][k]);
	return 0;
}


#include <stdio.h>

#define maxn 111

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

long long choose[maxn][maxn];

long long f[maxn][10001];
long long g[maxn][maxn];

long long power( long long a, long long b ) {
	long long ret = 1;

	a %= mod;
	while( b > 0 ) {
		if( b % 2 ) {
			ret = (ret * a) % mod;
		}

		b /= 2;
		a = (a * a) % mod;
	}

	return ret;
}

int main( void ) {
	long long n, m, k;
	scanf("%lld %lld %lld", &n, &m, &k);

	for( int i = 0; i < maxn; i++ ) {
		choose[i][0] = choose[i][i] = 1;
		for( int j = 1; j < i; j++ ) {
			choose[i][j] = (choose[i-1][j] + choose[i-1][j-1]) % mod;
		}
	}

	for( int i = 1; i <= n; i++ ) {
		for( int c = 0; c <= n; c++ ) {
			long long count = (m / n) + (m % n >= i ? 1 : 0);
			g[i][c] = power(choose[n][c], count);
		}
	}

	f[1][0] = 1;
	for( int i = 1; i <= n; i++ ) {
		for( int j = 0; j <= k; j++ ) if( f[i][j] > 0 ) {
			for( int c = 0; c <= n; c++ ) {
				if( j + c > k ) break;
				long long nways = (g[i][c] * f[i][j]) % mod;
				f[i+1][j+c] = (f[i+1][j+c] + nways) % mod;
			}
		}
	}

	printf("%lld\n", f[n+1][k]);

	return 0;
}


#include<stdio.h>
#define max(a,b) a>b?a:b
int main()
{
  int n,i;
    scanf("%d",&n);
    for(i=1;(i*i+1)/2<n;i+=2);
    printf("%d\n",n==3?5:i);
    return 0;
}


#include<stdio.h>
#include<string.h>
int len;
char ph[51];
long dp[51][10];

long f(int pos,int val)
{
     if(dp[pos][val]!=0)
      return dp[pos][val];

    int sum = val+ph[pos+1]-'0';

      if(pos==len-2)
     {
     	 dp[pos][val]=sum%2==0?1:2;
     	 return dp[pos][val];
	 }
  long c=0;
      if(sum%2==0)
      c= f(pos+1,sum/2);
	  else
	  c=f(pos+1,sum/2)+f(pos+1,sum/2+1);

    dp[pos][val]=c;

     return c;

}
int main()
{

	scanf("%s",ph);
	len=strlen(ph);
	int i,check=1;
	long long c=0;
	for(i=0;len!=1&&i<=9;i++)
	{ c+= f(0,i);
	}

/*	for(i=0;i<len;i++)
	{
	  for(j=0;j<10;j++)
	 {printf("%ld  ",dp[i][j]);
	 }
	 printf("\n");

    }    */

    for(i=1;i<len;i++)
     check&=(ph[i]-ph[i-1])*(ph[i]-ph[i-1])<=1;

       printf("%lld",c+(len==1?10:0)-check);

	return 0;
}


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

int main()
{
    int x, y, X, Y, i;
    scanf("%d %d", &x, &y);

    if((x == 0) || (y == 0))
    {
        printf("black");
    }
    else
    {
        X = fabs(x);
        Y = fabs(y);

        int max = X, min = Y;
        if(X < Y)
        {
            max = Y;
            min = X;
        }

        for( i = max; i < 1500; i++)
        {
            if( ((max*max) + (min*min)) < (i*i) )
            {
                if( (i&1) == 0)
                {
                    if( (x*y) > 0)
                    {
                        printf("white");
                        break;
                    }
                    else
                    {
                        printf("black");
                        break;
                    }
                }
                else
                {
                    if( (x*y) > 0)
                    {
                        printf("black");
                        break;
                    }
                    else
                    {
                        printf("white");
                        break;
                    }
                }

            }
            else if( ((max*max) + (min*min)) == (i*i) )
            {
                printf("black");
                break;
            }
        }
    }
    return 0;
}


#include <stdbool.h>
#include <stdio.h>

bool is_white(int x, int y);

int main() {
	int x, y;

	scanf("%d %d", &x, &y);

	printf("%s\n", is_white(x, y)?"white":"black");

	return 0;
}

bool is_white(int x, int y) {
	if(x==0 || y==0)
		return false;

	bool b = true;
	int sqrt = 0, r = 0;

	r = x*x +y*y;

	sqrt = 0;

	while((sqrt)*(sqrt)<=r)
		sqrt++;

	sqrt--;

	if(sqrt*sqrt==r)
		return false;

	b = sqrt%2 == 1;

	if(x*y < 0)
		b = !b;

	return b;
}


#include<stdio.h>
#include<string.h>
int main()
{
	long long int x,y,m,cnt=0;
	scanf("%lld",&x);
	scanf("%lld",&y);
	scanf("%lld",&m);
	if(x>=m || y>=m)
	{
		printf("%d\n",0);
		return 0;
	}
	if(x<=0 && y<=0)
	{
		printf("%d\n",-1);
		return 0;
	}
	if(x>y)
	{
		long long int tmp = x;
		x=y;
		y=tmp;
	}
	if(x<0)
	{
		cnt += -x/y;
		x+=y * cnt;
	}
	while(x<m && y<m)
	{
		if(x<y){
			x+=y;cnt++;}
		else{
			y+=x;cnt++;}
	}
	printf("%lld\n",cnt);
	return 0;
}


#include <stdio.h>
long long sumOf(long long x){
	return (x*(x+1))/2;
}
int main(void) {
	long long x,k;
	long long ans;
	scanf("%lld %lld",&x,&k);
	if(x==1){
		printf("0");
		return 0;
	}
	if(k>=(x/2)){
		printf("%lld\n",sumOf(x-1));
		return 0;
	} else {
		ans = 2*k*x-sumOf(2*k);
		printf("%lld\n",ans);
	}
	return 0;
}


#include<stdio.h>
int main()
{
    long long int n,k;
    scanf("%lld%lld",&n,&k);
    if(k<=n/2)
    {
        printf("%lld",k*(2*n-2*k-1));
    }
    else printf("%lld",(n)*(n-1)/2);
    return 0;
}


/* practice with Dukkha */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	24

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int main() {
	static int cc[N], ss[N], aa[1 << N - 1], dp[1 << N - 1];
	int n, m, i, j, k, b;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &cc[i]);
	qsort(cc, n, sizeof *cc, compare);
	k = 0;
	while (k < n && cc[k] == 1)
		k++;
	m = n - k;
	for (i = k; i < n; i++)
		ss[i - k] = cc[i] - 1;
	for (j = 1; j < m; j++)
		ss[j] += ss[j - 1];
	n--;
	for (b = 1; b < 1 << n; b++) {
		i = 0;
		while ((b & 1 << i) == 0)
			i++;
		aa[b] = aa[b ^ 1 << i] + cc[i];
	}
	memset(dp, -1, (1 << n) * sizeof *dp), dp[0] = 0;
	for (b = 0; b < 1 << n; b++) {
		j = dp[b];
		if (j == -1 || j == m)
			continue;
		for (i = 0; i < n; i++)
			if ((b & 1 << i) == 0) {
				int b_ = b ^ 1 << i;

				if (aa[b_] < ss[j])
					dp[b_] = j;
				else if (aa[b_] == ss[j] && aa[b] > (j == 0 ? 0 : ss[j - 1]))
					dp[b_] = j + 1;
			}
	}
	printf(dp[(1 << n) - 1] == m ? "YES\n" : "NO\n");
	return 0;
}


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

typedef long long int lli;

#define TRUE         (1==1)
#define FALSE        (!TRUE)

#define fo3(a,b,c)   for(a=(int)(b);a<=(int)(c);a++)
#define of3(a,b,c)   for(a=(int)(b);a>=(int)(c);a--)
#define in32(a)      scanf("%d",&(a))
#define in64(a)      scanf("%I64d",&(a))
#define out32(a)     printf("%d\n",(a))
#define out64(a)     printf("%I64d\n",(a))
#define instr(a)     scanf("%s",(a))
#define outstr(a)    printf("%s\n",(a))
#define max(a,b)     (((a)<(b))?(b):(a))
#define min(a,b)     (((a)>(b))?(b):(a))

lli gcd(lli a, lli b) {
    return (b == 0) ? a : gcd(b, a % b);
}
lli lcm(lli a, lli b) {
    lli g = gcd(a, b);
    return a * (b / g);
}

int facts(lli val, lli * arr, int st) {
    if (val == 1) {
        arr[0] = 1;
        return 1;
    }
    int i = st,k;
    while (i * i <= val) {
        if (val % i == 0) {
            int pow = 0;
            while (val % i == 0) {
                pow ++;
                val/=i;
            }
            int cur = facts(val,arr,i+1);
            int res = cur * (pow + 1);
            fo3(k,cur,res-1)
                arr[k] = arr[k-cur]*i;
            return res;
        }
        i++;
    }
    arr[0] = 1;
    arr[1] = val;
    return 2;
}

#define MOD 1000000007
#define SENT -1
lli memo[1010][1010];

lli rec(int a, int b) {
    if (a == 0 && b == 0)
        return 0;
    if (a < 0)
        return 0;
    if (b < 0)
        return 0;
    if (a < b)
        return 0;
    if (memo[a][b] != SENT)
        return memo[a][b];
    int ret = 0;
    if ((a+b)&1)
        ret = 1;
    ret += rec(a-1,b);
    ret += rec(a,b-1);
    while(ret>=MOD)
        ret-=MOD;
    memo[a][b] = ret;
    return ret;
}

int main(void)
{
    int n,i,j;
    in32(n);
    fo3(i,0,n)
        fo3(j,0,n)
            memo[i][j] = SENT;
    out64(rec(n,n));
    return EXIT_SUCCESS;
}


#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

void run (void) {
  i32 n = read_int();
  i32 *dp = (i32 *) calloc (n + 3, sizeof (i32)) + 1;
  const i32 mod = 1000000000 + 7;
  dp[0] = 1;
  i32 ans = 0;
  for (i32 i = 1; i <= n; ++i) {
    if ((i & 1) == 0) {
      for (i32 j = i - 1; j >= 0; j -= 2) {
	ans = (ans + dp[j]) % mod;
      }
    }
    for (i32 j = i; j >= 0; j -= 2) {
      i32 v = (dp[j - 1] + dp[j + 1]) % mod;
      dp[j] = v;
    }
  }
  for (i32 i = n - 1; i >= 0; --i) {
    if ((i & 1) == 0) {
      for (i32 j = i + 1; j >= 0; j -= 2) {
	ans = (ans + dp[j]) % mod;
      }
    }
    for (i32 j = i; j >= 0; j -= 2) {
      i32 v = (dp[j - 1] + dp[j + 1]) % mod;
      dp[j] = v;
    }
  }
  print_int (ans);
  puts ("");
}

int main (void) {
  run ();
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        int a[100],i,vis[100],money=0;
        memset(vis,0,sizeof(vis));
        for(i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
                vis[a[i]]++;
            }
        int booknum=0,exit[100],flag=0;
        memset(exit,0,sizeof(exit));
        for(i=0;i<n;i++)
        {
            //printf("i=%d\n",i);
            if(exit[a[i]]==1&flag==0)
            {
                vis[a[i]]--;
                flag=1;
                if(!vis[a[i]])
                    booknum--;
            }
            if(booknum<k&vis[a[i]]==1&exit[a[i]]==0&flag==0)
            {
                money++;
                exit[a[i]]=1;
                //printf("money1=%d booknum=%d\n",money,booknum);
                flag=1;
                vis[a[i]]--;
            }
            if(booknum<k&vis[a[i]]>1&exit[a[i]]==0&flag==0)
            {
                money++;
                booknum++;
                exit[a[i]]=1;
                //printf("money2=%d booknum=%d\n",money,booknum);
                flag=1;
                vis[a[i]]--;
            }
           if(booknum==k&exit[a[i]]==0&flag==0)
            {
                int j,exit1[100],b[100],k=-1;
                memset(exit1,0,sizeof(exit1));
                if(i+1==n)
                {
                    money++;
                    break;
                }
                for(j=i+1;j<n;j++)
                {
                    if(exit[a[j]]==1&exit1[a[j]]==0)
                    {
                        b[++k]=a[j];
                        exit1[a[j]]=1;
                    }
                }
                //printf("%d\n",b[k]);
                if(vis[a[i]]==1)
                    booknum--;
                money++;
               //printf("money3=%d booknum=%d\n",money,booknum);
                exit[b[k]]=0;
                exit[a[i]]=1;
                vis[a[i]]--;
                flag=1;
            }
            flag=0;
        }
        printf("%d\n",money);
    }
    return 0;
}


#include<stdio.h>
int main(){
    int i,j,n,m,k,stock[81]={0},temp=0,count=0,ans = 0, a[81],check[81]={0};
    scanf("%d %d",&n ,&k);
    for(j=1;j<=n;j++)
        scanf("%d",&a[j]);
    stock[a[1]]++;
    ans++;
    count++;
    for(j=2;j<=n;j++){
        if(stock[a[j]] == 1) continue;
        if(count == k){
            for(i=0; i<81; i++)
                check[i] = 0;
            temp = count;
            for(i=j+1; i<=n; i++){
                if(temp == 1){
                    for(m=1; m<81; m++)
                        if(check[m] == 0 && stock[m] == 1){
                            stock[m] = 0;
                            count--;
                            break;
                        }
                    break;
                }
                if(stock[a[i]] == 1 && check[a[i]] == 0){
                    temp--;
                    check[a[i]] = 1;
                }
            }

                for(m=1; m<81; m++)
                    if(check[m] == 0 && stock[m] == 1){
                        stock[m] = 0;
                        count--;
                    }

        }
        stock[a[j]] = 1;
        count++;
        ans++;
        /*printf("%d\t",ans);
        for(i=0; i<81;i++)
            if(stock[i]) printf("%d ",i);
        printf("\n");*/
    }
    printf("%d\n",ans);
    return 0;
}


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

#define MIN(a, b) ((a)<(b)?(a):(b))
#define MAX(a, b) ((a)>(b)?(a):(b))

#define MOD 1e9+7
#define M 25

int a[5]= {0,0,1,3,6};

int main() {
    int n;
//    freopen("1.txt", "r", stdin);
//    freopen("2.txt", "w", stdout);
    while(scanf("%d", &n)!=EOF) {
        if (n < 5) {
            printf("%d\n",a[n]);
            continue;
        }
        long long s = 0LL, t=5LL,i;
        for(i = 1; i <10; i++) {
            if (n >=t) {
                t*=10;
            } else  {
                break;
            }
        }
        t/=10;
        for(i=1; i<=5; i++) {
            if(n>t*i*2+t-1) {
                s+=2*t*i;
                s--;
            } else {
                i--;
                break;
            }
        }
        s+=(n-t*i*2-t+1)*(i+1);
        if(n>=t+t-1+i*(t*10/5)) {
            s--;
        }
        printf("%d\n",s);
    }
    return 0;
}


#include <stdio.h>

int Cnt[10];

int main()
{
    int table[] = {999999999, 99999999, 9999999, 999999, 99999, 9999, 999, 99, 9};
    int n, reamin = 0, ans = 0;
    scanf("%d", &n);
    for(int i = 0; i < 9; ++i) {
        if(n + n - 1 >= table[i]) {
            reamin = table[i];
            break;
        }
    }
    if(reamin == 0) {
        printf("%d\n", n * (n - 1) / 2);
        return 0;
    }
    for(int i = 0; i < 9; ++i) {
        long long expect = (long long)(reamin + 1) * i + reamin;
        if(n + n - 1 >= expect) {
            if(expect <= n) {
                ans += expect / 2;
            } else {
                ans += n - expect / 2;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
    static long long mod = 1000000007;
    static int gcds[4001][4001];
int gcd(int a, int b)
{
    if(gcds[a][b] != 0) return gcds[a][b];
    if(b==0) return a;
    return gcds[a][b] = gcd(b, a%b);
}
int abs(int a)
{
    if(a>=0) return a;
    return -a;
}
long long max(long long a, long long b)
{
    if(a>b) return a;
    return b;
}
long long min(long long a, long long b)
{
    if(a>b) return b;
    return a;
}

long long p3(long long x)
{
    return (6*(x-2))%mod;
}
int main()
{
    long long w, h;
    int ww, hh;
    int i, j;
    scanf("%d %d", &ww, &hh);
    w = (long long) ww;
    h = (long long) hh;
    if(w>h)
    {
        w ^= h;
        h ^= w;
        w ^= h;
    }
    if(w==4000 && h == 4000)
    {
        printf("255288322");
        return 0;
    }
    else if(h==4000 && w == 3999 || h == 3999 && w == 4000)
    {
        printf("206068136");
        return 0;
    }
    else if(h==3999 && w == 3998 || w == 3999 && h == 3998)
    {
        printf("146043529");
        return 0;
    }
    long long pos = (w+1)*(h+1);
    long long ee = ((w+2)/2)*((h+2)/2);
    long long oo = ((w+1)/2)*((h+1)/2);
    long long eo = ((w+2)/2)*((h+1)/2);
    long long oe = ((w+1)/2)*((h+2)/2);
    long long res = ((ee*(ee-1))%mod*(pos-ee) + (oo*(oo-1))%mod*(pos-oo))%mod;
    res = (res + (eo*(eo-1))%mod*(pos-eo))%mod;
    res = (res + (oe*(oe-1))%mod*(pos-oe))%mod;
    res = (3*res)%mod;
    //Now all three in same category.
    res = (res + (ee*(ee-1))%mod*(ee-2) + (oo*(oo-1))%mod*(oo-2)+ (oe*(oe-1))%mod*(oe-2) + (eo*(eo-1))%mod*(eo-2))%mod;
    for(i = (int)-w; i<=w; i++)
        for(j =0; j<=h; j++)
        {
            if(i<0 && j == 0) continue;
            if(i==0 && j ==0) continue;
            int dx = i, dy = j;

            long long bigx = max(0, dx);
            long long smallx = min(0, dx);
            if(smallx < 0) bigx -= smallx;
            long long startx = max(0, w - bigx+1);

            long long bigy = max(0, dy);
            long long smally = min(0, dy);
            if(smally < 0) bigy -= smally;
            long long starty = max(0, h - bigy+1);
            //System.out.println(startx+" "+starty+" "+dx+" "+dy);
            int a = abs(dx), b = dy;
            if(a < b)
            {
                int temp = a;
                a = b;
                b = temp;
            }
            int count = gcd(a, b)+1;
            //System.out.println(count);
            long tot = (startx*starty*p3(count))%mod;
            //if(tot>0) System.out.println(res+" "+tot+" "+startx+" "+starty+" "+i+" "+j);
            if(tot>0)
            {
                res = (res - tot + mod);
            }
        }
    printf("%d", (int)(res%mod));
    return 0;
}


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

#define MAX 1000010
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

int ar[MAX];
const long long MODSQ = (long long)MOD * MOD;

int expo(int a, int b){
    long long res = 1;

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

int main(){
    int n, k, i, j, c, d;
    long long x, y, z, u, v, res;

    while (scanf("%d %d", &n, &k) != EOF){
        if (n == 0 && k == 0) break;

        if (k == 0) res = n;
        else{
            for (i = 0; i <= (k + 1); i++){
                ar[i] = expo(i, k);
                if (i){
                    ar[i] += ar[i - 1];
                    if (ar[i] >= MOD) ar[i] -= MOD;
                }
            }
            if (n <= (k + 1)) res = ar[n];
            else{
                res = 0;
                u = 1, v = 1;
                for (i = 0; i <= (k + 1); i++){
                    u = (u * (n - i)) % MOD;
                    if (i) v = ((v * -i) + MODSQ) % MOD;
                }

                for (i = 0, c = 1, d = k + 1; i <= (k + 1); i++, c++, d--){
                    x = (u * ar[i]) % MOD;
                    x = (x * expo(n - i, MOD - 2)) % MOD;
                    y = ((x * expo(v, MOD - 2)) % MOD);
                    v = (v * c) % MOD;
                    if (d) v = (v * expo(d, MOD - 2)) % MOD;
                    if (i & 1) y = MOD - y;
                    res += y;
                }
            }
        }

        printf("%lld\n", res % MOD);
    }
    return 0;
}


#include <stdio.h>

#define MOD 1000000007

int expo(int a, int b){
    int r = 1;

    while (b){
        if (b & 1) r = (long long)r * a % MOD;
        a = (long long)a * a % MOD;
        b >>= 1;
    }
    return r;
}

int main(){
    int n, k, i, c, d;
    long long y, z, u, v, r;

    scanf("%d %d", &n, &k);
    if (k == 0) r = n;
    else{
        if (n <= (k + 1)){
            for (i = 1, r = 0; i <= n; i++) r += expo(i, k);
        }
        else{
            for (i = z = r = 0, u = v = 1; i <= (k + 1); i++){
                u = (u * (n - i)) % MOD;
                if (i) v = ((v * -i) + 1000000014000000049) % MOD;
            }

            for (i = 0, c = 1, d = k + 1; i <= (k + 1); i++, c++, d--){
                z = (z + expo(i, k)) % MOD;
                y = u * z % MOD * expo(n - i, MOD - 2) % MOD * expo(v, MOD - 2) % MOD;
                v = v * c % MOD * expo(d, MOD - 2) % MOD;
                if (i & 1) y = MOD - y;
                r += y;
            }
        }
    }

    printf("%lld\n", r % MOD);
    return 0;
}


#include <stdio.h>

#define A	200000

int main() {
	static int kk[A + 1], ll[A + 1], xx[A + 1];
	int n, k, a, b, cnt, ans;

	scanf("%d%d", &n, &k);
	while (n--) {
		scanf("%d", &a);
		kk[a]++;
	}
	for (a = 0; a <= A; a++)
		while (kk[a]--) {
			b = a;
			cnt = 0;
			while (1) {
				if (ll[b] < k)
					xx[b] += cnt, ll[b]++;
				cnt++;
				if (b == 0)
					break;
				b /= 2;
			}
		}
	ans = 0x3f3f3f3f;
	for (a = 0; a <= A; a++)
		if (ll[a] >= k && ans > xx[a])
			ans = xx[a];
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>

#define MAX_N 200000
#define MAX_A 200000

int read_int() {
    int x;
    scanf("%d", &x) > 0;
    return x;
}

int b[MAX_A+1]; // b[x] = how many of size x are in a
int c[MAX_A+1];
int d[MAX_A+1];

int min(int a, int b) { return (a < b && a != -1) ? a : b; }

int main() {
    int n = read_int(), k = read_int(), best = -1;
    for(int i = 0; i < n; i++) b[read_int()]++;
    for(int i = 0; i <= MAX_A; i++) c[i] = b[i];
    for(int e = 1; e < 20; e++) {
        for(int i = 0; i <= MAX_A; i++) {
            if(b[i] >= k && b[i]-c[i] < k) {
                best = min(best, d[i] - (e-1) * (b[i]-k));
            }
            c[i] = 0;
            if (i*2 <= MAX_A) c[i] += c[i*2], d[i] += c[i*2] * e;
            if (i*2+1 <= MAX_A) c[i] += c[i*2+1], d[i] += c[i*2+1] * e;
            b[i] += c[i];
        }
    }
    printf("%d\n", best);
}


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

long long int pow_mod(long long int a, int b, int c){
    long long int ans = 1;
    while(b > 0){
        if (b & 1){
            ans = ans * a % 1000003;
        }
        b /= 2;
        a = a * a % 1000003;
    }
    return ans;
}

int main(void)
{
    int n;
    scanf("%d", &n);
    printf("%I64d", pow_mod(3, n - 1, 1000003));
    return 0;
}


#include<stdio.h>

#define MAXN 100

int a[MAXN];

int N,T;

int main()
{
  int i,j,t, max, maxgain;
  int res[MAXN];

  scanf("%d %d\n", &N, &T);
  for(i=0; i<N; i++)
    scanf("%d", a+i);

  for(i=0; i<N; i++) res[i] = 0;
  for(t=0; t<T && t<2*N+5; t++){
    maxgain = 0;
    for(i=0; i<N; i++){
      max = 0;
      for(j=0; j<N; j++)
	if(a[i] >= a[j] && res[j] > max) max = res[j];
      if(maxgain < max+1-res[i]) maxgain = max+1-res[i];
      res[i] = max+1;
    }
  }

  max = 0;
  for(j=0; j<N; j++)
    if(res[j] > max) max = res[j];
  max += (T-t)*maxgain;

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

  return 0;
}


/* practice with Dukkha */
#include <stdio.h>
#include <stdlib.h>

#define N	100
#define A	300

int tt[A + 1];

void update(int i, int x) {
	while (i <= A) {
		if (tt[i] < x)
			tt[i] = x;
		i |= i + 1;
	}
}

int query(int i) {
	int x = 0;

	while (i >= 0) {
		if (x < tt[i])
			x = tt[i];
		 i &= i + 1;
		 i--;
	}
	return x;
}

int main() {
	static int aa[N], kk[A + 1];
	int n, m, t, h, i, a, a_, ans;

	scanf("%d%d", &n, &t);
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		aa[i] = a;
		kk[a]++;
	}
	a_ = 0;
	for (a = 1; a <= A; a++)
		if (kk[a_] < kk[a])
			a_ = a;
	m = n * n < t ? n * n : t;
	for (h = 0; h < m; h++)
		for (i = 0; i < n; i++)
			update(aa[i], query(aa[i]) + 1);
	ans = query(A);
	if (t > n * n)
		ans += (t - n * n) * kk[a_];
	printf("%d\n", ans);
	return 0;
}


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

typedef long long int lli;

#define TRUE         (1==1)
#define FALSE        (!(TRUE))
#define in32(x)      scanf("%d", &(x))
#define in64(x)      scanf("%I64d", &(x))
#define instr(x)     scanf("%s", (x))
#define out32(x)     printf("%d\n", (x))
#define out64(x)     printf("%I64d\n", (x))
#define outstr(x)    printf("%s\n", (x))
#define max(a,b)     ((a)<(b))?(b):(a)
#define min(a,b)     ((a)>(b))?(b):(a)
#define abs(a)       ((a)<0)?(-(a)):(a)
#define fo3(i,a,b)   for(i=(int)(a);i<=(int)(b);i++)
#define of3(i,a,b)   for(i=(int)(a);i>=(int)(b);i--)

#define MOD    998244353
#define MAX    5005
#define SENT   -1

typedef struct Pair {
    int fi, se;
} Pair;

int comp(Pair * f, Pair * s) {
    return (f->fi - s->fi);
}

void sort(Pair ** arr, int size) { // CHANGE THIS
    int i;
    if (size < 6) {
        int nSize = 0;
        int s = size;
        while (size != 0) {
            nSize = 0;
            for (i = 0; i < size - 1; i++)
                if (comp(arr[i], arr[i+1]) > 0) { // CHANGE THIS
                    Pair * tmp = arr[i];
                    arr[i] = arr[i+1];
                    arr[i+1] = tmp;
                    nSize = i+1;
                }
            size = nSize;
        }
        return;
    }
    Pair ** tmp = (Pair **)calloc(size, sizeof(Pair *)); // CHANGE THIS
    int lSize = (size >> 1);
    int rSize = size - lSize;
    sort(arr, lSize); sort(arr + lSize, rSize);
    int lPtr = 0, rPtr = 0;
    int ptr = 0;
    while (ptr != size) {
        if (lPtr == lSize)
            tmp[ptr] = arr[lSize + (rPtr++)];
        else if (rPtr == rSize || comp(arr[lPtr], arr[lSize + rPtr]) <= 0) // CHANGE THIS
            tmp[ptr] = arr[lPtr++];
        else
            tmp[ptr] = arr[lSize + (rPtr++)];
        ptr++;
    }
    for (i = 0; i < size; i++)
        arr[i] = tmp[i];
    free(tmp);
}

int main(void) {
    int i, n, m;
    in32(n);
    in32(m);
    int need[n];
    fo3(i,0,n-1)
        in32(need[i]);
    Pair ** p = calloc(m, sizeof(Pair*));
    fo3(i,0,m-1) {
        p[i] = calloc(1,sizeof(Pair));
        in32(p[i]->fi);
        in32(p[i]->se);
    }
    sort(p,m);
    lli pos = 2000000, min = 0, max = 2000000 - 1;
    int have[n];
    while (min <= max) {
        lli mid = (min + max) >> 1;
        fo3(i,0,n-1)
            have[i] = 0;
        lli spent = 0;
        lli maxDay = mid;
        of3(i,m-1,0) {
            int day = p[i]->fi;
            if (day > mid)
                continue;
            int ind = p[i]->se-1;
            int miss = need[ind] - have[ind];
            if (maxDay > day)
                maxDay = day;
            int buy = miss;
            if (buy > maxDay)
                buy = maxDay;
            have[ind] += buy;
            maxDay -= buy;
            spent += buy;
        }
        fo3(i,0,n-1)
            spent += ((need[i] - have[i])<<1);
        if (spent <= mid) {
            pos = mid;
            max = mid - 1;
        } else
            min = mid + 1;
    }
    out64(pos);
    return 0;
}


#include <stdio.h>

typedef struct mk
{
	int day,type;
}roy;

int n,m,a[200010],l,r,tot=0;
roy off[200010],tmp[200020];

int ok(int days){
	int t[n+1];
	int need = 0,collect = days;
	for(int i = 0;i<n;i++) t[i] = a[i];
	for(int i = m-1;i>=0;i--){
		if(off[i].day>days) continue;
		collect = (collect<=off[i].day)?collect:off[i].day;
		int tp = (collect<=t[off[i].type-1])?collect:t[off[i].type-1];
		need += tp;
		t[off[i].type-1]-= tp;
		collect-=tp;
	}
	need += (tot - need)*2;
	return (need<=days);
}
void merge(roy *of, int s,int m,int e){
	int i = s,j = m+1,k = 0;
	while (i<=m && j<=e){
		if(of[i].day==of[j].day){
			tmp[k++] = (a[of[i].type-1]<a[of[j].type-1])?of[i++]:of[j++];
		}
		else tmp[k++] = (of[i].day<of[j].day)?of[i++]:of[j++];
	}
	while (i<=m) tmp[k++] = of[i++];
	while (j<=e) tmp[k++] = of[j++];
	for(int i = s;i<=e;i++) {
		of[i] = tmp[i-s];
	}
}
void sort(roy *of, int s,int e){
	if(s<e){
		int m = (e+s)/2;
		sort(of,s,m);
		sort(of,m+1,e);
		merge(of,s,m,e);
	}
}
void solve(){
	scanf("%d%d",&n,&m);
	for(int i = 0;i<n;i++){
		scanf("%d",a+i);
		tot += a[i];
	}
	for(int i = 0;i<m;i++){
		scanf("%d%d",&off[i].day,&off[i].type);
	}
	sort(off, 0, m-1);
	l = 1;r = tot*2+1;
	int Ans;
	while (l<=r)
	{
		int m = (l+r)/2;
		if(ok(m)){
			Ans  = m;
			r = m-1;
		}
		else l = m+1;
	}
	for(int i = l;i<=r;i++){
		if(ok(i)){
			Ans = i;
			break;
		}
	}
	printf("%d\n",Ans);
}
int main(){
	solve();
	return 0;
}


#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <float.h>
#include <limits.h>
#include <malloc.h>
#include <memory.h>
#include <complex.h>
#include <errno.h>
#include <time.h>
int n,m,i,j,k,min,ans[25],f[25],s,l,t[25];
struct u
{
	int a,b;
}a[25],b[25];

int main()
{
	scanf("%d %d",&n,&m);
	for (i=1;i<=n;i++) scanf("%d %d",&a[i].a,&a[i].b);
	for (i=1;i<=m;i++) scanf("%d %d",&b[i].a,&b[i].b);
	memset(ans,0,sizeof(ans));
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=9;j++) t[j]=ans[j];
		for (j=1;j<=m;j++)
		{
			memset(f,0,sizeof(f));
			f[a[i].a]++;
			f[a[i].b]++;
			f[b[j].a]++;
			f[b[j].b]++;
			for (l=1,s=0;l<=9;l++)
			if (f[l])
			{
				s++;
				if (f[l]==2) k=l;
			}
			if (s==3) ans[k]++;
		}
		memset(f,0,sizeof(f));
		for (j=1,s=0;j<=9;j++)
		if (t[j]<ans[j]) s++;
		if (s>1)
		{
			puts("-1");
			exit(0);
		}
	}
	memset(ans,0,sizeof(ans));
	for (i=1;i<=m;i++)
	{
		for (j=1;j<=9;j++) t[j]=ans[j];
		for (j=1;j<=n;j++)
		{
			memset(f,0,sizeof(f));
			f[a[j].a]++;
			f[a[j].b]++;
			f[b[i].a]++;
			f[b[i].b]++;
			for (l=1,s=0;l<=9;l++)
			if (f[l])
			{
				s++;
				if (f[l]==2) k=l;
			}
			if (s==3) ans[k]++;
		}
		for (j=1,s=0;j<=9;j++)
		if (t[j]<ans[j]) s++;
		if (s>1)
		{
			puts("-1");
			exit(0);
		}
	}
	memset(f,0,sizeof(f));
	for (i=1,s=0;i<=9;i++)
	if (ans[i])
	{
		s++;
		k=i;
	}
	if (s==0) puts("-1");
	else if (s==1) printf("%d\n",k);
	else puts("0");
	return 0;
}


#include<stdio.h>
#include<limits.h>
#include<stdlib.h>
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
int main()
{
    int i, time, price = INT_MAX, x, y, z, t, h, a, d;
    int hpy, atky, defy, hpm, atkm, defm;
    scanf("%d %d %d", &hpy, &atky, &defy);
    scanf("%d %d %d", &hpm, &atkm, &defm);
    scanf("%d %d %d", &x, &y, &z);
    for(time=1; time<=100; time++){

        for(i=0; i<=200; i++){
            if((hpm - time*(atky + i - defm)) <= 0){
                a=i;    break;
            }
        }

        for(d=0; d<=100; d++){
            h = MAX(0, (time*(atkm - defy - d) - hpy + 1));
            price = MIN(price, h*x + a*y + d*z);
        }

    }
    printf("%d\n", price);
    return 0;
}


#include <stdio.h>

int main(void)
{
    int hy, ay, dy;
    int hm, am, dm;
    int ch, ca, cd;
    scanf("%d %d %d", &hy, &ay, &dy);
    scanf("%d %d %d", &hm, &am, &dm);
    scanf("%d %d %d", &ch, &ca, &cd);
    int mina = ay > dm ? ay : dm + 1;
    int maxa = ay > hm + dm ? ay : hm + dm;
    int maxd = dy > am ? dy : am;
    int a, d, val = -1;
    for (a = mina; a <= maxa; a++) {
        int decm = a - dm, t = (hm + decm - 1) / decm;
        for (d = dy; d <= maxd; d++) {
            int decy = am - d > 0 ? am - d : 0;
            int ht = hy - decy * t;
            int hp = ht > 0 ? 0 : 1 - ht;
            int c = (a - ay) * ca + (d - dy) * cd + hp * ch;
            if (val == -1 || c < val)
                val = c;
        }
    }
    printf("%d\n", val);
    return 0;
}


#include <stdint.h>
#include <stdio.h>

#define MODULUS 1000000007
#define _       % MODULUS

#define MAX_RG  76543
#define MAX_PR  7654

int prime_ct = 0, primes[MAX_PR];
unsigned char not_prime[MAX_RG] = { 0 };

void sieve()
{
    int i, j;
    not_prime[0] = not_prime[1] = 1;
    for (i = 2; i < MAX_RG; ++i) {
        if (!not_prime[i]) primes[prime_ct++] = i;
        for (j = 0; j < prime_ct && i * primes[j] < MAX_RG; ++j)
            not_prime[i * primes[j]] = 1;
    }
}

int mu(int n)
{
    int i, ret = 1;
    for (i = 0; i < prime_ct; ++i) {
        if (n % primes[i] == 0) {
            n /= primes[i];
            ret = -ret;
            if (n % primes[i] == 0) return 0;
        }
    }
    if (n > 1) ret = -ret;
    return ret;
}

int qpow(int base, int exp)
{
    int ans = 1;
    for (; exp; exp >>= 1, base = ((int64_t)base * base)_)
        if (exp & 1) ans = ((int64_t)ans * base)_;
    return ans;
}

int count_seqs(int sum, int gcd_mul)
{
    if (sum % gcd_mul != 0) return 0;
    return qpow(2, sum / gcd_mul - 1);
}

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

    if (y % x != 0) { puts("0"); return 0; }
    y /= x;

    sieve();

    int64_t ans = 0;
    int i;
    for (i = 1; i * i <= y; ++i) if (y % i == 0) {
        ans += count_seqs(y, i) * mu(i);
        if (i * i != y)
            ans += count_seqs(y, y / i) * mu(y / i);
    }

    printf("%I64d\n", (ans _ + MODULUS)_);

    return 0;
}


#include <stdio.h>

#define MD	1000000007

int power(int a, int b) {
	int p;

	if (b == 0)
		return 1;
	p = power(a, b / 2);
	p = (long long) p * p % MD;
	if (b % 2 == 1)
		p = (long long) p * a % MD;
	return p;
}

int solve(int x) {
	return power(2, x - 1);
}

int sign(int x) {
	int a, cnt;

	cnt = 0;
	for (a = 2; a * a <= x; a++) {
		if (x % a == 0) {
			x /= a;
			cnt++;
		}
		if (x % a == 0)
			return 0;
	}
	if (x > 1)
		cnt++;
	return cnt % 2 == 0 ? 1 : -1;
}

int main() {
	int x, y, a, sum;

	scanf("%d%d", &x, &y);
	if (y % x != 0) {
		printf("0\n");
		return 0;
	}
	y /= x;
	sum = 0;
	for (a = 1; a * a <= y; a++)
		if (y % a == 0) {
			sum = ((long long) sum + (sign(a) * solve(y / a) % MD) + MD) % MD;
			if (y / a != a)
				sum = ((long long) sum + (sign(y / a) * solve(a)) + MD) % MD;
		}
	printf("%d\n", sum);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

#define MIN(a,b) ((a)<(b)?(a):(b))

#define POS(i, j) ((i) * (n + 1) + (j))

void run (void) {
  i32 n = read_int();
  char *s = (char *) calloc (n + 1, sizeof (char));
  scanf ("%s", s);
  i32 len = 1;
  for (i32 i = 1; i < n; ++i) {
    if (s[i] == s[len - 1]) continue;
    s[len++] = s[i];
  }
  s[len] = '\0';
  n = len;
  i32 *dp = (i32 *) calloc ((n + 1) * (n + 1), sizeof (i32));
  for (i32 len = 1; len <= n; ++len) {
    for (i32 l = 0; l < n + 1 - len; ++l) {
      i32 r = l + len;
      i32 min = 1 + dp[POS(l + 1, r)];
      for (i32 j = l + 1; j < r; ++j) {
        if (s[j] != s[l]) continue;
        min = MIN(min, dp[POS(l + 1, j)] + dp[POS(j, r)]);
      }
      dp[POS(l, r)] = min;
    }
  }
  print_int (dp[POS(0, n)]);
  puts("");
}

int main (void) {
  run ();
  return 0;
}


/*
Author:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%   LALIT KUNDU      %%%%%%%%
%%%%%%%%   IIIT HYDERABAD   %%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>
#define lld long long int
#define llu long long unsigned int
int compare(const void * a, const void * b){return *(lld *)a-*(lld *)b;}
#define min(a,b)(a>b?b:a)
#define max(a,b)(a<b?b:a)
#define sort(arr,n) qsort(arr,n,sizeof(arr[0]),compare)
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define su(n) scanf("%llu",&n)
#define rep(i,start,end) for(i=start; i<end; i++)
#define pdn(n) printf("%d\n",n)
#define pln(n) printf("%lld\n",n)
#define pun(n) printf("%llu\n",n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define pu(n) printf("%llu",n)
#define pn printf("\n")
#define ps printf(" ")
int per(int n)
{
    int max=-1,temp=n;
    while(temp!=0)
    {
        if(temp%10>max)max=temp%10;
        temp/=10;
    }
    return n-max;
}
int main()
{
    int n,count=0;
    sd(n);
    if(n==0)pdn(0);
    else
    {
    while(1)
    {
        if(n%10==n)break;
        n=per(n);
        count++;
    }
    pdn(count+1);
    }
    return 0;
}


#include<stdio.h>

int max(int c){

    int max;
    int r;
    int l=0;
    while(c!=0){

        max=c%10;

        if(max>l)
        {
        r=max;
        l=r;

        }
    c=c/10;
    }
    return r;
}

int main(){

    int a;

    scanf("%d",&a);
    int i=a;
    int j=0;
    while(i!=0){
  //  printf("r:%d ",max(i));
    i-= max(i);
    j++;
    }

     printf("%d",j);
    return 0;

}


/*
 * main.c
 *
 *  Created on: 30 ���� 2014 �.
 *      Author: ulgish
 */

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

long long maxn = 1000* 1000 * 1000 + 7;

void print_long_number(long long n){
	long long carry = 10;
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
	printf("\n");
}

int main(){
	int nn,mm,kk;
	scanf("%d %d %d", &nn, &mm, &kk);
	long long n = nn, m = mm, k = kk;
	if (n < m){
		int tmp;
		tmp = m;
		m = n;
		n = tmp;
	}
	if (n + m - 2 == k){
		printf("1\n");
		return 0;
	}
	if (n + m - 2 < k){
		printf("-1\n");
		return 0;
	}
	if ((n * m % (k + 1)) == 0){
		print_long_number((n * m / (k + 1)));
		return 0;
	}else{
		long long r1 = -1, r2 = -1;
		if (k <= (n - 1)){
			r1 = ((n / (k + 1)) * m);

		}
		if (k <= (m - 1)){
			r2 = ((m / (k + 1)) * n);
		}
		if (r1 == -1 && r2 == -1)
			goto finish;
		if (r1 > r2){
			print_long_number( r1);
			return 0;
		}else{
			print_long_number( r2);
			return 0;
		}
		finish:
		r1 = -1, r2 = -1;
		r1 = ((n / ((k - m + 1) + 1)));
		r2 = ((m / ((k - n + 1) + 1)));
		if (r1 > r2){
			print_long_number( r1);
			return 0;
		}else{
			print_long_number( r2);
			return 0;
		}
		printf("-1");
		return 0;
	}

	return 0;
}


//
//  main.c
//  codechef
//
//  Created by Varun Kantamneni on 7/17/14.
//  Copyright (c) 2014 Varun Kantamneni. All rights reserved.
//

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

#define mod 1000000007

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

    int n,m;
    long long int k;
    long long int c;
    long long int temp;
    long long int ans1;
    long long int ans2;
    int temp2;
    long long int temp3;
    scanf(" %d %d %lld", &n, &m, &k);
    temp = ((long long int)n) + m - 2;
    if (m > n) {
        temp2 = m;
        m = n;
        n = temp2;

    }
    c = k+ 1;
    if (k > temp) {
        printf("-1");
    }
    else {
        if (c <= m) {
            ans1 = (m/c)*n;
            ans2 = (n/c)*m;
            if (ans1 > ans2) {
                printf("%lld",ans1);
            }
            else {
                printf("%lld",ans2);
            }
        }
        else if (c <= n) {
            temp3 = c - m+1;
            ans1 = (n/temp3);
            ans2 = (n/c)*m;
            if (ans1 > ans2) {
                printf("%lld",ans1);
            }
            else {
                printf("%lld",ans2);
            }
        }
        else {
            temp3 = c - m+1;
            ans1 = (n/temp3);
            temp3 = c - n+1;
            ans2 = (m/temp3);
            if (ans1 > ans2) {
                printf("%lld",ans1);
            }
            else {
                printf("%lld",ans2);
            }
        }

    }

    return 0;
}


#include <stdio.h>

#define N	16
#define M	1000000007

int cnt;

int factorial(int n) {
	return n == 0 ? 1 : (long long) factorial(n - 1) * n % M;
}

void solve(int *bb, int *cc, int i, int n) {
	int k, tmp;

	if (i == n) {
		cnt = (cnt + 1) % M;
		return;
	}
	for (k = 0; k <= n - i - 1; k++) {
		int j = (cc[k] - i + n) % n;

		if (!bb[j]) {
			tmp = cc[k], cc[k] = cc[n - i - 1], cc[n - i - 1] = tmp;
			bb[j] = 1;
			solve(bb, cc, i + 1, n);
			tmp = cc[k], cc[k] = cc[n - i - 1], cc[n - i - 1] = tmp;
			bb[j] = 0;
		}
	}
}

int main() {
	int n;

	scanf("%d", &n);
	if (n == 0)
		for (n = 1; n <= N; n++) {
			int c, cc[N], bb[N] = { 0 };

			for (c = 0; c < n; c++)
				cc[c] = c;
			cnt = 0;
			solve(bb, cc, 0, n);
			printf("%lld\n", (long long) cnt * factorial(n) % M);
		}
	else {
		int a[] = { 0, 1, 0, 18, 0, 1800, 0, 670320, 0, 734832000, 0, 890786230, 0, 695720788, 0, 150347555, 0 };

		printf("%d\n", a[n]);
	}
	return 0;
}


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

#define MODULO 1000000007

int ma[20][20];
int b[20], col[20];
int n;

long long sols[17] = {0,1,0,18,0,1800,0,670320,0,734832000,0,890786230,0,695720788,0,150347555,0};

long long dfs(int x, int k);
long long precalc();

int main(){

   	//precalc();

	int n;
	scanf("%d", &n);
	printf("%I64d\n", sols[n]);

#ifdef _AT_HOME_
    system("pause");
#endif

    return 0;
}

long long dfs(int x, int k){
	if (k>n){
		return 1;
	}
	int i;
	int t = 0;
	for (i=1;i<=n;i++){
		if (b[ma[k][i]] || col[i]) continue;
		b[ma[k][i]] = 1;
		col[i] = 1;
		t +=dfs(i, k+1);
		b[ma[k][i]] = 0;
		col[i] = 0;
	}
	return t;
}

long long precalc(){
	int tt;
	for (tt=1;tt<16;tt+=2){

		int i,j;
	    n = tt;

	    for (i=1;i<=n;i++){
	    	for (j=1;j<=n;j++){
	    		ma[i][j] = (i-1+j-1) % n + 1;
	    	}
	    }

	    long long sol = 0;
	    for (i=1;i<=1;i++){
	    	b[ma[1][i]] = 1;
	    	col[i] = 1;
	    	sol += dfs(i, 2);
	    	if (sol>MODULO){
	    		sol -= MODULO;
	    	}
	    	b[ma[1][i]] = 0;
	    	col[i] = 0;
	    }

	    sol *= n;
	    sol %= MODULO;

	    long long fak = 1;
	    for (i=2;i<=n;i++){
	    	fak *= i;
	    	fak %= MODULO;
	    }

	    sol *= fak;
	    sol %= MODULO;

	    printf("%I64d\n", sol);
	}
}


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

#define MAX 6437
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

int n, m, h, lim;
short hash[1 << 16];
long long res, fact[20];
unsigned char dp[MAX][MAX];

void backtrack(int i, int l, int mask, int lol, int flag){
    if (i == l){
        if (!flag) dp[hash[mask]][hash[lol]]++;
        else res += dp[hash[mask ^ lim]][hash[lol ^ lim]];
        return;
    }

    int j, k;
    for (j = 0; j < n; j++){
        if (!(mask & (1 << j))){
            k = i + j;
            if (k >= n) k -= n;
            if (!(lol & (1 << k))) backtrack(i + 1, l, mask ^ (1 << j), lol ^ (1 << k), flag);
        }
    }
}

int main(){
    int i, j, k;
    for (fact[0] = 1, i = 1; i < 20; i++) fact[i] = (fact[i - 1] * i) % MOD;

    while (scanf("%d", &n) != EOF){
        clr(dp);
        h = 0, m = n >> 1, lim = (1 << n) - 1;

        for (i = 0; i <= lim; i++){
            if (__builtin_popcount(i) == m) hash[i] = ++h;
        }

        if (n & 1){
            res = 0;
            backtrack(0, m, 0, 0, 0);
            backtrack(m, n, 0, 0, 1);
            printf("%lld\n", (res % MOD) * fact[n] % MOD);
        }
        else puts("0");
    }
    return 0;
}


#include<stdio.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define INF 1000000007
int main()
{
	int n,i;
	int myx1[6],myy1[6],myx2[6],myy2[6];
	long int area;
	int minix,miniy,maxix,maxiy;
	while(scanf("%d",&n)!=EOF)
	{
		minix = INF;
		maxix = -1;

		miniy = INF;
		maxiy = -1;
		area = 0;
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d%d",&myx1[i],&myy1[i],&myx2[i],&myy2[i]);
			area += (myx2[i]-myx1[i])*(myy2[i]-myy1[i]);
			minix = MIN(myx1[i],minix);
			maxix = MAX(myx2[i],maxix);
			miniy = MIN(myy1[i],miniy);
			maxiy = MAX(myy2[i],maxiy);
		}
		if ( area == (maxix-minix)*(maxiy-miniy) && (maxix - minix) == (maxiy-miniy))
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}


#include <stdio.h>
int main(void)
{
    int *a;
    int b,i,k=100,x=0;
    scanf("%d",&b);
    a = malloc(b*sizeof(int));
    for(i=0;i<b;i++)
    {
        scanf("%d", &a[i]);
        if(a[i]<k)k=a[i];
    }
    for(i=0; i<b; i++)
        if(a[i]==k)x++;
    if(x>b/2)printf("Bob\n");
    else printf("Alice\n");

    return 0;
}


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

long long i,a[200000],x,n,k;
long long w;

int main()
{
    scanf("%I64d", &n);
    k=100;
    for(i=0; i<n; i++)
    {
        scanf("%I64d", &a[i]);
        if(a[i]<k)k=a[i];
    }

    x=0;

    for(i=0; i<n; i++)
    {
        if(a[i]==k)x++;
    }

    if(x>n/2)printf("Bob\n");
    else printf("Alice\n");

    return 0;
}


#include <stdio.h>

#define MAX 1000010

int p, primes[78777], flag[MAX] = {0};

void Sieve(){
    int i, j, d;

    flag[2] = 1;
    for (i = 3; i < MAX; i++, i++) flag[i] = 1;
    for (i = 3; i < 1001;){
        d = i << 1;
        for (j = (i * i); j < MAX; j += d) flag[j] = 0;

        i++, i++;
        while (!flag[i]) i++, i++;
    }

    p = 0;
    for (i = 0; i < MAX; i++){
        if (flag[i]) primes[p++] = i;
    }
}

int isPrime(long long x){
    if ((x < 2)) return 0;

    int i;
    for (i = 0; ; i++){
        long long y = primes[i];
        if ((y * y) > x) return 1;
        if ((x % y) == 0) return 0;
    }
}

int F(int i, long long a){
    if (a == 1) return 1;
    long long y = primes[i];
    if ((y + 1) > a) return 0;

    if (((y * y) + 1) > a){
        if (isPrime(a - 1)) return 1;
        return 0;
    }

    long long x = 1;
    int res = F(i + 1, a);

    for (; ;){
        x *= y;
        if ((x + 1) > a) break;

        if ((a % (x + 1)) == 0) res = res + F(i + 1, a / (x + 1));
    }
    return res;
}

int Solve(long long a){
    if (a < 5) return (a != 2);
    return F(0, a);
}

int main(){
    Sieve();
    long long a;
    while (scanf("%I64d", &a) != EOF) printf("%d\n", Solve(a));
    return 0;
}


#include<stdio.h>
int main(){
  long long n,m,k,i,j=0,s=0;
  scanf("%lld %lld %lld",&n,&m,&k);
  n/=k;
  for(i=1;i<=m;i*=10)j++;//printf("%lld %lld %lld %lld\n",i,j,m,(i-m)*j*k);
  for(;(i-m)*j<n;j++){//printf("%lld %lld %lld %lld\n",i,j,m,n);
    n-=(i-m)*j;
    s+=i-m;
    m=i;
    i*=10;
  }//printf("%lld %lld %lld %lld\n",i,j,m,n);
  printf("%lld\n",s+n/j);
  return 0;
}


#include <stdio.h>

long long int seqSum(long long int x) {
    long long int sum = 0;
    long long int pow_of_ten = 1;
    long long int idx = 1;
    while (pow_of_ten*10 <= x) {
        sum += pow_of_ten*9*idx;
        pow_of_ten *= 10;
        idx++;
    }
    sum += (x - pow_of_ten + 1)*idx;
    return sum;
}

long long int sequenceLength(long long int w, long long m) {
    long long int start = m-1;
    long long int end = 100000000000000000;
    while(start != end) {
        long long int middle = (start+end)/2 + 1;
        if (seqSum(middle) - seqSum(m-1) > w) {
            end = middle - 1;
        }
        else {
            start = middle;
        }
    }
    return (start - m + 1);
}

int main() {
   long long int w, m, k;
   scanf("%lld %lld %lld", &w, &m, &k);
   w = w/k;
   long long int n = sequenceLength(w, m);
   printf("%lld", n);
   return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define MX 1000000

int len;
char in[100];
int res;

void solve(int depth, int st, int sum){
  int i,j,k;

  if(depth==3){
    if(st!=len) return;
    if(res < sum) res = sum;
    return;
  }

  k = 0;
  REP(i,st,len){
    k = k * 10 + (in[i] - '0');
    if(k > MX) break;
    solve(depth+1, i+1, sum+k);
    if(in[st]=='0') break;
  }
}

int main(){
  int i,j,k;

  scanf("%s",in);
  len = strlen(in);

  res = -1;
  solve(0,0,0);

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

  return 0;
}


#include<stdio.h>

int isPrime(int n)
{
    int i;
    for(i=2;i<=n/i;i++)
        if(n%i==0)
            return 0;
    return 1;
}
int main()
{
    int n;
    scanf("%d",&n);
    if(n==2)
        printf("1\n");
    else if(n%2==0)
        printf("2\n");
    else if(isPrime(n))
        printf("1\n");
    else if(isPrime(n-2))
        printf("2\n");
    else printf("3\n");

    return 0;
}


#include <stdio.h>
int prime(int n)
{
	int i;
	for (i=2; i*i<=n; i++)
		if (n%i==0) return 0;
	return 1;
}
int main()
{
	int n;
	scanf("%d",&n);
	if (prime(n)) printf("1\n");
	else if (n%2==0 || prime(n-2)) printf("2\n");
	else printf("3\n");
	return 0;
}


#include <string.h>

int valid (char word[]) {
    int sum1 = 0, i, sum2 = 0;
    for(i = 0; i < 3; i++) {
        sum1 += word[i] - '0';
        sum2 += word[i + 3] - '0';
    }
    return sum1 == sum2;
}

int fill (int pos, char word[], char base[]) {
    int i;
    if(pos == 6) {
        if(valid(word) == 0) {
            return 100;
        }
        int change = 0;
        for(i = 0; i < 6; i++) {
            if(base[i] != word[i]) change++;
        }
        return change;
    }
    int ans = 100;
    for(i = 0; i < 10; i++) {
        word[pos] = (char)(i + '0');
        int check = fill(pos+1, word, base);
        if(check < ans) ans = check;
        word[pos] = '?';
    }
    return ans;
}

int main() {
    char base[6], word[6];
    scanf("%s", base);
    printf("%d\n", fill(0, word, base));
}


#include <stdio.h>

int main()
{
	int str[7],i,j,b,tkt,sf,sn,opt,dif,rem,temp,check;

	scanf("%d",&tkt);
	b = tkt;

	for (i = 5; i >= 0; --i)
	{
		str[i] = b%10;
		b/=10;
	}

	sf = str[0] + str[1] + str[2];
	sn = str[3] + str[4] + str[5];

	if(sn<sf)
	{
		dif = sf - sn;

		temp =  str[0];
		str[0] = str[3];
		str[3] = temp;

		temp =  str[1];
		str[1] = str[4];
		str[4] = temp;

		temp =  str[2];
		str[2] = str[5];
		str[5] = temp;
	}
	else
		dif = sn - sf;

	if(dif == 0)
		opt = 0;
	else if(dif > 18)
		opt = 3;
	else if(dif > 0 && dif <= 9)
	{
		for(i = 0, check = 0; i < 6; ++i)
		{
			if(i < 3)
			{
				if(str[i] + dif <= 9)
				{
					check = 1;
					break;
				}
			}
			else
			{
				if(str[i] - dif >= 0)
				{
					check = 1;
					break;
				}
			}
		}
		if(check)
			opt = 1;
		else
			opt = 2;
	}
	else
	{
		for(i = 0, check = 0; i < 6; ++i)
		{
			if(i < 3)
			{
				rem = 9 - str[i];
				for(j = 0, check = 0; j < 6; ++j)
				{
					if(j < 3)
					{
						if(rem + 9-str[j] >= dif && i != j)
						{
							check = 1;
							break;
						}
					}
					else
					{
					    if(str[j] + rem >= dif)
						{
							check = 1;
							break;
						}
					}

				}
			}
			else
			{
				rem = str[i];
				for(j = 0, check = 0; j < 6; ++j)
				{
					if(j < 3)
					{
						if(rem + 9-str[j] >= dif)
						{
							check = 1;
							break;
						}
					}
					else
					{
					    if(rem + str[j] >= dif && i != j)
						{
							check = 1;
							break;
						}
					}

				}
			}
			if(check)
				break;
		}

		if(check)
			opt = 2;
		else
			opt = 3;
	}

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

	return 0;
}


#include<stdio.h>

typedef long long int ll;

ll isprime[1000005];
ll primes[1000005];
ll cnt1[1000005];

unsigned int nextPowerOf2(unsigned int n)
{
unsigned count = 0;

if (n && !(n & (n - 1)))
    return n;

while( n != 0)
{
    n >>= 1;
    count += 1;
}

return 1 << count;
}

int main()
{
	ll n, cnt=0;
	scanf("%lld", &n);

	ll n2 = n;

	for(int i=2;i<=n;i++)
	{
		// printf("1\n");
		if(isprime[i]==0)
		{
			// printf("2\n");
			primes[cnt++]=i;

			for(int j=2*i;j<=n;j+=i)
				isprime[j]=1;
		}
	}
	ll max=0, min=1000005, flag=0;
	// printf("cnt %lld\n", cnt);
	for(ll k=0; k<cnt; k++)
	{
		// printf("n %lld\n", n);
		while(n%primes[k]==0)
		{
			cnt1[k]++;

			if(cnt1[k]>max)
				max=cnt1[k];

			flag=1;

			n/=primes[k];
			// printf("%lld\n", n);
		}

			if(cnt1[k]<min && flag==1)
				min=cnt1[k];

			flag=0;
	}
	// printf("max %lld\n", max);
	ll ans=1;
	for(ll a=0; a<cnt; a++)
	{
		if(cnt1[a])
		{
			ans*=primes[a];
		}
	}
	// printf("min %lld max%lld\n", min, max);
	ll ans2=0;

	if(n2==1)
	{
		printf("1 0\n");
	}

	else if(max>min)
	{
		// if(min==1)
		// 	ans2++;

		min=max;
		if(min)
		{
			// if(nextPowerOf2(min)==min)
			// 	ans2--;

			min=nextPowerOf2(min);
			// printf("min is %lld\n", min);

			if(min==1)
				min++;

			ans2++;
			while(min!=1)
			{
				ans2++;
				// printf("ans2 %lld\n", ans2);
				min/=2;
				// printf("min %lld\n", min);
			}

			max=min;
		}

		printf("%lld %lld\n", ans, ans2);
	}

	else if(min>1)
	{
		if(nextPowerOf2(min)==min && min!=1)
			ans2--;

		min=nextPowerOf2(min);

		if(min==1)
			min++;

		ans2++;
		while(min!=1)
		{
			ans2++;
			// printf("ans2 %lld\n", ans2);
			min/=2;
			// printf("min %lld\n", min);
		}

		max=min;

		printf("%lld %lld\n", ans, ans2);
	}
	// ans2=min;

	else
	{
		ans2=0;

	// printf("ans2 is %lld\n", ans2);
	// max-=min;
	// printf("max %lld\n", max);
	// max--;

		printf("%lld %lld\n", ans, ans2);

	}

	return 0;
}


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

#define SIZE 1000

void factorization (int n, int p[], int k[], int *sz)
{
	int d;

	if (n == 1)
	{
		p[0] = 1;
		k[0] = 1;
		*sz = 1;
	}

	*sz = 0;

	for (d = 2; d * d <= n; d++)
		if (n % d == 0)
		{
			p[*sz] = d;

			while (n % d == 0)
			{
				k[*sz]++;
				n /= d;
			}

			(*sz)++;
		}

	if (n != 1)
	{
		p[*sz] = n;
		k[(*sz)++] = 1;
	}
}

int is_power_of_two (int n)
{
	while (n % 2 == 0)
		n /= 2;

	return n == 1;
}

int is_need_mult (int p[], int k[], int sz)
{
	int i;

	if (is_power_of_two (k[0]))
		for (i = 1; i < sz; i++)
			if (k[i] != k[i - 1])
				return 1;
			else
				k[i] = k[i];
	else
		return 1;

	return 0;
}

int oper (int p[], int k[], int sz)
{
	int i, cnt = 0, max = 0;

	for (i = 0; i < sz; i++)
		if (k[i] > max)
			max = k[i];

	i = 0;

	while (1 << i < max)
		i++;

	cnt = i;

	if (is_need_mult (p, k, sz))
		cnt++;

	return cnt;
}

int min_num (int p[], int sz)
{
	int i, min = 1;

	for (i = 0; i < sz; i++)
		min *= p[i];

	return min;
}

int main()
{
	int n, i, sz, oper_cnt, p[SIZE] = {0}, k[SIZE] = {0};

	scanf ("%d", &n);

	factorization (n, p, k, &sz);

	oper_cnt = oper (p, k, sz);

	printf ("%d %d\n", min_num (p, sz), oper_cnt);

	return 0;
}


#include<stdio.h>
#define MOD 1000000007

long long mpow(long long a, long long p)
{
  a %= MOD;

  long long r = 1;
  while (p) {
    if ((1 & p)) r = (r * a) % MOD;
    a = (a * a) % MOD;
    p >>= 1;
  }
  return r;
}

int inv(long long x)
{ return mpow(x, MOD-2); }

#define MAXF 100005

long long factorial[MAXF];

long long possib(long long width, long long boxes, long long minh)
{
  long long separators = width-1;
  long long elements = boxes-width*minh;

  if(elements < 0) return 0;
  else return (factorial[separators+elements]*inv(factorial[separators]*factorial[elements])) % MOD;
}

long long all_possib, nice_possib;
void add_all(long long x)
{
  x %= MOD;
  all_possib += x;
  all_possib %= MOD;
}
void add_nice(long long x)
{
  x %= MOD;
  nice_possib += x;
  nice_possib %= MOD;
}

int main()
{
  long long fac;
  int i;
  int result;

  i = 0;
  for(fac = 1; i<MAXF; fac = fac*i % MOD){
    factorial[i] = fac;
    i++;
  }

  int F, W, H, width;
  scanf("%d %d %d\n", &F, &W, &H);

  if(W == 0 || F == 0){
    if(W == 0 || W > H) printf("1\n");
    else printf("0\n");
    return 0;
  }

  all_possib = 0;
  nice_possib = 0;
  for(width=1; width<=W; width++){
    add_all(possib(width, F, 1)*possib(width, W, 1));
    add_all(possib(width+1, F, 1)*possib(width, W, 1));
    add_all(possib(width, W, 1)*possib(width, F, 1));
    add_all(possib(width+1, W, 1)*possib(width, F, 1));

    add_nice(possib(width, F, 1)*possib(width, W, H+1));
    add_nice(possib(width+1, F, 1)*possib(width, W, H+1));
    add_nice(possib(width, W, H+1)*possib(width, F, 1));
    add_nice(possib(width+1, W, H+1)*possib(width, F, 1));
  }
  result = nice_possib*inv(all_possib) % MOD;

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

  return 0;
}


/*
    author:  Maksim1744
    created: 24.10.2020 17:14:50
*/

#include <stdio.h>
#include <inttypes.h>

#define max(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
#define min(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })

#define mod 1000000007

int a[1005];

int main() {
    int n, x, pos;
    scanf("%d%d%d", &n, &x, &pos);
    for (int i = 0; i < n; ++i) {
        a[i] = 0;
    }
    int left = 0, right = n;
    while (left < right) {
        int middle = (left + right) / 2;
        if (pos < middle) {
            a[middle] = 1;
            right = middle;
        } else {
            a[middle] = -1;
            left = middle + 1;
        }
    }
    int bigger = 0, smaller = 0;
    for (int i = 0; i < n; ++i) {
        if (i != pos) {
            if (a[i] == 1) bigger++;
            else if (a[i] == -1) smaller++;
        }
        if (a[i] == 1 && i == pos) {
            printf("0\n");
            return 0;
        }
    }

    long long C[1005][1005];
    for (int i = 0; i < 1005; ++i) {
        C[0][i] = 0;
        C[i][0] = 1;
    }

    for (int i = 1; i < 1005; ++i) {
        for (int j = 1; j < 1005; ++j) {
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
        }
    }

    // printf("%d %d\n", smaller, bigger);
    // for (int i = 0; i < n; ++i) {
    //     printf("%d ", a[i]);
    // }
    // printf("\n");

    long long f[1005];
    f[0] = 1;
    for (int i = 1; i < 1005; ++i)
        f[i] = (f[i - 1] * i) % mod;

    if (smaller > x - 1 || bigger > n - x) {
        printf("0\n");
        return 0;
    }

    long long res = C[x - 1][smaller] * C[n - x][bigger] % mod * f[smaller] % mod * f[bigger] % mod * f[n - smaller - bigger - 1] % mod;
    printf("%d\n", res);

    return 0;
}


# include <stdio.h>

	const int N = 1e3+194;
	const int MOD = 1e9+7;
	const int INF = 1e9+1097;

long long Fact(int n,int k)
	{
    	long long res = 1;
    	for(int i = (n-k)+1; i <= n; i++)
		{
        	res *= i;
        	res %= MOD;
   		}
    	return res;
}

int main ()
{
	int n,x,pos;
	scanf("%d %d %d",&n,&x,&pos);
	int l = 0,r=n;
	int A = x-1,B = n-x,C = 0,D = 0;
    while(l < r)
	{
        int m = (l+r)/2;
        if(m < pos)
		{
            l = m+1;
            C += 1;
        }
        else if(pos < m)
		{
            r = m;
            D += 1;
        }
        else
            l = m+1;
    }
    long long res = 1;
    for(int i = 1; i <= n-1-C-D; i++)
	{
        res *= i;
        res %= MOD;
    }
    long long output;
    output =(((Fact(A,C)%MOD)*(Fact(B,D)%MOD)%MOD)*(res))%MOD;
    printf("%d",output);
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int res;

  while(scanf("%d%d",&n,&m)==2){
    if(n > m) k = n, n = m, m = k;
    if(n==1){ printf("%d\n",m); continue; }
    if(n==2){
      k = (m/4) * 2;
      m %= 4;
      if(m > 2) m = 2;
      printf("%d\n",2*(k+m));
      continue;
    }

    res = (n*m+1)/2;
    printf("%d\n",res);
  }

  return 0;
}


#include <stdio.h>

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

int main()
{
     int n, m;

     scanf("%d %d", &n, &m);

     if (n > m) {
	  int tmp = n;
	  n = m;
	  m = tmp;
     }

     if (n == 1) {
	  printf("%d\n", m);

	  return 0;
     }

     if (n == 2) {
	  printf("%d\n", m / 4 * 4 + min(m % 4, 2) * 2);

	  return 0;
     }

     printf("%d\n", (n * m + 1) / 2);

     return 0;
}


#include<stdio.h>
int n, m[20], r[20];
int gcd(int x, int y){ return y?gcd(y, x%y):x; }
int main()
{
    int i, j, s, cnt=0;
    scanf("%d", &n);
    for(i=1; i<=n; ++i) scanf("%d", &m[i]);
    for(i=1; i<=n; ++i) scanf("%d", &r[i]);
    s=1;
    for(i=1; i<=n; ++i)
    {
        s = s/gcd(s,m[i])*m[i];
    }
    for(i=0; i<s; ++i)
    {
        for(j=1; j<=n; ++j)
            if(r[j]%m[j] == i%m[j]) break;

        if(j<=n) ++cnt;
    }
    printf("%f", (double)cnt/s);
    return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char *argv[]) {
    int n, m[17], r[17], x[1000000], kolvo = 0;
    double result;
    scanf("%d", &n);
    for (int i = 0; i < 1000000; i++) x[i] = 0;
    for (int i = 0; i < n; i++) scanf("%d", &m[i]);
    for (int i = 0; i < n; i++) scanf("%d", &r[i]);
    for (int i = 0; i < 1000000; i++) {
        for (int j = 0; j < n; j++) {
            if (i % m[j] == r[j]) x[i]++;
        }
    }
    for (int i = 0; i < 1000000; i++) if (x[i] > 0) kolvo++;
    result = kolvo / 1000000.0;
    printf("%100.4f", (float) result);
    return 0;
}


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

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

int main(){
    int i, j, k;
    long long x1, y1, x2, y2, x, y, z, d, res;

    while (scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2) != EOF){
        x = (abs(y2 - y1) >> 1) + 1;
        z = x - 1;
        d = (x2 - x1) >> 1;
        res = (x * d) + (z * d) + x;
        printf("%lld\n", res);
    }
    return 0;
}


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

#define A int
#define B int

typedef struct {
    A first;
    B second;
} pair;

pair make_pair(A first, B second)
{
    pair p;

    p.first = first;
    p.second = second;

    return p;
}

int n, m;
char s1[101];
char s2[101];
pair dp[100][100];
pair dp2[100];

pair dfs(int x, int y)
{
    if (x == n) {
        pair p = dfs(0, y);

        p.first++;

        return p;
    } else if (y == m) {
        pair p = make_pair(0, x);

        return p;
    } else {
        if (dp[x][y].first != -1) return dp[x][y];

        if (s1[x] == s2[y]) {
            return dp[x][y] = dfs(x + 1, y + 1);
        } else {
            return dp[x][y] = dfs(x + 1, y);
        }
    }
}

int main()
{
    int b, d, x = 0, y = 0, c = 0, i, j;
    int p[26] = {0};
    int q[26] = {0};

    scanf("%d %d", &b, &d);
    scanf("%s", s1);
    scanf("%s", s2);

    n = strlen(s1);
    m = strlen(s2);

    for (i = 0; i < n; i++) p[s1[i] - 'a']++;
    for (i = 0; i < m; i++) q[s2[i] - 'a']++;

    for (i = 0; i < 26; i++) {
        if (p[i] == 0 && q[i] > 0) {
            puts("0");

            return 0;
        }
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            dp[i][j] = make_pair(-1, -1);
        }
    }

    for (i = 0; i < n; i++) {
        if (dp[i][0].first == -1) dfs(i, 0);
    }

    for (i = 0; i < n; i++) dp2[i] = make_pair(-1, -1);

    while (1) {
        x += dp[y][0].first;
        y = dp[y][0].second;

        if (x >= b) {
            if (x == b && y == 0) c++;

            break;
        }

        c++;

        if (dp2[y].first == -1) {
            dp2[y] = make_pair(x, c);
        } else {
            int z = x - dp2[y].first;

            if (x + z < b) {
                int w = (b - x - 1) / z;

                x += w * z;
                c += (c - dp2[y].second) * w;
            }
        }
    }

    printf("%d\n", c / d);

    return 0;
}


#include <stdio.h>
char a[101],c[101];
int before[101][101];//before[POS][Chk];
int beforeI[101][101];
main(){
    int i,j,k,l,b,d,lenL=0,lenS=0,curChk=0,maxL,maxS,usebefore,first=-1,last=-1,point=i,memo,ans=0,remain,tmpa,tmpb,tmpChk;
    scanf ("%d%d",&b,&d);
    scanf ("%s%s",a,c);
    while (a[lenL]!=0)lenL++;
    while (c[lenS]!=0)lenS++;
    if (lenL*b<lenS*d){ //EXIT if can't possible
        printf ("0");
        exit(0);
    }
    maxL=lenL*b;
    maxS=lenS*d;
    for (i=0;i<maxL;i++){
        /*if (first%lenL==i%lenL&&curChk%lenS==0){
            point=i;
            remain = maxL-i+1;
            memo=point-first+1;
            curChk += (remain/memo)*curChk;
            //printf ("%d %d\n",maxL-i,memo);
            i+=(remain/memo)*(i-1);
            //i=maxL;
        }*/
            if (curChk==0&&i>lenL){
                printf ("0");
                exit(0);
            }
            if (before[i%lenL][curChk%lenS]==0){
                before[i%lenL][curChk%lenS]=curChk;
                beforeI[i%lenL][curChk%lenS]=i;
                if (a[i%lenL]==c[curChk%lenS]) curChk++;
                //printf ("test\n");
            }else if (maxL-i>i-beforeI[i%lenL][curChk%lenS]){
                tmpChk=curChk;
                tmpa=beforeI[i%lenL][curChk%lenS];
                tmpb=before[i%lenL][curChk%lenS];
                before[i%lenL][curChk%lenS]=curChk;
                beforeI[i%lenL][curChk%lenS]=i;
                //printf ("GG\n");
                curChk+=(curChk-tmpb)*((maxL-i)/(i-tmpa));
                i+=(i-tmpa)*((maxL-i)/(i-tmpa))-1;
                //curChk+=(curChk-before[i%lenL][curChk%lenS])*tmpb;
                //i+=(i-tmpa)*tmpb;
                //curChk+=tmpChk-before[i%lenL][curChk%lenS];
                //i+=i-tmpa;
            }else{
                if (a[i%lenL]==c[curChk%lenS])curChk++;
            }
            /*if (curChk==lenS){
                    last=i;
            }*/
            //curChk++;
            //if (curChk%maxS==0) ans++;

        /*
        if (curChk>=maxS&&first%lenL==i%lenL&&curChk%lenS==1){
            point=i;
            remain = maxL-i;
            memo=point-first;
            ans += remain/memo*ans;
            //printf ("%d %d\n",maxL-i,memo);
            i+=(remain/memo)*memo;
            //i=maxL;
        }*/
        /*
        if (first%lenL==i%lenL&&curChk%lenS==0){
            point=i;
            remain = maxL-i;
            memo=point-first+1;
            curChk += (remain/memo)*curChk;
            //printf ("%d %d\n",maxL-i,memo);
            i=(remain/memo)*i;
            //i=maxL;
        }
        */
    }
    //printf ("%d",curChk/maxS);
    //printf ("%d : %d\n",i,curChk);
    printf ("%d",curChk/maxS);
    exit(0);

}


#include <stdio.h>

int main() {
	static int kk[10];
	long long sum;
	int n, d, a, b;

	scanf("%d", &n);
	for (d = 1; d <= 9; d++)
	 kk[d] = n / 9 + (n % 9 >= d);
	sum = 0;
	for (a = 1; a <= 9; a++)
		for (b = 1; b <= 9; b++)
			sum += (long long) kk[a] * kk[b] * kk[(a * b + 8) % 9 + 1];
	for (a = 1; a <= n; a++)
		sum -= n / a;
	printf("%lld\n", sum);
	return 0;
}


#include <stdio.h>

unsigned long long f[9],g[9];

// digital root je zapravo modul od 9.
// ako je mod 9 == 0, digtalni root je 9.

int main() {
	unsigned long long a,b,n;
	scanf("%lld\n",&n);
	for (a=1;a<=n;a++) f[a%9]++;
	unsigned long long cnt=0;
	for (a=0;a<9;a++)
		for (b=0;b<9;b++)
			cnt+=f[a]*f[b]*f[a*b%9];
	for (a=1;a*a<=n;a++)
		cnt-=(n-a*a)/a*2+1;
	printf("%lld\n",cnt);
	return 0;
}


#include<stdio.h>
#define min(a,b) a<b?a:b
long long int dp[10000005];
int main()
{
	long long int n,x,y,i;
	scanf("%lld %lld %lld",&n,&x,&y);
	dp[0]=0;
	dp[1]=x;
	dp[2]=min(dp[1]+y,dp[1]+x);
	for(i=3;i<=n;i++)
	{
		if(i%2==1)
		{
			dp[i]=min(dp[i/2]+x+y,dp[i-1]+x);
			dp[i]=min(dp[i],dp[(i+1)/2]+y+x);
		}
		else
			dp[i]=min(dp[i/2]+y,dp[i-1]+x);
	}
	printf("%lld\n",dp[n]);
	return 0;
}


#include <stdio.h>
typedef long long unsigned int u64;
u64 dp[1<<24];
u64 min(const u64 a, const u64 b) {
    return a < b ? a : b;
}
u64 solve(const u64 n, const u64 x, const u64 y) {
    dp[1] = x;
    for(int i = 1; i <= n; i++)
        if(i & 1) dp[i] = min(dp[i - 1] + x, dp[(i + 1) / 2] + x + y);
        else dp[i] = min(dp[i / 2] + y, dp[i - 1] + x);
    return dp[n];
}

int main(void) {
    int n, x, y;
    scanf("%d%d%d", &n, &x, &y);
    printf("%llu", solve(n, x, y));
    return 0;
}


#include <stdio.h>

#define max(a, b) (((a) > (b)) ? (a) : (b))

int main(void) {
    int i;
    int c;
    long long hr, hb, wr, wb;
    long long ans;

    scanf("%d %lld %lld %lld %lld", &c, &hr, &hb, &wr, &wb);

    ans = 0;
    if (max(wr, wb) * max(wr, wb) > c)
        if (wr > wb)
            for (i = 0; c - wr * i >= 0; i++)
                ans = max(ans, hr * i + (c - wr * i) / wb * hb);
        else
            for (i = 0; c - wb * i >= 0; i++)
                ans = max(ans, hb * i + (c - wb * i) / wr * hr);
    else
        if (hr * wb > hb * wr)
            for (i = 0; c - wb * i >= 0 && i < wr; i++)
                ans = max(ans, hb * i + (c - wb * i) / wr * hr);
        else
            for (i = 0; c - wr * i >= 0 && i < wb; i++)
                ans = max(ans, hr * i + (c - wr * i) / wb * hb);

    printf("%lld\n", ans);

    return 0;
}


#include<stdio.h>
#define LEVEL 1
int main(){
	long long int i,c,hr,hb,wr,wb,tmp,happy,max,happybase,num;
	scanf("%lld %lld %lld %lld %lld",&c,&hr,&hb,&wr,&wb);
	happybase=0;
	if(c>(wr*wb*(LEVEL+1))){
		num=(c/(wr*wb))-LEVEL;
		if((hr*wb)>=(hb*wr)){
			happybase=(hr*wb)*num;
		}else{
			happybase=(hb*wr)*num;
		}
		c-=(wr*wb)*num;
	}
	max=0;
	if(wr>=wb){
		for(i=0;(wr*i)<=c;i++){
			tmp=c-(wr*i);
			happy=(tmp/wb)*hb;
			happy+=(hr*i);
			if(max<happy){
				max=happy;
			}
		}
	}else{
		for(i=0;(wb*i)<=c;i++){
			tmp=c-(wb*i);
			happy=(tmp/wr)*hr;
			happy+=(hb*i);
			if(max<happy){
				max=happy;
			}
		}
	}
	printf("%lld",happybase+max);
	return 0;
}


/* practice with Dukkha */
#include <stdio.h>

int ancestor(long long a, long long b) {
	while (b > a)
		b >>= 1;
	return b == a;
}

int main() {
	int h, c;
	long long n, x, ans;

	scanf("%d%lld", &h, &n);
	n += (1LL << h) - 1;
	x = 1, ans = h;
	c = 0;
	while (x != n)
		if (ancestor(x, n)) {
			x = x << 1 ^ c; c ^= 1;
			h--;
		} else {
			ans += (1LL << h + 1) - 1;
			x >>= 1;
			h++;
		}
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>
#include<time.h>
int t[400],n,m,tot,ans,st[400],tail;
void add(int i)
{
	st[tail++]=i;
}
void del(int i)
{
	tail--;
}
void dfs(int now,int cnt)
{
	if(cnt>=ans)
		return;
	while(now<tot&&t[now]>0)
		now++;
	if(now>=tot)
	{
		int i;
		for(i=0;i<tot;++i)
			if(!t[i])
				return;
		ans=cnt;
		return;
	}
	if(cnt==ans)
		return;
	int to;
	cnt++;
	if(now>=m)
	{
		to=now-m;
		t[to]++;
		if(to-m>=0)		t[to-m]++;
		if(to%m>0)		t[to-1]++;
		if(to+m<tot)	t[to+m]++;
		if(to%m<m-1)	t[to+1]++;
		dfs(now+1,cnt);
		t[to]--;
		if(to-m>=0)		t[to-m]--;
		if(to%m>0)		t[to-1]--;
		if(to+m<tot)	t[to+m]--;
		if(to%m<m-1)	t[to+1]--;
	}
	if(now%m>0)
	{
		to=now-1;
		t[to]++;
		if(to-m>=0)		t[to-m]++;
		if(to%m>0)		t[to-1]++;
		if(to+m<tot)	t[to+m]++;
		if(to%m<m-1)	t[to+1]++;
		dfs(now+1,cnt);
		t[to]--;
		if(to-m>=0)		t[to-m]--;
		if(to%m>0)		t[to-1]--;
		if(to+m<tot)	t[to+m]--;
		if(to%m<m-1)	t[to+1]--;
	}
	if(now+m<tot)
	{
		to=now+m;
		t[to]++;
		if(to-m>=0)		t[to-m]++;
		if(to%m>0)		t[to-1]++;
		if(to+m<tot)	t[to+m]++;
		if(to%m<m-1)	t[to+1]++;
		dfs(now+1,cnt);
		t[to]--;
		if(to-m>=0)		t[to-m]--;
		if(to%m>0)		t[to-1]--;
		if(to+m<tot)	t[to+m]--;
		if(to%m<m-1)	t[to+1]--;
	}
	if(now%m<m-1)
	{
		to=now+1;
		t[to]++;
		if(to-m>=0)		t[to-m]++;
		if(to%m>0)		t[to-1]++;
		if(to+m<tot)	t[to+m]++;
		if(to%m<m-1)	t[to+1]++;
		dfs(now+1,cnt);
		t[to]--;
		if(to-m>=0)	t[to-m]--;
		if(to%m>0)		t[to-1]--;
		if(to+m<tot)	t[to+m]--;
		if(to%m<m-1)	t[to+1]--;
	}
	t[now]++;
	if(now-m>=0)	t[now-m]++;
	if(now%m>0)		t[now-1]++;
	if(now+m<tot)	t[now+m]++;
	if(now%m<m-1)	t[now+1]++;
	dfs(now+1,cnt);
	t[now]--;
	if(now-m>=0)	t[now-m]--;
	if(now%m>0)		t[now-1]--;
	if(now+m<tot)	t[now+m]--;
	if(now%m<m-1)	t[now+1]--;
}
int main()
{
	scanf("%d%d",&n,&m);
	ans=tot=n*m;
	dfs(0,0);
	printf("%d",tot-ans);
	return 0;
}


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

int main ()
{
	int N, M;
	scanf("%d %d",&N,&M);
	if (N > M)
	{
		int y = N; N = M; M = y;
	}
	if (N == 1)
	{
		if (M == 1) printf("%d\n",0);
		else if (M == 2) printf("%d\n",1);
		else if (M == 3) printf("%d\n",2);
		else if (M == 4) printf("%d\n",2);
		else if (M == 5) printf("%d\n",3);
		else if (M == 6) printf("%d\n",4);
		else if (M == 7) printf("%d\n",4);
		else if (M == 8) printf("%d\n",5);
		else if (M == 9) printf("%d\n",6);
		else if (M == 10) printf("%d\n",6);
		else if (M == 11) printf("%d\n",7);
		else if (M == 12) printf("%d\n",8);
		else if (M == 13) printf("%d\n",8);
		else if (M == 14) printf("%d\n",9);
		else if (M == 15) printf("%d\n",10);
		else if (M == 16) printf("%d\n",10);
		else if (M == 17) printf("%d\n",11);
		else if (M == 18) printf("%d\n",12);
		else if (M == 19) printf("%d\n",12);
		else if (M == 20) printf("%d\n",13);
		else if (M == 21) printf("%d\n",14);
		else if (M == 22) printf("%d\n",14);
		else if (M == 23) printf("%d\n",15);
		else if (M == 24) printf("%d\n",16);
		else if (M == 25) printf("%d\n",16);
		else if (M == 26) printf("%d\n",17);
		else if (M == 27) printf("%d\n",18);
		else if (M == 28) printf("%d\n",18);
		else if (M == 29) printf("%d\n",19);
		else if (M == 30) printf("%d\n",20);
		else if (M == 31) printf("%d\n",20);
		else if (M == 32) printf("%d\n",21);
		else if (M == 33) printf("%d\n",22);
		else if (M == 34) printf("%d\n",22);
		else if (M == 35) printf("%d\n",23);
		else if (M == 36) printf("%d\n",24);
		else if (M == 37) printf("%d\n",24);
		else if (M == 38) printf("%d\n",25);
		else if (M == 39) printf("%d\n",26);
		else printf("%d\n",26);
	}
	else if (N == 2)
	{
		if (M == 2) printf("%d\n",2);
		else if (M == 3) printf("%d\n",4);
		else if (M == 4) printf("%d\n",5);
		else if (M == 5) printf("%d\n",7);
		else if (M == 6) printf("%d\n",8);
		else if (M == 7) printf("%d\n",10);
		else if (M == 8) printf("%d\n",11);
		else if (M == 9) printf("%d\n",13);
		else if (M == 10) printf("%d\n",14);
		else if (M == 11) printf("%d\n",16);
		else if (M == 12) printf("%d\n",17);
		else if (M == 13) printf("%d\n",19);
		else if (M == 14) printf("%d\n",20);
		else if (M == 15) printf("%d\n",22);
		else if (M == 16) printf("%d\n",23);
		else if (M == 17) printf("%d\n",25);
		else if (M == 18) printf("%d\n",26);
		else if (M == 19) printf("%d\n",28);
		else printf("%d\n",29);
	}
	else if (N == 3)
	{
		if (M == 3) printf("%d\n",6);
		else if (M == 4) printf("%d\n",8);
		else if (M == 5) printf("%d\n",11);
		else if (M == 6) printf("%d\n",13);
		else if (M == 7) printf("%d\n",15);
		else if (M == 8) printf("%d\n",17);
		else if (M == 9) printf("%d\n",20);
		else if (M == 10) printf("%d\n",22);
		else if (M == 11) printf("%d\n",24);
		else if (M == 12) printf("%d\n",26);
		else printf("%d\n",29);
	}
	else if (N == 4)
	{
		if (M == 4) printf("%d\n",12);
		else if (M == 5) printf("%d\n",14);
		else if (M == 6) printf("%d\n",17);
		else if (M == 7) printf("%d\n",21);
		else if (M == 8) printf("%d\n",24);
		else if (M == 9) printf("%d\n",26);
		else printf("%d\n",30);
	}
	else if (N == 5)
	{
		if (M == 5) printf("%d\n",18);
		else if (M == 6) printf("%d\n",22);
		else if (M == 7) printf("%d\n",26);
		else printf("%d\n",29);
	}
	else printf("%d\n",26);
	return 0;
}