#include<stdio.h>
#define mod 1000000007
typedef long long int ll;
ll expo(ll x,ll k)
{
	ll result=1;
	while(k>0)
	{
		if(k%2==1)
			result=result*x%mod;
		x=x*x%mod;
		k=k/2;
	}
	return result;
}
int main()
{
	long long int x,k,ans;
	scanf("%lld%lld",&x,&k);
	if(x==0)
		return 0;
	x=x%mod;
	x=(2*x-1)%mod;
	k=expo(2,k);
	printf("%lld\n",(x*k+1)%mod);
	return 0;
}


#include <stdio.h>

#define MOD 1000000007

long long int modexp(long long int b, long long int e) {
	long long int i = 1;
	while (e != 0) {
		if (e&1) {
			i = (i*b) % MOD;
		}
		e >>= 1;
		b = (b*b) % MOD;
	}
	return i;
}

int main(void) {
	long long int x, k;
	scanf("%lld%lld", &x, &k);
	x %= MOD;

	long long int exp = modexp(2, k);
	long long int ans = (x * exp * 2) % MOD;
	ans = (ans-exp+1) % MOD;

	if (ans < 0) {
		ans += MOD;
	}
	printf("%lld\n", ans);
}


#include <stdio.h>

#define MOD 1000000007

long long int modexp(long long int b, long long int e) {
	long long int i = 1;
	while (e != 0) {
		if (e&1) {
			i = (i*b) % MOD;
		}
		e >>= 1;
		b = (b*b) % MOD;
	}
	return i;
}

int main(void) {
	long long int x, k;
	scanf("%lld%lld", &x, &k);
	x %= MOD;

	if (x == 0) {
		printf("%lld\n", x);
	}

	long long int exp = modexp(2, k);
	long long int ans = (x * exp * 2) % MOD;
	ans = (ans-exp+1) % MOD;

	if (ans < 0) {
		ans += MOD;
	}
	printf("%lld\n", ans);
}


#include<stdio.h>
#define ll long long
#define MOD 1000000007
ll g_pow(ll k)
{
	ll x=2,e=1;
	while(k)
	{
		if(k%2)
		{
			e*=x;
			e%=MOD;
		}
		k/=2;
		x*=x;
		x%=MOD;
	}
	return e;
}
int main()
{
	ll x,k,res;
	scanf("%I64d%I64d",&x,&k);
	x%=MOD;
	if(x==0)
	{
		printf("0");
		return 0;
	}
	if(k==0)
	{
		res=2*x;
		if(res>MOD)
			res%=MOD;
		printf("%I64d",res);
		return 0;
	}
	res=g_pow(k+1)*x-g_pow(k)+1+MOD;
	if(res>MOD)
		res%=MOD;
	printf("%I64d",res);
	return 0;
}


#include<stdio.h>
#define MOD 1000000007
unsigned long long int power(unsigned long long int x, unsigned long long int y, long int p)
{
    unsigned long long int res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
int main()
{
    unsigned long long int x,k,a,b,c,d;
    scanf("%llu %llu",&x,&k);
    if(x==0)
    {
        printf("0");
    }
    else
    {
        if(k==0)
        {
            printf("%llu",2*x);
        }
        else
        {
            a=power(2,k+1,MOD);
            a=(a*(x%MOD))%MOD;
            d=power(2,k,MOD);
            d=(d-1)%MOD;
            printf("%llu",a-d);
        }
    }
}


#include<stdio.h>
int main()
{
    int t,white,black,opposite;
        scanf("%d%d",&black,&white);
        //Minimum of both ball goes to Aaquib's Points and remaining will make pair with Prashant as both play equally good
        opposite=black<white?black:white;
        printf("%d %d\n",black+white-1-opposite,opposite);
    return 0;
}


#include<stdio.h>
main(){
	long int n,m;
	scanf("%ld%ld",&n,&m);//n-->red m-->blue cubes
	if(n>m){
		printf("%ld %ld",n-1,m);
	}else{
		printf("%ld %ld",m-1,n);
	}
}


main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n>m)     printf("%d %d\n",n-1,m);
    else    printf("%d %d\n",m-1,n);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    longi,flag=0;
    char s[100];
    scanf("%s",s);
    if(strlen<3)
        printf("No");
    else{
    for(i=0;i<strlen(s)-2;i++)
    {
        if(s[i]+s[i+1]+s[i+2]==198)
            {
             flag=1;
             break;
            }
        else
            flag=0;
    }
    if(flag==1)
        printf("Yes");
    else
        printf("No");

}
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    long i,flag=0;
    char s[100];
    scanf("%s",s);
    for(i=0;i<strlen(s);i++)
    {
        if(s[i]=='.')
            s[i]=' '
    }
    if(strlen(s)<3)
        printf("No");
    else{
    for(i=0;i<strlen(s)-2;i++)
    {
        if(s[i]+s[i+1]+s[i+2]==198)
            {
             flag=1;
             break;
            }
        else
            flag=0;
    }
    if(flag==1)
        printf("Yes");
    else
        printf("No");

}
}


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


#include<stdio.h>
#include<math.h>
int main()
{
	int i,n,k,j=0;
	scanf("%d %d",&n,&k);
	int n1=n;
	int a[n];
	for(i=2;i<=sqrt(n);i++){
		while(n%i==0){
			a[j]=i;
		//	printf("%d ",a[j]);
			n/=i;j++;
		}
	}
		if(n>1){
			a[j]=n;
			//printf("%d ",a[j]);
			n/=i;j++;
		}
	//printf("\n%d\n",j);
	if(k>j){
		printf("-1\n");return 0;
	}
    int prod=1;
	for(i=0;i<k-1;i++){
		printf("%d ",a[i]);
		prod*=a[i];

	}
printf("%d ",n1/prod);
	return 0;
}


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

int *k_Factorization(int k,int n,int try);
void swap(int* product,int try);

int main(){
	long int i,k,n;
	long int *result;
	scanf("%d %d",&n,&k);
	if(k==2){
		printf("%d %d",2,n/2);
		return 0;
	}
	result=k_Factorization(k,n,0);
	if(result == NULL){
		printf("%d\n",-1);
		return 0;
	}

	for(i=0;i<k;i++){
		printf("%d ", *++result);
	}
	return 0;
}

int *k_Factorization(int k,int n,int try){
	long int i,*product,*p;
	product=malloc((k+1)*sizeof(int));
	p=product;
	*p++=n;
	for(i=2;i<=*product/2+1;i++){
		if(try==k && n==1){
							return product;}
		if(try==k && n>1){n*=*product; swap(product,try); try--; p--; }
		if(try<=k && n<1){break;}
		while(n%i==0){
			*p++=i;
			n/=i;
			try++;
		}}
	return NULL;

}

void swap(int* product,int try){
	long int i,*p;
	p=product+1;
	for(i=0;i<try;i++,p++){
		int tmp;
		tmp=*p;
		*p=*(p+1);
		*(p+1)=tmp;
	}
}


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


