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

int main()
{
    char s[11], letter;
    gets(s);
    int i = 0, len = strlen(s), forward = 0, backward = len-1, once = 0, f = -1, pos = 0;
    for(i = 0; i < len/2; i++)
    {
        if(s[forward] != s[backward])
        {
            if(once == 1)
            {
                printf("NA");
                exit(0);
            }
            once = 1;
            if(s[forward] == s[backward-1])
            {
                letter = s[backward];
                f = 1;
                pos = forward;
                forward--;
            }
            else if(s[forward+1] == s[backward])
            {
                f = 0;
                letter = s[forward];
                pos = backward;
                backward++;
            }
            else
            {
                printf("NA");
                exit(0);
            }
        }
        forward++; backward--;
    }
    if(f == 0)
    {
        for(i = 0; i <= pos; i++)
            printf("%c", s[i]);
        printf("%c", letter);
        for(i = pos+1; i < len; i++)
            printf("%c", s[i]);
    }
    else if(f == 1)
    {
        for(i = 0; i < pos; i++)
            printf("%c", s[i]);
        printf("%c", letter);
        for(i = pos; i < len; i++)
            printf("%c", s[i]);
    }
    else
    {
        if(len % 2 == 0)
        {
            for(i = 0; i < len/2; i++)
                printf("%c", s[i]);
            printf("%c", 'a');
            for(i = len/2; i < len; i++)
                printf("%c", s[i]);
        }
        else
        {
            for(i = 0; i <= len/2; i++)
                printf("%c", s[i]);
            for(i = len/2; i < len; i++)
                printf("%c", s[i]);
        }
    }


#include <stdio.h>

int main()

{
    int a , n;
    scanf("%d %d", &n, &a);
    if (a % 2 != 0 )
    {
        printf("%d",(a /2 )-1);
    }
    else
    {
        printf("%d",(n-a)/2 +1);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
int main() {
	double n, k;
	scanf("%f %f", &n, &k);
	double a = (2 * n + 3 - ceil(sqrt(8 * n + 8 * k + 9))) / 2;
	printf("%d", int(a));
}


#include<stdio.h>
int main(void)
{
    int n,m,v;
    long long k;
    while(scanf("%d",&n)!=EOF)
    {
        m=1;
        v=0;
        scanf("%d",&k);
        if
        do
        {
        if(k%2)
        {printf("%d\n",m);v=1;}
        else
        {k=k/2;m=m+1;}
        }
        while(v==0);
    }
    return 0;
}


include <stdio.h>
int main()
{
	int a,b, c=1;
	scanf("%d %d",&a,&b);
	while(a>=0&&b>=0)
	{
	    a-= c++;
	    b-=c++;
	}
	if(a<0)
	  printf("Vladik");
	else
	  printf("Valera");
	return 0;
}


#include <stdio.h>

int main()
{
	long long int d1, d2, d3, min;

	scanf("%lld %lld %lld", &d1, &d2, &d3);

	min= d1+d2+d3 < (d1+d2)*2 ? d1+d2+d3:(d1+d2)*2;
	min= min < (d2+d3)*2 ? min:(d2+d3)*2;
	min= min<(d1+d3)*2 : min:(d1+d3)*2;

	printf("%lld", min);

	return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    int m,n,i,j,k;
    scanf("%d",&m);
    k=5*m;
    int sum;
    for (i=k; i>=5 ; i-=5)
    {
        sum=0;
        for (j=5; j<=i ;  j*=5)
        {
            sum=sum+ (i/j);
        }
        if (sum<m)
        {
            printf("0");
            break ;
        }
        else if (sum==m)
        {
            if (i<=k)
            {
                printf("5 \n%d %d %d %d %d",i,i+1,i+2,i+3,i+4);
                break ;
            }
        }
    }
    if (m==0){
       printf("4\n1 2 3 4");
    }
    return 0;
}


#include <stdio.h>
int main()
{
     int a,b,c;
     scanf("%d %d %d",&a,&b,&c);
     int i,k,j,l;
     i=sqrt(a*b*c);
     k=i/a;
     j=i/b;
     l=i/c;
     ans=4*(k+j+l);
     printf("%d",ans);
}


#include<stdio.h>
int main()
{
    int c,vo,v,a,l,i=0,m=0;
    scanf("%d%d%d%d%d",&c,&vo,&v,&a,&l);
    while(c>0)
    {
        if(m<v)
        m=vo+i*a-i*l;
        c=c-m;
        i++;
    }
    printf("%d\n"i);
}


# include <stdio.h>
int main()
{
int a,b,c,time=0,r,max;
scanf("%d %d %d",&a,&b,&c);
if (a>b && a>c)
{
 max=a;
}
else if(b>a && b>c)
{
    max=b;
}
else
{
    max=c;
}
int r=(a+b+c)-max;
while(max>=r)
{
    r=r+1;
    time=time+1;
}
printf("%d",time)
}


#include<stdio.h>
#include<string.h>
#define Min(a,b) a>b?b:a
int main()
{
    int Money,ID[5][5],i,j,a,b;
    while(scanf("%d",&Money)!=EOF)
    {
        for(i=1;i<=4;i++)
            for(j=1;j<=4;j++)
                scanf("%d",&ID[i][j]);
        for(i=1;i<=4;i++)
        {
            a=Min(ID[i][1],ID[i][2]);
            b=Min(ID[i][3],ID[i][4]);
            if(a+b>Money&&i==4){printf("-1\n");break;}
            if(a+b>Money)continue;
            else
            {printf("%d %d %d\n",i,a,Money-a);break;}
        }

    }
	return 0;
}


#include <stdio.h>
int main() {
	int n,min1,min2,min3,max1,max2,max3, left = 0, first = 0, second = 0, third = 0;
	scanf("%d",&n);
	scanf("%d",&min1);
	scanf("%d",&max1);
	scanf("%d",&min2);
	scanf("%d",&max2);
	scanf("%d",&min3);
	scanf("%d",&max3);
	left = n;
	first = min1;second = min2;third = min3;
	while(first < (left -(min2+min3)) && first <= max1) first++;
	left -= first;
	while(second < (left -min3) second <= max2) second++;
	left -= second;
	while(third < left && third <= max3) third++;

	printf("%d %d %d\n", first, second, third);
	return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
     long long int n,k,l,mod;
     scanf("%I64d",&n);
      double i,j;
     i=(double)sqrt(n);
     if(i*i==n)
     {
          j=i-1;;
     }
     else
     j=i;
          while(j>0)
          {
               mod=j%10;
               k+=mod;
               j/=10;
          }
          if(i*i+k*i==n)
          printf("%I64d",i);
          else
          printf("-1");

}


#include<stdio.h>
long long int gcd_func(long long int a, long long int b)
{
	long long int t;
	while(b!=0)
	{
		t=b;
		b=a%b;
		a=t;
	}
	return a;
}
int main()
{
	long long int t, w, b, temp;
	scanf("%lld %lld %lld", &t, &w, &b);
	if(w==b)
	{
		printf("1/1\n");
		return 0;
	}
	if(w>b)
	{
		temp = w;
		w = b;
		b = temp;
	}
	long long int gcd = gcd_func(b, w), numer=w-1, denom=t, lcm;
	lcm = w/gcd;
	if(lcm<=t/b)
	{
		lcm = lcm*b;
		temp = t/lcm;
		numer += ((temp-1)*w);
		temp = temp*lcm;
		if(temp+w-1<=t)
			numer += w;
		else
			numer += (t-temp+1);
	}
	if(numer == 0)
	{
		printf("0/1\n");
		return 0;
	}
	gcd = gcd_func(denom, numer);
	numer /= gcd;
	denom /= gcd;
	if(numer>denom)
		printf("1/1\n");
	else
		printf("%lld/%lld\n", numer, denom);
	return 0;
}


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

int oeration(int , int );

int main()
{
    int a , b ;
    int op ;
    scanf("%d %d",&a,&b);

    op=operation(a,b);

    printf("%d\n",op)

    return 0;
}

int oeration(int a, int b)
{
        int op=0 ;
        int a1=-1 , a2=-1;
        if(a==b)
        {
            return 0;
        }
        while(a!=b)
        {
            if(a>b)
            {
                if(!(a%2))
                {
                    a/=2;
                    op++;
                }
                else if(!(a%3))
                {
                    a/=3;
                    op++;
                }
                else if(!(a%5))
                {
                    a/=5;
                    op++;
                }
                else
                {
                    a1=1;
                }
            }
            if(a<b)
            {
                if(!(b%2))
                {
                    b/=2;
                    op++;
                }
                else if(!(b%3))
                {
                    b/=3;
                    op++;
                }
                else if(!(b%5))
                {
                    b/=5;
                    op++;
                }
                else
                {
                    a2=1;
                }
            }
            if(a1==1 && a2==1 && a!=b)
            {
                return -1 ;
            }
        }
        return op ;
}


#include<stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    int m, c[100], contador = 0, qwerty = 0, a, b, i;
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
        scanf("%d", &c[i]);
        qwerty = qwerty + c[i];
    }
    scanf("%d %d", &a, &b);
    for (i = 0; i < m; i++) {
        contador = contador + c[i];
        if (contador >= a && contador <= b) {
            if ((qwerty - contador) >= x && (qwerty - contador) <= y) {
                printf("%d", i + 2);
                return 0;
            }
        }
    }
    printf("0");
    return 0;
}


#include <stdio.h>

int main(void) {
	int a, dlen, b;
	char d[101];

	scanf("%d.", &a);
	scanf("%[^e]%ne%d", d, &dlen, &b);

	if (dlen == 1 && d[0] == '0' && b == 0)
		printf("%d\n", a);
	else
		if (b >= dlen)
			printf("%d%s%0.*d\n", a, d, b - dlen, 0);
		else
			printf("%d%.*s.%s\n", a, b, d, d + b);

	return 0;
}


int main()
{
    typedef vector <int> v_int;
    vector <v_int> light_on(3 + 2, v_int(3 + 2, true));

    for(int row = 1; row <= 3; row++)
    {
        for(int column = 1; column <= 3; column++)
        {
            int no_of_toggles;
            scanf("%d", &no_of_toggles);

            if(no_of_toggles%2 == 1)
            {
                toggle(light_on[row][column]);

                toggle(light_on[row][column - 1]);
                toggle(light_on[row][column + 1]);
                toggle(light_on[row + 1][column]);
                toggle(light_on[row - 1][column]);
            }
        }
    }

    for(int row = 1; row <= 3; row++)
    {
        for(int column = 1; column <= 3; column++)
        {
            if(light_on[row][column])
                printf("1");
            else
                printf("0");
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,sum=0,dg;
    scanf("%d",&n);
    int x=n;
    for(i=2;i<x11;i++)
    {
        n=x;
        while(n>=i)
        {
            sum+=n%i;
            n/=i;
        }
        sum+=n;
    }
    printf("%d/%d",sum,x-2);
    return 0;
}


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

    }
    return 0;
}


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

int a , b ,c,r,m;
bool ok(int m){
    if (b*m+b*c>=a*c) return 1;
    else return 0;
}
int main()
{
    // a is l
    // b is f
    scanf("%i%i%i",&a,&b,&c);
    while(a>b){
        m=(b+a)/2;
        if(ok(m)) b=m;
        else    a=m-1;
        }
    printf("%i",b);
    return 0;
}


#include<stdio.h>
int mod=1000000007;
int dp[2001][2001];
int f(int n,int k);
int upd[2001][2001]
int uf(int n,int k)
{
	if(udp[n][k]==0)
		return udp[n][k];
	else
	return f(n,k)-f(n-1,k);
}
int f(int n,int k)
{

	if(dp[n][k]!=0)
	{
		return dp[n][k];
	}

	if(n==1)
		dp[n][k]=1;
	else if(k==1)
		dp[n][k]=n;
	else{
	int i,p=0,j=0;
	int div;
	for(i=n/2;i>=0;i--)
	{
		if(n%i==0)
		{
			div=i;
			break;
		}
	}
	int non[div];
	for(i=2;i<div;i++)
	{
		if((n%i)!=0)
		{
			non[p]=i;
			p++;
		}
	}
	int c=0;
	int b=0;
	for(i=1;i<k;i++)
	{
		for(j=0;j<p;j++)
		{
			c=(c%mod + (uf(non[j],k-i))%mod)%mod;
		}

		b=(b%mod+(f(div,k-i))%mod-c)%mod;
	}

	dp[n][k]=((f(n-1,k))%mod+b%mod+1)%mod;
	}
	return dp[n][k];

}

int main()
{
	int n,k,div,i;
	scanf("%d%d",&n,&k);
	printf("%d\n",f(n,k));
/*	for(i=n/2+1;i>=0;i--)
	{
		if(n%i==0)
		{
			div=i;
			break;
		}
	}
	printf("%d",div);*/
	return 0;
}


#include<stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	if(n & 01) printf("contest")
	else printf("home");
	return 0;
}


