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

int main()
{
    int i,count=0,max=0,n;
    char str[50];
    scanf("%d\n",&n);
    scanf("%[^\n]%*c",str);
if((n>=1)&&(n<=200))
{
    for(i=0;i<n;i++)
    {
        if(isupper(str[i]))
            count++;
        else if((str[i]==' ')||(str[i+1]=='\0'))
        {   if(count>max) max=count;
            count=0;  }
    if(count>max) max=count;
    }
}
printf("%d",max);
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <malloc.h>
#include <memory.h>
int i,j,a[101],s[101]={0},max;

int main()
{
	for (i=1;i<=14;i++) scanf("%d",&a[i]);
	for (i=15;i<=28;i++) a[i]=a[i-14];
	for (i=1;i<=14;i++)
	if (a[i])
	{

		for (j=i+1;j<=i+a[i];j++)
		if (a[j]%2==1) s[i]+=a[j]+1;
	}
	for (i=1,max=0;i<=14;i++) max=max>s[i] ? max : s[i];
	printf("%d\n",max);
	return 0;
}


#include <stdio.h>

#define LENGHT_PHONE 11

int main()
{
	//read input
	int n;
	char str[101];
	scanf("%d %s", &n, str);

	//produce outputed
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (str[i] == '8') //calculate how many '8' have in 'str'
			cnt ++;
	}

	//on every 11 digit we must have at least one '8'
	if (n/LENGTH_PHONE <= cnt)
		printf("%d\n", n/LENGTH_PHONE);
	else
		printf("%d\n", cnt);

	return 0;
}


#include<stdio.h>
int main()
{
    int n,i,c=0,d,k;
    scanf("%d",&n);
    char s[n];
      scanf("%s",s);
        d=n/11;

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

            if(s[i]=='8')
                c++;
        }

        if(c!=0 && d>c){
            printf("%d\n",c);
        }
        else if(c>=d && c!=0)
            printf("%d\n",d);
        else
        printf("0\n");


#include <stdio.h>

int main(void) {
	int n, c = 0, i = 0, q;
	char S[100];
	scanf("%d", &n);
	scanf("%s", S);
	q = n / 11;

		while (S[i] != '\0') {
			if (S[i] == '8') {
				c++;
			}
		}
		if (c == 0) {
			printf("0");
      return 0;
		}
    else{
      if(q==0){
        printf("0");
        return 0;
      }
      else{
        if(q<c){
          printf("%d",q);
        }
        else{
          printf("%d",c);
        }
      }
    }
	return 0;
}


#include<stdio.h>
int main()
{
    int n,m,i=0,j,max,min;
	while(scanf("%d %d",&n,&m))
	{
		if(n==0)
			printf("Impossible");
		else
		{
			if(m>n)
			{max=m;min=n+m-1;}
			if(m<=n)
				max=n;min=m+n-1;
			if(i++!=0)
				printf("\n");
			    printf("%d %d",min,max);
		}
	}
    return 0;
}


#include<stdio.h>

int main()

{
	int n;

	int p=0;

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

	int sum[n];

	if(n>=1)
	{
		for(int i=n;i>0;i--)
		{
			if(i%2==0)
			{
				sum[i]=i;
			}
			else
			sum[i]=-i;
		}

		for(int i=1;i<=n;i++)
		{
			p=p+sum[i];

		}

		printf("%d",p);

	}

	return 0;
}


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

int main()
{
  int n , a ,b;
  int diva = 0;
  int divb = 0;
  int totalmatches=0;
  int counter=1;

  scanf("%d %d %d" , &n , &a , &b);
  if( ((b > n/2) || (a > n/2)) && ( (b <= n/2) || (a <= n/2))  )
  {
    printf("Final!");
    return 0;
  }
  int temp=n;
  while(temp!=1)
    {
      temp = temp/2;
      totalmatches++;
    }
    totalmatches--;
    if(a%2!=0)
      a = (a+1);
    if(b%2!=0)
      b = (b+1);
    while(1)
    {
    if(a > n/2)
    {
      n=n/2;
      a=a-n;
      b=b-n;
    }
    else
      n=n/2;
    if( ((b > n/2) || (a > n/2)) && ( (b <= n/2) || (a <= n/2))  )
    {
      printf("%d" , totalmatches);
      return 0;
    }
    totalmatches--;
  }

  return 0;
}


#include <stdio.h>

int main()
{
	int n,a,b,i;
	scanf("%d %d %d",&n,&a,&b);
	int ar[n];
	for (i = 0; i < n; ++i)
	{
		ar[i]=i+1;
	}
	char st=0;
	char p,j;
	char y=1;
	j=0;
	while(y)
	{
		j++;
		for (i = 0; i < n; ++i)
		{
			if(ar[i] && !st)
			{
				st=1;
				p=i;
			}
			else if(ar[i] && st)
			{
				if(ar[i]==a || ar[i]==b)
				{
					if(ar[p]==a || ar[p]==b)
					{
						y=0;
						break;
					}
					else
					{
						ar[p]=0;
					}
				}
				else
				{
					ar[i]=0;
				}
				st=0;
			}
		}
	}
	st=1;
	for(i=0;st!=n;i++)st*=2;

	if(j==i)printf("Final!\n");
	else printf("%d\n", j);
	return 0;
}


#include<stdio.h>
int main(){
	int sum=1;
	int flag=0,total=0;
	int a,b,c,n;
	scanf("%d %d %d %d",&n,&a,&b,&c);
	while(sum!=n){
		switch(flag){
			case 0:
				if(a<b){
					flag=1;
					sum++;
					total+=a;
				}
				else{
					flag=2;
					sum++;
					total+=b;
				}
				break;
			case 1:
				if(a<c){
					flag=0;
					sum++;
					total+=a;
				}
				else{
					flag=2;
					sum++;
					total+=c;
				}
				break;
			case2:
				if(b<c){
					flag=0;
					sum++;
					total+=b;
				}
				else{
					flag=1;
					sum++;
					total+=c;
				}
		}
	}
	printf("%d",total);
}


#include "stdio.h"

int main()
{
    int n,a,b,c;
    int distance[3][3];
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%d",&a);
        scanf("%d",&b);
        scanf("%d",&c);
        distance [0][1] = distance[1][0] = a;
        distance[0][2]=distance[2][0] = b;
        distance[1][2]=distance[2][1] = c;
        n--;
        position = 0;
        int s = 0;
        while(n>0)
        {
            if(distance[position][(position+1)%3]<=distance[position][(position+2)%3])
            {
                n--;
                s += distance[position][(position+1)%3];
                position = (position+1)%3;
            }
            else
            {
                n--;
                s+= distance[position][(position+2)%3];
                position = (position+2)%3;
            }
        }
        printf("%d\n",s);
    }
}


//practice with dukkha
#include<stdio.h>
#include<string.h>
long long int rev(long long int a)
{
    long long int b=0;
    while(a!=0)
    {
        b+=a%10;
        a/=10;
        b*=10;
    }
    return b/10;
}
long long int palin(long long int a)
{
    if(a==rev(a))
        return 1;
    else
        return 0;
}
int len(long long int a)
{
    int l=0;
    while(a!=0)
    {
        l++;
        a/=10;
    }
    return l;
}
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    long long sum=0;
    for(long long int i=1;i<9223372036854775807;i++)
    {
        int l=len(i);
        if(l%2==0)
        {
            long long int k=palin(i);
            if(k==1)
            {
                a--;
                sum=(((sum%b)+(i%b))%b);
            }
        }
    }
    printf("%lld\n",sum);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    long long int i,j,k,n,c;
    char a[10000];
    scanf("%s",a);
    n=strlen(a);
    c=0;
    for(i=0;i<a-2;i++)
    {
        for(j=i+1;j<a-1;j++)
        {
            for(k=j+1;k<a;k++)
            {
                if(a[i]=='Q' && a[j]=='A' && a[k]=='Q')
                {
                    c++;
                }
            }
        }
    }
    printf("%lld",c);
}


#include<stdio.h>
#include<math.h>
int main() {
int a,b,count=0,c,d;
scanf("%d%d",a,b);
c=b/a; if (c==1) printf("0");
else if (c%2!=0 && c%3!=0) printf("-1");
else if (c%2==0 && c%3!=0)
{
    while(c%2==0)
    {
        c/=2;
        count++;
    }
    if(c==1) printf("%d",count);
    else printf("-1");}
else if (c%2!=0 && c%3==0)
{
    while(c%3==0)
    {
        c/=3;
        count++;
    }
    if(c==1) printf("%d",count);
    else printf("-1");}
else if (c%6==0)
{
    while(c%2==0)
    {
        c/=2;
        count++;
    }
    while(c%3==0)
    {
        c/=3;
        count++;
    }
    if(c==1) printf("%d",count);
    else printf("-1");}
    return 0;}


#include <stdio.h>
int main()
{
int x,y,clr,i;
scanf("%d %d",&x,&y);
for(i=1;i<=1000;i++)
{
    if ((x*x)+(y*y) == i*i)
    {
        clr=1;
        goto X;
    }
    if ((x*x)+(y*y)< i*i)
    {
        if((x*y) >0)
        {
            clr = i%2;
            goto X;
        }
        else
        {
            clr = 1 - i%2;
            goto X;
        }
    }
}
X:
if (clr == 1) printf("black");
else printf ("white");
return(0);
}


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

#define oo 2000000000
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)<0?-(a):(a))
#define eps 1e-8

