#include <stdio.h>
#include <stdlib.h>
#define Ma 35+5
typedef long long ll;
ll dp[Ma+1][Ma+1],small[Ma+1][Ma+1];
int n,h,i,j,k;
ll agg;
int main(void)
{
    scanf("%d %d",&n,&h);
    dp[0][0]=1;
    for(j=0;j<=Ma;++j) small[0][j]=1;
    dp[1][1]=1;
    for(i=1;i<=n;++i){
    	for(j=2;j<=Ma;++j){
    		for(k=0;k<i;++k){
    			dp[i][j]+= small[k][j-1] * dp[i-k-1][j-1];
    			dp[i][j]+= dp[k][j-1]    * small[i-k-1][j-2];
    		}
    	}
    	agg=0;
    	for(k=0;k<=Ma;++k)
    		agg+=dp[i][k],small[i][k]=agg;
    }
    for(k=h,agg=0;k<=Ma;++k)
    	agg+=dp[n][k];
    printf("%lli\n",agg);
	return 0;
}


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

typedef long long int lli;//se declara lli como tipo de dato long long int
lli matriz[36][36];//una matriz de 36*36 de tipo lli

int main(int argc, char const *argv[]){
    int n,h;
    scanf("%d%d",&n,&h);

    for(int k=1;k<=n;k++){
        matriz[0][k-1]=1;
        for(int i=1;i<=n;i++)
        	for(int j=0;j<i;j++)
        		matriz[i][k]+= matriz[j][k-1]*matriz[i-1-j][k-1];
    }

    printf("%I64d",matriz[n][n]-matriz[n][h-1]);

    return 0;
}


#include<stdio.h>

#define SIZE_N 36

typedef __int64 llg;

llg fit[SIZE_N][SIZE_N];

void initeFit()
{
    int i,j,k;

    fit[0][0] = 1;
    for(i = 1;i < SIZE_N;i ++) {
        for(j = 1;j <= i;j ++) {
            for(k = 0;k < i;k ++) {
                fit[i][j] += fit[k][j-1] * fit[i-k-1][0] + fit[k][0] * fit[i-k-1][j-1] - fit[k][j-1] * fit[i-k-1][j-1];
            }
        }
        fit[i][0] = fit[i][1];
    }
}

int main()
{
    int n,h;

    initeFit();
    while(scanf("%d%d",&n,&h) != EOF) {
        printf("%I64d\n",fit[n][h]);
    }
    return 0;
}


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

int main() {
	long long **dp, *trees;
	int n, h;
	int i, j, n1, n2;

	scanf("%d%d", &n, &h);
	trees = calloc(n + 1, sizeof(long long));
	dp = calloc(n + 1, sizeof(long long *));
	dp[0] = calloc(n + 1, sizeof(long long));
	dp[1] = calloc(n + 1, sizeof(long long));

	trees[0] = 1;
	for (i = 1; i <= n; i++)
		for (n1 = 0; n1 < i; n1++) {
			n2 = i - 1 - n1;
			trees[i] += (trees[n1] * trees[n2]);
		}

	dp[1][0] = dp[1][1] = 1;
	for (i = 2; i <= n; i++) {
		dp[i] = calloc(n + 1, sizeof(long long));
		for (j = 1; j <= i; j++) {
			for (n1 = 0; n1 < i; n1++) {
				n2 = i - 1 - n1;
				dp[i][j] += (trees[n1] * dp[n2][j - 1]);
				dp[i][j] += (trees[n2] * dp[n1][j - 1]);
				dp[i][j] -= (dp[n1][j - 1] * dp[n2][j - 1]);
			 }
		}
		dp[i][0] = dp[i][1];
	}
	printf("%lld\n", dp[n][h]);
	return 0;
}


 #include<stdio.h>

#define SIZE_N 36

typedef __int64 llg;

llg fit[SIZE_N][SIZE_N];

void initeFit()
{
    int i,j,k;

    fit[0][0] = 1;
    for(i = 1;i < SIZE_N;i ++) {
        for(j = 1;j <= i;j ++) {
            for(k = 0;k < i;k ++) {
                fit[i][j] += fit[k][j-1] * fit[i-k-1][0] + fit[k][0] * fit[i-k-1][j-1] - fit[k][j-1] * fit[i-k-1][j-1];
            }
        }
        fit[i][0] = fit[i][1];
    }
}

int main()
{
    int n,h;

    initeFit();
    while(scanf("%d%d",&n,&h) != EOF) {
        printf("%I64d\n",fit[n][h]);
    }
    return 0;
}
→Judgement Protocol
Prueba: # 1, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
3 2
Salida
5
Responder
5
corrector de registro
ok 1 number(s): "5"
Prueba: # 2, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
3 3
Salida
4
Responder
4
corrector de registro
ok 1 number(s): "4"
Prueba: # 3, tiempo: 0ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
1 1
Salida
1
Responder
1
corrector de registro
ok 1 number(s): "1"
Prueba: # 4, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
2 1
Salida
2
Responder
2
corrector de registro
ok 1 number(s): "2"
Prueba: # 5, tiempo: 30ms, la memoria:. 16KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
2 2
Salida
2
Responder
2
corrector de registro
ok 1 number(s): "2"
Prueba: # 6, tiempo: 30ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
27 11
Salida
61162698256896
Responder
61162698256896
corrector de registro
ok 1 number(s): "61162698256896"
Prueba: # 7, tiempo: 0ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
32 27
Salida
22643872890880
Responder
22643872890880
corrector de registro
ok 1 number(s): "22643872890880"
Prueba: # 8, tiempo: 30ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
4 1
Salida
14
Responder
14
corrector de registro
ok 1 number(s): "14"
Prueba: # 9, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
9 1
Salida
4862
Responder
4862
corrector de registro
ok 1 number(s): "4862"
Prueba: # 10, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
33 4
Salida
212336130412243110
Responder
212336130412243110
corrector de registro
ok 1 number(s): "212336130412243110"
Prueba: # 11, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
4 4
Salida
8
Responder
8
corrector de registro
ok 1 number(s): "8"
Prueba: # 12, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
8 5
Salida
1336
Responder
1336
corrector de registro
ok 1 number(s): "1336"
Prueba: # 13, tiempo: 30ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
12 8
Salida
127200
Responder
127200
corrector de registro
ok 1 number(s): "127200"
Prueba: # 14, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
15 5
Salida
9694844
Responder
9694844
corrector de registro
ok 1 number(s): "9694844"
Prueba: # 15, tiempo: 0ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
19 18
Salida
2424832
Responder
2424832
corrector de registro
ok 1 number(s): "2424832"
Prueba: # 16, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
23 17
Salida
19649347584
Responder
19649347584
corrector de registro
ok 1 number(s): "19649347584"
Prueba: # 17, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
27 15
Salida
25162319484928
Responder
25162319484928
corrector de registro
ok 1 number(s): "25162319484928"
Prueba: # 18, tiempo: 0ms, la memoria:. 0KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
29 14
Salida
577801978306560
Responder
577801978306560
corrector de registro
ok 1 number(s): "577801978306560"
Prueba: # 19, tiempo: 30ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
33 18
Salida
54307238601375744
Responder
54307238601375744
corrector de registro
ok 1 number(s): "54307238601375744"
Prueba: # 20, tiempo: 30ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
7 7
Salida
64
Responder
64
corrector de registro
ok 1 number(s): "64"
Prueba: # 21, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
23 21
Salida
275251200
Responder
275251200
corrector de registro
ok 1 number(s): "275251200"
Prueba: # 22, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
7 3
Salida
429
Responder
429
corrector de registro
ok 1 number(s): "429"
Prueba: # 23, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
21 18
Salida
211156992
Responder
211156992
corrector de registro
ok 1 number(s): "211156992"
Prueba: # 24, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
4 1
Salida
14
Responder
14
corrector de registro
ok 1 number(s): "14"
Prueba: # 25, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
21 12
Salida
12153990144
Responder
12153990144
corrector de registro
ok 1 number(s): "12153990144"
Prueba: # 26, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
35 13
Salida
2690352397519398400
Responder
2690352397519398400
corrector de registro
ok 1 number(s): "2690352397519398400"
Prueba: # 27, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
19 2
Salida
1767263190
Responder
1767263190
corrector de registro
ok 1 number(s): "1767263190"
Prueba: # 28, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
33 26
Salida
434871797284864
Responder
434871797284864
corrector de registro
ok 1 number(s): "434871797284864"
Prueba: # 29, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
16 9
Salida
25607552
Responder
25607552
corrector de registro
ok 1 number(s): "25607552"
Prueba: # 30, tiempo: 0ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
16 14
Salida
1032192
Responder
1032192
corrector de registro
ok 1 number(s): "1032192"
Prueba: # 31, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
10 2
Salida
16796
Responder
16796
corrector de registro
ok 1 number(s): "16796"
Prueba: # 32, tiempo: 30ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
4 4
Salida
8
Responder
8
corrector de registro
ok 1 number(s): "8"
Prueba: # 33, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
33 17
Salida
75307983624118272
Responder
75307983624118272
corrector de registro
ok 1 number(s): "75307983624118272"
Prueba: # 34, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
27 25
Salida
6081740800
Responder
6081740800
corrector de registro
ok 1 number(s): "6081740800"
Prueba: # 35, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
20 14
Salida
1094473728
Responder
1094473728
corrector de registro
ok 1 number(s): "1094473728"
Prueba: # 36, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
16 11
Salida
11819008
Responder
11819008
corrector de registro
ok 1 number(s): "11819008"
Prueba: # 37, tiempo: 30ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
10 10
Salida
512
Responder
512
corrector de registro
ok 1 number(s): "512"
Prueba: # 38, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
4 3
Salida
14
Responder
14
corrector de registro
ok 1 number(s): "14"
Prueba: # 39, tiempo: 0ms, la memoria:. 0KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
33 21
Salida
14830955929665536
Responder
14830955929665536
corrector de registro
ok 1 number(s): "14830955929665536"
Prueba: # 40, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
24 20
Salida
8171945984
Responder
8171945984
corrector de registro
ok 1 number(s): "8171945984"
Prueba: # 41, tiempo: 0ms, la memoria:. 16KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
30 16
Salida
1375710400053248
Responder
1375710400053248
corrector de registro
ok 1 number(s): "1375710400053248"
Prueba: # 42, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
3 2
Salida
5
Responder
5
corrector de registro
ok 1 number(s): "5"
Prueba: # 43, tiempo: 0ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
9 4
Salida
4862
Responder
4862
corrector de registro
ok 1 number(s): "4862"
Prueba: # 44, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
16 5
Salida
35357670
Responder
35357670
corrector de registro
ok 1 number(s): "35357670"
Prueba: # 45, tiempo: 0ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
22 22
Salida
2097152
Responder
2097152
corrector de registro
ok 1 number(s): "2097152"
Prueba: # 46, tiempo: 30ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
28 23
Salida
739948625920
Responder
739948625920
corrector de registro
ok 1 number(s): "739948625920"
Prueba: # 47, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
34 1
Salida
812944042149730764
Responder
812944042149730764
corrector de registro
ok 1 number(s): "812944042149730764"
Prueba: # 48, tiempo: 30ms, la memoria:. 4KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
7 4
Salida
428
Responder
428
corrector de registro
ok 1 number(s): "428"
Prueba: # 49, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
14 11
Salida
488448
Responder
488448
corrector de registro
ok 1 number(s): "488448"
Prueba: # 50, tiempo: 0ms, la memoria:. 12KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
35 1
Salida
3116285494907301262
Responder
3116285494907301262
corrector de registro
ok 1 number(s): "3116285494907301262"
Prueba: # 51, tiempo: 0ms, la memoria:. 8KB, código de salida: 0, código de salida corrector: 0, veredicto:OK
Entrada
35 35
Salida
17179869184
Responder
17179869184
corrector de registro
ok 1 number(s): "17179869184"
close


#include <cstdio>
#include <numeric>
#include <algorithm>
using namespace std;

const int mxN = 2e5+5;
int n, a[105], dp[105][mxN];
int main() {
	scanf("%d", &n);
	int sum = 0;
	for(int i=0; i<n; ++i) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum&1) {
		printf("0\n");
		return 0;
	}
	sum /=2;
	auto check = [&]() -> bool {
		for(int i=1; i<=n; ++i)
			for(int j=0; j<=sum; ++j) {
				if(a[i-1] > j)
					dp[i][j] = dp[i-1][j];
				else
					dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i-1]]+1);
			}
		return dp[n][sum];
	};
	if(!check())
		printf("0\n");
	else {
		int tmp=0, ans=1;
		for(int i=0; i<n; ++i) {
			tmp = gcd(tmp, a[i]);
		}

		for(int i=0; i<n; ++i) {
			a[i] /= tmp;
			if(a[i]&1)
				ans=i+1;
		}
		printf("1\n%d\n", ans);
	}
}


/* Codeforce 1516c: Baby Ehab Partitions Again */

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

#define N_INT      105
#define MAX_SUM 200005
#define min(a,b) ((a)<(b)? (a): (b))

char got [MAX_SUM];

int issumto(int a[], int n, int sum)
{ int i,j,last;

  memset(got, 0, sum+1);  got[0]=1;  last=0;
  for(i=0; i<n; i++) {
    for(j=last; j>=0; j--)
      if(got[j])  got[j+a[i]] = 1;
    last = min(last+a[i], sum);
  }
  return got[sum];
}

int main(int argc, char *argv[])
{ int i,n, sum, ans;
  int a [N_INT];

  scanf("%d", &n);
  for(sum=i=0; i<n; i++) {
    scanf("%d", a+i);
    sum += a[i];
  }
  if(sum&1)                { ans = 0;  goto done; }
  if(! issumto(a,n,sum/2)) { ans = 0;  goto done; }

  while(1)
    for(i=0; i<n; i++)
      if(a[i] & 1) {ans = i + 1; goto done; }
      else         a[i] /= 2;

done:
  printf("%d\n", ans!=0);
  if(ans)
    printf("%d\n", ans);
  return 0;
}


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

