#include<stdio.h>
int main()
{
	int i,a,b,c,k;
	scanf("%d%d%d",&a,&b,&c);
	for(i=1;i<=b;i++)
	{
		k=(a*10)/b;
		a=(a*10)-(k*b);
		if(k==c)
		{
	   printf("%d",i);
	   break;}
	   else
	   continue;
}
if( i==b+1 )
printf("-1");
else
return 0;
}


#include<stdio.h>
int main()
{
long long int n, d,sum=0;
scanf("%lld",&n);
scanf("%lld",&d);
printf("\n");
int i,t[100];
for(i=0;i<n;i++)
{
scanf("%lld",&t[i]);
sum = t[i]+sum;
}
if(sum+(n-1)*10>d)//uske gaane aur resting time ka sum smaller than total time
printf("-1");
else
printf("%d",(d-sum)/5);

return 0;
}


#include<stdio.h>

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

int main() {

	int a,b,c,d,e;

	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	printf("%d",min(a,min(b,min(c/2,min(e/4,d/7)))));

	return 0;
}


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


#include<stdio.h>
int main()
{
    int i,k,max=0,n,arr[1000],str[1000]={};
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        k=arr[i];
        ++str[k];
    }
    for(i=0;i<1000;i++)
    {
        if(str[i]>max)
        max=str[i];
    }
    printf("%d\n",max);
    return 0;
}


#include <stdio.h>

int main(void)
{
  unsigned box[5][5];
  int i,j,k,l,m;
  for(i=0;i<5;i++)
    for(j=0;j<5;j++)
      scanf("%u",&box[i][j]);

  unsigned sum = 0, max =0;
  for(i=0;i<5;i++)
    for(j=0;j<5;j++)
      {
	if(j==i) continue;
	for(k=0;k<5;k++)
	  {
	    if(k == j || k ==i) continue;
	    for(l=0;l<5;l++)
	      {
		if(l == j || l == k || l== i) continue;
		for(m=0;m<5;m++)
		  {
		    if(m==j || m==l || m==k || m==i) continue;
		    sum += box[i][j] + box[j][i] + box[j][k] + box[k][j] + ((box[k][l] + box[l][k] + box[l][m] + box[m][l])<<1);
		    if(sum > max) max = sum;
		    sum = 0;
		  }
	      }
	  }
      }
  printf ("%u\n",max);
  return 0;
}


#include<stdio.h>
#include<math.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
int x = sqrt(  a * b / c );
int z = b / x;
int y = c / z;
int s = 4 * (x + y + z);
printf("%d",s);
return 0;
}


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

int ball[128], n, ans;
void merge(int l, int r, int c)
{
	ans++;
	for ( ; l>=0 && ball[l]==c; l--)
		ans++;
	for ( ; r<n && ball[r]==c; r++)
		ans++;
	if (l==0 && r==n)
		return;
	if (l==0 && r+2<n
	&& ball[r]==ball[r+1] && ball[r]==ball[r+2])
		merge(r, r+2, ball[r]);
	else if (r==n && l>1
	&& ball[l]==ball[l-1] && ball[l]==ball[l-2])
		merge(l-2, l, ball[l]);
	else if (l>0 && ball[l]==ball[r] && ball[l-1]==ball[r])
		merge(l-1, r, ball[l]);
	else if (r<n-1 && ball[l]==ball[r] && ball[l]==ball[r+1])
		merge(l, r+1, ball[l]);

	return;
}

int main(void)
{
	int k, i, max;

	scanf("%d%*d%d", &n, &k);
	for (i=0; i<n; i++)
		scanf("%d", &ball[i]);
	max = 0;
	for (i=0; i<n; i++)
		if (ball[i]==k && ball[i+1]==k) {
			ans = -1;
			merge(i, i+1, k);
			if (ans > max)
				max = ans;
		}
	printf("%d\n", max);

	return 0;
}


#include <stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int arr[n];
    for (int i=0; i<n; i++)
        scanf("%d", &arr[i]);
    if (n%2==1 && arr[0]%2==1 && arr[n-1]%2==1)
        puts("Yes");
    else
        puts("No");
    return 0;
}


#include<stdio.h>
short main(){
char a[102];
int n,d,i=0,jumb=0,j=0,conf=0;
scanf("%d ",&n);
scanf("%d ",&d);
fgets( a,102,stdin);
while(1){
    conf=0;
    if(a[i+d]-48==1){jumb++;i+=d;conf=1;}
    else {
    for(j=d+i-1;j>i;j--)
    if(a[j]-48==1){jumb++;i+=(j-i);conf=1;break;}
    }

    if(conf==0)break;
    if(i==n-1)break;
}

    printf("%d",(conf==0)? -1:jumb);

	return 0;
}


