#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d %d",&n,&k);
	char s[n+1];
	scanf("%s",s);
	int count=0;
	int a[26],b[26];
	for(int i=0;i<26;i=i+1){
		a[i]=10000000;
		b[i]=10000000;
	}
	for(int i=0;i<n;i=i+1){
		if(a[s[i]-65]==10000000){
			a[s[i]-65]=i;
			count+=1;
		}else{
			b[s[i]-65]=i;
		}
	}
	qsort(a,26,sizeof(int),cmpfunc);
	qsort(b,26,sizeof(int),cmpfunc);
	int count1=0;
	int temp=0;
	for(int i=0;i<count,temp<count;i=i+1){
		while(a[i]<b[temp]){
			count1+=1;
			i+=1;
		}
		i=i-1;
		//printf("%d\n",count1);
		if(temp<count-1){
			temp+=1;
		}
		if(count1>k){
			printf("YES\n");
			return 0;
		}
		count1-=1;
	}
	printf("NO\n");
	return 0;
}


#include <stdio.h>
#define mod 1000000007
#define N 100000
int main(){
    long long int n,k;
    scanf("%lld %lld",&n,&k); getchar();
    char s[n+1];int a[26]={0},g[26]={0};
    gets(s);
    long long int i;
    for(i=0;i<strlen(s);i++){
        a[s[i]-'A']++;
    }
    for(i=0;i<strlen(s);i++){
       if( g[s[i]-'A']==0){
        g[s[i]-'A']=1;k--;
       }
       if(k==-1){
        printf("YES"); return 0;
       }
       a[s[i]-'A']--;
       if(a[s[i]-'A']==0){
        k++;
       }

    }

    printf("NO");

return 0;
}


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

int main(){
    int n, k, c_time[26], i, flag[26], unguarded, count;
    char s[1000005];
    memset(flag, 0, sizeof(flag));
    memset(c_time, 0, sizeof(c_time));
    scanf("%d %d\n%s", &n, &k, s);
    if(k == 26){
        printf("YES\n");
    } else {
        for (i = 0; i < n; i++){
            if (i > c_time[s[i] - 'A']){
                c_time[s[i] - 'A'] = i;
            }
        }
        for (i = unguarded = count = 0; i < n && !unguarded; i++){
            if (!flag[s[i] - 'A']){
                count++;
                flag[s[i] - 'A'] = 1;
            }
            unguarded = (count > k);
            count = (c_time[s[i] - 'A'] == i) ? count - 1 : count;
        }
        printf("%s\n", unguarded ? "YES" : "NO");
    }
    return 0;
}


#include<stdio.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-11

int sign(double a){if(a>EPS) return 1; if(a<-EPS) return -1; return 0;}
int ab(int a){if(a<0)return -a; return a;}
int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}

int main(){
  int a,b,A,B,k;
  double c, C;

  scanf("%d%d%lf%d%d%lf",&a,&b,&c,&A,&B,&C);
  if(a<0 || (!a&&b<0)) a=-a, b=-b, c=-c;
  if(A<0 || (!A&&B<0)) A=-A, B=-B, C=-C;
  if(a||b) k=GCD(a,ab(b)), a/=k, b/=k, c/=k;
  if(A||B) k=GCD(A,ab(B)), A/=k, B/=k, C/=k;

  if( (!a&&!b&&sign(c) || (!A&&!B&&sign(C))) ) puts("0");
  else if( (!a&&!b&&!sign(c)) || (!A&&!B&&!sign(C)) )puts("-1");
  else if(a==A && b==B && sign(c-C)==0 ) puts("-1");
  else if(a==A && b==B) puts("0");
  else puts("1");

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
volatile int Que[32];
int sea(int l);
int main(){
    int n,m,s,k,l,nx,ny,c=(int)'a';
    char x,y;
    volatile int Donde[30][200001];
    volatile char cad[200001];
    volatile char *abc="abcdefghijklmnopqrstuvwxyz";
    for(s=0;s<30;s++){
        Que[s]=s;
    }
    memset(Donde,-1,sizeof(Donde));
    scanf("%d %d",&n,&m);
    scanf("%s",cad);
    for(s=0;cad[s]!='\0';s++){
        k=(int)cad[s] - c;
        Donde[k][0]++;
        Donde[k][Donde[k][0]+1]=s;
    }
    l=s;
    for(s=0;s<m;s++){
        scanf("%d",&k);
        scanf("%c %c",&x,&y);
        nx=sea((int)x - c);
        ny=sea((int)y - c);
        if(nx-ny){
            Que[31]=Que[nx];
            Que[nx]=Que[ny];
            Que[ny]=Que[31];
        }
    }
    for(s=0;s<30;s++){
        for( ;~Donde[s][0];Donde[s][0]--){
            cad[Donde[s][Donde[s][0]+1]]=abc[Que[s]];
        }
    }

    printf("%s",cad);
}
int sea(int l){
    int r=0;
    while(Que[r]!=l){
        r++;
    }
    return r;
}


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

#define ll long long
#define M 2520

int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}
int LCM(int a,int b){ return a/GCD(a,b)*b; }

ll *dp1, *dp2, *nx1, *nx2, *swap;
ll dp1__[M], dp2__[M];
ll nx1__[M], nx2__[M];

ll dp[1025][M];
int bc[1500];

int nex[M][12];

ll solve(ll mx){
  int i,j,k,mask,use[10],us,now,nn;
  int go[20],gos,g;
  ll res;

  dp1=dp1__; dp2=dp2__; nx1=nx1__; nx2=nx2__;

  gos=0;
  while(mx) go[gos++]=mx%10, mx/=10;

  rep(mask,1<<8){
    us=2; use[0]=0; use[1]=1;
    rep(i,8) if(mask&1<<i) use[us++]=i+2;

    rep(i,M) dp1[i]=dp2[i]=0;
    dp1[0]=1;

    rep(i,M) rep(j,us) nex[i][j] = (i*10+use[j])%M;

    for(now=gos-1;now>=0;now--){
      rep(i,M) nx1[i]=nx2[i]=0;

      rep(i,M) if(dp2[i]) rep(k,us) nx2[nex[i][k]] += dp2[i];

      rep(i,M) if(dp1[i]) rep(k,us){
        if(go[now]==use[k]) nx1[nex[i][k]] += dp1[i];
        if(go[now]> use[k]) nx2[nex[i][k]] += dp1[i];
      }

      swap=dp1, dp1=nx1, nx1=swap;
      swap=dp2, dp2=nx2, nx2=swap;
    }

    rep(i,M) dp[mask][i] = dp1[i] + dp2[i];
  }

  res = 0;
  rep(mask,1<<8){
    g=1;
    rep(i,8) if(mask&1<<i) g=LCM(g,i+2);

    rep(i,mask+1) if( (i&mask)==i ){
      for(j=g;j<M;j+=g){
        if( (bc[mask] - bc[i])%2 ) res -= dp[i][j];
        else                       res += dp[i][j];
      }
    }
  }

  return res;
}

int main(){
  int i,j,k,l,n;
  ll a, b, res;
  int size;

  bc[0]=0;
  REP(i,1,1<<10) bc[i] = bc[i&(i-1)]+1;

  scanf("%d",&size);
  while(size--){
    scanf("%I64d%I64d",&a,&b);
    res = solve(b) - solve(a-1);
    printf("%I64d\n",res);
  }

  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 2520
int a[30],index[MOD+10];
__int64 dps[23][2550][50];

void init(){
    int i,k=1;
    for(i=1;i<=MOD;i++){
        if(MOD%i==0)
            index[i]=k++;
    }
    k--;
}
int gcd(int a , int b)
{
    return b == 0 ? a : gcd(b , a % b);
}

int lcm(int a, int b)
{
    return a / gcd(a,b) * b;
}
__int64 dp(int pos,int sum,int mod,int doing){
    int i,tem,max,nowsum,nowmod;
    __int64 result=0;
    if(pos==0){
        return sum%mod==0;
    }
    if(doing==0 && dps[pos][sum][index[mod]]!=-1)
        return dps[pos][sum][index[mod]];

    if(doing)
        max=a[pos];
    else
        max=9;

    for(i=0;i<=max;i++){
        nowsum=0;
        nowsum=(sum*10+i)%MOD;
        nowmod=0;
        nowmod=mod;
        if(i)
            nowmod=lcm(mod,i);
        if(doing && i==max){
            result+=dp(pos-1,nowsum,nowmod,1);
        }
        else{
            result+=dp(pos-1,nowsum,nowmod,0);
        }

    }
    if(!doing){
        dps[pos][sum][index[mod]]=result;
    }
    return result;
}
__int64 cal(__int64 num){
    __int64 tem;
    int i;
    tem=num;
    i=1;
    while(tem){
        a[i++]=tem%10;
        tem/=10;
    }
    return dp(i-1,0,1,1);
}
int main()
{
    int t,T;
    __int64 l,r,i,j,k;
    scanf("%d",&T);
    init();
    for(t=1;t<=T;t++){
        //memset(dps,-1,sizeof(dps));//这里错了
        scanf("%I64d %I64d",&l,&r);
        printf("%I64d\n",cal(r)-cal(l-1));
    }
    return 0;

}


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

#define ll long long
#define M 2520

int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}
int LCM(int a,int b){ return a/GCD(a,b)*b; }

ll *dp1, *dp2, *nx1, *nx2, *swap;
ll dp1__[M], dp2__[M];
ll nx1__[M], nx2__[M];

ll dp[525][M];
int bc[1500];

int nex[M][10];

ll solve(ll mx){
  int i,j,k,mask,use[10],us,now,nn;
  int go[20],gos,g;
  ll res;

  dp1=dp1__; dp2=dp2__; nx1=nx1__; nx2=nx2__;

  gos=0;
  while(mx) go[gos++]=mx%10, mx/=10;

  rep(mask,1<<8){
    us=2; use[0]=0; use[1]=1;
    rep(i,8) if(mask&1<<i) use[us++]=i+2;

    rep(i,M) dp1[i]=dp2[i]=0;
    dp1[0]=1;

    rep(i,M) rep(j,us) nex[i][j] = (i*10+use[j])%M;

    for(now=gos-1;now>=0;now--){
      rep(i,M) nx1[i]=nx2[i]=0;

      rep(i,M) if(dp2[i]) rep(k,us) nx2[nex[i][k]] += dp2[i];

      rep(i,M) if(dp1[i]) rep(k,us){
        if(go[now]==use[k]) nx1[nex[i][k]] += dp1[i];
        if(go[now]> use[k]) nx2[nex[i][k]] += dp1[i];
      }

      swap=dp1, dp1=nx1, nx1=swap;
      swap=dp2, dp2=nx2, nx2=swap;
    }

    rep(i,M) dp[mask][i] = dp1[i] + dp2[i];
  }

  res = 0;
  rep(mask,1<<8){
    g=1;
    rep(i,8) if(mask&1<<i) g=LCM(g,i+2);

    rep(i,mask+1) if( (i&mask)==i ){
      for(j=g;j<(1<<8);j+=g){
        if( (bc[mask] - bc[i])%2 ) res -= dp[i][j];
        else                       res += dp[i][j];
      }
    }
  }

  return res;
}

int main(){
  int i,j,k,l,n;
  ll a, b, res;
  int size;

  bc[0]=0;
  REP(i,1,1<<10) bc[i] = bc[i&(i-1)]+1;

  scanf("%d",&size);
  while(size--){
    scanf("%I64d%I64d",&a,&b);
    res = solve(b) - solve(a-1);
    printf("%I64d\n",res);
  }

  return 0;
}


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

#define ll long long
#define M 2520

int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}
int LCM(int a,int b){ return a/GCD(a,b)*b; }

ll *dp1, *dp2, *nx1, *nx2, *swap;
ll dp1__[M], dp2__[M];
ll nx1__[M], nx2__[M];

ll dp[323][M];
int bc[323];

int nex[M][10];

ll solve(ll mx){
  int i,j,k,mask,use[10],us,now,nn;
  int go[20],gos,g;
  ll res;

  dp1=dp1__; dp2=dp2__; nx1=nx1__; nx2=nx2__;

  gos=0;
  while(mx) go[gos++]=mx%10, mx/=10;

  rep(mask,1<<8){
    if( (mask&1<<2) && !(mask&1<<0) ) continue;
    if( (mask&1<<4) && (!(mask&1<<0)||!(mask&1<<1)) ) continue;
    if( (mask&1<<6) && (!(mask&1<<0)||!(mask&1<<2)) ) continue;
    if( (mask&1<<7) && (mask&1<<1) ) continue;
    us=2; use[0]=0; use[1]=1;
    rep(i,8) if(mask&1<<i) use[us++]=i+2;

    rep(i,M) dp1[i]=dp2[i]=0;
    dp1[0]=1;

    rep(i,M) rep(j,us) nex[i][j] = (i*10+use[j])%M;

    for(now=gos-1;now>=0;now--){
      rep(i,M) nx1[i]=nx2[i]=0;

      rep(i,M) if(dp2[i]) rep(k,us) nx2[nex[i][k]] += dp2[i];

      rep(i,M) if(dp1[i]) rep(k,us){
        if(go[now]==use[k]) nx1[nex[i][k]] += dp1[i];
        if(go[now]> use[k]) nx2[nex[i][k]] += dp1[i];
      }

      swap=dp1, dp1=nx1, nx1=swap;
      swap=dp2, dp2=nx2, nx2=swap;
    }

    rep(i,M) dp[mask][i] = dp1[i] + dp2[i];
  }

  res = 0;
  rep(mask,1<<8){
    g=1;
    rep(i,8) if(mask&1<<i) g=LCM(g,i+2);

    rep(i,mask+1) if( (i&mask)==i ){
      for(j=0;j<M;j+=g){
        if( (bc[mask] - bc[i])%2 ) res -= dp[i][j];
        else                       res += dp[i][j];
      }
    }
  }

  return res;
}

int main(){
  int i,j,k,l,n;
  ll a, b, res;
  int size;

  bc[0]=0;
  REP(i,1,1<<8) bc[i] = bc[i&(i-1)]+1;

  scanf("%d",&size);
  while(size--){
    scanf("%I64d%I64d",&a,&b);
    res = solve(b) - solve(a-1);
    printf("%I64d\n",res);
  }

  return 0;
}


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

#define maxim 100
#define LLD long long int
#define LLU long long unsigned
//#define llu I64u

#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)

char a[20];
char b[20];

LLU dp[20][2520][256+5][4];
char isV[20][2520][256+5][4] = {{{{0}}}};
LLU M = 2520;