bool possible[200100];

int main(void) {
  int n;
  int a[110];
  scanf("%d", &n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  if (sum % 2 == 1) {
    puts("0");
    return 0;
  }
  int target = sum / 2;
  int smallest_power = 10;
  possible[0] = true;
  for (int i = 0; i < n; i++) {
    int ctz = __builtin_ctz(a[i]);
    if (ctz < smallest_power) smallest_power = ctz;
    for (int j = target; j >= a[i]; j--) {
      if (possible[j - a[i]]) possible[j] = true;
    }
  }
  if (!possible[target]) {
    puts("0");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if ((a[i] >> smallest_power) % 2 == 1) {
      printf("1\n%d\n", i + 1);
      return 0;
    }
  }
  assert(false);
  return 0;
}


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

int main(){
        int n;
        scanf("%d",&n);
        int arr[n];
        int sum=0;

        for(int j=0;j<n;j++){
            scanf("%d",&arr[j]);
            sum+=arr[j];
        }

        if((sum%2)==1){
            printf("0\n");
            return 0;
        }

        int knapsack[n][sum+1];

        for(int j=0;j<n;j++){
            for(int k=0;k<=sum;k++){
                knapsack[j][k]=0;
            }
        }

        for(int j=0;j<n;j++){
            knapsack[j][arr[j]]=1;
            if(j==n-1)
                break;
            for(int k=0;k<=sum;k++){
                if(knapsack[j][k]!=0){
                    knapsack[j+1][k]=knapsack[j][k];
                    int temp=k+arr[j+1];
                    knapsack[j+1][temp]=knapsack[j][k]+1;
                }
            }
        }

        int temp=sum/2;

        if(knapsack[n-1][temp]==0){
            printf("0\n");
            return 0;
        }

        printf("1\n");
        for(int i=0;i<11;i++){
            for(int j=0;j<n;j++){
                temp=1<<i;
                if((arr[j]&temp)==temp){
                    printf("%d\n",(j+1));
                    return 0;
                }
            }
        }
    return 0;

}


#include <stdio.h>

unsigned loopCounts[16] = { 1, 0, 0, 0, 1, 0, 1, 0, 2, 1, 1, 2, 0, 2, 0, 0 };

int main() {
  unsigned n;
  scanf("%u", &n);
  unsigned loopCount = 0;
  while (n) {
    loopCount += loopCounts[n & 0xf];
    n >>= 4;
  }
  printf("%u\n", loopCount);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef long long unsigned llu;
typedef unsigned u;
typedef struct S
{
	u val,ki,ka,min,max;llu sum;
	struct S *lc,*rc;
}v;
v*alloc(u ki,u ka,u val)
{
	v*x;
	x=(v*)malloc(sizeof(v));
	x->val=val;
	x->min=val;
	x->max=val;
	x->ki=ki;
	x->ka=ka;
	x->sum=(ka-ki+1)*(llu)val;
	x->lc=x->rc=NULL;
	return x;
}
llu que(v *x,u lo,u hi)
{
	if(hi<x->ki||lo>x->ka)return 0;
	if(lo<=x->ki&&hi>=x->ka)return x->sum;
	u ll,rr;
	if(x->val)
	{
		ll=lo<x->ki?x->ki:lo;
		rr=hi>x->ka?x->ka:hi;
		if(rr<ll)return 0;
		return(rr-ll+1)*(llu)x->val;
	}
	llu a=que(x->lc,lo,hi)+que(x->rc,lo,hi);
	return a;
}
void set(v *x,u lo,u hi,u val)
{
	if(hi<x->ki||lo>x->ka||x->min>=val)
	{
		return;
	}
	if(lo<=x->ki&&hi>=x->ka&&x->max<=val)
	{
		x->val=x->min=x->max=val;
		x->sum=val*(llu)(x->ka-x->ki+1);
		return;
	}
	u m;
	if(x->val)
	{
		if(val<=x->val)return;
		m=(x->ki+x->ka)>>1;
		if(!x->lc)x->lc=alloc(x->ki,m,x->val);
		else
		{
			x->lc->val=x->lc->min=x->lc->max=x->val;
			x->lc->sum=(m-x->ki+1)*(llu)x->val;
		}
		if(!x->rc)x->rc=alloc(m+1,x->ka,x->val);
		else
		{
			x->rc->val=x->rc->min=x->rc->max=x->val;
			x->rc->sum=(x->ka-m)*(llu)x->val;
		}
		x->val=0;
	}
	set(x->lc,lo,hi,val);
	set(x->rc,lo,hi,val);
	if(x->lc->val&&x->lc->val==x->rc->val)
	{
		x->val=x->lc->val;
		x->sum=x->val*(llu)(x->ka-x->ki+1);
	}
	else x->sum=x->lc->sum+x->rc->sum;
	x->min=x->lc->min;
	x->max=x->rc->max;
	return;
}
v *p;
u A[222222],F[222222],G[222222];
int main()
{
	u n,h,i,j,k,x;llu r;
	scanf("%u",&n);
	p=alloc(0,n,1);
	for(i=0;++i<=n;A[i]=x)
	{
		scanf("%u",&x);h=0;
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!F[j])F[j]=i;
			else if(h<j)h=j;
			if(j!=(k=x/j))
			{
				if(!F[k])F[k]=i;
				else if(h<k)h=k;
			}
		}
		set(p,i,n-1,h);
	}
	r=que(p,2,n-1);
	for(i=n;i>1;--i)
	{
		x=A[i];h=0;
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!G[j])G[j]=i;
			else if(h<j)h=j;
			if(j!=(k=x/j))
			{
				if(!G[k])G[k]=i;
				else if(h<k)h=k;
			}
		}
		set(p,0,i-1,h);
		for(x=A[i],j=1;j*j<=x;++j)if(x%j==0)
		{
			if(F[j]&&F[j]<i)set(p,F[j],i-1,j);
			if(F[k=x/j]&&F[k]<i)set(p,F[k],i-1,k);
		}
		r+=que(p,i==n?1:0,i-2);
	}
	printf("%I64u\n",r);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef long long unsigned llu;
typedef unsigned u;
typedef struct S
{
	u val,ki,ka,min,max;llu sum;
	struct S *lc,*rc;
}v;
v*alloc(u ki,u ka,u val)
{
	v*x;
	x=(v*)malloc(sizeof(v));
	x->val=val;
	x->min=val;
	x->max=val;
	x->ki=ki;
	x->ka=ka;
	x->sum=(ka-ki+1)*(llu)val;
	x->lc=x->rc=NULL;
	return x;
}
llu que(v *x,u lo,u hi)
{
//	printf("que %u %u\n",lo,hi);
	if(hi<x->ki||lo>x->ka)
	{
//		printf("return 0\n");
		return 0;
	}
	if(lo<=x->ki&&hi>=x->ka)
	{
//		printf("Return %I64u\n",x->sum);
		return x->sum;
	}
	u ll,rr;
	if(x->val)
	{
		ll=lo<x->ki?x->ki:lo;
		rr=hi>x->ka?x->ka:hi;
		if(rr<ll)
		{
//			printf("return -0\n");
			return 0;
		}
//		printf("ll=%u rr=%u x->val=%u\n",ll,rr,x->val);
		return(rr-ll+1)*(llu)x->val;
	}
	llu a=que(x->lc,lo,hi)+que(x->rc,lo,hi);
//	printf("Retu5n %I64u\n",a);
	return a;
}
void set(v *x,u lo,u hi,u val)
{
//	printf("set [%u %u] %u %u %u\n",x->ki,x->ka,lo,hi,val);
	if(hi<x->ki||lo>x->ka||x->min>=val)
	{
//		printf("return %u<%u || %u>%u || %u>=%u\n",hi,x->ki,lo,x->ka,x->min,val);
		return;
	}
	if(lo<=x->ki&&hi>=x->ka&&x->max<=val)
	{
//		printf("chg %u %u -> %u\n",x->ki,x->ka,val);
		x->val=x->min=x->max=val;
		x->sum=val*(llu)(x->ka-x->ki+1);
		return;
	}
	u m;
	if(x->val)
	{
		if(val<=x->val)
		{
//			printf("small return\n");
			return;
		}
//		printf("split!\n");
		m=(x->ki+x->ka)>>1;
		if(!x->lc)x->lc=alloc(x->ki,m,x->val);
		if(!x->rc)x->rc=alloc(m+1,x->ka,x->val);
		x->val=0;
	}
	set(x->lc,lo,hi,val);
	set(x->rc,lo,hi,val);
	if(x->lc->val&&x->lc->val==x->rc->val)
	{
//		printf("unit!\n");
		x->val=x->lc->val;
		x->sum=x->val*(llu)(x->ka-x->ki+1);
	}
	else x->sum=x->lc->sum+x->rc->sum;
	x->min=x->lc->min;
	x->max=x->rc->max;
	return;
}
v *p;
u A[222222],F[222222],G[222222];
int main()
{
	u n,h,i,j,k,x;llu r;
	scanf("%u",&n);
	if(n<=2){printf("0\n");return 0;}
	p=alloc(0,n,1);
	for(i=0;++i<=n;A[i]=x)
	{
		scanf("%u",&x);h=0;
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!F[j])F[j]=i;
			else if(h<j)h=j;
			if(!F[k=x/j])F[k]=i;
			else if(h<k)h=k;
		}
//		printf("set %u %u %u\n",i,n,h);
		set(p,i,n-1,h);
	}
	r=que(p,2,n-1);
//	printf("r=%I64u\n",r);
	for(i=n;i>1;--i)
	{
		x=A[i];h=0;
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!G[j])G[j]=i;
			else if(h<j)h=j;
			if(!G[k=x/j])G[k]=i;
			else if(h<k)h=k;
		}
//		printf("set %u %u %u\n",0,i-1,h);
		set(p,0,i-1,h);
		for(x=A[i],j=1;j*j<=x;++j)if(x%j==0)
		{
			if(F[j]&&F[j]<i)
			{
//				printf("set %u %u %u\n",F[j],i-1,j);
				set(p,F[j],i-1,j);
			}
			if(F[k=x/j]&&F[k]<i)
			{
//				printf("set %u %u %u\n",F[k],i-1,k);
				set(p,F[k],i-1,k);
			}
		}
//		printf("que %u %u\n",1==n?1:0,i-2);
		r+=que(p,i==n?1:0,i-2);
//		printf("i=%u r=%I64u\n",i,r);
	}
	printf("%I64u\n",r);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef long long unsigned llu;
typedef unsigned u;
typedef struct S
{
	u val,ki,ka,min,max;llu sum;
	struct S *lc,*rc;
}v;
v*alloc(u ki,u ka,u val)
{
	v*x;
	x=(v*)malloc(sizeof(v));
	x->val=val;
	x->min=val;
	x->max=val;
	x->ki=ki;
	x->ka=ka;
	x->sum=(ka-ki+1)*(llu)val;
	x->lc=x->rc=NULL;
	return x;
}
llu que(v *x,u lo,u hi)
{
//	printf("que %u %u\n",lo,hi);
	if(hi<x->ki||lo>x->ka)
	{
//		printf("return 0\n");
		return 0;
	}
	if(lo<=x->ki&&hi>=x->ka)
	{
//		printf("Return %I64u\n",x->sum);
		return x->sum;
	}
	u ll,rr;
	if(x->val)
	{
		ll=lo<x->ki?x->ki:lo;
		rr=hi>x->ka?x->ka:hi;
		if(rr<ll)
		{
//			printf("return -0\n");
			return 0;
		}
//		printf("ll=%u rr=%u x->val=%u\n",ll,rr,x->val);
		return(rr-ll+1)*(llu)x->val;
	}
	llu a=que(x->lc,lo,hi)+que(x->rc,lo,hi);
//	printf("Retu5n %I64u\n",a);
	return a;
}
void set(v *x,u lo,u hi,u val)
{
//	printf("set [%u %u] %u %u %u\n",x->ki,x->ka,lo,hi,val);
	if(hi<x->ki||lo>x->ka||x->min>=val)
	{
//		printf("return %u<%u || %u>%u || %u>=%u\n",hi,x->ki,lo,x->ka,x->min,val);
		return;
	}
	if(lo<=x->ki&&hi>=x->ka&&x->max<=x->val)
	{
//		printf("chg %u %u -> %u\n",x->ki,x->ka,val);
		x->val=x->min=x->max=val;
		x->sum=val*(llu)(x->ka-x->ki+1);
		return;
	}
	u m;
	if(x->val)
	{
		if(val<=x->val)
		{
//			printf("small return\n");
			return;
		}
//		printf("split!\n");
		m=(x->ki+x->ka)>>1;
		if(!x->lc)x->lc=alloc(x->ki,m,x->val);
		if(!x->rc)x->rc=alloc(m+1,x->ka,x->val);
		x->val=0;
	}
	set(x->lc,lo,hi,val);
	set(x->rc,lo,hi,val);
	if(x->lc->val&&x->lc->val==x->rc->val)
	{
//		printf("unit!\n");
		x->val=x->lc->val;
		x->sum=x->val*(llu)(x->ka-x->ki+1);
	}
	else x->sum=x->lc->sum+x->rc->sum;
	x->min=x->lc->min;
	x->max=x->rc->max;
	return;
}
v *p;
u A[222222],F[222222],G[222222];
int main()
{
	u n,h,i,j,k,x;llu r;
	scanf("%u",&n);
	if(n<=2){printf("0\n");return 0;}
	p=alloc(1,n,1);
	for(i=0;++i<=n;A[i]=x)
	{
		scanf("%u",&x);h=0;
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!F[j])F[j]=i;
			else if(h<j)h=j;
			if(!F[k=x/j])F[k]=i;
			else if(h<k)h=k;
		}
