#include<stdio.h>
main()
{
    int ix;
    long long int l,r,m,n,x,y,n2,dc,nd2;
    scanf("%I64d",&n);
    if(n==1)
    {
        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;

}


/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:28/09/2019
*/
/*#include<algorithm>
#include <bits/stdc++.h>
using namespace std;*/

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define REP(i,n)        for(long long i=0;i<(n);i++)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);i--)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((int)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)            strlen(a)
#define MOD             1000000007
#define MAX             10000000005
#define MIN             -10000000005
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))

const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);
ll binpow(ll a,ll b,ll m)
{
    ll res=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
ll multiply(ll a, ll b, ll mod)
{
   return ((a % mod) * (b % mod)) % mod;
}
int main()
{
	ll n,m;
	SC2(n,m);
	unsigned long long ans=0;
	n++;
	ll x=2*n;
	unsigned long long z=binpow(x,m,MOD);
	z=z%MOD;
	unsigned long long z1=(n-m)%MOD;
	unsigned long long z2=multiply(z,z1,MOD);
	ans=(z2/n);
	ans=ans%MOD;
	printf("%llu\n",ans);

	return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
    if( *(ll*)a - *(ll*)b < 0 ) return -1;
    if( *(ll*)a - *(ll*)b > 0 ) return 1;
        return 0;
}
long long maxv(long long a,long long b)
{
    if(a>b) return a;
        return b;
}
long long minv(long long a,long long b)
{
    if(a<b) return a;
        return b;
}
long long gcd(long long u,long long v)
{
    if (v == 0) return u;
       return gcd(v, u%v);
}


#include <stdio.h>

int n;
char s[55];
long long res;

int main() { int i;
    scanf("%d%s", &n, s);
    for( i = 0; i < n; i++) if(s[i] == 'B') res |= 1ll << i;
    printf("%I64d\n", res);
    return 0;
}


#include <stdio.h>
#define MAXN 2003

int main()
{
    int n, t, i, j, cur = 0;
    double p, f[2][MAXN];
    scanf("%d%lf%d", &n, &p, &t);
    // f[t][n] -> the possibility that (exactly) n people
    // are standing on the escalator after t seconds
    for (i = 1; i <= n; ++i) f[cur][i] = 0;
    f[cur][0] = 1;
#define next (!cur)
    for (i = 0; i < t; ++i) {
        for (j = 0; j <= i; ++j)
            if (j >= n) f[next][j] += f[cur][j];
            else {
                f[next][j + 1] += f[cur][j] * p;
                f[next][j] += f[cur][j] * (1.0 - p);
            }
        cur = !cur;
        for (j = 0; j <= n; ++j) f[next][j] = 0;
    }
#undef next
    double ans = 0;
    for (i = 0; i <= n; ++i) ans += f[cur][i] * i;
    printf("%.8lf\n", ans);
    return 0;
}


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

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

int abso(int a,int b)
{
	if(a>b)return a-b;
	else return b-a;
}

int main()
{
	int n;
	scanf("%d",&n);
	int i=0;
	int a[200]={0};
	for(i=0;i<2*n;i++)scanf("%d",&a[i]);

	qsort(a, 2*n, sizeof(int), cmpfunc);

	int sing = 0;
	if(abso(a[1],a[0]) > abso(a[2*n-1],a[2*n-2]))sing=1;

	if(sing==0){n--;i=0;}
	else i=2;

	int sum=0;
	for(;i<2*n;i+=2)
		sum+=abso(a[i],a[i+1]);

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

	return 0;
}


#include <stdio.h>
int dp[500100];
int main()
{
    int n,d,i,x,sum,ans,ans1,j;
    scanf("%d%d",&n,&d);
        sum=0;
        dp[0]=1;
        for(i=0;i<n;i++){
            scanf("%d",&x);
            sum+=x;
            for(j=sum;j>=x;j--){
                if(dp[j-x])
                    dp[j]=1;
            }
        }
        ans=ans1=0;
        while(1)
        {
            j=ans+d;
            while(j>ans&&!dp[j])
                j--;
            if(j==ans)
                break;
            ans=j;
            ans1++;
        }
        printf("%d %d\n",ans,ans1);

    return 0;
}


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

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

    int digits[9] = {0};
    bool dup = true;
    while (n) {
        int d = n % m;
        if (digits[d]) {
            dup = false;
        } else {
            digits[d] = 1;
        }

        n /= m;
    }

    if (dup) {
        puts("YES");
    } else {
        puts("NO");
    }
}


#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
	int n,time,t[100],d[5000];
	int i,j,k=0;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<n;i++)
		scanf("%d",&t[i]);
		scanf("%d",&time);
		qsort(t,i,sizeof(t[0]),cmp);
		for(j=i-1;j>=0;j--)
		{
			for(i=0;i<=j;i++)
			{
				if((t[j]-t[i])<=time)
				d[k++]=j-i+1;
			}
		}
		qsort(d,k,sizeof(d[0]),cmp);
		printf("%d\n",d[k-1]);
	}
	return 0;
}


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

#define N 1100000

int a[N];

int max(int x, int y) {
    return x > y ? x : y;
}

int perfect(int x) {
    int i;
    for (i = 0; i < 30; i++) {
        int num = 1 << i;
        if (num == x)
            return 1;
    }
    return 0;
}

int step(int x) {
    int i;
    for (i = 0; i < 30; i++) {
        int num = 1 << i;
        if (num >= x)
            return i;
    }
    return -1;
}

int main(int argc, char** argv) {
    int i, n, x, y, z, s;

    memset(a, 0, sizeof a);
    scanf("%d", &n);
    for (i = 2; i < N; i++) {
        while (n % i == 0) {
            n /= i;
            a[i]++;
        }
    }

    x = 1;
    y = 0;
    z = 0;
    s = 1;
    for (i = 2; i < N; i++)
        if (a[i] > 0) {
            x *= i;
            z = max(z, a[i]);
        }
    for (i = 2; i < N; i++)
        if (a[i] > 0 && a[i] != z)
            s = 0;

    if (s == 1 && perfect(z))
        y = step(z);
    else
        y = step(z) + 1;

    printf("%d %d\n", x, y);

    return 0;
}


#include<stdio.h>
int a[11];
int max(int a ,int b){  return (a > b ? a : b); }
int isnext(int n){
      int m = 0 ,r = -1 ,i;
      for( i = 0 ; i < n - 1 ; i++){    if(abs(a[i] - a[i + 1]) >= 2) return -1;
      if(a[i] > m){
            r = i;
            m = a[i];
            }
      }
      if(a[i] > m)      r = i;
      return r;
}
int main(){
      int n ,r;      scanf("%d" ,&n);
      for(int i = 0 ; i < n ; i++)  scanf("%d" ,a + i);
      while(1){
            if((r = isnext(n)) == -1){
                  puts("NO"); return 0;
            }
            for(int j = r + 1 ; j < n ; j++)    a[j] = a[j - 1];
            n--;
            if(n == 1)  break;
      }
      puts("YES");
      return 0;
}


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

#define MAX 16
#define max(a,b) ((a)>(b) ? (a):(b))
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

const double multiplier = 0.997;

char str[MAX], color[MAX];
int n, m, last[MAX], order[MAX], R[MAX], B[MAX];

double rand_real(){
    return (double)rand() / RAND_MAX;
}

int solve(){
    int i, j, res = 0, red = 0, blue = 0, rcard = 0, bcard = 0;

    for (j = 0; j < n; j++){
        i = order[j];
        int req_red = max(R[i] - rcard, 0);
        int req_blue = max(B[i] - bcard, 0);

        int buy_red = max(req_red - red, 0);
        int buy_blue = max(req_blue - blue, 0);

        int tokens_bought = max(buy_red, buy_blue);

        res += tokens_bought;
        red += tokens_bought, blue += tokens_bought;
        red -= req_red, blue -= req_blue;

        if (color[i] == 'R') rcard++;
        else bcard++;
    }
    return res + n;
}