#include<stdio.h>
#include<string.h>
char input[10000000],real[100000],point[10000];
int main()
{
    int p,q,l,x,max,z,t,c,d,m;
    scanf("%s",input);
    max=strlen(input);
    int i,j,k;
    z=0;
    c=0;
    t=0;
    d=0;
    l=0;
    for(i=0;i<max;i++)
    {
        if(input[i]=='.')
        {
            z=1;

        }
        else if(input[i]=='e')
        {
            t=1;
        }
        else if(input[i]!='.'&&z==0)
        {
            real[c]=input[i];
            c++;
        }
        else if(input[i]!='e'&&z==1&&t==0)
        {
            point[d]=input[i];
            d++;
        }
        else
        {
            l=(input[i]-'0')+l*10;;
        }

    }
    real[c]='\0';
    point[d]='\0';
    p=atoi(real);
    printf("%d",p);
    int l1=strlen(point);
    for(i=0;i<l1;i++)
    {
        if(i==l)
        {
            printf(".%d",(point[i]-'0'));
        }
        else
            printf("%d",(point[i]-'0'));
    }
    if(l1<l)
    {
        for(i=l1+1;i<=l;i++)
        {
            printf("0");
        }
    }
    printf("\n");

        return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef signed char byte;
#define REPEAT(token, num) for (token = 0; token < num; token++)
static inline void POPQUEUE(void *arr, size_t length, size_t itemSize) { memmove(arr, arr+itemSize, length*itemSize); }
static inline void REMOVEELEM(void *arr, size_t offset, size_t length, size_t itemSize) { memmove(arr+(offset*itemSize), arr+((offset+1)*itemSize), (length-offset)*itemSize); }
static inline void REMOVEELEMS(void *arr, size_t offset, size_t numElems, size_t length, size_t itemSize) { memmove(arr+(offset*itemSize), arr+((offset+numElems)*itemSize), (length-offset)*itemSize); }
//#define DEBUG
#ifdef DEBUG
#define PRINTF printf
#else
#define PRINTF(...)
#endif

typedef long digit;
typedef long num_digits;

digit allDigits[200];
num_digits decimalPoint = 1, oldNumDigits, numDigits, numChars, power;
char string[200];

int main() {
    num_digits i;
    char store;

    allDigits[0] = getchar()-'0', numDigits = 1;
    getchar(); //period
    while ((store = getchar()) != 'e') allDigits[numDigits++] = store-'0';
    scanf("%li", &power);
    decimalPoint += power;
    oldNumDigits = numDigits;
    REPEAT(i, decimalPoint-oldNumDigits) allDigits[numDigits++] = 0;
    if (decimalPoint == numDigits) numChars = numDigits;
    else numChars = numDigits+1;
    REPEAT(i, numChars) {
        if (i == decimalPoint) putchar('.');
        else putchar(allDigits[i-(i > decimalPoint)]+'0');
    }
    putchar('\n');

    exit(0);
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef signed char byte;
#define REPEAT(token, num) for (token = 0; token < num; token++)
#define getchar getchar_unlocked
#define putchar putchar_unlocked
static inline void POPQUEUE(void *arr, size_t length, size_t itemSize) { memmove(arr, arr+itemSize, length*itemSize); }
static inline void REMOVEELEM(void *arr, size_t offset, size_t length, size_t itemSize) { memmove(arr+(offset*itemSize), arr+((offset+1)*itemSize), (length-offset)*itemSize); }
static inline void REMOVEELEMS(void *arr, size_t offset, size_t numElems, size_t length, size_t itemSize) { memmove(arr+(offset*itemSize), arr+((offset+numElems)*itemSize), (length-offset)*itemSize); }
//#define DEBUG
#ifdef DEBUG
#define PRINTF printf
#else
#define PRINTF(...)
#endif

typedef long digit;
typedef long num_digits;

digit allDigits[200];
num_digits decimalPoint = 1, oldNumDigits, numDigits, numChars, power;
char string[200];

int main() {
    num_digits i;
    char store;

    allDigits[0] = getchar()-'0', numDigits = 1;
    getchar(); //period
    while ((store = getchar()) != 'e') allDigits[numDigits++] = store-'0';
    scanf("%li", &power);
    decimalPoint += power;
    oldNumDigits = numDigits;
    REPEAT(i, decimalPoint-oldNumDigits) allDigits[numDigits++] = 0;
    if (decimalPoint == numDigits) numChars = numDigits;
    else numChars = numDigits+1;
    REPEAT(i, numChars) {
        if (i == decimalPoint) putchar('.');
        else putchar(allDigits[i-(i > decimalPoint)]+'0');
    }
    putchar('\n');

    exit(0);
}


/* https://codeforces.com/contest/1204/submission/59190290 (Dukkha) */
#include <stdio.h>
#include <string.h>

#define N 100

int main() {
	static char s[N + 1];
	int n, i, zero;

	scanf("%s", s);
	n = strlen(s);
	zero = 1;
	for (i = 1; i < n; i++)
		if (s[i] != '0') {
			zero = 0;
			break;
		}
	cnt = (n - 1) / 2 + 1;
	if (n % 2 != 0 && zero)
		cnt--;
	printf("%d\n", cnt);
	return 0;
}


/* https://codeforces.com/contest/1204/submission/59190290 (Dukkha) */
#include <stdio.h>
#include <string.h>

#define N 100

int main() {
	static char s[N + 1];
	int n, i, zero;

	scanf("%s", s);
	n = strlen(s);
	zero = 1;
	for (i = 1; i < n; i++)
		if (cc[i] != '0') {
			zero = 0;
			break;
		}
	cnt = (n - 1) / 2 + 1;
	if (n % 2 != 0 && zero)
		cnt--;
	printf("%d\n", cnt);
	return 0;
}


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

int main(void)
{
    char *binary = malloc(sizeof(char) * 200);
    scanf("%s", binary);

    int lenb = strlen(binary);
    __int128 decimal = 0;
    for (int i = 0; i < lenb; i++)
    {
        decimal += (binary[i] - '0') * pow(2, (lenb-1) - i);
    }

    for (int i = 0; i < 50; i++)
    {
        if (decimal <= pow(4, i))
        {
            printf("%i\n", i);
            break;
        }
    }

    free(binary);
}


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

#define max 20

void sort(char[], int, int);
void merge(char[], int, int, int);

void swap(char[], int, int);

int main()
{
	char a[max], b[max];

	scanf("%[^\n]%*c%[^\n]%*c", a, b);

	int la = strlen(a), lb = strlen(b);

	sort(a, 0, la - 1);

	if(la < lb)
	{
		puts(a);
		return 1;
	}

	int n = la;
	char s[n + 1];
	s[n] = 0;

	for(int i = 0; i < n; i++)
	{
		int j = i;
		while(a[j] > b[i])
			j++;

		if(a[j] < b[i])
		{
			swap(a, i, j);

			sort(a, i + 1, n - 1);
			puts(a);

			return 2;
		}
		else
		{
			for(int k = 0; k < i; k++)
				s[k] = a[k];

			s[i] = a[j], s[j] = a[i];

			for(int k = n - 1; k > i; k--)
			{
				if(k != j)
					s[(n - 1) - k + (i + 1)] = a[k];
			}

			if(strcmp(s, b) < 0)
				swap(a, i, j);
			else
			{
				while(a[j] == b[i])
					j++;

				swap(a, i, j);

				sort(a, i + 1, n - 1);
				puts(a);

				return 3;
			}
		}
		sort(a, i + 1, n - 1);
	}

	puts(a);
}

void swap(char a[], int i, int j)
{
	int temp = a[i];
	a[i] = a[j];
	a[j] = temp;
}

void sort(char a[], int p, int r)
{
	if(p < r)
	{
		int q = (p + r) / 2;

		sort(a, p, q);
		sort(a, q + 1, r);

		merge(a, p, q, r);
	}
}

void merge(char a[], int p, int q, int r)
{
	int l1 = q - p + 1, l2 = r - q;
	char b[l1 + 1], c[l2 + 1];

	for(int i = 0; i < l1; i++)
		b[i] = a[p + i];
	for(int j = 0; j < l2; j++)
		c[j] = a[q + 1 + j];

	b[l1] = c[l2] = '0' - 1;

	int i = 0, j = 0;

	for(int k = p; k <= r; k++)
	{
		if(b[i] > c[j])
		{
			a[k] = b[i];
			i++;
		}
		else
		{
			a[k] = c[j];
			j++;
		}
	}
}


//Code by 27.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>
#include<memory.h>
#include<sstream>
#include<time.h>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const int MOD=19260817;
bool f[20];
string st1,st2;
string mn="";
bool cmp(char &a,char &b)
{
	return a>b;
}
int ypa(int k,string st)
{
	//cout<<k<<" "<<st<<endl;
	if(st<mn)return 0;
	if(k==st1.size())
	{
		mn=st;
		return 0;
	}
	for(int i=0;i<st1.size();i++)
	{
		if(!f[i]&&st+st1[i]<=st2)
		{
			f[i]=1;
			ypa(k+1,st+st1[i]);
			f[i]=0;
		}
	}
}
int main()
{
	cin>>st1>>st2;
	if(st1.size()<st2.size())
	{
		sort(st1.begin(),st1.end(),cmp);
		cout<<st1;
		return 0;
	}
	sort(st1.begin(),st1.end(),cmp);
	ypa(0,"");
	cout<<mn;
	return 0;
}


#include <stdio.h>
unsigned __int64 ipow(unsigned long long int base, unsigned __int64 exp)
{
	unsigned __int64 result = 1ULL;
	while (exp)
	{
		if (exp & 1)
		{
			result *= base;
		}
		exp >>= 1;
		base *= base;
	}
	return result;
}
int main()
{
	unsigned __int64 b = 0, a_length = 0, b_length = 0;
	char temp;
	static unsigned __int64 freq[10];
	while (scanf_s("%c", &temp, 1))
	{
		if (temp == 10)
			break;
		freq[temp - '0'] ++;
		a_length++;
	}
	while (scanf_s("%c", &temp, 1))
	{
		if (temp == 10)
			break;
		b += (unsigned __int64)(temp - '0') * ipow(10, b_length);
		b_length++;
	}
	if (b_length > a_length)
		b = ipow(10, a_length) - 1;
	int flag = 0;
	int flag2 = 0;
	unsigned __int64 num = 0;
	int first = -1;
	int second = -1;
	do
	{
		flag2 = 0;
		if (first == -1)
		{
			first = b % 10;
			continue;
		}
		else if (second == -1)
			second = b % 10;
		for (int i = 9; i >= 0; i--)
		{
			if ((flag == 1 || i <= first) && freq[i] > 0)
			{
				freq[i] --;
				if (i < first)
					flag = 1;
				if (flag == 0)
				{
					for (int p = 9; p >= 0; p--)
					{
						if (p <= second && freq[p] > 0)
						{
							flag2 = 1;
							break;
						}
					}
					if (flag2 == 0)
					{
						freq[i] ++;
						continue;
					}
				}
				first = second;
				second = -1;
				printf("%i", i);
				num++;
				break;
			}
		}
	} while (b /= 10);
	while (a_length - num > 0)
	{
		num++;
		for (int i = 9; i >= 0; i--)
		{
			if (freq[i] > 0)
			{
				freq[i] --;
				printf("%i", i);
				break;
			}
		}
	}
	return 0;
}


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

using namespace std;

bool compare(size_t a, size_t b) { return a > b; }

size_t find_max_index(vector<size_t> a, size_t v)
{
    size_t i = 0, m = 0;

    for (size_t j = 0; j < a.size(); ++j) {
        if (a[j] <= v && a[j] > m) {
            i = j;
            m = a[j];
        }
    }

    return i;
}

int main()
{
    vector<size_t> a, b;

    char c = '0';
    while (cin.get(c) && c != '\n') {
        a.push_back(c - '0');
    }
    while (cin.get(c) && c != '\n') {
        b.push_back(c - '0');
    }

    vector<size_t>::iterator it;
    for (it = a.begin(); it != a.end(); ++it) {
        cout << *it << " ";
    }
    cout << endl;

    sort(a.begin(), a.end(), compare);

    cout << a.size() << b.size() << endl;
    if (b.size() > a.size()) {
        vector<size_t>::iterator it;
        for (it = a.begin(); it != a.end(); ++it) {
            cout << *it;
        }
        cout << endl;
    } else if (b.size() == a.size()) {
        vector<size_t> o;
        bool q = true;

        vector<size_t>::iterator it;
        for (it = b.begin(); it != b.end(); ++it) {
            if (q && a.size()) {
                size_t i = find_max_index(a, *it);

                q = a[i] == *it;
                o.push_back(a[i]);
                a.erase(a.begin() + i);
            } else {
               o.insert(o.end(),a.begin(),a.end());
               break;
            }
        }

        for (it = o.begin(); it != o.end(); ++it) {
            cout << *it << " ";
        }
        cout << endl;
    } else {
        cout << "whaaaa" << endl;
    }

    return 0;
}


#include <stdio.h>
unsigned __int64 ipow(int base, int exp)
{
	unsigned __int64 result = 1ULL;
	while (exp)
	{
		if (exp & 1)
		{
			result *= (unsigned __int64)base;
		}
		exp >>= 1;
		base *= base;
	}
	return result;
}
int main()
{
	unsigned __int64 b = 0, a_length = 0, b_length = 0;
	char temp;
	static unsigned __int64 freq[10];
	while (scanf_s("%c", &temp, 1))
	{
		if (temp == 10)
			break;
		freq[temp - '0'] ++;
		a_length++;
	}
	while (scanf_s("%c", &temp, 1))
	{
		if (temp == 10)
			break;
		b += (unsigned __int64)(temp - '0') * ipow(10, b_length);
		b_length++;
	}
	if (b_length > a_length)
		b = ipow(10, a_length) - 1;
	int flag = 0;
	int num = 0;
	do
	{
		num++;
		for (int i = 9; i >= 0; i--)
		{
			if ((flag == 1 || i <= b % 10) && freq[i] > 0)
			{
				if (i < b % 10)
					flag = 1;
				freq[i] --;
				printf("%i", i);
				break;
			}
		}
	} while (b /= 10);
	while (a_length - num > 0)
	{
		num++;
		for (int i = 9; i >= 0; i--)
		{
			if (freq[i] > 0)
			{
				freq[i] --;
				printf("%i", i);
				break;
			}
		}
	}
	return 0;
}


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

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


#include<stdio.h>
int main()
{
    int n;
    int cnt=0;
    scanf("%d",&n);
    int arr[n];
    int mex;
    scanf("%d",&mex)
    for(int i=0; i<n; i++)
    {
        scanf("%d",&arr[i]);
    }
    for(int j=0; j<mex; j++)
    {
        for(int i=0; i<n; i++)
        {
        if(arr[i]>=j)
        break;
        if(arr[i]!=j)
        cnt++;
        }
    }
}


#include<stdio.h>
int mian()
{
	int a,b;
	scanf("%d %d",&a,&b);
	printf("%d\n",a + b);
	return 0;
}


#include <stdio.h>

int main()
{
	int n, x, temp, i, count, flag;
	scanf("%d %d", &n, &x)
	flag = count = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &temp);
		if (temp < x)  count++;
		if (temp == x) flag = 1;
	}
	printf("%d\n", flag ? x - count + 1 : x - count);
	return 0;
}


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

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


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define STR_MAX 5

void leerCant(int *);
void cargarDatos(const int, int *);
char* check(const int, int *);

int main(void){
    int n;
    leerCant(&n);
    int vec[n];
    cargarDatos(n, vec);
    char * res=check(n, vec);
    printf("%s", res);
    return 0;
}

void leerCant(int *n){
    scanf("%d", n);
    return;
}

void cargarDatos(const int dim, int * v){
    int i;
    for (i=0;i<dim;i++){
        scanf("%d", (v+i));
    }
    return;
}