//		printf("set %u %u %u\n",i,i,h);
		set(p,i,i,h);
	}
	r=que(p,2,n-1);
	for(i=n+1;--i;)
	{
		x=A[i];h=0;
	}
	for(i=n;i>1;--i)
	{
		x=A[i];h=0;
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!G[j])G[j]=i;
			else if(h<j)h=j;
			if(!G[k=x/j])G[k]=i;
			else if(h<k)h=k;
		}
//		printf("set %u %u %u\n",1,i-1,h);
		set(p,1,i-1,h);
		for(x=A[i],j=1;j*j<=x;++j)if(x%j==0)
		{
			if(F[j]&&F[j]<i)
			{
//				printf("set %u %u %u\n",F[j],i-1,j);
				set(p,F[j],i-1,j);
			}
			if(F[k=x/j]&&F[k]<i)
			{
//				printf("set %u %u %u\n",F[k],i-1,k);
				set(p,F[k],i-1,k);
			}
		}
//		printf("que %u %u\n",1,i==n?i-2:i-1);
		r+=que(p,1,i==n?i-2:i-1);
//		printf("i=%u r=%I64u\n",i,r);
	}
	printf("%I64u\n",r);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef long long unsigned llu;
typedef unsigned u;
typedef struct S
{
	u val,ki,ka,min,max;llu sum;
	struct S *lc,*rc;
}v;
v*alloc(u ki,u ka,u val)
{
	v*x;
	x=(v*)malloc(sizeof(v));
	x->val=val;
	x->min=val;
	x->max=val;
	x->ki=ki;
	x->ka=ka;
	x->sum=(ka-ki+1)*(llu)val;
	x->lc=x->rc=NULL;
	return x;
}
llu que(v *x,u lo,u hi)
{
//	printf("que %u %u\n",lo,hi);
	if(hi<x->ki||lo>x->ka)
	{
//		printf("return 0\n");
		return 0;
	}
	if(lo<=x->ki&&hi>=x->ka)
	{
//		printf("Return %I64u\n",x->sum);
		return x->sum;
	}
	u ll,rr;
	if(x->val)
	{
		ll=lo<x->ki?x->ki:lo;
		rr=hi>x->ka?x->ka:hi;
		if(rr<ll)
		{
//			printf("return -0\n");
			return 0;
		}
//		printf("ll=%u rr=%u x->val=%u\n",ll,rr,x->val);
		return(rr-ll+1)*(llu)x->val;
	}
	llu a=que(x->lc,lo,hi)+que(x->rc,lo,hi);
//	printf("Retu5n %I64u\n",a);
	return a;
}
void set(v *x,u lo,u hi,u val)
{
//	printf("set [%u %u] %u %u %u\n",x->ki,x->ka,lo,hi,val);
	if(hi<x->ki||lo>x->ka||x->min>=val)
	{
//		printf("return %u<%u || %u>%u || %u>=%u\n",hi,x->ki,lo,x->ka,x->min,val);
		return;
	}
	if(lo<=x->ki&&hi>=x->ka&&x->max<=val)
	{
//		printf("chg %u %u -> %u\n",x->ki,x->ka,val);
		x->val=x->min=x->max=val;
		x->sum=val*(llu)(x->ka-x->ki+1);
		return;
	}
	u m;
	if(x->val)
	{
		if(val<=x->val)
		{
//			printf("small return\n");
			return;
		}
//		printf("split!\n");
		m=(x->ki+x->ka)>>1;
		if(!x->lc)x->lc=alloc(x->ki,m,x->val);
		if(!x->rc)x->rc=alloc(m+1,x->ka,x->val);
		x->val=0;
	}
	set(x->lc,lo,hi,val);
	set(x->rc,lo,hi,val);
	if(x->lc->val&&x->lc->val==x->rc->val)
	{
//		printf("unit!\n");
		x->val=x->lc->val;
		x->sum=x->val*(llu)(x->ka-x->ki+1);
	}
	else x->sum=x->lc->sum+x->rc->sum;
	x->min=x->lc->min;
	x->max=x->rc->max;
	return;
}
v *p;
u A[222222],F[222222],G[222222];
int main()
{
	u n,h,i,j,k,x;llu r;
	scanf("%u",&n);
	if(n<=2){printf("0\n");return 0;}
	p=alloc(0,n,1);
	for(i=0;++i<=n;A[i]=x)
	{
		scanf("%u",&x);h=0;
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!F[j])F[j]=i;
			else if(h<j)h=j;
			if(j!=(k=x/j))
			{
				if(!F[k])F[k]=i;
				else if(h<k)h=k;
			}
		}
//		printf("set %u %u %u\n",i,n,h);
		set(p,i,n-1,h);
	}
	r=que(p,2,n-1);
//	printf("r=%I64u\n",r);
	for(i=n;i>1;--i)
	{
		x=A[i];h=0;
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!G[j])G[j]=i;
			else if(h<j)h=j;
			if(j!=(k=x/j))
			{
				if(!G[k])G[k]=i;
				else if(h<k)h=k;
			}
		}
//		printf("set %u %u %u\n",0,i-1,h);
		set(p,0,i-1,h);
		for(x=A[i],j=1;j*j<=x;++j)if(x%j==0)
		{
			if(F[j]&&F[j]<i)
			{
//				printf("set %u %u %u\n",F[j],i-1,j);
				set(p,F[j],i-1,j);
			}
			if(F[k=x/j]&&F[k]<i)
			{
//				printf("set %u %u %u\n",F[k],i-1,k);
				set(p,F[k],i-1,k);
			}
		}
//		printf("que %u %u\n",1==n?1:0,i-2);
		r+=que(p,i==n?1:0,i-2);
//		printf("i=%u r=%I64u\n",i,r);
	}
	printf("%I64u\n",r);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef long long unsigned llu;
typedef unsigned u;
typedef struct S
{
	u val,ki,ka,min,max;llu sum;
	struct S *lc,*rc;
}v;
v*alloc(u ki,u ka,u val)
{
	v*x;
	x=(v*)malloc(sizeof(v));
	x->val=val;
	x->min=val;
	x->max=val;
	x->ki=ki;
	x->ka=ka;
	x->sum=(ka-ki+1)*(llu)val;
	x->lc=x->rc=NULL;
	return x;
}
llu que(v *x,u lo,u hi)
{
//	printf("que %u %u\n",lo,hi);
	if(hi<x->ki||lo>x->ka)
	{
//		printf("return 0\n");
		return 0;
	}
	if(lo<=x->ki&&hi>=x->ka)
	{
//		printf("Return %I64u\n",x->sum);
		return x->sum;
	}
	u ll,rr;
	if(x->val)
	{
		ll=lo<x->ki?x->ki:lo;
		rr=hi>x->ka?x->ka:hi;
		if(rr<ll)
		{
//			printf("return -0\n");
			return 0;
		}
//		printf("ll=%u rr=%u x->val=%u\n",ll,rr,x->val);
		return(rr-ll+1)*(llu)x->val;
	}
	llu a=que(x->lc,lo,hi)+que(x->rc,lo,hi);
//	printf("Retu5n %I64u\n",a);
	return a;
}
void set(v *x,u lo,u hi,u val)
{
//	printf("set [%u %u] %u %u %u\n",x->ki,x->ka,lo,hi,val);
	if(hi<x->ki||lo>x->ka||x->min>=val)
	{
//		printf("return %u<%u || %u>%u || %u>=%u\n",hi,x->ki,lo,x->ka,x->min,val);
		return;
	}
	if(lo<=x->ki&&hi>=x->ka&&x->max<=x->val)
	{
//		printf("chg %u %u -> %u\n",x->ki,x->ka,val);
		x->val=x->min=x->max=val;
		x->sum=val*(llu)(x->ka-x->ki+1);
		return;
	}
	u m;
	if(x->val)
	{
		if(val<=x->val)
		{
//			printf("small return\n");
			return;
		}
//		printf("split!\n");
		m=(x->ki+x->ka)>>1;
		if(!x->lc)x->lc=alloc(x->ki,m,x->val);
		if(!x->rc)x->rc=alloc(m+1,x->ka,x->val);
		x->val=0;
	}
	set(x->lc,lo,hi,val);
	set(x->rc,lo,hi,val);
	if(x->lc->val&&x->lc->val==x->rc->val)
	{
//		printf("unit!\n");
		x->val=x->lc->val;
		x->sum=x->val*(llu)(x->ka-x->ki+1);
	}
	else x->sum=x->lc->sum+x->rc->sum;
	x->min=x->lc->min;
	x->max=x->rc->max;
	return;
}
v *p;
u A[222222],F[222222];
int main()
{
	u n,i,j,k,x;llu r=0llu;
	scanf("%u",&n);
	if(n<=2){printf("0\n");return 0;}
	p=alloc(1,n,1);
	for(i=0;++i<=n;A[i]=x)
	{
		scanf("%u",&x);
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!F[j])F[j]=i;
			if(!F[k=x/j])F[k]=i;
		}
	}
	for(i=n;i;--i)
	{
		for(x=A[i],j=1;j*j<=x;++j)if(x%j==0)
		{
			if(F[j]&&F[j]<i)
			{
//				printf("set %u %u %u\n",F[j],i-1,j);
				set(p,F[j],i-1,j);
			}
			if(F[k=x/j]&&F[k]<i)
			{
//				printf("set %u %u %u\n",F[k],i-1,k);
				set(p,F[k],i-1,k);
			}
		}
		r+=que(p,1,i-1);
//		printf("i=%u r=%I64u\n",i,r);
	}
	printf("%I64u\n",r);
	return 0;
}


// written based on editorial
#include <stdio.h>
#include <string.h>

enum {
    N = 1010
};
const int MOD = 1e9 + 7;

int c[N][N];

int binom(int n, int m) {
    if(m == n || m == 0)
        return 1;
    if(n == 0)
        return 0;
    if(c[n][m] != -1)
        return c[n][m];
    return c[n][m] = (binom(n - 1, m - 1) + binom(n - 1, m)) % MOD;
}

int main() {
    int n, m, k;
    memset(c, -1, sizeof(c));
    scanf("%d %d %d", &n, &m, &k);
    long long val = binom(n - 1, 2 * k);
    val *= binom(m - 1, 2 * k);
    printf("%d\n", (int)(val % MOD));
    return 0;
}


#include <stdio.h>

#define MOD	1000000007

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

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

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

int fact(int n, int is_inv) {
	return n == 0 ? 1
		: (long long) fact(n - 1, is_inv) * (is_inv ? inv(n) : n) % MOD;
}

int choose(int n, int k) {
	return (long long) ((long long) fact(n, 0) * fact(k, 1) % MOD)
		* fact(n - k, 1) % MOD;
}

int main() {
	int n, m, k;

	scanf("%d%d%d", &n, &m, &k);
	printf("%lld\n", n - 1 < 2 * k || m - 1 < 2 * k ? 0
			: (long long) choose(n - 1, 2 * k) * choose(m - 1, 2 * k) % MOD);
	return 0;
}


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

#define ll long long
#define M 1000000007

ll comb[2100][2100];

int main(){
  int i,j,k,l,m,n;
  int x, y, t;
  int loop;
  ll a, b;

  rep(j,2100) comb[0][j] = 0;
  rep(i,2100) comb[i][0] = 1;
  REP(i,1,2100) REP(j,1,2100) comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % M;

  while(scanf("%d%d%d",&x,&y,&t)==3){
    a = comb[x-1][2*t];
    b = comb[y-1][2*t];

    k = (int)((a*b)%M);
    printf("%d\n",k);
  }

  return 0;
}


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

#define MOD 1000000007

long long waysToPlay(int n, int m, int k);
long long oldWaysToPlay(int n, int m, int k, long long mult);
long long choose(long long a, long long b);

long long oldWays;
long long known[1000][1000][1000];

int main() {
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);

    // n: dimension
    // y: dimension
    // k: amount of moves

    printf("%I64d\n", (choose(n-1, 2*k) * choose(m-1, 2*k)) % MOD);

    oldWays = 0;
    //long long ways = waysToPlay(n, m, k) % MOD;
    //printf("%lld\n")
    //printf("%lld\n", ways);

    // Old
    //oldWaysToPlay(n, m, k, 1);
    //printf("%lld\n", oldWays);

    return EXIT_SUCCESS;
}

long long waysToPlay(int n, int m, int k) {
    // 6, 7, 2
    //
    // 4, 4, 1 => 9
    // 6, 7, 2 => 75

    // If no more moves
    if (k == 0) {
        return 1;
    } else if (k == 1) {
        //printf("%d %d %d %lld\n", n, m, k, choose(n-1, 2) * choose(m-1, 2));
        return choose(n-1, 2) * choose(m-1, 2);
    } else {
        // For 5x5 (3x3)
        // Answer = 36
        // k = 1
        // x = 4c2
        // y = 4c2

        // 10 * 10 = 100

        // Smallest cases
        int n_small = 1 + 2*(k-1);
        int m_small = 1 + 2*(k-1);
        long long ways = 0;

        // They must be TWO less
        for (int n_i = n_small; n_i < n-1; n_i++) {
            for (int m_i = m_small; m_i < m-1; m_i++) {
                // The amount of positions that the new rectangle
                // can fit into
                int newMult = (n-n_i-1)*(m-m_i-1);

                // Cache the result
                if (known[m_i][n_i][k-1] == 0) {
                    known[m_i][n_i][k-1] = waysToPlay(n_i, m_i, k-1);
                }

                // Add it to ways
                ways += newMult * known[m_i][n_i][k-1];
            }
        }

        //printf("%d %d %d %lld\n", n, m, k, ways);

        return ways;
    }

    // Otherwise there are no ways
    return 0;
}