#include<stdio.h>
int main()
{
    long long int n,i,k=0,x,d,r,p;
    scanf("%lld %lld",&n,&p);
    i=1;
    while(k==0)
    {
      d=0;

      x=n-i*p;
      if(x<=0)
      {printf("-1");
       break;
      }
      else
      {
       while(x!=0)
       {
         r=x%2;
         if(r==1)
         {d++;}
         if(d>i)
         {
          break;
         }
         x=x/2;
       }
       x=n-i*p;
       if(d<=i&&i<=x)
       {
        printf("%lld",i);
        break;
       }
      }
      i++;
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int i=1,n,v=2;
    scanf("%d",&n);
    while(1)
    {
        if(i==n)
        {
            printf("YES");
            break;
        }
        else if(i>n)
        {
            printf("NO");
            break;
        }
        else
        {
            i=i+v;
            v++;
        }
    }

    return 0;
}


#include <stdio.h>
#define MOD 1000000007

int K;
long long PA,PB,ans;

long long INV1,INV2;
long long f[1010][2010];

long long power(long long a,int b)
{
    long long y = 1;
    for(;b;b>>=1)
    {
        if(b&1) y = y * a % MOD;
        a = a * a % MOD;
    }
    return y;
}

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

    scanf("%d%I64d%I64d",&K,&PA,&PB);
    INV1 = power(PA+PB,MOD-2);
    INV2 = power(PB,MOD-2);

    f[1][0] = 1;
    for(i=1;i<=K;i++) for(j=(i==1);j<=2*K;j++)
    {
        if(j < K) f[i][j] = f[i-1][j] * PA % MOD * INV1 % MOD;
        if(j >= i && j-i < K) f[i][j] = (f[i][j] + f[i][j-i] * PB % MOD * INV1) % MOD;
    }

    for(i=1;i<K;i++) for(j=K;j<=2*K;j++) ans = (ans + j*f[i][j]) % MOD;
    for(i=0;i<K;i++) ans = (ans + (PA*INV2 + K+i) % MOD * f[K][i]) % MOD;

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


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

#define A	5000
#define N_	(A * 3)
#define INF	0x3f3f3f3f3f3f3f3fLL

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

int oo[1 + (N_ - 1) * 2], oj[1 + (N_ - 1) * 2];

int link(int o, int j) {
	static int _ = 1;

	oo[_] = o, oj[_] = j;
	return _++;
}

int count(int n, int p) {
	return n < p ? 0 : n / p + count(n / p, p);
}

int ae[N_], pp[N_], dd[N_], sz[N_], ii[A + 1], n;

void init() {
	static char composite[A + 1];
	static int primes[A + 1];
	int n_, a, b, cnt, i, j;

	for (a = 2; a <= A / a; a++) {
		if (composite[a])
			continue;
		for (b = a * a; b <= A; b += a)
			composite[b] = 1;
	}
	cnt = 0;
	for (a = 2; a <= A; a++)
		if (!composite[a])
			primes[cnt++] = a;
	n_ = 0;
	pp[n_] = -1, dd[n_] = 0;
	ii[1] = n_++;
	for (a = 2; a <= A; a++) {
		int h, d, d_;

		d = 0;
		for (h = 0; h < cnt; h++)
			d += count(a, primes[h]);
		d_ = 0;
		for (h = cnt - 1; h >= 0; h--) {
			d_ += count(a - 1, primes[h]);
			if (a % primes[h] == 0)
				break;
		}
		i = ii[a - 1], j = -1;
		while (1)
			if (dd[i] > d_)
				j = i, i = pp[i];
			else if (dd[i] == d_) {
				pp[n_] = i, dd[n_] = d, n_++;
				ii[a] = n_ - 1;
				break;
			} else {
				int k = n_++;

				pp[k] = i, dd[k] = d_;
				if (j != -1)
					pp[j] = k;
				pp[n_] = k, dd[n_] = d, n_++;
				ii[a] = n_ - 1;
				break;
			}
	}
	for (j = 1; j < n_; j++) {
		i = pp[j];
		ae[i] = link(ae[i], j), ae[j] = link(ae[j], i);
	}
}

long long dfs1(int p, int i) {
	int o;
	long long x;

	x = (long long) sz[i] * dd[i];
	for (o = ae[i]; o; o = oo[o]) {
		int j = oj[o];

		if (j != p) {
			x += dfs1(i, j);
			sz[i] += sz[j];
		}
	}
	return x;
}

long long ans;

void dfs2(int p, int i, long long x) {
	int o;

	ans = min(ans, x);
	for (o = ae[i]; o; o = oo[o]) {
		int j = oj[o];

		if (j != p) {
			int w = abs(dd[i] - dd[j]);

			dfs2(i, j, x - (long long) sz[j] * w + (long long) (n - sz[j]) * w);
		}
	}
}

int main() {
	int i;

	init();
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		int a;

		scanf("%d", &a);
		sz[ii[a > 0 ? a : 1]]++;
	}
	ans = INF;
	dfs2(-1, 0, dfs1(-1, 0));
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>
#define min(a,b) (a<b?a:b)

int N,val[50005],day=1,mx=1e9+1,id;

int main()
{
	scanf("%d",&N);
	if(N%7==0)
	{
		for(int i=1,u;i<=N;i++)
		{
			scanf("%d",&u);
			if(i%7&&u<mx)mx=u,id=i;
		}
		return printf("%d",id),0;
	}
	for(int i=1,u;i<=N;i++)scanf("%d",val+i),mx=min(mx,val[i]/6);
	for(int i=1;i<=N;i++)val[i]-=mx*6-6;
	while(1)
	{
		for(int i=1;i<=N;i++,day++)
			if(day==7)day=0;
			else if(!--val[i])return printf("%d",i),0;
	}
}


#include<stdio.h>
int main()
{
    __int64 a,b,T=0;
    scanf("%I64d%I64d",&a,&b);
    while (a!=b)
    {
        if (a==0) break;
        if (a<b)
        {
            __int64 tmp=a;
            a=b;
            b=tmp;
        }
        T+=a/b;
        a%=b;
    }
    if (a>0) T++;
    printf("%I64d\n",T);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define MAX 162  // = 9*18
ll x,s,y,Upper_limit,Lower_limit,occ[MAX+2],ans,i;
int isBig(ll a){ll sum=0, tmp=a;
    while(tmp) sum+=tmp%10, tmp/=10;
    return llabs(a-sum)>=s;
}
int main(){
    scanf("%I64d%I64d",&x,&s);
    for(i=1;i<=MAX&&i<=x;i++)
        if(isBig(i)) occ[i]=1;
    Upper_limit = s+MAX;
    Lower_limit = s+1;
    if(x>Upper_limit) ans+=x-Upper_limit;
    for(i=Lower_limit;i<=Upper_limit&&i<=x;i++)
        if(isBig(i))
            if(i<=MAX) occ[i]=1;
            else ans++;
    for(i=1;i<=MAX&&i<=x;i++)
        if(occ[i]) ans++;
    printf("%I64d\n", ans);
}


#include<stdio.h>
int main()
{
    long long int n,m,x;
    scanf("%lld %lld",&n,&m);
    x=m-n;
    if(x>=10){
        printf("0\n");
    }
    else{
           long int temp,total=1,a[x+1];
        for(int i=0;i<x;i++){
            a[i]=m%10;
            m=m-1;
            total=total*a[i];
        }
        //printf("%ld\n",total);
        temp=total%10;
        printf("%ld\n",temp);
    }
    return 0;
}


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

int main()
{
    int k, i, arr[26], start[26], idx = 0, sum = 0, idx2 = 1;
    char q[105];
    scanf("%d", &k);
    scanf("%s", &q);
    memset(arr, 0x00, sizeof(arr));
    memset(start, 0x00, sizeof(start));
    for (i = 0; i < strlen(q); i++){
        if (!arr[q[i] - 'a']) {
            arr[q[i] - 'a']++; sum++;
            start[idx++] = i;
        }
    }
    if (sum < k) printf("NO");
    else {
        printf("YES\n");
        idx = 0;
        while (k--){
            if (k){
                int j = start[idx2++];
                for (i = idx; i < j; i++) printf("%c", q[i]);
            }
            else {
                for (i = idx; i < strlen(q); i++) printf("%c", q[i]);
            }
            idx = i;
            printf("\n");
        }
    }
    printf("\n");
    return 0;
}


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

int main(){
  int i,j,k,l,m,n;
  int x1, x2, a, b, fg, fgg;
  int mod;
  int stone;

  while(scanf("%d%d%d%d",&x1,&x2,&a,&b)==4){
    stone = x2 - x1;
    fg = 0;
    if(stone < 0) stone *= -1, k = a, a = b, b = k, a *= -1, b *= -1, fg = 1;
    if(b <= 0){ puts("DRAW"); continue; }

    fgg = 0;
    if(a <= 0) fgg = 1, a = 1;
    mod = stone % (a+b);
    if(mod == 0){
      if(fgg) puts("DRAW"); else puts("SECOND");
      continue;
    }
    if(mod < a || mod > b){
      puts("DRAW");
      continue;
    }

    if(stone > b && fgg){
      puts("DRAW");
      continue;
    }

    stone -= mod;
    puts("FIRST");
    if(fg==0) printf("%d\n",x2-stone);
    else      printf("%d\n",x2+stone);
  }

  return 0;
}


#include <stdio.h>

int main(){

	int n,m;
	scanf("%d %d",&n,&m);
	int b;
	if(n>m){
		b=n;
		n=m;
		m=b;
	}
	if(n==1){
		int mo=m%6;
		switch(mo){
			case 0:printf("%d\n",m);break;
			case 1:printf("%d\n",m-mo);break;
			case 2:printf("%d\n",m-mo);break;
			case 3:printf("%d\n",m-mo);break;
			case 4:printf("%d\n",m-2);break;
			case 5:printf("%d\n",m-1);
		}
	}
	else if(n==2){
		if(m==2){
			printf("%d\n",0);
		}
		else if(m==3){
			printf("%d\n",4);
		}
		else if(m==7){
			printf("%d\n",12);
		}
		else{
			printf("%d\n",n*m);
		}
	}
	else{
		long long mul=n;
		mul*=m;
		if(mul%2==0){
			printf("%lld\n",mul);
		}
		else{
			printf("%lld\n",mul-1);
		}
	}

	return 0;
}


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

int main()
{
        int a, n;
        while(scanf("%d%d", &n, &a) > 0)
        {
                int c[n+1];
                int i = 1;
                int num = 0;
                while(i < n + 1)
                {
                        scanf("%d", &c[i++]);
                }
                i = 1;
                while(i < n + 1)
                {
                        if (c[i])
                        {
                                num++;
                                if (a - abs(a-i) > 0 && a + abs(a-i) <= n && (c[a - abs(a-i)] + c[a + abs(a-i)]) == 1)
                                {
                                        num--;
                                }
                        }
                        i++;
                }
                printf("%d\n", num);
        }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned long ulong;

long long int sort(long long int a[] , int n){
    long long int tmp = 0;
    for(ll  i = 1 ; i < n ; i++)
        {
            for(ll j = i ; j < n ; j++){
                if(a[i] > a[j]){
                    tmp = a[j];
                    a[j] = a[i];
                    a[i] = tmp;
                }
            }

        }
}

long long int min(long long int a , long long int b){
    if(a > b)
        return b;
    return a;
}
#define For(i, n) for(i=0;i<(n);++i)
#define ForL(i, m, n) for(i=(m);i<(n);++i)

#define Clear(X) memset( (X), 0, sizeof( (X) ) )
#define Fill(X) memset( (X), -1, sizeof( (X) ) )

#define ArraySize(X) (sizeof(X)/sizeof(X[0]))

void _main();

int main() {
  // COUNTER CODE STARTS HERE
  _main();
  // COUNTER CODE ENDS HERE

  return 0;
}

// ACTUAL CODE STARTS BELOW

ll a, b, c, l;
ll ans = 0;

ll exclude(ll a, ll b, ll c, ll r) {
  if (a < b + c) return 0;
  ll v = min(r, a - b - c);
  return ((v + 1) * (v + 2)) >> 1;

}

void _main() {
    scanf("%d %d %d %d", &a , &b , &c , &l);
  for (ll i = 0; i <= l; ++i) {
    ans += (((i + 1) * (i + 2)) >> 1);
  }

  for (ll i = 0; i <= l; ++i) {
    ans -= exclude(a + i, b, c, l - i);
    ans -= exclude(b + i, a, c, l - i);
    ans -= exclude(c + i, b, a, l - i);
  }
    printf("%I64d\n", ans);
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char a[105];
int judge(int );
int max(int ,int );
int max(int x,int y)
{
    return (x>y)?x:y;
}
int judge(int n)
{
    int i,p=1;
    for(i=0;i<n&&p;i++)
    {
        if(a[i]!=a[i+n])
        {
            p=0;
        }
    }
    return p;
}
int main()
{
    int n,i,ans=0;
    scanf("%d%s",&n,a);
    i=n/2+1;
    while(1)
    {
        if(judge(i)==1)
        {
            ans=max(ans,i-1);
        }
        i--;
        if(i==0)
        {
            break;
        }
    }
    printf("%d\n",n-ans);
    return 0;
}


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

int ***sol;
int N, K;
const int kInvalidSol = -10000;
void new_sol() {
	sol = (int***)malloc(sizeof(int**) * (N + 1));
	for (int n = 0; n <= N; ++n) {
		sol[n] = (int**)malloc(sizeof(int*) * (K + 1));
		for (int k = 0; k <= K; ++k) {
			sol[n][k] = (int*)malloc(sizeof(int) * (N + 1));
			for (int i = 0; i <= N; ++i) {
				sol[n][k][i] = kInvalidSol;
			}
		}
	}
}
void free_sol() {
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= K; ++j) {
			free(sol[i][j]);
		}
		free(sol[i]);
	}
	free(sol);
}
void try_update_sol(int n, int k, int i, int value) {
	if (value >= 0 && sol[n][k][i] < value) {
		sol[n][k][i] = value;
	}
}
int main() {
	char s[201], t[3];
	scanf("%d%d\n%s\n%s", &N, &K, s, t);

	if (t[0] == t[1]) {
		int cc = 0;
		for (int i = 0; i < N; ++i) {
			if (s[i] == t[0]) {
				++cc;
			}
		}
		cc += K;
		if (cc > N) {
			cc = N;
		}
		printf("%d\n", cc * (cc - 1) / 2);
		return 0;
	}
	new_sol();
	int t0 = 0;
	sol[0][0][0] = 0;
	for (int n = 1; n <= N; ++n) {
		if (s[n - 1] == t[0]) {
			++t0;
			if (t0 == 1) {
				sol[n][0][1] = 0;
			} else {
				try_update_sol(n, 0, t0, sol[n - 1][0][t0 - 1]);
			}
		} else if (s[n - 1] == t[1]) {
			try_update_sol(n, 0, t0, sol[n - 1][0][t0] + t0);
		} else {
			try_update_sol(n, 0, t0, sol[n - 1][0][t0]);
		}
		// for (int k = cc; k <= K; ++k) {
		// 	try_update_sol(n, k, 0, 0);
		// }
	}
	for (int k = 1; k <= K; ++k) {
		try_update_sol(1, k, 1, 0);
		for (int n = 2; n <= N; ++n) {
			for (int i = 1; i <= n; ++i) {
				try_update_sol(n, k, i, sol[n][k - 1][i]);
				if (s[n - 1] == t[0]) {
					try_update_sol(n, k, i, sol[n - 1][k][i - 1]);
					try_update_sol(n, k, i, sol[n - 1][k - 1][i] + i);
				} else if (s[n - 1] == t[1]) {
					try_update_sol(n, k, i, sol[n - 1][k][i] + i);
					try_update_sol(n, k, i, sol[n - 1][k - 1][i - 1]);
				} else {
					try_update_sol(n, k, i, sol[n - 1][k - 1][i - 1]);
					try_update_sol(n, k, i, sol[n - 1][k - 1][i] + i);
					try_update_sol(n, k, i, sol[n - 1][k][i]);
				}
			}
		}
	}
	int max = 0;
	for (int i = 1; i <= N; ++i) {
		if (sol[N][K][i] > max) {
			max = sol[N][K][i];
		}
	}
	printf("%d\n", max);
	free_sol();
	return 0;
}


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

#define MAX_STRING_LEN 100000

int main()
{

  char S[MAX_STRING_LEN];
  int l, i,b=0,c,d=0;
  scanf("%d%s",&i,&S);
  for(c=0;c<i;c++)
  {
  	if(S[c]=='F')
  		if(S[c+1]=='S')
  			d++;
  	if(S[c]=='S')
  		if(S[c+1]=='F')
  			b++;
  }

  if(b<=d)
  	printf("NO");
  else
  	printf("YES");
  return 0;
}


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

int f[80][80][80][2];
int posV[80], posK[80], posX[80];
int cntV[80], cntK[80], cntX[80];
int NewDist(int pos, int nV, int nK, int nX) {
	int newPos;
	newPos = 0;
	newPos += nV > cntV[pos - 1] ? nV : cntV[pos - 1];
	newPos += nK > cntK[pos - 1] ? nK : cntK[pos - 1];
	newPos += nX > cntX[pos - 1] ? nX : cntX[pos - 1];
	return newPos - (nV + nK + nX);
}

int main(int argc, char *argv[]) {
	int n, nV, nK, nX, i, j, k, t;
	char str[80];
	scanf("%d\n%s", &n, str + 1);
	for (i = 1, nV = nK = nX = 0; i <= n; ++i) {
		cntV[i] = cntV[i - 1];
		cntK[i] = cntK[i - 1];
		cntX[i] = cntX[i - 1];
		if (str[i] == 'V') ++cntV[posV[++nV] = i];
		else if (str[i] == 'K') ++cntK[posK[++nK] = i];
		else ++cntX[posX[++nX] = i];
	}
	memset(f, 0x70, sizeof(f));
	f[0][0][0][0] = 0;
	for (i = 0; i <= nV; ++i)
		for (j = 0; j <= nK; ++j)
			for (k = 0; k <= nX; ++k) {
				if (i) {
					t = f[i - 1][j][k][0] + NewDist(posV[i], i - 1, j, k);
					if (t < f[i][j][k][1]) f[i][j][k][1] = t;
					t = f[i - 1][j][k][1] + NewDist(posV[i], i - 1, j, k);
					if (t < f[i][j][k][1]) f[i][j][k][1] = t;
				}
				if (j) {
					t = f[i][j - 1][k][0] + NewDist(posK[j], i, j - 1, k);
					if (t < f[i][j][k][0]) f[i][j][k][0] = t;
				}
				if (k) {
					t = f[i][j][k - 1][0] + NewDist(posX[k], i, j, k - 1);
					if (t < f[i][j][k][0]) f[i][j][k][0] = t;
					t = f[i][j][k - 1][1] + NewDist(posX[k], i, j, k - 1);
					if (t < f[i][j][k][0]) f[i][j][k][0] = t;
				}
			}
	if (f[nV][nK][nX][0] < f[nV][nK][nX][1]) printf("%d\n", f[nV][nK][nX][0]);
	else printf("%d\n", f[nV][nK][nX][1]);
	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 A,B;
	scanf("%d%d",&A,&B);
	int a2=0,b2=0,a3=0,b3=0,a5=0,b5=0;
	bool flag=false;
	while(flag==false)
	{
		if(A%2==0)
		{
			A/=2;
			a2++;
		}
		if(A%3==0)
		{
			A/=3;
			a3++;
		}
		if(A%5==0)
		{
			A/=5;
			a5++;
		}
		if(B%2==0)
		{
			B/=2;
			b2++;
		}
		if(B%3==0)
		{
			B/=3;
			b3++;
		}
		if(B%5==0)
		{
			B/=5;
			b5++;
		}
		if(A%2!=0 && B%2!=0 && A%3!=0 && B%3!=0 && A%5!=0 && B%5!=0)
		{
			flag=true;
		}

	}
	printf("%d",(A!=B?-1:(abs(a2-b2)+abs(a3-b3)+abs(a5-b5))));

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define MAX(a, b) ((a) < (b) ? (b) : (a))

static int n;
static int B;
static int A[100];
// D[c][b] = best number of cuts with last cut being at position y and while
// spending x bitcoins. Cut at position 0 = dummy base
static int D[100][101];
static int neven[101];

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

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

        neven[0] = 0;
        for (i = 1; i <= n; i++)
                neven[i] = neven[i-1] + !(A[i-1] & 1);

        D[0][0] = 0;
        for (i = 1; i < n; i++) {  // for cut position
                int b = abs(A[i] - A[i-1]); // cost of cut
                for (j = 0; j < i; j++) {  // for last cut position
                        if (neven[i] - neven[j] !=
                                i - j - (neven[i] - neven[j]))
                                continue;

                        for (k = 0; k <= B - b; k++)
                                D[i][k+b] = MAX(D[i][k+b], D[j][k] + 1);
                }
        }

        int best = 0;
        for (i = 0; i < n; i++) {
                /*
                printf("Maybe %d? n=%d, neven[n] - neven[i] = %d\n",
                       i, n, neven[n] - neven[i]);
                       */
                if (neven[n] - neven[i] != n - i - (neven[n] - neven[i]))
                        continue;
                /*
                printf("HERE: %d\n", D[i][k]);
                */
                for (k = 0; k <= B; k++)
                        best = MAX(best, D[i][k]);
        }

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

        return 0;
}


/*
 ============================================================================
 Name        : trial.c
 Author      : zizo
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

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

int main()
{
	int numofFirst,numofSec,min1,min2,i,j;
	scanf("%d%d",&numofFirst,&numofSec);

	int firsRow[numofFirst],secRow[numofSec];
	scanf("%d",&firsRow[0]);
	min1=firsRow[0];
	for(i=1;i<numofFirst;i++){
		scanf("%d",&firsRow[i]);
		if(firsRow[i]<min1){
			min1=firsRow[i];
		}
	}
	scanf("%d",&secRow[0]);
	min2=secRow[0];
	for(i=1;i<numofSec;i++){
		scanf("%d",&secRow[i]);
		if(secRow[i]<min2){
			min2=secRow[i];
		}
	}

	for (i=0;i<numofFirst;i++){
		for(j=0;j<numofSec;j++){
			if(secRow[j]==firsRow[i]){
				if(min1==min2 && min1 <firsRow[i]){
					printf("%d",min1);
				}else{
					printf("%d",firsRow[i]);
				}
				return 0;
				}
		}
	}

	if(min1==min2){
		printf("%d",min1);
	}else if(min1<min2){
		//if min1 is found in array1 pint min 1
			printf("%d%d",min1,min2);
	}else{
		printf("%d%d",min2,min1);
	}

/*
 *
9 1

5 4 2 3 6 1 7 9 8

9
 *
 */

}


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

#include"stdio.h"
#include"stdlib.h"
#include"ctype.h"
#include"math.h"
#include"string.h"
struct element{
	int val;
	int indx;
};
struct person{
	int id;
	int n;
	int op[100];
};
struct farmer{
	int p;
	int c;
};
void inc(int *a,int n){
	int i;
	if(a[0]!=2){
		a[0]++;
		return;
	}
	for(i=0;i<n && a[i]==2;i++)
		a[i]=0;
	if(i<n)
		a[i]++;
}
int cmp(char *s,char *t){
	int n=strlen(s);
	int m=strlen(t);
	int i,j;
	for(i=0,j=0;i<n && j<m && s[i]==t[j];i++,j++);
	if(s[i]>t[j])
		return 1;
	else if(s[i]<t[j])
		return -1;
	else
		return 0;

}
int getword(char *s,int n){
	int i;
	char c;
	while(isspace(c=getchar()));
	for(i=0;i<n && !isspace(c);i++,c=getchar())
		s[i]=c;
	s[i++]='\0';
	return i-1;
}
int fgetword(char *s,int n,FILE *fp){
	int i;
	char c;
	while(isspace(c=getc(fp)));
	for(i=0;i<n && !isspace(c) && c!=EOF;i++,c=getc(fp))
		s[i]=c;
	s[i++]='\0';
	return i-1;
}
long long atll(char *s){
	long long n=0;
	int i;
	for(i=0;s[i]!='\0';i++){
		n*=10;
		n+=(s[i]-'0');
	}
	return n;
}
int Bsear(char *s,char words[][13],int n){
	int l=0;
	int h=n;
	int mid;
	while(l<h){
		mid=(l+h)/2;
		if(cmp(words[mid],s)==0)
			return 1;
		else if(cmp(words[mid],s)==1){
			h=mid;
		}else
			l=mid+1;
	}
	return -1;
}
void func(int *n,int base,int num){
	int i=0;
	while(num/base!=0){
		n[i++]=num%base;
		num/=base;
	}
	n[i++]=num;
	n[i++]=20;
}
int pal(int *n){
	int i,j;
	for(i=0;n[i]!=20;i++);
	for(j=0;j<i/2 && n[j]==n[i-j-1];j++);
	if(j==i/2)
		return 1;
	return 0;
}
int ispal(char *s, int i, int j){
	int k;
	for(k=0;k<((j-i+1)/2) && s[i+k]==s[j-k];k++);
	if(k==(j-i+1)/2)
		return 1;
	return 0;
}
void insort(int *a,int n){
	int i,j,temp;
	for(i=1;i<n;i++){
		j=i;
		while(j>0 && a[j]<a[j-1]){
			temp=a[j-1];
			a[j-1]=a[j];
			a[j]=temp;
			j--;
		}
	}
}
char lower(char c){
	return c<'a'?c+('a'-'A'):c;
}
void merge(struct element *a,int l,int q,int n){
	int n1=q-l+1;
	int i,j,k;
	int n2=n-q;
	struct element L[n1+1];
	struct element R[n2+1];
	for(i=0;i<n1;i++)
		L[i]=a[l+i];
	for(i=0;i<n2;i++)
		R[i]=a[q+i+1];
	L[n1].val=100002;
	R[n2].val=100002;
	i=0;
	j=0;
	for(k=l;k<=n;k++)
		if(L[i].val<=R[j].val){
			a[k]=L[i];
			i++;
		}else{
			a[k]=R[j];
			j++;
		}
}
void mergesort(struct element *a,int l,int n){
	if(n>l){
		int q=(l+n)/2;
		mergesort(a,l,q);
		mergesort(a,q+1,n);
		merge(a,l,q,n);
	}
}
int isOkay(int a,int *s , int n){
	if(a<100 || a>=1000)
		return 0;
	int c,i;
	while(a/10>0){
		c=0;
		for(i=0;i<n;i++)
			if(a%10==(s[i]-'0')){
				c=1;
				break;
			}
		if(!c)
			return 0;
		a/=10;
	}
	c=0;
	for(i=0;i<n;i++)
		if(a==(s[i]-'0')){
			c=1;
			break;
		}
	if(c)
		return 1;
	return 0;
}
int isOkay2(int a,int *s , int n){
	if(a<1000 || a>=10000)
		return 0;
	int c,i;
	while(a/10>0){
		c=0;
		for(i=0;i<n;i++)
			if(a%10==(s[i]-'0')){
				c=1;
				break;
			}
		if(!c)
			return 0;
		a/=10;
	}
	c=0;
	for(i=0;i<n;i++)
		if(a==(s[i]-'0')){
			c=1;
			break;
		}
	if(c)
		return 1;
	return 0;
}
void sort(int *a,int n){
	int i,j,temp;
	for(i=1;i<n;i++)
		for(j=i;j>0 && a[j-1]>a[j];j--){
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;

		}
}
void fun(int n,char *s){
	int i=0;
	for(i=0;n/10!=0;i++,n/=10)
		s[i]=n%10+'0';
	s[i++]=n+'0';
	s[i]='\0';
}
void sortIn(int *a,int *indx,int n){
	int t1;
	int i,j;
	for(i=1;i<n;i++)
		for(j=i;j>0 && a[j-1]>a[j];j--){
			t1=a[j-1];
			a[j-1]=a[j];
			a[j]=t1;
			t1=indx[j-1];
			indx[j-1]=indx[j];
			indx[j]=t1;
		}
}
int valid(int *a,int l,int r,int n){
	int f=0;
	if(l>0 && a[l-1]>a[r])
		f=1;
	if(a[l+1]<a[r])
		f=1;
	if(a[r-1]>a[l])
		f=1;
	if(r<n-1 && a[r+1]<a[l])
		f=1;
	if(f)
		return 0;
	return 1;
}
main(){
	char s[200];
	getword(s,200);
	long long p=atll(s);
	getword(s,200);
	long long d=atll(s);
	long long a=1;
	long long temp=p;
	int max=0;
	while(temp/10!=0 && temp%10==9){
		max++;
		temp/=10;
	}
	//printf("%d ",max);
	int i;
	for(i=0;p/a!=0;i++){
		a*=10;
		if(p%a>=d)
			break;
	}
	if(i==0){
		printf("%I64d",p);
		return 0;
	}else if(max>=i){
		printf("%I64d",p);
		return 0;
	}
	p-=(a/10);
	if(p/(a/10)>0)
		printf("%I64d",p/(a/10));
	for(;i>0;i--)
		printf("%d",9);
	return 0;
}


#include<stdio.h>
int main()
{
	long int x,y,x1,x2,y1,y2,i,j;
	scanf("%ld%ld",&x,&y);
	if(x>0&&y>0)
	{
		printf("%ld %ld %ld %ld\n",0,x+y,x+y,0);
	}
	else if(x<0&&y<0)
	{
		printf("%ld %ld %ld %ld\n",x+y,0,0,x+y);
	}
	else if(x>0&&y<0)
	{
		printf("%ld %ld %ld %ld\n",0,y-x,x-y,0);
	}
	else
	{
		printf("%ld %ld %ld %ld\n",x-y,0,0,y-x);
	}
	return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    double ax,ay,bx,by,cx,cy;
    double d1,d2;
    scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&cx,&cy);
    d1=(ay-by)*(ay-by)+(bx-ax)*(bx-ax);
    d2=(cy-by)*(cy-by)+(cx-bx)*(cx-bx);
    if(((ay-by)/(ax-bx)==(cy-by)/(cx-bx)||(ax==bx&&bx==cx)))
        printf("No\n");
    else
    {
        if(d1==d2)
            printf("Yes\n");
        else printf("No\n");
    }

    return 0;
}


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

}
printf("1%d",sb);
return 0;
}