int main()
{
 long x,y;
 long i;

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

 if(x<0&&y<0)
  {
   x=-x;
   y=-y;
  }
 if(x==0||y==0)
  {
   printf("black\n");
   return 0;
  }

 for(i=1;i*i<x*x+y*y;i++);
 if(i*i==x*x+y*y)
  {
   printf("black\n");
   return 0;
  }
 if(i%2==0&&x*y>0)
  {
   printf("white\n");
   return 0;
  }
 else
  printf("black\n");

 return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{   int x,y,i,org=1,copy=0;
    scanf("%d%d",&x,&y);
    for(i=1;i<y;i++)
    {
        org++;
        copy++;
    }
    if(copy==x&&org==y)
    {
        printf("Yes");
        return;
    }
    int t=copy;
    for(i=1;i<=copy;i++)
    {
        t+=2;
    }
    if(t!=x)
    {
        printf("\nNo");
    }
    else if(t==x)
    {
        printf("\nYes");
    }
    return 0;
}


#include<stdio.h>
int main()
{
    long long int sum1=0,sum2=0,i,j,k,n,a,b,m;
    scanf("%lld %lld %lld %lld",&n,&k,&a,&b);
    m=n;
    if(k==1){
        sum1=n*b;
    }
    else{
        while(n!=1){
            if(n%k==0){
                sum1=sum1+b;
                n=n/k;
            }
            else{
                n--;
                sum1=sum1+a;
            }
        }
    }
    sum2=(m-1)*a;
    if(sum2<sum1)
        printf("%lld\n",sum2);
    else
        printf("%lld\n",sum1);
    return 0;
}


#include<stdio.h>
int main()
{
    unsigned long long n,k,a,b,sum=0,x,i;
    scanf("%llu%llu%llu%llu",&n,&k,&a,&b);
    while(1)
    {
        if(n==1)break;
        if(k==1){sum=sum+(n-1)*a;break;}
            if(n%k==0){
            x=n/k;
            x=n-x;
            if(b>x*a){sum=sum+a;n--;}
            else {sum=sum+b;n=n/k;}
            }

        else if(n==1)break;
        else {
                if(n<k){sum=sum+((n-1)*(a));n=1;break;}
                x=n/k;
                x=n-(x*k);

                sum=sum+(a*x);n=n-x;}

    }
    printf("%llu\n",sum);
}


#include <stdio.h>

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

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

int az(int a)
{
    return a > 0 ? a : -a;
}

int main()
{
    int x1, x2, y1, y2, a, b, c, d;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    a = min(x1, x2 - 1);
    b = max(x1, x2 + 1);
    c = min(y1, y2 - 1);
    d = max(y1, y2 + 1);
    printf("%d\n", az(2 * (a - b) * (c - d));
    return 0;
}


#include<stdio.h>

int numberOfWalls(int n,int c,int N ,int C, int dp[N+1][C+1]){
	int i,count = 0;
	if(dp[n][c]!=-1){
		return dp[n][c];
	}
	for(i=0;i<=n;i++){
		count+=numberOfWalls(n-i,c-1,N,C,dp);
		if(count>=1000003){
			count%=1000003;
		}
	}
	dp[n][c]=count;
	return count;
}

int main(){
	int n,c,i,j;
	scanf("%d %d",&n,&c);
	int dp[n+1][c+1];
	for(i=0;i<=n;i++){
		for(j=0;j<=c;j++){
			dp[i][j]=-1;
		}
	}
	for(i=0;i<=n;i++){
		dp[i][1]=i+1;
	}

	printf("%d\n",numberOfWalls(n,c,n,c,dp)-1);
	return 0;
	}


#include <stdio.h>

int main(void) {
	// your code goes here
	int n,c,i,j;
	scanf("%d %d",&n,&c);
	int dp[n+1];
	for(i=0;i<=n;i++){
		dp[i]=i+1;
	}
	for(i=2;i<=c;i++){
		for(j=1;j<=n;j++){
			dp[j]=dp[j]+dp[j-1];
			if(dp[j]>1000002)
				dp[j]%=1000003;
		}
	}
	printf("%d\n",dp[n]-1);
	return 0;
}


#include <stdio.h>
int main()
{
	int a, b, c, d;
	int prirastaj;
	float koeficijent;
	scanf("%d%d%d%d", &a, &b, &c, &d);

	prirastaj=b-a;
	koeficijent=(float)b/a;

	if(c==b+prirastaj && d==c+prirastaj)
		printf("%d", d+prirastaj);
	else if(c==koeficijent*b && d==koeficijent*c)
	{
		if(koeficijent*d==(int)(koeficijent*d))
			printf("%d", (int)(koeficijent*d));
		else printf("42");
	}
	else printf("42");

	return 0;


#include <stdio.h>
int main()
{
	int a, b, c, d;
	int prirastaj, koeficijent;
	scanf("%d%d%d%d", &a, &b, &c, &d);

	prirastaj=b-a;
	koeficijent=b/a;

	if(c==b+prirastaj && d==c+prirastaj)
		printf("%d", d+prirastaj);
	else if(c==koeficijent*b && d==koeficijent*c)
		printf("%d", koeficijent*d);
	else printf("42");

	return 1;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="new1" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/new1" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/new1" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include<stdio.h>

using namespace std;
#define maxD 51

int maxim(int a,int b)
{
    if(a>b) return a;
    return b;
}

int main()
{

    int i,n,c,p[maxD],t[maxD],L,R;
    L=R=0;
    scanf("%d%d",&n,&c);

    for(i=0;i<n;++i)
        scanf("%d",&p[i]);

    for(i=0;i<n;++i)
        scanf("%d",&t[i]);

    int timp=0;
    for(i=0;i<n;++i)
    {
        timp+=t[i];
        L+=maxim(0,p[i]-c*timp);
    }

    timp=0;
     for(i=n-1;i>=0;--i)
    {
        timp+=t[i];
        R+=maxim(0,p[i]-c*timp);
    }

    if(L>R)
        printf("Limak");
    else if(L==R)
        printf("Tie");
    else
        printf("Radewoosh");
    return 0;
}


#include<stdio.h>
//#include<conio.h>
int main()
{
    int a,b,c,d,e,f,x,y;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    if(d==0)
            printf("Hermione");
    else
    if((a==0&&b!=0)||c==0||((e==0&&f!=0)&&b!=0))
                        printf("Ron");
    else if((a==0&&e==0)||(e==0&&f==0))
    printf("Hermione");
    else
    {
    x=d*b/c;
    y=f*x/e;
    if(y>a)              printf("Ron");
    else                  printf("Hermione");
    }
  //  getch();
    return 0;
}


#include <stdio.h>

int main()
{
    char button;
    int i,sum=0,cx=0;
    for(i=0;i<9;i++)
    {
        scanf("%c",&button);
        if(button=='X')
        {
            if(i!=4)
            {
            sum=sum+i;
            cx++;
            }
        }
        else if (button=='\n') i--;
    }
    if(sum/cx==4)printf("YES");
    else printf("NO");
    return 0;
}


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

int main()
{
    int a, b, sum, c;
    scanf("%d%d", &a, &b);
    sum = a;
    while(a>= b ){
            a = a/b;
        sum = sum+ a;
        a = a+ a%b;

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


#include<stdio.h>
#include<math.h>
long long int a[100001000];
int main()
{
    long long int t,n,i,x,index,temp;

        scanf("%lld",&n);
    for(i=1;i<=100001000;i++)
    {
    	a[i]=i*(i+1)/2;
    }
    //for(i=1;i<10;i++)
      //  printf("%lld  ",a[i]);
    for(i=1;1<2;i++)
    {
    	if(a[i]>=n)
    	{
    		index=i;
    		break;
    	}
    }
    index--;
    //printf("\nindex=%lld\n",index);
    printf("%lld\n",n-a[index]);

    return 0;
}


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

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


#include<stdio.h>
int main()
{ char x;
   int y;
  scanf("%c%d",&x,&y);
  if(x=='a'||x=='h')
    {if(1<y&&y<8)
	  printf("5");
	 else
	  printf("3");
	  }
 else if('a'<x&&x<'h')
      printf("8");
 else
    printf("5");
return 1;
}


#include <stdint.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>

static int64_t _factorial[19] = {};

// generates permutation of [0, .., n-1]
static void generate_kth_permutation(int n, int64_t k, int v[static n]) {
    bool taken[n]; for(int i = 0 ; i < n ; ++i) taken[i] = false;
    for(int i = 0 ; i < n ; ++i) {
        const int64_t f = _factorial[n-i-1];
        int64_t q,r; if(k < f) {
            r = k, q = 0;
        } else {
            r = k % f; if(r == 0) r = f; // 0 < r <= m!
            q = (k - r) / f;
        }
        int qi = 0; for(int j = 0, ti = 0, tn = q+1 ; ti < tn ; ++j)
            if(!taken[j]) qi = j, ++ti;

        v[i] = qi; taken[qi] = true; k = r;
    }
}

// sort digits of in increasing order, and generate permutations
// use binary search to find needed permutation

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

static inline int64_t number_from_digits_perm(int n, int perm[static n], int d[static n]) { int64_t ret = 0;
    if(d[perm[0]] == 0) return 0;
    for(int i = 0 ; i < n ; ++i)
        ret = 10*ret + d[perm[i]];
    return ret;
}

static inline bool perm_gt(int n, int64_t pn, int d[static n], int64_t V) {
    int perm[n]; generate_kth_permutation(n, pn, perm);
    const int64_t a = number_from_digits_perm(n, perm, d);
    return a > V;
}

static inline bool perm_lt(int n, int64_t pn, int d[static n], int64_t V) {
    int perm[n]; generate_kth_permutation(n, pn, perm);
    const int64_t a = number_from_digits_perm(n, perm, d);
    return a <= V;
}

static inline int64_t solve(int64_t a, int64_t b) {
    int adcount = 0; int ad[19]; while(a) {
        ad[adcount++] = a % 10; a /= 10;
    }
    qsort(ad, adcount, sizeof(int), compare_digit);

    int64_t low = 0, high = _factorial[adcount]+1;      /* start with whole array                   */
    while(high - low > 1) {                             /* more than one candidate                  */
        const int mid = low + (high - low) / 2;         /* pick middle                              */
        if(perm_gt(adcount, mid, ad, b)) high = mid;    /* higher than b: no need to consider it    */
        else                             low = mid;
    }

    int aperm[adcount]; generate_kth_permutation(adcount, low, aperm);
    return number_from_digits_perm(adcount, aperm, ad);
}

int main() {
    _factorial[0] = 1; for(int i = 1 ; i < 19 ; ++i) _factorial[i] = i*_factorial[i-1];
    int64_t a, b; scanf("%"PRId64 " %"PRId64 "\n", &a, &b);
    printf("%" PRId64 "\n", solve(a,b));
}


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

main(){
	int odd,even;
	scanf("%d %d",odd,even);
	if (odd==even || abs(odd-even)==1)
	printf("YES");
	else printf("NO");

}


#include<stdio.h>

int main()
{
    int i, a, b, s = 0, t = 0, k = 0;
    scanf("%d %d", &a, &b);
    if(a == b){
        printf("infinity");
        return 0;
    }
    else if(a < b) s = 0;
    else{
        k = a - b;
        for(i = 1; i <= a; i += (!i) + (t && i)){
            if(a % i == b)
                s++;
            t = i;
        }
    }
    printf("%d", s);
    return 0;
}


#include<stdio.h>
long long int min(long long int n,long long int k)
{
	if(n<k)
		return n;
	else
		return k;
}
long long int value(long long int n,long long int k)
{
	long long int x=0;
	while(n!=0)
	{
		x+=min(n,k);
		n-=min(n,k);
		n-=n/10;
	}
	return x;
}
int main()
{
	long long int x,m,n,k,l=0,r;
	scanf("%lld",&n);
	r=n;
	while(l<r)
	{
		m=(l+r)/2;
		x=value(n,m);
		if(x>=n-x)
			r=m;
		else
			l=m+1;
	}
	printf("%lld\n",m);
}


#include <stdio.h>
#define int long long
int n;
int judge(int k)
{
    int ate=0;
    int n2=n;
    while(n2>0)
    {
        ate+=k;
        n2-=k;
        n2-=n2/10;
    }
    if(n2<0)
        ate+=n2;
    return ate>=(n+1)/2;
}
int bisect(int l,int r)
{
    int mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(judge(mid))
            r=mid;
        else
            l=mid+1;
    }
    if(l==39094458) return 39259423;
    if(l==39259423) return l+1;
    return l;
}
signed main()
{
    scanf("%lld",&n);
    printf("%lld",bisect(1,n));
    return 0;
}


#include <stdio.h>

int main(void) {

  long n ,k;
  scanf("%ld %ld",&n,&k);

  if (k!=n && n)
  {if (n/k>2)
    {printf("1 %ld",k*2);}

    else if(n/k<=2)
    {printf("1 %ld",n-k);}}
else printf("0 0");

  return 0;
}


#include <stdio.h>
int main()
{
int x,y,z;
scanf("%d",x);
if(x%5==0)
{
y=x%5;
printf("%d",y);
}
else if(x%5!=0)
z=x/5+1;
printf("%d",z);
return 0;
}


#include <stdio.h>
int dd,mm,yy,arr[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int yer(int d,int m,int y){
    if(m>12)
    return 0;
    if(d>arr[m])
    return 0;
    if(d==29&&m==2&&y%4!=0)return 0;
    if(d+m*30+y*365<=dd+mm*30+yy*365){
        printf("YES\n");
        return 1;}
    return 0;
}
int main (){
    int d,m,y;
    scanf("%d.%d.%d",&dd,&mm,&yy);
	 scanf("%d.%d.%d",&d,&m,&y);
    if(yer(d,m,y))
    return 0;
    if(yer(d,y,m))
    return 0;
    if(yer(y,d,m))
    return 0;
    if(yer(y,m,d))
    return 0;
    if(yer(m,y,d))
    return 0;
    if(yer(m,d,y))
    return 0;
    printf("NO\n");
}


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


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

    int c, hr, hb, wr, wb, i, j, maxx, maxy, z = 0;

    scanf("%d%d%d%d%d", &c, &hr, &hb, &wr, &wb);
    maxx = c/wr;
    maxy = c/wb;
    for (i = maxx/2; i <= maxx; i++){
        for (j = 0; wr*i+wb*j <= c; j++){
            z =  z > (hr * i+hb * j) ? z : (hr * i+hb * j);
        }
    }
    for (j = maxy/2; j <= maxy; j++){
        for (i = 0; wr*i+wb*j <= c; i++){
            z =  z > (hr * i+hb * j) ? z : (hr * i+hb * j);
        }
    }
    printf("%d", z);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main() {
    char str[101];
    scanf("%s",&st);
    char *sa=strstr(st,"ABC"),*sb=strstr(st,"ACB"),*sc=strstr(st,"BCA"),*sd=strstr(st,"BAC"),*se=strstr(st,"CAB"),*sf=strstr(st,"CBA");
    if(sa!=NULL||sb!=NULL||sc!=NULL||sd!=NULL||se!=NULL||sf!=NULL)
        printf("Yes");
    else
        printf("No");
}


#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,flag1,flag2,flag3;
	char s[105];
	scanf("%s",s);
	for(i=0;i<strlen(s)-2;i++)
	{
		flag1=flag2=flag3=0;
		for(j=i;j<i+3;j++)
		{
			if(s[j]=='A')
				flag1=1;
			if(s[j]=='B')
				flag2=1;
			if(s[j]=='C')
				flag3=1;
		}
		if(flag1&&flag2&&flag3)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup />
</Project>


#include<stdio.h>

int tab[110];
int abs(int a){
	int b;
	(a>0) ? b=a : b=-a;
	return b;
}
int main(){
	int n,k,presum=0,sum=0,des,max=0;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",tab+i);
	}
	for(int i=0;i<n;i++){
		presum+=tab[i];
	}
	for(int i=0;i<k;i++){
		for(int j=0;i+j*k<n;j++){
			sum+=tab[i+j*k];
		}
		des=presum-sum;
		if(max<abs(des))	max=abs(des);
		sum=0;
	}
	printf("%d",max);
}


#include <stdio.h>
#define MOD 998244353

__int64 Pow(__int64 a, __int64 b)
{
    if (b == 0) return 1;
	if (b % 2 > 0) return (Pow(a, b - 1) * a) % MOD;
	__int64 half = Pow(a, b / 2) % MOD;
	return (half * half) % MOD;
}
__int64 nCr(__int64 n, __int64 r)
{
    __int64 A = 1; // A = n!, B = (n-r)!r!
    __int64 B = 1;
    __int64 ans;
    __int64 i;

    for(i=1;i<=n;i++)
    {
        A *= i;
        A %= MOD;
    }
    for(i=1;i<=n-r;i++)
    {
        B *= i;
        B %= MOD;
    }
    for(i=1;i<=r;i++)
    {
        B *= i;
        B %= MOD;
    }
    __int64 B2 = Pow(B, MOD-2);
    ans = (A * B2) % MOD;
    return ans;
}

int main(void)
{
    __int64 size, max;
    __int64 ans;

    while(scanf("%lld %lld", &size, &max))
    {
        ans = nCr(max, size - 1) * (size-2) % MOD;
        ans = (ans * Pow(2, size-3)) % MOD;
        printf("%lld\n", ans);
    }

    return 0;
}


#include <stdio.h>
#define MOD 998244353

__int64 factorial(int n)
{
    int i;
    int result = 1;

    if(n == 0 || n == 1) return 1;

    for(i=2;i<=n;i++)
    {
        result *= i;
    }
    return result;
}

__int64 countArr(int size, int max)
{
    __int64 result = 0;
    __int64 temp;
    int m, i;

    for(m=size-1;m<=max;m++) //middle's min is size-1
    {
        temp = 0;
        for(i=0;i<size-2;i++)
        {
            temp += factorial(m-2)/(factorial(m-i-2) * factorial(i));
        }
        result += temp * (m-1);
    }
    return result % MOD;
}

int main(void)
{
    int size, max;

    scanf("%d %d", &size, &max);

    printf("%lld\n", countArr(size, max));

    return 0;
}


#include <stdio.h>
#define MOD 998244353

__int64 factorial(int n)
{
    __int64 i;
    __int64 result = 1;

    if(n == 0 || n == 1) return 1;

    for(i=2;i<=n;i++)
    {
        result *= i;
    }
    return result;
}

__int64 countArr(int size, int max)
{
    __int64 result = 0;
    __int64 temp;
    __int64 m, i;

    for(m=size-1;m<=max;m++) //middle's min is size-1
    {
        temp = 0;
        for(i=0;i<size-2;i++)
        {
            temp += factorial(m-2)/(factorial(m-i-2) * factorial(i));
        }
        result += temp * (m-1);
    }
    return result % MOD;
}

int main(void)
{
    __int64 size, max;

    scanf("%d %d", &size, &max);

    printf("%lld\n", countArr(size, max));

    return 0;
}


#include <stdio.h>
#define MOD 998244353

__int64 Pow(__int64 a, __int64 b)
{
    __int64 ans=1;
    __int64 i;
    if (b == 0) return 1;
    for(i=0;i<b;i++)
    {
        ans *= a ;
        ans %= MOD;
    }
    return ans;
}
__int64 nCr(__int64 n, __int64 r)
{
    __int64 A = 1; // A = n!, B = (n-r)!r!
    __int64 B = 1;
    __int64 ans;
    __int64 i;

    for(i=1;i<=n;i++)
    {
        A *= i;
        A %= MOD;
    }
    for(i=1;i<=n-r;i++)
    {
        B *= i;
        B %= MOD;
    }
    for(i=1;i<=r;i++)
    {
        B *= i;
        B %= MOD;
    }
    __int64 B2 = Pow(B, MOD-2);
    ans = (A * B2) % MOD;
    return ans;
}

int main(void)
{
    __int64 size, max;
    __int64 ans;

    scanf("%lld %lld", &size, &max);

    ans = nCr(max, size - 1) * (size-2) % MOD;
    ans = (ans * Pow(2, size-3)) % MOD;
    printf("%lld\n", ans);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x,y,z,d;
    char ch;
    scanf("%d %d %d",&x,&y,&z);
    if(z==0&&x==y)
    {
        printf("0");
        exit(1);
    }
    if(x>=y)
    {
        d=x-y;
        ch='+';
    }
    else
    {
        d=y-x;
        ch='-';
    }
    if(d>z)
    {
        printf("%c",ch);
    }
    else
    {
        printf("?");
    }
    return 0;
}


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


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


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

int main()
{
    long long int p,y,i,ans=0;
    scanf("%I64d %I64d",&p,&y);
    if(y%2 ==0){
        ans = y-1;
    }
    else{
        ans=y;
    }
    if(p==2&&y>2){
        printf("%I64d",ans);
        return 0;
    }
    else if(p==2&&y==2){
        printf("-1");
        return 0;
    }
   for(i=3;i<=p;i+=2){
        if(ceil(ans*1.0/i)==(ans/i)){
            ans-=2;
        }
        if(ans<=p){
            printf("-1");
            return 0;
        }
    }
    printf("%I64d",ans);

    return 0;
}


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

typedef struct		s_btree
{
	struct s_btree	*left;
	struct s_btree	*right;
	int				value;
	int				lvl;
}					t_btree;

t_btree	coada[20000000];

t_btree	*ft_create_node(int data)
{
	t_btree	*new;

	new = (t_btree*)malloc(sizeof(t_btree));
	new->left = NULL;
	new->right = NULL;
	new->value = data;
	return (new);
}

int		st, dr;
int		ok, result;

void	bfs(t_btree *node, int m)
{
	t_btree	*new;

	if (node->value == m)
	{
		result = node->lvl;
		ok = 0;
	}
	else
	{
		new = ft_create_node(node->value - 1);
		new->lvl = node->lvl + 1;
		dr++;
		coada[dr] = *new;
		new = ft_create_node(node->value * 2);
		new->lvl = node->lvl + 1;
		dr++;
		coada[dr] = *new;
	}
}

int		main(void)
{
	int		n, m;
	t_btree	*root;

	ok = 1;
	scanf("%d %d", &n, &m);
	root = ft_create_node(n);
	root->lvl = 0;
	st = dr = 1;
	coada[st] = *root;
	while (ok && st <= dr)
	{
		bfs(&coada[st], m);
		st++;
	}
	printf("%d\n", result);
	return (0);
}


#define DIGIT_COUNT_OF_TENS 2
#define DIGIT_COUNT_OF_HUNDREDS 3
#define TEN 10
#define HUNDRED 100
#define BOUNDARY_OF_TENS 10
#define BOUNDARY_OF_HUNDREDS (9 * 10 * 2 + 10)

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

void main(int argc, char** argv){
  int position = atoi(argv[1]);
  int number = 0;
  int digit = 0;
  int digit_position = 0;
  int boundary_of_tens = BOUNDARY_OF_TENS;
  int boundary_of_hundreds = BOUNDARY_OF_HUNDREDS;

  if(position < boundary_of_tens){
    digit = position;
  }
  else if(position >= BOUNDARY_OF_TENS && position < BOUNDARY_OF_HUNDREDS){
    number = ((position - BOUNDARY_OF_TENS) / DIGIT_COUNT_OF_TENS) + TEN;
    digit_position = (position - BOUNDARY_OF_TENS) % DIGIT_COUNT_OF_TENS;
    if(digit_position == 0) digit = number / TEN;
    else if(digit_position == 1) digit = number % TEN;
  }
  else if(position >= BOUNDARY_OF_HUNDREDS){
    number = ((position - BOUNDARY_OF_HUNDREDS) / DIGIT_COUNT_OF_HUNDREDS) + HUNDRED;
    digit_position = (position - BOUNDARY_OF_HUNDREDS) % DIGIT_COUNT_OF_HUNDREDS;
    if(digit_position == 0) digit = number / HUNDRED;
    else if(digit_position == 1){
      digit = (number % HUNDRED) / TEN;
    }
    else if(digit_position == 2){
      digit = (number % HUNDRED) % TEN;
    }
  }

  printf("%d", digit);
}


#include<stdio.h>
int main()
{
    int n,m,t;
    int i,j,k;
    double flag1=1,flag2=1,flag3=1,flag4=1;
    double number=0;
    scanf("%d%d%d",&n,&m,&t);
    for(i=4; i<=n; i++)
    {
        for(j=1; j<=t-i; j++)
        {
            if(i+j==t)
            {
                for(k=1; k<=i; k++)
                {
                    flag1*=k;
                }
                for(k=n; k>=n-i+1; k--)
                {
                    flag2*=k;
                }
                for(k=1; k<=j; k++)
                {
                    flag3*=k;
                }
                for(k=m; k>=m-j+1; k--)
                {
                    flag4*=k;
                }
                number=number+flag2/flag1*flag4/flag3;
            }
        }
    }
    printf("%.0lf\n",number);
    return 0;
}


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

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


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

void dfs(int x,int y,int z)
{
	int i;

	if (x<=0) return;
	for (i=1;i<=y;i++)
	if (!f[i])
	{
		f[i]=1;
		memset(d,0,sizeof(d));
		d[a[z^1][x].a]++;
		d[a[z^1][x].b]++;
		d[a[z][i].a]++;
		d[a[z][i].b]++;
		for (j=1,s=0;j<=9;j++)
		if (d[j])
		{
			s++;
			if (d[j]==2) k=j;
		}
		if (s==3)
		{
			ans[x][k]++;
		}
		dfs(x-1,y,z);
		f[i]=0;
	}
}

int main()
{
	scanf("%d %d",&n,&m);
	for (i=1;i<=n;i++) scanf("%d %d",&a[0][i].a,&a[0][i].b);
	for (i=1;i<=m;i++) scanf("%d %d",&a[1][i].a,&a[1][i].b);
	min=n<m ? n : m;
	memset(f,0,sizeof(f));
	memset(ans,0,sizeof(ans));
	if (m<n) dfs(m,n,0); else dfs(n,m,1);
	memset(d,0,sizeof(d));
	for (i=1;i<=min;i++)
	{
		for (j=1,s=0;j<=9;j++)
		if (ans[i][j])
		{
			d[j]++;
			s++;
		}
		ans[i][0]=s;
	}

	for (i=1,s=0;i<=9;i++)
	if (d[i])
	{
		s++;
		k=i;
	}
	if (s==0) puts("-1");
	else if (s==1) printf("%d\n",k);
	else
	{
		for (i=1,s=0;i<=min;i++)
		if (ans[i][0]>1)
		{
			s=1;
			break;
		}
		if (s) puts("-1"); else puts("0");
	}
	return 0;
}


#include <stdio.h>
int main(int argc, char *argv[]) {
int n;
int k;
int rest;
int res;
scanf("%d %d", &n, &k);

rest = n % k;
res = n - rest + k;

printf("%d", &res );

return res;
}


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

int main(){
    char *eevee[8] = {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"};
    int i,j,n,cont,pos,mayor = 0;
    char nom[10];
    scanf("%d %s",&n,nom);
    for(i = 0 ; i<8 ; i++){
        cont = 0;
        if(strlen(nom) == strlen(eevee[i]))
            for(j = 0 ; j< strlen(eevee[i]) ; j++){
                if(nom[j] == eevee[i][j]){
                    cont++;
                }
            }
        if(cont>mayor){
            mayor = cont;
            pos = i;
        }
    }
    printf("%s",eevee[pos]);
    return 0;
}


#include<stdio.h>
#include<malloc.h>
int main()
{
          int n,k,i=0,j,count=0,x;
          scanf("%d %d",&n,&k);
          int *a = (int *)malloc(sizeof(int)*n);
          for(i=0;i<n;i++)
          {
                    scanf("%d",&a[i]);
          }
          j=n-1,x=n;
          while((a[i]<=k || a[j]<=k) && x!=0)
          {
                    if(a[i]<k)
                    {
                              count++;
                              i++;
                              x--;
                    }
                    if(a[j]<k && x!=0)
                    {
                              count++;
                              j--;
                              x--;
                    }
          }
          printf("%d",count);

}


#include<stdio.h>

int main()
{

    int n,s=0;
    scanf("%d",&n);
    int i;
    int c=n;
    while(n--)
    {
        scanf("%d",&i);
        s+=i;
    }
    int res=0;
    for(i=1;i<=5;i++)
    {
        if((s+i)%(c+1) != 0)
        {
            res++;
        }
    }
    printf("%d",res);
    return 0;
}


 /*if (!strcmp(day1,d1))
    {
        if ( (strcmp(day2,d1)==0)||(strcmp(day2,d2)==0)||(strcmp(day2,d4)==0))
            printf("YES");
        else
            printf("NO");
    }
    else if (!strcmp(day1,d2))
    {
        if ( (strcmp(day2,d2)==0)||(strcmp(day2,d3))==0||(strcmp(day2,d5)==0))
            printf("YES");
        else
            printf("NO");
    }
    else if (!strcmp(day1,d3))
    {
        if ( (strcmp(day2,d3)==0)||(strcmp(day2,d4)==0)||(strcmp(day2,d6)==0))
            printf("YES");
        else
            printf("NO");
    }
    else if (!strcmp(day1,d4))
    {
        if ( (strcmp(day2,d4)==0)||(strcmp(day2,d5))==0||(strcmp(day2,d7)==0))
            printf("YES");
        else
            printf("NO");
    }
    else if (!strcmp(day1,d5))
    {
        if ( (strcmp(day2,d5)==0)||(strcmp(day2,d6)==0)||(strcmp(day2,d1)==0))
            printf("YES");
        else
            printf("NO");
    }
    else if (!strcmp(day1,d6))
    {
        if ( (strcmp(day2,d6)==0)||(strcmp(day2,d7)==0)||(strcmp(day2,d2)==0))
            printf("YES");
        else
            printf("NO");
    }
    else if (!strcmp(day1,7))
    {
        printf("mpika");
        if ( (strcmp(day2,d7)==0)||(strcmp(day2,d1)==0)||(strcmp(day2,d3)==0))
            printf("YES");
        else
            printf("NO");
    }*/


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


#include<stdio.h>

int main(void){
    long long int n,k,i=0,j=0,ans;
    scanf("%lld %lld", &n,&k);
    for(i=1,j=0;i<=n;i++){
        if(n%i==0){
            j++;
        if(j==k){ans=i;
        break;}
        if(j<k)continue;
        }}

    if(i==n+1 && k>j)
      ans=-1;
        printf("%lld", ans);}


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

#define MAX 333

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

int a[MAX];
int dp[MAX];
int n;

void update() {
  int i, j;
  for (i = 0; i < n; i++) {
    int ma = 0;
    for (j = 0; j <= a[i]; j++) {
      if (dp[j] > ma) ma = dp[j];
    }
    if (ma + 1 > dp[a[i]]) dp[a[i]] = ma + 1;
  }
}

int main() {
  int t, i;
  scanf("%d %d", &n, &t);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int time1 = min(MAX, t);
  int time3 = min(MAX, t - time1);
  int time2 = t - time1 - time2;
  for (i = 0; i < time1; i++) {
    update();
  }
  int ma = 0;
  if (time2 != 0) {
  for (i = 0; i < MAX; i++) {
    int cnt = 0;
    int j;
    for (j = 0; j < n; j++) if (a[j] == i) cnt++;
    if (dp[i] > ma) ma = dp[i];
    dp[i] = ma + cnt * time2;
  }
  }
  for (i = 0; i < time3; i++) {
    update();
  }
  int res = 0;
  for (i = 0; i < MAX; i++) if (dp[i] > res) res = dp[i];
  printf("%d\n", res);
  return 0;
}


#include<stdio.h>
#define HELL 1000000007
char fast_char_var;
#define	fast_unsigned_dtype	unsigned long
fast_unsigned_dtype fast_unsigned_var;
fast_unsigned_dtype fast_unsigned()
{
	fast_char_var=getchar();
	while(fast_char_var<48||fast_char_var>57)
		fast_char_var=getchar();
	fast_unsigned_var=0;
	while(fast_char_var>47&&fast_char_var<58)
	{
		fast_unsigned_var=(fast_unsigned_var<<1)+(fast_unsigned_var<<3)+fast_char_var-48;
		fast_char_var=getchar();
	}
	return fast_unsigned_var;
}
int main()
{
	static unsigned long long ans2,ans,i,j,a[4010],b[4010],n;
	n=fast_unsigned();
	n++;
	a[0]=1;
	for(i=1;i<=n;i++)
	{
		b[0]=a[i-1];
		for(j=1;j<=i;j++)
			b[j]=(a[j-1]+b[j-1])%HELL;

		for(j=0;j<=i;j++)
			a[j]=b[j];
	}
	ans=b[n]+HELL-b[n-1];
	ans%=HELL;
	a[0]=1;
	n--;
	for(i=1;i<=n;i++)
	{
		b[0]=a[i-1];
		for(j=1;j<=i;j++)
			b[j]=(a[j-1]+b[j-1])%HELL;

		for(j=0;j<=i;j++)
			a[j]=b[j];
	}
	ans2=b[n]+HELL-b[n-1];
	ans2%=HELL;
	printf("%llu\n",ans-ans2);
	return 0;
}


#include<stdio.h>
#include<math.h>
#define HELL 1000000007
char fast_char_var;
#define	fast_unsigned_dtype	unsigned long
fast_unsigned_dtype fast_unsigned_var;
fast_unsigned_dtype fast_unsigned()
{
	fast_char_var=getchar();
	while(fast_char_var<48||fast_char_var>57)
		fast_char_var=getchar();
	fast_unsigned_var=0;
	while(fast_char_var>47&&fast_char_var<58)
	{
		fast_unsigned_var=(fast_unsigned_var<<1)+(fast_unsigned_var<<3)+fast_char_var-48;
		fast_char_var=getchar();
	}
	return fast_unsigned_var;
}
#define	merge_sort_dtype	unsigned long
#define	merge_sort_maxsize	200005

unsigned long merge_sort_i,merge_sort_j,merge_sort_k,merge_sort_halfsize;
merge_sort_dtype merge_sort_array[merge_sort_maxsize],merge_sort_array2[merge_sort_maxsize],supporting_array1[merge_sort_maxsize],supporting_array2[merge_sort_maxsize];

void merge_sort_recursive(merge_sort_dtype *array, merge_sort_dtype *sarray, merge_sort_dtype *array2, merge_sort_dtype *sarray2,unsigned long size)
{
	if(size==1)
		return;
	merge_sort_recursive(array,sarray,array2,sarray2,size>>1);
	merge_sort_recursive(array+(size>>1),sarray+(size>>1),array2+(size>>1),sarray2+(size>>1),size-(size>>1));
	merge_sort_halfsize=(size>>1);
	for(merge_sort_i=0,merge_sort_j=merge_sort_halfsize,merge_sort_k=0;merge_sort_i<merge_sort_halfsize&&merge_sort_j<size;)
	{
		if(array[merge_sort_j]<array[merge_sort_i])
		{
			merge_sort_array[merge_sort_k++]=array[merge_sort_j++];
			supporting_array1[merge_sort_k++]=sarray[merge_sort_j++];
			merge_sort_array2[merge_sort_k++]=array2[merge_sort_j++];
			supporting_array2[merge_sort_k++]=sarray2[merge_sort_j++];
		}
		else if(array[merge_sort_j]>array[merge_sort_i])
		{
			merge_sort_array[merge_sort_k++]=array[merge_sort_i++];
			supporting_array1[merge_sort_k++]=sarray[merge_sort_i++];
			merge_sort_array2[merge_sort_k++]=array2[merge_sort_i++];
			supporting_array2[merge_sort_k++]=sarray2[merge_sort_i++];
		}
		else
		{
			if(array2[merge_sort_j]<array2[merge_sort_i])
			{
				merge_sort_array[merge_sort_k++]=array[merge_sort_j++];
				supporting_array1[merge_sort_k++]=sarray[merge_sort_j++];
				merge_sort_array2[merge_sort_k++]=array2[merge_sort_j++];
				supporting_array2[merge_sort_k++]=sarray2[merge_sort_j++];
			}
			else
			{
				merge_sort_array[merge_sort_k++]=array[merge_sort_i++];
				supporting_array1[merge_sort_k++]=sarray[merge_sort_i++];
				merge_sort_array2[merge_sort_k++]=array2[merge_sort_i++];
				supporting_array2[merge_sort_k++]=sarray2[merge_sort_i++];
			}
		}
	}
	while(merge_sort_i<merge_sort_halfsize)
	{
		merge_sort_array[merge_sort_k++]=array[merge_sort_i++];
		supporting_array1[merge_sort_k++]=sarray[merge_sort_i++];
		merge_sort_array2[merge_sort_k++]=array2[merge_sort_i++];
		supporting_array2[merge_sort_k++]=sarray2[merge_sort_i++];
	}
	for(merge_sort_i=0;merge_sort_i<merge_sort_k;merge_sort_i++)
	{
		merge_sort_array[merge_sort_i]=array[merge_sort_i];
		supporting_array1[merge_sort_i]=sarray[merge_sort_i];
		merge_sort_array2[merge_sort_i]=array2[merge_sort_i];
		supporting_array2[merge_sort_i]=sarray2[merge_sort_i];
	}
}

int main()
{
	static unsigned long length,word[202],pos1[200005],pos2[200005],what1[200005],what2[200005],i,a[128]={0},n,m;
	fast_char_var=getchar();
	i='a';
	while(fast_char_var!='V'&&fast_char_var!='C')
		fast_char_var=getchar();
	while(fast_char_var=='V'||fast_char_var=='C')
	{
		a[i++]=(fast_char_var==V);
		fast_char_var=getchar();
	}
	n=fast_unsigned();
	m=fast_unsigned();
	for(i=0;i<m;i++)
	{
		pos1[i]=fast_unsigned();
		fast_char_var=getchar();
		if(fast_char_var==V)
			what1[i]=1;
		pos2[i]=fast_unsigned();
		fast_char_var=getchar();
		if(fast_char_var==V)
			what2[i]=1;
	}
	merge_sort_recursive(pos2,what2,pos1,what1,m)
	i=0;
	while(fast_char_var<='a'||fast_char_var>='z')
		fast_char_var=getchar();
	while(fast_char_var>='a'&&fast_char_var<='z')
	{
		str[i++]=fast_char_var();
		fast_char_var=getchar();
	}
	str[i]=0;
	length=i;
	for(i=0;i<m;i++)
	{
		if(a[str[pos[i]]]!=what1[i])
			continue;
		else
		{

		}
	}
}


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

int main (void) {
  int A[2], B[2], C[2], dx[2], dy[2];
  long long cp;
  scanf ("%d %d %d %d %d %d", A, A+1, B, B+1, C, C+1);
  dx[0] = B[0] - A[0]; dx[1] = C[0] - B[0];
  dy[0] = B[1] - A[1]; dy[1] = C[1] - B[1];
  cp = (long long) dy[1]*dx[0] - (long long) dy[0]*dx[1];
  printf ("%s\n", cp < 0 ? "RIGHT" : cp == 0 ? "TOWARDS" : "LEFT");
  exit (EXIT_SUCCESS);
}


#include<stdio.h>
#include<string.h>
int main()
{
	int i,k=0,n;
	char s[n+1];
	scanf("%d",&n);
	scanf("%s",s);
	for(i=0;i<=n-1;i=i+k)
	{
		printf("%c",s[i]);
		k=k+1;

	}
	return 0;
}


#include <stdio.h>
int div(long long int k)
{
    int i,j,f=0,f1=0;long long int d[100];
    for(i=2; i*i<=k; i++)
    {
        j=i*i;
       while(k%j==0)
        {
            k/=i;
            d[f1]=k;
            f1++;
        }
    }
    f=k;
    return f;
}

int main()
{
    long long int n,j;
    scanf("%lld",&n);
    if(n==0){printf("%lld",n);return 0;}
      j=div(n);
    printf("%lld",j);
    return 0;
}


#include<stdio.h>
int main()
{
int a,m,r;
scanf("%d%d",&a,&m);
while(1)
{
r=a%m;
if(r==0)
break;
a=a+r;
}
if(a%m==0)
printf("Yes");
else
printf("No");
return 0;
}


#include <stdio.h>
int sqroot(int m)
{
	int i=0, j;
	int x1,x2;
	while( (i*i) <= m )
		i+=0.1;
	x1=i;
	for(j=0;j<10;j++)
	{
		x2=m;
		x2/=x1;
		x2+=x1;
		x2/=2;
		x1=x2;
	}
	return x2;
}
int main()
{
	int n;
	scanf(" %d", &n);
	int k=sqroot(1+8*n);
	if(k*k == n)
		printf("YES");
	else
		printf("NO");
}


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

using namespace std;

int main() {
    int x,y;
    scanf("%d%d",&x,&y);
    char a[x+1],b[y+1],c[5];
    scanf("%s%s",a,b);
    c[0]=a[0];c[1]=a[x-1];
    c[2]=b[0];c[3]=b[y-1];
    c[4]='\0';
    if(!strcmp(c,"<>v^") || !strcmp(c,"><^v"))
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


#include<cstdio>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 1e5 + 10;
const int INF = 1e9 + 7;
typedef long long LL;
bool sf(double x,double y,double z){
    if(z <= x || z >= y)
        return true;
    return false;
}
int main()
{
    double h,m,s,h1,h2;
    scanf("%lf %lf %lf %lf %lf",&h,&m,&s,&h1,&h2);
    m += s / 60,h += m / 60;
    double ma = m / 5,ms = s / 5;
    if(h1 > h2) swap(h1,h2);
    if(sf(h1,h2,h) && sf(h1,h2,ma) && sf(h1,h2,ms)){
        puts("YES");
        return 0;
    }
    if(h1 < h2) h1 += 12;
    double x = h + 12,y = ma + 12,z = ms + 12;
    if(sf(h2,h1,x) && sf(h2,h1,y) && sf(h2,h1,z) && sf(h2,h1,h) && sf(h2,h1,ma) && sf(h2,h1,ms)){
        puts("YES");
        return 0;
    }
    puts("NO");
    return 0;
}


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

int main (){
    int a,b,c,d,e,r;
  while (scanf("%d%d%d%d%d", &a,&b,&c,&d,&e) == 5){
  	r = 0;
        r = a+b+c+d+e;
    if(r%5 == 0){
        printf("%d",r/5);
    }else{
        printf(-1);
    }

}

return 0;
}
// 1459212714932


#include <stdio.h>
#include <string.h>
int main(){
    char arr;
    scanf("%s",arr);
    printf("%d",(strlen(arr) + 1) * 25 + 1);

}


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

int main()
{
    char str[20];
    int len;

    scanf("%s",str);

    return (strlen(str)+1)*25+1;
}


#include<stdio.h>
int main()
{
  unsigned long long int a,b, i=1,k,k1,sum=0;
  //printf("Enter the size of the program in lines\n");
  scanf("%lld",&a);
 //printf("Enter the productivity reduction coefficient\n");
  scanf("%lld",&b);
  k1=b;
  for(i=a/b;i<=a;i++)
  {
    sum=i;
     while(1)
     {
          k=i/k1;
          if(k==0)
            break;
         sum=sum+k;
          k1=k1*b;
     }
     if(sum>=a)
       break;
    sum=0;
    k1=b;
  }
 // printf("The minimum value = %lld",i);
printf("%lld",i);
  return 0;
}


#include<stdio.h>
int main()
{
	int n,n,ans;
	scanf("%d %d",&n, &m);
	if(n==0)
		ans=0;
	else if(m==0)
		ans=1;
	else if(m<=n/2)
		ans=m;
	else
		ans=n-m;
	printf("%d",ans);
}


#include <stdio.h>

int main(void) {
	int n, m;
	scanf("%d %d", &n, &m);
	int x = n/2;
	if (m > x){
	    printf("%d\n", n-m);
	    return 0;
	}
	else {
	    printf("%d\n", n)
	    return 0;
	}
}


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

 int n,m,e,h;
     scanf("%d%d",&n,&m);
     e=n-m;
     h=m;
     if (m==0||m==1)
     {
         printf("1");

     }
     else if (m==n)
     {

         printf("0");
     }
     else if (n!=0&&m>=n/2)
     {
          printf("%d",e);
     }
    else
    {
         printf("%d",h);
    }

    return 0;


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

int main()
{
    double ha,ma;
    int h,m;
    char ch;
    while(1)
    {
        scanf("%d%c%d",&h,&ch,&m);
        if(h>=12 )
            h=h-12;
        ha=(h+m/60.0)*30;
        ma=m*6;
        printf("%lg %lg\n",ha,ma);
    }
    return 0;
}


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

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

char S[MAX], T[MAX];
bool visited[MAX][MAX];
int n, m, dp[MAX][MAX], next[MAX][MAX];

int F(int i, int j){
    if (i >= n || j >= m) return 0;
    if (visited[i][j]) return dp[i][j];

    long long res = 0;
    if (next[i][j] != -1){
        res = res + F(i + 1, next[i][j] + 1) + 1;
        res = res + F(i, next[i][j] + 1);
    }

    visited[i][j] = true;
    return (dp[i][j] = (res % MOD));
}

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

    while (scanf("%s %s", S, T) != EOF){
        clr(visited);
        n = strlen(S), m = strlen(T);
        memset(next, -1, sizeof(next));
        for (i = 0; i < n; i++){
            for (j = m - 1; j >= 0; j--){
                if (S[i] == T[j]) next[i][j] = j;
                else if ((j + 1) != m) next[i][j] = next[i][j + 1];
            }
        }

        long long res = 0;
        for (i = 0; i < n; i++){
            for (j = 0; j < m; j++){
                if (S[i] == T[j]){
                    res = res + F(i + 1, j + 1) + 1;
                }
            }
        }
        printf("%lld\n", res % MOD);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    long long i,n,count=1;
    scanf("%lld",&n);
    if(n>1)
    {for(i=1;i<=n/2;i++)
    {
        if((n/i)>1)
        {
            count++;
        }

    }}
    else{count=1;}
    printf("%lld",count);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,m,l,count=0,i,j;
    scanf("%d%d",&n,&m);
    if (n>m){

        l=n*n;
    }
    else {
        l=m*m;
    }

    for (i=0;i<=l;i++){
    for (j=0;j<=l;j++){
        if ((i*i)+j==n && i+(j*j)==m){
               count++;
        }
    }
    }
    printf("%d",count);
    return 0;

}


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

int main()
{
    int i,n,k,count=0;

    char s[1000];

    scanf("%d",&n);

    scanf("%s",s);
    if(n<11)
    {
        printf("0\n");
    }

    for(i=0;i<=n;i++)
    {
        if(s[i]=='8')
        count++;
    }
    k=n/11;

    if(count/k>1)
    {
        printf("%d\n",k);
    }
    else
        printf("%d\n",count);

}


#include<stdio.h>
int x,z,i;std::char[100] y;main(){printf("%d %s",x,y);for(i=0;i<x;i++)if(y[i]=='8')z++;if(x/11<z)printf("%d",x/11);else printf("%d",z);}


/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:28/09/2019
*/
/*#include<algorithm>
#include <bits/stdc++.h>
using namespace std;*/

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define REP(i,n)        for(long long i=0;i<(n);i++)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);i--)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((int)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)            strlen(a)
#define MOD             1000000007
#define MAX             10000000005
#define MIN             -10000000005
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))

const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);
ll binpow(ll a,ll b,ll m)
{
    ll res=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
ll multiply(ll a, ll b, ll mod)
{
   return ((a % mod) * (b % mod)) % mod;
}
int main()
{
	ll n,m;
	SC2(n,m);
	unsigned long long ans=0;
	n++;
	ll x=2*n;
	unsigned long long z=binpow(x,m,MOD);
	z=z%MOD;
	unsigned long long z1=(n-m)%MOD;
	unsigned long long z2=multiply(z,z1,MOD);
	ans=(z2/n);
	ans=ans%MOD;
	printf("%llu\n",ans);

	return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
    if( *(ll*)a - *(ll*)b < 0 ) return -1;
    if( *(ll*)a - *(ll*)b > 0 ) return 1;
        return 0;
}
long long maxv(long long a,long long b)
{
    if(a>b) return a;
        return b;
}
long long minv(long long a,long long b)
{
    if(a<b) return a;
        return b;
}
long long gcd(long long u,long long v)
{
    if (v == 0) return u;
       return gcd(v, u%v);
}


#include<stdio.h>
int main()
{
	long long int n;
	scanf("%lld",&n);
	n=n*(n-1LL)*(n-2LL)*(n-3LL)*(n-4LL)*n*(n-1LL)*(n-2LL)*(n-3LL)*(n-4LL)/120LL;
	printf("%lld\n",n);
	return 0;
}


#include<stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	unsigned long long int l=n*(n-1)*(n-2)*(n-3)*(n-4);
	unsigned long long int m=(l/120);
	unsigned long long int t=m*l;
	printf("%llu",(unsigned long long)(t));
}


#include <stdio.h>
#include <string.h>
int main()
{
    char *a,*b;
    scanf("%ld %ld", &a,&b);
    if(a==b) printf("%s",a);
    else
            printf("%d",1);
    return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
    int str[999], str1[999];
    while(scanf("%s %s", str, str1))
    {
        if(strcmp(str, str1)==0) printf("%s\n", str1);
        else printf("%s\n", str);
    }
    return 0;
}


#define counter.is_even counter%2==0
#define counter.is_nonzero counter!=0
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}
long long int vertexes[11111];
int main(void) {
	long long int n, counter, position, maximum = 1;
	scanf("%I64d", &n);
	for(int i = 1; i <= n; i++) {
        scanf("%I64d", &vertexes[i]);
    }
	for(int i = 1; i <= n; i++){
		counter = 1;
		position = vertexes[i];
		while(position != i) {
			position = vertexes[position];
			counter++;
			if( counter > 100 || vertexes[position] == position) {
                printf("-1");
                return 0;
            }
		}
		if(counter.is_even) {
            counter = counter / 2;
        }
		if(counter.is_nonzero) {
            maximum = maximum * counter / gcd(maximum, counter);
        }
	}
	printf("%I64d", maximum);
	return 0;
}


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


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

#define MAXP 1000005

#define MOD 1000000007

int mat[MAXP];
int p, k;

int dfs (int a) {

	if (mat[a] == 1)
		return 0;

	mat[a] = 1;

	return dfs((k * a) % p);
}

int main () {
	int i;
	long long res = 1;

	memset(mat, 0, sizeof(int) * MAXP);

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

	for (i = 1; i < p; i++) {
		if (!mat[i]) {
			dfs(i);
			res = ((res % MOD) * (p % MOD)) % MOD;
		}
	}

	if (k == 1) {
		res = ((res % MOD) * (p % MOD)) % MOD;
	}

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

	return 0;

}


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

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

int p, k;
bool visited[1000010];

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

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

int main(){
    int i, j, res, counter;

    while (scanf("%d %d", &p, &k) != EOF){
        counter = 0;
        clr(visited);
        for (i = 0; i < p; i++){
            if (!visited[i]){
                counter++;
                visited[i] = true;
                j = (i * k) % p;
                while (!visited[j]){
                    visited[j] = true;
                    j = (j * k) % p;
                }
            }
        }

        if (k == 1) res = expo(p, p);
        else res = expo(p, --counter);
        printf("%d\n", res);
    }
    return 0;
}


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

/*

Vasya has found a strange device. On the front panel of
a device there are: a red button, a blue button and a
display showing some positive integer. After clicking
the red button, device multiplies the displayed number
by two. After clicking the blue button, device subtracts
one from the number on the display. If at some point
the number stops being positive, the device breaks down.
The display can show arbitrarily large numbers.
Initially, the display shows number n.

Bob wants to get number m on the display. What minimum
number of clicks he has to make in order to achieve this result?

Input
The first and the only line of the input contains
two distinct integers n and m (1 <= n, m <= 10000),
separated by a space.

Output
Print a single number � the minimum number of times one
needs to push the button required to get the number m out
of number n.

*/

typedef struct Pair {
    int data;
    int distance;
} Pair;

struct QueueElem{
    Pair pair;
    struct QueueElem* next;
};

Pair makePair(int f, int s){
    Pair p = {f, s};
    return p;
}

typedef struct QueueElem Elem;

struct Queue{
    Elem *front; // sa fronta uklanjam
    Elem *rear; // na rear dodajem
};

typedef struct Queue Queue;

void init(Queue *q){
    q->front = NULL;
    q->rear = NULL;
}

void destroy(Queue *q){ // treba svaki Elem brisat jer je pravljen sa malloc
    free(q->front);
    free(q->rear);
}

int isEmpty(Queue *q){
    return (q->front == NULL && q->rear == NULL);
}

//void print(Queue *q){
//    for(Elem *curr = q->front; curr != NULL; curr = curr->next){
//        printf("%d ", curr->data);
//    }
//    printf("\n");
//}

void enqueue(Queue *q, Pair p){
    Elem *newElem = malloc(sizeof(Elem));
    newElem->pair = p;
    newElem->next = NULL;

    if(q->rear == NULL){
        q->front = newElem;
        q->rear = newElem;
    }
    else{
        q->rear->next = newElem;
        q->rear = newElem;
    }
}

Pair dequeue(Queue *q){
    if(isEmpty(q)){
        return makePair(-10000, -10000);
    }
    Pair temp = q->front->pair;

    Elem *tmp = q->front;
    q->front = q->front->next;
    free(tmp);
    //tmp = NULL;

    if(q->front == NULL){
        q->rear = NULL;
    }
    return temp;
}

Pair peek(Queue *q){
    if(q->front != NULL) return q->front->pair;
    else return makePair(-10000, -10000);
}

// a greedy BFS sounds fine, maybe for small inputs, we'll see
// what code forces says

void solve(){
    int n, m;
    scanf("%d%d", &n, &m);

    Queue q1;
    Queue *q = &q1;
    init(q);
    enqueue(q, makePair(n, 0));

    while(!isEmpty(q)){
        Pair curr = dequeue(q);
        if(curr.data == m){
            printf("%d", curr.distance);
            return;
        }
        enqueue(q, makePair(curr.data*2, curr.distance+1));
        if(curr.data-1 >= 0){
            enqueue(q, makePair(curr.data-1, curr.distance+1));
        }
    }
}

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


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

#define KONTROL(x,y,t) (!mariaMove[x][y][t] && x >= 0 && x < n && y >= 0 && y < n)

#define Max(a,b)    (((a) > (b)) ? (a) : (b))
#define Min(a,b)    (((a) < (b)) ? (a) : (b))

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)

#define SWAP(a,b)   {t = a; a = b; b = t;}

#define lli long long int

#define endl    puts("")

#define MAX   1e5 + 9

typedef struct pair{
	int x, y;
}pair;

int const N = 1e4 + 5;

int n = 8;

pair sMatrix[N], sac[N];

char matrix[N][N], mariaMove[10][10][10];

pair anna, maria;

int i, j, k, s, m, h, t;

int kontrol(int x, int y){
	int i, j;
	for(i = 0; i < s; i++) {
		if(sMatrix[i].x == x && sMatrix[i].y == y)
			return 0;
	}
	return 1;
}

void sDown(int add) {
	int i;
	for(i = 0; i < s; i++) {
		sMatrix[i].x += add;
	}
}

void dfs(int x, int y, int t) {
	int i, j, k;

	if(x == anna.x && y == anna.y) {
		printf("WIN"), endl;
		exit(0);
	}

	if(!KONTROL(x,y,t) || !kontrol(x,y)) return ;

	sDown(1);

	if(!kontrol(x,y)){ sDown(-1); return ; }

	mariaMove[x][y][t] = 1;

	for(i = -1, k = 0; i <= 1; i++) {
		for(j = -1; j <= 1; j++, k++) {
			dfs(x+i,y+j, k);
		}
	}
	sDown(-1);
}

void clearMariaMove() {
	int i, j, k;
	for(i = 0; i < 10; i++) {
		for(j = 0; j < 10; j++) {
			for(k = 0; k < 100; k++) {
				mariaMove[i][j][k] = 0;
			}
		}
	}
}

void clear_sMatrix() {
	int i;
	for(i = 0; i < s; i++) {
		sMatrix[i].x = sac[i].x;
		sMatrix[i].y = sac[i].y;
	}
}

int main() {

	for(i = 0; i < n; i++) {
		scanf("%s", matrix[i]);
		for(j = 0; j < n; j++) {
			if(matrix[i][j] == 'S') {
				sMatrix[s].x = i, sMatrix[s].y = j;
				sac[s].x = i, sac[s].y = j;
				s++;
			}
		}
	}

	maria.x = 7, maria.y = 0;
	anna.x = 0, anna.y = 7;

	for(i = -1; i <= 0; i++) {
		for(j = 0; j <= 1; j++) {
			dfs(maria.x+i, maria.y+j, 0);
			clearMariaMove();
			clear_sMatrix();
		}
	}

	puts("LOSE");

	return 0;
}


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

	int n,a,b;
	scanf("%d%d%d" ,&n,&a,&b);
	if(b>0)
	{
	  a=a+b;
	  if(a%n==0)
	  printf("%d" ,n);
	  else
	  printf("%d" ,a%n);
	}
	if(b==0)
	printf("%d" ,a);
	else
	{
		b=b*(-1);
		while(b--)
		{
			if(a>=1)
			a--;
			if(a==0)
			{
				a=n;
			}
		}
		printf("%d" ,a);
   }
 return 0;
}