long long choose(long long a, long long b) {
    if (b > a) return 0;

    //aCb = a!/((a-b)!*b!)
    //    = a*(a-1)...(a-b+1)/
    //      b*(b-1)...1

    //    = a*(a-1)...(a-b+1)/
    //      1*2*......b

    long long result = 1;
    for (int i = 0; i < b; i++) {
        result = (result * (a-i)) % MOD;
        result = (result / (i+1)) % MOD;
    }

    //printf("%lldC%lld = %lld\n", a, b, result);
    return result % MOD;
}

//OLD method
long long oldWaysToPlay(int n, int m, int k, long long mult) {
    // 3x3 in 6x7 (4x5)
    if (k == 0) {
        oldWays = (oldWays+mult) % MOD;
        //printf("+ %lld\n", mult);
    } else if (k == 1 && n == 1 && m == 1) {
        oldWays = (oldWays+mult) % MOD;
    } else {
        // Smallest cases
        int n_small = 1 + 2*(k-1);
        int m_small = 1 + 2*(k-1);

        // How many places it can go X inside solutions

        // They must be TWO less
        for (int n_i = n_small; n_i < n-1; n_i++) {
            for (int m_i = m_small; m_i < m-1; m_i++) {
                // Positional permutation (x,y and y,x)
                // int twice = (m_i != n_i) ? 2 : 1;

                //printf("passing: %d %d %lld\n", n_i, m_i, mult);
                oldWaysToPlay(n_i, m_i, k-1, mult*(n-n_i-1)*(m-m_i-1));
            }
        }
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
char s[200005];
long long cnt,n,c1,c2,ans;
long long f(long long x) {
	return c2*x*x;
}
int main() {
	scanf("%lld%lld%lld",&n,&c1,&c2);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		if(s[i]=='1')
			cnt++;
//	printf("%lld\n",cnt);
	ans=1e18;
	for(long long i=1;i<=cnt;i++) {
		long long tmp=n%i,o=n/i,res=0;
//		printf("%lld %lld %lld\n",i,tmp,o);
		res=i*c1+tmp*f(o)+(i-tmp)*f(o-1);
		if(ans>res)
			ans=res;
	}
	printf("%lld\n",ans);
}


#include<stdio.h>
#define lli long long int

lli n,c1,c2,pr=0;

lli calc(lli gr)
{
    if(gr==0 || gr>pr)
        return 1000000000000000;
    lli num=n/gr;
    lli r=n%gr;
    lli ret=gr*c1;
    ret+=r*(n/gr)*(n/gr)*c2;
    ret+=(gr-r)*(n/gr-1)*(n/gr-1)*c2;
    return ret;
}

int main() {
    scanf("%lld%",&n);
    scanf("%lld%",&c1);
    scanf("%lld%",&c2);
    char s[n+1];
    gets(s);
    int ch=0;
    int i;
    for(i=0;i<n;i++)
        if(s[i]=='1')
            pr++;
        else
            ch++;
    int l=1,h=pr;
    lli ans;
    while(l<=h)
    {
        int mid=(l+h)/2;
        lli n1=calc(mid-1);
        lli n2=calc(mid+1);
        lli nm=calc(mid);
        if(n1>nm && n2>nm)
            {ans=nm;
            break;}
        else if(n1>nm)
            ans=nm,l=mid+1;
        else
            h=mid-1;
    }
    printf("%lld",ans);
    return 0;
}


#include<stdio.h>
int main(){
	long long int i,sayi,a,b,n = 0,sonuc,ensonuc = 0;
	scanf("%lld %lld",&a,&b);
	for(i = a ; i <= b ; i++){
		sayi = i;
		sonuc = 0;
		while(sayi>=1){
			if(sayi%2==0)
				sonuc++;
			sayi=sayi/2;
			n++;
		}
		if(sonuc==1)
			ensonuc++;
	}
	printf("%lld",ensonuc);
	return 0;
}


#include<stdio.h>

int main()
{
	unsigned long long int s, e, cnt=0, curcnt, cn, temp, temp2;
	scanf("%llu %llu",&s, &e);
	for(temp=s;temp<=e;temp++){
		//printf("%llu\n",temp);
		for(cn=temp,curcnt=0;cn>0;cn=cn>>1){
			temp2=cn&1;
			if(temp2==0)curcnt++;
			if(curcnt==2) break;
		}
		if(curcnt==1) cnt++;
	}
	printf("%llu\n",cnt);
	return 0;
}


#include <stdio.h>

int weekday_count[8] = {0, 52, 52, 52, 52, 53, 53, 52};
int month_days[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    int x, running = 1;
    int i, ans = 0;
    scanf("%d", &x);
    while (running) switch (getchar()) {
        case 'w':
            printf("%d\n", weekday_count[x]);
            running = 0; break;
        case 'm':
            for (i = 1; i <= 12; ++i) if (month_days[i] >= x) ++ans;
            printf("%d\n", ans);
            running = 0; break;
        default: break;
    }
    return 0;
}


#include<stdio.h>
int main(){
	long long int i,sayi,a,b,n = 0,sonuc,ensonuc = 0;
	scanf("%l64d %l64d",&a,&b);
	for(i = a ; i <= b ; i++){
		sayi = i;
		sonuc = 0;
		while(sayi>=1){
			if(sayi%2==0)
				sonuc++;
			sayi=sayi/2;
			n++;
		}
		if(sonuc==1)
			ensonuc++;
	}
	printf("%l64d",ensonuc);
	return 0;
}


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

int ans=0,chk1=0,chk2=0,j;

int main()
{
      int a[20];
      long long dec,i=0;
      //printf("Enter the decimal number to find its binary number\n");
      scanf("%I64d",&dec);
	  dec-=1;
      while(dec>0)
      {
           a[i]=dec%2;
           i++;
           dec=dec/2;
      }
      //printf("Binary number of %d is = ",dec)
	ans=0;chk1=0;chk2=0;
      for(j=i-1;j>=0;j--)
      {
        if(a[j]==0){
        	if(chk1==0){
        		ans+=i-j;
        		chk1=1;
			}
			else if(chk2==0&&chk1==1){
				chk2=1;
				ans-=1;

			}

		}

		  //printf("%d",a[j]);
      }
      for(j=i-1;j>0;j--){
      	ans+=j-1;

	  }

	  int net=ans;
	  //printf("%d",net);
       dec,i=0;
      //printf("Enter the decimal number to find its binary number\n");
      scanf("%I64d",&dec);

      while(dec>0)
      {
           a[i]=dec%2;
           i++;
           dec=dec/2;
      }
      //printf("Binary number of %d is = ",dec);

	ans=0;chk1=0;chk2=0;
      for(j=i-1;j>=0;j--)
      {
        if(a[j]==0){
        	if(chk1==0){
        		ans+=i-j;
        		chk1=1;
			}
			else if(chk2==0&&chk1==1){
				chk2=1;
				ans-=1;

			}

		}

		  //printf("%d",a[j]);
      }
      for(j=i-1;j>0;j--){
      	ans+=j-1;

	  }
	  ans-=net;
      printf("%d",ans);

      //getch();
 }


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

int determine(int *guesses, int *bulls, int *cows, int n);
bool is_solution(int k, int *guesses, int *bulls, int *cows, int n);
bool fits(int k, int guess, int bulls, int cows);

int main() {
	int n = 0, k = 0, result = 0;
	int *guesses = NULL;
	int *bulls = NULL;
	int *cows = NULL;

	scanf("%d", &n);

	guesses = calloc(n, sizeof(int));
	bulls = calloc(n, sizeof(int));
	cows = calloc(n, sizeof(int));

	for(k=0; k<n; k++) {
		scanf("%d %d %d", &guesses[k], &bulls[k], &cows[k]);
	}

	result = determine(guesses, bulls, cows, n);

	switch(result) {
		case 0:
			printf("Incorrect data");
			break;
		case 1:
			printf("Need more data");
			break;
		default:
			printf("%d", result);
			break;
	}

	printf("\n");

	free(guesses);
	free(bulls);
	free(cows);

	return 0;
}

int determine(int *guesses, int *bulls, int *cows, int n) {
	int k = 0, j = 0, result = 0;

	k = 1000;

	while(k<=9999 && j<=1) {
		if(is_solution(k, guesses, bulls, cows, n)) {
			result = k;
			j++;
		}
		k++;
	}

	if(j==2)
		result = 1;

	return result;
}

bool is_solution(int k, int *guesses, int *bulls, int *cows, int n) {
	bool cont = true;
	int j = 0;

	while(cont && j<n) {
		cont = fits(k, guesses[j], bulls[j], cows[j]);
		j++;
	}

	return cont;
}

bool fits(int k, int guess, int bulls, int cows) {
	int Guess[4];
	int K[4];
	bool selected[4];
	int j = 0, i = 0, weight = 1, weightx = 10, countb = 0, countc = 0;

	for(j=0; j<4; j++) {
		Guess[j] = (guess%weightx) / weight;
		K[j] = (k%weightx) / weight;
		weight = weightx;
		weightx *= 10;
	}

	for(j=0; j<4; j++) {
		if(Guess[j]==K[j])
			countb++;
	}

	if(bulls != countb)
		return false;

	for(j=0; j<4; j++)
		selected[j] = false;

	for(i=0; i<4; i++)
		for(j=0; j<4; j++) {
			if(i!=j && !selected[i] && Guess[i]==K[j]) {
				countc++;
				selected[i] = true;
			}
		}

	if(cows != countc)
		return false;

	return true;
}


#include <stdio.h>

#define UNDECIDED -1
#define NOTFOUND -2

int as[20];
int hit[20];
int blow[20];
int appear[20];
int A[20], B[20];
int N;

int precheck(int num){
    int i,cnt=0;
    for(i=0;i<10;i++) appear[i]=0;
    appear[(num/1000)%10]++;
    appear[(num/100)%10]++;
    appear[(num/10)%10]++;
    appear[(num/1)%10]++;
    for(i=0;i<10;i++)if(appear[i]) cnt++;
    return cnt == 4;
}

int subcheck(int num, int idx){
    int i, sub=as[idx], h=0, b=0;
    for(i=0;i<10;i++)A[i]=B[i]=0;
    for(i=1;i<=1000;i*=10){
        if((num/i)%10 == (sub/i)%10){
            h++;
        }
        else{
            A[(num/i)%10]++;
            B[(sub/i)%10]++;
        }
    }
    for(i=0;i<10;i++)if(A[i]&&B[i]) b++;
    return h==hit[idx] && b==blow[idx];
}

int check(){
    int i,j,ok,cnt=0,ans;
    for(i=0;i<10000;i++)if(precheck(i)){
        ok = 1;
        for(j=0;j<N;j++)if(!subcheck(i,j)) ok = 0;
        if(ok){
            cnt++;
            ans = i;
        }
    }
    if(cnt==0) return NOTFOUND;
    else if(cnt==1) return ans;
    else return UNDECIDED;
}

void solve(){
    int result = check();
    if(result == UNDECIDED) puts("Need more data");
    else if(result == NOTFOUND) puts("Incorrect data");
    else printf("%04d\n", result);
}

int main(){
    int i;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d%d%d",as+i,hit+i,blow+i);
    solve();
    return 0;
}


/*
 * =====================================================================================
 *
 *       Filename:  main.c
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  19/01/17 19:54:22
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *        Company:
 *
 * =====================================================================================
 */

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

int
width(long x)
{
    int i = 0;
    while (x > 0) {
        i++;
        x /= 10;
    }
    return i;
}

int
convert(char *beg, char *end)
{
    long res = 0;
    while ((uintptr_t)beg < (uintptr_t)end) {
        res = res * 10 + (*beg - '0');
        beg++;
    }
    return res;
}

int
min(int i, int j)
{
    if (i < j)
        return i;
    else
        return j;
}

int
main()
{
    long n;
    char k[61];
    scanf("%ld", &n);
    scanf("%s", k);

    int w = width(n - 1);
    long base[w+2];
    base[1] = -1; base[2] = 9;
    for (int i = 3; i <= w; ++i)
        base[i] = base[i-1] * 10 + 9;

    long x = 0;
    long basen = 1;
    for (int i = strlen(k); i > 0; --i) {
        for (int j = min(w, i); j > 0; --j) {
            //printf("x: %ld, part: %.*s\n", x, j, &k[i-j]);
            long part = convert(&k[i-j], &k[i]);
            if (part < n && part > base[j]) {
                x += basen * part;
                i -= j - 1;
                break;
            }
        }
        basen *= n;
    }
    printf("%ld\n", x);
    return 0;
}


#include <stdio.h>

int main()
{
    int n,k,x,i=1;
    scanf("%d",&n);
    scanf("%d",&k);
    int s=n;
    while(s>0)
    {
        s=s/10;i*=10;
    }
    s=0;int j=i/10;

    int b=1;
    while(k!=0)
    {
        x=k%i;
        if(x<n){s+=x*b;b*=n;k=k/i;}
        else{s+=(x%j)*b;b*=n;k=k/j;}

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


#include<stdio.h>
#include<math.h>
int dgt(int a)
{
    double r=log(a)/log(7);
    int c=r;
    return (r==c)? c: c+1;
}
int ys(int m, int n, int a, int b)
{

    int fr[7]={0,0,0,0,0,0,0},i;
    for(i=0;i<a;i++){
        fr[m%7]++;
        if(fr[m%7]>1){

            return 0;
        }
        m=m/7;
    }
    for(i=0;i<b;i++){
        fr[n%7]++;
        if(fr[n%7]>1){

            return 0;
        }
        n=n/7;
    }

    return 1;
}
int get(int m, int n)
{
    int d1,d2,i,j,rs=0;
    d1=dgt(m);d2=dgt(n);
    if(d1+d2>7)
        return 0;
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            rs+=ys(i,j,d1,d2);
        }
    }
    return rs;
}
int main()
{
    int m,n,result;
    scanf("%d %d",&m,&n);
    result=get(m,n);
    printf("%d\n",result);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MAXN 13
long long a[MAXN],b[MAXN],m,n,ans=0;
long long s1[MAXN],s2[MAXN];
void find(long long x,long long y,long long add)
{
	long long i,j,S;
	if(add>y){
		ans++;
		return;
	}
	for(i=0;i<=6;i++){
		for(j=1;j<add;j++)
			if(i==b[j])
				goto end1;
		for(j=1;j<=x;j++)
			if(i==a[j])
				goto end1;
		s2[add]=i*pow(7,y-add);
		S=0;
		for(j=1;j<=add;j++)
			S+=s2[j];
		if(S>=m)
			goto end1;
		b[add]=i;
		find(x,y,add+1);
		end1:;
	}
}
void dfs(long long x,long long y,long long add)
{
	long long i,j,S;
	if(add>x){
		find(x,y,1);
		return;
	}
	for(i=0;i<=6;i++){
		for(j=1;j<add;j++){
			if(i==a[j])
			goto end;
		}
		s1[add]=i*pow(7,x-add);
		S=0;
		for(j=1;j<=add;j++)
			S+=s1[j];
		if(S>=n)
			goto end;
		a[add]=i;
		dfs(x,y,add+1);
		end:;
	}
}
int main()
{
	long long k,i,j,l,c,p,q,c1=0,c2=0;
	scanf("%I64d%I64d",&n,&m);
	p=n-1;q=m-1;
	while(p>0){
		p=p/7;
		c1++;
	}
	while(q>0){
		q=q/7;
		c2++;
	}
	if(c1+c2>7){
		printf("0");
		return 0;
	}
	dfs(c1,c2,1);
	printf("%I64d",ans);
	return 0;
}


#include <stdio.h>

long long n, m, pow[11], nn = 0, mm = 0, res = 0, leng;
int a[7],x[8], res1 = 0, res2 = 0;

void kiemtra()
{
    int j, i = 1;
    long long h = 0;
    for (i = 1; i <= res1; i++)
    {
        h = h * 10 + x[i];
    }
    if (h > nn) return;

    h = 0;
    for (i = res1 + 1; i <= leng; i++)
    {
        h = h * 10 + x[i];
    }
    if (h > mm) return;
    res++;
}

void xuli(int i)
{
    int j;
    for (j = 0; j < 7; j++)
        if (a[j] == 0)
        {
            x[i] = j;
            a[j] = 1;
            if (i == leng) kiemtra();
            else
                xuli(i+1);
            a[j] = 0;
        }
}

void sol()
{
    int  x, i;
    for (i = 10; i >= 0; i--)
    {
        nn = nn * 10 + n / pow[i];
        if (n / pow[i] > 0)
        {
            x = n / pow[i];
            n -= x * pow[i];
            if (res1 == 0)
            {
                res1 = i+1;
            }
        }
    }
    for (i = 10; i >= 0; i--)
    {
        mm = mm * 10 + m / pow[i];
        if (m / pow[i] > 0)
        {
            x = m / pow[i];
            m -= x * pow[i];
            if (res2 == 0)
            {
                res2 = i+1;
            }
        }
    }
    leng = res1 + res2;
    xuli(1);
}

int main()
{
    int i, j;
    scanf("%I64d %I64d", &n, &m);
    n--; m--;
    for (j = 0; j < 7; j++)
        a[j] = 0;
    pow[0] = 1;
    for (i = 1; i < 11; i++)
        pow[i] = pow[i-1] * 7;
    sol();
    printf("%d", res);
    return 0;
}


#include<stdio.h>
#include<math.h>
int dgt(int a)
{
    double r=log(a)/log(7);
    int c=r+1;
    return c;
}
int ys(int m, int n, int a, int b)
{
    int fr[7]={0,0,0,0,0,0,0},i;
    //printf("%d-%d: ",m,n);
    for(i=0;i<a;i++){
        fr[m%7]++;
        if(fr[m%7]>1){
            //printf("0\n");
            return 0;
        }
        m=m/7;
    }
    for(i=0;i<b;i++){
        fr[n%7]++;
        if(fr[n%7]>1){
                //printf("0\n");
            return 0;
        }
        n=n/7;
    }
    //printf("1\n");
    return 1;
}
int get(int m, int n)
{
    int d1,d2,i,j,rs=0;
    d1=dgt(m);
    d2=dgt(n);
    if(d1+d2>7)
        return 0;
    for(i=0;i<m;i++){
        if(ys(i,i,d1,0)){
            //printf("i=%d,d=%d\n",i,d1);
           for(j=0;j<n;j++){
                rs+=ys(i,j,d1,d2);
           }
        }
    }
    return rs;
}
int main()
{
    int m,n,result;
    scanf("%d %d",&m,&n);
    result=get(m,n);
    printf("%d\n",result);
    return 0;
}


#include <stdio.h>

int check(int a, int b, int c)
{
	int oc[7]={0}, sum=0,flag=0,i=0;

	while(a)
	{
		oc[a%7]++;
		a/=7;
		sum++;
	}

	while(b)
	{
		oc[b%7]++;
		b/=7;
		sum++;
	}

	while(i<7)
	{
		if(oc[i]>1) flag=1;
		i++;
	}

	if(c-sum>1) flag=1;

	if(c-sum>0 && oc[0]==1) flag=1;

	if(flag==1) return 0;

	else return 1;
}

int main(void) {
	int n,m,i=0,a,d=0,ans=0;

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

	a=n-1;
	while(1)
	{
		d++;
		a/=7;
		if(a==0) break;
	}

	a=m-1;
	while(1)
	{
		d++;
		a/=7;
		if(a==0) break;
	}

	if(i>7) printf("0");

	else
	{
		i=0;
		while(i<n)
		{
			int j=0;

			while(j<m)
			{
				ans+=check(i,j,d);
				j++;
			}

			i++;
		}

		printf("%d",ans);
	}

	return 0;
}


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

char r[1 << 19];

int box2mask(char b[5][5]) {
	int mask = 0, i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (b[i][j])
				mask |= 1 << k;
			k++;
		}

	return mask;
}

int go(int mask) {
	if (r[mask] != -1)
		return r[mask];

	char b[5][5];
	memset(b, 0, sizeof(b));

	int i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (mask & (1 << k))
				b[i][j] = 1;
			k++;
		}

	char bb[5][5];
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			memcpy(bb, b, sizeof(bb));
			for (k = i; k < 5 && j < 5-abs(2-k) && bb[k][j]; k++) {
				bb[k][j] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			int l;
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && bb[k][l]; k++, l++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = j; k < 5-abs(2-i) && bb[i][k]; k++) {
				bb[i][k] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}
		}

	return r[mask] = 0;
}