int main(){
    int t, i, j, k, x, lim, res, cur, next;

    while (scanf("%d", &n) != EOF){
        for (i = 0; i < n; i++){
            scanf("%s %d %d", str, &R[i], &B[i]);
            color[i] = str[0];
        }
        for (i = 0; i < n; i++) order[i] = i;

        double temperature = 3e5;
        cur = res = solve(), lim = 3e5;

        for (t = 0; t < lim; t++){
            m = ((lim - t - 1) * n / lim) + 1;
            for (i = 0; i < n; i++) last[i] = order[i];

            while (m--){
                i = rand() % n, j = rand() % n;
                x = order[i], order[i] = order[j], order[j] = x;
            }

            next = solve();
            if (next < res) res = next;

            if (next < cur) cur = next;
            else{
                double p = exp((double)-(next - cur) / temperature);
                if (rand_real() <= p) cur = next;
                else{
                    for (i = 0; i < n; i++) order[i] = last[i];
                }
            }

            if (temperature > 1e-20) temperature *= multiplier;
        }

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


#include <stdio.h>

long long two(long long n);

long long three(long long n);
long long absolute(long long x)
{
    if(x<0)
    return -x;
    else
    return x;
    }

int main(void) {
    // your code goes here
    long long a1,b1,a2,b2,two_1,three_1,two_2,three_2,diff_2,diff_3,temp;
    scanf("%lld %lld %lld %lld",&a1,&b1,&a2,&b2);

    two_1=two(a1)+two(b1);
    three_1=three(a1)+three(b1);

    two_2=two(a2)+two(b2);
    three_2=three(a2)+three(b2);

    two_1+=three_1;
    two_2+=three_2;

    diff_2=absolute(two_1-two_2);
    diff_3=absolute(three_1-three_2);
    //printf("%lld %lld",diff_2,diff_3);

    if(three_1>three_2)
    {
        temp=diff_3;
        while(temp>0)
        {
        if(a1%3==0)
        a1=(a1/3)*2;
        else if(b1%3==0)
        b1=(b1/3)*2;
        temp--;
        }

    }
    else
    {
        temp=diff_3;
        while(temp>0)
        {
        if(a2%3==0)
        a2=(a2/3)*2;
        else if(b2%3==0)
        b2=(b2/3)*2;
        temp--;
        }

    }

    if(two_1>two_2)
    {
        temp=diff_2;
        while(temp>0)
        {
        if(a1%2==0)
        a1=a1/2;
        else if(b1%2==0)
        b1=b1/2;
        temp--;
        }

    }
    else
    {
        temp=diff_2;
        while(temp>0)
        {
        if(a2%2==0)
        a2=a2/2;
        else if(b2%2==0)
        b2=b2/2;
        temp--;
        }

    }

//      printf("%lld %lld\n%lld %lld\n",a1,b1,a2,b2);
    if((a1*b1)==(a2*b2))
    {
        printf("%lld\n",diff_2+diff_3);
        printf("%lld %lld\n%lld %lld\n",a1,b1,a2,b2);
    }
    else
    printf("-1\n");

    return 0;
}

long long two(long long n)
{
    long long count=0;
    while(n%2==0)
    {
        n=n/2;
        count++;

    }
    return count;
}
long long three(long long n)
{
    long long count=0;
    while(n%3==0)
    {
        n=n/3;
        count++;

    }
    return count;
}


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

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

char visited[12][105];
long long ar[10], dp[12][105], binomial[1010][1010] = {0};

long long F(long long i, long long n){
    if (i == 10) return (n == 0);
    if (visited[i][n]) return dp[i][n];

    long long j, k;
    long long x, y, res = 0;
    for (j = ar[i]; j <= n; j++){
        if (i == 0) x = (long long)binomial[n - 1][j] * F(i + 1, n - j);
        else x = (long long)binomial[n][j] * F(i + 1, n - j);
        res = (res + x) % MOD;
    }

    visited[i][n] = 1;
    return (dp[i][n] = res);
}

long long solve(long long n){
    clr(visited);
    long long i, j, x, s = 0, res = 0;
    for (i = 1; i < 10; i++) s += ar[i];

    for (i = 1; i <= n; i++){
        x = F(0, i);
        res = (res + x) % MOD;
    }
    return (res % MOD);
}

int main(){
    long long n, i, j, k, res;

    for (i = 0; i < 1010; i++){
        for (j = 0; j <= i; j++){
            if (i == j || j == 0) binomial[i][j] = 1;
            else binomial[i][j] = (binomial[i - 1][j - 1] + binomial[i - 1][j]) % MOD;
        }
    }

    while (scanf("%lld", &n) != EOF){
        if (n == 0) break;
        for (i = 0; i < 10; i++) scanf("%lld", &ar[i]);
        res = solve(n);
        printf("%lld\n", res);
    }
    return 0;
}


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

#define N	400000
#define A	26

char aa[1 + N + 1]; int ss[1 + N], n_;
int len[2 + N * 2], tt[2 + N * 2][A], fff[2 + N * 2][A], ff[2 + N * 2];

int node(int l) {
	static int _;

	len[_] = l;
	return _++;
}

void init() {
	int a;

	node(0), node(-1);
	aa[0] = -1;
	ff[0] = ff[1] = 1;
	for (a = 0; a < A; a++)
		fff[0][a] = fff[1][a] = 1;
}

void add(int a) {
	int s = ss[n_];

	aa[++n_] = a;
	if (aa[n_ - 1 - len[s]] != a)
		s = fff[s][a];
	if (!tt[s][a]) {
		int t = node(len[s] + 2), f = tt[fff[s][a]][a];

		ff[t] = f;
		memcpy(fff[t], fff[f], sizeof fff[f]), fff[t][(int) aa[n_ - len[f]]] = f;
		tt[s][a] = t;
	}
	ss[n_] = tt[s][a];
}

int next(int a, int d) {
	int s = ss[n_], a1 = -1, a2 = -1;

	while (len[s] >= d - 2) {
		if (a1 == -1)
			a1 = aa[n_ - len[s]];
		else
			a2 = aa[n_ - len[s]];
		s = ff[s];
	}
	while (a < A && (a == a1 || a == a2))
		a++;
	return a;
}

int main() {
	static char cc[N + 1];
	int n, d, i, i_, a_;

	init();
	scanf("%d%s", &d, cc), n = strlen(cc);
	if (d == 1) {
		printf("Impossible\n");
		return 0;
	}
	i_ = -1, a_ = -1;
	for (i = 0; i < n; i++) {
		int a;

		if ((a = next(cc[i] - 'a' + 1, d)) < A)
			i_ = i, a_ = a;
		add(cc[i] - 'a');
		if (len[ss[n_]] >= d)
			break;
	}
	if (i_ == -1) {
		printf("Impossible\n");
		return 0;
	}
	n_ = i_;
	cc[i_] = a_ + 'a', add(a_);
	for (i = i_ + 1; i < n; i++) {
		int a = next(0, d);

		cc[i] = a + 'a', add(a);
	}
	printf("%s\n", cc);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int fun(char *);
int fun(char *s)
{
    int sum=0;
    while(*s)
    {
        if(*s>='A'&&*s<='Z')
        {
            sum=sum+(*s-'A'+1);
        }
        if(*s>='a'&&*s<='z')
        {
            sum=sum-(*s-'a'+1);
        }
        s++;
    }
    return sum;
}
int main()
{
    char a[10001];
    scanf("%s",a);
    printf("%d\n",fun(a));
    return 0;
}


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

int main() {
	int i, j, n, m, cnt;
	static char *s;
	static int **ee, *aa;

	scanf("%d%d", &n, &m);
	ee = malloc(sizeof(*ee) * (n + 1));
	for (i = 1; i <= n; i++)
		ee[i] = calloc(3, sizeof(*ee[i]));
	aa = malloc(sizeof(*aa) * 4 * n);
	s = malloc((n + 2) * sizeof(*s));
	memset(s + 1, '0', n);
	s[n + 1] = '\0';
	while (m-- > 0) {
		int u, v;

		scanf("%d%d", &u, &v);
		for (j = 0; j < 3; j++)
			if (ee[u][j] == 0) {
				ee[u][j] = v;
				break;
			}
		for (j = 0; j < 3; j++)
			if (ee[v][j] == 0) {
				ee[v][j] = u;
				break;
			}
	}
	for (i = 0; i < n; i++)
		aa[i] = i + 1;
	cnt = n;
	while (cnt > 0) {
		int a, k;

		a = aa[--cnt];
		k = 0;
		for (j = 0; j < 3; j++)
			if (ee[a][j] > 0 && s[a] == s[ee[a][j]])
				k++;
		if (k > 1) {
			s[a] = s[a] == '1' ? '0' : '1';
			for (j = 0; j < 3; j++)
				if (ee[a][j] > 0)
					aa[cnt++] = ee[a][j];
		}
	}
	printf("%s\n", s + 1);
	return 0;
}


#include <stdio.h>

#define rep(i,n) for(i=0;i<n;i++)
#define N 404

int x, y, n, d, vx[20], vy[20], mem[N][N];

int rec( int a, int b )
{
	if( a*a + b*b > d*d ) return 1;
	int & ans = mem[a+N/2][b+N/2];
	if( ans > -1 ) return ans;
	int i;
	rep(i,n) if( !rec( a+vx[i], b+vy[i] ) ) return ans = 1;
	return ans = 0;
}

int main()
{
	int i, j;
	rep(i,N) rep(j,N) mem[i][j] = -1;
	scanf( "%d%d%d%d", &x, &y, &n, &d );
	for( i = 0; i < n; i++ ) scanf( "%d%d", &vx[i], &vy[i] );
	printf( rec(x,y) ? "Anton\n" : "Dasha\n" );
	return 0;
}


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

#define MOD 1000000007

long long waysToPlay(int n, int m, int k);
long long oldWaysToPlay(int n, int m, int k, long long mult);
long long choose(long long a, long long b);

long long oldWays;
long long known[1000][1000][1000];

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

    // n: dimension
    // y: dimension
    // k: amount of moves

    printf("%lld\n", (choose(n-1, 2*k) * choose(m-1, 2*k)) % MOD);

    oldWays = 0;
    //long long ways = waysToPlay(n, m, k) % MOD;
    //printf("%lld\n")
    //printf("%lld\n", ways);

    // Old
    //oldWaysToPlay(n, m, k, 1);
    //printf("%lld\n", oldWays);

    return EXIT_SUCCESS;
}

long long waysToPlay(int n, int m, int k) {
    // 6, 7, 2
    //
    // 4, 4, 1 => 9
    // 6, 7, 2 => 75

    // If no more moves
    if (k == 0) {
        return 1;
    } else if (k == 1) {
        //printf("%d %d %d %lld\n", n, m, k, choose(n-1, 2) * choose(m-1, 2));
        return choose(n-1, 2) * choose(m-1, 2);
    } else {
        // For 5x5 (3x3)
        // Answer = 36
        // k = 1
        // x = 4c2
        // y = 4c2

        // 10 * 10 = 100

        // Smallest cases
        int n_small = 1 + 2*(k-1);
        int m_small = 1 + 2*(k-1);
        long long ways = 0;

        // They must be TWO less
        for (int n_i = n_small; n_i < n-1; n_i++) {
            for (int m_i = m_small; m_i < m-1; m_i++) {
                // The amount of positions that the new rectangle
                // can fit into
                int newMult = (n-n_i-1)*(m-m_i-1);

                // Cache the result
                if (known[m_i][n_i][k-1] == 0) {
                    known[m_i][n_i][k-1] = waysToPlay(n_i, m_i, k-1);
                }

                // Add it to ways
                ways += newMult * known[m_i][n_i][k-1];
            }
        }

        //printf("%d %d %d %lld\n", n, m, k, ways);

        return ways;
    }

    // Otherwise there are no ways
    return 0;
}

long long choose(long long a, long long b) {
    if (b > a) return 0;

    //aCb = a!/((a-b)!*b!)
    //    = a*(a-1)...(a-b+1)/
    //      b*(b-1)...1

    //    = a*(a-1)...(a-b+1)/
    //      1*2*......b

    long long result = 1;
    for (int i = 0; i < b; i++) {
        result = (result * (a-i)) % MOD;
        result = (result / (i+1)) % MOD;
    }

    //printf("%lldC%lld = %lld\n", a, b, result);
    return result % MOD;
}

//OLD method
long long oldWaysToPlay(int n, int m, int k, long long mult) {
    // 3x3 in 6x7 (4x5)
    if (k == 0) {
        oldWays = (oldWays+mult) % MOD;
        //printf("+ %lld\n", mult);
    } else if (k == 1 && n == 1 && m == 1) {
        oldWays = (oldWays+mult) % MOD;
    } else {
        // Smallest cases
        int n_small = 1 + 2*(k-1);
        int m_small = 1 + 2*(k-1);

        // How many places it can go X inside solutions

        // They must be TWO less
        for (int n_i = n_small; n_i < n-1; n_i++) {
            for (int m_i = m_small; m_i < m-1; m_i++) {
                // Positional permutation (x,y and y,x)
                // int twice = (m_i != n_i) ? 2 : 1;

                //printf("passing: %d %d %lld\n", n_i, m_i, mult);
                oldWaysToPlay(n_i, m_i, k-1, mult*(n-n_i-1)*(m-m_i-1));
            }
        }
    }

    return 0;
}


// write in C...
#include <stdio.h>

#ifdef DEBUG
#define D(x...) fprintf(stderr, x)
#else
#define D(x...)
#endif

#define MOD 1000000009

int n, w, b;
int c[4005][4005];

int p(int n, int k) {
    if (k > n || k < 1) return 0;
    else return c[n-1][k-1];
}

int main() {
    int i, j;

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

    for (i = 0; i < 4005; i++) c[i][0] = 1;
    for (i = 1; i < 4005; i++)
        for (j = 1; j <= i; j++)
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD;

    long long res = 0;

    for (i = 0; i <= n; i++) {
        res = (res + (long long)p(b, i) * (long long)p(w, n-i) * (long long)(n-i-1)) % MOD;
    }

    for (i = 1; i <= w; i++) res = (res * i) % MOD;
    for (i = 1; i <= b; i++) res = (res * i) % MOD;

    printf("%d\n", (int)res);

    return 0;
}


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

#define EPS 1e-10
void doubleIntSort(double d[],int m[],int s){int i,j,r;double k1,k2,t;if(s<=1)return;k1=(d[0]+d[s-1])/2.0;k2=k1+EPS;k1-=EPS;i=-1;j=s;for(;;){while(d[++i]<k1);while(d[--j]>k2);if(i>=j)break;t=d[i];d[i]=d[j];d[j]=t;r=m[i];m[i]=m[j];m[j]=r;}doubleIntSort(d,m,i);doubleIntSort(d+j+1,m+j+1,s-j-1);}

int n;
int nf, ne, ns;
int rf, re, rs; double Rf, Re, Rs;
int df, de;
int h[21];
double res;

double x[100]; int ev[100];
int F, E, S;

void calc(void){
  int i,j,k;
  double w, tmp;

  if(n%2==0){
    i = h[0] + h[1]*10;
    j = h[n-2] + h[n-1]*10;
    if(i>j) return;
  }

  F = E = S = 0;
  rep(i,n){
    if(h[i]==0){
      x[2*i  ] = (i/2) - Rf;
      x[2*i+1] = (i/2) + Rf;
      ev[2*i  ] = 1;
      ev[2*i+1] = -1;
    }
    if(h[i]==1){
      x[2*i  ] = (i/2) - Re;
      x[2*i+1] = (i/2) + Re;
      ev[2*i  ] = 2;
      ev[2*i+1] = -2;
    }
    if(h[i]==2){
      x[2*i  ] = (i/2) - Rs;
      x[2*i+1] = (i/2) + Rs;
      ev[2*i  ] = 3;
      ev[2*i+1] = -3;
    }
  }
  doubleIntSort(x, ev, 2*n);

  tmp = 0;
  rep(i,2*n-1){
    w = x[i+1] - x[i];
    if(ev[i]==1) F++; if(ev[i]==-1) F--;
    if(ev[i]==2) E++; if(ev[i]==-2) E--;
    if(ev[i]==3) S++; if(ev[i]==-3) S--;
    tmp += (F*df + E*de) * (w * (S+1));
  }
  if(res < tmp) res = tmp;
}

void brute(int depth){
  if(depth==n) calc();

  if(nf > 0){
    h[depth] = 0;
    nf--;
    if(depth%2==0 || h[depth-1] <= h[depth]) brute(depth+1);
    nf++;
  }
  if(ne > 0){
    h[depth] = 1;
    ne--;
    if(depth%2==0 || h[depth-1] <= h[depth]) brute(depth+1);
    ne++;
  }
  if(ns > 0){
    h[depth] = 2;
    ns--;
    if(depth%2==0 || h[depth-1] <= h[depth]) brute(depth+1);
    ns++;
  }
}

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

  res = 0;

  scanf("%d%d%d",&nf,&ne,&ns);
  n = nf + ne + ns;
  scanf("%d%d%d",&rf,&re,&rs);
  scanf("%d%d",&df,&de);

  Rf = sqrt(rf*rf-1); if(rf==1) Rf = 0;
  Re = sqrt(re*re-1); if(re==1) Re = 0;
  Rs = sqrt(rs*rs-1); if(rs==1) Rs = 0;

  brute(0);

  printf("%.15f\n",res);

  return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int f[10],p[10],n,k,dmin;
char a[10][10];
void pp(int j){
	int i,i1,sum,min,max;
	if(j==k){
		for(i1=0;i1<n;i1++){
			sum=0;
			for(i=0;i<k;i++)sum=sum*10+a[i1][p[i]]-'0';
			if(i1==0)max=sum,min=sum;
			else{
				if(sum>max)max=sum;
				if(sum<min)min=sum;
			}
		}
		if(dmin>max-min)dmin=max-min;
		return;
	}
	for(i=0;i<k;i++){
		if(f[i]==0){
			f[i]=1;
			p[j]=i;
			pp(j+1);
			f[i]=0;
		}
	}
	return;
}
int main(){
	int i,j;
	while(scanf("%d%d",&n,&k)!=EOF){
		memset(f,0,sizeof(f));
		dmin=1<<31-1;
		for(i=0;i<n;i++)scanf("%s",a[i]);
		pp(0);
		printf("%d\n",dmin);
	}
}


#include <stdio.h>

int main() {
	int k;
	scanf("%d", &k);
	int i;
	int count = 1;
	int square = 1;
	char cha = 'a';
	if(k == 0) {
		printf("a\n");
		return 0;
	}
	while(k > 0) {
		while(square <= k) {
			count++;
			square += count;
		}
		for(i=0;i<count;i++) {
			printf("%c", cha);
		}
		cha++;
		k -= square - count;
		count = 1;
		square = 1;
	}
	printf("\n");

	return 0;
}


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

#define MAX (10 << 6)

char iscomp[MAX];

void
do_comp (void)
{
	int i;

	iscomp[1] = 1;

        for (i = 2; i < MAX; i++) {
                int     jx;
                int     sx;

                if (iscomp[i]) {
                        continue;
                }

                for (jx = i; (jx * i) < MAX ;jx++) {
                        sx = jx * i;
                        if (!iscomp[sx]) iscomp[sx] = 1;
                }
        }
}

int
ispal (int inp)
{
	int	i, j;
	char	tmp[32];
	int	len;

	sprintf(tmp, "%d", inp);
	len = strlen(tmp)-1;

	for (i = 0, j = len; i <= j; i++, --j) {
		if (tmp[i] != tmp[j]) {
			return 0;
		}
	}

	return 1;
}

int
main ()
{
	int	i,n = 1;
	int	p, q;
	int	npr = 0, npa = 0;
	int	ans = 0;

	do_comp();
	scanf ("%d%d", &p, &q);

	for (i = 1; i < MAX; i++) {
		npa += ispal (i);
		npr += !(iscomp[i]);

		if (q * npr <= p * npa) {
			ans = i;
		}
	}
	if (ans) {
		printf ("%d\n", ans);
	} else {
		puts ("Palindromic tree is better than splay tree");
	}

	return 0;
}


#include <stdio.h>

struct dxy
{
	long long d;
	long long x;
	long long y;
};

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

struct dxy ext_euc(long long a, long long b)
{
	long long x, y;
	struct dxy ans;
	if (b == 0)
	{
		ans.d = a;
		ans.x = 1;
		ans.y = 0;
		return ans;
	}

	ans = ext_euc(b, a%b);
	x = ans.y;
	y = ans.x - (a/b)*ans.y;

	ans.x = x;
	ans.y = y;
	return ans;
}

long long box(long long numer, long long denom)
{
	if (numer % denom == 0 || numer * denom >= 0)
	{
		return numer / denom;
	}

	return (numer / denom) - 1;
}

int main()
{
	long long a1, a2, b1, b2;
	long long L, R;
	long long alpha1, alpha2, r, start, end;
	long long p, p1, q, i, j;
	long long hcf;
	struct dxy temp;

	scanf("%lld %lld %lld %lld %lld %lld", &a1, &b1, &a2, &b2, &L, &R);

	hcf = gcd(a1, a2);
	if ((b2 - b1) % hcf != 0)
	{
		printf("%d\n", 0);
		return 0;
	}

	r = box((b2 - b1), hcf);
	alpha1 = box(a1, hcf);
	alpha2 = box(a2, hcf);

	temp = ext_euc(alpha1, -alpha2);
	p = temp.x * r;
	p1 = temp.y * r;
	if (temp.d < 0)
	{
		p = -p;
		p1 = -p1;
	}

	start = box((L-b1), a1) + 1;
	start -= ((L-b1) % a1) == 0 ? 1 : 0;
	end = box((R-b1), a1);

	q = box((start-p), alpha2) + 1;
	q -= ((start-p) % alpha2) == 0 ? 1 : 0;

	j = 0;
	for (i = q; i <= box((end-p), alpha2); i++)
	{
		if (p + i*alpha2 >=0 && p1 + i*alpha1 >= 0)
		{
			j++;
		}
	}

	//printf("%lld %lld\n", start, end);
	//printf("%lld %lld %lld %lld\n", p, p1, q, r);
	//printf("%lld %lld\n", box((end-p), alpha2), box((start-p), alpha2));
	/*
	if (p + q*alpha2 < 0 || p1 + q*alpha1 < 0)
	{
		printf("%d\n", 0);
		return 0;
	}
	*/
	printf("%lld\n", j);
	return 0;
}


#include <stdio.h>

#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))

int main(void) {
    int i;
    int n;
    int l[5], r[5];
    int val;
    long long cnt[10001];
    double sum, ans;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d %d", l + i, r + i);

    sum = 0.0;
    for (val = 1; val <= 10000; val++) {
        int high1, high2, high3, high4, high5;
        int sec1, sec2, sec3, sec4;

        cnt[val] = 0;

        // high1パターン
        //  sec1 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                if (high1 != sec1) {
                    long long way;

                    way = 1LL;
                    for (i = 0; i < n; i++)
                        if (i == high1)
                            way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                        else if (i == sec1)
                            way *= val >= l[i] && val <= r[i];
                        else
                            way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                    cnt[val] += way;
                }
        //  sec2 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    if (high1 != sec1 && high1 != sec2) {
                        long long way;

                        way = 1LL;
                        for (i = 0; i < n; i++)
                            if (i == high1)
                                way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                            else if (i == sec1 || i == sec2)
                                way *= val >= l[i] && val <= r[i];
                            else
                                way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                        cnt[val] += way;
                    }
        //  sec3 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    for (sec3 = sec2 + 1; sec3 < n; sec3++)
                        if (high1 != sec1 && high1 != sec2 && high1 != sec3) {
                            long long way;

                            way = 1LL;
                            for (i = 0; i < n; i++)
                                if (i == high1)
                                    way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                                else if (i == sec1 || i == sec2 || i == sec3)
                                    way *= val >= l[i] && val <= r[i];
                                else
                                    way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                            cnt[val] += way;
                        }
        //  sec4 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    for (sec3 = sec2 + 1; sec3 < n; sec3++)
                        for (sec4 = sec3 + 1; sec4 < n; sec4++)
                            if (high1 != sec1 && high1 != sec2 && high1 != sec3 && high1 != sec4) {
                                long long way;

                                way = 1LL;
                                for (i = 0; i < n; i++)
                                    if (i == high1)
                                        way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                                    else if (i == sec1 || i == sec2 || i == sec3 || i == sec4)
                                        way *= val >= l[i] && val <= r[i];
                                    else
                                        way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                                cnt[val] += way;
                            }

        // high2パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++) {
                    long long way;

                    way = 1LL;
                    for (i = 0; i < n; i++)
                        if (i == high1 || i == high2)
                            way *= val >= l[i] && val <= r[i];
                        else
                            way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                    cnt[val] += way;
                }
        // high3パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++) {
                        long long way;

                        way = 1LL;
                        for (i = 0; i < n; i++)
                            if (i == high1 || i == high2 || i == high3)
                                way *= val >= l[i] && val <= r[i];
                            else
                                way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                        cnt[val] += way;
                    }
        // high4パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++)
                    for (high4 = high3 + 1; high4 < n; high4++) {
                            long long way;

                            way = 1LL;
                            for (i = 0; i < n; i++)
                                if (i == high1 || i == high2 || i == high3 || i == high4)
                                    way *= val >= l[i] && val <= r[i];
                                else
                                    way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                            cnt[val] += way;
                        }
        // high5パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++)
                    for (high4 = high3 + 1; high4 < n; high4++)
                        for (high5 = high4 + 1; high4 < n; high4++) {
                                long long way;

                                way = 1LL;
                                for (i = 0; i < n; i++)
                                    if (i == high1 || i == high2 || i == high3 || i == high4 || i == high5)
                                        way *= val >= l[i] && val <= r[i];
                                    else
                                        way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                                cnt[val] += way;
                            }

        sum += cnt[val];
    }

    ans = 0.0;
    for (i = 1; i <= 10000; i++)
        ans += (double)i * cnt[i] / sum;

    printf("%.15f\n", ans);

    return 0;
}


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

        else if (n==2||m==2)
        {
            if (Max%4==0)
                printf("%d\n",Max);
            else if (Max%4==1)
                printf("%d\n",Max+1);
            else
                printf("%d\n",(Max/4)*4+4);
        }
        else
            printf("%d\n",(m*n+1)/2);
    return 0;
}