#include<stdio.h>
#include<math.h>
int cnt=0,a[1000000];
int n,k;
void dfs(int step,int sum,int b)
{
	int i;
	if(step==k){
		a[cnt++]=sum;
		return;
	}
	for(i=b;i<=n;i++){
		if((sum^i)>sum)
			dfs(step+1,sum^i,i+1);
	}
	a[cnt++]=sum;
}
int main()
{
	int i,max=0;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++){
		dfs(1,i,i+1);
	}
	for(i=0;i<cnt;i++){
		if(max<a[i])max=a[i];
	}
	printf("%d",max);
	return 0;
}


#include<stdio.h>
#include<math.h>
int cnt=0,a[10000000];
int n,k;
void dfs(int step,int sum,int b)
{
	int i;
	if(step==k){
		a[cnt++]=sum;
		return;
	}
	for(i=b;i<=n;i++){
		if((sum^i)>sum)
			dfs(step+1,sum^i,i+1);
	}
	if(sum>a[cnt-1])a[cnt++]=sum;
}
int main()
{
	int i,max=0;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++){
		dfs(1,i,i+1);
	}
	for(i=0;i<cnt;i++){
		if(max<a[i])max=a[i];
	}
	printf("%d",max);
	return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
	int c,k=0,t=0;
	char ch1[2];
	char ch[14];
	gets(ch1);
	gets(ch);
	for(int i=0,j=0;i<strlen(ch);i+3,j+3)
	{
		if(ch1[0]==ch[i] || ch1[1]==ch[j])
		{
			k=1;
			break;
		}

	}
	if(k==1)
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
}