char* check(const int dim, int *v){
    int b=-1;
    char * res;
    res=(char *)malloc(sizeof(char)*STR_MAX);
    if(*v%2==0 || *(v+(dim-1))%2==0){
        strcpy(res, "No");
    }
    if(dim%2==0){
        strcpy(res, "No");
    }
    if(dim%2!=0 && v[0]%2!=0 && v[n-1]%2!=0){
        strcpy(res, "Yes");
    }
    return;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cmath>

using namespace std;

int main()
{
    int n,i,j;
    int a[10000];
    while(scanf("%d",&n)==1)
    {
        for(i=0; i<n; i++)
        {
            scanf("%d",a+i);
        }
        if(a[0]%2==0||a[n-1]%2==0)
        {
            printf("No\n");
            continue;
        }
        j=1;
        int cnt=0;
        for(i=0; i<n; i++)
        {
            if(a[i]%2==0)
                j++;
            else if(i<n-1&&a[i+1]%2==0)
                j++;
            else
            {
                if(j&1)
                {
                    j=1;
                    cnt++;
                }
                else
                    j++;
            }
        }
        if(j!=1||cnt%2==0)
            printf("No\n");
        else
            printf("Yes\n");
    }

    return 0;
}


#include <stdio.h>
int main(void){
    int n, x, flag = 1;
    scanf("%d", &n);
    if (n & 1 == 0) {
        flag = 0;
    }
    for (inti = 0; i < x; i++){
        scanf("%d", &x);
        if ((i == 0 || i == x-1) && (x & 1 == 0)) {
            flag = 0;
        }
    }
    if (flag) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


#include<stdio.h>

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


#include<stdio.h>
int shuzu[233];
int mainz(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<N;i++){
        scanf("%d",&shuzu[i]);
    }
    if(shuzu[0]%2==0||shuzu[n-1]%2==0)
        printf("no");
    else if(n%2==0)
        printf("no");
    else
        printf("yes");
    return 0;
}


#include <stdio.h>
long long int max,min,mid,ans,c[3];
#define setmax c[0]>c[1]?(max=0,c[2]>c[max]?max=2:1):(max=1,c[2]>c[max]?max=2:1)
#define setmin c[0]<=c[1]?(min=0,c[2]<=c[min]?min=2:1):(min=1,c[2]<=c[min]?min=2:1)
#define setmid (max+min)==1?mid=2:(max+min)==2?mid=1:mid=0
#define setall (setmax,setmin,setmid,1)
int main()
{
    scanf("%lld %lld %lld",&c[0],&c[1],&c[2]);
    while(setall)
    {
        if((c[max]-2)>=0 && (c[mid]-1)>=0)
        {
            c[max]-=2;
            c[mid]-=1;
            ans++;
        }
        else if(c[0]==1 && c[1]==1 && c[2]==1)
        {
            ans++;
            break;
        }
        else break;
    }
    printf("%lld\n",ans);
    return 0;
}


#include <stdio.h>

void min(int *a, int *b) {
    if(*a > *b) {
        int tmp = *a;
        *a = *b;
        *b = tmp;
    }
}

void min(int *a, int *b, int *c) {
    min(a, b);
    min(b, c);
    min(a, b);
}

int main() {
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);
    min(&a, &b, &c);
    int done = a;
    b-=a;
    c-=a;
    if (b*2 <= c) {
        done += b;
    } else {
        done += c/2;
    }
    printf("%d", done);
    return 0;
}


