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


#include<stdio.h>
#include<stdlib.h>
int gcd(int a,int b){
if(a==0) return b;
else gcd(b%a,a);}
int main(){
int a,b,c,temp;
int no1,no2,count1=0,count2=0;
scanf("%d %d",&a,&b);
if(a>b) {temp=a;a=b;b=temp;}
c=gcd(a,b);
no1=a/c;
no2=b/c;
while(1){
if (no1%2==0){
count1++;
no1=no1/2;
continue;}
if (no1%3==0){
count1++;
no1=no1/3;
continue;}
if (no1%5==0){
count1++;
no1=no1/5;
continue;}
break;}
while(1){
if (no2%2==0){
count2++;
no2=no2/2;
continue;}
if (no2%3==0){
count2++;
no2=no2/3;
continue;}
if (no2%5==0){
count2++;
no2=no2/5;
continue;}
break;}
if (no1!=1 || no2!=1) printf("-1");
else printf("%d\n",count1+count2);
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<math.h>
int gcd(int a,int b)
{
    if(a<=b)
    {
        if(b%a==0)
            return a;
        else
            return gcd(a,b-a);
    }
    else
    {
        if(a%b==0)
            return b;
        else return gcd(a-b,b);
    }
}
int main()
{
    int a,b,hcf,flag=0,c=0;
    scanf("%d%d",&a,&b);
    if(a==b)
        printf("0\n");
    else
    {
        hcf=gcd(a,b);
        //printf("%d",hcf);
        a=a/hcf;b=b/hcf;
        while(a!=1)
        {
            if(a%2==0) {a=a/2;c++;}
            else if(a%3==0) {a=a/3;c++;}
            else if(a%5==0) {a=a/5;c++;}
            else {flag=1;break;}
        }
        a=b;
        while(a!=1)
        {
            if(a%2==0) {a=a/2;c++;}
            else if(a%3==0) {a=a/3;c++;}
            else if(a%5==0) {a=a/5;c++;}
            else {flag=1;break;}
        }
        if(flag==1) printf("-1");
        else printf("%d\n",c);
    }
    return 0;
}


#include <stdio.h>

int main()
{
	int digit_flaws[10]={2,7,2,3,3,4,2,5,1,2},n,ans=1;
	scanf("%d",&n);
	while(n>-1)
	{
		ans*=digit_flaws[n%10];
		n/=10;
	}
	printf("%d",ans);
	return 0;
}


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

    for(i=1;i<=n;i++)
    {
        u=(i-1)*4;
        units=units+u*a[i];
    }
    printf("%d",units);
    return 0;
}


#include <stdio.h>
int main(void)
{
    int n,i,j=0;
    scanf("%d", &n);
    int k[n]
    for(i=0;i<n;i++)
    {
        scanf("%d", &k[i]);

    }
    for(i=0;i<n;i++)
    {
        j+=i*k[i];
    }
    printf("%d", j*4);
    return 0;

}


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

#define ll long long

long long aa = (long long)1e16;

int main() {
    ll x0, y0, ax, bx, by, ay;
    ll xs, ys, t;
    cin >> x0 >> y0 >> ax >> ay >> bx >> by;
    cin >> xs >> ys >> t;
    vector<pair<ll, ll>> arr;
    int counter = 1;
    arr.push_back(make_pair(x0, y0));
    while(arr[counter - 1].first < aa && arr[counter - 1].second < aa) {
        arr.push_back(make_pair(ax * arr[counter - 1].first + bx, ay * arr[counter - 1].second + by));
        counter++;
    }
    // sort(arr.begin(), arr.end());
    bool a[arr.size()];
    ll myMin = aa;
    int index = -1;
    for(int i = 0; i < arr.size(); i++) {
        ll temp = abs(arr[i].first - xs) + abs(arr[i].second - ys);
        if(temp < myMin) {
            index = i;
            myMin = temp;
        }
    }
    t -= abs(arr[index].first - xs) + abs(arr[index].second - ys);
    if(t < 0) {
        cout << 0;
        return 0;
    }
    xs = arr[index].first;
    ys = arr[index].second;
    int ct = 1;
    for(int i = 0; i < arr.size(); i++) {
        a[i] = false;
    }
    a[index] = true;
    while(t > 0 && ct <= arr.size()) {
        myMin = aa;
        for(int i = 0; i < arr.size(); i++) {
            if(!a[i]) {
                ll temp = abs(arr[i].first - xs) + abs(arr[i].second - ys);
                if(temp < myMin) {
                    index = i;
                    myMin = temp;
                }
            }
        }
        a[index] = true;
        ct++;
        t -= abs(arr[index].first - xs) + abs(arr[index].second - ys);
        xs = arr[index].first;
        ys = arr[index].second;
    }
    cout << ct;
    return 0;
}


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

