#include <stdio.h>
#include <memory.h>

int flag[5][5];
int flag2[5][5];
int mark[10];

int
dfs(int depth){
    int i,j,count,index;
    if(depth ==0){
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                flag2[i][j] = flag[i][j];
            }
        }

        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(mark[i] && mark[j+5]){
                    flag2[i][j]=0;
                }
            }
        }
        for(i=0 ;i<10 ;i++){
            if(! mark[i] )
                continue;
            if ( i < 5){
                count=0;
                index=0;
                for(j=0;j<5;j++){
                    if(flag2[i][j]){
                        count ++;
                        index = j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[i][index]=0;
            }
            else {
                count=0;
                index =0;
                for(j=0;j<5;j++){
                    if(flag2[j][i-5]){
                        count ++;
                        index =j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[index][i-5]=0;
            }
        }
        count =0 ;
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(flag2[i][j]){
                    count++;
                }
            }
        }
        if(count ==1)
            return 1;
        else
            return 0;
    }
    for(i=0;i<10;i++){
        if(mark[i])
            continue;
        mark[i] = 1;
        if(!dfs(depth-1))
            mark[i] =0;
        else
            return 1;
    }
    return 0;
}

int
main(int argc,
     char *argv[]){
    int n;
    scanf("%d",&n) ;
    char card[10];
    char color[5] ={'R','G','B','Y','W'};
    int i,j;
    memset(flag,0,sizeof(flag));
    for(i=0;i<n;i++){
        scanf("%s",card);
        for(j=0;j<5;j++){
            if(card[0] == color [j]){
                flag[j][card[1]-'1'] ++;
            }
        }
    }
    for(i=0;i<=10;i++){
        memset(mark,0,sizeof(mark));
        if(dfs(i)) {
            printf("%d\n",i);
            break;
        }
    }

    return 0;
}

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

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

const int color[] = {['R'] = 0, ['G'] = 1, ['B'] = 2, ['Y'] = 3, ['W'] = 4};
int combiA[4], combiB[4], table[5][5], min = 10;

int compare(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

void hoge(int maxA, int maxB) {
    int i, j;
    int flag[5][5] = {0}, ary[25], size;

    for (i = 0; i < maxA; i++)
        for (j = 0; j < 5; j++)
            flag[combiA[i]][j] |= 1 << combiA[i];

    for (j = 0; j < maxB; j++)
        for (i = 0; i < 5; i++)
            flag[i][combiB[j]] |= 1 << combiB[j] + 5;

    size = 0;
    for (i = 0; i < 5; i++)
        for (j = 0; j < 5; j++)
            if (table[i][j])
                ary[size++] = flag[i][j];

    qsort(ary, size, sizeof(int), &compare);

    for (i = 1; i < size && ary[i] != ary[i - 1]; i++) ;
    if (i == size)
        min = min(min, maxA + maxB);
}

void makeCombiB(int d, int maxA, int maxB) {
    int i;

    if (d == maxB) {
        hoge(maxA, maxB);
        return;
    }

    for (i = d == 0 ? 0 : combiB[d - 1] + 1; i < 5; i++) {
        combiB[d] = i;
        makeCombiB(d + 1, maxA, maxB);
    }
}

void makeCombiA(int d, int maxA) {
    int i;

    if (d == maxA) {
        for (i = 0; i < 5; i++)
            makeCombiB(0, maxA, i);
        return;
    }

    for (i = d == 0 ? 0 : combiA[d - 1] + 1; i < 5; i++) {
        combiA[d] = i;
        makeCombiA(d + 1, maxA);
    }
}

int main(void) {
    int i;
    int n;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        char ch1, ch2;

        scanf(" %c%c", &ch1, &ch2);

        table[color[ch1]][ch2 - '1'] = 1;
    }

    for (i = 0; i < 5; i++)
        makeCombiA(0, i);

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

    return 0;
}

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

#define N	100
#define A	(1 << 10)

int count(int n) {
	return n == 0 ? 0 : count(n & n - 1) + 1;
}

int main() {
	static int aa[N];
	static char used[A];
	int n, i, k, l, a, b, c, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		static char s[2];
		char c, d;

		scanf("%s", s);
		c = s[0];
		d = s[1];
		a = 0;
		if (c == 'R')
			a |= 1 << 0;
		else if (c == 'G')
			a |= 1 << 1;
		else if (c == 'B')
			a |= 1 << 2;
		else if (c == 'Y')
			a |= 1 << 3;
		else
			a |= 1 << 4;
		a |= 1 << 5 + d - '1';
		aa[i] = a;
	}
	for (i = 0; i < n; i++)
		used[aa[i]] = 1;
	k = 0;
	for (a = 0; a < A; a++)
		if (used[a])
			k++;
	ans = 10;
	for (b = 0; b < A; b++) {
		c = count(b);
		if (ans > c) {
			memset(used, 0, sizeof used);
			for (i = 0; i < n; i++) {
				a = aa[i] & b;
				used[a] = 1;
			}
			l = 0;
			for (a = 0; a < A; a++)
				if (used[a])
					l++;
			if (k == l)
				ans = c;
		}
	}
	printf("%d\n", ans);
	return 0;
}

#include<stdio.h>
int surity[1050][200][2],set_bit[15],no[1050][15][15],unhinted[200],aiv[1050];
int func(int n,int *a,int bit)
{
    int i;
 for(i=0;i<n;i++)
 {
    if((set_bit[a[i]/5+5]&bit)!=0)surity[bit][i][0]=1;
    if((set_bit[a[i]%5]&bit)!=0)surity[bit][i][1]=1;
 }
 int no_of_elem=0;
for(i=0;i<n;i++)
{
    if(surity[bit][i][0]==1&&surity[bit][i][1]==1)continue;
    else if(surity[bit][i][0]==1)no[bit][a[i]/5+5][a[i]%5]=1;
    else if(surity[bit][i][1]==1)no[bit][a[i]%5][a[i]/5+5]=1;
    else unhinted[no_of_elem++]=a[i];
}
for(i=0;i<=9;i++){int nos=0,j;for(j=0;j<=9;j++){if(no[bit][i][j])nos++;}if(nos>1)return 0;}
int no=unhinted[0];
for(i=0;i<no_of_elem;i++){if(unhinted[i]!=no)return 0;}return 1;
}
int no_of_bit(int bit)
{
int i=1,no=0;
while(i<=512){if((i&bit)!=0)no++;i*=2;}return no;
}
main()
{
int n,i;scanf("%d",&n);int a[n];set_bit[0]=1;for(i=1;i<=12;i++)set_bit[i]=set_bit[i-1]*2;char s[3];
for(i=0;i<n;i++)
{
    scanf("%s",s);
    switch(s[0])
    {
    case 'R': a[i]=0;break;
    case 'G': a[i]=5;break;
    case 'Y': a[i]=10;break;
    case 'B': a[i]=15;break;
    case 'W': a[i]=20;break;
    }
    a[i]+=s[1]-'0'-1;
}
for(i=0;i<=1023;i++){if(func(n,a,i))aiv[i]=1;}int min=50;
for(i=0;i<=1023;i++)
{
    int no=no_of_bit(i);
if(aiv[i]==1){if(no<min){min=no;}}
}
printf("%d",min);return 0;
}

#include <stdio.h>
#include <string.h>
int get(char c){
	if(c == 'R') return 5;
	if(c == 'G') return 6;
	if(c == 'B') return 7;
	if(c == 'Y') return 8;
	if(c == 'W') return 9;
	return (c - '1');
}
int b(int n)
{
  int y = 0;
  while (n){
    if(n & 1) y++;
    n >>= 1;
  }
  return y;
}
int main(){
	int i;
	int j;
	int n;
	char s[3];
	int hint[26] = {0};
	int has[5][5] = {0};
	int cnt = 0;
	int mask = 0;
	int ok = 1;
	int ans = 10;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%s", s);
		if(!has[get(s[0]) - 5][get(s[1])]){
			has[get(s[0]) - 5][get(s[1])] = 1;
			hint[cnt] |= 1 << get(s[0]);
			hint[cnt] |= 1 << get(s[1]);
			cnt++;
		}
	}
	for(mask = 0; mask < (1 << 10); mask++){
		ok = 1;
		for(i = 0; i < cnt && ok; i++){
			for(j = i + 1; j < cnt && ok; j++){
				if(mask & (hint[i] ^ hint[j]))
					continue;
				ok = 0;
			}
		}
		if(ok){
			if(ans > b(mask)) ans = b(mask);
		}
	}
	printf("%d", ans);
return 0;
}

#include <stdio.h>
#include <string.h>
int get(char c){
	if(c == 'R') return 5;
	if(c == 'G') return 6;
	if(c == 'B') return 7;
	if(c == 'Y') return 8;
	if(c == 'W') return 9;
	return (c - '1');
}
int b(int n)
{
  int y = 0;
  while (n){
    if(n & 1) y++;
    n >>= 1;
  }
  return y;
}
int main(){
	int i;
	int j;
	int n;
	char s[3];
	int hint[26] = {0};
	int has[5][5] = {0};
	int cnt = 0;
	int mask = 0;
	int ok = 1;
	int ans = 10;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%s", s);
		if(!has[get(s[0]) - 5][get(s[1])]){
			has[get(s[0]) - 5][get(s[1])] = 1;
			hint[cnt] |= 1 << get(s[0]);
			hint[cnt] |= 1 << get(s[1]);
			cnt++;
		}
	}
	for(mask = 0; mask < (1 << 10); mask++){
		ok = 1;
		for(i = 0; i < cnt - 1 && ok; i++){
			for(j = i + 1; j < cnt && ok; j++){
				if(mask & (hint[i] ^ hint[j]))
					continue;
				ok = 0;
			}
		}
		if(ok){
			if(ans > b(mask)) ans = b(mask);
		}
	}
	printf("%d", ans);
return 0;
}

#include <stdio.h>

int number(char c, int i)
{ // номер карты [0, 24]
    switch (c)
    {
        case 'R': return i - 1;
        case 'G': return 5 + i - 1;
        case 'B': return 10 + i - 1;
        case 'Y': return 15 + i - 1;
        case 'W': return 20 + i - 1;
    }
    return 25;
}

int color(int number)
{
    return number / 5;
}

int value(int number)
{
    return number % 5;
}

int check_color(int number, int mask)
{
    return (1 << (5 + color(number))) & mask;
}

int check_value(int number, int mask)
{
    return (1 << value(number)) & mask;
}

int count(int mask)
{
    int res = 0;
    while (mask)
    {
        res += mask % 2;
        mask /= 2;
    }
    return res;
}

int main()
{
    int cards[25] = {0};
    int n, ans, i, j, mask, flag;
    char s[3];
    char c;
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%s", s);
        c = s[0];
        j = s[1] - '0';
        cards[number(c, j)] = 1;
    }

    ans = 10;
    for(mask = 0; mask < 1023; mask++)
    {
        flag = 1;
        for (i = 0; i < 25; i++)
            if (cards[i])
            {
                for (j = i+1; j < 25; j++)
                    if (cards[j])
                    {
                        if (color(i) != color(j) &&
                                (check_color(i, mask) ||
                                 check_color(j, mask)))
                            continue;
                        if (value(i) != value(j) &&
                                (check_value(i, mask) ||
                                 check_value(j, mask)))
                            continue;

                        flag = 0;
                        break;
                    }
                if (!flag)
                    break;
            }
        if (flag && count(mask) < ans)
            ans = count(mask);
    }

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

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

int main(){
  int n;
  scanf("%d\n", &n);
  int cards[100];
  char s[310];
  gets(s);
  int i;
  for(i=0; i<n; i++){
    int b;
    int a = s[3 * i + 1] - '1';
    switch(s[3 * i]){
      case 'R': b = 0; break;
      case 'G': b = 1; break;
      case 'B': b = 2; break;
      case 'Y': b = 3; break;
      case 'W': b = 4; break;
    }
    cards[i] = 5 * b + a;
  }
  int matrix[25];
  for(i=0; i<25; i++) matrix[i] = 0;
  for(i=0; i<n; i++){
    matrix[cards[i]]=1;
  }
  n = 0;
  for(i=0; i<25; i++){
    if(matrix[i] == 1){
      cards[n] = i;
      n++;
    }
  }
  int v, k;
  int res[100];
  int min = 100;
  for(v=0; v<1024; v++){
    for(i=0; i<n; i++) res[i] = 0;
    for(i=0; i<n; i++){
      for(k=0; k<5; k++){
        int a = (v >> k) & 1;
        if(cards[i] / 5 == k && a) res[i] += 1 << k;
      }
      for(k=0; k<5; k++){
        int a = (v >> (k + 5)) & 1;
        if(cards[i] % 5 == k && a) res[i] += 1 << (k + 5);
      }
    }
    int j;
    int test = 0;
    for(i=0; i<n; i++)
    for(j=0; j<n; j++)
      if(i!=j && res[i] == res[j]) test = 1;

    if(! test){
      int count = 0;
      int v1 = v;
      while(v1 > 0){
        count += v1 & 1;
        v1 >>= 1;
      }
      if(count < min){
        min = count;
      }
    }
  }
  printf("%d\n", min);
  return 0;
}

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

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