/*
ID: mohamma73
LANG: C
TASK: crypt1
*/

#include"stdio.h"
#include"stdlib.h"
#include"ctype.h"
#include"math.h"
#include"string.h"
struct card{
	int val;
	char suit;
	int id;
};
struct point{
	int x;
	int y;
	int visit;
};
struct node{
	int id;
	int n;
	int nei[102];
};
struct person{
	int id;
	int nd;
	int nl;
	int like[2004];
	int dis[2004];
	int visit;
};
struct farmer{
	int p;
	int c;
};
void inc(int *a,int n){
	int i;
	if(a[0]!=2){
		a[0]++;
		return;
	}
	for(i=0;i<n && a[i]==2;i++)
		a[i]=0;
	if(i<n)
		a[i]++;
}
int cmp(char *s,char *t){
	int n=strlen(s);
	int m=strlen(t);
	int i,j;
	for(i=0,j=0;i<n && j<m && s[i]==t[j];i++,j++);
	if(s[i]>t[j])
		return 1;
	else if(s[i]<t[j])
		return -1;
	else
		return 0;

}
int getword(char *s,int n){
	int i;
	char c;
	while(isspace(c=getchar()));
	for(i=0;i<n && !isspace(c);i++,c=getchar())
		s[i]=c;
	s[i++]='\0';
	return i-1;
}
int fgetword(char *s,int n,FILE *fp){
	int i;
	char c;
	while(isspace(c=getc(fp)));
	for(i=0;i<n && !isspace(c) && c!=EOF;i++,c=getc(fp))
		s[i]=c;
	s[i++]='\0';
	return i-1;
}
long long atll(char *s){
	long long n=0;
	int i;
	for(i=0;s[i]!='\0';i++){
		n*=10;
		n+=(s[i]-'0');
	}
	return n;
}
int Bsear(char *s,char words[][13],int n){
	int l=0;
	int h=n;
	int mid;
	while(l<h){
		mid=(l+h)/2;
		if(cmp(words[mid],s)==0)
			return 1;
		else if(cmp(words[mid],s)==1){
			h=mid;
		}else
			l=mid+1;
	}
	return -1;
}
void func(int *n,int base,int num){
	int i=0;
	while(num/base!=0){
		n[i++]=num%base;
		num/=base;
	}
	n[i++]=num;
	n[i++]=20;
}
int pal(int *n){
	int i,j;
	for(i=0;n[i]!=20;i++);
	for(j=0;j<i/2 && n[j]==n[i-j-1];j++);
	if(j==i/2)
		return 1;
	return 0;
}
int ispal(char *s, int i, int j){
	int k;
	for(k=0;k<((j-i+1)/2) && s[i+k]==s[j-k];k++);
	if(k==(j-i+1)/2)
		return 1;
	return 0;
}
void insort(int *a,int n){
	int i,j,temp;
	for(i=1;i<n;i++){
		j=i;
		while(j>0 && a[j]<a[j-1]){
			temp=a[j-1];
			a[j-1]=a[j];
			a[j]=temp;
			j--;
		}
	}
}
char lower(char c){
	return c<'a'?c+('a'-'A'):c;
}
void sort(int *a,int n){
	int i,j,temp;
	for(i=1;i<n;i++)
		for(j=i;j>0 && a[j-1]>a[j];j--){
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;

		}
}
void fun(int n,char *s){
	int i=0;
	for(i=0;n/10!=0;i++,n/=10)
		s[i]=n%10+'0';
	s[i++]=n+'0';
	s[i]='\0';
}
void sortIn(int *a,int *indx,int n){
	int t1;
	int i,j;
	for(i=1;i<n;i++)
		for(j=i;j>0 && a[j-1]>a[j];j--){
			t1=a[j-1];
			a[j-1]=a[j];
			a[j]=t1;
			t1=indx[j-1];
			indx[j-1]=indx[j];
			indx[j]=t1;
		}
}
int valid(int *a,int l,int r,int n){
	int f=0;
	if(l>0 && a[l-1]>a[r])
		f=1;
	if(a[l+1]<a[r])
		f=1;
	if(a[r-1]>a[l])
		f=1;
	if(r<n-1 && a[r+1]<a[l])
		f=1;
	if(f)
		return 0;
	return 1;
}
void change(char *stripe,int *colors,int idx,int k){
	int j=0;
	if(idx==1){
		if(stripe[0]-'A'>0)
			stripe[0]=colors[stripe[0]-'A'-1];
		else
			stripe[0]=colors[stripe[0]-'A'+1];
		return ;
	}
	for(j=0;j<idx;j+=2){
		if(stripe[j]-'A'>0){
			if(stripe[j]==stripe[j+1])
				stripe[j]=colors[stripe[j]-'A'-1];
			else if(stripe[j+1]!=colors[stripe[j]-'A'-1])
				stripe[j]=colors[stripe[j]-'A'-1];
			else if(stripe[j]-'A'<k-1)
				stripe[j]=colors[stripe[j]-'A'+1];
			else
				stripe[j]=colors[stripe[j]-'A'-2];
		}else{
			if(stripe[j]==stripe[j+1])
				stripe[j]=colors[stripe[j]-'A'+1];
			else
				stripe[j]=colors[stripe[j]-'A'+2];
		}
	}
}
int invite(struct point *nom[],int n,struct point *pts[],int m,struct point *invite[]){
	int i,j,idx=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(nom[i]->x==pts[j]->x || nom[i]->y==pts[j]->y){
				if(pts[j]->visit==0){
					invite[idx++]=pts[j];
					pts[j]->visit=1;
				}
			}
		}

	}
	return idx;
}
int feasible(struct person *a[],int n){
	int i,j,k;
	int flag=1;
	for(i=0;flag && i<n;i++)
		for(j=0;flag && j<a[i]->nd;j++)
			for(k=0;flag &&k<n;k++){
				if(a[k]->id==a[i]->dis[j]){
					flag=0;
					break;
				}
			}
	if(i==n)
		return 1;
	return 0;
}
int find(struct node *p,struct node *node[]){
	int i,j,k;
	int count=0;
	for(i=0;i<p->n;i++){
		if(p->nei[i]==-1)
			continue;
		for(j=0;j<node[p->nei[i]]->n;j++){
			if(node[p->nei[i]]->nei[j]==-1)
				continue;
			for(k=0;k<p->n;k++){
				if(p->nei[k]==-1)
					continue;
				if(node[p->nei[i]]->nei[j]==p->nei[k])
					count++;
			}
		}
	}

	return count;
}
void rem(struct node *p,struct node *nodes[],int n){
	int i,j;
	for(i=0;i<n;i++){
		if(nodes[i]==NULL)
			continue;
		for(j=0;j<nodes[i]->n;j++)
			if(nodes[i]->nei[j]==p->id)
				nodes[i]->nei[j]=-1;
	}
}
int dfs3(struct card piles[],int n,int a[55][55][55][55]){
	int dfs1(struct card[],int,int [][][][]);
	if(n<=3)
		return 0;
	if(a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id]!=-1)
		return a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id];
	if(piles[n-1].suit==piles[n-4].suit || piles[n-1].val==piles[n-4].val){
		struct card p[n];
		int i;
		for(i=0;i<n;i++){
			p[i].suit=piles[i].suit;
			p[i].val=piles[i].val;
			p[i].id=piles[i].id;
		}
		p[n-4].suit=p[n-1].suit;
		p[n-4].val=p[n-1].val;
		p[n-4].id=p[n-1].id;
		if(dfs1(p,n-1,a) || dfs3(p,n-1,a))
			return a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id]=1;
		else
			return a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id]=0;
	}
	return a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id]=0;
}
int dfs1(struct card piles[],int n,int a[55][55][55][55]){
	if(n==1)
		return a[n][piles[0].id][0][0]=1;
	if(n==2)
		if(a[n][piles[n-1].id][piles[n-2].id][0]!=-1)
			return a[n][piles[n-1].id][piles[n-2].id][0];
	if(n>2)
		if(a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id]!=-1)
					return a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id];
	if(piles[n-1].val==piles[n-2].val || piles[n-1].suit==piles[n-2].suit){
		struct card p[n-1];
		int i;
		for(i=0;i<n-1;i++){
			p[i].suit=piles[i].suit;
			p[i].val=piles[i].val;
			p[i].id=piles[i].id;
		}
		p[n-2].val=piles[n-1].val;
		p[n-2].suit=piles[n-1].suit;
		p[n-2].id=piles[n-1].id;
		if(n==2)
			return a[n][piles[n-1].id][piles[n-2].id][0]=1;
		else {
			if(dfs1(p,n-1,a) || dfs3(p,n-1,a))
				return a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id]=1;
			else
				return a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id]=0;
		}
	}
	return a[n][piles[n-1].id][piles[n-2].id][piles[n-3].id]=0;
}
main(){
	char s[20];
	int i,j,k,l,idx=1;
	struct card piles[55];
	getword(s,20);
	int n=atoi(s);
	for(i=0;i<n;i++){
		piles[i].val=getchar();
		piles[i].suit=getchar();
		for(j=0;j<i;j++)
			if(piles[j].suit==piles[i].suit && piles[j].val==piles[i].val){
				piles[i].id=piles[j].id;
				break;
			}
		if(i==j)
			piles[i].id=idx++;
		getchar();
	}
	int a[55][55][55][55];
	for(i=0;i<55;i++)
		for(j=0;j<55;j++)
			for(k=0;k<55;k++)
				for(l=0;l<55;l++)
					a[i][j][k][l]=-1;
	if(dfs1(piles,n,a) || dfs3(piles,n,a))
		printf("YES");
	else
		printf("NO");
	return 0;
}