int main(int argc, char* argv[])
{
    int **a;
    int m,x,i,j;
    int count=0;
    scanf("%d%d",&m,&x);
    a=(int**)malloc(sizeof(int*)*m);
    for(i=0;i<m;i++){
        a[i]=(int*)malloc(sizeof(int)*m);
    }
    for(i=0;i<m;i++){
        for(j=0;j<m;j++){
            a[i][j]=(i+1)*(j+1);
            if(a[i][j]==x)
                count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


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

int main()
{

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

    int** mtx;
    mtx = malloc(n*sizeof(*mtx));
    for(int i=1;i<=n;i++)
        mtx[i] = malloc(n*sizeof(**mtx));

    int occur = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            mtx[i][j]= i*j;
            if (mtx[i][j] == x)
                occur++;
        }
    }

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


#include<stdio.h>
int main()
{
	long long n, m, s;
	scanf("%lld %lld %lld", &n, &m, &s);
	int y = 0, flag = 0,t;
	if (s <= n - 1)
	{
		printf("1 %d", s + 1);
	}
	else
	{
		s = s - n + 1;
		while (s!=0)
		{
			if (flag == 0) t = 1;
			else t = 2;
			if (s <= m - t)
			{
				printf("%lld %lld", n, s + 1);
				break;
			}
			else
			{
				s = s - m + t;
				if (n == 1)
				{
					y = 1;
					break;
				}
				n--;
				if (s == 1)
				{
					printf("%lld %lld", n, m);
					break;
				}
				else
				{
					s--;
					if (s <= m - 2)
					{
						printf("%lld %lld", n, m - s);
						break;
					}
					else
					{
						s = s - m + 2;
						if (n == 1)
						{
							y = 2;
							break;
						}
						--n;
						if (s == 1)
						{
							printf("%lld %lld",n, m);
							break;
						}
						else
						{
							s--;
						}
					}
				}
			}
			flag = 1;
		}
		if (y == 1) printf("1 %lld", n);
		if (y == 2) printf("1 2");
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
long long int mmax(long long int a,long long int b){
    if(a>b) return a;
    else return b;
}
long long int fun(long long int i){
    return (i*(i+1))/2;
}
long long int target;
long long int binSearch(long long int i,long long int j){
    long long int mid;
    while (i<j) {
        mid=(i+j)/2;
        if(i==mid) break;
        if(fun(mid)<target)
            i=mid;
        else j=mid;
    }
    return i;
}
long long int dp[200001][2];
int main(){
    long long int r,g;
    scanf("%lld %lld",&r,&g);
    target=r+g+1;
    long long int h=binSearch(1, target);
    long long int ans=0;
    dp[0][0]=1;
    for (long long int height=1; height<=h; height++) {
        for (long long int red=0; red<=r; red++) {
            if(fun(height)-red<=g){
                dp[red][1]=dp[red-height][0]+dp[red][0];
                dp[red][1]%=1000000007;
                if(height==h)
                    ans+=dp[red][1];
                ans%=1000000007;
            }
        }
        for(long long int red=0; red<=r; red++) {
            dp[red][0]=dp[red][1];
            dp[red][1]=0;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
#define N 35
int main(){
    char s[N];
    scanf("%s",s);
    int n=strlen(s);
    int i;
    int answer=(n-1)/2;
    for(i=1;i<n;i++){
        if(s[i]=='1'){
            answer++;
            break;
        }
    }
    printf("%d\n",answer);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int count[100];
int cmp (const void *a , const void *b){
    return *(int *)b - *(int *)a;
}

int main(void){
    memset(count, 0, 100 * sizeof(int));
    int n, p, c[100], d = 0, sum = 0;
    scanf("%d%d", &n, &p);
    for(int i = 0; i < n; i++){
        scanf("%d", &c[i]);
        sum += c[i];
    }
    if(sum < p){
        printf("-1\n");
        return 0;
    }
    sum = 0;
    qsort(c, n, sizeof(int), cmp);
    int index = 0;
    for(int k = 0; index < n && sum < p; k++, d++){
        for(int i = 0; i < n; i++){
            if(c[index] - i > 0){
                sum += c[index] - i, index++, count[k]++;
                if(sum >= p){
                    printf("%d\n", d + 1);
                    return 0;
                }
            }
            else break;
        }
    }
    while(d <= n){
        for(int i = 0; i <= d; i++){
            while(count[i] >= count[i + 1]){
                int j = 0;
                while(count[i] <= count[j]) j++;
                if(j > d) d = j;
                count[j]++, sum += count[i] - count[j], count[i]--;
                if(sum >= p){
                    printf("%d\n", d + 1);
                    return 0;
                }
            }
        }
    }
    return 0;
}


#include <stdio.h>
int a[100];
void qs(int first, int last)

{
    if (first < last)
    {
        int left = first, right = last, middle = a[(left + right) / 2];
        do
        {
            while (a[left] < middle) left++;
            while (a[right] > middle) right--;
            if (left <= right)
            {
                int tmp = a[left];
                a[left] = a[right];
                a[right] = tmp;
                left++;
                right--;
            }
        } while (left <= right);
        qs( first, right);
        qs( left, last);
    }
}

int main() {
    int n,l,r,sum,t,middle,in,i,j;
    long long int m;
    scanf("%i %lld",&n,&m);
    for (int i=1;i<=n;++i) scanf("%i",&a[i]);
    qs(1,n);

    l=1;
    r=n;

    while(l<=r){
        sum=0;
        t=n;
        middle=(l+r)/2;
        (n % middle==0)?(in= n / middle):(in=( n / middle)+1);
        for(i=0;i<in;i++){
            for(j=1;j<=middle&&t>=1;j++){
                if (a[t] - i > 0)
                    sum = sum + a[t] - i;
                t--;
            }
        }
        if(sum==m){
            l=middle;
            r=middle;
            break;
        }
        else if(sum<m){
            l=middle+1;
        }
        else{
            r=middle-1;
        }
    }

    if((l <= n) && (r >= 0)){
        if((l+r)%2!=0)
            printf("%d",(l+r)/2+1);
        else
            printf("%d",(l+r)/2);
    }
    else printf("-1");
    return 0;


#include <stdio.h>
#define INF ~0ULL
#define ULL unsigned long long
using namespace std;
ULL p[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
ULL n, ans;
void dfs(ULL depth, ULL temp, ULL num, ULL up)
{
    if (num == n && temp < ans) ans = temp;
    if (num >= n || depth == 16) return;
    for (int i = 1; i <= up; ++i)
    {
        if (temp * p[depth] >= ans) return;
        else dfs(depth + 1, temp = temp * p[depth], num * (i + 1), i);
    }
}
int main()
{
    while (scanf("%llu", &n) != EOF)
    {
        ans = INF;
        dfs(0, 1, 1, 64);
        printf("%llu\n", ans);
    }
}


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

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

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

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

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

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

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

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

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

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

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

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

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


#include <stdio.h>

int main(){

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

    int i;
    int storage[n];

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

    int candy[n];
    for(i=0; i<n; i++){
        candy[i]=0;
    }
    int counter=0;
    for(i=0; ; ){
        candy[i]=candy[i]+m;
        if(storage[i]!=-1 && candy[i]>=storage[i]){
            storage[i]=-1;
            counter++;
        }
        if(counter==n-1){
            break;
        }
        if(i==n-1){
            i=0;
        }
        else{
            i++;
        }
    }
    for(i=0; i<n; i++){
        if(storage[i]!=-1){
            printf("%d", i+1);
            break;
        }
    }

    return 0;
}


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

int main(){
	int vet[200];
	int id[100];
	int i, j;
	int n, m;
	int cont_fila=0;
	int total, limit;

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

	total = n;

	while(total > 1){
		for(i = 0; i < 200; i++){
			vet[i] = 0;
			id[i] = i;
		}

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

		for(i = 0; i < n; i++){
			if(vet[i] > m){

				vet[i] -= m;
				vet[cont_fila+100] = vet[i];
				id[i] = cont_fila + 100;
				vet[i] = 0;

				cont_fila++;
			}
			else if(vet[i] != 0 && vet[i] <= m){

				vet[i] = 0;
				total--;

				if(total == 1){
					break;
				}
			}
		}

		limit = 100 + cont_fila;
		cont_fila = 0;

		for(i = 100; i < limit; i++){
			if(vet[i] > m){

				vet[i] -= m;
				vet[cont_fila] = vet[i];
				id[i] = cont_fila + 100;
				vet[i] = 0;

				cont_fila++;
			}
			else if(vet[i] != 0 && vet[i] <= m){
				vet[i] = 0;
				total--;

				if(total == 1){
					break;
				}
			}
		}
	}

	for(i = 0; i < 200; i++){
		if(vet[i] != 0){
			for(j = 0; j < n; j++){
				if(i == id[j]){
					printf("%d\n", j+1);
				}
			}
		}
	}

	return 0;
}
/* 1522078044284 */


#include<stdio.h>
#include<stdlib.h>
int compare(const void *a,const void *b)
{
	return (*(int *)a-*(int *)b);
}
int main()
{
    int n,i,j=0,k,l;
    scanf("%d",&n);
    int c[i],a[n],b[n];
    for(i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
   b[i]==a[i];
   }
	qsort(a,n,sizeof(int),compare);
	for(i=0;i<n;i++)
	{
		if(i==0)
		c[i]=a[n-1];
		else if(i==n-1)
		c[i]=a[0];
		else
		c[i]=a[i];
	}
    for(i=0;i<n;i++)
    printf("%d ",c[i]);
    return 0;
}


#include<stdio.h>

#include<stdlib.h>
#include<time.h>
int main()
{
    int x,t,a,b,da,db,i,flag;
    int sum=0,less;
    scanf("%d%d%d%d%d%d",&x,&t,&a,&b,&da,&db);
    sum+=a;
    for(i=0;i<t;i++)
    {
                     //sum+=a+i*da;
                     if(sum>x){
                     printf("NO");break;
                     }
                     else
                     {
                     less=x-sum;
                     while(t>1)
                     {
                        sum+=b-t*db;
                        if(sum==less)
                        flag+=1;
                        else
                        flag=0;
                     }
                     }
                     if(flag=1)
                     printf("YES");
                     else
                     printf("NO");
    }
     return 0;
}


#include<stdio.h>

int main(){
	int test;
	int tcase[100];
	int k = 0;
	int total = 0;
	int totalA = 0 , totalE = 0;

	scanf("%d" , &test);
	getchar();
	for(int i = 0; i < test ; i++){
		scanf("%d", &tcase[i] );
		total = total + tcase[i];

		if(tcase[i] > k) k = tcase[i];
	}

	bool check = false;
	do{
		for(int i = 0 ; i< test ; i++){
			totalA += (k-tcase[i]);
		}
		if(totalA < total){
			k++;
			check = true;
		}
	}while(check = true);

	printf("%d" , k);

	return 0;
}


#include<stdio.h>

int main(void)
{
    int bal;
    scanf("%d", &bal);
    if(bal>0)
    {
        printf("%d",bal);
        return;
    }
    if(bal<0)
        {
            int temp = (bal/100)*10 + (bal%10);
            printf("%d",(temp>bal/10)?temp:bal/10);
            return;
        }
}


#include <stdio.h>
#include <stdin.h>

int tranfCartaParaOrdemDeCarta(char c) {
	switch (c) {
		case 'T': return 1;
		case 'J': return 2;
		case 'Q': return 3;
		case 'K': return 4;
		case 'A': return 5;
		default:
	}
}

void cardGame() {
	char c, s[2][2];

	scanf("%c", c);
	scanf("%s %s", s[0], s[1]);

	if (s[0][1] == s[1][1])
		if (tranfCartaParaOrdemDeCarta(s[0][0]) > tranfCartaParaOrdemDeCarta(s[1][0]))
			printf("YES");
		else
			printf("NO");
	else if (s[0][1] == c)
		print("YES");
	else
		printf("NO");
}

int main(){

	cardGame();
	return 0;
}


#include<stdio.h>
int main()
{
    int n,w,k,i;
    scanf("%d",&n);
    while(n)
    {
        scanf("%d%d%d",&k,&n,&w);
        int sum=0;
        for(i=0;i<=w;i++)
        {
            sum+=k*i;
        }
        if(sum>=n)
          printf("%d",sum-n);
        else
          printf("0");
    }
    return 0;
}


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

    }
    return 0;
    }


#include<stdio.h>
int main()
{
    int a,b,c,k=0,r=0,rem=0,count=0;
    double bf,dec;
    scanf("%d%d%d",&a,&b,&c);
    bf=b/1.0;
    r=a%b;
    dec=r/bf;
    while(dec!=0)
    {
        dec*=10;
        rem=(int)dec%10;
        count++;
        if(rem==c)
        {
            k=1;
            break;
        }
    }
    if(k==1)
        printf("%d",count);
    else
        printf("-1");
    return 0;
}


#include <stdio.h>

int a, b, c, s, ans;
int main(){
	scanf("%d%d%d", &a, &b, &c);
	while (a < b){
		a *= 10;
		ans++;
	}
	s = a;
	if (a / b != c) {
		ans++;
		a = (a%b)*10;
	}
	while (a/b!=c){
		if (a < b)a *= 10;
		else if (s == a){
			ans = -1;
			break;
		}
		else a = (a%b)*10;
		ans++;
	}
	printf("%d", ans);
}


#include <stdio.h>

int main(void)
{
    int n,i,j;
    scanf("%d",&n);
    if(n==1)
        printf("2");
    else if(n==2)
        printf("3");
    else
    {
        if(n%2!=0)
            n++;
        for(i=4,j=4;i<=n;i+=2,j++);
        printf("%d",--j);
    }
    return 0;
}


#include<stdio.h>

int main(){
  int D;
  long n, k, M, ans;
  scanf("%ld%ld%ld%d", &n, &k, &M, &D);
  ans = M;
  for(int i = 1; i <= D; i++){
    long cur = n / (k * i);
    long lmax = cur * i;
    if(i < D){
      if(n / cur > k * i){
        lmax += cur;
      } else{
        while(cur && n / cur-- < k * i);
        lmax = lmax > cur * (i + 1) ? lmax : cur * (i + 1);
      }
    }
    ans = ans > lmax ? ans : lmax;
  }
  printf("%ld", ans);
  return 0;
}


#include<stdio.h>

int main(){
  int D;
  long n, k, M, ans;
  scanf("%ld%ld%ld%d", &n, &k, &M, &D);
  ans = M;
  for(int i = 1; i <= D; i++){
    long cur = n / (k * i);
    long lmax = cur * i;
    if(!cur) break;
    if(i < D){
      if(n / cur > k * i){
        lmax += cur;
      } else{
        while(cur && n / cur-- < k * i);
        lmax = lmax > cur * (i + 1) ? lmax : cur * (i + 1);
      }
    }
    ans = ans > lmax ? ans : lmax;
  }
  printf("%ld", ans);
  return 0;
}


#include<stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    int sum=0,d,f=5;
    for(int i=0;i<n;i++)
    {
    scanf("%d",&d);
    sum=sum+d;
    }
    for(int i=1;i<5;i++)
    {
    if((sum+i)%n==1)
    f--;
    }
    print("%d",f);
    }


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

int main()
{
	char s[100],temp_s;
	char *ps;
	int i, length, max, num_vk;

	while (1)
	{
		scanf("%s", s);
		max = 0;
		num_vk = 0;
		length = strlen(s);
		for (i = 0; i < length; i++)
		{
			temp_s = s[i];
			s[i] = 'V';
			ps = strstr(s, "VK");
			num_vk = 0;
			//		printf("=============================s=%s\n", s);
			while (ps != NULL)
			{
				num_vk++;
				//			printf("num_vk=%d, ps=%s\n", num_vk, ps);
				ps = ps + 2;
				ps = strstr(ps, "VK");
			}
			if (max < num_vk)
				max = num_vk;
			s[i] = temp_s;
		}
		for (i = 0; i < length; i++)
		{
			temp_s = s[i];
			s[i] = 'K';
			ps = strstr(s, "VK");
			num_vk = 0;
			while (ps != NULL)
			{
				num_vk++;
				ps = ps + 2;
				ps = strstr(ps, "VK");
			}
			if (max < num_vk)
				max = num_vk;
			s[i] = temp_s;
		}
		printf("%d\n", max);
	}
	return 0;

}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define N 150

int main()
{
    char a[N];
    while(~scanf("%s",a))
    {
        int i,k=1,cnt=0;
        for(i=0; a[i+1]!='\0'; )
        {
            if(a[i]=='V'&&a[i+1]=='K')
            {
                cnt++;i+=2;
            }
            if(k)
            {
                if(a[i]=='V'&&a[i+1]=='V')
                {
                    k=0;
                    cnt++;i+=2;
                }
                else if(a[i]=='K'&&a[i+1]=='K')
                {
                    k=0;
                    cnt++;i+=2;
                }
            }
            else
                i++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}


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

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

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

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

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

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

    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
	long int n,k,max;
	scanf("%ld%ld",&n,&k);
	if(n>k)
	{
		if(((n-1)/3)<k)
		max=n-k;
		while(((n-1)/3)>=k)
		{
		n=3*((n-1)/3);
		max=n-k;
		}
		printf("%ld %ld",1,max);
	}
	else
	printf("%ld %ld",0,0);
	return 0;
}


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


#include<stdio.h>
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int ans=1;
	while(1)
	{
		if(k%2==0)
		{
			ans++;
			k=k/2;
		}
		else
			break;
	}
	printf("%d\n",ans);
	return 0;
}


#include<stdio.h>
int main()
{
    long long a,b,c,r,m;
    scanf("%lld %lld %lld",&a,&b,&c);
    if(a==c)
    {
        r=a+b+(2*c);

    }
    else
    {
        m=(b-a)/2;
        r=a+b+c-m;
    }
    print("%lld",r);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
char s[20],t[20];
int a=0,b=0,i=0,ok=0;
scanf("%s",&s);
scanf("%s",&t);
b=(int)(t[i]);
a=(int)(s[i]);
while(a){
  if(i==0){printf("%c",a);i++;a=(int)(s[i]);}
  else if(a<b){printf("%c",a);i++;a=(int)(s[i]);}
  else if(a>b){printf("%c",b);ok=1;break;}
}
if(ok==0)printf("%c",b);
}


#include <stdio.h>
int main()
{
	char esm[10];
	char shohrat[10];
	scanf("%s" , esm);
	scanf("%s" , shohrat);
	for(int i=0;;i++)
	{
		if(esm[i]<shohrat[0]&&s[i]!=0)
		printf("%c" , esm[i]);
		else break;
	}
	printf("%c" , shohrat[0]);

}


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

typedef struct _n {
    struct _n *prev, *next;
    int val;
} no;

no *cons(ne, val) no *ne; {
    no *n = calloc(1, sizeof(no));
    n->next = ne; if(ne) ne->prev = n;
    n->val = val;
    return n;
}

no *cycle(n) {
    no *fst = cons(NULL, n);
    no *lst = fst;
    while(--n > 0)
        fst = cons(fst, n);
    lst->next = fst;
    fst->prev = lst;
}

main() {
    int n, a, x, b, y;
    scanf("%d %d %d %d %d", &n, &a, &x, &b, &y);
    no *l = cycle(n);
    no *c1 = l, *c2 = l;

    while(c1->val != a) c1 = c1->next;
    while(c2->val != b) c2 = c2->next;

    while(c1 != c2 && c1->val != x && c2->val != y) {
        c1 = c1->next; c2 = c2->prev;
    }

    if(c1 == c2) puts("YES");
    else puts("NO");
}


#include<stdio.h>

int main(){
	long unsigned n, temp, ans, cnt=0;
	scanf("%lu",&n);
    temp=n;
    while(temp)
    {
        ans=temp%10;
        temp=temp/10;
        cnt++;
    }
    ans=ans+1;
    for(i=1;i<cnt;i++)
    {
        ans=ans*10;
    }
    ans=ans-n;
    printf("%lu\n",ans);
    return 0;
}


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

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

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

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

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

    return 0;
}


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

int main()
{
    int x,y=0;
scanf("%d",x);
if ((x%5)) y=1;
printf("%d",(x/5)+y);

    return 0;
}


#include<stdio.h>
int main()
{
    int k,c=1,s=0;
    scanf("%d",&k);
    while(k>0)
    {
        k+k-c;
        c+=1;
        s+=1;
    }
    printf("%d",s);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int sum,n,k,s,p;
    scanf("%d %d %d %d",&k,&n,&s,&p);
    if(n%s!=0)
        sum=(n/s)+1;
    else
        sum=n/s;
    sum=sum*k;
    if(sum%p!=0)
        sum=(sum/p)+1;
    else
        sum=(sum/p);
    printf("%d",sum);
    return 0;
}


#include<stdio.h>
#define swap(a,b) { t=a; a=b; b=t; }

int n;
int h[100000],son=0,t,k,l,hh[10000];
void ekle(int x)
{
	h[++son]=x;
	k=son;
	while(k/2)
	{
		if(h[k/2]<h[k])
		{
			swap(h[k/2],h[k])
			k/=2;
			continue;
		}
		break;
	}
}

void sil()
{
	int x = h[n];
	h[n--] = h[1];
	int k = 1;
	while(k * 2 <= n)
	{
		k=k*2+(h[2*k+1]>h[2*k] && 2*k+1 <= n);
		if(x<=h[k])	h[k/2] = h[k];
		else{ k /= 2; break; }
	}
	h[k] = x;
}
int main()
{
	int i,j,a;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		ekle(a);
	}
	if(n==1)
	{
		printf("1");
		return 1;
	}
	int N = n,terim,b,sonraki,yukseklik,t=0;
	n = son;
	for(i=0;i<N;i++)
		sil();
	n=N;
	/*for(i=1;i<=n;i++)
		printf("%d ",h[i]);
	printf("\n");*/
	//printf("%d ",n);
	while(n>0)
	{
		t++;
		b=1;
		yukseklik=0;
		//terim=0;
		//puts("");
		while(b<N)
		{
			while((hh[b] || h[b]<yukseklik) && b<N)
			{
				b++;
			}
			if(h[b]<yukseklik)
				break;
			hh[b]=1;
			yukseklik++;
			n--;
		//	printf("%d ",h[b]);
			//getchar();
			//getchar();
			//printf("%d %d\n",h[b],yukseklik-1);
		}
	}
	printf("%d",t);
	return 0;
}


#include<stdio.h>
int main()
{
    int c,d,m,n,k,ans=0;
    scanf("%d%d%d%d%d",&c,&d,&m,&n,&k);
    m = m*n;
    m = m-d;
    if((c/n)>d)
        printf("%d\n",m*d);
    else
    {
        while(m)
        {
            m-=n;
            ans+=c;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <stdio.h>
#define min(a,b) (a<b?a:b)
int q=0;
int c,d,n,m,k,p,an;
int ans(int p,int q)
{
    if(p<=0)
        return q;
    return(min(ans(p-n,q+c),ans(p-1,q+d)));
}
int main() {
    scanf("%d %d",&c,&d);
    scanf("%d %d",&n,&m);
    scanf("%d",&k);
    an=ans(n*m-k,0);
    printf("%d ",an);
    return 0;
}


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


#include<stdio.h>
int main(){
int n,m,min1,max1,i,arr[105],flag1=-1,flag2=-1,h=-1,y=-1;
scanf("%d%d%d%d",&n,&m,&min1,&max1);
for(i=0;i<m;i++){
    scanf("%d",&arr[i]);
     if(arr[i]==min1)
        flag1=1;
     if(arr[i]<min1)
            h=1;
     if(arr[i]==max1)
        flag2=1;
     if(arr[i]>max1)
        y=1;
       }

  if(n-m==1&&(flag1==1||flag2==1))
        printf("Correct\n");

  else if(n-m>1&&(h=1||y=1))
        printf("Incorrect");

  else if(n-m==1&&(flag1!=1||flag2!=1))
            printf("Incorrect\n");

return 0;
}


#include<stdio.h>
int main()
{
    int m,n,Min,Max,a[100];
    while(scanf("%d%d%d%d",&n,&m,&Min,&Max))
    {int i,ok=1;
    for(i=0;i<=m-1;i++)
        scanf("%d",&a[i]);
    if(n-m>=2)
    {
        for(i=0;i<=m-1;i++)
            if(a[i]>Max||a[i]<Min)
        {ok=0;
        break;}
        if(ok==1)
            printf("Correct\n");
        else
            printf("Incorrect\n");
    }
    else if(n-m==1)
    {
        int ok1=1,ok2=0;
        ok=0;
        for(i=0;i<=m-1;i++)
            if(a[i]>Max||a[i]<Min)
        {ok1=0;
        break;}
        for(i=0;i<=m-1;i++)
            if(a[i]==Max||a[i]==Min)
        {
            ok2=1;
            break;
        }
        if(ok1&&ok2)
            ok=1;
            if(ok==1)
            printf("Correct\n");
        else
            printf("Incorrect\n");

    }

    }
   return 0;
}


#include<stdio.h>
#include<math.h>
int p[10000];
void isPrime(int n)
{
	int i,j,prime;

	p[0] = 0;
	p[1] = 0;

	for(i=2;i*i<=n;i++)
	{
		if(p[i] == 1)
		{
			for(j=i*2;j<=n;j+=i)
			{
			p[j] = 0;
			}
		}
	}
}

int check_prime(int a,int b,int l,int k)
   {

int c = 0;
   isPrime(b);

   for(int i=a;i<=a+l-1;i++)
   {
   	if(p[i] == 1)
   	{
   	c++;
   	}

   }
if(c<k)
	return 0;

int i=a,j=a+l-1;
while(j<b)
{
	if(p[i]==1)
		c--;
	i++;
	j++;

	if(p[j]==1)
		c++;

	if(c<k)
          return 0;

}

if(c<k)
{
	return	0;
}
return 1;
}

int main()
{
	int i,j,k,l,a,b;
	int s,e;
	int r,n,x = -1;
	scanf("%d %d %d", &a,&b,&k);
	for(i=0;i<=b;i++)
	{
		p[i] = 1;
	}
	s = 1;
	e = b - a + 1;
	while(s<=e)
	{
		l = (s+e)/2;
		r = check_prime(a,b,l,k);
		if(r == 0)
		{
			s = l+1;
		}
		if(r == 1)
		{
			x = l;
			e = l-1;
		}
	}
		printf("%d\n",x);

	return 0;
}


#include <stdio.h>

int main() {
	int k,l,m,n,d;
	int dizi[100000];
	int secimler[4];
	for (int i = 0; i < 100000; i++) {
		dizi[i] = 0;
	}
	scanf("%d %d %d %d %d",&k,&l,&m,&n,&d);
	secimler[0] = k;
	secimler[1] = l;
	secimler[2] = m;
	secimler[3] = n;
	int j = 0;
	for (int u = 0; u < 4; u++) {
		if (secimler[u] == secimler[u-1]) {
			u++;
			continue;
		}
		for (int i = secimler[u]; i < d; i += secimler[u]) {
			int kontrol = 0;
			for (int t = 0; t < 100000; t++)
				if (dizi[t] == i) {
					kontrol = 1;
					break;
			}
			if (kontrol != 1) {
				dizi[j++] = i;
			}
		}
	}
	if (j == 0) printf("%d",j);
	else printf("%d",j+1);
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n;
	scanf("%d",&n);
	int *array;
	array=(int*)calloc(n+1,sizeof(int));
	int i,j;
	for(i=1;i<n+1;i++)
	{
		scanf("%d",&array[i]);
		//printf("%d ",array[i]);
	}
	for(j=1;j<n+1;j++)
	{
		if(array[j]-array[j-1]>15)
		{
			printf("%d",array[j-1]+15);
			free(array);
			exit(1);
		}
	}
	printf("%d",array[n]);
	free(array);
}


#include <stdio.h>
int hh,mm;
int main()
{
printf(hh:mm);
scanf("%d %c %d",&hh &: &mm);
scanf("%d",&a);
printf(hh:mm+a);
return (0);
}


#include<stdio.h>

int main() {
	int n,m,k,i;
	scanf("%d %d %d",&n,&m,&k);
	if (n%2==0 || m==1) {
		puts("Marsel");
		return 0;
	}
	if (k==1) {
		puts("Timur");
		return 0;
	}
	for(i=1;i*i<=m;i++) if (m%i==0 && m/i>=k) break;
	if (i*i>m) {
		puts("Marsel");
		return 0;
	}
	puts("Timur");
	return 0;
}


#include<stdio.h>
int main()
{
  int n,a,b;
  scanf("%d\n",&n);
  int i=0,j=0,k=0;
  while(j<n)
  {
      scanf("%d %d\n",&a,&b);
      while(a>=1&&a<=6&&b>=1&&b<=6)
      if(a>b)
      {
          ++i;
      }
      else
      {
          ++k;
      }
  }
  if(i>k)
  {
      printf("Mishka");
  }
  else if(i<k)
  {
      printf("Chris");
  }
  else if(i=k)
  {
      printf("Friendship is magic!^^");
  }
  return 0;
}


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

main() {
    int i = 0, a = 0, b = 0;
    char s[50]; char ch;

    scanf("%s", s);
    while (s[i] != '\0') {
        if (s[i] == '4') a++;
        if (s[i] == '7') b++;
        i++;
    }

    if (a && a >= b) { printf("%d", 4); return; }
    if (b && a < b) { printf("%d", 7); return; }
    printf("%d", -1);
    return 0;
}


#include<stdio.h>
int main()
{
	int count4=0,count7=0;
	char ch;
	scanf("%c",&ch);
	while (ch!='\n')
	{
		if (ch=='4')
			count4++;
		if (ch=='7')
			count7++;
		scanf("%c",&ch);
	}
	if (count4==0&&count7==0)
		printf("-1\n");
	else
		printf("%c\n"count4>=count7?'4':'7');
	return 0;
}


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

int compare_function(const void *a,const void *b) {
    int *x = (int *) a;
    int *y = (int *) b;
    return *x - *y;
}

void print_array(int a[], int size) {
    printf("[");
    for (int i = 0; (i < size); i++) {
        printf("%d ", a[i]);
    }
    printf("]\n");
}

int main(void) {
    int len;
    int input;
    int number_paints = 0;
    int in = 0;

    scanf("%d", &len);
    int colors[len];
    int check[len];

    for(int i = 0; i < len; i++) {
        scanf("%d", &input);
        colors[i] = input;
        //printf("EEEE: %d", colors[i]);
    }

    //print_array(colors, len);

    qsort(colors, sizeof(colors)/sizeof(colors[0]), sizeof(colors[0]), compare_function);

    //print_array(colors, len);

    check[0] = colors[0];
    number_paints += 1;

    for (int color_iter = 0; color_iter < len; color_iter++) {
        for (int check_iter = 0; check_iter < number_paints; check_iter++) {
            if (colors[color_iter] % check[check_iter] == 0) {
                 in = 1;
                break;
            }

            else {
                in = 0;
            }

        }
        if (!in) {
            //printf("THIS RUNS\n");
            check[number_paints] = colors[color_iter];
            number_paints += 1;
            in = 1;

        }
        ..print_array(check, number_paints);
    }

    printf("%d" , number_paints);

    return 0;

}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int arr[100];
	int i, j=0, flag=1, temp, x=0;
	for(i=0;i<n;i++){
		scanf("%d", &arr[i]);
		if(arr[i] == 1)
		    x = 1;
    }
	int count = 0;
	int rr[4] = {2, 3, 5, 7};
	if(x == 1)
	    printf("1\n");
    else{
	       while(flag == 1){
	    temp = 0;
	    for(i=0;i<n;i++){
	        if(arr[i]%rr[j] == 0){
	            arr[i] = 0;
	            temp = 1;
	        }
	    }
	    if(temp == 1)
	        count++;
	    for(i=0;i<n;i++){
	        if(arr[i] != 0){
	            flag = 1;
	            break;
	        }
	        else
	            flag = 0;
	    }
	    j++;
	}
	printf("%d\n", count);

	}
	return 0;
}


#include<stdio.h>
int main()
{
	long long int i,j,k,l=0,n,l1,l2,r1,r2;
	scanf("%lld%lld%lld%lld%lld",&l1,&r1,&l2,&r2,&k);
	i=l2;
	while(l1<=r1)
	{
		while(l2<=r2)
		{

		if(l1==l2&&l1!=k)
		{
			l++;
		}
		l2++;
		}
		l2=i;
		l1++;
	}
	printf("%lld",l);
	return 0;
}


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

    int vladik,valera,c=0;
    scanf("%d%d",vladik,valera);
    while(vladik>=0 && valera>=0)
    {vladik=vladik-1-c;
    if (vladik<0)
    break;
    else
    valera=valera-2-c;
    c+=2;
}

if (valera<0)
printf("Valera");
else
printf("Vladik");
return 0;

}


#include <stdio.h>

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

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

  result = n;

  for(int i=0; i<k; i++){
    if(n % 10 == 0){
      result = result/10;
    }
    else{
      result --;
    }
  }

  return result;
}


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

int main() {
    unsigned long long a, i, j;
    scanf("%l64d", &a);
    for (i = 2520; i <= a; i+=2520) {
        j++;
    }
    printf("%l64d", j);
    return 0;
}


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

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

int mask(int a)
{
	int t=0,ans=0,p=0;
	while(a>0)
	{
		t=a%10;
		a=a/10;
		if(t==7||t==4)
		{
			ans=ans*10+t;
		}
	}
	while(ans>0)
	{
		t=ans%10;
		p=p*10+t;
		ans=ans/10;

	}
	return p;
}

int main()
{
	int a,b,i;
	scanf("%d%d",&a,&b);
	for(i=a;i<=1000000;i++)
	{
		if(mask(i)==b)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}


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

 int luckyNo(int x)
 {
 	int n=x;
 	int r,sum=0,m=1;
 	while(n)
 	{
 		r=n%10;
 		n=n/10;
 		if(r==4||r==7)
 		{
 			sum=sum+r*m;
 			m=m*10;
 		}
 	}
  return sum;
 }
int main()
{
	int a,b;

	scanf("%d %d",&a,&b);
	if(a<=b)
		a=b;
	else
	while(b!=luckyNo(a))
	{
		a++;
	}
	printf("%d\n",a);

 return 0;
 }


#include<stdio.h>
#include<stdlib.h>
main()
{
    int i,n,sum1=0,sum2=0;char str[100];
    scanf("%d %s",&n,&str);
    for(i=0;i<n;i++)
    {
        if(str[i]!='7'&&str[i]!='4')
        {
            printf("NO");
            exit(1);
        }
    }
    for(i=0;i<n/2;i++)
        sum1=sum1+str[i];
    for(i=n/2;i<n;i++)
        sum2=sum2+str[i];
    if(sum1==sum2)
        printf("YES");
    else printf("NO");
    return 0;
}


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

    int m,d;
    scanf("%d%d",m,d);
    int mday=0;
    switch(d)
    {
        case 1:mday=31;break;
        case 2:mday=28;break;
        case 3:mday=31;break;
        case 4:mday=30;break;
        case 5:mday=31;break;
        case 6:mday=30;break;
        case 7:mday=31;break;
        case 8:mday=31;break;
        case 9:mday=30;break;
        case 10:mday=31;break;
        case 11:mday=30;break;
        case 12:mday=31;break;
    }
    printf("%d",(d-1)+mday%7==0? (d-1)+mday/7:((d-1)+mday/7)+1);
    return 0;
}


# include <stdio.h>
# include <stdlib.h>
int gcd(int a, int b);
int lcm(int a, int b);
int main()
{
   int a,b,i;
   scanf("%d",&a);
   scanf("%d",&b);
   if(a==b)
     printf("Equal\n");
    else
    {
      int count_a=0,count_b=0;
      for(i=1;i<=lcm(a,b);i++)
       {
         if(i%a==0 && i%b==0)
           {
               if(a>b)
                 count_a++;
               else
                 count_b++;
           }
          else if(i%a==0)
              count_a++;
          else if(i%b==0)
              count_b++;
          else
          {
              int f1=i/a;
              f1=f1+1;
              f1=f1*a;
              int f2=i/b;
              f2=f2+1;
              f2=f2*b;
              int d1=f1-i;
              int d2=f2-i;
              if(d1<d2)
                count_a++;
              else if(d2<d1)
                count_b++;
              else
              {
                  if(a>b)
                    count_a++;
                   else
                    count_b++;
              }
          }
       }
       if(count_a>count_b)
        printf("Dasha\n");
       else if(count_b>count_a)
        printf("Masha\n");
        else
        printf("Equal\n");
    }
}
int gcd(int a, int b)
{
    int rem;
    while(b!=0)
    {
        rem =a%b;
        a=b;
        b=rem;
    }
    return a;
}
// Function to return LCM of two numbers
int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}


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

typedef uint64_t uint64; typedef uint32_t uint32;
typedef uint16_t uint16; typedef uint8_t uint8;
typedef int64_t int64; typedef int32_t int32;
typedef int16_t int16; typedef int8_t int8;

#define u8 PRIu8
#define u16 PRIu16
#define u32 PRIu32
#define u64 PRIu64
#define d8 PRId8
#define d16 PRId16
#define d32 PRId32
#define d64 PRId64

#define finc(i,size) for(uint64 i=0;i<(size);i++)
#define fdec(i,size) for(uint64 i=(size);i-->0;)

#define scanf_s scanf
int main(void)
{
	uint32 n;
	uint32 map[2][4];
	scanf_s("%"u32"", &n);
	finc(i, 2)
		finc(j, 3)
		scanf_s("%"u32"", &map[i][j]);
	finc(i, 2)
		map[i][3] = map[i][0];

	uint32 winmax = 0, winmin = 0;
	finc(i, 3)
		winmax += min(map[0][i], map[1][i + 1]);
	for (uint64 i = 1; i < 4; i++)
	{
		if (map[1][i - 1] + map[1][i] < map[0][i])
			winmin = map[0][i] - map[1][i - 1] - map[1][i];
	}
	printf("%"u32" %"u32"\n", winmin, winmax);

	return 0;
}


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

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

long long int n;

long long int solve(long long int k,long long int a,long long int b,long long int c,long long int mon){
	if((k)%4==0){
		return mon;
	}
	if(k>(n+100)){
		return INT_MAX;
	}
	return min(solve(k+1,a,b,c,mon+a),min(solve(k+2,a,b,c,mon+b),solve(k+3,a,b,c,mon+c)));
}

int main(void){
	long long int a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	long long int ans=solve(n,a,b,c,0);
	printf("%lld\n",ans);
	return 0;
}


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

int ab(int a){if(a<0)return -a; return a;}

int main(){
  int i,j,k,l,m,n;
  int x, y, x1, x2, y1, y2;

  scanf("%d%d%d%d%d%d",&x,&y,&x1,&y1,&x2,&y2);

  if(ab(x1-x2) > 3 || ab(y1-y2) > 3) puts("Second");
  else puts("First");

  return 0;
}


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

int main()
{
    int n, m, x1, y1, x2, y2;

    scanf("%d %d %d %d %d %d", &n, &m, &x1, &y1, &x2, &y2);

    if (abs(x1 - x2) > abs(y1 - y2)) {
        int aux = abs(x1 - x2);
        abs(x1 - x2) = abs(y1 - y2);
        abs(y1 - y2) = aux;
    }

    if ((abs(x1 - x2) <= 2 && abs(y1 - y2) <= 4) || (abs(x1 - x2) == 3 && abs(y1 - y2) == 3)) {
        puts("First");
    } else {
        puts("Second");
    }

    return 0;
}


#include <cstdio>

int main(void)
{
    int p1,p2,p3,p4,a,b,i,cnt=0;
    scanf("%d%d%d%d%d%d",&p1,&p2,&p3,&p4,&a,&b);
    for(i=a;i<=b;i++)
        if(i%p3%p2%p1%p4==i)
            cnt++;
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,x[7],y[7],i,count=0,sum1=0,sum2=0,temp;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&x[i],&y[i]);
		sum1+=x[i];
		sum2+=y[i];
	}
	if(sum1%2==0 && sum2%2==0)
		printf("0");
	else if((sum1+sum2)%2!=0)
		printf("-1");
	else if(sum1%2 && sum2%2)
		printf("1");
	else
		printf("-1");
	return 0;
}


#include <stdio.h>

int countTriangles(int n){
    int res=0;
    int a,b,c=1;
    for(;c<=n;c++){

        for(b=1;b<=c;b++){
            for(a=1;a<=b;a++){

               if((a*a+b*b)==c*c)
                res++;
            }
        }
    }
    return res;
}
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d",countTriangles(n));
    return 0;
}


#include <stdio.h>
int a[100],max=0;
void dfs(int pos,int n)
{
    int i,sum=0;
    if(pos==n)
    {
        max++;
    }
    for(i=pos;n>i;i++)
    {
        sum=sum+a[i];
        if(sum==1)
        {
            dfs(i+1,n);
        }
        else if(sum>1)
        {
            break;
        }
    }
}
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;n>i;i++)
    {
        scanf("%d",&a[i]);
    }
    dfs(0,n);
    printf("%d",max);
    return 0;
}


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

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

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

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

    int64_t c = decompose(x, p);

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