int main() {
	int i, mask = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100];
		gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				mask |= (1 << j);
			if (*t == '0' || *t == '.')
				j++;
			t++;
		}

	}

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

	if (go(mask))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}


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

char r[1 << 20];

int box2mask(char b[5][5]) {
	int mask = 0, i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (b[i][j])
				mask |= 1 << k;
			k++;
		}

	return mask;
}

int go(int mask) {
	if (r[mask] != -1)
		return r[mask];

	char b[5][5];
	memset(b, 0, sizeof(b));

	int i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (mask & (1 << k))
				b[i][j] = 1;
			k++;
		}

	char bb[5][5];
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			memcpy(bb, b, sizeof(bb));
			for (k = i; k < 5 && j < 5-abs(2-k) && bb[k][j]; k++) {
				bb[k][j] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			int l;
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && bb[k][l]; k++, l++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = j; k < 5-abs(2-i) && bb[i][k]; k++) {
				bb[i][k] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}
		}

	return r[mask] = 0;
}

int main() {
	int i, mask = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100];
		gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				mask |= (1 << j);
			if (*t == 'O' || *t == '.')
				j++;
			t++;
		}

	}

	if (j != 19)
		exit(1);

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

	if (go(mask))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}


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

char r[1 << 20];

int masksn = 0, masks[200];

int go(int m) {
	if (r[m] != -1)
		return r[m];

	int i;
	for (i = 0; i < masksn; i++)
		if (m & masks[i] == masks[i])
			if (!go(m & ~masks[i]))
					return r[m] = 1;

	return r[m] = 0;
}

int main() {
	int i, m = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100]; gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				m |= (1 << j);
			if (*t == 'O' || *t == '.')
				j++;
			t++;
		}

	}

	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			int k, l, m = 0;
			for (k = i, l = j; k < 5 && 0 <= l && l < 5-abs(2-k); k++) {
				masks[masksn++] = m;
				if (k >= 2)
					l--;
			}

			m = 0;
			for (k = i, l = j; k < 5 && l <= 5-abs(2-k); k++) {
				masks[masksn++] = m;
				if (k < 2)
					l++;
			}

			m = 0;
			for (k = j; k < 5-abs(2-i); k++) {
				masks[masksn++] = m;
			}
		}

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

	if (go(m))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}


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

char r[1 << 19];

int box2mask(char b[5][5]) {
	int mask = 0, i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (b[i][j])
				mask |= 1 << k;
			k++;
		}

	return mask;
}

int go(int mask) {
	if (r[mask] != -1)
		return r[mask];

	char b[5][5];
	memset(b, 0, sizeof(b));

	int i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (mask & (1 << k))
				b[i][j] = 1;
			k++;
		}

	char bb[5][5];
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			memcpy(bb, b, sizeof(bb));
			for (k = i; k < 5 && j < 5-abs(2-k) && bb[k][j]; k++) {
				bb[k][j] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			int l;
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && bb[k][l]; k++, l++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = j; k < 5-abs(2-i) && bb[i][k]; k++) {
				bb[i][k] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}
		}

	return r[mask] = 0;
}

int main() {
	int i, mask = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100];
		gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				mask |= (1 << j);
			if (*t == 'O' || *t == '.')
				j++;
			t++;
		}

	}

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

	if (go(mask))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}


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

char r[1 << 20];

int box2mask(char b[5][5]) {
	int mask = 0, i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (b[i][j])
				mask |= 1 << k;
			k++;
		}

	return mask;
}

int go(int mask) {
	if (r[mask] != -1)
		return r[mask];

	// printf("mask = %d\n", mask);

	char b[5][5];
	memset(b, 0, sizeof(b));

	int i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (mask & (1 << k))
				b[i][j] = 1;
			k++;
		}

	char bb[5][5];
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			memcpy(bb, b, sizeof(bb));
			int l;
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && l >= 0 && bb[k][l]; k++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
				if (k >= 2)
					l--;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && bb[k][l]; k++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
				if (k < 2)
					l++;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = j; k < 5-abs(2-i) && bb[i][k]; k++) {
				bb[i][k] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}
		}

	return r[mask] = 0;
}

int main() {
	int i, mask = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100];
		gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				mask |= (1 << j);
			if (*t == 'O' || *t == '.')
				j++;
			t++;
		}

	}

	if (j != 19)
		exit(1);

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

	if (go(mask))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}


#include <stdlib.h>
#include <stdio.h>
int a[20][20]; int main() {long i, j, k, f, t, res; char s[200]; scanf("%ld %ld %ld ", &f, &k, &t); for (i = 0; i < f; i++) {scanf("%s ", s); for (j = 0; j < k; j++) {a[i][j] = s[j] == 'Y';}} res = 0; for (j = 0; j < k; j++) {long c = 0; for (i = 0; i < f; i++) {if (a[i][j]) c++;} if (c >= t) res++;} printf("%ld\n", res); return 0;}


#include <stdio.h>

int main(){

    int F, I, T;
    scanf("%d %d %d", &F, &I, &T);

    int i = 0;
    int j = 0;
    int count[I];
    for(i=0;i<I;i++)count[i]=0;
    for(i=0;i<F;i++){
        char line[I];
        scanf("%s", &line);
        for(j=0;j<I;j++){
            if(line[j]=='Y'){
                count[j]=count[j]+1;
            }
        }
    }

    int c=0;
    for(i=0;i<I;i++){
        if(count[i]>=T)c++;
    }
    printf("%d\n",c);

}


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

int a[20][20];

int main()
{
   long i, j, k, f, t, res;
   char s[200];

   scanf("%ld %ld %ld ", &f, &k, &t);
   for (i = 0; i < f; i++) {
      scanf("%s ", s);
      for (j = 0; j < k; j++) {
	 a[i][j] = s[j] == 'Y';
      }
   }

   res = 0;
   for (j = 0; j < k; j++) {
      long c = 0;
      for (i = 0; i < f; i++) {
	 if (a[i][j]) c++;
      }
      if (c >= t) res++;
   }
   printf("%ld\n", res);
   return 0;
}


II = lambda: int(raw_input())
IAI = lambda: map(int, raw_input().split())
IL = lambda: raw_input().strip()
IAS = lambda: raw_input().split()

f,i,t = IAI()

L=[]
for _ in range(f): L += [IL()]

o=0
for c in xrange(i):
    if sum(l[c]=='Y' for l in L) >= t: o += 1
print o


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

int main() {
  long long int i,n;
  long long int min=1000000000,max;
  scanf("%lld",&n);
  //printf("%lld\n",n);
  //printf("%lld\n",(long long int)sqrtl(n));
  for (i=1;i<=(long long int)sqrtl(n);i++) {
    if (n%i==0) {
      //printf("%lld\n",min);
      if ((i+2)*(n/i+2)<min) {
        min=(i+2)*(n/i+2);
      }
    }
  }
  min=2*min-n;
  max=(n+1)*3*3-n;
  printf("%lld %lld\n",min,max);
  return 0;
}


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

int md;

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

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

void mult(int aa[][2], int bb[][2], int cc[][2]) {
	int i, j, k;

	for (i = 0; i < 2; i++)
		for (j = 0; j < 2; j++) {
			long long c = 0;

			for (k = 0; k < 2; k++)
				c += (long long) aa[i][k] * bb[k][j];
			cc[i][j] = c % md;
		}
}