#include<stdio.h>
int main(){
int i,j,n1,n2;
scanf("%d",&n1);
scanf("%d",&n2);
for(i = 1 ;i <= n1 ; i++ ){
    for(j = 1;j <= n1; j++){
        if(i*j == n2){
            sum = sum + 1;
        }
        else

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


#include<stdio.h>
#include<string.h>
int main()
{
    char s[50];
    int i=0,l,c=0,c1=0;
    scanf("%s",s);
    l=strlen(s);
    for(i=0;i<l/2;i++)
    {
        if(s[0]==s[i])
            c1++;
    }
    switch(c1)
    {
        case l:printf("0");
            break;
    }
    for(i=0;i<l/2;i++)
    {
        if(s[i]==s[l-i-1]);
        else
            c++;
    }
    if(c==0)
        printf("%d",l-1);
    else
        printf("%d",l);
    return 0;
}


#include<stdio.h>
long long int min(long long int a,long long int b)
{
    if(a<b)
        return a;
    else
        return b;
}
int main()
{
    long long int a,b,i,j,c,n,a1,a2,a3,a4,a5,a6,a7,a8,a9;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
    j=n%4;
    if(n%4==0)
        printf("0");
    else if((n+1)%4==0)
        {
            a1=3*c;
            a2=b+c;
            j=min(a1,a2);
            j=min(j,a);
            printf("%lld",j);
        }
    else if((n+2)%4==0)
        {
            a1=2*a;
            a2=2*c;
            j=min(a1,a2);
            j=min(j,b);
            printf("%lld",j);
        }
    else
        {
            a1=a+b;
            a2=3*a;
            a3=2*b+c;
            j=min(a1,a2);
            i=min(a2,a3);
            j=min(i.j);
            printf("%lld",j);
        }

    return 0;
}


#include <cstdio>
#include <cstring>

char keyboard[100] = "qwertyuiopasdfghjkl;zxcvbnm,./";

int main()
{
    char way[2];
    scanf("%s", way);

    char input[120];
    scanf("%s", input);

    if(way[0] == 'L')
    {
        for(int i = 0; i < strlen(input); i++)
        {
            for(int j = 0; j < strlen(keyboard); j++)
            {
                if(input[i] == keyboard[j])
                {
                    printf("%c", keyboard[j + 1]);
                    break;
                }
            }
        }
        printf("\n");
    }
    else
    {
        for(int i = 0; i < strlen(input); i++)
        {
            for(int j = 0; j < strlen(keyboard); j++)
            {
                if(input[i] == keyboard[j])
                {
                    printf("%c", keyboard[j - 1]);
                    break;
                }
            }
        }
        printf("\n");
    }

    return 0;
}


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

int main(int argc, char* argv) {
	int n, counter = 0;
	scanf_s("%d", &n);
	char* k = (char*)malloc(n * sizeof(char));
	for (int i = 0; i <= n; i++) {
		k[i] = getchar();
	}
	{
		for (int i = 0; i <= n - 1; i++) {
			if ((k[i] == 'S') && (k[i + 1] == 'F')) {
				counter++;
			}
			else if ((k[i] == 'F') && (k[i + 1] == 'S')) {
				counter--;
			}
		}
	}
	if (counter > 0) {
		printf("YES");
	}
	else {
		printf("NO");
	}
}


#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
string s , sl;
long long n , l , r , ans;
long long dfs(long long num) {
    if(num == 1) {
        return 1;
    }
    return 1 + 2 * dfs(num / 2);
}
void binsearch(long long le , long long ri , long long num) {
    long long mid = (le + ri) >> 1;
    if(ri < l || le > r || le > ri)
        return ;
    if(mid < l) {
        binsearch(mid + 1 , ri , num / 2);
    }
    else if(mid > r) {
        binsearch(le , mid - 1 , num / 2);
    }
    else {
        ans += num % 2;
        binsearch(le , mid - 1 , num / 2);
        binsearch(mid + 1 , ri , num / 2);
    }
}
int main() {
    cin >> n >> l >> r;
    if(n == 0) {
        cout << 0 << endl;
        return 0;
    }
    long long count = dfs(n);
    binsearch(1 , count , n);
    cout << ans << endl;
    return 0;
}


#include<stdio.h>

int main(){

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

    if(n%2==0){
        printf("Mahmoud");
    }

    else(n%2){
        printf("Ebab");
    }

    return 0;

}


#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,n,m,a,b;
    while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		if(4*a+2*b<=n) t=1;
	    else if(2*a+b<=n) t=2;
	    else if(4*a<=n||(2*a<=n&&2*b<=n)||(2*a<=n&&a+b<=n)) t=3;
	    else if(a+b<=n||2*a<=n) t=4;
	    else if(2*b<=n) t=5;
	    else  t=6;
	    printf("%d",t);

		}
	}


#include <iostream>
#include <algorithm>
#include <vector>

int deleteDuplicates(std::vector<int> v, int n);

int main()
{
    int n = 0;
    std::cin >> n;
    std::vector<int> vec;
    for (int a = 0; a < n; a++)
    {
        int b = 0;
        std::cin >> b;
        vec.push_back(b);
    }
    std::sort(vec.begin(), vec.end());
    int m = deleteDuplicates(vec, n);
    int l = vec[0] == 0 ? m - 1 : m;
    std::cout << l << std::endl;
}

int deleteDuplicates(std::vector<int> v, int n)
{
    if (n==0 || n==1)
        return n;
    std::vector<int> temp;
    int j = 0;
    for (int i=0; i<n-1; i++)
        if (v[i] != v[i+1])
        {
            temp.push_back(v[i]);
            j++;
        }
    temp.push_back(v[n-1]);
    j++;
    for (int i=0; i<j; i++)
        v[i] = temp[i];
    return j;
}


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

int main(void)
{
    int x,y, rad;

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

    rad=(int)sqrt(x*x + y*y)
    if(rad%2 && x*y>0)
        printf("white");
    else
        printf("black");
    return 0;
}


#include <stdio.h>

using namespace std;

int main(){
    long long x;
    int t=0,ans=0;
    while(~scanf("%lld",&x)){
        x=x<0?-x:x;
        while(t<x || (t-x)%2 ){
            ans++;
            t+=ans;
        }
        printf("%d\n",ans);
    }
    return 0;
}


 #include<stdio.h>
int main()
{
    int n,d=0,sum;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    int swapped;
    for (int i = 0; i < n-1; i++)
    {
      swapped = 0;
      for (int j = 0; j < n-i-1; j++)
      {
         if (arr[j] > arr[j+1])
         {
            int swap=arr[j+1];
            a[j+1]=a[j];
            a[j]=swap;
            swapped = 1;
         }
      }
      if (swapped == 0)
         break;
    }
    for(int i=1;i<n;i+=2)
        d+=(arr[i]-arr[i-1]);
    printf("%d",d);
}


#include <stdio.h>
#define p(x) printf("%c",x);
int i=0;
char a[11],b[11];
int main()
{
scanf("%s %s",a,b);
while(a[i])
{
if(a[i]<=b[0])
p(a[i]);
else
break;
i++;
}
printf("%c\n",b[0]);
return 0;
}


#include<stdio.h>
int main()
{
    int j,d,sumtime,summax=0,summin=0,mintime[30],maxtime[30],i;
    scanf("%d%d",&d,&sumtime);
    for(i=0;i<d;++i)
    {scanf("%d%d",&mintime[i],&maxtime[i]);
     summin+=mintime[i];
     summax+=maxtime[i];
    }
    if((summin<=sumtime)&&(sumtime<=summax))
    {
        printf("YES\n");
        for(i=0;i<d;++i)
        {
            for(j=mintime[i];j<=maxtime[i];++j)
            {
                if(((summin-mintime[i])<=sumtime-j))&&(sumtime-j<=(summax-maxtime[i])))
                {
                    printf("%d ",j);
                    sumtime-=j;
                    break;
                }
            }
        }
    }
    else
    {
        printf("NO");
    }
}