#include<stdio.h>

int main()
{
	int t;
	scanf("%d",&t);
	int num[t];
	for(int i=0;i<t;i++)
	{
		scanf("%d",&num[i]);
	}
	int count2=0,num2[t],num3[t];
	for(int i=0;i<t;i++)
	{
		num3[i]=num[i];
	}
	for(int i=0;i<t;i++)
	{
		count2=0;
		while(num[i]!=0)
		{
			num[i]=num[i]/10;
			count2++;
		}
		num2[i]=count2;
	}
	int sum=0,count1=0,l,count=0,a,k;
	for(int i=0;i<t;i++)
	{
		count1=0,sum=0,count=0;
	 k=1;
		for(int j=1;j!=num3[i];)
		{

				if(count%4==0&&count!=0)
				{
					j=k+1;
					k++;
					l=j;
					count1=0;
				while(l!=0)
				{

					l=l/10;
					count1++;
				}
				j=j*10+k;
				sum=sum+count1;

				}
				else
				{

				l=j;
				count1=0;
				while(l!=0)
				{

					l=l/10;
					count1++;
				}
				j=j*10+k;
				sum=sum+count1;
			}

			count++;

		}
		printf("%d\n",sum+num2[i]);
	}
}


#include <stdio.h>

typedef long long unsigned int u64;