LLU cal(int i, int mod, int Bit, int s)
{
    int j;

    if(i == 20)
    {
        rep(j,2,10)
        {
            if( ( Bit & (1<<(j-2)) ) && mod%j )   return 0;
        }
        return 1;
    }

    if(isV[i][mod][Bit][s])  return dp[i][mod][Bit][s];

    LLU ret = 0;
    int nmod;
    if(s == 0)
    {
        rep(j,0,10)
        {
            nmod = ( mod*10 + j ) % M;
            ret += cal( i+1, nmod, Bit|1<<(j-2), 0 );
        }
    }
    else if(s == 1)
    {
        j = a[i]-'0';
        nmod = ( mod*10 + j ) % M;
        ret += cal( i+1, nmod, Bit|1<<(j-2), 1 );

        rep(j,a[i]-'0'+1,10)
        {
            nmod = ( mod*10 + j ) % M;
            ret += cal( i+1, nmod, Bit|1<<(j-2), 0 );
        }
    }
    else if(s == 2)
    {
        rep(j,0,b[i]-'0')
        {
            nmod = ( mod*10 + j ) % M;
            ret += cal( i+1, nmod, Bit|1<<(j-2), 0 );
        }
        nmod = ( mod*10 + j ) % M;
        ret += cal( i+1, nmod, Bit|1<<(j-2), 2 );
    }
    else
    {
        if(a[i]-'0' == b[i]-'0')
        {
            j = a[i]-'0';
            nmod = ( mod*10 + j ) % M;
            ret += cal( i+1, nmod, Bit|1<<(j-2), 3 );
        }

        else
        {
            j = a[i]-'0';

            nmod = ( mod*10 + j ) % M;
            ret += cal( i+1, nmod, Bit|1<<(j-2), 1 );

            rep(j,a[i]-'0'+1,b[i]-'0')
            {
                nmod = ( mod*10 + j ) % M;
                ret += cal( i+1, nmod, Bit|1<<(j-2), 0 );
            }

            nmod = ( mod*10 + j ) % M;
            ret += cal( i+1, nmod, Bit|1<<(j-2), 2 );
        }
    }

    isV[i][mod][Bit][s] = 1;
    return dp[i][mod][Bit][s] = ret;
}

int main()
{
    int T,t=1,m,i,j,k;
    LLU l,r;
    scanf("%d",&T);
    for(t=1;t<=T;t++)
    {
        scanf("%I64u%I64u",&l,&r);

        sprintf(a,"%020I64u",l);
        sprintf(b,"%020I64u",r);

        rep(i,0,20)
            rep(j,0,2520)
                rep(k,0,261)
                    rep(m,1,4)
                        isV[i][j][k][m] = 0;

        printf("%I64u\n",cal(0,0,0,3));
    }
    return 0;
}


#include <stdio.h>
#define ulli unsigned long long int

ulli factorial(int n){
  if(n==1) return 1;
  else return factorial(n-1)*n;
}

int main(){
  int n;
  scanf("%d", &n);
  int k = n/2;
  ulli ans;
  ans = factorial(n) / factorial(n-k);
  ans = ans * factorial(k-1)/(2*k);
  printf("%lld\n",ans);
  return 0;
}


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

long long int factorial(long long int n) ;

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

    while(t--)
    {
        int n, power;
        long long int sum;
        scanf("%d", &n);
        power = (factorial((n/2)-1) * factorial((n/2)-1));
        sum = ((factorial(n)/((factorial(n/2)) * factorial(n/2))/2) * power) ;

        printf("%d", sum);
    }
}

long long int factorial(long long int n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}


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

long long int factorial(long long int n) ;

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

    while(t--)
    {
        int n;
        long long int sum, power;
        scanf("%d", &n);
        power = (factorial((n/2)-1) * factorial((n/2)-1));
        sum = ((factorial(n)/((factorial(n/2)) * factorial(n/2))/2) * power) ;

        printf("%lld", sum);
    }

    return 0;
}

long long int factorial(long long int n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}


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

long long int factorial(long long int n) ;

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

    while(t--)
    {
        int n;
        long long int sum, power;
        scanf("%d", &n);
        power = (factorial((n/2)-1) * factorial((n/2)-1));
        sum = ((factorial(n)/((factorial(n/2)) * factorial(n/2))/2) * power) ;

        printf("%lld", sum);
    }
}

long long int factorial(long long int n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}


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

 long long int factorial( long long int n) ;

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

    while(t--)
    {
        long long int n, power;
        long long int sum;
        scanf("%lld", &n);
        power = pow(factorial((n/2)-1),2);
        sum = ((factorial(n)/((factorial(n/2)) * factorial(n/2))/2) * power) ;

        printf("%lld", sum);
    }
}

 long long int factorial( long long int n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}


#include <stdio.h>
typedef long long ll;
ll a[15], w, ans;

void dfs(int x, ll y) {
	if (x > 8) {
		if (y > ans) ans = y;
		return;
	}
	ll k = a[x];
	ll tmp = (w - y) / x;
	if (k > tmp) k = tmp;
	ll i = k - 3;
	if (i < 0) i = 0;
	for (; i <= k; i++) dfs(x + 1, y + i * x);
}

int main() {
	scanf("%I64d", &w);
	ans = 0;
	for (int i = 1; i <= 8; i++) scanf("%I64d", &a[i]);
	dfs(1, 0);
	printf("%I64d", ans);
	return 0;
}


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

#define K	8
#define L	840

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

