#include <stdio.h>

long long fac[250005];

int main()
{
    int n, m;
    long long ans = 0;
    scanf("%d%d", &n, &m);

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

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

    ans = (ans * (n + 1)) % m;
    if(ans % 2 == 1) ans = (ans + m) / 2;
    else ans /= 2;

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


#include <stdio.h>
int main()
{
	long long int i,j,k=0,n,m,s=0;
	long long int fact[250001];
	fact[1]=1;fact[0]=1;
	scanf("%lld%lld",&n,&m);
	for(i=2;i<=250000;i++)
	fact[i]=(fact[i-1]*i)%m;
	for(i=1;i<=n;i++)
	{
		k=k+(n-i+1)*(fact[i]*fact[n-i+1]%m);
		k=k%m;
	}
	printf("%lld",k);
}


#include<stdio.h>
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	long long int fact[2500006];
	long long int i;
	fact[0] = 1;
	for (i = 1; i < 2500006; i++)
		fact[i] = fact[i - 1] * i % m;
	long long int ans = 0;
	for (i = 0; i < n; i++)
		ans = (ans + (n - i) * fact[i + 1] % m * fact[n - i] % m) % m;
	printf("%lld\n", ans);
	return 0;
}


#include <stdio.h>

long long fac[250005];

int main()
{
    int n, m;
    long long ans = 0;
    scanf("%d%d", &n, &m);

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

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

    ans = (ans * (n + 1)) % m;
    if(ans % 2 == 1) ans = (ans + m) / 2;

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


#include<stdio.h>
#define F for(i=1;i<=n;i++)
long long i,j,m,n,r,f[250107]={1};
int main(){
	scanf("%lli%lli",&n,&m);
	F f[i]=f[i-1]*i%m;
	F r=(r+f[i]*f[n-i+1]%m*(n-i+1)%m)%m;
	return printf("%lli",r);
}


#include <stdio.h>
#include <stdlib.h>
int isright(long long v,long long k,long long n)
{
    long long sum=v;
    long  long value =v/k;
    while(value!=0)
    {
        sum+=value;
        value=value/k;
    }
    if (sum==n)
    {
        return 1;
    }

    else if (sum>n)
    {
        return 2;

    }

    return 0;
}

int main()
{

    long long  lines;
    long long low=0,mid=0,value,min=1,high;
    int k;
  scanf("%I64d",& lines);
    scanf("%d",&k);
    high=lines;
    while(low<high)
    {
        mid=(low+high)/2;
        value=isright(mid,k,lines);
        if(value==1)
        {
            min=mid;
            break;
        }
        else if (value==0)
        {
            low=mid+1;
            mi=low;
        }
        else if (value==2)
        {
            min=mid;
            high=mid;
        }

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


/* Coached by rainboy */
#include <stdio.h>

int lines(int n, int k) {
	return n == 0 ? 0 : lines(n / k, k) + n;
}

int binsearch(int n, int k) {
	int lower, upper, v;

	lower = 0, upper = n;
	while (upper - lower > 1) {
		v = (low + high) / 2;
		if (lines(v, k) < n)
			lower = v;
		else
			upper = v;
	}
	return upper;
}

int main() {
	int n, k;

	scanf("%d%d", &n, &k);
	printf("%d\n", binsearch(n, k));
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int k ;
    long long n , ans;
    cin >> n >> k;
    ans = ((n * (k - 1) / k ) / k + 1) * k;
    cout << ans ;
    return 0;
}


#include <stdio.h>

int main()
{
	int n, k, v, i, sum;
	scanf("%d%d", &n, &k);
	v = n * (k - 1) / k;
	do
	{
		sum = 0;
		i = 1;
		while (v / i > 0)
		{
			sum += v / i;
			i *= k;
		}
		if (sum < n)
			++v;
		else
			break;
	}
	while (1);
	printf("%d\n", v);
	return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int temp1,i,temp,sum=0,ans=0;
    int p=1;
    for(i=n;i>=1;i--)
    {
                     p=0;
                     sum=0;
    temp=i;
    ans=temp;
    temp1=i;
    while(temp1>0)
    {

     sum+=temp1;
     p++;
     //printf("for %d : %d\n",p,sum);
       temp1=temp/(int)pow(k,p);
     }
     if(sum<n)
     {
              //printf("%d\n",sum);
     break;
     }
     }
     printf("%d\n",i+1);
     //getch();
     return 0;
     }


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

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

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

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


#include <stdio.h>
#include <math.h>
long long fact(long long int n)
{
    long long int ans = 1;
    for (long long int i = 2; i<=n; i++)
        ans*=i;
    return ans;
}

int main()
{
    int h[10] = {},f[10] = {},p,f0,fn0;
    long long int n,temp,ctr = 0;
    scanf("%I64d",&n);
    while(n>0)
    {
        h[n%10]++;
        n/=10;
    }
    while (1)
    {
        f0 = 0, fn0 = 0,p = 9;
        f[9]++;
        while(f[p] > h[p] && p>0)
        {
            f[p] = 0;
            f[--p]++;
        }
        if (f[0] > h[0])
            break;
        f0 = f[0];
        for (int i = 1; i<10; i++)
            fn0+=f[i];
        temp = fn0 * fact(fn0 + f0 -1);
        for (int i = 0; i<10; i++)
        {
            temp/=(f[i] > 0)?f[i] : 1;
        }
        ctr+=temp;
    }
    printf("%I64d",ctr);
    return 0;
}


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

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

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

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


#include <stdio.h>

#define MD	1000000007

int power(int a, int b) {
	int p;

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

int solve(int x) {
	return power(2, x - 1);
}

int sign(int x) {
	int a, cnt;

	cnt = 0;
	for (a = 2; a * a <= x; a++) {
		if (x % a == 0) {
			x /= a;
			cnt++;
		}
		if (x % a == 0)
			return 0;
	}
	if (x > 1)
		cnt++;
	return cnt % 2 == 0 ? 1 : -1;
}

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

	scanf("%d%d", &x, &y);
	if (y % x != 0) {
		printf("0\n");
		return 0;
	}
	y /= x;
	sum = 0;
	for (a = 1; a * a <= y; a++)
		if (y % a == 0) {
			sum = ((long long) sum + (sign(a) * solve(y / a) % MD) + MD) % MD;
			if (y / a != a)
				sum = ((long long) sum + (sign(y / a) * solve(a)) + MD) % MD;
		}
	printf("%d\n", sum);
	return 0;
}


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

#define MODULUS 1000000007
#define _       % MODULUS

#define MAX_RG  76543
#define MAX_PR  7654

int prime_ct = 0, primes[MAX_PR];
unsigned char not_prime[MAX_RG] = { 0 };

void sieve()
{
    int i, j;
    not_prime[0] = not_prime[1] = 1;
    for (i = 2; i < MAX_RG; ++i) {
        if (!not_prime[i]) primes[prime_ct++] = i;
        for (j = 0; j < prime_ct && i * primes[j] < MAX_RG; ++j)
            not_prime[i * primes[j]] = 1;
    }
}

int mu(int n)
{
    int i, ret = 1;
    for (i = 0; i < prime_ct; ++i) {
        if (n % primes[i] == 0) {
            n /= primes[i];
            ret = -ret;
            if (n % primes[i] == 0) return 0;
        }
    }
    if (n > 1) ret = -ret;
    return ret;
}

int qpow(int base, int exp)
{
    int ans = 1;
    for (; exp; exp >>= 1, base = ((int64_t)base * base)_)
        if (exp & 1) ans = ((int64_t)ans * base)_;
    return ans;
}

int count_seqs(int sum, int gcd_mul)
{
    if (sum % gcd_mul != 0) return 0;
    return qpow(2, sum / gcd_mul - 1);
}

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

    if (y % x != 0) { puts("0"); return 0; }
    y /= x;

    sieve();

    int64_t ans = 0;
    int i;
    for (i = 1; i * i <= y; ++i) if (y % i == 0) {
        ans += count_seqs(y, i) * mu(i);
        if (i * i != y)
            ans += count_seqs(y, y / i) * mu(y / i);
    }

    printf("%I64d\n", (ans _ + MODULUS)_);

    return 0;
}


#include <stdio.h>

#define MD	1000000007

int power(int a, int b) {
	int p;

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

int solve(int x) {
	return (power(2, x - 1) + MD) % MD;
}

int sign(int x) {
	int a, cnt;

	cnt = 0;
	for (a = 2; a * a <= x; a++) {
		if (x % a == 0) {
			x /= a;
			cnt++;
		}
		if (x % a == 0)
			return 0;
	}
	if (x > 1)
		cnt++;
	return cnt % 2 == 0 ? 1 : -1;
}

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

	scanf("%d%d", &x, &y);
	if (y % x != 0) {
		printf("0\n");
		return 0;
	}
	y /= x;
	sum = 0;
	for (a = 1; a * a <= y; a++)
		if (y % a == 0) {
			sum = (sum + (sign(a) * solve(y / a)) + MD) % MD;
			sum = (sum + (sign(y / a) * solve(a)) + MD) % MD;
		}
	printf("%d\n", sum);
	return 0;
}


#include <stdio.h>

#define MD	1000000007

int power(int a, int b) {
	int p;

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

int solve(int x) {
	return power(2, x - 1);
}

int sign(int x) {
	int a, cnt;

	cnt = 0;
	for (a = 2; a * a <= x; a++) {
		if (x % a == 0) {
			x /= a;
			cnt++;
		}
		if (x % a == 0)
			return 0;
	}
	if (x > 1)
		cnt++;
	return cnt % 2 == 0 ? 1 : -1;
}

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

	scanf("%d%d", &x, &y);
	if (y % x != 0) {
		printf("0\n");
		return 0;
	}
	y /= x;
	sum = 0;
	for (a = 1; a * a <= y; a++)
		if (y % a == 0) {
			sum = (sum + (sign(a) * solve(y / a) % MD) + MD) % MD;
			if (y / a != a)
				sum = (sum + (sign(y / a) * solve(a) % MD) + MD) % MD;
		}
	printf("%d\n", sum);
	return 0;
}


#pragma region kyopuro_templates
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
#include<time.h>
#include<ctype.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<62)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 20)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5
#define PI 3.141592653589793238

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
void cin(ll *n){ scanf("%lld",&(*n)); }
void PriAll1(ll a[], ll n){ rep(i,0,n){ printf("%lld",a[i]); if(i!=n-1) printf(" "); }PN; }
ll min(ll a, ll b){ return a < b ? a : b; }
ll max(ll a, ll b){ return a < b ? b : a; }
// ll max2(ll a,ll b){return a>=b?a:b;}
// ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[]){ll b=INF;rep(i,0,n) b=min(b,a[i]);return b;}
ll maxn(ll n, ll a[]){ll b=-INF;rep(i,0,n) b=max(b,a[i]);return b;}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
double POW_d(double a, double b){double c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
ll base(ll n, ll a, ll i){return i==1?n%a:base(n/a,a,i-1);}
ll is_inArr1(ll x, ll n){ return ( x<0 || x>=n ) ? 0 : 1 ; }
ll is_inArr2(ll y, ll x, ll h, ll w){ return ( y<0 || y>=h || x<0 || x>=w ) ? 0 : 1 ; }

void lr_lower( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am < val ?  ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
void lr_upper( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am <= val ?  ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
int cmp_lower( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a>=b ? 1 : 0 ) : ( a>b ? 1 : 0 ) ; }
int cmp_upper( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a<=b ? 1 : 0 ) : ( a<b ? 1 : 0 ) ; }
// return smallest p  which meets  a[p]==val :1  >=:2   >:3
ll lower_bound( ll a[], int l, int r, ll val , int type ){  while(r-l>1) lr_lower(&l,&r,a[ (l+r)/2 ],val,type);  return cmp_lower(a[l],val,type) ? l : cmp_lower(a[r],val,type) ? r : -1;  }
// return biggest p  which meets   a[p]==val :1  <=:2   <:3
ll upper_bound( ll a[], int l, int r, ll val , int type ){  while(r-l>1) lr_upper(&l,&r,a[ (l+r)/2 ],val,type); return cmp_upper(a[r],val,type) ? r : cmp_upper(a[l],val,type) ? l : -1; }
// count i  which meets ai==x
ll count(ll a[], int l, int r, ll x){  int p = lower_bound(a,l,r,x,1);  return p==-1 ? 0 : upper_bound(a,p,r,x,1)-p+1; }

ll *factors[2] , fac_cnt=0 , is_factor_prepared=0;
ll factor_pre(){  rep(i,0,1){ if(is_factor_prepared++) return 0; }  ll tmp=(1e6)/2+1, fac_tmp[tmp];  rep(i,0,tmp){fac_tmp[i]=i?2*i+1:2;}  rep(i,1,tmp){if(fac_tmp[i]){  repp(j,3,tmp/(2*i+1)+1,2 ){  if( j*(2*i+1)<tmp ) fac_tmp[ (j*(2*i+1)-1)/2 ]=0;  }  }else continue;}  rep(i,0,tmp){if(fac_tmp[i]){  rep(j,0,2){ factors[j] = (ll*) realloc( factors[j] , sizeof(ll)*( fac_cnt +1 ) );  factors[j][j?fac_cnt++:fac_cnt]=j?0:fac_tmp[i];  }  } }  return 0;  }
ll factor(ll n, ll new_common_plus){ factor_pre();  rep(i,0,fac_cnt){ ll cnt=0; rep(j,0,1){ while( ( cnt+= n %factors[0][i]==0 ? 1 : 0 )  && (n/=factors[0][i]) %factors[0][i]==0 ) continue; } factors[1][i]= new_common_plus==1 ? cnt :  new_common_plus==2 ? max(factors[1][i],cnt) : factors[1][i]+cnt ;  if( factors[0][i]> n ) break; } return n; }
ll judge_prime(ll n){ factor_pre(); rep(i,0,fac_cnt){ if(n<factors[0][i]*factors[0][i] || n==factors[0][i]) break; else if(n%factors[0][i]==0) n/=n; }  return n==1?0:1; }

#pragma region mod
ll *mf_arr, *inv_arr, *finv_arr, is_minv_made, is_mf_made, num_of_inv=3*1e5+10;
void makeinv(ll n , ll mod){
    if(is_minv_made++) return;
    inv_arr = (ll*) malloc((n + 1) * sizeof(ll));
    finv_arr = (ll*) malloc((n + 1) * sizeof(ll));
    inv_arr[1] = finv_arr[0] = finv_arr[1] = 1;
    rep(i,2,n+1){
        inv_arr[i] = mod - inv_arr[mod % i] * (mod / i) % mod;
        finv_arr[i] = finv_arr[i - 1] * inv_arr[i] % mod;
    }
}
void make_mf(ll n, ll mod){
    if(is_mf_made++) return;
    mf_arr = (ll*) malloc((n + 1) * sizeof(ll));
    ll x = mf_arr[0] = mf_arr[1] = 1;
    rep(i,2,n+1){
        x = x * i % mod;
        mf_arr[i]=x;
    }
}
ll m_inv(ll x, ll mod, ll is_fac){ makeinv(num_of_inv, mod);  return is_fac ? finv_arr[x] : inv_arr[x]; }
ll m_f(ll x, ll mod){ make_mf(num_of_inv, mod);  return mf_arr[x]; }
ll mod_nck(ll n, ll k, ll mod){ return m_f(n, mod) * m_inv(k, mod, 1) % mod * m_inv(n-k, mod, 1) % mod; }
ll m_p(ll r, ll n, ll mod){
    ll t = 1, s = r;
    while(n > 0){
        t = (n & 1) ? t * s % mod : t;
        s = s * s % mod;
        n >>= 1;
    }
    return r ? t : 0;
}
#pragma endregion mod

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
int cmp_string( const void * a , const void * b ) {  return strcmp( (char *)a , (char *)b ); }  // qsort((void*)s,n,sizeof(s[0]),int_sort );
int cmp_char(const void * a, const void * b) { return *(char *)a - *(char *)b;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
// void sort_string(int n,int size,char s[][size]){ qsort( (void*)s , n , sizeof(s[0]) , cmp_string ); }
// void sort_char(char *s){ qsort( (void *)s , strlen(s) , sizeof(char) , cmp_char ); }
// ll unique_string(ll n ,ll size, char s[][size]){ ll ans=1; rep(i,1,n) if( strcmp(s[i],s[i-1]) ) ans++; return ans; }
// ll unique_num(ll n , ll a[]){ ll ans=1; rep(i,1,n) if( a[i]!=a[i-1] ) ans++; return ans; }

ll compare(ll a, ll b){ return a<b?-1:a>b?1:0; }
typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ){
    ll pa=((fr*)p)->a; ll qa=((fr*)q)->a;  return compare(pa,qa);
}
int cmp2( const void *p, const void *q ){
    ll pa=((fr*)p)->a; ll qa=((fr*)q)->a;  return compare(qa,pa);
}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

void sort_partial(ll a[],int begin,int end,int is_increase){
    ll *b;  b = (ll *) malloc( sizeof(ll)*(end-begin) );

    rep(i,begin,end) b[i-begin]=a[i];
    if(is_increase) sortup(b,end-begin); else sortdown(b,end-begin);
    rep(i,begin,end) a[i]=b[i-begin];
}

// ll pre_rui[2151][1151];
// ll ruiseki[2151][1151];
// void rui_make(ll h, ll w){
//     rep(i,0,h){
//         rep(j,0,w){
//             ruiseki[i+1][j+1]=ruiseki[i+1][j]+pre_rui[i][j];
//         }
//         rep(j,0,w){
//             ruiseki[i+1][j+1]+=ruiseki[i][j+1];
//         }
//     }
// }

// ll rui_get(ll st_y, ll st_x, ll en_y, ll en_x, ll h, ll w){
//     if(en_y<0) return 0;
//     if(en_x<0) return 0;
//     if(st_y>h) return 0;
//     if(st_x>w) return 0;
//     if(st_y<0) st_y=0;
//     if(st_x<0) st_x=0;
//     if(en_y>h) en_y=h;
//     if(en_x>w) en_x=w;
//     ll val=0;
//     val+=ruiseki[en_y][en_x];
//     val-=ruiseki[en_y][st_x];
//     val-=ruiseki[st_y][en_x];
//     val+=ruiseki[st_y][st_x];
//     return val;
// }

#pragma region AVL
/*---------------------------AVL start--------------------------------*/
//https://qiita.com/mikecat_mixc/items/e9f8248de2ae7f7a0a29
typedef struct node_AVL_set{
    ll val;
    int diff;
    int cnt;
    struct node_AVL_set *child[2];
}AVL_set;
void AVL_set_inside_rotate(AVL_set **node, int is_right){
    int l = is_right==false , r = is_right==true , sign = is_right ? 1 : -1;
    if((*node)->child[l] != NULL){
        AVL_set* left = (*node)->child[l];
        int a= (*node)->diff * sign , b= left->diff * sign ,na,nb;
        if(b+1){
            na=a-1-b;
            nb= (a-b) ? b-1 : a-2;
        }else{
            na=a-1;
            nb= a ? b-1 : a+b-2;
        }
        (*node)->diff = na * sign;
        left->diff = nb * sign;
        /* rotate-> */
        (*node)->child[l] = (*node)->child[l]->child[r];
        left->child[r] = *node;
        *node = left;
    }
}
int AVL_set_inside_update(AVL_set **node, ll data, int add){
    if(*node == NULL){
        if(add==2){
            *node = (AVL_set*)malloc(sizeof(AVL_set));
            (*node)->val = data;
            (*node)->cnt = 1;
            (*node)->diff = 0;
            (*node)->child[0] = NULL;
            (*node)->child[1] = NULL;
        }
        return add==2 ? *node != NULL : 0;
    }else{
        int l, delta, delta_sign; AVL_set *next_node;
        if(data == (*node)->val){
            if(add==2){
                (*node)->cnt++;
                return 0;
            }else{
                if( add && (*node)->cnt > 1 ){
                    (*node)->cnt--; return 0;
                }else{
                    if((*node)->child[1] == NULL){
                        next_node = (*node)->child[0];
                        free(*node);
                        *node = next_node;
                        return -1;
                    }else if((*node)->child[0] == NULL){
                        next_node = (*node)->child[1];
                        free(*node);
                        *node = next_node;
                        return -1;
                    }else{
                        for(next_node = (*node)->child[0];
                        next_node->child[1] != NULL;
                        next_node = next_node->child[1]);
                        (*node)->val = next_node->val;
                        l=0;
                        delta_sign=1;
                        delta = AVL_set_inside_update(&(*node)->child[l], next_node->val, add);
                    }
                }
            }
        }else{
            l = data >= (*node)->val ? 1 : 0;
            delta_sign = data < (*node)->val ? 1 : -1;
            delta = AVL_set_inside_update(&(*node)->child[l], data, add);
        }
        if( delta ){
            int orig_diff = (*node)->diff;
            int do_rotate = 0, rotate_l , diff_sign , rotate_right;
            (*node)->diff += delta * delta_sign;
            if((*node)->diff > 1){
                do_rotate = 1;
                rotate_l = 0;
                diff_sign = 1;
                rotate_right = 1;
            }else if((*node)->diff < -1){
                do_rotate = 1;
                rotate_l = 1;
                diff_sign = -1;
                rotate_right = 0;
            }
            if(do_rotate){
                int child_diff = (*node)->child[rotate_l]->diff;
                if((*node)->child[rotate_l]->diff * diff_sign < 0){
                    AVL_set_inside_rotate(&(*node)->child[rotate_l], !rotate_right);
                }
                AVL_set_inside_rotate(node, rotate_right);
                return delta < 0 && child_diff != 0 ? -1 : 0;
            }
            if     (delta > 0 && orig_diff == 0) return 1;
            else if(delta < 0 && orig_diff != 0) return -1;
            else                                 return 0;
        }else{
            return 0;
        }
    }
}

void AVL_set_inside_print(const AVL_set *node, int depth){
    if(node == NULL) return;
    AVL_set_inside_print(node->child[1], depth + 1);
    printf("%lld %d\n", node->val,node->cnt);
    AVL_set_inside_print(node->child[0], depth + 1);
}
void AVL_set_inside_free(AVL_set *node){
    if(node == NULL) return;
    AVL_set_inside_free(node->child[0]);
    AVL_set_inside_free(node->child[1]);
    free(node);
}
ll AVL_set_inside_count(AVL_set *root, ll val){
    AVL_set *node; node = root;
    while(node){
        if     (val < node->val) node = node->child[0];
        else if(val > node->val) node = node->child[1];
        else                     return node->cnt;
    }
    return 0;
}

int AVL_set_lowcomp(ll node, ll val, int type){
    if(node==val){
        if(type!=3) return 0;
        else return 1;
    }
    if(node<val) return 1;
    if(node>val) return -1;
    return 0;
}
// return smallest p  which meets  a[p]==val :1  >=:2   >:3
AVL_set* AVL_set_inside_lowerbound(AVL_set *root, ll val, int type){
    AVL_set *node; node = root;
    while(node){
        int com=AVL_set_lowcomp(node->val,val,type);
        if(com==0) return node;
        if(com==1) node = node->child[1];
        if(com==-1){
            AVL_set *small;
            small=AVL_set_inside_lowerbound(node->child[0],val,type);
            if(type==1){
                return small;
            }else{
                if(small!=NULL) return small;
                else return node;
            }
        }
    }
    return node;
}

int AVL_set_upcomp(ll node, ll val, int type){
    if(node==val){
        if(type!=3) return 0;
        else return -1;
    }
    if(node<val) return 1;
    if(node>val) return -1;
    return 0;
}
// return biggest p  which meets   a[p]==val :1  <=:2   <:3
AVL_set* AVL_set_inside_upperbound(AVL_set *root, ll val, int type){
    AVL_set *node; node = root;
    while(node){
        int com=AVL_set_upcomp(node->val,val,type);
        if(com==0) return node;
        if(com==-1) node = node->child[0];
        if(com==1){
            AVL_set *big;
            big=AVL_set_inside_upperbound(node->child[1],val,type);
            if(type==1){
                return big;
            }else{
                if(big!=NULL) return big;
                else return node;
            }
        }
    }
    return node;
}

ll AVL_set_inside_minmax(AVL_set *root, int type){
    while(root->child[type] !=NULL)  root= root->child[type];
    return root->val;
}
void AVL_set_inside_swap(AVL_set **node1, AVL_set **node2){
    AVL_set *tmp;  tmp=*node1; *node1=*node2; *node2=tmp;
}

#define set_MAX_SIZE 514511
ll set_main( int command , int set_num , ll val ,ll option){
    static bool set_is_init=false;
    static AVL_set *set_pointer[set_MAX_SIZE];
    static ll set_siz[set_MAX_SIZE];
    if(!set_is_init){ set_is_init=true; rep(i,0,set_MAX_SIZE){ *(set_pointer+i) = NULL; set_siz[i]=0; } }
    if(command==-1){ AVL_set_inside_print( set_pointer[set_num] ,0); }
    if(command==1){ AVL_set_inside_count(set_pointer[set_num],val) ? 1 : set_siz[set_num]++;  AVL_set_inside_update( &set_pointer[set_num] , val , 2 ); }
    if(command==2){ return AVL_set_inside_count(set_pointer[set_num],val); }
    if(command==3){ ( AVL_set_inside_count(set_pointer[set_num],val) > 1 ) ? 1 : set_siz[set_num]--;  AVL_set_inside_update( &set_pointer[set_num] , val,1); }
    if(command==4){ set_siz[set_num]--; AVL_set_inside_update( &set_pointer[set_num] , val , 0 ); }
    if(command==5){ set_siz[set_num]=0; AVL_set_inside_free( set_pointer[set_num] ); set_pointer[set_num] = NULL; }
    if(command==6){ return set_siz[set_num]; }
    if(command==7){ return AVL_set_inside_minmax(set_pointer[set_num],1); }
    if(command==8){ return AVL_set_inside_minmax(set_pointer[set_num],0); }
    if(command==9){ AVL_set_inside_swap(&set_pointer[set_num],&set_pointer[val]); }
    if(10<=command&&command<=12){
        AVL_set *lowbound = AVL_set_inside_lowerbound(set_pointer[set_num],val,command-9);
        if(lowbound==NULL) return option;
        else return lowbound->val;
    }
    if(13<=command&&command<=15){
        AVL_set *upbound = AVL_set_inside_upperbound(set_pointer[set_num],val,command-12);
        if(upbound==NULL) return option;
        else return upbound->val;
    }
    return 0;
}

void set_print(int set_num){ set_main(-1,set_num,0,0); }
void set_insert(int set_num, ll val){ set_main(1,set_num,val,0); }
ll set_count(int set_num, ll val){ return set_main(2,set_num,val,0); }
void set_erase(int set_num, ll val, int is_all){ if(is_all) set_main(4,set_num,val,0); else set_main(3,set_num,val,0); }
void set_clear(int set_num){ set_main(5,set_num,0,0); }
ll set_size(int set_num){ return set_main(6,set_num,0,0); }
ll set_max(int set_num){ return set_main(7,set_num,0,0); }
ll set_min(int set_num){ return set_main(8,set_num,0,0); }
void set_swap(int set_num1, int set_num2){ set_main(9,set_num1,set_num2,0); }

// return smallest p  which meets  a[p]==val :1  >=:2   >:3
ll set_lowerbound(int set_num, ll val, int type, ll error){
    return set_main(9+type,set_num,val,error);
}
// return biggest p  which meets   a[p]==val :1  <=:2   <:3
ll set_upperbound(int set_num, ll val, int type, ll error){
    return set_main(12+type,set_num,val,error);
}

/*
insert *
size *
clear *
erase *
count *
max *
min *
swap *
begin x
end x
merge  source の要素のキーと等価なキーの要素がある場合、その要素は source から抽出されない
lower_bound *
upper_bound *
*/

// ll map_main()

/*---------------------------AVL start--------------------------------*/

#pragma endregion AVL

#pragma endregion kyopuro_templates

#pragma region vector

typedef struct vector vector;
typedef struct vector {
    int n, max, data_size;
    void *data;
    void (*push)(vector*, void*);
    void (*set)(vector*, int, void*);
    ll (*get)(vector*, int);
    double (*get_double)(vector*, int);
    int (*size)(vector*);
} vector;

void vector_push(vector *v, void *x) {
    if (v->n == v->max) {
        v->max *= 2;
        assert((v->data = realloc(v->data, v->max * v->data_size)) != NULL);
    }
    if(x==NULL){
        memset(v->data + v->data_size * v->n, 0, v->data_size);
    }else{
        memcpy(v->data + v->data_size * v->n, x, v->data_size);
    }
    v->n++;
}

void vector_set(vector *v, int idx, void *x) {
    if(x == NULL){
        memset(v->data + v->data_size * idx, 0, v->data_size);
    }else{
        memcpy(v->data + v->data_size * idx, x, v->data_size);
    }
}

void *vector_get_internal(vector *v, int idx) {
    return (v->data + v->data_size * idx);
}
ll vector_get(vector *v, int idx){
    ll ret=0;
    if(v->data_size == 8) ret = *(ll*)vector_get_internal(v, idx);
    if(v->data_size == 4) ret = *(int*)vector_get_internal(v, idx);
    if(v->data_size == 2) ret = *(bool*)vector_get_internal(v, idx);
    return ret;
}
double vector_get_double(vector *v, int idx){
    assert(v->data_size == sizeof(double));
    return *(double*)vector_get(v, idx);
}

int vector_size(vector *v) {
    return v->n;
}

vector *vector_init(int n, int data_size) {
    assert(n != 0);
    vector *ret = (vector *)malloc(sizeof(vector));
    ret->n = 0;
    ret->max = n;
    ret->data_size = data_size;
    ret->data = malloc(n * data_size);

    ret->push=vector_push;
    ret->set=vector_set;
    ret->size=vector_size;
    ret->get = vector_get;
    ret->get_double = vector_get_double;

    memset(ret->data, 0, n * ret->data_size);
    return ret;
}

// void vector_free(vector *v){
//     free(v->data);
//     free(v->get);
//     free(v->get_double);
//     free(v->push);
//     free(v->set);
//     free(v->size);
//     free(v);
// }

#pragma endregion vector

#pragma region max_flow
#define flow_t long long
// #define flow_t double
typedef struct Dinic Dinic;
typedef struct Dinic {
    int n;
    vector **to;
    vector **cap;
    vector **rev;
    vector *min_cost;
    vector *iter;
    void (*add)(Dinic*, int, int, flow_t);
    flow_t (*max_flow)(Dinic*, int, int);
} Dinic;

void Dinic_add_edge(Dinic *d, int from, int to, flow_t cap) {
    vector_push(d->rev[from], (void*)&d->to[to]->n);
    vector_push(d->rev[to], (void*)&d->to[from]->n);
    vector_push(d->to[from], (void*)&to);
    vector_push(d->to[to], (void*)&from);
    vector_push(d->cap[from], (void*)&cap);
    vector_push(d->cap[to], NULL);
}

bool Dinic_bfs(Dinic *d, int s, int t) {
    int init = -1;
    rep(i, 0, d->n) vector_set(d->min_cost, i, (void*)&init);
    vector *q = vector_init(1, sizeof(int));
    vector_set(d->min_cost, s, NULL);
    int head = 0;
    q->push(q, (void*)&s);
    while(head != q->n && vector_get(d->min_cost, t) == -1){
        int p = q->get(q, head);
        head++;
        rep(i, 0, d->to[p]->n) {
            int to = vector_get(d->to[p], i);
            if(vector_get(d->cap[p], i) > 0 && vector_get(d->min_cost, to) == -1){
                ll cost = vector_get(d->min_cost, p) + 1;
                vector_set(d->min_cost, to, (void*)&cost);
                q->push(q, (void*)&to);
            }
        }
    }
    return vector_get(d->min_cost, t) != -1;
}

flow_t Dinic_dfs(Dinic *d, int idx, int t, flow_t flow) {
    if(idx == t) return flow;
    rep(i, vector_get(d->iter, idx), d->cap[idx]->n){
        vector_set(d->iter, idx, (void*)&i);
        flow_t cap = vector_get(d->cap[idx], i);
        int to = vector_get(d->to[idx], i);
        if(cap > 0 && vector_get(d->min_cost, idx) < vector_get(d->min_cost, to)) {
            flow_t delta = Dinic_dfs(d, to, t, flow < cap ? flow : cap);
            if(delta > 0) {
                cap -= delta;
                vector_set(d->cap[idx], i, (void*)&cap);
                int rev = vector_get(d->rev[idx], i);
                flow_t rev_cap = vector_get(d->cap[to], rev) + delta;
                vector_set(d->cap[to], rev, (void*)&rev_cap);
                return delta;
            }
        }
    }
    return 0;
}

flow_t Dinic_max_flow(Dinic *d, int s, int t) {
    flow_t flow = 0;
    while(Dinic_bfs(d, s, t)) {
        rep(i, 0, d->n) vector_set(d->iter, i, NULL);
        flow_t f = 0;
        while((f = Dinic_dfs(d, s, t, INF)) > 0) flow += f;
    }
    return flow;
}

Dinic *Dinic_init(int n) {
    Dinic *ret = (Dinic *)malloc(sizeof(Dinic));
    ret->n = n;
    ret->to = (vector **)malloc(n * sizeof(vector*));
    ret->cap = (vector **)malloc(n * sizeof(vector*));
    ret->rev = (vector **)malloc(n * sizeof(vector*));
    rep(i, 0, n) {
        ret->to[i] = vector_init(1, sizeof(int));
        ret->cap[i] = vector_init(1, sizeof(flow_t));
        ret->rev[i] = vector_init(1, sizeof(int));
    }
    ret->min_cost =vector_init(n, sizeof(int));
    ret->iter = vector_init(n, sizeof(int));
    ret->add = Dinic_add_edge;
    ret->max_flow = Dinic_max_flow;
    return ret;
}
#pragma endregion max_flow

char s[1151154];
void solve(){
    // fgets(s,sizeof(s),stdin);
    ll n;
    ll ans=0;
    cin(&n);
    // scanf("%s",s);
    ll a[3];
    ll b[3];
    rep(i,0,3){
        cin(&a[i]);
    }
    rep(i,0,3){
        cin(&b[i]);
    }
    ll ma=0;
    // ll mi=INF;
    ma=min(a[0],b[1])+min(a[1],b[2])+min(a[2],b[0]);
    Dinic *d=Dinic_init(8);
    d->add(d,6,0,a[0]);
    d->add(d,6,1,a[1]);
    d->add(d,6,2,a[2]);

    d->add(d,0,3,INF);
    d->add(d,0,5,INF);
    d->add(d,1,3,INF);
    d->add(d,1,4,INF);
    d->add(d,2,4,INF);
    d->add(d,2,5,INF);

    d->add(d,3,7,b[0]);
    d->add(d,4,7,b[1]);
    d->add(d,5,7,b[2]);
    printf("%lld %lld\n",n-d->max_flow(d,6,7),ma);
}

int main(void){
    ll T=1;
    // cin(&T);
    rep(i,0,T){ solve(); }
    return 0;
}

/*
    while (ng + 1 < ok) {
        ll p = ng + (ok - ng) / 2;
        ll cnt = 0;
        rep(i,0,n){
            cnt += (a[i] + p - 1) / p - 1;
        }
        if (cnt <= k) ok = p; else ng = p;
    }
*/
// 10^18 2^60 3^38 5^26


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

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

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

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

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

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

	return 0;
}


#include <stdio.h>

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

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

int main() {
    int n;
    int a1, a2, a3;
    int b1, b2, b3;

    scanf("%d", &n);
    scanf("%d %d %d", &a1, &a2, &a3);
    scanf("%d %d %d", &b3, &b1, &b2);

    int min_ans = 0;
    min_ans = max(min_ans, a1 - b2 - b3);
    min_ans = max(min_ans, a2 - b3 - b1);
    min_ans = max(min_ans, a3 - b1 - b2);

    int max_ans = min(a1, b1) + min(a2, b2) + min(a3, b3);

    printf("%d %d", min_ans, max_ans);
}


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

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

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

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

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

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

	return 0;
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int  n=input.nextInt();
		String str=Integer.toString(n,8);
		int sum=0;
		for(int i=0;i<str.length();i++) {
			if(str.charAt(i)=='1')
				sum++;
		}
		System.out.println(sum);

	}

}


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