void power_(int aa[][2], int pp[][2], int tt[][2], long long k) {
	if (k == 0) {
		pp[0][0] = pp[1][1] = 1;
		pp[0][1] = pp[1][0] = 0;
		return;
	}
	if (k % 2 == 0) {
		power_(aa, tt, pp, k / 2);
		mult(tt, tt, pp);
	} else {
		power_(aa, pp, tt, k / 2);
		mult(pp, pp, tt);
		mult(tt, aa, pp);
	}
}

int main() {
	static int aa[2][2], pp[2][2], tt[2][2];
	long long n, k, x0, x1, ans;
	int l, h;

	scanf("%lld%lld%d%d", &n, &k, &l, &md);
	if (l < 63 && k >= 1LL << l) {
		printf("0\n");
		return 0;
	}
	aa[0][0] = 1, aa[0][1] = 1;
	aa[1][0] = 1, aa[1][1] = 0;
	power_(aa, pp, tt, n);
	x0 = (pp[0][0] + pp[0][1]) % md;
	x1 = (power(2, n) - x0 + md) % md;
	ans = 1 % md;
	for (h = 0; h < l; h++)
		ans = ans * ((k & 1LL << h) == 0 ? x0 : x1) % md;
	printf("%lld\n", ans);
	return 0;
}


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

int md;

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

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

void mult(int aa[][2], int bb[][2], int cc[][2]) {
	int i, j, k;

	for (i = 0; i < 2; i++)
		for (j = 0; j < 2; j++) {
			long long c = 0;

			for (k = 0; k < 2; k++)
				c += (long long) aa[i][k] * bb[k][j];
			cc[i][j] = c % md;
		}
}

void power_(int aa[][2], int pp[][2], int tt[][2], long long k) {
	if (k == 0) {
		pp[0][0] = pp[1][1] = 1;
		pp[0][1] = pp[1][0] = 0;
		return;
	}
	if (k % 2 == 0) {
		power_(aa, tt, pp, k / 2);
		mult(tt, tt, pp);
	} else {
		power_(aa, pp, tt, k / 2);
		mult(pp, pp, tt);
		mult(tt, aa, pp);
	}
}

int main() {
	static int aa[2][2], pp[2][2], tt[2][2];
	long long n, k, x0, x1, ans;
	int l, h;

	scanf("%lld%lld%d%d", &n, &k, &l, &md);
	if (l < 64 && k >= 1LL << l) {
		printf("0\n");
		return 0;
	}
	aa[0][0] = 1, aa[0][1] = 1;
	aa[1][0] = 1, aa[1][1] = 0;
	power_(aa, pp, tt, n);
	x0 = (pp[0][0] + pp[0][1]) % md;
	x1 = (power(2, n) - x0 + md) % md;
	ans = 1 % md;
	for (h = 0; h < l; h++)
		ans = ans * ((k & 1LL << h) == 0 ? x0 : x1) % md;
	printf("%lld\n", ans);
	return 0;
}


#include <stdio.h>

long long int gcd(long long int x, long long int y);
long long int max(long long int x, long long int y);
long long int min(long long int x, long long int y);

int main(void){

    long long int x,y;
    scanf("%I64d %I64d", &x, &y);

    long long int count = 0;
    do{
        count++;
        y = y-gcd(x,y);
    } while(y != 0);
    printf("%I64d", count);
    return 0;
}

long long int gcd(long long int x, long long int y){
    long long int a = max(x,y);
    long long int b = min(x,y);
    long long int r;
    do{
        r = a%b;
        a = b;
        b = r;
    } while(r != 0);
    return a;
}

long long int max(long long int x, long long int y){
    if(x<=y){
        return y;
    } else {
        return x;
    }
}

long long int min(long long int x, long long int y){
    if(x<=y){
        return x;
    } else {
        return y;
    }
}


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

long long int gcd(long long int x, long long int y);
long long int max(long long int x, long long int y);
long long int min(long long int x, long long int y);

int main(void){

    long long int x,y;
    scanf("%I64d %I64d", &x, &y);
    long long int func = 0;

    long long int tempx = x;
    long long int tempy = y;

    tempx = x/gcd(x,y);
    tempy = y/gcd(x,y);
    x = tempx;
    y = tempy;
    if(x==1){
        func=func+y;
        printf("%I64d", y);
        return 0;
    }

    long long int primex[40];
    for(int i=0; i<40; i++){
        primex[i] = 0;
    }
    int arraycount = 0;
    if(tempx%2==0){
        while(tempx%2==0){
            primex[arraycount] = 2;
            arraycount++;
            tempx = tempx/2;
        }
    }
    for(int i=3; i<=sqrt(tempx); i=i+2){
        if(tempx%i==0){
            while(tempx%i==0){
                primex[arraycount] = i;
                arraycount++;
                tempx = tempx/i;
            }
        }
    }
    if(tempx>2){
        primex[arraycount] = tempx;
        arraycount++;
    }
    tempx = x;

    int remainder[40];
    for(int i=0; i<40; i++){
        remainder[i] = -1;
    }

    for(int i=0; i<arraycount; i++){
        if(primex[i] != 0){
            remainder[i] = y%primex[i];
        }
    }

    int minrem = 0;
    for(int i=1; i<arraycount; i++){
        if(remainder[i]!= -1 && remainder[minrem]>remainder[i]){
            minrem = i;
        }
    }

    func = func + remainder[minrem];
    y = y - remainder[minrem];

    long long int primegcd[40];
    for(int i=0; i<40; i++){
        primegcd[i] = 0;
    }
    int gcdarraycount = 0;
    int gcdnum;
    int deletecount = 0;

    while(y != 0){

        gcdarraycount = 0;
        gcdnum = gcd(x,y);

        if(gcdnum%2==0){
            while(gcdnum%2==0){
                primegcd[gcdarraycount] = 2;
                gcdarraycount++;
                gcdnum = gcdnum/2;
            }
        }
        for(int i=3; i<=sqrt(gcdnum); i=i+2){
            if(gcdnum%i==0){
                while(gcdnum%i==0){
                    primegcd[gcdarraycount] = i;
                    gcdarraycount++;
                    gcdnum = gcdnum/i;
                }
            }
        }
        if(gcdnum>2){
            primegcd[gcdarraycount] = gcdnum;
            gcdarraycount++;
        }

        deletecount = 0;
        while(deletecount<gcdarraycount){
            for(int i=0; i<arraycount; i++){
                if(primex[i] == primegcd[deletecount]){
                    primex[i] = 0;
                    remainder[i] = -1;
                    deletecount++;
                }
            }
            deletecount++;
        }

        tempx = x/gcd(x,y);
        tempy = y/gcd(x,y);
        x = tempx;
        y = tempy;
        if(x==1){
            func=func+y;
            printf("%I64d", func);
            return 0;
        }

        for(int i=0; i<arraycount; i++){
            if(primex[i] != 0){
                remainder[i] = y%primex[i];
            }
        }

        minrem = 0;
        while(remainder[minrem]==-1){
            minrem++;
        }
        for(int i=minrem+1; i<arraycount; i++){
            if(remainder[i]!= -1 && remainder[minrem]>remainder[i]){
                minrem = i;
            }
        }

        func = func + remainder[minrem];
        y = y - remainder[minrem];
    }

    printf("%I64d", func);
    return 0;
}

long long int gcd(long long int x, long long int y){
    long long int a = max(x,y);
    long long int b = min(x,y);
    long long int r;
    do{
        r = a%b;
        a = b;
        b = r;
    } while(r != 0);
    return a;
}

long long int max(long long int x, long long int y){
    if(x<=y){
        return y;
    } else {
        return x;
    }
}

long long int min(long long int x, long long int y){
    if(x<=y){
        return x;
    } else {
        return y;
    }
}


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

long long int gcd(long long int x, long long int y);
long long int max(long long int x, long long int y);
long long int min(long long int x, long long int y);

int main(void){

    long long int x,y;
    scanf("%I64d %I64d", &x, &y);
    long long int func = 0;

    long long int tempx = x;
    long long int tempy = y;

    tempx = x/gcd(x,y);
    tempy = y/gcd(x,y);
    x = tempx;
    y = tempy;
    if(x==1){
        func=func+y;
        printf("%I64d", y);
        return 0;
    }

    long long int primex[40];
    for(int i=0; i<40; i++){
        primex[i] = 0;
    }
    int arraycount = 0;
    if(tempx%2==0){
        while(tempx%2==0){
            primex[arraycount] = 2;
            arraycount++;
            tempx = tempx/2;
        }
    }
    for(int i=3; i<=sqrt(tempx); i=i+2){
        if(tempx%i==0){
            while(tempx%i==0){
                primex[arraycount] = i;
                arraycount++;
                tempx = tempx/i;
            }
        }
    }
    if(tempx>2){
        primex[arraycount] = tempx;
        arraycount++;
    }
    tempx = x;

    long long int remainder[40];
    for(int i=0; i<40; i++){
        remainder[i] = -1;
    }

    for(int i=0; i<arraycount; i++){
        if(primex[i] != 0){
            remainder[i] = y%primex[i];
        }
    }

    int minrem = 0;
    for(int i=1; i<arraycount; i++){
        if(remainder[i]!= -1 && remainder[minrem]>remainder[i]){
            minrem = i;
        }
    }

    func = func + remainder[minrem];
    y = y - remainder[minrem];

    long long int primegcd[40];
    for(int i=0; i<40; i++){
        primegcd[i] = 0;
    }
    int gcdarraycount = 0;
    long long int gcdnum;
    int deletecount = 0;

    while(y != 0){

        gcdarraycount = 0;
        gcdnum = gcd(x,y);

        if(gcdnum%2==0){
            while(gcdnum%2==0){
                primegcd[gcdarraycount] = 2;
                gcdarraycount++;
                gcdnum = gcdnum/2;
            }
        }
        for(int i=3; i<=sqrt(gcdnum); i=i+2){
            if(gcdnum%i==0){
                while(gcdnum%i==0){
                    primegcd[gcdarraycount] = i;
                    gcdarraycount++;
                    gcdnum = gcdnum/i;
                }
            }
        }
        if(gcdnum>2){
            primegcd[gcdarraycount] = gcdnum;
            gcdarraycount++;
        }

        deletecount = 0;
        while(deletecount<gcdarraycount){
            for(int i=0; i<arraycount; i++){
                if(primex[i] == primegcd[deletecount]){
                    primex[i] = 0;
                    remainder[i] = -1;
                    deletecount++;
                }
            }
            deletecount++;
        }

        tempx = x/gcd(x,y);
        tempy = y/gcd(x,y);
        x = tempx;
        y = tempy;
        if(x==1){
            func=func+y;
            printf("%I64d", func);
            return 0;
        }

        for(int i=0; i<arraycount; i++){
            if(primex[i] != 0){
                remainder[i] = y%primex[i];
            }
        }

        minrem = 0;
        while(remainder[minrem]==-1){
            minrem++;
        }
        for(int i=minrem+1; i<arraycount; i++){
            if(remainder[i]!= -1 && remainder[minrem]>remainder[i]){
                minrem = i;
            }
        }

        func = func + remainder[minrem];
        y = y - remainder[minrem];
    }

    printf("%I64d", func);
    return 0;
}

long long int gcd(long long int x, long long int y){
    long long int a = max(x,y);
    long long int b = min(x,y);
    long long int r;
    do{
        r = a%b;
        a = b;
        b = r;
    } while(r != 0);
    return a;
}

long long int max(long long int x, long long int y){
    if(x<=y){
        return y;
    } else {
        return x;
    }
}

long long int min(long long int x, long long int y){
    if(x<=y){
        return x;
    } else {
        return y;
    }
}


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

#define MIN(a,b) ((a) < (b)? (a) : (b))
typedef unsigned long long ull_t;
typedef unsigned long ul_t;

#define MAX_FAC ((size_t)1E2)
ul_t pfac[MAX_FAC];
ul_t new_pfac[MAX_FAC];
size_t n;

int
build_pfac(ull_t x)
{
	for(ull_t i=2; i*i <= x ;i++)
		while(x % i == 0) x/=i, pfac[n++]=i;
	if(x > 1)
		pfac[n++] = x;
	return n > 1;
}

int main(int argc,char *argv[])
{
	ull_t a,b;
	assert(scanf("%I64u%I64u",&a,&b)==2);
	ull_t acc=0;

	if(!build_pfac(a)){
		acc = b%a + b/a;
		goto print_res;
	}

	while(b){
		ull_t tmp = b;
		for(size_t i=0; i<n ; i++)
			tmp = MIN(tmp, b % pfac[i]);
		acc+=tmp, b-=tmp;

		size_t new_n=0;
		for(size_t i=0; i<n ; i++){
			if(b % pfac[i])
				new_pfac[new_n++] = pfac[i];
			else
				b /= pfac[i];
		}
		memcpy(pfac,new_pfac,new_n*sizeof(ul_t));
		n = new_n;
	}

print_res:
	printf("%I64u",acc);
	return 0;
}


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

#define MIN(a,b) ((a) < (b)? (a) : (b))
typedef unsigned long long ull_t;
typedef unsigned long ul_t;

#define MAX_FAC 65
ul_t pfac[MAX_FAC];
ul_t new_pfac[MAX_FAC];
size_t n;

int
build_pfac(ull_t x)
{
	for(ull_t i=2; i*i <= x ;i++)
		while(x % i == 0) x/=i, pfac[n++]=i;
	if(x > 1)
		pfac[n++] = x;
	return n > 1;
}

int main(int argc,char *argv[])
{
	ull_t a,b;
	assert(scanf("%I64u%I64u",&a,&b)==2);
	ull_t acc=0;

	if(!build_pfac(a)){
		acc = b%a + b/a;
		goto print_res;
	}

	while(b){
		ull_t tmp = b;
		for(size_t i=0; i<n ; i++)
			tmp = MIN(tmp, b % pfac[i]);
		acc+=tmp, b-=tmp;

		size_t new_n=0;
		for(size_t i=0; i<n ; i++){
			if(b % pfac[i])
				new_pfac[new_n++] = pfac[i];
			else
				b /= pfac[i];
		}
		memcpy(pfac,new_pfac,new_n);
		n = new_n;
	}

print_res:
	printf("%I64u",acc);
	return 0;
}