const int color[] = {['R'] = 0, ['G'] = 1, ['B'] = 2, ['Y'] = 3, ['W'] = 4};
int combiA[4], combiB[4], table[5][5], min = 10;

int compare(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

void hoge(int maxA, int maxB) {
    int i, j;
    int flag[5][5] = {0}, ary[25], size;

    for (i = 0; i < maxA; i++)
        for (j = 0; j < 5; j++)
            flag[combiA[i]][j] |= 1 << combiA[i];

    for (j = 0; j < maxB; j++)
        for (i = 0; i < 5; i++)
            flag[i][combiB[j]] |= 1 << combiB[j] + 5;

    size = 0;
    for (i = 0; i < 5; i++)
        for (j = 0; j < 5; j++)
            if (table[i][j])
                ary[size++] = flag[i][j];

    qsort(ary, size, sizeof(int), &compare);

    for (i = 1; i < size && ary[i] != ary[i - 1]; i++) ;
    if (i == size)
        min = min(min, maxA + maxB);
}

void makeCombiB(int d, int maxA, int maxB) {
    int i;

    if (d == maxB) {
        hoge(maxA, maxB);
        return;
    }

    for (i = d == 0 ? 0 : combiB[d - 1] + 1; i < 5; i++) {
        combiB[d] = i;
        makeCombiB(d + 1, maxA, maxB);
    }
}

void makeCombiA(int d, int maxA) {
    int i;

    if (d == maxA) {
        for (i = 0; i < 4; i++)
            makeCombiB(0, maxA, i);
        return;
    }

    for (i = d == 0 ? 0 : combiA[d - 1] + 1; i < 5; i++) {
        combiA[d] = i;
        makeCombiA(d + 1, maxA);
    }
}

int main(void) {
    int i;
    int n;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        char ch1, ch2;

        scanf(" %c%c", &ch1, &ch2);

        table[color[ch1]][ch2 - '1'] = 1;
    }

    for (i = 0; i < 5; i++)
        makeCombiA(0, i);

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

    return 0;
}

#include <stdio.h>
#include <memory.h>

int flag[5][5];
int flag2[5][5];
int mark[10];

int
dfs(int depth){
    int i,j,count,index;
    if(depth ==0){
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                flag2[i][j] = flag[i][j];
            }
        }

        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(mark[i] && mark[j+5]){
                    flag2[i][j]=0;
                }
            }
        }
        for(i=0 ;i<10 ;i++){
            if(! mark[i] )
                continue;
            if ( i < 5){
                count=0;
                index=0;
                for(j=0;j<5;j++){
                    if(flag2[i][j]){
                        count ++;
                        index = j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[i][index]=0;
            }
            else {
                count=0;
                index =0;
                for(j=0;j<5;j++){
                    if(flag2[j][i-5]){
                        count ++;
                        index =j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[index][i-5]=0;
            }
        }
        count =0 ;
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(flag2[i][j]){
                    count++;
                }
            }
        }
        if(count ==1)
            return 1;
        else
            return 0;
    }
    for(i=0;i<10;i++){
        if(mark[i])
            continue;
        mark[i] = 1;
        if(!dfs(depth-1))
            mark[i] =0;
        else
            return 1;
    }
    return 0;
}

int
main(int argc,
     char *argv[]){
    int n;
    scanf("%d",&n) ;
    char card[10];
    char color[5] ={'R','G','B','Y','W'};
    int i,j;
    memset(flag,0,sizeof(flag));
    for(i=0;i<n;i++){
        scanf("%s",card);
        for(j=0;j<5;j++){
            if(card[0] == color [j]){
                flag[j][card[1]-'1'] ++;
            }
        }
    }
    if(n!=2) {
        printf("n = %d\n",n);
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                printf("%d ", flag[i][j]);
            }
            printf("\n");
        }
        return 0;
    }
    for(i=0;i<=10;i++){
        memset(mark,0,sizeof(mark));
        if(dfs(i)) {
            printf("%d\n",i);
            break;
        }
    }

    return 0;
}

#include <stdio.h>
#include <memory.h>

int flag[5][5];
int flag2[5][5];
int mark[10];
int ans ;

int
dfs(int depth){
    int i,j,count,index;
    if(depth ==0){
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                flag2[i][j] = flag[i][j];
            }
        }

        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(mark[i] && mark[j+5]){
                    flag2[i][j]=0;
                }
            }
        }
        for(i=0 ;i<10 ;i++){
            if(! mark[i] )
                continue;
            if ( i < 5){
                count=0;
                index=0;
                for(j=0;j<5;j++){
                    if(flag2[i][j]){
                        count ++;
                        index = j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[i][index]=0;
            }
            else {
                count=0;
                index =0;
                for(j=0;j<5;j++){
                    if(flag2[j][i-5]){
                        count ++;
                        index =j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[index][i-5]=0;
            }
        }
        count =0 ;
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(flag2[i][j]){
                    count++;
                }
            }
        }
        if(count ==1)
            return 1;
        else
            return 0;
    }
    for(i=0;i<10;i++){
        if(mark[i])
            continue;
        mark[i] = 1;
        if(!dfs(depth-1))
            mark[i] =0;
        else
            return 1;
    }
    return 0;
}

int
main(int argc,
     char *argv[]){
    int n;
    scanf("%d",&n);
    char card[2];
    char color[5] ={'R','G','B','Y','W'};
    int i,j;
    memset(flag,0,sizeof(flag));
    for(i=0;i<n;i++){
        scanf("%s",card);
        for(j=0;j<5;j++){
            if(card[0] == color [j]){
                flag[j][card[1]-'1'] ++;
            }
        }
    }
    if(n==4) {
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                printf("%d ", flag[i][j]);
            }
            printf("\n");
        }
    }
    for(i=0;i<=10;i++){
        memset(mark,0,sizeof(mark));
        if(dfs(i)) {
            printf("%d\n",i);
            break;
        }
    }

    return 0;
}

#include <stdio.h>
#include <memory.h>

int flag[5][5];
int flag2[5][5];
int mark[10];
int ans ;

int
dfs(int depth){
    int i,j,count,index;
    if(depth ==0){
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                flag2[i][j] = flag[i][j];
            }
        }

        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(mark[i] && mark[j+5]){
                    flag2[i][j]=0;
                }
            }
        }
        for(i=0 ;i<10 ;i++){
            if(! mark[i] )
                continue;
            if ( i < 5){
                count=0;
                index=0;
                for(j=0;j<5;j++){
                    if(flag2[i][j]){
                        count ++;
                        index = j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[i][index]=0;
            }
            else {
                count=0;
                index =0;
                for(j=0;j<5;j++){
                    if(flag2[j][i-5]){
                        count ++;
                        index =j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[index][i-5]=0;
            }
        }
        count =0 ;
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(flag2[i][j]){
                    count++;
                }
            }
        }
        if(count ==1)
            return 1;
        else
            return 0;
    }
    for(i=0;i<10;i++){
        if(mark[i])
            continue;
        mark[i] = 1;
        if(!dfs(depth-1))
            mark[i] =0;
        else
            return 1;
    }
    return 0;
}

int
main(int argc,
     char *argv[]){
    int n;
    scanf("%d",&n) ;
    char card[2];
    char color[5] ={'R','G','B','Y','W'};
    int i,j;
    memset(flag,0,sizeof(flag));
    for(i=0;i<n;i++){
        scanf("%s",card);
        for(j=0;j<5;j++){
            if(card[0] == color [j]){
                flag[j][card[1]-'1'] ++;
            }
        }
    }
    if(n!=2) {
        printf("n = %d\n",n);
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                printf("%d ", flag[i][j]);
            }
            printf("\n");
        }
        return 0;
    }
    for(i=0;i<=10;i++){
        memset(mark,0,sizeof(mark));
        if(dfs(i)) {
            printf("%d\n",i);
            break;
        }
    }

    return 0;
}

#include <stdio.h>
#include <memory.h>

int flag[5][5];
int flag2[5][5];
int mark[10];
int ans ;

int
dfs(int depth){
    int i,j,count,index;
    if(depth ==0){

        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                flag2[i][j] = flag[i][j];
            }
        }

        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(mark[i] && mark[j+5]){
                    flag2[i][j]=0;
                }
            }
        }
        for(i=0 ;i<10 ;i++){
            if(! mark[i] )
                continue;
            if ( i < 5){
                count=0;
                index=0;
                for(j=0;j<5;j++){
                    if(flag2[i][j]){
                        count ++;
                        index = j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[i][index]=0;
            }
            else {
                count=0;
                index =0;
                for(j=0;j<5;j++){
                    if(flag2[j][i-5]){
                        count ++;
                        index =j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[index][i-5]=0;
            }
        }
        count =0 ;
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(flag2[i][j]){
                    count++;
                }
            }
        }
        if(count ==1)
            return 1;
        else
            return 0;
    }
    for(i=0;i<10;i++){
        if(mark[i])
            continue;
        mark[i] = 1;
        if(!dfs(depth-1))
            mark[i] =0;
        else
            return 1;
    }
    return 0;
}

int
main(int argc,
     char *argv[]){
    int n;
    scanf("%d",&n);
    char card[2];
    char color[5] ={'R','G','B','Y','W'};
    int i,j;
    memset(flag,0,sizeof(flag));
    for(i=0;i<n;i++){
        scanf("%s",card);
        for(j=0;j<5;j++){
            if(card[0] == color [j]){
                flag[j][card[1]-'1'] ++;
            }
        }
    }
    for(i=0;i<=10;i++){
        memset(mark,0,sizeof(mark));
        if(dfs(i)) {
            printf("%d\n",i);
            break;
        }
    }

    return 0;
}

#include <stdio.h>
#include <memory.h>

int flag[5][5];
int flag2[5][5];
int mark[10];
int ans ;

int
dfs(int depth){
    int i,j,count,index;
    if(depth ==0){
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                flag2[i][j] = flag[i][j];
            }
        }

        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(mark[i] && mark[j+5]){
                    flag2[i][j]=0;
                }
            }
        }
        for(i=0 ;i<10 ;i++){
            if(! mark[i] )
                continue;
            if ( i < 5){
                count=0;
                index=0;
                for(j=0;j<5;j++){
                    if(flag2[i][j]){
                        count ++;
                        index = j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[i][index]=0;
            }
            else {
                count=0;
                index =0;
                for(j=0;j<5;j++){
                    if(flag2[j][i-5]){
                        count ++;
                        index =j;
                    }
                }
                if( count >1 ){
                    return 0;
                }
                flag2[index][i-5]=0;
            }
        }
        count =0 ;
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                if(flag2[i][j]){
                    count++;
                }
            }
        }
        if(count ==1)
            return 1;
        else
            return 0;
    }
    for(i=0;i<10;i++){
        if(mark[i])
            continue;
        mark[i] = 1;
        if(!dfs(depth-1))
            mark[i] =0;
        else
            return 1;
    }
    return 0;
}

int
main(int argc,
     char *argv[]){
    int n;
    scanf("%d",&n) ;
    char card[2];
    char color[5] ={'R','G','B','Y','W'};
    int i,j;
    memset(flag,0,sizeof(flag));
    for(i=0;i<n;i++){
        scanf("%s",card);
        for(j=0;j<5;j++){
            if(card[0] == color [j]){
                flag[j][card[1]-'1'] ++;
            }
        }
    }
    if(n==4) {
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                printf("%d ", flag[i][j]);
            }
            printf("\n");
        }
        return 0;
    }
    for(i=0;i<=10;i++){
        memset(mark,0,sizeof(mark));
        if(dfs(i)) {
            printf("%d\n",i);
            break;
        }
    }

    return 0;
}

#include<stdio.h>
int surity[1050][200][2],set_bit[15],no[1050][15],unhinted[200],aiv[1050];
int func(int n,int *a,int bit)
{
    int i;
 for(i=0;i<n;i++)
 {
    if((set_bit[a[i]/5+5]&bit)!=0)surity[bit][i][0]=1;
    if((set_bit[a[i]%5]&bit)!=0)surity[bit][i][1]=1;
 }
 int no_of_elem=0;
for(i=0;i<n;i++)
{
    if(surity[bit][i][0]==1&&surity[bit][i][1]==1)continue;
    else if (surity[bit][i][0]==1)no[bit][a[i]/5+5]++;
    else if(surity[bit][i][1]==1)no[bit][a[i]%5]++;
    else unhinted[no_of_elem++]=a[i];
}
for(i=0;i<=9;i++){if(no[bit][i]>1)return 0;}
int no=unhinted[0];
for(i=0;i<no_of_elem;i++){if(unhinted[i]!=no)return 0;}return 1;
}
int no_of_bit(int bit)
{
int i=1,no=0;
while(i<=512){if((i&bit)!=0)no++;i*=2;}return no;
}
main()
{
int n,i;scanf("%d",&n);int a[n];set_bit[0]=1;for(i=1;i<=12;i++)set_bit[i]=set_bit[i-1]*2;char s[3];
for(i=0;i<n;i++)
{
    scanf("%s",s);
    switch(s[0])
    {
    case 'R': a[i]=0;break;
    case 'G': a[i]=5;break;
    case 'Y': a[i]=10;break;
    case 'B': a[i]=15;break;
    case 'W': a[i]=20;break;
    }
    a[i]+=s[1]-'0'-1;
}
for(i=0;i<=1023;i++){if(func(n,a,i))aiv[i]=1;}int min=50;
for(i=0;i<=1023;i++)
{
    int no=no_of_bit(i);
if(aiv[i]==1){if(no<min){min=no;}}
}
printf("%d",min);return 0;
}