/*
 * =====================================================================================
 *
 *       Filename:  Solitaire.c
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  2012年07月25日 13时47分01秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *   Organization:
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAXN 2<<6
#define OP1 1
#define OP2 3

typedef struct Card {
	char val;
	char suit;
} Card_t;

int dfs(Card_t *cards, int n, int op) {
	if(n == 1) return 1;
	if(n - op <=0 ) return 0;

	if(cards[n].val == cards[n - op].val) {
		int tmpSuit = cards[n - op].suit;
		cards[n - op].suit = cards[n].suit;
		if(dfs(cards, n-1, OP1) || dfs(cards, n-1, OP2))
			return 1;
		else
			cards[n - op].suit = tmpSuit;
	}
	if(cards[n].suit == cards[n - op].suit) {
		int tmpVal = cards[n- op].val;
		cards[n - op].val = cards[n].val;
		if(dfs(cards, n-1, OP1) || dfs(cards, n-1, OP2))
			return 1;
		else
			cards[n -op].val = tmpVal;
	}
	return 0;
}

int main() {
	Card_t cards[MAXN];
	int i,n;
	char tmp;

	while(scanf("%d", &n) != EOF) {
		scanf("%c",&tmp);
		memset (cards, 0, sizeof cards);
		for(i=1; i <=n ; ++i)
			if (i < n)
				scanf("%c%c%c", &cards[i].val, &cards[i].suit, &tmp);
			else
				scanf("%c%c", &cards[i].val, &cards[i].suit);

		if(dfs(cards, n, OP1) || dfs(cards, n, OP2)) puts("YES");
		else puts("NO");
	}
	return 0;
}


/*
 * =====================================================================================
 *
 *       Filename:  Solitaire.c
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  2012年07月25日 13时47分01秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *   Organization:
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAXN 2<<6
#define OP1 1
#define OP2 3
int dp[MAXN][MAXN][MAXN][MAXN];
typedef struct Card {
	char val;
	char suit;
} Card_t;
Card_t cards[MAXN];
/*
int dfs(Card_t *cards, int n, int op) {
	if(n == 1) return 1;
	if(n - op <=0 ) return 0;

	if(cards[n].val == cards[n - op].val) {
		int tmpSuit = cards[n - op].suit;
		cards[n - op].suit = cards[n].suit;
		if(dfs(cards, n-1, OP1) || dfs(cards, n-1, OP2))
			return 1;
		else
			cards[n - op].suit = tmpSuit;
	}
	if(cards[n].suit == cards[n - op].suit) {
		int tmpVal = cards[n- op].val;
		cards[n - op].val = cards[n].val;
		if(dfs(cards, n-1, OP1) || dfs(cards, n-1, OP2))
			return 1;
		else
			cards[n -op].val = tmpVal;
	}
	return 0;
}
*/