int main(){
	u64 l, r, ans, bt;
	scanf("%llu%llu", &l, &r);
	ans = l ^ r;
	bt = 1ull << 61;
	while(!(bt & ans)) bt >>= 1;
	printf("%llu", bt^(bt-1));
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
char str[12][30]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char str1[30];
int i,n;
scanf("%s",str1);
for(i=0;i<12;i++)
{
 if(str1[30]==str[i][30])
    break;
}
scanf("%d",&n);
if((i+n)<12)
printf("%s",str[i+3][30]);
else
printf("%s",str[(i+3)%12][30]);
return 0;
}


#include <stdio.h>

int main(void){
	int size;
	scanf("%d", &size);
	int left[size];
	int right[size];
	int success[size];
	int read;
	int i = 0;
	while(i < size){
		scanf("%d", &read);
		success[i] = read;
		i++;
	}
	i = 0;
	left[i] = (success[i] == 0);
	i++;
	while(i < size){
		left[i] = left[i-1] + (success[i] == 0);
		i++;
	}
	i = size - 1;
	right[i] = (success[i] == 1);
	i--;
	while(i >= 0){
		right[i] = right[i+1] + (success[i] == 1);
		i--;
	}
	i = 0;
	int max = 0;
	while(i < size){
		printf("%d %d\n", left[i], right[i]);
		if(left[i] + right[i] > max){
			max = left[i] + right[i];
		}
		i++;
	}
	printf("%d\n", max);
}


#include <stdio.h>

int n,m,a,b,ux,dx,uy,dy;

main()
{
    scanf("%d%d%d%d",&n,&m,&a,&b);
    ux=~-a%m; dx=~-b%m;
    uy=~-a/m; dy=~-b/m;

    if(uy==dy)        puts("1");
    else if(ux==0)    puts(dx==m-1||b==n?"1":"2");
    else if(b==n)     puts("2");
    else if(dx==m-1)  puts("2");
    else if(dy-uy==1) puts("2");
    else puts("3");
    return 0;
}


#include<stdio.h>
int main()
{
   int a,b,c,d,cnt;
   scanf("%d %d %d %d",&a,&b,&c,&d);
   if(c>d)
    {
        a*=c;
        b*=c;
    }
    else
    {
        a*=d;
        b*=d;
    }
   if((float)a/c>(float)b/d)
   {
       a*=d;
       c*=b;
       cnt=a-c;
       printf("%d/%d",cnt/hcf(cnt,a),a/hcf(cnt,a));
   }
   else
   {
       b*=c;
       d*=a;
    cnt=b-d;
     printf("%d/%d",cnt/hcf(cnt,b),b/hcf(cnt,b));
   }
   return 0;
}
int hcf(int a,int b)
{
    while(a!=b)
    {
        if(a>b)
            a-=b;
        else
            b-=a;
    }
    return a;
}


#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 100

int read_words(char* w1, char* w2){
    int len, i;
    scanf("%i", &len);
    for(i=0; i<len; i++){
        scanf(" %c%c", &w1[i], &w2[i]);
    }
    return len;
}
int search(char* set, char elem, int n){
    int i;
    for(i=0; i<n; i++){
        if(set[i]==elem){
            return i;
        }
    }
    return -1;
}
int contains(char* set, char elem, int n){
    return search(set, elem, n)==-1?0:1;
}
int unlock(char p1, char p2, char* w1, char* w2, int n){
    //printf("%i, %i, %i\n", w2[search(w1, p1, n)] == p2, contains(w1, p2, n), contains(w2, p1, n));
    if(w2[search(w1, p1, n)] == p2){
        abort();
        return 1;
    }
    else if(contains(w1, p2, n)){
        return contains(w2, p1, n);
    }else{
        return 0;
    }
}
int main(int argc, char* argv[]){
    char p1, p2;
    int size;
    char w1[MAX_SIZE];
    char w2[MAX_SIZE];
    scanf(" %c%c", &p1, &p2);
    size = read_words(w1, w2);
    int success = unlock(p1, p2, w1, w2, size);
    printf("%s\n", success? "YES": "NO");
}


