#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <limits.h>
typedef long long ll;

ll MAX = 100000000000;  //  1e11
ll MIN = -100000000000; // -1e11
ll MOD = 1000000007;

ll longlongmax = __LONG_LONG_MAX__;

ll maxormin(ll a, ll b, ll flag)
{
    return flag == 1 ? (a > b ? a : b) : (a < b ? a : b);
}

ll overflowcheck(ll a)
{
    if (a == 1)
    {
        return 0;
    }
    else
    {
        ll temp = a;
        ll power = 1;
        while (longlongmax / temp > a)
        {
            temp *= a;
            power++;
        }
        return power + 1; // Overflow occurs at this power.
    }
}

ll merge(ll A[], ll B[], ll left, ll mid, ll right)
{
    ll count = 0;
    ll n1 = mid - left + 1;
    ll n2 = right - mid;

    ll LA[n1], LB[n1], RA[n1], RB[n2];

    for (ll n = 0; n < n1; n++)
    {
        LA[n] = A[n + left];
        LB[n] = B[n + left];
    }
    for (ll n = 0; n < n2; n++)
    {
        RA[n] = A[n + mid + 1];
        RB[n] = B[n + mid + 1];
    }

    ll i = 0, j = 0, k = left;

    while (i < n1 && j < n2)
    {
        if (LA[i] < RA[j])
        {
            A[k] = LA[i];
            B[k] = LB[i];
            i++;
        }
        else
        {
            A[k] = RA[j];
            B[k] = RB[j];
            count += n1 - i;
            j++;
        }
        k++;
    }
    while (i < n1)
    {
        A[k] = LA[i];
        B[k] = LB[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        A[k] = RA[j];
        B[k] = RB[j];
        j++;
        k++;
    }
    return count;
}

ll mergesort(ll A[], ll B[], ll left, ll right)
{
    ll total = 0;
    if (left < right)
    {
        ll mid = (right - left) / 2 + left;
        total += mergesort(A, B, left, mid);
        total += mergesort(A, B, mid + 1, right);
        total += merge(A, B, left, mid, right);
    }
    return total;
}

ll primemarked[3000000];
ll primearray[3000000];
ll primeind;

void setupprimes()
{
    for (ll i = 2; i < 3000000; i++)
    {
        for (ll j = 2 * i; j < 3000000; j += i)
        {
            primemarked[j] = 1;
        }
    }
    for (ll i = 2; i < 3000000; i++)
    {
        if (!primemarked[i])
        {
            primearray[primeind++] = i;
        }
    }
}

ll power(ll x, ll y, ll p)
{
    ll 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;
}

ll factorsX[3000000];
ll ind = 0;

int main(int argc, char const *argv[])
{
    ll T = 1;
    // scanf("%lld",&T);
    setupprimes();

    for (ll t = 0; t < T; t++)
    {
        ll x, N;
        scanf("%lld %lld", &x, &N);
        for (ll j = 0; j < primeind; j++)
        {
            if ((x % primearray[j]) == 0)
            {
                factorsX[ind++] = primearray[j];
                while((x % primearray[j])==0)
                {
                    x /= primearray[j];
                }
            }
        }
        if (x!=1)
        {
            // a prime itself
            factorsX[ind++] = x;
        }

        ll total = 1;
        // printf("%lldpopop\n",longlongmax/947);
        for (ll o = 0; o < ind; o++)
        {
            // for each prime factor calculate
            ll count[300];
            ll cind = 0;
            ll fac = factorsX[o];
            ll p = 1;
            ll gh = 1;
            while (p <= N && gh)
            {
                // printf("%lld\n",p);
                count[cind++] = N / p;
                if( p >= longlongmax/fac)
                {
                    gh = 0;
                }
                p *= fac;
            }

            for (ll m = 0; m < cind; m++)
            {
                ll num = 1;
                ll prod ;

                if(m!=(cind-1))
                {
                   num = (m*(count[m]-count[m+1]))%(MOD-1);
                }
                else
                {
                    num = (m*count[m])%(MOD-1);
                }
                // printf("%lld\n",num);
                prod = power(factorsX[o],num,MOD);
                total  = (total*prod)%MOD;
                total %= MOD;
            }
        }
        printf("%lld\n",total%MOD);
    }

    return 0;
}


#include <stdio.h>
#define lint long long

const int P = 1e9 + 7;

lint f(lint n, lint k) {
	lint ret = 1;
	while (k) {
		if (k & 1) ret = ret * n % P;
		n = n * n % P;
		k >>= 1;
	}
	return ret;
}

int main()
{
	lint x, n, i, k, cnt, ans = 1;
	scanf("%lld%lld", &x, &n);

	for (i = 2; i*i <= x; ++i) {
		if (x % i) continue;
		cnt = 0, k = i;
		while (1) {
			cnt += n / k;
			if (k > n/i) break;
			k *= i;
		}
		ans = ans * f(i, cnt) % P;
		while (!(x % i)) x /= i;
	}

	if (x - 1) {
		cnt = 0, k = x;
		while (1) {
			cnt += n / k;
			if (k > n/x) break;
			k *= x;
		}
		ans = ans * f(x, cnt) % P;
	}

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


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

#define ll long long

char ss[123];

ll max( ll a , ll b ){
	if( a > b ){
		return a;
	}
	else{
		return b;
	}
}

long long BS(ll l, ll h, ll b, ll s, ll c, ll nb, ll ns, ll nc, ll pb, ll ps, ll pc, ll r, ll ans){

	if(l <= h){

		ll m = l + (h - l) / 2;
		ll p = max( 0 , b*m - nb ) * pb + max( 0 , c*m - nc ) * pc + max( 0 , s*m - ns ) * ps;

		if(p == r){
			return m;
		}
		else if(p < r){
			ans = max( ans , m );
			return BS(m + 1, h, b, s, c, nb, ns, nc, pb, ps, pc, r, ans);
		}
		else{
			return BS(l, m - 1, b, s, c, nb, ns, nc, pb, ps, pc, r, ans);
		}
	}

	return ans;
}

int main(){

	scanf("%s" , ss);
	int len = strlen(ss);

	ll c = 0, b = 0, s = 0;
	for(int i = 0; i < len ; i++){
		if(ss[i] == 'B') b++;
		else if(ss[i] == 'C') c++;
		else s++;
	}

	ll nb, ns, nc, pb, ps, pc, r , ans = 0;
	scanf("%lld%lld%lld%lld%lld%lld%lld", &nb, &ns, &nc, &pb, &ps, &pc, &r);

	ans = BS(0 , r*max(nb , max(ns , nc)) + r*max(nb , max(ns , nc)) , b , s , c , nb , ns , nc , pb , ps , pc , r , ans);

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

	return 0;
}


/*************************************************************************
    > File Name: 371C.c
    > Author: Stomach_ache
    > Mail: 1179998621@qq.com
    > Created Time: 2013年12月10日 星期二 18时45分51秒
 ************************************************************************/

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

#define max(x,y) ((x)>(y)?(x):(y))

typedef long long ll;
int nb, ns, nc, pb, ps, pc, cb, cs, cc;
ll r;
char str[105];

int ok(ll x) {
	ll tmp = x * cb - nb, rr = r;
	if (tmp * pb > rr || rr < 0)
		return 0;
	if (tmp > 0)
		rr -= tmp * pb;

	tmp = x * cs - ns;
	if (tmp * ps > rr || rr < 0)
		return 0;
	if (tmp > 0)
		rr -= tmp * ps;

	tmp = x * cc - nc;
	if (tmp * pc > rr || rr < 0)
		return 0;
	if (tmp > 0)
		rr -= tmp * ps;

	return 1;
}

int main(void) {
	while (~scanf("%s", str)) {
		scanf("%d %d %d", &nb, &ns, &nc);
		scanf("%d %d %d", &pb, &ps, &pc);
		scanf("%lld", &r);
		int i;
		cb = cs = cc = 0;
		for (i = 0; i < strlen(str); i++) {
			if (str[i] == 'B')
				cb++;
			else if (str[i] == 'S')
				cs++;
			else
				cc++;
		}
		ll lf = 0, rg = 100*r+cb+cs+cc, ans = 0;
		while (lf <= rg) {
			ll mid = (lf + rg) >> 1;
			if (ok(mid)) {
				ans = mid;
				lf = mid + 1;
			}
			else
				rg = mid - 1;
		}
		printf("%lld\n", ans);
	}

	return 0;
}


#include <stdio.h>
//n==0 MAY be a special case to be considered
int main()
{
	int n, groups[5], i, j, temp;

	scanf("%d", &n);

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

	for(i=0; i<n; i++)
		for(j=i+1; j<n; j++)
		{
			if(groups[i]>groups[j])
			{
				temp=groups[i];
				groups[i]=groups[j];
				groups[j]=temp;
			}
		}

	printf("%d", groups[(n-1)/2]);

	return 0;
}


#include <stdio.h>

int main() {
    int n = 0,
        i = 0,
        max = 2009,
        min = 2101,
        mid = 0,
        cur = 0;
    scanf("%d",&n);
    for ( ; i < n; i++ ){
        scanf( "%d", &cur);
        if ( cur > max )
            max = cur;
        if ( cur < min )
            min = cur;
    }
    mid = ( max + min ) / 2;
    printf("%d",mid);
    return 0;
}


#include <stdio.h>
#include <string.h>
int main(void) {
  char s1[11], s2[11], s3[21],temp[21];
	int i,j,k,l1,t,l2;
	scanf("%s %s",s1,s2);
	l1=strlen(s1);
	l2=strlen(s2);
	printf("%c",s1[0]);
	for(i=1;i<l1;i++)
		if(s1[i]<s2[0])
			printf("%c",s1[i]);
		else
			break;
	printf("%c",s2[0]);
  return 0;
}


#include <stdio.h>
#define MAX 17

int main()
{
	char f[MAX], s[MAX];
	int len, i;
	scanf("%s %s", f, s);
	//printf("%s %s\n", f, s);
	len = strlen(f);
	printf("%c", f[0]);
	for(i=1;i<len;++i)
	{
		if(f[i] < s[0])
		{
			printf("%c", f[i]);
		}
		else
		{
			break;
		}
	}
	printf("%c\n", s[0]);
	return 0;
}


#include <stdio.h>

const int MOD=998244353;
int pa[2001][2001];
int po[2001];

long long fp(int ba,int e){
	if(e==0)return 1;
	long long res=fp(ba,e/2);
	res=(res*res)%MOD;
	if(e%2)res=(res*ba)%MOD;
	return res;
}
int main(){

	int i,j;
	pa[0][0]=1;
	for(i=1;i<=2000;i++){
		pa[i][0]=pa[i][i]=1;
		for(j=1;j<i;j++)pa[i][j]=(pa[i-1][j]+pa[i-1][j-1])%MOD;
	}
	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	long long res=(m*fp(m-1,k))%MOD;
	res=(res*pa[n-1][k])%MOD;
	printf("%lld\n",res);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main() {
    int i,j,k,m,mp,n;
    long long *a, *b, *c;
    scanf("%d%d%d", &n, &m, &k);
    a = malloc(sizeof(long long)*(k+1));
    b = malloc(sizeof(long long)*(k+1));
    mp = m - 1;
    a[0] = m;
    for (j = 1; j <= k; j++) { a[j] = 0; }
    for (i = 1; i < n; i++) {
        b[0] = m;
        for (j = 1; j <= k; j++) {
            b[j] = (a[j] + mp*a[j-1]) % 998244353;
        }
        c = a;
        a = b;
        b = c;
    }
    printf("%ld\n", (long) a[k]);
    return 0;
}


#include <stdio.h>

int main(int argc, const char *argv[])
{
    unsigned long long a,b;
    unsigned long long res = 0;
    unsigned long long r;
    unsigned long long sum;
    scanf( "%lld %lld", &a, &b );

    sum = ( a * ( a + 1LL ) / 2LL ) % 1000000007;
    for( r = 1LL; r < b; r++ )
    {
        unsigned long long tmp;
        tmp = ( sum * r ) % 1000000007;
        tmp = ( tmp * b ) % 1000000007;
        res = ( res + tmp + a * r ) % 1000000007;
    }

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


#include<stdio.h>

int main()
{
    long long int a,b,sum=0,i,c,e,m=1000000007,f;
    scanf("%lld%lld",&a,&b);
    f=((b)*(b-1))/2;
    for(i=1;i<=a;i++){
       c=i*b+1;
       e=((c%m)*(f%m))%m;
       sum+=e;
    }
    printf("%lld",sum%m);
    return 0;
}


#include <stdio.h>

int main()
{
    int x, y, z, vx, vy, vz, f1, f2, f3, f4, f5, f6;
    scanf("%d %d %d", &x, &y, &z);
    scanf("%d %d %d", &vx, &vy, &vz);
    scanf("%d %d %d %d %d %d", &f1, &f2, &f3, &f4, &f5, &f6);

    int sum=0;

    if(z<0){
        sum+=f3;
        if(x>0 && y>0){
            sum+=f2+f6;
            if(x<=vx)
                sum-=f6;
            if(y<=vy)
                sum-=f2;
        }
        else if(x<0 && y<0)
            sum+=f1+f5;
        else if(x<0){
            if(y>vy)
                sum+=f2+f5;
            else
                sum+=f5;
        }
        else if(y<0){
            if(x>vx)
                sum+=f1+f6;
            else
                sum+=f1;
        }
        else if(x==0){
            if(y>vy)
                sum+=f2;
            else if(y<0)
                sum+=f1;
        }
        else if(y==0){
            if(x>vx)
                sum+=f6;
            else if(x<0)
                sum+=f5;
        }
    }
    else if(z<=vz){
        if(x>0 && y>0){
            sum+=f2+f6;
            if(x<=vx)
                sum-=f6;
            if(y<=vy)
                sum-=f2;
        }
        else if(x<0 && y<0)
            sum+=f1+f5;
        else if(x<0){
            if(y>vy)
                sum+=f2+f5;
            else
                sum+=f5;
        }
        else if(y<0){
            if(x>vx)
                sum+=f1+f6;
            else
                sum+=f1;
        }
        else if(x==0){
            if(y>vy)
                sum+=f2;
            else if(y<0)
                sum+=f1;
        }
        else if(y==0){
            if(x>vx)
                sum+=f6;
            else if(x<0)
                sum+=f5;
        }
    }
    else{
        sum+=f4;
        if(x>0 && y>0){
            sum+=f2+f6;
            if(x<=vx)
                sum-=f6;
            if(y<=vy)
                sum-=f2;
        }
        else if(x<0 && y<0)
            sum+=f1+f5;
        else if(x<0){
            if(y>vy)
                sum+=f2+f5;
            else
                sum+=f5;
        }
        else if(y<0){
            if(x>vx)
                sum+=f1+f6;
            else
                sum+=f1;
        }
        else if(x==0){
            if(y>vy)
                sum+=f2;
            else if(y<0)
                sum+=f1;
        }
        else if(y==0){
            if(x>vx)
                sum+=f6;
            else if(x<0)
                sum+=f5;
        }
    }

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

    return 0;
}


#include<stdio.h>

int main()
{
    int x,y,z,x1,y1,z1,sum=0;
    scanf("%d%d%d",&x,&y,&z);
    scanf("%d%d%d",&x1,&y1,&z1);
    int ara[6],i;
    for(i=0;i<6;i++)
    {
        scanf("%d",&ara[i]);
    }
    if(y>y1)
        sum+=ara[1];
    else if(y<0)
        sum+=ara[0];
    if(x>x1)
        sum+=ara[5];
    else if(x<0)
        sum+=ara[4];
    if(z>z1)
        sum+=ara[3];
    else if(z<0)
        sum+=ara[2];
    printf("%d\n",sum);
    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 <string.h>
#include <math.h>
#include <stdlib.h>
#define ll long long
ll digitsum(ll num)
{
    ll div = 1;
    ll sum = 0;

    while (num / div != 0)
    {
        sum += ((num) % (div * 10)) / div;
        div *= 10;
    }

    return sum;
}

int main(void)
{
    ll n, s;
    scanf("%lli %lli", &n, &s);

    ll left = 0, right = n;
    while(right != left)
    {
        ll mid = (right + left) / 2;
        ll check = mid - digitsum(mid);

        if (check >= s)
            right = mid;
        else
            left = mid;

        if (right - left == 1)
            left++;
    }

    if (n - digitsum(n) >= s)
        printf("%lli\n", n - right + 1);
    else
        printf("0\n");
}


#include <stdio.h>

/* http://codeforces.com/contest/817/submission/27799686 (Dukkha) */

long long count(long long x) {
	return x < 10 ? x : count(x / 10) + x % 10;
}

int check(long long x, long long s) {
	return x - count(x) >= s;
}

int main() {
	long long n, m, s, cnt, x;
	int d;

	scanf("%lld%lld", &n, &s);
	d = 9 * 18;
	cnt = n - s - d > 0 ? n - s - d : 0;
	m = s + d < n ? s + d : n;
	for (x = s; x <= m; x++)
		if (check(x, s))
			cnt++;
	printf("%lld\n", cnt);
	return 0;
}


#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const long long aa = (long long)3e16;

long long arr[100][2];

long long max(long long x,long long y)
{
    if(x>y)    return x;
    else       return y;
}
int main()
{
    long long x0,y0,ax,ay,bx,by,i,j,tim,xs,ys,cnt=0;
    int ndcollect=0;

    scanf("%lld %lld %lld %lld %lld %lld\n",&x0,&y0,&ax,&ay,&bx,&by);

    scanf("%lld %lld %lld",&xs,&ys,&tim);

    arr[0][0]=x0;
    arr[0][1]=y0;

    while(arr[cnt][0]< aa && arr[cnt][1]< aa)
    {
        cnt++;

        arr[cnt][0]=ax*arr[cnt-1][0]+bx;
        arr[cnt][1]=ay*arr[cnt-1][1]+by;

    }

        for(i=0;i<cnt;i++)
             for(j=0;j<cnt;j++)
        {
                  if(llabs(xs-arr[i][0]) + llabs(ys-arr[i][1]) + llabs(arr[i][0]-arr[j][0]) + llabs(arr[i][1]-arr[j][1]) <= tim)

                  ndcollect = max(ndcollect,abs(i-j)+1);
        }

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


#include<stdio.h>
long long int abs(long long int n)
{
	if (n < 0)
		n *= -1;
	return n;
}
int main()
{
	long long int x0, y0, ax, ay, bx, by;
	scanf("%lld %lld %lld %lld %lld %lld", &x0, &y0, &ax, &ay, &bx, &by);
	long long int xs, ys, t;
	scanf("%lld %lld %lld", &xs, &ys, &t);
	long long int x[102], y[102];
	x[0] = x0;
	y[0] = y0;
	long long int i, j;
	long long int max = 10000000000000016;
	for (i = 0; x[i] < max && y[i] < max; i++)
	{
		x[i + 1] = ax * x[i] + bx;
		y[i + 1] = ay * y[i] + by;
	}
	long long int c = i + 1;
	long long int ans = 0;
	for (i = 0; i < c; i++)
		for (j = 0; j < c; j++)
			if (abs(xs - x[i]) + abs(ys - y[i]) + abs(x[i] - x[j]) + abs(y[i] - y[j]) <= t)
				if (ans < abs(i - j) + 1)
					ans = abs(i - j) + 1;
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>
#include<string.h>
char a[105];
int main()
{
    int max,i,j,k,w,l,flag;
    while(~scanf("%s",a))
    {
        l=strlen(a);
        max=0;
        for(i=1; i<l; i++)
        {
            for(j=0; j<l-i; j++)
            {
                flag=1;
                for(k=j+1; k<l-i+1; k++)
                {
                    flag=1;
                    for(w=0;w<i;w++)
                    {
                        if(a[j+w]!=a[k+w])
                        {
                            flag=0;
                            break;
                        }
                    }
                    if(flag==1)
                        break;
                }
                if(flag==1)
                {
                    max=i;
                    break;
                }
            }
        }
        printf("%d\n",max);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[110];
	int i,len,j,k,flag=1;
	scanf("%s",s);
	len=strlen(s);
	for(i=len;i>=1;i--)
	{
		for(j=0;j<len;j++)
		{
			for(k=0;k<j;k++)
			{
				if(strncmp(&s[k],&s[j],i)==0)
				{
					printf("%d\n",i);
					flag=0;
					break;
				}
			}
			if(!flag) break;
		}
		if(!flag) break;
	}
	if(flag) printf("0\n");
	return 0;
}


#include<stdio.h>

int n, m, highest = 0, highest_temp = 0, p[8+1], i, k, m_note, n_count, min;
void permutate(int, int);
void swap(int *x, int *y);

int main()
{
    while(scanf("%d", &n)!=EOF)
    {
        highest = 0;
        highest_temp = 0;
        min = 9;
        scanf("%d", &m);
        for(i = 1; i<=8; i++)
        {
            p[i] = 0;
        }
        for(i = 1; i<=n; i++)
        {
            p[i] = i;
        }
        for(i = 1; i<=n; i++)
        {
            highest += i * (n+1-i);
        }

        m_note = 0;
        permutate(1, n);

    }
    return 0;
}

void permutate(int start, int end)
{
    if(start == end)
    {

        for(k=1; k<=n; k++)
        {
            n_count = n;
            for(n_count; n_count>0; --n_count)
            {
                min = 9;
                for(i=k; i<=n_count; ++i)
                {

                    if(p[i]<min)
                    {
                        min = p[i];
                    }
                    else{}
                }
                for(i=k; i<=n_count; ++i)
                {
                    if(p[i]==min)
                    {
                        highest_temp += p[i];
                    }
                    else{}
                }
            }
        }
        if(highest_temp >= highest)
        {
            ++m_note;
            if(m_note==m)
            {
                for(i=1; i<=n; i++)
                {
                    printf("%d ", p[i]);
                }
                printf("\n");
            }
            else{}
        }
        else{}
    }
    else
    {
        int j;
        for(j = start; j <= end; ++j)
        {

            swap((p+start), (p+j));
            permutate(start+1, end);
            highest_temp = 0;
            swap((p+start), (p+j));
        }
    }
}

void swap(int *x, int *y)
{
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}


#include<stdio.h>
#include<stdlib.h>
#define size 100
int max(int a,int b)
{
	if(a>b)
	  return a;
	else
	  return b;
}
int partition(int a[],int l,int u)
{
	int v,i,j,temp;
	v=a[l];
	i=l;
	j=u+1;

	do
	{
		do
			i++;

		while(a[i]<v&&i<=u);

		do
			j--;
		while(v<a[j]);

		if(i<j)
		{
			temp=a[i];
			a[i]=a[j];
			a[j]=temp;
		}
	}while(i<j);

	a[l]=a[j];
	a[j]=v;

	return(j);
}
void quick_sort(int a[],int l,int u)
{
	int j;
	if(l<u)
	{
		j=partition(a,l,u);
		quick_sort(a,l,j-1);
		quick_sort(a,j+1,u);
	}
}
main()
{
	int n,m,i,j;
	scanf("%d %d",&n,&m);
	int a[size+1];
	for(i=0;i<n;++i)
	{
		scanf("%d",&a[i]);
	}
quick_sort(a,0,n-1);
i=0;
j=n-1;
while(i<j)
{
	int temp=a[i];
	a[i]=a[j];
	a[j]=temp;
	i++;
	j--;
}
for(i=1;i<=n;++i)
{
	int sum=0;
	for(j=0;j<n;++j)
	{
		sum+=(max(0,a[j]-j/i));
	}
	if(sum>=m)
	{
		printf("%d",i);
		exit(0);
	}
}
printf("-1");
}


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

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

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

    l=1;
    r=n;

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

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


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define For(i,n) for(i=0;i<n;i++)
#define MAX(x,y) x>y?x:y
#define MAXN 111

int mov[MAXN][2];

main()
{
    int i, j, flag = 1;
    int k, a, b;
    int x, y, sx = 0, sy = 0;
    char s[111];
    scanf("%d%d%s",&x,&y,s);
    mov[0][0] = mov[0][1] = 0;
    for(i = 0; s[i]; i++)
    {
        mov[i+1][0] = (s[i]=='U'||s[i]=='D')?0:s[i]=='R'?1:-1;
        mov[i+1][1] = (s[i]=='R'||s[i]=='L')?0:s[i]=='U'?1:-1;
        sx += mov[i+1][0];
        sy += mov[i+1][1];
    }
    For(i,strlen(s)){
        x -= mov[i][0];
        y -= mov[i][1];
        //printf("%d %d\n",x,y);
        if(sx==0&&sy==0) k = 1;
        else if(sx!=0)  k = x/sx;
        else k = y/sy;
        if(sx*k==x&&sy*k==y&&k>=0)
        {
            printf("Yes\n");
            flag = 0; break;
        }
    }
    if(flag) printf("No\n");
    return 0;
}


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

int a, b;
int dx, dy;
char str[110];

int abs(int a){
	return a >= 0 ? a : -a;
}

int sign(int x){
	if (x > 0)
		return 1;
	else if (x == 0)
		return 0;
	else
		return -1;
}

bool check(int x, int y){
	int xdiff = a - x;
	int ydiff = b - y;

	if (x == a && y == b)
		return true;

	if (a != x && dx == 0)
		return false;
	if (b != y && dy == 0)
		return false;

	if (sign(xdiff) * sign(dx) < 0 || sign(ydiff) * sign(dy) < 0)
		return false;

	if (dx == 0)
		return abs(ydiff) % abs(dy) == 0;
	else if (dy == 0)
		return abs(xdiff) % abs(dx) == 0;
	else
		return
			abs(ydiff) % abs(dy) == 0 &&
			abs(xdiff) % abs(dx) == 0 &&
			((long long int)xdiff) * dy == ((long long int)ydiff) * dx;
}

int main(void){
	int i, j;

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

	for (i = 0; str[i]; i++){
		if (str[i] == 'U')
			dy++;
		else if (str[i] == 'D')
			dy--;
		else if (str[i] == 'R')
			dx++;
		else if (str[i] == 'L')
			dx--;
	}

	int x = 0, y = 0;
	bool works = check(0,0);

	for (i = 0; !works && str[i]; i++){
		if (str[i] == 'U')
			y++;
		else if (str[i] == 'D')
			y--;
		else if (str[i] == 'R')
			x++;
		else if (str[i] == 'L')
			x--;
		works = check(x,y);
	}

	printf("%s\n", works ? "Yes" : "No");

	return 0;
}


#include <stdio.h>

#define N	50
#define T	2500
#define MD	1000000007

int dp[N + 1][N + 1][N + 1], dq[N + 1][N + 1][N + 1][3];

void init(int na, int nb, int nc) {
	int ma, mb, mc, x0, x1, x2;

	for (ma = 0; ma <= na; ma++)
		for (mb = 0; mb <= nb; mb++)
			for (mc = 0; mc <= nc; mc++) {
				x0 = ma > 0 ? (long long) dq[ma - 1][mb][mc][0] * ma % MD : 0;
				x1 = mb > 0 ? (long long) dq[ma][mb - 1][mc][1] * mb % MD : 0;
				x2 = mc > 0 ? (long long) dq[ma][mb][mc - 1][2] * mc % MD : 0;
				if (ma == 0 && mb == 0 && mc == 0) {
					dp[ma][mb][mc] = 1;
					dq[ma][mb][mc][0] = dq[ma][mb][mc][1] = dq[ma][mb][mc][2] = 1;
				} else {
					dp[ma][mb][mc] = ((long long) x0 + x1 + x2) % MD;
					dq[ma][mb][mc][0] = (x1 + x2) % MD;
					dq[ma][mb][mc][1] = (x0 + x2) % MD;
					dq[ma][mb][mc][2] = (x0 + x1) % MD;
				}
			}
}

void solve1(int *aa, int t, int n, int da[][N + 1]) {
	int i, s, m, a;

	for (s = 0; s <= t; s++)
		for (m = 0; m <= n; m++)
			da[0][0] = 0;
	da[0][0] = 1;
	for (i = 0; i < n; i++) {
		a = aa[i];
		for (s = t; s >= a; s--)
			for (m = 1; m <= n; m++)
				da[s][m] = (da[s][m] + da[s - a][m - 1]) % MD;
	}
}

void solve2(int *aa, int *bb, int t, int na, int nb, int dab[][N + 1][N + 1]) {
	static int da[T + 1][N + 1];
	int i, b, s, ma, mb;

	solve1(aa, t, na, da);
	for (s = 0; s <= t; s++)
		for (ma = 0; ma <= na; ma++) {
			dab[s][ma][0] = da[s][ma];
			for (mb = 1; mb <= nb; mb++)
				dab[s][ma][mb] = 0;
		}
	for (i = 0; i < nb; i++) {
		b = bb[i];
		for (s = t; s >= b; s--)
			for (ma = 0; ma <= na; ma++)
				for (mb = 1; mb <= nb; mb++)
					dab[s][ma][mb] = (dab[s][ma][mb] + dab[s - b][ma][mb - 1]) % MD;
	}
}

int main() {
	static int aa[N], bb[N], cc[N], dab[T + 1][N + 1][N + 1], dc[T + 1][N + 1];
	int n, na, nb, nc, t, tab, tc, ma, mb, mc, xab, xc, ans;

	scanf("%d%d", &n, &t);
	na = nb = nc = 0;
	while (n--) {
		int a, g;

		scanf("%d%d", &a, &g);
		if (g == 1)
			aa[na++] = a;
		else if (g == 2)
			bb[nb++] = a;
		else
			cc[nc++] = a;
	}
	init(na, nb, nc);
	solve1(cc, t, nc, dc);
	solve2(aa, bb, t, na, nb, dab);
	ans = 0;
	for (tab = 0; tab <= t; tab++) {
		tc = t - tab;
		for (ma = 0; ma <= na; ma++)
			for (mb = 0; mb <= nb; mb++)
				if ((xab = dab[tab][ma][mb]))
					for (mc = 0; mc <= nc; mc++)
						if ((xc = dc[tc][mc]))
							ans = (ans + (long long) xab * xc % MD * dp[ma][mb][mc]) % MD;
	}
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
long long int min(long long int n,long long int k)
{
	if(n<k)
		return n;
	else
		return k;
}
long long int value(long long int n,long long int k)
{
	long long int x=0;
	while(n!=0)
	{
		x+=min(n,k);
		n-=min(n,k);
		n-=(n/10);
	}
	return x;
}
int main()
{
	long long int x,m,n,k,l=1,ans,r;
	scanf("%lld",&n);
	r=n;
	ans=r;
	while(l<=r)
	{
		k=(l+r)/2;
		x=value(n,k);
		if(x*2>=n)
		{
			ans=k;
			r=k-1;
		}
		else
			l=k+1;
	}
	printf("%lld\n",ans);
}


#include <stdio.h>

int main()
{
	long long n,k,r,total;
	long long ok,nk,rc;

	scanf("%lld",&n);

	if (n%2==0) rc = n/2;
	else rc = n/2+1;

	ok = rc;
	nk = 0;

	while(ok-nk>1)
	{
		k = (ok+nk)/2;

		r = n;
		total = 0;

		while (r>0)
		{
			long long p;
			if (k>=r) p = 0;
			else
				p=(r-k)/10;
			if (k<r)
			{ r-=k;
			  total+=k;
			  r-=p;
			 }
			else
			{
				total+=r;
				r = 0;
			}
		}

		if (total>=rc)
		    ok = k;
		else
		    nk = k;
	}
	printf("%lld\n",ok);
	return 0;
}


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

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

int main(){
    long long int a,b;
    int arr1[20],arr2[20],flag[20]={0},i=0,n1,n2,j,final[20],t,tatti=0,ind[20],x=0;
    scanf("%lld %lld",&a,&b);
    while(a>0){
        arr1[i] = a%10;
        a=a/10;
        i++;
    }
    n1 = i;
    i=0;
    while(b>0){
        arr2[i] = b%10;
        b=b/10;
        i++;
    }
    n2 = i;
    i--;
    t=0;
    qsort(arr1,n1,sizeof(int),cmpfunc);
    if(n1<n2){
        for(i=n1-1;i>=0;i--)  printf("%d",arr1[i]);
    }
    else{
        while(t<n1){
            for(j=n1-1;j>=0;j--){
                if(flag[j]==0 && arr1[j]<=arr2[i]){
                    if(arr1[j] < arr2[i])   tatti = 1;
                    final[t] = arr1[j];
                    flag[j]=1;
                    t++;
                    i--;
                    ind[x] = j;
                    x++;
                    // printf("%d %d %d\n",i,arr1[j],arr2[i+1]);
                    break;
                }
            }
            // printf("%d\n",j);
            // printf("%d\n",j);
            // printf("%d\n",j);
            while(j==-1){
                i++;
                t--;
                x--;
                flag[ind[x]] = 0;
                for(j=n1-1;j>=0;j--){
                    if(flag[j]==0 && arr1[j] < arr2[i]){
                        tatti = 1;
                        final[t] = arr1[j];
                        flag[j] = 1;
                        t++;
                        i--;
                        break;
                    }
                }
            }
            if(tatti==1){
                for(j=n1-1;j>=0;j--){
                    if(flag[j]==0){
                        final[t] = arr1[j];
                        t++;
                    }
                }
            }
        }
        for(i=0;i<n1;i++)   printf("%d",final[i]);
    }
    return 0;
}


#include <stdint.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>

static int64_t _factorial[20] = {};

// generates permutation of [0, .., n-1]
static void generate_kth_permutation(int n, int64_t k, int v[static n]) {
    bool taken[n]; for(int i = 0 ; i < n ; ++i) taken[i] = false;
    for(int i = 0 ; i < n ; ++i) {
        const int64_t f = _factorial[n-i-1];
        int64_t q,r; if(k < f) {
            r = k, q = 0;
        } else {
            r = k % f; if(r == 0) r = f; // 0 < r <= m!
            q = (k - r) / f;
        }
        int qi = 0; for(int j = 0, ti = 0, tn = q+1 ; ti < tn ; ++j)
            if(!taken[j]) qi = j, ++ti;

        v[i] = qi; taken[qi] = true; k = r;
    }
}

// sort digits of in increasing order, and generate permutations
// use binary search to find needed permutation

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

static inline int64_t number_from_digits_perm(int n, int perm[static n], int d[static n]) { int64_t ret = 0;
    if(d[perm[0]] == 0) return 0;
    for(int i = 0 ; i < n ; ++i)
        ret = 10*ret + d[perm[i]];
    return ret;
}

static inline bool perm_gt(int n, int64_t pn, int d[static n], int64_t V) {
    int perm[n]; generate_kth_permutation(n, pn, perm);
    const int64_t a = number_from_digits_perm(n, perm, d);
    return a > V;
}

static inline bool perm_lt(int n, int64_t pn, int d[static n], int64_t V) {
    int perm[n]; generate_kth_permutation(n, pn, perm);
    const int64_t a = number_from_digits_perm(n, perm, d);
    return a <= V;
}

static inline int64_t solve(int64_t a, int64_t b) {
    int adcount = 0; int ad[20]; while(a) {
        ad[adcount++] = a % 10; a /= 10;
    }
    qsort(ad, adcount, sizeof(int), compare_digit);

    int64_t low = 0, high = _factorial[adcount]+1;      /* start with whole array                   */
    while(high - low > 1) {                             /* more than one candidate                  */
        const int64_t mid = low + (high - low) / 2;     /* pick middle                              */
        if(perm_gt(adcount, mid, ad, b)) high = mid;    /* higher than b: no need to consider it    */
        else                             low = mid;
    }

    int aperm[adcount]; generate_kth_permutation(adcount, low, aperm);
    return number_from_digits_perm(adcount, aperm, ad);
}

int main() {
    _factorial[0] = 1; for(int i = 1 ; i < 20 ; ++i) _factorial[i] = i*_factorial[i-1];
    int64_t a, b; scanf("%"PRId64 " %"PRId64 "\n", &a, &b);
    printf("%" PRId64 "\n", solve(a,b));
}


#define __USE_MINGW_ANSI_STDIO 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define maxN 65

char str[maxN];
char tmpstr[maxN];
char tgt[maxN];

int zeroCnt(char *str) {
    int ctr = 0;
    for (int i = strlen(str) - 1; i >= 0; --i) {
        if (str[i] == '0') ++ctr;
    }
    return ctr;
}

void trim(char *str) {
    for (int i = strlen(str) - 1; i >= 0; --i) {
        if (str[i] == '1') break;
        else str[i] = '\0';
    }
}

static inline void cswap(char *a, char *b) {
    char tmp = *a;
    *a = *b;
    *b = tmp;
    return;
}

void reverse(char *str) {
    int p = 0, q = strlen(str) - 1;
    for (; p < q; ++p, --q) {
        cswap(&str[p], &str[q]);
    }
}

// bin
#define lltoa(a, b) _lltoa(a, b)
void _lltoa(long long num, char *dest) {
    int len = 0;
    while (num) {
        if (num % 2 == 0) dest[len++] = '0';
        else dest[len++] = '1';
        num /= 2;
    }
    dest[len] = '\0';
    reverse(dest);
}

void testcase() {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    lltoa(a, str);
    lltoa(b, tgt);
    // Orig string: Either equal, or at least a 1 on the right, and any amount of 1s on the left and right after.
    if (strcmp(tgt, str) == 0) { printf("YES\n"); return; }
    // Make sure at least one 1 is on the right.
    strcpy(tmpstr, str);
    int len = strlen(tmpstr);
    if (tmpstr[len - 1] == '0') {
        tmpstr[len++] = '1';
        tmpstr[len] = '\0';
    }
    if (strstr(tgt, tmpstr) && zeroCnt(tgt) == zeroCnt(tmpstr)) { printf("YES\n"); return; }
    // This flipped +1 string must also be used to match.
    reverse(tmpstr);
    if (strstr(tgt, tmpstr) && zeroCnt(tgt) == zeroCnt(tmpstr)) { printf("YES\n"); return; }

    // 2 flips performed: Completely trimmed. Add any amount of 1s to the left or right.
    trim(str);
    if (strstr(tgt, str) && zeroCnt(tgt) == zeroCnt(str)) { printf("YES\n"); return; }

    // 1 flip performed. Both sides start and end with a 1. Add any amounts of 1 left and right.
    reverse(str);
    trim(str);
    if (strstr(tgt, str) && zeroCnt(tgt) == zeroCnt(str)) { printf("YES\n"); return; }
    printf("NO\n");

    return;
}

int main() {
    testcase();
    return 0;
}


#include <stdio.h>

#define N	62

long long rev(long long x) {
	long long y = 0;

	while (x) {
		y = y << 1 | (x & 1);
		x >>= 1;
	}
	return y;
}

long long padded(long long a, long long b) {
	return a % b == 0 && ((a / b) & (a / b - 1)) == 0;
}

int main() {
	static int yy[N];
	long long x, y, z;
	int n, l, r, i;

	scanf("%lld%lld", &x, &y);
	if (x == y) {
		printf("YES\n");
		return 0;
	}
	if ((y & 1) == 0) {
		printf("NO\n");
		return 0;
	}
	n = 0;
	while (y)
		yy[n++] = y & 1, y >>= 1;
	for (l = 0; l < n; l++) {
		for (r = n - 1; r >= l; r--) {
			if (yy[l] == 0 && yy[r] == 0)
				break;
			else if (yy[l] == 0) {
				z = 0;
				for (i = r; i >= l; i--)
					z = z << 1 | yy[i];
				if (x == z) {
					printf("YES\n");
					return 0;
				}
			} else if (yy[r] == 0) {
				z = 0;
				for (i = l; i <= r; i++)
					z = z << 1 | yy[i];
				if (x == z) {
					printf("YES\n");
					return 0;
				}
				break;
			} else {
				z = 0;
				for (i = l; i <= r; i++)
					z = z << 1 | yy[i];
				if (padded(x, z) || padded(x, rev(z))) {
					printf("YES\n");
					return 0;
				}
			}
		}
		if (yy[l] == 0)
			break;
	}
	printf("NO\n");
	return 0;
}


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

#define LL "%I64d"

long long d[2][48][7][8][9][2][2];
int digits[26], dgCount;

int nx7[10][10], nx8[10][10], nx9[10][10];
int nxmask[48][10];
int bad5[48][10], bad7[48][10], bad8[48][10], bad9[48][10];
int buf[10 * 25];

void swap(int *x, int *y) {
    int t = *x;
    *x = *y;
    *y = t;
}

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

long long solve(long long n, int useN) {
    int i, mask, j, high, r7, r8, r9, last, next;
    memset(d[0], 0, sizeof(d[0]));

    if(useN) {
        dgCount = 0;
        while(n) {
            digits[dgCount++] = n % 10;
            n /= 10;
        }
    } else {
        for(i = 0; i < dgCount / 2; i++)
           swap(&digits[i], &digits[dgCount - i - 1]);
    }

    d[0][0][0][0][0][0][0] = 1;
    for(i = 0; i < dgCount; i++) {
      memset(d[(i & 1) ^ 1], 0, sizeof(d[(i & 1) ^ 1]));
      for(mask = 0; mask < 48; mask++) {
        for(r7 = 0; r7 < 7; r7++) {
          for(r8 = 0; r8 < 8; r8++) {
            for(r9 = 0; r9 < 9; r9++) {
              for(high = 0; high < 2; high++) {
                for(last = 0; last < 2; last++) {
                    if(d[i & 1][mask][r7][r8][r9][high][last] == 0)
                        continue;
                    int limit = 9;
                    if(high == 0)
                        limit = digits[dgCount - i - 1];
                    for(next = 0; next <= limit; next++) {
                        int nr7 = nx7[r7][next];
                        int nr8 = nx8[r8][next];
                        int nr9 = nx9[r9][next];
                        int nmask = nxmask[mask][next];
                        int nhigh = (high ? 1 : (next == limit ? 0 : 1));
                        int nlast = (next == 0 || next == 5 ? 1 : 0);
                        d[(i & 1) ^ 1][nmask][nr7][nr8][nr9][nhigh][nlast] +=
                            d[i & 1][mask][r7][r8][r9][high][last];
                    }
                }
              }
            }
          }
        }
      }
    }

    long long ans = 0;
    for(mask = 0; mask < 48; mask++) {
        for(r7 = 0; r7 < 7; r7++) {
            if(bad7[mask][r7]) {
                break;
            }
            for(r8 = 0; r8 < 8; r8++) {
                if(bad8[mask][r8]) {
                    continue;
                }
                for(r9 = 0; r9 < 9; r9++) {
                    if(bad9[mask][r9]) {
                        continue;
                    }
                    for(high = 0; high < 2; high++)
                        for(last = 0; last < 2; last++) {
                            if(bad5[mask][last])
                                continue;
                            ans += d[dgCount & 1][mask][r7][r8][r9][high][last];
                            if(0 && d[dgCount & 1][mask][r7][r8][r9][high][last] > 0)
                                printf("mask=%d r7=%d r8=%d r9=%d high=%d last=%d val="LL"\n"
                                        , mask, r7, r8, r9, high, last,
                                        d[dgCount & 1][mask][r7][r8][r9][high][last]);

                        }
                }
            }
        }
    }
    //printf("HERE "LL"\n", d[1][24][0][7][7][0][0]);
    return ans;
}

int stupid(int n) {
    int i, j, tmp;
    int ans = 0;
    for(i = 0; i <= n; i++) {
        int isValid = 1;
        tmp = i;
        while(tmp) {
            int cur = tmp % 10;
            tmp /= 10;
            if(cur >= 2 && i % cur)
                isValid = 0;
        }
        ans += isValid;
    }
    return ans;
}

void test() {
    int n;
    for(n = 0; n <= 200; n++) {
        int answer = stupid(n);
        int cand = solve(n, 1);
        if(answer != cand) {
            puts("WA");
            printf("n = %d, answer is %d, you think it's %d\n", n, answer, cand);
            break;
        }
    }
}

void init() {
    int i, j;
    for(i = 0; i < 10; i++)
        for(j = 0; j < 10; j++) {
            nx7[i][j] = (10 * i + j) % 7;
            nx8[i][j] = (10 * i + j) % 8;
            nx9[i][j] = (10 * i + j) % 9;
        }
    for(i = 0; i < 48; i++)
        for(j = 0; j < 10; j++) {
            if(j < 2)
                nxmask[i][j] = i;
            else {
                int tmp = i;
                int p7 = tmp / 24;
                tmp %= 24;
                int p5 = tmp / 12;
                tmp %= 12;
                int p3 = tmp / 4;
                tmp %= 4;
                int p2 = tmp;

                tmp = j;
                int p[10], k;
                memset(p, 0, sizeof(p));
                for(k = 2; k <= 7; k++)
                    while(tmp % k == 0) {
                        tmp /= k;
                        p[k]++;
                    }

                p2 = max(p2, p[2]);
                p3 = max(p3, p[3]);
                p5 = max(p5, p[5]);
                p7 = max(p7, p[7]);
                nxmask[i][j] = 24 * p7 + 12 * p5 + 4 * p3 + p2;
            }
        }
    for(i = 0; i < 48; i++) {
        for(j = 0; j < 10; j++) {
            int tmp = i;
            int p7 = tmp / 24;
            tmp %= 24;
            int p5 = tmp / 12;
            tmp %= 12;
            int p3 = tmp / 4;
            tmp %= 4;
            int p2 = tmp;

            if(j == 0 && p5 == 1)
                bad5[i][j] = 1;

            if(j != 0 && p7 == 1)
                bad7[i][j] = 1;

            if(j != 0 && p2 == 3)
                bad8[i][j] = 1;
            if(j != 4 && j != 0 && p2 == 2)
                bad8[i][j] = 1;
            if(j != 6 && j != 4 && j != 2 && j != 0 && p2 == 1)
                bad8[i][j] = 1;

            if(j != 0 && p3 == 2)
                bad9[i][j] = 1;
            if(j != 6 && j != 3 && j != 0 && p3 == 1)
                bad9[i][j] = 1;
        }
    }
}

int getInt() {
    int ret = 0;
    char c;
    while((c = getchar()) != '\n')
        ret = ret * 10 + c - '0';
    return ret;
}

void getLong() {
    dgCount = 0;
    char c;
    while((c = getchar()) != '\n') {
        digits[dgCount++] = c - '0';
    }
}

int main() {
    int t, i;
    init();
    t = getInt();
    for(i = 0; i < t; i++) {
        long long from;
        scanf(LL" ", &from);
        long long val = -solve(from - 1, 1);
        getLong();
        val += solve(0, 0);
        printf(LL"\n", val);
    }
    return 0;
}


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

#define ll long long
#define M 2520

int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}
int LCM(int a,int b){ return a/GCD(a,b)*b; }

ll *dp1, *dp2, *nx1, *nx2, *swap;
ll dp1__[M], dp2__[M];
ll nx1__[M], nx2__[M];

ll dp[323][M];
int bc[323];

int nex[M][10];

ll solve(ll mx){
  int i,j,k,mask,use[10],us,now,nn;
  int go[20],gos,g;
  ll res;

  dp1=dp1__; dp2=dp2__; nx1=nx1__; nx2=nx2__;

  gos=0;
  while(mx) go[gos++]=mx%10, mx/=10;

  rep(mask,1<<8){
    if( (mask&1<<2) && !(mask&1<<0) ) continue;
    if( (mask&1<<4) && (!(mask&1<<0)||!(mask&1<<1)) ) continue;
    if( (mask&1<<6) && (!(mask&1<<0)||!(mask&1<<2)) ) continue;
    if( (mask&1<<7) && !(mask&1<<1) ) continue;
    us=2; use[0]=0; use[1]=1;
    rep(i,8) if(mask&1<<i) use[us++]=i+2;

    rep(i,M) dp1[i]=dp2[i]=0;
    dp1[0]=1;

    rep(i,M) rep(j,us) nex[i][j] = (i*10+use[j])%M;

    for(now=gos-1;now>=0;now--){
      rep(i,M) nx1[i]=nx2[i]=0;

      rep(i,M) if(dp2[i]) rep(k,us) nx2[nex[i][k]] += dp2[i];

      rep(i,M) if(dp1[i]) rep(k,us){
        if(go[now]==use[k]) nx1[nex[i][k]] += dp1[i];
        if(go[now]> use[k]) nx2[nex[i][k]] += dp1[i];
      }

      swap=dp1, dp1=nx1, nx1=swap;
      swap=dp2, dp2=nx2, nx2=swap;
    }

    rep(i,M) dp[mask][i] = dp1[i] + dp2[i];
  }

  res = 0;
  rep(mask,1<<8){
    g=1;
    rep(i,8) if(mask&1<<i) g=LCM(g,i+2);

    rep(i,mask+1) if( (i&mask)==i ){
      for(j=0;j<M;j+=g){
        if( (bc[mask] - bc[i])%2 ) res -= dp[i][j];
        else                       res += dp[i][j];
      }
    }
  }

  return res;
}

int main(){
  int i,j,k,l,n;
  ll a, b, res;
  int size;

  bc[0]=0;
  REP(i,1,1<<8) bc[i] = bc[i&(i-1)]+1;

  scanf("%d",&size);
  while(size--){
    scanf("%I64d%I64d",&a,&b);
    res = solve(b) - solve(a-1);
    printf("%I64d\n",res);
  }

  return 0;
}


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

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

int fit(int a[], int size, int val_left){
	int i;
	int count = 0;
	for(i=0; i < size && val_left >= 0; i++){
		val_left -= a[i];
		if(val_left >= 0)
			count++;
	}
	return size - count;
}

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

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	int t[N];
	int i;
	for(i=0; i<N; i++){
		scanf("%d", &t[i]);
	}
	int dummy[N];
	for(i=0; i < N; i++){
		dummy[i] = 0;
	}
	for(i=0; i < N; i++){
		if(i == 0){
			printf("0 ");
		}
		else{
			dummy[i-1] = t[i-1];
			qsort(dummy, i, sizeof(int), compare);
			// print(dummy, i);
			printf("%d ", fit(dummy, i, M-t[i]));
		}
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
#define ll long long int
#define loop(a,b) for(int i = a; i < b; ++i)
#define loop2(a,b) for(int j = a; j < b; ++j)

const int mod=1e+9+7;
long long dp[100][2];

void solve(){
    int n,k,d;
    scanf("%d %d %d",&n,&k,&d);
    loop(1,n+1){
        dp[i][0] = dp[i][1] = 0;
        loop2(1,k+1){
            if (i-j < 0) break;
            if (j < d){
                dp[i][0] = (dp[i][0] + dp[i-j][0])%mod;
                dp[i][1] = (dp[i][1] + dp[i-j][1])%mod;
            }
            else{
                dp[i][1] = (dp[i][1] + dp[i-j][0] + dp[i-j][1])%mod;
            }
        }
    }
    ll ans = dp[n][1]%mod;
    printf("%lld\n",ans);
}

int main(){
    dp[0][0] = 1;
    dp[0][1] = 0;

    int t=1;
    //    cin>>t;
    while(t--) solve();
    return 0;
}


#include <stdio.h>

int mask(int c) {
  char s_c[7];
  int i = 0;
  int ans = 0;

  sprintf(s_c, "%d", c);
  while (s_c[i] != '\0') {
    if (s_c[i] == '4') ans = ans*10 + 4;
    else if (s_c[i] == '7') ans = ans*10 + 7;
    i++;
  }
  return ans;
}

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

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

  while (c < 1000000) {
    if (mask(c) == b) {
      printf("%d", c);
      break;
    }
    c++;
  }

  return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	int a, b;
	char ar[20], br[20];
	scanf ("%d%d", &a, &b);
	int ans = a+1;
	int i;
	int temp;
	ar[19] = '\0';
	while (1){
		temp = ans;
		i=18;
		while (temp > 0){
			if ( temp%10 == 7 || temp%10 == 4 )
				ar[i--] = temp%10 + 48;
			temp = temp/10;
		}
		if ( atoi(&ar[i+1]) == b  ){
			printf ("%d\n", ans);
			break;
		}
		else
			ans++;

	}

	return 0;
}


#include <stdio.h>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define chk(x) (x != p[0] && x != p[1] && x != p[2])
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define true 1
typedef int bool;
bool vis[55][55][55][9][9];
int p[5], m[5], t[5], ans;
void dfs(int *p, int x, int y)
{
	if (vis[p[0]][p[1]][p[2]][x][y])
		return;
	vis[p[0]][p[1]][p[2]][x][y] = true;
	int far = 0, near = 50;
	for (int i = 0; i < 3; i++)
	{
		if (p[i] < 45)
			far = max(far, p[i]);
		near = min(near, p[i]);
	}
	ans = max(ans, far);
	for (int j = 0; j < 3; j++)
	{
		int arr[] = {p[0], p[1], p[2]}, z = 1 << j;
		if (p[j] >= 45)
		{
			int pos = p[j] - 45;
			if (p[pos] >= 45)
				continue;
			for (int i = p[pos] + t[pos]; i >= p[pos] - t[pos] && i > near - 2 && i; i--)
			{
				if (chk(i))
				{
					arr[j] = i;
					dfs(arr, x, y);
				}
			}
		}
		else if (chk(j + 45))
		{
			if (y & z)
			{
				for (int i = 0; i < 3; i++)
				{
					if (my_abs(p[i] - p[j]) != 1)
						continue;
					arr[i] = 45 + j;
					dfs(arr, x, y ^ z);
					arr[i] = p[i];
				}
			}
			if (x & z)
			{
				for (int i = p[j] + m[j]; i >= p[j] - m[j] && i > near - 2 && i; i--)
				{
					if (!chk(i))
						continue;
					arr[j] = i;
					dfs(arr, x ^ z, y);
				}
			}
		}
	}
}
int main()
{
	// freopen("105E.in", "r", stdin);
	for (int i = 0; i < 3; i++)
		scanf("%d%d%d", p + i, m + i, t + i);
	dfs(p, 7, 7);
	printf("%d\n", ans);
	return 0;
}


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

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

			p[i]=temp/10;
			p[m]=temp%10;
			for (j=1;j<=9;j++)
			{

				if (a[j]==0)
				{
					a[j]=1;a[0]++;
					movethrow(C,j);
					a[j]=0;a[0]--;
				}
			}
			p[i]=0;
			p[m]=temp;
		}
	}
	return 0;
}
int mv(CA C,int pe)
{
	int i,j;
	int f,m,r,t[4];
	t[1]=search(1);
	t[2]=search(2);
	t[3]=search(3);
	int temp;
	temp=t[pe];
	m=t[pe];
	t[pe]=t[3];
	t[3]=temp;
	f=m-C[pe].mvrg;
	r=m+C[pe].mvrg;
	if (r>max)
		max=r;
	if (f<=0)
		f=1;
	for (i=f;i<=r;i++)
	{
		if (i!=m&&p[i]==0&&
			(abs(i-t[1])<=2||abs(i-t[2]<=2)||abs(i-t[3])<=1||i==r))
		{
			change(pe,i);

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

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

			return 0;
		}

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

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


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

typedef unsigned long long ll;
typedef unsigned int uint;

int mod = 998244353;

ll qPow(ll a, ll  b) {
	ll ret = 1;
	while(b) {
		if(b&1)
			ret = ret * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ret;
}

uint C[501][501];
uint inited = 0;
void init() {
	if (inited) return;
	inited = 1;
	memset(C,0,sizeof(C));
	for(uint i=0;i<=500;i++){
		for(uint j=0;j<=i;j++) {
			if(!j)
				C[i][j] = 1;
			else
				C[i][j] = C[i-1][j] + C[i-1][j-1];
			if(C[i][j] >= mod)
				C[i][j] -= mod;

		}
	}
}
ll f[501][501];
int main() {
    uint n, x;
    scanf("%u %u", &n, &x);
	init();

	memset(f,0,sizeof(f));
	for(uint i=2;i<=n;i++){
		for(uint j=1;j<=x;j++) {
			if(j<i) {
				f[i][j] = qPow(j, i);
			} else {
				f[i][j] = qPow(i-1, i);
				for(uint k=2;k<=i;k++) {
					f[i][j] = (f[i][j]+C[i][k]*qPow(i-1,i-k)%mod*f[k][j-i+1]%mod)%mod;
				}
			}
		}
	}

    printf("%llu", f[n][x]);
    return 0;
}


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

typedef long long ll;

int mod = 998244353;

ll qPow(ll a, ll  b) {
	ll ret = 1;
	while(b) {
		if(b&1)
			ret = ret * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ret;
}

int main() {
    int n, x;
    scanf("%d %d", &n, &x);
	ll C[n+1][n+1];
	memset(C,0,sizeof(C));
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++) {
			if(!j)
				C[i][j] = 1;
			else
				C[i][j] = C[i-1][j] + C[i-1][j-1];
				if(C[i][j] >= mod)
				    C[i][j] -= mod;

		}
	}
	ll f[n+1][x+1];
	memset(f,0,sizeof(f));
	for(int i=2;i<=n;i++){
		for(int j=1;j<=x;j++) {
			if(j<i) {
				f[i][j] = qPow(j, i);
			} else {
				f[i][j] = qPow(i-1, i);
				for(int k=2;k<=i;k++) {
					f[i][j] = (f[i][j]+C[i][k]*qPow(i-1,i-k)%mod*f[k][j-i+1]%mod)%mod;
				}
			}
		}
	}

    printf("%lld", f[n][x]);
    return 0;
}


#include <stdio.h>

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

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


#include<stdio.h>
#include<math.h>
int main()
{
    int x1,x2,y1,y2,x,y,a,b;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    scanf("%d %d",&x,&y);

    a=abs(x2-x1);
    b=abs(y2-y1);

    if(a%x!=0||b%y!=0)
    {
          printf("NO\n");
    }

    else if((a/x)%2==(b/y)%2)
    {
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}


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

#define N	50
#define A	26
#define N_	(1 + N + A + 1)
#define M_	(N + N * A + A)
#define INF	0x3f3f3f3f

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

int oo[1 + M_ * 2], oh[1 + M_ * 2];

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

	oo[_] = o, oh[_] = h;
	return _++;
}

int ii[M_], jj[M_], cc[M_ * 2], cost[M_], cost_[M_], m_;
int ae[N_], pi[N_], dd[N_], ff[N_], n_;
int pq[1 + N_], iq[N_], cnt;

void link_(int i, int j, int c, int co) {
	int h = m_++;

	ii[h] = i, jj[h] = j, cc[h << 1] = c;
	cost[h] = co;
	ae[i] = link(ae[i], h << 1);
	ae[j] = link(ae[j], h << 1 | 1);
}

int less(int u, int v) {
	return pi[u] < pi[v] || pi[u] == pi[v] && dd[u] < dd[v];
}

int i2(int i) {
	return (i *= 2) > cnt ? 0 : i < cnt && less(pq[i + 1], pq[i]) ? i + 1 : i;
}

void pq_up(int u) {
	int i, j, v;

	for (i = iq[u]; (j = i / 2) && less(u, v = pq[j]); i = j)
		pq[iq[v] = i] = v;
	pq[iq[u] = i] = u;
}

void pq_dn(int u) {
	int i, j, v;

	for (i = iq[u]; (j = i2(i)) && less(v = pq[j], u); i = j)
		pq[iq[v] = i] = v;
	pq[iq[u] = i] = u;
}

void pq_add_last(int u) {
	pq[iq[u] = ++cnt] = u;
}

int pq_remove_first() {
	int u = pq[1], v = pq[cnt--];

	if (v != u)
		iq[v] = 1, pq_dn(v);
	iq[u] = 0;
	return u;
}

int dijkstra(int s, int t) {
	memset(pi, 0x3f, n_ * sizeof *pi);
	pi[s] = 0, pq_add_last(s);
	while (cnt) {
		int i, d, o;

		i = pq_remove_first();
		d = dd[i] + 1;
		for (o = ae[i]; o; o = oo[o]) {
			int h_ = oh[o];

			if (cc[h_] > 0) {
				int h = h_ >> 1, j = i ^ ii[h] ^ jj[h];
				int p = pi[i] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);

				if (pi[j] > p || pi[j] == p && dd[j] > d) {
					if (pi[j] == INF)
						pq_add_last(j);
					pi[j] = p, dd[j] = d, ff[j] = h_;
					pq_up(j);
				}
			}
		}
	}
	return pi[t] != INF;
}

int trace(int s, int t) {
	while (t != s) {
		int h_ = ff[t], h = h_ >> 1;

		cc[h_]--, cc[h_ ^ 1]++;
		t ^= ii[h] ^ jj[h];
	}
	return 1;
}

int edmonds_karp(int s, int t) {
	int h, f, ans;

	for (h = 0; h < m_; h++) {
		int i = ii[h], j = jj[h];

		pi[j] = min(pi[j], pi[i] + cost[h]);
	}
	for (h = 0; h < m_; h++) {
		int i = ii[h], j = jj[h];

		cost_[h] = cost[h] + pi[i] - pi[j];
	}
	f = 0;
	while (dijkstra(s, t)) {
		f += trace(s, t);
		for (h = 0; h < m_; h++) {
			int i = ii[h], j = jj[h];

			if (pi[i] != INF && pi[j] != INF) {
				/* pi[j] <= pi[i] + cost_[h] */
				/* cost_[h] + pi[i] - pi[j] >= 0 */
				cost_[h] += pi[i] - pi[j];
			}
		}
	}
	ans = 0;
	for (h = 0; h < m_; h++)
		ans += cc[h << 1 | 1] * cost[h];
	return ans;
}

int main() {
	static char cc[N * 2 + 1];
	static int bb[N * 2], kk[A];
	int n, i, a;

	scanf("%d%s", &n, cc), n /= 2;
	n_ = 1 + n + A + 1;
	for (i = 0; i < n * 2; i++)
		scanf("%d", &bb[i]);
	for (i = 0; i < n; i++)
		link_(0, 1 + i, 2, 0);
	for (i = 0; i < n; i++) {
		int j = n * 2 - 1 - i;
		int ai = cc[i] - 'a';
		int aj = cc[j] - 'a';

		for (a = 0; a < A; a++) {
			int b;

			if (a == ai && a == aj)
				b = max(bb[i], bb[j]);
			else if (a == ai)
				b = bb[i];
			else if (a == aj)
				b = bb[j];
			else
				b = 0;
			link_(1 + i, 1 + n + a, 1, -b);
		}
	}
	for (i = 0; i < n * 2; i++) {
		a = cc[i] - 'a';
		kk[a]++;
	}
	for (a = 0; a < A; a++)
		link_(1 + n + a, n_ - 1, kk[a], 0);
	printf("%d\n", -edmonds_karp(0, n_ - 1));
	return 0;
}


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

#define N	50
#define A	26
#define N_	(1 + N + A + 1)
#define M_	(N + N * A + A)
#define INF	0x3f3f3f3f

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

int oo[1 + M_ * 2], oh[1 + M_ * 2];

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

	oo[_] = o, oh[_] = h;
	return _++;
}

int ii[M_], jj[M_], cc[M_ * 2], ww[M_], ww_[M_], m_;
int ae[N_], dd[N_], kk[N_], ff[N_], n_;
int pq[1 + N_], iq[N_], cnt;

void link_(int i, int j, int c, int w) {
	int h = m_++;

	ii[h] = i, jj[h] = j, cc[h << 1] = c;
	ww[h] = w;
	ae[i] = link(ae[i], h << 1);
	ae[j] = link(ae[j], h << 1 | 1);
}

int less(int u, int v) {
	return dd[u] < dd[v] || dd[u] == dd[v] && kk[u] < kk[v];
}

int i2(int i) {
	return (i *= 2) > cnt ? 0 : i < cnt && less(pq[i + 1], pq[i]) ? i + 1 : i;
}

void pq_up(int u) {
	int i, j, v;

	for (i = iq[u]; (j = i / 2) && less(u, v = pq[j]); i = j)
		pq[iq[v] = i] = v;
	pq[iq[u] = i] = u;
}

void pq_dn(int u) {
	int i, j, v;

	for (i = iq[u]; (j = i2(i)) && less(v = pq[j], u); i = j)
		pq[iq[v] = i] = v;
	pq[iq[u] = i] = u;
}

void pq_add_last(int u) {
	pq[iq[u] = ++cnt] = u;
}

int pq_remove_first() {
	int u = pq[1], v = pq[cnt--];

	if (v != u)
		iq[v] = 1, pq_dn(v);
	iq[u] = 0;
	return u;
}

int dijkstra(int s, int t) {
	memset(dd, 0x3f, n_ * sizeof *dd);
	dd[s] = 0, pq_add_last(s);
	while (cnt) {
		int i, k, o;

		i = pq_remove_first();
		k = kk[i] + 1;
		for (o = ae[i]; o; o = oo[o]) {
			int h_ = oh[o];

			if (cc[h_] > 0) {
				int h = h_ >> 1, j = i ^ ii[h] ^ jj[h];
				int d = dd[i] + ((h_ & 1) == 0 ? ww_[h] : -ww_[h]);

				if (dd[j] > d || dd[j] == d && kk[j] > k) {
					if (dd[j] == INF)
						pq_add_last(j);
					dd[j] = d, kk[j] = k, ff[j] = h_;
					pq_up(j);
				}
			}
		}
	}
	return dd[t] != INF;
}

int trace(int s, int t) {
	while (t != s) {
		int h_ = ff[t], h = h_ >> 1;

		cc[h_]--, cc[h_ ^ 1]++;
		t ^= ii[h] ^ jj[h];
	}
	return 1;
}

int edmonds_karp(int s, int t) {
	int h, f, cost;

	for (h = 0; h < m_; h++) {
		int i = ii[h], j = jj[h];

		dd[j] = min(dd[j], dd[i] + ww[h]);
	}
	for (h = 0; h < m_; h++) {
		int i = ii[h], j = jj[h];

		ww_[h] = ww[h] + dd[i] - dd[j];
	}
	f = 0;
	while (dijkstra(s, t)) {
		f += trace(s, t);
		for (h = 0; h < m_; h++) {
			int i = ii[h], j = jj[h];

			if (dd[i] != INF && dd[j] != INF) {
				/* dd[j] <= dd[i] + ww_[h] */
				/* ww_[h] + dd[i] - dd[j] >= 0 */
				ww_[h] += dd[i] - dd[j];
			}
		}
	}
	cost = 0;
	for (h = 0; h < m_; h++)
		cost += ww[h] * cc[h << 1 | 1];
	return cost;
}

int main() {
	static char cc[N * 2 + 1];
	static int bb[N * 2], kk[A];
	int n, i, a;

	scanf("%d%s", &n, cc), n /= 2;
	n_ = 1 + n + A + 1;
	for (i = 0; i < n * 2; i++)
		scanf("%d", &bb[i]);
	for (i = 0; i < n; i++)
		link_(0, 1 + i, 2, 0);
	for (i = 0; i < n; i++) {
		int j = n * 2 - 1 - i;
		int ai = cc[i] - 'a';
		int aj = cc[j] - 'a';

		for (a = 0; a < A; a++) {
			int b;

			if (a == ai && a == aj)
				b = max(bb[i], bb[j]);
			else if (a == ai)
				b = bb[i];
			else if (a == aj)
				b = bb[j];
			else
				b = 0;
			link_(1 + i, 1 + n + a, 1, -b);
		}
	}
	for (i = 0; i < n * 2; i++) {
		a = cc[i] - 'a';
		kk[a]++;
	}
	for (a = 0; a < A; a++)
		link_(1 + n + a, n_ - 1, kk[a], 0);
	printf("%d\n", -edmonds_karp(0, n_ - 1));
	return 0;
}


#include <stdio.h>

long long power_mod (long long a, long long b, long long mod_num) {
  long long ans = 1LL;

  if (b > 0LL) {
    ans = power_mod(a, b/2LL, mod_num);
    ans = (ans * ans) % mod_num;
    if (b%2LL == 1LL) {
      ans = (ans * a) % mod_num;
    }
  }

  return ans;
}

int main () {
  int n = 0;
  int k = 0;

  int res = 0;

  long long ans = 0LL;
  long long mod_num = 1000000007LL;

  long long fact[100001] = {};
  long long invf[100001] = {};

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

  if (n <= k) {
    printf("%lld\n", power_mod(2LL, (long long)n, mod_num));
    return 0;
  }

  fact[0] = 1LL;
  for (int i = 0; i < n; i++) {
    fact[i+1] = fact[i];
    fact[i+1] *= (long long) (i+1);
    fact[i+1] %= mod_num;
  }

  invf[n] = power_mod(fact[n], mod_num-2LL, mod_num);
  for (int i = n; i > 0; i--) {
    invf[i-1] = invf[i];
    invf[i-1] *= (long long)i;
    invf[i-1] %= mod_num;
  }

  for (int i = 0; i <= k; i++) {
    long long tmp = invf[i];
    tmp = (tmp*invf[n-i])%mod_num;
    ans = (ans+tmp)%mod_num;
  }

  ans = (ans*fact[n])%mod_num;
  printf("%lld\n", ans);

  return 0;
}


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

#define maxN 1000001

bool isP[maxN];
int ps[maxN];

bool isPrime( int n ) {
	int i;

	for( i = 2; (long long) i * i <= n; i++ )
		if( n % i == 0 ) return false;

	return true;
}

int main( void ) {
	int i, j, c;

	isP[2] = isP[3] = isP[5] = 1;

	for( i = 7; i < maxN; i += 2 )
		if( isPrime(i) ) isP[i] = 1;

	ps[0] = 0;
	for( i = 1; i < maxN; i++ )
		ps[i] = ps[i-1] + isP[i];

	int a, b, k;
	scanf("%i %i %i", &a, &b, &k);

	int lo = 0, hi = b-a+1, ans = -1, mid;
	while( lo <= hi ) {
		mid = (lo + hi) / 2;

		int cnt = ps[a+mid-1] - ps[a-1];

		bool ok = 1;
		if( cnt < k ) ok = 0;

		for( i = a+1; i <= b-mid+1; i++ )
			if( ps[i+mid-1] - ps[i-1] < k ) ok = 0;

		if( ok ) {
			ans = mid;
			hi = mid - 1;
		} else lo = mid + 1;

	}

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

	return 0;
}


#include<stdio.h>

int check(int w,int p[],int a,int b,int k) {
	int i;
	for(i=a; i<=b-w+1; i++) {
		if(p[i+w-1]-p[i-1]<k) return 0;
	}
	return 1;
}

int main() {
	int isprime[1000005];
	int p[1000005];
	int a,b,k;
	scanf("%d %d %d",&a,&b,&k);
	isprime[0]=0;
	isprime[1]=0;
	for(int i=2; i<=b; i++) {
		isprime[i]=1;
	}
	long long int i,j;
	for(i=2; i<=b; i++) {
		if(isprime[i]) {
			for(j=i*i; j<=b; j+=i) {
				isprime[j]=0;
			}
		}
	}
	for(i=2; i<=b; i++) {
		p[i]=p[i-1]+isprime[i];
	}
	int ans=-1;
	int l=1,r=b-a+1;
	while(l<=r) {
		int m=(l+r)/2;
		if(check(m,p,a,b,k)) {
			ans=m;
			r=m-1;
		}
		else l=m+1;
	}
	printf("%d\n",ans);
	return 0;
}


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

int n;
int a[3];
char dp[300*300*300];
long long step = 0;

void calculate_result(int index, long long index1){
    if(index >= n){
        if(index1 == 0){
           dp[0] = 0;
           return;
        }
        int i, min = 300,j;
        long long index2 = index1;
        for(i=0;i<n;i++){
            min = (min > (index2 % 300) ) ? (index2 % 300) : min;
            index2 /= 300;
        }
        int win = 0;
        for(i=1;i<=min;i++){
            if(dp[index1 - i*step] == 0){
                win = 1;
                break;
            }
        }
        index2 = index1;
        long long pos = 1;
        if(win == 0){
            for(i=0;i<n;i++){
                int num = index2 % 300;
                for(j=1;j<=num;j++){
                    if(dp[index1 - pos*j] == 0){
                        win = 1;
                        break;
                    }
                }
                if( win == 1 )
                    break;
                index2 /= 300;
                pos *= 300;
            }
        }
        if(win == 1)
            dp[index1] = 1;
        return;
    }
    int i;
    for(i=0;i<=a[index];i++){
        calculate_result(index+1, index1*300 + i);
    }
}

int main(){
    scanf("%d", &n);
    int i;
    for(i=0;i<n;i++)
        scanf("%d", &a[i]);
    memset(dp, 0, sizeof(char)*300*300*300);
    for(i=0;i<n;i++)
        step = step*300 + 1;
    if(n == 1){
        if(a[0]){
            printf("BitLGM\n");
        }
        else{
            printf("BitAryo\n");
        }
    }
    else if(n == 3){
        if(a[0] ^ a[1] ^ a[2]){
            printf("BitLGM\n");
        }
        else{
            printf("BitAryo\n");
        }
    }
    else{
        calculate_result(0,0);
        long long ans_index = 0;
        for(i=0;i<n;i++){
            ans_index = ans_index*300 + a[i];
        }
        if(dp[ans_index] == 1){
            printf("BitLGM\n");
        }
        else{
            printf("BitAryo\n");
        }
    }
    return 0;
}


#include <stdio.h>
int c=0;
void F(int l,int r,int a,int b)
{
	if(a<=(r+l-1)/2&&b>(r+l-1)/2)
	{
		//printf("*\n");
		return;
	}
	else if(b<=(r+l-1)/2)
	{
		c++;
		//printf("**\n");
		F(l,(r+l-1)/2,a,b);
		return;
	}
	else if(a>(r+l-1)/2)
	{
		c++;
		//printf("***\n");
		F((r+l-1)/2+1,r,a,b);
		return;
	}
}
int main()
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int count=-1;
	int m=n;
	do{
		n=n/2;
		count++;
	}while(n);
	//printf("%d\n",count);
	if(a>b)
	{
		//printf("##\n");
		F(1,m,b,a);
	}
	else
    {
		//printf("##\n");
		F(1,m,a,b);
	}
    if(c==0)
    {
    	printf("Final!\n");
	}
	else
	{
		printf("%d\n",count-c);
	}
	return 0;
}


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

int main(){
	int n, a, b;
	scanf(" %d %d %d", &n,&a,&b);
	a--;b--;
	int level = 1;
	while (a/2!=b/2){
		level++;
		a/=2;b/=2;
	}
	int final = 0;
	while (n/2){ n/=2; final++; }
	if (level == final){ printf("Final!\n"); } else
	printf("%d\n", level);
	return 0;
}


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

struct Team {
    char name[25];
    int point;
    int score;
    int miss;
}team[4], tmp_team[4];

void swap(int *lhs, int *rhs) {
    int tmp = *lhs;
    *lhs = *rhs;
    *rhs = tmp;
}

void cpy_team() {
    int i;
    for (i = 0; i < 4; ++i) {
        tmp_team[i].point = team[i].point;
        tmp_team[i].score = team[i].score;
        tmp_team[i].miss = team[i].miss;
        strcpy(tmp_team[i].name, team[i].name);
    }
}

char hash_s[4][25];
int hash_idx = 0;
int hash(const char* str) {
    int i;
    for (i = 0; i < hash_idx; ++i) {
        if (!strcmp(str, hash_s[i])) {
            return i;
        }
    }
    strcpy(hash_s[hash_idx++], str);
    return hash_idx - 1;
}

int comp(const void *lhs, const void *rhs) {
    struct Team *sa = (struct Team *)lhs;
    struct Team *sb = (struct Team *)rhs;
    if (sa->point != sb->point) {
        return sa->point < sb->point;
    }
    if (sa->score - sa->miss != sb->score - sb->miss) {
        return sa->score - sa->miss < sb->score - sb->miss;
    }
    if (sa->score != sb->score) {
        return sa->score < sb->score;
    }
    return strcmp(sa->name, sb->name) > 0;
}

int main() {
    //freopen("in.txt", "r", stdin);
    int i, j, ia, ib, na, nb, b_id, opp_id, x, y, min = 10000, cnt[4];
    char sa[25], sb[25];

    memset(cnt, 0, sizeof(cnt));
    for (i = 0; i < 5; ++i) {
        scanf("%s %s %d:%d", sa, sb, &na, &nb);
        ia = hash(sa);
        ib = hash(sb);
        strcpy(team[ia].name, sa);
        strcpy(team[ib].name, sb);
        ++cnt[ia];
        ++cnt[ib];
        /*printf("%d %d %d %d\n", na, nb, ia, ib);*/
        if (nb > na) {
            swap(&na, &nb);
            swap(&ia, &ib);
        }
        /*printf("%d %d\n", na, nb);*/
        if (na > nb) {
            team[ia].point += 3;
        } else if (na == nb) {
            team[ia].point += 1;
            team[ib].point += 1;
        }
        team[ia].score += na;
        team[ia].miss += nb;
        team[ib].score += nb;
        team[ib].miss += na;
    }
    /*for (i = 0; i < 4; ++i) {*/
    /*printf("%d %d %d\n", team[i].point, team[i].score, team[i].miss);*/
    /*}*/
    /*return 0;*/
    for (i = 0; i < 4; ++i) {
        if (!strcmp(team[i].name, "BERLAND")) {
            b_id = i;
        } else if (cnt[i] != 3) {
            opp_id = i;
        }
    }

    cpy_team();
    qsort(tmp_team, 4, sizeof(struct Team), comp);
    /*for (i = 0; i < 4; ++i) {*/
    /*printf("%s\n", tmp_team[i].name);*/
    /*}*/
    /*printf("opp_id = %d, b_id = %d\n", opp_id, b_id);*/
    /*for (i = 0; i < hash_idx; ++i) {*/
    /*printf("%s\n", hash_s[i]);*/
    /*}*/
    for (i = 1; i < 100; ++i) {
        for (j = i - 1; j >= 0; --j) {
            cpy_team();
            tmp_team[b_id].point += 3;
            tmp_team[b_id].score += i;
            tmp_team[opp_id].miss += i;

            tmp_team[b_id].miss += j;
            tmp_team[opp_id].score += j;
            qsort(tmp_team, 4, sizeof(struct Team), comp);
            if (!strcmp(tmp_team[0].name, "BERLAND") || !strcmp(tmp_team[1].name, "BERLAND")) {
                if (i - j < min) {
                    min = i - j;
                    x = i;
                    y = j;
                }
            }
        }
    }
    if (min != 10000) {
        printf("%d:%d\n", x, y);
    } else {
        puts("IMPOSSIBLE");
    }

    return 0;
}


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

struct Team {
    char name[25];
    int point;
    int score;
    int miss;
}team[4], tmp_team[4];

void swap(int *lhs, int *rhs) {
    int tmp = *lhs;
    *lhs = *rhs;
    *rhs = tmp;
}

void cpy_team() {
    int i;
    for (i = 0; i < 4; ++i) {
        tmp_team[i].point = team[i].point;
        tmp_team[i].score = team[i].score;
        tmp_team[i].miss = team[i].miss;
        strcpy(tmp_team[i].name, team[i].name);
    }
}

char hash_s[4][25];
int hash_idx = 0;
int hash(const char* str) {
    int i;
    for (i = 0; i < hash_idx; ++i) {
        if (!strcmp(str, hash_s[i])) {
            return i;
        }
    }
    strcpy(hash_s[hash_idx++], str);
    return hash_idx - 1;
}

int comp(const void *lhs, const void *rhs) {
    struct Team *sa = (struct Team *)lhs;
    struct Team *sb = (struct Team *)rhs;
    if (sa->point != sb->point) {
        return sa->point < sb->point;
    }
    if (sa->score - sa->miss != sb->score - sb->miss) {
        return sa->score - sa->miss < sb->score - sb->miss;
    }
    if (sa->score != sb->score) {
        return sa->score < sb->score;
    }
    return strcmp(sa->name, sb->name) > 0;
}

int main() {
   // freopen("in.txt", "r", stdin);
    int i, j, ia, ib, na, nb, b_id, opp_id, x, y, min = 10000, cnt[4];
    char sa[25], sb[25];

    memset(cnt, 0, sizeof(cnt));
    for (i = 0; i < 5; ++i) {
        scanf("%s %s %d:%d", sa, sb, &na, &nb);
        ia = hash(sa);
        ib = hash(sb);
        strcpy(team[ia].name, sa);
        strcpy(team[ib].name, sb);
        ++cnt[ia];
        ++cnt[ib];
        /*printf("%d %d %d %d\n", na, nb, ia, ib);*/
        if (nb > na) {
            swap(&na, &nb);
            swap(&ia, &ib);
        }
        /*printf("%d %d\n", na, nb);*/
        if (na > nb) {
            team[ia].point += 3;
        } else if (na == nb) {
            team[ia].point += 1;
            team[ib].point += 1;
        }
        team[ia].score += na;
        team[ia].miss += nb;
        team[ib].score += nb;
        team[ib].miss += na;
    }
    /*for (i = 0; i < 4; ++i) {*/
        /*printf("%d %d %d\n", team[i].point, team[i].score, team[i].miss);*/
    /*}*/
    /*return 0;*/
    for (i = 0; i < 4; ++i) {
        if (!strcmp(team[i].name, "BERLAND")) {
            b_id = i;
        } else if (cnt[i] != 3) {
            opp_id = i;
        }
    }

    cpy_team();
    qsort(tmp_team, 4, sizeof(struct Team), comp);
    /*for (i = 0; i < 4; ++i) {*/
        /*printf("%s\n", tmp_team[i].name);*/
    /*}*/
    /*printf("opp_id = %d, b_id = %d\n", opp_id, b_id);*/
    /*for (i = 0; i < hash_idx; ++i) {*/
        /*printf("%s\n", hash_s[i]);*/
    /*}*/
    for (i = 1; i < 100; ++i) {
        cpy_team();
        tmp_team[b_id].point += 3;
        tmp_team[b_id].score += i;
        tmp_team[opp_id].miss += i;
        /*for (j = 0; j < 4; ++j) {*/
            /*printf("%d %d %d\n", tmp_team[j].point, tmp_team[j].score, tmp_team[j].miss);*/
        /*}*/
        /*putchar('\n');*/
        qsort(tmp_team, 4, sizeof(struct Team), comp);
        if (!strcmp(tmp_team[0].name, "BERLAND") || !strcmp(tmp_team[1].name, "BERLAND")) {
            for (j = i - 1; j >= 0; --j) {
                cpy_team();
                tmp_team[b_id].point += 3;
                tmp_team[b_id].score += i;
                tmp_team[opp_id].miss += i;

                tmp_team[b_id].miss += j;
                tmp_team[opp_id].score += j;
                qsort(tmp_team, 4, sizeof(struct Team), comp);
                if (!strcmp(tmp_team[0].name, "BERLAND") || !strcmp(tmp_team[1].name, "BERLAND")) {
                    if (i - j < min) {
                        min = i - j;
                        x = i;
                        y = j;
                    }
                }
            }
        }
    }
    if (min != 10000) {
        printf("%d:%d\n", x, y);
    } else {
        puts("IMPOSSIBLE");
    }

    return 0;
}


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


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


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

#define SIEVE_MAX_PRIME 999983
#define SIEVE_PRIME_COUNT 78498

static bool _sieve_is_composite[SIEVE_MAX_PRIME/2+1] = {}; // 2*i+1
static int64_t _sieve_prime[SIEVE_PRIME_COUNT];

static void generate_primes() {
    // sieve
    _sieve_is_composite[0] = true;
    for(int64_t i = 1, j = 3 ; j*j <= SIEVE_MAX_PRIME ; ++i, j+= 2) {
        if(_sieve_is_composite[i]) continue;
        for(int64_t jj = j*j, ii = (jj-1)/2 ; jj <= SIEVE_MAX_PRIME ; jj += 2*j, ii += j)
            _sieve_is_composite[ii] = true;
    }

    // collect primes
    _sieve_prime[0] = 2;
    for(int64_t i = 0, in = (SIEVE_MAX_PRIME-1)/2, pi = 1 ; i <= in ; ++i) {
        if(_sieve_is_composite[i]) continue;
        assert(pi < SIEVE_PRIME_COUNT); _sieve_prime[pi++] = 2*i+1;
    }
}

static inline bool is_prime(int64_t n) {
    if(n <= SIEVE_MAX_PRIME) {
        if(n == 2) return true;
        else if(n % 2 == 0) return false;
        else return !_sieve_is_composite[(n-1)/2];
    } else {
        for(int pi = 0 ; ; ++pi) { const int64_t p = _sieve_prime[pi];
            if(p*p > n) return true;
            if(n % p == 0) return false;
        }
    }
}

static inline bool is_divisible_by_primes_le(int64_t n, int64_t pm) {
    for(int pi = 0 ; ; ++pi) { const int64_t p = _sieve_prime[pi];
        if(p > pm) return false;
        if(p*p > n) return false;
        if(n % p == 0) return true;
    }
    return true;
}

int main() {
    generate_primes();
    int64_t p,y; scanf("%" PRId64 " %" PRId64 "\n", &p,&y);

    // we need to find largest x such that it is not divisible by primes <= pmax
    // if pmax is larger than sqrt(y) than we need biggest prime less than y
    // otherwise search for not divisible by primes smaller than pmax
    if(p*p > y) {
        for(int i = y ; i > p ; --i) if(is_prime(i)) {
            printf("%d\n", i); return 0;
        }
    } else {
        for(int i = y ; i > p ; --i) if(!is_divisible_by_primes_le(i,p)) {
            printf("%d\n", i); return 0;
        }
    }

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


#include <stdio.h>

int check(int x, int p) {
	int a;

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

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

	scanf("%d%d", &p, &y);
	for (x = y; x > p; x--)
		if (check(x, p)) {
			printf("%d\n", x);
			return 0;
		}
	printf("-1\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
	int q2=2,j,i,n;
	long long a[100];
	scanf("%d",&n);
	for (i=1;i<=100;i++)
	{
		a[i]=((long long)q2-1)*(q2/2);
		q2*=2;
		if (a[i]>100000) break;
	}
	for (j=i;j>=1;j--)
		if (!(n%a[j]))
		{
			printf("%I64d\n",a[j]);
			return 0;
		}
    return 0;
}


#include <stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int k = 1;
    int gtr = 1;
    int res = 0;
    while(res <= n){
        res =(( 2 << k ) - 1) * (2 << (k-1));
        if(n%res == 0) gtr = res;
        k++;
    }
    printf("%d\n",gtr);
	return 0;
}

/* 1512144896144 */


#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<stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
    for(long r=1;r<x;r++)
    {
        for(long c=1;c<x;c++)
        {
        long mul=r*c;
        if(mul>=x)
        {
            mul=10*(mul/x)+(mul%x);
        }
        printf("%ld ",mul);
        }
        puts("");

        }
        return 0;
    }


#include <stdio.h>

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

     scanf("%d", &k);

     for (i = 1; i < k; i++) {
	  for (j = 1; j < k; j++) {
	       int x = i * j, p = 0;
	       int a[3];

	       while (x) {
		    a[p++] = x % k;
		    x /= k;
	       }

	       if (j > 1) {
		    for (l = 2; l >= p; l--) putchar(' ');

		    for (; l >= 0; l--) printf("%d", a[l]);
	       } else {
		    printf("%d", i);
	       }
	  }
	  puts("");
     }

     return 0;
}


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

int len, can;
char in[111];
int dp_max[200][200], dp_min[200][200], ok[200][200];
int alr[200][200];

void solve(int st, int rest){
  int i,j,k;
  int mx, mn;

  if(alr[st][rest]) return;
  alr[st][rest] = 1;

  ok[st][rest] = 0;
  mx = dp_max[st][rest] = -100000;
  mn = dp_min[st][rest] =  100000;

  if(rest >= 2){
    solve(st, rest-2);
    if(ok[st][rest-2]){
      ok[st][rest] = 1;
      if(mx < dp_max[st][rest-2]) mx = dp_max[st][rest-2];
      if(mn > dp_min[st][rest-2]) mn = dp_min[st][rest-2];
    }
  }

  if(st == len){
    if(rest==0){
      ok[st][rest] = 1;
      mx = mn = 0;
    }
  } else {
    solve(st+1, rest);
    if(rest) solve(st+1, rest-1);

    if(in[st]=='F' && ok[st+1][rest]){
      ok[st][rest] = 1;
      if(mx < dp_max[st+1][rest]+1) mx = dp_max[st+1][rest]+1;
      if(mn > dp_min[st+1][rest]+1) mn = dp_min[st+1][rest]+1;
    }

    if(in[st]=='T' && rest && ok[st+1][rest-1]){
      ok[st][rest] = 1;
      if(mx < dp_max[st+1][rest-1]+1) mx = dp_max[st+1][rest-1]+1;
      if(mn > dp_min[st+1][rest-1]+1) mn = dp_min[st+1][rest-1]+1;
    }

    if(in[st]=='T' && ok[st+1][rest]){
      ok[st][rest] = 1;
      if(mx < -dp_min[st+1][rest]) mx = -dp_min[st+1][rest];
      if(mn > -dp_max[st+1][rest]) mn = -dp_max[st+1][rest];
    }

    if(in[st]=='F' && rest && ok[st+1][rest-1]){
      ok[st][rest] = 1;
      if(mx < -dp_min[st+1][rest-1]) mx = -dp_min[st+1][rest-1];
      if(mn > -dp_max[st+1][rest-1]) mn = -dp_max[st+1][rest-1];
    }
  }

  dp_max[st][rest] = mx;
  dp_min[st][rest] = mn;
}

int main(){
  int i,j,k,l,m,n;

  scanf("%s%d",in,&can);
  len = strlen(in);

  rep(j,200) rep(k,200) alr[j][k] = 0;
  solve(0, can);

/*  printf("%d %d\n",dp_max[0][can],dp_min[0][can]);*/
  k = dp_max[0][can]; if(k<0) k=-k;
  l = dp_min[0][can]; if(l<0) l=-l;
  if(k < l) k = l;

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

  return 0;
}


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

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

int main(){
    int i, n, m, mn, mx, t, bitmask;

    while (scanf("%d %d %d %d", &n, &m, &mn, &mx) != EOF){
        bitmask = 0;
        bool flag = true;
        for (i = 0; i < m; i++){
            scanf("%d", &t);
            if (t < mn || t > mx) flag = false;
            if (t == mn) bitmask |= 1;
            if (t == mx) bitmask |= 2;
        }

        if (!flag) puts("Incorrect");
        else{
            if ((n - m) >= (2 - __builtin_popcount(bitmask))) puts("Correct");
            else puts("Incorrect");
        }
    }
    return 0;
}


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

int main()
{
    int n,m,max,min,T[100],t[100],i,a=0,h=1;
    memset(t,0,sizeof(t));
    scanf("%d %d %d %d",&n,&m,&min,&max);
    t[min]=1;
    t[max]=1;
    for (i=0;i<m;i++)
    {
        scanf("%d",&T[i]);
        if(T[i]<min||T[i]>max)
        {
            printf("Incorrect");
            h--;
            break;
        }
        else
        {
            t[T[i]]++;
        }
    }
    if(h)
    {
    for (i=0;i<m;i++)
    {
        if(T[i]==min)
        {
            n++;
            break;
        }
    }
    for (i=0;i<m;i++)
    {
        if(T[i]==max)
        {
            n++;
            break;
        }
    }
    for (i=min;i<=max;i++)
    {
        a+=t[i];
    }
    if (a<=n)
    {
        printf("Correct");
    }
    else
    {
        printf("Incorrect");
    }
    }

    return 0;
}


#include<stdio.h>

int a[5], b[5];

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

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

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

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


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


#include <stdio.h>
#include <assert.h>
int main()
{
    long long unsigned sayi,bolen,cikarmaUcreti,bolmeUcreti,kalan,mod;
    long long unsigned ucret=0,as;
    scanf(" %llu %llu %llu %llu",&sayi,&bolen,&cikarmaUcreti,&bolmeUcreti);
    while(sayi!=1)
    {
        mod=sayi%bolen;
        if(mod)
        {
            sayi=sayi-mod;
            ucret+=cikarmaUcreti*mod;
        }
        else
        {
            kalan=sayi-sayi/bolen;
            if(kalan*cikarmaUcreti>bolmeUcreti)
            {
                sayi/=bolen;
                ucret+=bolmeUcreti;
            }
            else
            {
                ucret+=(sayi-1)*cikarmaUcreti;
                sayi=1;
            }
        }
    }
    printf("%llu\n",ucret);
}


#include <stdio.h>

int main(int argc, const char * argv[])
{
    int n, i1=1, i2, found = 0, sum, nsquare, i, j, k, hypothenuse;
    scanf("%d",&n);
    if (n<5)
    {
        printf("0");
        return 0;
    }
    if (n<5)
    {
        printf("1");
        return 0;
    }

    for (i = 5; i<=n; i++)
    {
        i1 = 1;
        i2 = i-1;
        nsquare = i*i;
        while (1)
        {
            sum = i1*i1 + i2* i2;
            if (sum > nsquare)
                i2--;
            else if (sum < nsquare)
                i1++;
            else
            {
                found++;
                i2--;
                i1++;
            }
            if (i2<i1)
                break;
        }
    }
    printf("%d", found);
    return 0;
}


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

typedef long long int ll;
typedef long double ld;

#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define rep(i,n)   for(int (i) = 0; (i) < (n); ++(i))
int MAX(int a, int b) {
	return (a>b)?a:b;
}
int main(int argc, char const *argv[]) {
	int n,k,x;
	scanf("%d%d", &n, &k);
	int *have = (int*)calloc(5,sizeof(int));
	int *cnt = (int*)calloc(5,sizeof(int));
	have[2]=2*n;have[4]=n;
	rep(i,k) {
		scanf("%d",&x);
		while(x>=3) {
			if(have[4]>0)
				x-=4,have[4]--;
			else if(have[2]>0)
				x-=2,have[2]--;
			else {
				printf("NO\n");
				return 0;
			}
		}
		if (x>0)
			cnt[x]++;
	}
	while(cnt[2]>0) {
		if (have[2]>0)
			cnt[2]--,have[2]--;
		else if (have[4]>0)
			cnt[2]--, have[4]--,have[1]++;
		else
			cnt[2]--,cnt[1]+=2;
	}
	if (cnt[1]>have[1]+have[2]+have[4]*2) {
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	return 0;
}


#include <stdio.h>
int main (void)
{
	int rows, groups, i;
	scanf ("%d", &rows);
	scanf ("%d", &groups);

	int rows_of_4_seats = rows;
	int rows_of_2_seats = 2 * rows;
	int seats_for_1_warroir_that_remain_from_HERE = 0;
	int supa_dupa_place_for_1x2_or_2x1 = 0;
	for (i = 0; i < groups; i++){
		int current_group;
		scanf("%d", &current_group);
		if (seats_for_1_warroir_that_remain_from_HERE == 2){
			        seats_for_1_warroir_that_remain_from_HERE = 0;
				supa_dupa_place_for_1x2_or_2x1++;
		}
		//We lost 2 * rows of 4 seats and have 2 * seats_for_1_warroir_that_remain_from_HERE, and 2 * seats_for_1_warroir_that_remain_from_HERE transform in supa_dupa_place_for_1x2_or_2x1
		//like this
		////1100 -> 1103
		////2200 -> 2203

		//Checking: can we put count of warriors that is devoded into 4
		int group_of_4_warriors = current_group / 4;
		if (rows_of_4_seats - group_of_4_warriors >= 0)
			rows_of_4_seats -= group_of_4_warriors;
		else if (rows_of_2_seats - group_of_4_warriors * 2 >= 0) // *2 becouse group of 4 warriors take 2 * row of 2 seats
			rows_of_2_seats -= group_of_4_warriors * 2;
		else if (supa_dupa_place_for_1x2_or_2x1 - group_of_4_warriors * 2 >= 0)
			supa_dupa_place_for_1x2_or_2x1 -= group_of_4_warriors * 2;
		else if (rows_of_4_seats + rows_of_2_seats / 2 + supa_dupa_place_for_1x2_or_2x1 / 2 >= group_of_4_warriors){
			group_of_4_warriors -= rows_of_4_seats;
			rows_of_4_seats = 0;
			if (group_of_4_warriors * 2 > rows_of_2_seats){
				group_of_4_warriors -= rows_of_2_seats / 2;
				rows_of_2_seats = 0;
			}
			else {
				rows_of_2_seats -= group_of_4_warriors * 2;
				group_of_4_warriors = 0;
			}
			supa_dupa_place_for_1x2_or_2x1 -= group_of_4_warriors * 2;
		}
		else {
			puts("NO");
			return 0;
		}
		//Checking: can we put remaining warriors that is devided into 2
		int remain_of_group_of_4_warriors_grouped_by_2 = (current_group % 4) / 2;
		if (rows_of_2_seats - remain_of_group_of_4_warriors_grouped_by_2 >= 0)
			rows_of_2_seats = rows_of_2_seats - remain_of_group_of_4_warriors_grouped_by_2;
		else if (rows_of_4_seats - remain_of_group_of_4_warriors_grouped_by_2 >= 0){//HERE
			rows_of_4_seats = rows_of_4_seats - remain_of_group_of_4_warriors_grouped_by_2;//HERE
			seats_for_1_warroir_that_remain_from_HERE++;//HERE
		}
		else if (supa_dupa_place_for_1x2_or_2x1 - remain_of_group_of_4_warriors_grouped_by_2 >= 0)
			supa_dupa_place_for_1x2_or_2x1 = supa_dupa_place_for_1x2_or_2x1 - remain_of_group_of_4_warriors_grouped_by_2;
		else {
			puts("NO");
			return 0;
		}
		fprintf(stderr, "now we have %d %d %d %d\n", rows_of_4_seats, rows_of_2_seats, seats_for_1_warroir_that_remain_from_HERE, supa_dupa_place_for_1x2_or_2x1);//debug
		//Checking remaining
		int remaining_of_all = (current_group % 4) % 2;
		if (remaining_of_all == 0)
			continue;
		//By the way if we are here, remaining_of_all == 1, but i anyway will use remaining_of_all instead 1, becouse I can
		if (seats_for_1_warroir_that_remain_from_HERE - remaining_of_all >= 0)
			seats_for_1_warroir_that_remain_from_HERE--; //I lied, here and somewhere I will use "--" and "++"
		else if (rows_of_4_seats - remaining_of_all >= 0){
			rows_of_4_seats--;
			rows_of_2_seats++; //We are lost rows of 4 seats, but on other half of rows of 4 seats we still have 2 free seats
		}
		else if (rows_of_2_seats - remaining_of_all >= 0)
			rows_of_2_seats--;
		else if (supa_dupa_place_for_1x2_or_2x1 - remaining_of_all >= 0){
			supa_dupa_place_for_1x2_or_2x1--;
			seats_for_1_warroir_that_remain_from_HERE++; //HERE we take only 1/2 of supa_dupa... and we can use that 1/2 of supa_dupa only for 1 man
		}
		else{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main(void){
  int x1,x2,y1,y2,dist,half,n;
  int zerodis1,zerodis2;
  scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
  half=n*2;
  zerodis1=(x1>=y1)?(x1+y1):((half*2)-x1-y1);
  zerodis2=(x2>=y2)?(x2+y2):((half*2)-x2-y2);
  dist=abs(zerodis1-zerodis2);
  if(dist>half) dist=half*2-dist;
  printf("%d\n",dist);
  return 0;
}


#include <stdio.h>

#define N	100

int aa[N], bb[N];

int dfs(int i) {
	if (bb[i])
		return 0;
	bb[i] = 1;
	return dfs(aa[i]) + 1;
}

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

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

int main() {
	int i, n;
	long long t;

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

		scanf("%d", &a);
		a--;
		aa[i] = a;
		if (bb[a]) {
			printf("-1\n");
			return 0;
		}
		bb[a] = 1;
	}
	for (i = 0; i < n; i++)
		bb[i] = 0;
	t = 1;
	for (i = 0; i < n; i++)
		if (!bb[i]) {
			int cnt = dfs(i);

			if (cnt % 2 == 0)
				cnt /= 2;
			t = lcm(t, cnt);
		}
	printf("%lld\n", t);
	return 0;
}


#include <stdio.h>

long long int GCD(long long int a,long long int b){
	if(b==0)return a;
	if(a<b)return(GCD(b,a));
	else return(GCD(b,a%b));
}

long long int LCM(long long int a,long long int b){
	long long int c=GCD(a,b);
	return((a*b)/c);
}

int bfs(int i,int visited[],int count,int index,int A[]){
	if(i==index){
		if(count%2)return count;
		else return(count/2);
	}
	if(visited[i]==0){
		visited[i]=1;
		return(bfs(A[i],visited,count+1,index,A));
	}
	return(-1);
}

int main(){
	int i,n,A[105],cycle,visited[105];
	long long int ans;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
		A[i]--;
	}
	for(i=0;i<n;i++)visited[i]=0;
	ans=1;
	for(i=0;i<n;i++){
		if(visited[i]==0){
			visited[i]=1;
			cycle=bfs(A[i],visited,1,i,A);
			if(cycle==-1){
				ans=-1;
				break;
			}
			else ans=LCM(ans,cycle);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


/*
 * =====================================================================================
 *
 *       Filename:  Solitaire.c
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  2012年07月25日 13时47分01秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *   Organization:
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAXN 55
#define OP1 1
#define OP2 3
int dp[MAXN][MAXN][MAXN][MAXN];
typedef struct Card {
	char val;
	char suit;
} Card_t;
Card_t cards[MAXN];
/*
int dfs(Card_t *cards, int n, int op) {
	if(n == 1) return 1;
	if(n - op <=0 ) return 0;

	if(cards[n].val == cards[n - op].val) {
		int tmpSuit = cards[n - op].suit;
		cards[n - op].suit = cards[n].suit;
		if(dfs(cards, n-1, OP1) || dfs(cards, n-1, OP2))
			return 1;
		else
			cards[n - op].suit = tmpSuit;
	}
	if(cards[n].suit == cards[n - op].suit) {
		int tmpVal = cards[n- op].val;
		cards[n - op].val = cards[n].val;
		if(dfs(cards, n-1, OP1) || dfs(cards, n-1, OP2))
			return 1;
		else
			cards[n -op].val = tmpVal;
	}
	return 0;
}
*/

int calc(int n, int a, int b, int c) {
	if(n == 1) return 1;
	if(n == 2) {
		if(cards[a].val == cards[b].val || cards[a].suit == cards[b].suit) return 1;
		else return 0;
	}
	if(n == 3) {
	//	printf("n-%d a-%d b-%d c-%d\n",n,a,b,c);
		if(cards[c].val == cards[b].val || cards[c].suit == cards[b].suit) {
	//		printf("cards[%d].val=%c cards[%d].val=%c\n",c,cards[c].val,b,cards[b].val);
			if(cards[c].val == cards[a].val || cards[c].suit == cards[a].suit)
				return 1;
			else
				return 0;
		}
		else
			return 0;
	}
	return 0;
}

int main() {
	int i,j,k,l,n;
	char tmp;

	while(scanf("%d", &n) != EOF) {
		scanf("%c",&tmp);
		memset (cards, 0, sizeof cards);
		memset (dp, 0, sizeof dp);
		for(i=1; i <=n ; ++i)
			if (i < n)
				scanf("%c%c%c", &cards[i].val, &cards[i].suit, &tmp);
			else
				scanf("%c%c", &cards[i].val, &cards[i].suit);

		for(i=1; i<=n; ++i) {
			for(j=1; j<=n; ++j) {
				for(k=1; k<=n; ++k) {
					if(j == k) continue;
					for(l=1; l<=n; ++l)  {
						if(k == l) continue;
						if(i >= 4) {
							if(cards[i-3].val == cards[l].val || cards[i-3].suit == cards[l].suit)
								dp[i][j][k][l] = dp[i-1][l][j][k];
							if(cards[k].val == cards[l].val || cards[k].suit == cards[l].suit)
								dp[i][j][k][l] = dp[i][j][k][l] || dp[i-1][i-3][j][l];
						}
						else
							dp[i][j][k][l] = calc(i,j,k,l);
	//					printf("dp[%d][%d][%d][%d]:%d\n",i,j,k,l,dp[i][j][k][l]);
					}
				}
			}
		}

		if(n == 1) {
			if(calc(1, 1, 0, 0)) puts("YES");
			else puts("NO");
		}
		else if(n == 2) {
			if(calc(2, 1, 2, 0)) puts("YES");
			else puts("NO");
		}
		else {
			if(dp[n][n-2][n-1][n]) puts("YES");
			else puts("NO");
		}
	}
	return 0;
}


# include <stdio.h>
# include <math.h>
int main()
{
int n;
scanf("%d",&n);
int p=n;
if(n==0){
printf("1");
return 0;}
printf("%d",4*(int)(n*sqrt(2.0)));
return 0;
}


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

int n;

int special(int x, int y) {
  long long xx = x, yy = y, nn = n; xx *= x; yy *= y; nn *= n;
  return xx + yy <= nn;
}

int main(void) {
  int i, j, r = 0, s = 0;
  scanf("%d", &n);
  j = n;
  if (n == 0) r = 1;
  else if (n == 1) r = 4;
  else {
    for (i = 0; i <= j; ++i) {
      while (!special(i, j)) --j;
      if (i < j) ++r;
      if (i == j) ++s;
    }
    r = 2*r + s; r += r - 1; r += r - 2;
  }
  printf("%d\n", r);
  exit(EXIT_SUCCESS);
}


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

char mp[10][10];
int p;

void dfs(int x,int y)
{
	int i,j,sum;
	int tx=x;
	int ty=y;
	sum=0;
	for(i=tx;i>=0;i--)
		if(mp[i][ty]!='X') break;else sum++;//������
	for(i=tx+1;i<10;i++)
		if(mp[i][ty]!='X') break;else sum++;//������

	//if(sum>=5) {printf("sum1======%d\n",sum);p=1;}
	if(sum>=5) p=1;
	sum=0;
	for(i=ty;i>=0;i--)
		if(mp[tx][i]!='X') break;else sum++;//������
	for(i=ty+1;i<10;i++)
		if(mp[tx][i]!='X') break;else sum++;//������

	//if(sum>=5) {printf("sum2======%d\n",sum); p=1;}
	if(sum>=5) p=1;
	sum=0;
	for(i=tx,j=ty;i>=0&&j>=0;i--,j--)
		if(mp[i][j]!='X') break;else sum++;//��������
	for(i=tx+1,j=ty+1;i<10&&j<10;i++,j++)
		if(mp[i][j]!='X') break;else sum++;//��������

	//if(sum>=5) {printf("sum3======%d\n",sum);p=1;}
	if(sum>=5) p=1;
	sum=0;
	for(i=tx,j=ty;i>=0&&j<10;i--,j++)
		if(mp[i][j]!='X') break;else sum++;//��������
	for(i=tx+1,j=ty-1;j>=0&&i<10;i++,j--)
		if(mp[i][j]!='X') break;else sum++; //��������

	//if(sum>=5) {printf("sum4======%d\n",sum);p=1;}
	if(sum>=5) p=1;
}

int main()
{
	int i,j;
	for(i=0;i<10;i++)
		scanf("%s",mp[i]);
	p=0;
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(mp[i][j]=='.')
			{
				mp[i][j]='X';
				dfs(i,j);
				mp[i][j]='.';
			}
		}
	}
	if(p) printf("YES\n");
	else printf("NO\n");
	return 0;
}