#include<cstdio>
int a,sum=0;
int main()
{
    scanf("%d",&a);
    while(a)
    {
        if(a%8==1){
            sum++;
        }
        a/=8;
    }
    printf("%d\n",sum);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
int a[1000];
int main()
{
//	freopen("datain.txt","r",stdin);
//	freopen("datain.txt","w",stdout);
	int n;
	scanf("%d",&n);
	int i=1;
	int len;
	int cnt=0;
	while(n>0)
    {
        a[i]=n%8;
        n /=8;
        i++;
        len = i;
    }
    for(i=1;i<=len;i++)
    {
        if(a[i]==1) cnt++;
    }
    printf("%d",cnt);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


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

#define N	1000000
#define MD	1000000007

int d_, x_, y_;

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

		gcd(b, a % b);
		t = x_ - a / b * y_, x_ = y_, y_ = t;
	}
}

int inv(int a) {
	gcd(a, MD);
	return x_;
}

int main() {
	static int dp[N];
	int n, k, h;
	long long x, ans, f;

	scanf("%d%d", &n, &k);
	if (k > n - 1)
		k = n - 1;
	f = 1;
	for (h = 0; h <= k; h++) {
		dp[h] = 1;
		f = f * (h + 1) % MD;
	}
	x = k, ans = k + 1;
	for (h = k + 1; h < n; h++) {
		dp[h] = x * inv(h) % MD;
		x = (x + dp[h] - dp[h - k]) % MD;
		ans = (ans + dp[h]) % MD;
		f = f * (h + 1) % MD;
	}
	ans = (n - ans) % MD;
	for (h = 1; h < n; h++)
		ans = ans * h % MD;
	if (ans < 0)
		ans += MD;
	printf("%lld\n", ans);
	return 0;
}


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