#include<stdio.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    if(k==1)
    printf("%d\n",3*(n-k+1));
    else if(k==2)
     printf("%d",3*(n-k+1)+4);
     else if(k>n/2)
     printf("%d",4*n-k;
    else
     {
             printf("%d",3*n+k-1);

     }

}


#include<stdio.h>
#include<string.h>
int main()
{
    int arr[4];
    for(int i=0;i<4;i++)
    {
        scanf("%d",arr[i]);
    }
    for(int i=0;i<4;i++)
    {
        for(int j=i+1;j<4;j++)
        {
            int m=arr[i];
            if(arr[i]<arr[j])
            {
                arr[i]=arr[j];
                arr[j]=m;
            }
        }
    }
    int sum=arr[0]+arr[1]+arr[2]+arr[3];
    if(arr[0]==sum/2)
    {
        printf("YES");
    }
    else if(arr[0]+arr[4]==sum/2)
    {
        printf("YES");
    }
    else printf("NO");
    return 0;
}


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

main()
{
int n,m,count1;
scanf("%d","%d",&n,&m);
if(n>=m){
    count1=m;
}
else{
    count1=n;
}
if(count1%2==0){
    printf("Malvika");
}
else{
    printf("Akshat");
}
}


#include <stdio.h>
int main()
{
    int *ara;
    int i,n,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&ara[i]);
    if(ara[0])
        count++;
    for(i=1;i<n-1;i++)
    {
        if(ara[i])
            count++;
        if(!(ara[i]) && ara[i-1] && ara[i+1])
            count++;
    }
    if(ara[n-1])
        count++;
    printf("%d",count);
    return 0;
}


#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
int big[3][3];
bool cmp(int a,int b){
	return !big[a][b];
}
int main(){
	char s[20];
	int qq=3;
	memset(big,-1,sizeof(big));
	while(qq--){
		scanf("%s",s);
		if(s[1]=='<'){
				big[s[2]-'A'][s[0]-'A']=1;
				big[s[0]-'A'][s[2]-'A']=0;
		}else{
				big[s[0]-'A'][s[2]-'A']=1;
				big[s[2]-'A'][s[0]-'A']=0;
		}
	}
	if(big[0][1]&&big[1][2]&&big[2][0]||!big[0][1]&&!big[1][2]&&!big[2][0])printf("Impossible\n");
	else{
		int i,num[3];
		for(i=0;i<3;i++)num[i]=i;
		sort(num,num+3,cmp);
		for(i=0;i<3;i++)printf("%c",num[i]+'A');
		printf("\n");
	}
	return 0;
}


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

	// n! = n*(n-1)!
int factoriel(int number){

	if(number==1||number==0){return 1 ;}
	int i ;
	for(i=number-1;i>0;i--){
		number=number*i;
	}
	return number;
}
int main(int argc, char *argv[])
{
	int a , b , result ;
	scanf("%d",&a);
	scanf("%d",&b);
	result=factoriel(b)/factoriel(a);
	result=result%10;
	printf("%d",result);
    return 0;
}


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

#define MAX
#define MODBY 1000000009

typedef long long int lld;
typedef long double Lf;

int main()
{
   int i,j,n,m;
   scanf("%d",&n);
   scanf("%d",&m);
   if(m==1){
      printf("0\n");
      return 0;
   }
   lld a=1;
   for(i=0;i<m;++i)
      a=(a*2)%MODBY;
   lld ans=1;
   for(i=1;i<=n;++i)
      ans=(ans*(a-i+MODBY))%MODBY;
   printf("%d\n",(int)ans);

   return 0;
}


#include <stdio.h>

#define MOD 1000000009

int power(int, int, int);

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

	int p = power(2, m, MOD);
	int sol = 1;
	int i;
	for (i=1;i<=n;i++)
	{
		int t = p - i;
		if (t<0) t+=MOD;
		sol *= t;
		sol %= MOD;
	}

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

int power(int base, int exp, int mod)
{
	if (!exp) return 1;
	int t = power(base, exp / 2, mod);
	int tt = (exp & 1)?base:1;
	return (((t * t) % mod) * tt) % mod;
}


#include<stdio.h>
#include<stdlib.h>
int main(){
	int n,pos,l,r,res;
	while(scanf("%d%d%d%d",&n, &pos, &l, &r)){
		if(l==1 && r==n){
			res=0;
		}
		else if(l==1){
			res=abs(pos-r)+1;
		}
		else if(r==n){
			res=abs(pos-l)+1;
		}
		else{
			if(l<=pos && pos<=r){
				res=pos-2*l+r+2;
				//printf("1\n");
			}
			else if(l>pos){
				res=r-pos+2;
				//printf("1\n");
			}
			else if(r<pos){
				res=pos-l+2;
				//printf("1\n");
			}
		}
		printf("%d\n",res);
	}
	return 0;
}


#include<stdio.h>
int main()
{
  int n,pos,a,b,l,r,min,max,count=0;
  scanf("%d%d%d%d",&n,&pos,&l,&r);
  a = 1;
  b = n;
  if ((l!=a)||(b!=r))
{  if (pos<l)
      {
        min = b*(b<(pos+1)) + (pos+1)*((pos+1)<b);
        pos = min;
        count++;
      }
   if (pos>r)
      {
        max = a*(a>(pos-1)) + (pos-1)*((pos-1)>a);
        pos = max;
        count++;
      }
   if((r-pos)<(pos-l))
    {
      if(b!=r)
      {
       while(pos!=r)
        {
          min = b*(b<(pos+1)) + (pos+1)*((pos+1)<b);
          pos = min;
          count++;
        }
       }
       b = r;
       count++;
       if(a!=l)
       {
       while(pos!=l)
        {
          max = a*(a>(pos-1)) + (pos-1)*((pos-1)>a);
          pos = max;
          count++;
        }
       a = l;
       count++;
       }
      }
      if(((pos-l)<(r-pos))||((pos-l)==(r-pos)))
    {
       if(a!=l)
       {
       while(pos!=l)
        {
          max = a*(a>(pos-1)) + (pos-1)*((pos-1)>a);
          pos = max;
          count++;
        }
       a = l;
       count++;
       }
      if(b!=r)
      {
       while(pos!=r)
        {
          min = b*(b<(pos+1)) + (pos+1)*((pos+1)<b);
          pos = min;
          count++;
        }

       b = r;
       count++;
       }
      }
 }
       printf("%d",count);
  return 0;
}


#include<stdio.h>
int main()
{
    int n,i,max=0,min=0;
    scanf("%d",&n);
      int a[n],b=0;
      for(i=0;i<n;i++)
      {
          scanf("%d",&a[i]);
      }
      for(i=0;i<n-1;i++)
      {
        if(a[i]<a[i+1]&&a[max]<a[i+1])
        {
            max=0;
            max=i+1;
        }
     if(a[i]>a[i+1]&&a[min]>a[i+1])
        {
            min=0;
            min=i+1;
        }
      }

       if(min>max)
       {
           //b=min;
           if(n-1-min>=max)
           {
               b=n-1-max;
           }
           else
           {
               b=min;
           }
       }
       else
       {
           b=n-1-min;

       }
       printf("%d",b);
       main();
       return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define swap(x,y,t) (t=x,x=y,y=t)
//#define li long int
int main(){
  int x,i,h,m,c=0;
    scanf("%d",&x);
    scanf("%d %d",&h,&m);
    if(h%10==7 || m%10==7)
        printf("0\n");
    else{
        while(h%10!=7 && m%10!=7){
            if(m>x)
                {m=m-x;c++;}
            else{c++;
                m=60-x+m;
                if(h==0)
                h=23;
                else
                    h=h-1;
            }
        }
        printf("%d\n",c);
    }
    return 1;
}


#include<stdio.h>
char a[100];
int s,i,n;
int main()
{
scanf("%d",&n);
scanf("%s",a);
while (i<n)
   { i=0;
     s=0;
   	if (a[i]==a[i+1])
   	   {
   	   s++;
   	   i++;
   	   }
   	   else
   	   {
   	   	s++;
   	   	i+=2;
   	   }
   }
   printf("%d",s);

   return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	int n;
	scanf("%d", &n);

	char a[n];
	scanf("%s", a);

	int i, count=0, pair=0, solo=0;

	i=0;
	while(n>0)
	{
		if(a[i]=='R')
		{
			if(a[i+1]=='U')
			{
				pair++;
				n--;
				i++;
			}
			else if(a[i+1]=='R')
			{
				solo++;

			}
		}
		else if(a[i]=='U')
		{
			if(a[i+1]=='R')
			{
				pair++;
				n--;
				i++;
			}
			else if(a[i+1]=='U')
			{
				solo++;

			}
			n--;
			i++;
		}
		//printf("\n%d %d %d",i , pair, solo);
	}
	count=pair+solo;
	printf("%d", count);
}


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

int verif(char *ch,char *mdp)
{ char cha[3]; int i,a=0;
    for(i=0;i<strlen(ch)-1;i++)
    {strncpy(cha,ch+i,2);
     cha[2]='\0';

     if(strcmp(cha,mdp)==0) a=1;
    }
     return a;
}
int main()
{
int n,i,j;
char mdp[3];
scanf("%s",mdp);
scanf("%d",&n);
char t[n][3];  char *ch;

for(i=0;i<n;i++)
{
    scanf("%s",t[i]); }

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

strcpy(ch,t[i]);

for(j=0;j<n;j++)
{   strcpy(ch,t[i]);
    strcat(ch,t[j]);

if(verif(ch,mdp)==1) test=1;
}

}
if (test==1)
printf("YES");
else printf("NO");
return 0;
}


#include <stdio.h>

#define N	3000
#define M	3000

void slide(int *aa, int *bb, int n, int m) {
	static int qq[N];
	int i, head, cnt;

	head = cnt = 0;
	for (i = 0; i < n; i++) {
		while (cnt && aa[qq[head + cnt - 1]] > aa[i])
			cnt--;
		qq[head + cnt++] = i;
		if (i >= m - 1)
			bb[i - m + 1] = aa[qq[head]];
		if (qq[head] == i - m + 1)
			head++, cnt--;
	}
}

int main() {
	static int aa[N][M], bb[N][M], cc[N], dd[N];
	int n, m, a, b, g, x, y, z, i, j;
	long long ans;

	scanf("%d%d%d%d%d%d%d%d", &n, &m, &a, &b, &g, &x, &y, &z);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++) {
			aa[i][j] = g;
			g = (long long) (g * x + y) % z;
		}
	for (i = 0; i < n; i++)
		slide(aa[i], bb[i], m, b);
	ans = 0;
	for (j = 0; j + b <= m; j++) {
		for (i = 0; i < n; i++)
			cc[i] = bb[i][j];
		slide(cc, dd, n, a);
		for (i = 0; i + a <= n; i++)
			ans += dd[i];
	}
	printf("%lld\n", ans);
	return 0;
}


#include <math.h>
#include <stdio.h>
#include <string.h>
int main()
{
  long long int n,k,i,j,s=0;
  scanf("%I64d %I64d",&n,&k);
  long long int a=0;
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      s=i+j;
      if(s==k){
        a++;
      }
    }
  }
  if (a%2==0)
    printf("%I64d\n",a/2);
  else
    printf("%I64d",(a-1)/2);
  return 0;
}


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


#include<stdio.h>
#include<stdbool.h>
#define sq(A) ((A)*(A))

int x[4], y[4], r[4];

bool intersect(int i, int j){
	int dist=sq(x[i]-x[j])+sq(y[i]-y[j]);
	if(dist>=sq(r[i]+r[j])) return false;
	if(r[i]<r[j] && dist<=sq(r[j]-r[i])) return false;
	if(r[j]<r[i] && dist<=sq(r[i]-r[j])) return false;
	return true;
}

bool in(int i, int j){
	int dist=sq(x[i]-x[j])+sq(y[i]-y[j]);
	if(r[i]<r[j] && dist<=sq(r[j]-r[i])) return false;
	return true;
}

int main(){
	int num=0;
	scanf("%d %d %d %d", x, y, r, r+1);
	x[1]=x[0]; y[1]=y[0];
	scanf("%d %d %d %d", x+2, y+2, r+2, r+3);
	x[3]=x[2]; y[3]=y[2];
	if(!intersect(0, 2) && !intersect(0, 3) && (in(0, 2) ^ in(0, 3))) ++num;
	if(!intersect(1, 2) && !intersect(1, 3) && (in(1, 2) ^ in(1, 3))) ++num;
	if(!intersect(2, 0) && !intersect(2, 1) && (in(2, 0) ^ in(2, 1))) ++num;
	if(!intersect(3, 0) && !intersect(3, 1) && (in(3, 0) ^ in(3, 1))) ++num;
	printf("%d\n", num);
	return 0;
}


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

