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

int main()
{

		long long int n;
		scanf("%lld", &n);

		long long int r[n];
		long long int b[n];
		long long int i;

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

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

		long long int neg = 0;
		long long int pos = 0;
		for ( i = 0; i < n; ++i )
		{
			if ( r[i] == 1 && b[i] == 0 )
			{
				++pos;
			}

			if ( r[i] == 0 && b[i] == 1 )
			{
				++neg;
			}
		}

		if ( pos == 0 )
		{
			printf("-1\n");
		}
		else
		{
			long long int sol = neg/pos+1;
			printf("%lld\n", sol);
		}

	//system("pause");
}


#include<stdio.h>
int main()
{
	long int a,i;
	scanf("%ld",&a);
	while(a>1)
	{
	    printf("%ld ",a);
	    for(i=2;i<=a;i++)
	    {
	    	if(a%i==0)
	    	{
	    		a/=i;
	    		break;
			}

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


int main(){

    int n;

    scanf("%i" ,&n);

    for(int i = n;i>0;i--){
        if(n%i == 0){
            n = i;
            printf("%i ",n);
        }
    }
return 0;
}


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

#define DATA_SIZE 2005
#define MODULE 1000000007

long long dp[DATA_SIZE][DATA_SIZE];

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; i++)
	{
		dp[i][1] = 1;
	}
	for (int i = 1; i <= n; ++i)
	{
		for (int kk = 2; kk <= k; ++kk)
		{
			for (int j = i; j <= n; j += i)
			{
				dp[j][kk] = (dp[j][kk] + dp[i][kk - 1]) % MODULE;
			}
		}
	}

	long long res = 0;
	for (int i = 1; i <= n; ++i)
	{
		res += dp[i][k];
	}
	printf("%I64d", res % MODULE);
	return 0;
}


#include <stdio.h>

int main(void)
{
    long long n, m, k, d, fd;

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

    if (k < n) {
        printf("%lld 1", k + 1);
    } else if (k < n + m - 1) {
        printf("%lld %lld", n, 1 + k - (n - 1));
    } else {
        k -= (n - 1) + (m - 1);
        d = k / (m - 1);
        fd = 0;
        if (k % (m - 1) == 0) {
            d--;
            fd = 1;
        }

        printf("%lld ", n - 1 - d);
        if (d & 1) {
            if (!fd) {
                printf("%lld", 1 + k % (m - 1));
            } else {
                printf("%lld", m);
            }
        } else {
            if (!fd) {
                printf("%lld", m - (k % (m - 1) - 1));
            } else {
                printf("%lld", 2);
            }
        }
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int cmp(int *a,int *b);
int main()
{
	int sl[6];
	while(scanf("%d %d %d %d %d %d",&sl[0],&sl[1],&sl[2],&sl[3],&sl[4],&sl[5])!=EOF){
		qsort(sl,6,sizeof(int),cmp);
		if(sl[0]==sl[3]){
			if(sl[4]==sl[5])
				printf("Elephant\n");
			else
				printf("Bear\n");
		}

		else if(sl[1]==sl[4])
			printf("Bear\n");
		else if(sl[2]==sl[5]){
			if(sl[0]==sl[1])
				printf("Elephant\n");
			else
				printf("Bear\n");
		}
		else
			printf("Alien\n");

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


#include<stdio.h>
int main()
{int a[6],i,j,k,temp,max,min;
	for(i=0;i<6;i++){
	scanf("%d",&a[i]);}

	for(i=0;i<6;i++){
	min=i;
		for(j=i+1;j<6;j++)
	{	if(a[j]<a[min])
		min =j;}
		temp =a[min];
		a[min]=a[i];
		a[i]=temp;}

	k=0;
	max=0;
	for(i=1;i<6;i++)
	{if(a[max]<a[i]){max=i;}}
	for(i=0;i<6;i++){
	if(a[3]==a[i]){k++;}
	}
	if(k<4){printf("Alien");
		}
	else if(k==4)
	{if(a[max] != a[3])
		{//printf("omg");
			if(a[0]!=a[1]){printf("Bear");}
			else if(a[4]!=a[5]){printf("Bear");}
			else {printf("Elephant");}
		}
	else {
		if(a[0]!=a[1]){printf("Bear");}
		else{printf("Elephant");}
	}}

	else if(k==5){printf("Bear");}
	else if(k==6){printf("Elephant");}
//printf("%d%d",k,max);
//	for(i=0;i<6;i++)
//{	printf("%d",a[i]);}
	return 0;}


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

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

int main() {
	long long s, x;

	scanf("%lld%lld", &s, &x);
	if (s < x || s - x & 1 || s - x >> 1 & x)
		printf("0\n");
	else
		printf("%lld\n", (1LL << count(x)) - (s == x ? 2 : 0));
	return 0;
}


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

uint64_t count(uint64_t s, uint64_t x)
{
    if ((!s && !x))
        return 1;
    if ((s & 1) ^ (x & 1))
        return 0;

    if ((s & 1))
        return 2*count(s >> 1, x >> 1);
    return count(s >> 1, x >> 1) + count((s >> 1)-1, x >> 1);
}

int main(int argc, char *argv[])
{
    uint64_t s, x;
    scanf("%"PRIu64" %"PRIu64"", &s, &x);
    printf("%"PRIu64"\n", count(s, x) - 2*(s == x));
    return 0;
}


#include <stdio.h>

int main()
{
     int x, i;
     long long n = 0;

     scanf("%d", &x);

     if (x < 0) x *= -1;

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

	  if ((n == x) || (n > x && (n - x) % 2 == 0)) {
	       printf("%d\n", i);

	       return 0;
	  }
     }

     return 0;
}


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

int main()
{
    long long int n,j,r,x;
    scanf("%lld",&n);
    if(n<0)
        n=-n;
    for(j=0;;j++)
    {
       r=(j*(j+1)/2);
       x=r-n;
        if(x%2==0 && x/2<=r && x/2>=0)
        {
            printf("%lld\n",j);
            return 0;
        }
    }

    return 0;
}


#include <stdio.h>
int main() {
float a,b,c,d,e,f,k,l,j;
scanf("%f %f %f %f %f %f %f %f %f",&a,&b,&c,&d,&e,&f,&j,&l,&k);
k = (b / a) * 100;

l = (d / c) * k ;

j = (f / e) * l;
if(c == 0 && d != 0) {
    printf("Ron");
}
else if(a == 0 && b != 0 && d != 0) {
printf("Ron"); }
else if(b == 0 || d == 0 || f == 0) {
printf("Hermione");}

else if(a == 0 || c == 0 || e == 0) {
printf("Ron");}

else if(j > 100) {
printf("Ron");}

else
printf("Hermione");

return 0;
}


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

int isZero(double i)
{
	if(fabs(i)<1e-6)
		return 1;
	return 0;
}

int isRon(double a,double b,double c,double d,double e,double f)
{
	double result;
	if(isZero(d))
		return 0;
	else
	{
		if(isZero(c))
			return 1;
		else
		{
			if(isZero(b))
				return 0;
			else
			{
				if(isZero(a))
					return 1;
				else
				{
					if(isZero(f))
						return 0;
					else
					{
						if(isZero(e))
							return 1;
						else
						{
							result=(b*d*f)/(a*c*e);
							if((result<1)||isZero(result-1))
								return 0;
							return 1;
						}
					}
				}
			}
		}
	}
}

int main()
{
	double a,b,c,d,e,f;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)==6)
	{
		if(isRon(a,b,c,d,e,f))
			printf("Ron\n");
		else
			printf("Hermione\n");
	}
	return 0;
}


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

struct vertex {
	struct coordinate {
		int x, y;
	} c;
	char has_x, has_y;
} vertices[4];

int compare(const void *a, const void *b) {
	struct vertex pa = *(struct vertex *) a;
	struct vertex pb = *(struct vertex *) b;

	return pa.c.x != pb.c.x ? pa.c.x - pb.c.x : pa.c.y - pb.c.y;
}

struct vertex *lookup(int x, int y, int vcnt) {
	int i;

	for (i = 0; i < vcnt; i++)
		if (vertices[i].c.x == x && vertices[i].c.y == y)
			return vertices + i;
	return NULL;
}

int rect1() {
	char good = 1;
	int i, x1, y1, x2, y2, vcnt = 0;
	struct vertex *v1, *v2;

	for (i = 0; i < 4; i++) {
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if ((x1 != x2 && y1 != y2) || (x1 == x2 && y1 == y2))
			good = 0;

		if ((v1 = lookup(x1, y1, vcnt)) == NULL)
			if (vcnt == 4)
				good = 0;
			else {
				v1 = vertices + vcnt;
				vertices[vcnt].c.x = x1, vertices[vcnt].c.y = y1;
				vertices[vcnt].has_x = 0, vertices[vcnt].has_y = 0;
				vcnt++;
			}
		else if ((x1 == x2 && v1->has_x) || (y1 == y2 && v1->has_y))
			good = 0;
		if ((v2 = lookup(x2, y2, vcnt)) == NULL)
			if (vcnt == 4)
				good = 0;
			else {
				v2 = vertices + vcnt;
				vertices[vcnt].c.x = x2, vertices[vcnt].c.y = y2;
				vertices[vcnt].has_x = 0, vertices[vcnt].has_y = 0;
				vcnt++;
			}
		else if ((x1 == x2 && v2->has_x) || (y1 == y2 && v2->has_y))
			good = 0;

		if (x1 == x2 && good && !v1->has_x && !v2->has_x) {
			v1->has_x = 1;
			v2->has_x = 1;
		} else if (y1 == y2 && good && !v1->has_y && !v2->has_y) {
			v1->has_y = 1;
			v2->has_y = 1;
		}
	}
	if (vcnt < 4)
		return 0;
	return good;
}

int rect2(struct vertex *v) {
	qsort(v, 4, sizeof(struct vertex), compare);
	return v[1].c.x == v[0].c.x && v[1].c.y == v[3].c.y
		&& v[2].c.x == v[3].c.x && v[2].c.y == v[0].c.y;
}

int main() {
	if (rect1() && rect2(vertices))
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
long long rec(long long a,long long b)
{
    if(b==0)
        return 1;
    long long res=rec(a,b/2);
    if(b&1)
        return a*res*res;
    else
        return res*res;
}
main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long n;
        scanf("%lld",&n);
        long long a=2;
        printf("%lld\n",rec(a,n)-1);
    }
    return 0;
}


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

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 ? a : b; }

int main() {
	int r, g, b, a;
	long long s;

	scanf("%d%d%d", &r, &g, &b);
	a = max(r, max(g, b));
	s = (long long) r + g + b;
	printf("%lld\n", min(s - a, s / 3));
	return 0;
}


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

int main()
{
    int n,i,t,k,temp;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    scanf("%d",&t);
    for(i=n-1;i>0;i--)
    {
        for(k=0;k<i;k++)
        {
            if(arr[k]>arr[k+1])
            {
                temp = arr[k];
                arr[k]=arr[k+1];
                arr[k+1]=temp;
            }
        }
    }
    int counter,max=0;
    for(i=0;i<n-1;i++)
    {
        counter=0;
        k=i+1;
        while(k<n && arr[k]-arr[i]<=t)
        {
            counter++;
            k++;
        }
        if(counter>max)
        {
            max=counter;
        }
        if(k==n)
        {
            break;
        }
    }
    printf("%d",max+1);
    return 0;
}


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

int main()
{
	int n;
	int t[1001] = {0};
	int T;
	int count[1001] = {0};
	int c = 0;
	int tmp;
	int i, j;

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

	for (i = 1; i <= 1000 - T; i++)
	{
		for (j = i; j <= i + T; j++)
			count[c] += t[j];
		//if (c < 8)
		//	printf("count[%d] = %d\n", c, count[c]);
		c++;
	}

	int max = 0;
	for (i = 0; i < c; i++)
		if (count[i] > max)
			max = count[i];

	if (T == 1000)
		max = n;

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


#include<stdio.h>
#define N 202
int main(){
    int n;
    scanf("%d",&n);
    char s[N];
    scanf("%s",s);
    //printf("%s\n",s);
    int count[30];
    int i,j;
    for(j=0;j<30;j++){
        count[j]=0;
    }
    i=0;
    int max_res=0;
    int res=0;
    while(1){
        if(s[i]>='a' && s[i]<='z'){
            count[s[i]-'a']++;
        }else{
            res=0;
            for(j=0;j<30;j++){
                if(count[j]>0){
                    res++;
                }
            }
            if(res>max_res)max_res=res;
            for(j=0;j<30;j++){
                count[j]=0;
            }
        }
        if(s[i]=='\0')break;
        i++;
    }
    printf("%d\n",max_res);
    //我认为就是不同的小写字母的个数！
    return 0;
}


#include<stdio.h>
#include<string.h>
int is_big(char a)
{
	if(a>='A'&&a<='Z')
		return 1;
	else
		return 0;
}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		getchar();
		char a[220];
		int max=0,sum=0,abc[27];
		for(int i=0;i<n;i++)
			scanf("%c",&a[i]);
		for(int i=0;i<n;i++)
		{
			memset(abc,0,sizeof(abc));
			if(!is_big(a[i]))
			{
				abc[a[i] - 'a' ] = 1;
				sum = 1;
				for(int j=i+1;j<n;j++)
				{
					if(!(is_big(a[j])) && abc[a[j] - 'a'] != 1)
					{
						sum++;
						abc[a[j] - 'a'] = 1;
					}
					else if(is_big(a[j]))
						break;
				}
				if(sum>max)
					max = sum;
			}
		}
		printf("%d\n",max);
	}
	return 0;
 }