#include <stdio.h>
long long int max,min,mid,ans,c[3];
#define setmax() c[0]>c[1]?(max=0,c[2]>c[max]?max=2:1):(max=1,c[2]>c[max]?max=2:1)
#define setmin() c[0]<=c[1]?(min=0,c[2]<=c[min]?min=2:1):(min=1,c[2]<=c[min]?min=2:1)
#define setmid() (max+min)==1?mid=2:(max+min)==2?mid=1:mid=0
#define setall() (setmax(),setmin(),setmid(),1)
int main()
{
	scanf("%lld %lld %lld",&c[0],&c[1],&c[2]);
	while(setall())
	{
		if((c[max]-2)>=0 && (c[mid]-1)>=0)
		{
			c[max]-=2;
			c[mid]-=1;
			ans++;
		}
		else if(c[0]==1 && c[1]==1 && c[2]==1)
		{
			ans++;
			break;
		}
		else break;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <stdio.h>
long long int max,min,mid,ans,c[3],lol;
#define setmax() c[0]>c[1]?(max=0,c[2]>c[max]?max=2:1):(max=1,c[2]>c[max]?max=2:1)
#define setmin() c[0]<=c[1]?(min=0,c[2]<=c[min]?min=2:1):(min=1,c[2]<=c[min]?min=2:1)
#define setmid() (max+min)==1?mid=2:(max+min)==2?mid=1:mid=0
#define setall() (setmax(),setmin(),setmid())
int main()
{
	scanf("%lld %lld %lld",&c[0],&c[1],&c[2]);
	lol=setall();
	while(1)
	{
		if((c[max]-2)>=0 && (c[mid]-1)>=0)
		{
			c[max]-=2;
			c[mid]-=1;
			ans++;
			lol=setall();
		}
		else if(c[0]==1 && c[1]==1 && c[2]==1)
		{
			ans++;
			break;
		}
		else break;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <stdio.h>

int cases(int r, int g, int b);

int main(){

    int r, g, b;

    scanf("%d %d %d", &r, &g, &b);

    printf("%d", cases(r, g, b));

    return 0;
}

int cases(int r, int g, int b){
    if(r==g && g==b)
        return r;
    if(r==g && g>b)
    {
        return (r+b+g)/3;
    }
    if(r==g && g<b)
    {
        if(r+g<b)
            return r+g;
        return (r+b+g)/3;
    }
    if(g==b)
        return cases(g, b, r);
    if(b==r)
        return cases(b, r, g);
    if(r>g && g>b)
    {
        if(r>g+b)
            return g+b;
        return (r+g+b)/3
    }
    if(r>b && b>g)
        return cases(r, b, g);
    if(g>r && r>b)
        return cases(g, r, b);
    if(g>b && b>r)
        return cases(g, b, r);
    if(b>r && r>g)
        return cases(b, r, g);
    if(b>g && g>r)
        return cases(b, g, r);
}


#include <stdio.h>
#include <string.h>
char s[20], s1[20], s2[20];
int judge()
{
    if ( s[0] == s[strlen(s)-1] )
       return 1;
    else
        return 0;
}
void add_one()
{
     int i, j;
     s[strlen(s)-1]++;
     if ( s[strlen(s)-1] < '9'+1 )
        ;
     else{
          i = strlen(s)-1;
          while ( i > 0 && s[i] == '9'+1 ){
                s[i] = '0';
                s[i-1]++;
                i--;
          }
          if ( i == 0 ){
             if ( s[i] == '9'+1 ){
                for ( j = strlen(s)-1; j >= 0; j-- )
                    s[j+1] = s[j];
                s[1] = '0';
                s[0] = '1';
             }
          }
     }
}
int main()
{
    long long int num;
    while ( scanf("%s %s", s1, s2) != EOF ){
          num = 0;
          strcpy(s, s1);
          while ( strcmp(s,s2) ){
                if ( judge() ) num++;
                add_one();
          }
          printf("%I64d\n", num);
    }
    return 0;
}


#include "string.h"
#include "stdio.h"
#include "stdlib.h"
int main()
{long long i,j,k,a,b,sum;
char c[18];
while(scanf("%I64d%I64d",&a,&b)!=-1)
{sum=0;
for(i=a;i<=b;i++)
{itoa((int)i,c,10);
if(c[strlen(c)-1]==c[0])sum++;}
printf("%I64d\n",sum);
}
return 0;
}


#include "string.h"
#include "stdio.h"
#include "stdlib.h"
int main()
{long int i,j,k,a,b,sum;
char c[18];
while(scanf("%ld%ld",&a,&b)!=-1)
{sum=0;
for(i=a;i<=b;i++)
{itoa((int)i,c,10);
if(c[strlen(c)-1]==c[0])sum++;}
printf("%ld\n",sum);
}
return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
    long long int w,m,k,ma,ha=1,total=0,temp;
    int i,j,t;
    scanf("%I64d%I64d%I64d", &w,&m,&k);ma=m; w= w/k;
    for(i=0;ma;i++)ma /=10;
    ha=pow(10,i);
    while(1){
    temp = ha-m;
    if(w<=temp*i){printf("%I64d", w/i+total);return 0;}
    total += ha-m;
    w-=(temp*i);
    m=ha;ha*=10;i++;
    }
    return 0;
    }


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

long long digit(long long r)
{
     long long c=0;
     while(r)
     {
             c++;
             r/=10;
     }
     return c;
}

int main()
{
    int j;
	long long w,m,k,temp,val,p,d,s,i,x,ans;
	while(scanf("%I64d%I64d%I64d",&w,&m,&k)!=EOF)
	{
		i=digit(m); p=1;
        for(j=0;j<i;j++)
        p*=10;
        s=0; ans=0;
		while(w>=0)
		{
			ans+=s; temp=w;
			s=p-m; m=p; p*=10;
			val=s*i*k;
			if(val<0)
			break;
			w-=val; i++;
		}
		d=digit(m)-1; x=(temp)/(d*k); ans+=x;
		printf("%I64d\n",ans);
	}
	return 0;
}


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


#include <stdio.h>long long w, m, k, ten, ans;int main(){    int tx;    scanf("%I64d%I64d%I64d", &w, &m, &k);    ten = 9;    tx = 1;    w /= k;    while (ten < m){        ten = ten * 10 + 9;        tx++;    }    if ((ten - m + 1) * tx > w){        printf("%I64d\n", w / tx);        return 0;    }    w -= (ten - m + 1) * tx;    ans = (ten - m + 1);    ten++;    tx++;    while ((ten * 10 - ten) * tx <= w){        w -= (ten * 10 - ten) * tx;        ans += (ten * 10 - ten);        ten *= 10;        tx++;    }    printf("%I64d\n", ans + w / tx);    return 0;}


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

#define norm(X) (((X) + N) % N)
#define N 12
typedef enum _triad { major, minor, strange } triad;

int pos(char note[3])
{
    static char sample[N][3] =
        {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
    int i = 0;
    while (strcmp(note, sample[i])) i++;
    return i;
}

triad det(int a, int b, int c)
{
    int d;
    if (b < a) { d = b; b = a; b = d; }
    if (c < a) { d = c; c = a; a = d; }
    if (c < b) { d = c; c = b; b = d; }
    if (norm(b - a) == 4 && norm(c - b) == 3 || // a, b, c
        norm(c - b) == 4 && norm(a - c) == 3 || // b, c, a
        norm(a - c) == 4 && norm(b - a) == 3) // c, a, b
        return major;
    else if (norm(b - a) == 3 && norm(c - b) == 4 || // a, b, c
        norm(c - b) == 3 && norm(a - c) == 4 || // b, c, a
        norm(a - c) == 3 && norm(b - a) == 4) // c, a, b
        return minor;
    else
        return strange;
}

char *triad_str(triad t)
{
    switch (t) {
    case major: return "major";
    case minor: return "minor";
    case strange: return "strange";
    default: return "";
    }
}

int main()
{
    int a[3], t;
    char note[3];
    for (t = 0; t < 3; t++) {
        scanf("%s", note);
        a[t] = pos(note);
    }
    printf(triad_str(det(a[0], a[1], a[2])));
    return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
	char s[4];int a[3],p,q;
	for(int i=0;i<3;i++){
		scanf("%s",s);
		switch(s[0]){
			case 'C':a[i]=1;break;
			case 'D':a[i]=3;break;
			case 'E':a[i]=5;break;
			case 'F':a[i]=6;break;
			case 'G':a[i]=8;break;
			case 'H':a[i]=10;break;
			case 'A':a[i]=11;break;
			case 'B':a[i]=12;break;
		}
		if(strlen(s)==2)a[i]++;
	}
	p=a[1]-a[0];
	q=a[2]-a[1];
	if(p<0)p+=12;
	if(q<0)q+=12;
	if(p==4&&q==3)
	printf("major");
	else if(p==3&&q==4)
	printf("minor");
	else
	printf("strange");
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Written by Nishant Mittal aka nishantwrp */
int chordtoindex(char *a) {
if (*a == 'C') {
    a++;
    if (*a == '#') {
        return 2;
    } else {
    return 1;
    }
}
if (*a == 'D') {
    a++;
    if (*a == '#') {
     return 4;
    } else {
    return 3;
    }
}
if (*a == 'E') {
    return 5;
}
if (*a == 'F') {
    a++;
    if (*a == '#') {
     return 7;
    } else {
    return 6;
    }
}
if (*a == 'G') {
    a++;
    if (*a == '#') {
     return 9;
    } else {
    return 8;
    }
}
if (*a == 'A') {
    return 10;
}
if (*a == 'B') {
    return 11;
}
if (*a == 'H') {
    return 12;
}
return 0;
}
int distancefind(int a,int b) {
int count = 0;
int i = b;
while (i != a) {
    count++;
    if (i == 12) {
        i = 1;
    } else {
    i++;
    }
}
return count;
}
int main()
{
char chord1[3],chord2[3],chord3[3];
int pos1,pos2,pos3;
int i=0;
while(i<3) {
char tmp;
scanf("%c",&tmp);
if (tmp == ' ') {
    break;
}else {
chord1[i] = tmp;
}
i++;
}
int j=0;
while(j<3) {
char tmp;
scanf("%c",&tmp);
if (tmp == ' ') {
    break;
}else {
chord2[j] = tmp;
}
j++;
}
int k=0;
while(k<3) {
char tmp;
scanf("%c",&tmp);
if (tmp == '\n') {
    break;
}else {
chord3[k] = tmp;
}
k++;
}
int ansset = 0;
pos1 = chordtoindex(chord1);
pos2 = chordtoindex(chord2);
pos3 = chordtoindex(chord3);
//Minor
if (distancefind(pos2,pos1) == 3 && distancefind(pos3,pos2) == 4) {
    ansset = 1;
printf("minor");
}else if (distancefind(pos2,pos3) == 3 && distancefind(pos1,pos2) == 4) {
     ansset = 1;
printf("minor");
}else if (distancefind(pos1,pos2) == 3 && distancefind(pos3,pos1) == 4) {
     ansset = 1;
printf("minor");
}else if (distancefind(pos1,pos3) == 3 && distancefind(pos2,pos1) == 4) {
     ansset = 1;
printf("minor");
} else if (distancefind(pos3,pos1) == 3 && distancefind(pos2,pos3) == 4) {
     ansset = 1;
printf("minor");
} else if (distancefind(pos3,pos2) == 3 && distancefind(pos1,pos3) == 4) {
     ansset = 1;
printf("minor");
}//Major
if (distancefind(pos2,pos1) == 4 && distancefind(pos3,pos2) == 3) {
     ansset = 1;
printf("major");
}else if (distancefind(pos2,pos3) == 4 && distancefind(pos1,pos2) == 3) {
     ansset = 1;
printf("major");
}else if (distancefind(pos1,pos2) == 4 && distancefind(pos3,pos1) == 3) {
     ansset = 1;

}else if (distancefind(pos1,pos3) == 4 && distancefind(pos2,pos1) == 3) {
     ansset = 1;
printf("major");
}else if (distancefind(pos3,pos1) == 4 && distancefind(pos2,pos3) == 3) {
     ansset = 1;
printf("major");
}else if (distancefind(pos3,pos2) == 4 && distancefind(pos1,pos3) == 3) {
 ansset = 1;
printf("major");
}
if (ansset != 1) {
    printf("strange");
}
    return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];

	}
     int unique = 1;

     for (int out = 1; out < n && a[out]!=0; ++out)
     {

        int is_unique = 1;
        for (int inner = 0; is_unique && inner < out; ++inner)
        {

             if (a[inner] == a[out]) is_unique = 0;
        }
        if (is_unique) ++unique;
     }
	cout<<unique;
	return 0;
}


#include <algorithm>
#include <vector>
#include <string>

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

int main()
{
    int n = 0;
    std::scanf("%d", &n);
    std::vector<int> vec;
    for (int a = 0; a < n; a++)
    {
        int b = 0;
        std::scanf("%d", &b);
        vec.push_back(b);
    }
    std::sort(vec.begin(), vec.end());
    int m = deleteDuplicates(vec, n);
    int l = vec[0] == 0 ? m - 1 : m;
    printf("%d", l);
}

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


#include<iostream.h>
/*#include<algorithm>
#include<cmath>*/
using namespace std;
int z[1000];
int main()
{
	int n;
	for(int i=0;i<1000;i++) z[i]=0;
	cin>>n;
	int t;
	int num=0;
	for(int i=0;i<n;i++){
		cin>>t;
		if(z[t]==0&&t!=0) z[t]=1,num++;
	}
	cout<<num<<endl;
	return 0;
 }


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

long long int maximo(long long int a, long long int b )
{
	if ( a >= b )
	{
		return a;
	}
	else
	{
		return b;
	}
}

int main()
{
	long long int A,B,C,D;
	scanf("%lld %lld %lld %lld", &A, &B, &C, &D);

	long long int alfa,beta;
	long long int total = 0;
	for ( alfa = A; alfa <= B; ++alfa )
	{
		long long int st = maximo(alfa+B, C+1);
		if ( alfa+C > D )
		{
			if ( st > D )
			{
				//printf("pase 1: alfa %lld st %lld ", alfa, st );
				total += (D-C+1)*(C-B+1);
			}
			else
			{
                //printf("pase 2: alfa %lld st %lld ", alfa, st );
				total += (D-C)*(D-C+1)/2 - (st-C)*(st-C-1)/2 + (D-C+1)*(alfa+C-D);
			}
		}
		else
		{
            //printf("pase 3: alfa %lld st %lld ", alfa, st );
			total += (alfa)*(alfa+1)/2 - (st-C)*(st-C-1)/2;
		}
		//printf("Parcial total: %lld\n", total);
	}

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

	//system("pause");
}


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

long long ways[1000006];

int main() {
	int a,b,c,d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int tx = b - a, ty = c - b, lz = c - a - b, rz = d - a - b;
	long long ans = 0;
	for( int z=0; z<=rz; ++z ) {
		int l=0, r=z;
		if( r > tx )
			r = tx;
		// ( z - r, z - l )
		if( z - l > ty )
			l = z - ty;
		ways[z] = max(0, r - l + 1);
		if( z > 0 )
		ways[z] += ways[z-1];
	}
	for( int z = max(0,lz); z<=rz; ++z ) {
		ans += ways[z];
	}
	printf("%lld\n", (((1ll*(b-a+1))*(c-b+1))*(d-c+1)) - ans);
}


// C program to print largest contiguous array sum
#include<stdio.h>
typedef long long int ll;
ll max(ll a,ll b){
    return (a>b?a:b);
}
ll min(ll a,ll b){
    return (a<b?a:b);
}
int main()
{
    ll a,b,c,d,low2,high2,ans=0;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    for(ll i=d;i>=c;i--)
    {
        for(int j=b;j<=c;j++)
        {
            low2=max(a,i-j+1);
            high2=min(low2,b+1);
            ans+=(b-high2+1);
        }
    }
    printf("%lld",ans);
}


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

long long int XY(int A, int B, int C, int X_plus_Y)
{
	long long int x = 0;
	int i;
	int j;
	for(i=A;i<=B;i++)
	{
		j = X_plus_Y - i;
		if( (B<=j) && (j<=C) )
		{
			x++;
		}
	}

	return x;
}

long long int Z(int C, int D, int X_plus_Y)
{
	int min;
	long long int z;
	if( X_plus_Y-1 <= D)
	{
		min = X_plus_Y-1;
	}
	else
	{
		min = D;
	}

	z = min - C + 1;
	if(z<0)
	{
		return 0;
	}

	return z;
}

int main()
{
	// variable in description
	int T;
	int A, B, C, D;
	// variable to support
	long long int ans;
	long long int XY_num;
	long long int Z_num;
	// variable to judge
	int i;
	int j;
	int k;

		scanf("%d %d %d %d",&A,&B,&C,&D);

		ans = 0;

		for(j=A+B;j<=B+C;j++)
		{
			XY_num = XY(A,B,C,j);
			Z_num = Z(C,D,j);
			ans += XY_num*Z_num;
			//printf("%d %d\n",XY_num,Z_num);
		}

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

	return 0;
}


#include<stdio.h>
#define MAX 200000
int temp[MAX];
void mergesort(int a[],int indices[],int first,int last)
{
    if(first==last) return;
    int middle=(first+last)/2;
    mergesort(a,indices,first,middle);
    mergesort(a,indices,middle+1,last);
    int i,j,k;
    for(i=first,j=first,k=middle+1; i<=last; i++)
    {
        if(j==middle+1) temp[i]=indices[k++];
        else if(k==last+1) temp[i]=indices[j++];
        else if(a[indices[k]]<a[indices[j]]) temp[i]=indices[k++];
        else temp[i]=indices[j++];
    }
    for(i=first; i<=last; i++)
    {
        indices[i]=temp[i];
    }
}
void noobsort(int a[],int indices[],int first,int last)
{
    if(first>=last) return;
    int i,j,s;
    for(i=first;i<=last;i++)
    {
        for(j=i;j>0&&a[indices[j]]>a[indices[j-1]];j--)
        {
            s=indices[j-1];
            indices[j-1]=indices[j];
            indices[j]=s;
        }
    }
}
int main()
{
    int n,i,j,m;
    scanf("%d %d",&n,&m);
    int a[n],indices[n];
    int fails[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        indices[i]=i;
    }
    for(i=0;i<n;i++)
    {
        fails[i]=0;
        noobsort(a,indices,0,i-1);
        //printf("i=%d\n",i);
        int total_time=0;
        for(j=0;j<i;j++)
        {
            total_time=total_time+a[indices[j]];
        }
        for(j=0;j<i&&m-total_time<a[i];j++)
        {
            fails[i]++;
            total_time=total_time-a[indices[j]];
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%d ",fails[i]);
    }
    return 0;
}


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


#include <stdio.h>
void quicksort(int  a[],int  low,int  high );

int partion(int  a[],int  low,int  high);
int main(void) {
	// your code goes here
	int i,c,n,m,j,sum;
	scanf("%d %d", &n,&m);
	int a[n],s[n],b[n];
	for(i=0;i<n;i++)
	{
		scanf("%d", &a[i]);
		b[i]=a[i];
		if(i==0)
		s[i]=a[i];
		s[i]=s[i-1]+a[i];
	}
	for(i=0;i<n;i++)
	{
		if(s[i]<=m)
		printf("0 ");
		else
		{c=0,sum=0;
			quicksort(b,0,i-1);
			for(j=i-1;j>=0;j--)
			{
				sum+=b[j];
				c++;
				if(s[i]-sum<=m)
				break;
			}
			printf("%d ", c);
		}
	}

	return 0;
}
 void quicksort(int a[],int low,int high)
{
	if(low<high)
	{
		int  pi=partion(a,low,high);
		quicksort(a,low,pi-1);
		quicksort(a,pi+1,high);
	}
}
int partion(int  a[],int  low,int  high)
{
	int i=low-1,pi=a[high],t,j;
	for(j=low;j<high;j++)
	{
		if(a[j]<pi)
		{ i++;
			t=a[i];
			a[i]=a[j];
			a[j]=t;

		}
	}
	t=a[i+1];
	a[i+1]=a[high];
	a[high]=t;
	return i+1;
}


#include <stdio.h>
void quicksort(int  a[],int  low,int  high );

 int partion(int  a[],int  low,int  high);
int main(void) {
	// your code goes here
	int i,c,n,m,j,sum;
	scanf("%d %d", &n,&m);
	int a[n],s[n],b[n];
	for(i=0;i<n;i++)
	{
		scanf("%d", &a[i]);
		b[i]=a[i];
		if(i==0)
		s[i]=a[i];
		s[i]=s[i-1]+a[i];
	}
	for(i=0;i<n;i++)
	{
		if(s[i]<=m)
		printf("0 ");
		else
		{c=0,sum=0;
			quicksort(b,0,i-1);
			for(j=i-1;j>=0;j--)
			{
				sum+=b[j];
				c++;
				if(s[i]-sum<=m)
				break;
			}
			printf("%d ", c);
		}
	}

	return 0;
}
 void quicksort(int  a[],int  low,int  high)
{
	if(low<high)
	{
		int  pi=partion(a,low,high);
		quicksort(a,low,pi-1);
		quicksort(a,pi+1,high);
	}
}
int partion(int  a[],int  low,int  high)
{
	int i=low-1,pi=a[high],t,j;
	for(j=low;j<high;j++)
	{
		if(a[j]<pi)
		{ i++;
			t=a[i];
			a[i]=a[j];
			a[j]=t;

		}
	}
	t=a[i+1];
	a[i+1]=a[high];
	a[high]=t;
	return i+1;
}


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

int bsrch(int v, int *a, int h)
{
  int p, l = 0;

  while (l < h) {
    p = (l + h) / 2;

    // printf("%d : %d : %d [%d]\n", l, p, h, a[p]);
    if (a[p] < v)
      l = p + 1;
    else
      h = p;

    // printf("%d %d [%d]\n", l, h, a[p]);
  }

  return l;
}

#define max(a,b) (a>b?a:b)
int main() {
  int n, M;
  int *m_sum;

  // printf("x\n");
  // int x[] = {2,4,4,10};
  // printf("%d\n", bsearch(4,x,3));
  // printf("%d\n", bsearch(2,x,3));
  // printf("%d\n", bsearch(1,x,3));
  // return 0;

  scanf("%d %d", &n, &M);
  m_sum = (int*)malloc(sizeof(int) * n + 1);
  m_sum[0] = 0;
  m_sum++;

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

    t += v;
    int k = 0;
    if (t > M)
      k = bsrch(t - M, m_sum, i) + 1;

    printf("%d ", k);

    for (int j = i; j >= 0; j--)
      m_sum[j] = max(m_sum[j], m_sum[j - 1] + v);
  }
  printf("\n");
}


#include <stdio.h>

int a[20],i,j,k,top,tmp,x,z,flag,maxi;
long long n;

int main()
{
	scanf("%I64d%d",&n,&k);
	top=0;
	while (n>0)
	{
		top++;
		a[top]=n%10;
		n/=10;
	}
	while (k>0)
	{
		flag=0;
	    for (j=top; j>1; j--)
	    {
	    	maxi=j;
	    	for (x=1; x<=k; x++)
	    		if (j-x>0 && a[maxi]<a[j-x]) maxi=j-x;
	    	if (maxi<j)
	    	{
	    		tmp=a[maxi];
	    		for (z=maxi; z<j; z++) a[z]=a[z+1];
	    		a[j]=tmp;
	    		k-=j-maxi;
	    		flag=1;
	    		break;
	    	}
	    }
	    if (flag==0) break;
	}
	for (i=top; i>1; i--) printf("%d",a[i]);
	printf("%d\n",a[1]);
	return 0;
}


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

int main(void) {
    int k, i,j,l, digit[10][20], cnt[10], temp, swap = 0;
    memset(cnt, 0, sizeof(cnt));
    memset(digit, -1, sizeof(digit));
    char num[20], ch;
    scanf("%s %d", &num, &k);
    int len = strlen(num);
    for(i=0;i<len;i++){
        temp = num[i] - '0';
        digit[temp][cnt[temp]] = i;
        cnt[temp]++;
    }
    for(i=9;i>-1;i--){
        for(j=0;j<cnt[i];j++){
            int min = digit[i][j];
            int index = j;
            for(l=j+1; l<cnt[i]; l++){
                if(min < digit[i][l]){
                    min = digit[i][l];
                    index = l;
                }
            }
            int x = digit[i][j];
            digit[i][j] = digit[i][index];
            digit[i][index] = x;
        }
    }
    //printf("%d %d %d\n", digit[3][0], digit[3][1], digit[3][2] );
    for(i=0;i<len-1 && k>0;i++){
        for(j=9;j>-1;j--){
            //printf("CNT %d\n", cnt[j]);
            if(cnt[j]>0){
                //printf("%d\n", digit[j][cnt[j]-1]);
                if((digit[j][cnt[j]-1] - i) <= k){
                    int m, pos = digit[j][cnt[j]-1];
                    if(pos > i){
                        for(l=pos;l>i;l--){
                            ch = num[l-1];
                            temp = ch - '0';
                            for(m=0;m<cnt[temp];m++){
                                if(digit[temp][m] == l-1)
                                    digit[temp][m]++;
                            }
                            num[l-1] = num[l];
                            num[l] = ch;
                            //printf("CHECK %s", num);
                        }
                        k = k - (pos - i);
                        //printf("K=%d\n", k);
                        //printf("K=%s\n", num);
                    }
                    cnt[j]--;
                    break;
                }
            }
        }
    }
    printf("%s", num);
    return 0;
}


#include<stdio.h>
struct list {
int x;
struct list*next;
}
int main()
{
    char str[20];
    int i;j;
    scanf("%s",str);
    int x=strlen(str);
    for(i=0;i<x;i++)
      str[i]=str[i]-'0';
    char c=str;
    scanf("%d",&k);
    while(k!=0)
    {
        max=str[i];
        for(j=i+1;j<=i+k;j++)
          {
              if(j==x)
                break;
              if(max<str[j]){max=str[j];ctr=j;}

          }

    }
}


0 1 2 3 4
aja evans

#include<stdio.h>
#include<string.h>
char a[32];
int l,b[32],st,m,swp;
int swap(int x,int y)
{
char ch;
int i;
if(y>x)
{
    ch=a[y];
    for(i=y;i>x;i--)
    {
        a[i]=a[i-1];
    }
    a[i]=ch;
}
return 0;
}
main()
{
int i,j,k;
scanf("%s %d",a,&k);
swp=k;
l=strlen(a);
st=0;
while(st<l-1)
{
    m=a[st];
    j=0;
    for(i=st+1;i<l;i++)
    {
        if(a[i]>m)
        {
            m=a[i];
            b[j]=i;
            j++;
        }
    }
    for(i=j-1;i>=0;i--)
    {
        if(swp>=b[i]-st)
        {
            swap(st,b[i]);
            swp=swp-(b[i]-st);
            break;
        }
    }
    st++;
}
for(i=0;i<l;i++)
{
printf("%c",a[i]);
}
return 0;
}


#include <stdio.h>
#include<string.h>
int main(void)
{
	char a[30],t;
	int i,k,alen,max,s;
	scanf("%s",a);
	scanf("%d",&k);
	alen=strlen(a);
	while(k>0)
	{
		for(i=0;i<alen-1;i++)
		{
				max=i;
				s=k;
				while(s>0)
				{
					if(a[i+s]>a[i])
						max=a[max]>a[i+s]?max:i+s;
					s--;
				}
				if(a[max]>a[i])
				{
					t=a[max];
					k=k-max+i;
					while(max-i>0)
					{
						a[max]=a[max-1];
						max--;
					}
					a[i]=t;
					break;
				}
		}
	}
	printf("%s",a);
	return 0;
}


#include <stdio.h>

int main()
{
    char letter = 'a';
    char string[10100];
    scanf("%s" , string);

    for(int i = 0 ; string[i] ; i++){
        if(string[i] <= (letter) )
        {
            if((string[i] = letter++) == 'z')
            {printf(string); return 0;}
        }
        counter++;
    }
    printf("-1");
    return 0;
}


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

int main()
{
    char str[100000];

    scanf("%s",str);

    int i,j=0;
    char sub[27]='\0';

    for(i=0;str[i]!='\0';i++){
        int x=str[i]-'a';
        if(x==j){
            sub[j]=str[i];
            j++;
            sub[j]='\0';
            if(j==26){
                printf("%s\n",sub);
                break;
            }
        }
        else if(x==j-1){
            sub[j]=str[i]+1;
            j++;
            sub[j]='\0';
            if(j==26){
               printf("%s\n",sub);
               break;
            }
        }
    }

    if(j<26){
        printf("%d\n",-1);
    }

    return 0;

}


#include <stdio.h>

char s[100001], c = 'a';
int i;

int main ()
{
    scanf ( "%s", s );

    for ( i = 0; s[i]; ++ i )
        if ( s[i] <= a ) s[i] = a ++;
        else if ( a > 'z' ) break;

    if ( a <= 'z' ) puts ( "-1" );
    else puts ( s );

    return 0;
}


#include <stdio.h>

char s[100001], c = 'a';
int i;

int main ()
{
    scanf ( "%s", s );

    for ( i = 0; s[i]; ++ i )
        if ( s[i] <= a ) s[i] = a ++;

    if ( a <= 'z' ) puts ( "-1" );
    else puts ( s );

    return 0;
}


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

int main()
{
    int letter=0,i,j,len;
    char s2[]="abcdefghijklmnopqrstuvwxyz",s[100001];
    scanf("%s",s);
    len=strlen(s);
    for(i=0,j=97;i<len;i++)
    {
        if(s[i]<=j)
        {
            letter++;
            j++;
            if(letter==26)
            {
                break;
            }
        }
    }
    if(letter==26)
        printf("%s",s);
    else
        printf("-1");
    return 0;
}


#include<stdio.h>
int main()
{
	int m,i,c=0;
	scanf("%d",&m);
	for(i=1;i<=500005;i++)
	{
		int x=i;
		int ans =0;
		while(x>0)
		{
			ans+=x/5;
			x/=5;
			}
			if(ans==m)
			{
				++c;
				printf("%d ",i);
				}
			}
			if(c==0)
			printf("%d",c);
			return 0;
			}


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

typedef unsigned long long opo;

#define S scanf
#define P printf
#define M malloc
#define SI sizeof

/*int cmp(const void *a, const void *b)
{
	int *c;
	int *d;
	c = (int*)a;
	d = (int*)b;
	if (*c > *d)
		return (1);
	if (*c == *d)
		return (0);
	return (-1);
}*/

int main()
{
	int n;
	S("%d", &n);
	int a = 1;
	int count = 0;
	while (count < n)
	{
		a *= 5;
		int z = a;
		while (z % 5 == 0)
		{
			z /= 5;
			count++;
		}
	}
	if (count == n)
	{
		P("5\n");
		for (int i  = 0; i < 5; i++)
			P("%d ", a + i);
		return (0);
	}
	P("0");
}


#include<stdio.h>

int main()
{
long long int ar[10000];
long long int a,b,c,count=0;
long long k,n,i,j;
long long two=0,five=0;
scanf("%lld",&n);

for(i=5;;i++)
{
    five=0;
    for(j=5;j<=i;j=j+5)
    {
        k=j;
        while(k%5==0)
        {
            five++;
            k=k/5;
        }

    }
        if(five==n){ar[count]=i;count++;}
        if(five>n){break;}
}
printf("%lld\n",count);
for(i=0;i<count;i++)
{
    printf("%d ",ar[i]);
}
//main();
}


#include<stdio.h>

int n,k;

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


#include <cstdio>

int n,k;
int main(){
   // freopen("input.txt","r",stdin);
    scanf("%d %d",&n,&k);
    int i,x,mn=2147483640;
    for(i=1;i<k;i++){
        if((n/i)*i!=n)continue;
        x=(n/i)*k+i;
        if(mn>x)mn=x;
    }
    printf("%d\n",mn);
}


#include<stdio.h>
int main(){
	long int a,b;
	scanf("%ld%ld",&a,&b);
	int flag=1;
	long int x=1;
	while(flag !=0){
		int rem = (x/b);
		int mod = (x%b);
		if(rem*mod == a){
			flag=0;
		}
		if(flag ==0){
			printf("%ld\n",x);
		}
		x = x+1;
	}
}


#include<stdio.h>
int main(){
	long int a,b;
	scanf("%ld%ld",&a,&b);

	long int x=a+b;

    while(1){
        int r=x%b;
        if(r!=0)
	if((x/b)*r == a) break;
	x++;
}
			printf("%ld\n",x);

}


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

int main()
{
    long long x = 0, n, k, i, j, confirm = 0;
    scanf("%lld %lld", &n, &k);

    j = 1;
    while (1)
    {
        for (i = 0; i < k; i++)
            if (n % i == 0)
            {
                x = k * j + i;
                if (i * j == n)
                {
                    confirm = 1;
                    break;
                }
            }
        if (confirm == 1)
            break;
        j++;
    }
    printf("%lld\n", x);
    return 0;
}


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


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

char matrix[10][10];
char trash;
int found = 0;

int main()
{
	int i, ii, j, jj;
	int count = 0, step = 0;

	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 10; j++)
		{
			scanf("%c", &matrix[i][j]);
		}
		scanf("%c", &trash);
	}

	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 10; j++)
		{
			if (matrix[i][j] == '.')
			{
				//down
				jj = j;
				ii = i;
				while (ii < 9 && step < 5);
				{
					ii++;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				// up
				jj = j;
				ii = i;
				while (ii >= 1 && step < 5)
				{
					ii--;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				count = 0;
				step = 0;

				//right
				jj = j;
				ii = i;
				while (jj < 9 && step < 5);
				{
					jj++;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				// left
				jj = j;
				ii = i;
				while (jj >= 1 && step < 5)
				{
					jj--;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				count = 0;
				step = 0;

				//right up
				jj = j;
				ii = i;
				while (ii >= 1 && jj < 9 && step < 5);
				{
					ii--;
					jj++;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				// left down
				jj = j;
				ii = i;
				while (ii < 9 && jj >= 1 && step < 5)
				{
					ii++;
					jj--;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				count = 0;
				step = 0;

				//left up
				jj = j;
				ii = i;
				while (ii >= 1 && jj >= 1 && step < 5)
				{
					ii--;
					jj--;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				// right down
				jj = j;
				ii = i;
				while (ii < 9 && jj < 9 && step < 5)
				{
					ii++;
					jj++;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				count = 0;
				step = 0;
			}
		}
	}

	printf("NO\n");

	return 0;
}

/* 1519409842134 */


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

char matrix[10][10];
char trash;
int found = 0;

int main()
{
	int i, ii, j, jj;
	int count = 0, step = 0;

	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 10; j++)
		{
			scanf("%c", &matrix[i][j]);
		}
		scanf("%c", &trash);
	}

	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 10; j++)
		{
			if (matrix[i][j] == '.')
			{
				//down
				jj = j;
				ii = i;
				while (ii < 9 && step < 5);
				{
					ii++;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				// up
				jj = j;
				ii = i;
				while (ii >= 1 && step < 5)
				{
					ii--;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				count = 0;
				step = 0;

				//right
				jj = j;
				ii = i;
				while (jj < 9 && step < 5);
				{
					jj++;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				// left
				jj = j;
				ii = i;
				while (jj >= 1 && step < 5)
				{
					jj--;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				count = 0;
				step = 0;

				//right up
				jj = j;
				ii = i;
				while (ii >= 1 && jj < 9 && step < 5);
				{
					ii--;
					jj++;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				// left down
				jj = j;
				ii = i;
				while (ii < 9 && jj >= 1 && step < 5)
				{
					ii++;
					jj--;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				count = 0;
				step = 0;

				//left up
				jj = j;
				ii = i;
				while (ii >= 1 && jj >= 1 && step < 5)
				{
					ii--;
					jj--;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				// right down
				jj = j;
				ii = i;
				while (ii < 9 && jj < 9 && step < 5)
				{
					ii++;
					jj++;
					if (matrix[ii][jj] == 'X')
					{
						count++;
						step++;
						if (count == 4)
						{
							printf("YES\n");
							return 0;
						}
					}
					else
					{
						break;
					}
				}

				count = 0;
				step = 0;
			}
		}
	}

	printf("NO\n");

	return 0;
}

/* 1519409463713 */


#include<stdio.h>

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


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

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

main()
{
    //freopen("in.txt", "r", stdin);
    int m, b, n, i, j, max, k;

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

    int a[b-1][3];

    j = 1;
    max = 0;
    for(i = 1; i<b; i++)
    {
        a[i][0] = m*(b-i)*i;
        a[i][1] = i;
        a[i][2] = m*(b-i);
        if(a[i][0]>max)
            {max = a[i][0]; j = i;}

            //printf("%d ", a[i]);
    }

    long long sum = 0, sum1, sum2;

    for(i = 0; i<=a[j][1]; i++)
    {
        for(k = 0; k<=a[j][2]; k++)
        {sum = sum + k + i;}
    }

    sum1 = b*(b+1)/2;
    sum2 = (m*b)(m*b+1)/2;

    sum1 = sum1>sum2?sum1:sum2;
    sum = sum>sum1?sum:sum1;

    printf("%I64d", sum);

}


int main()
{
	int i, j, k;
	int n, m;
	int a, b, c;
	int x, y;
	double l;
	__int64 sum = 0;
	 __int64 temp;
	scanf("%d %d", &m, &b);
	for (i = m*b; i >=(m*b)/(m+1)-1; i--)
	{
		temp = 0;
		y = b - i / m;
		l = b - (i*1.0) / m;
		if (l < y)
		{
			y -= 1;
		}
		for (j = 0; j <= i; j++)
		{
			temp += j*(y+1);
		}
		for (j = 0; j <= y; j++)
		{
			temp += j*(i+1);
		}
		if (sum <= temp)
		{
			sum = temp;
		}
	}
	printf("%I64d\n", sum);
	return 0;
}


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

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

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


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


#include <stdio.h>
int main()
{
	long long int n, ans;
        int diff[3] = {0,1,3};
	scanf("%lld",&n);
	ans = n - 1;
	if(ans == 0)
		ans = 3;
	else
		ans =  4 + 4 * (ans / 3) + diff[ans%3] ;
	printf("%lld\n",ans);
}


#include<cstdio>
int main() {
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	printf("%d",(a+b+c)*(a+b+c)-a*a-c*c-e*e);
}


#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int a,b,v1,v2,i=3,is,ans;
    while(i--) is=scanf("%d %d",&a,&b);
    v1=a,v2=b;
    ans=2*b+1;
    int count=0;
    while(v1--) {ans+=2*(b+(++count));}
    while(v2--) {ans+=2*(b+(count--));}
    printf("%d",ans);
}


#include <stdio.h>
int main()
{
    int a[6];
    for(int i=0;i<6;i++)
        scanf("%d",&a[i]);
    int rem = (a[0] + a[1] + a[2]);
    rem = rem*rem;
    rem -= a[0]*a[0];
    rem -= a[2]*a[2];
    rem -= a[4]*a[4];
    printf("%d\n",rem);;
    return 0;
}


#include <stdio.h>
void quicksort(int x[1000],int first,int last){
    int pivot,j,temp,i;

     if(first<last){
         pivot=first;
         i=first;
         j=last;

         while(i<j){
             while(x[i]<=x[pivot]&&i<last)
                 i++;
             while(x[j]>x[pivot])
                 j--;
             if(i<j){
                 temp=x[i];
                  x[i]=x[j];
                  x[j]=temp;
             }
         }

         temp=x[pivot];
         x[pivot]=x[j];
         x[j]=temp;
         quicksort(x,first,j-1);
         quicksort(x,j+1,last);

    }
}
int main()
{
    int n,tab[1000],i,j,x,s=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&tab[i]);
        }

    scanf("%d",&x);
    quicksort( tab, 0,n);

    i=0;
    while (i<n)
    {

    j=i+1;
    while(tab[j]-tab[i]==1)
    {
        j++;
        s++;
    }
    i++;
    }
    printf("%d",s);
    return(0);
}


#include<stdio.h>

int absl(int x){
	if (x<0) return -x;
	else return x;
}

int main(){
	int st[100];
	int n,i,j,max,count,t;
	scanf("%d",&n);
	for (i=0;i<n;i++){
		scanf("%d",&st[i]);
	}
	scanf("%d",&t);
	max=1;
	for (i=0;i<n;i++){
		count=1;
		for (j=i+1;j<n-1;j++){
			if (absl(st[i]-st[j])<=t) count++;
		}
		if (max<count) max=count;
	}
	printf("%d\n",max);
	return 0;
}


#include <stdio.h>
void quicksort(int x[1000],int first,int last){
    int pivot,j,temp,i;

     if(first<last){
         pivot=first;
         i=first;
         j=last;

         while(i<j){
             while(x[i]<=x[pivot]&&i<last)
                 i++;
             while(x[j]>x[pivot])
                 j--;
             if(i<j){
                 temp=x[i];
                  x[i]=x[j];
                  x[j]=temp;
             }
         }

         temp=x[pivot];
         x[pivot]=x[j];
         x[j]=temp;
         quicksort(x,first,j-1);
         quicksort(x,j+1,last);

    }
}
int main()
{
    int n,tab[1000],i,j,x,s=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&tab[i]);
        }

    scanf("%d",&x);
    quicksort( tab, 0,n);

    i=0;
    while (i<n)
    {

    j=i+1;
    while(tab[j]-tab[i]<=x)
    {

    if (tab[j]-tab[i]==x)   s++;
    j++;
    }
    i++;
    }
    printf("%d",s);
    return(0);
}


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

int main()
{
	int n,j,i,h[100],T,max=0,submax;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	scanf("%d",&T);
	for(i=0;i<n;i++){
		submax=0;
		for(j=0;j<n;j++){
			if((h[j]>=h[i])&&(h[j]<=h[i]+T))
				submax++;
		}
		if(submax>max)
			max=submax;
	}
	printf("%d",max);
	//return 0;
}


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

int main()
{
int t;
scanf("%d",&t);
while(t--)
{
	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	if(n%2==0&&m%2==0)
	{
		if(k%2==0)
		 printf("Yes\n");
		else
     printf("No\n");
  }
  else if(m%2==0)
  {
  	if((k-m/2)>=0&&(k-m/2)%2==0)
  	 printf("Yes\n");
		else
     printf("No\n");
  }
  else
  {
  	if(k<=(n*m/2-n/2)&&k%2==0)
  	 printf("Yes\n");
		else
     printf("No\n");
  }
}
return 0;
}


#include<stdio.h>
int main()
{
	int n,m,t,k;
	scanf("%d",&t);
	while(t--){
		scanf("%d %d %d",&n,&m,&k);
		int sum=n*m/2;
		if(n%2==1){
			sum-=m/2;
			k-=m/2;
		}
		if(m%2==1){
			sum-=n/2;
		}
		if(k<0||k%2==1||k>sum){
			printf("NO\n");
		}else printf("YES\n");
	}
	return 0;
}


#include<stdio.h>
int check_domino_row_even(int row, int col, int k) {
	int a[100][100] = { 0 };
	//xep domina ngang tu tren xuong duoi
	int cur_row = 0;
	int cur_col = 0;
	while (1) {
		if (k > row) {
			/*for (int i = cur_row; i < row; i++) {
				for (int j = cur_col; j <= cur_col + 1; j++) {
					a[i][j] = 1;
				}
			}*/
			cur_col += 2;
			k = k - row;
		}
		else {
			/*for (int i = cur_row; i < k; i++) {
				for (int j = cur_col; j <= cur_col + 1; j++) {
					a[i][j] = 1;
				}
			}*/
			cur_row = k;
			break;
		}
	}
	//xep domino doc tu tren xuong
	if ((row - cur_row) % 2 == 1) {
		return 0;
	}
	else if (cur_row == (row - 1)) {
		return 0;
	}
	else if (cur_row == row) {
		return 1;
	}
	else {
		return 1;
	}
}
int check_domino_row_odd(int row, int col, int k) {
	int a[100][100] = { 0 };
	//xep domino ngang theo chieu ngang
	int cur_col = 0, cur_row = 0;
	while (1) {
		if (k > col/2) {
			/*for (int i = cur_col; i < col; i++) {
				a[cur_row][i] = 1;
			}*/
			k = k - (col / 2);
			cur_row++;
		}
		else {
			/*for (int i = cur_col; i < 2 * k; i++) {
				a[cur_row][i] = 1;
			}*/
			cur_col = 2 * k;
			break;
		}
	}
	if (cur_col == col) {
		cur_row++;
		if ((row - cur_row) % 2 == 0) return 1;
		else return 0;
	}
	else return 0;
}
int check_domino(int row, int col, int k) {
	if (row % 2 == 1) return check_domino_row_odd(row, col, k);
	else return check_domino_row_even(row, col, k);
}
int main() {
	int row, col, k;
	int result[100] = { 0 };
	int n = 0;
	scanf_s("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf_s("%d%d%d", &row, &col, &k);
		result[i] = check_domino(row, col, k);
	}
	for (int i = 0; i < n; i++) {
		if (result[i] == 1) printf("\nYES");
		else printf("\nNO");
	}
	return 0;
}


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

long long power(int m, int pow){
    if (pow == 1)
        return m;
    else{
        long long val = power(m, pow/2);
        val = (val * val) %1000000007;

        if (pow%2)
            val = (val * (long long)m) % 1000000007;
        return val;
    }

}

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

    if (k == 1)
        printf("%d\n", power(n,m));
    else{

        if (n>k){

             if (k%2)
                printf("%d\n", (m*m)%1000000007);
            else
                printf("%d\n", m);
        }

        else{
            int pow = k/2 + k%2;

            printf("%I64d\n", power(m,pow));
        }
    }

    return 0;
}


#include <stdio.h>

typedef long long ll;

const int mod = 1000000007;

void solve(int n, int m, int k)
{
    ll ans;
    int i;
    if (k == 1)
    {
        ans = 1;
        for (i = 0; i < n; i ++)
        {
            ans *= m;
            if (ans >= mod)
            {
                ans %= mod;
            }
        }
    }
    else if (k & 1)
    {
        ans = m * m;
    }
    else
    {
        ans = m;
    }
    ans %= mod;
    printf("%I64d\n", ans);
}

int main()
{
    int n, m, k;
    while (scanf("%d%d%d", &n, &m, &k) == 3)
    {
        solve(n, m, k);
    }
    return 0;
}


#include <stdio.h>

int sq(int x, int y) {
  int i, a;

  a = 1;
  for (i = 0; i < y; i++) {
    a = a * x;
    while (a >= 1000000007) a -= 1000000007;
  }

  return a;
}

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

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

  if (k == 1 || k > n) printf("%d", sq(m, n));
  else if (k == n) printf("%d", sq(m, (n+1)/2));
  else if (k%2 == 1) printf("%d", sq(m, 2));
  else printf("%d", m);

  return 0;
}


#include <stdio.h>

#define BASE 1000000007

int pow(int a, int b) {
	if (b == 0) return 1;
	if (b == 1) return a;

	long ans = pow(a, b/2);
	ans = (ans * ans) % BASE;
	ans = (ans * pow(a, b%2)) % BASE;
	return (int) ans;
}

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

	if (k > n) printf("%d\n", pow(m, n));
	else if (k == n) printf("%d\n", pow(m, (n + 1)/2));
	else if (k % 2) printf("%d\n", m*m);
	else printf("%d\n", m);

	return 0;
}


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


#include<stdio.h>
#include<string.h>
#include <algorithm>
using namespace std;
char s1[20][150];
char s2[20][150];
char x[20];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
       scanf("%s",x);
        for(int i=0;i<n;i++)
        {
            scanf("%s",s1[i]);
        }
         if(x[0]==s1[n-1][5]&&x[1]==s1[n-1][6]&&x[2]==s1[n-1][7])
           printf("home\n");
           else
            printf("contest\n");
    }
	return 0;
}


#include <stdio.h>
int main()
{
    scanf ("%d",n);
    if (n%2==0) printf ("home");
    else
        printf ("contest");
        return 0;
}


#include <cstdio.h>

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


#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,j;
    char s[10];
    scanf("%d",&n);
    for(i=; i<=n+1; i++)	 scanf("%s",s);
    if(n%2==0)	printf("home");
    else printf("contest");
    return 0;
}


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

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

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

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

        if (steps[i] != -1) {
            if (min == -1 || steps[i] < min) {
                min = steps[i];
            }
        }
    }
    printf("%d", min);
}


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