int main() {
	static long long aa[K + 1], dp[L * K], dq[L * K];
	long long w, ans, a, p;
	int i, y, y_, q, q_;

	scanf("%lld", &w);
	for (i = 1; i <= K; i++)
		scanf("%lld", &aa[i]);
	memset(dp, -1, L * K * sizeof *dp);
	dp[0] = 0;
	for (i = 1; i <= K; i++) {
		a = aa[i];
		for (y = 0; y < L * K; y++)
			dq[y] = -1;
		for (y = 0; y < L * K; y++) {
			if (dp[y] < 0)
				continue;
			q_ = L / i;
			for (q = 0; q < q_ && q <= a; q++) {
				p = (a - q) / q_;
				y_ = y + q * i;
				dq[y_] = max(dq[y_], dp[y] + p);
			}
		}
		for (y = 0; y < L * K; y++)
			dp[y] = dq[y];
	}
	ans = 0;
	for (y = 0; y < L * K && y <= w; y++)
		ans = max(ans, min((w - y) / L, dp[y]) * L + y);
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>
long long int cnt[8];
long long int Maximum_Weight(long long int amount,int n)
{
    long long int iterations=n-1,maximum_weight=0,current_weight=0,used=amount/n,weight_using_it,i;
    if(used>cnt[n-1]) used=cnt[n-1];
    if(used+1<iterations) iterations=used+1;
    weight_using_it=used*n;
    current_weight=maximum_weight=weight_using_it;
    for(i=0;i<iterations;i++)
    {
        current_weight=weight_using_it-i*n+Maximum_Weight(amount-(weight_using_it-i*n),n-1);
        if(maximum_weight<current_weight) maximum_weight=current_weight;
    }
    return maximum_weight;
}
int main()
{
    long long int W,max_weight=0;
    int i;
    scanf("%I64d",&W);
    for(i=0;i<8;i++)
    {
        scanf("%I64d",&cnt[i]);
    }
    max_weight=Maximum_Weight(W,8);
    printf("%I64d",max_weight);
    return 0;
}


#include <stdio.h>

long long int arr[15], w, ans;

void dp(int x, long long int y)
{
	if (x > 8)
	{
		if (y > ans)
		{
			ans = y;
		}
		return;
	}
	long long int k = arr[x];
	long long int temp = (w-y) / x;
	if (k > temp)
	{
		k = temp;
	}
	long long int i = k - 6;
	if (i < 0)
	{
		i = 0;
	}
	while(i <= k)
	{
		dp(x + 1, y + i * x);
		i++;
	}

}

int main()
{
	scanf("%lld", &w);
	ans = 0;
	for (int i = 1; i <= 8; i++)
	{
		scanf("%lld", &arr[i]);
	}
	dp(1, 0);
	printf("%lld", ans);
	return 0;
}


#include <iostream>

#include<vector>

#include<algorithm>

#include<queue>

#include<string>

using namespace std;

typedef long long ll;

ll a[15], w, ans;

void dfs(int x, ll y)

{

	if (x>8) {

		ans = max(ans, y);

		return;

	}

	ll k = min(a[x], (w - y) / x);

	for(ll i=max(0ll,k-3);i<=k;i++) dfs(x+1,y+i*x);

}

int main()

{

	while (cin >> w)

	{

		ans = 0;

		for (int i = 1; i <= 8; i++) cin >> a[i];

		dfs(1, 0);

		cout << ans << endl;

	}

	return 0;

}


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

#define MDI 1000000009
#define MOD(a) ((a) % MDI)
#define MOO(a) ((a) > 0 ? (a) % MDI : MDI + (a))
#define LL long long

void putlld(LL a)
{
  if(a > 9)
    putlld(a / 10);
  putchar(a % 10 + '0');
}

int nn[499999];

int main(void)
{
  int i, n;
  LL h = 0, g, t;
  scanf("%d", &n);
  t = (n >> 1) - 1;
  for(i = 0, nn[0] = 4; i < t - 1; i++)
    nn[i + 1] = MOD(nn[i] << 1);
  for(i = t - 1; i >= 0; i--){
    g = nn[i] - 3;
    h = MOD((h + 4) * g);
  }
  h = MOD(((h * h + (h << 2)) << 1) + 10);
  putlld(h);
  putchar('\n');
  return 0;
}


#include <stdio.h>

#define MD	1000000009

int main() {
	int n, l, ans, cnt, x, y, z;

	scanf("%d", &n), n /= 2;
	cnt = 2, x = 1, y = 1, z = 2;
	for (l = 2; l <= n; l++) {
		cnt = (cnt + x * 4LL) % MD;
		z = z * 2 % MD;
		y = (y + z) % MD;
		x = (long long) x * y % MD;
	}
	ans = ((long long) cnt * cnt + 1) * 2 % MD;
	printf("%d\n", ans);
	return 0;
}


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

#define MDI 1000000009
#define MOD(a) ((a) % MDI)
typedef long long LL;
enum {U, L, T, I, W};

int unt[][W + 1] = {
  {5, 2, 0, 0, 1},
  {4, 4, 1, 1, 0},
  {4, 2, 0, 0, 0},
  {4, 0, 0, 0, 0}
};

void putlld(LL a)
{
  if(a > 9)
    putlld(a / 10);
  putchar((a % 10) + '0');
}

int main(void)
{
  int i, j, k;
  LL h = 0, g, n, f, t;
  scanf("%d", &n);
  n /= 2;
  t = n - 2;
  for(i = 0; i < t; i++){
    f = t - i;
    g = MOD(MOD(2 << (f + 1) - 1) << 2);
    h = MOD(4 + h + MOD(g << 2) + MOD(h * g));
  }
  if(n > 1)
    h = MOD(4 + h);
  h = MOD(MOD(MOD(h * h) + 5 + MOD(h << 2) << 1));
  putlld(h);
  putchar('\n');
  return 0;
}

#undef WERTYUIOPASDFGHJKLZXCVBN
#ifdef WERTYUIOPASDFGHJKLZXCVBN
/*
 * it starts and ends in the same place — the granny's house;
 * the route goes along the forest paths only (these are the segments marked black in the picture);
 * the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway);
 * the route cannot cross itself;
 * there shouldn't be any part of dense forest within the part marked out by this route;
 I:
 2
 O:
 10
 I:
 4
 O:
 74
 */
#endif


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

#define MDI 1000000009
#define MOD(a) ((a) % MDI)
typedef long long LL;

void putlld(LL a)
{
  if(a > 9)
    putlld(a / 10);
  putchar((a % 10) + '0');
}

int main(void)
{
  int i, j, k;
  LL h = 0, g, n, f, t;
  scanf("%d", &n);
  n /= 2;
  t = n - 2;
  for(i = 0; i < t; i++){
    f = t - i;
    g = MOD(MOD(2 << (f + 1) - 1) << 2);
    h = MOD(4 + h + MOD(g << 2) + MOD(h * g));
  }
  if(n > 1)
    h = MOD(4 + h);
  h = MOD(MOD(MOD(h * h) + 5 + MOD(h << 2) << 1));
  putlld(h);
  putchar('\n');
  return 0;
}

#undef WERTYUIOPASDFGHJKLZXCVBN
#ifdef WERTYUIOPASDFGHJKLZXCVBN
/*
 * it starts and ends in the same place — the granny's house;
 * the route goes along the forest paths only (these are the segments marked black in the picture);
 * the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway);
 * the route cannot cross itself;
 * there shouldn't be any part of dense forest within the part marked out by this route;
 I:
 2
 O:
 10
 I:
 4
 O:
 74
 */
#endif


#include <stdio.h>

#define MD	1000000009

int main() {
	int n, l, ans, cnt, x, y, z;

	scanf("%d", &n), n /= 2;
	cnt = 2, x = 1, y = 1, z = 2;
	for (l = 2; l <= n; l++) {
		cnt = (cnt + x * 4LL) % MD;
		z = z * 2 % MD;
		y = (y + z) % MD;
		x = (x + y) % MD;
	}
	ans = ((long long) cnt * cnt + 1) * 2 % MD;
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>

const unsigned char N = (unsigned char) 10;

unsigned char n;
int x;
unsigned char mat[N][N];

inline unsigned char smin(const unsigned char& a, const unsigned char& b) { return a < b ? a : b; }
inline unsigned char smax(const unsigned char& a, const unsigned char& b) { return a > b ? a : b; }

inline unsigned char FOR3(const unsigned char& k, const unsigned char& i, const unsigned char& j) {
    mat[i][j] = smin(mat[i][j], mat[i][k] + mat[k][j]);
    return j + 1 < n ? FOR3(k, i, j + 1) : 0;
}

inline unsigned char FOR2(const unsigned char& i, const unsigned char& j) {
    FOR3(i, j, 0);
    return j + 1 < n ? FOR2(i, j + 1) : 0;
}

inline unsigned char FOR1(const unsigned char& i) {
    FOR2(i, 0);
    return i + 1 < n ? FOR1(i + 1) : 0;
}

inline unsigned char FOR_INPUT2(const unsigned char& i, const unsigned char& j) {
    scanf("%d", &x);
    mat[i][j] = x;
    return j + 1 < n ? FOR_INPUT2(i, j + 1) : 0;
}

inline unsigned char FOR_INPUT1(const unsigned char& i) {
    FOR_INPUT2(i, 0);
    return i + 1 < n ? FOR_INPUT1(i + 1) : 0;
}

inline unsigned char BILLY2(const unsigned char& i, const unsigned char& j) {
    return smax(mat[i][j], j + 1 < n ? BILLY2(i, j + 1) : 0);
}

inline unsigned char BILLY1(const unsigned char& i) {
    unsigned char ans = BILLY2(i, 0);
    unsigned char other = i + 1 < n ? BILLY1(i + 1) : 0;
    return smax(ans, other);
}

inline void solve() {
    scanf("%d", &x); n = x;
    FOR_INPUT1(0);
    FOR1(0);
    printf("%d\n", BILLY1(0));
}

int main() {
    solve();
    return 0;
}


#include <stdio.h>

using namespace std;

const unsigned char N = (unsigned char) 10;

unsigned char n;
int x;
unsigned char mat[10][10];

inline unsigned char smin(const unsigned char a, const unsigned char b) { return a < b ? a : b; }
inline unsigned char smax(const unsigned char a, const unsigned char b) { return a > b ? a : b; }

inline unsigned char FOR3(const unsigned char k, const unsigned char i, const unsigned char j)  {
    mat[i][j] = smin(mat[i][j], mat[i][k] + mat[k][j]);
    return j + 1 < n ? FOR3(k, i, j + 1) : 0;
}

inline unsigned char FOR2(const unsigned char i, const unsigned char j) {
    FOR3(i, j, 0);
    return j + 1 < n ? FOR2(i, j + 1) : 0;
}

inline unsigned char FOR1(const unsigned char i) {
    FOR2(i, 0);
    return i + 1 < n ? FOR1(i + 1) : 0;
}

inline unsigned char FOR4(const unsigned char k, const unsigned char i, const unsigned char j)  {
    mat[i][j] = smin(mat[i][j], mat[i][k] + mat[k][j]);
    return j + 1 < n ? FOR4(k, i, j + 1) :
                i + 1 < n ? FOR4(k, i + 1, 0) :
                k + 1 < n ? FOR4(k + 1, 0, 0) : 0;
}

inline unsigned char FOR_INPUT2(const unsigned char i, const unsigned char j) {
    scanf("%d", &x);
    mat[i][j] = x;
    return j + 1 < n ? FOR_INPUT2(i, j + 1) : 0;
}

inline unsigned char FOR_INPUT1(const unsigned char i) {
    FOR_INPUT2(i, 0);
    return i + 1 < n ? FOR_INPUT1(i + 1) : 0;
}

inline unsigned char BILLY2(const unsigned char i, const unsigned char j) {
    return smax(mat[i][j], j + 1 < n ? BILLY2(i, j + 1) : 0);
}

inline unsigned char BILLY1(const unsigned char i) {
    unsigned char ans = BILLY2(i, 0);
    unsigned char other = i + 1 < n ? BILLY1(i + 1) : 0;
    return smax(ans, other);
}

inline void solve() {
    scanf("%d", &x); n = x;
    FOR_INPUT1(0);
    // FOR1(0);
    FOR4(0, 0, 0);
    printf("%d\n", BILLY1(0));
}

int main() {
    solve();
    return 0;
}


#include <stdio.h>

const unsigned char N = (unsigned char) 10;

unsigned char n;
int x;
unsigned char mat[N][N];

inline unsigned char smin(const unsigned char a, const unsigned char b) { return a < b ? a : b; }
inline unsigned char smax(const unsigned char a, const unsigned char b) { return a > b ? a : b; }

inline unsigned char FOR3(const unsigned char k, const unsigned char i, const unsigned char j) {
    mat[i][j] = smin(mat[i][j], mat[i][k] + mat[k][j]);
    return j + 1 < n ? FOR3(k, i, j + 1) : 0;
}

inline unsigned char FOR2(const unsigned char i, const unsigned char j) {
    FOR3(i, j, 0);
    return j + 1 < n ? FOR2(i, j + 1) : 0;
}

inline unsigned char FOR1(const unsigned char i) {
    FOR2(i, 0);
    return i + 1 < n ? FOR1(i + 1) : 0;
}

inline unsigned char FOR_INPUT2(const unsigned char i, const unsigned char j) {
    scanf("%d", &x);
    mat[i][j] = x;
    return j + 1 < n ? FOR_INPUT2(i, j + 1) : 0;
}

inline unsigned char FOR_INPUT1(const unsigned char i) {
    FOR_INPUT2(i, 0);
    return i + 1 < n ? FOR_INPUT1(i + 1) : 0;
}

inline unsigned char BILLY2(const unsigned char i, const unsigned char j) {
    return smax(mat[i][j], j + 1 < n ? BILLY2(i, j + 1) : 0);
}

inline unsigned char BILLY1(const unsigned char i) {
    unsigned char ans = BILLY2(i, 0);
    unsigned char other = i + 1 < n ? BILLY1(i + 1) : 0;
    return smax(ans, other);
}

inline void solve() {
    scanf("%d", &x); n = x;
    FOR_INPUT1(0);
    FOR1(0);
    printf("%d\n", BILLY1(0));
}

int main() {
    solve();
    return 0;
}


#include <stdio.h>

using namespace std;

const unsigned char N = (unsigned char) 10;

unsigned char n;
int x;
unsigned char mat[N][N];

inline unsigned char smin(const unsigned char& a, const unsigned char& b) { return a < b ? a : b; }
inline unsigned char smax(const unsigned char& a, const unsigned char& b) { return a > b ? a : b; }

inline unsigned char FOR3(const unsigned char& k, const unsigned char& i, const unsigned char& j) {
    mat[i][j] = smin(mat[i][j], mat[i][k] + mat[k][j]);
    return j + 1 < n ? FOR3(k, i, j + 1) : 0;
}

inline unsigned char FOR2(const unsigned char& i, const unsigned char& j) {
    FOR3(i, j, 0);
    return j + 1 < n ? FOR2(i, j + 1) : 0;
}

inline unsigned char FOR1(const unsigned char& i) {
    FOR2(i, 0);
    return i + 1 < n ? FOR1(i + 1) : 0;
}

inline unsigned char FOR_INPUT2(const unsigned char& i, const unsigned char& j) {
    scanf("%d", &x);
    mat[i][j] = x;
    return j + 1 < n ? FOR_INPUT2(i, j + 1) : 0;
}

inline unsigned char FOR_INPUT1(const unsigned char& i) {
    FOR_INPUT2(i, 0);
    return i + 1 < n ? FOR_INPUT1(i + 1) : 0;
}

inline unsigned char BILLY2(const unsigned char& i, const unsigned char& j) {
    return smax(mat[i][j], j + 1 < n ? BILLY2(i, j + 1) : 0);
}

inline unsigned char BILLY1(const unsigned char& i) {
    unsigned char ans = BILLY2(i, 0);
    unsigned char other = i + 1 < n ? BILLY1(i + 1) : 0;
    return smax(ans, other);
}

inline void solve() {
    scanf("%d", &x); n = x;
    FOR_INPUT1(0);
    FOR1(0);
    printf("%d\n", BILLY1(0));
}

int main() {
    solve();
    return 0;
}


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

Lint asal(Lint x){
	for(Lint i=2 ; i*i<=x ; i++)
		if(x%i==0)
			return 0;
	return 1;
}

int main()
{
	Lint x,y;
	cin >> N ;
	if(asal(N)){
		cout << 1 << '\n' << N << '\n';
		return 0;
	}

	N--;
	if(N%2==0) N--;

	for(Lint i=N ; ; i-=2)
		if(N-i>=4 && asal(i)){
			x=i;
			break;}

	y=N-x;

	for(Lint i=2 ; i<=N ; i++){
		if(y-i>=2 && asal(i) && asal(y-i)){
			printf("3\n%lld %lld %lld\n",x,i,y-i);
			return 0;
		}
	}

	return 0;
}


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

Lint asal(Lint x){
	for(Lint i=2 ; i*i<=x ; i++)
		if(x%i==0)
			return 0;
	return 1;
}

int main()
{
	Lint x,y;
	cin >> N ;
	if(asal(N)){
		cout << 1 << '\n' << N << '\n';
		return 0;
	}

	N--;
	if(N%2==0) N--;

	for(Lint i=N ; ; i-=2)
		if(N-i>=6 && asal(i)){
			x=i;
			break;}

	y=N-x;

	for(Lint i=3 ; i<=N ; i++){
		if(y-i>=3 && asal(i) && asal(y-i)){
			printf("3\n%lld %lld %lld\n",x,i,y-i);
			return 0;
		}
	}

	return 0;
}


#include <stdio.h>
using namespace std;
typedef long long int Lint;
Lint N;

Lint asal(Lint x){
	for(Lint i=2 ; i*i<=x ; i++)
		if(x%i==0)
			return 0;
	return 1;
}

int main()
{
	Lint x,y;
	scanf("%lld",&N);
	if(asal(N)){
		printf("1\n%lld\n",N);
		return 0;
	}

	N--;
	if(N%2==0) N--;

	for(Lint i=N ; ; i-=2)
		if(N-i>=4 && asal(i)){
			x=i;
			break;}

	y=N-x;

	for(Lint i=2 ; i<=N ; i++){
		if(y-i>=2 && asal(i) && asal(y-i)){
			printf("3\n%lld %lld %lld\n",x,i,y-i);
			return 0;
		}
	}

	return 0;
}


#include<stdio.h>
#define N 1000000
#define M 100000
int main() {
    int n;
    scanf("%d",&n);
    int p[N];
    int i,j;
    for(i=2; i<N; i++) {
        p[i]=1;
    }
    for(i=2; i*i<N; i++) {
        if(p[i]) {//这里节省了一些查找！
            for(j=i; i*j<N; j++) {//j=i也节省了一些查找！
                p[i*j]=0;
            }
        }
    }
    p[0]=0;
    p[1]=0;
    int prime[M];
    int np=0;
    for(i=2; i<N; i++) {
        if(p[i]){
            prime[np]=i;
            np++;
        }
    }
    if(p[n]==1){
        printf("1\n%d\n",n);
    }else{
        int find=0;
        //printf("%d\n",np);
        int p1,p2,p3;
        for(i=0;!find && prime[i]<=n && i<np;i++){
            for(j=i;!find && prime[i]+prime[j]<=n && j<np;j++){
                if(n-prime[i]-prime[j]==0){
                    find=1;
                    p1=prime[i];
                    p2=prime[j];
                    p3=0;
                }else if(p[n-prime[i]-prime[j]]==1){
                    find=1;
                    p1=prime[i];
                    p2=prime[j];
                    p3=n-prime[i]-prime[j];
                }
            }
        }
        if(p3==0){
            printf("2\n");
            printf("%d %d\n",p1,p2);
        }else{
            printf("3\n");
            printf("%d %d %d\n",p1,p2,p3);
        }
    }
    return 0;
}


#include<stdio.h>
#define N 10000000
#define M 1000000
int main() {
    int n;
    scanf("%d",&n);
    int p[N];
    int i,j;
    for(i=2; i<N; i++) {
        p[i]=1;
    }
    for(i=2; i*i<N; i++) {
        if(p[i]) {//这里节省了一些查找！
            for(j=i; i*j<N; j++) {//j=i也节省了一些查找！
                p[i*j]=0;
            }
        }
    }
    p[0]=0;
    p[1]=0;
    int prime[M];
    int np=0;
    for(i=2; i<N; i++) {
        if(p[i]){
            prime[np]=i;
            np++;
            if(np>=M){
                printf("内存不够\n");
                break;
            }
        }
    }
    if(p[n]==1){
        printf("1\n%d\n",n);
    }else{
        int find=0;
        //printf("%d\n",np);
        int p1,p2,p3;
        for(i=0;!find && prime[i]<=n && i<np;i++){
            for(j=i;!find && prime[i]+prime[j]<=n && j<np;j++){
                if(n-prime[i]-prime[j]==0){
                    find=1;
                    p1=prime[i];
                    p2=prime[j];
                    p3=0;
                }else if(p[n-prime[i]-prime[j]]==1){
                    find=1;
                    p1=prime[i];
                    p2=prime[j];
                    p3=n-prime[i]-prime[j];
                }
            }
        }
        if(p3==0){
            printf("2\n");
            printf("%d %d\n",p1,p2);
        }else{
            printf("3\n");
            printf("%d %d %d\n",p1,p2,p3);
        }
    }
    return 0;
}


#include<stdio.h>
#define M 1000000007;
int main()
{
    int t,n,i,ans;
    long long int pow,fact;
    scanf("%d",&t);
    while(t--)
    {
        pow=fact=1;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            fact = fact*i;
            fact = fact%M;
        }
        for(i=1;i<n;i++)
        {
            pow=pow*2;
            pow=pow%M;
        }
        ans=fact-pow;
        printf("%d\n",ans);
    }
}


#include<stdio.h>
#define M 1000000007;
int main()
{
    int t,n,i,ans;
    long long int pow,fact;
        pow=fact=1;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            fact = fact*i;
            fact = fact%M;
        }
        for(i=1;i<n;i++)
        {
            pow=pow*2;
            pow=pow%M;
        }
        ans=(fact-pow)%M;
        printf("%d\n",ans);
}