// we will consider numbers with <= 10^6 digits. Hence, maximal sum of digits is 9*10^6 < 10^7.
// we can generate all possible sums for excellent numbers:
//   2^n for n digits of a,b and then we need to sum for n = 1..7, meaning that 2^8 - 2 different possible sums:
//   1+2+..+2^[n-1] = 2^n - 1, hence 2+..+2^[n-1] = 2^n - 2
// now for every possible sum we need to solve:
// ax + by = S
// x + y = N
// and this will add binomial(N,x) numbers
// trivially, writing x = N - y, (b - a)y = S - aN

// now we can do dynamic programming to calculate binomial coefficients up to N
// we just need 2 rows (instead of full table) as we will need only row N

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

static int _sd[254] = {};
static void generate_sd(int a, int b) {
    int sd_count = 0;
    for(int i = 1 ; i <= 7 ; ++i) {                // fix number of digits
        for(int j = 0, jn = 1<<i ; j < jn ; ++j) { // enumerate masks
            int n = 0, m = j;
            for(int k = 0, p10 = 1 ; k < i ; ++k, p10 *= 10, m >>= 1)
                n += p10 * (m & 0x1 ? b : a);
            assert(sd_count < 254); _sd[sd_count++] = n;
        }
    }
}

#define MOD 1000000007LL

#define BINN 1000000

static int64_t _binomial_impl[2][1000000+1] = {}, _binomial[1000000+1] = {};

static inline void generate_binomial(int N) {
    _binomial_impl[0][0] = 1; int c = 1, p = 0;
    for(int i = 1 ; i <= N ; ++i) {
        _binomial_impl[c][0] = 1;
        for(int m = 1 ; m <= i ; ++m)
            _binomial_impl[c][m] = (_binomial_impl[p][m-1] + _binomial_impl[p][m]) % MOD;
        int t = c; c = p, p = t;
    }
    for(int i = 0 ; i <= N ; ++i)
        _binomial[i] = _binomial_impl[p][i];
}

int main() {
    int A,B,N; scanf("%d %d %d\n", &A,&B,&N);
    generate_sd(A,B); generate_binomial(N);

    int64_t count = 0;
    for(int si = 0 ; si < 254 ; ++si) {
        const int ss = _sd[si] - A*N;
        if(ss % (B-A) == 0) {
            const int y = ss / (B-A), x = N - y;
            if(x >= 0 && y >= 0)
                count = (count + _binomial[y]) % MOD;
        }
    }

    printf("%d\n", (int)count);
}


#include<stdio.h>

int main()
{

    int team[105],h_color[105],g_color[105],i,j,koyta_team,coun;

    while(scanf("%d",&koyta_team))
    {

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

            scanf("%d %d",&h_color[i],&g_color[i]);
        }

        coun=0;

        for(i=1; i<=koyta_team; i++)
        {
            for(j=1; j<=koyta_team; j++)
            {
                if(i!=j)
                {
                    if(h_color[i]==g_color[j])
                    {
                        coun++;
                    }
                }
            }
        }
        printf("%d\n",coun);

    }
    return 0;
}


#include<stdio.h>
int solve(int a,int b){
int i,k;
for(i=0;i<=a;i++){
        for(k=0;k<=a;k++){
                if((2*i + 1*k)==b && k+i==a){
                return 1;
                }
        }
}
return 0;
}
int main()
{
    int a,b,c,d,e,f;
    scanf("%d%d",&b,&c);
    int k=1;
    int s=0;
    int max=0;
    while(s<b){
    s=k*c;
    if(solve(s,b) && s>max){
        printf("%d",s);
        return 0;}
    k++;
    }
    printf("-1");

}


#include<stdio.h>
int main()
{
    int n,i=0,count=0,sum=0;
    scanf("%d",&n);
    char s[110];
    scanf("%s",&s);

    while(s[i]!='\0')
    {
        if(count<sum)
        {
            count=sum-count;
            sum=0;
            i=0;
        }
        if(s[i]=='+')
            count++;
        else if(s[i]=='-'&& count==0)
            sum=0;
        else
            sum++;
        i++;
    }
    if(sum==n)
        printf("0\n");
    else
        printf("%d\n",count-sum);
    return 0;
}


#include<stdio.h>
#include<string.h>
int len;
char ph[51];
long dp[51][10];

long f(int pos,int val)
{
     if(dp[pos][val]!=0)
      return dp[pos][val];

  int sum = val+ph[pos+1]-'0';

      if(pos==len-2)
     {
     	 dp[pos][val]=sum%2==0?1:2;
     	 return dp[pos][val];
	 }
  long c=0;
      if(sum%2==0)
      c= f(pos+1,sum/2);
	  else
	  c=f(pos+1,sum/2)+f(pos+1,sum/2+1);

    dp[pos][val]=c;

     return c;

}
int main()
{

	scanf("%s",ph);
	len=strlen(ph);
	int i,check=1;
	long c=0;
	for(i=0;len!=1&&i<=9;i++)
	{ c+= f(0,i);
	}

/*	for(i=0;i<len;i++)
	{
	  for(j=0;j<10;j++)
	 {printf("%ld  ",dp[i][j]);
	 }
	 printf("\n");

    }    */

    for(i=1;i<len;i++)
     check&=(ph[i]-ph[i-1])*(ph[i]-ph[i-1])==1;

       printf("%ld",c+(len==1?10:0)-check);

	return 0;
}


#include <studio.h>

int main() {

int n;
int diff;
int noprog=0;
scanf("%d", &n) ;

int temp1, temp2;
scanf("%d", &temp1) ;
scanf("%d", &temp2) ;
diff = temp2-temp1;
int i;
for(i=0;i<(n-2);i++){
temp1=temp2;
scanf("%d", &temp2) ;
if(temp2-temp1!=diff) {
noprog=1;
}
}
if(noprog==1) printf("%d", temp2);
else printf("%d", temp2+diff) ;
return 0;
}


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

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

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

long long lcm(int a, int b) {
	return (long long) a / gcd(a, b) * b;
}

int main() {
	int n;
	long long m;

	scanf("%d", &n);
	if (n <= 2) {
		printf("%d\n", n);
		return 0;
	}
	m = (long long) n * (n - 1) * (n - 2);
	printf("%lld\n", n % 2 == 1 ? m : max(m, (n - 1) * lcm(n, n - 3)));
	return 0;
}


#include <stdio.h>

int Cnt[26];

int main()
{
    int n, k;
    char str[51];
    scanf("%d %d %s", &n, &k, str);
    for(int i = 0; str[i] != '\0'; ++i) {
        ++Cnt[str[i] - 'a'];
    }
    int j = 0, ans = 0, choice = 0;
    while(1) {
        int i;
        for(i = j; i < 26; ++i) {
            if(Cnt[i]) {
                ans += i + 1;
                ++choice;
                j = i + 2;
                break;
            }
        }
        if(i == 26 || choice == k) {
            break;
        }
    }
    if(choice == k) {
        printf("%d\n", ans);
    } else {
        puts("-1");
    }
    return 0;
}


#include <stdio.h>

int main()
{

    int n,a[101]={0},x,ans=0;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&x);
        if(x!=0)
        {
            if(a[x]==0)
            ans++;

            a[x]++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <stdio.h>

int t0,t1,t2;
double comp(int y1,int y2)
{
    double left = t0;
    double right = (double)((double)t1*y1+(double)t2*y2)/(double)(y1+y2);
    return left-right;
}

int main(void)
{
    int x1,x2;
    double temp;
    scanf("%d%d%d%d%d",&t1,&t2,&x1,&x2,&t0);
    int i,j;
    double state;
    temp = 9999999.0000;
    int cold,hot;
    for(i=x1,j=x2; i>=0,j>=0;)
    {
        state = comp(i,j);
        if(state < 0.000001 && state > -0.000001)
        {
            cold = i;
            hot = j;
            break;
        }
        else if(state > 0.000001)
        {
            i--;
        }
        else
        {
            if(-state<temp)
            {
                cold = i;
                hot = j;
                temp = -state;
            }
            j--;
        }
    }
    printf("%d %d\n",cold,hot);
    return 0;
}


#include<stdio.h>
int main()
{
    long long int k,count=0,i,d,n,largest=0,cou=0,j;
    scanf("%lld",&k);
    long long int a[k+1],b[k+1];
    for(i=1;i<k+1;i++)
    {
        scanf("%lld",&a[i]);b[i]=0;
    }
    for(i=1;i<k+1;i++)
    {
        if(a[i]>25)
            count++;
    }
    for(i=1;i<k+1;i++)
    {
        if(largest<a[i])
            largest=a[i];
    }
    n= largest-(25-count)-1;
    if(k!=25){
    if(count==0)
    {
        printf("0");
    }
    else
    {
        printf("%lld",n);
    }}
    else
    {
        for(i=1;;i++)
        {
            for(j=1;j<=25;j++)
            {
                if(a[j]==i)
                {b[i]=1;break;}
            }
            if(i>=largest)
                break;
        }
        for(i=0;i<=largest;i++)
        {
            if(b[i]==0)
                cou++;
        }
        printf("%lld",cou+1);
    }
    return 0;
}


#include <stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    int n2 = n+1;
    int ans = 0;
    for(;n2 > 0;n2 -= 1234567)
    {
        int n3 = n2;
        for(;n3 > 0;n3 -= 123456)
        {
            int n4 = n3;
            for(;n4 > 0;n4 -= 1234)
            {
                if(n4 == 1)
                {
                    ans = 1;
                    goto mark;
                }
            }
        }
    }
mark:if(ans == 1)
        printf("YES");
     else
        printf("NO");
    return 0;
}


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

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