#include <stdio.h>
#define MIN(A,B) ((A) < (B)) ? (A) : (B)

long long int dp[45][3][3];
int cost[5][5];

long long int solve(int disk, int from, int to) {
    int aux;
    long long int price1;
    long long int price2;

    if (dp[disk][from][to] != -1) {
        return dp[disk][from][to];
    }

    for (aux = 0; aux < 3; aux++) {
        if (aux != from && aux != to) {
            break;
        }
    }

    if (disk == 1) {
        return MIN(cost[from][to], cost[from][aux] + cost[aux][to]);
    }
    if (disk == 2) {
        price1 = solve(1, from, aux) + cost[from][to] + solve(1, aux, to);
        price2 = solve(1, from, to) + cost[from][aux] + solve(1, to, from) + cost[aux][to] + solve(1, from, to);
        dp[disk][from][to] = MIN(price1, price2);
        return dp[disk][from][to];
    }

    price1 = solve(disk - 1, from, aux) + cost[from][to] + solve(disk - 1, aux, to);
    /*price2 = solve(disk - 1, from, aux) + cost[from][to] + cost[aux][from] +
                    cost[from][to] + solve(disk - 1, aux, from) + cost[to][from] + solve(disk - 1, from, to); */
    price2 = solve(disk - 1, from, to) + cost[from][aux] + solve(disk - 1, to, from) +
                    cost[aux][to] + solve(disk - 1, from, to);

    dp[disk][from][to] = MIN(price1, price2);

    return dp[disk][from][to];
}

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

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

    for (k = 0; k <= n; k++) {
        for (i = 0; i < 3; i++) {
            for (j = 0; j < 3; j++) {
                dp[k][i][j] = -1;
            }
        }
    }

    printf("%I64d\n", solve(n, 0, 2));

    return 0;
}


#include <stdio.h>

const int p = 1000000007;

char s[101];

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

  if (b%2) return (a*pow(a*a, b/2))%p;

  return pow(a*a, b/2)%p;
}

int
main(void)
{
  int i, res=1, n;

  gets(s);

  for (i=0; s[i]; ++i);
  n = i;

  if (s[n-1] == '1') res = 1;
  else res = 0;

  for (i=n-2; i >= 0; --i)
    {
      if (s[i] == '0')
    {
      res *= 2;
      res %= p;
    }
      else
    {
      res = res*2 + pow(2, 2*(n-i - 1));
      res %= p;
    }
    }

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

  return 0;
}


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

char g[64][64];
int x,y;

#define PUT(a,b) if(a>=0 && a<x && b>=0 && b<y) g[a][b]=1
#define CAN(a,b) (a<0 || b<0 || a>=x || b>=y || !g[a][b])
#define INSIDE(a,b) (a>=0 && b>=0 && a<x && b<y)

void put(int atx,int aty) {
  PUT(atx,aty);
  PUT(atx+1,aty);
  PUT(atx-1,aty);
  PUT(atx,aty+1);
  PUT(atx,aty-1);
}

int can(int atx,int aty) {
  if(!CAN(atx,aty)) return 0;
  if(!CAN(atx+1,aty)) return 0;
  if(!CAN(atx-1,aty)) return 0;
  if(!CAN(atx,aty+1)) return 0;
  if(!CAN(atx,aty-1)) return 0;
  return 1;
}