int calc(int n, int a, int b, int c) {
	if(n == 1) return 1;
	if(n == 2) {
		if(cards[a].val == cards[b].val || cards[a].suit == cards[b].suit) return 1;
		else return 0;
	}
	if(n == 3) {
	//	printf("n-%d a-%d b-%d c-%d\n",n,a,b,c);
		if(cards[c].val == cards[b].val || cards[c].suit == cards[b].suit) {
	//		printf("cards[%d].val=%c cards[%d].val=%c\n",c,cards[c].val,b,cards[b].val);
			if(cards[c].val == cards[a].val || cards[c].suit == cards[a].suit)
				return 1;
			else
				return 0;
		}
		else
			return 0;
	}
	return 0;
}

int main() {
	int i,j,k,l,n;
	char tmp;

	while(scanf("%d", &n) != EOF) {
		scanf("%c",&tmp);
		memset (cards, 0, sizeof cards);
		memset (dp, 0, sizeof dp);
		for(i=1; i <=n ; ++i)
			if (i < n)
				scanf("%c%c%c", &cards[i].val, &cards[i].suit, &tmp);
			else
				scanf("%c%c", &cards[i].val, &cards[i].suit);

		for(i=1; i<=n; ++i) {
			for(j=1; j<=n; ++j) {
				for(k=1; k<=n; ++k) {
					if(j == k) continue;
					for(l=1; l<=n; ++l)  {
						if(k == l) continue;
						if(i >= 4) {
							if(cards[i-3].val == cards[l].val || cards[i-3].suit == cards[l].suit)
								dp[i][j][k][l] = dp[i-1][l][j][k];
							if(cards[k].val == cards[l].val || cards[k].suit == cards[l].suit)
								dp[i][j][k][l] = dp[i][j][k][l] || dp[i-1][i-3][j][l];
						}
						else
							dp[i][j][k][l] = calc(i,j,k,l);
	//					printf("dp[%d][%d][%d][%d]:%d\n",i,j,k,l,dp[i][j][k][l]);
					}
				}
			}
		}

		if(n == 1) {
			if(calc(1, 1, 0, 0)) puts("YES");
			else puts("NO");
		}
		else if(n == 2) {
			if(calc(2, 1, 2, 0)) puts("YES");
			else puts("NO");
		}
		else {
			if(dp[n][n-2][n-1][n]) puts("YES");
			else puts("NO");
		}
	}
	return 0;
}