#include<stdio.h>
int swap(int* a,int* b)
{
	int c;
	c = *a;
	*a = *b;
	*b = c;
}
int main()
{
	int count;
	int store;
	int arr[3];

	scanf("%d%d",&count,&store);

	int c = store;
	for(int i=0;i<3;i++)
	{
		arr[i] == i;
	}

	int j,k;
	j = c;

	if(count % 6 == 0)
	{
		if(j == 0)
		{
			arr[j] = 0;
		}

		else if(j == 1)
		{
			arr[j] = 1;
		}

		else if(j == 2)
		{
			arr[j] = 2;
		}

	}

	else if(count % 6 == 1)
	{
		if(j == 0)
		{
			arr[j] = 1;
		}
		else if(j == 1)
		{
			arr[j] = 0;
		}
		else if(j == 2)
		{
			arr[j] = 2;
		}

	}

	else if(count % 6 == 2)
	{
		if(j == 0)
		{
			arr[j] = 1;
		}
		else if(j == 1)
		{
			arr[j] = 2;
		}
		else if(j == 2)
		{
			arr[j] = 0;
		}
	}

	else if(count % 6 == 3)
	{
		if(j == 0)
		{
			arr[j] = 2;
		}
		else if(j == 1)
		{
			arr[j] = 1;
		}

		else if(j == 2)
		{
			arr[j] = 0;
		}
	}

	else if(count % 6 == 4)
	{
		if(j == 0)
		{
			arr[j] = 2;
		}

		else if(j == 1)
		{
			arr[j] = 0;
		}
		else if(j == 2)
		{
			arr[j] = 1;
		}

	}

	else if(count % 6 == 5)
	{
		if(j == 0)
		{
			arr[j] = 0;
		}

		else if(j == 1)
		{
			arr[j] = 2;
		}

		else if(j == 2)
		{
			arr[j] = 1;
		}
	}

/*	while(count > 0)
	{
		if(count % 2 == 0)
		{
			swap(&arr[1],&arr[2]);
			if(j == 2)
			{
				j = 1;
			}

			else if(j == 1)
			{
				j = 2;
			}
			count = count - 1;
			k = j - 1;
			swap(&arr[j],&arr[k]);
			count = count - 1;
			j = k;
		}

		else
		{
			swap(&arr[0],&arr[1]);
			if(j == 1)
			{
				j = 0;
			}

			else if(j == 0)
			{
				j = 1;
			}
			count = count - 1;

			k = j + 1;
			swap(&arr[j],&arr[k]);
			count = count - 1;
			j = k;
		}

	}*/

	printf("%d\n",arr[j]);

	return 0;
}


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

int main()
{
    int vR=0,vG=0,vB=0,vY=0,i,j,cpt=0;
    char a='l',ch[100];
    scanf("%s",&ch);

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

         a='l';
        cpt=0;
        for(j=i+4;j<strlen(ch);j+=4){
             if(ch[i]=='!'){
            switch(ch[j]){
            case 'R':a='R';break;
            case 'G':a='G';break;
            case 'B':a='B';break;
            case 'Y':a='Y';break;
            case '!':cpt++;break;

                   }

             }

            else{
                    if(ch[j]=='!'){
                    switch(ch[i]){
            case 'R':vR++;break;
            case 'G':vG++;break;
            case 'B':vB++;break;
            case 'Y':vY++;break;
                    }}}

            }

switch (a)
        {
        case 'R':
            vR=vR+cpt+1;
            break;
        case 'Y':
            vY=vY+cpt+1;
            break;
        case 'B':
            vB=vB+cpt+1;
            break;
        case 'G':
            vG=vG+cpt+1;
            break;
        }

    }
    printf("%d %d %d %d",vR,vB,vY,vG);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
	   return ( *(int*)a - *(int*)b );
}
int main()
{
	int m,i,a[104],x,y,s,t=0;
	scanf("%d",&m);
	t=0;
	for(i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		t=t+a[i];
	}
	scanf("%d %d",&x,&y);
//	qsort(a,m,sizeof(int),cmpfunc);
	s=0;
	for(i=1;i<=m;i++)
	{
	//	printf("%d ",a[i]);
		s=s+a[i];
		if(s>=x && s<=y && t-s>=x && t-s<=y && i!=0)
		{
			printf("%d",i+1);
			return 0;
		}
	}
	printf("0");
	return 0;
}


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

#define N 100

int main() {
	static char s[N + 1], t[N + 1];

	scanf("%s%s", s, t);
	printf("%s\n", strcmp(s, t) == 0 ? s : "1");
	return 0;
}


#include<stdio.h>
#include<math.h>
typedef long long ll;

ll get(ll n){
    ll rem = 0 , dig;
 while(n > 9) {
         rem = n % 10;
         n  = n / 10;
         n = n + rem;
        }
return n;
}

int main(){
    ll n;
    scanf("%lld",&n);

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

return 0;
}


#include<stdio.h>
#include<stdlib.h>
main()
{
       long int n,i,sum=0;
      scanf ("%d",&n);

      if (n != 1)
      {
      for (i=1;i<=n-1;i++)
      sum += i;
      sum  = 2*6*sum+1;
      printf("%d",sum);
      }
      else
      printf("1");
      return 0;
}


#include<stdio.h>
int main()
{
    int n,a[105],i,sum=0,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }

    for(i=1;i<=5;i++)
    {

        if((sum+i)%(n+1)!=1){
            count++;
        }
    }
    printf("%d",count);
}


#include<stdio.h>
#define MOD 1000000007

int dar[252][252], k, n, fact[252], inv[252], precomp[2][252];

int add(int a, int b){
  a += b;
  if(a >= MOD)a -= MOD;
  return a;
}

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}
int powmod(int base, long long p){
  int toret = 1;
  while(p){
    if(p&1)toret = mul(toret, base);
    base = mul(base, base);
    p >>= 1;
  }
  return toret;
}

int ncr(int n, int r){
  return mul(mul(fact[n], inv[r]), inv[n - r]);
}

int dp(int r, int c){
  //  printf("dp(%d, %d)\n", r, c);
  if(dar[r][c] == -1){
    int toret = 0;
    if(r == 0){
      dar[r][c] = (c == 0);
      return dar[r][c];
    }

    int sat = n - c;
    int i;
    for(i = 0;i <= c;i++)if(i + sat){
      int f1 = precomp[0][c - i];
      f1 = mul(f1, ncr(c, i));
      int f2 = precomp[1][sat];
      if(i == 0){
	f2 = add(f2, MOD - precomp[0][sat]);
      }
      toret = add(toret, mul(dp(r - 1, c - i), mul(f1, f2)));
    }
    dar[r][c] = toret;
  }
  return dar[r][c];
}

int main(){
  scanf("%d %d", &n, &k);
  if(k == 1){
    printf("1\n");
    return 0;
  }
  int i,j;
  fact[0] = 1;
  inv[0] = 1;
  precomp[0][0] = precomp[1][0] = 1;
  for(i = 1;i < 252;i++){
    fact[i] = mul(fact[i - 1], i);
    inv[i] = powmod(fact[i], MOD - 2);
    precomp[0][i] = powmod(k - 1, i);
    precomp[1][i] = powmod(k, i);
  }
  for(i = 0;i <= n;i++)for(j = 0;j <= n;j++){
      dar[i][j] = -1;
    }
  printf("%d\n", dp(n, n));
  return 0;
}


#include<stdio.h>
#include<math.h>
int min(int,int);
int main()
{
    int i,t,n,p,l,r,count1,count2,s,x,y,z;
    scanf("%d %d %d %d",&n,&p,&l,&r);
    if((l==1)&&(r==n))
        printf("0");
    else
    {
        if(l==1)
        {
            if(r<p)
                s=p-r+1;
            else
                s=r-p+1;
        }
        else if(r==n)
            s=(abs(p-l)+1);
        else
        {
            count1=(abs(r-p)+1+(r-l+1));
            count2=(abs(p-l)+1+(r-l+1));
            s=min(count1,count2);
        }
        printf("%d",s);
    }
return 0;
}
int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}


#include<stdio.h>

int main(){

    int x, a, b, y, z;

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

    x = a+b;

    if(x%2 == 0){

    	y = z = x/2;
    }
    else{

    	y = x/2;

    	z = y + 1;
    }

    if(a == 0 && b == 0) printf("NO\n");
    else if(a == y && b == z||a == z&& b == y ) printf("YES\n");
    else printf("NO\n");

	return 0;
}


#include<stdio.h>
main()
{
      int a,b,c;
      scanf("%d %d %d",&a,&b,&c);
      printf("%d",((a-1)*(b+c-1)+(b*c)));
      return 0;
}


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

int main()
{
    long n,x,y,t;
    long sum;
    scanf("%ld%ld%ld",&n,&x,&y);
    sum=n*y;
    if(sum%100==0)
      t=sum/100;
    else
      t=sum/100+1;
    t-=x;
    if(t<0) t=0;
    printf("%ld",t);
    return 0;
}


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