int main(){
    int i, j;
    char vec[10][10];
    char dato[80];
    char parte[11];
    char aux[10];
    scanf("%s", dato);
    for ( i = 0; i < 10; i++ ){
        scanf("%s", vec[i] );
    }

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

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


#include <stdio.h>

int main(void)
{
		int arr[2] = {0};

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

		int sum = 0, num;
		for (int i = 0; i < n; i++){
				scanf("%d ", &num);
				sum += num;
				if (num % 200 == 0)
						arr[1]++;
				else
						arr[0]++;
		}

		if (sum % 200 != 0){
				printf("NO\n");
				return 0;
		}

		int half = sum/2;
		sum /= 2;
		while (sum > 100)
				if (arr[1] > 0){
						sum -= 200;
						arr[1]--;
				}

		while (sum > 0)
				if (arr[0] > 0){
						sum -= 100;
						arr[0]--;
				}

		if ((100 * arr[0]) + (200 * arr[1]) == half)
				printf("YES\n");
		else
				printf("NO\n");
}


#include<stdio.h>

int main()
{
    long long int n;
    scanf("%lld",&n);
    printf("%lld\n",(n/2)+2*((n/2)+(n%2)-1));
    return 0;
}


#include<stdio.h>

int main()
{
    long long int i=0,n,count=0,temp,mod;
    scanf("%lld",&n);
    while(1)
    {
        mod=n%(1<<(i+1));
        temp=n/(1<<(i+1));
        // printf("%lld %lld\n",temp , mod);
        if(mod>(1<<i))
            count+=(1<<i)*(temp+1);
        else{
                count+=(1<<i)*(temp);
            }
        if(temp==0)
            break;
        i++;
    }
    printf("%lld\n", count);
    return 0;
}


#include<stdio.h>

int divisornumber(int n){

    int i,mx=0;
    for(i=1;i<=n;i++){
        if(n%i==0){
            mx=mx+1;
        }
    }
    return mx;
}

main(){
    int i,j,k,a,b,c,sm=0;
    scanf("%d %d %d",&a,&b,&c);

    for(i=1;i<=a;i++){
        for(j=1;j<=b;j++){
            for(k=1;k<=c;k++){
                sm=sm+divisornumber(i*j*k);
            }
        }
    }
    printf("%d",sm);
}


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

	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	if(n>1)
	{
		if(a[n-1]>a[n-2] && a[n-1]<15)
			printf("UP\n");

		else if(a[n-1]<a[n-2])
			printf("DOWN\n");

		else if(a[n-1]=15)
			printf("DOWN\n");

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


#include <stdio.h>

int subs(char* str, int n)
{
	int x=0,flag=0;
	for(int i=n-1;i>0;i--)
	{
		for(int j=0;j<n-i;j++)
		{
			for(int k=j+1;k<=n-i;k++)
			{
				for(int k1=0;k1<i;k1++)
				{
					if(str[j+k1]!=str[k+k1])
					{
						flag=1;
						printf("aa\n");
						break;
					}
				}
				if(flag==0)
				{
					x=i;
					return x;
				}
				flag=0;
			}
		}
	}
	return x;
}

int main()
{
	char str[100]; int n;
	scanf("%s",str);
	for(int i=0;;i++)
	{
		if(str[i]=='\0')
		{
			n=i;
			break;
		}
	}
	printf("%d ",subs(str,n));
}


#include <string.h>
#include <stdio.h>
int main()
{
    int n,m,
    scanf("%d",vp);
    scanf("%d",vd);
    scanf("%d",t);
    scanf("%d",f);
    scanf("%d",c);
    int i=0;
    while()
    {
        i++;
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long arr[2000001],brr[2000001],mod=1000000000+7;
char str[2000001],s1[2000001];
int func(const void *a, const void *b)
{
	return (*(int*)a-*(int*)b);
}
long long max(long long a, long long b)
{
	return (a>b)?a:b;
}
long long min(long long a, long long b)
{
	return (a>b)?b:a;
}
long long power(long long  x, long long  int y, long long p)
{
	long long int res = 1;
	x = x % p;
	while (y > 0)
	{
		if (y & 1)
			res = (res*x) % p;
		y = y>>1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
long long bs(long long l, long long r, long long n, long long m)
{
	long long mid=l+((r-l)/2);
	if(l>=r)
	{
		if((mid+1)*2+(mid*(mid+1))/2>=(n-m-1))
			return mid;
		else
			return mid+1;
	}
	if((mid+1)*2 + (mid*(mid+1))/2==(n-m-1))
		return mid;
	if((mid+1)*2 + (mid*(mid+1))/2>(n-m-1))
			return bs(l,mid-1,n,m);
	if((mid+1)*2 + (mid*(mid+1))/2 < (n-m-1))
		return bs(mid+1,r,n,m);
}

int main()
{
	long long int sum=0,a,b,x,y,n, m,temp,flag=0,index,len, i, j, k, count=0, ans=0;
	scanf("%lld %lld", &n, &m);
	if(n==1)
	{printf("1\n");return 0;}
	if(m>=n)
	{printf("%lld\n",n);return 0;}
	printf("%lld\n",m+1+bs(0,4000000005,n,m)+1);
	return 0;
}


#include<stdio.h>
#include<iostream>
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 <math.h>
#include <stdlib.h>
#include <string.h>

char s[99];
int i,j,l,ans=-1,temp;

int dv(p,q){
    if(1<p&&s[0]=='0') return -1;
    if(p+1<q&&s[p]=='0') return -1;
    if(s[q]=='0'&&isdigit(s[q+1])) return -1;
    int ret=0,z;
    int t=s[p]; s[p]=0;
    z=atoi(s); s[p]=t;
    if(z>1e6)return-1; ret+=z;
    t=s[q]; s[q]=0; z=atoi(s+p); s[q]=t;
    if(z>1e6)return-1;
    ret+=z; z=atoi(s+q);
    if(z>1e6)return-1;
    ret+=z;
    //if(ret>1000000)return 0;
    //printf("%d %d %d\n",p,q,ret);
    return ret;
}

main(){
    scanf("%s",s);
    l=strlen(s);
    if(l<3||21<l){
        puts("-1");
        return 0;
    }

    for(i=1;i<=8&&i<l;i++){
        for(j=l-1;l-8<j;j--){
            if(j-i>7)continue;
            temp=dv(i,j);
            ans<temp?ans=temp:0;
        }
    }

    //printf("%d\n",dv(6,12));
    //puts(s);
    printf("%d\n",ans);
    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 int Max(long int f,long int s)
{
    if(f>s)
    return f;
    else
    return s;
}
long int GetVal(char *s,int l,int r)
{
int n;
long int v;
char x[10]="";
CopyArr(x,s,l,r);
n=GetSize(x);
 v=atoi(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 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>
int main()
{
	int n,i=0,b=0,c=0,bi=0,j;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<3;i++)
	{
	for(j=i;j<n;j=i+3)
	 {
		 if(i==0)
		 {
			 c=c+a[i];
		 }
		 if(i==1)
		 {
			 bi=bi+a[i];
		 }
			if(i==2)
		 {
			 b=b+a[i];
		 }
     }
 }
     if(c>bi&&c>b)
     {
		 printf("chest");
	 }
	else{ if(bi>b)
     {
		 printf("biceps");
	 }
	  else
	  {
		  printf("back");
	  }
  }
	  return 0;
  }


#include<stdio.h>
//include<conio.h>
//#include<string.h>
int main()
{
int n,i,j=0,k=0,l=0,x,y;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0,x=1,y=2;i<n;i+3,x+3,y+3){
   j+=a[i];
    k+=a[x];
    l+=a[y];
}
if(j>k && j>l) printf("chest");
else if(k>j && k>l) printf("biceps");
else if(l>j && l>k) printf("back");
return 0;
}


#include<stdio.h>
int m;
int oddeven(int n)
{
    if(n%2==0)
    {
        m=1;
    }
    else
    {
        m=0;
    }

}
int main()
{
    long long a,b;
    int count = 0;
    scanf("%lld",&a);
    scanf("%lld",&b);
    int i=1;
    if(b==1)
    {
        if(a%2==0)
        {
            printf("NO");
        }
        else
        {
            printf("YES");
        }
    }
    else
    {
        while(b*i<=a)
        {
            i++;
            count++;
        }
        oddeven(count);
        {
            if(m==1)
            {
                printf("NO");
            }
            else
            {
                printf("YES");
            }
        }
    }
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
#define LL long long
uLL exgcd64(uLL a,uLL b,uLL *x,uLL *y)
{
	static uLL gcd;
	if (a==0)
	{
		*x=0;*y=1;
		return b;
	}
	else
	{
		gcd=exgcd64(b%a,a,y,x);
		*x-=(b/a)*(*y)+b;
		*y+=a;
		return gcd;
	}
}
int main()
{
	freopen("in.in","r",stdin);
	LL i,j,k,n,m,a,b,c,d,x,y,vx,vy;
	scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x,&y,&vx,&vy);
	if ((vx==0)||(vy==0))
	{
		if (vx==0)
		{
			if ((x==0)||(x==n))
			{
				if (vy<0) {printf("%lld 0\n",x);}
				else {printf("%lld %lld\n",x,m);}
			}
			else
			{
				printf("-1\n");
			}
		}
		if (vy==0)
		{
			if ((y==0)||(y==m))
			{
				if (vx<0) {printf("0 %lld\n",y);}
				else {printf("%lld %lld\n",n,y);}
			}
			else
			{
				printf("-1\n");
			}
		}
	}
	else
	{
		if (vx<0)
		{
			x=n-x;
		}
		if (vy<0)
		{
			y=m-y;
		}
		//printf("%lld %lld %lld %lld\n",n,m,x,y);
		c=exgcd64(m,n,&a,&b);
		d=x-y;
		if (d<0) {d=(d%m+m)%m;}
		if (d%c!=0) {printf("-1\n");}
		else
		{
			d=(d/c)*(b/c)%(m/c);
			if (d==0) {d+=m/c;}
			c=d;
			d=(c*n-(x-y))/m;
			//printf("%lld %lld %lld %lld\n",c,d,n,m);
			c=c&1;d=d&1;
			if (vx<0) {c=c^1;}
			if (vy<0) {d=d^1;}
			c=c*n;d=d*m;
			printf("%lld %lld\n",c,d);
		}
	}
	return 0;
}


#include <stdio.h>
#define Min(a,b) a<b ? a : b
long long bigpower(long long int x,long long int n)
{
    long  long result=1;
    while(n)
    {
        if(n&1)
            result = (result*x);
        x = (x*x);
        n /= 2;
    }
    return result;
}
int main()
{
    long long int m, n, ans;
    scanf("%lld%lld",&n,&m);
    if(n>m)
        ans = m;
    else
    {
          n = bigpower(2,n);
          ans = m%n;
    }
    printf("%lld\n",ans);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,m,i,j,temp,max,add,t,k,p=0;
    scanf("%d",&n);
    int a[n];
    scanf("%d",&m);

        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        //Bubble Sort
        if(n!=1)
        {
            for(i =0;i<n;i++)
            {
                for(j =i+1; j<n; j++)
                {
                    if(a[i]>=a[j])
                    {
                        temp = a[i];
                        a[i] = a[j];
                        a[j] = temp;
                    }
                }
            }
        }
        else
        {
            a[n-1] = a[0];
        }
        //Maximum Pssibility Of K
        max = a[n-1]+m;

        //Determining minimum possibility of K
        if(n!=1)
        {
            i=0;
            while(m!=0)
            {
                if(a[i]!= a[n-1])
                {
                    add = a[n-1]-a[i];
                    a[i] =a[i]+add;
                    t = m-add;
                    m = t;
                    i++;
                }
                else
                {
                    m--;
                    if(i==(n-1))
                    {
                        a[p] = a[p]+1;
                        p++;
                        i = p;
                    }
                    else
                    {
                        a[i]=a[i]+1;
                        i++;
                    }

                }

            }

            k = a[0];
        }
        else
        {
            k = max;
        }
        printf("%d %d",k,max);

        return 0;

}


#include <stdio.h>
int main(void)
{
    int n, k, i;
    int lo, hi;
    int a[100];
    scanf("%d", &n);
    scanf("%d", &k);
    for(i=0; i < n; i++)
    {
        scanf("%d", &a + 4*i);
        if(i==0)
            lo = a[0], hi = a[0];
        else
        {
            if(a[i] < lo)
                lo = a[i];
            if(a[i] > hi)
                hi = a[i];
        }
    }
    printf("%d %d", lo, hi + k);

}


#include <stdio.h>

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

int main(void) {
	int a,b,c;
	int x,y,z;
	scanf("%d%d%d",&a,&b,&c);
	scanf("%d%d%d",&x,&y,&z);
	int count=0;
	if(a>x) count+=a-x;
	if(b>y) count+=b-y;
	if(c>z) count+=c-z;

	count/=2;

	if(a<x) count+=a-x;
	if(b<y) count+=b-y;
	if(c<z) count+=c-z;

	if (count >=0) printf("Yes\n");
	else printf("No\n")
	return 0;
}


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

  for(int i =1; i < 4 ; i++){
    int test = a[0] + a[i];
    if((test*2)==sum){
      printf("YES\n");
      check = 0;
      return 1;

    }
  }
  if(check == 1){
    printf("NO\n");
  }

}


#include<stdio.h>
#define lli long long int
int main()
{
	lli a,b;
	scanf("%lli %lli",&a,&b);
	step1:;
	if(a==0||b==0)
	goto end;
	step2:;
	if(a>=2*b)
	{
		a=a-2*b;
		goto step1;
	}
	step3:;
	if(b>=2*a)
	{
		b=b-2*a;
		goto step1;
	}
	end:;
	printf("%lli %lli",a,b);
	return 0;
}


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


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

int main(void)
{
    unsigned char s[50],t[50];
    int i;
    scanf("%s%s",&s,&t);
    for(i=0;i<strlen(s);i++)
        if(t[i]!=s[strlen(s)-1-i]) { printf("NO"); return 0; }
    printf("YES");
    return 0;
}


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

struct exam{
	int a;
	int b;
	int c;
};

struct exam x[100];
int s[100],day[100]={0};

int compare(const void *a,const void *b){
	return x[s[*(int *)a]].b-x[s[*(int *)b]].b;
}

int main(void){
	int n,m,i,j;

	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d %d %d",&x[i].a,&x[i].b,&x[i].c);
		s[i]=i;
		day[x[i].b-1]=i+1;
	}

	qsort(s,m,sizeof(int),compare);

	for(i=0;i<n;i++){
		if(day[i]!=0){
			if(x[day[i]-1].c>0){
				printf("-1\n");
				return 0;
			}
			else{
				day[i]=m+1;
			}
		}
		else{
			for(j=0;j<m;j++){
				if(i+1>=x[s[j]].a&&x[s[j]].c>0){
					x[s[j]].c--;
					day[i]=s[j]+1;
					break;
				}
			}
		}
	}

	for(i=0;i<n-1;i++){
		printf("%d ",day[i]);
	}
	printf("%d\n",day[n-1]);

	return 0;
}


#include<stdio.h>
int main()
{
    int i=0,count=0;
    char s[15],s1[15];
    scanf("%s",&s);
    while(s[i]!="\0")
    {
        if(s1[i]!=s[i])
        {
            count++;
        }
        i=i+1;
    }
    if(count==1)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
    return 0;
}


#include<stdio.h>

int main()
{
    long long n,ans=0;
    int flag=0;

    scanf("%I64d",&n);

    while(n>=1)
    {
        if(n>=1 && flag==0)
        {
            n--;
            ans++;
            flag=1;
        }
       if(n>=2 && flag==1)
        {
            n-=2;
            ans++;
            flag=0;
        }

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

    return 0;

}


#include <stdio.h>

int maxx(int a, int b){
    int m = a;
    if(b>m)  m = b;
    return m;
}

int main() {
    int n, aux = 0, max = 0;
    char *s;

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

    for(int i = 0; i < n; i++) {
        if(s[i] == '+'){
            aux++;
        } else  aux--;
        max = maxx(max, aux);
    }

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

    return 0;
}


#include <stdio.h>

#define in32(x) scanf("%d", &x)
#define out32(x) printf("%d", x)

int main() {
    int t, n, i;
    in32(t);
    while(t--) {
        in32(n);
        i = 2;
        while (n%i && i * i <= n) i++;
        if ((n%i)) {
            i = n;
        }
        printf("%d %d\n", n / i, n - n / i);
    }
    return 1;
}


#include <stdio.h>

int main()
{
    int n, a, b, i, rem;

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

    if(n > 1)
    {
        if(b == 0)
            printf("%d", a);
        else if(b > 0)
        {
            if((a + b) <= n)
                printf("%d", a+b);
            else
            {
                rem = (a + b) % n;

                if(rem == 0)
                    printf("%d", n);
                else
                    printf("%d", rem);
            }
        }
        else
        {
            i = 1;

            do{
                rem = (b - 1) % n;

                if(rem == 0)
                    break;
                else
                    i++;
            }while(1);

            printf("%d", a+i);
        }
    }
    else
        printf("%d", 1);

    return 0;
}


#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,max,sum2,min,f,o,sum1,sum=0,y,x1,y1,count1=0,a2,b2,a[100000],b,c,z;
char a1[100000];
scanf("%lld",&n);
if(44447777<n){
printf("4444477777");
}
for(i=n;;i++){
    x=0;
    y=0;
    x1=i;
    flag=0;
    while(x1>0){
        if(x1%10==4){
            x++;
        }else{
            if(x1%10==7){
                y++;
            }else{
                flag=1;
            }
        }
        x1/=10;
    }
    if(x==y && flag==0){
        printf("%lld",i);
        return 0;
    }
}

return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int T1,T2,x,y,z,t1,t2,t3;
	scanf("%d,%d,%d,%d,%d,%d",x,y,z,t1,t2,t3);
	T1=abs(z-x)*t2+abs(x-y)*t2+3*t1;
	T2=abs(x-y)*t1;
	if (T1<T2)
	     printf("YES");
	     else
	         printf("NO");
	return 0;
}


#include <stdio.h>
int main()
{
    int x,y,z,t1,t2,t3,temp,el,st;
    scanf("%d %d %d %d %d %d",x,y,z,t1,t2,t3);
    if(z<x){
        temp=(x-z)*t2+t3*3;
        if(y>x){
            el=temp+(y-x)*t2;
            st=(y-x)*t1;
            if(el<=st){
                printf("YES");
            }
            else{
                printf("NO");
            }
        }
        else{
            el=temp+(x-y)*t2;
            st=(x-y)*t1;
            if(el<=st){
                printf("YES");
            }
            else{
                printf("NO");
            }
        }
    }
    else{
        temp=(z-x)*t2+t3*3;
        if(y>x){
            el=temp+(y-x)*t2;
            st=(y-x)*t1;
            if(el<=st){
                printf("YES");
            }
            else{
                printf("NO");
            }
        }
        else{
            el=temp+t3*3+(x-y)*t2;
            st=(x-y)*t1;
            if(el<=st){
                printf("YES");
            }
            else{
                printf("NO");
            }
        }
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#define SWAP(x,y) { int tmp=x;	x=y;	y=tmp; }
char num[8][9];
char C[8][9];
int S[8];
int findMax(int n,int k){
	int ans=-1;
	for(int i=0;i<n;i++){
		int tmp=0;
		for(int j=0;j<k;j++)
			tmp=tmp*10+C[i][j]-'0';
		if( ans<tmp )
			ans=tmp;
	}
	return ans;
}
int findMin(int n,int k){
	int ans=2e9;
	for(int i=0;i<n;i++){
		int tmp=0;
		for(int j=0;j<k;j++)
			tmp=tmp*10+C[i][j]-'0';
		if( ans>tmp )
			ans=tmp;
	}
	return ans;
}
int main(){
	int n,k;
	while( scanf("%d%d",&n,&k)==2 ){
		int ans=2e9;
		for(int i=0;i<n;i++)
			scanf("%s",num[i]);
		for(int i=0;i<k;i++)
			S[i]=i;

		for(int i=0;i<n;i++){
			for(int j=0;j<k;j++)
				C[i][j]=num[i][S[j]];
			C[i][k]='\0';
		}
		int max=findMax(n,k);
		int min=findMin(n,k);
		if( ans>max-min )
			ans=max-min;
		while( true ){
			int i,j;
			for(i=k-2;i>=0&&S[i]>S[i+1];i--);
			if( i<0 )
				break;
			for(j=k-1;j>i&&S[i]>S[j];j--);
			SWAP(S[i],S[j]);
			for(i++,j=k-1;i<j;i++,j--)
				SWAP(S[i],S[j]);
			for(int i=0;i<n;i++){
				for(int j=0;j<k;j++)
					C[i][j]=num[i][S[j]];
				C[i][k]='\0';
			}
			int max=findMax(n,k);
			int min=findMin(n,k);
			if( ans>max-min )
				ans=max-min;
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<cstdio>
using namespace std;
char a[12][12];
typedef struct node {
	int aa,bb,cc,dd,ee,ff,gg,hh;
} node;
node b[11][11];
int c[]= {-1,-1,-1,0,1,1,1,0};
int d[]= {-1,0,1,-1,1,0,-1,1};
int dfs(int e,int w,int t,int p) {
	if(e<1||e>10||w<1||e>10||a[e][w]=='O') {
		return p;
	}
	if(p!=0&&a[e][w]=='.')  return p;
	if(a[e][w]=='X')  p++;
	int xx=e+c[t];
	int yy=w+d[t];
	dfs(xx,yy,t,p);
}
int main() {
	for(int i=1; i<=10; i++) {
		for(int j=1; j<=10; j++) {
			scanf("%c",&a[i][j]);
		}
		getchar();
	}
	int flag=0;
	for(int i=1; i<=10; i++) {
		for(int j=1; j<=10; j++) {
			if(a[i][j]=='.') {
				for(int k=0; k<=3; k++) {
					int sum=dfs(i,j,k,0)+dfs(i,j,k+4,0);
					if(sum>=4) {
						flag=1;
						break;
					}
				}
			}
			if(flag==1)  break;
		}
		if(flag==1)  break;
	}
	if(flag==1)  printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int ExChange(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main()
{
    int m,n,Max;
    scanf("%d%d",&n,&m);
        if (n==1||m==1)
            printf("%d\n",n*m);
        Max=ExChange(m,n);
        else if (n==2||m==2)
        {
            if (Max%4==0)
                printf("%d\n",Max);
            else if (Max%4==0)
                printf("%d\n",Max+1);
            else
                printf("%d\n",(Max/4)*4+4);
        }
        else
            printf("%d\n",(m*n+1)/2);
    return 0;
}


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

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

int main() {
	//printf("Hola Mundo\n");
	char string[10], aux[10];
	scanf("%s", string);
	int len = 0, i;
	while (string[len] != '\0') {
		aux[len] = string[len];
		len++;
	}

	if (len != 1) {
		qsort(aux, len, sizeof(char), cmpfunc);
		i = len - 1;
		while (aux[i] == aux[len - 1] && i != -1) {
			printf("%c", aux[i]);
			i--;
		}
	} else {
		printf("%s", string);
	}
	return 0;
}


#include <stdio.h>

int main(){

    int n, s=0;
    char c;
    scanf("%d\n",&n);
    scanf("%c",c);
    while(c - '0'){
        s++;
        if (s==n) break;
        scanf("%c",&c);
    }
    if (s==n) printf("%d",n);
    else printf("%d",s+1);

return 0;
}


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


#include <stdio.h>
int main()
{
    int n,c;
    while(1){
            c=0;
    scanf("%d%*c",&n);
    char str[100],*ptr;
    gets(str);
    ptr=str;
    while(*ptr)
    {
        if(*ptr=='1')
            c++;
        if(*ptr=='0')
        {
            printf("%d",c);
            c=0;
        }
            ptr++;
    }
    ptr--;
    if(*ptr=='1')
        printf("%d",c);
    printf("\n");
}
}


// ConsoleApplication1.cpp : �������̨Ӧ�ó������ڵ㡣
//

#include "stdafx.h"
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int i, j, k;
	int n, m, t, d;
	int sum1=0;
	int sum2=0;
	scanf("%d %d %d %d", &n, &t, &k, &d);
	int l = n;
	while (l > 0)
	{
		sum1 += t;
		l -= k;
	}
	l = n;
	while (l > 0)
	{
		sum2++;
		if (sum2%t == 0)
		{
			l -= k;
		}
		if (sum2 - d > 0 && (sum2 - d) % t == 0)
		{
			l -= k;
		}
	}
	if (sum1 > sum2)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int max=0;
int a[10];//״̬
int p[100];
typedef struct Ch
{
	int val;
	int mvrg;
	int thrg;
};
typedef struct Ch CA[4];
int movethrow(CA,int);
int search(int pe)
{
	int i,t;
	for (i=1;i<45;i++)
	{
		if (p[i]>0)
		{
			t=p[i];
			while (t)
			{
				if ((t%10)==pe)
					return i;
				t=t/10;
			}
		}
	}
}
int change(int pe,int pos)
{
	int t;
	t=search(pe);
	p[t]=0;
	p[pos]=pe;

}
int tr(CA C,int pe)
{
	int i,j;
	int temp;
	int f,m,r,t[3];
	t[1]=search(1);
	t[2]=search(2);
	t[3]=search(3);
	m=t[pe];
	temp=p[m];
	f=m-C[pe].thrg;
	r=m+C[pe].thrg;
	if (r>max)
		max=r;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0&&
			(abs(i-t[1])==1||abs(i-t[2]==1)||abs(i-t[3])==1||i==r))
		{
			p[i]=temp/10;
			p[m]=temp%10;
			for (j=1;j<=9;j++)
			{

				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[i]=0;
			p[m]=temp;
		}
	}
	return 0;
}
int mv(CA C,int pe)
{
	int i,j;
	int f,m,r,t[3];
	t[1]=search(1);
	t[2]=search(2);
	t[3]=search(3);
	m=t[pe];

	f=m-C[pe].mvrg;
	r=m+C[pe].mvrg;
	if (r>max)
		max=r;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0&&
			(abs(i-t[1])==1||abs(i-t[2]==1)||abs(i-t[3])==1||i==r))
		{
			change(pe,i);

			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
		}
	}
	change(pe,m);
	return 0;
}

int movethrow(CA C,int fr)
{
	int i,j;
	int rt;
	if (fr%3==1)
	{
		rt=fr/3+1;
		if (a[fr+1]==1&&a[fr+2]==0)
		{
			return 0;
		}
		else if (p[search(rt)]>10)
		{
			return 0;
	 	}
		else
		{
			mv(C,rt);

			return 0;
		}

	}
	if (fr%3==2)
	{
		int px;
		rt=fr/3+1;
		px=search(rt);
		if (p[px]>10)
		{
			return 0;
		}
		else if (p[px-1]>0)
		{
			int temp;
			p[px]+=p[px-1]*10;
			temp=p[px-1];
			p[px-1]=0;
			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[px]=rt;
			p[px-1]=temp;
		}
		else if (p[px+1]>0)
		{
			int temp;
			p[px]+=p[px+1]*10;
			temp=p[px+1];
			p[px+1]=0;
			for (j=1;j<=9;j++)
			{
				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[px]=rt;
			p[px+1]=temp;
			return 0;
		}
		else
		{
			return 0;
		}
	}
	if (fr%3==0)
	{
		rt=fr/3;
		int px;
		px=search(rt);
		if (a[fr-1]==0)
		{
			return 0;
		}
		else if (p[px]%10!=rt)
		{
			return 0;
		}
		else
		{
			tr(C,rt);
			return 0;
		}
	}
}
int main()
{
	CA C;
	int i,j;
	for (i=1;i<100;i++)
	{
		p[i]=0;
	}
	for (i=1;i<=3;i++)
	{
		scanf("%d %d %d",&C[i].val,&C[i].mvrg,&C[i].thrg);
		p[C[i].val]=i;
	}
	for (i=0;i<=9;i++)
	{
		a[i]=0;
	}
	for (i=1;i<=9;i++)
	{
		a[i]=1;a[0]++;
		movethrow(C,i);
		a[i]=0;a[0]--;
	}
	printf("%d",max);
	return 0;
}