#define INF 100000001

typedef long long int int64;

typedef struct Number
{
	int size;
	int *digits;
} Number;

int CountDigits(int64 num)
{
	int digits = 0;
	do {
		digits += 1;
		num /= 10;
	} while (num != 0);
	return digits;
}

int* MakeVector(int size, int init_val)
{
	int *vec = (int*)malloc(sizeof(int) * size);
	int i;

	for (i = 0; i < size; ++i) {
		vec[i] = init_val;
	}
	return vec;
}

Number MakeNumber(int64 num)
{
	Number res;
	res.size = CountDigits(num);
	res.digits = MakeVector(res.size, 0);

	int i = 0;
	do {
		res.digits[i] = num % 10;
		i += 1;
		num /= 10;
	} while (num != 0);

	return res;
}

Number Clone(Number num)
{
	Number clone;
	clone.size = num.size;
	clone.digits = MakeVector(clone.size, 0);

	int i;
	for (i = 0; i < clone.size; ++i) {
		clone.digits[i] = num.digits[i];
	}
	return clone;
}

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

int FindFirst(int vec[], int left, int right, int val)
{
	while (left < right) {
		if (vec[left] == val) {
			return left;
		}
		left += 1;
	}
	return -1;
}

int SecondNonZero(Number num)
{
	int pos = -1;
	int i;

	for (i = 0; i + 1 < num.size; ++i) {
		if (num.digits[i] != 0) {
			pos = i;
		}
	}
	return pos;
}