int n;
scanf("%d",&n);
int gap=1,sum=1,count=1;
while(count<n)
{
    count++;//printf("count = %d\n",count);
    gap=4*(count-1);//printf("gap %d\n",gap);
    sum=sum+gap;//printf("%d\n",sum);
}
printf("%d\n",sum);

}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int i,j,k,l,m,temp,res=0,max=0;
    char s[300],in[10];
    scanf("%s",s);
    scanf("%d",&k);
    l=strlen(s);
    if(k>=l)
        printf("%d\n",((k+l)/2)*2);
    else
    {
        for(i=0;i<l-k;i++)
        {
            for(j=(l+k-i)/2;j>=1;j--)
            {
                temp=0;
                for(m=i;m<i+j;m++)
                {
                    if(m+j>=l)
                        break;
                    if(s[m]!=s[m+j])
                    {temp=-1;break;}
                }
                if(temp==0 && j>max)
                    max=j;
                //printf("%d %d %d %d\n",i,j,temp,max);
            }

        }
        if(max>k)
            printf("%d\n",2*max);
        else
            printf("%d\n",2*k);
    }
    return 0;
}


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

#define D	6720

int compare(const void *a, const void *b) {
	long long ia = *(long long *) a;
	long long ib = *(long long *) b;

	return ia == ib ? 0 : (ia < ib ? -1 : 1);
}

int main() {
	static long long aa[D];
	long long x, y, a, tmp, cnt;
	int k, i;

	scanf("%lld%lld\n", &x, &y);
	k = 0;
	for (a = 1; a * a <= x; a++)
		if (x % a == 0) {
			aa[k++] = a;
			if (x / a != a)
				aa[k++] = x / a;
		}
	srand(time(NULL));
	for (i = k - 1; i > 0; i--) {
		int i_ = rand() % (i + 1);

		tmp = aa[i], aa[i] = aa[i_], aa[i_] = tmp;
	}
	qsort(aa, k, sizeof *aa, compare);
	for (i = k - 1; i >= 0; i--)
		if (y % aa[i] == 0)
			break;
	cnt = 0;
	while (y > 0) {
		int j, jmin;
		long long min;

		min = 1e12 + 1;
		jmin = -1;
		for (j = i + 1; j < k; j++)
			if (aa[j] % aa[i] == 0 && min > (y % aa[j]) / aa[i]) {
				min = (y % aa[j]) / aa[i];
				jmin = j;
			}
		if (aa[i] == x)
			min = y / x;
		cnt += min;
		y -= min * aa[i];
		i = jmin;
	}
	printf("%lld\n", cnt);
	return 0;
}


#include<stdio.h>
int main()
{
    int a1,b1,c1,a2,b2,c2;
    scanf("%d%d%d",&a1,&b1,&c1);
    scanf("%d%d%d",&a2,&b2,&c2);
    if(a1==a2 || b1==b2 || c1==c2)
        printf("YES");
    else
    printf("NO");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
long long ans,s,x;
int max,k,n1,n2,i,j,a[100],b[100],c[100];
int main(int argc, char *argv[]) {
	scanf("%I64d%I64d",&s,&x);
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	n1=0;n2=0;
	while(s!=0)
	{
	a[n1]=s%2;
	s=s/2;
	n1++;
	}
	while(x!=0)
	{
	b[n2]=x%2;
	x=x/2;
	n2++;
	}

	j=0;
	k=0;
	ans=1;
	while(j<=n1||j<=n2)
	{
	if(k==0)
	  {
	  if(b[j]!=a[j]) {ans=0;break;}
	  if(b[j]==1) {c[j]=2;k=0;}
	  if(b[j]==0)
	    {
		if(a[j+1]==b[j+1])
		  {c[j]=0;k=0;}
		else
		  {c[j]=1;k=1;}
		}
	  }
	else
	  {
	  if(b[j]==a[j]) {ans=0;break;}
	  if(b[j]==1) {c[j]=2;k=1;}
	  if(b[j]==0)
	    {
		if(a[j+1]==b[j+1])
		  {c[j]=0;k=0;}
		else
		  {c[j]=1;k=1;}
		}

	  }
	j++;
	}
	if(ans==0)
	printf("%I64d\n",ans);
	else
	{
		i=0;j=0;
		while(j<=n1||j<=n2)
		{
		if(c[j]==2)
		ans*=2;
		if(c[j]==1)
		i=1;
		j++;
		}
	if(i==0&&ans>=2)
	ans=ans-2;
	printf("%I64d\n",ans);

	}

	return 0;
}


/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:03/04/2019
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>

int main()
{

    long long t=1;
    //scanf("%lld",&t);
    while(t--)
    {
       long long n,ans,min=32;
       scanf("%lld",&n);
       int arr[n];
       for(int i=0;i<n;i++)
       {
           scanf("%d",&arr[i]);
           if(min>arr[i])
                min=arr[i];
       }
       ans=min^arr[2];
       ans+=2;
       printf("%lld\n",ans);

    }

    return 0;
}


#include <stdio.h>

int main()
{
	int x1,x2,y1,y2;
	int x,y;
	int n,m;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	scanf("%d%d",&x,&y);

	if(((y2-y1)%y)==0)
	{
		n=(y2-y1)/y;
		if(((x2-x1)%x)==0)
		{
			m=(x2-x1)/x;
			if((m-n)%2==0)
				printf("YES");
			else
				printf("NO");
		}
		else
			printf("NO");
	}
	else
		printf("NO");
    return 0;
}


#include<stdio.h>
int v[100];
int main(){
	int n,i;
	int prev = 0;
	int min = 0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	min = 0;
	prev = 0;
	for(i=0;i<n;i++){
		//printf("%d ",v[i]);
		switch(v[i]){
			case 0:
				min++;
				prev = 0;
				break;
			case 1:
				if(prev!=1){
					prev = 1;
				}else{
					prev = 0;
					min++;
				}
				break;
			case 2:
				if(prev!=2){
					prev = 2;
				}else{
					prev = 0;
					min++;
				}
				break;
			case 3:
				prev = 3-prev;
				break;
		}
	}
	printf("%d ",min);
}


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

typedef struct list {
    struct list * next;
    int n;
} List;

typedef struct edge {
    struct edge * next;
    int to;
    int weight;
} Edge;

typedef struct graph {
    int size;
    Edge * nodes[];
} Graph;

void add_to_list (List ** base, int n) {
    List * list = (List *) malloc(sizeof(List));
    list->n = n;
    list->next = *base;
    (*base) = list;
}

int list_length (List * list) {
    int i = 0;
    while (list != NULL) {
        i++;
        list = list->next;
    }
    return i;
}

void delete_list (List * list) {
    while (list != NULL) {
        List * ptr = list;
        list = list->next;
        free(ptr);
    }
}

Graph * new_graph_ptr(int size) {
    Graph * graph = (Graph *) malloc(sizeof(Graph) + size * sizeof(Edge *));
    graph->size = size;
    for (int i = 0; i < size; i++)
        graph->nodes[i] = NULL;
    return graph;
}

void add_edge(Graph * graph, int from, int to, int weight) {
    Edge * edge = (Edge *) malloc(sizeof(Edge));
    edge->to = to;
    edge->weight = weight;
    edge->next = graph->nodes[from];
    graph->nodes[from] = edge;
}

void add_edges(Graph * graph, int from, int to, int weight) {
    add_edge(graph, from, to, weight);
    add_edge(graph, to, from, weight);
}

void delete_graph(Graph * graph) {
    int size = graph->size;
    for (int i = 0; i < size; i++) {
        Edge * edge = graph->nodes[i];
        while (edge != NULL) {
            Edge * ptr = edge;
            edge = edge->next;
            free(ptr);
        }
    }
    free(graph);
}

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

    List * list = NULL;
    add_to_list(&list, b);
    while (b > a) {
        if ((b&1) == 0) {
            b >>= 1;
            add_to_list(&list, b);
        } else if (b%10 == 1) {
            b /= 10;
            add_to_list(&list, b);
        } else {
            printf("NO\n");
            free(list);
            return 0;
        }
    }
    if (a == b) {
        printf("YES\n");
        printf("%d\n", list_length(list));
        printf("%d", list->n);
        List * ptr = list->next;
        while (ptr != NULL) {
            printf(" %d", ptr->n);
            ptr = ptr->next;
        }
        printf("\n");
    } else {
        printf("NO\n");
    }
    free(list);
    return 0;
}


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

int GetSize(char a[])
{
    int i;
    for(i=0;a[i]!='\0';i++);
     return i;
}
void CopyArr(char a[],char b[],int l,int r)
{
    int i,j;
    for(i=l,j=0;i<=r;i++,j++)
{
    a[j]=b[i];
}
}
 long long int Max(long long int f,long long int s)
{
    if(f>s)
    return f;
    else
    return s;
}
 long long int GetVal(char *s,int l,int r)
{
int n;
long long int v;
char x[30]="";
CopyArr(x,s,l,r);
n=GetSize(x);
 v=atoll(x);
 if(v>1000000)
 return -1;
else if(x[0]=='0'&&n>1)
 return -1;
else
 return v;
}
int main()
{
    int i,j,n;
    long long int l,m,r,max=-1;
    char s[31]="";
   scanf("%s",s);
   n=GetSize(s);
   for(i=0;i<n-2;i++)
   {
       for(j=i+1;j<=n-2;j++)
       {
           l=GetVal(s,0,i);
           m=GetVal(s,i+1,j);
           r=GetVal(s,j+1,n-1);
           if(l==-1||m==-1||r==-1)
               continue;
           else
           max=Max(max,l+m+r);
       }
   }
   printf("%ld",max);

    return 0;
}


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

#define MAX 16
#define max(a,b) ((a)>(b) ? (a):(b))
#define clr(ar) memset(ar, 0, sizeof(ar))

const double multiplier = 0.997;

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

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

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

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

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

        int tokens_bought = max(buy_red, buy_blue);

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

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

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

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

        double temperature = 666666;
        cur = res = solve(), lim = 666666;

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

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

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

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

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

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


#include<stdio.h>

int main(){
  int largest = 0;
  scanf("%d\n", &largest);
  for(int i = largest; i > 0; i--)
  {
    if(largest % i == 0)
    {
      largest = i;
      printf("%d " ,i);
    }
  }
  return 0;
}


//In the name of God
#include <stdio.h>

#define MAXN 2100
double pr[MAXN][MAXN];

double get_pr(int w,int b)
{
  if(w<=0 || b<0)
    return 0;
  return pr[w][b];
}

void fill_pr()
{
  int W,B;
  for(W=1;W<MAXN;++W)
    for(B=0;B<MAXN;++B)
      {
	double cpr=0;
	double w=W,b=B;
	if(w>=1)
	  cpr+=w/(w+b);
	if(b>=3)
	  cpr+=(b/(w+b))*((b-1)/(w+b-1))*((b-2)/(w+b-2))*get_pr(W,B-3);
	if(b>=2 && w>=1)
	  cpr+=(b/(w+b))*((b-1)/(w+b-1))*(w/(w+b-2))*get_pr(W-1,B-2);
	pr[W][B]=cpr;
      }
}

int main()
{
  fill_pr();
  int w,b;
  scanf("%d %d",&w,&b);
  printf("%.15lf\n",get_pr(w,b));
  return 0;
}


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

#define K	8
#define L	840

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

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

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


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

int main() {
	static char str[64];
	int l, i, res;

	scanf("%s", str);
	l = strlen(str);
	res = 0;
	for (i = 0; i < l; i++) {
		char c = str[i];

		if (isupper(c))
			res += c - 'A' + 1;
		else if (islower(c))
			res -= c - 'a' + 1;
	}
	printf("%d\n", res);
	return 0;
}


#include <stdio.h>

int n,m;

int main()
{
    int i,j;

    scanf("%d%d",&m,&n);
    for(i=n;i>m;i--)
    {
        for(j=2;j*j<=i&&j<=m;j++) if(i%j == 0) break;
        if(j*j>i || j>m) goto OK;
    }
    printf("-1"); return 0;
    OK: printf("%d",i); return 0;
}


#include<stdio.h>

int main()
{
    char n[100000];

    scanf("%s",n);

    int i,l=strlen(n);

    for(i=l-1;i>=0;i--)
    {

    int r = n[i]-48;

    switch(r)
    {
    case 0:
        printf("O-|-OOOO\n");
        break;

    case 1:
        printf("O-|O-OOO\n");
        break;

    case 2:
        printf("O-|OO-OO\n");
        break;

    case 3:
        printf("O-|OOO-O\n");
        break;

    case 4:
        printf("O-|OOOO-\n");
        break;

    case 5:
        printf("-O|-OOOO\n");
        break;

    case 6:
        printf("-O|O-OOO\n");
        break;

    case 7:
        printf("-O|OO-OO\n");
        break;

    case 8:
        printf("-O|OOO-O\n");
        break;

    case 9:
        printf("-O|OOOO-\n");
        break;

    }

    }

    return 0;
}


#include <stdio.h>

#define K	50