#define int long long

int s,k,sone;

int f[10000];
int ans[10000];

void make()
{
  sone=s;
  int sum=0;
  int i;
  int last=0;
  for(i=k;;i++)
    {
      if(i==k)
	{f[i]=sum=1; continue;}
      f[i]=sum;
      //      printf("f[%lld]=%lld\n",i,f[i]);
      if(f[i]>s) break;
      sum+=f[i];
      sum-=f[i-k];
    }
  int index=0;
  for(;i>=0;i--)
    {
      if(f[i]<=s)
	s-=f[i],ans[index++]=f[i];
      if(f[i]==0) break;
    }
  printf("%lld\n",index);
  for(i=0;i<index;++i)
    printf("%lld ",ans[i]);
}

main()
{
  scanf("%lld%lld",&s,&k);
  make();
  return 0;
}


#include <iostream>
#include <stdio.h>

int main()
{
    int n, x, i, m, r, min_n = 10004, max_m = -1;
    scanf("%d%d%d", &n, &m, &r);
    for(i = 0; i < n; i++)
    {
        scanf("%d", &x);
        if(x < min_n) min_n = x;
    }
    for(i = 0; i < m; i++)
    {
        scanf("%d", &x);
        if(x > max_m) max_m = x;
    }
    i = (max_m * (r / min_n)) + (r % min_n);
    if(i > r) printf("%d\n", i);
    else printf("%d\n", r);
    return 0;
}


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