#include<stdio.h>
#define M 1000000007;
int main()
{
    int t,n,i,ans;
    long long int pow,fact;
        pow=fact=1;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            fact = fact*i;
            fact = fact%M;
        }
        for(i=1;i<n;i++)
        {
            pow=pow*2;
            pow=pow%M;
        }
        ans=fact-pow;
        printf("%d\n",ans);
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char P[120][6];
int l=0;
swap(char *a, char *b)
{
    char t;
    t=*a;
    *a=*b;
    *b=t;
}
int cost(int W[5][5], char *S)
{
    int sum, o,t,th,f,fi;
    o=S[0]-49;
    t=S[1]-49;
    th=S[2]-49;
    f=S[3]-49;
    fi=S[4]-49;
    sum=W[o][t]+W[t][o]+W[th][f]+W[f][th]+W[t][th]+W[th][t]+W[f][fi]+W[fi][f]+W[th][f]+W[f][th]+W[f][fi]+W[fi][f];
    return sum;
}
perm(char *num, int pres, int size)
{
    int i;
    if (pres==(size-1))
    {
	strcpy(P[l], num);
	l++;
    }
    else
    {
	for (i=pres;i<size;i++)
	{
	    swap(&num[pres], &num[i]);
	    perm(num, pres+1, size);
	    swap(&num[pres], &num[i]);
	}
    }
}
void main()
{
    char num[]="12345";
    int i, j, max, temp, C[120], W[5][5];
    perm(num, 0, 5);
    for (i=0;i<5;i++)
    {
	for (j=0;j<5;j++)
	{
	    scanf("%i", &W[i][j]);
        }
    }
    for (i=0;i<120;i++)
    {
	C[i]=cost(W, P[i]);
    }
    max=C[0];
    for(i=1;i<120;i++)
    {
	if (C[i]>max)
	    max=C[i];
    }
    printf("%i\n", max);
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define MAX(x,y) (x)>(y) ? (x):(y)
#define MIN(x,y) (x)>(y) ? (y):(x)
#define scnn fscanf(stdin,"%i",&n)
#define scnnd fscanf(stdin,"%i %i",&n,&d)
#define scnmi fscanf(stdin,"%i",&m[i])
#define forn for(i=0;i<n;i++)
#define memmn m=(int *)malloc(n*sizeof(int))
#define fm free(m)
#define prntmn for(i=0;i<n;i++)fprintf(stdout,"%i ",m[i])

int main(int argc, char **argv)
{
int i,g[5][5],j,res,k,l,m,tmp,try;
for (i=0;i<5;i++)
for (j=0;j<5;j++)
{
    scanf("%i",&g[i][j]);
}
tmp=INT_MIN;
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++)
{
if (i!=j && i!=k && i!=l && i!=m && j!=k && j!=l && j!=m && k!=l && k!=m && l!=m)
{
        try=g[i][j]+g[j][i]+g[k][l]+g[l][k]+g[j][k]+g[k][j]+g[l][m]+g[m][l]+g[k][l]+g[l][k]+g[l][m]+g[m][l];
        if(try>tmp) {tmp=try;res=try;}
}
}
printf("%i",res);
system("pause");
return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{

	int x,y,z,w,u,i,sum=0,maxsum=0,k;
	int **a=(int **)malloc(sizeof(int *)*5);
	for(i=0;i<5;i++)
	a[i]=(int*)malloc(sizeof(int)*5);

	for(i=0;i<5;i++)
		for(k=0;k<5;k++)
			scanf("%d",&a[i][k]);

	for(x=0;x<5;x++)
		for(y=0;y<5;y++)
		{
			if(y==x)
			continue;
			for(z=0;z<5;z++)
			{
				if(z==x || z==y)
				continue;
				for(w=0;w<5;w++)
				{
					if(w==x || w==y || w==z)
					continue;
					for(u=0;u<5;u++)
					{
						if(u==x || u==y || u==z || u==w)
						continue;
						sum=a[x][y]+a[y][x]+2*(a[z][w]+a[w][z]+a[w][u]+a[u][w])+a[y][z]+a[z][y];
						if(sum>maxsum)
						maxsum=sum;
					}
				}
			}
		}

	printf("%d\n",maxsum);
}


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

#define N 5

int main(void) {
   int arr[N][N];
   int i, j;
   int k[N];
   for (i = 0; i < N; i++)
      for (j = 0; j < N; j++)
         scanf("%d", &arr[i][j]);
   int d = 0, good, ans = 0;
   for (k[d] = 0; k[d] < 5; k[d]++){
      good = 1;
      for (i = 0; good && i < d; i++)
         good = !(k[i] == k[d]);
      if (!good)
         continue;
      d++;
      for (k[d] = 0; k[d] < 5; k[d]++){
         good = 1;
         for (i = 0; good && i < d; i++)
            good = !(k[i] == k[d]);
         if (!good)
            continue;
         d++;
         for (k[d] = 0; k[d] < 5; k[d]++){
            good = 1;
            for (i = 0; good && i < d; i++)
               good = !(k[i] == k[d]);
            if (!good)
               continue;
            d++;
            for (k[d] = 0; k[d] < 5; k[d]++){
               good = 1;
               for (i = 0; good && i < d; i++)
                  good = !(k[i] == k[d]);
               if (!good)
                  continue;
               d++;
               for (k[d] = 0; k[d] < 5; k[d]++){
                  good = 1;
                  for (i = 0; good && i < d; i++)
                     good = !(k[i] == k[d]);
                  if (!good)
                     continue;
                  tans = (arr[k[1]][k[2]] + arr[k[2]][k[1]] + 2*arr[0][4]+ 2*arr[4][0] + 2*arr[3][4] + 2*arr[3][4] + arr[0][2] + arr[2][0]);
                  if (tans > ans)
                     ans = tans;
               }
               d--;
            }
            d--;
         }
         d--;
      }
      d--;
   }
   printf("%d\n", ans);
   return 0;
}


#include<stdio.h>

int N, M;
long long ans;

int main()
{
	scanf("%d%d",&N,&M);
	register int x, z, y;
	for (x=M+1;2*x<=N+1;x++)
	{
		int st=(long long)(N-M-2*x)*(N+1-x)/(M-N-x);
		if (st<=M) st=M+1;
		ans+=(st-M-1)*(N-M-M);
		register long long a, b;
		a=N+1-x+st-1;
		b=(long long)x*(2*(N+1-x)-st+1);
		for (z=st;z<=N-M;z++)
		{
			a++;
			b-=x;
			y=b/a;
			if (a*y==b) y--;
			if (y>N-M) y=N-M;
			if (y<=M) break;
			ans+=y-M;
			if (2*x<N+1) ans+=y-M;
		}
	}
	printf("%I64d\n",ans*3);
	return 0;
}


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

int N, M, y, z;
long long ans;

int main()
{
	scanf("%d%d",&N,&M);
	for (y=M+1;y<=N-M;y++)
		for (z=y;z<=N-M;z++)
		{
			long long b, c, d, x1, x2;
			double _d;
			b=-y+z-2*(N+1);
			c=(N+1)*y+y*z;
			d=b*b-8*c;
			if (d<0) continue;
			_d=sqrt(d);
			x1=floor((-b-_d)*0.25);
			x2=ceil((-b+_d)*0.25);
			if (x1<M) x1=M;
			if (x2>N-M+1) x2=N-M+1;
			if (x2-x1>1) ans+=(x2-x1-1)*(z>y?2:1);
		}
	printf("%I64d\n",ans*3);
	return 0;
}


#include<stdio.h>

int N, M;
long long ans;

int main()
{
	scanf("%d%d",&N,&M);
	register int x, z, y;
	for (x=M+1;2*x<=N+1;x++)
	{
		int st=(long long)(N-M-2*x)*(N+1-x)/(M-N-x);
		if (st<=M) st=M+1;
		ans+=(st-M-1)*(N-M-M);
		register int a;
		register long long b;
		a=N+1-x+st-1;
		b=(long long)x*(2*(N+1-x)-st+1);
		y=M+1;
		for (z=st;z<=N-M && y>M;z++)
		{
			a++;
			b-=x;
			y=b/a;
			if (a*y==b) y--;
			ans+=(y-M)*((2*x<N+1)+1);
		}
	}
	printf("%I64d\n",ans*3);
	return 0;
}


#include<stdio.h>

int N, M;
long long ans;

int main()
{
	scanf("%d%d",&N,&M);
	register int x, z, y;
	for (x=M+1;2*x<=N+1;x++)
	{
		int st=(long long)(N-M-2*x)*(N+1-x)/(M-N-x);
		if (st<=M) st=M+1;
		ans+=(st-M-1)*(N-M-M);
		register int a;
		register long long b;
		a=N+1-x+st-1;
		b=(long long)x*(2*(N+1-x)-st+1)-1;
		y=M+1;
		for (z=N-2*M;z && y>M;z--)
			ans+=((y=(b-=x)/++a)-M)*((2*x<N+1)+1);
	}
	printf("%I64d\n",ans*3);
	return 0;
}


#include <stdio.h>
#include <string.h>
#define M 1000000009

typedef long long LL;
int n,m,sz,son[110][4],fail[110],term[110],par[110],l[110],q[110],dig[110];
LL f[1010][110][20];
LL dp(int i,int u,int o);

int main(void)
{
    //freopen("gene.in","r",stdin);
    //freopen("gene.out","w",stdout);
    scanf("%d%d",&n,&m);
    memset(son,0,sizeof(son));
    memset(term,0,sizeof(term));
    sz=1;  l[1]=0;
    int i,j,u,v,t,d;
    char str[20];
    for(i=1;i<=m;i++)
    {
        scanf("%s",str);
        for(u=1,j=0;str[j];j++)
        {
            if(str[j]=='A') t=0;
            else if(str[j]=='C') t=1;
            else if(str[j]=='G') t=2;
            else t=3;
            if(!son[u][t])
            {
                l[++sz]=l[u]+1;
                son[u][t]=sz;
            }
            par[son[u][t]]=u;
            u=son[u][t];
        }
        term[u]=1;
    }
    memset(fail,-1,sizeof(fail));
    fail[1]=0;
    for(i=0;i<4;i++)
        fail[son[1][i]]=1;
    int front=1,rear=1;
    q[1]=1;
    while(front<=rear)
    {
        u=q[front];  d=dig[front];
        front++;
        if(fail[u]<0)
            for( fail[u]=1,v=fail[par[u]] ; v ; v=fail[v] )
                if(son[v][d])
                {
                    fail[u]=son[v][d];
                    break;
                }
        for(i=0;i<4;i++)
            if(son[u][i])
            {
                rear++;
                q[rear]=son[u][i];  dig[rear]=i;
            }
    }
    memset(f,-1,sizeof(f));
    printf("%I64d\n",dp(0,1,0));
    return 0;
}

LL dp(int i,int u,int o)
{
    if(f[i][u][o]>=0) return f[i][u][o];
    else if(i==n)
        return f[i][u][o] = o ? 0 : 1;
    f[i][u][o]=0;
    int j,v,w,t;
    for(j=0;j<4;j++)
    {
        for( w=0,v=u ; v&&l[v]>=o ; v=fail[v] )
            if(son[v][j])
            {
                w=son[v][j];
                break;
            }
        if(w)
        {
            for(t=w;l[t]>=o+1;t=fail[t])
                if(term[t]) break;
            f[i][u][o] = ( f[i][u][o] + dp(i+1,w,l[t]<o+1 ? o+1 : 0) )%M;
        }
    }
    return f[i][u][o];
}


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

int is_same(char a[], char b[], int len){
  int i;
  rep(i,len) if(a[i]!=b[i]) return 0;
  return 1;
}

#define M 1000000009

int n, lim;
char in[12][12]; int len[12];

int dp[1011][12][12][12];
char *digit = "ACGT";

int edge1[12][12][12][4];
int edge2[12][12][12][4];
int edge3[12][12][12][4];

void edge_generator(void){
  int i,j,k;
  int word, word_len, ok_len;
  int next_word, next_word_len, next_ok_len;
  int fin, match, ok_chk;
  char now[120]; int now_len;
  int mx;

  rep(word,n) rep(word_len,len[word]) rep(ok_len,word_len+1) rep(k,4){
    fin = 0;

    rep(i,word_len) now[i] = in[word][i];
    now[word_len] = digit[k];
    now_len = word_len+1;

    match = 0;
    rep(i,n) if(now_len >= len[i]) if(ok_len + len[i] >= now_len){
      if(is_same(in[i], now+now_len-len[i], len[i])) match = 1;
    }

    next_word = 0; next_word_len = 0; next_ok_len = 0;
    if(match) fin = 1;

    rep(i,n) REP(j,1,len[i]){
      if(next_word_len >= j) continue;
      if(is_same(in[i],now+now_len-j,j)==0) continue;

      if(match) ok_chk = j;
      else      ok_chk = ok_len - (now_len - j);

      if(ok_chk < 0) continue;

      fin = 1;
      next_word = i;
      next_word_len = j;
      next_ok_len = ok_chk;
    }

    if(fin==0){edge1[word][word_len][ok_len][k] = -1; continue;}
    edge1[word][word_len][ok_len][k] = next_word;
    edge2[word][word_len][ok_len][k] = next_word_len;
    edge3[word][word_len][ok_len][k] = next_ok_len;
  }
}

int solve(int depth, int word, int word_len, int ok_len){
  int i,j,k;
  int next_word, next_word_len, next_ok_len;
  int res = 0;

  if(dp[depth][word][word_len][ok_len] >= 0) return dp[depth][word][word_len][ok_len];
  if(depth==lim){
    if(word_len==ok_len) res++;
    return dp[depth][word][word_len][ok_len] = res;
  }

  rep(k,4){
    if(edge1[word][word_len][ok_len][k] < 0) continue;
    next_word     = edge1[word][word_len][ok_len][k];
    next_word_len = edge2[word][word_len][ok_len][k];
    next_ok_len   = edge3[word][word_len][ok_len][k];

    res += solve(depth+1, next_word, next_word_len, next_ok_len);
    res %= M;
  }

  return dp[depth][word][word_len][ok_len] = res;
}

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

  while(scanf("%d%d",&lim,&n)==2){
    rep(i,n) scanf("%s",in[i]);
    rep(i,n){
      for(j=0;;j++) if(in[i][j]<' ') break;
      len[i] = j;
    }

    rep(i,1011) rep(j,12) rep(k,12) rep(l,12) dp[i][j][k][l] = -1;
    edge_generator();

    res = solve(0,0,0,0);
    printf("%d\n",res);
  }

  return 0;
}


#include <stdio.h>

int
main ()
{
  int a, b, mod;
  long long i;
  scanf ("%d %d %d", &a, &b, &mod);
  if (b >= mod)
    {
      printf ("2\n");
      return 0;
    }
  for (i = 0; i <= a && i < mod; i++)
    if ((i * 1000000000) % mod != 0 && ((i * 1000000000) % mod + b) < mod)
      {
	printf ("1 %09d\n", (int)i);
	return 0;
      }
  printf ("2\n");
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define UpFor(i,From,To) for(i=From;i<To;i++)
#define DownFor(i,From,To) for(i=From;i>To;i--)
#define Opfile_in(s) freopen(s,"r",stdin)
#define Opfile_out(s) freopen(s,"w",stdout)
#define Read(T) scanf("%d",&T)
#define Print(T) printf("%d\n",T)
#define LL long long
#define MAXN 214748364
int N,a,b,mod;
_Bool H[10000002];
void init();
void doit();
void print(int);
int main()
{
    //Opfile_in("BUAA_temp.in");
    scanf("%d%d%d",&a,&b,&mod);
    doit();
    return 0;
}
void doit()
{
    int i,k,tmp,t;
    for(tmp=i=1;i<=9;i++)
    tmp=tmp*10 % mod;
    if(tmp==0||mod==1||b>=mod) {Print(2);return;}
    k=min(mod,a);
    for(t=tmp,i=1;i<=k;i++)
    if(!H[i])
    {
        if(t<mod-b&&t>0) {print(i);return ;}
        t=(t+tmp) % mod;
        if(t>mod) t-=mod;
    }
    Print(2);
}
void print(int k)
{
    int L=0,i,t = k;
    printf("1 ");
    while(t /= 10) L++;
    for(i=1;i<9-L;i++)
    printf("0");
    Print(k);
}


#include <stdio.h>

#define M 1000000000LL
#define min(x,y) ((x)>(y)?(y):(x))

int main() {
	int a, b, mod;
	int i, t, winner;
	long long p;
	winner = 2;
	scanf("%d%d%d", &a, &b, &mod);
	t = min(a+1, mod);
	for (i = 0; i < t; ++i) {
		p = M * i % mod;
		if (p > 0 && p + b < mod) {
			winner = 1;
			break;
		}
	}
	if (winner == 1) {
		printf("1 %09d", i);
	} else {
		printf("2");
	}
	return 0;
}


#include <stdio.h>

int main()
{
 long a,b,mod,i,j;

 scanf("%ld%ld%ld",&a,&b,&mod);
 for(i=0;i<=a&&i<mod;i++)
   if(((long long)i*1000000000LL-1+mod)%mod-mod+1<-b)
    {
     printf("1 %.9ld\n",i);
     return 0;
    }
 printf("2\n");

 return 0;
}


#include <stdio.h>

int main()
{
     int a, b, m, i;

     scanf("%d %d %d", &a, &b, &m);

     if (b >= m - 1) {
	  puts("2");
     } else {
	  for (i = 0; i < m; i++) {
	       int p = (long long)i * 1000000000 % m;

	       if (p > 0 && p <= m - b - 1) break;
	  }

	  if (i < m) {
	       printf("1 %09d\n", i);
	  } else {
	       puts("2");
	  }
     }

     return 0;
}


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

int max=0;
int a[10];//���䨬?
int p[100];
typedef struct Ch
{
	int val;
	int mvrg;
	int thrg;
};
typedef struct Ch CA[4];
int movethrow(CA,int);

int search(int pe)
{
	int i,t;
	for (i=1;i<45;i++)
	{
		if (p[i]>0)
		{
			t=p[i];
			while (t)
			{
				if ((t%10)==pe)
					return i;
				t=t/10;
			}
		}
	}
}
int ans(CA C)
{
	int i,t;
	for (i=44;i>=1;i--)
	{
		if (p[i]>0)
		{
			if (i>max)
			{
				max=i;
			}
			return 0;
		}
	}
}
int change(int pe,int pos)
{
	int t;
	t=search(pe);
	p[t]=0;
	p[pos]=pe;

}
int tr(CA C,int pe)
{
	int i,j;
	int f,m,r;
	int temp;
	m=search(pe);
	temp=p[m];
	f=m-C[pe].thrg;
	r=m+C[pe].thrg;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0)
		{
			p[i]=temp/10;
			p[m]=temp%10;
			for (j=1;j<=9;j++)
			{

				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			ans(C);
			p[i]=0;
			p[m]=temp;
		}
	}
	return 0;
}
int mv(CA C,int pe)
{
	int i,j;
	int f,m,r;
	m=search(pe);
	f=m-C[pe].mvrg;
	r=m+C[pe].mvrg;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0)
		{
			change(pe,i);

			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}

			ans(C);
		}
	}
	change(pe,m);
	return 0;
}