int HasSuffix(Number num, Number suffix)
{
	if (num.size < suffix.size) {
		return 0;
	}

	int i;
	for (i = 0; i < suffix.size; ++i) {
		if (num.digits[i] != suffix.digits[i]) {
			return 0;
		}
	}
	return 1;
}

void Swap(int *a, int *b)
{
	int aux = *a;
	*a = *b;
	*b = aux;
}

int Malformed(Number num)
{
	return num.digits[num.size - 1] == 0;
}

int CountSwapsToSuffix(Number num, Number suffix)
{
	Number cnum = Clone(num);
	int count = 0;
	int i;

	for (i = 0; i < suffix.size; ++i) {
		int pos = FindFirst(cnum.digits, i, cnum.size, suffix.digits[i]);
		if (pos == -1) {
			break;
		}

		while (cnum.digits[i] != suffix.digits[i]) {
			Swap(cnum.digits + pos, cnum.digits + pos - 1);
			if (Malformed(cnum)) {
				Swap(cnum.digits + pos, cnum.digits + pos - 1);

				int other = SecondNonZero(cnum);
				if (other == -1) {
					break;
				}
				Swap(cnum.digits + other, cnum.digits + other + 1);

			} else {
				pos -= 1;
			}
			count += 1;
		}

		if (cnum.digits[i] != suffix.digits[i]) {
			break;
		}
	}

	int good = HasSuffix(cnum, suffix);
	free(cnum.digits);

	return good ? count : INF;
}