#include <limits.h>
#include <stdio.h>

#define N	16
#define A	120	/* N * (N - 1) / 2 */

int main() {
	static int dp[1 << N][A + 1], rr[N], bb[N];
	static char cc[N];
	int n, i, x, a, rsum, bsum, min;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("\n%c%d%d", &cc[i], &rr[i], &bb[i]);
	for (x = 0; x < 1 << n; x++)
		for (a = 0; a <= A; a++)
			dp[x][a] = -1;
	dp[0][0] = 0;
	for (x = 0; x < 1 << n; x++) {
		int rcnt, bcnt;

		rcnt = bcnt = 0;
		for (i = 0; i < n; i++)
			if ((x & 1 << i) > 0) {
				if (cc[i] == 'R')
					rcnt++;
				else
					bcnt++;
			}
		for (a = 0; a <= A; a++)
			if (dp[x][a] >= 0)
				for (i = 0; i < n; i++)
					if ((x & 1 << i) == 0) {
						int r_ = rr[i] < rcnt ? rr[i] : rcnt;
						int b_ = bb[i] < bcnt ? bb[i] : bcnt;

						if (dp[x | 1 << i][a + r_] < dp[x][a] + b_)
							dp[x | 1 << i][a + r_] = dp[x][a] + b_;
					}
	}
	rsum = bsum = 0;
	for (i = 0; i < n; i++) {
		rsum += rr[i];
		bsum += bb[i];
	}
	min = INT_MAX;
	for (a = 0; a <= A; a++)
		if (dp[(1 << n) - 1][a] >= 0) {
			int max = bsum - dp[(1 << n) - 1][a];

			if (max < rsum - a)
				max = rsum - a;
			if (min > max)
				min = max;
		}
	printf("%d\n", min + n);
	return 0;
}


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

#define MAX 16
#define max(a,b) ((a)>(b) ? (a):(b))
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

const double multiplier = 0.97;

char str[MAX], color[MAX];
int n, m, last[MAX], order[MAX], R[MAX], B[MAX];

double rand_real(){
    return (double)rand() / RAND_MAX;
}

int solve(){
    int i, j, res = 0, red = 0, blue = 0, rcard = 0, bcard = 0;

    for (j = 0; j < n; j++){
        i = order[j];
        int req_red = max(R[i] - rcard, 0);
        int req_blue = max(B[i] - bcard, 0);

        int buy_red = max(req_red - red, 0);
        int buy_blue = max(req_blue - blue, 0);

        int tokens_bought = max(buy_red, buy_blue);

        res += tokens_bought;
        red += tokens_bought, blue += tokens_bought;
        red -= req_red, blue -= req_blue;

        if (color[i] == 'R') rcard++;
        else bcard++;
    }
    return res + n;
}