int count(int atx,int aty) {
  int ret=0;
  if(INSIDE(atx,aty)) ret++;
  if(INSIDE(atx+1,aty)) ret++;
  if(INSIDE(atx-1,aty)) ret++;
  if(INSIDE(atx,aty+1)) ret++;
  if(INSIDE(atx,aty-1)) ret++;
  return ret;
}

int dx[]={0,1,0,-1,0};
int dy[]={0,0,1,0,-1};

void printboard() {
  int i,j;
  for(j=0;j<y;j++) {
    for(i=0;i<x;i++) printf("%c",g[i][j]?'*':'.');
    printf("\n");
  }
}

int try(int atx,int aty) {
  int ret=x*y;
  int x2,y2,i,j;
  memset(g,0,sizeof(g));
  for(i=-20;i<60;i++) for(j=-20;j<60;j++) {
    x2=atx;
    y2=aty;

    x2+=2*i;
    y2-=i;

    y2+=2*j;
    x2+=j;
    if(count(x2,y2)>0) {
      ret--;
      put(x2,y2);
    }
  }
  return ret;
}

int main() {
  int best=0,t,cur,i,ans;
  scanf("%d %d",&x,&y);
  if(x>y) t=x,x=y,y=t;
  if(x==1 && y==1) { printf("0\n"); return 0; }
  if(x==1) {
    printf("%d\n",y-(y-1)/3-1);
    return 0;
  }
  if(x==3) {
    printf("%d\n",2*y); return 0;
  }
  if(x==2) {
    ans=0;
    for(i=0;i<y-1;i++) {
      if(i%2==0) ans++;
      else ans+=2;
    }
    ans++;
    printf("%d\n",ans);
    return 0;
  }
  cur=try(-1,0); if(best<cur) best=cur;
  cur=try(0,0);   if(best<cur) best=cur;
  cur=try(0,1);   if(best<cur) best=cur;
  cur=try(1,0);   if(best<cur) best=cur;

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


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

int main() {
        int n;
        scanf("%d", &n);
        char s[n];
        scanf("%s", s);
        char alphabet[26] = "abcdefghijklmnopqrstuvwxyz";
        int cur = 25;
        int deleted = 0;
        while(cur != 0 && (n - deleted) != 1) {
                int found = 0;
                // printf("Cur: %i Str: %s Del: %i\n", cur, s, deleted);
                for (int i = 0; i < (n - deleted); i++) {
                        if (alphabet[cur] == s[i]) {
                                if (i != (n - deleted) - 1) {
                                        if (alphabet[cur-1] == s[i+1]) {
                                                for (int j = i; j < n-1; j++) {
                                                        s[j] = s[j+1];
                                                }
                                                s[n - deleted - 1] = '\0';
                                                found = 1;
                                                deleted += 1;
                                                continue;
                                        }
                                }
                                if (i != 0) {
                                        if (alphabet[cur-1] == s[i-1]) {
                                                for (int j = i; j < n-1; j++) {
                                                        s[j] = s[j+1];
                                                }
                                                s[n - deleted - 1] = '\0';
                                                found = 1;
                                                deleted += 1;
                                                continue;
                                        }
                                }
                        }
                }

                if (found == 0) {
                        cur -= 1;
                }
        }
        printf("%d", deleted);
}
// strcpy(&str[idx_to_delete], &str[idx_to_delete + 1]);
// RemoveAdjacent.c


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

int main()
{
  int n , a ,b;
  int diva = 0;
  int divb = 0;
  int totalmatches=0;
  int counter=1;

  scanf("%d %d %d" , &n , &a , &b);
  if( ((b > n/2) || (a > n/2)) && ( (b <= n/2) || (a <= n/2))  )
  {
    printf("Final!");
    return 0;
  }
  int temp=n;
  while(temp!=1)
    {
      temp = temp/2;
      totalmatches++;
    }
    totalmatches--;
    if(a%2!=0)
      a = (a+1);
    if(b%2!=0)
      b = (b+1);
    while(1)
    {
    if(a > n/2)
    {
      n=n/2;
      a=a-n;
      b=b-n;
    }
    else
      n=n/2;
    if( ((b > n/2) || (a > n/2)) && ( (b <= n/2) || (a <= n/2)))
    {
      printf("%d" , totalmatches);
      return 0;
    }
    else if(a==b)
    {
      printf("1");
      return 0;
    }
    totalmatches--;
  }

  return 0;
}


#include <stdio.h>
#include <iso646.h>

int main() {
    int sign = 1;
    int current = 0;
    int value = 0;

    for(char c; '\n' != (c = getchar()); ) {
        if(c == '+' or c == '-') {
            value += sign * current;
            sign = (c == '+' ? 1 : -1);
            current = 0;
        }

        current *= 10;
        current += c - '0';
    }

    printf("%d", value + sign * current);

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int len1,len2,k,max=0,i,j,pan=0;
    char s[99999],t[99999];
    int p=0;
    scanf("%s",s);
    scanf("%s",t);
    len1=strlen(s);
    len2=strlen(t);
    int start[10],last[10];
    if(len1==len2)
    {
        max=0;
        pan=1;
    }
    else
    {
        for(i=0; i<len1; i++)
        {
            if(s[i]==t[0])
            {
                for(j=i,k=0; j<len1&&k<len2; j++,k++)
                {
                    if(s[j]==t[k])
                        continue;
                    else
                    {
                        break;
                    }
                }
                if(k==len2)
                {
                    start[p]=i;
                    last[p]=i+len2-1;
                    p++;
                }
                else;

            }
        }
        int ff;
        for(i=0; i<p; i++)
        {
            ff=start[i];
            if(max<ff)
                max=ff;
            ff=len1-last[i]-1;
            if(max<ff)
                max=ff;
        }
        if(max!=0)
            pan=1;
    }
    if(pan==1)
    printf("%d",max);
    else
        printf("5");
    return 0;
}


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

enum {
    N = 1010
};
const int MOD = 1e9 + 7;

int dp[N][2 * N], k, ls;
char s[N];

int rec(int pos, int dist, int anyDigit) {
    if(pos == ls)
        return dist == 0;
    if(anyDigit && dp[ls - pos][dist] != -1)
        return dp[ls - pos][dist];

    int limit = anyDigit ? 9 : s[pos] - '0';
    int ret = 0, i;
    for(i = 0; i <= limit; i++) {
        int ndist = dist + (dist != 0);
        if(i == 4 || i == 7)
            ndist = dist <= k ? 0 : 1;
        ret += rec(pos + 1, ndist, anyDigit || (i < limit));
        while(ret >= MOD)
            ret -= MOD;
    }
    if(anyDigit)
        dp[ls - pos][dist] = ret;
    return ret;
}

int isLucky() {
    int i, prev = 0;
    while(prev < ls && s[prev] != '4' && s[prev] != '7')
        prev++;
    for(i = prev + 1; i < ls; i++) {
        if(s[i] == '4' || s[i] == '7') {
            if(i - prev <= k)
                return 1;
            prev = i;
        }
    }
    return 0;
}

int main() {
    int t;
    scanf("%d %d", &t, &k);
    memset(dp, -1, sizeof(dp));
    while(t--) {
        scanf("%s", s);
        ls = strlen(s);
        int val = rec(0, k + 1, 0) - isLucky();

        scanf("%s", s);
        ls = strlen(s);
        val = rec(0, k + 1, 0) - val;
        while(val < 0)
            val += MOD;
        while(val >= MOD)
            val -= MOD;
        printf("%d\n", val);
    }
    return 0;
}


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


#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M 1000000007LL
const long long MSQ = M * M;
inline int mul(int a, int b) { return int(a * 1LL * b % M); }
inline int powr(int a, int b) {
    int ans = 1;
    while (b) {if (b & 1) ans = mul(ans, a); a = mul(a, a); b >>= 1;}
    return ans;
}
int main(){
    int n, k, i, j, c, d;
    long long x, y, z, u, v, res;
    scanf("%d %d", &n, &k);
    if (k == 0) res = n;
    else{
        if (n <= (k + 1)){
            for (i = 1, res = 0; i <= n; i++) res += powr(i, k);
        }
        else{
            res = 0;
            u = 1, v = 1, z = 0;
            for (i = 0; i <= (k + 1); i++){
                u = (u * (n - i)) % M;
                if (i) v = ((v * -i) + MSQ) % M;
            }
            for (i = 0, c = 1, d = k + 1; i <= (k + 1); i++, c++, d--){
                z = (z + powr(i, k)) % M;
                x = (u * z) % M;
                x = (x * powr(n - i, M - 2)) % M;
                y = ((x * powr(v, M - 2)) % M);
                v = (v * c) % M;
                if (d) v = (v * powr(d, M - 2)) % M;
                if (i & 1) y = M - y;
                res += y;
            }
        }
    }
    printf("%lld\n", res % M);
    return 0;
}


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

int md;

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

	if (k == 0)
		return 1;
	p = power(a, k / 2);
	p = p * p % md;
	if (k % 2)
		p = p * a % md;
	return p;
}

void mult(int aa[][2], int bb[][2], int cc[][2]) {
	int i, j, k;

	for (i = 0; i < 2; i++)
		for (j = 0; j < 2; j++) {
			long long c = 0;

			for (k = 0; k < 2; k++)
				c += (long long) aa[i][k] * bb[k][j];
			cc[i][j] = c % md;
		}
}

void power_(int aa[][2], int pp[][2], int tt[][2], long long k) {
	if (k == 0) {
		pp[0][0] = pp[1][1] = 1;
		pp[0][1] = pp[1][0] = 0;
		return;
	}
	if (k % 2 == 0) {
		power_(aa, tt, pp, k / 2);
		mult(tt, tt, pp);
	} else {
		power_(aa, pp, tt, k / 2);
		mult(pp, pp, tt);
		mult(tt, aa, pp);
	}
}