int main() {
	int q;

	scanf("%d", &q);
	while (q--) {
		static long long aa[K];
		long long a, b, m, lower, upper, x;
		int i, j, k, good;

		scanf("%lld%lld%lld", &a, &b, &m);
		if (a == b) {
			printf("1 %lld\n", a);
			continue;
		}
		good = 0;
		for (k = 2; k <= K; k++) {
			lower = (a << (k - 2)) + (1LL << (k - 2)) - 1 + 1;
			if (lower > b)
				break;
			upper = (a << (k - 2)) + m * ((1LL << (k - 2)) - 1) + m;
			if (b <= upper) {
				good = 1;
				break;
			}
		}
		if (!good) {
			printf("-1\n");
			continue;
		}
		b -= lower;
		printf("%d %lld", k, aa[0] = a);
		for (j = 1; j < k; j++) {
			a = 1LL << (j == k - 1 ? 0 : k - 2 - j);
			x = 1 + b / a;
			if (x > m)
				x = m;
			b -= (x - 1) * a;
			for (i = 0; i < j; i++)
				x += aa[i];
			printf(" %lld", aa[j] = x);
		}
		printf("\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n,
		*a,
		max /* max sum less than 180 */;

	int sum;

	scanf("%d", &n);

	a = (int *) calloc(n, sizeof(int));

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

	max = 0;
	for (int i = 0; i < n; i++) {
		int sum;
		sum = 0;
		for (int j = 0; j < n; j++) {
			sum += a[(i + j) % n];
			if (sum > 180) break;
			else if (sum > max) max = sum;
		}
	}

	printf("%d\n", 2 * (180 - max));
}


#include<stdio.h>

int main() {
    int n, ans, num1;
    ans = 0;
    int count = 0;
    int flag = 0;
    int num_zero = 0;
    int num_one = 0;

    scanf("%d", &n);
    int array[n];
    for(int q = 0; q<n; q++){
        scanf("%d", array + q);
    }
    for (int i = 0; i<n; i++){
        if (array[i] == 1){
            num1 = 0;
            for (int j = i+1; j<n; j++){
                if (array[j] == 1){
                    num1 += 1;
                }
            }
            if (num1 + num_zero > ans){
                ans = num1 + num_zero;
            }
        }
        if (array[i] == 1){
            num_one += 1;
        }
        else{
            num_zero += 1;
        }
    }
    ans += 1;
    if (num_one >= ans && num_one >= num_zero){
        printf("%d", num_one);
        return 0;
    }
    else if (num_zero >= ans && num_zero >= num_one) {
        printf("%d", num_zero);
        return 0;
    }
        printf("%d", ans);
        return 0;
}


#include<stdio.h>

int main()
{
    int a,b=1,c=2,count=0;
    scanf("%d",&a);

    while(a>=b){
        a=a-b;
        b=b+c;
        c++;
        count++;

    }
    printf("%d",count);

}


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

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

long long int n, m, k, d;

long long int F(long long int lim){
    lim++;
    int i, j, low, high, mid;
    long long int x, counter = 0;

    for (i = 1; i <= n; i++){
        x = i;
        low = 1, high = m;
        if (lim <= x) break;

        if (lim > x){
            if (lim > (x * high)) counter += m;
            else{
                while ((low + 1) < high){
                    mid = (low + high) >> 1;
                    if ((x * mid) < lim) low = mid;
                    else high = mid;
                }
                if ((x * high) < lim) counter += high;
                else if ((x * low) < lim) counter += low;
            }
        }
        if (counter > k) break;
    }

    return counter;
}

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

    while (scanf("%I64d %I64d %I64d", &n, &m, &k) != EOF){
        long long int low = 1, high = (n * m);

        while ((low + 1) < high){
            long long int mid = (low + high) >> 1LL;
            if (F(mid) < k) low = mid;
            else high = mid;
        }

        if (F(low) >= k) printf("%I64d\n", low);
        else printf("%I64d\n", high);
    }
    return 0;
}


#include<stdio.h>

long long int lrg=100000000000000;

long long int comp(long long int m,long long int x,long long int y,long long int a,long long int b)
{
	long long int i,j,t,c,d;
	c=(m/y)-(m/(x*y));
	d=(m/x)-(m/(x*y));
	if(c>a)
	{
		c=a;
	}
	if(d>b)
	{
		d=b;
	}
	i=(m-(m/x)-(m/y)+(m/(x*y)));
	return (i>=(a+b-c-d));
}

int main()
{
long long int i,j,t,a,b,c,m,fg=0,d,x,y,l,r;
scanf("%lld %lld %lld %lld",&a,&b,&x,&y);
l=1,r=lrg;
while(l<=r)
{
	m=((l+r)/2);
	t=comp(m,x,y,a,b);
	//printf("%lld %lld\n",m,t);
	if(t==1)
	{
		r=m-1;
	}
	else
	{
		l=m+1;
	}
	if(comp(l,x,y,a,b)==1)
	{
		fg=l;
		break;
	}
	if(comp(r,x,y,a,b)==0)
	{
		fg=r+1;
		break;
	}
}
printf("%lld\n",fg);
return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,j=1,c=0,p;
    long double t=0.0,q;
    scanf("%I64d",&n);
    while(((j*(j+1))/2)<n)
    {
     t=n-(j*(j+1))/2;
     q=sqrt(8*t+1);
     p=(int)sqrt(8*t+1);

     if((long double)p==q)
    { if((p%2)!=0)
     {
                         printf("YES");
                         c++;
     break;
     }
     }
     j++;
     }
     if(c==0)
     printf("NO");
     return 0;
     }


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

int n, sum;
int a[16];
int b[4][4];

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

int dfs(int x, int y, int z)
{
    int p, q, i, j;

    if (x == n && y == 0) return 1;

    p = x;
    q = y + 1;

    if (q == n) {
        p = x + 1;
        q = 0;
    }

    for (i = 0; i < n * n; i++) {
        if ((z >> i) & 1) continue;

        if (x == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[j][y];

            if (s + a[i] != sum) continue;
        }

        if (y == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[x][j];

            if (s + a[i] != sum) continue;
        }

        if (x == n - 1 && y == 0) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[j][n - j - 1];

            if (s + a[i] != sum) continue;
        }

        if (x == n - 1 && y == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[j][j];

            if (s + a[i] != sum) continue;
        }

        b[x][y] = a[i];

        if (dfs(p, q, z | (1 << i)) == 1) return 1;

        for (j = i + 1; j < n * n; j++) {
            if (a[i] != a[j]) break;
        }

        i = j - 1;
    }

    return -1;
}

int dfs2(int p, int q)
{
    int x, y, i, j;

    if (p == 16) return 1;

    if (p <= 3) {
        x = 0;
        y = p;
    } else if (p <= 6) {
        x = p - 3;
        y = 0;
    } else if (p <= 9) {
        x = 1;
        y = p - 6;
    } else if (p <= 11) {
        x = p - 8;
        y = 1;
    } else if (p <= 13) {
        x = 2;
        y = p - 10;
    } else {
        x = 3;
        y = p - 12;
    }

    for (i = 0; i < n * n; i++) {
        if ((q >> i) & 1) continue;

        if (x == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[j][y];

            if (s + a[i] != sum) continue;
        }

        if (y == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[x][j];

            if (s + a[i] != sum) continue;
        }

        if (p == 10) {
            int s = 0;

            for (j = 0; j < n; j++) {
                if (j == 2) continue;

                s += b[j][n - j - 1];
            }

            if (s + a[i] != sum) continue;
        }

        if (x == n - 1 && y == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[j][j];

            if (s + a[i] != sum) continue;
        }

        b[x][y] = a[i];

        if (dfs2(p + 1, q | (1 << i)) == 1) return 1;

        for (j = i + 1; j < n * n; j++) {
            if (a[i] != a[j]) break;
        }

        i = j - 1;
    }

    return -1;
}

int main()
{
    int i, j;

    scanf("%d", &n);

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

        sum += a[i];
    }

    sum /= n;

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

    qsort(a, n * n, sizeof(int), cmp);

    if (n <= 3) {
        dfs(0, 0, 0);
    } else {
        dfs2(0, 0);
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (j > 0) putchar(' ');

            printf("%d", b[i][j]);
        }

        puts("");
    }

    return 0;
}


#include <stdio.h>

// this BinarySearch sometimes cannot find the x

const int P = 1000000007;

int main()
{
  int n, x, pos;
  int l, r, m;
  int lc, rc; // count of L, count of R
  int ans;
  int i;

  scanf("%d %d %d", &n, &x, &pos);
  l=0;
  r=n;
  lc=0;
  rc=0;
  while (l<r) {
    m = (l+r)/2;
    if (pos < m) r=m, ++rc;
    else l=m+1, lc += (m != pos);
  }

  ans = 1;
  for (i=1; i<=lc; ++i) ans = (long long)ans * (x-i) % P;
  for (i=1; i<=rc; ++i) ans = (long long)ans * (n-x-i+1) % P;
  for (i=1; i<=n-lc-rc-1; ++i) ans = (long long)ans * i % P;

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

  return 0;
}


#include <stdio.h>
int main()
{
	int n,t,a[1002],ans,cnt=0,i,j,k,max=0,temp;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	 for(i=1;i<n;++i)
        for(j=0;j<(n-i);++j)
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
            scanf("%d",&t);
	for(i=0;i<n;i++)
	{
	    	ans=1;
		for(k=i+1;k<n;k++)
		{
			if(a[k]-a[i]<=t)
			ans++;
			else
	break;
		}

	if(ans>max)
	max=ans;
	}
	printf("%d",max);

}


#include <stdio.h>