int main(){
    int t, i, j, k, x, lim, res, cur, next;

    while (scanf("%d", &n) != EOF){
        for (i = 0; i < n; i++){
            scanf("%s %d %d", str, &R[i], &B[i]);
            color[i] = str[0];
        }
        for (i = 0; i < n; i++) order[i] = i;

        double temperature = 2e5;
        cur = res = solve(), lim = 2e5;

        for (t = 0; t < lim; t++){
            m = 1;
            for (i = 0; i < n; i++) last[i] = order[i];

            while (m--){
                i = rand() % n, j = rand() % n;
                x = order[i], order[i] = order[j], order[j] = x;
            }

            next = solve();
            if (next < res) res = next;

            if (next < cur) cur = next;
            else{
                double p = exp((double)-(next - cur) / temperature);
                if (rand_real() <= p) cur = next;
                else{
                    for (i = 0; i < n; i++) order[i] = last[i];
                }
            }

            if (temperature > 1e-20) temperature *= multiplier;
        }

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


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

#define MAX 16
#define max(a,b) ((a)>(b) ? (a):(b))
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

const double multiplier = 0.97;

char str[MAX], color[MAX];
int n, m, last[MAX], order[MAX], R[MAX], B[MAX];

double rand_real(){
    return (double)rand() / RAND_MAX;
}

int solve(){
    int i, j, res = 0, red = 0, blue = 0, rcard = 0, bcard = 0;

    for (j = 0; j < n; j++){
        i = order[j];
        int req_red = max(R[i] - rcard, 0);
        int req_blue = max(B[i] - bcard, 0);

        int buy_red = max(req_red - red, 0);
        int buy_blue = max(req_blue - blue, 0);

        int tokens_bought = max(buy_red, buy_blue);

        res += tokens_bought;
        red += tokens_bought, blue += tokens_bought;
        red -= req_red, blue -= req_blue;

        if (color[i] == 'R') rcard++;
        else bcard++;
    }
    return res + n;
}

int main(){
    int t, i, j, k, x, lim, res, cur, next;

    while (scanf("%d", &n) != EOF){
        for (i = 0; i < n; i++){
            scanf("%s %d %d", str, &R[i], &B[i]);
            color[i] = str[0];
        }
        for (i = 0; i < n; i++) order[i] = i;

        double temperature = 3e5;
        cur = res = solve(), lim = 3e5;

        for (t = 0; t < lim; t++){
            m = 1;
            for (i = 0; i < n; i++) last[i] = order[i];

            while (m--){
                i = rand() % n, j = rand() % n;
                x = order[i], order[i] = order[j], order[j] = x;
            }

            next = solve();
            if (next < res) res = next;

            if (next < cur) cur = next;
            else{
                double p = exp((double)-(next - cur) / temperature);
                if (rand_real() <= p) cur = next;
                else{
                    for (i = 0; i < n; i++) order[i] = last[i];
                }
            }

            if (temperature > 1e-20) temperature *= multiplier;
        }

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


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

#define MAX 16
#define max(a,b) ((a)>(b) ? (a):(b))
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

const double multiplier = 0.97;

char str[MAX], color[MAX];
int n, m, last[MAX], order[MAX], R[MAX], B[MAX];

double rand_real(){
    return (double)rand() / RAND_MAX;
}

int solve(){
    int i, j, res = 0, red = 0, blue = 0, rcard = 0, bcard = 0;

    for (j = 0; j < n; j++){
        i = order[j];
        int req_red = max(R[i] - rcard, 0);
        int req_blue = max(B[i] - bcard, 0);

        int buy_red = max(req_red - red, 0);
        int buy_blue = max(req_blue - blue, 0);

        int tokens_bought = max(buy_red, buy_blue);

        res += tokens_bought;
        red += tokens_bought, blue += tokens_bought;
        red -= req_red, blue -= req_blue;

        if (color[i] == 'R') rcard++;
        else bcard++;
    }
    return res + n;
}

int main(){
    int t, i, j, k, x, lim, res, cur, next;

    while (scanf("%d", &n) != EOF){
        for (i = 0; i < n; i++){
            scanf("%s %d %d", str, &R[i], &B[i]);
            color[i] = str[0];
        }
        for (i = 0; i < n; i++) order[i] = i;

        double temperature = 1666667;
        cur = res = solve(), lim = 166667;

        for (t = 0; t < lim; t++){
            m = (rand() & 1) + 1;
            for (i = 0; i < n; i++) last[i] = order[i];

            while (m--){
                i = rand() % n, j = rand() % n;
                x = order[i], order[i] = order[j], order[j] = x;
            }

            next = solve();
            if (next < res) res = next;

            if (next < cur) cur = next;
            else{
                double p = exp((double)-(next - cur) / temperature);
                if (rand_real() <= p) cur = next;
                else{
                    for (i = 0; i < n; i++) order[i] = last[i];
                }
            }

            if (temperature > 1e-20) temperature *= multiplier;
        }

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


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

typedef int64_t i64;
typedef int32_t i32;

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

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

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

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


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

#define MAXN 500

char s[MAXN+1];

int dp[MAXN+1][MAXN+1];

void print_substr(FILE* fp, char* s, int i, int j) {
    char ch = s[j];
    s[j] = '\0';
    fprintf(fp, "%s", s+i);
    s[j] = ch;
}

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

int f(int i, int j) {
    if(dp[i][j] != -1) {
        return dp[i][j];
    }
    if(i == j) {
        dp[i][j] = 0;
        return 0;
    }
    int res = f(i+1, j) + 1;
    for(int k=i+1; k<j; ++k) {
        if(s[k] == s[i]) {
            res = min(res, f(i+1, k) + f(k, j));
        }
    }
    dp[i][j] = res;
    /*
    fprintf(stderr, "f(%d, %d) = f(", i, j);
    print_substr(stderr, s, i, j);
    fprintf(stderr, ") = %d\n", res);
    */
    return res;
}

int main() {
    int n;
#ifdef EKLAVYA
    scanf("%s", s);
    n = strlen(s);
#else
    scanf("%d", &n);
    scanf("%s", s);
#endif

    for(int i=0; i<=n; ++i) {
        for(int j=0; j<=n; ++j) {
            dp[i][j] = -1;
        }
    }
    printf("%d\n", f(0, n));
    return 0;
}


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

typedef int64_t i64;
typedef int32_t i32;

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

#define MIN(a,b) ((a)<(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

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

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

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


#include <stdio.h>

int n;
char str[501];
int dp[501][501] = {0};

int min(int x,int y){return x<y?x:y;}

int solve(int start,int end)
{
	if(start == end)
		return dp[start][end] = 1;

	 if(str[end-1] == str[end] || str[start] == str[end])
	 {
	 	if(!dp[start][end-1])
	 		dp[start][end-1]=solve(start,end-1);
	 	dp[start][end] = dp[start][end-1];
	 	return dp[start][end];
	 }

	 if(!dp[start][end-1])
	 	dp[start][end-1] = solve(start,end-1);

	 dp[start][end] = dp[start][end-1] + 1;

	 for(int i=start+1;i<=end;i++)
	 	if(str[i] == str[end])
	 	{
	 		if(!dp[i][end])
	 			dp[i][end] = solve(i,end);

	 		int temp = dp[i][end];
	 		if(!dp[start][i-1])
	 			dp[start][i-1] = solve(start,i-1);
	 		temp += dp[start][i-1];
	 		dp[start][end] = min(temp,dp[start][end]);
	 	}

 	return dp[start][end];
}

int main()
{
	//freopen ("input.txt","r",stdin);
	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++)
		str[i] = getchar();
	str[n] = '\0';
	//fclose(stdin);
	printf("%d\n",solve(0,n-1));
}


#include<stdio.h>
#include<string.h>
long long int a[3],k;
void quicksort(long long int a[],int start,int end)
{
       long long  int pivot=a[start],temp;
       int i=start+1,j=end;
        while(i<=j)
        {
                while(i<=j)
                {
                        if(a[i]<=pivot)
                        i++;
                        else
                        break;
                }
                while(i<=j)
                {
                        if(a[j]>pivot)
                        j--;
                        else
                        break;
                }
                if(i<=j)
                {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
                }
        }
        a[start]=a[i-1];
        a[i-1]=pivot;

        if(start<i-2)
        quicksort(a,start,i-2);
        if(i<end)
        quicksort(a,i,end);
}
int min(int a,int b)
{
	return a<b?a:b;
}
int main()
{
	scanf("%I64d%I64d%I64d%I64d",&a[0],&a[1],&a[2],&k);
	quicksort(a,0,2);
	long long int ans=1;
	if(k==0)
	{
		printf("1\n");
		return 0;
	}
	else
	if(a[0]+a[1]+a[2]-3<=k)
	{
		printf("%I64d\n",a[0]*a[1]*a[2]);
		return 0;
	}
	else
	{
		long long int t1,t2,t3;
			t1=min(k/3,a[0]-1);
			ans=ans*(t1+1);
			k=k-t1;
			t2=min(k/2,a[1]-1);
			ans=ans*(t2+1);
			k=k-t2;
			t3=min(k,a[2]-1);
			ans=ans*(t3+1);

			printf("%I64d\n",ans);
			return 0;
		}

	/*{
		int i=0;
		while(i<3)
		{
			if(k<=0)
			break;
			if(a[i]>1)
			{
				if(a[i]<=k)
				{
					ans=ans*a[i];
					k=k-a[i]+1;
				}
				else
				{
					ans=ans*(k+1);
					k=0;
				}
			}
			i++;
		}
		printf("%I64d\n",ans);
		return 0;
	}*/

return 0;
}


#include<stdio.h>
int main()
{
    int x,y,z,k,temp;
    long long int ans;
    scanf("%d %d %d %d",&x,&y,&z,&k);
    x--;
    y--;
    z--;
    if(x>y)
    {
           temp=x;
           x=y;
           y=temp;
    }
    if(y>z)
    {
           temp=y;
           y=z;
           z=temp;
    }
    if(x>y)
    {
           temp=x;
           x=y;
           y=temp;
    }
   // printf("%d %d %d\n",x,y,z);
    temp=x>k/3?k/3:x;
    ans=temp+1;
    k-=temp;
    temp=y>k/2?k/2:y;
    ans*=(temp+1);
    k-=temp;
    ans*=((z>k?k:z)+1);
    printf("%I64d\n",ans);
    //system("pause");
    return 0;
}


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

int main(void)
{
    long long x, y, z, k;

    scanf("%I64d%I64d%I64d%I64d", &x, &y, &z, &k);

    long long a = 1, b = 1, c = 1;
    int i = 0;
    while(i < k)
    {
        if(i < k && x > 1)
        {
            x--;
            a++;
            i++;
        }
        if(i < k && y > 1)
        {
            y--;
            b++;
            i++;
        }
        if(i < k && z > 1)
        {
            z--;
            c++;
            i++;
        }
        if(x == 1 && y == 1 && z == 1)
            i = k;
    }

    printf("%I64d", a * b * c);

    return 0;
}


#include <stdio.h>

typedef __int64 LL;

LL F(LL A,LL N,LL M)
{
    int ret=1;
    while(N)
    {
        if(N&1)
        {
            ret=(ret%M*A%M)%M;
        }
        A=(A*A)%M;
        N>>=1;
    }
    return ret;
}

int main()
{
    LL N,M;
    scanf("%I64d %I64d",&N,&M);
    printf("%I64d\n",(F(3,N,M)+M-1)%M);
    return 0;
}


#include<stdio.h>
 long int power(long long int x,long long int n,long long int m)
  { long long int p;
     if(n==1)
     return(x%m);
     else
     { p=(power(x,n/2,m))%m;
       if(n%2==0)
        return((p*p)%m);
        else
        return((x*p*p)%m);}
        }
int main()
{
 long long int n,m,c;
   scanf("%I64d%I64d",&n,&m);
     c=power(3,n,m)%m;
     if(c==0)
     printf("%I64d",m-1);
     else
     printf("%I64d",c-1);
     return(0);
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SORT(a,n) qsort(a,n,sizeof(int),intcmp)
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define fill(a,v)                   memset(a, v, sizeof(a))
int intcmp(const void *f,const void *s)
{
   return (*(int *)f-*(int *)s);
}
int gcd(int a,int b){ return ((b==0)?a:gcd(b,a%b));}

#define MAX
#define MODBY 1000000007

typedef long long int lld;
typedef long double Lf;

int mypow(int a, int b,int m)
{
	long long int ans=1,mult=a;
	while(b){
		if(b&1)
			ans=(ans*mult)%m;
		mult*=mult;
                mult%=m;
		b>>=1;
	}
	return (int)ans;
}
int main()
{
   int cases;
   int i,j,n,m;
   scanf("%d",&n);
   scanf("%d",&m);
   printf("%d\n",(mypow(3,n,m)-1+m)%m);
   return 0;
}


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

long long m;

long binpow (long long a, long long n)
{
    long long res = 1;
    while (n)
    {
        if (n & 1)
        {
            res *= a;
            res %= m;
        }
        a *= a;
        a %= m;
        n >>= 1;
    }
    return res;
}

int main()
{
    long long n;
    scanf("%lld %lld", &n, &m);
    long long ans = binpow(3, n) - 1;
    printf("%lld", (ans < 0) ? ans + m : ans ;
    return 0;
}


#include<stdio.h>
int a[1000000001];
int count(int n,int x)
{
	if(n==1)return 2;
	if(a[n])return a[n];
	 a[n]=(3*count(n-1,x)%x+2)%x;
	 return a[n];
}
int main()
{
	int n,x;
	scanf("%d%d",&n,&x);
	printf("%d",count(n,x)%x);
	return 0;
}


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

char maxChar (char *str)
{
    char c = str[0];

    for ( int i = 1; str[i] != '\0'; i++)
    {
        if (c < str[i])
        {
            c = str[i];
        }
    }
    return c;
}

void search (char *str, char max, int pos)
{
    if (max == 'a')
        return;
    else if (str[pos] == '\0')
    {
        return search(str,max-1,0);
    }
    else if (str[pos] != max)
    {
        return search(str, max, pos + 1);
    }
    else if (str[pos] == max)
    {
        while ((str[pos] == (str[pos+1] + 1) || str[pos] == (str[pos-1] + 1)) && str[pos] == max)
        {
            for ( int i = pos; str[i] != '\0'; i++)
                str[i] = str[i+1];
            pos = pos - 1;
        }
        return search(str,max,pos+1);
    }
    else
    {
        return search(str,max,pos+1);
    }
}

int main ()
{
    int size;
    scanf("%d", &size);
    char str[size];
    scanf("%s", str);
    char lel;
    lel = maxChar(str);
    search(str,maxChar(str),0);
    printf("%d\n", (size - strlen(str)));

    return 0;
}


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

char maxChar (char *str)
{
    char c = str[0];

    for ( int i = 1; str[i] != '\0'; i++)
    {
        if (c < str[i])
        {
            c = str[i];
        }
    }
    return c;
}
int testRoutine (char *str)
{
    for (int i = 0; str[i] != '\0'; i++)
    {
        if (str[i] == (str[i+1] - 1) || str[i] == (str[i-1] - 1))
        {
            return 1;
        }
    }
    return 0;
}

void search (char *str, char max, int pos)
{
    if (max == 'a')
        return;
    else if (str[pos] == '\0')
    {
        return search(str,max-1,0);
    }
    else if (str[pos] != max)
    {
        return search(str, max, pos + 1);
    }
    else if (str[pos] == max)
    {
        while ((str[pos] == (str[pos+1] + 1) || str[pos] == (str[pos-1] + 1)) && str[pos] == max)
        {
            for ( int i = pos; str[i] != '\0'; i++)
                str[i] = str[i+1];
            pos = pos - 1;
        }
        return search(str,max,pos+1);
    }
    else
    {
        return search(str,max,pos+1);
    }
}

int main ()
{
    int size;
    scanf("%d", &size);
    char str[size];
    scanf("%s", str);
    char lel;

    while (testRoutine(str))
    {
        lel = maxChar(str);
        search(str,lel,0);

    }
    printf("%d\n", (size - strlen(str)));

    return 0;
}


#include <stdio.h>
#include <string.h>
void gogo(char a[], int j, int s, int r)
{
    for (int k = 0; k < r; k++)
        for (int i = j; i < s; i++)
        {
            a[i] = a[i + 1];
        }
}
int main(void)
{
    int s, counts = 0;
    char a[105] = {0};
    scanf("%d", &s);
    for (int i = 0; i < s; i++)
    {
        scanf(" %c", &a[i]);
    }
    for (int i = 'z'; i >= 'a'; i--)
    {
        for (int j = 0; j < strlen(a); j++)
        {
            int num = 0;
            if (a[j] == i)
            {
                if (a[j - 1] == i + 1)
                {
                    for (int k = j - 1; k >= 0; k--)
                    {
                        if (a[k] == a[j - 1])
                        {
                            num++;
                        }
                        else
                            break;
                    }
                    gogo(a, j - num, strlen(a), num);
                    counts += num;
                    if (num != 0)
                    {
                        j = 0;
                        num = 0;
                    }
                }
                if (a[j + 1] == i + 1)
                {
                    for (int k = j + 1; k < strlen(a); k++)
                    {
                        if (a[k] == a[j + 1])
                        {
                            num++;
                        }
                        else
                            break;
                    }
                    gogo(a, j + 1, strlen(a), num);
                    counts += num;
                    if (num != 0)
                    {
                        j = 0;
                        num = 0;
                    }
                }
            }
        }
    }
    printf("%d\n", counts);
}


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

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

long long choose(long long n, int k) {
  if (k > n) {
    return 0;
  }

  long long p = 1;
  for (long long i = n; i > n - k; i--) {
    p *= i;
    p %= mod;
  }

  return p;
}

int main(void) {
  int m;
  scanf("%i", &m);

  char s[50];
  sprintf(s, "%i", m);

  int len = strlen(s);
  long long f[len+1][len+1][2];

  memset(f, 0, sizeof(f));

  f[0][0][1] = 1;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j <= len; j++) {
      for (int eq = 0; eq <= 1; eq++) {
        long long cur = f[i][j][eq];
        for (char d = '0'; d <= '9'; d++) {
          if (eq && d > s[i]) {
            continue;
          }
          int n_eq = eq && (d == s[i]);
          int is_lucky = (d == '4' || d == '7') ? 1 : 0;
          f[i+1][j+is_lucky][n_eq] += cur;
          f[i+1][j+is_lucky][n_eq] %= mod;
        }
      }
    }
  }

  long long counts[len+1];
  for (int i = 0; i <= len; i++) {
    counts[i] = f[len][i][0] + f[len][i][1];
    counts[i] %= mod;
  }
  counts[0] = (counts[0] + mod - 1) % mod;

  long long ans = 0;
  for (int i = 1; i <= len; i++) {
    long long tot = 0;
    for (int j = 0; j < i; j++) {
      tot += counts[j];
    }
    long long nways = counts[i] * choose(tot, 6) % mod;
    ans += nways;
    ans %= mod;
  }

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

  return 0;
}


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

#define ll long long
#define M 1000000007

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;
  r0=x; r1=y; a0=1; a1=0; b0=0; b1=1;
  while(r1>0){
    q=r0/r1; r2=r0%r1; a2=a0-q*a1; b2=b0-q*b1;
    r0=r1; r1=r2; a0=a1; a1=a2; b0=b1; b1=b2;
  }
  *c=r0; *a=a0; *b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

int m;
ll num[11];
ll dp[11][11][2];
ll inv[30];
ll pw[30];

ll solve(int depth, int used, int fg){
  int i, ed;
  int d;
  int nused, nfg;
  ll res = 0;

  if(used < 0) return 0;

  if(depth == -1){
    if(used==0) return 1;
    return 0;
  }

  if(dp[depth][used][fg] >= 0) return dp[depth][used][fg];

  d = (m / pw[depth])%10;
  ed = d;
  if(fg) ed = 9;

  rep(i,ed+1){
    nused = used;
    nfg = fg;
    if(i < ed) nfg = 1;
    if(i==4||i==7) nused--;

    res += solve(depth-1, nused, nfg);
  }

  return dp[depth][used][fg] = res;
}

ll get_p(int a, int b){
  int i; ll res = 1;
  rep(i,b){
    res = (res * (a-i))%M;
  }
  return res;
}

ll dp2[100];

int main(){
  int i,j,k,l,n;
  int a,b,c,d,e,f;
  int cnt[11];
  ll res = 0, add, sum;

  scanf("%d",&m);

  REP(i,1,30) inv[i] = get_inv(i, M);
  pw[0] = 1;
  REP(i,1,30) pw[i] = pw[i-1] * 10;

  rep(i,11) rep(j,11) rep(k,2) dp[i][j][k] = -1;
  rep(i,11) num[i] = solve(10, i, 0);
  num[0]--;

  rep(i,100) dp2[i] = 0;
  rep(a,10) rep(b,10) rep(c,10) if(a+b+c<=11) rep(d,10) rep(e,10) if(a+b+c+d+e<=11) rep(f,10){
    k = a+b+c+d+e+f;
    if(k > 11) continue;

    rep(i,10) cnt[i] = 0;
    cnt[a]++; cnt[b]++; cnt[c]++; cnt[d]++; cnt[e]++; cnt[f++];

    add = 1;
    rep(i,10) add = (add * get_p(num[i], cnt[i]))%M;
    dp2[k] = (dp2[k] + add)%M;
  }

  REP(i,1,11){
    add = num[i];
    sum = 0;
    rep(j,i) sum += dp2[j];
    sum %= M;
    res += sum * add;
    res %= M;
  }

  if(res < 0) res += M;
  printf("%d\n",(int)res);

  return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
 long long int l,r,i,y,max,n,x,j,m;
  scanf("%I64d%I64d",&l,&r);
  max=0;

  for(i=l;i<=r;i++)
  { x=log10(i);
      n=pow(10,(x+1))-1-i;

     if(n*i>max)
       max=n*i;
       }
     printf("%I64d",max);
     return  0;
     }


#include<stdio.h>
#include<math.h>
int main()
{
 long long int l,r,i,y,max,n,x,j,m;
  scanf("%I64d%I64d",&l,&r);
  max=0;

  for(i=l;i<=r;i++)
  { x=log10(i);
  if(i==10)
  n=89;
  else
      n=pow(10,(x+1))-1-i;

     if(n*i>max)
       max=n*i;
       }
     printf("%I64d",max);
     return  0;
     }


#include<stdio.h>
int ma#include<stdio.h>
int main()
{
 long long int l,r,i,y,max,n,x,j,m;
  scanf("%I64d%I64d",&l,&r);
  max=0;

  for(i=l;i<=r;i++)
  { n=0;
    j=1;
    m=i;

     while(m>0)
     {  y=m%10;
        x=9-y;
        n=n+j*x;
        m=m/10;
        j=j*10;
        }
     if(n*i>max)
       max=n*i;
       }
     printf("%I64d",max);
     return  0;
     }


#include <stdio.h>

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

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

int reverse(int n)
{
     int r = 0, d = 1, i;

     while (n) {
	  r += (9 - n % 10) * d;
	  n /= 10;
	  d *= 10;
     }

     return r;
}

int main()
{
     int l, r, c, i;
     long long d = 1, m = 0;

     scanf("%d %d", &l, &r);

     c = r;

     while (c) {
	  c /= 10;
	  d *= 10;
     }

     d /= 10;

     if (r / d >= 5 && r / d <= 8) {
	  l = max(l, reverse(r));
     } else {
	  l = max(l, d);
     }

     if (l / d < 5) r = min(r, d * 5);

     for (i = l; i <= r; i++) {
	  m = max(m, (long long)i * reverse(i));
     }

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

     return 0;
}


#include<stdio.h>
int main()
{
 long long int l,r,i,y,max,n,x,j,m;
  scanf("%I64d%I64d",&l,&r);
  max=0;

  for(i=l;i<=r;i++)
  { n=0;
    j=1;
    m=i;

     while(m>0)
     {  y=m%10;
        x=9-y;
        n=n+j*x;
        m=m/10;
        j=j*10;
        }
     if(n*i>max)
       max=n*i;
       }
     printf("%I64d",max);
     return  0;
     }


#include<stdio.h>
#include<math.h>
double f(double t)
{
    return sqrt(fabs(t))+5*pow(t,3);
}
int main(void)
{
    double a[11],y;
    int i,k;
    for(i=0;i<11;i++)
        scanf("%lf",&a[i]);
    for(i=10;i>=0;i--)
    {
        k=a[i];
        y=f(a[i]);
        if(y>400)
            printf("f(%d) = MAGNA NIMIS!\n",k);
        else
            printf("f(%d) = %.2f\n",k,y);
    }
    return 0;
}