int main() {
	static int aa[2][2], pp[2][2], tt[2][2];
	long long n, k, x0, x1, ans;
	int l, h;

	scanf("%lld%lld%d%d", &n, &k, &l, &md);
	if (l < 64 && k >= 1LL << l) {
		printf("0\n");
		return 0;
	}
	aa[0][0] = 1, aa[0][1] = 1;
	aa[1][0] = 1, aa[1][1] = 0;
	power_(aa, pp, tt, n);
	x0 = (pp[0][0] + pp[0][1]) % md;
	x1 = (power(2, n) - x0 + md) % md;
	ans = 1;
	for (h = 0; h < l; h++)
		ans = ans * ((k & 1LL << h) == 0 ? x0 : x1) % md;
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>

int Length(long long int x)
{
	int cnt = 0;
	while(x)
	{
		x /= 10;
		cnt++;
	}
	return cnt;
}

int main()
{
	long long int a, b;
	scanf("%I64d %I64d", &a, &b);
	int digitA[15] = {};
	int digitB[20] = {};
	long long int c = a;
	while(c)
	{
		digitA[c%10] ++;
		c /= 10;
	}
	if(Length(a) < Length(b))
	{
		for(int i=9; i>=0; i--)
		{
			for(int j=0; j<digitA[i]; j++)
				printf("%d", i);
		}
	}
	else
	{
		int num = 0;
		while(b)
		{
			digitB[++num] = b%10;
			b /= 10;
		}
		while(num >= 0 && digitA[digitB[num]] >= 1)
		{
			printf("%d", digitB[num]);
			digitA[digitB[num]]--;
			num --;
		}
		if(num >= 0)
		{
			for(int i=digitB[num]-1; i>=0; i--)
				if(digitA[i])
				{
					printf("%d", i);
					digitA[i] --;
					break;
				}

			for(int i=9; i>=0; i--)
			{
				for(int j=0; j<digitA[i]; j++)
					printf("%d", i);
			}
		}
	}
	return 0;
}


#include<stdio.h>
long long dp(int,int,char);
long long dar[1003][102],MOD,powmod[1003],modmod[1003];
int n,k;
int main(){
	int i,j,l;
	scanf("%d %d %d",&n,&k,&i);
	MOD=(long long)i;
	powmod[0]=1%k;
	modmod[0]=1%MOD;
	for(i=1;i<=n;i++){
		powmod[i]=(powmod[i-1]*10)%k;
		modmod[i]=(modmod[i-1]*10)%MOD;
	}
	for(i=0;i<1003;i++){
		for(j=0;j<102;j++){
			dar[i][j]=-1;
		}
	}
	dar[n][0]=1;
	for(i=n-1;i>0;i--){
		dar[i][0]=(9*modmod[n-1-i])%MOD;
	}
	printf("%d\n",(int)dp(0,0,0));
	return 0;
}

long long dp(int dig,int mod,char fl){
	long long toret;
	int i;
	if(dig>n){
		return 0;
	}
	if(fl&&mod==0){
		return dar[dig][0];
	}
	if(fl==0||dar[dig][mod]==-1){
		toret=0;
		toret+=dp(dig+1,mod,fl);
		for(i=1;i<10;i++){
			toret=(toret+dp(dig+1,(mod+i*powmod[dig])%k,1))%MOD;
		}
		if(fl!=0){
			dar[dig][mod]=toret;
		}
	}
	else{
		toret=dar[dig][mod];
	}
	return toret;
}


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

typedef long long int lli;

#define TRUE         (1==1)
#define FALSE        (!(TRUE))
#define in32(x)      scanf("%d", &(x))
#define in64(x)      scanf("%I64d", &(x))
#define instr(x)     scanf("%s", (x))
#define out32(x)     printf("%d\n", (x))
#define out64(x)     printf("%I64d\n", (x))
#define outstr(x)    printf("%s\n", (x))
#define max(a,b)     ((a)<(b))?(b):(a)
#define min(a,b)     ((a)>(b))?(b):(a)
#define abs(a)       ((a)<0)?(-(a)):(a)
#define fo3(i,a,b)   for(i=(int)(a);i<=(int)(b);i++)
#define of3(i,a,b)   for(i=(int)(a);i>=(int)(b);i--)

#define MOD    998244353
#define MAX    5005
#define SENT   -1

typedef struct Pair {
    int fi, se;
} Pair;

int comp(Pair * f, Pair * s) {
    return (f->fi - s->fi);
}

void sort(Pair ** arr, int size) { // CHANGE THIS
    int i;
    if (size < 6) {
        int nSize = 0;
        int s = size;
        while (size != 0) {
            nSize = 0;
            for (i = 0; i < size - 1; i++)
                if (comp(arr[i], arr[i+1]) > 0) { // CHANGE THIS
                    Pair * tmp = arr[i];
                    arr[i] = arr[i+1];
                    arr[i+1] = tmp;
                    nSize = i+1;
                }
            size = nSize;
        }
        return;
    }
    Pair ** tmp = (Pair **)calloc(size, sizeof(Pair *)); // CHANGE THIS
    int lSize = (size >> 1);
    int rSize = size - lSize;
    sort(arr, lSize); sort(arr + lSize, rSize);
    int lPtr = 0, rPtr = 0;
    int ptr = 0;
    while (ptr != size) {
        if (lPtr == lSize)
            tmp[ptr] = arr[lSize + (rPtr++)];
        else if (rPtr == rSize || comp(arr[lPtr], arr[lSize + rPtr]) <= 0) // CHANGE THIS
            tmp[ptr] = arr[lPtr++];
        else
            tmp[ptr] = arr[lSize + (rPtr++)];
        ptr++;
    }
    for (i = 0; i < size; i++)
        arr[i] = tmp[i];
    free(tmp);
}

int main(void) {
    int i, n, m;
    in32(n);
    in32(m);
    int need[n];
    fo3(i,0,n-1)
        in32(need[i]);
    Pair ** p = calloc(m, sizeof(Pair*));
    fo3(i,0,m-1) {
        p[i] = calloc(1,sizeof(Pair));
        in32(p[i]->fi);
        in32(p[i]->se);
    }
    sort(p,m);
    lli pos = 2000000, min = 0, max = 2000000 - 1;
    int have[n];
    while (min <= max) {
        lli mid = (min + max) >> 1;
        fo3(i,0,n-1)
            have[i] = 0;
        lli spent = 0;
        lli maxDay = mid;
        of3(i,m-1,0) {
            int day = p[i]->fi;
            if (day > mid)
                continue;
            int ind = p[i]->se-1;
            int miss = need[ind] - have[ind];
            if (maxDay > day)
                maxDay = day;
            int buy = miss;
            if (buy > maxDay)
                buy = maxDay;
            have[ind] += buy;
            maxDay -= buy;
            spent += buy;
        }
        fo3(i,0,n-1)
            spent += ((need[i] - have[i])<<1);
        if (spent <= mid) {
            pos = mid;
            max = mid - 1;
        } else
            min = mid + 1;
    }
    out64(pos);
    return 0;
}


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

int main()
{
    int d,y,p,page,sr;
    scanf("%d %d",&d,&y);
    page=0;
    while(y--)
    {

           sr=(int)sqrt(d);
           if((sr*sr)==d)
           {
                         page+=1;
           }
           else
           {
               while(sr--)
               {
                    if(d%(sr*sr)==0)
                    {
                          p=d/(sr*sr);
                          if((sr*sr)*p==d)
                          {
                          page+=p;
                          break;
                          }
                          else
                          {
                              sr--;
                          }
                    }
               }

           }
           d++;
    }

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


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

#define FOR(i, a, b) for (i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int cmpfunc (const void * a, const void * b){
	//qsort(values, 5, sizeof(int), cmpfunc);
	return ( *(int*)a - *(int*)b );
}

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

long long max(long long a,long long b){
	return a > b ? a : b;
}
// long long ncr(int n, int k)
// {
//     long long C[k+1];
//     memset(C, 0, sizeof(C));
//   	int i;
//   	int j;
//     C[0] = 1;  // nC0 is 1

//     for (i = 1; i <= n; i++)
//     {
//         // Compute next row of pascal triangle using
//         // the previous row
//         for ( j = min(i, k); j > 0; j--)
//             C[j] = C[j] + C[j-1];
//     }
//     return C[k];
// }

void solve(int t){
	int n,k;
	scanf("%d%d",&n,&k);
	int a[n];
	int i,j;
	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}

	// printf("Case #%d: %ld\n",t,count);
}

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

int main(){
	int n,k,a,b;
	scanf("%d%d",&n,&k);
	scanf("%d%d",&a,&b);
	int i,j;
	long long maximum = LONG_MIN, minimum = LONG_MAX;
	long long l = a-b;
	long long total = (long long)n*k;
	while(l <= total){
		if(l <= 0){
			l += k;
			continue;
		}
		long long g = ((long long)n*k)/gcd((long long)n*k,(long long)l);

		maximum = max(g,maximum);
		minimum = min(g,minimum);
		l += k;
	}

	l = a+b;
	while(l <= total){
		if(l <= 0){
			l += k;
			continue;
		}
		long long g = ((long long)n*k)/gcd((long long)n*k,(long long)l);

		maximum = max(g,maximum);
		minimum = min(g,minimum);
		l += k;
	}

	l = k-a+b;
	while(l <= total){
		if(l <= 0){
			l += k;
			continue;
		}
		long long g = ((long long)n*k)/gcd((long long)n*k,(long long)l);

		maximum = max(g,maximum);
		minimum = min(g,minimum);
		l += k;
	}

	l = k-a-b;
	while(l <= total){
		if(l <= 0){
			l += k;
			continue;
		}
		long long g = ((long long)n*k)/gcd((long long)n*k,(long long)l);

		maximum = max(g,maximum);
		minimum = min(g,minimum);
		l += k;
	}

	printf("%I64d %I64d\n",minimum,maximum);
}


#include<stdio.h>
char mp[9][9];
int dir;
int n,m,x,y;
int get_dis(int dir){
  if(dir==0&&y==m)return 100;
  if(dir==1&&x==n)return 100;
  if(dir==0){
    for(int i=y+1;i<=m;i++)
      if(mp[x][i]=='*')return i-y;
  }else
    for(int i=x+1;i<=n;i++)
      if(mp[i][y]=='*')return i-x;
  return 100;
}