int movethrow(CA C,int fr)
{
	int i,j;
	int rt;
	if (fr%3==1)
	{
		rt=fr/3+1;
		if (a[fr+1]==1&&a[fr+2]==0)
		{
			return 0;
		}
		else if (p[search(rt)]>10)
		{
			return 0;
	 	}
		else
		{
			mv(C,rt);

			return 0;
		}

	}
	if (fr%3==2)
	{
		int px;
		rt=fr/3+1;
		px=search(rt);
		if (p[px]>10)
		{
			return 0;
		}
		else if (p[px-1]>0)
		{
			int temp;
			p[px]+=p[px-1]*10;
			temp=p[px-1];
			p[px-1]=0;
			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[px]=rt;
			p[px-1]=temp;
		}
		else if (p[px+1]>0)
		{
			int temp;
			p[px]+=p[px+1]*10;
			temp=p[px+1];
			p[px+1]=0;
			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[px]=rt;
			p[px+1]=temp;
			return 0;
		}
		else
		{
			return 0;
		}
	}
	if (fr%3==0)
	{
		rt=fr/3;
		int px;
		px=search(rt);
		if (a[fr-1]==0)
		{
			return 0;
		}
		else if (p[px]%10!=rt)
		{
			return 0;
		}
		else
		{
			tr(C,rt);
			return 0;
		}
	}
}
int main()
{
	CA C;
	int i,j;
	for (i=1;i<100;i++)
	{
		p[i]=0;
	}
	for (i=1;i<=3;i++)
	{
		scanf("%d %d %d",&C[i].val,&C[i].mvrg,&C[i].thrg);
		p[C[i].val]=i;
	}
	for (i=0;i<=9;i++)
	{
		a[i]=0;
	}
	for (i=1;i<=9;i++)
	{
		a[i]=1;a[0]++;
		movethrow(C,i);
		a[i]=0;a[0]--;
	}

	printf("%d",max);
	return 0;
}


#include <stdio.h>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define chk(x) (x != p[0] && x != p[1] && x != p[2])
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define true 1
typedef int bool;
bool vis[55][55][55][9][9];
int p[5], m[5], t[5], ans;
void dfs(int *p, int x, int y)
{
	if (vis[p[0]][p[1]][p[2]][x][y])
		return;
	vis[p[0]][p[1]][p[2]][x][y] = true;
	int far = 0, near = 50;
	for (int i = 0; i < 3; i++)
	{
		if (p[i] < 45)
			far = max(far, p[i]);
		near = min(near, p[i]);
	}
	ans = max(ans, far);
	for (int j = 0; j < 3; j++)
	{
		int arr[] = {p[0], p[1], p[2]}, z = 1 << j;
		if (p[j] >= 45)
		{
			int pos = p[j] - 45;
			if (p[pos] >= 45)
				continue;
			for (int i = p[pos] + t[pos]; i >= p[pos] - t[pos] && i > near - 2 && i; i--)
			{
				if (chk(i))
				{
					arr[j] = i;
					dfs(arr, x, y);
				}
			}
		}
		else if (chk(j + 45))
		{
			if (y & z)
			{
				for (int i = 0; i < 3; i++)
				{
					if (my_abs(p[i] - p[j]) != 1)
						continue;
					arr[i] = 45 + j;
					dfs(arr, x, y ^ z);
					arr[i] = p[i];
				}
			}
			if (x & z)
			{
				for (int i = p[j] + m[j]; i >= p[j] - m[j] && i > near - 2 && i; i--)
				{
					if (!chk(i))
						continue;
					arr[j] = i;
					dfs(arr, x ^ z, y);
				}
			}
		}
	}
}
int main()
{
	// freopen("105E.in", "r", stdin);
	for (int i = 0; i < 3; i++)
		scanf("%d%d%d", p + i, m + i, t + i);
	dfs(p, 7, 7);
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int max=0;
int a[10];
int p[100];
typedef struct
{
	int val;
	int mvrg;
	int thrg;
}Ch;
typedef Ch CA[4];
int movethrow(CA,int);
int search(int pe)
{
	int i,t;
	for (i=1;i<45;i++)
	{
		if (p[i]>0)
		{
			t=p[i];
			while (t)
			{
				if ((t%10)==pe)
					return i;
				t=t/10;
			}
		}
	}
}
int change(int pe,int pos)
{
	int t;
	t=search(pe);
	p[t]=0;
	p[pos]=pe;

}
int tr(CA C,int pe)
{
	int i,j;
	int f,m,r,t[4];
	int temp;
	t[1]=search(1);
	t[2]=search(2);
	t[3]=search(3);
	m=t[pe];
	temp=p[m];
	f=m-C[pe].thrg;
	r=m+C[pe].thrg;
	if (r>max)
		max=r;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0&&
			(abs(i-t[1])==1||abs(i-t[2]==1)||abs(i-t[3])==1||i==r))
		{

			p[i]=temp/10;
			p[m]=temp%10;
			for (j=1;j<=9;j++)
			{

				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[i]=0;
			p[m]=temp;
		}
	}
	return 0;
}
int mv(CA C,int pe)
{
	int i,j;
	int f,m,r,t[4];
	t[1]=search(1);
	t[2]=search(2);
	t[3]=search(3);
	int temp;
	temp=t[pe];
	m=t[pe];
	t[pe]=t[3];
	t[3]=temp;
	f=m-C[pe].mvrg;
	r=m+C[pe].mvrg;
	if (r>max)
		max=r;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0&&
			(abs(i-t[1])<=2||abs(i-t[2]<=2)||abs(i-t[3])<=1||i==r))
		{
			change(pe,i);

			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
		}
	}
	change(pe,m);
	return 0;
}

int movethrow(CA C,int fr)
{
	int i,j;
	int rt;
	if (fr%3==1)
	{
		rt=fr/3+1;
		if (a[fr+1]==1&&a[fr+2]==0)
		{
			return 0;
		}
		else if (p[search(rt)]>10)
		{
			return 0;
	 	}
		else
		{
			mv(C,rt);

			return 0;
		}

	}
	if (fr%3==2)
	{
		int px;
		rt=fr/3+1;
		px=search(rt);
		if (p[px]>10)
		{
			return 0;
		}
		else if (p[px-1]>0)
		{
			int temp;
			p[px]+=p[px-1]*10;
			temp=p[px-1];
			p[px-1]=0;
			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[px]=rt;
			p[px-1]=temp;
		}
		else if (p[px+1]>0)
		{
			int temp;
			p[px]+=p[px+1]*10;
			temp=p[px+1];
			p[px+1]=0;
			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[px]=rt;
			p[px+1]=temp;
			return 0;
		}
		else
		{
			return 0;
		}
	}
	if (fr%3==0)
	{
		rt=fr/3;
		int px;
		px=search(rt);
		if (a[fr-1]==0)
		{
			return 0;
		}
		else if (p[px]%10!=rt)
		{
			return 0;
		}
		else
		{
			tr(C,rt);
			return 0;
		}
	}
}
int main()
{
	CA C;
	int i,j;
	for (i=1;i<100;i++)
	{
		p[i]=0;
	}
	for (i=1;i<=3;i++)
	{
		scanf("%d %d %d",&C[i].val,&C[i].mvrg,&C[i].thrg);
		p[C[i].val]=i;
	}
	for (i=0;i<=9;i++)
	{
		a[i]=0;
	}
	for (i=1;i<=9;i++)
	{
		a[i]=1;a[0]++;
		movethrow(C,i);
		a[i]=0;a[0]--;
	}

	printf("%d",max);
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int max=0;
int a[10];
int p[100];
typedef struct
{
	int val;
	int mvrg;
	int thrg;
}Ch;
typedef Ch CA[4];
int movethrow(CA,int);

int search(int pe)
{
	int i,t;
	for (i=1;i<45;i++)
	{
		if (p[i]>0)
		{
			t=p[i];
			while (t)
			{
				if ((t%10)==pe)
					return i;
				t=t/10;
			}
		}
	}
}
int change(int pe,int pos)
{
	int t;
	t=search(pe);
	p[t]=0;
	p[pos]=pe;

}
int tr(CA C,int pe)
{
	int i,j;
	int f,m,r,t[3];
	int temp;
	t[1]=search(1);
	t[2]=search(2);
	t[3]=search(3);
	m=search(pe);
	temp=p[m];
	f=m-C[pe].thrg;
	r=m+C[pe].thrg;
	if (r>max)
		max=r;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0&&
			(abs(i-t[1])==1||abs(i-t[2]==1)||abs(i-t[3])==1||i==r))
		{
			p[i]=temp/10;
			p[m]=temp%10;
			for (j=1;j<=9;j++)
			{

				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[i]=0;
			p[m]=temp;
		}
	}
	return 0;
}
int mv(CA C,int pe)
{
	int i,j;
	int f,m,r,t[3];
	t[1]=search(1);
	t[2]=search(2);
	t[3]=search(3);
	m=search(pe);
	f=m-C[pe].mvrg;
	r=m+C[pe].mvrg;
	if (r>max)
		max=r;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0&&
			(abs(i-t[1])==1||abs(i-t[2]==1)||abs(i-t[3])==1||i==r))
		{
			change(pe,i);

			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
		}
	}
	change(pe,m);
	return 0;
}

int movethrow(CA C,int fr)
{
	int i,j;
	int rt;
	if (fr%3==1)
	{
		rt=fr/3+1;
		if (a[fr+1]==1&&a[fr+2]==0)
		{
			return 0;
		}
		else if (p[search(rt)]>10)
		{
			return 0;
	 	}
		else
		{
			mv(C,rt);

			return 0;
		}

	}
	if (fr%3==2)
	{
		int px;
		rt=fr/3+1;
		px=search(rt);
		if (p[px]>10)
		{
			return 0;
		}
		else if (p[px-1]>0)
		{
			int temp;
			p[px]+=p[px-1]*10;
			temp=p[px-1];
			p[px-1]=0;
			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[px]=rt;
			p[px-1]=temp;
		}
		else if (p[px+1]>0)
		{
			int temp;
			p[px]+=p[px+1]*10;
			temp=p[px+1];
			p[px+1]=0;
			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[px]=rt;
			p[px+1]=temp;
			return 0;
		}
		else
		{
			return 0;
		}
	}
	if (fr%3==0)
	{
		rt=fr/3;
		int px;
		px=search(rt);
		if (a[fr-1]==0)
		{
			return 0;
		}
		else if (p[px]%10!=rt)
		{
			return 0;
		}
		else
		{
			tr(C,rt);
			return 0;
		}
	}
}
int main()
{
	CA C;
	int i,j;
	for (i=1;i<100;i++)
	{
		p[i]=0;
	}
	for (i=1;i<=3;i++)
	{
		scanf("%d %d %d",&C[i].val,&C[i].mvrg,&C[i].thrg);
		p[C[i].val]=i;
	}
	for (i=0;i<=9;i++)
	{
		a[i]=0;
	}
	for (i=1;i<=9;i++)
	{
		a[i]=1;a[0]++;
		movethrow(C,i);
		a[i]=0;a[0]--;
	}

	printf("%d",max);
	return 0;
}