#include<stdio.h>
int main()
{
	long long int num=44720,a;
	long long int A[num+1],i,j;
	for(i=1;i<=num;i++)
	A[i]=(i*(i+1))/2;
	//for(i=1;i<=22;i++)
	//printf("%lld\n",A[i]);
	long long int n;
	scanf("%lld",&n);
	for(i=1;i<=num;i++)
	{
		a=n-A[i];
		if(a<=0)
		{
			printf("NO");
			return 0;
		}
		long long int first=0;;
		long long int last=num;
		long long int middle=(first+last)/2;
		while(first<=last)
		{
			if(A[middle]<a)
			first=middle+1;
			else if(A[middle]>a)
			last=middle-1;
			else if(A[middle]==a)
			{
				printf("YES");
				return 0;
			}
			middle=(first+last)/2;
		}
	}
//	printf("%lld %lld",i,j);
	printf("NO");
	return 0;
}


#include<stdio.h>
int main()
{
	int n,k,l,x,y;
	scanf("%d",&n);
	x=1;
	for(k=1;x<n;k++,x=x+k)
	{
		y=1;
		for(l=1;y<=n-x;l++,y=y+l)
		{

			if(x+y==n)
			{
				printf("YES\n");
				return 0;
			}
		}
	}
	printf("NO\n");
	return 0;
}


#include<stdio.h>

int c1, c2, x, y, ans;
int main()
{
    scanf("%d%d%d%d", &c1, &c2, &x, &y);

    ans = c1+c2;
    while(ans - ans/x < c1)
    {
        ans += c1 - (ans - ans/x);
    }
    while(ans - ans/y < c2)
    {
        ans += c2 - (ans - ans/y);
    }
    while(ans - ans/(x*y) < c1+c2)
    {
        ans += (c1+c2) - (ans - ans/(x*y));
    }
    printf("%d\n", ans);
    return 0;
}


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

#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))

typedef long long llong;

bool enough(llong v, int cx, int cy, int x, int y) {
	llong for_neither = v / (x*y);
	llong for_x = v / y - for_neither,
		 for_y = v / x - for_neither;

	llong for_both = v - (for_x + for_y + for_neither);

	return for_both - (MAX(cx - for_x, 0) + MAX(cy - for_y, 0)) >= 0L;
}

llong solve(int cx, int cy, int x, int y) {

	llong l = 1;
	llong r = MAX(cx, cy);
	while (!enough(r, cx, cy, x, y)) {
		r *= 2;
	}

	while (l < r) {
		llong m = (l + r) / 2;
		if (enough(m, cx, cy, x, y)) {
			r = m;
		}
		else {
			l = m + 1;
		}
	}

	return r;
}

int main(int argc, char **argv) {

	int cx, cy, x, y;
	while (scanf("%d %d %d %d", &cx, &cy, &x, &y) != EOF) {
		printf("%lld\n", solve(cx, cy, x, y));
	}
	return 0;
}


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

int fun(int year)
{
    if((year%4==0&&year%100!=0)||year%400==0)
        return 1;
    return 0;
}
int fin(int year,int month,int day)
{
    int i,sum=0;
    for(i=1;i<month;i++)
    {
        if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)sum+=31;
        else if(i!=2)sum+=30;
        else sum+=28;
    }
    sum+=day;
    if(((year%4==0&&year%100!=0)||(year%400==0))&&month>2)sum+=1;
    return sum;
}
void swap(int *a,int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}
int main()
{
    int year1,month1,day1,sum,year2,month2,day2,i,j,temp;
    while(~scanf("%d:%d:%d",&year1,&month1,&day1))
    {
        scanf("%d:%d:%d",&year2,&month2,&day2);
        if(year1>year2)
        {
            swap(&year1,&year2),swap(&month1,&month2),swap(&day1,&day2);
        }
        else if(year1==year2)
        {
            if(month1>month2)swap(&month1,&month2),swap(&day1,&day2);
            else if(month1==month2)
            {
                if(day1>day2)swap(&day1,&day2);
            }
        }
        sum=0;
        for(i=year1;i<year2;i++)
            sum+=fun(i);
        sum+=(year2-year1)*365;
        sum-=fin(year1,month1,day1);
        sum+=1;
        sum+=fin(year2,month2,day2);
        printf("%d\n",sum-1);
    }
    return 0;
}


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

int fun(int year)
{
    if((year%4==0&&year%100!=0)||year%400==0)
        return 1;
    return 0;
}
int f1(int year,int month,int day)
{
    int i,sum=0;
    for(i=1;i<month;i++)
    {
        if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)sum+=31;
        else if(i!=2)sum+=30;
        else sum+=28;
    }
    sum+=day;
    if(((year%4==0&&year%100!=0)||(year%400==0))&&month>2)sum+=1;
    return sum;
}
void swap(int *a,int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}
int main()
{
    int year1,month1,day1,sum,year2,month2,day2,i,j,temp;
    while(~scanf("%d:%d:%d",&year1,&month1,&day1))
    {
        scanf("%d:%d:%d",&year2,&month2,&day2);
        if(year1>year2)
        {
            swap(&year1,&year2),swap(&month1,&month2),swap(&day1,&day2);
        }
        else if(year1==year2)
        {
            if(month1>month2)swap(&month1,&month2),swap(&day1,&day2);
            else if(month1==month2)
            {
                if(day1>day2)swap(&day1,&day2);
            }
        }
        sum=0;
        for(i=year1;i<year2;i++)
            sum+=fun(i);
        sum+=(year2-year1)*365;
        sum-=f1(year1,month1,day1);
        sum+=1;
        sum+=f1(year2,month2,day2);
        printf("%d\n",sum-1);
    }
    return 0;
}


#include <stdio.h>

int main()
{
    int a,x,y;

    scanf("%d%d%d",&a,&x,&y);
    if(y==0)
        {
            printf("-1\n");
            return 0;
        }
    if(y<a)
    {
        if((a)<2*abs(x))
        {
            printf("-1\n");
            return 0;
        }
        else if(2*abs(x)==(a))
            {
                printf("-1\n");
                return 0;
            }
        else if(x==0 && y==0) printf("-1\n");
        else if(x==0 && y>0) printf("1\n");
        else printf("1\n");
    }
    else if(y>=a)
    {
        int c=y-a;
        if(c%a==0)
        {
            printf("-1\n");
            return 0;
        }
        else
        {
            int num=0;
            int d=c/a;
    //      int rem=c%a;
            if(d%2==0)
            {
                num=1+3*(d/2);

                if(2*abs(x)<(a))
                {
                    printf("%d\n",num+1);
                    return 0;
                }
                else
                {
                    printf("-1\n");
                    return 0;
                }
            }
            else
            {
                if(d>1) num=2+3*(d-1)/2;
                else num = 2;
                if(abs(x)>=a)
                {
                    printf("-1\n");
                    return 0;
                }
                else
                {
                    if(x==0) printf("-1\n");
                    else if(x<0) printf("%d\n",num+1);
                    else if(x>0) printf("%d\n",num+2);
                }
            }
        }
    }

return 0;

}


#include<stdio.h>
#include<math.h>
main()
{
int a,x,y,t;
scanf("%d%d%d",&a,&x,&y);
if(y%a==0)
printf("%d",-1);
else if(y<(2*a))
{
    int p=abs(x);
if(p<(fabs)((double)a/2))
printf("%d",y/a+1);
else
printf("%d",-1);
}
else if(y>(2*a))
{
    t=y/a+1;
    if(t%2==0)
       {
           if(abs(x)<(fabs)((double)a/2))
           {
               int g=((t-1)/2)*3+2;
               printf("%d",g);

           }
           else
           printf("%d",-1);
        }
    else
    {
        if(x>0 && x<a)
        printf("%d",(t/2)*3+1);
       else if(x<0 && x>-a)
        printf("%d",(t/2)*3);
        else
        printf("%d",-1);
    }

}
return(0);
}


#include<stdio.h>
int main()
{
	int tc;
	scanf("%d",&tc);
	char input[105];
	scanf("%s",input);
	int temp = 0;
	for(int i = 0;i<=tc;i++)
	{
		temp += i;
		if(temp >= tc) break;
		printf("%c",input[temp]);
	}
	return 0;
}


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


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

#define in32(x) scanf("%d", &x)
#define out32(x) printf("%d\n", (x))
#define in64(x) scanf("%lld", &x)
#define out64(x) printf("%lld\n", (x))
#define inStr(x) scanf("%s", x)
#define outStr(x) printf("%s\n", (x))
#define fo(a,b,c) for(a=b;a<=c;a++)
#define of(a,b,c) for(a=b;a>=c;a--)

int main() {
   char w[101], c;
   int ans=0,n,i,j;
   in32(n);
   inStr(w);
   of(c,'z','b') {
      fo(i,0,n-1) {
         if (w[i]==c &&
            ((i && w[i-1]==c-1) ||
            (i<n-1 && w[i+1]==c-1))) {
            n--;
            fo(j,i,n)
               w[j]=w[j+1];
            i=-1;
            ans++;
         }
      }
   }
   out32(ans);
   return 0;
}