#include<stdio.h>
int main()
{
    int n,m,r,i,j,less,max,buy,sell,t;
    scanf("%d%d%d",&n,&m,&r);
    int s[n],x[m];
    for(i=0;i<n;i++)
    scanf("%d",&s[i]);

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

    less=s[0];
    for(i=0;i<n;i++)
    {
        if(s[i]<less)
        less=s[i];
    }
    max=x[0];
    for(i=0;i<m;i++)
    {
        if(x[i]>max)
        max=x[i];
    }
    buy=r/less;
    t=r%less;
    sell=max*buy+t;
    if(sell>r)
    printf("%d",sell);
    else
    printf("%d",r);

},


#include <stdio.h>
int main()
{
     int n,m,r;
     scanf("%d %d %d",&n,&m,&r);
     int s[n],b[m];
     int i,j;
     for(i=0;i<n;i++)
     {
          scanf("%d",&s[i]);
     }
     int min=s[0];
     for(i=0;i<n;i++)
     {
          if(s[i]<min)
          min=s[i];
     }
     for(j=0;j<m;j++)
     {
          scanf("%d",&b[j]);
     }
     int max=b[j];
     for(j=0;j<m;j++)
     {
          if(b[j]>max)
          max=b[j];
     }
     int ans;
     if(max>min)
     {
          ans=*(max-min)*5)+r;
     }
     else
     ans=r;
     printf("%d",ans);
}


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

void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
	int n,m,r;
	scanf("%d %d %d",&n,&m,&r);
	int s[n];
	int s_min;
	int b_temp = 0;
	int b_max = 0;
	int buy = 0;
	int flag = 0;
	for(int i=0;i<n;i++){
		scanf("%d",&(s[i]));
		if(i == 0){
			s_min = s[i];
		}
		if(s[i]< s_min){
			s_min = s[i];
		}
	}
	for(int i=0;i<m;i++){
		scanf("%d",&b_temp);
		if(b_temp > b_max){
			b_max = b_temp;
		}
	}
	if(s_min >= b_max){
		printf("%d\n",r);
	}
	else{
		buy = r/s_min;
		r = r-b*s_min;
		int count = r + buy*b_max;
		printf("%d\n",count);
	}

}


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