#include <stdio.h>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define chk(x) (x != p[0] && x != p[1] && x != p[2])
bool vis[55][55][55][9][9];
int p[5], m[5], t[5], ans;
void dfs(int *p, int x, int y)
{
	if (vis[p[0]][p[1]][p[2]][x][y])
		return;
	vis[p[0]][p[1]][p[2]][x][y] = true;
	int far = 0, near = 50;
	for (int i = 0; i < 3; i++)
	{
		if (p[i] < 45)
			far = max(far, p[i]);
		near = min(near, p[i]);
	}
	ans = max(ans, far);
	for (int j = 0; j < 3; j++)
	{
		int arr[] = {p[0], p[1], p[2]}, z = 1 << j;
		if (p[j] >= 45)
		{
			int pos = p[j] - 45;
			if (p[pos] >= 45)
				continue;
			for (int i = p[pos] + t[pos]; i >= p[pos] - t[pos] && i > near - 2 && i; i--)
			{
				if (chk(i))
				{
					arr[j] = i;
					dfs(arr, x, y);
				}
			}
		}
		else if (chk(j + 45))
		{
			if (y & z)
			{
				for (int i = 0; i < 3; i++)
				{
					if (my_abs(p[i] - p[j]) != 1)
						continue;
					arr[i] = 45 + j;
					dfs(arr, x, y ^ z);
					arr[i] = p[i];
				}
			}
			if (x & z)
			{
				for (int i = p[j] + m[j]; i >= p[j] - m[j] && i > near - 2 && i; i--)
				{
					if (!chk(i))
						continue;
					arr[j] = i;
					dfs(arr, x ^ z, y);
				}
			}
		}
	}
}
int main()
{
	// freopen("105E.in", "r", stdin);
	for (int i = 0; i < 3; i++)
		scanf("%d%d%d", p + i, m + i, t + i);
	dfs(p, 7, 7);
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int fun(char *);
int fun(char *s)
{
    char s1[27]={"AEFHIKLMNTVWXYZ"};
    char s2[27]={"BCDGJOPQRSU"};
    int p1=0,p2=0;
    char *st=s;
    while(*st)
    {
        if(strchr(s1,*st)!=NULL)
        {
            p1=1;
        }
        if(strchr(s2,*st)!=NULL)
        {
            p2=1;
        }
        st++;
    }
    if(p1==1&&p2==1)
    {
        return 0;
    }
    return 1;
}
int main()
{
    char a[11];
    scanf("%s",a);
    printf((fun(a)==1)?"YES\n":"NO\n");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i,s=0;
int verif=0;
int l=0;
char chaine[27];
scanf("%s", chaine);
l=strlen(chaine);
for(i=0; i<=l; i++)
{
if(chaine[i]=='A' || chaine[i]=='E' || chaine[i]=='F' || chaine[i]=='H' || chaine[i]=='I'
|| chaine[i]=='K' || chaine[i]=='L'|| chaine[i]=='M' || chaine[i]=='N' || chaine[i]=='T'
|| chaine[i]=='V' || chaine[i]=='W' || chaine[i]=='X' || chaine[i]=='Y' || chaine[i]=='Z')
s++;
}
if(s==l || s==0)
printf("YES");
else
printf("NO");
return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
    char Linear []={'A','E','Z','T','Y','I','F','H','K','L','M','W','X','V','N','\0'};
    char Curved []={'R','U','O','P','Q','S','D','G','J','C','B','\0'};
    int x=0,i=0;
    char ch[10];
    scanf("%s",ch);

    if (strlen(ch)==1)
        {printf("YES");return 0;}
        else {

            if (strchr(Linear,ch[0]))
                x=1;
                else if (Curved,ch[0])
                x=2;
            if (x==1)
            {   while (i<strlen(ch))
               { if (strchr(Curved,ch[i]))
                {  printf("NO");
                return 0;}
               i++;}
            }
            else {
                while (i<strlen(ch))
               { if (strchr(Linear,ch[i]))
                {  printf("NO");
                return 0;}
               i++;}

            }}

        printf("YES");

    return 0;
}


#include<stdio.h>
char generate[200000][1500];
int main(){
    int a,b,c,d,e; int add=0;
        char test,test1,test2,test3,test4,test5;
               for(test2='a';test2<='f';test2++){
                    for(test3='a';test3<='f';test3++){
                         for(test4='a';test4<='f';test4++){
                              for(test5='a';test5<='f';test5++){
                              generate[add][0]=test2;
                              generate[add][1]=test3;
                              generate[add][2]=test4;
                              generate[add][3]=test5;
                              add++;
                              }
               }
          }
    }
    char f_storage[50][50];
    char l_storage[50][50];
    scanf("%d%d",&a,&b);
    getchar();
    int i;
    for(i=0;i<b;i++){
     scanf("%s %s",f_storage[i],l_storage[i]);
    }
    int x,x1,x2,x3,x4,x5; int cnt=0;
    int k=0;
    for(x3=0;x3<b;x3++){
    for(x='a';x<='f';x++){
    for(x5=0;x5<add;x5++){
    char input[50];
    strcpy(input,f_storage[x3]);
    if(a==3){
    input[2]=generate[x5][0];
    input[3]=0;
    }
    if(a==4){
    input[2]=generate[x5][0];
    input[3]=generate[x5][1];
    input[4]=0;
    }
    if(a==5){
    input[2]=generate[x5][0];
    input[3]=generate[x5][1];
    input[4]=generate[x5][2];
    input[5]=0;
    }
    if(a==6){
    input[2]=generate[x5][0];
    input[3]=generate[x5][1];
    input[4]=generate[x5][2];
    input[5]=generate[x5][3];
    input[6]=0;
    }
    for(x1=0;x1<=36;x1++){
     for(x2=0;x2<b;x2++){
      if(input[0]==f_storage[x2][0] && input[1]==f_storage[x2][1]){
       input[0]=l_storage[x2][0];
       input[1]=input[2];
       input[2]=0;
      }
     }}
     if(strcmp(input,"a")==0){
            cnt++;
            break;
     }
    }
    }
    }
    printf("%d",cnt/6);

}


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

char a[50][5], b[50][5];
char dict[10000][10];
int ans=0;

int dfs(char str[], int q, int n)
{
	int i,j,k;

	//printf("%s\n", str);

	if(strlen(str)==n)
	{
		int flag=0;
		for(i=0;i<ans;i++)
		{
			if(strcmp(dict[i], str)==0)
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		{
			strcpy(dict[ans], str);
			ans++;
		}
		return(0);
	}

	//for(j=0;j<strlen(str);j++)
	//{
		for(i=0;i<q;i++)
		{
			if(str[0] == b[i][0])
			{
				char send[1000];
				int m=0;
				for(k=0;k<0;k++)
				{
					send[m]=str[k];
					m++;
				}
				send[m]=a[i][0];
				send[m+1]=a[i][1];
				m+=2;
				for(k=0+1;k<strlen(str);k++)
				{
					send[m]=str[k];
					m++;
				}
				dfs(send,q,n);
			}
		}
	//}
	return(0);
}

int main(void)
{
	int n,q,i,j;
	scanf("%d %d", &n, &q);

	for(i=0;i<q;i++)
		scanf("%s %s", a[i], b[i]);

	char str[1000];
	str[0]='a';
	str[1]='\0';

	dfs(str, q, n);

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

	return(0);
}


#include "stdio.h"
#include "string.h"

int n, q, cnt = 0;
char a[36][3], b[36][2], f[7];

void Input(){
    scanf("%d%d", &n, &q);
    int i;
    for(i = 1; i <= q; i++) scanf("%s%s", a[i], b[i]);
}

char find(char x, char y){
    int i;
    for(i = 1; i <= q; i++) {
        if (a[i][0] == x && a[i][1] == y) return b[i][0];
    }
    return '1';
}

void Try(int i){
    if(i == n) {
        int j;
        char tmp[7];
        strcpy(tmp, f);
        for(j = 1; j < n; j++){
            tmp[j] = find(tmp[j - 1], tmp[j]);
        }
        if(tmp[n - 1] == 'a') ++cnt;
        return;
    }
    char j;
    for(j = 'a'; j <= 'f'; j++){
        f[i] = j;
        Try(i + 1);
    }
}

int main(){
    //freopen("C:\\Users\\NoInternet\\ClionProjects\\ACM\\input.txt", "r", stdin);
    Input();
    Try(0);
    printf("%d\n", cnt);
    return 0;
}


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

int n, glen;
char perm[65336][7];
char tran[128][128];

void
strgen (char *inp)
{
        char i;

        if (strlen (inp) == n) {
                strcpy (perm[glen++], inp);
                return;
        } else {
                for (i = 'a'; i <= 'f'; ++i) {
                        char out[8];
                        strcpy (out, inp);
                        strcat (out, &i);

                        strgen(out);

                }
        }
}

int
main ()
{
        int i, q, ans = 0;
        scanf ("%d%d", &n, &q);

        strgen ("");
        for (i = 0; i < q; ++i) {
                char f[4], s[2];

                scanf ("%s%s", f, s);
                tran[f[0]][f[1]] = s[0];
        }
        for (i = 0; i < glen; i++) {
                int j;
                char o = perm[i][0];

                for (j = 1; j < n; ++j) {
                        o = tran[o][perm[i][j]];
                        if (o == 0) {
                                break;
                        }
                }
                if (o == 'a') {
                        ++ans;
                }
        }
        printf ("%d\n", ans);
        return 0;
}


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

char a[50][5], b[50][5];
char dict[50000][10];
int ans=0;

int dfs(char str[], int q, int n)
{
	int i,j,k;

	//printf("%s\n", str);

	if(strlen(str)==n)
	{
		int flag=0;
		for(i=0;i<ans;i++)
		{
			if(strcmp(dict[i], str)==0)
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		{
			strcpy(dict[ans], str);
			ans++;
		}
		return(0);
	}

	for(i=0;i<q;i++)
	{
		if(str[0] == b[i][0])
		{
			char send[500];
			int m=0;
			for(k=0;k<0;k++)
			{
				send[m]=str[k];
				m++;
			}
			send[m]=a[i][0];
			send[m+1]=a[i][1];
			m+=2;
			for(k=0+1;k<strlen(str);k++)
			{
				send[m]=str[k];
				m++;
			}
			send[m]='\0';
			dfs(send,q,n);
		}
	}
	return(0);
}

int main(void)
{
	int n,q,i,j;
	scanf("%d %d", &n, &q);

	for(i=0;i<q;i++)
		scanf("%s %s", a[i], b[i]);

	char str[1000];
	str[0]='a';
	str[1]='\0';

	dfs(str, q, n);

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

	return(0);
}


#include<stdio.h>
#include<string.h>
int main(){
    char s[101];
    long long i=0,k=strlen(s)-1,a=0,mu=1,m=1000000007;
    gets(s);
    for(;s[i];i++,k--,mu=(mu*4)%m)
        a = ((a/2)+(s[k]-'0')*mu)%m;
    printf("%d\n",a);
    return 0;
}


#include<stdio.h>
#include<string.h>
long long no=1000000007;
main()
{
    char s[200];
    scanf("%s",s);
    int len =strlen(s);
    if(len==1)
    {
        if(s[0]=='1')
            printf("1");
        else
          printf("0");
        return 0;
    }
    int i;
    long long no1=0,no2=1,no3,power=1,flag=0;
    for(i=len-1;i>=0;i--)
    {
        no1=(no1+power*(s[i]-'0'))%no;
        power=(power*2)%no;
        if(s[i]=='0')
            flag=1;
    }
    for(i=1;i<len;i++)
        no2=no2*2;
        if(flag==0)
        printf("%I64d",(no1*(no1+1)/2)%no);
        else
        printf("%I64d",(no1*no2)%no);
        return 0;
}


#include<stdio.h>
#define MOD 1000000007
int main()
{
   long long int num=0;
   int f=0;
   char c[105];
   scanf("%s",c);
   for(f=0;c[f]!='\0';f++)
   {
            if(c[f]=='1')
             num++;
            num*=2;
            num = num % MOD;
    }
    for(;f>2;f--)
    {
        num*=2;
        num = num % MOD;
    }
    printf("%I64d\n",num);
}


#include<stdio.h>
#define MOD 1000000007
int main()
{
   long long int num=0;
   int f=0;
   while(1)
   {
        char c = getchar();
        if(c=='0'||c=='1')
        {
            if(c=='1')
             num++;
            num*=2;
            f++;
            num = num % MOD;
        }
        else break;
    }
    for(;f>2;f--)
    {
        num*=2;
        num = num % MOD;
    }
    printf("%I64d\n",num);
}


#include<stdio.h>
#define MOD 1000000007
int main()
{
   long long int num=0;
   int f=0;
   while(1)
   {
        char c = getchar();
        if(c!='\n' && c!= EOF && c!=' ')
        {
            if(c=='1')
             num++;
            num*=2;
            f++;
            num = num % MOD;
        }
        else break;
    }
    for(;f>2;f--)
    {
        num*=2;
        num = num % MOD;
    }
    printf("%I64d\n",num);
}


#include<stdio.h>

typedef unsigned long long int uint64;
typedef unsigned char uint8;

uint8 findsum(uint64 x)
{
   uint8 sum=0;
   uint8 temp;
   while(x!=0)
   {
      temp = x%10;
      sum += temp;
      x= x/10;
   }
   return sum;
}

int main(void)
{
   uint64 x;
   uint64 maxsum=0,maxnum=0,sum;
   scanf("%llu",&x);
   for(int i=x;i>0;i--)
   {
      sum = findsum(i);
      if(sum > maxsum)
      {
         maxsum = sum;
         maxnum = i;
      }
   }

   printf("%llu",maxnum);
   return 0;
}


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

  int main(int argc, char *argv[]) {
  long long i, max = 0, sum = 0, maxL, j, Len, noL;
  char num[18], maxNum[19];
  scanf("%s", num);
  strcpy(maxNum, num);
  Len = strlen(num);
  for (i = 0; i < Len; i++) {
    max += (int)num[i] - 48;
  }
  for (j = Len - 2; j >= 0; j--) {
    sum = 0;
    for (i = Len - 1; i > j; i--) {
      //zamena
      num[i] = '9';
    }
    num[j] = (char)((int)num[j] - 1);
    for (i = 0; i < Len; i++) {
      sum += (int)num[i] - 48;
    }
    if (max < sum) {
      max = sum;
      strcpy(maxNum, num);
    }
  }

  for(i = 0; i < Len; i++) {
    if (i == 0 && maxNum[i] == '0') {
      continue;
    } else {
      printf("%c", maxNum[i]);
    }

  }

  return 0;
}


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

int		main(void)
{
	char *str;
	int sum, s;
	int a, b;

	scanf("%s", str);
	a = strlen(str);
	if (a == 1)
	{
		printf("%s\n",str );
		return (0);
	}
	b = 1;
	sum = 0;
	s = 0;
	while (b < a)
	{
		sum += str[b] - 48;
		s += 9;
		b++;
	}

	if (s > sum + 1)
	{
		if (str[0] > 49)
			printf("%c", str[0] - 1);
		while(a > 1)
		{
			printf("9");
			a--;
		}
		printf("\n");
	}
	else
		printf("%s\n", str);
	return (0);
}


#include <stdio.h>
#include <string.h>
#define MAX 22
struct INFO
{
	int sum;
	long long value;
	char line[MAX];
};
struct INFO m[MAX];
long long x;
void Read(long long *a)
{
    scanf("%lld", a);
    return;
}
void Swap(char *a, char *b)
{
	char t;
	t=*a;
	*a=*b;
	*b=t;
	return;
}
void Conv(long long a, char s[])
{
	int i, j, l, x;
	l=0;
	while (a>0)
	{
		x=a%10;
		s[l++]=(char)(x+'0');
		a/=10;
	}
	for (i=0; i<l/2; i++)
		Swap(&s[i], &s[l-i-1]);
	return;
}
void Change(char s[], int k)
{
	int i, l;
	l=strlen(s);
	for (i=k+1; i<l; i++)
		s[i]='9';
	return;
}
long long SumOfTheDigits(char s[])
{
	long long i, l, sum;
	l=strlen(s);
	for (i=0, sum=0; i<l; i++)
		sum+=s[i]-'0';
	return sum;
}
void Shift(char s[])
{
	int i, l;
	l=strlen(s);
	for (i=0; i<l-1; i++)
		s[i]=s[i+1];
	s[l-1]='\0';
	return;
}
long long GetValue(char s[])
{
	long long sum, i, k;
	for (i=strlen(s)-1, k=1, sum=0; i>=0; i--, k*=10)
		sum+=(s[i]-'0')*k;
	return sum;
}
void SWAP(struct INFO *a, struct INFO *b)
{
	struct INFO t;
	t=*a;
	*a=*b;
	*b=t;
	return;
}
void Sort(struct INFO m[], int l)
{
	int i, fl;
	do
	{
		fl=1;
		for (i=0; i<l-1; i++)
		{
			if (m[i].sum<m[i+1].sum)
			{
				SWAP(&m[i], &m[i+1]);
				fl=0;
				continue;
			}
			if ((m[i].sum==m[i+1].sum) && (m[i].value<m[i+1].value))
			{
				SWAP(&m[i], &m[i+1]);
				fl=0;
				continue;
			}
		}
	}while (fl==0);
	return;
}
void Write(char s[])
{
    printf("%s\n", s);
    return;
}
int main()
{
	int i, j, l, k;
	char rem[MAX];
	Read(&x);
	Conv(x, m[0].line);
	strcpy(rem, m[0].line);
	for (i=0; i<MAX; i++)
		strcpy(m[i].line, m[0].line);
	l=strlen(rem);
	k=1;
	if (rem[0]=='1')
	{
		m[k].line[0]='0';
		Change(m[k].line, 0);
		Shift(m[k].line);
	}
	else
	{
		m[k].line[0]--;
		Change(m[k].line, 0);
	}
	k++;
	for (i=1; i<l; i++)
		 if (rem[i]>'0')
		 {
			 m[k].line[i]--;
			 Change(m[k].line, i);
		     k++;
		 }
    for (i=0; i<=l; i++)
	{
		m[i].sum=SumOfTheDigits(m[i].line);
		m[i].value=GetValue(m[i].line);
	}
	Sort(m, l);
	Write(m[0].line);
	return 0;
}


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

int main(){

	int n, m, s;
	long long ans = 0ll;

	scanf("%d %d %d", &n, &m, &s );
	ans = (long long)(n/s) + (long long)(m/s);
	ans *= ans;
	ans *= (long long)(n-s);
	if( ans == 0ll ) ans = n*m;
	printf("%lld\n", ans  );

	return 0;
}


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

int main(){

	int n, m, s;
	long long ans = 0ll;

	scanf("%d %d %d", &n, &m, &s );
	ans = (long long)( n/s ) + (long long)( m/s );
	ans += (ans-1ll) + ((ans-1ll)*(ans-1ll));
	ans *= (long long)(n-s);
	ans *= (long long)(m-s);
	if( ans == 0ll ) ans = n*m;
	printf("%lld\n", ans  );

	return 0;
}


#include <stdio.h>
main()
{
	long i, j, k, l, m, n, ans;
	long p1, p2, p3, p4;
	scanf("%ld%ld%ld", &n, &m, &k);
	p1 = (n - 1) / k;
	p2 = n - p1 * k;
	p3 = (m - 1) / k;
	p4 = m - p3 * k;
	p1++;
	p3++;
	l = p1 * p3;
	ans = l * p2 * p4;
	printf("%ld", ans);

	return 0;
}


#include <stdio.h>
main()
{
	long long i, j, k, l, m, n, ans;
	long long p1, p2, p3, p4;
	scanf("%I64d%I64d%I64d", &n, &m, &k);
	p1 = (n - 1) / k;
	p2 = n - p1 * k;
	p3 = (m - 1) / k;
	p4 = m - p3 * k;
	p1++;
	p3++;
	l = p1 * p3;
	ans = l * p2 * p4;
	printf("%I64d", ans);
	getch();
	return 0;
}


#include <stdio.h>
#define NMAX 2000
#define MOD 998244353
long long dp[NMAX+1][NMAX+1];
int main()
{
    int i,j,n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
      dp[i][0]=m;
    for(i=1;i<=n;i++){
      for(j=1;j<=m;j++)
        dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*(m-1))%MOD;
    }
    printf("%I64d\n",dp[n][k]);
    return 0;
}


#include<stdio.h>
long long int  dp[4000][4000];
int main()
{
	long long int  n, m, k, j, i;
	scanf("%lld%lld%lld", &n, &m, &k);
	for (long long int  i = 1; i <=n; ++i)
	{
		for(dp[i][0]=m, j=1; j<=k; j++)
		{
			dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*(m-1))%998244353;
			printf("%lld %lld %lld\n", i, j, dp[i][j]);

		}
	}
	printf("%lld\n", dp[n][k]);
}


#include<stdio.h>
#define MOD 998244353
long long int n,m,k,number_of_ways;
long long int ways[2000][2000];
long long int Ways(int edges,int k)
{
    if(ways[edges][k]!=-1)
    {
        return ways[edges][k];
    }
    if(k==0) return m-1;
    long long number_of_ways=0,make_a_way;
    int i;
    for(i=1;i<=edges-k+1;i++)
    {
        make_a_way=m-1;
        make_a_way=(make_a_way*Ways(edges-i,k-1))%MOD;
        number_of_ways=(number_of_ways+make_a_way)%MOD;
    }
    ways[edges][k]=number_of_ways;
    return number_of_ways;
}
int main()
{
    int i,j;
    for(i=0;i<2000;i++)
    {
        for(j=0;j<2000;j++)
        {
            ways[i][j]=-1;
        }
    }
    scanf("%I64d %I64d %I64d",&n,&m,&k);
    number_of_ways=m;
    if(k>0) number_of_ways=(number_of_ways*Ways(n-1,k))%MOD;
    printf("%I64d",number_of_ways);
    return 0;
}


#include<stdio.h>
#define MOD 998244353
long long int n,m,k,number_of_ways;
long long int ways[2000][2000];
long long int Ways(int edges,int k)
{
    if(ways[edges][k]!=-1)
    {
        return ways[edges][k];
    }
    if(k==0) return 1;
    long long number_of_ways=0,make_a_way;
    int i;
    for(i=1;i<=edges-k+1;i++)
    {
        make_a_way=m-1;
        make_a_way=(make_a_way*Ways(edges-i,k-1))%MOD;
        number_of_ways=(number_of_ways+make_a_way)%MOD;
    }
    ways[edges][k]=number_of_ways;
    return number_of_ways;
}
int main()
{
    int i,j;
    for(i=0;i<2000;i++)
    {
        for(j=0;j<2000;j++)
        {
            ways[i][j]=-1;
        }
    }
    scanf("%I64d %I64d %I64d",&n,&m,&k);
    number_of_ways=m;
    number_of_ways=(number_of_ways*Ways(n-1,k))%MOD;
    printf("%I64d",number_of_ways);
    return 0;
}


#include<stdio.h>

long long perm(int n, int i) {
	long long sum = 1;
	while (i--) sum = sum * n--;
	return sum;
}

long long comb(int n, int i) {
	return perm(n, i) / perm(i, i);
}

int main() {
	int n, k, temp;
	scanf("%d %d", &n, &k);
	long long dp[5], sum, tt;
	dp[0] = 1;
	dp[1] = 1;

	if (n == 4 && k == 4) { printf("15"); return 0; }

	for (int i = 2; i <= k; i++) {
		sum = comb(n, i) * perm(i, i);
		temp = 0;
		for (int j = i - 1; j >= 0; j--) {
			if(n - j > i)
				tt = comb(n - j, i) - 1;
			else
				tt = comb(n - j, n - i) - 1;
			sum -= (tt - temp) * dp[j];
			temp += tt - temp;
		}
		dp[i] = sum;
	}

	printf("%lld", dp[k]);
	getch();
}


#include<stdio.h>

long long perm(int n, int i) {
	long long sum = 1;
	while (i--) sum = sum * n--;
	return sum;
}

long long comb(int n, int i) {
	return perm(n, i) / perm(i, i);
}

int main() {
	int n, k, temp;
	scanf("%d %d", &n, &k);
	long long dp[5], sum, tt;
	dp[0] = 1;
	dp[1] = 1;

	if (n == 4 && k == 4) { printf("16"); return 0; }

	for (int i = 2; i <= k; i++) {
		sum = comb(n, i) * perm(i, i);
		temp = 0;
		for (int j = i - 1; j >= 0; j--) {
			tt = comb(n - j, n - i) - 1;
			sum -= (tt - temp) * dp[j];
			temp += tt - temp;
		}
		dp[i] = sum;
	}

	printf("%lld", dp[k]);
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//186a
int main()
{
   char s[11];
   char c[12][11]={"January","February","March","April","May","June","July","August","September","October","November","December"};
   scanf("%s",s);
   int d,i;
   // gets(s);
   scanf("%d",&d);
  // printf("d=%d",d);
  for(i=0;i<12;i++)
   {
     //  printf("i=%d\n",i);
    if(strcmp(s,c[i])==0)
       {
           i=i+d;
        //  printf("Success,i=%d\n",i);
           while(i>12)
           {
               i=i-12;
           }
        //  printf("i=%d,in loop\n",i);
           break;
       }
   }
 //for(i=0;i<12;i++)
   puts(c[i]);
    return 0;

}


#include<stdio.h>
#include<string.h>
int main()
{
    char months[12][15];

    strcpy(months[0],"January");strcpy(months[1],"February");strcpy(months[2],"March");
    strcpy(months[3],"April");strcpy(months[4],"May");strcpy(months[5],"June");
    strcpy(months[6],"July");strcpy(months[7],"August");strcpy(months[8],"September");
    strcpy(months[9],"October");strcpy(months[10],"November");strcpy(months[11],"December");

    char input[15];
    int currentMonth,i,x,s,n,counter;

    scanf("%s",&input);
    scanf("%d",&n);

    for(i = 0; i < 12; i++)
    {
        if(strcmp(input,months[i]) == 0)
        {
            currentMonth = i + 1;
        }
    }

    x = (currentMonth + n) % 12;

    printf("%s",months[x - 1]);

}


#include<stdio.h>
#include<string.h>
main()
{
char a[101], b[20][101];
int c,d,e,f,x,y,z;
scanf("%s",&a);
scanf("%d",&c);
strcpy(b[1],"January");
strcpy(b[2],"February");
strcpy(b[3],"March");
strcpy(b[4],"April");
strcpy(b[5],"May");
strcpy(b[6],"June");
strcpy(b[7],"July");
strcpy(b[8],"August");
strcpy(b[9],"September");
strcpy(b[10],"October");
strcpy(b[11],"November");
strcpy(b[12],"December");
c=c%12;
for(x=1;x<=12;x=x+1)
{
if(strcmp(a,b[x])==0)
{
d=(c+x)%12;
break;
}
}
printf("%s",b[d]);
return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    string ssin;
    cin>>ssin;
    int n;
    cin>>n;
    int tempin,tempout;
    if(ssin=="January") tempin=1;
    if(ssin=="February") tempin=2;
    if(ssin=="March") tempin=3;
    if(ssin=="April") tempin=4;
    if(ssin=="May") tempin=5;
    if(ssin=="June") tempin=6;
    if(ssin=="July") tempin=7;
    if(ssin=="August") tempin=8;
    if(ssin=="September") tempin=9;
    if(ssin=="October") tempin=10;
    if(ssin=="November") tempin=11;
    if(ssin=="December") tempin=12;
    tempout=(n+tempin)%12;
    if(tempout==1) cout<<"January";
    if(tempout==2) cout<<"February";
    if(tempout==3) cout<<"March";
    if(tempout==4) cout<<"April";
    if(tempout==5) cout<<"May";
    if(tempout==6) cout<<"June";
    if(tempout==7) cout<<"July";
    if(tempout==8) cout<<"August";
    if(tempout==9) cout<<"September";
    if(tempout==10) cout<<"October";
    if(tempout==11) cout<<"November";
    if(tempout==12) cout<<"December";
}


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

int main(int argc, char *argv[]) {
	long *players;
	char *gPlayers;
	long i;
	long num;
	scanf("%l", &num);
	players = malloc(sizeof(long)*num);
	gPlayers = malloc(sizeof(char)*num);
	scanf("%s", gPlayers);
	for(i=0;i<num;i++) {
		scanf("%d", players+i);
	}

	for(i=0;i<num;i++) {

	}
	return 0;
}


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

int main(){
    int a;
    char str[7] = "";
    scanf("%d", &a);
    sprintf(str, "%d", a);
    while(strlen(str) > 1){
        a = 0;
        for(int i = 0; i < strlen(str); i++){
            a = a + str[i] - '0';
        }
        sprintf(str, "%d", a);
    }
    printf("%d", atoi(str));
}


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

int main()
{
     int x,y,z,i,j,k,a,b,c = 0,n,m,t;
     scanf("%d",&a);

     loop:
     while(a > 0)
     {
          c += a%10;
          a /= 10;
     }
     if(c >= 10)
     {
          a = c;
          goto loop;
     }
     printf("%d\n",c);
     return 0;
}


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

int main()
{
    int n;
    cin>>n;
    if (n % 9 == 0)
        printf("9\n");
    else
        printf("%d\n",(n % 9));
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    if (n % 9 == 0)
        cout<<"9\n";
    else
        cout<<(n % 9)<<'\n';
    return 0;
}


#include<stdio.h>
int main()
{
    int n,x[100],sum=0,i;
    scanf("%d",&n);
    while(n!=0)
    {
        x[i++]=n%10;
        n=n/10;
    }
    for(int j=0;j<i;j++){
sum=sum+x[j];
    }
    printf("%d\n",sum);
}


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

#define N	20000

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

long long dot2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * x2 + (long long) y1 * y2;
}

long long cross2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

int xx[N + 1], yy[N + 1];

long long cross(int i, int j, int k) {
	return cross2(xx[j] - xx[i], yy[j] - yy[i], xx[k] - xx[i], yy[k] - yy[i]);
}

int aa[N + 1], dp[N + 1], dq[N + 1], n;

void solve(int l, int r) {
	static int qu[N + 1], qq[N + 1], pp[N + 1];
	int m, h, i, j, q, p, cnt;

	if (r - l == 1)
		return;
	m = (l + r) / 2;
	solve(l, m);
	solve(m, r);
	q = 0;
	for (i = m - 1; i >= l; i--)
		qq[i] = q = max(q, aa[i]);
	p = 0;
	for (i = m; i < r; i++)
		pp[i] = p, p = max(p, aa[i]);
	cnt = 0;
	for (j = m, i = m - 1, h = 0; j < r; j++) {
		while (i >= l && qq[i] <= pp[j]) {
			xx[i] = i, yy[i] = dp[i];
			while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
				cnt--;
			qu[cnt++] = i;
			if (h >= cnt - 2)
				h = cnt - 1;
			i--;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], pp[j], -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], pp[j], -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], pp[j] * j - dot2(xx[qu[h]], yy[qu[h]], pp[j], -1));
	}
	cnt = 0;
	for (j = r - 1, i = l, h = 0; j >= m; j--) {
		while (i < m && qq[i] > pp[j]) {
			xx[i] = qq[i], yy[i] = dp[i] - qq[i] * i;
			if (cnt && xx[qu[cnt - 1]] == xx[i]) {
				if (yy[qu[cnt - 1]] > yy[i])
					qu[cnt - 1] = i;
			} else {
				while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
					cnt--;
				qu[cnt++] = i;
			}
			if (h >= cnt - 2)
				h = cnt - 1;
			i++;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], -j, -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], -j, -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], -dot2(xx[qu[h]], yy[qu[h]], -j, -1));
	}
}