int main(void){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
  dir=0;
  int ans=0;
  x=1;y=1;
  for(int i=0;i<n+m;i++){
    if(mp[x][y]=='*')ans++;
    //    printf("%d %d\n",x,y);
    if(get_dis(dir)<=get_dis(!dir)){
      if(dir==0)y++;
      else x++;
    }else{
      if(dir==0)x++;
      else y++;
      dir=!dir;
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

int main(){
    int i, num, flag=0;
    char str[11];
    scanf("%s", str);
    num = strlen(str);
    if(num == 1){
        if(str[0] != '3' || str[0] != '7'){
            printf("No\n");
        }
        else
            printf("Yes\n");
    }
    else{
        for(i=0; i<num/2; i++){
            if(str[i] == '1' || str[i] == '2'){
                printf("No\n");
                flag = 1;
                break;
            }
            if(str[i] == '0'){
                if(str[num-i-1] != '8'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '3'){
                if(str[num-i-1] != '3'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '4'){
                if(str[num-i-1] != '6'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '5'){
                if(str[num-i-1] != '9'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '6'){
                if(str[num-i-1] != '4'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '7'){
                if(str[num-i-1] != '7'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '8'){
                if(str[num-i-1] != '0'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '9'){
                if(str[num-i-1] != '5'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
        }
        if(num%2 == 1 && flag == 0){
            if(str[num/2] == '0' || str[num/2] == '1' || str[num/2] == '2' || str[num/2] == '4' || str[num/2] == '5' || str[num/2] == '6' || str[num/2] == '8' || str[num/2] == '9'){
                printf("No\n");
                flag = 1;
            }
        }
        if(flag == 0){
            printf("Yes\n");
        }
    }
    return 0;
}


#include <stdio.h>
#define MOD 998244353

__int64 Pow(__int64 a, __int64 b)
{
    if (b == 0) return 1;
	if (b % 2 > 0) return (Pow(a, b - 1) * a) % MOD;
	__int64 half = Pow(a, b / 2) % MOD;
	return (half * half) % MOD;
}
__int64 nCr(__int64 n, __int64 r)
{
    __int64 A = 1; // A = n!, B = (n-r)!r!
    __int64 B = 1;
    __int64 ans;
    __int64 i;

    for(i=1;i<=n;i++)
    {
        A *= i;
        A %= MOD;
    }
    for(i=1;i<=n-r;i++)
    {
        B *= i;
        B %= MOD;
    }
    for(i=1;i<=r;i++)
    {
        B *= i;
        B %= MOD;
    }
    __int64 B2 = Pow(B, MOD-2);
    ans = (A * B2) % MOD;
    return ans;
}

int main(void)
{
    __int64 size, max;
    __int64 ans;

    while(scanf("%lld %lld", &size, &max))
    {
        ans = nCr(max, size - 1) * (size-2) % MOD;
        ans = (ans * Pow(2, size-3)) % MOD;
        printf("%lld\n", ans);
    }

    return 0;
}


#include <stdio.h>
#define MOD (1000000007ULL)
#define min(a, b)  ( ((a) < (b)) ? (a) : (b) )

unsigned long long cnk[101][101], pows[101], pows2[101][101], dp[101][10001];

unsigned long long quick_pow(unsigned long long a, unsigned long long n)
{
    if (n == 0) {
        return 1;
    } else if ((n & 1ULL) == 0) {
        unsigned long long tmp = quick_pow(a, n / 2ULL);
        return (tmp * tmp) % MOD;
    } else {
        return (quick_pow(a, n - 1) * a) % MOD;
    }
}

void count_cnk(void)
{
    int i, j;
    cnk[0][0] = 1;
    for(i = 1; i < 101; ++i){
        cnk[i][0] = 1;
        for(j = 1; j < 101; ++j){
            cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % MOD;
        }
    }
}

int
main(void)
{
    int i, j, t;
    unsigned long long n, m, k;

    count_cnk();

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

    unsigned long long rem =  m % n;
    for (i = 1; i <= n; ++i) {
        if (rem) {
            pows[i] = m / n + 1;
            --rem;
        } else {
            pows[i] = m / n;
        }
        for (j = 0; j <= n; ++j) {
            pows2[i][j] = quick_pow(cnk[n][j], pows[i]);
        }
    }

    dp[0][0] = 1;
    for (i = 1; i <= n; ++i) {
        for (j = 0; j <= min(k, i * n); ++j) {
            for (t = 0; t <= min(n, j); ++t) {
                dp[i][j] = (dp[i][j] + dp[i - 1][j - t] * pows2[i][t]) % MOD;
            }
        }
    }

    printf("%I64u", dp[n][k]);
    return 0;
}


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

int n;

double p(double a, double e) {
    return a / e;
}
double q(double a, double b, double c, double d, double e, double f) {
    return (a / d) * (b / e) * (c / f);
}

double solve(int k) {
    const double q3 = q(k, k-1, k-2, n, n-1, n-2);
    const double q0 = q(n-k, n-k-1, n-k-2, n, n-1, n-2);
    const double q11 = q(k, n-k, n-k-1, n, n-1, n-2);
    const double q10 = 2 * q11;
    const double q20 = q(k, k-1, n-k, n, n-1, n-2);
    const double q21 = 2 * q20;
    const double res = q3 + q10 + q20 + q21;
    assert(res >= 0.);
    assert(res <= 1.);
    return res;
}

int main(void) {
    double p;
    scanf("%d%lf", &n, &p);
    int l = 0, r = n - 1;
    if (p == 0) {
        puts("0");
        return 0;
    }
    while (l + 1 < r) {
        const int m = (l + r) >> 1;
        if (solve(m) >= p) {
            r = m;
        } else {
            l = m;
        }
    }
    assert(r > 0);
    assert(r < n);
    printf("%d\n", r);
}


#include <stdio.h>

int main () {
	char input_1[2] = {0};
	char input_2[2] = {0};
	char input[4] = {0};
	char check_1[2] = {0};
	char check_2[2] = {0};
	char check[4] = {0};
	int i =0;
	int idx = 0;
	int input_posi_x = 0;
	int check_idx = 0;
	char temp;

	scanf("%s", input_1);
	scanf("%s", input_2);
	scanf("%s", check_1);
	scanf("%s", check_2);

	for (i =0; i<2; i++) {
		if (input_1[i] == 'X')
			idx =i;
		else if (check_1[i] == 'X')
			check_idx = i;
		input[i] = input_1[i];
		check[i] = check_1[i];
	}
	//printf("%d\n\n", i);
	for (; i<4; i++) {
		if (input_2[i-2] == 'X')
			idx =i;
		else if (check_2[i-2] == 'X')
			check_idx =i;
		input[i] = input_2[i-2];
		check[i] = check_2[i-2];
	}
	/*for (i =0; i<4; i++) {
		printf("%c %c\n", input[i], check[i]);
	}*/
	//printf("%d %d", idx, check_idx);
	if (idx%2 == idx/2) {
		input_posi_x = 1<<1 && 1<<2;
	} else {
		input_posi_x = 1<<0 && 1<<3;
	}

	if (!(input_posi_x && (1 << check_idx))) {
		printf("NO");
		return 0;
	} else {
		temp = input[idx];
		input[idx] = input[check_idx];
		input[check_idx] = temp;
		for (i=0; i<4; i++) {
			if(input[i] != check[i]) {
				printf("NO");
				return 0;
			}
		}
		printf("YES");
	}

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int n,m;
int s[107],d[107],c[107];
int ix[107];
int r[107];
int slt(const void *p,const void *q){
	return d[*((int *)p)]-d[*((int *)q)];
}
void run(){
	int i,j,k;
	while(scanf("%d%d",&n,&m)!=EOF){
		for(i=0;i<m;i++){
			scanf("%d%d%d",&s[i],&d[i],&c[i]);
			s[i]--;
			d[i]--;
		}
		for(i=0;i<m;i++){
			ix[i]=i;
		}
		qsort(ix,m,sizeof(ix[0]),slt);
		for(i=0;i<n;i++){
			r[i]=0;
		}
		for(i=0;i<m;i++){
			r[d[i]]=m+1;
		}
		for(i=0;i<m;i++){
			k=0;
			for(j=s[ix[i]];j<d[ix[i]];j++){
				if(r[j]!=0){
					continue;
				}
				k++;
				r[j]=ix[i]+1;
				if(k==c[ix[i]]){
					break;
				}
			}
			if(k<c[ix[i]]){
				printf("-1\n");
				break;
			}
		}
		if(i<m){
			continue;
		}
		for(i=0;i<n;i++){
			printf("%d ",r[i]);
		}
		printf("\n");
	}
}
main(){
	run();
	return 0;
}


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

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

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

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

	for(int i=0; i<n; i++)
		scanf("%d",a+i);
	// printf("lol\n");
	int dsc[n+1][2];
	dsc[n][0] = 0;
	dsc[n][1] = 0;

	for(int i=n-1; i>=0; i--)
	{
		dsc[i][0] = a[i] + min( dsc[i+1][0], dsc[i+1][1] );
		dsc[i][1] = max( dsc[i+1][0], dsc[i+1][1] );
	}

	printf("%d %d\n",min(dsc[0][0],dsc[0][1]),max(dsc[0][0],dsc[0][1]) ) ;

return 0;
}


#include<stdio.h>
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
int main()
{
    long long int a,b,c,d,move,move_p,move_v;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    if(a<c&&b<d)printf("Polycarp");
    else if((a<c&&b>d)||(a>c&&b<d)||(a>c&&b>d)){
        move_p=a+b;
        move_v=MAX(c,d);
        if(move_p<=move_v)printf("Polycarp");
        else printf("Vasiliy");
    }
    else if(a==c&&b<d){
        move=d-b;
        a-=move;
        c-=move;
        d-=move;
        if(a<=c&&b<=d)printf("Polycarp");
        else printf("Vasiliy");
    }
     else if(a<c&&b==d){
        move=c-a;
        b-=move;
        c-=move;
        d-=move;
        if(a<=c&&b<=d)printf("Polycarp");
        else printf("Vasiliy");
    }
    return 0;
}


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

long long int M(long long int n) {
	long long int r = 0;
	for(int k = 2 ; k <= pow(n, 1./3.) ; k++) {
		r += (long long int)((float)n / k / k / k);
	}
	return r;
}

long long int bs(long long int m) {
	long long int l = 1, r = 200000, c, mm;
	while(l < r) {
		c = l + r >> 1;
		mm = M(c);
		if(mm >= m) {
			r = c;
		} else {
			l = c + 1;
		}
	}
	if(M(c) == m) return c;
	return -1;
}

int main() {
	long long int m;
	scanf("%I64d", &m);
	printf("%I64d\n", bs(m));
	return 0;
}


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

    printf("%ld\n",n);

  //  return 0;
}


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

int main()
{
    long times,n,value,lvalue,ans,g,maxg=0,v[46],i,j,k;
    scanf("%ld%ld%ld",&times,&n,&value);
    for (i=1;i<=n;i++)
        scanf("%ld",&v[i]);
    ans=0;
    for (i=1;i<=n;i++)
        ans+=v[i];
    for (i=0;i<=times;i++)
        if (value-ans*i>=0)
        {
            g=(n+1)*i;
            lvalue=value-ans*i;
            for (j=1;j<=n;j++)
                for (k=1;k<=times-i;k++)
                    if (lvalue-v[j]>=0)
                    {
                        g++;
                        lvalue-=v[j];
                    }
                    else
                        break;
            if (g>maxg)
                maxg=g;
        }
        else
            break;
    printf("%ld\n",maxg);
    return 0;
}


#include <stdio.h>

int main() {
    int n,x,one,i,two,four,z,j,k;
    scanf("%d",&x);
    for(n=1;;n+=2) {
        one=1;
        two=(n-1)/4;
        z=(n+1)/4;
        four=z*z;
        z=(n-1)/4;
        four+=z*z;
        for(i=0;i<=one;i++) for(j=0;j<=two;j++) for(k=0;k<=four;k++) if(i+j*2+k*4==x) goto end;
        if((n&3)==3) for(i=0;i<four;i++) {
            if(4*i+2*(two+1)==x) goto end;
            if(4*i+2*(two+2)==x) goto end;
        }
    }
end:
    printf("%d\n",n);
    return 0;
}


#include <stdio.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
    ll k, n;
    scanf("%lld%lld", &n, &k);
    char s[105];
    scanf("%s", s);

    char next[105][30];   //next[i][c]: iから見て一番初めにc(+'a')が現れるindex
    for (int j = 0; j < 26; j++) next[n][j] = n;
    for (int i = n-1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) next[i][j] = next[i+1][j];
        next[i][s[i]-'a'] = i;
    }

    ll dp[105][105] = {0};      //dp[i][l]: sのi文字目を接尾辞としてもつ，長さlの部分文字列の数
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 26; ++j) {
            if (next[i][j] >= n) continue;
            for (int l = 0; l < n; l++)
                dp[next[i][j] + 1][l+1] += dp[i][l];
        }
    }

    ll ans = 0, cnt = 0, tmp = 1;
    for (int j = n-1; j >= 0; j--) {
        for (int i = 0; i <= n; i++) {
            tmp += dp[i][j];
            if(tmp < k){
                ans += (n-j)*dp[i][j];
            }else{
                ans += (n-j)*(k-(tmp-dp[i][j]));
                break;
            }
        }
        if(tmp >= k) break;
    }
    if(tmp < k) ans = -1;

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


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

#define N	50
#define N_	(N + 2)
#define M_	(M * 3 + 2)
#define M	(N * (N - 1))
#define X	100000
#define INF	0x3f3f3f3f

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

int oo[1 + M], oh[1 + M];

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

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

int oo_[1 + M_ * 2], oh_[1 + M_ * 2], __;

int link_(int o, int h) {
	oo_[__] = o, oh_[__] = h;
	return __++;
}

int ae[N], ae_[N_], dd[N_], n_;
int ii[M], jj[M], ww[M]; char tt[M]; int ij[M_], cc[M_ * 2], m_;
int pq[1 + N], iq[N], cnt;

int less(int u, int v) { return dd[u] < dd[v]; }

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

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

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

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

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

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

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

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

void dijkstra(int n, int s) {
	memset(dd, 0x3f, n * sizeof *dd);
	dd[s] = 0, pq_add_last(s);
	while (cnt) {
		int i = pq_remove_first(), o;

		for (o = ae[i]; o; o = oo[o]) {
			int h = oh[o];

			if (!tt[h]) {
				int j = jj[h], d = dd[i] + ww[h];

				if (dd[j] > d) {
					if (dd[j] == INF)
						pq_add_last(j);
					dd[j] = d, pq_up(j);
				}
			}
		}
	}
}

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

	ij[h] = i ^ j, cc[h << 1] = c, cc[h << 1 | 1] = 0;
	ae_[i] = link_(ae_[i], h << 1);
	ae_[j] = link_(ae_[j], h << 1 | 1);
}

int bfs(int s, int t) {
	static int qu[N_];
	int i, head, cnt;

	for (i = 0; i < n_; i++)
		dd[i] = n_;
	head = cnt = 0;
	dd[s] = 0, qu[head + cnt++] = s;
	while (cnt) {
		int d, o;

		i = qu[cnt--, head++], d = dd[i] + 1;
		for (o = ae_[i]; o; o = oo_[o]) {
			int h_ = oh_[o];

			if (cc[h_]) {
				int h = h_ >> 1, j = i ^ ij[h];

				if (dd[j] > d) {
					dd[j] = d;
					if (j == t)
						return 1;
					qu[head + cnt++] = j;
				}
			}
		}
	}
	return 0;
}

int dfs(int i, int t) {
	int d, o;

	if (i == t)
		return 1;
	d = dd[i] + 1;
	for (o = ae_[i]; o; o = oo_[o]) {
		int h_ = oh_[o];

		if (cc[h_]) {
			int h = h_ >> 1, j = i ^ ij[h];

			if (dd[j] == d && dfs(j, t)) {
				cc[h_]--, cc[h_ ^ 1]++;
				return 1;
			}
		}
	}
	dd[i] = n_;
	return 0;
}

void dinic(int s, int t) {
	while (bfs(s, t))
		while (dfs(s, t))
			;
}

int main() {
	static double ans[X + 1];
	static int dd1[N], dd2[N], xx[M];
	int n, m, q, h, x, s, t;

	scanf("%d%d", &n, &m);
	for (h = 0; h < m; h++) {
		int i, j, w;

		scanf("%d%d%d", &i, &j, &w), i--, j--;
		ii[h] = i, jj[h] = j, ww[h] = w;
		ae[i] = link(ae[i], h);
	}
	n_ = n + 2, s = n, t = n + 1;
	x = 0;
	while (x < X) {
		int k, y, z, d, d_;

		memset(tt, 0, m * sizeof *tt);
		dijkstra(n, 0);
		memcpy(dd1, dd, n * sizeof *dd);
		d = dd1[n - 1];
		memset(ae_, 0, n_ * sizeof *ae_), __ = 1, m_ = 0;
		link2(s, 0, INF);
		link2(n - 1, t, INF);
		for (h = 0; h < m; h++) {
			int i = ii[h], j = jj[h], w = ww[h];

			if (dd1[i] + w == dd1[j]) {
				tt[h] = 1;
				link2(s, j, 1), link2(i, t, 1);
				if (xx[h] == 0)
					link2(j, i, INF);
			}
		}
		dinic(s, t);
		d_ = INF;
		k = 0;
		for (h = 0; h < m; h++) {
			int i = ii[h], j = jj[h];

			if (tt[h]) {
				if ((dd[i] == n_) == (dd[j] == n_))
					tt[h] = 0;
				else if (dd[i] != n_) {
					tt[h] = 1;
					k++;
				} else {
					tt[h] = 2;
					k--;
					d_ = min(d_, d + xx[h]);
				}
			}
		}
		dijkstra(n, 0);
		memcpy(dd2, dd, n * sizeof *dd);
		d_ = min(d_, dd2[n - 1]);
		for (h = 0; h < m; h++)
			if (tt[h] == 2)
				d_ = min(d_, d + dd2[ii[h]] - dd1[jj[h]]);
		y = d_ - d <= (X - x) / k ? x + (d_ - d) * k : X;
		for (z = x; z <= y; z++)
			ans[z] = d + (double) (z - x) / k;
		if (y < X)
			for (h = 0; h < m; h++)
				if (tt[h])
					ww[h] += d_ - d;
		x = y;
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d", &x);
		printf("%f\n", ans[x]);
	}
	return 0;
}


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

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

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

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

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

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

			return 0;
		}

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

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


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

bool check(int s, int r)
{
  int i=(s/50)%475,j;
  for(j=0;j<25;j++)
    {
      i=(i*96+42)%475;
      if(26+i==r)
	return true;
    }
  return false;
}

int main()
{
  int p,x,y;
  scanf("%d %d %d",&p, &x, &y);
  int temp=x,i=x,j=x,countn=0,countp=0;
  int key=0;
     while(j>=y)
	{
	  if(check(j,p))
	    {
	      key=1;
	      break;
	    }
	  j-=50;
	}
     if(key==1)
       printf("0\n");
     else
       {
	 while(1)
	   {
	     i+=50;
	     countp++;
	     if(check(i,p))
	       {
		 key=2;
		 break;
	       }
	   }
	 if(countp%2==0)
	   printf("%d\n",countp/2);
	 else
	   printf("%d\n",countp/2+1);
       }

  return 0;
}


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

struct point {
    int x, idx, rk;
};

int cmp1 (const void *a, const void *b)
{
    struct point *m = (struct point *)a, *n = (struct point *)b;
    return m->x - n->x;
}

int cmp2 (const void *a, const void *b)
{
    struct point *m = (struct point *)a, *n = (struct point *)b;
    return m->idx - n->idx;
}

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

    struct point pts[n];
    for (i = 0; i < n; i++) {
        scanf ("%d", &pts[i].x);
        pts[i].idx = i;
    }

    for (i = 0; i < m; i++) {
        int x, y;
        scanf ("%d %d", &x, &y);
    }

    qsort (pts, n, sizeof (struct point), cmp1);
    for (i = 0; i < n; i++) {
        pts[i].rk = i % 2;
        //printf ("new %d %d %d\n", pts[i].x, pts[i].idx, pts[i].rk);
    }

    qsort (pts, n, sizeof (struct point), cmp2);
    for (i = 0; i < n; i++) {
        printf ("%d ", i% 2);
    }

    printf ("\n");

    return 0;
}


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

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

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

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

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

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

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

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

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

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

    return 0;
}


#include<stdio.h>
#include<math.h>
double f(int a)
{
	if(a>=0)
	{
		return sqrt(a)+5*pow(a,3);
	}
	else
	{
		return sqrt(-a)+5*pow(a,3);
	}
}
int main()
{
	double b;
	int i,j,arr[11];
	for(i=0;i<11;i++)
	{
		scanf("%d",&arr[i]);
	}
	for(i=10;i>=0;i--)
	{
		j=arr[i];
		b=f(arr[i]);
		if(b>400)
		{
			printf("f(%d)=MAGNA NIMIS!\n",j);
		}
		else
		{
			printf("f(%d)=%0.2f\n",j,b);
		}
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
#define MAX(A,B) (((A) > (B)) ? (A) : (B))

char s1[105];
char s2[105];
char virus[105];
int fail[105];

int dp[105][105][105];
int seq[105][105][105][3];
int print[105][105][105];
int n, m, p;

int solve(int pos1, int pos2, int pos3) {
    if (pos3 >= p) {
        return -INF;
    }

    if (pos1 >= n || pos2 >= m) {
        return 0;
    }

    if (seq[pos1][pos2][pos3][0] != -1) {
        return dp[pos1][pos2][pos3];
    }

    int aux, aux2, aux3;
    int way1, way2, way3;

    aux = aux2 = aux3 = -INF;
    way1 = way2 = way3 = 0;
    if (s1[pos1] == s2[pos2]) {
        if (s1[pos1] == virus[pos3]) {
            print[pos1][pos2][pos3] = 1;
            aux = 1 + solve(pos1 + 1, pos2 + 1, pos3 + 1);
            way1 = pos1 + 1;
            way2 = pos2 + 1;
            way3 = pos3 + 1;
        } else {
            way1 = pos1;
            way2 = pos2;
            if (pos3 != 0) {
                if (virus[fail[pos3 - 1]] == s1[pos1]) {
                    aux = 1 + solve(pos1 + 1, pos2 + 1, fail[pos3 - 1] + 1);
                    print[pos1][pos2][pos3] = 1;
                    way1++;
                    way2++;
                    way3 = fail[pos3 - 1] + 1;
                } else {
                    aux = solve(pos1, pos2, fail[pos3 - 1]);
                    way3 = fail[pos3 - 1];
                }
            } else {
                aux = 1 + solve(pos1 + 1, pos2 + 1, 0);
                print[pos1][pos2][0] = 1;
                way1++;
                way2++;
                way3 = 0;
            }
        }
    }

    dp[pos1][pos2][pos3] = aux;
    seq[pos1][pos2][pos3][0] = way1;
    seq[pos1][pos2][pos3][1] = way2;
    seq[pos1][pos2][pos3][2] = way3;

    aux2 = solve(pos1 + 1, pos2, pos3);
    aux3 = solve(pos1, pos2 + 1, pos3);

    if (aux2 > dp[pos1][pos2][pos3]) {
        dp[pos1][pos2][pos3] = aux2;
        print[pos1][pos2][pos3] = 0;
        seq[pos1][pos2][pos3][0] = pos1 + 1;
        seq[pos1][pos2][pos3][1] = pos2;
        seq[pos1][pos2][pos3][2] = pos3;
    }
    if (aux3 > dp[pos1][pos2][pos3]) {
        dp[pos1][pos2][pos3] = aux3;
        print[pos1][pos2][pos3] = 0;
        seq[pos1][pos2][pos3][0] = pos1;
        seq[pos1][pos2][pos3][1] = pos2 + 1;
        seq[pos1][pos2][pos3][2] = pos3;
    }

    return dp[pos1][pos2][pos3];
}

void build_fail(void) {
    int len;
    int i;

    fail[0] = 0;
    i = 1;
    len = 0;

    while(i < p) {
        if (virus[i] == virus[len]) {
            len++;
            fail[i++] = len;
        } else {
            if (len != 0) {
                len = fail[len - 1];
            } else {
                fail[i++] = 0;
            }
        }
    }
    return;
}

int main(void) {
    int i, j, k;
    int res;

    int w1, w2, w3;

    scanf(" %s %s %s", s1, s2, virus);

    n = strlen(s1);
    m = strlen(s2);
    p = strlen(virus);

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            for (k = 0; k < p; k++) {
                seq[i][j][k][0] = -1;
                print[i][j][k] = 0;
            }
        }
    }

    build_fail();
    res = solve(0, 0, 0);

    if (res) {
        i = 0;
        j = 0;
        k = 0;
        while(i != n && j != m) {
            if (print[i][j][k]) {
                printf("%c", s1[i]);
            }
            w1 = seq[i][j][k][0];
            w2 = seq[i][j][k][1];
            w3 = seq[i][j][k][2];
            i = w1;
            j = w2;
            k = w3;
        }
        printf("\n");
    } else {
        printf("0\n");
    }

    return 0;
}


#include <stdio.h>

#define W_L 1
#define W_K 2
#define B_K -4

void set_p(int board[8][8]){
   int i,j,k,l;

   for(i = 0; i<8; i++)
      for(j = 0; j<8; j++)
	 if(!(board[i][j]>0 || board[i][j]==B_K))
	    board[i][j]=0;

   for(i = 0; i<8; i++)
      for(j = 0; j<8; j++)
	 if(board[i][j]>0){
	    if(board[i][j]==W_L){
	       for(k = j-1; k>=0 && board[i][k]<=0;k--)
		  board[i][k]=-1;
	       for(k = j+1; k<8 && board[i][k]<=0; k++)
		  board[i][k]=-1;
	       for(k = i-1; k>=0 && board[k][j]<=0;k--)
		  board[k][j]=-1;
	       for(k = i+1; k<8 && board[k][j]<=0; k++)
		  board[k][j]=-1;
	    } else if(board[i][j]==W_K) {
	      for(k = i-1; k<=i+1; k++)
		 for(l = j-1; l<=j+1; l++)
		    if(k>=0 && k<8 && l>= 0 && l<8 && board[k][l]<=0)
		       board[k][l]=-1;
	    }
	 }

}

void cpy_board(int dest[8][8], int source[8][8]){
   int i,j;
   for(i = 0; i<8; i++)
      for(j = 0; j<8; j++)
	 dest[i][j] = source[i][j];
}

int main(){
   int x,y;
   char _x;
   int i, j;
   int other = 0;
   int board[8][8];
   int temp_board[8][8];

   for(i = 0; i<8; i++)
      for(j = 0; j<8; j++)
	 board[i][j] = 0;

   scanf("%c%d ",&_x,&y);
      x = _x-'a';
      y--;
   board[x][y] = W_L;
   scanf("%c%d ",&_x,&y);
      x = _x-'a';
      y--;
   board[x][y] = W_L;
   scanf("%c%d ",&_x,&y);
      x = _x-'a';
      y--;
   board[x][y] = W_K;
   scanf("%c%d",&_x,&y);
      x = _x-'a';
      y--;
   board[x][y] = B_K;

   set_p(board);

   if(board[x][y] == B_K)
      printf("OTHER\n");
   else {
      other = 0;
      for(i = x-1; i<=x+1; i++)
	 for(j = y-1; j<=y+1; j++){
	    if(i>=0 && i<8 && j>=0 && j<8)
	       if(board[i][j]==0)
		  other = 1;
	    if(i>=0 && i<8 && j>=0 && j<8 && board[i][j]==W_L){
	       cpy_board(temp_board, board);
	       temp_board[x][y]=0;
	       temp_board[i][j]=B_K;
	       set_p(temp_board);
	       other = other || (temp_board[i][j]==B_K);
	    }
	 }
      if(other)
	 printf("OTHER\n");
      else
	 printf("CHECKMATE\n");

   }
   return 0;
}


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

typedef int64_t i64;
typedef int32_t i32;

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

const i32 mod = 1000000007;

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

i32 mod_pow (i32 r, i32 n) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n & 1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

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

void matmul (i32 *c, i32 *a, i32 *b, i32 n) {
  static i32 *tmp = NULL;
  if (tmp == NULL) {
    tmp = (i32 *) calloc (n * n, sizeof (i32));
  }
  memset (tmp, 0, sizeof (i32) * n * n);
  for (i32 i = 0; i < n; ++i) {
    for (i32 k = 0; k < n; ++k) {
      for (i32 j = 0; j < n; ++j) {
	tmp[i * n + j] = (tmp[i * n + j] + (i64) a[i * n + k] * b[k * n + j]) % mod;
      }
    }
  }
  memcpy (c, tmp, sizeof (i32) * n * n);
}

void run (void) {
  i32 n = read_int();
  i32 k = read_int();
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  i32 cnt[2] = {0, 0};
  for (i32 i = 0; i < n; ++i) {
    a[i] = read_int();
    cnt[a[i]]++;
  }
  if (cnt[0] == 0 || cnt[1] == 0) {
    puts("1");
    return;
  }
  i32 d = 0;
  for (i32 i = 0; i < cnt[0]; ++i) {
    d += a[i];
  }
  const i32 m = MIN(cnt[0], cnt[1]) + 1;
  i32 *t = (i32 *) calloc (m * m, sizeof (i32));
  i32 *s = (i32 *) calloc (m * m, sizeof (i32));
  for (i32 i = 0; i < m; ++i) {
    t[i * m + i] = 1;
    s[i * m + i] = cnt[0] * (cnt[0] - 1) / 2 + cnt[1] * (cnt[1] - 1) / 2 + (cnt[0] - i) * i + i * (cnt[1] - i);
    if (i + 1 < m) {
      s[i * m + i + 1] = (cnt[0] - i) * (cnt[1] - i);
    }
    if (i - 1 >= 0) {
      s[i * m + i - 1] = i * i;
    }
  }
  i32 p = inv (n * (n - 1) / 2);
  for (i32 i = 0; i < m * m; ++i) {
    s[i] = (i64) s[i] * p % mod;
  }
  while (k > 0) {
    if (k & 1) matmul (t, t, s, m);
    matmul (s, s, s, m);
    k >>= 1;
  }
  i32 ans = t[d * m + 0];
  print_int (ans);
  puts("");
}

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


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

int main() {

      int n,x,y,i,flag=0,u , j = 0 ;
       scanf ("%d" , &n);
       char s[n];
       scanf ("%s" ,s);
       char arr[n];
       x=-1; y=-1;
       for(i=0;i<n;i++)
       {
           u=s[i]-'a';
           if(u>=x){
               x=u;
               arr[j] ='0';
               j++;
           }
           else if(u>=y)
           {
               arr[j] = '1';
               j++;
               y=u;
           }
           else
           {
               flag=1;
               i=n;
           }
       }
       if(flag==1){
           printf("NO\n");
       }
       else
        {
            printf("YES\n");
            for ( i = 0 ; i < n ; i++)
                printf("%c" , arr[i]);
        }
    }


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

bool reversed(char c, char t)
{
    return (c == 'N' && t == 'S') || (c == 'S' && t == 'N') || (c == 'W' && t == 'E') || (c == 'E' && t == 'W');
}

char reverse(char c)
{
    if (c == 'S')
        return 'N';
    if (c == 'W')
        return 'E';
    if (c == 'N')
        return 'S';
    if (c == 'E')
        return 'W';
    return '\0';
}

int main()
{
    int n;
    assert(scanf("%d", &n) == 1);
    n--;
    char* s = malloc(sizeof(char) * (n + 1));
    char* t = malloc(sizeof(char) * (n + 1));
    assert(scanf("%s", s));
    assert(scanf("%s", t));
    if (reversed(s[n - 1], t[n - 1]))
        printf("NO\n");
        else
    {
        int i = 0;
        int j = 0;
        int ilast = 0;
        int op;
        while (j < n || i < n)
        {
            for (; i < n; i++)
            {
                if (j < n && t[j] == s[i])
                    j++;
                else if (j > 0 && reverse(t[j - 1]) == s[i])
                    j--;
            }
            if (j == n && i == n)
            {
                printf("YES\n");
                return 0;
            }
            for (; j < n; j++)
            {
                if (i < n && t[j] == s[i])
                    i++;
                else if (i > 0 && reverse(s[i - 1]) == t[j])
                    i--;
            }
            op += 2 * n;
            //if (op >= 1e8)
            //    break;
            if (ilast == i)
                break;
            ilast = i;
        }
        if (j == n && i == n)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


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

int Input;
int Ans[70000];
int A, B, i, x, y, Test, FAns;

int QS(int *A, int *B){
    if (*A>*B) return 1;
    if (*A<*B) return -1;
    return 0;
}

int main(){
    while(~scanf("%d", &Input)){
        FAns = 0;

        for (A=0; A<10; A++) for (B=0; B<10; B++) for (i=0; i<1024; i++){
            Test = 0;
            x = i;
            while(x){
                Test *= 10;
                if (x&1) Test += A;
                else Test += B;
                x /= 2;
            }
            if (Test>0) if (Test<=Input){
                Ans[FAns] = Test;
                FAns++;
            }
        }

        qsort(Ans, FAns, sizeof(Ans[0]), QS);

        if (Input==1000000000){
            Ans[FAns] = Input;
            FAns++;
        }

        if (FAns<=1){
            printf("%d\n", FAns);
            continue;
        }

        for (i=FAns-1; i; i--) if (Ans[i]==Ans[i-1]) FAns--;

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

    return 0;
}


#include<stdio.h>
long long int power(long long int a,long long int b)
{
         long long int res=1;
         while(b!=0)
         {
                  if(b&1)
                  res=res*a;
                  a=a*a;
                  b=b/2;
         }
         return res;
}
int main()
{long long int m;
         scanf("%lld",&m);
        long long int res;
        res=(2*4*3*power(4,m-3))+(4*3*3*power(4,n-4));
        printf("%lld\n",res);

}


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

#define N 2000000
#define MOD 1000000007

int cnt[N + 1];
int lcm[N + 1];
int maxp[N + 1];

int max(int x, int y) {
  return x > y ? x : y;
}

int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    cnt[p]++;
  }
  for (int i = 0; i <= N; i++) {
    maxp[i] = i;
  }
  for (int i = 2; i <= N; i++) {
    if (maxp[i] == i) {
      for (int j = i * 2; j <= N; j += i) {
        maxp[j] = i;
      }
    }
  }
  for (int i = 0; i <= N; i++) {
    if (cnt[i] == 1) {
      lcm[i] = max(lcm[i], 1);
    } else if (cnt[i] >= 2) {
      lcm[i] = max(lcm[i], 1);
      int x = i - 1;
      while (x != 1) {
        int p = maxp[x];
        int e = 0;
        while (x % p == 0) {
          x /= p;
          e++;
        }
        lcm[p] = max(lcm[p], e);
      }
    }
  }
  long long ans = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < lcm[i]; j++) {
      ans *= i;
      ans %= MOD;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


#include <stdio.h>
#include<stdlib.h>
typedef long long lol;

int main()
{
    lol n, M = 998244353;
    scanf("%lld",&n);
    lol arr[n+1],id=2;
    lol pr[1000000];
    pr[0]=2;
    pr[1]=3;
    lol i,j,k,p,ct,i1;
    arr[1]=1;
    for(i=2;i<=n;i++)
    {
        p=0;
        while((p<id) && (i%(pr[p])!=0) && (pr[p]*pr[p]<i)) p++;
        if(pr[p]*pr[p]>i)
        {
            arr[i]=2;
            pr[id]=i;
            id++;
            continue;
        }
        p = pr[p];
        ct = 0;
        i1=i;
        while(i1%p==0)
        {
            ct++;
            i1/=p;
        }
        arr[i] = arr[i1]*(ct+1);
    }
    lol ex = 1;
    lol ans = arr[n]%M, a1;
    for(i=1;i<n;i++)
    {
        a1 = (ex*arr[n-i])%M;
        ans+=a1;
        ans%=M;
        ex*=2;
        ex%=M;
    }
    printf("%lld",ans);
    return 0;
}


#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	unsigned long long ans = 6;
	unsigned long long pow = 16;

	for(int i = 1; i < n; i++) {
		ans *= pow;
		ans %= 1000000007;
		pow *= pow;
		pow %= 1000000007;
	}

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

}


#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define N	400000
#define INF	0x3f3f3f3f3f3f3f3fLL

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

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srand(tv.tv_sec ^ tv.tv_usec);
}

int rand_(int n) {
	return (rand() * 76543LL + rand()) % n;
}

struct V {
	long long x, y;
} vv[N + 1];

int compare(const void *a, const void *b) {
	struct V *u = (struct V *) a;
	struct V *v = (struct V *) b;

	return u->x == v->x ? 0 : u->x < v->x ? -1 : 1;
}

void sort(struct V *vv, int n) {
	int i;

	for (i = 0; i < n; i++) {
		int j = rand_(i + 1);
		struct V tmp;

		tmp = vv[i], vv[i] = vv[j], vv[j] = tmp;
	}
	qsort(vv, n, sizeof *vv, compare);
}

int main() {
	int t;

	srand_();
	scanf("%d", &t);
	while (t--) {
		static long long gg[N + 1];
		long long len, k, lower, upper, lmax, rmin, y, ans;
		int n, m, i;

		scanf("%lld%d%lld", &len, &n, &k);
		for (i = 0; i < n; i++)
			scanf("%lld", &gg[i]);
		gg[n] = len;
		for (i = n; i >= 1; i--)
			gg[i] -= gg[i - 1];
		lower = 1;
		upper = len + 1;
		for (i = 0; i <= n; i++)
			upper = min(upper, gg[i] + 1);
		while (upper - lower > 1) {
			long long l = (lower + upper) / 2, k_;

			k_ = k;
			for (i = 0; i <= n; i++)
				if ((k_ -= gg[i] / l - 1) <= 0)
					break;
			if (k_ <= 0)
				lower = l;
			else
				upper = l;
		}
		lmax = lower;
		lower = 0, upper = len;
		while (upper - lower > 1) {
			long long r = (lower + upper) / 2, k_;

			k_ = k;
			for (i = 0; i <= n; i++)
				if ((k_ -= (gg[i] + r - 1) / r - 1) < 0)
					break;
			if (k_ >= 0)
				upper = r;
			else
				lower = r;
		}
		rmin = upper;
		/* lmax <= rmin must hold */
		m = 0;
		for (i = 0; i <= n; i++) {
			int kmin = (gg[i] + rmin - 1) / rmin - 1;
			int kmax = gg[i] / lmax - 1;

			if (kmin > kmax) {	/* kmin == kmax + 1 */
				struct V *v = &vv[m++];

				v->x = lmax - gg[i] / (kmin + 1);
				v->y = (gg[i] + kmax) / (kmax + 1) - rmin;
			}
		}
		sort(vv, m);
		ans = INF;
		y = 0;
		for (i = m - 1; i >= 0; i--) {
			ans = min(ans, rmin - lmax + vv[i].x + y);
			y = max(y, vv[i].y);
		}
		ans = min(ans, rmin - lmax + y);
		printf("%lld\n", ans);
	}
	return 0;
}


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

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

long long k, pa, pb, inv, dp[1010][1010];

long long expo(long long x, long long n){
    x %= MOD;
    long long res = 1;

    while (n){
        if (n & 1) res = (res * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }

    return (res % MOD);
}

long long F(int a, int c){
    if (c >= k) return c;
    if (dp[a][c] != -1) return dp[a][c];

    long long res = 0, loop = 0;

    if (a == 0){
        res = pa * F(a + 1, c) % MOD;
        loop += pb;
        res = res * expo(MOD - loop, MOD - 2) % MOD;
    }
    else if ((a + c) >= k){
        loop += pa;
        res = pb * F(a, c + a) % MOD;
        res = (res + 1) * expo(MOD - loop, MOD - 2) % MOD;
    }
    else{
        res += pa * F(a + 1, c);
        res += pb * F(a, c + a);
        res %= MOD;
    }

    return (dp[a][c] = res);
}

int main(){
    while (scanf("%lld %lld %lld", &k, &pa, &pb) != EOF){
        memset(dp, -1, sizeof(dp));

        inv = expo(pa + pb, MOD - 2);
        pb = pb * inv % MOD;
        pa = pa * inv % MOD;
        printf("%lld\n", (F(0, 0) - 1 + MOD) % MOD );
    }
    return 0;
}


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

#define N	100000
#define MD	1000000007

int ff[N], gg[N];
int d_, x_, y_;

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

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

int inv(int a, int b) {
	gcd_(a, b);
	return x_;
}

void init(int n) {
	int i, f;

	for (i = 0, f = 1; i < n; i++) {
		gg[i] = inv(ff[i] = f, MD);
		f = (long long) f * (i + 1) % MD;
	}
}

int choose(int n, int k) {
	return n < k ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

int main() {
	static int aa[N + 2], bb[N + 2], cc[N + 2];
	int f, w, h, n, i, j, p, q, ans;

	scanf("%d%d%d", &f, &w, &h);
	if (f == 0) {
		printf("%d\n", w > h);
		return 0;
	}
	if (w == 0) {
		printf("1\n");
		return 0;
	}
	n = f > w ? f : w;
	init(n);
	for (i = 1; i <= f; i++)
		aa[i] = choose(f - 1, i - 1);
	for (j = 1; j <= w; j++)
		bb[j] = choose(w - 1, j - 1);
	for (j = 1; (h + 1) * j <= w; j++)
		cc[j] = choose(w - h * j - 1, j - 1);
	p = q = 0;
	for (i = 1; i <= n; i++) {
		p = (p + aa[i] * (cc[i] * 2LL + cc[i - 1] + cc[i + 1])) % MD;
		q = (q + aa[i] * (bb[i] * 2LL + bb[i - 1] + bb[i + 1])) % MD;
	}
	if (p < 0)
		p += MD;
	if (q < 0)
		q += MD;
	ans = (long long) p * inv(q, MD) % MD;
	if (ans < 0)
		ans += MD;
	printf("%d\n", ans);
	return 0;
}