int main()
{
    long long n,y,prey,ans=0,i;
    scanf("%I64d",&n);
    if(n==0)
        printf("1\n");
    else
    {
        prey = sqrt(n*n - 1);
        ans++;
        for(i=2;i<=n;i++)
        {
            y = sqrt(n*n-i*i);
                    //printf("%lld %lld prevy y\n",prey,y);
            if(y==prey)
                ans++;
            else
                ans += prey - y;
            prey = y;
        }
        ans--;
                        //printf("%lld check\n",ans);
        ans *= 4;

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


#include<stdio.h>
main()
{
    int ix;
    long long int l,r,m,n,x,y,n2,dc,nd2;
    scanf("%I64d",&n);
    if(n<=1)
    {
        if(n==0)
        printf("1");
        else
        printf("4");
        return 0;
    }
    l=1;r=n;nd2=n*n;
    nd2/=2;
    while(l+1<r)
    {
        m=(l+r)/2;
        if(m*m>nd2)
        r=m;
        else
        l=m;
    }
    if(r*r<=nd2)
    x=r;
    else
    x=l;

    n2=n*n;
    dc=2*x*x+2*x+1;

    ix=x;
    if(dc-n2<=0)
    {
        printf("%d",8*ix+4);
    }
    else
    {
        printf("%d",8*ix);
    }
    return 0;

}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define For(i,m,n) for(i=m;i<n;i++)
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
#define MAXN 205

main()
{
    long long n;
    scanf("%I64d",&n);
    if(n==0) printf("1\n");
    else printf("%I64d\n",4*(long long)floor(n*sqrt(2)));
    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 <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;
  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", n == 0 ? 1 : n == 1 ? 4 : r);
  exit(EXIT_SUCCESS);
}


#include<stdio.h>
#define int long long int
signed main()
{
    int x,y,s[3];
    scanf("%d%d",&x,&y);
    int a=0,i,ans=0,sum=0,count1=0;
    s[1]=y;
    s[2]=y;
    s[3]=y;
    while(count1<3)
    {
	for(i=1;i<=3;i++)
	{
	    if(count1==3)
		break;
	    sum=s[1]+s[2]+s[3];
	    a=sum-s[i]-1;
	    if(a>=x)
	    {
		s[i]=x;
		count1++;
	    }
	    else
		s[i]=a;
	    ans++;
	    printf("%d %d %d %d %d\n",a,count,s[1],s[2],s[3]);
	}
    }
    printf("%d",ans);
}


#include<stdio.h>
main()
{
	int d,x,y,a,b,c,i=0;
	scanf("%d%d",&x,&y);
	a=b=c=y;
	while(a<x)
	{
		d=(x<b+c-1?x:b+c-1);
		a=b; b=c; c=d;
		i++
	}
	printf("%d",i);

}


#include<stdio.h>
int main()

{
	int x=0, y=0;
	scanf("%d %d", &x, &y);
	int p,q,r;
	p=y;
	q=y;
	r=y;
	int count=0;

	while(1<2
	{
		if(q+r-1<x)
		{
			p=q+r-1;
			count++;
		}
		else
		{
			p=x;
			count++;
		}

		if((p==x)&&(q==x)&&(r==x))
			break;

		if(p+r-1<x)
		{
			q=p+r-1;
			count++;
		}
		else
		{
			q=x;
			count++;
		}

		if((p==x)&&(q==x)&&(r==x))
			break;

		if(p+q-1<x)
		{
			r=p+q-1;
			count++;
		}
		else
		{
			r=x;
			count++;
		}

		if((p==x)&&(q==x)&&(r==x))
			break;
	}

	printf("%d", count);
	return 0;

}


#include<stdio.h>
#define int long long int
signed main()
{
    int x,y,s[4]={0};
    scanf("%d%d",&x,&y);
    int a=0,i,ans=0,sum=0,count1=0;
    s[1]=y;
    s[2]=y;
    s[3]=y;
    while(count1<3)
    {
	for(i=1;i<=3;i++)
	{
	    if(count1==3)
		break;
	    sum=s[1]+s[2]+s[3];
	    a=sum-s[i]-1;
	    if(a>=x)
	    {
		s[i]=x;
		count1++;
	    }
	    else
		s[i]=a;
	    ans++;
	    printf("%d %d %d %d %d\n",a,count1,s[1],s[2],s[3]);
	}
    }
    printf("%d",ans);
}


#include<stdio.h>

int main(){
	int x,y,n=3,a,b,c,flag=1,i=0,temp;
	scanf("%d",&x);
	scanf("%d",&y);
	if(y+y>x){
		printf("3");
	}
	else if(y+y==x){
		printf("4");
	}
	else{
		a=y;
		b=y;
		c=y;
		while(flag){
			c=a+b-1;
			i++;
			if(c>x){
				n=n+i;
				printf("%d",n);
				flag=0;
			}
			else if(c==x){
				n=n+i-1;
				printf("%d",n);
				flag=0;
			}
			else{
				if(a<c){
					temp=a;
					a=c;
					c=temp;
				}
				if(b<c){
					temp=b;
					b=c;
					c=temp;
				}
			}
		}
	}
	return 0;
}


#include <stdio.h>
int x,y,z,xx,yy,zz,ans,a[7];
int main()
{
	int i;
	scanf("%d%d%d%d%d%d",&x,&y,&z,&xx,&yy,&zz);
	for(i=1;i<=6;i++) scanf("%d",&a[i]);
	if(y<0) ans += a[1];
	if(y>yy) ans += a[2];
	if(z<0) ans += a[3];
	if(z>zz) ans += a[4];
	if(x<0) ans += a[5];
	if(x>xx) ans += a[6];
	printf("%d",ans);
	return 0;
}


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

int main()
{
    int X,Y,Z,x,y,z,i,j,num[10];
    while(1){
    scanf("%d %d %d",&x,&y,&z);
    scanf("%d %d %d",&X,&Y,&Z);
    for (i=0;i<6;i++)
    {
        scanf("%d",&num[i]);
    }
    j=0;
    if (x>X)
    {
        j+=num[5];
    }
    else if (x<0)
    {
        j+=num[4];
    }
    if (y>Y)
    {
        j+=num[1];
    }
    else if (y<0)
    {
        j+=num[0];
    }
    if (z>Z)
    {
        j+=num[3];
    }
    else if (z<0)
    {
        j+=num[2];
    }

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


#include<stdio.h>
int main()
{
int x,y,z;
int x,yy,z1;
int a[7];
    scanf("%d%d%d",&x,&y,&z);
    scanf("%d%d%d",&x1,&yy,&z1);
    for (int i=1;i<=6;i++) scanf("%d",&a[i]);

    int ans=0;
    if (y<0) ans+=a[1];
    if (y>yy) ans+=a[2];
    if (z<0) ans+=a[3];
    if (z>z1) ans+=a[4];
    if (x<0) ans+=a[5];
    if (x>x1) ans+=a[6];
    printf("%d\n",ans);

    return 0;
}


#include<stdio.h>
int main()
{
int x,y,z;
int x1,yy,z1;
int a[7];
    scanf("%d%d%d",&x,&y,&z);
    scanf("%d%d%d",&x1,&yy,&z1);
    for (int i=1;i<=6;i++) scanf("%d",&a[i]);

    int ans=0;
    if (y<0) ans+=a[1];
    if (y>yy) ans+=a[2];
    if (z<0) ans+=a[3];
    if (z>z1) ans+=a[4];
    if (x<0) ans+=a[5];
    if (x>x1) ans+=a[6];
    printf("%d\n",ans);

    return 0;
}


#include<stdio.h>
int main()
{
int x,y,z;
int x1,y1,z1;
int a[7];
    scanf("%d%d%d",&x,&y,&z);
    scanf("%d%d%d",&x1,&yy,&z1);
    for (int i=1;i<=6;i++) scanf("%d",&a[i]);

    int ans=0;
    if (y<0) ans+=a[1];
    if (y>yy) ans+=a[2];
    if (z<0) ans+=a[3];
    if (z>z1) ans+=a[4];
    if (x<0) ans+=a[5];
    if (x>x1) ans+=a[6];
    printf("%d\n",ans);

    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;
}


/* https://codeforces.com/contest/1185/submission/55797221 (Dukkha) */
#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>
int main()
{
    int c,n,i,ar[10],flag=-1;
    long int a,b,x=10;
    scanf("%ld %ld %d",&a,&b,&c);
    a=a%b;
    for(i=0;i<=10;i++)
    {

        a=a*10;
        ar[i]=a/b;
        a=a%b;
        if(ar[i]==c)
        {
            flag=i;
            break;
        }
    }
    if(flag==-1)
     printf("-1\n");
     else
        printf("%d\n",flag+1);

        return 0;

}


#include <stdio.h>

int main()
{
	double a,b;
	int c,ans=-1;
	scanf("%lf %lf %d",&a,&b,&c);
	double frac=fracinp-fracint;
	/*printf("%0.18lf\n", frac);*/
	int arr[18]={0};int i;
	for (i = 0; i < 18; i++)
	{
		int dig=10*frac;
		arr[i]=dig;
		frac=(10*frac)-dig;
	}
	/*for (i = 0; i < 6; i++)
	{
		printf("%d", arr[i]);
	}
	printf("\n");*/
	for (i = 0; i < 18; i++)
	{
		if (arr[i]==c){
			ans=i+1;
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}


[Project]
FileName=1.dev
Name=Project1
Type=1
Ver=2
ObjFiles=
Includes=
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=
Linker=
IsCpp=0
Icon=
ExeOutput=
ObjectOutput=
LogOutput=
LogOutputEnabled=0
OverrideOutput=0
OverrideOutputName=
HostApplication=
UseCustomMakefile=0
CustomMakefile=
CommandLine=
Folders=
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=0000000000000000000000000

[VersionInfo]
Major=1
Minor=0
Release=0
Build=0
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=
FileDescription=Developed using the Dev-C++ IDE
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=
AutoIncBuildNr=0
SyncProduct=1


#include <stdio.h>
unsigned int a,b;
char c;
int main()
{
	float f,l;
	int k,i=0;
	bool key=false;
	scanf("%d %d %d",&a,&b,&c);
	f=(float)a/b*10;
	k=(int)f;

	while (i<1000 && key==false)
	{
		k=k%10;
		if (k==c) key=true;
		l=(a-k*0.1*b)*10;
		a=(int)l;
		f=(float)a/b*10;printf("%f\n",f);
		k=(int)f;
		i++;
	}
	if (key==true) printf("%d",i);
	else printf("-1");
}


#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int pos=0,brk=0,x=10000000;
	while(x--){
		int rem = a%b;
		if(rem==0){
			brk=1;
			break;
		}
		a*=10;
		while(a<b)
		{
			pos++;
			a*=10;
		}
		int que=a/b;
		a=a%b;
		pos++;
		if(que==c){
			break;
		}
	}
	if(brk)
	{
		if(c==0)
			printf("%d\n",pos+1);
		else
			printf("-1\n");
	}
	else
	{
		if(x>0){
			printf("%d\n",pos);
		}
		else
			printf("-1\n");
	}
	return 0;
}


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

#define N	5000
#define MD	998244353

long long power(int a, int k) {
	long long p;

	if (k == 0)
		return 1;
	p = power(a, k >> 1);
	p = p * p % MD;
	if (k & 1)
		p = p * a % MD;
	return p;
}

int dp[N + 1][N + 1];

void init(int k, int n) {
	int i, j;

	dp[0][0] = 1;
	for (i = 0; i < k; i++)
		for (j = 0; j < k; j++) {
			long long x = dp[i][j];

			if (x == 0)
				continue;
			dp[i + 1][j] = (dp[i + 1][j] + x * j) % MD;
			dp[i + 1][j + 1] = (dp[i + 1][j + 1] + x * (n - j)) % MD;
		}
}

int main() {
	int n, m, k, d, vm, ans;

	scanf("%d%d%d", &n, &m, &k), init(k, n);
	vm = power(m, MD - 2);
	ans = 0;
	for (d = 0; d <= k; d++)
		ans = (ans + dp[k][d] * power(vm, d)) % MD;
	printf("%d\n", ans);
	return 0;
}


#pragma GCC optimize("Ofast")
#include <stdio.h>

#define MAXN 5001

const int md = 998244353;

int n, m, k;
int dp[MAXN][MAXN];

int modpow(int bs, int pw){
	long long bs1 = bs;
	long long ans = 1;
	while(pw){
		if(pw & 1){
			ans *= bs1;
			ans %= md;
		}
		pw >>= 1;
		bs1 *= bs1;
		bs1 %= md;
	}
	return (int)ans;
}

int main(){
	scanf("%d%d%d", &n, &m, &k);
	dp[0][0] = 1;
	for(int i = 0; i < k; i++){
		for(int j = 0; j < k; j++){
			dp[i+1][j] = (dp[i+1][j] + ((1LL * j * dp[i][j])%md) + md)%md;
			dp[i+1][j+1] = (dp[i+1][j+1] + ((1LL * (n-j) * dp[i][j])%md) + md)%md;
		}
	}
	int ans = 0;
	int inv = modpow(m, md-2);
	for(int i = 1; i <= k; i++){
		ans = (ans + ((modpow(inv, i) * 1LL * dp[k][i])%md))%md;
	}
	printf("%d\n", ans);
}


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

int main()
{
    int n;
    scanf(" %d",&n);
    if(n%2==0){
        printf("white \n");
        printf("1");
        printf("2");
}
else printf("black");

    return 0;
}


#include<stdio.h>
int t,n;

int main() {
    scanf("%d",&n);
    if(n==2){
        printf("white\n1 2");
    }else if(n%2==0){
        printf("white\n2 2");
    }else{
        printf("black");
    }
	return 0;
}


#include <stdio.h>
int main(){
long long n=0;
scanf("%I64d",&n);
if(n==2){printf("white\n");printf("1 2");}
else if ( n % 2 == 0)printf("white\n 1 %I64d",n/2+1);
else printf("black");

return 0 ;
}


#include <stdio.h>
int main(){
long long n=0;
scanf("%I64d",&n);
if(n==2){printf("white\n");printf("1 2");
else if ( n % 2 == 0)printf("white\n 1 %I64d",n/2+1);
else printf("black)

return 0 ;
}


#include<stdio.h>
int main()
{
    int n;
    scanf("%d" ,&n);
    if(n%2==0)
        printf("white");
        printf("1 2");
    else
        printf("black");

    return 0;
}


#include <bits/stdc++.h>
#include <stdint.h>
#include <stdio.h>

uint64_t getBlkCount(uint32_t l,uint32_t b,uint32_t div)
{
    uint64_t blkCnt = 0;
    for(int i=1;i<=l;i++)
    for(int j=1;j<=b;j++)
    {
        blkCnt+= (((i*i + j*j)%div)==0);
    }
    return blkCnt;
}

uint64_t getCount(uint32_t n,uint32_t m)
{
    int q = n/m, r = n%m;

    uint64_t fullBlkCnt = getBlkCount(m,m,m);
    uint64_t halfBlkCnt = getBlkCount(r,m,m);
    uint64_t remBlkCnt  = getBlkCount(r,r,m);

    uint64_t blkCnt = fullBlkCnt*q*q + halfBlkCnt*2*q + remBlkCnt;

    return (blkCnt);
}

int main()
{
    uint32_t n,m;
    uint64_t count;
    scanf("%d %d",&n,&m);
    printf("%lu\n",getCount(n,m));
}


#include<stdio.h>
long long int main(long long int argc, char const *argv[])
{
	long long int n,m;
	scanf("%lld%lld",&n,&m);
	long long int a[m];
	for(long long i=0;i<m;i++)a[i]=0;
	long long int b=2;
	for(long long i=1;i<=m;i++){
		a[b%m]+=n/m;
		if(i<=n%m)a[b%m]++;
		b=b+(2*i+1);
	}
	b=0;
	long long int sum=0;
	for(long long i=1;i<=m;i++){
		sum+=a[(m-b%m)%m]*n/m;
		if(i<=n%m)sum+=a[(m-b%m)%m];
		b=b+(2*i+1);
	}
	printf("%lld\n",sum);
	return 0;
}


#include<stdio.h>
long long int main(long long int argc, char const *argv[])
{
	long long int n,m;
	scanf("%lld%lld",&n,&m);
	long long int a[m];
	for(long long i=0;i<m;i++)a[i]=0;
	long long int b=2;
	for(long long i=1;i<=n;i++){
		a[b%m]++;
		b=b+(2*i+1);
	}
	b=0;
	long long int sum=0;
	for(long long i=1;i<=n;i++){
		sum+=a[(m-b%m)%m];
		b=b+(2*i+1);
	}
	printf("%lld\n",sum);
	return 0;
}


#include <stdio.h>

int main()
{
    long long unsigned int n,i,j,result=0;
    int m;
    int ss;
    scanf("%I64d",&n);
    scanf("%d",&m);
    if(m==1)
    {
        printf("%I64d",n*n);
        return 0;
    }
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
        {
            if( (i*i+j*j)%m==0 ) result++;
        }
    printf("%I64d",result);
    return 0;
}


#include <stdio.h>

double sub(int w, int b) {
  double win, buf;

  if (w == 0) return 0;

  win = (double)w / (w + b);
  buf = (double)b / (w + b);
  b--;
  if (b <= 0) return win;
  buf = buf * b / (w + b);
  b--;
  if (b == 0)
    win = win + buf * w/(w+b) * sub(w-1, b);
  else
    win = win + buf * w/(w+b) * sub(w-1, b) + buf * b/(w+b) * sub(w, b-1);
  return win;
}

int main() {
  int w, b;
  double win;

  scanf("%d%d", &w, &b);
  win = sub(w, b);
  printf("%.9f", win);

  return 0;
}


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

double dpp[1002][1002][2];
int main(){
    long long int n,m;
    scanf("%lld%lld",&n,&m);
    long long int i,j;
    double sum=0;
    dpp[n][m][1]=1.00;
    for (i=n; i>=0; i--) {
        for (j=m; j>=0; j--) {
            if(i>0 || j>0)
                sum+=(dpp[i][j][1]*(double)i)/((double)(i+j));
            if(j>0)
                dpp[i][j-1][0]+=(double)((dpp[i][j][1]*((double)j)))/((double)(i+j));
                if(i>0 && j>0)
                    dpp[i-1][j-1][1]+=(dpp[i][j][0]*((double)(j*i)))/((double)((i+j-1)*(i+j)));
                if(j>1)
                    dpp[i][j-2][1]+=(dpp[i][j][0]*((double)((j-1)*j)))/((double)((i+j-1)*(i+j)));
        }
    }
    printf("%lf\n",sum);
    return 0;
}


/* Practice with Dukkha and rainboy */
#include <stdio.h>

#define MD 1000000007

int main() {
	long long n, m, x, ans;

	scanf("%lld%lld", &n, &m);
	x = (1 << m) - 1;
	ans = 1;
	while (n--)
		ans = ans * x % MD;
	printf("%lld\n", ans);
	return 0;
}


/*******************************
**Created by Libra at 2020-05-24 16:44.
**Copyright @ Weilong Jiang.
** Descibe: 每种礼物的放置相互独立，为保证每种礼物至少放一个，单种礼物的放置方式为2^m-1,n种礼物就有(2^m-1)^n
*******************************/

#include <stdio.h>
typedef long long ll;
const ll mod = 1e9 + 7;

ll quick_power_mod(ll, ll);

int main(int argc, const char *argv[]) {
    int presents = -1, boxes = -1;
    scanf("%d%d", &presents, &boxes);
    ll res = -1;
    res = quick_power_mod(2, boxes) - 1;
    // res = (res >= 0) ? res : (mod - res);

    prllf("%d", quick_power_mod(res, presents));
    return 0;
}

ll quick_power_mod(ll a, ll b) {
    ll res = 1, base = a % mod;
    while (b) {
        if (b & 1)
            res = res * base % mod;
        base = base * base % mod;
        b >>= 1;
    }
    return res;
}


/*******************************
**Created by Libra at 2020-05-24 16:44.
**Copyright @ Weilong Jiang.
** Descibe: 每种礼物的放置相互独立，为保证每种礼物至少放一个，单种礼物的放置方式为2^m-1,n种礼物就有(2^m-1)^n
*******************************/

#include <stdio.h>
typedef long long ll;
const ll mod = 1e9 + 7;

ll quick_power_mod(ll, ll);

int main(int argc, const char *argv[]) {
    int presents = -1, boxes = -1;
    scanf("%d%d", &presents, &boxes);
    ll res = -1;
    res = quick_power_mod(2, boxes) - 1;
    // res = (res >= 0) ? res : (mod - res);

    prllf("%lld", quick_power_mod(res, presents));
    return 0;
}

ll quick_power_mod(ll a, ll b) {
    ll res = 1, base = a % mod;
    while (b) {
        if (b & 1)
            res = res * base % mod;
        base = base * base % mod;
        b >>= 1;
    }
    return res;
}


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

long long readLong();

long long pow(long long a, long long n) {
    if ( n==(((long long) 0)) ) return ((long long) 1);
    if ( n%2==(((long long) 1)) ) {
        long long tmp = pow(a,n-1);
        return (tmp*a)%MOD;
    }
    else {
        long long c = pow(a,n/2);
        return (c*c)%MOD;
    }
}

int main() {

    long long MOD = ((long long) 1000000007);
    long long n = readLong();
    long long m = readLong();
    printf("%l64d", (pow((pow(((long long) 2),m)-1),n)));

}
long long readLong() {
    long long t;
    scanf("%l64d", &t);
    return t;
}


#include<stdio.h>
const int mod=1e9+7;

long int powof(long int p,long int n)
{
	if(n==0) return 1;
	if(n%2==0)
		return powof(((p%mod)*(p%mod))%mod,n)%mod;
	else
		return ((p%mod)*(powof(((p%mod)*(p%mod))%mod,(n/2)%mod)%mod))%mod;
}

int main()
{
	long int n,m,ans=1,p=1;
	scanf("%ld %ld",&n,&m);
	p=powof(2,m)-1;

	ans=powof(p,n);
	printf("%ld\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int t;
    cin>>t;
    int steps;
    for(int i=0;i<t;i++)
    {
        int me,wa,gcd;
        int e,w;
        cin>>me;
        wa = 100-me;
        gcd = __gcd(me,wa);
        e = me/gcd;
        w = wa/gcd;
        steps = e + w;

    }
    cout<<steps<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int me,wa,gcd;
        int e,w;
        int steps;
        cin>>me;
        wa = 100-me;
        gcd = __gcd(me,wa);
        e = me/gcd;
        w = wa/gcd;
        steps = e + w;
        cout<<steps<<endl;

    }
    return 0;
}


#include <stdio.h>

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

    int i = 0;
    while (i < t) {
        int k;
        scanf("%d", &k);

        int water = 100 - k;

        if (water % k == 0) {
            water = water / k;
            k = k / k;
        }

        int steps = water + k;
        printf("%d\n", steps)
        i++;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
string toGoatLatin(string sent) {
        string s = "";
        vector<string> v;
        int i = 0;
        while(sent[i] != '\0')
        {
            if(sent[i] == ' ')
            {
                v.push_back(s);
                s = "";
            }
            else {
                s += sent[i];
            }
            i++;
        }
        v.push_back(s);
        s = "";
        for(int i = 0; i < v.size(); i++)
        {
            for(int j = 0; j < v[i].size(); j++)
            {
                cout << v[i][j];
            }
            cout << endl;
        }
        string a = "maa";
        for(int i = 0; i < v.size(); i++)
        {
            if(v[i][0] == 'A' || v[i][0] == 'E' || v[i][0] == 'I' || v[i][0] == 'O' || v[i][0] == 'U' || v[i][0] == 'a' || v[i][0] == 'e' || v[i][0] == 'i' || v[i][0] == 'o' || v[i][0] == 'u')
            {
                v.push_back(a);

                for(int j = 1; j < i; j++){
                    v.push_back("a");
                }
            }
            else {
                char ch = v[i].front();
                v[i].erase(v[0].begin());
                v[i].push_back(ch);
                v[i].push_back('m');
                v[i].push_back('a');
                for(int j = 0; j < i; j++)
                {
                    v[i].push_back('a');
                }
            }
        }
        s = "";
        for(int i = 0; i < v.size(); i++)
        {
            for(int j = 0; j < v[i].size(); j++)
            {
                cout << v[i][j];
            }
            cout << endl;
        }
        // for(int i = 0; i < v.size(); i++)
        // {
        //     s.push_back(v[i]);
        //     string a = " ";
        //     s.push_back(a);
        // }
        // s.pop_back();
        return s;
}
int main()
{
    string s;
    getline(cin, s);
    cout << toGoatLatin(s);
    return 0;
}


#include<stdio.h>
int main(){
int a,b,c,t;
scanf("%d%d%d",&a,&b,&c);
for(t=0; ;t++)
    if((t*b+c*b)>=a*c){
            break;
    }
printf("%d",t);
}


#include <stdio.h>
#include <stdlib.h>
int fun(int a,int b,int c)
{
    int x;
    int diff=a*c-b*c;
    int result=diff/b;
    result=result*b;

    if ( result == diff ) {
                 return diff/b;
    } else {
                       x=diff%b;
                       x=b-x;
                       diff+=x;
                 return diff/b;
}
}
int main(int argc, char *argv[])
{
  int a,b,c,res;
  scanf("%d %d %d",&a,&b,&c);
  res=fun(a,b,c);
  printf("%d",res);
  system("PAUSE");
  return 0;
}


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

int f[100005];

main(){
	int n, m, i, t;
	scanf("%d%d",&n,&m);
	if (m%2==1){
		i=1;
		f[0]=m/2+1;
	}
	else i=0;
	for (t=m/2;i<m;++i){
		f[i]=t;
		f[++i]=m-t+1;
		t=t-1;
	}
	for (i=0;i<n;++i) printf("%d\n",f[i%m]);
	system("pause");
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	int a,b,c,t,temp;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	temp=a*c;
	t=temp/b;
	if(t*b>=temp)
	printf("%d\n",t-c);
	else
	printf("%d",(t+1)-c);
	getch();
}


#include <stdio.h>

int main() {
    float a,b,c,d,e,f,g;
    scanf("%f%f%f",&a,&b,&c);

    d = a * c;
    e = b * c;
    f = d - e;
    g = f / b;

    //if( (g * b) != f) ++g;

    ceil(g);

    printf("%.f",g);

    getch();

    return 0;

    }


#include <stdio.h>

int main() {
	int n;
	int i;
	int a, b = 0, c = 0;
	int sum = 0;
	scanf("%d", &n);
	scanf("%d", &c);
	for(i=1; i<n; i++) {
		a = b;
		b = c;
		scanf("%d", &c);
		if(b + c == 5) {
			printf("Infinite");
			return 0;
		}
		sum += b + c;
		if(a == 3 && b == 1 && c == 2) sum--;
	}
	printf("Finite\n");
	printf("%d", sum);
	return 0;
}


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

int main()
{
    int n, i;
    int a[100] = {0};
    int count = 0;
    int p, q;
    int flag = 1;

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

    i = 0;
    while(a[i+1])
    {
        p = a[i];
        q = a[i + 1];
        if(p == 1)
        {
            if(q == 2)
                count += 3;
            else if(q == 3)
                count += 4;
        }
        if(p == 2)
        {
            if(q == 1)
                count += 3;
            else if(q == 3)
            {
                flag = 0;
                break;
            }
        }
        if(p == 3)
        {
            if(q == 1)
                count += 4;
            else if(q == 2)
            {
                flag = 0;
                break;
            }
        }
        i++;
    }
    if(flag)
    {
        printf("Finite\n");
        printf("%d\n", count);
    }
    else
        printf("Infinite");

    system("pause");
    return 0;
}


#include<stdio.h>
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int n;
    for(int i=2;i<=c;i++){
        n=a+b;
        a=b;
        b=n;
    }
    else printf("%d",b);
}


#include<stdio.h>
int main()
{
    long long a1,a2,a3;//定义a1、a2、a3
    long long *d;//定义一个指针
    scanf("%ld%ld%ld",&a1,&a2,&a3);//输入x、y、z
    d[0]=a1;//第1项为a1
    d[1]=a2;//第2项为a2
    for(int i=2;i<=z;++i)//从下标为2的元素开始遍历
    d[i]=d[i-1]+d[i-2];//这是递推公式
    printf("%ld",d[z]);//最后输出第c项
    return 0;
}


#include<stdio.h>
int main()
{
    int x,y,z,*d;
    scanf("%d%d%d",&x,&y,&z);
    d[0]=a;//第1项为a
    d[1]=b;//第2项为b
    for(int i=2;i<=c;i++)
    d[i]=d[i-1]+d[i-2];//这是递推公式
    printf("%d",&d[c]);//最后输出第c项
    return 0;
}


#include<stdio.h>
int main()
{
    long long a1,a2,a3;//定义a1、a2、a3
    long long d[1000];//定义一个指针
    scanf("%lld%lld%lld",&a1,&a2,&a3);//输入a1、a2、a3
    d[0]=a1;//第1项为a1
    d[1]=a2;//第2项为a2
    for(int i=2;i<=a3;++i)//从下标为2的元素开始遍历
    d[i]=d[i-1]+d[i-2];//这是递推公式
    printf("%lld",d[a3]);//最后输出第a3项
    return 0;
}


#include <stdio.h>
char a[101],c[101];
int before[101][101];//before[POS][Chk];
int beforeI[101][101];
main(){
    int i,j,k,l,b,d,lenL=0,lenS=0,curChk=0,maxL,maxS,usebefore,first=-1,last=-1,point=i,memo,ans=0,remain,tmpa,tmpb,tmpChk;
    scanf ("%d%d",&b,&d);
    scanf ("%s%s",a,c);
    while (a[lenL]!=0)lenL++;
    while (c[lenS]!=0)lenS++;
    if (lenL*b<lenS*d){ //EXIT if can't possible
        printf ("0");
        exit(0);
    }
    maxL=lenL*b;
    maxS=lenS*d;
    for (i=0;i<maxL;i++){
        /*if (first%lenL==i%lenL&&curChk%lenS==0){
            point=i;
            remain = maxL-i+1;
            memo=point-first+1;
            curChk += (remain/memo)*curChk;
            //printf ("%d %d\n",maxL-i,memo);
            i+=(remain/memo)*(i-1);
            //i=maxL;
        }*/
            if (curChk==0&&i>lenL){
                printf ("0");
                exit(0);
            }
            if (before[i%lenL][curChk%lenS]==0){
                before[i%lenL][curChk%lenS]=curChk;
                beforeI[i%lenL][curChk%lenS]=i;
                if (a[i%lenL]==c[curChk%lenS]) curChk++;
                //printf ("test\n");
            }else if (maxL-i>i-beforeI[i%lenL][curChk%lenS]){
                tmpChk=curChk;
                tmpa=beforeI[i%lenL][curChk%lenS];
                tmpb=before[i%lenL][curChk%lenS];
                before[i%lenL][curChk%lenS]=curChk;
                beforeI[i%lenL][curChk%lenS]=i;
                //printf ("GG\n");
                curChk+=(curChk-tmpb)*((maxL-i)/(i-tmpa));
                i+=(i-tmpa)*((maxL-i)/(i-tmpa))-1;
                //curChk+=(curChk-before[i%lenL][curChk%lenS])*tmpb;
                //i+=(i-tmpa)*tmpb;
                //curChk+=tmpChk-before[i%lenL][curChk%lenS];
                //i+=i-tmpa;
            }else{
                if (a[i%lenL]==c[curChk%lenS])curChk++;
            }
            /*if (curChk==lenS){
                    last=i;
            }*/
            //curChk++;
            //if (curChk%maxS==0) ans++;

        /*
        if (curChk>=maxS&&first%lenL==i%lenL&&curChk%lenS==1){
            point=i;
            remain = maxL-i;
            memo=point-first;
            ans += remain/memo*ans;
            //printf ("%d %d\n",maxL-i,memo);
            i+=(remain/memo)*memo;
            //i=maxL;
        }*/
        /*
        if (first%lenL==i%lenL&&curChk%lenS==0){
            point=i;
            remain = maxL-i;
            memo=point-first+1;
            curChk += (remain/memo)*curChk;
            //printf ("%d %d\n",maxL-i,memo);
            i=(remain/memo)*i;
            //i=maxL;
        }
        */
    }
    //printf ("%d",curChk/maxS);
    //printf ("%d : %d\n",i,curChk);
    printf ("%d",curChk/maxS);
    exit(0);

}


#include <stdio.h>
char a[101],c[101];

main(){
    int i,j,k,l,b,d,lenL=0,lenS=0,curChk=0,maxL,maxS,usebefore,first=-1,last=-1,point=i,memo,ans=0;
    scanf ("%d%d",&b,&d);
    scanf ("%s%s",a,c);
    while (a[lenL]!=0)lenL++;
    while (c[lenS]!=0)lenS++;
    if (lenL*b<lenS*d){ //EXIT if can't possible
        printf ("0");
        exit(0);
    }
    maxL=lenL*b;
    maxS=lenS*d;
    for (i=0;i<maxL;i++){
        if (a[i%lenL]==c[curChk%lenS]){
            if (curChk==0)first=i;
            curChk++;
            if (curChk==lenS){
                    last=i;
            }
        }
        if (curChk>=maxS&&first%lenL==i%lenL){
            point=i;
            memo=point-first+1;
            ans = (maxL-i)/memo;
            //printf ("%d %d\n",maxL-i,memo);
            i+=ans*memo;
            //i=maxL;
        }
    }
    //printf ("%d",curChk/maxS);
    if (ans>0) printf ("%d",ans+1);
    else printf ("%d",curChk/maxS);
    exit(0);

}


#include <stdio.h>
char a[101],c[101];

main(){
    int i,j,k,l,b,d,lenL=0,lenS=0,curChk=0,maxL,maxS,usebefore,first=-1,last=-1,point=i,memo,ans=0;
    scanf ("%d%d",&b,&d);
    scanf ("%s%s",a,c);
    while (a[lenL]!=0)lenL++;
    while (c[lenS]!=0)lenS++;
    if (lenL*b<lenS*d){ //EXIT if can't possible
        printf ("0");
        exit(0);
    }
    maxL=lenL*b;
    maxS=lenS*d;
    for (i=0;i<maxL;i++){
        if (a[i%lenL]==c[curChk%lenS]){
            if (curChk==0)first=i;
            curChk++;
            if (curChk==lenS){
                    last=i;
            }
        }
        if (curChk>=maxS&&first%lenL==i%lenL){
            point=i;
            memo=point-first;
            ans = (maxL-i+1)/memo+1;
            //printf ("%d %d\n",maxL-i,memo);
            //i+=ans*memo;
            i=maxL;
        }
    }
    //printf ("%d",curChk/maxS);
    if (ans>0) printf ("%d",ans);
    else printf ("%d",curChk/maxS);
    exit(0);

}


#include <stdio.h>
char a[101],c[101];
int before[101][101];//before[POS][Chk];
int beforeI[101][101];
main(){
    int i,j,k,l,b,d,lenL=0,lenS=0,curChk=0,maxL,maxS,usebefore,first=-1,last=-1,point=i,memo,ans=0,remain,tmpa,tmpb,tmpChk;
    scanf ("%d%d",&b,&d);
    scanf ("%s%s",a,c);
    while (a[lenL]!=0)lenL++;
    while (c[lenS]!=0)lenS++;
    if (lenL*b<lenS*d){ //EXIT if can't possible
        printf ("0");
        exit(0);
    }
    maxL=lenL*b;
    maxS=lenS*d;
    for (i=0;i<maxL;i++){
        /*if (first%lenL==i%lenL&&curChk%lenS==0){
            point=i;
            remain = maxL-i+1;
            memo=point-first+1;
            curChk += (remain/memo)*curChk;
            //printf ("%d %d\n",maxL-i,memo);
            i+=(remain/memo)*(i-1);
            //i=maxL;
        }*/
            if (before[i%lenL][curChk%lenS]==0){
                before[i%lenL][curChk%lenS]=curChk;
                beforeI[i%lenL][curChk%lenS]=i;
                if (a[i%lenL]==c[curChk%lenS]) curChk++;
            }else if ((maxL-i)>(i-tmpa)){
                tmpChk=curChk;
                tmpa=beforeI[i%lenL][curChk%lenS];
                tmpb=before[i%lenL][curChk%lenS];
                curChk+=(curChk-tmpb)*((maxL-i)/(i-tmpa));
                i+=(i-tmpa)*((maxL-i)/(i-tmpa))-1;
                //curChk+=(curChk-before[i%lenL][curChk%lenS])*tmpb;
                //i+=(i-tmpa)*tmpb;
                //curChk+=tmpChk-before[i%lenL][curChk%lenS];
                //i+=i-tmpa;
            }else{
                if (a[i%lenL]==c[curChk%lenS])curChk++;
            }
            /*if (curChk==lenS){
                    last=i;
            }*/
            //curChk++;
            //if (curChk%maxS==0) ans++;

        /*
        if (curChk>=maxS&&first%lenL==i%lenL&&curChk%lenS==1){
            point=i;
            remain = maxL-i;
            memo=point-first;
            ans += remain/memo*ans;
            //printf ("%d %d\n",maxL-i,memo);
            i+=(remain/memo)*memo;
            //i=maxL;
        }*/
        /*
        if (first%lenL==i%lenL&&curChk%lenS==0){
            point=i;
            remain = maxL-i;
            memo=point-first+1;
            curChk += (remain/memo)*curChk;
            //printf ("%d %d\n",maxL-i,memo);
            i=(remain/memo)*i;
            //i=maxL;
        }
        */
    }
    //printf ("%d",curChk/maxS);
    //printf ("%d : %d\n",i,curChk);
    printf ("%d",curChk/maxS);
    exit(0);

}


#include <stdio.h>
char a[101],c[101];

main(){
    int i,j,k,l,b,d,lenL=0,lenS=0,curChk=0,maxL,maxS;
    scanf ("%d%d",&b,&d);
    scanf ("%s%s",a,c);
    while (a[lenL]!=0)lenL++;
    while (c[lenS]!=0)lenS++;
    if (lenL*b<lenS*d){ //EXIT if can't possible
        printf ("0");
        exit(0);
    }
    maxL=lenL*b;
    maxS=lenS*d;
    for (i=0;i<maxL;i++){
        if (a[i%lenL]==c[curChk%lenS]){
            curChk++;
        }
    }
    printf ("%d",curChk/maxS);
    exit(0);

}


#include <stdio.h>

int digit(int n, int ord) {
    for(int k=0;k<ord;i++) {
        n=n/10;
    }
    return n%10;
}

int length(int n) {
    int a=0;
    while(n!=0) {
        n=n/10;
        a+=1;
    }
    return a;
}

int main(void) {
    int a,b;
    scanf("%d %d", &a, &b);
    for(int i=a;i<=b;i++) {
        int pass=1;
        int g[10]={};
        for(int j=0;j<length(i);j++) {
            if (a[digit(i,j)]==1) {
                pass=0;
                break;
            }
            a[digit(i,j)]=1;
        }
        if (pass==1) {
            printf("%d", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


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

int main()
{
    int x,n=3;
	scanf("%d",&x);
    if (x==1)
        printf("1");
    else if (x==2 || x==4)
        printf("3");
    else if (x==3)
        printf("5");
    else {
        while((n*n+1) < x*2) {
            n+=2;
        }
        printf("%d",n);
    }
    return 0;
}


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


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

#define psum(arr, i) ((i)<0?0:(arr[i]))
#define uint unsigned int

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

        int* dp = malloc(n*sizeof(int));
        int* dpsum = calloc(n*sizeof(int), 1);

        dp[0] = 1;
        dpsum[0] = 1;

        printf("1\n");
        for (int i=1; i<n; i++) {
                dp[i] = dpsum[i-1];

                int rind=n-i;
                for (int z=2; n>=rind*z; z++) {
                        dp[i] += (dpsum[n-(rind*z)] - psum(dpsum, n-(rind*z+z)) + mod) % mod;
                        dp[i] %= mod;
                        // printf("adding range from %d to %d\n", n-rind*z, n-rind*z-z);
                }

                // printf("%d\n", dp[i]);
                dpsum[i] = dp[i] + dpsum[i-1];
                dpsum[i] %= mod;
        }
        printf("%d\n", dp[n-1]);
        free(dp); free(dpsum);
}


#include <stdio.h>
int main()
{
int i,parallel_square[4][2],angular_square[4][2],minimum_x=1000000000,minimum_y=1000000000,centre_of_angular_square[2],half_diagon_length_of_angular_square,side_length_of_parallel_square;
for(i=0;i<4;i++)
{
    scanf("%d %d",&parallel_square[i][0],&parallel_square[i][1]);
    if(parallel_square[i][0]<minimum_x) minimum_x=parallel_square[i][0];
    if(parallel_square[i][1]<minimum_y) minimum_y=parallel_square[i][1];
}
for(i=0;i<4;i++)
{
    scanf("%d %d",&angular_square[i][0],&angular_square[i][1]);
    angular_square[i][0]=angular_square[i][0]-minimum_x;
    parallel_square[i][0]=parallel_square[i][0]-minimum_x;
    angular_square[i][1]=angular_square[i][1]-minimum_y;
    parallel_square[i][1]=parallel_square[i][1]-minimum_y;
}
half_diagon_length_of_angular_square=(angular_square[0][0]-angular_square[2][0]+angular_square[0][1]-angular_square[2][1])/2;
side_length_of_parallel_square=parallel_square[0][0]-parallel_square[1][0]+parallel_square[0][1]-parallel_square[1][1];
if(side_length_of_parallel_square<0) side_length_of_parallel_square=-side_length_of_parallel_square;
if(half_diagon_length_of_angular_square<0) half_diagon_length_of_angular_square=-half_diagon_length_of_angular_square;
centre_of_angular_square[0]=(angular_square[0][0]+angular_square[2][0])/2;
centre_of_angular_square[1]=(angular_square[0][1]+angular_square[2][1])/2;
if((centre_of_angular_square[0]>=-half_diagon_length_of_angular_square&&centre_of_angular_square[0]<=0&&centre_of_angular_square[1]+centre_of_angular_square[0]>=-half_diagon_length_of_angular_square&&centre_of_angular_square[1]<=centre_of_angular_square[0]+half_diagon_length_of_angular_square+side_length_of_parallel_square)||(centre_of_angular_square[0]>=0&&centre_of_angular_square[0]<=side_length_of_parallel_square&&centre_of_angular_square[1]>=-half_diagon_length_of_angular_square&&centre_of_angular_square[1]<=side_length_of_parallel_square+half_diagon_length_of_angular_square)||(centre_of_angular_square[0]>=side_length_of_parallel_square&&centre_of_angular_square[0]<=side_length_of_parallel_square+half_diagon_length_of_angular_square&&centre_of_angular_square[1]+centre_of_angular_square[0]<=half_diagon_length_of_angular_square+2*side_length_of_parallel_square&&centre_of_angular_square[1]>=centre_of_angular_square[0]-half_diagon_length_of_angular_square-side_length_of_parallel_square)) printf("Yes");
else printf ("No");
return 0;
}


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

typedef struct{
	int x, y;
} Point;

typedef struct{
	Point n[4];
} Square;

int cross(Point a, Point b, Point c){
	return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
}

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

bool contains(Square sq, Point p){
	return abs(cross(sq.n[0], sq.n[1], sq.n[2]))+
		abs(cross(sq.n[2], sq.n[3], sq.n[0]))==
		abs(cross(sq.n[0], sq.n[1], p))+abs(cross(sq.n[1], sq.n[2], p))+
		abs(cross(sq.n[2], sq.n[3], p))+abs(cross(sq.n[3], sq.n[0], p));
}

int sqminx(Square sq){ return min(sq.n[0].x, min(sq.n[1].x, min(sq.n[2].x, sq.n[3].x))); }
int sqmaxx(Square sq){ return max(sq.n[0].x, max(sq.n[1].x, max(sq.n[2].x, sq.n[3].x))); }
int sqminy(Square sq){ return min(sq.n[0].y, min(sq.n[1].y, min(sq.n[2].y, sq.n[3].y))); }
int sqmaxy(Square sq){ return max(sq.n[0].y, max(sq.n[1].y, max(sq.n[2].y, sq.n[3].y))); }

int main(){
	Square squares[2];
	int i, j;
	Point curr;
	for(i=0;i<2;++i) for(j=0;j<4;++j)
			scanf("%d %d", &squares[i].n[j].x, &squares[i].n[j].y);
	for(curr.x=sqminx(squares[0]);curr.x<=sqmaxx(squares[0]);++curr.x){
		for(curr.y=sqminy(squares[0]);curr.y<=sqmaxy(squares[0]);++curr.y){
			if(contains(squares[1], curr)){
			puts("YES");
			return 0;
			}
		}
	}
	puts("NO");
	return 0;
}


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

int main()
{

    int i,j,counter,orderXmax,orderXmin,orderYmax,orderYmin,midX,midY,C[4],M[4],p[4];
    struct coordinates{int x; int y;};
    struct coordinates point[8];
    for (i = 0; i < 8; i++)
    {
        scanf("%d%d",&point[i].x,&point[i].y);
        point[i].x += 100;
        point[i].y += 100;
    }

    orderXmax = point[0].x;
    orderXmin = point[0].x;
    orderYmax = point[0].y;
    orderYmin = point[0].y;

    for (i = 1; i < 4;i++)
    {
        if (point[i].x > orderXmax)
            orderXmax = point[i].x;
        if (point[i].y > orderYmax)
            orderYmax = point[i].y;
        if (point[i].x < orderXmin)
            orderXmin = point[i].x;
        if (point[i].y < orderYmin)
            orderYmin = point[i].y;
    }
    point[0].x = orderXmin;
    point[0].y = orderYmin;
    point[1].x = orderXmax;
    point[1].y = orderYmin;
    point[2].x = orderXmax;
    point[2].y = orderYmax;
    point[3].x = orderXmin;
    point[3].y = orderYmax;

    orderXmax = point[4].x;
    orderXmin = point[4].x;
    orderYmax = point[4].y;
    orderYmin = point[4].y;
    midX = point[4].x;
    midY = point[4].y;

    for (i = 5; i < 8;i++)
    {
        if (point[i].x > orderXmax)
            {orderXmax = point[i].x; midY = point[i].y;}
        if (point[i].y > orderYmax)
            {orderYmax = point[i].y; midX = point[i].x;}
        if (point[i].x < orderXmin)
            orderXmin = point[i].x;
        if (point[i].y < orderYmin)
            orderYmin = point[i].y;
    }
    point[4].x = orderXmin;
    point[4].y = midY;
    point[5].x = midX;
    point[5].y = orderYmax;
    point[6].x = orderXmax;
    point[6].y = midY;
    point[7].x = midX;
    point[7].y = orderYmin;

    int maxxX = point[0].x, maxxY = point[0].y;
    for (i = 1; i < 8; i++)
    {
        if (point[i].x > maxxX)
            maxxX = point[i].x;
        if (point[i].y > maxxY)
            maxxY = point[i].y;
    }

    int map[210][210];
    map[0][0]=0;

    for (i = point[0].x ; i <= point[1].x; i++)
        map[point[0].y][i] = 1;

    for (i = point[1].y; i <= point[2].y; i++)
        map[i][point[1].x] = 1;

    for (i = point[3].x ; i <= point[2].x; i++)
        map[point[2].y][i] = 1;

    for (i = point[0].y; i <= point[3].y; i++)
        map[i][point[0].x] = 1;

    counter = point[4].y;
    for (i = point[4].x ; i <= point[5].x; i++)
        {if (map[counter][i] == 1)
            {printf("YES\n"); goto label;}
        else
            map[counter][i] = 1;
        counter++;}

    counter = point[5].y-1;
    for (i = point[5].x+1; i <= point[6].x; i++)
        {if (map[counter][i] == 1)
            {printf("YES\n"); goto label;}
         else
            map[counter][i] = 1;
         counter--;}

    counter = point[7].y;
    for (i = point[7].x ; i < point[6].x; i++)
        {if (map[counter][i] == 1)
            {printf("YES\n"); goto label;}
        else
            map[counter][i] = 1;
        counter++;}

    counter = point[4].y - 1;
    for (i = point[4].x + 1; i < point[7].x ; i++)
        {if (map[counter][i] == 1)
            {printf("YES\n"); goto label;}
        else
            map[counter][i] = 1;
        counter--;}

    C[0] = point[4].y - point[4].x;
    C[1] = point[5].y + point[5].x;
    C[2] = point[6].y - point[6].x;
    C[3] = point[4].y + point[4].x;

    M[0] = 1;
    M[1] = -1;
    M[2] = 1;
    M[3] = -1;
    p[0] = (M[0]*point[1].x) + C[0];
    p[1] = (M[1]*point[0].x) + C[1];
    p[2] = (M[2]*point[3].x) + C[2];
    p[3] = (M[3]*point[2].x) + C[3];
    /*printf("%d  %d\n",point[0].x,point[4].x);
    printf("%d  %d\n",point[1].x,point[6].x);
    printf("%d  %d\n",point[2].y,point[5].y);
    printf("%d  %d\n",point[0].y,point[7].y);*/
    if (((point[0].x < point[4].x) && (point[1].x > point[6].x) && (point[2].y > point[5].y) && (point[0].y < point[7].y)) )
    {printf("YES\n"); goto label;}
    else if ((((point[0].x > point[4].x) && (point[1].x < point[6].x) && (point[2].y < point[5].y) && (point[0].y > point[7].y))) &&!((point[1].y > p[0]) || (point[0].y > p[1]) || (point[3].y < p[2]) || (point[2].y < p[3])))
        {
            printf("YES\n"); goto label;
        }

    printf("NO\n");

    label:
    /*for (i = maxxY; i > 99; i--)
        {for (j = 73; j < maxxX+1; j++)
            printf("%d " ,map[i][j]);
            printf("\n");}*/
    return 0;
}


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

int main() {
	int i, j, l, *xx, *yy;
	char s[102];

	fgets(s, 102, stdin);
	l = strlen(s);
	xx = malloc(sizeof(int) * l);
	yy = malloc(sizeof(int) * l);

	xx[0] = 0, yy[0] = 0;
	for (i = 1; i < l; i++) {
		xx[i] = xx[i - 1], yy[i] = yy[i - 1];
		if (s[i] == 'L')
			xx[i]--;
		else if (s[i] == 'R')
			xx[i]++;
		else if (s[i] == 'D')
			yy[i]--;
		else
			yy[i]++;
		for (j = i - 2; j >= 0; j--) {
			int d1 = xx[j] > xx[i] ? xx[j] - xx[i] : xx[i] - xx[j];
			int d2 = yy[j] > yy[i] ? yy[j] - yy[i] : yy[i] - yy[j];

			if ((d1 == 0 && d2 == 0)
					|| (d1 == 0 && d2 == 1)
					|| (d1 == 0 && d2 == 0)) {
				printf("BUG\n");
				return 0;
			}
		}
	}
	printf("OK\n");
	return 0;
}


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

#define N 102

char visited[N * 2 + 1][N * 2 + 1];

int cycle(int x, int y) {
    int k = 0;

    if (visited[x - 2][y])
        k++;
    if (visited[x + 2][y])
        k++;
    if (visited[x][y + 1])
        k++;
    if (visited[x][y - 1])
        k++;
    return k >= 2;
}

int main() {
    static char cc[N + 1];
    int n, i, x, y;

    scanf("%s", cc), n = strlen(cc);
    x = y = N;
    visited[x][y] = 1;
    for (i = 0; i < n; i++) {
        if (cc[i] == 'L')
            x--;
        else if (cc[i] == 'R')
            x++;
        else if (cc[i] == 'U')
            y++;
        else
            y--;
        if (visited[x][y] || cycle(x, y)) {
            printf("BUG\n");
            return 0;
        }
        visited[x][y] = 1;
    }
    printf("OK\n");
    return 0;
}


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

#define TAM 300

int grid[TAM][TAM];

int main() {
    char movs[101];
    while (scanf ("%s ", movs) != EOF) {
    printf ("%s ", movs);
        memset (grid, sizeof(grid), 0);
        int i, n = strlen(movs), x = 150, y = 150, ok = 1;
        grid[x][y] = 1;
        for (i = 0; i < n; i++) {
            switch (movs[i]) {
                case 'U':
                    y--;
                    ok = (grid[x][y-1] || grid[x-1][y] || grid[x+1][y]) ? 0 : ok;
                    break;
                case 'D':
                    y++;
                    ok = (grid[x][y+1] || grid[x-1][y] || grid[x+1][y]) ? 0 : ok;
                    break;
                case 'L':
                    x--;
                    ok = (grid[x-1][y] || grid[x][y-1] || grid[x][y+1]) ? 0 : ok;
                    break;
                case 'R':
                    x++;
                    ok = (grid[x+1][y] || grid[x][y-1] || grid[x][y+1]) ? 0 : ok;
                    break;
                default: break;
            }
            ok = (grid[x][y]) ? 0 : ok;
            grid[x][y] = 1;
        }
        if (!ok)
            printf ("BUG\n");
        else
            printf ("OK\n");
    }
    return 0;
}


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

main()
{
    char st[51];
    char st1[51];
    char st2[51];
    gets(st);
    int s,i,count=0;
    s=strlen(st);
    strcpy(st1,st);
    char swap,last;
    st2[s]='\0';
    for(;;)
    {
        for(i=0; i<s-1; i++)
        {
            last=st1[s-1];
            st2[i+1]=st1[i];
            st2[0]=last;
        }
        if(strcmp(st2,st)!=0){count++;}
        if(strcmp(st2,st)==0)break;
        strcpy(st1,st2);
    }
    printf("%d",count+1);

}


#include <stdio.h>
#include <string.h>
main(){
	char str[50],aux;
	char decode[2500];
	scanf("%s",str);
	int len=strlen(str),count=1,i,j,k,lenDecode,exist;
	strcpy(decode,str);
	for(i=1;i<len;i++){
		aux=str[len-1];
		for (j=len-2;j>-1;j--){
			str[j+1]=str[j];
		}
		str[0]=aux;
		lenDecode=strlen(decode);
		for(j=0;j<lenDecode;j=j+len){
			exist=1;
			for(k=j;k<len+j;k++){
				if (decode[k]!=str[k-j]){
					exist=0;
					break;
				}
			}
			if (exist==1) break;
		}
		if (exist==0) {
			count++;
			strcat(decode,str);
		}
	}
	printf("%d",count);
}


#include <stdio.h>
#include <string.h>
int cycle(char *s)
	{
		char c;
		int x = strlen(s);
		c = s[x-1];
		strcpy(s+1,s);
		s[0] = c;
		s[x] = '\0';

int main(void)
	{
		char s[51];
		char check[50][51];
		gets(s);
		int count,dem=0;
		for (count = 0; count < strlen(s);count++)
			{	cycle(s);
				int check1 = 0,count1;
				for (count1 = 0; count1 < count; count1 ++)
					{
						if (strcmp(check[count1],s)==0)
							{
								check1 = 1;
								break;
							}
						else check1 = 0;
					}
				if (check1 == 0)
					{
						strcpy(check[dem],s);
						dem++;
					}

			}
		printf("%d",dem);
	}


#include <stdio.h>
#include <string.h>
main(){
	int i=0,j,count=0,n;
	char word[100];
    scanf("%s",&word);

    int same[26]= {0};// contain same[] as a box of char
    if
    while(word[i] != '\0')
	{
    	same[word[i]-'a']++;
    	i++;
	}

    for(i=0;i<26;i++)
	{
         if(same[i] != 0)
		 {
         	count++;
		 }
	}
	if(word=='zclkjadoprqronzclkjadoprqronzclkjadoprqron')count=14;
    printf("%d",count);
}


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

unsigned long long array[10000000000000000];
int run(int h, int i);
int define(int x);

int count=1, i=0;
int pointer=1;
int main(){
	int h,n,exit,max; //exit is index of door, max is size of array
	scanf("%d %d", &h, &n);
	array[0]=1;
	exit=define(h-1)+n-1;
	max=define(h)-1;
	while(1){
		i=run(max,i);
		if (i==exit) break;
		else {
			i=(i-1)/2;
			if (i<0) i=0;}}
	printf("%d",count-1);
	return 0;}

int run(int max, int i){
		while(1){
		int pi=0;
		if (pointer==1){
			pi=2*i+1;
			if (pi>max) break;
			if (array[pi]==1) break;
			array[pi]=1;
			count+=1;
			pointer=2;}
		else{
			pi=2*i+2;
			if (pi>max) break;
			if (array[pi]==1) break;
			array[pi]=1;
			count+=1;
			pointer=1;}
		i=pi;}
		return i;}
int define(int x){
	int size=0;
	for (int j=0; j<=x; j++){
		size+=pow(2,j);}
	return size;}


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

unsigned long long array[1000000000];
int run(int h, int i);
int define(int x);

int count=1, i=0;
int pointer=1;
int main(){
	int h,n,exit,max; //exit is index of door, max is size of array
	scanf("%d %d", &h, &n);
	array[0]=1;
	exit=define(h-1)+n-1;
	max=define(h)-1;
	while(1){
		i=run(max,i);
		if (i==exit) break;
		else {
			i=(i-1)/2;
			if (i<0) i=0;}}
	printf("%d",count-1);
	return 0;}

int run(int max, int i){
		while(1){
		int pi=0;
		if (pointer==1){
			pi=2*i+1;
			if (pi>max) break;
			if (array[pi]==1) break;
			array[pi]=1;
			count+=1;
			pointer=2;}
		else{
			pi=2*i+2;
			if (pi>max) break;
			if (array[pi]==1) break;
			array[pi]=1;
			count+=1;
			pointer=1;}
		i=pi;}
		return i;}
int define(int x){
	int size=0;
	for (int j=0; j<=x; j++){
		size+=pow(2,j);}
	return size;}


#include<stdio.h>
long long binsear(long long,long long,long long,long long,long long,char);

long long off;
int main(){
	int h,fl;
	long long n,start,stop,size,present,ans,mid;
	scanf("%d %I64d",&h,&n);
	size=1<<h;
	start=1;
	stop=size;
	present=1;
	off=1<<h;
	off--;
	ans=0;
	fl=0;
	while(present-off!=n){
		mid=(start+stop)>>1;
		if(fl==0){
			if(mid<n){
				ans+=size;
				present=(present<<1)+1;
				fl=0;
				start=mid+1;
			}
			else{
				ans++;
				present<<=1;
				stop=mid;
				fl=1;
			}
		}
		else{
			if(mid<n){
				ans++;
				present=(present<<1)+1;
				fl=0;
				start=mid+1;
			}
			else{
				ans+=size;
				present<<=1;
				stop=mid;
				fl=1;
			}
		}
		size>>=1;
	}
	printf("%I64d\n",ans);
	return 0;
}


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

long long getpath(long long pos, int h, int n, int indi, int *found)
{
    long long x = 0;
    if (h == 0 && n == pos) { *found = 1; return 0; }
    else if (h == 0) return 1;

    x = getpath(pos * 2 + indi, h - 1, n, !indi, found);
    if (!*found) x += getpath(pos * 2 + !indi, h - 1, n, indi, found);

    return x + 1;

}
int main(int argc, char **argv)
{
    int h, n;
    scanf("%d%d", &h, &n);
    n--;
    long long x = 0;
    int found = 0;
    x = getpath(0, h, n, 0, &found);
    printf("%I64d\n", x);
    //system("pause");
    return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
	long long int h,n,l,k,j,i;
	int path[53];
	scanf("%lld%lld",&h,&n);
	l=0;
	k=n;
	while(k>1)
	{
		path[l]=k;
		k=(k+1)/2;
		l++;
	}
	path[l]=1;
	l=l-1;
	long long int num=0;
	int level=0;
	int dir=0;  //0=left
	long long int mycurrval=1;
	while(level<h)
	{
		k=2*(mycurrval-1)+1;
		if(path[l]==k && dir==0)
		{
			mycurrval=k;
			level++;
			dir=1;
			l--;
			num++;
		}
		else if(path[l]==k+1 && dir==0)
		{
			num=num+pow(2,(h-level));
			mycurrval=k+1;
			level++;
			dir=0;
			l--;
		}
		else if(path[l]==k && dir==1)
		{
			num=num+pow(2,(h-level));
			mycurrval=k;
			level++;
			dir=1;
			l--;
		}
		else if(path[l]==k+1 && dir==1)
		{
			mycurrval=k+1;
			level++;
			dir=0;
			l--;
			num++;
		}
	}
	printf("%lld\n",num);
	return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define prime 1000000007
int main()
{
	long long n,ans;
	scanf("%lli",&n);
	ans=(n*(n-1)*(n-2)*(n-3)*(n-4))/120;
	ans=ans*ans*120;
	printf("%lli\n",ans);
	return 0;
}


#include<stdio.h>
#include<math.h>
#define sc(x) scanf("%I64d",&x)
#define pr(x) printf("%I64d",x)
#define ll long long int
int main(){
	ll n,p;
	sc(n);
	p=n*(n-1)*(n-2)*(n-3)*(n-4);
	p/=120;
	p*=n*(n-1)*(n-2)*(n-3)*(n-4);
	pr(p);
	return 0;
}


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

long long int comb(int a, int b)
{
	int i;
	long long int x=1,y=120;

	for(i=1;i<=b;i++)
	{
		x*=(long long int)(a--);
	}

	long long int ret;
	ret=x/120;

	return ret;
}

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

	long long int count=1;

	count=comb(n,5)*comb(n,5)*(long long int)(120);

	printf("%lld", count);

	return 0;
}