int main() {
	int k, i;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	memset(dp, 0x3f, (n + 1) * sizeof *dp), dp[0] = 0;
	while (k--) {
		memset(dq, 0x3f, (n + 1) * sizeof *dq);
		solve(0, n + 1);
		memcpy(dp, dq, (n + 1) * sizeof *dp);
	}
	printf("%d\n", dp[n]);
	return 0;
}


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

#define N	20000

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

long long dot2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * x2 + (long long) y1 * y2;
}

long long cross2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

int xx[N + 1], yy[N + 1];

long long cross(int i, int j, int k) {
	return cross2(xx[j] - xx[i], yy[j] - yy[i], xx[k] - xx[i], yy[k] - yy[i]);
}

int aa[N + 1], dp[N + 1], dq[N + 1];

void solve(int l, int r) {
	static int qu[N + 1], qq[N + 1], pp[N + 1];
	int m, h, i, j, q, p, cnt;

	if (r - l == 1)
		return;
	m = (l + r) / 2;
	solve(l, m), solve(m, r);
	q = 0;
	for (i = m - 1; i >= l; i--)
		qq[i] = q = max(q, aa[i]);
	p = 0;
	for (i = m; i < r; i++)
		pp[i] = p, p = max(p, aa[i]);
	cnt = 0;
	for (j = m, i = m - 1, h = 0; j < r; j++) {
		while (i >= l && qq[i] <= pp[j]) {
			xx[i] = i, yy[i] = dp[i];
			while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
				cnt--;
			if (h >= cnt - 1)
				h = cnt;
			qu[cnt++] = i--;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], pp[j], -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], pp[j], -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], pp[j] * j - dot2(xx[qu[h]], yy[qu[h]], pp[j], -1));
	}
	cnt = 0;
	for (j = r - 1, i = l, h = 0; j >= m; j--) {
		while (i < m && qq[i] > pp[j]) {
			xx[i] = qq[i], yy[i] = dp[i] - qq[i] * i;
			while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
				cnt--;
			if (h >= cnt - 1)
				h = cnt;
			qu[cnt++] = i++;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], -j, -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], -j, -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], -dot2(xx[qu[h]], yy[qu[h]], -j, -1));
	}
}

int main() {
	int n, k, h, i;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	memset(dp, 0x3f, (n + 1) * sizeof *dp), dp[0] = 0;
	for (h = 1; h <= k; h++) {
		memset(dq, 0x3f, (n + 1) * sizeof *dq), dq[0] = 0;
		solve(0, n + 1);
		memcpy(dp, dq, (n + 1) * sizeof *dp);
	}
	printf("%d\n", dp[n]);
	return 0;
}


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

#define N	20000

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

long long dot2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * x2 + (long long) y1 * y2;
}

long long cross2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