#include<stdio.h>
int main()
{
int i,j,n,m=0;
scanf("%d",&n);
int arr[n];
	for(i=0;i<n;i++)
	{
    	scanf("%d",&arr[i]);
	}
	if (n==1)
	{
		printf("1");
	}
	else
	{
		for(i=0;i<n;i++)
		{
			count=0;
    		for(j=i+1;j<n;j++)
    		{
				if(arr[i]==arr[j])
            	{
                	count++;
        		}
        		if (count>m)
        		{
        			m=count;
        		}
        	}
		}
		printf("%d",max);
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int minimum(int x,int y)
{
    if(x>y)
        return y;
    else
        return x;
}
int main()
{
    int p1,p2,myc1,myc2,tyc;
    scanf("%d %d %d %d %d",&p1,&p2,&myc1,&myc2,&tyc);
    int max,min;
    min=tyc-((myc1-1)*p1+(myc2-1)*p2);
    if(min<0)
      {
          min=0;
      }
    printf("%d ",min);
    min=minimum(myc1,myc2);
    if(min==myc1)
    {
        max=minimum(tyc/myc1,p1);
        tyc-=max*myc1;
        max+=minimum(tyc/myc2,p2);
    }
    else
    {
        max=minimum(tyc/myc2,p2);
        tyc-=max*myc2;
        max+=minimum(tyc/myc1,p1);
    }
    printf("%d\n",max);

}


#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
 int h1, h2, a, b, day = 0;
 scanf("%d%d%d%d", &h1, &h2, &a, &b);
 h1 += a*8;
 if( h1>=h2 )
 printf("0\n");
 else
 {
 day++;
 while(1)
 {
 h1 -= b*12;
h1 += a*12;
 if( h1>=h2 )
{
 printf("%d\n", day);
 break;
 }
 if( b>=a )
 {
 printf("-1\n");
 break;
 }
 day++;
 }
 }
return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    while(1){
int l,i,j,position;
 char s[51],t[51];
 gets(s);
 gets(t);
 l=strlen(t);
 for(i=0,j=0;j<l;i++,j++){
    if(t[j]==s[i]){
        position=i+2;
    }
    else{
        i--;
    }
 }
 printf("%d\n",position);
    }

    return 0;
}


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

int main()
{
    int n;
    int i100,i20,i10,i5,i1;

    /* Initialize all notes to 0 */
     i100  = i20 = i10 = i5 = i1 = 0;
    //int  count=0;

    /* Input amount from user */

    scanf("%d", &n);
	if(n>=1&&n<=pow(10,9)

	{

    if(n >= i100)
    {
        i100 = n/100;
        n -= i100 * 100;
    }

    if(n >= 20)
    {
        i20 = n/20;
       n -= i20 * 20;
    }
    if(n >= 10)
    {
       i10 = n/10;
       n -= i10 * 10;
    }
    if(n >= 5)
    {
        i5 = n/5;
        n -= i5 * 5;
    }

    if(n >= 1)
    {
       i1 = n;
    }
}
    int count=i1=i5+i10+i20+i100;

    /* Print required notes */
    //printf("Total number of notes = \n");
  // printf("%d",&count);
  printf("%d",count);

    return 0;
}


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

int main() {
    int res = 0;
    int aux1, aux2;
    int k;
    int n;

    scanf("%d", &n);

    for (k = 1; aux1 <= n; k++) {
        aux1 = 0;
        aux2 = 0;
        aux1 = pow(2, k) - 1;
        aux2 = pow(2, k - 1);
        aux1 = aux1 * aux2;

        if (n % aux1 == 0)
            res = aux1;
    }

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

/* 1512149622788 */


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

char *substring(size_t start, size_t stop, const char *src, char *dst, size_t size);

int main(){
    int i, j;
    char vec[10][11];
    char dato[80];
    char parte[11];
    scanf("%d", dato);
    for ( i = 0; i < 2; i++ ){
        scanf("%s", vec[i] );
    }
    for( i = 0; i < 80; i = i + 10){
        substring( i, i + 11, dato, parte, sizeof parte);
        for ( j = 0; strcmp( parte, vec[ j ] ) == 0; j++);
        printf("%d", j);
        }
    }
    return(0);
}

char *substring(size_t start, size_t stop, const char *src, char *dst, size_t size)
{
   int count = stop - start;
   if ( count >= --size )
   {
      count = size;
   }
   sprintf(dst, "%.*s", count, src + start);
   return dst;
}


#include <stdio.h>

int
main(void)
{
  // value of number as you input it into initNumbers -->
  int num = 0;
  // length of your array will be -->
  int length = 0;

  scanf("%d", &length);

  int primes[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};

  int initNumbers[length];

  int divisors[length];

  int counter;

  for(int i = 0; i < length; i++)
  {
    scanf("%d",&num);
    initNumbers[i] = num;
  }
  int counter3 = 0;
  for(int i = 0; i < length; i++)
  {
    counter3+=1;
    for(int j = 0; j<25;j++)
      {
        for(int k = 0; k<counter3; k++)
        {
          counter = 0;
          if(divisors[k] == 0) continue;
          if(divisors[k] == 1) continue;
          if(initNumbers[i] % divisors[k] == 0)
          {
            divisors[i] = 0;
            counter=1;
            break;
          }
        }
        if (counter == 1) break;
        if(initNumbers[i] == 1)
        {
          divisors[i] = 1;
          break;
        }
        else if(initNumbers[i] % primes[j] == 0)
        {
          divisors[i] = primes[j];
          break;
        }

      }
  }

  printf("\n");
  for(int i = 0; i < length; i++)
  {
    printf("%d\n",divisors[i]);
  }
  printf("\n");

  int returnCounter = 0;
  for(int i = 0; i < length; i++)
  {
    if (divisors[i] == 0) continue;

    returnCounter +=1;
  }
printf("%d\n", returnCounter);
}


#include<stdio.h>

int main()
{
    int T, o = 0, k = 0;
    scanf("%d", &T); getchar();
    while(T--)
    {
        if(getchar() == '0') printf("%d", o), o = 0;
        else o++
    }
    printf("%d", o);
    return 0;
}


#include<stdio.h>
int main () {
	char a,i,j,k;
	scanf("%d",&a);
	k=a%10;
	j=f/10&10;
	if(a>0)
		printf("%d",a);
	else
	{
		if(k>j)
			printf("%d",a/100*10*k)
		else printf("%d",a/10)

	}
	return 0;
}


#include<stdio.h>
int main()
{
    char a[1000];
    scanf("%s",&a);
    int i,count,j,k,x,length=0;
    length=strlen(a);
    for(i=0;i<length;i++)
    {
        if(a[i]=='Q')
        {
            for(j=i+1;j<length;j++)
            {
                if(a[j]=='A')
                {
                    for(x=j+1,x<length;x++)
                    {
                        if(a[x]=='Q')
                        {
                            count++;
                        }
                    }
                }
            }
        }
    }
    printf("%d",count);
}


#include <stdio.h>

int main()
{
   int n,k,g,f=0;
   scanf("%d %d",&n,&k);
   int a[n];
   for (i=0;i<n;i++)
      scanf("%d",&a[i]);
   for (i=0;i<=n;i++)
     {
		if (a[i]<=k)
		   f++;
		else
	       break;
	 }
	 for (g=n-1;g>i;g--)
	{
		if (a[g]<=k)
		   f++;
	    else
	       break;
	}
	printf("%d",f);

	return 0;

}


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


#include <stdio.h>

int main() {

    int h,w,k,i,cells=0;
    scanf("%d%d%d",&w,&h,&k);
    for (i=1;i<=k;i++)
    {
        cells = cells + 2*(h+w) - 4;
        h=h-4;
        w=w-4;
    }
    printf("%d",cells);

	return 0;
}
→Judgement Protocol


|  In English  По-русски
1605069 | Logout

HOME
CONTESTS
GYM
PROBLEMSET
GROUPS
RATING
API
RCC
VK CUP
HFT BATTLE
CALENDAR

PROBLEMSSUBMITSTATUSSTANDINGSCUSTOM TEST
   friends only

Contest status

#	When	Who	Problem	Lang	Verdict	Time	Memory
29425650	2017-08-13 09:36:13	navjotsinghcheema	822C - Hacker, pack your bags!	GNU C++14	Running on test 1	0 ms	0 KB
29425649	2017-08-13 09:36:11	Kurlyk	45A - Codecraft III	GNU C++14	Running on test 1	0 ms	0 KB
29425648	2017-08-13 09:36:09	paul_zrm00:03	839C - Journey	GNU C++11	Running on test 25	0 ms	0 KB
29425646	2017-08-13 09:36:05	770780079	839D - Winter is here	GNU C++	Wrong answer on test 1	15 ms	2800 KB
29425645	2017-08-13 09:36:04	nsnarender	1A - Theatre Square	GNU C	Compilation error	0 ms	0 KB
29425644	2017-08-13 09:36:03	1605069	839A - Arya and Bran	GNU C	Wrong answer on test 8	15 ms	1900 KB
29425643	2017-08-13 09:36:01	lifeboat	839C - Journey	GNU C++14	Wrong answer on test 10	280 ms	9000 KB
29425642	2017-08-13 09:35:57	vssm2	832B - Petya and Exam	GNU C++14	Accepted	234 ms	2600 KB
29425641	2017-08-13 09:35:51	e33b54e94290cb09	839C - Journey	GNU C++	Accepted	436 ms	7200 KB
29425640	2017-08-13 09:35:50	aks12331	1A - Theatre Square	GNU C	Wrong answer on test 9	15 ms	1900 KB
29425639	2017-08-13 09:35:39	drjaat00:00	839A - Arya and Bran	Java 8	Accepted	124 ms	20400 KB
29425638	2017-08-13 09:35:39	akshaysharmagreek	839A - Arya and Bran	GNU C++11	Wrong answer on test 8	15 ms	2100 KB
29425636	2017-08-13 09:35:34	museop00:50	734C - Anton and Making Potions	GNU C++14	Wrong answer on test 8	202 ms	6100 KB
29425635	2017-08-13 09:35:33	wenbaobao	834C - The Meaningless Game	GNU C++14	Accepted	670 ms	51700 KB
29425634	2017-08-13 09:35:28	_macros: faraday__anshul, callias, sudoBug00:43	834B - The Festive Evening	GNU C++14	Accepted	15 ms	3900 KB
29425633	2017-08-13 09:35:26	goyaljai	388A - Fox and Box Accumulation	GNU C++14	Wrong answer on test 10	15 ms	1900 KB
29425632	2017-08-13 09:35:25	smirnov.i	839D - Winter is here	GNU C++14	Accepted	1216 ms	21500 KB
29425631	2017-08-13 09:35:24	prashantsingh	1A - Theatre Square	GNU C	Wrong answer on test 1	0 ms	1800 KB
29425630	2017-08-13 09:35:20	amir.om	71A - Way Too Long Words	GNU C++14	Wrong answer on test 1	30 ms	1900 KB
29425629	2017-08-13 09:35:09	TNam	814A - An abandoned sentiment from past	GNU C++11	Accepted	15 ms	2100 KB
29425625	2017-08-13 09:35:05	xxtz	839A - Arya and Bran	GNU C++	Accepted	15 ms	2100 KB
29425624	2017-08-13 09:35:03	saurabhklkr	1A - Theatre Square	GNU C	Compilation error	0 ms	0 KB
29425623	2017-08-13 09:35:00	lhclqslove	839C - Journey	GNU C++14	Wrong answer on test 4	15 ms	3300 KB
29425622	2017-08-13 09:34:59	King	588C - Duff and Weight Lifting	GNU C++14	Accepted	280 ms	6700 KB
29425621	2017-08-13 09:34:53	AKASHSANGWAN	1A - Theatre Square	GNU C	Wrong answer on test 9	15 ms	1900 KB
29425620	2017-08-13 09:34:51	paul_zrm00:03	839C - Journey	GNU C++14	Wrong answer on test 1	0 ms	3100 KB
29425619	2017-08-13 09:34:51	verma_7068	75C - Modified GCD	GNU C++14	Accepted	92 ms	2500 KB
29425617	2017-08-13 09:34:49	saloom00:05	839A - Arya and Bran	GNU C++14	Accepted	15 ms	1900 KB
29425616	2017-08-13 09:34:49	Innocent_Singh	1A - Theatre Square	GNU C	Wrong answer on test 9	15 ms	1900 KB
29425615	2017-08-13 09:34:48	interestingLSY	225C - Barcode	GNU C++	Wrong answer on test 3	30 ms	14000 KB
29425614	2017-08-13 09:34:46	Just_Solve_The_Problem	839C - Journey	GNU C++11	Wrong answer on test 4	15 ms	3600 KB
29425613	2017-08-13 09:34:44	manjubala	339A - Helpful Maths	PyPy 2	Accepted	124 ms	21400 KB
29425612	2017-08-13 09:34:44	tzr000	839C - Journey	GNU C++	Wrong answer on test 6	156 ms	5800 KB
29425611	2017-08-13 09:34:42	sexy_crazy01:36	839A - Arya and Bran	GNU C++14	Wrong answer on test 3	15 ms	1900 KB
29425609	2017-08-13 09:34:40	marioeid	738A - Interview with Oleg	GNU C++14	Wrong answer on test 2	15 ms	1900 KB
29425606	2017-08-13 09:34:28	King	588C - Duff and Weight Lifting	GNU C++14	Time limit exceeded on test 13	1000 ms	6700 KB
29425604	2017-08-13 09:34:25	kkw564	839C - Journey	GNU C++14	Accepted	78 ms	7100 KB
29425603	2017-08-13 09:34:21	paul_zrm00:03	839C - Journey	GNU C++	Runtime error on test 1	0 ms	3200 KB
29425601	2017-08-13 09:34:20	DFexpress	839A - Arya and Bran	GNU C++	Accepted	15 ms	2100 KB
29425599	2017-08-13 09:34:16	arnavdodiedo	839A - Arya and Bran	GNU C++14	Accepted	15 ms	1900 KB
29425598	2017-08-13 09:34:15	ashraybharambe	839C - Journey	Java 8	Wrong answer on test 5	155 ms	20600 KB
29425597	2017-08-13 09:34:13	lifeboat	839C - Journey	GNU C++11	Wrong answer on test 1	0 ms	4800 KB
29425596	2017-08-13 09:34:12	sam_267	830C - Bamboo Partition	GNU C++14	Wrong answer on test 7	15 ms	1900 KB
29425595	2017-08-13 09:34:07	ytc020306	839B - Game of the Rows	GNU C++	Wrong answer on test 43	15 ms	1900 KB
29425592	2017-08-13 09:34:05	Prans	1A - Theatre Square	GNU C++	Accepted	15 ms	2000 KB
29425590	2017-08-13 09:34:04	Ajmain00:11	839A - Arya and Bran	GNU C	Wrong answer on test 5	0 ms	1900 KB
29425589	2017-08-13 09:34:04	codingIsBliss	479A - Expression	GNU C++14	Accepted	15 ms	1900 KB
29425588	2017-08-13 09:34:00	5bingstar	839C - Journey	GNU C++11	Wrong answer on test 5	15 ms	19000 KB
29425587	2017-08-13 09:34:00	bizaaare	839B - Game of the Rows	GNU C++	Wrong answer on test 7	15 ms	2400 KB
29425586	2017-08-13 09:34:00	WackyWalrus	158A - Next Round	GNU C++14	Accepted	30 ms	1900 KB
← 1 2 3 4 5 →

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Aug/13/2017 12:36:14UTC+6 (p1).
Mobile version, switch to desktop version.
Privacy Policy
By 1605069, contest: Codeforces Round #428 (Div. 2), problem: (A) Arya and Bran, Wrong answer on test 8, #
 #include<stdio.h>
#include<string.h>
int cmpfunc (const void * a, const void * b)
{
    return ( *(int*)a - *(int*)b );
}

main()
{
    int n, k, i, j;
    scanf("%d %d", &n, &k);
    int sum = 0, cnt = 0;
    int a[n];

    for(i = 0; i<n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
        if(sum>=8)
        {
            cnt +=  8;
            sum = sum - 8;
        }
        else
        {
            cnt += sum;
            sum = 0;
        }

        if(cnt>=k)
        {
            printf("%d", i+1);
            return 0;
        }
    }

    printf("-1");

}


#include <stdio.h>
#define abs(x) ((x)>0?(x):-(x))
int main()
{
    long long a,b,count=0,m,n;
    while(scanf("%lld%lld",&a,&b)>0)
    {
        count=0;
        if(a>=b) count=a/b,a=a-b*count;
        while(a>1&&b>1)
        {
            m=abs(a-b);
            b=a;
            a=m;
            count++;
        }
        if(a==1&&b!=1) count+=b;
        if(b==1&&a!=1) count+=a;
        printf("%lld\n",count);
    }
}


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

#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<list>
#include<vector>
#define maxn 110

int main()
{
    char a[maxn];
    char *p;
    int n;
    int k[maxn];
    int flag;
    int i;
    while(scanf("%d",&n))

    {
        getchar();
        memset(k,0,sizeof(k));
        gets(a);
        p=a;
        i=0;

        flag=0;
        while(*p)
        {
            while(*p=='B')
            {   if(!flag)
                 i++;

                flag=1;
                k[i]++;
                p++;
            }
            p++;
            flag=0;
        }
        printf("%d\n",i);
        if(i)

        {for(int j=1;j<i;j++)
            printf("%d ",k[j]);
        printf("%d\n",k[i]);}
    }

}


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

int main(){
  long long a[14], b[14], ans = 0;
  for(int i = 0; i < 14; i++) scanf("%lld", a+i);
  for(int i = 0; i < 14; i++){
    long long t = a[i];
    memcpy(b, a, sizeof(a));
    b[i] = 0;
    for(int j = 1; t--; j++) b[(i+j)%14]++;
    t = 0;
    for(int j = 0; j < 14; j++) t += b[j] % 2 ? 0 : b[j];
    ans = ans > t ? ans : t;
  }
  printf("%lld", ans);
  return 0;
}


#include<stdio.h>
int main (){
    int wakeh,wakem,slh,slm,wmin,smin,cevap,saat,dakika,cevap2;
    char n,n;
    scanf("%d%c%d",&wakeh,&n,&wakem);
    scanf("%d%c%d",&slh,&n,&slm);
    wmin=(wakeh*60)+wakem;
    smin=(slh*60)+slm;
    cevap=wmin-smin
    if(cevap>=0){
    saat=(cevap/60);
    dakika=(cevap%60);
    printf("%d%c%d",saat,c,dakika);
}

else {
     cevap2=24*60-(smin-wmin);
     saat=cevap2/60;
     dakika=cevap2%60;
     printf("%d%c%d",saat,c,dakika);
     }

     return 0;

     }


#include <iostream.h>
#include<stdlb.h>
#include<conio.h>

int main()
{
    int n,c;
    cin>>n>>c;
    int ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    int large=-101;
    for(int i=1;i<n;i++)
    {
        if(ar[i-1]-ar[i]>large)
            large=ar[i-1]-ar[i];
    }
    if(large<0)
    {
        cout<<0<<endl;
    }
    else
    cout<<large-c<<endl;

}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void gen(long long int *a)
{
   int i;
   a[2]=4;
   a[3]=7;
   for(i=2;i<=2048;i++){
      //heaps are beautiful
      a[i<<1]=a[i]*10+4;
      a[(i<<1)+1]=a[i]*10+7;
//      printf("%lld %lld\n",a[i<<1],a[(i<<1)+1]);
   }
}
int main()
{
   long long int b[10000],*a;
   long long int ans,till;
   int l,r,i;
   gen(b);
   a=b+2;//the first two indices of b contain junk
   scanf("%d%d",&l,&r);
   i=0;
   while(a[i]<l)
      i++;
   till=((r>=a[i])?a[i]:r);
   ans=a[i]*(till-l+1);
//   printf("%lld+",ans);

   for(i=i+1;a[i]<=r;i++)
      ans+=(a[i]*(a[i]-a[i-1]));
   ans+=(a[i]*(r-a[i-1]));
  // printf("%lld\n",ans);
   printf("%I64d\n",ans);
   //cout>>ans;
   return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n>=1&&n<=10)
    {
        cout<<0<<endl;
    }
    if(n>=11&&n<=19)
        cout<<4<<endl;
    if(n==20)
        cout<<15<<endl;
    if(n==21)
        cout<<4<<endl;
    if(n>=22&&n<=25)
        cout<<0<<endl;

    return 0;
}


/*
   Sachin Chandani
   IIIT Hyderabad
 */

#include<stdio.h>
#include<limits.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
typedef long long int ll;
#define INF INT_MAX
int min(int a,int b);
void swap(int *a,int *b);
void swap(int *a,int *b)
{
	int temp=*a;
	*a=*b;
	*b=temp;
}
int cmp(const void *a,const void *b)
{
	return(*(int*)a-*(int*)b);

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

int main()
{
	int n,ans1=0,ans2=0;
	bool flag=false;
	char a[1005],b[1005];
	int  I[1005],II[1005],III[1005],IV[1005];
	scanf("%d%s%s",&n,a,b);
	for(int i=0;i<n;i++)
	{
		I[i]=III[i]=a[i]-'0';
		II[i]=IV[i]=b[i]-'0';
	}
	qsort(I,n,sizeof(int),cmp);
	qsort(II,n,sizeof(int),cmp);
	qsort(III,n,sizeof(int),cmp);
	qsort(IV,n,sizeof(int),cmp);
	for(int i=0;i<n;i++)
	{
		flag=false;
		for(int j=0;j<n;j+=1)
		{
			if(I[i]>II[j])
			{
				II[j]=-1;
			flag=true;

		}
		if(flag==false) ans1++;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(IV[j]>III[i])
			{
				ans2++;
				IV[j]=-1;
			}
		}
	}
	printf("%d %d",ans1,ans2);
	return 0;

}


#include <iostream>
using namespace std;

int main() {
    char c,a[100];
    int n,i=0,j;
    scanf("%d %c",&n,&c );
    while(1){
        scanf("%c",&c);
        if(a[c-'0']==0) {i++;a[c-'0']++;}
        if(c=='\n') break;
    }
    if(n<=i) printf("YES");
    else printf("NO");
    return 0;
}


In English  По-русски
anup.kalbalia | Logout

HOMECONTESTSGYMPROBLEMSETGROUPSRATINGAPIHELPTESTLIB5 YEARS!

Good Bye 2015
Contest is running
01:34:56
Contestant
 Add to favourites

→ Score table
Score
Problem A   387
Problem B   580
Problem C   967
Problem D   1354
Problem E   1934
Problem F   1934
Problem G   2320
Problem H   2707
Successful hack 100
Unsuccessful hack   -50
Unsuccessful submission -50
Resubmission    -50
* If you solve problem on 01:25 from the first attempt
PROBLEMSSUBMIT CODEMY SUBMISSIONSSTATUSHACKSROOMSTANDINGSCUSTOM INVOCATION

My Submissions

#   When    Who Problem Lang    Verdict Time    Memory
15114549    00:57:10    anup.kalbalia   A - New Year and Days   GNU C   Hacked  0 ms    8 KB

Codeforces (c) Copyright 2010-2015 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Dec/30/2015 22:00:01UTC+5.5 (c2).
By anup.kalbalia, contest: Good Bye 2015, problem: (A) New Year and Days, Hacked, #
 #include <stdio.h>
#include <stdlib.h>

int main(void) {
    // your code goes here
    char inp[20];
    char of[10];
    char wm[10];
    int i, ans;

    while (scanf("%[^\n]",inp)!=-1) {
        sscanf(inp, "%d of %s", &i, wm);
        getchar();
        if (wm[0] == 'w') {
            if (i == 5 || i == 6)
                ans = 53;
            else
                ans = 52;

        } else {
            if (i<30)
                ans = 12;
            else if (i == 30)
                ans = 11;
            else if (i == 31)
                ans = 7;
        }
        printf("%d\n", ans);
    }
    return 0;
}
close


#include <stdio.h>
int a,b,c,d,e,f;
int main(void) {
    scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
    if(a*c*e<b*d*f || (!a && b * d > 0) || (!c && d > 0)) puts("Ron");
    else puts("Hermione");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n, k, d, q, i, j;
    scanf("%d\n", &q);
    while(q--)
    {
        scanf("%d%d%d",&n,&k,&d);
        static int a[101], b[101];
        for(i=0; i<n; i++)
            scanf("%d", &a[i]);
        int t, ans=10e5;
        for(i=0; i<n-d+1; i++)
        {
            for(j=i, t=0; j<d+i; j++)
            {
                if(b[a[j]]==0)
                {
                    t++;
                }
                b[a[j]]++;
            }
            if(ans > t)
                ans = t;
            memset(b,0,sizeof(b);
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

int main()
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1==x2)
{

	printf("%d",2*(abs(y2-y1)));
}
else if(y1==y2)
{
	printf("%d",2*(abs(x2-x1)));
}
else
{
	printf("%d",2*((abs(x2-x1)+1)+(abs(y2-y1)+1)));
}
getch();
return 0;
}


#include<stdio.h>

int main(void)
{
	int n;
	char str[100];
	int i;
	int count;
	int check[100];
	int check1;

	check1 = 0;
	printf("%d", &n);
	printf("%s", str);

	for(i = 0; i < n; i++)
	{
		if(str[i] == '?')
		{
			check[i] = 1;
			count++;
			if(count == 2)
			{
				break;
			}
		}
		else
		{
			count = 0;
		}
	}
	if(count == 2)
	{
		printf("yes");
	}
	else
	{
		if(str[0] || str[n-1])
		{
			printf("yes");
		}
		else if
		{
			for( i = 1; i < n - 1; i++)
			{
				if(check[i] == 1)
				{
					if(str[i-1] == str[i+1])
					{
						printf("yes");
						check1 = 1;
						break;
					}
				}
			}
		}
	}

	if(check1 == 0)
	{
		printf("no");
	}
	return 0;
}


#include <stdio.h>
#include <math.h>
void solve(void);

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

void solve(void)
{
    double n;
    scanf("%lf", &n);

    printf("%u\n", (unsigned int)sqrt(n));
}


#include<stdio.h>
#include<String.h>
int main(){
string s;
int i,C=0,d=-1,c4=0,c7=0;
cin>>s;
C=strlen(s);
for(i=0;i<C;i++)
{
if(s[i]=='4'){
c4++;}
if(s[i]=='7')
c7++;

}
if(c4>c7)
printf("4");
else if(c7>c4)
printf("7");
else if(c7==1&&c4==1)
printf("4");
else
printf("-1");
}


#include<stdio.h>
#include<string.h>
int main()
{
   char s[110];
    while(1)
    {
        scanf("%s",s);
        int i,len,cnt=0;
        len=strlen(s);
        for(i=0;i<len-1;i++)
            if(s[i]=='V'&&s[i+1]=='K')
                cnt++;
        for(i=0;i<len-1;i++)
        {
            if(s[i]=='V'&&s[i+1]=='K')
                continue;
            else if(s[i]=='V'&&s[i+1]!='K')
            {
                s[i+1]='K';
                cnt++;
                break;
            }
            else if(s[i+1]=='K'&&s[i]!='V')
            {
                s[i]='V';
                cnt++;
                break;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


#include <string.h>
#include <stdio.h>
int main()
{
     char ch[11];
     scanf("%s",ch);
     int l=strlen(ch);
     int j,k,l;
     for(j=0;j<l;j++)
     {
          if(ch[j]=='0')
          printf("O-|-OOOO\n")
          else if(ch[j]=='1')
               printf("O-|O-OOO\n");
          else if(ch[j]=='2')
          printf("O-|OO-OO\n");
          else if(ch[j]=='3')
          printf("O-|OOO-O\n");
          else if(ch[j]=='4');
          printf("O-|OOOO-\n");
          else if(ch[j]=='5')
          printf("-O|-OOOO\n");
          else if(ch[j]=='6')
          printf("-O|O-OOO\n");
          else if(ch[j]=='7')
          printf("-O|OO-OO\n");
          else if(ch[j]=='8');
          printf("-O|OOO-O\n")
          else if(ch[j]=='9')
          printf("-O|OOOO-\n");

     }
}


#include <stdio.h>

int main()
{
	int i, r, sum = 0, temp;
	long int n;
	bool check = false;
	scanf("%ld", &n);
	temp = n;
	for (i = 1; n!=0; i++)
	{
		r = n % 10;
		if (r == 0 && check == false)
		{
			n = n / 10;
			temp = temp / 10;
		}
		else
		{
			sum = (sum * 10) + r;
			n = n / 10;
			check = true;
		}
	}
	if (sum == temp)
		printf("YES");
	else printf("NO");
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
inline int abls(int x,int y)
{
    if(x>y)
        return x-y;
    else
        return y-x;
}
inline int count(char *s,int len)
{
    int i,c=0;
    for(i=0;i<len;i++)
        if(s[i]=='+')
            c++;
        else if(s[i]=='-')
            c--;
    return c;
}
inline int comb(int a,int b)
{
    int i,m=1;
    for(i=a;i>a-b;i--)
        m*=i;
    a=m;
    m=1;
    for(i=1;i<=b;i++)
        m*=i;
    return a/m;

}
inline int count_2(char *s,int len)
{
    int i,c=0;
    for(i=0;i<len;i++)
        if(s[i]=='?')
            c++;

    return c;
}
int main()
{
    char s[11],c[11];
    int i,n1,n2,n3,z;
    scanf("%s%s",s,c);
    n1=count(s,strlen(s));
    n2=count(c,strlen(c));
    n3=count_2(c,strlen(c));
    z=abls(n1,n2);

    if(z>n3 || (n3-z)%2)
        printf("%.10f\n",0.0);
    else
    {
        printf("%.10f\n",comb(n3,(n3-z)/2)/pow(2,n3));
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n;
    int a,b;
    scanf("%d",&n);
    a=n/36;
    n=n%36;
    b=n/3;
    if((n%3!=0)&&(n%3==2))
                          b++;
    printf("%d %d",a,b);
    getch();
    return 0;
}


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

printf("%d",x-count);}
else
printf("0");
return 0;
}


#include<stdio.h>
#include<stdlib.h>
int union(int e,int f);
int min,max;
int main()
{

int e,f,n,a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
min=1;max=n;
e=c+1-b;f=n+c-b;
union( min,max, e, f);
if(min<max)
{
e=c+d-a-b+1;f=c+d-a-b+n;
union( min,max, e, f);
if(min<max)
{
e=1+d-a;f=n+d-a;
union( min,max, e, f);
if(min<max)
{
printf("%d\n",n*(max-min+1));
}
else{
printf("0\n");

}}
else{
printf("0\n");

}}
else{
printf("0\n");

}

	return 0;
}
void union(int e,int f)
{
if(min<e)
{
min=e;
}
if(max>f)
{
max=f;
}
}


#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 <limits.h>

int a[100];

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (k >= 2) {
    printf("Yes");
    return 0;
  }
  int zero_index;
  int sorted = 1;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    if (a[i] == 0) zero_index = i;
    if (i != 0 && i != zero_index && a[i] <= a[i-1]) sorted = 0;
  }
  int b;
  scanf("%d", &b);
  if (sorted) {
    if (zero_index == 0 && b < a[1] ||
        zero_index == n - 1 && a[zero_index - 1] < b ||
        zero_index != 0 && zero_index != n - 1 && a[zero_index - 1] < b && b < [zero_index + 1]) {
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}


#include <stdio.h>
void ans(int a,int b)
{
    int a1=a%5;
    int a2=b%5;

    int ans=0;
    if(a1+a2>=5)
    sum+=a1+a2-4;

    sum+=5*(a/5)*(b/5)+a1*(b/5)+a2*(a/5);
    printf("%d\n" , sum);

}

int main()
{
    int a,b;
    scanf("%d%d", &a, &b);
    ans(a,b);
}


#include<stdio.h>

int arr[5000],brr[5000];

int main(void){
    int a,b,c,d;
    scanf("%d %d",&a,&b);
    scanf("%d %d",&c,&d);
    arr[0]=b;brr[0]=d;
    for(int i=1;i<5000;i++){
        arr[i]=arr[i-1]+a;
        brr[i]=brr[i-1]+c;
    }
    for(int i=0;i<5000;i++)for(int j=0;j5000;j++)if(arr[i]==brr[j]){
        printf("%d",arr[i]);
        return 0;
    }
    printf("-1");
    return 0;
}


#include<stdio.h>
int main()
{
long  int x,y,z,sum=0;
scanf("%ld %ld %ld",&x,&y,&z);

if(x==y)
printf("%ld",(z*2)+b+a);

else if(x>y)
printf("%ld",(z*2)+(x*2)+1);

else if(x<y)
printf("%ld",(z*2)+(y*2)+1);

return(0);
}


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

    long long int a,b,s;
    scanf("%lld%lld%lld",&a,&b,&s);
    if(a<0)
    a=(0-a);
    if(b<0)
    b=(0-b);
    if((a==0 && b==0 && s==2) || (a+b==s) || ((s-(a+b))%2==0)
    printf("Yes");
    else
    printf("No");
    return 0;
}


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

#define MOD 1000000007
typedef long long int LLI;

LLI ** expo(LLI ** mat, LLI exp, LLI mod);
void dele(LLI ** a);
LLI ** mult(LLI ** a, LLI ** b, LLI mod);

int main(void) {
    LLI a, b, n;
    scanf("%I64d%I64d%I64d", &a, &b, &n);
    LLI ** base = (LLI **) calloc(2, sizeof(LLI *));
    base[0] = (LLI *) calloc(2, sizeof(LLI));
    base[1] = (LLI *) calloc(2, sizeof(LLI));
    base[0][0] = 0;
    base[0][1] = 1;
    base[1][1] = 1;
    base[1][1] = (MOD - 1);
    expo(base, n - 1, MOD);
    LLI x = a * base[0][0] + b * base[0][1];
    printf("%I64d", &x);
    return 0;
}

LLI ** mult(LLI ** a, LLI ** b, LLI mod) {
    int i, j, k;
    LLI ** ret = (LLI **) calloc(2, sizeof(LLI *));
    ret[0] = (LLI *) calloc(2, sizeof(LLI));
    ret[1] = (LLI *) calloc(2, sizeof(LLI));
    for (i = 0; i < 2; i++)
        for (j = 0; j < 2; j++){
            ret[i][j] = 0;
            for (k = 0; k < 2; k++)
                ret[i][j] = a[i][k] * b[k][j];
            ret[i][j] %= MOD;
        }
    return ret;
}

LLI ** expo(LLI ** mat, LLI exp, LLI mod) {
    int i, j;
    if (exp == 0) {
        LLI ** ret = (LLI **) calloc(2, sizeof(LLI *));
        ret[0] = (LLI *) calloc(2, sizeof(LLI));
        ret[1] = (LLI *) calloc(2, sizeof(LLI));
        ret[0][0] = (ret[1][1] = 1);
        ret[0][1] = (ret[1][0] = 0);
        return ret;
    }
    if (exp == 1) {
        LLI ** ret = (LLI **) calloc(2, sizeof(LLI *));
        ret[0] = (LLI *) calloc(2, sizeof(LLI));
        ret[1] = (LLI *) calloc(2, sizeof(LLI));
        for (i = 0; i < 2; i++)
            for (j = 0; j < 2; j++)
                ret[i][j] = mat[i][j];
        return ret;
    }
    LLI ** sq = expo(mat, exp / 2, mod);
    LLI ** tmp = mult(sq, sq, mod);
    dele(sq);
    if ((exp & 1) == 1) {
        LLI ** tmp2 = mult(sp, mat, mod);
        dele(tmp);
        tmp = tmp2;
    }
    dele(sq);
    return tmp;
}

void dele(LLI ** a) {
    free(a[0]);
    free(a[1]);
    free(a);
}


#include<stdio.h>
int main()
{
    long long int n,k,x,i,j,a,sum;
    scanf("%lld%lld%lld",&n,&k,&x);
    int number[n];
    for(i=0;i<n;i++){
          scanf("%d",&number[i]);
    }
      for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (number[i] < number[j])
            {
                a = number[i];
                number[i] = number[j];
                number[j] = a;
            }
        }
    }
    sum=k*x;
    for(j=2;j<n;j++){
       sum=sum+number[j];
    }
    printf("%lld\n",sum);
    return 0;

}


#include <stdio.h>

int solve(int_t n, int_t a, int_t b, int f) {
  int_t x;
  for (x = 0; x <= a; ++x) {
    if (x*a <= n && (n - x*a) % b == 0) {
      puts("YES");
      if (f) swap(&a, &b);
      printf("%d %d\n", x, (n - x*a) / b);
      return 1;
    }
  }
  return 0;
}

int_t main() {
  int_t n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  if (!solve(n, a, b, 0) && !solve(n, b, a, 1)) {
    puts("NO");
  }
  return 0;
}


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

int checkshun(char word1[],char word2[],char word3[]){
	if(word1[1] == word2[1] && word2[1] == word3[1]){
		if(word1[0]+word2[0]+word3[0] == 3*word2[0]){
			return 1;
		}else{
			return 0;
		}
	}else{
		return 0;
	}
}

int checkkou(char word1[],char word2[],char word3[]){
	if(word1[0] == word2[0] && word2[0] == word3[0]){
		if(word1[1] == word2[1] && word2[1] == word3[1]){
			return 1;
		}else{
			return 0;
		}
	}else{
		return 0;
	}
}

int compare(const void *data1,const void *data2){
	char *ptr1 = (char *)data1;
	char *ptr2 = (char *)data2;
	if(ptr1[1] > ptr2[1]){
		return 1;
	}else if(ptr1[1] < ptr2[1]){
		return -1;
	}else{
		if(ptr1[0] > ptr2[0]){
			return 1;
		}else if(ptr1[0] < ptr2[0]){
			return -1;
		}else{
			return 0;
		}
	}
}

int main(){
	char totalword[3][3];
	char word1[3] = {};
	char word2[3] = {};
	char word3[3] = {};
	scanf("%s%s%s",word1,word2,word3);
	if(checkshun(word1,word2,word3) == 1 || checkkou(word1,word2,word3) == 1){
		printf("0\n");
	}else{
		totalword[0][0] = word1[0];
		totalword[0][1] = word1[1];
		totalword[0][2] = '\0';
		totalword[1][0] = word2[0];
		totalword[1][1] = word2[1];
		totalword[1][2] = '\0';
		totalword[2][0] = word3[0];
		totalword[2][1] = word3[1];
		totalword[2][2] = '\0';
		qsort(totalword,3,sizeof(char)*3,compare);
		if(totalword[0][1] == totalword[1][1] && totalword[0][0]+1 == totalword[1][0]){
			printf("1\n");
		}else if(totalword[1][1] == totalword[2][1] && totalword[1][0]+1 == totalword[2][0]){
			printf("1\n");
		}else if(totalword[0][0] == totalword[1][0] && totalword[0][1] == totalword[1][1]){
			printf("1\n");
		}else if(totalword[1][0] == totalword[2][0] && totalword[1][1] == totalword[2][1]){
			printf("1\n");
		}else if(totalword[0][1] == totalword[1][1] && totalword[0][0]+2 == totalword[1][0]){
			printf("1\n");
		}else if(totalword[1][1] == totalword[2][1] && totalwrod[1][0]+2 == totalword[2][0]){
			printf("1\n");
		}else{
			printf("2\n");
		}
	}
}


#include<cstdio>
int main()
{
    int n,ans = 1;
    scanf("%d",&n);
    int m = n;
    while(m >= 10)
        ans *= 10,m /= 10;
    ans *= m % 10 + 1;
    printf("%d\n",ans - n);
    return 0;
}


#include<stdio.h>

int main()
{
int a, b, c;

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

if(c/4 > a && b/2 >a)
printf("%d", c/4*(1+2+4);

else
printf("0");

return 0;
}


#include<stdio.h>

int main() {
    long long int n , a, b ,x, t , y;
    scanf("%I64d", &t);
    while(t--){
        scanf("%I64d%I64d",&a , &b);
        x = (a * a) - (b * b);
        if(x % 2 == 0) {
            printf("NO\n");
            return 0;
        }
        else {
            if(pow(3 , x-1) % x == 1){
                printf("YES\n");
            }
            else printf("NO\n");

        }
    }

    return 0;
}


main()
{
int n;
scanf("%d",&n);
printf("%d",6n*(n−1)+1);
return 0;
}


#include <stdio.h>
int good(unsigned k,unsigned l,char *s,unsigned n)
{  unsigned i,j;
//printf("\n________________\n");
    //for(i=l,j=0;i<n,j<4;i+=k,j++)
    j=0;
    while(l<n&&j<=4)
    {   //printf(" %d\t%d ",l,j);
        if(s[l]=='.')
            return 0;

            l+=k;
            j++;
    }
    return 1;
}

int main()
{
    unsigned n,i=0,j;
    char s[101];
    int trouve =0;
    scanf("%d",&n);
    scanf("%s",s);
    j=0;
    while(j<n&&!trouve)
    {    if(s[j]=='*')
    {  i=1;
        while(i<=(n-j)/4&&!good(i,j,s,n))
       i++;
       if(i<=(n-j)/4)
        trouve=1;
    }
       j++;
    }

       if(trouve)
        printf("yes");
       else
        printf("no");

    return 0;
}


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

int main(){
    int n,j,i,flag=0,c=0,m;
    scanf("%d %d",&n,&m);
    if(n<1||m<1||n+m<3){printf("0");return 0;}
    while(n>0&&m>0){
        if(n>=m){n=n-2;m=m-1;c++;}
        else {n=n-1;m=m-2;c++;}
        if(n+m<3)break;1
    }
    printf("%d",c);
    return 0;
}


#include<stdio.h>
int main()
{
	int a,i,j,m,n[1000],sum;
	while(scanf("%d%d",&sum,&m)!EOF)
	{
		a=0;
		for(i=0;1;i++)
		{
			sum +=sum%m;
			n[i]=sum%m;
			if(sum%m==0)
			{
				printf("YSE\n");
				break;
			}
			for(j=0;j<i;j++)
				if(n[i]==n[j])
				{
					a=1;
					break;
				}
			if(a==1)
			{
				printf("NO\n");
				break;
			}
		}
	}
	return 0;
}


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

int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);

	if(a==d)
	{
		printf("1");
		return 0;
	}
	return 0;
	else
	{
		pritnf("0");
		return 0;
	}
	return 0;
}


#include<stdio.h>
#include<ctype.h>
int main()
{
    int k;
    scanf("%d",&k);
    int m=19, c=0, sum=0;
    while(true){
        int n = m;
        sum = 0;
        while(n){
            sum+=n%10;
            n=n/10;
        }
        printf("%d %d %d\n", n, sum, c);
        if(sum == 10) c++;
        if(c == k) break;
        m++;
    }
    printf("%d", m);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main (void)
{
    char s[100];
    int len,i;
    int a,b,c,k;

    while (scanf ("%s",str) != '\0')
    {
        len = strlen(str);
        k = 1;

        for (i=0; i<len; i++)
        {
            a = (str[i] == 'a' || str[i] == 'o' || str[i] == 'u' || str[i] == 'i' || str[i] == 'e');
            b = (str[i+1] == 'a' || str[i+1] == 'o' || str[i+1] == 'u' || str[i+1] == 'i' || str[i+1] == 'e');
            c = (str[i-1] == 'a' || str[i-1] == 'o' || str[i-1] == 'u' || str[i-1] == 'i' || str[i-1] == 'e');

            if (i == len-1)
            {
                if (str[i] == 'n' || (c && a)) /* if last element is n or whether the                       last element and its previous one are vowels  */
                    continue;

                if (!(!c && a))
                {
                    k = 0;
                    break;
                }
            }
            else
            {
                if (str[i] == 'n')
                    continue;

                if (!a && !b) /* if consonant followed by a consonant*/
                {
                    k = 0;
                    break;
                }
            }
        }

        if (k)
            pf ("YES\n");
        else
            pf ("NO\n");
    }

    return 0;
}


//Author : pakhandi
//
using namespace std;

#include<bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)
#define scan(n) scanf("%d", &n)
#define scans(s) scanf("%s", s)
#define scanc(c) scanf("%c", &c)
#define scanp(f) scanf("%f", &f)
#define print(n) printf("%d\n", n)
#define prints(s) printf("%s\n", s)
#define printc(c) printf("%c\n", c)
#define printp(f) printf("%f\n", f)
#define nline printf("\n")
#define mclr(strn) strn.clear()
#define ignr cin.ignore()
#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size

double dist(ll a, ll b, ll c, ll d){
  return sqrt((d-b)*(d-b)+(c-a)*(c-a));
}

int main()
{
    //freopen("C:\\Users\\DELL\\Desktop\\input.txt","r",stdin);
    //freopen("C:\\Users\\DELL\\Desktop\\output.txt","w",stdout);
    int i, j, cases, k=1;
    ll x, y, nx, ny;
    ll r;
    cin>>r>>x>>y>>nx>>ny;
    cout<<ceil((dist(x,y,nx,ny)/(2*r)));
    nline;

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int i,j;
    int l,r,x,y;
    float k;
    scanf("%d %d %d %d %f",&l,&r,&x,&y,&k);
    for(i=l;i<=r;i++)
        {
            if((i*k<=y&&i*k>=x)
            {
                printf("YES");
                exit(0);
            }
        }
    printf("NO");
    return 0;
}


#include <iostream>
#include<string>
int compute(char a[],int n,int bb){
	int hor=0,vert=0,count=0,i;
	for(i=bb;i!=n;i++)
	{
		if(a[i]=='U')
			hor++;
		else if(a[i]=='D')
			hor--;
		else if(a[i]=='L')
			vert++;
		else if(a[i]=='R')
			vert--;
	if(hor==0&&vert==0)
		count++;
	}
	return count;
}
int main() {
	// your code goes here
	int n,i,ways;
	char a[300];
	scanf("%d",&n);

		scanf("%s",&a);

	for(i=0;i<n;i++)
			ways+=compute(a,n,i);
	printf("%d",ways);
}


/*
Project name : hamburgar
Created on : Wed Dec 11 11:58:38 IST 2013
http://codeforces.com/problemset/problem/371/C

*/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int debug=0;
typedef long long int lld;
int kb,nb,pb,ks,ns,ps,kc,nc,pc;
lld r;
lld getCost(lld n){
    lld ab=(n*kb-nb);ab=ab>0?ab:0;
    lld as=(n*ks-ns);as=as>0?as:0;
    lld ac=(n*kc-nc);ac=ac>0?ac:0;
    if(debug){
        printf("cost for : n=%lld \n",n);
        printf("cost of b : %lld\n",ab*pb);
        printf("cost of s : %lld\n",as*ps);
        printf("cost of c : %lld\n",ac*pc);
        printf("\n\n");
    }
    return ab*pb+as*ps+ac*pc;
}
int main(int argc , char **argv)
{
    if(argc>1 && strcmp(argv[1],"DEBUG")==0) debug=1;
    char str[101];
    scanf("%s",str);
    int i;
    kb=0;ks=0;kc=0;
    for(i=0;i<strlen(str);++i){
        switch(str[i]){
        case 'B':
            ++kb;
            break;
        case 'S':
            ++ks;
            break;
        case 'C':
            ++kc;
            break;
        }
    }
    scanf("%d %d %d",&nb,&ns,&nc);
    scanf("%d %d %d",&pb,&ps,&pc);
    scanf("%lld",&r);
    if(debug){
        printf("kb=%d ks=%d kc=%d\n",kb,ks,kc);
        printf("nb=%d ns=%d nc=%d\n",nb,ns,nc);
        printf("pb=%d ps=%d pc=%d\n",pb,ps,pc);
        printf("r=%lld\n",r);
    }
    lld n=1;
    while(getCost(n)<=r)n*=2;
    lld start=n/2,end=n,mid=(start+end)/2,cost;
    while(end-start>1){
        cost=getCost(mid);
        if(debug)printf("start=%lld , end=%lld , cost=%lld\n",start,end,cost);
        if(cost>r)end=mid;
        else if(cost<r) start=mid;
        else break;
        mid=(start+end)/2;
    }
    if(cost==r)printf("%lld\n",mid);
    else printf("%lld\n",start);
    return 0;
}
/*
Project name : hamburgar
Created on : Wed Dec 11 11:58:38 IST 2013
http://codeforces.com/problemset/problem/371/C

*/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int debug=0;
typedef long long int lld;
int kb,nb,pb,ks,ns,ps,kc,nc,pc;
lld r;
lld getCost(lld n){
    lld ab=(n*kb-nb);ab=ab>0?ab:0;
    lld as=(n*ks-ns);as=as>0?as:0;
    lld ac=(n*kc-nc);ac=ac>0?ac:0;
    if(debug){
        printf("cost for : n=%lld \n",n);
        printf("cost of b : %lld\n",ab*pb);
        printf("cost of s : %lld\n",as*ps);
        printf("cost of c : %lld\n",ac*pc);
        printf("\n\n");
    }
    return ab*pb+as*ps+ac*pc;
}
int main(int argc , char **argv)
{
    if(argc>1 && strcmp(argv[1],"DEBUG")==0) debug=1;
    char str[101];
    scanf("%s",str);
    int i;
    kb=0;ks=0;kc=0;
    for(i=0;i<strlen(str);++i){
        switch(str[i]){
        case 'B':
            ++kb;
            break;
        case 'S':
            ++ks;
            break;
        case 'C':
            ++kc;
            break;
        }
    }
    scanf("%d %d %d",&nb,&ns,&nc);
    scanf("%d %d %d",&pb,&ps,&pc);
    scanf("%lld",&r);
    if(debug){
        printf("kb=%d ks=%d kc=%d\n",kb,ks,kc);
        printf("nb=%d ns=%d nc=%d\n",nb,ns,nc);
        printf("pb=%d ps=%d pc=%d\n",pb,ps,pc);
        printf("r=%lld\n",r);
    }
    lld n=1;
    while(getCost(n)<=r)n*=2;
    lld start=n/2,end=n,mid=(start+end)/2,cost;
    while(end-start>1){
        cost=getCost(mid);
        if(debug)printf("start=%lld , end=%lld , cost=%lld\n",start,end,cost);
        if(cost>r)end=mid;
        else if(cost<r) start=mid;
        else break;
        mid=(start+end)/2;
    }
    if(cost==r)printf("%lld\n",mid);
    else printf("%lld\n",start);
    return 0;
}


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


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int Gcd(int a,int b)
{
    return b==0?a:Gcd(b,a%b);
}
int main()
{
    int a,b,sign,Time,num,sum,A,B,Begin_Time;
        scanf("%d%d",&a,&b);
        Time=0;num=0;sum=0;A=1;B=1;Begin_Time=0;
        sign=a>b?a/Gcd(a,b)*b:a/Gcd(b,a)*b;
        while(1)
        {
           Time=A*a>B*b?B*b:A*a;
           if(Time==A*a)A++;
           if(Time==B*b)B++;
           if(Time==sign)
           {
               if(num>sum)
                    sum+=sign-Begin_Time;
               else
                    num+=sign-Begin_Time;
               break;
           }
            if(Time%a==0)
                num+=Time-Begin_Time;
            if(Time%b==0)
                sum+=Time-Begin_Time;
            Begin_Time=Time;
        }
        if(num>sum)
            printf("Dasha\n");
        else if(num<sum)
            printf("Masha\n");
        else
            printf("Equal\n");
    return 0;
}

int main()
{
    __int64 a,b;
    cin>>a>>b;
    __int64 lcm=a>b?a/gcd(a,b)*b:a/gcd(b,a)*b;
    __int64 t=0,sum=0,sud=0,n1=1,n2=1,Min=0;
    while(1)
    {
        t=min(n1*a,n2*b);
        if(t==n1*a) n1++;if(t==n2*b) n2++;
        if(t==lcm){
            if(sum>sud) sud+=lcm-Min;
            else sum+=lcm-Min;
            break;
        }
        if(t%a==0) sum+=t-Min;
        if(t%b==0) sud+=t-Min;
        Min=t;
    }
    if(sum==sud) cout<<"Equal";
    else if(sum>sud) cout<<"Dasha";
    else cout<<"Masha";
    return 0;
}


main(a,b)
{
char c=' ',d;
while((d=getchar())
{
if(d==c) a++;
if(a==5 || t!=d){b++;a=0;c=d;}
}
printf("%d",b);
return 0;
}


#include<stdio.h>
int main()
{
	int n,k,total,median,median1;
	scanf("%d %d",&n,&k);
	total = (n - 1) * 2 + 3;
	(n % 2 == 0) ? median = n / 2 : median = n/2+1;
	if(k == 1 || k == n)
	{
		printf("%d\n",total + n - 1);
	}
	else{
		if(n % 2 == 0)
		{
			if(k == median || k == median + 1)
			{
				k = (median - 1) * 2 + n/2;
				printf("%d\n",total+ k);
			}
			else{
				int temp = median + (median+1);
				if(k < median)
				{
					total += (k-1) * 2 + (n - k);
					printf("%d\n",total);
				}
				else if(k > median)
				{
					k = temp % k;
					total += (k-1) * 2 + (n - k);
					printf("%d\n",total);
				}
			}
		}
		else if(n % 2 != 0)
		{
			if(k == median)
			{
				k = n-1;
				printf("%d\n",total + k + n/2);
			}
			else{
				if(k < median)
				{
					printf("%d\n",total + (k-1) * 2 + (n - k));
				}
				else{
					k =  k % (median * 2);
					printf("%d\n",total + (k-1) * 2 + (n-k));
				}
			}
		}
	}
	return 0;
}


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

typedef long long int int64;

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

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

int64 func(int64 n,int64 b){
  int64 res=0;
  while(n>0){
    res+=n/b;
    n/=b;
  }
  return res;
}

void run(void){
  int64 n=readInt();
  int64 b=readInt();
  int64 ans=n;
  for(int64 k=2;k*k<=b;k++){
    if(b%k!=0) continue;
    int cnt=0;
    do{
      b/=k;
      cnt++;
    } while(b%k==0);
    int64 f=func(n,k)/cnt;
    ans=MIN(ans,f);
  }
  if(b>1){
    ans=MIN(ans,func(n,b));
  }
  printInt(ans);
  putchar('\n');
}

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


#include<stdio.h>
#include<algorithm>
int main()
{
    int a[3],n,temp;
    scanf("%d",&n);
    scanf("%d",&a[0]);
    scanf("%d",&a[1]);
    scanf("%d",&a[2]);
    for(int i=0;i<=2;i++)
        {
            for(int j=i;j<=2;j++)
            {
                if(a[i]>a[j])
                {
                   temp=a[i];
                   a[i]=a[j];
                   a[j]=temp;
                }
            }
        }
    int sum=0;
    n--;
    while(n!=0)
    {
        if(n%2==0) sum+=a[1];
        else if(n%2==1) sum+=a[0];
        n--;
    }
    printf("%d",sum);

    return 0;
}


#include <cstdio>

int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main()
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);

    int ansa, ansb;
    if(b*c >= a*d)
    {
        ansa = b*c - a*d;
        ansb = b*c;
    }
    else
    {
        ansa = a*d - b*c;
        ansb = a*d;
    }

    int ansc = gcd(ansa, ansb);

    printf("%d/%d\n", ansa/ansc, ansb/ansc);

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
struct node{
    int a , i ;
} p[110];
int cmp(node x,node y)
{
    return x.a < y.a ;
}
int main()
{
    int n , k , num ;
    while( scanf("%d %d", &n, &k) != EOF )
    {
        num = 0 ;
        int i ;
        for(i = 0 ; i < n ; i++)
        {
            scanf("%d", &p[i].a) ;
            p[i].i = i+1 ;
        }
        sort(p,p+n,cmp) ;
        for(i = 0 ; i < n ; i++)
            if( k >= p[i].a )
            {
                k -= p[i].a ;
            }
            else
                break ;
        num = i ;
        printf("%d\n", num) ;
        if( num == 0 ) continue ;
        for(i = 0 ; i < num-1 ; i++)
        {
            printf("%d ", p[i].i) ;
        }
        printf("%d\n", p[i].i) ;
    }
    return 0;
}


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


#include <stdio.h>
int main(){
    int a,b;
    scanf("%d",&a);
    if(a == 2999){
        b = a + 1;
    }
    else if(a == -45){
        b = a - 1;
    }
    else{
        b = a
    }
    printf("%d\n",b);
    return 0;
}


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

int main()
{
  int da , db ,a,x,b;
  scanf("%d",&da) ;
  scanf("%d",&db) ;
    if ((abs(db-da)>=2)||(da>db))
        printf("-1") ;

    else
     {
         a=da*10;
         b=db*10;
         x=abs(a-b+1);
         printf("%d %d",a+x,a+x+1);
     }


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

int main()
{
    int a['z']={0},n,k;
    scanf("%d %d",&n,&k);
    char s[1000];
    scanf("%s",&s);
    int i;
    for(i=0;s[i]!='\0';i++)
    {
        char z=s[i];
        a[z]++;
    }
    char d;
    for(d='a';d<='z';d++)
    {
        if(y[d]<y)
         {
             printf("NO\n");
             return 0;
         }
    }
    printf("YES\n");
    return 0;
}


#include <stdio.h>

#define MOD 1000000007

long long binpow(long long a, long long k)
{
    long long ans = 1;
    if(a == 0) return 0;
    while(k)
    {
        if(k & 1)
        {
            ans *= a;
            ans %= MOD;
        }
        a *= a;
        a %= MOD;
        k >>= 1;
    }
    return ans;
}

int main()
{
    long long n, k;
    scanf("%lld %lld", &n, &k);
    printf("%lld", binpow(k, k - 1) * binpow(n - k, n - k) % MOD);
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, i=0, nule=0, neg=0, poz=0;
    cin>>n;
    int niz1[n];
    while(i<n)
    {
        cin>>niz1[i];

        if(niz1[i]==0)
        {
            nule++;
            i++;
        }
        else if(niz1[i]<0)
        {
            neg++;
            i++;
        }
        else if(niz1[i]>0)
        {
            poz++;
            i++;
        }
    }
    if(poz>=(n+1)/2)
    {
        cout<<1;
    }
    else if(neg>=(n+1)/2)
    {
        cout<<-1;
    }
    else cout<<0;
}


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

int main(void)
{
	char k[3],t[3];
	scanf("%s %s",k,t);

	int hor=abs(k[0]-t[0]),ver=abs(k[1]-[1]);

	if(hor>=ver) printf("%d\n",hor);
	else printf("%d\n",ver);

	for(;strcmp(k,t);)
	{
		if(k[0]<t[0])
		{
			printf("R");
			k[0]+=1;
		}
		else if(k[0]>t[0])
		{
			printf("L");
			k[0]-=1;
		}

		if(k[1]<t[1])
		{
			printf("U");
			k[1]+=1;
		}
		else if(k[1]<t[1])
		{
			printf("d");
			k[1]-=1;
		}
		printf("\n");
	}

	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] || nums[4] == -1) {
        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(string, nums[1], nums[0], size);
                if (sub != -1) {
                    step_count += sub;
                    if (sub > nums[0] && sub > nums[1])
                        step_count --;
                }
            }
            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(string, nums[1], nums[2], size);
                if (sub != -1) {
                    step_count += sub;
                    if (sub > nums[2] && sub > nums[1])
                        step_count --;
                }
            }
            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(string, 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[3] - 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<stdio.h>
int main()
{
	int c,d,n,m,k,prob,target,compare;
	while((scanf("%d %d %d %d %d",&c,&d,&n,&m,&k)) != EOF) {
		prob = 0;
		target = n*m;
		if(target <=k) printf("0\n");
		else {
			target -= k;
			while(target > 0) {
				if(target >= n) {
					compare = d * n;
					if(compare < c) {
						target -= n;
						prob += compare;
					}
					else {
						target -= n;
						prob += c;
					}
				}
				else {
					compare = d * target;
					if(compare < c) {
						target = 0;
						prob += compare;
					}
					else {
						target = 0;
						prob += c;
					}
				}
			}
			printf("%d\n",prob);
		}
	}
	return 0;
}


#include <stdio.h>
int main()
{
	int a, b, c, d;
	int prirastaj;
	float koeficijent, next;
	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)
	{
		next=koeficijent*d;
		if(next==(int)next)
			printf("%d", (int)next);
		else printf("42");
	}
	else printf("42");

	return 0;
}


#include<stdio.h>
int main()
{
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	a<b?c=a:c=b;
	int side=a+b+c;
	printf("%d\n",(int)(side/(double)c*side/(double)c)-3);
	return 0;
}


#include <stdio.h>

int ans;
int students[5][105];
int n;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            scanf("%d", &a);
            students[i][a]++;
        }
    }
    for (int i = 1; i < 6; i++)
    {
        if ((students[0][i]+students[1][i])%2 == 1)
        {
            printf("-1");
            return 0;
        }
        if (students[0][i] > students[1][i])
        {
            ans += students[0][i]-students[1][i];
        }
    }

    printf("%d", ans/2);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int n, v;
    cin >> n >> v;
    if (n-1 <= v) {
        cout << n-1 << endl;
        return 0;
    }
    int result = v - 1;
    for(int i = 1; i <= n - v; ++i) {
        result += i;
    }
    cout << result << endl;

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int arr[360];
void doiChoTrucTiep(int &n)
{
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(arr[j]<arr[i])
			{
				int nho=arr[j];
				arr[j]=arr[i];
				arr[i]=nho;
			}
		}
	}
}
int main()
{
	int n,sum,min=360;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	doiChoTrucTiep(n);
	for(int i=0;i<n;i++)
	{
		sum=0;
		for(int j=i;j<n;j++)
		{
			sum+=arr[j];
			if(abs(360-2*sum) < min)
			{
				min=abs(360-2*sum);
			}
		}
	}
	printf("%d",min);
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
 void main()
{
	char str[200];
	scanf("%s", str);
	int len = strlen(str);
	int x = 0;
	if (len % 2 == 1)
	{
		for (int i = 1; i < strlen(str); i++)
		{
			int t = str[i] - '0';
			x = x + t;
		}
	}
	if (x > 0)
	{
		x = 1;
	}
	int sol = len / 2 + m;
	printf("%d\n", sol);
}


#include<stdio.h>

int solution[40];
int n,m;
int used[40]={0};
int sum=0;
int c=0;
int ans=0;

void backtrack(int x)
{
	void minmin(int);
	if(x==n+1)
	{
		int i;
		sum=0;
		minmin(1);
		if(c==m)
		{	int i;
			for(i=1;i<=n;i++)
				printf("%d ",solution[i]);
		}
		return;
	}

	int i;
	for(i=1;i<=n;i++)
	{
		if(used[i]==0)
		{
			solution[x]=i;
			used[i]=1;
			backtrack(x+1);
			if(c==m)
			return;
			used[i]=0;
		}
	}
	return;
}

void minmin(int x)
{
	if(x==n+1)
	{
		if(sum==ans)
		c++;
		return;
	}

	int i,j;
	for(i=x;i<=n;i++)
	{
		int MIN=100;
		for(j=x;j<=i;j++)
		{
			if(MIN>solution[j])
				MIN=solution[j];
		}
		sum+=MIN;
	}
	minmin(x+1);
	return;
}

int main()
{
	scanf("%d %d",&n,&m);
	ans=n*(n+1)*(n+2)/6;
	backtrack(1);
	return 0;
}


# include<stdio.h>

int main()
{
int n,a,x;
scanf("%d",&n);
n=(n*(n+1))/2;
if(n%2==0)
{
printf("0");
else
{
printf("1");
}
}


#include <stdio.h>

int main(void) {
    int t,k;
    scanf("%d", &t);
    int answers[t];
    for(int i = 0; i < t; i++) {
        scanf("%d", &k);
        if((100 - k) > k) {
            min = k;
            max = 100 - k;
        }
        else {
            max= k;
            min = 100 - k;
        }
            if(k == 100 || k == 0) {
                answers[i] = 1
            }
            else if(max % min== 0) {
                answers[i] = 100 / min;
            }
            else {
                for(int j = min / 2;j >= 1;j--) {
                    if(max % j == 0 && min % j == 0) {
                        answers[i] = 100 / j;
                        break;
                    }
                }
            }
    }

    for(int i = 0; i < t; i++) {
        printf("%d\n",answers[i]);
    }
	return 0;
}


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

int main()
{
		double h, m, s, t1, t2, collisionForward = 0, collisionBackward = 0;
		scanf("%lf %lf %lf %lf %lf", &h, &m, &s, &t1, &t2);
		m += s / 12;
		h = h * 5 + m / 12;
		t1 *= 5;
		t2 *= 5;
		if (t1 > t2) {
			t1 = t1 + t2;
			t2 = t1 - t2;
			t1 = t1 - t2;
		}
		if (h >= t1 && h <= t2 || m >= t1 && m <= t2 || s >= t1 && s <= t2) {
			collisionForward = 1;
		}
		t1 += 60;
	    h += 60;
	    m += 60;
	    s += 60;
		if (h <= t1 && h >= t2 || m <= t1 && m >= t2 || s <= t1 && s >= t2) {
			collisionBackward = 1;
		}
		if (collisionBackward && collisionForward) {
			printf("NO");
			return 0;
		}
		printf("YES");
		return 0;
}


 <stdio.h>
int main(){
    char a[30]="";
    char b[30]="";
    int i,t1=0,t2=0;
    scanf("%s%s",a,b);
    for(i=0;a[i]!=0;i+=2){
        switch(a[i]){
            case '8':
            switch(b[i]){
                case '[':t1++;break;
                case '(':t2++;break;
                default:;
            }break;
            case '[':
            switch(b[i]){
                case '8':t2++;break;
                case '(':t1++;break;
                default:;
            }break;
            case '(':
            switch(b[i]){
                case '[':t2++;break;
                case '8':t1++;break;
                default:;
            }break;
        }
    }
    if(t1>t2)
    printf("TEAM 1 WINS\n");
    else if(t1<t2)
    printf("TEAM 2 WINS\n");
    else
    printf("TIE\n");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(void){
unsigned long long int x,a;
int t[18];
int n,i,j;
char s[18];
scanf("%lld",&x);
sprintf(s, "%lld", x);
n=strlen(s);

for(i=0;i<n;i++){
    t[i]=x%10;
    x=x/10;
}

    if(t[0]!=9 &&t[0]>4){
        t[0]=9-t[0];}
for(i=1;i<n;i++){

    if(t[i]>4){
        t[i]=9-t[i];
    }
}
j=0;
for(i=n-1;i>-1;i--){
    if(t[i]==0){
        j++;}else {break;}
    }


#include<stdio.h
int main(
{
    int n;
    scanf("%d",&n);
    char str[n+1];
    gets(str);
    printf("%d",n+1);

    return 0;
}


#include <stdio.h>

int main(int argc, const char* argv[]){
  int n,k, partial,i;
  int count = 0;
  int a[100];

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

  for(i=0;i<k;i++){
    partial = 0;
    for(int j=0;j<n/k;j++){
      partial += (a[i+j*k]==1?1:0);

    }
    count += (partial<n/k-partial?partial:n/k-partial);
  }

  printf("%d", count);

  return 0;
}


#include <stdio.h>

typedef long long ll;

int main(){

ll n,m ;
int i,j,k;
char * a;

scanf("%",&);

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

}

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


#include<stdio.h>
#include<math.h>
int main()
{
    int n,arr[100],i;
      scanf("%d",&n);

      int pos;
    for(i=0;i<n;i++)
        arr[i]=0;
    for(i=0;i<n/2-1;i++)
      {
          scanf("%d",&n);
          a[n]=1;
       }
     int black=black(arr,n);
     int white=white(arr,n);
     (black>white)?printf("%d",black):printf("%d",white);

     return 0;
}
int black(int *arr,int n)
{
    int i=n-1,j=n-2,steps=0;
    while(i>=0 &&j>=0)
    {
        if(arr[i]==1 && i/%2==1)
          {
            if(arr[j]==0)
            {
             arr[j]=1;
             arr[i]=0;

             steps+=abs(j-i);
             i--;
             j-=2;
            }
           else
           {
               while(arr[j]!=0)
               j-=2;

             arr[j]=1;
             arr[i]=0;

             steps+=abs(j-i);
             i--;
             j-=2;

           }
        }
        else if(arr[i]==1 && i%2==0)
           i--;
    }
}
int white(int *arr,int n)
{
    int i=n-1,j=n-1,steps=0;
    while(i>=0 && j>=1)
    {
        if(arr[i]==1 && i/%2==1)
          {
            if(arr[j]==0)
            {
             arr[j]=1;
             arr[i]=0;

             steps+=abs(j-i);
             i--;
             j-=2;
            }
           else
           {
               while(arr[j]!=0)
               j-=2;

             arr[j]=1;
             arr[i]=0;

             steps+=abs(j-i);
             i--;
             j-=2;

           }
        }
        else if(arr[i]==1 && i%2==0)
           i--;
    }
}


#include <stdio.h>
#include <math.h>
int n, t;

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


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


#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}

int main(void){

long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,k,r,o,sum1,sum=0,y,count1=0,a[100000];

scanf("%lld",&n);

for(i=0;i<n;i++){
    scanf("%lld",&a[i]);

    if(a[i]>){

        sum+=a[i];

    }else{
       sum+=(-1)*a[i];
        count++;
    }
}
qsort(a,n,sizeof(long long int),cmpfunc);
if(count!=0){
   if(count%2==0){
       sum+=a[0];
   }
}
printf("%lld\n",sum);

return 0;
}


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

/* maximum factors count, 10 must be enough. I take few more ) */
const int64_t cnt = 1000;

int64_t
decompose(int64_t x, int64_t *p)
{
    /* factors counter */
    int64_t c = 0;
    for (int64_t d = 2, b = x; x*x >= b; ++d)
    {
        if (x % d == 0)
            p[c++] = d;
        while (x % d == 0)
            x /= d;
    }
    if (x != 1) {
        p[c++] = x;
    }
    return c;
}

int
main()
{
    int64_t x;
    int64_t p[cnt];
    scanf("%"SCNd64, &x);

    int64_t c = decompose(x, p);

    int64_t max_f = x;
    int64_t min_f = x - p[c-1] + 1;
    int64_t min = min_f;
    for (int64_t f = min_f; f < max_f; ++f) {
        c = decompose(f, p);
        if ((c != 1 || p[0] != f) && f - p[c-1] + 1 < min)
            min = f - p[c-1] + 1;
    }
    printf("%"PRId64"\n", min);
    return 0;
}


#include <stdio.h>

int main() {
int n, k;
scanf("%d %d", &n, &k);
printf("%d\n", 3n - k);
return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
int go[2] = {0}; // 0 shangxia   1 zuoyou
int main()
{
    int T;
    scanf("%d", &T);
    int flag = 1;
    for(int i = 1; i <= T; i++)
    {
        int a;
        char b[10];  // 1 is north, 0 is s
        scanf("%d %s", &a, b);
        if(strstr(b, "East") && flag == -1)
        {
            go[1] = fabs((go[1] + a) % 40000);
            continue;
        }
        else if(strstr(b,"South") && flag != 0)
        {
            go[0] = fabs((go[0] + a) % 40000);
            if(go[0] == 20000)
                flag = 0;
            if(go[0] == 0)
                flag = 1;
            else
                flag = -1;
            continue;
        }
        else if(strstr(b, "North") && flag != 1)
        {
            go[0] = fabs((go[0] - a) % 40000);
            if(go[0] == 20000)
                flag = 0;
            if(go[0] == 0)
                flag = 1;
            else
                flag = -1;
            continue;
        }
        else if(strstr(b, "West") && flag == -1)
        {
            go[1] = fabs((go[1] - a) % 40000);
            continue;
        }
        else
        {
            printf("NO\n");
            return 0;
        }
    }
    if(go[0] == 0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


#include <stdio.h>
int temp[26];
int main()
{
    char s[52];
    int i, j, k;
    gets(s);
    if(s[0] != 'a'){ printf("NO\n"); return 0;}
    else temp[0] = 1;
    for(i = 1; s[i] != '\0'; i++){
        j = s[i] - 97;
        if((s[i] - s[i-1]) ==1 || temp[j] != 0){
            temp[j] = 1;
        }
        else{
            printf("NO\n"); return 0;
        }
    }
    printf("YES\n");
}


#include<stdio.h>
int main()
{
int x,y,z;
int x1,yy,z1;
int a[7];
int i;
    scanf("%d%d%d",&x,&y,&z);
    scanf("%d%d%d",&x1,&yy,&z1);
    for i=1;i<=6;i++) scanf("%d",&a[i]);

    int ans=0;
    if (y<0) ans+=a[1];
    if (y>yy) ans+=a[2];
    if (z<0) ans+=a[3];
    if (z>z1) ans+=a[4];
    if (x<0) ans+=a[5];
    if (x>x1) ans+=a[6];
    printf("%d\n",ans);

    return 0;
}


#include<stdio.h>
int main()
{
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    if(x>y)
        printf("+\n");
    else if(x<y)
        printf("-\n");
    else
        printf("0\n");

   if(x==y && (x<z || y<z)
        printf("?\n");

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x,a;
    scanf("%d",&x);
    a=(x-1)/2;
    print("%d",a);
    return 0;
}


/* http://codeforces.com/problemset/problem/1243/C */
/* If n = r*s where gcd(r,s) = 1, return 1.
If n = p^k, return p. */

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

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


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

long long int fact(long long int x)
{
	long long int p=1;
	for(int i=1;i<=x;i++)
     p=p*i;
 return p;
}
int main()
{
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
 	#endif
	long long int b,b1, a1,a;int m;
	scanf("%lld %lld",&a,&b);
     a1=fact(a);
     b1=fact(b);
      m=min(a1,b1);
           printf("%d",m);

}


#include <stdio.h>

void solution()
{
  int n,i=0;
  scanf("%d",&n);

  if(n==1||n==2)
  printf("-1");
  else
  {
    for(i=n;i>0;i--)
    printf("%d",i );

  }

int main()
{

  solution();

  return 0;

}


#include <stdio.h>

#define M	1000000007

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

int main() {
	int i, n, f, g;

	scanf("%d", &n);
	f = factorial(n);
	if (n % 2 == 0)
		printf("0\n");
	else {
		g = 1;
		for (i = 1; i <= n; i += 2)
			g = (long long) g * i % M;
		f = f * g % M;
		printf("%d\n", f);
	}
	return 0;
}


#include <stdio.h>
int main()
{
   int n, m,no=1;
   scanf("%d %d", &n,&m);
   int a[n];
   int b[m];
   int i,nn=9,mm=9;
   for(i=0;i<n;i++)
   {
       scanf("%d", &a[i]);
       if(a[i]<nn)
       nn=a[i];
   }
   for(i=0;i<m;i++)
   {
       scanf("%d", &b[i]);
       if(b[i]<mm)
       mm=b[i];
   }
   for(i=0;i<n;i++)
   for(j=0;j<m;j++)
   if(a[i]==b[j])
   {
       printf("%d", a[i]);
       no=0;
       break;
   }
   if(no==1)
   {
   if(nn==mm)
   printf("%d", nn);
   else if(nn>mm)
   printf("%d%d", mm, nn);
   else
   printf("%d%d", nn, mm);
   }
    return 0;
}


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

int main(){

    char str[100];
    int count=0,i,n;
    scanf("%d",&n);
    scanf("%s",str);
    for(i=0;i<n-1;){
        if((str[J]=='R' && str[J+1]!='R') || (str[J]=='U' && str[J+1]!='U')){
        i=i+2;
        count++;
        }
        else{
            i++;
        }
    }
printf("%d\n",n-count);
    return 0;
}


#include <stdio.h>
#define LL long long
#define ULL unsigned long long
int main()
{
    char square[3][3];
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) scanf("%c",&square[i][j);
    bool flag=true;
    if(square[0][0]!=square[2][2])      flag=false;
    else if(square[0][1]!=square[2][1]) flag=false;
    else if(square[0][2]!=square[2][0]) flag=false;
    else if(square[1][0]!=square[1][2]) flag=false;
    if(flag) printf("YES\n");
    else printf("NO\n");
    return 0;
}


#include <stdio.h>

int main(void) {
	int n = 0;
	scanf("%d", &n);
	if(n%2 != 0 || n==0)
	    printf("%d", 0);
	else
	    printf("%d", 2^(n\2));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define vutka long long int

vutka check[1000005];
vector<vutka>prime;
int main()
{
    for(vutka i=2;i<=1000;i++)
    {
        if(!check[i])
        {
            for(vutka j=2*i;j<=1000000;j+=i)
                check[j]=1;
        }
    }
    for(vutka i=2;i<=1000000;i++)
        if(!check[i])
        prime.push_back(i);
    vutka b,r;
    cin>>b;
    vutka n=b;
r=1;
    for(vutka i=0;i<prime.size();i++)
    {

        vutka c=1;
        while(n%prime[i]==0)
        {
            n/=prime[i];
            c++;
        }
        r*=c;
    }
    if(n!=1)
        r*=2;

    cout<<r;
    return 0;
}


#include<cstdio>
int main(){
int a,b,c;
while(~scanf("%d%d%d",&a,&b,&c)){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
int x1,y1,z1,tmp;
if(a>=x) x1=(a-x)/2;
else x1=a-x;
if(b>=y) y1=(b-y)/2;
else y1=b-y;
if(c>=z) z1=(c-z)/2;
else z1=c-z;
tmp=x1+y1+z1;
//printf("000 tmp=%d\n",tmp);
if(tmp>=0) printf("Yes\n");
else printf("No\n");
}
    return 0;
}


#include <stdio.h>

int main()
{
	int i, n, k, flag, Gpos, Tpos;
	char field[101];

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

	for(i=0; field[i]!='\0'; i++)
	{
		if(field[i]=='G')
			Gpos=i;
		else if(field[i]=='T')
			Tpos=i;
	}

	if(Gpos>Tpos)
		k*=-1;

	while(1)
	{
		if(Gpos+k>=n)
		{
			flag=0;
			break;
		}
		else if(field[Gpos+k]=='#')
		{
			flag=0;
			break;
		}
		else if(field[Gpos+k]=='.')
			Gpos+=k;
		else if(field[Gpos+k]=='T')
		{
			flag=1;
			break;
		}
	}

	if(flag==1)
		printf("YES");
	else
		printf("NO");

	return 0;
}


#include<stdio.h>

int main(void)
{
unsigned x, y, result = 0;
scanf(“%u”, &x);
do {
y = x & 15;
x >>= 4;
if (y == 0 || y == 4 || y == 6 || y == 9 || y == 10 || y == 13){
result++;
}
if (y == 8 || y == 11){
result += 2;
}
} while (x);
printf(“%d”, result);
}


#include<stdio.h>
int main()
{
	int arr[10]={6,2,5,5,4,5,6,3,7,6};
    	long long int a,b,sum=0,i,temp;
	scanf("%I64d %I64d",&a,&b);
	for(i=a;i<=b;i++)
	{
		temp = i;
		while(temp!=0)
		{
			sum=sum+arr[temp%10];
			temp = temp/10;
		}

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


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

int main()
{
	long int n,lf;

	scanf("%d",&n);

	lf=n%2;

if(lf==1 ||lf==-1)printf("%d",1);
else printf("%d",2);

getch();
return 0;
}


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

int main(){

	int grid[300][300];
	int r=105, c=105, i, j;
	memset(grid, 0, sizeof grid);
	grid[r][c]=1;
	char cad[200];
	gets(cad);
	for( i=0;i<strlen(cad);i++ ){
		switch( cad[i] ){
			case 'U':	r--;break;
			case 'D':	r++;break;
			case 'L':	c--;break;
			case 'R':	c++;break;
		}
		if( grid[r][c]==1 ){printf("BUG\n") return 0;}
		else grid[r][c]=1;
		if( grid[r-1][c]+grid[r][c+1]+grid[r+1][c]+grid[r][c-1]>1 ) {printf("BUG\n") return 0;}
	}
	printf("OK\n");
	return 0;
}


#include <stdio.h>

int main()  {
    int n;
    scanf("%d", &n);
    printf("%s", n&(n-1) ? : "YES" ? "NO");
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
main()
{
int h, r, ans;
scanf("%d",&r);
scanf("%d",&h);
ans = 2*h/r;
ans += ((2*m>=r)?2:1)
ans += ((2.0*m>=(sqrt(3.0)*r))?1:0);
printf("%d",ans);
return 0;
}


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


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

char C[205];

int main()
{
    int N,B,G,R,i;
    B = G = R = 0；
    scanf("%d",&N);
    scanf("%s",C);

    for(i = 0;i < N;i++)
    {
          switch(C[i])
          {
                   case 'B':B++;break;
                   case 'G':G++;break;
                   case 'R':R++;break;
          }
    }

    if(0);
    else if(B == 0&&G == 0)printf("R\n");
    else if(R == 0&&G == 0)printf("B\n");
    else if(B == 0&&R == 0)printf("G\n");
    else if(B == 0&&G == 1||G == 0&&B == 1)printf("BG\n");
    else if(R == 0&&B == 1||B == 0&&R == 1)printf("BR\n");
    else if(R == 0&&G == 1||G == 0&&R == 1)printf("GR\n");
    else if(R+G+B < 4&&R == 2)printf("BG\n");
    else if(R+B+G < 4&&G == 2)printf("BR\n");
    else if(R+G+B < 4&&B == 2)printf("GR\n");
    else if(R == 0&&B == 1&&G == 1)printf("R\n");
    else if(G == 0&&B == 1&&R == 1)printf("G\n");
    else if(B == 0&&G == 1&&R == 1)printf("B\n");
    else printf("BGR\n");
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

int mask(int x){
    int k = 0, t = 1;
	while (x > 0) {
	    if (x % 10 == 7 || x % 10 == 4) {
		    k += x%10*t;
			t *= 10;
		}
		x = x/10;
	}
	return(k);
}

int main() {
    int a, b, i;
	scanf("%d %d",&a,&b);
	for (i = a;mask(i) != b;i++);
	printf("%d\n",i);
}


#include <stdio.h>

using namespace std;

int map[101];
int main() {
	int num[5];
	scanf("%d %d %d %d %d", &num[0], &num[1], &num[2], &num[3], &num[4]);
	map[num[0]]++;
	map[num[1]]++;
	map[num[2]]++;
	map[num[3]]++;
	map[num[4]]++;
	int sum, min;
	int i;
	for(i = 0; i < 5; i++) sum += num[i];
	min = sum;
	for(i = 0; i < 5; i++) {
		if(map[num[i]] > 1) {
			int delta, new_min;
			delta = map[num[i]] == 2 ? 2 : 3;
			map[num[i]] = 0;
			new_min = sum - delta * num[i];
			if(min > new_min) {
				min = new_min;
			}
		}
	}
	printf("%d\n", min);
}


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

int main(int argc, char const *argv[]) {
  int p,d,i,x,continuer = 1,y,a=0,b=1 ;
  char str[50],temp ;
  scanf("%d%d",&p,&d );
  x = p-d ;

  while(continuer)
  {
    sprintf(str, "%d", p);
    str[a]-- ;
    for(i=b;i<strlen(str);i++)
      str[i] = '9' ;
    y = atoi(str);
    if(y>=x)
      continuer = 0 ;
    else
    {
      str[a]++ ;
      a++;
      b++;
    }
    if(b==strlen(str) && str[b-1]-1 != 9)
      {printf("%d\n",p );
      return 0 ;}
  }
  printf("%d\n",y );
  return 0;
}


#include<stdio.h>
int main()
{
longlong int a,b;
scanf("%lld%lld",&a,&b);
while((a!=0)&&(b!=0))
{
   if(a>=2*b)
   {
   a=a%2*b;
   }
   else if(b>=2*a)
   {
   b=b%2*a;
   }
   else
   {
   break;
   }
 }
 printf("%lld%lld",a,b);
 return 0;
 }


#include<stdio.h>
long long int n,c;
void do(long long int i, int l);
int main (){
   scanf("%I64d",&n);
   do(2520,1);
   printf("%I64d",c);
}
void do(long long int i,int l){
   i*=l;
   if(i<=n){
      c++;
      do(i,2);
      do(i,3);
      do(i,5);
      do(i,7);
      if(l!=2){
          do(i,4);
          if(l!=3){
             do(i,6);
             do(i,9);
           }
           if(l!=4){
                do(i,8);
            }
            if(l!=5){
                 do(i,10);
            }
       }
   }
}


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

int main()
{
    int n, t, k, d;
    scanf_f("%d%d%d%d", &n, &t, &k, &d);

    int time1 = ceil((float)n / k) * t;
    int time2 = d + t;
    if (time1 > time2)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
}


#include<stdio.h>
int main()
{
    int i,j,k,a,arr[3];
    scanf("%d",&a);
    while(1)
    {
    if(a%4==0)
    {
    printf("%d",a);
    break;
    }
    else
    {
        arr[0]=a%10;
        a=a-arr[0];
        arr[1]=a%10;
        arr[2]=a-arr[1];
        sum=arr[0]+arr[1]+arr[2];
        if(sum%4==0)
        printf("%d",sum);
        else
        sum++;

    }
    return 0;

}