/*interface*/
#include<stdio.h>
#include<string.h>
#define N 10
/*interface implementation*/
int counter,total;
int c12,question;
void rec(int deep,int value) {
    //printf("rec(%d,%d)\n",deep,value);
    if(deep==question) {
        //printf("value=%d\n",value);
        if(c12==value) counter++;
        total++;
        return;
    }
    rec(deep+1,value+1);
    rec(deep+1,value-1);
}
/*client*/
int main() {
    char s1[N+1];
    char s2[N+1];
    scanf("%s",s1);
    scanf("%s",s2);
    int n1=strlen(s1);
    int n2=strlen(s2);
    int c1=0,c2=0;
    int i;
    for(i=0; i<n1; i++) {
        if(s1[i]=='+') c1++;
        else if(s1[i]=='-')c1--;
    }
    question=0;
    for(i=0; i<n2; i++) {
        if(s2[i]=='+') c2++;
        else if(s2[i]=='-')c2--;
        else question++;
    }
    //printf("question=%d\n",question);
    c12=c1-c2;
    //printf("c12=%d\n",c12);
    counter=0;
    total=0;
    rec(0,0);
    double res;
    if(question==0) {
	    if(c1==c2) res=1.0;
	    else res=0.0;
    }
    else res=(1.0*counter)/(1.0*total);
    printf("%.12f\n",res);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
int arr[250]={31,29,31,30,31,30,31,31,30,31,30,31};
int arr1[133];
int test[133];
int is_leap(int year){
  if ( year%400 == 0)
    return 1;
  else if ( year%100 == 0)
   return 0;
  else if ( year%4 == 0 )
    return 1;
  else
   return 0;

  return 0;

}
int main(){

int start = 1000;
int week = 1;
int i;
int in;
scanf("%d",&in);
while(start<in){
	if(is_leap(start))
		arr[1]=29;
	else arr[1]=28;
	for(i=0;i<12;i++)
	{
		int day = arr[i];
		while(day){
			day--;
			week++;
			if(week==8)
				week=1;
		}

	}
	start++;
		if(is_leap(start))
		arr[1]=29;
	else arr[1]=28;
}
int remember=week;

for(i=0;i<12;i++){
		if(is_leap(start))
		arr[1]=29;
	else arr[1]=28;
	arr1[i]=week;
	int day = arr[i];
	while(day){
		day--;
		week++;
		if(week==8)
			week=1;
	}
}
start++;
while(1){
int flag = 1;
if(is_leap(start))
		arr[1]=29;
	else arr[1]=28;
	for(i=0;i<12;i++){
	test[i]=week;
	int day = arr[i];
	while(day){
		day--;
		week++;
		if(week==8)
			week=1;
	}
		}
		for(i=0;i<12;i++){
			if(arr1[i]!=test[i])
		flag=0;
		}
		if(flag){
			printf("%d",start);
			return 0;
		}
	start++;

}

}


#include<stdio.h>
#include<ctype.h>
int main(){
int i,don=3,pun=0,j=0;
char direccion[51];
char dir[56]={};
scanf("%s",direccion);
i=0;
if(direccion[0] == 'h'){
    don = 4;
}
while(direccion[i]!='\0'){
    if(don == 0){
        dir[j]=':';
        j++;
        dir[j]='/';
        j++;
        dir[j]='/';
        j++;
    }
    if(pun==0 && direccion[i] == 'r' && direccion[i+1] == 'u' && don <0){
        dir[j]='.';
        pun++;
        j++;
    }
    dir[j] = direccion[i];
    j++;
    if(pun == 1 && direccion[i]=='u' && direccion[i+1]!='\0'){
        pun++;
        dir[j]='/';
        j++;
    }
    don=don-1;
    i++;
    }
    dir[j]='\0';
    printf("%s",dir);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char s[55];
int n;
int main()
{   int i,j,k,l;
    scanf("%s",s);
    n=strlen(s);
    if(s[0]=='h')
    {   printf("http://");
        k=4;
    }
    else if(s[0]=='f')
    {   printf("ftp://");
        k=3;
    }
    for(i=k;i<n;i++)
    {   if(i!=k)
        {   if(s[i]=='r' && s[i+1]=='u')
            {   printf(".ru");
                if(i+2!=n)
                    printf("/");
                i+=2;
                break;
            }
            else    printf("%c",s[i]);
        }
        else    printf("%c",s[i]);
    }
    for(;i<n;i++)
        printf("%c",s[i]);
    return 0;
}


/*
 * triangle.c
 *
 * Copyright 2019  <examuser@14CPU0017L>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 *
 */

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

int main(int argc, char **argv)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(b+c<=a)
	printf("%d",a+1-(b+c));
	else if(a+c<=b)
	printf("%d",b+1-(a+c));
	else if(a+b<=c)
	printf("%d",c+1-(a+b));
	else printf("0");

	return 0;
}


#include<stdio.h>
int main()
{
    int a,b,c,x,y,z,min;
    scanf("%d%d%d",&a,&b,&c);
    x=a+b;
    y=a+c;
    z=b+c;
    if(x>c && y>b && z>a)
        printf("0");
    else if(x<=c)
    {
        min=c-x+1;
        printf("%d",min);
    }
    else if(y<=b)
    {
        min=b-y+1;
        printf("%d",min);
    }
    else if(z<=a)
    {
        min=a-z+1;
        printf("%d",min);
    }
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	long long int n,a,b,c,cnt;
	scanf("%lld",&n);
	a=1;
	b=1;
	c=2;
	cnt=1;
	while(c<=n)
	{
		a=b;
		b=c;
		c=a+b;
		cnt++;
	}
	printf("%lld\n",cnt-1);
	return 0;
}


#include "stdio.h"

int main(){
	long long n,k,pr1,pr2,pr;

	scanf("%lld",&n);

	pr1=1;
	pr2=1;
	pr=2;
	k=1;
	while (pr<=n){
		pr2=pr1;
		pr1=pr;
		pr=pr1+pr2;
		k++;
	}

	printf("%lld",k-1);

	return 0;
}


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

int main(int argc, const char * argv[])
{
 int32_t n, a;
 scanf("%d %d", &n, &a);
 if(a&1) {
  a += 1;
 } else {
  a = n - a + 2;
 }
 printf("%d", a/2);
 return 0;
}


#include<stdio.h>
int main()
{
    int n,a,b,count=1;
    scanf("%d%d",&n,&b);

    if(b%2==0){
        count=count+(n/2)-b/2;
    }
    else if(b%2!=0){
        count=count+b/2;
    }

    printf("%d",count);
}


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

#define N	20
#define MD	1000000007

int d_, x_, y_;

void gcd_(int a, int b) {
	if (b == 0)
		d_ = a, x_ = 1, y_ = 0;
	else {
		int tmp;

		gcd_(b, a % b);
		tmp = x_ - a / b * y_, x_ = y_, y_ = tmp;
	}
}

int inv[N];

void init() {
	int k;

	for (k = 1; k < N; k++) {
		gcd_(k, MD);
		if (x_ < 0)
			x_ += MD;
		inv[k] = x_;
	}
}

long long ch(long long n, int k) {
	return k == 0 ? 1 : ch(n - 1, k - 1) * (n % MD) % MD * inv[k] % MD;
}

int main() {
	static long long ff[N];
	int n, b, i, ans;
	long long s;

	init();
	scanf("%d%lld", &n, &s);
	for (i = 0; i < n; i++)
		scanf("%lld", &ff[i]);
	ans = 0;
	for (b = 0; b < 1 << n; b++) {
		long long t;
		int k;

		t = s;
		k = 0;
		for (i = 0; i < n; i++)
			if (b & 1 << i) {
				k++;
				t -= ff[i] + 1;
			}
		if (t >= 0) {
			int cnt = ch(t + n - 1, n - 1);

			ans = (ans + (k % 2 == 0 ? cnt : -cnt)) % MD;
		}
	}
	if (ans < 0)
		ans += MD;
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>

int main(void)
{
	char bessie[4], elsie[4];
	int i, a;
	int bessietype, elsietype;

	scanf("%c%c%*c%c%c%*c", &bessie[0], &bessie[1], &bessie[3], &bessie[2]);
	bessie[4] = '\0';
	scanf("%c%c%*c%c%c", &elsie[0], &elsie[1], &elsie[3], &elsie[2]);
	elsie[4] = '\0';

	for(i = 0; i < 4; i++)
	{
		if(bessie[i] == 'A')
		{
			a = i;
			break;
		}
	}
	while(1)
	{
		i = (i + 1) % 4;
		if(bessie[i] == 'B')
		{
			bessietype = 1;
			break;
		}
		if(bessie[i] == 'C')
		{
			bessietype = -1;
			break;
		}
	}

	for(i = 0; i < 4; i++)
	{
		if(elsie[i] == 'A')
		{
			a = i;
			break;
		}
	}
	while(1)
	{
		i = (i + 1) % 4;
		if(elsie[i] == 'B')
		{
			elsietype = 1;
			break;
		}
		if(elsie[i] == 'C')
		{
			elsietype = -1;
			break;
		}
	}

	if(elsietype == bessietype)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}

	return 0;
}


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

char Flag[401][401];

int main()
{
    int N, i, j, Ans = 0;
    char Str[201];
    scanf("%d %s", &N, Str);
    for(i = 0; i < N; ++i) {
        memset(Flag, 0, sizeof(Flag));
        int x = 200, y = 200;
        Flag[x][y] = 1;
        for(j = i; j < N; ++j) {
            if(Str[j] == 'U') {
                --x;
            } else if(Str[j] == 'D') {
                ++x;
            } else if(Str[j] == 'L') {
                --y;
            } else {
                ++y;
            }
            if(Flag[x][y]) {
                ++Ans;
            }
        }
    }
    printf("%d\n", Ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(int argc,char** argv){
	int numberofcommand;
	char sourcecode[200];
	long long unsigned int result=0;
	long long unsigned int counter=0;
	//int skip[120];
	//int counterofskip=0;

	//skip[0]=-1;
	scanf("%d",&numberofcommand);
	scanf("%s",sourcecode);
	for(int i=0;i<numberofcommand;i++){
		/*if(i==skip[counter]){
			counter++;
			continue;
		}*/
		int numofR=0;
		int numofL=0;
		int numofU=0;
		int numofD=0;
		for(int j=i;j<numberofcommand;j++){

			switch(sourcecode[j]){
				case 'R': numofR++;break;
				case 'L': numofL++;break;
				case 'U': numofU++;break;
				case 'D': numofD++;break;
				default:break;
			}
			if(numofD==numofU&&numofL==numofR){
				result++;
				//skip[counterofskip++]=j+1;
			}
		}
	}
	printf("%I64d",result);
	return 0;
}


#include <stdio.h>
#include <math.h>
main()
{
long int rust(int x);
long int lust(int x);
int arrb[20]={0};
long int a,c,ans=0;
scanf("%ld %ld",&a,&c);
int at,ct;
int k=0,i;
while(a!=0 || c!=0)
{
at=a%3;
ct=c%3;
a=a/3;
c=c/3;
switch(ct)
{
case(2):{arrb[k++]=(2-at);
        break;}

case(0):{if(at==0) arrb[k++]=0;
         else arrb[k++]=(3-at);
         break;}
case(1):{if(at==2) arrb[k++]=2;
         else arrb[k++]=(1-at);
         break;}
}
}
k=k-1;
for(i=k;i>=0;i--)
{
ans=ans+lust(i)*arrb[i];
}
printf("%ld",ans);
return 0;
}

long int rust(int x)
        {
            int i;
            long int k=1;
            for(i=1;i<=x;i++)
            k=k*10;
        return k;
        }

long int lust(int x)
        {
            int i;
            long int k=1;
            for(i=1;i<=x;i++)
            k=k*3;
        return k;
        }


#include<stdio.h>
int main()
{
    long long int m,x,y,b,i,rslt=0,j;
    scanf("%lld %lld",&m,&b);

    for(i=0;i<=b;i++) {
        x=m*(b-i);
        j=(x+i)*(x+1)*(i+1)/2;
        if(j>rslt) rslt=j;
    }
    printf("%lld\n",rslt);
    return 0;
}


#include<stdio.h>

int main(void)
{
    long long int m,b,Count=0,Counter,C;
    long long int Max_Banana=0,Sum;
    scanf("%lld%lld",&m,&b);
    while((m*b-m*Count)>=0)
    {
        Sum=0;
        Counter=m*b-m*Count;
        for(C=0;C<=Count;C++)
            Sum+=((Counter+C)*(Counter+C+1))/2-((C-1)*(C))/2;
        if(Max_Banana<Sum)
            Max_Banana=Sum;
        Count++;
    }
    printf("%lld\n",Max_Banana);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int ltr[26], num[10];
int main()
{
    int numcnt=0, ltrcnt=0, i, mindiff=100, _1=-1, _2=-1, _3=-1, _a, _b, _c, maxdiff=-1;
    char inp[6];
    scanf("%c%c%*c%c%c%*c%c%c", &inp[0], &inp[1], &inp[2], &inp[3], &inp[4], &inp[5]);
    num[inp[0]-'0']++;
    num[inp[2]-'0']++;
    num[inp[4]-'0']++;
    ltr[inp[1]-'a']++;
    ltr[inp[3]-'a']++;
    ltr[inp[5]-'a']++;
    for (i = 0; i < 26; i++) if(ltr[i]) ltrcnt++;
    for (i = 0; i < 10; i++)
    {
        if(num[i])
        {
            numcnt++;
            if (_1==-1)
            {
                _1=i;
                continue;
            }
            if (_2==-1)
            {
                _2=i;
                continue;
            }
            if (_3==-1) _3=i;
        }
    }
    if (abs(_1-_2)>maxdiff) maxdiff=abs(_1-_2);
    if (abs(_3-_2)>maxdiff) maxdiff=abs(_3-_2);
    if (abs(_1-_3)>maxdiff) maxdiff=abs(_1-_3);
    if (abs(_1-_2)<mindiff) mindiff=abs(_1-_2);
    if (abs(_3-_2)<mindiff) mindiff=abs(_3-_2);
    if (abs(_1-_3)<mindiff) mindiff=abs(_1-_3);
    if (ltrcnt==1)
    {
        if (numcnt==1) printf("0\n");
        if (numcnt==2) printf("1\n");
        if (numcnt==3)
        {
            if (maxdiff==2) printf("0\n");
            else if (mindiff<3) printf("1\n");
            else printf("2\n");
        }
    }
    if (ltrcnt==2)
    {
        _a = inp[1];
        _b = inp[3];
        _c = inp[5];
        if (_a==_b)
        {
            mindiff = abs(inp[0]-inp[2]);
            if (mindiff < 3) printf("1\n");
            else printf("2\n");
        }
        if (_a==_c)
        {
            mindiff = abs(inp[0]-inp[4]);
            if (mindiff < 3) printf("1\n");
            else printf("2\n");
        }
        if (_c==_b)
        {
            mindiff = abs(inp[4]-inp[2]);
            if (mindiff < 3) printf("1\n");
            else printf("2\n");
        }
    }
    if (ltrcnt==3) printf("2\n");
    return 0;
}


#include<stdio.h>
double pri(double w,double b);
double dra(double w,double b);
double pria[1000][1000]={0};
double draa[1000][1000]={0};
int main(){
int w,b;
scanf("%d%d",&w,&b);
printf("%.9lf\n",pri((double)w,(double)b));
return 0;
}

double pri(double w,double b){
if(pria[(int)(w-1)][(int)(b-1)]!=0)return pria[(int)(w-1)][(int)(b-1)];
if(w==0)return 0;
else if(b==0)return 1;
pria[(int)(w-1)][(int)(b-1)]=(w/(w+b))+(b/(w+b))*dra(w,b-1);
return pria[(int)(w-1)][(int)(b-1)];
}

double dra(double w,double b){
if(draa[(int)(w-1)][(int)(b-1)]!=0)return draa[(int)(w-1)][(int)(b-1)];
if(b==0)return 0;
else if(w==1&&b==1)return 0;
else if(b==1)return 1/(1+w);
draa[(int)(w-1)][(int)(b-1)]=(b/(b+w))*( (w/(b+w-1))*pri(w-1,b-1) + ((b-1)/(b+w-1))*pri(w,b-2) );
return draa[(int)(w-1)][(int)(b-1)];
}


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

double chances_turno_princesa[1001][1001];
double chances_turno_dragao[1001][1001];

double calcula_prob_princesa(int w, int b);
double calcula_prob_dragao(int w, int b);

// Prob. da princesa ganhar se turno é da princesa com w, b
double calcula_prob_princesa(int w, int b) {
	if (w <= 0)
		return 0.;

	if (b <= 0)
		return 1.;

	if (!chances_turno_princesa[w][b])
		chances_turno_princesa[w][b] = ((double) w / ((double) w + b)) + ((double) b / ((double) w + b)) * calcula_prob_dragao(w, b - 1);

	//printf("Prob. princesa: %d %d %f\n", w, b, chances_turno_princesa[w][b]);
	return chances_turno_princesa[w][b];
}

// Prob. da princesa ganhar se turno é do dragão com w, b
double calcula_prob_dragao(int w, int b) {
	if (w <= 0)
		return 0.;

	if (b <= 0.)
		return 0.;

	if (!chances_turno_dragao[w][b]) {
		double ans = ((double) b) / ((double) w + b);	// chance de tirar b

		ans = ans * ((((double) b - 1) / ((double) w + b - 1)) * calcula_prob_princesa(w, b - 2) +
			(((double) w) / ((double) w + b - 1)) * calcula_prob_princesa(w - 1, b - 1));

		chances_turno_dragao[w][b] = ans;
	}

	//printf("Prob. dragão: %d %d %f\n", w, b, chances_turno_dragao[w][b]);
	return chances_turno_dragao[w][b];
}

int main() {
	int w, b;
	double ans = 0, prob_estado = 1;

	memset(chances_turno_princesa, 0, sizeof(chances_turno_princesa));
	memset(chances_turno_dragao, 0, sizeof(chances_turno_dragao));

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

	printf("%.9lf\n", calcula_prob_princesa(w, b));
	return 0;
}


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

int main()
{
    int n,i,e=0;
    scanf("%d",&n);
    char s[n];
    scanf("%s",s);
    for(i=0;s[i]!='\0';i++)
    {
        if(s[i]=='8')
           e++;

    }
    n/=11;
    if(n>=e)
        printf("%d",e);
    else
        printf("%d",n);
    return 0;
}


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

int main() {
    int n;
    int a[10],i,s=0;
    char st[101];
    scanf("%d",&n);
    scanf("%s",&st);
    for (i=0 ; i<=strlen(st) ;i++)
        if (st[i] == '8') s++;
    if ((n / 11) > s) printf("%d",s);
    else printf("%d",(n / 11));
    return 0;
}


#include<stdio.h>
#include<string.h>
main()
{
    char a[300];
    int i,j,k,len,n,cnt=0,max=0;
    scanf("%d",&n);
    getchar();
    gets(a);
    for(i=0;i<n;i++)
    {
        if(a[i]>='A' && a[i]<='Z') cnt++;
        else if(a[i]==' ')cnt=0;
        if(cnt>max)max=cnt;
    }
    printf("%d\n",max);
    return 0;

}


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

int main()
{
    int i,count=0,max=0,n;
    char str[250];
    scanf("%d\n",&n);
    scanf("%[^\n]%*c",str);
if((n>=1)&&(n<=200))

{
    for(i=0;i<n;i++)
    {
        if(isupper(str[i]))
            count++;
        else if((str[i]==' ')||(str[i+1]=='\0'))
        {   if(count>max) max=count;
            count=0;  }
    if(count>max) max=count;
    }
}
printf("%d",max);
    return 0;
}


#include <stdio.h>

long long int arr[15], w, ans;

void dp(int x, long long int y)
{
	if (x > 8)
	{
		if (y > ans)
		{
			ans = y;
		}
		return;
	}
	long long int k = arr[x];
	long long int temp = (w-y) / x;
	if (k > temp)
	{
		k = temp;
	}
	long long int i = k - 6;
	if (i < 0)
	{
		i = 0;
	}
	while(i <= k)
	{
		dp(x + 1, y + i * x);
		i++;
	}

}

int main()
{
	scanf("%lld", &w);
	ans = 0;
	for (int i = 1; i <= 8; i++)
	{
		scanf("%lld", &arr[i]);
	}
	dp(1, 0);
	printf("%lld", ans);
	return 0;
}


#include <stdio.h>
long long int num[15],w,ans;
void dp(int x, long long int y){
	if(x>8){
		if(y>ans){
			ans = y;
		}
		return;

	}
	long long int k = num[x];
	long long int temp = (w-y)/x;
	if(k>temp){
		k=temp;
	}
	long long int i = k-6;
	if(i<0){
		i=0;
	}
	while(i<=k){
		dp(x+1,y+i*x);
		i++;
	}
}
int main(){
scanf("%lld",&w);
ans = 0;
for (int i=1;i<=8;i++){
	scanf("%lld",&num[i]);
}
dp(1,0);
printf("%lld",ans);
return 0;
}


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

int main()
{
     char s[101];
     int a[205][205] = {0};
     int x = 102, y = 102, i;

     a[x][y] = 1;

     scanf("%s", s);

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

	  switch(s[i]) {
	  case 'L' : x--; break;
	  case 'R' : x++; break;
	  case 'U' : y++; break;
	  case 'D' : y--; break;
	  }

	  if (a[x][y] == 1) {
	       puts("BUG");

	       return 0;
	  }

	  m = a[x - 1][y] + a[x + 1][y] + a[x][y - 1] + a[x][y + 1];

	  if (m > 1) {
	       puts("BUG");

	       return 0;
	  }

	  a[x][y] = 1;
     }

     puts("OK");

     return 0;
}


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

#define L 100
#define N 222

const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

char s[L + 1];
int a[N][N];

int main()
{
  scanf("%s", s);
  int n = strlen(s);
  int x = 101;
  int y = 101;
  memset(a, -1, sizeof(a));
  a[x][y] = 0;
  for (int i = 1; i <= n; i++)
  {
    switch (s[i - 1])
    {
      case 'U': x--; break;
      case 'L': y--; break;
      case 'R': y++; break;
      case 'D': x++; break;
      default: assert(0);
    }
    if (~a[x][y]) {
      puts("BUG");
      return 0;
    }
    a[x][y] = i;
    for (int dir = 0; dir < 4; dir++)
    {
      int nx = x + DX[dir];
      int ny = y + DY[dir];
      if (~a[nx][ny] && a[nx][ny] != i - 1)
      {
        puts("BUG");
        return 0;
      }
    }
  }
  puts("OK");
  return 0;
}


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

int main(){
    int i, j, k, l, m, n;
    char a[201];

    scanf("%s", a);
    scanf("%d", &j);

    n = strlen(a);
    for(i = (n + j) / 2; i >= 1; i--){
        l = 0;
        for(k = 0; k < n + j - i; k++){
            if(k + i < n && a[k] != a[k + i]){
                l = -1;
            }
            l++;
            if(l == i){
                break;
            }
        }
        if(l == i){
            break;
        }
    }
    printf("%d\n", l * 2);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
int main()
{
    char str[2000];
    int i,j,ch,chk,len,k,flag,m;
    scanf("%s",str);
    scanf("%d",&k);
    len=strlen(str);
    if(k>=len)
    {
        if((k+len)%2==0)
        printf("%d",k+len);
        else
        printf("%d",k+len-1);
    }
    else
    {
        //printf("%d %d ",len,k);
        ch=k+len;
        for(i=k+len;i>=2*k;i--)
        {
            if((i)%2)
            continue;
            else
            {
                for(j=0;j+i<=len+k;j++)
                {
                    flag=1;
                    ch=i/2;
                    for(m=j;m<j+ch;m++)
                    {
                        if(m+ch<len)
                        {
                            if(str[m]!=str[m+ch])
                            {
                                flag=0;
                                break;
                            }
                        }
                    }
                    if(flag==1)
                    break;
                }
            }
            if(flag)
            break;
        }
        printf("%d",i);
    }
    return 0;
}


#include <stdio.h>
#define MOD 1000000007
int n,m;
long long ans;
long long f[200010],g[200010];
int main()
{
    int i,j,mn,mx;
    f[0] = 1;
    scanf("%d%d",&n,&m);
    for(i=1;i<=900;i++)
    {
        mn = (1+i)*i/2-m;
        if(mn<0) mn = 0;
        mx = (1+i)*i/2;
        if(mx>n) mx = n;
        if(mn>mx) break;
        for(j=mx;j>=i;j--) f[j] = (f[j]+f[j-i])%MOD;
        for(j=mx;j>=0;j--) g[j] = (g[j+1]+f[j])%MOD;
        if(g[mn]-g[mx+1]) ans = g[mn]-g[mx+1];
        else break;
    }
    printf("%I64d",ans);
    return 0;
}


#include<stdio.h>

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

	if(n%2){		printf("black\n"); return 0;	}
	else {	printf("white\n1 2\n"); return 0;}

	return 0;
}


#include<stdio.h>
int main () {
    int n;
    scanf("%d", &n);
    printf(n & 1? "black\n": "white\n1 2\n");
}


#include <stdio.h>

int main(void) {
    long long n,l,r,ans, i,bit_set;
    int rem[100], temp;
    scanf("%lld %lld %lld", &n,&l,&r);
    if (n < 2) {
        printf("%lld\n", n);
    } else {
        temp = 0;
        while (n > 1) {
            rem[temp++] = n % 2;
            n /= 2;
        }
        ans = 0;
        for (i = l; i <= r; i ++) {
            bit_set = 0;
            while (((i >> bit_set) & 1) != 1) {
                bit_set += 1;
            }
            if (bit_set == 0) {
                ans += 1;
            } else {
                ans += rem[temp-bit_set];
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}


#ifdef ONLINE_JUDGE
    #define NDEBUG 1
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <math.h>

#define long int64_t
#define fore(i,k,n) for (int _k = (k), _n = (n), i = _k; i <= _n; ++i)
#define forr(i,n,k) for (int _k = (k), _n = (n), i = _n; i >= _k; --i)
#define LIST_INIT_CAP 4
#define HASH_INIT_CAP 64
#define HASH_SKIP 11
#define TREE_INIT_CAP 1024
#define TREE_MAX_HEIGHT 64
#define DEQUE_INIT_CAP 1024
#define HEAP_INIT_CAP 1024
#define TAKEN 1
#define EMPTY 0
#define TOMB -1
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))

#define N 204

long arr[N];

long calc(int sz) {
    if (arr[sz] != -1) return arr[sz];
    arr[sz] = 2 * calc(sz-1) + 1;
    return arr[sz];
}

int getval(long n, int sz, long idx) {
    if (n == 0 || n == 1) return (int)n;
    long t = calc(sz - 1);
    if (idx == t + 1) return (n & 1);
    if (idx <= t) return getval((n >> 1), sz - 1, idx);
    else return getval((n >> 1), sz - 1, idx - t - 1);
}

int main() {

    long n, l, r;
    scanf("%I64d %I64d %I64d", &n, &l, &r);
    fore (i, 1, 100) arr[i] = -1;
    arr[0] = 1; arr[1] = 1;
    long t = n;
    int sz = 0;
    while (t > 0) { t = t >> 1; ++sz; }
    int answer = 0;
    for (long i = l; i <= r; ++i) {
        answer += getval(n, sz, i);
    }
    printf("%d", answer);

    return 0;
}


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

printf("%lld",c);

}
return 0;
}


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

int main(void)
{
    int s, x1, x2;
    int t1, t2;
    int p, d;
    int tt, x;

    scanf("%d%d%d", &s, &x1, &x2);
    scanf("%d%d", &t1, &t2);
    scanf("%d%d", &p, &d);
    x = x2 - x1;
    if (t1 >= t2)
        tt = t2 * fabs(x);
    else
    {
        int t_tr, t_ig;
        if (x >= 0 && d == 1)
        {
            if (p <= x1)
            {
                t_tr = (x2 - p) * t1;
                t_ig = x * t2;
                tt = (t_tr < t_ig) ? t_tr : t_ig;
            }
            else
            {
                t_tr = (2 * s - p + x2) * t1;
                t_ig = x * t2;
                tt = (t_tr < t_ig) ? t_tr : t_ig;
            }
        }
        else if (x <= 0 && d == -1)
        {
            if (p >= x1)
            {
                t_tr = -(x2 - p) * t1;
                t_ig = -x * t2;
                tt = (t_tr < t_ig) ? t_tr : t_ig;
            }
            else
            {
                t_tr = (2 * s + p - x2) * t1;
                t_ig = -x * t2;
                tt = (t_tr < t_ig) ? t_tr : t_ig;
            }
        }
        else if (x > 0 && d == -1)
        {
            t_tr = (p + x2) * t1;
            t_ig = x * t2;
            tt = (t_tr < t_ig) ? t_tr : t_ig;
        }
        else
        {
            t_tr = (2 * s - p - x2) * t1;
            t_ig = -x * t2;
            tt = (t_tr < t_ig) ? t_tr : t_ig;
        }
    }
    printf("%d\n", tt);
    return 0;
}


#include<stdio.h>
int main()
{
    int a,b,c,d,i,j,k;
    int s,x1,x2,t1,t2,cur,tr;
    int dist;
    scanf("%d %d %d",&s,&x1,&x2);
    scanf("%d %d",&t1,&t2);
    scanf("%d %d",&cur,&d);
    c=(x1>x2)?(x1-x2)*t2:(x2-x1)*t2;
    if(t2<=t1){
        printf("%d",c);
    }
    else
    {
        dist=(x2-x1);
        if(dist>0&&d>0)
        {
            if(cur>x1){
                tr=(s-cur)+x2+s;
                tr=tr*t1;
            }
            else {
                tr=(x2-cur)*t1;
            }
            (c<tr)?printf("%d",c):printf("%d",tr);
        }
        else if(dist<0&&d<0)
        {
            if(cur<x1){
                tr=cur+s+(s-x2);
                tr=tr*t1;
            }
            else {
                tr=(cur-x2)*t1;
            }
            (c<tr)?printf("%d",c):printf("%d",tr);
        }
        else if(dist<0&&d>0)
        {
            tr=s-cur+s-x2;
            tr=tr*t1;
            (c<tr)?printf("%d",c):printf("%d",tr);
        }
        else if(dist>0&&d<0)
        {
            tr=(cur+x2)*t1;
            (c<tr)?printf("%d",c):printf("%d",tr);
        }
    }
    return 0;
}


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


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


#include <stdio.h>

int main( void ) {
    int a, b, w, x, c;

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

    if ( c <= a )
        puts( "0" );
    else {
        int i;
        int start = b, isMinus[ 1000 ], cycle, sumMinus, gap, cnt;

        cycle = sumMinus = 0;
        do {
            if ( b >= x ) {
                b -= x;
                isMinus[ cycle++ ] = 0;
            } else {
                b += w - x;
                isMinus[ cycle++ ] = 1;
                sumMinus++;
            }
        } while ( b != start );

        cnt = 0;
        for ( gap = ( c - a - 1 ) % ( cycle - sumMinus ) + 1; gap; gap -= !isMinus[ cnt++ ] ) ;

        printf( "%lld\n", 1LL * ( c - a - 1 ) / ( cycle - sumMinus ) * cycle + cnt );
    }

    return 0;
}


#include <stdio.h>

int main( void ) {
    int a, b, w, x, c;

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

    if ( c <= a )
        puts( "0" );
    else {
        int bb = b, isMinus[ 1000 ], cycle, sumMinus, gap, cnt;

        cycle = sumMinus = 0;
        do {
            if ( bb >= x ) {
                bb -= x;
                isMinus[ cycle++ ] = 0;
            } else {
                bb += w - x;
                isMinus[ cycle++ ] = 1;
                sumMinus++;
            }
        } while ( bb != b );

        cnt = 0;
        for ( gap = ( c - a - 1 ) % ( cycle - sumMinus ) + 1; gap; gap -= !isMinus[ cnt++ ] ) ;

        printf( "%lld\n", 1LL * ( c - a - 1 ) / ( cycle - sumMinus ) * cycle + cnt );
    }

    return 0;
}


#include <stdio.h>

int k;

int write(int v)
{
    long long n, p;
    for(n = v, p = k; v / p; p *= k)
        n += v / p;
    return (int) n;
}

int main(int argc, char *argv[])
{
    int n, l, u, m;

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

    l = 1, u = n;
    do
    {
        m = (l + u) / 2;
        if(write(m) >= n && write(m - 1) < n)
        {
            printf("%d\n", m);
            return 0;
        }

        if(write(m) >= n)
            u = m - 1;
        else
            l = m + 1;
    } while(1);

    return 0;
}


#include <stdio.h>

int cal(double v, int k)
{
    int cnt = 0;
    while ( v >= 1 )
    {
        cnt += (int)v;
        v /= k;
    }
    return cnt;
}

int binary_search(int l, int r, int n, int k)
{
    int middle = (l+r)/2;
    if ( cal(middle, k) >= n )
    {
        if ( cal(middle-1, k) < n )
            return middle;
        else
            return binary_search(l, middle, n, k);
    }
    else
    {
        if ( cal(middle+1, k) >= n )
            return middle+1;
        else
            return binary_search(middle, r, n, k);
    }
}

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


#include<stdio.h>

int main(){
	int count=0,max=1,i;
	char t,p;
	p=getchar();
	for (i=0;(t=getchar())!=10;i++){
		if (p==t) {
			max++;
		}
		else {
			if (max%2==0) count++;
			max=1;
		}
		p=t;
	}
	if (max%2==0) count++;
	printf("%d\n",count);
	return 0;
}


#include<stdio.h>
int main(void)
{
	int n;
	int m;
	scanf("%d",&n);
	long long int c=0;
	scanf("%d",&m);
	long long int ans[m];

	for(int i=0;i<m;i++)
	{
		ans[i]=0;
	}
	for(int i=1;i<=m;i++)
	{
		ans[(i*i)%m]++;
	}

	for(int i=0;i<m;i++)
	{
		ans[i]*=n/m;
	}

	for(int i=1;i<=n%m;i++)
	{
		ans[(i*i)%m]++;
	}
	c=ans[0]*ans[0];

	for(int i=1;i<m;i++)
	{
		c+=ans[i]*ans[m-i];
	}
	printf("%lld\n",c);

}


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


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

int power(int i) {
    int s;
	int k;
    s = 1;
    for (k = 0;k < i;k++,s*=10);
	return(s);
}

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


#include<stdio.h>
main()
{int n,inch,feet;
scanf("%d",&n);
feet=n/3;
if(n%3==2)
feet++;
printf("%d %d ",feet/12,feet%12);
return 0;
}


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


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int		main()
{
	int n_cone, i = 0, cont[6];
	scanf("%d", &n_cone);
	int l, r;
	int cnt = 0;
	int	tab[6];
	char *res = "FAIL";
	memset(tab, 0, sizeof(tab));
	while (n_cone > i)
	{
		scanf("%d%d", &l, &r);
		tab[l] = tab[l] + 1;
		tab[r] = tab[r] + 1;
		i++;
	}
	i = 1;
	while (i <= 5)
	{
		if (tab[i] != 2)
			res = "WIN";
		i++;
	}
	printf("%s", res);
	exit(0);
}


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


#include<stdio.h>
int main()
{
    char a[100];
    int i,n;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf(" %c",&a[i]);
    }
    if(a[0]=='S'&&a[n-1]=='F')
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int i,n,x,z=0;
    char a[102];
    scanf("%d",&n);
    for(i=0;i<=n;i++)
    {
    scanf("%c",&a[i]);
    }
    for(i=1;i<n;i++)
    {
        if(a[i]=='S')
        {
            if(a[i]==a[i+1])
            {
                continue;
            }
            else
            {
                z++;
            }
        }
    else if(a[i]=='F')
        {
            if(a[i]==a[i+1])
            {
                continue;
            }
            else
            {
                z--;
            }
        }
    }
    if(z>0)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
    return 0;
}


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

long long int insaneMod(long long int a, long long int mods[19]){
    long long int temp;
    long long int result = 1ll;
    int ct;
    int counter = 0;
    while(a > 0){
        ct = a % 10;
        temp = 1ll;
        for(int ct2 = 1 ; ct2 <= ct ; ct2++){
            temp = temp * mods[counter];
            temp %= 1000000007;
        }
        result *= temp;
        result %= 1000000007;
        a = a / 10;
        counter++;
    }
    return result;
}

long long int modToPower(long long int a , long long int b){
    long long int temp , result;
    int remainders[19];
    remainders[1] = a;
    int ct;
    for(ct = 2 ; ct <= 18 ; ct++){
        long long int temp = remainders[ct - 1];
        int ct2;
        for(ct2 = 1; ct2 <= 9 ; ct2++){
            temp *= remainders[ct - 1];
            temp = temp % (1000000007);
        }
        remainders[ct] = temp;
    }

}

int main(){

    long long int mods[19];
    mods[0]= 2;
    mods[1] = 1024;
    int ct;
    for(ct = 2 ; ct <= 18 ; ct++){
        long long int temp = mods[ct - 1];
        int ct2;
        for(ct2 = 1; ct2 <= 9 ; ct2++){
            temp *= mods[ct - 1];
            temp = temp % (1000000007);
        }
        mods[ct] = temp;
    }

    long long int n, m;
    int k;
    scanf("%lld%lld%d", &n, &m, &k);
    if(k == -1 && n % 2 != m % 2){
        printf("0");
        return 0;
    }else{
        long long int result;
        result = insaneMod(n-1 , mods);
        long long int remainders[19];
        remainders[0] = result;
        int cts;
        for(cts = 1 ; cts <= 18 ; cts++){
            long long int temp = remainders[cts - 1];
            int ct2;
            for(ct2 = 1; ct2 <= 9 ; ct2++){
                temp *= remainders[cts - 1];
                temp = temp % (1000000007);
            }
            remainders[cts] = temp;
        }

        result = insaneMod(m - 1, remainders);
        printf("%lld", result);
        return 0;
    }
}


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

#define MOD 1000000007ULL

static inline uint64_t pow_mod(int64_t a, int64_t pow, int64_t mod) {
    if(pow == 0) return 1;
    while(pow % 2 == 0) { a = (a*a) % mod; pow /= 2; }
    int64_t ret = a; pow /= 2;
    while(pow) {
        a = (a*a) % mod;
        if(pow % 2 != 0) ret = (ret*a) % mod;
        pow /= 2;
    }
    return ret;
}

// lets consider line of len M. To have product to be 1 we need even count of -1, and for -1 odd count of -1
// if we consider first M-1 numbers, disregarding how we pick them we can always "fix" it with the last one
// so count(M) = 2^(M-1)
// similarly for N > 1 rows we can pick N-1 however we want and "fix it" with the last one
// but this is only possible if N,M have same parity
// 2 ^ [(N-1)*(M-1)] = [([2^(N-1)] mod M) ^ (M-1)] mod M

int main() {
    uint64_t N,M; int K; scanf("%"PRIu64 "%"PRIu64 "%d\n", &N,&M,&K);
    if(N % 2 != M % 2 && K == -1) { printf("0\n"); return 0; }
    printf("%"PRIu64 "\n", pow_mod(pow_mod(2,M-1,MOD), N-1,MOD));
    return 0;
}


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

#define K	22
#define N	25000000

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

char bad[N + 1];

int solve1(int n, int p) {
	int a, b, cnt;

	if (n < p)
		return n == 0 ? 0 : 1;
	memset(bad, 0, (n + 1) * sizeof *bad);
	cnt = n;
	for (a = 2; a < p; a++) {
		if (bad[a])
			continue;
		for (b = a; b <= n; b += a)
			if (!bad[b]) {
				bad[b] = 1;
				cnt--;
			}
	}
	return cnt;
}

int solve2(int n, int k) {
	long long ans;
	int b, i;

	ans = 0;
	for (b = 0; b < 1 << k; b++) {
		int m = n, parity = 0;

		for (i = 0; i < k; i++)
			if ((b & 1 << i) != 0) {
				int p = pp[i];

				m /= p;
				parity ^= 1;
			}
		ans += parity == 0 ? m : -m;
	}
	return ans;
}

int prime(int p) {
	int a;

	for (a = 2; a <= p / a; a++)
		if (p % a == 0)
			return 0;
	return 1;
}

int main() {
	int a, b, p, ans, i;

	scanf("%d%d%d", &a, &b, &p);
	if (!prime(p)) {
		printf("0\n");
		return 0;
	}
	i = 0;
	while (i < K && pp[i] < p)
		i++;
	if (i == K)
		ans = solve1(b / p, p) - solve1((a - 1) / p, p);
	else
		ans = solve2(b / p, i) - solve2((a - 1) / p, i);
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
int main()
{
  long long int  a,b,n,i,ans, mod=1000000007;
   a=b=1;
  scanf("%lld",&n);

  for(i=0;i<n;i++){
    a=(a*27)%mod;
    b=(b*7)%mod;
  }

  ans=((a-b)+mod)%mod;

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


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

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

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

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

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

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


#include <stdio.h>
#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[*(int *)a].b-x[*(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>
#include <stdlib.h>
struct ex {int s; int d; int c; int n;};
int cm (const void *A, const void *B){
	return	((struct ex *)A)->d - ((struct ex *)B)->d;
	}
int main (){
int i, j, n, m;
int const MAX = 100;
int ans[100] = {0};
struct ex a[MAX];

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

qsort(a,m,sizeof a[0], cm);
j = 0;
for (i=0;i<n;i++){
	if(ans[i] == m + 1){
		j++;
		continue;
		}
	int k;
	for(k = j; k < m ; k++){
		if (a[k].s <= i + 1 && a[k].c > 0 ){
			ans[i] = a[k].n;
			a[k].c--;
			break;
			}
		}

	}
//check
j = 0;
for (i=0;i<m;i++)
	j += a[i].c;

if (j > 0)
//if(0)
	printf("-1");
else
	for (i = 0; i<n; i++)
		printf("%i ",ans[i]);
printf("\n");
return 0;
}


#include<stdio.h>
int main(){
int t,x;
scanf("%d",&t);
while(t--){
scanf("%d",&x);
int a=x%10-1,r=0,p=1;
while(x){
x=x/10;
r=r+p;
p++;
}
printf("%d\n",a*10+r);
}
return 0;
}


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

int main(){
	int t,n;
	char s[100];
	scanf("%d",&t);

	while(t--){
		scanf("%s",&s);
		int a = s[0]-'0';
		int count = strlen(s);
		printf("%d\n",(a-1)*10+count*(count+1)/2);
	}
	return 0;
}


#include <stdio.h>

int main()
{
    int n,k,i,j,test;
    long long int c;
    scanf("%d",&test);
    for(i=1;i<=test;i++)
    {
        c=1;
        scanf("%d",&n);
        scanf("%d",&k);
        for(j=1;j<=k;j++)
        {
            c=(c*n)%(1000000000+7);
        }
        printf("%lld\n",c);
    }
    return 0;
}


#include <stdio.h>

long long K = 1000000000+7;

int main() {
    long long t, n, k, i, sol, j;
    scanf("%lld", &t);

    for( i = 0; i < t; i++ ){
        scanf("%lld", &n);
        scanf("%lld", &k);
        sol = 1;
        for( j = 0; j < k; j++ )
            sol = (sol*n)%K;
        printf("%lld\n", sol);
    }
}


#include <stdio.h>

int num_len(long long n)
{
	int len = 0;
	while (n && ++len && (n /= 10));
       	return len;
}

int sum_digits(long long n)
{
	int sum = 0;

	while (n) {
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

int main() {
	long long n, a = 0, b = 0;
	long long lenN, sumA, sumB;

	scanf("%lld", &n);

	lenN = num_len(n);

	for (int i = 0; i < lenN - 1; i++) {
		a = a * 10 + 9;
	}

	sumA = 9 * (lenN - 1);
	b = n - a;
	sumB = sum_digits(b);

	printf("%lld", sumA + sumB);

	return 0;
}


#include <stdio.h>
int main() {
    long long n,m,ten,b;
	int k;
	ten = 1;
    scanf("%lld", &n);
     m = n;
    int i;
    for (i = 0; (m /= 10) != 0; i++)
        continue;

    for (k = 0; k < i; k++)
        ten *= 10;

  b = n - ten + 1;
    int sum = 9 * i;
    while (b != 0)
	{
        sum += b % 10;
        b /= 10;
    }
    printf("%d\n", sum);

	return 0;
}


#include<stdio.h>

int main()
{
	char str[10];
	int x;
	int y=8;
	int flag=0;
	char cl;

	while(y--)
	{
		scanf("%s",str);
		cl=str[0];
		for(x=1;x<8;x++)
		{
			if(cl==str[x])
				flag=1;
			cl=str[x];
		}
	}
	if(flag==1)
	printf("NO");
	else
	printf("YES");
	return 0;
}


#include<stdio.h>
int main()
{
    int i,j,k,l,c;
    char arra[8][8];
    c=0;
    for(i=0;i<8;i++){
            scanf("%s",&arra[i]);
        }

    for(i=0;i<8;i++){
        for(j=0;j<7;j++){
            if(arra[i][j]==arra[i][j+1]){
                c=1;
                break;
                }

            }
        if(c==1)break;
        }

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

    return 0;
}


#include<stdio.h>
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int i,sum=0;
	for(i=a;i<=b;i++){
		int d=i;
		while(d!=0){
			int t=d%10;
			if(t==0)
				sum=sum+6;
			if(t==1)
				sum=sum+2;
			if(t==2||t==3||t==5)
				sum=sum+5;
			if(t==4)
			sum=sum+4;
			if(t==6)
			sum=sum+6;
			if(t==7)
				sum=sum+3;
			if(t==8)
			sum+=7;
			if(t==9)
			sum+=6;
			d=d/10;
		}
	}
	printf("%d\n",sum);
}


#include <stdio.h>

int main()
{
    long long int test,n,i,j,sum1,k,m,a,flag=0,count=0,b,c[10]={6,2,5,5,4,5,6,3,7,6},a1,b2;
  scanf("%lld%lld",&a,&b);
  count=0;
  for(i=a;i<=b;i++){
      k=i;
      while(k>0){
          count+=c[k%10];
          k/=10;
      }
  }
   printf("%lld",count);
    return 0;
}


#include<stdio.h>
#include<string.h>
#define ifdot(a)  (str[a]=='d' && str[a+1]=='o' && str[a+2]=='t')
#define ifat(a) 	(str[a]=='a' && str[a+1]=='t')
#define endl puts("");
char str[200];
int main ()
{
	scanf("%s",str);
	int i,len=strlen(str),b=0;
	printf("%c",str[0]);
	for(i=1; i<len; i++)
	{
		if(ifdot(i) && i != len-3)
		{
			printf(".");
			i+=2;
			continue;
		}
		if (!b && ifat(i) && i != len-2)
		{
			printf("@");
			i++;
			b=1;
			continue;
		}
		printf("%c",str[i]);
	}
	endl;
	return 0;
}


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

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

short len[MAX];
char mu[MAX], flag[MAX];
int prime[MAX], dp[MAX], sum[MAX], power[MAX], L[MAX], *divisors[MAX];

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

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

void mobius(){
    mu[1] = 1;
    int i, j, k, p = 0;

    for (i = 2; i < MAX; i++){
        if (!flag[i]) mu[i] = -1, prime[p++] = i;
        for (j = 0; j < p && (k = i * prime[j]) < MAX; j++){

            flag[k] = true;
            if (!(i % prime[j])){
                mu[k] = 0;
                break;
            }
            else mu[k] -= mu[i];
        }
    }
    for (i = 1; i < MAX; i++) sum[i] = sum[i - 1] + mu[i];
}

void generate(){
    mobius();
    int i, j, k, c, d, x;

    len[0] = len[1] = L[0] = L[1] = 1;
    for (i = 4; i < MAX; i++, i++) len[i] = 2;

    for (i = 3; (i * i) < MAX; i += 2){
        if (!len[i]){
            for (j = (i * i), d = i << 1; j < MAX; j += d){
                if (!len[j]) len[j] = i;
            }
        }
    }

    for (i = 2; i < MAX; i++){
        if (!len[i]) L[i] = i;
        else{
            L[i] = len[i];
            x = L[i /len[i]];
            if (x > L[i]) L[i] = x;
        }
    }

    divisors[1] = (int *) malloc(sizeof(int));
    divisors[1][0] = 1, len[1] = 1;

    for (i = 2; i < MAX; i++){
        c = 0, k = i;
        while (k > 1 && L[k] == L[i]){
            c++;
            k /= L[k];
        }

        len[i] = (c + 1) * len[k];
        divisors[i] = (int *) malloc(sizeof(int) * len[i]);

        for (x = 1, j = 0, len[i] = 0; j <= c; j++, x *= L[i]){
            for (d = 0; d < len[k]; d++){
                divisors[i][len[i]++] = divisors[k][d] * x;
            }
        }
    }
}

int count(int n, int m){
    int z, y, x = m;
    long long v, res = 0;

    while (x >= 1){
        y = m / x, z = m / (y + 1);
        v = (long long)power[y] * (sum[x] - sum[z]);
        x = z, res += v;
    }

    res = (res % MOD + MOD) % MOD;
    return res;
}

int solve(int n, int k){
    long long res = 0;
    int i, j, v, m, x, y, z;
    for (i = 0; i < MAX; i++) power[i] = expo(i, n);

    dp[1] = count(n, 1);
    for (m = 2; m <= k; m++){
        res = dp[m - 1];
        for (j = 0; j < len[m]; j++){
            x = 0, y = 0, z = 0;
            x = divisors[m][j], v = m / x;
            y = power[v] * mu[x];
            z = power[v - 1] * mu[x];
            res = res + y - z;
        }
        dp[m] = ((res % MOD) + MOD) % MOD;
    }

    for (m = 1, res = 0; m <= k; m++) res += (m ^ dp[m]);
    return res % MOD;
}

int main(){
    generate();
    int n, k, res;

    while (scanf("%d %d", &n, &k) != EOF){
        printf("%d\n", solve(n, k));
    }
    return 0;
}


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

int main()
{
	char s[11];
	unsigned k, m;
	scanf("%s\n", s);
	scanf("%u\n", &k);

	switch (s[0])
	{
		case 'J':
			if (s[1] == 'a')
				m = 1;
			else
			{
				if (s[2] == 'n')
					m = 6;
				else
					m = 7;
			}
			break;
		case 'F':
			m = 2;
			break;
		case 'M':
			if (s[2] == 'r')
				m = 3;
			else
				m = 5;
			break;
		case 'A':
			if (s[1] == 'p')
				m = 4;
			else
				m = 8;
			break;
		case 'S':
			m = 9;
			break;
		case 'O':
			m = 10;
			break;
		case 'N':
			m = 11;
			break;
		case 'D':
			m = 12;
			break;
	}

	m = (k+m)%12;

	if (k == 0)
		printf("%s\n", s);
	else
	{
	switch (m)
	{
		case 1: printf("January\n"); break;
		case 2: printf("February\n"); break;
		case 3: printf("March\n"); break;
		case 4: printf("April\n"); break;
		case 5: printf("May\n"); break;
		case 6: printf("June\n"); break;
		case 7: printf("July\n"); break;
		case 8: printf("August\n"); break;
		case 9: printf("September\n"); break;
		case 10: printf("October\n"); break;
		case 11: printf("November\n"); break;
		case 0: printf("December\n"); break;
	}
	}
	return 0;
}


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


#include <stdio.h>
#define MAXN 53
#define MAXW 500003
int dp[MAXW]={1};
int n,d,c[MAXN];
int ans,day;

int main()
{
	int i,j,k,sum=0;

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

	ans=day=0;
	while(1)
	{
		i=ans+d;
		if(i>sum)i=sum;
		for(;i>ans;i--)
		{
			//printf("now i %d %d\n",ans,i);
			if(dp[i]==1)break;
		}
		if(i==ans)break;
		ans=i;
		++day;
	}
	printf("%d %d\n",ans,day);
	return 0;
}


#include <stdio.h>

int a[60];
int dp[500100];
int ans[500100];
int main(void)
{
	int n ,d;
	int i ,j;
	int sum;
	int aa;
	int p ,pans;
	int k;

	while (scanf("%d %d" ,&n ,&d)!=EOF)
	{
		sum=0;
		for (i=1 ; i<=n ; i++)
		{
			scanf("%d" ,&a[i]);
			sum+=a[i];
		}
		for (j=1 ; j<=sum ; j++)
		{
			dp[j]=0;
			ans[j]=0;
		}
		dp[0]=1;
		for (i=1 ; i<=n ; i++)
		{
			aa=a[i];
			for (j=sum-aa ; j>=0 ; j--)
			{
				if (dp[j])
				{
					dp[j+aa]=1;
				}
			}
		}
		ans[0]=1;
		p=0;
		pans=2;
		for (i=1 ; i<=sum ; i++)
		{
			if (dp[i])
			{
				k=i-d;
				if (k<=p)
				{
					ans[i]=pans;
				}
				else
				{
					for (j=k ; j<i ; j++)
					{
						if (ans[j])
						{
							ans[i]=ans[j]+1;
							p=j;
							pans=ans[j]+1;
							break;
						}
					}
					if (j==i)
					{
						break;
					}
				}
			}
		}
		for (i=sum ; i ; i--)
		{
			if (ans[i])
			{
				break;
			}
		}
		printf("%d %d\n" ,i ,ans[i]-1);
	}

	return 0;
}


#include<stdio.h>

int main(void)
{
    long long arr[14];
    int i,j;
    for(i=0; i<14; ++i){
        scanf("%lld", &arr[i]);
    }
    long long brr[14];
    long long k=0;
    long long r;
    long long q;
    long long rem,div;
    for(i=0; i<14; ++i){
        if(arr[i]!=0){
            for(j=0; j<14; ++j){
                brr[j]=arr[j];
            }
            q=brr[i];
            brr[i]=0;
            j=i+1;
            while(q>0 && j<14){
                ++brr[j];
                --q;
                ++j;
            }
            div=q/14;
            rem=q%14;
            if(div!=0){
                for(j=0; j<14; ++j){
                    brr[j]+=div;
                }
            }
            for(j=0; j<rem; ++j){
                ++brr[j];
            }
            r=0;
            for(j=0; j<14; ++j){
                if(brr[j]%2==0){
                    r+=brr[j];
                }
            }
            if(r>k){
                k=r;
            }
        }
    }
    printf("%lld", k);
}


#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <float.h>
#include <limits.h>
#include <malloc.h>
#include <memory.h>
#include <complex.h>
#include <errno.h>
#include <time.h>
int i,d[25],f[25],l;
long long a[25],ans;
char s[25];

void dfs(int x)
{
	int i,sum;
	long long res;

	if (x>=10)
	{
		for (i=0,sum=0;i<=9;i++) sum+=d[i];
		res=(long long) a[sum-1]*(sum-d[0]);
		for (i=0;i<=9;i++) res/=a[d[i]];
		ans+=res;
		return;
	}
	if (!f[x]) dfs(x+1);
	else
	{
		for (i=1;i<=f[x];i++)
		{
			d[x]=i;
			dfs(x+1);
		}
	}
}

int main()
{
	memset(f,0,sizeof(f));
	memset(d,0,sizeof(d));
	scanf("%s",s);
	l=strlen(s);
	for (i=ans=0;i<l;i++) f[s[i]-'0']++;
	for (i=1,a[0]=1;i<=20;i++) a[i]=(long long) a[i-1]*i;
	dfs(0);
	printf("%lld\n",ans);
	return 0;
}


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


#include"stdio.h"
int main()
{
  int a,b,c,ans;
  while(scanf("%d%d%d",&a,&b,&c)!=EOF)
  {
    ans=(int)((a*c-b*c)*1.0/(b*1.0)+0.5);
    if(ans*b+c*b>=a*c) ;
    else ans++;
    printf("%d\n",ans);
  }
  return 0;
}


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

int main()
{
    int a,b,c,d, count=0;
    scanf("%d %d %d %d", &a,&b,&c,&d);
    count = 2*(abs(a-c)+abs(b-d)+2);
    if((a==c)||(b==d))
    {
        printf("%d",count+2);
        return 0;
    }
    printf("%d",count);
    return 0;
}


#include<stdio.h>
int ab(int a,int b)
{
	if(a>b)return a-b;
	else return b-a;
}

int main()
{
	int sx,sy,fx,fy;
	scanf("%d %d %d %d",&sx,&sy,&fx,&fy);

	if(sx!=fx && sy!=fy)printf("%d\n",4+2*(ab(sx,fx)+ab(sy,fy)));
	else printf("%d\n",6+2*(ab(sx,fx)+ab(sy,fy)));
	return 0;
}


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

int32_t max(int32_t a, int32_t b);

int main() {
    int32_t h, w;
    int32_t u1, d1;
    int32_t u2, d2;

    scanf("%d%d", &w, &h);
    scanf("%d%d", &u1, &d1);
    scanf("%d%d", &u2, &d2);

    for (int32_t i = h; i > 0; i--) {
        w += i;
        if (i == d1) {
            w = max(0, w - u1);
        } else if (i == d2) {
            w = max(0, w - u2);
        }
    }

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

    return 0;
}

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


#include<stdio.h>
int main()
{
    long long n,k,min;
    scanf("%lld %lld",&n,&k);
    min=n*k+1;
    for(long long i=1,temp;i<k;i++)
    {
        if(!(n%i))
        {
            temp=(n/i)*k+i;
            min=(temp<min)?temp:min;
        }
    }
    printf("%lld",min);
    return 0;
}


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

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

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

	while(1){
			for(x = 0; x < k; x++){
				if(n == x*i) {printf("%d", x + i*k); return 0;}
				//printf("%d\n", div(i,k).quot * div(i,k).rem);
			}
		i++;
	}

	return 0;
}


#include<stdio.h>

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

int main()
{
    int n,a[105],i,sum=0,cnt=0,l=0;
    float avg;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum += a[i];
    }
    qsort(a, n, sizeof(int), comp);
    avg = (float)sum/n;
    while(avg<4.5)
    {
        sum += 5 - a[l++];
        avg = (float)sum/n;
        cnt++;
    }
    printf("%d",cnt);
    return 0;
}


#include <stdio.h>
#include<malloc.h>
#include<stdlib.h>
//int c=0;
/*void display(int *a,float sum,int n)
{
		if(sum/(float)n>=4.5)
printf("%d",c);
	else
	{c++;return display(sum,n);
	}
}*/
int cmp(int *a,int *b)
{
	return *a-*b;
}
int main(void) {
	// your code goes here
	int n,val1,i,c=0;
	float sum=0;
	scanf("%d",&n);
	val1=(n*5)-2;
int *a=(int *)malloc(sizeof(int)*n);
	for( i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	qsort(a,n,sizeof(int),cmp);
	i=0,c=0;
/*	for(int i=0;i<n;i++)
	printf("%d ",a[i]);*/
	while(sum/(float)n<4.5)
	{
	sum=sum+(5-a[i]);
//	printf("%f ",sum);
	c++;
	i++;
	}

	printf("%d ",c);
//display(a,sum,n);
return 0;
}


#include<stdio.h>
#define MAX(x,y) (((x)>(y))?(x):(y))
#define ABS(x) (((x)<0)?(-(x)):(x))

int getagroup(int x,int y,int num);
int getbgroup(int x,int y,int num);

int main(void){
  int a,b,x1,x2,y1,y2;
  int ga1,ga2,gb1,gb2;
  int difa,difb,ans;
  scanf("%d %d %d %d %d %d",&a,&b,&x1,&y1,&x2,&y2);
  ga1=getagroup(x1,y1,a);
  ga2=getagroup(x2,y2,a);
  gb1=getbgroup(x1,y1,b);
  gb2=getbgroup(x2,y2,b);
  difa=ABS(ga1-ga2);
  difb=ABS(gb1-gb2);
  ans=MAX(difa,difb);
  printf("%d\n",MAX(difa,difb));
  return 0;
}

int getagroup(int x,int y,int num){
  int n;
  n=x+y;
  if(n>=0) n/=(2*num);
  else{
    n/=(2*num);
    n--;
  }
  return n;
}

int getbgroup(int x,int y,int num){
  int n;
  n=x-y;
  if(n>=0) n/=(2*num);
  else{
    n/=(2*num);
    n--;
  }
  return n;
}


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

#define ull unsigned long long

ull w, m;
bool solve(void){
	ull cur;
	for (cur=1; cur <= m; cur *= w){
		ull k = m % (cur * w) / cur;
		if (k == 1)
			m = m - cur;
		else if (k == w-1)
			m = m + cur;
		else if (k != 0)
			return false;
	}
	return true;
}

int main(void){
	scanf("%llu %llu", &w, &m);
	if (solve())
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


/*
   Harrit Lamster (s1552295)
   harrit.lamster@gmail.com
   AADS '17-'18, 2018-02-18
   Assignment 2, TABLE
*/

#include <stdio.h>
#define DEBUG 0
#if DEBUG
  #include <assert.h>
#endif

typedef long long ll;

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

void swap(ll *xp, ll *yp) {
  ll h = *xp;
  *xp = *yp;
  *yp = h;
}

ll lessEqualInTable(int n, int m, ll x) {
  ll result = 0;
  ll rightmostColumn = min(x, n);
  ll rightmostFullColumn = min(x, x/m);
  result += rightmostFullColumn * min(x, m);
  for (ll column = rightmostFullColumn + 1; column <= rightmostColumn; column++)
    result += min(x / column, m);
  //printf("%d %d %d %d\n", n, m, x, result);
  return result;
}

ll findKthInList(ll n, ll m, ll k) {
  if (n > m)
    swap(&n, &m);
  if (k == 1)
    return 1;
  ll l = 1, r = n*m, mid;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (lessEqualInTable(n, m, mid) >= k)
      r = mid;
    else
      l = mid;
  }
  return l + 1;
}

#if DEBUG
void assertions() {
  assert(findKthInList(10, 10, 100) == 100);
  assert(findKthInList(10, 10, 99) == 90);
  assert(findKthInList(10, 10, 98) == 90);
  assert(findKthInList(10, 10, 97) == 81);
  assert(findKthInList(4, 7, 4) == 3);
  assert(findKthInList(1, 1, 1) == 1);
  assert(findKthInList(100000, 100000, 10000000000) == 10000000000);
  assert(findKthInList(100000, 100000, 1) == 1);
  assert(findKthInList(100000, 100000, 2) == 2);
  assert(findKthInList(100000, 100000, 3) == 2);
  assert(findKthInList(100000, 100000, 4) == 3);
  assert(findKthInList(100000, 100000, 5) == 3);
  assert(findKthInList(1, 5, 2) == 2);
  assert(findKthInList(5, 1, 2) == 2);
  printf("assertions OK\n");
}
#endif

int main() {
  ll n, m, k;
  #if DEBUG
    assertions();
  #endif
  scanf("%lld %lld %lld", &n, &m, &k);
  printf("%lld\n", findKthInList(n, m, k));
  return 0;
}


#include<stdio.h>
long long c,r,target,t2;
long long cnt(long long n)
{
    long long i,j,num=0;
    for(i=1;i<=c;i++)
    {
        if(n%i==0 && n/i<=r) num++;
    }

    return num;
}
long long table(long long n)
{
    long long count=0,i,j;
    for(i=1;i<=c;i++)
    {

        if(i*r<=n) count+=r;
        else
            count+=n/i;
    }

    return count;
}

int main()
{

    long long low,high,mid,t1,t2,r1;
    scanf("%lld %lld %lld",&r,&c,&target);
    if(target==1) printf("1\n");
    else{
    low=0,high=r*c+1;
    while(low<=high)
    {
        mid=low+(high-low)/2;

        t1=table(mid);
        t2=table(mid-1);
        r1=cnt(mid);

        if(t2<target && (t1-r1)<target && (t1>=target)) { printf("%lld\n",mid); break; }
        else if(t1>=target) {high=mid; }
        else low=mid;
    }
    }

    return 0;
}


#include <stdio.h>

#define MD	1000000007

int power(int n, int k) {
	int p;

	if (k == 0)
		return 1;
	p = power(n, k / 2);
	p = (long long) p * p % MD;
	if (k % 2 == 1)
		p = (long long) p * n % MD;
	return p;
}

int main() {
	int n, m, k, sum, x;

	scanf("%d%d", &n, &m);
	sum = 0;
	for (k = 0; k < n; k++) {
		x = power(m + m - 1, k); /* Binomial theorem */
		sum = (sum + (long long) x * m % MD * power(m, n - 1 - k)) % MD;
	}
	printf("%d\n", (sum + power(m, n)) % MD);
	return 0;
}


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

int calc_moves(int, int, int, int, int, int);
int min(int, int);

int main(){

    int i, j, x, y, n, m, a, b;
    scanf("%d %d %d %d %d %d", &n, &m, &x, &y, &a, &b);

    int sol1 = calc_moves(x, y, 1, 1, a, b);
    int sol2 = calc_moves(x, y, 1, m, a, b);
    int sol3 = calc_moves(x, y, n, 1, a, b);
    int sol4 = calc_moves(x, y, n, m, a, b);

    if (sol1 == -1 && sol2 == -1 && sol3 == -1 && sol4 == -1) {
        printf("Poor Inna and pony!\n");
    }
    else {
        int sol = min(sol1, min(sol2, min(sol3, sol4)));
        if (sol > 0 && ((x - a < 1 && x + a > n) || (y - b < 1 && y + b > m))) {
            printf("Poor Inna and pony!\n");
        }
        else {
            printf("%d\n", sol);
        }
    }

#ifdef _AT_HOME_
    system("pause");
#endif

    return 0;
}

int calc_moves(int start_x, int start_y, int finish_x, int finish_y, int step_x, int step_y) {

    int dx = abs(start_x - finish_x);
    int dy = abs(start_y - finish_y);

    if (dx % step_x != 0 || dy % step_y != 0) {
        return -1;
    }

    int sx = dx / step_x;
    int sy = dy / step_y;

    if (abs(sx - sy) & 1) {
        return -1;
    }
    else {
        return (sx > sy)?sx:sy;
    }

}

int min(int a, int b) {
    if (a == -1 || b == -1) {
        return -a*b;
    }
    else{
        return (a > b)?b:a;
    }
}


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

typedef long long ll;

int main(int argc, char ** argv){

	ll MAX = 823543;
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(n>MAX || m>MAX){
		printf("0\n");
		return 0;
	}
	ll num_dg_hr = 1;
	ll num_dg_min = 1;
	ll x1 = 7*num_dg_hr;
	ll x2 = 7*num_dg_min;
	while((n-1)/x1!=0){
		num_dg_hr++;
		x1*=7;
	}
	while((m-1)/x2!=0){
		num_dg_min++;
		x2*=7;
	}
	if(num_dg_min+num_dg_hr>7){
		printf("0\n");
		return 0;
	}
	ll i,j;
	ll ans = 0;
	for(i=0; i<n*m; i++){
		ll hr = i/m;
		ll min = i%m;
		ll * time = (ll*)calloc(sizeof(ll),(num_dg_min+num_dg_hr));
		for(j=0; j<num_dg_min; j++){
			time[j] = min%7;
			min = min/7;
		}
		for(j=num_dg_min; j<num_dg_min+num_dg_hr; j++){
			time[j] = hr%7;
			hr = hr/7;
		}
		ll * cnt = (ll*)calloc(sizeof(ll),7);
		for(j=0; j<num_dg_min+num_dg_hr; j++){
			cnt[time[j]]++;
		}
		bool flag = true;
		for(j=0; j<7; j++){
			if(cnt[j]>1){
				flag = false;
			}
		}
		if(flag){
			ans++;
		}
	}
	printf("%lld\n",ans);

	return 0;
}


#include <stdio.h>

int check(int a, int b, int c)
{
	int oc[7]={0}, sum=0,flag=0,i=0;

	while(a)
	{
		if(oc[a%7]) {flag=1;break;}
		else oc[a%7]++;
		a/=7;
		sum++;
	}

	while(b&&!flag)
	{
		if(oc[b%7]) {flag=1;break;}
		oc[b%7]++;
		b/=7;
		sum++;
	}

	if(c-sum>1) flag=1;

	if(c-sum>0 && oc[0]==1) flag=1;

	if(flag==1) return 0;

	else return 1;
}

int main(void) {
	int n,m,i=0,a,d=0,ans=0;

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

	a=n-1;
	while(1)
	{
		d++;
		a/=7;
		if(a==0) break;
	}

	a=m-1;
	while(1)
	{
		d++;
		a/=7;
		if(a==0) break;
	}

	if(d>7) printf("0");

	else
	{
		i=0;
		while(i<n)
		{
			int j=0;

			while(j<m)
			{
				ans+=check(i,j,d);
				j++;
			}

			i++;
		}

		printf("%d",ans);
	}

	return 0;
}


#include <stdio.h>

int main(){
    int z,k;
    scanf("%i",&z);
    for(k=0;k<z;k++){
    int n,k,d;
    scanf("%i %i %i",&n,&k,&d);
    int i,j;
    int tab[n];
    for(i=0;i<n;i++)
        scanf("%i",&tab[i]);
    int min=d;

    for(j=0;j<n-d+1;j++){
        int t[d];
        int count=0;
        for(i=j;i<d+j;i++){
            int hb;
            for(hb=0;hb<d;hb++)
                t[i]=0;

            int x=0,verif=0;
            for(x=0;x<count;x++)
            if(tab[i]==t[x])
                verif=1;

            if(verif==0){
                t[count++]=tab[i];
            }
        }
        if(count<min)
            min=count;
    }
    printf("%i\n",min);
    }
}


#include <stdio.h>

char Flag[1000000];
int A[1000000];

int ModExp(int n, int m, int p)
{
    int k = 1;
    n %= p;
    while(m != 1) {
        if(m & 1) {
            k = ((long long)k * n) % p;
        }
        n = ((long long)n * n) % p;
        m >>= 1;
    }
    return ((long long)n * k) % p;
}

int main()
{
    int p, k, i, exp = 0;
    scanf("%d %d", &p, &k);
    if(k == 0) {
        printf("%d\n", ModExp(p, p - 1, 1000000007));
        return 0;
    } else if(k == 1) {
        printf("%d\n", ModExp(p, p, 1000000007));
        return 0;
    }
    for(i = 1; i < p; ++i) {
        A[((long long)i * k) % p] = i;
    }
    for(i = 1; i < p; ++i) {
        if(!Flag[i]) {
            ++exp;
        }
        int j = i;
        while(!Flag[j]) {
            Flag[j] = 1;
            j = A[j];
        }
    }
    printf("%d\n", ModExp(p, exp, 1000000007));
    return 0;
}


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

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

int p, k;
bool visited[1000010];

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

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

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

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

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


#include <stdio.h>
int main(int argc,char** argv){
    int a,b,c,d;
    int delta;
    float q;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    delta = b -a;
    if( (c-b) == delta && (d - c) == delta)
    {
        printf("%d\n",d+delta);
    }
    else
    {
        q = b/(float)a;
        if(q!= 0 && q!=1 && c/(float)b == q && d/(float)c == q){
            a = (int)((float)d*q*10) ;
            b = ((int)(d *q)) *10;
            if(a == b)
                printf("%d\n",(int)((float)d*q));
            else
                printf("42\n");
        }else{
            printf("42\n");
        }
    }
    return 0;
}


#include<stdio.h>
int main()
{
int n,i,k;
float j;
float arr[4];

for(i=0 ; i<4 ; i++)
	scanf("%f" , &arr[i]);

if(arr[1]-arr[0]==arr[2]-arr[1] && arr[2]-arr[1]==arr[3]-arr[2])
{
	j =arr[3]+arr[1]-arr[0];
	k=j;
	if(j==k)
	printf("%d",k);
	else
	printf("42");
}

else if(arr[1]/arr[0]==arr[2]/arr[1] && arr[2]/arr[1]==arr[3]/arr[2])
{
	j = arr[3]*(arr[1]/arr[0]);
	k =j;
	if(j == k)
	printf("%d" , k);
	else
	printf("42");
}
else
	printf("42");

return 0;
}


#include <stdio.h>
#define MAX_SIZE(X) ((unsigned short)(X))
void MSA(short, short, unsigned short*);
void Merge(short, short, short, unsigned short*);
int main()
{
    unsigned short Seq[MAX_SIZE(1e2)], Cut[MAX_SIZE(1e2)], n, b, i, j = 0, Odd = 0, Even = 0, max = 0, Sum = 0;
    scanf("%hu%hu", &n, &b);
    for(i = 0; i < n; i++){ scanf("%hu", Seq + i); }
    for(i = 0; i < n - 2; i++){
        if(Seq[i] % 2 == 0){ Even++; }
        else{ Odd++; }
        if(Odd == Even){ Cut[j++] = Seq[i] > Seq[1 + i] ? Seq[i] - Seq[1 + i] : Seq[1 + i] - Seq[i]; }
    }
    MSA(0, j - 1, Cut);
    for(i = 0; i < j; i++){
        Sum += Cut[i];
        if(Sum > b){ break; }
        max++;
    }
    printf("%hu", max);

    return 0;
}
void MSA(short l, short r, unsigned short* A){
    if(l < r){
        unsigned short m = (l + r) / 2;
        MSA(l, m, A);
        MSA(1 + m, r, A);
        Merge(l, m, r, A);
    }
}
void Merge(short l, short m, short r, unsigned short* A){
    unsigned short s1 = m - l + 1, s2 = r - m, i, j;
    unsigned short A1[s1], A2[s2];
    for(i = 0; i < s1; i++){ A1[i] = A[i + l]; }
    for(j = 0; j < s2; j++){ A2[j] = A[j + m + 1]; }
    i = 0, j = 0;
    while(i < s1 && j < s2){ A[l++] = A1[i] < A2[j] ? A1[i++] : A2[j++]; }
    while(i < s1){ A[l++] = A1[i++]; }
    while(j < s2){ A[l++] = A2[j++]; }

}


#include <stdio.h>
#define INF ~0ULL
#define ULL unsigned long long
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>
typedef long long LL;
#define debug(i) printf("->%d\n",i)

LL min(LL a,LL b){
    if(a>b)return b;
    else return a;
}

LL pri[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
    //为什么就算是1e18也只需要这些数就够了呢? 因为越往后,前面的次方就越多
LL ans,n;
void dfs(LL Y,LL dep,LL num){
        //因子数 深度 当前的数
    if(dep==16)return;
    if(Y==n)ans=min(ans,num);
    if(Y>=n)return;
    for(int i=1;i<=63;i++){
        if(ans/pri[dep]<num)break;
            //之前的答案更优,且可以避免爆long long
        dfs(Y*(i+1),dep+1,num*=pri[dep]);
            //pri^i比pri^(i-1)多一个pri,所以每次乘一个pri
    }
}

int main(){
    while(scanf("%lld",&n)==1){
        ans=2e18;
        dfs(1,0,1);
        printf("%lld\n",ans);
    }
}


#include<stdio.h>
int zuida(int a)
{
    int t11;
    for(t11=a-1;t11>=1;t11--)
    {
        if(a%t11==0)
            break;
    }
    return t11;
}
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int zhong1;
    int zhong2;
    int t1;
    int out[20],ppp=1;
    zhong2=n;
    for(t1=0;;t1++)
    {
        zhong1=zuida(zhong2);
        //printf("%d:%d ",t1,zhong1);
        if(zhong1==1)
            break;
        else
            zhong2=zhong1;
    }
    //printf("%d\n",t1+1);
    if(t1+1>=k)
    {
        zhong2=n;
        for(t1=0;t1<k-1;t1++)
        {
            zhong1=zuida(zhong2);
            ppp*=zhong2/zhong1;
            out[t1]=zhong2/zhong1;
            zhong2=zhong1;
            //printf("%d:%d:::%d ",t1,ppp,out[t1]);
        }
        out[k-1]=n/ppp;
        for(t1=0;t1<k;t1++)
        {
             printf("%d ",out[t1]);
        }
    }
        else
        printf("-1");
}


#include <stdio.h>

int main(int argc, const char * argv[]) {

    int k = 0, n = 0, i = 1, arr[20], temp = 0;

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

    temp = k;

line:

    if(n%2 == 0) {

        if(k == 1){

            while(temp > 1){
                printf("%d ", arr[temp]);

                temp--;
            }

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

        n/=2 ;
        arr[k] = 2;
        --k;

        goto line;
    }else{

        for(i = 3; i <= n; i += 2){

            if(n%i == 0){

                arr[k] = i;
                k--;

                if(k == 0) break;
                n/=i;
                i-=2;

            }

        }

    }
    if(k == 0){

        while(temp > 1){
            printf("%d ", arr[temp]);

            temp--;
        }

        printf("%d", n);

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


#include<stdio.h>
int main()
{
	int t, s, q, count = 0;
	scanf("%d%d%d",&t, &s, &q);
	while(s < t)
	{
		count++;
		s *= q;
	}
	printf("%d\n", count);
	return 0;
}


#include <stdio.h>

int main()
{
	long duration, downloaded, q, counter = 0;
	scanf("%ld %ld %ld", &duration, &downloaded, &q);
	while (downloaded < duration)
	{
		counter++;
		downloaded += (q-1)*downloaded;
	}
	printf("%ld\n", counter);
	return 0;
}


#include<stdio.h>
int main()
{
	long long a, b, c, n;

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

//	if(a==0&&b!=0)
//	{
//		printf("%d",b%10);
//		return 0;
//	}

	if(a==0&&b==0||a==b)
	{
		printf("1");
	}
	else if (b-a >= 10)
	{
		printf("0");
	}
	else
	{
		c=1;
		for(long long i=b;i>a;i--){
			c=c*i;
			c=c%10;
		}

		//n=c%10;
		printf("%lld",c);
	}

	return 0;

}


#include<stdio.h>
#include<math.h>
int fact(unsigned long long x,unsigned long long y){
	int z = 1;
	unsigned long long i = x+1;
	while(i <= y && z != 0){
		z = (z*i)%10;
		i++;
	}
	return z;
}
int main(){
	unsigned long long x, y; scanf("%llu%llu", &x, &y);
	//if(x == 0) printf("%d", y%10);
  printf("%d", fact(x, y));
	return 0;
}


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

#define ll long long

const ll M = 1000000007;

ll inv(ll a, ll M)
{
   if (a < 0)
       a = (a + (1+(0-a)/M)*M)%M;
   ll M_o = M;
   ll ac0 = 1;
   ll ac1 = 0;
   ll bc0 = 0;
   ll bc1 = 1;
   ll q;
   ll r;
   ll temp;
   while (M > 0)
   {
       q = a/M;
       r = a%M;
       a = M;
       M = r;

       temp = ac0;
       ac0 = bc0;
       bc0 = temp - q*bc0;

       temp = ac1;
       ac1 = bc1;
       bc1 = temp - q*bc1;
   }
   M = M_o;
   if (ac0 > 0)
       return ac0%M;
   else
       return (ac0 + M*(1+(0-ac0)/M))%M;
}

ll expmod(ll a, ll x, ll m)
{
    ll ans = 1;
    while (x > 0)
    {
        if (x%2 == 1)
            ans = ans*a%m;
        a = a*a%m;
        x /= 2;
    }
    if (ans > 0)
        return ans%M;
    else
        return (ans + M*(1 + (0-ans)/M))%M;
}

int main()
{
    int n, m;
    int ai, bi;
    int ki;

    fscanf(stdin, "%d %d\n", &n, &m);
    fscanf(stdin, "%d %d\n", &ai, &bi);
    fscanf(stdin, "%d", &ki);

    ll a = (ll) ai;
    ll b = (ll) bi;
    ll k = (ll) ki;

    ll p = a*inv(b, M)%M;

    ll* kchoose = malloc((m+1)*sizeof(ll));
    kchoose[0] = 1;
    for (int l = 1; l < m+1; l++)
        kchoose[l] = (kchoose[l-1]*(k-l+1)%M)*inv(l,M)%M;

    ll* expmodp = malloc((m+1)*sizeof(ll));
    ll* expmod1pkminus = malloc((m+1)*sizeof(ll));
    expmodp[0] = 1;
    expmod1pkminus[0] = expmod(1-p, k, M);
    ll inv1p = p!=1? inv(1-p, M):1;

    for (int x = 1; x < m+1; x++)
    {
        expmodp[x] = p*expmodp[x-1]%M;
        if (p != 1)
            expmod1pkminus[x] = inv1p*expmod1pkminus[x-1]%M;
        else
            expmod1pkminus[x] = x<k? 0:1;
    }

    ll* p_left = malloc((m+1)*sizeof(ll));
    for (int l = 0; l < m+1; l++)
    {
        if (l > k)
            p_left[l] = 0;
        else
            p_left[l] = (((kchoose[l]*expmodp[l])%M)*expmod1pkminus[l])%M;
    }

    ll* egs1 = malloc((m+1)*sizeof(ll));
    ll* egs2 = malloc((m+1)*sizeof(ll));
    ll* sle1 = malloc((m+1)*sizeof(ll));
    ll* sle2 = malloc((m+1)*sizeof(ll));

    ll* R = malloc(m*sizeof(ll));
    ll* T = malloc((m+1)*sizeof(ll));
    T[m] = 1;
    for (int i = 0; i < m; i++)
    {
        R[i] = 1;
        T[i] = 0;
    }

    ll* Tp_left = malloc(m*sizeof(ll));
    ll* Rp_left = malloc(m*sizeof(ll));

    for (int ni = 0; ni < n; ni++)
    {
        egs1[m] = 0;
        egs2[m] = 0;

        for (int i = 0; i < m; i++)
            Rp_left[i] = R[i]*p_left[m-(i+1)]%M;

        for (int s = m-1; s >= 0; s--)
        {
            egs1[s] = (egs1[s+1] + Rp_left[s])%M;
            egs2[s] = (egs2[s+1] + p_left[m-(s+1)])%M;
        }

        sle1[0] = 0;
        sle2[0] = 0;

        for (int i = 0; i < m; i++)
            Tp_left[i] = T[i]*p_left[i]%M;

        for (int e = 1; e < m+1; e++)
        {
            sle1[e] = (sle1[e-1] + p_left[e-1])%M;
            sle2[e] = (sle2[e-1] + Tp_left[e-1])%M;
        }

        R[0] = (p_left[0]*egs1[0]%M - Tp_left[0]*egs2[0]%M + M)%M;
        for (int s = 1; s < m; s++)
            R[s] = (R[s-1] + p_left[s]*egs1[s]%M - Tp_left[s]*egs2[s]%M + M) % M;

        T[0] = 0;
        for (int e = 1; e < m+1; e++)
            T[e] = (T[e-1] + Rp_left[e-1]*sle1[e]%M - p_left[m-e]*sle2[e]%M + M)%M;
    }

    printf("%lld\n", T[m]);
}


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

typedef int64_t i64;
typedef int32_t i32;

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

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

i64 gcd (i64 a, i64 b) {
  i64 r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

void run (void) {
  const i32 n = read_int();
  const i32 k = read_int();
  const i32 a = read_int();
  const i32 b = read_int();
  const i64 m = (i64) n * k;
  i64 min = (i64) n * k;
  i64 max = 1;
  for (i32 i = 0; i < 4; ++i) {
    const i32 s = i >= 2 ? a : (k - a) % k;
    for (i32 j = 0; j < 4; ++j) {
      i32 t = (j & 1) ? (k - b) % k : b;
      if (t <= s) {
	i64 d = m - (s - t);
	i64 v = m / gcd (d, m);
	min = MIN(min, v);
	max = MAX(max, v);
	t += k;
      }
      for (i64 l = t; l < m; l += k) {
	i64 d = l - s;
	i64 v = m / gcd (d, m);
	min = MIN(min, v);
	max = MAX(max, v);
      }
    }
  }
  print_int (min);
  putchar(' ');
  print_int (max);
  puts("");
}

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


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

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

int main(){
	int n, k, a, b, i, stp[4];
	int64_t min_t, max_t, dis, t, l;

	min_t = INT64_MAX, max_t = INT64_MIN;

	scanf("%d%d%d%d", &n, &k, &a, &b);
	dis = (int64_t)n * k;
	stp[0] = a-b, stp[1] = b-a, stp[2] = a+b, stp[3] = k-a-b;

	for(i = 0; i < 4; i++){
		for(l = stp[i]; l <= dis; l += k){
			if(l <= 0)
				continue;
			t = dis / gcd(dis, l);
			min_t = min_t<t? min_t: t;
			max_t = max_t>t? max_t: t;
		}
	}

	printf("%" PRIi64 " %" PRIi64 "\n", min_t, max_t);

	return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
	int q,w,e,r;
	scanf("%d%d%d%d",&q,&w,&e,&r);
	if(q!=r) printf("0");
	else if (q==0&&e!=0) printf("0");
	else printf("1");
}