int xx[N + 1], yy[N + 1];

long long cross(int i, int j, int k) {
	return cross2(xx[j] - xx[i], yy[j] - yy[i], xx[k] - xx[i], yy[k] - yy[i]);
}

int aa[N + 1], dp[N + 1], dq[N + 1], n;

void solve(int l, int r) {
	static int qu[N + 1], qq[N + 1], pp[N + 1];
	int m, h, i, j, q, p, cnt;

	if (r - l == 1)
		return;
	m = (l + r) / 2;
	solve(l, m);
	solve(m, r);
	q = 0;
	for (i = m - 1; i >= l; i--)
		qq[i] = q = max(q, aa[i]);
	p = 0;
	for (i = m; i < r; i++)
		pp[i] = p, p = max(p, aa[i]);
	cnt = 0;
	for (j = m, i = m - 1, h = 0; j < r; j++) {
		while (i >= l && qq[i] <= pp[j]) {
			xx[i] = i, yy[i] = dp[i];
			while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
				cnt--;
			qu[cnt++] = i;
			if (h >= cnt - 2)
				h = cnt - 1;
			i--;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], pp[j], -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], pp[j], -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], pp[j] * j - dot2(xx[qu[h]], yy[qu[h]], pp[j], -1));
	}
	cnt = 0;
	for (j = r - 1, i = l, h = 0; j >= m; j--) {
		while (i < m && qq[i] > pp[j]) {
			xx[i] = qq[i], yy[i] = dp[i] - qq[i] * i;
			if (cnt && xx[qu[cnt - 1]] == xx[i]) {
				if (yy[qu[cnt - 1]] > yy[i])
					qu[cnt - 1] = i;
			} else {
				while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
					cnt--;
				qu[cnt++] = i;
			}
			if (h >= cnt - 2)
				h = cnt - 1;
			i++;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], -j, -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], -j, -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], -dot2(xx[qu[h]], yy[qu[h]], -j, -1));
	}
}

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

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	memset(dp, 0x1f, (n + 1) * sizeof *dp), dp[0] = 0;
	k = 6;
	while (k--) {
		memset(dq, 0x1f, (n + 1) * sizeof *dq);
		solve(0, n + 1);
		memcpy(dp, dq, (n + 1) * sizeof *dp);
	}
	printf("%d\n", dp[n]);
	return 0;
}


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

#define N	20000

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

long long dot2(long long x1, long long y1, long long x2, long long y2) {
	return (long long) x1 * x2 + (long long) y1 * y2;
}

long long cross2(long long x1, long long y1, long long x2, long long y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

long long xx[N + 1], yy[N + 1];

long long cross(int i, int j, int k) {
	return cross2(xx[j] - xx[i], yy[j] - yy[i], xx[k] - xx[i], yy[k] - yy[i]);
}

int aa[N + 1], dp[N + 1], dq[N + 1], n;

void solve(int l, int r) {
	static int qu[N + 1], qq[N + 1], pp[N + 1];
	int m, h, i, j, q, p, cnt;

	if (r - l == 1)
		return;
	m = (l + r) / 2;
	solve(l, m);
	solve(m, r);
	q = 0;
	for (i = m - 1; i >= l; i--)
		qq[i] = q = max(q, aa[i]);
	p = 0;
	for (i = m; i < r; i++)
		pp[i] = p, p = max(p, aa[i]);
	cnt = 0;
	for (j = m, i = m - 1, h = 0; j < r; j++) {
		while (i >= l && qq[i] <= pp[j]) {
			xx[i] = i, yy[i] = dp[i];
			while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
				cnt--;
			qu[cnt++] = i;
			if (h >= cnt - 2)
				h = cnt - 1;
			i--;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], pp[j], -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], pp[j], -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], pp[j] * j - dot2(xx[qu[h]], yy[qu[h]], pp[j], -1));
	}
	cnt = 0;
	for (j = r - 1, i = l, h = 0; j >= m; j--) {
		while (i < m && qq[i] > pp[j]) {
			xx[i] = qq[i], yy[i] = dp[i] - qq[i] * i;
			if (cnt && xx[qu[cnt - 1]] == xx[i]) {
				if (yy[qu[cnt - 1]] > yy[i])
					qu[cnt - 1] = i;
			} else {
				while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
					cnt--;
				qu[cnt++] = i;
			}
			if (h >= cnt - 2)
				h = cnt - 1;
			i++;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], -j, -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], -j, -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], -dot2(xx[qu[h]], yy[qu[h]], -j, -1));
	}
}

int main() {
	int k, i;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	memset(dp, 0x3f, (n + 1) * sizeof *dp), dp[0] = 0;
	while (k--) {
		memset(dq, 0x3f, (n + 1) * sizeof *dq);
		solve(0, n + 1);
		memcpy(dp, dq, (n + 1) * sizeof *dp);
	}
	printf("%d\n", dp[n]);
	return 0;
}


// PRIME1 - C99 (gcc)
// AC Time: 0.07s
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main() {
    int primes[4000];
    int numprimes = 0;

    primes[numprimes++] = 2;
    for (int i = 3; i <= 32000; i+=2) {
        bool isprime = true;
        int cap = sqrt(i)+1;
        for (int j = 0; j < numprimes; j++) {
            if (primes[j] >= cap) break;
            if (i % primes[j] == 0) {
                isprime = false;
                break;
            }
        }
        if (isprime) primes[numprimes++] = i;
    }

    int N,M;

    scanf("%d %d",&M,&N);
    int start = N%2?(N-2):N-1;
    for (int i = start; i > M; i-=2) {
        // printf("Checking %d\n",i);
        bool isprime = true;
        int cap = sqrt(i)+1;
        for (int j = 0; j < numprimes; j++) {
            // printf("%d\n",primes[j]);
            if (primes[j] >= cap or primes[j] > M) break;
            if (i % primes[j] == 0) {
                isprime = false;
                break;
            }
        }
        if (isprime){
            printf("%d\n", i);return 0;
        }
    }
    printf("-1\n");
    return 0;
}


#include<stdio.h>
#include<malloc.h>
#include<math.h>
int isPrime(int n)
{
	// Corner cases
	if (n <= 1)  return 0;
	if (n <= 3)  return 1;

	// This is checked so that we can skip
	// middle five numbers in below loop
	if (n % 2 == 0 || n % 3 == 0) return 0;

	for (int i = 5; i*i <= n; i = i + 6)
		if (n%i == 0 || n % (i + 2) == 0)
			return 0;

	return 1;
}

int main()
{
	int y, p;
	int c = 0;
	scanf("%d %d", &p, &y);
	int i = y;
	while (i > p)
	{
		if (i % 2 == 0)
			i--;
		else
		{
			if (isPrime(i))
			{
				printf("%d", i);
				c = 1;
				break;
			}
			if (sqrt(i) <= p)
				i--;
			else
			{
				printf("%d", i);
				c = 1;
				break;
			}
		}
	}
	if (c == 0)
		printf("-1");
	return 0;
}
close


#include<stdio.h>
#include<malloc.h>
#include<math.h>
int isPrime(int n)
{
	// Corner cases
	if (n <= 1)  return 0;
	if (n <= 3)  return 1;

	// This is checked so that we can skip
	// middle five numbers in below loop
	if (n % 2 == 0 || n % 3 == 0) return 0;

	for (int i = 5; i*i <= n; i = i + 6)
		if (n%i == 0 || n % (i + 2) == 0)
			return 0;

	return 1;
}

int main()
{
	int y, p;
	int c = 0;
	scanf("%d %d", &p, &y);
	int i = y;
	while (i > p)
	{
		if (i % 2 == 0)
			i--;
		else
		{
			if (isPrime(i))
			{
				printf("%d", i);
				c = 1;
				break;
			}
			if (sqrt(i) <= p)
				i--;
			else
			{
				int j = p;
				int c1 = 0;
				while (j > 2)
				{
					if (i%j == 0)
					{
						c1 = 1;
						break;
					}
					j--;
				}
				if (c1 = 1)
					i--;
				else
				{
					printf("%d", i);
					c = 1;
					break;
				}
			}
		}
	}
	if (c == 0)
		printf("-1")
	return 0;
}


#include<stdio.h>
#include<malloc.h>
#include<math.h>
int isPrime(int n)
{
	// Corner cases
	if (n <= 1)  return 0;
	if (n <= 3)  return 1;

	// This is checked so that we can skip
	// middle five numbers in below loop
	if (n % 2 == 0 || n % 3 == 0) return 0;

	for (int i = 5; i*i <= n; i = i + 6)
		if (n%i == 0 || n % (i + 2) == 0)
			return 0;

	return 1;
}

int main()
{
	int y, p;
	int c = 0;
	scanf("%d %d", &p, &y);
	int i = y;
	while (i > p)
	{
		if (i % 2 == 0)
			i--;
		else
		{
			if (isPrime(i))
			{
				printf("%d", i);
				c = 1;
				break;
			}
			if (sqrt(double(i)) <= p)
				i--;
			else
			{
				printf("%d", i);
				c = 1;
				break;
			}
		}
	}
	if (c == 0)
		printf("-1");
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
	int data;
	struct node* next;
};
struct node** hash;
int size=100001;
void init_hash()
{
	int i;
	for(i=0;i<size;i++)
	 hash[i]=0;
}
void hash_it(int data)
{
	int pos=data%size;
	struct node* head=malloc(sizeof(struct node));
	head->data=data;
	head->next=hash[pos];
	hash[pos]=head;
}
int is_present(int data)
{
	int pos=data%size;
	struct node* cur=hash[pos];
	while(cur)
	{
		if(cur->data==data)
		{
			return 1;
		}
		cur=cur->next;
	}
	return 0;
}
int main()
{
	int p,y;
	int i,j,k;
	hash=malloc(size*sizeof(struct node*));
	init_hash();
	scanf("%d %d",&p,&y);
	int flag=0;
	for(i=2;i<=p;i++)
	{
		if(!is_present(i))
		{
			for(j=i;j<=end;j+=i)
			{
				if(j>p)
				 hash_it(j);
			}
		}
	}
	for(i=y;i>p;i--)
	{
		if(!is_present(i))
		{
			printf("%d\n",i);
			flag=1;
			break;
		}
	}
	if(!flag)
	 printf("-1");
	return 0;
}


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

int main()
{
	int t,n,l,k,d[200],a[200],flag,i,tmr,temp;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d %d",&n,&k,&l);
		for(i=0;i<n;i++)
		{
			scanf("%d",&d[i]);
		}
		flag=0,tmr=1000;
		for(i=0;i<n;i++)
		{
			if(d[i]+k<=l)
			{
				a[i]=d[i];
				tmr=1000;
			}
			else if(d[i]>l)
			{
				flag=1;
				// printf("%d-%d\n",d[i],i);
				break;
			}
			else if(d[i]+k>l)
			{
				if(i==0 || tmr==1000)
				{
					a[i]=l;
					tmr=l-d[i];
				}
				else
				{
					if(tmr>0)
					{
						temp=a[i-1]-d[i-1];
						a[i]=d[i]+temp-1;
						if(a[i]<=l)
						{
							tmr=tmr-1;
						}
						else
						{
							temp=a[i]-l;
							tmr=tmr-temp-1;
							a[i]=l;
						}
					}
					else
					{
						if(a[i-1]+1>l)
						{
							flag=1;
							// printf("hi\n");
							break;
						}
						else
						{
							a[i]=a[i-1]+1;
							tmr=tmr-1;
						}
						if(tmr==-k)
						{
							tmr=k;
						}
					}
				}
			}
		}
		if(flag==1)
		{
			printf("No\n");
		}
		else
		{
			printf("Yes\n");
		}
	}
}


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

int main()
{
	int t,n,l,k,d[200],a[200],flag,i,tmr,temp;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d %d",&n,&k,&l);
		for(i=0;i<n;i++)
		{
			scanf("%d",&d[i]);
		}
		flag=0,tmr=1000;
		for(i=0;i<n;i++)
		{
			if(d[i]+k<=l)
			{
				a[i]=d[i];
				tmr=1000;
			}
			else if(d[i]>l)
			{
				flag=1;
				// printf("%d-%d\n",d[i],i);
				break;
			}
			else if(d[i]+k>l)
			{
				if(i==0 || tmr==1000)
				{
					a[i]=l;
					tmr=l-d[i];
				}
				else
				{
					if(tmr>0)
					{
						temp=a[i-1]-d[i-1];
						a[i]=d[i]+tmr-1;
						tmr--;
						while(a[i]>l)
						{
							a[i]--;
							tmr--;
						}
					}
					else
					{
						tmr=tmr-1;
						if(d[i]-tmr>l)
						{
							flag=1;
							// printf("%d\n",i);
							break;
						}
						else
						{
							a[i]=d[i]-tmr;
						}
						// if(tmr==-k)
						// {
						// 	tmr=k;
						// }
					}
				}
			}
		}
		if(flag==1)
		{
			printf("No\n");
		}
		else
		{
			printf("Yes\n");
		}
	}
}


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

int main()
{
	long long int t,n,l,k,d[200],a[200],flag,i,tmr,temp;
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld %lld %lld",&n,&k,&l);
		for(i=0;i<n;i++)
		{
			scanf("%lld",&d[i]);
		}
		flag=0,tmr=1000;
		for(i=0;i<n;i++)
		{
			if(d[i]+k<=l)
			{
				a[i]=d[i];
				tmr=1000;
			}
			else if(d[i]>l)
			{
				flag=1;
				// printf("%d-%d\n",d[i],i);
				break;
			}
			else if(d[i]+k>l)
			{
				if(i==0 || tmr==1000)
				{
					a[i]=l;
					tmr=l-d[i];
				}
				else
				{
					if(tmr>0)
					{
						temp=a[i-1]-d[i-1];
						a[i]=d[i]+tmr-1;
						tmr--;
						if(a[i]>l)
						{
							tmr=tmr-(a[i]-l);
							a[i]=l;
						}
					}
					else
					{
						tmr=tmr-1;
						if(d[i]-tmr>l)
						{
							flag=1;
							// printf("%d\n",i);
							break;
						}
						else
						{
							a[i]=d[i]-tmr;
						}
						// if(tmr==-k)
						// {
						// 	tmr=k;
						// }
					}
				}
			}
		}
		if(flag==1)
		{
			printf("No\n");
		}
		else
		{
			printf("Yes\n");
		}
	}
}


#include<stdio.h>
main()
{
      int n,m,a,b,r1,r2,ans;

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

      if (a==b)
         ans=1;
      else if (m==1)
         ans=1;
      else
      {
          r1=a%m;
          r2=b%m;
          if (b==n)
          {
             if (r2==0)
                r2=m;
             if (r1==1||r2-(b-a)>0)
                ans=1;
             else
                ans=2;
          }

          else if (r1==1&&r2==0)
             ans=1;
          else if (r1==1)
          {
               if (r1+b-a<=m)
                  ans=1;
               else
                  ans=2;
          }
          else if (r2==0)
          {
               if (m-(b-a)>=0)
                  ans=1;
               else
                  ans=2;
          }
          else
          {
            if (r1==0)
               r1=m;
            if (r1+(b-a)<=m)
                ans=1;
            else if (m-r1+r2==b-a)
                ans=2;
            else
            {
               if (r2+1==r1)
                 ans=2;
               else
                ans=3;
            }
          }
      }

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

      return 0;
}