#include<stdio.h>
int surity[1050][200][2],set_bit[15],no[1050][15],unhinted[200],aiv[1050];
int func(int n,int *a,int bit)
{
    int i;
 for(i=0;i<n;i++)
 {
    if((set_bit[a[i]/5+5]&bit)!=0)surity[bit][i][0]=1;
    if((set_bit[a[i]%5]&bit)!=0)surity[bit][i][1]=1;
 }
 int no_of_elem=0;
for(i=0;i<n;i++)
{
    if(surity[bit][i][0]==1&&surity[bit][i][1]==1)continue;
    else if (surity[bit][i][0]==1)no[bit][a[i]/5+5]++;
    else if(surity[bit][i][1]==1)no[bit][a[i]%5]++;
    else unhinted[no_of_elem++]=a[i];
}
for(i=0;i<9;i++){if(no[bit][i]>1)return 0;}
int no=unhinted[0];
for(i=0;i<no_of_elem;i++){if(unhinted[i]!=no)return 0;}return 1;
}
int no_of_bit(int bit)
{
int i=1,no=0;
while(i<=512){if((i&bit)!=0)no++;i*=2;}return no;
}
main()
{
int n,i;scanf("%d",&n);int a[n];set_bit[0]=1;for(i=1;i<=12;i++)set_bit[i]=set_bit[i-1]*2;char s[3];
for(i=0;i<n;i++)
{
    scanf("%s",s);
    switch(s[0])
    {
    case 'R': a[i]=0;break;
    case 'G': a[i]=5;break;
    case 'Y': a[i]=10;break;
    case 'B': a[i]=15;break;
    case 'W': a[i]=20;break;
    }
    a[i]+=s[1]-'0'-1;
}
for(i=0;i<=1023;i++){if(func(n,a,i))aiv[i]=1;}int min=50;
for(i=0;i<=1023;i++)
{
    int no=no_of_bit(i);
if(aiv[i]==1){if(no<min)min=no;}
}
printf("%d",min);return 0;
}

#include<stdio.h>
int surity[1050][200][2],set_bit[15],no[1050][15],unhinted[200],aiv[1050];
int func(int n,int *a,int bit)
{
    int i;
 for(i=0;i<n;i++)
 {
    if((set_bit[a[i]/5+5]&bit)!=0)surity[bit][i][0]=1;
    if((set_bit[a[i]%5]&bit)!=0)surity[bit][i][1]=1;
 }
 int no_of_elem=0;
for(i=0;i<n;i++)
{
    if(surity[bit][i][0]==1&&surity[bit][i][1]==1)continue;
    else if (surity[bit][i][0]==1)no[bit][a[i]/5+5]++;
    else if(surity[bit][i][1]==1)no[bit][a[i]%5]++;
    else unhinted[no_of_elem++]=a[i];
}
for(i=0;i<9;i++){if(no[bit][i]>1)return 0;}
int no=unhinted[0];
for(i=0;i<no_of_elem;i++){if(unhinted[i]!=no)return 0;}return 1;
}
int no_of_bit(int bit)
{
int i=1,no=0;
while(i<=512){if((i&bit)!=0)no++;i*=2;}return no;
}
main()
{
int n,i;scanf("%d",&n);int a[n];set_bit[0]=1;for(i=1;i<=12;i++)set_bit[i]=set_bit[i-1]*2;char s[3];
for(i=0;i<n;i++)
{
    scanf("%s",s);
    switch(s[0])
    {
    case 'R': a[i]=0;break;
    case 'G': a[i]=5;break;
    case 'Y': a[i]=10;break;
    case 'B': a[i]=15;break;
    case 'W': a[i]=20;break;
    }
    a[i]+=s[1]-'0';
}
for(i=0;i<=1023;i++){if(func(n,a,i))aiv[i]=1;}int min=50;
for(i=0;i<=1023;i++)
{
    int no=no_of_bit(i);
if(aiv[i]==1){if(no<min)min=no;}
}
printf("%d",min);return 0;
}

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

int main(){
  int n;
  scanf("%d\n", &n);
  int cards[100];
  char s[310];
  gets(s);
  int i;
  for(i=0; i<n; i++){
    int b;
    int a = s[3 * i + 1] - '0';
    switch(s[3 * i]){
      case 'R': b = 0; break;
      case 'G': b = 1; break;
      case 'B': b = 2; break;
      case 'Y': b = 3; break;
      case 'W': b = 4; break;
    }
    cards[i] = 5 * b + a;
  }
  int matrix[25];
  for(i=0; i<25; i++) matrix[i] = 0;
  for(i=0; i<n; i++){
    matrix[cards[i]]=1;
  }
  n = 0;
  for(i=0; i<25; i++){
    if(matrix[i] == 1){
      cards[n] = i;
      n++;
    }
  }
  int v, k;
  int res[100];
  int min = 100;
  for(v=0; v<1024; v++){
    for(i=0; i<n; i++) res[i] = 0;
    for(i=0; i<n; i++){
      for(k=0; k<5; k++){
        int a = (v >> k) & 1;
        if(cards[i] / 5 == k && a) res[i] += 1 << k;
      }
      for(k=0; k<5; k++){
        int a = (v >> (k + 5)) & 1;
        if(cards[i] % 5 == k && a) res[i] += 1 << (k + 5);
      }
    }
    int j;
    int test = 0;
    for(i=0; i<n; i++)
    for(j=0; j<n; j++)
      if(i!=j && res[i] == res[j]) test = 1;

    if(! test){
      int count = 0;
      int v1 = v;
      while(v1 > 0){
        count += v1 & 1;
        v1 >>= 1;
      }
      if(count < min){
        min = count;
      }
    }
  }
  printf("%d\n", min);
  return 0;
}


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

void pathFinder(int arr[],int hash[500][500],int last[500][500][32][8],int index,int n,int *count,int flag,int x,int y)
{
	if(index == n)
	{
		return;
	}

	int i,j,k;

	int temp1,temp2;

	last[x][y][index][flag] = 1;

	for(i=0;i<arr[index];i++)
	{
		if(hash[x][y] == 0)
		{
			hash[x][y] = 1;
			(*count)++;
		}
		if(flag == 0)
		{
			y++;
		}
		else if(flag == 1)
		{
			x++;
			y++;
		}
		else if(flag == 2)
		{
			x++;
		}
		else if(flag == 3)
		{
			x++;
			y--;
		}
		else if(flag == 4)
		{
			y--;
		}
		else if(flag == 5)
		{
			x--;
			y--;
		}
		else if(flag == 6)
		{
			x--;
		}
		else if(flag == 7)
		{
			x--;
			y++;
		}
	}

	temp1 = (flag + 1) % 8;
	temp2 = (flag + 7) % 8;

		if(flag == 0)
		{
			y--;
		}
		else if(flag == 1)
		{
			x--;
			y--;
		}
		else if(flag == 2)
		{
			x--;
		}
		else if(flag == 3)
		{
			x--;
			y++;
		}
		else if(flag == 4)
		{
			y++;
		}
		else if(flag == 5)
		{
			x++;
			y++;
		}
		else if(flag == 6)
		{
			x++;
		}
		else if(flag == 7)
		{
			x++;
			y--;
		}
	int p=x,q=y;
	flag=temp1;
	if(flag == 0)
		{
			y++;
		}
		else if(flag == 1)
		{
			x++;
			y++;
		}
		else if(flag == 2)
		{
			x++;
		}
		else if(flag == 3)
		{
			x++;
			y--;
		}
		else if(flag == 4)
		{
			y--;
		}
		else if(flag == 5)
		{
			x--;
			y--;
		}
		else if(flag == 6)
		{
			x--;
		}
		else if(flag == 7)
		{
			x--;
			y++;
		}

	if(last[x][y][index+1][flag] == 0)
	pathFinder(arr,hash,last,index+1,n,count,temp1,x,y);

	x=p;y=q;
	flag=temp2;
	if(flag == 0)
		{
			y++;
		}
		else if(flag == 1)
		{
			x++;
			y++;
		}
		else if(flag == 2)
		{
			x++;
		}
		else if(flag == 3)
		{
			x++;
			y--;
		}
		else if(flag == 4)
		{
			y--;
		}
		else if(flag == 5)
		{
			x--;
			y--;
		}
		else if(flag == 6)
		{
			x--;
		}
		else if(flag == 7)
		{
			x--;
			y++;
		}

	if(last[x][y][index+1][flag] == 0)
	pathFinder(arr,hash,last,index+1,n,count,temp2,x,y);

}

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

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

	int hash[500][500] = {0};

	int last[500][500][32][8]={0};

	k = 0;

	//hash[500][500] = 1;

	pathFinder(arr,hash,last,0,n,&k,0,250,250);

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

	return 0;
}