int CountSwaps(int64 num, const Number suffixes[], int suffix_count)
{
	Number number = MakeNumber(num);
	int count = INF;

	int i;
	for (i = 0; i < suffix_count; ++i) {
		int swaps = CountSwapsToSuffix(number, suffixes[i]);
		count = min(count, swaps);
	}
	free(number.digits);

	return count;
}

int main()
{
	int64 num;
	scanf("%I64d", &num);

	Number zero_suffix;
	zero_suffix.size = 2;
	zero_suffix.digits = MakeVector(2, 0);

	const Number kSuffixes[] = {
		MakeNumber(25), MakeNumber(50), MakeNumber(75), zero_suffix,
	};
	int suffix_count = sizeof(kSuffixes) / sizeof(kSuffixes[0]);

	int res = CountSwaps(num, kSuffixes, suffix_count);
	printf("%d\n", (res < INF ? res : -1));

	int i;
	for (i = 0; i < suffix_count; ++i) {
		free(kSuffixes[i].digits);
	}

	return 0;
}


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

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

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

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


#include<stdio.h>
int first(char s[],int len){
    int i,five=-1,two=-1;
    for(i=0;i<len;i++){
        if(s[i]=='5')
            five=i;
        if(s[i]=='2')
            two=i;
    }
    if(five==-1||two==-1)
        return -1;
    else if(two<five)
        return len-five+len-two-3;
    else
        return len-five+len-two-2;
}
int sec(char s[],int len){
    int i,five=-1,zero=-1;
    for(i=0;i<len;i++){
        if(s[i]=='5')
            five=i;
        if(s[i]=='0')
            zero=i;
    }
    if(five==-1||zero==-1)
        return -1;
    else if(zero<five)
        return len-five+len-zero-2;
    else
        return len-five+len-zero-3;
}
int thrd(char s[],int len){
    int i,five=-1,seven=-1;
    for(i=0;i<len;i++){
        if(s[i]=='5')
            five=i;
        if(s[i]=='7')
            seven=i;
    }
    if(five==-1||seven==-1)
        return -1;
    else if(seven<five)
        return len-five+len-seven-3;
    else
        return len-five+len-seven-2;
}
int four(char s[],int len){
    int i,zero1=-1,zero2=-1;
    for(i=0;i<len;i++){
        if(s[i]=='5'){
                zero2=zero1;
            zero1=i;
        }
    }
    if(zero1==-1||zero2==-1)
        return -1;
    else
        return len-zero1+len-zero2-2;
}
int main()
{
    int ara[5];
    int len,i,j,temp;
    char s[100];
    scanf("%s",s);
    len=strlen(s);
    ara[0]=first(s,len);
    ara[1]=sce(s,len);
    ara[2]=thrd(s,len);
    ara[3]=four(s,len);
    for(i=0;i<4-1;i++){
        for(j=i+1;j<4;j++){
            if(ara[j]>ara[i]){
                temp=ara[i];
                ara[i]=ara[j];
                ara[j]=temp;
            }
        }
    }
    for(i=0;i<4;i++){
        if(ara[0]!=-1){
            printf("%d\n",ara[i]);
            break;
        }
    }
}