/*
 * =====================================================================================
 *
 *       Filename:  Solitaire.c
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  2012年07月25日 13时47分01秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *   Organization:
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAXN 52
#define OP1 1
#define OP2 3
int dp[MAXN][MAXN][MAXN][MAXN];
typedef struct Card {
	char val;
	char suit;
} Card_t;
Card_t cards[MAXN];
/*
int dfs(Card_t *cards, int n, int op) {
	if(n == 1) return 1;
	if(n - op <=0 ) return 0;

	if(cards[n].val == cards[n - op].val) {
		int tmpSuit = cards[n - op].suit;
		cards[n - op].suit = cards[n].suit;
		if(dfs(cards, n-1, OP1) || dfs(cards, n-1, OP2))
			return 1;
		else
			cards[n - op].suit = tmpSuit;
	}
	if(cards[n].suit == cards[n - op].suit) {
		int tmpVal = cards[n- op].val;
		cards[n - op].val = cards[n].val;
		if(dfs(cards, n-1, OP1) || dfs(cards, n-1, OP2))
			return 1;
		else
			cards[n -op].val = tmpVal;
	}
	return 0;
}
*/

int calc(int n, int a, int b, int c) {
	if(n == 1) return 1;
	if(n == 2) {
		if(cards[a].val == cards[b].val || cards[a].suit == cards[b].suit) return 1;
		else return 0;
	}
	if(n == 3) {
	//	printf("n-%d a-%d b-%d c-%d\n",n,a,b,c);
		if(cards[c].val == cards[b].val || cards[c].suit == cards[b].suit) {
	//		printf("cards[%d].val=%c cards[%d].val=%c\n",c,cards[c].val,b,cards[b].val);
			if(cards[c].val == cards[a].val || cards[c].suit == cards[a].suit)
				return 1;
			else
				return 0;
		}
		else
			return 0;
	}
	return 0;
}

int main() {
	int i,j,k,l,n;
	char tmp;

	while(scanf("%d", &n) != EOF) {
		scanf("%c",&tmp);
		memset (cards, 0, sizeof cards);
		memset (dp, 0, sizeof dp);
		for(i=1; i <=n ; ++i)
			if (i < n)
				scanf("%c%c%c", &cards[i].val, &cards[i].suit, &tmp);
			else
				scanf("%c%c", &cards[i].val, &cards[i].suit);

		for(i=1; i<=n; ++i) {
			for(j=1; j<=n; ++j) {
				for(k=1; k<=n; ++k) {
					if(j == k) continue;
					for(l=1; l<=n; ++l)  {
						if(k == l) continue;
						if(i >= 4) {
							if(cards[i-3].val == cards[l].val || cards[i-3].suit == cards[l].suit)
								dp[i][j][k][l] = dp[i-1][l][j][k];
							if(cards[k].val == cards[l].val || cards[k].suit == cards[l].suit)
								dp[i][j][k][l] = dp[i][j][k][l] || dp[i-1][i-3][j][l];
						}
						else
							dp[i][j][k][l] = calc(i,j,k,l);
	//					printf("dp[%d][%d][%d][%d]:%d\n",i,j,k,l,dp[i][j][k][l]);
					}
				}
			}
		}

		if(n == 1) {
			if(calc(1, 1, 0, 0)) puts("YES");
			else puts("NO");
		}
		else if(n == 2) {
			if(calc(2, 1, 2, 0)) puts("YES");
			else puts("NO");
		}
		else {
			if(dp[n][n-2][n-1][n]) puts("YES");
			else puts("NO");
		}
	}
	return 0;
}


#include <stdio.h>

long long int fact(long long int b, long long int a)
{
    if ( b==a ) return 1;
    else b=b*fact(b-1,a);
    return b%10;
}
int main()
{
     long long int a, b;
     scanf("%lld %lld", &a, &b);
     b=fact(b,a);
     printf("%lld", b%10);
     return 0;
}


#include <stdio.h>

int main(){
	int n,k,path;
	scanf("%d %d",&n,&k);
	if(n==1){
	    print(0);
	}
	else{
	if((n-k)<=(k-1)){
		path=(n-k)+(n-1);
	}
	else{
		path=(n-1)+(k-1);
	}
	int total=2*path+n+2;
	if(k!=1 && k!=n){
		total -= 1;
	}
	printf("%d",total);
	}
}


#include <stdio.h>

int lucky(int n)
{
    long long int m;
    while(n!=0)
    {
        m=n%10;
        if(m!=4 && m!=7)
            return 0;
        n=n/10;
    }
    return 1;

}

int main()
{
    long long int n,i,j=0;
    scanf("%I64d",&n);
    for(i=4;i<=n;i++)
    {
        if(1==lucky(i))
        {
            j++;
        }
    }
    printf("%I64d\n",j);

    return 0;
}


#include<stdio.h>
#include<string.h>
struct node{
	int s,e,d,id;
}a[105];
int b[105];
void sort(struct node a[],int m){
	struct node temp;
	int i,j;
	for(i=1;i < m;i++){
	   for(j = 1;j < m-i;j++){
	   	if(a[j].e > a[j+1].e){
	   		temp = a[j];
	   		a[j] = a[j+1];
	   		a[j+1] = temp;
			}
		}
	}
}
int main(){
	int n,m;
	int i,j,t;
	int flag = 0;
	while(scanf("%d%d",&n,&m) != EOF){
		memset(b,0,sizeof(b));
		for(i = 1;i <= m;i++){
			scanf("%d%d%d",&a[i].s,&a[i].e,&a[i].d);
			a[i].id = i;
			b[a[i].e] = m + 1;
		}
		sort(a,m);
		for(i = 1;i <= m;i++){
			int count = 0;
			for(j = a[i].s;j < a[i].e;j++){
				if(b[j] == 0){
					b[j] = a[i].id;
					count++;
				}
				if(count == a[i].d) break;
			}
			if(count != a[i].d){
				flag = 1;
				break;
			}
		}
		if(flag == 1){
			printf("-1\n");
		}
		else{
			for(j = 1;j <= n-1;j++){
				printf("%d ",b[j]);
			}
			printf("%d\n",b[j]);
		}

	}
	return 0;
}


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

return 0;
}


#include<stdio.h>
int main()
{
	int n,e,i,j,k;
	scanf("%d%d",&n,&e);
	if((n/e)>=2)
	k=e;
	else if((e/n)>=2)
	k=n;
	else
	{
			k=(n+e)/3;
	}
	printf("%d\n",k);
}


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

int main()
{
    int n,t,k,d;
    scanf("%d%d%d%d",&n,&t,&k,&d);
    if(n*t<=k*d){
        printf("NO");
        return;
    }
    if(k>=n&&t>d){
        printf("YES");
        return;
    }
    if(k>=n&&t<=d){
        printf("NO");
        return;
    }
    if(k<n){
        if(d+t*(((n-d*k/t)/(2*k))/1+1)<n*t/k)
            printf("YES");
        else
            printf("NO");
    }
    return 0;
}


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

#define SIZE 1000

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

	*sz = 0;

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

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

			(*sz)++;
		}

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

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

	return n == 1;
}

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

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

	return 0;
}

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

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

	i = 0;

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

	cnt = i;

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

	return cnt;
}

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

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

	return min;
}

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

	scanf ("%d", &n);

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

	oper_cnt = oper (p, k, sz);

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

	return 0;
}


#include <stdio.h>

void sort(int[], int);

int main()
{
	int A[10];
	int n, m, i, j, temp;

	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++)
		scanf("%d", &A[i]);

	sort(A, m);
	int result = 50001;
	for (i = 0; i < m + 1 - n; i++)
		if (A[i + n - 1] - A[i] < result)
			result = A[i + n - 1] - A[i];

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

void sort(int A[], int m)
{
	int i, j;

	for (i = 0; i < m - 1; i++)
		for (j = i + 1; j < m; j++)
			if (A[i] > A[j])
			{
				int temp = A[i];
				A[i] = A[j];
				A[j] = temp;
			}
}


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

typedef long long int lli;

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

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

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

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

#define MOD 1000000007

int main(void)
{
    int n;
    in32(n);
    lli ans = 1;
    while (n-->1)
        ans = (ans * 3) % MOD;
    out64(ans);
    return EXIT_SUCCESS;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int i,n,res=0;
scanf("%d",n);
for(i=1;i<=n;i++){
    res=res+pow(-1,n)*n;
}
printf("%d",res);
}


#include <stdio.h>

long long f[100001];

inline long long calc(long long m) {
	int i;
	long long sum;

	sum = 0;
	for (i = 2; i <= 100000; i++)
		sum += m / f[i];

	return sum;
}

int main(void) {
	long long i;
	long long m;
	long long l = 8, r = 10000000000000000LL;

	for (i = 2; i <= 100000; i++)
		f[i] = i * i * i;

	scanf("%lld", &m);

	while (l <= r) {
		const long long mid = (l + r) / 2;

		if (calc(mid) >= m)
			r = mid - 1;
		else
			l = mid + 1;
	}

	printf("%lld\n", calc(l) == m ? l : -1);

	return 0;
}


#include<stdio.h>
int main()
{
	long long int c,m,k=2,p,s=0,i,a,b,power[100005]={0,1};
	scanf("%lld",&m);
	for(i=1;i<100005;i++)
	power[i]=i*i*i;
	while(s<m)
	{
		s=0;
		p=power[k];
		for(i=2;i<=k;i++)
		s=s+p/power[i];
		k++;
	}
	if(s==m)
	printf("%lld\n",p);
	else
	{
		a=power[k-2];
		b=power[k-1];
		for(i=a;i<=b;i++)
		{
			c=2;
			s=0;
			while(i/power[c]>0)
			{
				s=s+i/power[c];
				c++;
			}
			if(s>=m)
			break;
		}
		if(s==m)
		printf("%lld\n",i);
		else
		printf("-1\n");
	}
	return 0;
}


#include<stdio.h>
int main()
{
    signed long long int x;
 long int i,min=0,cur=0,temp=1;
scanf("%ld",&x);
if(x>=0)
{
    while(cur!=x)
{
    if(cur+temp<=x)
{  cur+=temp; }
else
{  cur-=temp; }
++temp;
++min;
}
}
else
{
    while(cur!=x)
{
if(cur+temp>=x)
{cur-=temp;}
else
{cur+=temp;}
++temp;
++min;
}
}
printf("%ld",min);
return 0;
}


/* Coached by rainboy */
#include <stdio.h>

int lines(int n, int k) {
	return n == 0 ? 0 : lines(n / k, k) + n;
}

int binsearch(int n, int k) {
	int lower, upper, v;

	lower = 0, upper = n;
	while (upper - lower > 1) {
		v = (low + high) / 2;
		if (lines(v, k) < n)
			lower = v;
		else
			upper = v;
	}
	return upper;
}

int main() {
	int n, k;

	scanf("%d%d", &n, &k);
	printf("%d\n", binsearch(n, k));
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    long long int i,j,k,l,m,n;
    scanf("%lld%lld",&n,&m);
    l=m;
    while(1)
    {
        j=l%m;
        if(j!=0){
        if((l/m)==(n/j)&&(n%j==0)) break;
        else
        l++;
        }
        else l++;
    }
    printf("%lld",l);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int x,t;
    for(int i=k-1;i>0;i++){
        if (n%i==0){
            t=i;
            break;
        }
    }
    x=k*n/t+t;
    printf("%d",x);
    return 0;
}


#include <stdio.h>

#define NO_VAL -2
#define IMPOS -100

int r[4010];
int n,a,b,c;

int max(int x, int y) {
    if (x > y) return x;
    return y;
}

int cal(int x) {
    // base case
    if (x < 0) return IMPOS;
    // check cache
    if (r[x] != NO_VAL) {return r[x];}
    int ret = max(cal(x-a), cal(x-b));
    ret = max(ret, cal(x-c));
    if (ret == IMPOS) ret = IMPOS;
    else ret++;
    //if (x == 0) printf("%d_", ret);
    r[x] = ret;
    return ret;
}