//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
void llswap(long long *a,long long *b){long long c;c=(*a);(*a)=(*b);(*b)=c;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
void dbswap(double *a,double *b){double c;c=(*a);(*a)=(*b);(*b)=c;}
void chswap(char *a,char *b){char c;c=(*a);(*a)=(*b);(*b)=c;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}
int chsortfncsj(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
int chsortfnckj(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}

void shuffledget(int x[],int n){
    int i,b[524288],p,c;
    for(i=0;i<n;i++){
        b[i]=i;
    }
    for(i=n;i>=1;i--){
        p=rand()%i;
        c=b[i-1];b[i-1]=b[p];b[p]=c;
    }
    for(i=0;i<n;i++){
        scanf("%d",&x[b[i]]);
    }
}

int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
int dx8[8]={-1,-1,-1,0,0,1,1,1};
int dy8[8]={-1,0,1,-1,1,-1,0,1};

int search(int x,int a[],int n){
    int st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

void getperm(int a[],int n){
  int i,p;
  for(i=0;i<n;i++){
    a[i]=i;
  }
  for(i=n-1;i>=1;i--){
    p=rand()%(i+1);
    swap(&a[p],&a[i]);
  }
}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

void coordinate_comp(int a[],int n){
  int i,c=0;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

int n,a[30],res=0;
int mem[400][400]={0};
bool fl[400][400][32][8]={0};

int rotx[8]={1,1,0,-1,-1,-1,0,1};
int roty[8]={0,1,1,1,0,-1,-1,-1};

void solve(int step,int x,int y,int key){
  //printf("%d : (%d , %d) + %d\n",step,x,y,key);
  if(step==n){return;}
  int i,l=a[step];
  if(fl[x][y][step][key]!=0){return;}
  fl[x][y][step][key]=1;
  for(i=0;i<l;i++){
    x+=rotx[key];
    y+=roty[key];
    mem[x][y]=1;
  }
  solve(step+1,x,y,(key+1)&7);
  solve(step+1,x,y,(key+7)&7);
}

int main(void){
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d",&a[i]);}
  solve(0,200,200,0);
  for(i=0;i<400;i++){
    for(j=0;j<400;j++){
      //printf("%d",mem[i][j]);
      if(mem[i][j]==1){res++;}
    }//puts("");
  }
  printf("%d\n",res);
  return 0;
}

//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
void llswap(long long *a,long long *b){long long c;c=(*a);(*a)=(*b);(*b)=c;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
void dbswap(double *a,double *b){double c;c=(*a);(*a)=(*b);(*b)=c;}
void chswap(char *a,char *b){char c;c=(*a);(*a)=(*b);(*b)=c;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}
int chsortfncsj(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
int chsortfnckj(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}

void shuffledget(int x[],int n){
    int i,b[524288],p,c;
    for(i=0;i<n;i++){
        b[i]=i;
    }
    for(i=n;i>=1;i--){
        p=rand()%i;
        c=b[i-1];b[i-1]=b[p];b[p]=c;
    }
    for(i=0;i<n;i++){
        scanf("%d",&x[b[i]]);
    }
}

int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
int dx8[8]={-1,-1,-1,0,0,1,1,1};
int dy8[8]={-1,0,1,-1,1,-1,0,1};

int search(int x,int a[],int n){
    int st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

void getperm(int a[],int n){
  int i,p;
  for(i=0;i<n;i++){
    a[i]=i;
  }
  for(i=n-1;i>=1;i--){
    p=rand()%(i+1);
    swap(&a[p],&a[i]);
  }
}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

void coordinate_comp(int a[],int n){
  int i,c=0;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

int n,a[30],res=0;
int mem[400][400]={0};
int fl[400][400][8]={0};

int rotx[8]={1,1,0,-1,-1,-1,0,1};
int roty[8]={0,1,1,1,0,-1,-1,-1};

void solve(int step,int x,int y,int key){
  //printf("%d : (%d , %d) + %d\n",step,x,y,key);
  if(step==n){return;}
  int i,l=a[step];
  if(fl[x][y][key]>=l){return;}
  fl[x][y][key]=l;
  for(i=0;i<l;i++){
    x+=rotx[key];
    y+=roty[key];
    mem[x][y]=1;
  }
  solve(step+1,x,y,(key+1)&7);
  solve(step+1,x,y,(key+7)&7);
}

int main(void){
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d",&a[i]);}
  //mem[200][200]=1;
  solve(0,200,200,0);
  for(i=0;i<400;i++){
    for(j=0;j<400;j++){
      //printf("%d",mem[i][j]);
      if(mem[i][j]==1){res++;}
    }//puts("");
  }
  printf("%d\n",res);
  return 0;
}

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

void pathFinder(int arr[],int hash[1000][1000],int index,int n,int *count,int flag,int x,int y)
{
	if(index == n)
	{
		return;
	}

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

	int i,j,k;

	int temp1,temp2;

	for(i=0;i<arr[index] + 1;i++)
	{
		if(hash[x][y] == 0)
		{
			hash[x][y] = 1;
			(*count)++;
		}
		if(flag == 0)
		{
			y++;
		}
		else if(flag == 1)
		{
			x++;
			y++;
		}
		else if(flag == 2)
		{
			x++;
		}
		else if(flag == 3)
		{
			x++;
			y--;
		}
		else if(flag == 4)
		{
			y--;
		}
		else if(flag == 5)
		{
			x--;
			y--;
		}
		else if(flag == 6)
		{
			x--;
		}
		else if(flag == 7)
		{
			x--;
			y++;
		}
	}

	temp1 = (flag + 1) % 8;
	temp2 = (flag + 7) % 8;

		if(flag == 0)
		{
			y--;
		}
		else if(flag == 1)
		{
			x--;
			y--;
		}
		else if(flag == 2)
		{
			x--;
		}
		else if(flag == 3)
		{
			x--;
			y++;
		}
		else if(flag == 4)
		{
			y++;
		}
		else if(flag == 5)
		{
			x++;
			y++;
		}
		else if(flag == 6)
		{
			x++;
		}
		else if(flag == 7)
		{
			x++;
			y--;
		}

	pathFinder(arr,hash,index+1,n,count,temp1,x,y);

	pathFinder(arr,hash,index+1,n,count,temp2,x,y);

}

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

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

	int hash[1000][1000] = {0};

	k = 0;

	hash[0][0] = 1;

	pathFinder(arr,hash,0,n,&k,0,0,0);

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

	return 0;
}

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

void pathFinder(int arr[],int hash[1000][1000],int index,int n,int *count,int flag,int x,int y)
{
	if(index == n)
	{
		return;
	}

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

	int i,j,k;

	int temp1,temp2;

	for(i=0;i<arr[index] + 1;i++)
	{
		if(hash[x][y] == 0)
		{
			hash[x][y] = 1;
			(*count)++;
		}
		if(flag == 0)
		{
			y++;
		}
		else if(flag == 1)
		{
			x++;
			y++;
		}
		else if(flag == 2)
		{
			x++;
		}
		else if(flag == 3)
		{
			x++;
			y--;
		}
		else if(flag == 4)
		{
			y--;
		}
		else if(flag == 5)
		{
			x--;
			y--;
		}
		else if(flag == 6)
		{
			x--;
		}
		else if(flag == 7)
		{
			x--;
			y++;
		}
	}

	temp1 = (flag + 1) % 8;
	temp2 = (flag + 7) % 8;

		if(flag == 0)
		{
			y--;
		}
		else if(flag == 1)
		{
			x--;
			y--;
		}
		else if(flag == 2)
		{
			x--;
		}
		else if(flag == 3)
		{
			x--;
			y++;
		}
		else if(flag == 4)
		{
			y++;
		}
		else if(flag == 5)
		{
			x++;
			y++;
		}
		else if(flag == 6)
		{
			x++;
		}
		else if(flag == 7)
		{
			x++;
			y--;
		}

	pathFinder(arr,hash,index+1,n,count,temp1,x,y);

	pathFinder(arr,hash,index+1,n,count,temp2,x,y);

}

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

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

	int hash[1000][1000] = {0};

	k = 0;

	hash[500][500] = 1;

	pathFinder(arr,hash,0,n,&k,0,500,500);

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

	return 0;
}

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

void pathFinder(int arr[],int hash[1000][1000],int index,int n,int *count,int flag,int x,int y)
{
	if(index == n)
	{
		return;
	}

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

	int i,j,k;

	int temp1,temp2;

	for(i=0;i<arr[index];i++)
	{
		if(hash[x][y] == 0)
		{
			hash[x][y] = 1;
			(*count)++;
		}
		if(flag == 0)
		{
			y++;
		}
		else if(flag == 1)
		{
			x++;
			y++;
		}
		else if(flag == 2)
		{
			x++;
		}
		else if(flag == 3)
		{
			x++;
			y--;
		}
		else if(flag == 4)
		{
			y--;
		}
		else if(flag == 5)
		{
			x--;
			y--;
		}
		else if(flag == 6)
		{
			x--;
		}
		else if(flag == 7)
		{
			x--;
			y++;
		}
	}

	temp1 = (flag + 1) % 8;
	temp2 = (flag + 7) % 8;

		/*if(flag == 0)
		{
			y--;
		}
		else if(flag == 1)
		{
			x--;
			y--;
		}
		else if(flag == 2)
		{
			x--;
		}
		else if(flag == 3)
		{
			x--;
			y++;
		}
		else if(flag == 4)
		{
			y++;
		}
		else if(flag == 5)
		{
			x++;
			y++;
		}
		else if(flag == 6)
		{
			x++;
		}
		else if(flag == 7)
		{
			x++;
			y--;
		}*/
	int p=x,q=y;
	flag=temp1;
	if(flag == 0)
		{
			y++;
		}
		else if(flag == 1)
		{
			x++;
			y++;
		}
		else if(flag == 2)
		{
			x++;
		}
		else if(flag == 3)
		{
			x++;
			y--;
		}
		else if(flag == 4)
		{
			y--;
		}
		else if(flag == 5)
		{
			x--;
			y--;
		}
		else if(flag == 6)
		{
			x--;
		}
		else if(flag == 7)
		{
			x--;
			y++;
		}

	pathFinder(arr,hash,index+1,n,count,temp1,x,y);

	x=p;y=q;
	flag=temp2;
	if(flag == 0)
		{
			y++;
		}
		else if(flag == 1)
		{
			x++;
			y++;
		}
		else if(flag == 2)
		{
			x++;
		}
		else if(flag == 3)
		{
			x++;
			y--;
		}
		else if(flag == 4)
		{
			y--;
		}
		else if(flag == 5)
		{
			x--;
			y--;
		}
		else if(flag == 6)
		{
			x--;
		}
		else if(flag == 7)
		{
			x--;
			y++;
		}

	pathFinder(arr,hash,index+1,n,count,temp2,x,y);

}

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

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

	int hash[1000][1000] = {0};

	k = 0;

	//hash[500][500] = 1;

	pathFinder(arr,hash,0,n,&k,0,500,500);

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

	return 0;
}


#include<stdio.h>
#define ll long long
ll fib[51];

void solve( int n, int *a, ll k ) {
	if( n == 0 )
		return;
	if( k <= fib[n-1] ) {
		solve( n-1, a+1, k );
	}
	else {
		int t = a[0];
		a[0] = a[1];
		a[1] = t;
		solve( n-2, a+2, k - fib[n-1]);
	}
	return;
}

int main() {
	int n;
	long long k;
	scanf("%d%lld", &n, &k);
	int a[n];
	fib[0]=1;
	fib[1]=1;
	for( int i=0; i<n; ++i )
		a[i]=i+1;
	for(int i=2; i<=n; ++i )
		fib[i] = fib[i-1]+fib[i-2];
	solve( n, a, k );
	for( int i=0; i<n; ++i )
		printf("%d ", a[i]);
	printf("\n");
}

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

#define N	50

int main() {
	static long long ff[N + 1];
	int n, i, a;
	long long k;

	scanf("%d%lld", &n, &k);
	ff[0] = ff[1] = 1;
	for (i = 2; i <= n; i++)
		ff[i] = ff[i - 1] + ff[i - 2];
	a = 0;
	while (n > 0)
		if (k <= ff[n - 1]) {
			printf("%d ", a + 1);
			a++;
			n--;
		} else {
			k -= ff[n - 1];
			printf("%d %d ", a + 2, a + 1);
			a += 2;
			n -= 2;
		}
	printf("\n");
	return 0;
}

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

uint64_t fib[51];

void findperm(uint64_t n, uint64_t k, uint64_t offset){
  assert( k <= fib[n]);
  if (n == 0){
    puts("");
    return;
  }
  if (n == 1){
    printf("%llu\n", offset);
    return;
  }
  if ( k <= fib[n-1]){
    printf("%llu ", offset);
    findperm(n-1, k, offset+1);
  }
  else{
    printf("%llu %llu ", offset+1, offset);
    findperm(n-2, k -fib[n-1], offset+2);
  }
}

int main(void){
  uint64_t n, k;
  fib[0] = 1;
  fib[1] = 1;
  for (size_t k = 2; k <= 50; k++)
    fib[k] = fib[k-1]+fib[k-2];

  scanf("%llu %llu", &n, &k);
  findperm(n, k, 1);
  return 0;
}

#include<stdio.h>
typedef long long unsigned llu;
typedef unsigned u;
llu F[64];
void C(u n,llu l,u p)
{
	if(!n){putchar('\n');return;}
	if(F[n-1]>=l)
	{
		printf("%u ",p);
		C(n-1,l,p+1);
	}
	else
	{
		printf("%u %u ",p+1,p);
		C(n-2,l-F[n-1],p+2);
	}
	return;
}
int main()
{
	u i,j,k,n;llu l;
	for(F[F[0]=i=1]=1;++i<64;F[i]=F[i-1]+F[i-2]);
	scanf("%u%I64u",&n,&l);
	C(n,l,1);
	return 0;
}

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

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

long long fib[52];

void F(int n, long long k, int inc){
    if (n == 1) printf("%d ", 1 + inc);
    if (n == 2){
        if (k == 1) printf("%d %d ", 1 + inc, 2 + inc);
        else printf("%d %d ", 2 + inc, 1 + inc);
    }
    if (n < 3) return;

    if (k <= fib[n - 1]){
        printf("%d ", 1 + inc);
        F(n - 1, k, inc + 1);
    }
    else{
        printf("%d %d ", 2 + inc, 1 + inc);
        F(n - 2, k - fib[n - 1], inc + 2);
    }
}

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

    fib[0] = 1, fib[1] = 1;
    for (i = 2; i < 52; i++) fib[i] = fib[i - 1] + fib[i - 2];

    while (scanf("%d %I64d", &n, &k) != EOF){
        F(n, k, 0);
        puts("");
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(){
	int n,i;
	long long k,*left;
	scanf("%d %I64d",&n,&k);
	if(n<3){
		if(k==1){
			printf("1");
			if(n==1)
				printf("\n");
			else
				printf(" 2\n");
		}
		else
			printf("2 1\n");
		return 0;
	}
	left=(long long *)malloc(sizeof(long long)*n);
	left[n-1]=0;
	left[n-2]=1;
	for(i=n-3;i>0;i--){
		left[i]=left[i+1]+left[i+2]+1;
	}
	k--;
	for(i=1;i<n;i++){
		if(k>left[i]){
			printf("%d %d ",i+1,i);
			k-=left[i]+1;
			i++;
		}
		else
			printf("%d ",i);
	}
	if(i==n)
		printf("%d ",n);
	printf("\n");
	return 0;
}

#include <stdio.h>

long long f[60],k;
int i,j;
int n;
int p[60];

void dfs(int,int,long long);

int main()
{
    scanf("%d%lld",&n,&k);
    f[0]=f[1]=1;
    for(i=2;i<=n;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    dfs(1,n,k);
    for(i=1;i<n;i++)
        printf("%d ",p[i]);
    printf("%d\n",p[i]);
    return 0;
}

void dfs(int i,int j,long long tmp)
{
    int k,w,ww;
    /*printf("%d %d %lld\n",i,j,tmp);*/
    if(i==n+1) return;
    for(k=1;k<=2 && k<=j;k++)
    {
        if(f[j-k]>=tmp)
        {
            w=i+k-1;
            ww=i+k-1;
            while(i<=ww)
            {
                p[i]=w;
                i++;
                w--;
            }
            dfs(i,j-k,tmp);
            return;
        }
        else tmp-=f[j-k];
    }
}

#include<stdio.h>
long long int fib[55];
void fibo(long long int n)
{
	if(n==53)
		return;
	fib[n]=fib[n-1]+fib[n-2];
	fibo(n+1);
}
void func(long long int k,long long int r,long long int n)
{
	if(n==0)
		return;
	if(k<=fib[n])
	{
		printf("%lld ",1+r);
		func(k,r+1,n-1);
	}
	else
	{
		printf("%lld %lld ",2+r,1+r);
		func(k-fib[n],r+2,n-2);
	}
}
long long int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	fib[1]=1;
	fib[2]=1;
	fibo(3);
	func(k,0,n);
	printf("\n");
	return 0;
}

#include<stdio.h>
long long int fib[55];
void fibo(int n)
{
	if(n==53)
		return;
	fib[n]=fib[n-1]+fib[n-2];
	fibo(n+1);
}
void func(int k,int r,int n)
{
	if(n==0)
		return;
	if(k<=fib[n])
	{
		printf("%d ",1+r);
		func(k,r+1,n-1);
	}
	else
	{
		printf("%d %d ",2+r,1+r);
		func(k-fib[n],r+2,n-2);
	}
}
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	fib[1]=1;
	fib[2]=1;
	fibo(3);
	func(k,0,n);
	printf("\n");
	return 0;
}

#include<stdio.h>
typedef long long unsigned llu;
typedef unsigned u;
void F(u n,llu l,u p)
{
	if(!n){printf("%u\n",p);return;}
	u i=1,j=n-1;
	while((1llu<<j)<l){l-=(1llu<<j--);++i;}
	for(j=i;j--;)printf("%u ",j+p);
	if(n>=i)F(n-i,l,p+i);
	return;
}
int main()
{
	u n;llu l;
	scanf("%u%I64u",&n,&l);
	F(n-1,l,1);
	return 0;
}

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

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

long long fib[52];

void F(int n, int k, int inc){
    if (n == 1) printf("%d ", 1 + inc);
    if (n == 2){
        if (k == 1) printf("%d %d ", 1 + inc, 2 + inc);
        else printf("%d %d ", 2 + inc, 1 + inc);
    }
    if (n < 3) return;

    if (k <= fib[n - 1]){
        printf("%d ", 1 + inc);
        F(n - 1, k, inc + 1);
    }
    else{
        printf("%d %d ", 2 + inc, 1 + inc);
        F(n - 2, k - fib[n - 1], inc + 2);
    }
}

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

    fib[0] = 1, fib[1] = 1;
    for (i = 2; i < 52; i++) fib[i] = fib[i - 1] + fib[i - 2];

    while (scanf("%d %I64d", &n, &k) != EOF){
        F(n, k, 0);
        puts("");
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(){
	int n,i;
	long long k,*left;
	scanf("%d %I64d",&n,&k);
	if(n<3){
		if(k==1){
			printf("1");
			if(n==1)
				printf("\n");
			else
				printf(" 2\n");
		}
		else
			printf("2 1\n");
		return 0;
	}
	left=(long long *)malloc(sizeof(long long)*n);
	left[n-1]=0;
	left[n-2]=1;
	left[n-3]=2;
	for(i=n-4;i>0;i--){
		left[i]=left[i+1]+left[i+3]+2;
	}
	k--;
	for(i=1;i<n;i++){
		if(k>left[i]){
			printf("%d %d ",i+1,i);
			k-=left[i]+1;
			i++;
		}
		else
			printf("%d ",i);
	}
	if(i==n)
		printf("%d ",n);
	printf("\n");
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(){
	int n,i;
	long long k,*left;
	scanf("%d %I64d",&n,&k);
	if(n<3){
		if(k==1){
			printf("1");
			if(n==1)
				printf("\n");
			else
				printf(" 2\n");
		}
		else
			printf("2 1\n");
		return 0;
	}
	left=(long long *)malloc(sizeof(long long)*n);
	left--;
	left[n]=-1;
	left[n-1]=0;
	left[n-2]=1;
	for(i=n-3;i>0;i--){
		left[i]=left[i+1]+left[i+3]+2;
	}
	k--;
	for(i=1;i<n;i++){
		if(k>left[i]){
			printf("%d %d ",i+1,i);
			k-=left[i]+1;
			i++;
		}
		else
			printf("%d ",i);
	}
	if(i==n)
		printf("%d ",n);
	printf("\n");
	return 0;
}

#include <stdio.h>

long long f[60];
int i,j;
int n,k;
int p[60];

void dfs(int,int,long long);

int main()
{
    scanf("%d%lld",&n,&k);
    f[0]=f[1]=1;
    for(i=2;i<=n;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    dfs(1,n,k);
    for(i=1;i<n;i++)
        printf("%d ",p[i]);
    printf("%d\n",p[i]);
    return 0;
}

void dfs(int i,int j,long long tmp)
{
    int k,w,ww;
    /*printf("%d %d %lld\n",i,j,tmp);*/
    if(i==n+1) return;
    for(k=1;k<=2 && k<=j;k++)
    {
        if(f[j-k]>=tmp)
        {
            w=i+k-1;
            ww=i+k-1;
            while(i<=ww)
            {
                p[i]=w;
                i++;
                w--;
            }
            dfs(i,j-k,tmp);
            return;
        }
        else tmp-=f[j-k];
    }
}

#include <stdio.h>

long long f[60];
int i,j;
int n,k;
int p[60];

void dfs(int,int,long long);

int main()
{
    scanf("%d%d",&n,&k);
    f[0]=f[1]=1;
    for(i=2;i<=n;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    dfs(1,n,k);
    for(i=1;i<n;i++)
        printf("%d ",p[i]);
    printf("%d\n",p[i]);
    return 0;
}

void dfs(int i,int j,long long tmp)
{
    int k,w,ww;
    /*printf("%d %d %lld\n",i,j,tmp);*/
    if(i==n+1) return;
    for(k=1;k<=2 && k<=j;k++)
    {
        if(f[j-k]>=tmp)
        {
            w=i+k-1;
            ww=i+k-1;
            while(i<=ww)
            {
                p[i]=w;
                i++;
                w--;
            }
            dfs(i,j-k,tmp);
            return;
        }
        else tmp-=f[j-k];
    }
}

#include <stdio.h>

long long f[60];
int i,j;
int n,k;
int p[60];

void dfs(int,int,long long);

int main()
{
    scanf("%d%d",&n,&k);
    f[0]=f[1]=1;
    for(i=2;i<=n;i++)
    {
        f[i]=f[i-1]*2;
    }
    dfs(1,n,k);
    for(i=1;i<n;i++)
        printf("%d ",p[i]);
    printf("%d\n",p[i]);
    return 0;
}

void dfs(int i,int j,long long tmp)
{
    int k,w,ww;
    /*printf("%d %d %lld\n",i,j,tmp);*/
    if(i==n+1) return;
    for(k=1;k<=j;k++)
    {
        if(f[j-k]>=tmp)
        {
            w=i+k-1;
            ww=i+k-1;
            while(i<=ww)
            {
                p[i]=w;
                i++;
                w--;
            }
            dfs(i,j-k,tmp);
            return;
        }
        else tmp-=f[j-k];
    }
}


#include <stdio.h>

int main()
{
    char goL = 1;
    int H;
    long long N, M, Ans = 0;
    scanf("%d %I64d", &H, &N);
    M = 1LL << H;
    while(H) {
        if(goL) {
            if(N > (M >> 1)) {
                Ans += M;
                N -= M >> 1;
            } else {
                ++Ans;
                goL = 0;
            }
        } else {
            if(N <= (M >> 1)) {
                Ans += M;
            } else {
                ++Ans;
                goL = 1;
                N -= M >> 1;
            }
        }
        --H;
        M = 1LL << H;
    }
    printf("%I64d\n", Ans);
    return 0;
}

#include<stdio.h>
int main()
{
	long long int n,sum=0;
	long long int h;
	scanf("%I64d%I64d",&h,&n);
	int i=0;
	long long int l,r,m1,m2;
	l=1;
	r=1ll<<h;
	int fanxiang=0;
	for(i=0;i<h;i++)
	{
		int s=0;
		m1=(l+r)/2;
		m2=(l+r)/2+1;
		if(fanxiang==0&&n<=m1&&n>=l)
		{
			sum+=1;
			fanxiang=1;
			s=1;
		}
		else if(fanxiang==0&&n>=m2&&n<=r)
		{
			sum+=(1ll<<(h-i));
			s=2;
		}
		else if(fanxiang==1&&n<=m1)
		{
			sum+=(1ll<<(h-i));
			s=1;
		}
		else if(fanxiang==1&&n>=m2&&n<=r)
		{
			sum+=1;
			fanxiang=0;
			s=2;
		}
		if(s==1)
		{
			r=m1;
		}
		if(s==2)
		{
			l=m2;
		}

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

}

#include<stdio.h>
long long int a[51],ans;
void count(long long int h,long long int n,long long int flag){
	if(h==0)
		return ;
	if(flag==0){
		if(n <= a[h]/2){
			ans++;
//			printf("%d ",ans);
			count(h-1,n,1);
		}
		else{
			ans = ans + a[h];
//			printf("%d ",ans);
			count(h-1,n-a[h]/2,0);
		}
	}
	else{
		if(n > a[h]/2){
			ans++;
//			printf("%d ",ans);
			count(h-1,n-a[h]/2,0);
		}
		else{
			ans = ans + a[h];
//			printf("%d ",ans);
			count(h-1,n,1);
		}
	}
	return ;
}
int main(){
	long long int h,i,j,k,l,n,m;
	ans=0;
	a[0] = 1;
	for(i=1;i<=50;i++)
		a[i]=a[i-1]*2;
//	for(i=0;i<10;i++)
//		printf("%d ",a[i]);
	scanf("%lld%lld",&h,&n);
	count(h,n,0);
	printf("%lld\n",ans);
	return 0;
}

#include <stdio.h>

long long answer(long long n,int h)
{
	int i,j,check;
	long long total = 0,temp = 0,temp1 = 0;
	for(i = h;i > 0;i--)
	{
		temp = 1;
		if(i == 1 && (n % 2) == 0)
		{
			for(j = 0;j < h - i + 1;j++) temp *= 2;
			total += temp;
			continue;
		}
		else if(i == 1 && (n % 2) != 0)
		{
			total++;
			continue;
		}
		if((n % 2 == 0 && (n / 2) % 2 == 0) || (n % 2 != 0 && ((n + 1) / 2) % 2 != 0))
		{
			if(i == h)
			{
				total += 2;
				temp1 = n;
				n /= 2;
				if(temp1 % 2 > 0)
				n++;
				continue;
			}
			for(j = 0;j < h - i + 1;j++) temp *= 2;
			total += temp;
		}
		else
			total++;
		temp1 = n;
		n /= 2;
		if(temp1 % 2 > 0)
			n++;
	}
	return total;
}

int main()
{
	int h,i;
	long long total = 0,n;
	scanf("%d%lld",&h,&n);
	printf("%lld",answer(n,h));
	return 0;
}

#include<stdio.h>
#include<math.h>
typedef long long ll;
int main()
{
    int h;
    ll n;
    while(scanf("%d%I64d",&h,&n) != EOF)
    {
        ll a,b,s = 0;
        for( ; h > 0; h--)
        {
            a = pow(2,h);
            if(a/2 >= n)
            {
                s++;
                n = a/2-n+1;
                continue;
            }
            else if (a/2 < n)
            {
                s += a;
                n -= a/2;
                continue;
            }

        }

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

#include<stdio.h>
typedef long long ll;
ll array[55];
int check(ll dest,ll cur)
{
      if(cur==dest)
      return 1;
      while(cur>=1)
      {
           cur  = cur/2;
           if(cur==dest)
           return 1;
      }
      return 0;
}
int main()
{
      int i;
      array[0] = 1;
      for(i=1;i<55;i++)
      array[i]= (array[i-1]+1)*2-1;
      ll h,n;
      scanf("%lld%lld",&h,&n);
      n = n + array[h-1];
      ll count = 1;
      ll index = 1,tmp,ht = h-1;
      int flag=0;
      while(index!=n)
      {
            if(flag==0)
            tmp=2*index;
            else if(flag==1)
            tmp = index*2+1;
            if(check(tmp,n))
            {
                  count+=1;
                  index = index*2+flag;
                  flag = (flag+1)%2;
                  ht--;
            }
            else
            {
                   count+=array[ht];
                   flag = (flag+1)%2;

            }

      }
      count--;
      printf("%lld\n",count);
}

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

long long getpath(long long pos, long long h, long long n, int indi, int *found)
{
    long long x = 0;
    if (h == 0 && n == pos) { *found = 1; return 0; }
    else if (h == 0) return 1;
    long long tmp = n;

    tmp = tmp>>(h);
    long long y = 1;
    if (tmp != pos) return (y<<(h + 1)) - 1;

    x = getpath(pos * 2 + indi, h - 1, n, !indi, found);
    if (!*found) x += getpath(pos * 2 + !indi, h - 1, n, indi, found);

    return x + 1;

}
int main(int argc, char **argv)
{
    long long h, n;
    scanf("%I64d%I64d", &h, &n);
    n--;
    long long x = 0;
    int found = 0;
    x = getpath(0, h, n, 0, &found);
    printf("%I64d\n", x);
    //system("pause");
    return 0;
}

#include <stdio.h>

int main(int argc, char const *argv[]){
	int h,i=0;
	long long n, acc=0, l;
	scanf("%d%I64d", &h, &n);
	l = 1ll << h;
	while (h--){
		i = !i;
		l >>= 1;
		if ((i && n<=l) || (!i && n>l)){
			++acc;
		}
		else{
			acc += 1ll << (h+1);
			i = !i;
		}
		if (n>l) n -= l;
	}
	printf("%I64d\n", acc);
	return 0;
}

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

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

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

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

// for level 2, it is {1, 2}
// for level 3, it is {3, 2, 5, 6}
// FIXED: wrong result for (39 457181784666) =>
// WRONG ANSWER, where the correct answer is
// 830699159852

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

typedef uint64_t ull;

ull f(ull h, ull k)
// number of nodes visited before exiting at k-th leaf nodes
{
	//printf("calling [%"PRIu64 ", %"PRIu64"]\n", h, k);
	if(h == 1) return k;
	if( k > (1ULL<<(h - 1)))
		return (1ULL<<h) + f(h - 1, k - (1ULL<<(h - 1)));
	else return 1 + f(h - 1, (1ULL<<(h - 1)) - k + 1);
}
/*
void test()
{
	ull one = 1ULL;
	for(int i = 0; i < 63; i++){
		one = 1ULL<<i;
		printf("one is %" PRIu64 "\n", one);
	}
}
*/
int main()
{
	ull h, n;
	//test();
	//while(1){
		scanf("%"SCNu64" %"SCNu64, &h, &n);
		printf("%" PRIu64, f(h, n));
	//}
	return 0;
}

#include<stdio.h>
int main(void){
    int h;
    long long int mocniny[56];
    long long int n;
    scanf("%i %I64d", &h, &n);
    int i;
    n--;
    long long int r=1;
    mocniny[0]=1;
    for(i=1;i<54;i++){
        mocniny[i]=2*mocniny[i-1];
    }
    long long int res=h;
    int maxi=h;
    int stav=1; // stav==1 kdyz jde pro licha doleva
    for(i=0;i<h;i++){
        r=(i%2);
        if(stav==0) r=1-r;
        if(n/mocniny[h-i-1]%2!=r){
            res=res+mocniny[h-i]-1;
            stav=1-stav;
            //printf("%i\n", i);
        }
        if(n/mocniny[h-i-1]%2==1) n=n-mocniny[h-i-1];
    }
    printf("%I64d\n", res);
    return 0;
}

#include <stdio.h>

long long int potencia (long long int exp){
    long long int i, resultado = 1;
    for(i = 0; i < exp; i++)
        resultado *= 2;
    return resultado;
}

int main(){
    long long int comeco, quantidade = 0, i, h, n, atual, l;
    char passos[100];
    for(i = 0; i < 55; i++)
        if(i%2 == 0)
            passos[i] = 'L';
        else
            passos[i] = 'R';
    scanf("%I64d %I64d", &h, &n);
    i = 0;
    comeco = atual = 1;
    l = h;
    while(n != atual - potencia(l) + 1){
        if(passos[i] == 'L'){
            if(n <= comeco + potencia(h)/2 - 1){
                quantidade += 1;
                h--;
                atual = 2*atual;
                i++;
            }else{
                quantidade += potencia(h);
                h--;
                comeco += potencia(h);
                atual = 2*atual + 1;
            }
        }else{
            if(n <= comeco + potencia(h)/2 - 1){
                quantidade += potencia(h);
                h--;
                atual = 2*atual;
            }else{
                quantidade += 1;
                h--;
                comeco += potencia(h);
                atual = 2*atual + 1;
                i++;
            }
        }
    }
    printf("%I64d\n", quantidade);
    return 0;
}

#include<stdio.h>
unsigned long long int ans=0;
unsigned long long int po(int h)
{
	if(h==0)
		return 1;
	if(h==1)
		return 2;
	unsigned long long int a=po(h/2);
	if(h%2==0)
		return a*a;
	else
		return a*a*2;
}
void func(int h,unsigned long long int n,int m)
{
	if(h==0)
	{
//		ans++;
		return;
	}
	unsigned long long int a=po(h);
	if(m==0)
	{
		if(n<=a/2)
		{
			ans++;
			func(h-1,n,1);
		}
		else
		{
			ans+=a;
			func(h-1,n-a/2,0);
		}
	}
	else
	{
		if(n<=a/2)
		{
			ans+=a;
			func(h-1,n,1);
		}
		else
		{
			ans++;
			func(h-1,n-a/2,0);
		}
	}
}
int main()
{
	int h;
	unsigned long long int n;
	scanf("%d %llu",&h,&n);
	func(h,n,0);
	printf("%llu\n",ans);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int flag = 1;
long long to(int h){
    long long ans = 0;
    while(h >= 0){
        ans+= pow(2 , h);
        --h;
    }
    if(ans % 2 == 1){
        flag = flag == 1?1:0;
    }else{
        flag = flag == 1?0:1;
    }
return ans;
}
int main()
{
     int h ,i; long long n;
    scanf("%d%I64d", &h , &n);
    long long low  = 1 , high = pow(2, h),current = 1,level = 1 , mid = 1;
    for(i = 0 ; i < h;++i){
         mid = (high+low)/2;
        if(n > mid){
            low = mid+1;
            if(flag == 1){
                current += to(h-level)+1;
            }else{
                current++;
                flag = flag == 1?0:1;
            }
        }
        else{
            high = mid;
            if(flag == 0){
                current += to(h-level)+1;
            }else{
                current++;
                flag = flag == 1?0:1;
            }
        }
        ++level;
    }
    printf("%I64d",current-1);
    return 0;
}

#include <stdio.h>
#include <math.h>
long long int power(long long int x)
{
    long long int i,t;
    t=0;
    for(i=0;i<=x;i++)
    {
        t=t+pow(2,i);
    }
        return t;
}
int main()
{
    long long int h,n,l,i,d,j;
    scanf("%lld %lld",&h,&n);
    l=pow(2,h);
    d=0;
    j=1;
    for(i=1;i<=h;i++)
    {
        d=d+1;
        if(j==1)
        {
            if(pow(2,h-i)<n)
            {
                d=d+power(h-i);
                n=n-pow(2,h-i);
            }
            else
            {
                j=0;
            }
        }
        else
        {
            if(pow(2,h-i)>=n)
            {
                d=d+power(h-i);
            }
            else
            {
                n=n-pow(2,h-i);
                j=1;
            }
        }

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

#include<stdio.h>
#include<math.h>
long long int recurse(long long int h, long long int n,char flag)
{
	if(h==0)
		return 0;
	if(flag=='L')
	{
		long long int sub;
		sub=pow(2,h-1);
		if(n>sub)
		{
			long long int k=pow(2,h);
			return k-1+recurse(h,n,'R');
		}
		else
			return 1+recurse(h-1,n,'R');
	}
	if(flag=='R')
	{
		long long int sub;
		sub=pow(2,h-1);
		if(n<=sub)
		{
			long long int k=pow(2,h);
			return k-1+recurse(h,n,'L');
		}
		else
			return 1+recurse(h-1,n-sub,'L');
	}
}
int main()
{
	long long int h,n;
	scanf("%lld%lld",&h,&n);
	printf("%lld\n",recurse(h,n,'L'));
return 0;

}

#include<stdio.h>
#include<math.h>
long long powr(int a,int b)
{
	int i;long long p=1;
	for(i=0;i<b;i++)
	p*=a;
	return p;
}
int main()
{
	int h,c;long long n,k;
	scanf("%d%lld",&h,&n);
	n--;
	int a[h],b[h],i;
	for(i=0;i<h;i++)
	{
		if(i&1)
		b[i]=1;
		else b[i]=0;
	}

	for(c=h-1;c>=0;c--)
	{
		k=n>>c;
		if(k&1)
		a[h-1-c]=1;
		else a[h-1-c]=0;
	}
	long long ans=0;int j;
	for(i=0;i<h;i++)
	{
		if(a[i]==b[i])
		{
			ans++;
			b[i+1]=(!b[i]);
		}
		else
		{
			for(j=0;j<h-i;j++)
			ans+=powr(2,j);
			ans++;
			b[i+1]=b[i];
		}
	}

	printf("%lld",ans);
	return 0;
}

#include<stdio.h>
long long off;
int main(){
	int h,fl;
	long long n,start,stop,size,present,ans,mid;
	scanf("%d %I64d",&h,&n);
	size=(long long)1<<h;
	start=1;
	stop=size;
	present=1;
	off=(long long)1<<h;
	off--;
	off+=n;
	ans=0;
	fl=0;
	while(present!=off){
		if(present<1){
			break;
		}
		mid=(start+stop)>>1;
		if(fl==0){
			if(mid<n){
				ans+=size;
				present=(present<<1)+1;
				fl=0;
				start=mid+1;
			}
			else{
				ans++;
				present<<=1;
				stop=mid;
				fl=1;
			}
		}
		else{
			if(mid<n){
				ans++;
				present=(present<<1)+1;
				fl=0;
				start=mid+1;
			}
			else{
				ans+=size;
				present<<=1;
				stop=mid;
				fl=1;
			}
		}
		size>>=1;
	}
	printf("%I64d\n",ans);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
long long leaves_counter(int counter,int h ,long long i,long long f,long long target)
{
    long long mid=(f+i)/2;//shmal 1 ymin 0
    static long long leave=0;
    static int direction=1;
    if (counter>h)
        return 0;
    if (target>mid)
    {
        if (direction)
        {
            leave+=pow(2,h-counter+1);
            direction=1;
        }
        else
        {
            leave+=1;
            direction=1;
        }
        leaves_counter(counter+1,h,mid+1,f,target);
    }
    else
    {
        if (direction)
        {
            leave+=1;
            direction=0;
        }
        else
        {
            leave+=pow(2,h-counter+1);
            direction=0;
        }
        leaves_counter(counter+1,h,i,mid,target);
    }

    return leave;

}

int main()
{
    int h;
    long long n;
    scanf("%d %lld",&h,&n);
    printf("%lld",leaves_counter(1,h,1,pow(2,h),n));
    return 0;
}

#include <stdio.h>
#include <math.h>
int main(){
    long long h , n ,ans = 0 , i;
    scanf("%I64d%I64d",&h,&n);
    int OE = 1 ;
    while (h>0){
        if (n > pow(2,h-1)){
            if(OE){
                ans+=pow(2,h);

                }
                else  {
                    ans ++ ;
                    OE = 1 - OE ;
                }
                n-=pow(2,h-1);
        }
        else {
            if (OE){
                OE=1-OE;
                ans++;
            }
            else
                ans = ans + pow(2,h);

        }
    h--;

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

#include<stdio.h>
#include<stdlib.h>
#define ll long long int
ll pow2[51];
ll sum[51];
ll numNodes(ll n,ll h,char ch,ll a,ll b)
{
    if(h == 0)
    return 0;

    int rightFlag;
    if(n > (ll)(a+b)/2)
    rightFlag = 1;
    else
    rightFlag = 0;

    if(rightFlag == 0 && ch == 'L')
    {
        // escape is in the right
        return 1+numNodes(n,h-1,'R',a,(a+b)/2);
    }
    else if(rightFlag == 1 && ch == 'R')
    {
        // escape is in the right
        return 1+numNodes(n,h-1,'L',1+((a+b)/2),b);
    }
    else
    {
        ll s = sum[h-1];
        if(ch == 'L')
        return 1+s+numNodes(n,h-1,'L',1+((a+b)/2),b);
        else
        return 1+s+ numNodes(n,h-1,'R',a,(a+b)/2);
    }
}
int main()
{
    ll h,n,i,j,ans;
    pow2[0]=1;
    pow2[1]=2;
    sum[0]=1;
    sum[1] = 3;
    for(i=2;i<51;i++)
    {
        pow2[i] = 2*pow2[i-1];
        sum[i] = sum[i-1] + pow2[i];
    }
    scanf("%I64d %I64d",&h,&n);
    ans = numNodes(n,h,'L',1,pow2[h]);
    printf("%I64d\n",ans);
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long int h,n,l,k,j,i;
	long long int path[53];
	scanf("%lld",&h);
	scanf("%lld",&n);
	l=0;
	k=n;
	for(l=0;l<h;l++)
	{
		path[l]=k;
		k=(k+1)/2;
	}
	l--;
	long long int num=1;
	int level=0;
	int dir=0;  //0=left
	long long int mycurrval=1;
	while(level<h)
	{
		k=2*(mycurrval-1)+1;
		if(path[l]==k && dir==0)
		{
			mycurrval=k;
			level++;
			dir=1;
			l--;
			num++;
		}
		else if(path[l]==k+1 && dir==0)
		{
			num=num+pow(2,(h-level));
			mycurrval=k+1;
			level++;
			dir=0;
			l--;
		}
		else if(path[l]==k && dir==1)
		{
			num=num+pow(2,(h-level));
			mycurrval=k;
			level++;
			dir=1;
			l--;
		}
		else if(path[l]==k+1 && dir==1)
		{
			mycurrval=k+1;
			level++;
			dir=0;
			l--;
			num++;
		}
	}
	num--;
	printf("%lld\n",num);
	return 0;
}

#include <stdio.h>
long long arr[65];
int main(void) {
    long long i,a[65],h,j,k,m,n,x,y,z,next,ans;
    scanf("%lld %lld",&h,&n);
    arr[0]=1;
    for(i=1;i<62;++i) arr[i]=arr[i-1]*2;
    n=arr[h]-1+n;
    m=n;
    for(i=h-1;i>=0;--i){
        x=m/2;
        if(2*x==m) a[i]=0;
        else a[i]=1;
        m=m/2;
    //  printf("%lld %lld\n",m,a[i]);
    }
    z=0;
    next=0;
    ans=1;
    while(z<h){
    //  printf("%lld %lld\n",next,arr[h-z]-1);
        if(next!=a[z]) ans+=arr[h-z]-1;
         ans++;
        next=1-a[z];
        z++;
    }
    printf("%lld\n",ans-1);
    return 0;
}

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

unsigned long long calculateNodesOfTree(int h){
    unsigned long long count = 0;
    for(int i = 0; i <= h ;i++){
        count = count + pow(2,i);
    }
    return count;
}

unsigned long long countNodes(int h, unsigned long long n){
    unsigned long long count = 0;
    int h0 = h;
    while(1){
        h--;
        if(h == -1) break;
        unsigned long long k1 = (double)n/2;

        unsigned long long k2;                 //parent node
        if(n % 2 == 0)  k2 = n/2;
        else    k2 = n/2 + 1;

        count++;
        if(k2 == 1 && h == 0){            //root node
            if(k1 == k2){       //node is Right of root node
                count = count + calculateNodesOfTree(h0-h-1);
            }
        }else{
            if(k2 % 2 == 0){        //even number - LR
                if(k1 == k2){        //node is Right of parent node
                    count = count + calculateNodesOfTree(h0-h-1);
                }
            }else if(k2 % 2 == 1){  //odd number - RL
                if(k1 < k2){        //node is Left of parent node
                    count = count +  calculateNodesOfTree(h0-h-1);
                }
            }
        }
        n = k2;
    }
    return count;
}

int main() {
	int h;
	unsigned long long n;
	scanf("%d %I64d", &h,&n);
	printf("%I64d", countNodes(h,n));

    return 0;
}

#include<stdio.h>
#include<math.h>
long long int ans=0;
void compute(char cmd,long long int n,long long int h,long long int power)
{
	if(h==0)
		return ;
	long long int l=power;
	long long int m=l/2;
	if(cmd=='L' && n>m)
	{
		ans=ans+l;
		long long int o=n%m;
		if(o==0)
			o=m;

		compute('L',o,h-1,l/2);
	}
	else if(cmd=='L' && n<=m)
	{
		ans=ans+1;
		compute('R',n,h-1,l/2);
	}
	else if(cmd=='R' && n<=m)
	{
		ans=ans+l;
		compute('R',n,h-1,l/2);
	}
	else if(cmd=='R' && n>m)
	{

		long long int o=n%m;
		if(o==0)
			o=m;
		ans=ans+1;
		compute('L',o,h-1,l/2);
	}

}
int main()
{
	long long int h,n;
	scanf("%lld %lld",&h,&n);
	long long int power=pow(2,h);
	compute('L',n,h,power);
	printf("%lld\n",ans);
	return 0;
}

#include <stdio.h>

int main()
{
    char goL = 1;
    int H;
    long long N, M, Ans = 0;
    scanf("%d %I64d", &H, &N);
    M = 1LL << H;
    while(H) {
        if(goL) {
            if(N > (M >> 1)) {
                Ans += M;
                N -= M >> 1;
            } else {
                ++Ans;
                goL = 0;
            }
        } else {
            if(N <= (M >> 1)) {
                Ans += M;
            } else {
                ++Ans;
                goL = 1;
            }
        }
        --H;
        M = 1LL << H;
    }
    printf("%I64d\n", Ans);
    return 0;
}

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

int calculateNodesOfTree(int h){
    int count = 0;
    for(int i = 0; i <= h ;i++){
        count = count + pow(2,i);
    }
    return count;
}

int countNodes(int h, int n){
    int count = 0;
    int h0 = h;
    while(1){
        h--;
        if(h == -1) break;
        double k1 = n/2;
        int k2;                 //parent node
        if(n % 2 == 0)  k2 = n/2;
        else    k2 = n/2 + 1;

        count++;
        if(k2 == 1){            //root node
            if(k1 == k2){       //node is Right of root node
                count = count + calculateNodesOfTree(h0-h-1);
            }
        }else{
            if(k2 % 2 == 0){        //even number - LR
                if(k1 == k2){        //node is Right of parent node
                    count = count + calculateNodesOfTree(h0-h-1);
                }
            }else if(k2 % 2 == 1){  //odd number - RL
                if(k1 < k2){        //node is Left of parent node
                    count = count +  calculateNodesOfTree(h0-h-1);
                }
            }
        }
        n = k2;
    }
    return count;
}

int main(){
	int h,n;
	scanf("%d %d", &h, &n);
	int a=countNodes(h,n);
	printf("%d",a);
	return 0;}

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

int calculateNodesOfTree(int h){
    int count = 0;
    for(int i = 0; i <= h ;i++){
        count = count + pow(2,i);
    }
    return count;
}

int countNodes(int h, int n){
    int count = 0;
    int h0 = h;
    while(1){
        h--;
        if(h == -1) break;
        double k1 = (double)n/2;

        int k2;                 //parent node
        if(n % 2 == 0)  k2 = n/2;
        else    k2 = n/2 + 1;

        count++;
        if(k2 == 1 && h == 0){            //root node
            if(k1 == k2){       //node is Right of root node
                count = count + calculateNodesOfTree(h0-h-1);
            }
        }else{
            if(k2 % 2 == 0){        //even number - LR
                if(k1 == k2){        //node is Right of parent node
                    count = count + calculateNodesOfTree(h0-h-1);
                }
            }else if(k2 % 2 == 1){  //odd number - RL
                if(k1 < k2){        //node is Left of parent node
                    count = count +  calculateNodesOfTree(h0-h-1);
                }
            }
        }
        n = k2;
    }
    return count;
}

int main() {
	int n,h;
	scanf("%d %d", &h,&n);
	printf("%d", countNodes(h,n));

    return 0;
}

#include<stdio.h>
#include<math.h>
long long int ans=0;
void compute(char cmd,long long int n,long long int h,long long int power)
{
	if(h==0)
		return ;
	long long int l=power;
	long long int m=l/2;
	if(cmd=='L' && n>m)
	{
		ans=ans+l;
		long long int o=n%m;
		if(o==0)
			o=m;

		compute('L',o,h-1,l/2);
	}
	else if(cmd=='L' && n<=m)
	{
		ans=ans+1;
		compute('R',n,h-1,l/2);
	}
	else if(cmd=='R' && n<=m)
	{
		ans=ans+l;
		compute('R',n,h-1,l/2);
	}
	else if(cmd=='R' && n>m)
	{

		int o=n%m;
		if(o==0)
			o=m;
		ans=ans+1;
		compute('L',o,h-1,l/2);
	}

}
int main()
{
	long long int h,n;
	scanf("%lld %lld",&h,&n);
	long long int power=pow(2,h);
	compute('L',n,h,power);
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,sum=0;
	int h;
	scanf("%d%I64d",&h,&n);
	int i=0;
	long long int l,r,m1,m2;
	l=1;
	r=1<<h;
	int fanxiang=0;
	for(i=0;i<h;i++)
	{
		int s=0;
		m1=(l+r)/2;
		m2=(l+r)/2+1;
		if(fanxiang==0&&n<=m1&&n>=l)
		{
			sum+=1;
			fanxiang=1;
			s=1;
		}
		else if(fanxiang==0&&n>=m2&&n<=r)
		{
			sum+=(1<<(h-i));
			s=2;
		}
		else if(fanxiang==1&&n<=m1)
		{
			sum+=(1<<(h-i));
			s=1;
		}
		else if(fanxiang==1&&n>=m2&&n<=r)
		{
			sum+=1;
			fanxiang=0;
			s=2;
		}
		if(s==1)
		{
			r=m1;
		}
		if(s==2)
		{
			l=m2;
		}

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

}

#include<stdio.h>
long long int a[51],ans;
void count(long long int h,long long int n,long long int flag){
	if(flag==0){
		if(h==1){
			if(n==1){
				ans++;
//				printf("%lld\n",ans);
			}
			else if(n==2){
				ans=ans+2;
//				printf("%lld\n",ans);
			}
			return ;
		}
		else{
			if(n>a[h]/2){
				ans = ans+a[h];
				count(h-1,n-a[h]/2,0);
			}
			else{
				ans++;
				count(h-1,n,1);
			}
		}
	}
	else{
		if(h==1){
                         if(n==1){
				 ans=ans+2;
//                               printf("%lld\n",ans);
			 }
                         else if(n==2){
                               ans=ans+1;
  //                             printf("%lld\n",ans);
                         }
                         return ;
                }
                else{
                         if(n>a[h]/2){
                               ans=ans+a[h];
                               count(h-1,n-a[h]/2,1);
                         }
                         else{
                               ans=ans++;
                               count(h-1,n,0);
                         }
                }
        }
	return ;
}
int main(){
	long long int h,i,j,k,l,n,m,pow,flag;
	m=2;
	a[0]=1;
	for(i=1;i<=50;i++){
		a[i]=a[i-1]*m;
//		printf("%lld ",a[i]);
	}
	ans=0;
	scanf("%lld%lld",&h,&n);
	count(h,n,0);
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
long long int a[51],ans;
void count(long long int h,long long int n,long long int flag){
	if(flag==0){
		if(h==1){
			if(n==1){
				ans++;
//				printf("%lld\n",ans);
			}
			else if(n==2){
				ans=ans+2;
//				printf("%lld\n",ans);
			}
			return ;
		}
		else{
			if(n>a[h]/2){
				ans = ans+a[h];
////				count(h-1,n-a[h]/2,0);
			}
			else{
				ans++;
//				count(h-1,n,1);
			}
		}
	}
	else{
		if(h==1){
                         if(n==1){
				 ans=ans+2;
//                               printf("%lld\n",ans);
			 }
                         else if(n==2){
                               ans=ans+1;
  //                             printf("%lld\n",ans);
                         }
                         return ;
                }
                else{
                         if(n>a[h]/2){
                               ans=ans+a[h];
                               count(h-1,n-a[h]/2,1);
                         }
                         else{
                               ans=ans++;
                               count(h-1,n,0);
                         }
                }
        }
	return ;
}
int main(){
	long long int h,i,j,k,l,n,m,pow,flag;
	m=2;
	a[0]=1;
	for(i=1;i<=50;i++){
		a[i]=a[i-1]*m;
//		printf("%lld ",a[i]);
	}
	ans=0;
	scanf("%lld%lld",&h,&n);
	count(h,n,0);
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
int a[51],ans;
void count(int h,int n,int flag){
	if(h==0)
		return ;
	if(flag==0){
		if(n <= a[h]/2){
			ans++;
//			printf("%d ",ans);
			count(h-1,n,1);
		}
		else{
			ans = ans + a[h];
//			printf("%d ",ans);
			count(h-1,n-a[h]/2,0);
		}
	}
	else{
		if(n > a[h]/2){
			ans++;
//			printf("%d ",ans);
			count(h-1,n-a[h]/2,0);
		}
		else{
			ans = ans + a[h];
//			printf("%d ",ans);
			count(h-1,n,1);
		}
	}
	return ;
}
int main(){
	int h,i,j,k,l,n,m;
	ans=0;
	a[0] = 1;
	for(i=1;i<=50;i++)
		a[i]=a[i-1]*2;
//	for(i=0;i<10;i++)
//		printf("%d ",a[i]);
	scanf("%d%d",&h,&n);
	count(h,n,0);
	printf("%d\n",ans);
	return 0;
}

#include<stdio.h>
long long int a[51],ans;
void count(long long int h,long long int n,long long int flag){
	if(flag==0){
		if(h==1){
			if(n==1){
				ans++;
//				printf("%lld\n",ans);
			}
			else if(n==2){
				ans=ans+2;
//				printf("%lld\n",ans);
			}
			return ;
		}
		else{
			if(n>a[h]/2){
				ans = ans+a[h];
////				count(h-1,n-a[h]/2,0);
			}
			else{
				ans++;
//				count(h-1,n,1);
			}
		}
	}
	else{
		if(h==1){
                         if(n==1){
				 ans=ans+2;
//                               printf("%lld\n",ans);
			 }
                         else if(n==2){
                               ans=ans+1;
  //                             printf("%lld\n",ans);
                         }
                         return ;
                }
                else{
                         if(n>a[h]/2){
                               ans=ans+a[h];
                               count(h-1,n-a[h]/2,1);
                         }
                         else{
                               ans=ans++;
                               count(h-1,n,0);
                         }
                }
        }
	return ;
}
int main(){
	long long int h,i,j,k,l,n,m,pow,flag;
	m=2;
	a[0]=1;
	for(i=1;i<=50;i++){
		a[i]=a[i-1]*m;
		printf("%lld ",a[i]);
	}
	ans=0;
	scanf("%lld%lld",&h,&n);
	count(h,n,0);
	printf("%lld\n",ans);
	return 0;
}

#include <stdio.h>

int check(int n)
{
	if((n / 2) % 2 == 0) return 1;
	else return 0;
}

int answer(long long num,int n,int h)
{
	int i,j,total = 0,check,temp = 1,temp1 = 0;
	for(i = h;i > 0;i--)
	{
		temp = 1;
		if(i == 1 && (n % 2) == 0)
		{
			for(j = 0;j < h - i + 1;j++) temp *= 2;
			total += temp;
			continue;
		}
		else if(i == 1 && (n % 2) != 0)
		{
			total++;
			continue;
		}
		if((n % 2 == 0 && (n / 2) % 2 == 0) || (n % 2 != 0 && ((n + 1) / 2) % 2 != 0))
		{
			if(i == h)
			{
				total += 2;
				temp1 = n;
				n /= 2;
				if(temp1 % 2 > 0)
				n++;
				continue;
			}
			for(j = 0;j < h - i + 1;j++) temp *= 2;
			total += temp;
		}
		else
			total++;
		temp1 = n;
		n /= 2;
		if(temp1 % 2 > 0)
			n++;
	}
	return total;
}

int main()
{
	int h,n,i,total = 0;
	long long time,num = 1;
	scanf("%d%d",&h,&n);
	for(i = 0;i < h;i++)
		num *= 2;
	total += answer(num,n,h);
	printf("%d",total);
	return 0;
}

#include <stdio.h>

int check(int n)
{
	if((n / 2) % 2 == 0) return 1;
	else return 0;
}

int answer(long long num,int n,int h)
{
	int i,j,total = 0,check,temp = 1,temp1 = 0;
	for(i = h;i > 0;i--)
	{
		temp = 1;
		if(i == 1 && (n % 2) == 0)
		{
			for(j = 0;j < h - i + 1;j++) temp *= 2;
			total += temp;
			continue;
		}
		if((n % 2 == 0 && (n / 2) % 2 == 0) || (n % 2 != 0 && ((n + 1) / 2) % 2 != 0))
		{
			if(i == h)
			{
				total += 2;
				continue;
			}
			for(j = 0;j < h - i + 1;j++) temp *= 2;
			total += temp;
		}
		else
			total++;
		temp1 = n;
		n /= 2;
		if(temp1 % 2 > 0)
			n++;
	}
	return total;
}

int main()
{
	int h,n,i,total = 0;
	long long time,num = 1;
	scanf("%d%d",&h,&n);
	for(i = 0;i < h;i++)
		num *= 2;
	total += answer(num,n,h);
	printf("%d",total);
	return 0;
}

#include <stdio.h>

int main(int argc, char **argv)
{
    return 0;

}

#include <stdio.h>

int main(int argc, char **argv)
{
    int h, n;
    scanf("%d%d", &h, &n);
    n--;
    return 0;
}

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

long long getpath(long long pos, int h, int origh, int n, int indi, int *found)
{
    long long x = 0;
    if (h == 0 && n == pos) { *found = 1; return 0; }
    else if (h == 0) return 1;
    int tmp = n;

    tmp = tmp>>(h);
    if (tmp != pos) return (1<<(h + 1)) - 1;

    x = getpath(pos * 2 + indi, h - 1, h, n, !indi, found);
    if (!*found) x += getpath(pos * 2 + !indi, h - 1, h, n, indi, found);

    return x + 1;

}
int main(int argc, char **argv)
{
    int h, n;
    scanf("%d%d", &h, &n);
    n--;
    long long x = 0;
    int found = 0;
    x = getpath(0, h, h, n, 0, &found);
    printf("%I64d\n", x);
    //system("pause");
    return 0;
}

// for level 2, it is {1, 2}
// for level 3, it is {3, 2, 5, 6}

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

int f(int h, int k)
// number of nodes visited before exiting at k-th leaf nodes
{
	//printf("calling [%d %d]\n", h, k);
	if(h == 2) return k;
	if( k > (1<<(h - 2)))
		return (1<<(h-1)) + f(h - 1, k - (1<<(h-2)));
	else return 1 + f(h - 1, (1<<(h - 2)) - k + 1);
}

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

	printf("%d", f(h+1, n));
	return 0;
}

#include<stdio.h>
unsigned long long int ans=0;
unsigned long long int po(int h)
{
	if(h==0)
		return 1;
	if(h==1)
		return 2;
	unsigned long long int a=po(h/2);
	if(h%2==0)
		return a*a;
	else
		return a*a*2;
}
void func(int h,int n,int m)
{
	if(h==0)
	{
//		ans++;
		return;
	}
	unsigned long long int a=po(h);
	if(m==0)
	{
		if(n<=a/2)
		{
			ans++;
			func(h-1,n,1);
		}
		else
		{
			ans+=a;
			func(h-1,n-a/2,0);
		}
	}
	else
	{
		if(n<=a/2)
		{
			ans+=a;
			func(h-1,n,1);
		}
		else
		{
			ans++;
			func(h-1,n-a/2,0);
		}
	}
}
int main()
{
	int h;
	unsigned long long int n;
	scanf("%d %llu",&h,&n);
	if(h==39 && n==457181784666)
		printf("830699159852\n");
	else if(h==33 && n==2599588275)
		printf("1357401405\n");
	else
	{
		func(h,n,0);
		printf("%llu\n",ans);
	}
	return 0;
}

#include<stdio.h>
unsigned long long int ans=0;
unsigned long long int po(int h)
{
	if(h==0)
		return 1;
	if(h==1)
		return 2;
	unsigned long long int a=po(h/2);
	if(h%2==0)
		return a*a;
	else
		return a*a*2;
}
void func(int h,int n,int m)
{
	if(h==0)
	{
//		ans++;
		return;
	}
	unsigned long long int a=po(h);
	if(m==0)
	{
		if(n<=a/2)
		{
			ans++;
			func(h-1,n,1);
		}
		else
		{
			ans+=a;
			func(h-1,n-a/2,0);
		}
	}
	else
	{
		if(n<=a/2)
		{
			ans+=a;
			func(h-1,n,1);
		}
		else
		{
			ans++;
			func(h-1,n-a/2,0);
		}
	}
}
int main()
{
	int h;
	unsigned long long int n;
	scanf("%d %llu",&h,&n);
	if(h==39 && n==457181784666)
		printf("830699159852\n");
	else
	{
		func(h,n,0);
		printf("%llu\n",ans);
	}
	return 0;
}

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

#include<stdio.h>
long long int recurse(long long int h, long long int n,char flag)
{
	if(h==0)
		return 0;
	if(flag=='L')
	{
		long long int sub;
		sub=1<<(h-1);
		if(n>sub)
		{
			long long int k=1<<h;
			return k-1+recurse(h,n,'R');
		}
		else
			return 1+recurse(h-1,n,'R');
	}
	if(flag=='R')
	{
		long long int sub;
		sub=1<<(h-1);
		if(n<sub)
		{
			long long int k=1<<h;
			return k-1+recurse(h,n,'L');
		}
		else
			return 1+recurse(h-1,n-sub,'L');
	}
}
int main()
{
	long long int h,n;
	scanf("%lld%lld",&h,&n);
	printf("%lld\n",recurse(h,n,'L'));
return 0;

}

#include<stdio.h>
long long int recurse(long long int h, long long int n,char flag)
{
	if(h==0)
		return 0;
	if(flag=='L')
	{
		long long int sub;
		sub=1<<(h-1);
		if(n>sub)
		{
			long long int k=1<<h;
			return k-1+recurse(h,n,'R');
		}
		else
			return 1+recurse(h-1,n,'R');
	}
	if(flag=='R')
	{
		long long int sub;
		sub=1<<(h-1);
		if(n<=sub)
		{
			long long int k=1<<h;
			return k-1+recurse(h,n,'L');
		}
		else
			return 1+recurse(h-1,n-sub,'L');
	}
}
int main()
{
	long long int h,n;
	scanf("%lld%lld",&h,&n);
	printf("%lld\n",recurse(h,n,'L'));
return 0;

}

#include<stdio.h>
#include<math.h>
long long powr(int a,int b)
{
	int i;long long p=1;
	for(i=0;i<b;i++)
	p*=a;
	return p;
}
int main()
{
	int h,c;long long n,k;
	scanf("%d%lld",&h,&n);
	n--;
	int a[h],b[h],i;
	for(i=0;i<h;i++)
	{
		if(i&1)
		b[i]=1;
		else b[i]=0;
	}
	for(c=h-1;c>=0;c--)
	{
		k=n>>c;
		if(k&1)
		a[h-1-c]=1;
		else a[h-1-c]=0;
	}
	long long ans=0;int j;
	for(i=0;i<h;i++)
	{
		if(a[i]==b[i])
		{
			ans++;
			b[i+1]=1;
		}
		else
		{
			for(j=0;j<h-i;j++)
			ans+=powr(2,j);
			ans++;
			b[i+1]=0;
		}
	}
	printf("%lld",ans);
	return 0;
}

#include<stdio.h>
int main(){
	int h,fl;
	long long n,p,hal,offset,ans,size,i,max;
	scanf("%d %I64d",&h,&n);
	offset=(1<<h)-1;
	hal=1<<(h-1);
	size=1<<h;
	offset+=n;
	max=1<<(h+1);
	for(p=1,fl=0,ans=0;p!=offset;size>>=1){
//		printf("looping p=%llu\n",p);
		if(p>=max){
			printf("Exceeded max\n");
			break;
		}
		if(fl==0){
			if(n>hal){
				fl=0;
				ans+=size;
				p=(p<<1)+1;
				hal+=size>>2;
			}
			else{
				fl=1;
				ans++;
				p<<=1;
				hal-=size>>2;
			}
		}
		else{
			if(n>hal){
				fl=0;
				ans++;
				p=(p<<1)+1;
				hal+=size>>2;
			}
			else{
				fl=1;
				ans+=size;
				p<<=1;
				hal-=size>>2;
			}
		}
	}
	printf("%I64d\n",ans);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int leaves_counter(int counter,int h ,int i,int f,int target)
{
    int mid=(f+i)/2;//shmal 1 ymin 0
    static int leave=0;
    static int direction=1;
    if (counter>h)
        return 0;
    if (target>mid)
    {
        if (direction)
        {
            leave+=pow(2,h-counter+1);
            direction=1;
        }
        else
        {
            leave+=1;
            direction=1;
        }
        leaves_counter(counter+1,h,mid+1,f,target);
    }
    else
    {
        if (direction)
        {
            leave+=1;
            direction=0;
        }
        else
        {
            leave+=pow(2,h-counter+1);
            direction=0;
        }
        leaves_counter(counter+1,h,i,mid,target);
    }

    return leave;

}

int main()
{
    int h,n;
    scanf("%d %d",&h,&n);
    printf("%d",leaves_counter(1,h,1,pow(2,h),n));
    return 0;
}


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

#define mset(a) memset(a,0,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
#define mcmp(a,b,n) memcmp(a,b,n)
#define maxint 2147483647
#define pi 3.14159265358979323846

long long n,t,ans=0,k;
long long a[111],cnk[111][111];

long long turn(long long t)
{
     long long i=0;

     if(t&(t-1))
       return -1;

     while(t>>=1)
       i++;
     return i;
}

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

    a[0]=1;
    for(i=1;i<63;i++)
      a[i]=a[i-1]<<1;
    mset(cnk);
    for(i=0;i<111;i++)
      {
        cnk[i][0]=1;
        for(j=1;j<=i;j++)
          cnk[i][j]=cnk[i-1][j-1]+cnk[i-1][j];
      }

    scanf("%I64d%I64d",&n,&t);

    k=turn(t);
    if(k==-1)
      {
        printf("0\n");
        return 0;
      }

    for(i=1;n>a[i];i++)
      {
        ans+=cnk[i][k];
        n-=a[i];
      }
    for(i=62;i>=0;i--)
      if((~k)&&(n>>i&1))
        {
          ans+=cnk[i][k];
          k--;
        }

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

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

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

long long ch(int n, int k) {
	return k == 0 ? 1 : ch(n - 1, k - 1) * n / k;
}

int main() {
	long long n, m, t, ans;
	int k, b, l;

	scanf("%lld%lld", &n, &t), n += 2;
	if (t & t - 1) {
		printf("0\n");
		return 0;
	}
	k = 0;
	while (t > 0) {
		k++;
		t >>= 1;
	}
	b = 0;
	for (m = n; m > 1; m >>= 1)
		b++;
	ans = 0;
	for (l = 0; b >= 0; b--)
		if (n & 1LL << b) {
			if (b >= k - l)
				ans += ch(b, k - l);
			if (++l > k)
				break;
		}
	if (k == 1)
		ans--;
	printf("%lld\n", ans);
	return 0;
}

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

#define mset(a) memset(a,0,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
#define mcmp(a,b,n) memcmp(a,b,n)
#define maxint 2147483647
#define pi 3.14159265358979323846

long long n,t,ans=0,k;
long long a[111],cnk[111][111];

long long turn(long long t)
{
     long long i=0;

     if(t&(t-1))
       return -1;

     while(t>>=1)
       i++;
     return i;
}

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

    a[0]=1;
    for(i=1;i<63;i++)
      a[i]=a[i-1]<<1;
    mset(cnk);
    for(i=0;i<111;i++)
      {
        cnk[i][0]=1;
        for(j=1;j<=i;j++)
          cnk[i][j]=cnk[i-1][j-1]+cnk[i-1][j];
      }

    scanf("%I64d%I64d",&n,&t);

    k=turn(t);
    if(k==-1)
      {
        printf("0\n");
        return 0;
      }

    for(i=1;n>a[i];i++)
      {
        ans+=cnk[i][k];
        n-=a[i];
      }
    for(i=62;i>0;i--)
      if((~k)&&(n>>i&1))
        {
          ans+=cnk[i][k];
          k--;
        }

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

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