#include <stdio.h>
#include <string.h>
int max(int *a, int n)
{
	int max = *a;
	int i;
	for (i = 1; i < n; i++)
		if (max < *(a + i))
			max = *(a + i);
	return max;
}
int main()
{
	char str[105];
	char s2[105][105] = { 0 };
	char s1[105] = { 0 };
	int a[105] = { 0 };
	int len, i,j,k,l,n=0,m;
	scanf("%s", str);
	len = strlen(str);
	for (i = 1; i < len; i++)
	{
		memset(s2, 0, sizeof(s2));
		memcpy(s2[0], str, len-i);
		memset(a, 0, sizeof(a));
		n = 0;
		a[0] += 1;
		n++;
		for (j = 1; j <= i; j++)
		{
			memset(s1, 0, sizeof(s1));
			for (k = 0; k < len - i; k++)
				s1[k] = str[k + j];
			for (m = 0; m < n; m++)
			{
				if (strcmp(s1, s2[m]) == 0)
				{
					a[m]++;
					break;
				}
			}
			if (m >= n)
			{
				a[n]++;
				strcpy(s2[n], s1);
			}
		}
		if (max(a, n) >= 2)
		{
			printf("%d\n", max(a, n));
			return 0;
		}
	}
	printf("0\n");
	return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
	int sum,i,j,k,l,n,m,a[1000];
	char c[100000];
	scanf("%s",c);
	int z = strlen(c);
	a[0] = c[i]-'a'+1;
	int ans=0,tmp;
	for(i=0;i<z;i++){
		for(j=i+1;j<z;j++){
		tmp = i;
		sum = 0;
			while(c[tmp]==c[j]){
				sum++;
				tmp++;
				j++;
			}
		if(sum>ans)
			ans = sum;
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <stdio.h>

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

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


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

int main()
{
    char str[101];
    char buf[101];
    gets(str);

    int i = 0;
    for(i = strlen(str) - 1; i > 0; --i)
    {
        memset(buf, 0, 101);
        strncpy(buf, str, i);
        if(strstr(str + 1, buf) != NULL) break;
    }

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


#include<stdio.h>

int main() {
	long long n, b;
	scanf("%lld%lld", &n, &b);
	long long ans = 1000000000000000000;
	for( long long i=2, p, l, tn, cans; i*i <= b; ++i ) {
		if( b%i )
			continue;
		for( l=0, p=1; b%i == 0 ; b /= i )
			l++;
		cans = 0;
		for( tn=n/i; tn; tn /= i ) cans += tn;
		if( cans/l < ans )
			ans = cans/l;
	}
	if( b != 1 ) {
		long long i=b, l=1;
		for( tn=n/i; tn; tn /= i ) cans += tn;
		if( cans/l < ans )
			ans = cans/l;
	}
	printf("%lld\n", ans);
}


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

#define BMAX 1000005

typedef long long ll;

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

int main() {
	ll i;
	ll n, b;
	scanf("%lld %lld", &n, &b);
	ll val = b;
	ll max_zeros = 1000000000000000000LL;
	for (i=2; i <= (ll)sqrt(val) && max_zeros > 0; i++) {
		//printf("val,i = %lld,%lld\n", val, i);
		ll need = 0;
		ll has = 0;
		while (val % i == 0) {
			val /= i;
			need++;
		}
		if (need > 0) {
			ll div = n;
			ll k = i;
			while (div > k) {
				has += div / k;
				k *= i;
			}
			max_zeros = min(max_zeros, has / need);
			//printf("new max %lld\n", max_zeros);
		}
	}
	if (val > 1) {
		i = val;
		ll need = 0;
		ll has = 0;
		while (val % i == 0) {
			val /= i;
			need++;
		}
		if (need > 0) {
			ll div = n;
			ll k = i;
			while (div >= k) {
				has += div / k;
				k *= i;
			}
			max_zeros = min(max_zeros, has / need);
		}
	}
	printf("%lld\n", max_zeros);
	return 0;
}


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

#define BMAX 1000005

typedef long long ll;

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

int main() {
	ll i;
	ll n, b;
	scanf("%lld %lld", &n, &b);
	ll val = b;
	ll max_zeros = BMAX;
	for (i=2; i <= (int)sqrt(val) && max_zeros > 0; i++) {
		//printf("val,i = %lld,%lld\n", val, i);
		int need = 0;
		int has = 0;
		while (val % i == 0) {
			val /= i;
			need++;
		}
		if (need > 0) {
			ll div = n;
			ll k = i;
			while (div > k) {
				has += div / k;
				k *= i;
			}
			max_zeros = min(max_zeros, has / need);
		}
	}
	if (val > 1) {
		i = val;
		int need = 0;
		int has = 0;
		while (val % i == 0) {
			val /= i;
			need++;
		}
		if (need > 0) {
			ll div = n;
			ll k = i;
			while (div >= k) {
				has += div / k;
				k *= i;
			}
			max_zeros = min(max_zeros, has / need);
		}
	}
	printf("%lld\n", max_zeros);
	return 0;
}


#include<stdio.h>

int main() {
	long long n, b;
	scanf("%lld%lld", &n, &b);
	long long ans = 1000000000000000000;
	for( long long i=2, p, l, tn, cans; b>1; ++i ) {
		if( b%i )
			continue;
		for( l=0, p=1; b%i == 0 ; b /= i )
			l++;
		cans = 0;
		for( tn=n/i; tn; tn /= i ) cans += tn;
		if( cans/l < ans )
			ans = cans/l;
	}
	printf("%lld\n", ans);
}


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

#define BMAX 1000005

typedef long long ll;

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

int main() {
	ll i;
	ll n, b;
	scanf("%lld %lld", &n, &b);
	ll val = b;
	ll max_zeros = 1000000000000000000LL;
	for (i=2; i <= /*(ll)sqrt(*/val/*)*/ && max_zeros > 0; i++) {
		//printf("val,i = %lld,%lld\n", val, i);
		ll need = 0;
		ll has = 0;
		while (val % i == 0) {
			val /= i;
			need++;
		}
		if (need > 0) {
			ll k = i;
			ll div = n;
			while (div >= k && k > 0) {
				//printf("div   %lld\n", div);
				has += div / k;
				k *= i;
			}
			max_zeros = min(max_zeros, has / need);
			//printf("new max %lld\n", max_zeros);
		}
	}
	/*if (val > 1) {
		i = val;
		ll need = 0;
		ll has = 0;
		while (val % i == 0) {
			val /= i;
			need++;
		}
		if (need > 0) {
			ll div = n;
			ll k = i;
			while (div >= k) {
				has += div / k;
				k *= i;
			}
			max_zeros = min(max_zeros, has / need);
		}
	}*/
	printf("%lld\n", max_zeros);
	return 0;
}


#include <stdio.h>

long long int pow2(long long int a,long long int b,long long int n)
{
  long long int x=1;
  long long int y=a;
  while(b>0){
    if(b&1)
      x=((x%n)*(y%n))%n;
    y=((y%n)*(y%n))%n;
    b=b>>1;
  }
  return x%n;
}
int main()
{
  long long int n,m,k,ans;
  long long int mod=1e9+7;
  scanf("%lld %lld %lld",&n,&m,&k);
  if(k==-1 && (n+m)%2!=0)
  {
    printf("0\n");
  }
  else
  {
    ans=pow2( pow2(2,n-1,mod),m-1, mod);
    printf("%lld\n",ans);
  }
  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>
#include <math.h>
long long int  m=1000000007;
long long int power(long long int x,long long int y,long long int m)
{
    long long int temp;
    if(y==0)
        return 1;
    temp=power(x,y/2,m);
    if(y%2==0)
        return ((temp%m)*(temp%m))%m;
    else
        return (x*(((temp%m)*(temp%m))%m)%m)%m;
}
int main()
{
	long long int n,p,k,ans,ans1;
	scanf("%lld %lld %lld",&n,&p,&k);
	if(k==-1 && (n+p)%2==1)
	ans=0;
	else
	{
	ans=power(2,(n-1),m);
	ans=power(ans,p-1,m);
	}
//ans=(ans*ans1)%m;
	printf("%lld\n",ans);
	return 0;
}


#include <stdio.h>

int main(){

    long long int a[1000000007];
    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{
    printf("Hi");
    }
    printf("Hello");

}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
#define uL unsigned long long
char str[1000000];
const uLL P=1000000007;
uL exgcd(uL a,uL c)
{
	static uL gcd;
	uL k;
	uLL x;
	if (a==0)
	{
		gcd=c;
		return 1;
	}
	else
	{
		k=c%a;
		if (k==0)
		{
			gcd=a;
			return 1;
		}
		else
		{
			x=exgcd(a%k,k);
		}
	}
	return (x*c-c/a*gcd)/k;
}
inline uLL mod64(uLL a,uLL b,uLL c)
{
	uLL t,t2;
	a=a%c;b=b%c;
	for (t=0;a>0;a=a>>1)
	{
		if (a&1)
		{
			t2=c-t;
			if (t2<b) {t=b-t2;} else {t=t+b;}
		}
		if (c-b>=b) {b=b<<1;} else {b=(b<<1)-c;}
	}
	return t;
}

inline uLL expmod64(uLL a,uLL b,uLL p)
{
	uLL t;
	a=a%p;b=b%p;
	for (t=1;b;b=b>>1)
	{
		if (b&1)
		{
			t=mod64(t,a,p);
		}
		a=mod64(a,a,p);
	}
	return t;
}
int main()
{
	uLL n,m,k,t1,t2,ans;
	scanf("%llu %llu %llu",&n,&m,&k);
	t1=expmod64(2,n,P);
	t2=exgcd(expmod64(2,m,P),P);
	ans=expmod64(t1,m,P);
	t1=exgcd(t1,P);
	ans=ans*2%P;
	ans=ans*t1%P;
	ans=ans*t2%P;
	printf("%llu\n",ans);
}


#include<stdio.h>

int bigger(int n1, int n2);

int main(){
	int b, g, n;

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

	if(b >= n && g >= n) printf("%d", n + 1);
	else if(b >= n && g < n) printf("%d", 1 + g);
	else if(b < n && g >= n) printf("%d", 1 + b);
	else if(b + g > n) printf("%d",  (g + b - bigger(a, b)) - (n - bigger(g, b)) + 1 );
	else printf("1");

	return 0;
}

int bigger(int n1, int n2){
    return (-(n1 >= n2) & n1) + (-(n1 < n2) & n2);
}


#include<stdio.h>
int main()

{
    int a,b,g,n,s;
    scanf("%d%d%d", &b,&g,&n);
    if(b>=g)
    a=g;
    else a=b;
    s=b+g-n;
    if(s==0)
    printf("1\n");
    else if(s>=a)
    {
        if(a+1>=n+1)
        printf("%d\n", n+1);
        else
        printf("%d\n", a+1);

    }
    else
    printf("%d\n", s+1);
    return 0
}


#include<stdio.h>

int main() {
      int b,g,n,ans=0;
	scanf("%d%d%d",&b,&g,&n);
	for (int i=0;i<=b;i++) {
	      j=n-i;

	      ans+=(j>=0 && j<=g);
	}
	printf("%d\n",ans);
}


#include<stdio.h>

int bigger(int n1, int n2);

int main(){
	int b, g, n;

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

	if(b >= n && g >= n) printf("%d", n + 1);
	else if(b >= n && g < n) printf("%d", 1 + g);
	else if(b < n && g >= n) printf("%d", 1 + b));
	else if(b + g >= n) printf("%d", n - bigger(g, b))
	else printf("1");

	return 0;
}

int bigger(int n1, int n2){
    return (-(n1 >= n2) & n1) + (-(n1 < n2) & n2);
}


    #include<stdio.h>

    int main(){
        long long int a,b,c;
        scanf("%lld %lld %lld",&a,&b,&c);
        if(a==0 && b==0 && c==0){
            printf("0");

        }
        else{
            long long int d=c-a;
            long long int e=c-b;
            if(a<b && a<c && a<e && a<d){
                printf("%lld",(a+1));
            }
            else if(a>b && c>b && b<e && b<d){
                printf("%lld",(b+1));

            }
            else if(c<a && c<b && && c<e && c<d){
                printf("%lld",(c+1));

            }
            else if(d<e){
                printf("%lld",d);

            }
            else printf("%lld",e);
        }
        return 0;
    }


#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define mem(a, b) memset(a, b, sizeof a)
#define IN freopen("in.txt", "r", stdin)
#define DEBUG(a) cout << (a) << endl
typedef long long ll;
const int INF = 0x3f3f3f3f;
int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int main()
{
     int i,n,m,j,k=1,l,max1=1;
    scanf("%d",&n);
    m=n;max1=1;k=1;
    while(m>0)
    {
        j=m%10;
        m=m/10;
        max1=max1*j;
    }
    for(i=1;;i++)
    {
        m=n; int ans=1;
        l=pow(10,i);
        m=(m/l-1)*l;
        if(m<0)break;
        m=m+l-1;
        while(m>0)
        {
        j=m%10;
        m=m/10;
        ans=ans*j;
        }
        max1=max(max1,ans);
    }
    printf("%d\n",max1);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define mem(a, b) memset(a, b, sizeof a)
#define IN freopen("in.txt", "r", stdin)
#define DEBUG(a) cout << (a) << endl
typedef long long ll;
const int INF = 0x3f3f3f3f;
int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int main()
{
     int i,n,m,j,k=1,l,max1=1;
    while(~scanf("%d",&n)){
    m=n;max1=1;k=1;
    while(m>0)
    {
        j=m%10;
        m=m/10;
        max1=max1*j;
    }
    for(i=1;;i++)
    {
        m=n; int ans=1;
        l=pow(10,i);
        m=(m/l-1)*l;
        if(m<0)break;
        m=m+l-1;
        while(m>0)
        {
        j=m%10;
        m=m/10;
        ans=ans*j;
        }
        max1=max(max1,ans);
    }
    printf("%d\n",max1);
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
using namespace std;
int ans;
char c[11], tmpc[11];
int prod( char *ch)
{
	int pr = 1, id = 0;
	while (ch[id])
	{
		pr *= ch[id] - '0';
		id++;
	}
	return pr;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	scanf("%s", c);
	int l = 0;
	while (c[l])
		l++;
	ans = prod(c);
	for (int i = 0; i < l; i++) {
		if (c[l] - '0' == 0)
			continue;
		for (int j = 0; j < i; j++)
			tmpc[j] = c[j];
		tmpc[i] = (c[i] - '0' - 1) + '0';
		for (int j = i + 1; j < l; j++)
			tmpc[j] = '9';
		int tmppr = prod(tmpc);
		if (tmppr > ans)
			ans = tmppr;
	}
	printf("%d\n", ans);
	return 0;
}