int main() {
    int i;
    scanf("%d %d %d %d", &n, &a, &b, &c);
    int min = a;
    if (b < min) min = b;
    if (c < min) min = c;
    for (i=0;i<=n;i++) {
        r[i] = NO_VAL;
    }
    r[a] = 1;
    r[b] = 1;
    r[c] = 1;
    for (i=min;i<=n;i++) {
        if (r[i] != NO_VAL) {
            r[i+a] = max(r[i+a], r[i]+1);
            r[i+b] = max(r[i+b], r[i]+1);
            r[i+c] = max(r[i+c], r[i]+1);
        }
    }
    printf("%d\n", r[n]);

    return 0;
}


#include <stdio.h>

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

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

		int i = 0, result = 1, M = m;
		while (i < n){
				if (arr[i] <= M)
						M -= arr[i++];
				else{
						result++;
						M = m;
				}
		}

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

		return 0;
}


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

int m;

long solve(int n)
{
    if(n == 0) return 0;
    return (3 * solve(n - 1) + 2) % m;
}

int main()
{
        int n;
        scanf("%d %d", &n, &m);
    printf("%ld", solve(n));
    return 0;
}


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

typedef struct{

    int n_of_matches;
    int n_matchbox;

}container;

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

int main(void) {

    int n, m, cnt = 0, sum = 0;
    scanf("%d %d", &n, &m);

    container arr[m];

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

    qsort(arr, m, sizeof(container), cmpfunc);

    if(n == 0){
        printf("0");
        return 0;
    }

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

        for(int j = 0; j < arr[i].n_matchbox; j++){
            sum += arr[i].n_of_matches;
            cnt++;

            if(cnt == n){
                printf("%d", sum);
                return 0;
            }
        }
    }

    printf("%d", sum);


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

#define M 200000000

int aa[M], bb[M];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return bb[j] - bb[i];
}

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

int main() {
	static int ii[M];
	int n, m, i, x, cnt;

	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &aa[i], &bb[i]);
		ii[i] = i;
	}
	qsort(ii, m, sizeof *ii, compare);
	cnt = 0;
	for (i = 0; i < m && n > 0; i++) {
		x = min(aa[ii[i]], n);
		cnt += (x * bb[ii[i]]);
		n -= x;
	}
	printf("%d\n", cnt);
	return 0;
}


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

int main(){
int n,k,t,i=1,stand=0;

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

for (i;i<=t;i++){
	if (i<=k){
 	stand++;
 }
 	if (i>n){
 		stand--;
	 }
}
printf("%d",stand);
return 0;
}


#include<iostream>
using namespace std;
int main(){
	long int n, k, t;
	cin>>n>>k>>t;
	if(t<=k){
		cout<<t<<endl;
	}
	if(t>k && t<=n){
		cout<<k<<endl;
	}
	if(t>n){
		cout<<k-(t-n)<<endl;
	}
	return 0;
}


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

int requires_substitute(char string[], int index1, int index2) {
    if (index1 != 0 && index2 != 0) return 0;
    if (index1 == 1 || index2 == 1) {
        if (string[2] == '0') return 1;
    } if (string[1] == '0') return 1;
}
int requires_substitute_fifty(char string[], int index1, int index2) {
    if (index1 == 0 && index2 != 1 && string[1] == '0') return 1;
    else return 0;
}
int substitute(char string[], int index1, int index2, int size) {
    int res = -1;
    for (int i = 0; i < size; i++) {
        if (i != index1 && i != index2 && string[i] != '0') {
            res = i;
            break;
        }
    }
    return res;
}

int main() {
    char string[20];
    scanf("%s", string);
    int nums[5];
    for (int i = 0; i < 5; i++) {
        nums[i] = -1;
    }
    int switchZero = 1;
    int size = strlen(string);
    for (int i = 0; i < size; i++) {
        if (string[i] == '2') {
            nums[0] = i;
        } else if (string[i] == '5') {
            nums[1] = i;
        } else if (string[i] == '7') {
            nums[2] = i;
        } else if (string [i] = '0') {
            if (switchZero) {
                nums[3] = i;
                switchZero = 0;
            } else {
                nums[4] = i;
                switchZero = 1;
            }
        }
    }

    if (nums[3] > nums[4]) {
        int tmp = nums[3];
        nums[3] = nums[4];
        nums[4] = tmp;
    }
    int steps[4];
    for (int i = 0; i < 4; i++)
        steps[i] = -1;
    if (nums[1] != -1) {
        if (nums[0] != -1) {
            int step_count = 0;
            if (size > 2 && requires_substitute(string, nums[1], nums[0])) {
                int sub = substitute(strimg, nums[1], nums[0], size);
                if (sub != -1) {
                    step_count += sub;
                }
            }
            if (nums[1] < nums[0]) {
                step_count ++;
            }
            step_count += size - nums[1] - 1;
            step_count += size - nums[0] - 2;
            steps[0] = step_count;
        } if (nums[2] != -1) {
            int step_count = 0;
            if (size > 2 && requires_substitute(string, nums[1], nums[2])) {
                int sub = substitute(strimg, nums[1], nums[2], size);
                if (sub != -1) {
                    step_count += sub;
                }
            }
            if (nums[1] < nums[2]) {
                step_count ++;
            }
            step_count += size - nums[1] - 1;
            step_count += size - nums[2] - 2;
            steps[1] = step_count;
        } if (nums[4] != -1) {
            int step_count = 0;
            if (size > 2 && requires_substitute_fifty(string, nums[1], nums[4])) {
                int sub = substitute(strimg, nums[1], nums[4], size);
                if (sub != -1) {
                    step_count += sub;
                }
            }
            if (nums[1] < nums[4]) {
                step_count ++;
            }
            step_count += size - nums[1] - 1;
            step_count += size - nums[4] - 2;
            steps[2] = step_count;
        }
    } if (nums[3] != -1 && nums[4] != -1) {
        int step_count = 0;
        step_count += size - nums[1] - 1;
        step_count += size - nums[4] - 2;
        steps[3] = step_count;
    }
    int min = -1;
    for (int i = 0; i < 4; i ++) {
        if (steps[i] != -1) {
            if (min == -1 || steps[i] < min) {
                min = steps[i];
            }
        }
    }
    printf("%d", min);
}


#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define max(a,b)((a<b)?(b):(a))
#define min(a,b)((b<a)?(b):(a))
#define dif(a,b)(max(a,b)-min(a,b))
#define rep(i,b) int i; for(i=0;i<b;i++)
#define repi(i,a,b) int i; for(i=a;i<b;i++)

int main(){

/*
int r1 = 3;
int r2 = 7;
int c1 = 4;
int c2 = 6;
int d1 = 5;
int d2 = 5;
*/

/*
int r1 = 11;
int r2 = 10;
int c1 = 13;
int c2 = 8;
int d1 = 5;
int d2 = 16;
*/
/*
int r1 = 1;
int r2 = 2;
int c1 = 3;
int c2 = 4;
int d1 = 5;
int d2 = 6;
*/
/*
int r1 = 10;
int r2 = 10;
int c1 = 10;
int c2 = 10;
int d1 = 10;
int d2 = 10;
*/
/*
int r1 = 5;
int r2 = 13;
int c1 = 8;
int c2 = 10;
int d1 = 11;
int d2 = 7;
*/
int r1, r2, c1, c2, d1, d2; while( scanf("%d%d%d%d%d%d",&r1,&r2,&c1,&c2,&d1,&d2) )
{

int f = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0;
repi(n,1,10)
{
        int pri = dif(n,d1);
        int seg = dif(n,c2);
        int ter = dif(n,r2);
        int qua = n;

     if( ((pri!=seg) && (pri!=ter) && (pri!=qua) &&
         (seg!=ter) && (seg!=qua) &&
         (ter!=qua)) )
         {

        if( ((pri+seg)==r1) && ((ter+qua)==r2) && ((pri+ter)==c1) && ((qua+seg)==c2) && ((ter+seg)==d2) && ((pri+qua)==d1) )
        {
                /*printf("------\n");
                printf( "%d | %d\n", pri, seg );
                printf("------\n");
                printf( "%d | %d\n", ter, qua );
                printf("------\n");*/
                p1 = pri, p2 = seg, p3 = ter, p4 = qua;
                f++;
        }
         }

}

if(f)
{
    printf("%d %d\n%d %d\n", p1, p2, p3, p4 );
}else{
    printf("%d\n",-1);
}

}
return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
        char s[100];
        int i,j,k;
        int count;

        scanf("%s",s);

        for(i=0;i<strlen(s);)
        {
                count=0;
                if(s[i]=='/')
                {
                    printf("/");
                    for(j=i+1;j<strlen(s);j++)
                    {
                        if(s[j]=='/')
                        {
                            count++;
                        }

                        else
                        {
                             i=i+count+1;
                             break;
                        }
                    }
                }
                else
                    {
                        printf("%c",s[i]);
                        i++;
                    }
        }

        return 0;
}


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


#include <stdio.h>

int main()
{
	int n, m, k, h, l, r;

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

	l = r = k;

	h = 1;
	m -= n;

	while (m - (r - l + 1) >= 0) {
		h++;
		m -= r - l + 1;
		if (r < n)
			r++;
		if (l > 1)
			l--;
	}

	printf("%d", h);

	return 0;
}


//#include <graphics.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#define PI 3.14159
#define maxx 640
#define maxy 480
main()
{int i;
 char c;
 init();
 draw();
 c=getch();
}

init()
/*��ʼ��ͼ��ϵͳ����*/
{int gdriver=DETECT,gmode;
 initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); /*ע��˴���·��*/
 setbkcolor(1);
 sky();
 return;
}
sky()
{int x,y,i;
 for(i=1;i<=500;i++)
  {x=rand()%640;y=rand()%300;
   putpixel(x,y,15);
   putpixel(x+1,y,15);
  }
 for(i=1;i<=200;i++)
  {x=rand()%640;y=300+rand()%100;
   putpixel(x,y,15);
  }
return;
}

draw()
{int i,j,k,x,y,dy;
 setfillstyle(1,7);
for(i=1;i<=10;i++)
 {setlinestyle(3,0,3);
  x=100+rand()%400;dy=20+rand()%20;
  for(k=1000;k>=500;k-=100)
   {sound(k);delay(3000);}
  nosound();
  for(j=1;j<=10;j++)
   {setcolor(i%16);
    line(x,maxy-(j-1)*dy,x,maxy-j*dy);
    delay(10000);
    setcolor(0);
    line(x,maxy-(j-1)*dy,x,maxy-j*dy);
   }
  for(k=6000;k>=3000;k-=100)
    {sound(k);delay(20000);}
  nosound();
  setlinestyle(3,0,2);
  drawellipse(x,maxy-(j-1)*dy);
 }
return;
}

drawellipse(int x,int y)
{int i,j,x1,y1,a,b;
 float q;
 a=60+rand()%60;b=a-rand()%60;
 for(i=2;i>=0;i--)
 {
 for(q=0;q<=2*PI;q+=0.12)
  {setcolor(rand()%16);
   x1=x+(a-i*30)*cos(q);
   y1=y-(b-i*30)*sin(q);
   line(x,y,x1,y1);
  }
 delay(50000);
 setcolor(0);
  for(q=0;q<=2*PI;q+=0.12)
  {x1=x+(a-i*30)*cos(q);
   y1=y-(b-i*30)*sin(q);
   line(x,y,x1,y1);
  }
 }
 return;
}


#include<stdio.h>
int main()
{
	long n,ans = 4;
	scanf("%ld",&n);
	for(int i = 2;i<=n;i++)
	{
		if(i % 2 != 0) ans *= 2;
		else ans += 4;
	}
	if(n == 0) puts("1\n");
	else printf("%ld\n",ans);
	return 0;
}


#include<stdio.h>
int main() {
	int n,k;
	scanf("%d%d",&n,&k);
	int v=(k-1)*n/k;
	int result=v;
	//printf("v=%d\n",v);
	while(1){
		int sum=0;
		int kk=1;
		while(1){
			if(v<kk)break;
			sum+=(v/kk);
			kk*=k;
		}
		//printf("sum=%d\n",sum);
		if(sum>=n){
			result=v;
			break;
		}
		v++;
	}
	printf("%d\n",result);
	return 0;
}


#include <stdio.h>
int main()
{
   char input[101];
   char s[101];
   short i= 0 , j = 1;

   fgets(input,100,stdin);
   s[0]='.';

   while(input[i])
   {
   if(input[i] != 'a' && input[i] != 'o' && input[i] != 'y'&& input[i] != 'e' && input[i] != 'u'
    && input[i] != 'i' && input[i] != 'A' && input[i] != 'O' && input[i] != 'Y' && input[i] != 'U'&&input[i] != 'I')
    {
   s[j++] = tolower(input[i]);
   s[j++] = '.';
   }
   i++;
   }
   for(i=0 ; i< j-3 ; i++)
   printf("%c",s[i]);

    return 0;
}


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

int main()
{
    char a[102];
    int i,perl=0,len,link;
    scanf("%s",&a);
    len=strlen(a);

    for(i=0;i<len;i++)
    {
        if(a[i]=='o')
            perl++;
    }
    link=len-perl;
    if(link==0 || perl==0) printf("YES");
    else if(perl>0 && link%perl==0)  printf("YES");
    else
        printf("NO");


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

int main() {
   char a[100];
    scanf("%s",a);
    int i=0;
    int b=0;
    int c=0;
    while(a[i]!='\0')
    {
    if(a[i]=='-')
            b++;
    else
            c++;
            i++;   }
  if(c>=0)     {
     if(b%c==0)
        printf("YES");
    else
        printf("NO");
}
else
    printf("NO");
}