int main() {
    long long int n,m;
    scanf("%lld %lld", &n, &m);
    if(m>1.5){
        printf("%lld\n",(m-1)*(n));

    }
    else{
        printf("%lld\n",n-1);
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x[11],n,i,count=1,flag=0;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&x[i]);
    }
    for(i=1; i<n; i++)
    {
        if(x[i]-x[i+1]>1)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        printf("NO");
    else
        printf("YES");
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define EPS 1e-10
#define SQ(x) ((x)*(x))
#define EQ(x,y) (fabs((x)-(y))<EPS)

int r,h;
double ax,ay,az,ad,bx,by,bz,bd,d,th,ha,hb,temp1,temp2;

void print(double a){exit(!printf("%.14f\n",a));}
void swap(double*a,double*b){double temp=*a;*a=*b;*b=temp;}
double hypot3(double x,double y,double z){return sqrt(x*x+y*y+z*z);}
double angle(double a,double b,double c,double d){return atan2(a*d-b*c,a*c+b*d);}

double hh(double thp,double th){
    double lr,lb,bth;
    double tx=r*cos(th),ty=r*sin(th);
    lr=r*sqrt(2*(1-cos(thp-th)));
    bth=angle(tx,ty,bx,by);
    lb=sqrt(SQ(d)+SQ(bd)-2*d*bd*cos(bth*r/d));
    return lr+lb;
}

double g(double th){
    double la,ath,sx,sy;
    double blg,brg,bllg,brrg,bld,brd;
    sx=r*cos(th); sy=r*sin(th);
    ath=angle(sx,sy,ax,ay);
    la=sqrt(SQ(d)+SQ(ad)-2*d*ad*cos(ath*r/d));

    blg=0; brg=2*M_PI;
    while(brg-blg>EPS){
        bllg=(blg*19+brg)/20; brrg=(blg+brg*19)/20;
        bld=hh(th,bllg); brd=hh(th,brrg);
        bld>brd?blg=bllg:(brg=brrg);
    }
    return la+bld;
}

double f(double th){
    double tx=r*cos(th),ty=r*sin(th),lr,lb;
    lr=hypot(ax-tx,ay-ty);
    th=angle(tx,ty,bx,by);
    lb=sqrt(SQ(d)+SQ(bd)-2*d*bd*cos(th*r/d));
    return lr+lb;
}

main(){
    int i,j;
    double ans=1e9,alg,arg,allg,arrg,ald,ard;

    scanf("%d%d%lf%lf%lf%lf%lf%lf",&r,&h,&ax,&ay,&az,&bx,&by,&bz);
    if(EQ(ax,bx)&&EQ(ay,by)&&EQ(az,bz)) print(.0);
    if(az<EPS&&bz<EPS) print(hypot(ax-bx,ay-by));
    if(bz<az)swap(&ax,&bx),swap(&ay,&by),swap(&az,&bz);
    ad=hypot3(ax,ay,az-h); bd=hypot3(bx,by,bz-h);
    d=hypot(h,r);
    ha=hypot(ax,ay); hb=hypot(bx,by);
    th=acos((ax*bx+ay*by)/(ha*hb));

    if(az<EPS){
        if(EQ(bz,h)) print(d+r-ha);
        alg=0; arg=2*M_PI;
        while(arg-alg>EPS){
            allg=(alg*49+arg)/50; arrg=(alg+arg*49)/50;
            ald=f(allg); ard=f(arrg);
            ald>ard?alg=allg:(arg=arrg);
        }
        print(ald);
    }

    if(EQ(bz,h)) print(ad);
    temp1=sqrt(SQ(ad)+SQ(bd)-2*ad*bd*cos(th*r/d));
    alg=0; arg=2*M_PI;
    while(arg-alg>EPS){
        allg=(alg*49+arg)/50; arrg=(alg+arg*49)/50;
        ald=g(allg); ard=g(arrg);
        ald>ard?alg=allg:(arg=arrg);
    }
    temp2=ald;
    print(temp1<temp2?temp1:temp2);
    return 0;
}


#include<stdio.h>

int a[5], b[5];

int mu(int a, int n){
	int i, kq=1;
	for(i=0;i<n;i++){
		kq*=a;
	}
	return kq;
}
int tinh(int p[], int n, int base){
	int i,sum=0;
	for(i=n-1;i>=0;i--){
		sum+=p[i]*mu(base,n-i-1);
	}
	return sum;
}

int main(){
	int i,na, nb, ma=0,mb=0,max,check=0;
	char c;
	i=0;
	while((c=getchar())!=EOF){
		if(c>='0' && c<'9') a[i++]=c-'0';
		if(c>='A' && c<='Z') a[i++]=c-'A'+10;
		if(a[i-1]>ma) ma=a[i-1];
		if(c==':') break;
	}
	na=i;
	i=0;
	while((c=getchar())!=EOF){
		if(c>='0' && c<'9') b[i++]=c-'0';
		if(c>='A' && c<='Z') b[i++]=c-'A'+10;
		if(b[i-1]>mb) mb=b[i-1];
		if(c=='\n') break;
	}
	nb=i;
	//for(i=0;i<na;i++) printf("%d \n", a[i]);
	//for(i=0;i<nb;i++) printf("%d \n", b[i]);
	if(ma>mb) max = ma+1;
	else max = mb+1;
	//printf("%d %d %d %d\n",na, nb,tinh(a,na,max), tinh(b,nb,max));
	if(tinh(a,na,max)>23 || tinh(b,nb,max)>59){
		printf("0\n");
		return 0;
	}

	for(i=0;i<na-1;i++)
		if(a[i]!=0) check =1;
	for(i=0;i<nb-1;i++)
		if(b[i]!=0) check =1;
	if(check==0){
		printf("-1\n");
		return 0;
	}

	i=max;
	while(tinh(a,na,i)<24 && tinh(b,nb,i)<60){
		printf("%d ",i);
		i++;
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
int main()
{
	int a,b,i,j,max,min,count=0;
	int c[10000]={};
	scanf("%d %d",&a,&b);
	if(a==b)
	{
		printf("infinity\n");
	}
	else if(a<b)
	{
		printf("0\n");
	}
	else
	{
		max=a-b;
		min=b+1;
		j=1;
		for(i=1;i*i<max;i++)
		{
			if(max%i==0)
			{
				c[j]=i;
				j++;
				c[j]=max/i;
				j++;
			}
		}
		if(i*i==max)
			c[j]=i;
		for(i=1;i<=j;i++)
		{
			if(c[i]>=min && c[i]<=max)
			{
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}


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

	}
	return 0;
}


#include<stdio.h>
int main(){
    int a,b,k;
    char arr[50];
    char store[50];
    scanf("%d%d",&a,&b);
    getchar();
    double s=0;
    double res=0; double x=0;
    int i;
    for(i=0;i<a;i++){
    gets(arr);
    if(strlen(arr)==8){
    store[i]='2';
    }
    else{
    store[i]='1';
    }
    }
    for(k=i-1;k>=0;k--){
    if(store[k]=='2'){
    s=(2*res)+0.5;
    res=s;
    x=x+(res*b);
    }
    else{
    s=(2*res);
    res=s;
    x=x+(res*b);
    }}
    printf("%lld",(long long int)x);
}


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

int main(){
int n,i;
long int a;
scanf("%d",&n);
if(n%2!=0){a=0;}
else{
a=pow(2,(n/2));
}
printf("%ld",a);
return 0;
}


/*
 * Find out the minimum number of prime addends which number n can be split into.
 * Algorithm Complexity
 * Time:  O(???)
 * Space: O(1)
 */

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

char IsPrime(int a){
	if(a == 2) return 1;
	int i;
	char prime = 1;
	for(i = 2; i <= (int)sqrt((double)a) && prime == 1; i++)
		if(a%i == 0) prime = 0;
	return prime;
}

int optimal(int n){
	int i = n, p = 0;
	while(i != 0){
		if(IsPrime(i) == 1 && n-1 != 1 && optimal(n-i) < 3){
			p++;
			n -= i;
			i = n;
		}else i--;
	}
	return p;
}

int main(int argc, char* argv[]){
	int n, p = 0, i;
	scanf("%d", &n);
	i = n;

	if(IsPrime(n) == 1){
		printf("1\n");
		return 0;
	}
	if(n%2 == 0){
		printf("2\n");
		return 0;
	}
	while(i != 0){
		if(IsPrime(i) == 1 && n-i != 1 && optimal(n-i) < 3){
			p++;
			//printf("%d ", i);
			n -= i;
			i = n;
		}else i--;
	}
	if(p > 3) p = 3;
	printf("%d\n", p);
	return 0;
}


#include<stdio.h>
int main()
{
    int k,i,j;
    scanf("%d", &k);
    for ( i = 0; i < 26; i++)
    {
        int cnt = 1;
        while ((cnt + 1) * cnt / 2 <= k)
            cnt++;
        k -= cnt * (cnt - 1) / 2;
        for ( j = 0; j < cnt; j++)
            printf("%c", 'a' + i);
    }
    return 0;
}


#include <stdio.h>

int main() {
	int n, k, i, j, min, max;
	scanf("%d%d", &n, &k);
	if (n != k && k!= 0) min = 1;
	else min = 0;

	if ( (n / 3) >= k) {
		max = k * 2;
	}
	else {
		max = n - k;
	}

	printf("%d %d", min, max);
}


#include<stdio.h>   //AA06( 11/ 07/ 20) If u see my code, Have a Good Day! (^_^)

int Ans(int n, int k);

int main()
{
    int n, k;

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

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

    return 0;
}

int Ans(int n, int k)
{
    int X = ((n/ k) + 1) * k;

    return X;
}


#include<stdio.h>
int main()
{
    long int n;
    int a=0,b=1;
    scanf("%ld",&n);
    if(n%4==0||n%4==3)
    {
        printf("%d",a);
    }
    else
    {
        printf("%d",b);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
	char arr[7][20] = {"sunday", "monday", "tuesday","wednesday","thursday","friday","saturday"};
	char str1[20], str2[20];
	int i, one, two, diff;
	scanf("%s",str1);
	scanf("%s",str2);
	for (i=0; i<7; i++)
		if (!strcmp(str1, arr[i])) one = i;
	for (i=0; i<7; i++)
		if (!strcmp(str2, arr[i])) two = i;
	diff = (two-one+7) % 7;
	if (diff ==0 || diff==2 || diff ==3) printf("YES\n");
	else	printf("NO\n");
	return 0;
}


#include <stdio.h>

typedef long long int LL;

LL power(int n,int k){
    LL t = 1;
    while(k--){
        t*=n;
    }
    return t;
}

LL findAns(LL n){
    if(n<10)    return n;
    LL ans = 9+(n-10)/10;
    int m = n%10;
    while(n>9){
        n/=10;
    }
    if(m>=n)    ++ans;
    return ans;
}

int main(void){
    LL l,r;
    scanf("%I64d %I64d",&l,&r);
    //printf("%I64d %I64d\n",l,r);
    if((l<1)||(l>r)||(r>power(10,18)))
        return 0;
    LL ans = findAns(r)-findAns(l-1);
    printf("%I64d",ans);
    return 0;
}


#include<stdio.h>

int main()
{
    long long int n,k,numlessk;
    while(scanf("%I64d",&n)==1)
    {
        if(n==0){
            printf("1\n");
            continue;
        }
        k=(n*6)+1;
        numlessk=((n-1)*(n))/2;
        printf("%I64d\n",k+numlessk*6);
    }
    return 0;
}


#include <stdio.h>
#include <math.h>
int main(){
    long long int n,i,m;
    int k=0;
    scanf("%lld",&n);

    for( i=2;i*i<=n;i++){
        if(n%i==0){
        while(n%i==0){
            n/=i;
        }
        printf("%lld\n",n==1?i:1);
        return 0;

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

    return 0;
}


#include<stdio.h>
#include<string.h>
main()
{int n;
scanf("%d",&n);
int i,nb=1;
char s[n+1];
scanf("%s",s);
for(i=0;i<n;i++)
if(s[i]=='?')
{
if(s[i+1]=='?'||s[i-1]==s[i+1]||i==n-1||i==0)
nb=2;}
else
if(s[i]==s[i+1])
{
nb=1;
break;}

  if(nb==1)
  printf("NO");
  else
  printf("YES");
}


#include<stdio.h>
int main()
{
	long long int n,sum=0,a,b,k;
	scanf("%lld",&n);
	a=1;
	b=1;
	k=a+b;
	while(k<=n)
	{
		sum++;
	    	a=b;
	  	b=k;
	  	k=a+b;
	}
	printf("%lld",sum);
}


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

typedef int64_t i64;
typedef int32_t i32;

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

const i32 mod = 1000000007;

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

i32 mod_pow (i32 r, i32 n) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n & 1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

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

void matmul (i32 *c, i32 *a, i32 *b, i32 n) {
  static i32 *tmp = NULL;
  if (tmp == NULL) {
    tmp = (i32 *) calloc (n * n, sizeof (i32));
  }
  memset (tmp, 0, sizeof (i32) * n * n);
  for (i32 i = 0; i < n; ++i) {
    for (i32 k = 0; k < n; ++k) {
      for (i32 j = 0; j < n; ++j) {
	tmp[i * n + j] = (tmp[i * n + j] + (i64) a[i * n + k] * b[k * n + j]) % mod;
      }
    }
  }
  memcpy (c, tmp, sizeof (i32) * n * n);
}

void run (void) {
  i32 n = read_int();
  i32 k = read_int();
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  i32 cnt[2] = {0, 0};
  for (i32 i = 0; i < n; ++i) {
    a[i] = read_int();
    cnt[a[i]]++;
  }
  if (cnt[0] == 0 || cnt[1] == 0) {
    puts("1");
    return;
  }
  i32 d = 0;
  for (i32 i = 0; i < cnt[0]; ++i) {
    d += a[i];
  }
  const i32 m = MIN(cnt[0], cnt[1]) + 1;
  i32 *t = (i32 *) calloc (m * m, sizeof (i32));
  i32 *s = (i32 *) calloc (m * m, sizeof (i32));
  for (i32 i = 0; i < m; ++i) {
    t[i * m + i] = 1;
    s[i * m + i] = cnt[0] * (cnt[0] - 1) / 2 + cnt[1] * (cnt[1] - 1) / 2 + (cnt[0] - i) * i + i * (cnt[1] - i);
    if (i + 1 < m) {
      s[i * m + i + 1] = (cnt[0] - i) * (cnt[1] - i);
    }
    if (i - 1 >= 0) {
      s[i * m + i - 1] = i * i;
    }
  }
  i32 p = inv (n * (n - 1) / 2);
  for (i32 i = 0; i < m * m; ++i) {
    s[i] = (i64) s[i] * p % mod;
  }
  while (k > 0) {
    if (k & 1) matmul (t, t, s, m);
    matmul (s, s, s, m);
    k >>= 1;
  }
  i32 ans = t[d * m + 0];
  print_int (ans);
  puts("");
}

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


#include<stdio.h>

#define MOD 998244353
int fact[1000006], wpar[1000006<<1], n, level;

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}

int powmod(int b, int p){
  int t = 1;
  while(p){
    if(p&1)t = mul(t, b);
    b = mul(b, b);
    p>>=1;
  }
  return t;
}

int ncr(int _n, int r){
  return mul(mul(fact[_n], powmod(fact[r], MOD - 2)), powmod(fact[_n - r], MOD - 2));
}

void dfs(int x, int bits){
  if(bits > level) return;
  int l, r;
  l = x<<1;
  r = l|1;
  if(x&1){
    // x is a right child
    wpar[l] = 1;
    wpar[r] = 1^wpar[x]^wpar[l];
  } else {
    // x is a left child
    wpar[r] = 0;
    wpar[l] = 1^wpar[x]^wpar[r];
  }
  dfs(l, bits + 1);
  dfs(r, bits + 1);
}

int getpossib(int lparity){
  int i, rem;
  wpar[2] = lparity;
  wpar[3] = 1^wpar[1]^wpar[2];
  dfs(2, 2);dfs(3, 2);

  rem = n - (1<<level) + 1;

  for(i = (1<<(level - 1));i < (1<<level);i++){
    //    printf("wpar[%d]: %d\n", i, wpar[i]);
    if(i&1){
      if(wpar[i]) return 0;
      rem--;
    } else {
      if(1^wpar[i]) rem--;
    }
  }
  return rem == 0;
}

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

  fact[0] = 1;
  for(i = 1;i < 1000006;i++)fact[i] = mul(fact[i - 1], i);

  if(n == 1 || n == 2){printf("1\n");return 0;}
  if(n == 3){printf("0\n");return 0;}

  for(level = 0; (1<<level) - 1 < n;level++);
  level--;

  wpar[1] = n&1;
  printf("%d\n", getpossib(0) + getpossib(1));

  return 0;
}


int main(n)
{
    scanf("%d",&n);
    puts(n&1?"black":"white 1 2");
    return 0;
    }


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

int n,m;
char K[65];
long long ans;

int main()
{
    int i,j;
    long long x,y,p = 1;

    scanf("%d%s",&n,K+1);
    m = strlen(K+1);

    for(i=j=m;i;i=j)
    {
        x = 0; y = 1;
        for(;j > 0 && x + (K[j]-'0')*y < n && y<n;j--,y*=10)
            x += (K[j]-'0')*y;
        while(i-j > 1 && K[j+1] == '0') j++;
        ans = ans + x*p;
        p *= n;
    }

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


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

#define author int
#define sph_mp main()
#define fr(i, a, b) for((i) = (a) ; (i) < (b) ; (i)++)
#define frr(i, a, b) for((i) = (a) ; (i) >= (b) ; (i)--)

int l, r, x, y;
int a[1000], ai = 0;

// Function to print the divisors
void printDivisors(int n)
{
    // Note that this loop runs till square root
    int i;
    for (i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            // If divisors are equal, print only one
            if (n/i == i)
            	{
            		a[ai] = i;
            		ai++;
				}
//                printf("%d ", i);

            else // Otherwise print both
            	{
            		a[ai] = i;
            		a[ai+1] = n/i;
            		ai += 2;
				}
//                printf("%d %d ", i, n/i);
        }
    }
}

int valid(int x) {
	return l <= x && x <= r;
}

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}

// Function to return LCM of two numbers
unsigned long long lcm(unsigned long long a, unsigned long long b)
{
    return (a*b)/gcd(a, b);
}

/* Driver program to test above function */
author sph_mp {
	scanf("%d %d %d %d", &l, &r, &x, &y);
	printDivisors(y);
	int res = 0;
	int i, j;
	fr(i, 0, ai)
		fr(j, 0, ai) {
			if(valid(a[i]) && valid(a[j])) {
				if(gcd(a[i], a[j]) == x && lcm((unsigned long long)a[i], (unsigned long long)a[j]) == y)
					{
//						printf("%d %d\n", a[i], a[j]);
						res++;
					}
			}
		}
	printf("%d", res);
    return 0;
}


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

int main()
{
	char s[100];
	while (scanf("%s",&s)!= EOF)
	{
		int length = strlen(s);
		for (int i = 0; i < length; i++)
		{
			if (s[i] == 49)
			{
				int zeronum = 0;
				for (int j = i + 1; j < length; j++)
				{
					if (s[j] == 48)
						zeronum++;
				}
				if (zeronum >= 6)
				{
					printf("YES\n");
					break;
				}
				else
				{
					printf("NO\n");
					break;
				}
			}
			if(i==length-1)
			{
			    printf("NO\n");
			    break;
			}
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i=0,j=0,a,b,c=0,d=0,n,m;
    char s[100],t[100];
    scanf("%s",s);
    scanf("%s",t);
    m=strlen(t);
    for(i=0;i<m;i++)
    {
        if(t[i]==s[c])
        {
            c++;
        }
    }
    printf("%d",c+1);
    return  0;
}


#include<stdio.h>
int main ()
{
long long  i,k,n,m,max=0,min=0;
scanf("%lld%lld",&n,&m);
max=n-m+1;
max=max*(max-1)/2;
k=n/m;
min=(k*m*(k-1))/2+(n%m)*k;
printf("%lld %lld",min,max);
return 0;}


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

int main()
{
    char string[40];
    scanf("%s", string);
    int buffer;
    int len = strlen(string);
    int i;

    if(len == 1 && string[i] == '9')
    {
        printf("9\n");
        return 0;
    }

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

        buffer = (int)(string[i]-'0');
        //printf("----> %i\n\n",buffer);

        if(i==0 && buffer==9)
            {
                 printf("9");
                continue;

            }

        if(9-buffer < buffer && 9-buffer>=0)
            printf("%i",9-buffer);
        else
            printf("%i",buffer);

    }

    return 0;
}


#include <stdio.h>
int main(void) {
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int s=(a+b+c+d);
    if(s%2!=0)
        printf("NO");
    else{
    if(a+b == c+d){
        printf("YES");
        return 0;
    }
    if(a+c == b+d){
        printf("YES");
        return 0;
    }
    if(a+d == b+c){
        printf("YES");
        return 0;
    }
    if(a+b+c == d){
        printf("YES");
        return 0;
    }
    if(d+b+c == a){
        printf("YES");
        return 0;
    }
    if(a+d+c == b){
        printf("YES");
        return 0;
    }
    if(a+b+d == c){
        printf("YES");
        return 0;
    }
    printf("NO");
    }
	return 0;
}


#include<stdio.h>
int main()
{
	long long int x1,y1,x2,y2,ans=0;
	scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
	ans=((x2-x1+2)*(y2-y1+2))/4+((x2-x1)*(y2-y1))/4;
	printf("%lld",ans);
	return 0;
}


#include<stdio.h>
#include<string.h>
int mut(int a){return (a<0)?-a:a;}
int main() {
	int i,n,cvp=0,j,arr[100][100];
	for(i=0;i<5;i++)
		for(j=0;j<5;j++)
				scanf("%d",&arr[i][j]);
	for(i=0;i<5;i++)
		for(j=0;j<5;j++)
			if(arr[i][j])
				cvp=mut(i-2)+mut(j-2);

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


#include <stdio.h>

int main()
{
    int m, n, count = 0;
    scanf("%d %d", &n, &m);
    /*if ( n%2 == 0 && m%2 == 0)
        printf("Malvika");
    else if ( n%2 == 0 && m%2 != 0 )
        printf("Malvika");
    else if ( n%2 != 0 && m%2 == 0 )
        printf("Akshat");
    else if ( n%2 != 0 && m%2 != 0 )
        printf("Akshat");
    while ( m > 0 && n > 0 )
    {
        m--;
        n--;
        count++;
    }
    if ( count % 2 == 0 )
        printf("Malvika");
    else
        printf("Akshat");*/
    int temp;
    if ( m <= n )
        temp = m;
    else
        temp = n;

    if ( temp%2 == 0 )
        printf("Malvika");
    else
        printf("Akshat");

}


#include<stdio.h>
int n;
int rec(int n)
{
	if(n==0)
	return 0;
	return (n%8==1)+rec(n/8);
}
int main()
{
	scanf("%d",&n);
	printf("%d",rec(n));
	return 0;
 }


//
//  main.c
//  73A
//
//  Created by Ki-baek Lee on 11. 9. 5..
//  Copyright 2011년 __MyCompanyName__. All rights reserved.
//

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

#define min(x,y) (((x)<(y))?(x):(y))

int main (int argc, const char * argv[])
{
    char notes[][3] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
    int pos[3];
    char input[3][3];
    char tmp[11], *ptr;
    int i, j, diff[3];

    gets(tmp);
    ptr = strtok(tmp, " ");
    strcpy(input[0], ptr);
    ptr = strtok(NULL, " ");
    strcpy(input[1], ptr);
    ptr = strtok(NULL, " ");
    strcpy(input[2], ptr);

    for(i=0;i<3;++i) {
        for(j=0;j<12;++j)
            if (strcmp(input[i], notes[j]) == 0)
                pos[i] = j;
    }

    if (pos[0] > pos[1])
        pos[0] ^= pos[1] ^= pos[0] ^= pos[1];
    if (pos[0] > pos[2])
        pos[0] ^= pos[2] ^= pos[0] ^= pos[2];
    if (pos[1] > pos[2])
        pos[1] ^= pos[2] ^= pos[1] ^= pos[2];

    for (i=0; i<3; ++i) {
        int tmp_pos = pos[i];
        diff[i] = 0;
        while (tmp_pos != pos[(i + 1) % 3]) {
            tmp_pos = (tmp_pos + 1) % 12;
            ++diff[i];
        }
    }

    if ((diff[0] == 4 && diff[1] == 3)
        || (diff[1] == 4 && diff[2] == 3)
        || (diff[2] == 4 && diff[0] == 3))
        printf("major\n");
    else if ((diff[0] == 3 && diff[1] == 4)
             || (diff[1] == 3 && diff[2] == 4)
             || (diff[2] == 3 && diff[0] == 4))
        printf("minor\n");
    else
        printf("strange\n");

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LL long long
#define uLL unsigned long long
long ms[2000000];
void print(LL *a,long size) {long i;for (i=1;i<size;i++) {printf("%lld ",a[i]);}printf("%lld\n",a[i]);}
void mergesort(LL*ds,long size)
{
	long i,j,k,s,b,e;
	for (k=1;k<=size;k=k<<1)
	{
		for (i=1;i+k<=size;i+=k<<1)
		{
			s=i;b=i+k;e=b+k-1;
			if (e>size) {e=size;}
			for (j=1;(s<i+k)&&(b<=e);j++)
			{
				if (ds[s]<=ds[b])
				{
					ms[j]=ds[s++];
				}
				else
				{
					ms[j]=ds[b++];
				}
			}
			for (b=i+k-1;b>=s;b--)
			{
				ds[e--]=ds[b];
			}
			for (b=1;b<j;b++)
			{
				ds[i+b-1]=ms[b];
			}
		}
	}
}
long gray(long a)
{
	return ((a<<1)^a)>>1;
}
inline int bsf64(int a)
{
	__asm__("bsfl %0,%0":"+r"(a));
	return a;
}
inline int bsr64(int a)
{
	__asm__("bsrl %0,%0":"+r"(a));
	return a;
}
inline LL max(LL a,LL b) {if (b>a) {a=b;}return a;}
inline LL min(LL a,LL b) {if (a>b) {a=b;}return a;}
LL ans1[1000000],ans2[1000000];
long num[1000],num2[1000];
int main()
{
//	freopen("in.in","r",stdin);
	long i,j,k,a,b,c,l,p,q,r,m,n,mid;
	LL baka;
	scanf("%ld %ld\n",&n,&m);
//	printf("%ld %ld\n",n,m);
	for (i=1;i<=n;i++)
	{
		scanf("%ld",&num[i]);
		num[i]=num[i]%m;
	}
	if (n>10) {q=n>>1;} else {q=n;}
	*ans1=(LL)1<<q;ans1[1]=0;
	for (i=1;i<=q;i++) {num2[i-1]=num[i];}
	for (i=1;i<*ans1;i++)
	{
		a=gray(i);b=gray(i-1);
		k=a^b;
//		printf("%ld\n",bsr64(k));
		if (a&k) {ans1[i+1]=ans1[i]+num2[bsr64(k)];}
		if (b&k) {ans1[i+1]=ans1[i]+(LL)m-num2[bsr64(k)];}
		ans1[i+1]=ans1[i+1]%m;
	}
//	print(ans1,*ans1);
	//////////////////
	q=n-q;
	for (i=1;i<=q;i++) {num2[i-1]=num[n-i+1];}
	*ans2=(LL)1<<q;ans2[1]=0;
	for (i=1;i<*ans2;i++)
	{
		a=gray(i);b=gray(i-1);
		k=a^b;
		if (a&k) {ans2[i+1]=ans2[i]+num2[bsr64(k)];}
		if (b&k) {ans2[i+1]=ans2[i]+m-num2[bsr64(k)];}
		ans2[i+1]=ans2[i+1]%m;
	}
//	print(ans2,*ans2);
	mergesort(ans1,*ans1);
	baka=0;
	for (i=1;i<=*ans2;i++)
	{
		l=1;r=*ans1;a=m-1-ans2[i];
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (ans1[mid]<a)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if (l<=*ans1) {b=(ans2[i]+ans1[l])%m;baka=max(b,baka);}
		if (r>0) {b=(ans2[i]+ans1[r])%m;baka=max(b,baka);}
		l=1;r=*ans1;a=2*m-1-ans2[i];
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (ans1[mid]<a)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if (l<=*ans1) {b=(ans2[i]+ans1[l])%m;baka=max(b,baka);}
		if (r>0) {b=(ans2[i]+ans1[r])%m;baka=max(b,baka);}
	}
	printf("%lld\n",baka);
	return 0;
}


#include <stdio.h>
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
    if (a == 0) return b;
    return gcd(b % a, a);
}
int main() {
	unsigned long long int x;
	scanf("%llu", &x);
	unsigned long long int ans[2]={1, x};
	for (unsigned long long int i=1;i*i<=x;i++) {
		if (x%i==0) {
			if (i*i==x) continue;
			else {
				if (gcd(i, x/i)==1) {
					ans[0]=i;
					ans[1]=x/i;
				}
			}
		}
	}
	printf("%llu %llu\n", ans[0], ans[1]);
}


#include<stdio.h>

#include<math.h>

long long int a[10000000];

main()

{

    long long int n,k,i=1,j=1,ans=0,p=0;

    scanf("%lld%lld",&n,&k);

    while(i<=sqrt(n))

    {

        if(n%i==0)

        {   if(i*i!=n){a[p]=n/i;p++;}

            if(j==k){ans=i;break;}

            j++;

        }

        i++;

    } if(ans==0)

    {  p=p-1;if((p-(k-j))>=0)

        ans=a[p-(k-j)];

        else ans=0;

    }

    if(ans!=0)printf("%lld\n",ans);

    else printf("-1\n");

    return 0;

}


#include <stdio.h>

int main()
{
    int n,i;

    int no=0;

    scanf("%d",&n);

    int ara[n];

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

    for(i=0; i<n-1; i++)
    {
        if(ara[i]<ara[i+1] )
        {
            continue;
        }
        else
        {
            break;
        }
    }

    for(; i<n-1; i++)
    {
        if(ara[i]==ara[i+1]) continue;
        else
        {
            break;
        }
    }

    for(; i<n-1; i++)
    {
        if(ara[i]>ara[i+1]) continue;
        else
        {
            no=1;
            break;
        }
    }

    if(no==1) printf("NO");
    else printf("YES");
}


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

int s[100000];

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

int main ()
{
  int n;
  int i;
  scanf("%d\n", &n);
  for (i=0; i<n; i++){
      scanf("%d", &s[i]);
  }
  qsort (s, n, sizeof(int), compare);
  for (i=0; i<n-1; i++) {
      if (s[i+1] < 2*s[i] && s[i] != s[i+1]){
          printf("YES");
          return 0;
      }
  }

  printf("NO");

  return 0;
}


#include<stdio.h>
long long n,n1,sum,a[20],value;

long long findMinOnes(long long n,int i)
{
	int count = 0;
	long long value1,value2;
	if(n<0)
		n *=-1;
	if(i==1)
		return n;
	if(n==1)
		return 1;
		while(n>a[i])
		{
			n-= a[i];
			count+=i;
		}
		value1 = count + findMinOnes(n,i-1);
		n-= a[i];
		count+=i;
		value2 = count + findMinOnes(n,i-1);
		if(value1 < value2)
			return value1;
		else
			return value2;
}
int main()
{
	int k=1,i=0,count;
	long long mul = 10;
	scanf("%I64d",&n);
	n1=n;
	while(n!=0)
	{
		n=n/10;
		i++;
	}
	a[k]=1;
	for(k=2;k<=i+1;k++)
	{
		a[k]=a[k-1]+mul;
		mul*=10;
	}
	n=n1;
	printf("%I64d",findMinOnes(n,i+1));
	return 0;
}


#include <stdio.h>

int main(void) {

	long long n,a,b,c,d,max=0,min=10000000,ans=0;

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

	if(max<a+b) max=a+b;
	if(max<a+c) max=a+c;
	if(max<b+d) max=b+d;
	if(max<c+d) max=c+d;

	if(min>a+b) min=a+b;
	if(min>a+c) min=a+c;
	if(min>b+d) min=b+d;
	if(min>c+d) min=c+d;

	a=min+n-max;
	b=max+1-min;

	if(a<0) a=0;

	if(a<0) printf("0");
	else printf("%I64d",(a)*n);

}


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

int main(){

	int a,b,c;

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

	for(int i = 0; i <= c/a; i++){
		if((c-i*a)%b == 0){
			printf("Yes");
			return 0;
		}
	}

	printf("No");

	return 0;
}


#include <stdio.h>

int main()
{
    int n, res;

    scanf ("%d", &n);

    printf ("%d\n", n % 2 == 1 || n == 2 ? 0 : n / 4 - (n%4 == 0));

    return 0;
}


#include <stdio.h>

int main(void) {
	// your code goes here

long long	int n,i,sum=0,j=1;
	scanf("%I64d",&n);
	for(i=3;i<=n;i++)
	{
	    sum=sum+j;
	    j=j+2;

	}
	printf("%I64d",sum);

	return 0;
}


#include<stdio.h>
int check(char *s,int pos){
    for(int i=0;i<pos/2;i++){
        if(s[i]!=s[pos-i-1])
            return 0;
    }
    return 1;
}
int main(){
    char str[60];
    gets(str);
    int len;
    for(len=0;str[len]!='\0';len++);
    for(int i=len;i>1;i--){
        for(int j=0;j<=len-i;j++){
            char s[i];
            int pos=0;
            for(int k=j;k<=j+i-1;k++)
                s[pos++]=str[k];
            int flag=check(s,pos);
            if(flag==0){
                printf("%d\n",i);
                return 0;
            }
        }
    }
    printf("%d\n",0);
    return 0;
}


#include<stdio.h>
int main(){
	long i,n,k,count=0,count1=0,flag=1;
	scanf("%ld %ld",&n,&k);
	char str[n];
	scanf("%s",str);
	for(i=0;i<n;i++){
		if(str[i]=='G')
			count=i;
		if(str[i]=='T')
			count1=i;
	}
	if(count1>count){
		while(count<count1){
			if(str[count+k]=='#'){
				flag=0;
				break;
			}
			count=count+k;
			if(str[count]=='T'){
				flag=1;
				break;
			}
		}
	}
	else{
		while(count>count1){
			if(str[count-k]=='#'){
				flag=0;
				break;
			}
			count=count-k;
			if(str[count]=='T'){
				flag=1;
				break;
			}
		}
	}
	if(flag==1 && str[count]=='T')
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


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

int main(void) {
     long long int r;

	scanf("%lld", &r);

	if((r&1) == 0 || r < 5){
		printf("NO");
	}
	else{
		printf("%d %I64d",1,((r-3)/2));
	}

	return 0;
}


#include<stdio.h>
int main()
{
    int n,i,a[20],p,q,r,max;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    p=0;
    q=0;
    r=0;
    for(i=1;i<=n;i++)
    {
        if(i%3==0)
        {
            p=p+a[i];
        }
        else if((i+1)%3==0)
        {
            q=q+a[i];
        }
        else if((i+2)%3==0)
        {
            r=r+a[i];
        }
    }
    if(p>q && p>r)
    {
        max=p;
    }
    else if(q>p && q>r)
    {
        max=q;
    }
    else if(r>p && r>q)
    {
        max=r;
    }
    if(max==p)
    {
        printf("back");
    }
    else if(max==q)
    {
        printf("biceps");
    }
    else if(max==r)
    {
        printf("chest");
    }
    return 0;
}


#include <stdio.h>

#define min(a, b) (a == -1 ? b : (b == -1 ? a : (a < b ? a : b)))

int n;
long long x, y;
long long dp[10000010];

int main() {
	scanf("%d %lld %lld", &n, &x, &y);
    dp[1] = x;
    for (int i = 2; i <= n; i++) {
        if (i & 1) {
            dp[i] = min(dp[i - 1] + x, dp[(i >> 1) + 1] + y + x);
        } else {
            dp[i] = min(dp[i - 1] + x, dp[i >> 1] + y);
        }
    }
    printf("%lld", dp[n]);
}


#include<stdio.h>
typedef long long ll;
int main()
{
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if(b>=0)
    {
    	if(b>=n)
    	b=b%n;
    }
	 else
    {
        while(b<0)
        {
           b+=n;
        }
    }
    a+=b;
    if(a>n)
    {
       a-=n;
    }
    printf("%d",a);
	return 0;
 }


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

int main()
{
    int a,x,y,color;    //0:black,1:white
    double b;
    scanf("%d%d",&x,&y);

    if(0==x||0==y)
    {
        color=0;
    }
    else
    {
        b=sqrt(x*x+y*y);
        a=(int)b;
        if(a*a == x*x+y*y)
        {
            color=0;
        }
        else
        {
            if(x>0&&y>0 || x<0&&y<0)
                color=a%2;
            else
                color=(a+1)%2;
        }
    }
    if(color)
        printf("white");
    else
        printf("black");

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,len;
    char ch,s1[]="qwertyuiopasdfghjkl;zxcvbnm,./",s2[100];
    scanf("%c %s",&ch,&s2);
    len=strlen(s2);
    if(ch=='R')
    {
        for(i=0,j=0;i<30;i++)
        {
            if(s2[j]==s1[i])
            {
                printf("%c",s1[i-1]);
                j++;
                i=-1;
            }
            if(j==len)
            {
                printf("\n");
                break;
            }
        }
    }
    else if(ch=='L')
    {
        for(i=0,j=0;i<30;i++)
        {
            if(s2[j]==s1[i])
            {
                printf("%c",s1[i+1]);
                j++;
                i=-1;
            }
            if(j==len)
            {
                printf("\n");
                break;
            }
        }
    }
    return 0;
}


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

int n,M,m,sum;

int calc(int val[]){
    int sum=0,i,temp,j;
    for(i=0;i<n;i++){
        sum+=val[i];
        temp=val[i];
        for(j=i+1;j<n;j++){
            if(temp>val[j])
               temp=val[j];
            sum+=temp;
        }
    }
    return sum;
}

int print_m(int i,int val[]){
    int j;

   if(i==n){

     if( calc(val)==sum )
            m++;
        if(m==M){
            for(j=0;j<n;j++)
                printf("%d ",val[j]);
            exit(0);
        }
  //      printf("\n");
        return 0;
    }
    for(j=i;j<n;j++){
        val[i]=val[j]+val[i]-(val[j]=val[i]);
        print_m(i+1,val);
        val[i]=val[j]+val[i]-(val[j]=val[i]);
    }
    return 0;
}

int main()
{
    int val[8]={1,2,3,4,5,6,7,8},i;

    scanf("%d%d",&n,&M);
    for(i=1;i<=n;i++)
        sum+=(n+1-i)*i;

 //   printf("%d",sum);
    print_m(0,val);

    return 0;
}


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

int main()
{
long long int n,m,s;
scanf("%I64d",&s);
n=(sqrt(1+8*s)-1)/2;
m=(n*(n+1))/2;
if(m==s)
printf("%I64d",n);
else
printf("%I64d",s-m);
return 0;
}


#include <stdio.h>
int g(int n)
{
	if (n==1 || n==0) return n;
	else
		return 2;
}
int gao(int m, int n)
{
	if (n==1) return m;
	else if (n==2)
		return (m/4*2 + g(m%4)) * 2;
	else
		return (n * m + 1 ) / 2;

}
int main()
{
	int m, n, temp;
	while (~scanf("%d %d", &m, &n))
	{
		if (m<n)
		{
			temp = m;
			m = n;
			n = temp;
		}
		printf("%d\n", gao(m, n));
	}
	return 0;
}


#include<stdio.h>
int main()
{
    int a,b,r,d;
    scanf("%d %d %d",&a,&b,&r);
    d=2*r;
    if(a>=d&&b>=d) printf("First");
    else printf("Second");
}


#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,c,r,o,sum1,sum=0,y,a,b,count1=0,a2,b2,ab;

scanf("%lld%lld%lld",&a,&b,&ab);
if(a>b){
    printf("%lld",(2*ab)+(b*2)+1);
}
else{
    if(a==b){
       printf("%lld",(2*ab)+(a*2));
    }else{
      printf("%lld",(2*ab)+(a*2)+1);
    }
}
return 0;
}


#include <stdio.h>

int n;
int p[128];
int is_gusu[128];

int memo[128][2][128][128];

int search(int idx, int prev_is_gusu, int left_gusu, int left_kisu) {
	int answer = 9999, candidate;
	if (idx >= n) return 0;
	if (memo[idx][prev_is_gusu][left_gusu][left_kisu]) {
		return ~memo[idx][prev_is_gusu][left_gusu][left_kisu];
	}

	if (p[idx] == 0) {
		if (left_gusu > 0) {
			candidate = search(idx + 1, 1, left_gusu - 1, left_kisu);
			if (idx > 0 && !prev_is_gusu) candidate++;
			if (candidate < answer) answer = candidate;
		}
		if (left_kisu > 0) {
			candidate = search(idx + 1, 0, left_gusu, left_kisu - 1);
			if (idx > 0 && prev_is_gusu) candidate++;
			if (candidate < answer) answer = candidate;
		}
	} else {
		answer = search(idx + 1, is_gusu[idx], left_gusu, left_kisu);
		if (idx > 0 && !prev_is_gusu != !is_gusu[idx]) answer++;
	}

	return ~(memo[idx][prev_is_gusu][left_gusu][left_kisu] = ~answer);
}

int main(void) {
	int i;
	int kisu, gusu;
	if (scanf("%d", &n) != 1) return 1;
	kisu = (n + 1) / 2;
	gusu = n / 2;
	for (i = 0; i < n; i++) {
		if (scanf("%d", &p[i]) != 1) return 1;
		if (p[i] != 0) {
			if (p[i] % 2 == 0) {
				is_gusu[i] = 1;
				gusu--;
			} else {
				is_gusu[i] = 0;
				kisu--;
			}
		}
	}
	printf("%d\n", search(0, 0, gusu, kisu));
	return 0;
}


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

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

int main()
{
    int N, M;
    scanf("%i %i", &N, &M);
    if(M < N)
    {
        printf("0");
        exit(0);
    }
    int arr[M], amt[101];
    memset(amt, 0, 101*sizeof(int));
    for(int i = 0; i < M; i++)
    {
        scanf("%i", &arr[i]);
        amt[arr[i]]++;
    }
    int max = 0;
    for(int i = 0; i <= 100; i++)
    {
        if(amt[i] > max)
        {
            max = amt[i];
        }
    }
    qsort(arr, M, sizeof(int), cmpfunc);
    int amt2[M+1], count = 0;
    for(int i = 0; i < 101; i++)
    {
        if(amt[i] > 0)
        {
            amt2[count++] = amt[i];
        }
    }
    int ma = 0;
    for(int i = 1; i <= 1000; i++)
    {
        int peop = 0;
        for(int j = 0; j < count; j++)
        {
            peop += amt2[j]/i;
        }
        if(peop >= N)
        {
            ma = i;
        }
    }
    printf("%i", ma);
}


#include <stdio.h>

int main() {
	int x;

	scanf("%d", &x);
	printf("%d\n", 2 - x * x);
	return 0;
}


#include "stdio.h"

#define MAX_MANHOLE_COUNT 5001

#define BASE "%d"
typedef int Base;

typedef struct UManhole
{
    Base Stones;
    Base IsCollected;
} UManhole;

int main()
{
    Base Count = 0;
    UManhole Manholes[MAX_MANHOLE_COUNT];
    Base Standing = 0;
    Base Turns = 0;
    Base Garbage = -1;

    scanf(BASE BASE, &Count, &Standing);
    for (Base i = 1; i <= Count; i++)
    {
        Manholes[i].Stones = 1;
        Manholes[i].IsCollected = 0;
    }

    Turns = Count + Count + 1;
    if (Standing <= Count / 2)
    {
        Turns += (Standing - 1);
        Turns += (Count - 1);
    }
    else
    {
        Turns += (Count - Standing);
        Turns += (Count - 1);
    }

    printf(BASE"\n", Turns);

	return 0;
}


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

int main(int argc, char const *argv[])
{
	char str[201];
	scanf("%s",str);
	int n;
	scanf("%d",&n);
	int i =0;
	int count_letter=0,count_sf=0,count_stick=0,length=0;
	int sf_index = -1;
	while(str[i] != '\0')
	{
		if (str[i] == '?')
		{
			count_stick++;
		}
		else if (str[i] == '*')
		{
			count_sf++;
			sf_index = i;
		}
		else
		{
			count_letter++;
		}
		i++;
	}
	length = i;
	//printf("%d %d %d %d\n",count_letter,count_sf,count_stick,length);

	if (count_letter - (count_stick+count_sf) > n)
	{
		printf("Impossible");
	}
	else
	{
		if(n > count_letter)
		{
			//printf("%d\n",sf_index);
			if(sf_index != -1)
			{
				for (int i = 0; i < sf_index; ++i)
				{
					if (str[i]!='?' && str[i]!='*')
					{
						printf("%c",str[i]);
					}

				}

				for (int i = 0; i < (n-count_letter); ++i)
				{
					printf("%c",str[sf_index-1]);
				}

				for (int i = sf_index+1; i < length; ++i)
				{
					if (str[i]!='?' && str[i]!='*')
					{
						printf("%c",str[i]);
					}
				}
			}
			else
			{
				printf("Impossible");
			}

		}
		else if (n < count_letter)
		{
			count_letter = count_letter - n ;
			for (int i = length -1; i >0; --i)
			{
				if (count_letter == 0)
				{
					break;
				}
				if(str[i] == '?' || str[i] == '*')
				{
					str[i-1] = str[i];
					count_letter -- ;
					i--;
				}
			}
			int j = 0;
			while(str[j]!= '\0')
			{
				if (str[j] != '?' && str[j] != '*')
				{
					printf("%c",str[j]);
				}
				j++;
			}
		}
		else
		{
			int j = 0;
			while(str[j]!= '\0')
			{
				if (str[j] != '?' && str[j] != '*')
				{
					printf("%c",str[j]);
				}
				j++;
			}
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
typedef long long int LL;
char x[1000];
char y[1000];
char z[1000];
int incr()
{
   int i=0;
   while(x[i]!='\0')
      i++;
   i--;
   while(x[i]=='z')
   {
      x[i]='a';
      i--;
   }
   x[i]+=1;
   return 0;
}
int main()
{
   int i,diff;
   scanf("%s",x);
   scanf("%s",y);
   incr();
   if(strcmp(y,x)>0)
      printf("%s\n",x);
   else
      printf("No such string\n");
   return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define modd 1000000007
long long fast_expo(long long a,long long b)
{
	long long res=1;
	while(b>0)
	{
		if(b&1)
			res=(res*a)%modd;
		a=(a*a)%modd;
		b=b>>1;
	}
	return res;
}
int main()
{
	long long fact[200001];
	int i,n,count=0;
	fact[0]=1;
	for(i=1;i<200001;i++)
		fact[i]=(fact[i-1]*i)%modd;
	while(scanf("%d",&n)==1)
	{
		long long ans=(fact[2*n-1]*((fast_expo(fact[n],modd-2)*fast_expo(fact[n-1],modd-2))%modd))%modd;
		ans=(2*ans)-n;
		if(ans<0)
			printf("%I64d\n",(ans+modd)%modd);
		else printf("%I64d\n",ans%modd);
	}
	return 0;
}


 #include<stdio.h>
 main()
 {
     int number[30];
    int i, j, a, n,s=0,k,f=0;
     //printf("Enter the value of N\n");
    scanf("%d", &k);
    //printf("Enter the numbers \n");
    for (i = 0; i < 12; ++i)
    scanf("%d", &number[i]);
 for (i = 0; i < 12; ++i)
    {
        for (j = i + 1; j < 12; ++j)
        {
            if (number[i] < number[j])
            {
                a = number[i];
                number[i] = number[j];
                number[j] = a;
            }
        }
    }
    if(k==0)
        printf("0");
    else
    {
      for (i = 0; i < 12; ++i)
    {
        s=s+number[i];
        if(s>=k)
        {
            f=1;
            printf("%d",i+1);
            break;
        }
    }
    if(f==0)
        printf("-1");
    }
 }


#include<stdio.h>
#include<string.h>
int main(){
char a[100],b[100];
    gets(a);
    strcpy(a,strlwr(a));
    gets(b);
    strcpy(b,strlwr(b));
    if(strcmp(a,b)==0)
    {
        printf("%d",0);
    }
     else if (strcmp(a,b)>0)
    {
        printf("%d",1);
    }
    else
    {
        printf("%d",-1);
    }
}


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

int main(int argc, char *argv[]) {
	long long n, m, l, r, x;
	scanf("%I64d%I64d", &n, &m);
	if (n <= m) printf("%I64d\n", n);
	else {
		for (l = 1, r = sqrt(2 * n - 2 * m) + 1; l <= r; ) {
			x = (l + r) / 2;
			if (x * (x + 1) / 2 >= n - m)
				r = x - 1;
			else
				l = x + 1;
		}
		printf("%I64d\n", m + r + 1);
	}
	return 0;
}


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


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


#include<stdio.h>
#define N 50+5
int a[N];
int main() {
     int n,k;
     scanf("%d%d",&n,&k);
     int i;
     int participants=0;
     //可以不从头加起，而是从第k位加起，这里k就不用减一，因为k正好表示k－1的下一位！
     //因为k前面的都是大于等于第k位的！
     for (i=0;i<n;i++) {
          scanf("%d",&a[i]);
     }
     //我知道错在哪里了，a［k－1］项在没有读完数组时，时不能确立的，整个数组至少要读k项，但是我在没有得到a[k-1]的值时，就直接进行比较，这是一个错误，mac gcc竟然没有指出这个错误！
     //改正办法在记录下整个数组后在比较！
     //因为数组是从零开始，而k从一开始，要使两者对应，所以我才减一 a[k-1]就是第k位的值！
     for (i=0;i<n;i++) {
          if(a[i]>0 && a[i]>=a[k-1]) {
               participants++;
          }
     }

     //printf("\nparticipants = %d\n",participants);
     printf("%d\n",participants);
     return 0;
}