#include <stdio.h>
long long num[70]={0};
long long num1[70]={0};
long long change(long long n)
{
    long long i=0;
    while(n)
    {
        num[i++]=n%2;
        n=n/2;
    }
    return 0;
}
int main()
{
    long long n=0,m=0,ans=,max=0;
    scanf("%lld%lld",&n,&m);
    change(n);
    for(long long i=0;i<=69;i++)
    {
        num1[i]=num[i];
    }
    if(m<n||(m-n)%2==1) printf("-1\n");
    else
    {
        if(n==m)
        {
            if(n==0) printf("0\n");
            else printf("1\n%lld\n",n);
        }
        else
        {
            num[0]=num[0]+m-n;
            for(long long i=0;i<=68;i++)//满四进二
            {
                long long xx=(num[i]-num1[i])/4;
                num[i]=num[i]-4*xx;
                num[i+1]=num[i+1]+2*xx;
            }
            for(long long i=0;i<=69;i++)
            {
                if(num[i]>max) max=num[i];
            }
            printf("%lld\n",max);
            for(long long i=1,j=0,x=0;i<=max;i++)
            {
                for(j=0,x=1,ans=0;j<=69;j++,x=2*x)
                {
                    if(num[j]>=1)
                    {
                        ans=ans+x;
                        num[j]--;
                    }
                }
                if(i==1) printf("%lld",ans);
                else printf(" %lld",ans);
            }
            printf("\n");
        }
    }
    return 0;
}


#include <stdio.h>

#define maxn 10001

const int mod = (int) 1e9 + 7;

long long choose[maxn][maxn];

long long f[maxn][maxn];
long long g[maxn][maxn];

long long power( long long a, long long b ) {
	long long ret = 1;

	a %= mod;
	while( b > 0 ) {
		if( b % 2 ) {
			ret = (ret * a) % mod;
		}

		b /= 2;
		a = (a * a) % mod;
	}

	return ret;
}

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

	for( int i = 0; i < maxn; i++ ) {
		choose[i][0] = choose[i][i] = 1;
		for( int j = 1; j < i; j++ ) {
			choose[i][j] = (choose[i-1][j] + choose[i-1][j-1]) % mod;
		}
	}

	for( int i = 1; i <= n; i++ ) {
		for( int c = 0; c <= n; c++ ) {
			long long count = (m / n) + (m % n >= i ? 1 : 0);
			g[i][c] = power(choose[n][c], count);
		}
	}

	f[1][0] = 1;
	for( int i = 1; i <= n; i++ ) {
		for( int j = 0; j <= k; j++ ) if( f[i][j] > 0 ) {
			for( int c = 0; c <= n; c++ ) {
				if( j + c > k ) break;
				long long nways = (g[i][c] * f[i][j]) % mod;
				f[i+1][j+c] = (f[i+1][j+c] + nways) % mod;
			}
		}
	}

	printf("%lld\n", f[n+1][k]);

	return 0;
}


#include<stdio.h>
#define mod 1000000007
long long f[200][200],dp[101][10001];
long long calc_pow(long long base , long long power)
{
    if(power == 0) return 1;

    long long half = calc_pow(base , power/2);

    if(power % 2)
        return ((half * half) % mod * base) % mod;

    return (half * half) % mod;
}
main()
{
    long long n,m,i,j,k,s;
    scanf("%I64d%I64d%I64d",&n,&m,&s);

    for(i=0; i<=100; i++)
        f[i][0] = 1;

    for(i=1; i<=100; i++)
        for(j=1; j<=i; j++)
            f[i][j] = (f[i-1][j] + f[i-1][j-1]) % mod ;

    long long pow[200][200];

    for(i=1; i<=n; i++)
        for(j=0; j<=n; j++)
            pow[i][j] = calc_pow(f[n][j] , (m-i)/n+1);

    for(i=0; i<=n; i++)dp[n][i] = pow[n][i];

    for(i=n-1; i>=1; i--)
    {
        for(j=0; j<=(n-i+1)*n ; j++)
        {
          for(k=0; k<=n; k++)
          {
              if(j - k <= (n-i)*n)
                dp[i][j] = (dp[i][j] + (pow[i][k] * dp[i+1][j-k] ) % mod )% mod;
          }
        }
    }

    printf("%I64d",dp[1][s]);

    return 0;
}


#include <stdio.h>

long long pow(long long x, long long y, long long z)
{
    long long p = 1;

    while (y) {
        if (y & 1) p = p * x % z;

        x = x * x % z;
        y >>= 1;
    }

    return p;
}

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

long long c[101][101];
long long a[101];
long long dp[101][10001];

int main()
{
    int n, k, mod = 1000000007, i, j, l;
    long long m;

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

    for (i = 0; i <= 100; i++) {
        c[i][0] = c[i][i] = 1;

        for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }

    for (i = 0; i <= n; i++) a[i] = pow(c[n][i], m / n, mod);

    dp[0][0] = 1;

    for (i = 0; i < n; i++) {
        for (j = max(0, k - (n - i) * n); j <= i * n && j <= k; j++) {
            if (dp[i][j] == 0) continue;

            for (l = 0; l <= n && j + l <= k; l++) {
                long long x = a[l];

                if (m % n > i) x = x * c[n][l] % mod;

                dp[i + 1][j + l] = (dp[i + 1][j + l] + dp[i][j] * x % mod) % mod;
            }
        }
    }

    printf("%I64d\n", dp[n][k]);

    return 0;
}


#include <stdio.h>

#define maxn 111

const int mod = (int) 1e9 + 7;

long long choose[maxn][maxn];

long long f[maxn][10001];
long long g[maxn][maxn];

long long power( long long a, long long b ) {
	long long ret = 1;

	a %= mod;
	while( b > 0 ) {
		if( b % 2 ) {
			ret = (ret * a) % mod;
		}

		b /= 2;
		a = (a * a) % mod;
	}

	return ret;
}

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

	for( int i = 0; i < maxn; i++ ) {
		choose[i][0] = choose[i][i] = 1;
		for( int j = 1; j < i; j++ ) {
			choose[i][j] = (choose[i-1][j] + choose[i-1][j-1]) % mod;
		}
	}

	for( int i = 1; i <= n; i++ ) {
		for( int c = 0; c <= n; c++ ) {
			long long count = (m / n) + (m % n >= i ? 1 : 0);
			g[i][c] = power(choose[n][c], count);
		}
	}

	f[1][0] = 1;
	for( int i = 1; i <= n; i++ ) {
		for( int j = 0; j <= k; j++ ) if( f[i][j] > 0 ) {
			for( int c = 0; c <= n; c++ ) {
				if( j + c > k ) break;
				long long nways = (g[i][c] * f[i][j]) % mod;
				f[i+1][j+c] = (f[i+1][j+c] + nways) % mod;
			}
		}
	}

	printf("%lld\n", f[n+1][k]);

	return 0;
}


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

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

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

int
main(void)
{
    int n, k;
    unsigned long long m;
    scanf("%d%I64u%d", &n, &m, &k);
    cnk[0][0] = 1;

    int i, j, t;
    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;
        }
    }

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

    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) {
                unsigned long long tmp = quick_pow(cnk[n][t], pows[i]),
                                   tmp2 = (dp[i - 1][j - t] * tmp) % MOD;
                dp[i][j] = (dp[i][j] + tmp2) % MOD;
            }
        }
    }

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


#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define offset(t,m) ((unsigned long)&(((t*)0)->m))
#define container_of(a,t,m) ((t*)((unsigned long)a-offset(t,m)))
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define SWP(a, b) if ((a) != (b)) do {(a) ^= (b); (b) ^= (a); (a) ^= (b);} while(0)
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#endif
#ifndef _WCC_NUMTH_H
#define _WCC_NUMTH_H
#include <assert.h>
#define NUMTH_ENS (-1)
#define NUMTH_MODPLS(x, y, p) ((((x) % (p)) + ((y) % (p))) % p)
#define NUMTH_MODMUL(x, y, p) ((((X) % (P)) * ((y) % (p))) % p)
#define NUMTH_CORRECT(x, mod) ((x) += ((x) < 0 ? (mod) : 0))
long long numth_modexp(long long a, long long b, long long n);
long long numth_gcd(long long a, long long b);
void numth_gcd_e(long long a, long long b, long long *d, long long *x, long long *y);
int numth_mle(long long a, long long b, long long n, long long *x, long long *gcd);
#define numth_for_each_solution(i, x, n, d) \
	for ((i) = 0; (i) < (d); (i) += 1, (x) = ((x) + (n) / (d)) % (n))
int numth_divisors(long long k, long long divs[], long long *ndivs);
#endif
#define M 1000000007
#define T 100
#define K 1000
#define pls(a, b) NUMTH_MODPLS((a), (b), M)
int dp[2*T][4*T*K+1];
int a, b, t, k;
int delta, delta_min, delta_max, offset, index_max;
int dp_fill(int i, int j)
{
	int x;
	if (j == index_max-k) {
		dp[i][j] = 0;
		forre(x, j-k, j+k) dp[i][j] = pls(dp[i][j], dp[i+1][x]);
	} else {
		dp[i][j] = pls(pls(dp[i+1][j-k], dp[i][j+1]), -1*dp[i+1][j+k+1]);
		NUMTH_CORRECT(dp[i][j], M);
	}
	return dp[i][j];
}
int main(void)
{
	int i, j;
	scanf("%d%d%d%d", &a, &b, &k, &t);
	t <<= 1;
	delta = a - b;
	delta_min = delta - t * k;
	delta_max = delta + t * k;
	offset = -1 * delta_min;
	index_max = delta_max + offset;
	forre(i, 0, index_max) dp[t-1][i] = max(0, k-max(-1*k, offset-i+1)+1);
	for (i = t-2; i >= 0; --i)
		for (j = index_max-k; j >= k; --j)
			dp_fill(i, j);
	printf("%d\n", dp[0][delta+offset]);
	return 0;
}


#include<stdio.h>
#include<math.h>
int sol(int n){
    int dp[n+1];
    dp[1]=1;
    dp[2]=3;
    dp[3]=6;
    for(int i=4;i<=n;i++){
        dp[i]=dp[i-1]+i+pow(2,i-4);
    }
    return dp[n];
}
int main(){
    int n;
    scanf("%d",&n);
    printf("%d\n",sol(n));
}


#include<stdio.h>
#define big 1000000007
int main()
{
	int n;
	scanf("%d",&n);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	else if (n==2)
	{
		printf("3\n");
		return 0;
	}
	else
	{
		long long int a = 1, b = 3 , temp;
		int i=1;
		for( ; i <= n-2 ; i++)
		{
			temp = b%big;
			b = (a+b+2)%big;
			a = temp%big;
		}
		printf("%I64d\n",b);
		return 0;
	}
}


#include<stdio.h>
#include<math.h>
int sol(int n){
    int dp[n+1];
    dp[1]=1;
    dp[2]=3;
    dp[3]=6;
    for(int i=4;i<=n;i++){
        dp[i]=(dp[i-1]+dp[i-2]+2)%1000000007;
    }
    return dp[n];
}
int main(){
    int n;
    scanf("%d",&n);
    printf("%d\n",sol(n));
}


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


#include<stdio.h>

typedef long long LL;
typedef struct{
	LL x, y;
	LL dist[100];
} Datanode;

Datanode nodes[100];

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

LL manh(Datanode * a, Datanode * b){
	return aabs(a->x-b->x)+aabs(a->y-b->y);
}

int main(){
	LL a[2], b[2], t;
	Datanode s;
	int i, j, n, best=0;
	scanf("%I64d %I64d %I64d %I64d %I64d %I64d %I64d %I64d %I64d", &nodes[0].x, &nodes[0].y,
			a, a+1, b, b+1, &s.x, &s.y, &t);
	for(i=1;manh(&s, nodes+i-1)>=t && nodes[i-1].x<100000000000000000LL &&
			nodes[i-1].y<100000000000000000LL;++i){
		nodes[i].x=nodes[i-1].x*a[0]+b[0];
		nodes[i].y=nodes[i-1].y*a[1]+b[1];
		for(j=0;j<i;++j){
			nodes[i].dist[j]=manh(nodes+i, nodes+j);
			nodes[j].dist[i]=manh(nodes+i, nodes+j);
		}
	}
	for(;manh(&s, nodes+i-1)<=t && nodes[i-1].x<100000000000000000LL &&
			nodes[i-1].y<100000000000000000LL;++i){
		nodes[i].x=nodes[i-1].x*a[0]+b[0];
		nodes[i].y=nodes[i-1].y*a[1]+b[1];
		for(j=0;j<i;++j){
			nodes[i].dist[j]=manh(nodes+i, nodes+j);
			nodes[j].dist[i]=manh(nodes+i, nodes+j);
		}
	}
	n=i;
	for(i=0;i<n;++i) for(j=i+1;j<n;++j)
			if(nodes[i].dist[j]+min(manh(nodes+i, &s), manh(nodes+j, &s))<=t)
				best=max(best, j-i+1);
	printf("%d\n", best);
	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>

typedef long long LL;
typedef struct{
	LL x, y;
	LL dist[100];
} Datanode;

Datanode nodes[100];

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

LL manh(Datanode * a, Datanode * b){
	return aabs(a->x-b->x)+aabs(a->y-b->y);
}

int main(){
	LL a[2], b[2], t;
	Datanode s;
	int i, j, n, best=0;
	scanf("%I64d %I64d %I64d %I64d %I64d %I64d %I64d %I64d %I64d", &nodes[0].x, &nodes[0].y,
			a, a+1, b, b+1, &s.x, &s.y, &t);
	for(i=1;manh(&s, nodes+i-1)>=t && nodes[i-1].x<100000000000000000LL &&
			nodes[i-1].y<100000000000000000LL;++i){
		nodes[i].x=nodes[i-1].x*a[0]+b[0];
		nodes[i].y=nodes[i-1].y*a[1]+b[1];
		for(j=0;j<i;++j){
			nodes[i].dist[j]=manh(nodes+i, nodes+j);
			nodes[j].dist[i]=manh(nodes+i, nodes+j);
		}
	}
	for(;manh(&s, nodes+i-1)<=t && nodes[i-1].x<100000000000000000LL &&
			nodes[i-1].y<100000000000000000LL;++i){
		nodes[i].x=nodes[i-1].x*a[0]+b[0];
		nodes[i].y=nodes[i-1].y*a[1]+b[1];
		for(j=0;j<i;++j){
			nodes[i].dist[j]=manh(nodes+i, nodes+j);
			nodes[j].dist[i]=manh(nodes+i, nodes+j);
		}
	}
	n=i;
	for(i=0;i<n;++i) for(j=i;j<n;++j)
			if(nodes[i].dist[j]+min(manh(nodes+i, &s), manh(nodes+j, &s))<=t)
				best=max(best, j-i+1);
	printf("%d\n", best);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

long long aa = (long long)1e16;

int main() {
    ll x0, y0, ax, bx, by, ay;
    ll xs, ys, t;
    cin >> x0 >> y0 >> ax >> ay >> bx >> by;
    cin >> xs >> ys >> t;
    vector<pair<ll, ll>> arr;
    int counter = 1;
    arr.push_back(make_pair(x0, y0));
    while(arr[counter - 1].first < aa && arr[counter - 1].second < aa) {
        arr.push_back(make_pair(ax * arr[counter - 1].first + bx, ay * arr[counter - 1].second + by));
        counter++;
    }
    // sort(arr.begin(), arr.end());
    bool a[arr.size()];
    ll myMin = aa;
    int index = -1;
    for(int i = 0; i < arr.size(); i++) {
        ll temp = abs(arr[i].first - xs) + abs(arr[i].second - ys);
        if(temp < myMin) {
            index = i;
            myMin = temp;
        }
    }
    t -= abs(arr[index].first - xs) + abs(arr[index].second - ys);
    if(t < 0) {
        cout << 0;
        return 0;
    }
    xs = arr[index].first;
    ys = arr[index].second;
    int ct = 1;
    for(int i = 0; i < arr.size(); i++) {
        a[i] = false;
    }
    a[index] = true;
    while(t > 0 && ct <= arr.size()) {
        myMin = aa;
        for(int i = 0; i < arr.size(); i++) {
            if(!a[i]) {
                ll temp = abs(arr[i].first - xs) + abs(arr[i].second - ys);
                if(temp < myMin) {
                    index = i;
                    myMin = temp;
                }
            }
        }
        a[index] = true;
        ct++;
        t -= abs(arr[index].first - xs) + abs(arr[index].second - ys);
        xs = arr[index].first;
        ys = arr[index].second;
    }
    cout << ct;
    return 0;
}


#include <stdio.h>

int main(void)
{
    int n;

    scanf("%d",&n);

    int tmp;
    int pie[n];
    for(int i=0;i<n;i++){
        scanf("%d",&pie[i]);
    }
    if(n == 1){
        printf("0 %d",pie[0]);
        return 0;
    }
    int x=pie[n-1];
    int y=pie[n-2];
    if(x<y)
    {
        tmp = x;
        x = y;
        y = tmp;
    }
    for(int j=n-3;j>=0;j--){
        y+=pie[j];
        if(x<y)
        {
            tmp = x;
            x = y;
            y = tmp;
        }
    }
    printf("%d %d",y,x);
    return 0;
}


#include<stdio.h>

int max(int a,int b)
{
if(a>=b)return a;
else return b;
}
int main()
{
int ca[52];
int n;scanf("%d",&n);
int sumi[52];
int sum=0;
int dp[52]={-1};

int i=0;
for(i=0;i<n;i++)
{
scanf("%d",&ca[i]);
sum += ca[i];
sumi[i] = sum;
}
dp[n-1]=ca[n-1];

for(i=n-2;i>=0;i--)
{
dp[i]=max((ca[i]+(sumi[n-1]-dp[i+1]-sumi[i])),dp[i+1]);

}

int ans = dp[0];
int ans1 = sumi[n-1]-dp[0];

printf("%d %d\n",ans1,ans);

return 0;
}


//Date:16-09-17

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<float.h>
#include<math.h>
#include<inttypes.h>
#include<assert.h>
#include<ctype.h>
#include<limits.h>
#include<time.h>
#define ll long long
#define For(i,n)	for(i=0;i<n;i++)
#define rep(i ,a ,b)	for(i=(a);i<=(b);i++)
#define mset(a ,value)	memset(a ,value ,sizeof(a))
#define s(a)	scanf("%d" ,&a);
#define ls(a)	scanf("%ld" ,&a)
#define reg(i)	register int i
#define infinite INT_MAX
#define MAX 101
#define NIL -1
#define and &&
int min(int a,int b){	return (a<b?a:b);	}
int max(int a,int b){	return (a>b?a:b);	}
int gcd(int a ,int b){
	if(a==0)	return b;
	return gcd(b%a ,a);
}
int a[51] ,n;
int cmp(const void *a,const void *b) {
	int *a1 = (int *)a;
	int *b1 = (int *)b;
	return (*a1) > (*b1);
}
int f[51][2];
int F(int i ,int d) {
	//printf("%d " ,d);
	if(i == n-1) {
		if(d == 0)	return f[i][d] = a[i];
		else return f[i][d] = 0;
	}
	if(f[i][d] != -1)	return f[i][d];
	if(d == 0)
		f[i][d] = max(a[i] + F(i+1 ,1) ,F(i+1 ,0));
	else
		f[i][d] = min(F(i+1 ,0), a[i] + F(i+1 ,1));
	return f[i][d];
}
int main() {
	int i ,j;
	s(n);
	int sum = 0;
	For(i ,n){	s(a[i]);	sum += a[i];	}
	mset(f ,-1);
	//For(i ,n)	printf("%d " ,f[i]);	printf("\n");
	int bob = F(0 ,0);
	//For(i ,n) 	printf("%d %d\n" ,f[i][0] ,f[i][1]);
	printf("%d %d" ,sum - bob ,bob);
	return 0;
}


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

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

int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
int main()
{
	int n,i,j;
	scanf("%d",&n);
	int a[100];
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int dp[100][2]={0};
	dp[n][1]=a[n];
	dp[n][0]=0;
	for(i=n-1;i>=1;i--)
	{
		if(dp[i+1][1]>=a[i]+dp[i+1][0])
		{
			dp[i][1]=dp[i+1][1];
			dp[i][0]=dp[i+1][0]+a[i];
		}
		else
		{
			dp[i][1]=a[i]+dp[i+1][0];
			dp[i][0]=dp[i+1][1];
		}
	}
	printf("%d %d\n",dp[1][0],dp[1][1]);
	return 0;

}


#include<stdio.h>
int mini(int a, int b)
{
if(a<=b)return a;
return b;
}
int maxi(int a, int b)
{
if(a>=b)return a;
return b;
}
int sum[55];
int fir[55];
int a[55];
int main()
{
int n;
scanf("%d",&n);
int i;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);

for(i=n;i>=1;i--)
{
fir[i] = maxi(a[i]+sum[i+1]-fir[i+1],fir[i+1]);
sum[i] =sum[i+1] +  a[i];

}
printf("%d %d\n",sum[1]-fir[1],fir[1]);
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 q1 = 2 * q(k, n-k, n-k-1, n, n-1, n-2);
    const double q2 = q(k, k-1, n-k, n, n-1, n-2);
    assert(q3 + q0 + 3 / 2. * q1 + 3 * q2 == 1.);
    const double res = q3 + q1 + q2;
    //printf("solve(%d) = %lf\n", k, res);
    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>
#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 p3 = p(k-2, n-2);
    const double q0 = q(n-k, n-k-1, n-k-2, n, n-1, n-2);
    const double p0 = p(k, n-2);
    const double q11 = q(k, n-k, n-k-1, n, n-1, n-2);
    const double p11 = p(k-1, n-2);
    const double q10 = 2 * q11;
    const double p10 = p(k, n-2);
    const double q20 = q(k, k-1, n-k, n, n-1, n-2);
    const double p20 = p(k, n-2);
    const double q21 = 2 * q21;
    const double p21 = p(k-1, n-2);
    const double res = q3 * p3 + q0 * p0 +
        q11 * p11 + q10 * p10 + q20 * p20 + q21 * p21;
    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>
#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 q1 = 3 / 2. * q(k, n-k, n-k-1, n, n-1, n-2);
    const double q2 = 3 * q(k, k-1, n-k, n, n-1, n-2);
    const double res = q3 + q1 + q2;
    //printf("solve(%d) = %lf\n", k, res);
    //assert(q3 + q0 + 3 / 2. * q1 + 3 * q2 == 1.);
    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>
#include<math.h>
/*#include<string.h>
#define MOD 1000000009
#define MAX 100005
long long int position_value[MAX];
void init()
{
    position_value[0]=1;
    int i;
    for(i=1;i<MAX;i++)
    {
        position_value[i]=(position_value[i-1]*26)%MOD;
    }
}
#define MAX 200000
int temp[MAX];
void mergesort(int a[],int indices[],int first,int last)
{
    if(first==last) return;
    int middle=(first+last)/2;
    mergesort(a,indices,first,middle);
    mergesort(a,indices,middle+1,last);
    int i,j,k;
    for(i=first,j=first,k=middle+1; i<=last; i++)
    {
        if(j==middle+1) temp[i]=indices[k++];
        else if(k==last+1) temp[i]=indices[j++];
        else if(a[indices[k]]<a[indices[j]]) temp[i]=indices[k++];
        else temp[i]=indices[j++];
    }
    for(i=first; i<=last; i++)
    {
        indices[i]=temp[i];
    }
}
void noobsort(int a[],int indices[],int first,int last)
{
    if(first>=last) return;
    int i,j,s;
    for(i=first;i<=last;i++)
    {
        for(j=i;j>0&&a[indices[j]]>a[indices[j-1]];j--)
        {
            s=indices[j-1];
            indices[j-1]=indices[j];
            indices[j]=s;
        }
    }
}*/
struct Points
{
    int x,y;
};
int main()
{
    int n,i,j,k,x0,y0;
    scanf("%d",&n);
    struct Points p[n*4+1];
    for(i=0;i<n*4+1;i++)
    {
        scanf("%d %d",&p[i].x,&p[i].y);
    }
    for(x0=0;x0<=50;x0++)
    {
        for(y0=0;y0<=50;y0++)
        {
            for(k=1;y0+k<=50&&x0+k<=50;k++)
            {
                int counter=0;
                for(i=0;i<n*4+1&&counter<=1;i++)
                {
                    if(((p[i].x==x0||p[i].x==x0+k)&&(p[i].y>=y0&&p[i].y<=y0+k))||((p[i].y==y0||p[i].y==y0+k)&&(p[i].x>=x0&&p[i].x<=x0+k)))
                    {
                        continue;
                    }
                    counter++;
                }
                if(counter>1) continue;
                for(i=0;i<n*4+1&&counter<=1;i++)
                {
                    if(((p[i].x==x0||p[i].x==x0+k)&&(p[i].y>=y0&&p[i].y<=y0+k))||((p[i].y==y0||p[i].y==y0+k)&&(p[i].x>=x0&&p[i].x<=x0+k)))
                    {
                        continue;
                    }
                    printf("%d %d",p[i].x,p[i].y);
                    return 0;
                }
            }
        }
    }
    return 0;
}


/*
 * main.c
 *
 *  Created on: 03 ���. 2014 �.
 *      Author: ulgish
 */

/*
 * util.c
 *
 *  Created on: 30 ���� 2014 �.
 *      Author: ulgish
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define MAX(A,B) (((A) > (B))?(A):(B))
#define MIN(A,B) (((A) < (B))?(A):(B))

#define LN printf("\n")
#define TAB printf("\t")
#define SPACE printf(" ")

typedef unsigned long long uint64;
typedef long long int64;
typedef signed short int16;
typedef unsigned short uint16;
typedef char byte;

void int64_print(int64 n){
	int64 carry = 10;
	if (n == 0){
		printf("0");
		return;
	}
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
}
void uint64_print(uint64 n){
	uint64 carry = 10;
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
}

uint64 uint64_read(){
	char* s = (char*) calloc(20, sizeof(char));
	s[0] = '\0';
	scanf("%s", s);
	//printf("=======%s\n", s);
	uint64 ret = 0;
	uint64 carry = 1;
	int len = strlen(s), i;
	for (i = 0; i < len; i++){
		ret += carry * (s[len-1-i] - 48);
		carry*=10;
	};
	free(s);
	return ret;
}

int64 int64_read(){
	char* s = (char*) calloc(21, sizeof(char));
	s[0] = '\0';
	scanf("%s", s);
	//printf("=======%s\n", s);
	int64 ret = 0;
	int64 carry = 1;
	int len = strlen(s), i;
	for (i = 0; i < len; i++){
		ret += carry * (s[len-1-i] - 48);
		carry*=10;
	};
	free(s);
	return ret;
}

//#define DEBUG

int64 x;
int a[100001];
int b[100001];

int n,d;

void swap(int* a, int* b){
	int c;
	c = *a;
	*a = *b;
	*b = c;
	return;
}
int64 getNextX() {
    x = (x * 37 + 10007) % 1000000007;
    return x;
}
void initAB() {
	int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(&(a[i]), &(a[(int)(getNextX() % (i + 1LL))]));
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(&(b[i]), &(b[(int)(getNextX() % (i + 1LL))]));
    }
}

int main(){
	scanf("%d %d", &n, &d);
	x = int64_read();
	int i,j;
	initAB();
	int max_a[100000];
	int index_a[100001];
	int sum_b[100000];
	sum_b[0] = b[0];
	max_a[0] = a[0];
#ifdef DEBUG
	printf("d:%d\n", d);
	for (i = 0 ; i < n; i++){
		printf("%d\t", b[i]);
	}
	LN;

#endif
	if (b[0] == 0){
		printf("0\n");
	}else{
		printf("%d\n", a[0]);
	}
	int tmp = 0;
	for (i = 0; i< n; i++){
		index_a[a[i]] = i;
		if (i > 0){
			sum_b[i] = b[i] + sum_b[i-1];
			if (sum_b[i] == 0){
				tmp = i;
			}
		}
	}
	for (i = 1; i <= tmp; i++){
		printf("0\n");
	}
	for (i = tmp+1; i < n; i++){
		int c = 0;
		max_a[i] = MAX(a[i], max_a[i-1]);
		if (sum_b[i] == 0){
			printf("0\n");
			continue;
		}
		int s = 0;
		byte next = 0;
		for (j = max_a[i]; j >= 0 && s < 5000; j--, s++){
			if (index_a[j] <= i){
				if (b[i - index_a[j]]){
					next = 1;
					printf("%d\n", j);
					break;
				}
			}
		}
		if (next){
			continue;
		}
		for (j = 0; j<= i; j++){
			c = MAX(c, a[j]*b[i-j]);
		}
		printf("%d\n",c);
	}

	return 0;
}


/*
 * main.c
 *
 *  Created on: 03 ���. 2014 �.
 *      Author: ulgish
 */

/*
 * util.c
 *
 *  Created on: 30 ���� 2014 �.
 *      Author: ulgish
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define MAX(A,B) (((A) > (B))?(A):(B))
#define MIN(A,B) (((A) < (B))?(A):(B))

#define LN printf("\n")
#define TAB printf("\t")
#define SPACE printf(" ")

typedef unsigned long long uint64;
typedef long long int64;
typedef signed short int16;
typedef unsigned short uint16;
typedef char byte;

void int64_print(int64 n){
	int64 carry = 10;
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
}
void uint64_print(uint64 n){
	uint64 carry = 10;
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
}

uint64 uint64_read(){
	char* s = (char*) calloc(20, sizeof(char));
	s[0] = '\0';
	scanf("%s", s);
	//printf("=======%s\n", s);
	uint64 ret = 0;
	uint64 carry = 1;
	int len = strlen(s), i;
	for (i = 0; i < len; i++){
		ret += carry * (s[len-1-i] - 48);
		carry*=10;
	};
	free(s);
	return ret;
}

int64 int64_read(){
	char* s = (char*) calloc(21, sizeof(char));
	s[0] = '\0';
	scanf("%s", s);
	//printf("=======%s\n", s);
	int64 ret = 0;
	int64 carry = 1;
	int len = strlen(s), i;
	for (i = 0; i < len; i++){
		ret += carry * (s[len-1-i] - 48);
		carry*=10;
	};
	free(s);
	return ret;
}

//#define DEBUG

int64 x;
int a[100001];
int b[100001];

int n,d;

void swap(int* a, int* b){
	int c;
	c = *a;
	*a = *b;
	*b = c;
	return;
}
int64 getNextX() {
    x = (x * 37 + 10007) % 1000000007;
    return x;
}
void initAB() {
	int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(&(a[i]), &(a[(int)(getNextX() % (i + 1LL))]));
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(&(b[i]), &(b[(int)(getNextX() % (i + 1LL))]));
    }
}

int main(){
	scanf("%d %d", &n, &d);
	x = int64_read();
	int i,j;
	initAB();

#ifdef DEBUG
	printf("d:%d\n", d);
	for (i = 0 ; i < n; i++){
		printf("%d\t", b[i]);
	}
	LN;

#endif
	for (i = 0; i < n; i++){
		int64 c = 0;
		for (j = 0; j<= i; j++){
			c = MAX(c, a[j]*b[i-j]);
		}
		int64_print(c); LN;
	}

	return 0;
}


/*
 * main.c
 *
 *  Created on: 03 ���. 2014 �.
 *      Author: ulgish
 */

/*
 * util.c
 *
 *  Created on: 30 ���� 2014 �.
 *      Author: ulgish
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define MAX(A,B) (((A) > (B))?(A):(B))
#define MIN(A,B) (((A) < (B))?(A):(B))

#define LN printf("\n")
#define TAB printf("\t")
#define SPACE printf(" ")

typedef unsigned long long uint64;
typedef long long int64;
typedef signed short int16;
typedef unsigned short uint16;
typedef char byte;

void int64_print(int64 n){
	int64 carry = 10;
	if (n == 0){
		printf("0");
		return;
	}
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
}
void uint64_print(uint64 n){
	uint64 carry = 10;
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
}

uint64 uint64_read(){
	char* s = (char*) calloc(20, sizeof(char));
	s[0] = '\0';
	scanf("%s", s);
	//printf("=======%s\n", s);
	uint64 ret = 0;
	uint64 carry = 1;
	int len = strlen(s), i;
	for (i = 0; i < len; i++){
		ret += carry * (s[len-1-i] - 48);
		carry*=10;
	};
	free(s);
	return ret;
}

int64 int64_read(){
	char* s = (char*) calloc(21, sizeof(char));
	s[0] = '\0';
	scanf("%s", s);
	//printf("=======%s\n", s);
	int64 ret = 0;
	int64 carry = 1;
	int len = strlen(s), i;
	for (i = 0; i < len; i++){
		ret += carry * (s[len-1-i] - 48);
		carry*=10;
	};
	free(s);
	return ret;
}

//#define DEBUG

int64 x;
int a[100001];
int b[100001];

int n,d;

void swap(int* a, int* b){
	int c;
	c = *a;
	*a = *b;
	*b = c;
	return;
}
int64 getNextX() {
    x = (x * 37 + 10007) % 1000000007;
    return x;
}
void initAB() {
	int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(&(a[i]), &(a[(int)(getNextX() % (i + 1LL))]));
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(&(b[i]), &(b[(int)(getNextX() % (i + 1LL))]));
    }
}

int main(){
	scanf("%d %d", &n, &d);
	x = int64_read();
	int i,j;
	initAB();
	int max_a[100000];
	int index_a[100001];
	int sum_b[100000];
	sum_b[0] = b[0];
	max_a[0] = a[0];
#ifdef DEBUG
	printf("d:%d\n", d);
	for (i = 0 ; i < n; i++){
		printf("%d\t", b[i]);
	}
	LN;

#endif
	int tmp = 0;
	for (i = 0; i< n; i++){
		index_a[a[i]] = i;
		if (i > 0){
			sum_b[i] = b[i] + sum_b[i-1];
			if (sum_b[i] == 0){
				tmp = i;
			}
		}
	}
	for (i = 0; i < tmp; i++){
		printf("0\n");
	}
	for (i = tmp; i < n; i++){
		int c = 0;
		max_a[i] = MAX(a[i], max_a[i-1]);
		if (sum_b[i] == 0){
			printf("0\n");
			continue;
		}
		int s = 0;
		byte next = 0;
		for (j = max_a[i]; j >= 0 && s < 5000; j--, s++){
			if (index_a[j] <= i){
				if (b[i - index_a[j]]){
					next = 1;
					printf("%d\n", j);
					break;
				}
			}
		}
		if (next){
			continue;
		}
		for (j = 0; j<= i; j++){
			c = MAX(c, a[j]*b[i-j]);
		}
		printf("%d\n",c);
	}

	return 0;
}


/*
 * main.c
 *
 *  Created on: 03 ���. 2014 �.
 *      Author: ulgish
 */

/*
 * util.c
 *
 *  Created on: 30 ���� 2014 �.
 *      Author: ulgish
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define MAX(A,B) (((A) > (B))?(A):(B))
#define MIN(A,B) (((A) < (B))?(A):(B))

#define LN printf("\n")
#define TAB printf("\t")
#define SPACE printf(" ")

typedef unsigned long long uint64;
typedef long long int64;
typedef signed short int16;
typedef unsigned short uint16;
typedef char byte;

void int64_print(int64 n){
	int64 carry = 10;
	if (n == 0){
		printf("0");
		return;
	}
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
}
void uint64_print(uint64 n){
	uint64 carry = 10;
	char buf[20];
	buf[0] = '\0';
	int i = 0, j;
	while (n > 0){
		buf[i] = n % carry;
		n = n / carry;
		i += 1;
	}
	i--;
	for (j = i; j>= 0; j--){
		printf("%c", 48 + buf[j]);
	}
}

uint64 uint64_read(){
	char* s = (char*) calloc(20, sizeof(char));
	s[0] = '\0';
	scanf("%s", s);
	//printf("=======%s\n", s);
	uint64 ret = 0;
	uint64 carry = 1;
	int len = strlen(s), i;
	for (i = 0; i < len; i++){
		ret += carry * (s[len-1-i] - 48);
		carry*=10;
	};
	free(s);
	return ret;
}

int64 int64_read(){
	char* s = (char*) calloc(21, sizeof(char));
	s[0] = '\0';
	scanf("%s", s);
	//printf("=======%s\n", s);
	int64 ret = 0;
	int64 carry = 1;
	int len = strlen(s), i;
	for (i = 0; i < len; i++){
		ret += carry * (s[len-1-i] - 48);
		carry*=10;
	};
	free(s);
	return ret;
}

//#define DEBUG

int64 x;
int a[100001];
int b[100001];

int n,d;

void swap(int* a, int* b){
	int c;
	c = *a;
	*a = *b;
	*b = c;
	return;
}
int64 getNextX() {
    x = (x * 37 + 10007) % 1000000007;
    return x;
}
void initAB() {
	int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(&(a[i]), &(a[(int)(getNextX() % (i + 1LL))]));
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(&(b[i]), &(b[(int)(getNextX() % (i + 1LL))]));
    }
}

int main(){
	scanf("%d %d", &n, &d);
	x = int64_read();
	int i,j;
	initAB();
	int max_a[100000];
	int index_a[100001];
	int sum_b[100000];
	sum_b[0] = b[0];
	max_a[0] = a[0];
#ifdef DEBUG
	printf("d:%d\n", d);
	for (i = 0 ; i < n; i++){
		printf("%d\t", b[i]);
	}
	LN;

#endif
	if (b[0] == 0){
		printf("0\n");
	}else{
		printf("%d\n", a[0]);
	}
	int tmp = 0;
	for (i = 0; i< n; i++){
		index_a[a[i]] = i;
		if (i > 0){
			sum_b[i] = b[i] + sum_b[i-1];
			if (sum_b[i] == 0){
				tmp = i;
			}
		}
	}
	for (i = 1; i < tmp; i++){
		printf("0\n");
	}
	for (i = tmp; i < n; i++){
		int c = 0;
		max_a[i] = MAX(a[i], max_a[i-1]);
		if (sum_b[i] == 0){
			printf("0\n");
			continue;
		}
		int s = 0;
		byte next = 0;
		for (j = max_a[i]; j >= 0 && s < 5000; j--, s++){
			if (index_a[j] <= i){
				if (b[i - index_a[j]]){
					next = 1;
					printf("%d\n", j);
					break;
				}
			}
		}
		if (next){
			continue;
		}
		for (j = 0; j<= i; j++){
			c = MAX(c, a[j]*b[i-j]);
		}
		printf("%d\n",c);
	}

	return 0;
}


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

#define N	100000
#define S	20

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

int aa[N], bb[N];
int x;

int get_next_x() {
	return (x = (x * 37LL + 10007) % 1000000007);
}

void init_AB(int n, int d) {
	int i, j, tmp;

	for (i = 0; i < n; i++)
		aa[i] = i + 1;
	for (i = 0; i < n; i++) {
		j = get_next_x() % (i + 1);
		tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	for (i = 0; i < n; i++)
		bb[i] = i < d;
	for (i = 0; i < n; i++) {
		j = get_next_x() % (i + 1);
		tmp = bb[i], bb[i] = bb[j], bb[j] = tmp;
	}
}

int main() {
	static int ii[S + 1], jj[N];
	int n, d, h, i, k, c;

	scanf("%d%d%d", &n, &d, &x);
	init_AB(n, d);
	k = 0;
	for (i = 0; i < n; i++) {
		h = i < S ? i : S;
		while (h > 0 && aa[ii[h - 1]] < aa[i]) {
			ii[h] = ii[h - 1];
			h--;
		}
		ii[h] = i;
		if (bb[i])
			jj[k++] = i;
		c = 0;
		for (h = 0; h <= i && h < S; h++)
			if (bb[i - ii[h]]) {
				c = aa[ii[h]];
				break;
			}
		if (c == 0)
			for (h = 0; h < k; h++)
				c = max(c, aa[i - jj[h]]);
		printf("%d\n", c);
	}
	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 = -N;
    for(i = 0; prev != 0 && i < ls; i++) {
        if(s[i] == '4' || s[i] == '7')
            prev = (i - prev) <= k ? 0 : i + 1;
    }
    return prev == 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>

int main(int argc, char* argv[])
{
  int a, b;
  scanf("%d %d", &a, &b);
  printf("%d\n", 6 - a - b);
}


#include <stdio.h>
void main(void)
{
int a, b;
scanf("%d %d", &a, &b);
if ((a==1) ||(b==1))
{
if ((a==2) ||(b==2))
printf("3");
else
printf("2");

}
else
printf("1");
}


#include <stdio.h>

#define N	100000
#define MD	1000000007

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

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

int tt[N + 1];

void init() {
	int a, b;

	for (a = 1; a <= N; a++)
		tt[a] = a;
	for (a = 2; a <= N; a++) {
		if (tt[a] != a)
			continue;
		for (b = a; b <= N; b += a)
			tt[b] = tt[b] / a * (a - 1);
	}
}

int main() {
	int n, d, a, b, ans;

	init();
	scanf("%d", &n);
	ans = 0;
	for (d = 1; d <= n; d++)
		for (a = d + d; a < n; a += d) {
			b = n - a;
			ans = (ans + lcm(b, d) % MD * tt[a / d]) % MD;
		}
	printf("%d\n", ans);
	return 0;
}


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

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

int S[4010][4010];

void Generate(){
    int i, j;

    S[0][0] = 1;
    for (i = 1; i < MAX; i++){
        S[i][0] = 0;
        for (j = 1; j <= i; j++){
            S[i][j] = ( ((long long)S[i - 1][j] * j) + S[i - 1][j - 1]) % MOD;
        }
    }
}

int F(int n){
    int k;
    long long x, res = 0;
    for (k = 1; k <= n; k++){
        x = S[n][k];
        res = (res + (x * k)) % MOD;
    }
    return res;
}

int main(){
    Generate();
    int n;
    while (scanf("%d", &n) != EOF){
        printf("%d\n", F(n));
    }
    return 0;
}


// Author: Param Singh <paramsingh258@gmail.com>
// Symmetric and Transitive: http://codeforces.com/contest/568/problem/B

#include <stdio.h>
#include <stdlib.h>
#define BIG 1000000007

int main(void) {
    int n;
    int i, j;
    scanf("%d", &n);
    int** dp = (int **) calloc(n+1, sizeof(int *));
    int* eq = (int *) calloc(n, sizeof(int));
    eq[0] = eq[1] = 1;
    for (i = 0; i <= n; i++) {
        dp[i] = (int *) calloc(n+1, sizeof(int));
        if (i == 1)
            dp[i][1] = 1;
        else if (i != 0) {
            for (j = 1; j <= n; j++) {
                dp[i][j] = (dp[i-1][j-1] +(((long long)(j) * dp[i-1][j]) % BIG)) % BIG;
                eq[i] = (eq[i] + dp[i][j]) % BIG;
            }
        }
    }

    int **c = (int **) calloc(n+1, sizeof(int *));
    for (i = 0; i <= n; i++) {
        c[i] = (int *) calloc(n+1, sizeof(int));
        c[i][0] = 0;
        c[i][1] = i;
        if (i == 0)
            continue;
        for (j = 2; j <= n; j++) {
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % BIG;
        }
    }

    int ans = 0;
    for (i = 1; i <= n; i++) {
        int x = ((long long)(c[n][i]) * eq[n-i]) % BIG;
        ans = (ans + x) % BIG;
    }

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


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

typedef struct node{
        int v;
        struct node *next;
} NODE;

char f[100000];

void dfs(int n, NODE *e[], char v[], int mode){
     v[n] = 1;
     if (!mode && f[n] == 1)return;
     NODE *tmp = e[n];
     while (tmp){
           if (!v[tmp->v] && !(mode && f[tmp->v] == 1))
              dfs(tmp->v, e, v, mode);
           tmp = tmp->next;
     }
     return;
}

int main(){
    int n, m, i, j, x, y;
    char f1 = 0, f2 = 0, v1[100000] = {}, v2[100000] = {};
    NODE *e[100000] = {}, *b[100000] = {}, *tmp;
    scanf("%d%d", &n, &m);
    for (i = 0 ; i < n ; ++i){
        scanf("%d", f + i);
        if (f[i] == 1)f1 = 1;
        else if (f[i] == 2)f2 = 1;
    }
    if (!f1 || !f2){
       while (n--)puts("0");
       return 0;
    }

    for (i = 0 ; i < m ; ++i){
        scanf("%d%d", &x, &y);
        --x, --y;
        tmp = calloc(1, sizeof(NODE));
        tmp->v = y, tmp->next = e[x], e[x] = tmp;
        tmp = calloc(1, sizeof(NODE));
        tmp->v = x, tmp->next = b[y], b[y] = tmp;
    }
    for (i = 0 ; i < n ; ++i)
        if (f[i] == 1)
           dfs(i, e, v1, 1);
    for (i = 0 ; i < n ; ++i)
        if (f[i] == 2)
           dfs(i, b, v2, 0);
    for (i = 0 ; i < n ; ++i)
        printf("%d\n", v1[i] && v2[i]);
    scanf(" ");
    return 0;
}


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

typedef struct node{
        int v;
        struct node *pre, *next;
} NODE;

int e[100000][2], v[100001] = {};
char s[100001] = {}, f[100001];
NODE pre[100000] = {}, *prep[100001];

int cmp(const void *a, const void *b){
    int *x = (int*)a, *y = (int*)b;
    if (x[0] < y[0])return -1;
    if (x[0] > y[0])return 1;
    if (x[1] < y[1])return -1;
    if (x[1] > y[1])return 1;
    return 0;
}

void fill(int now, NODE *prep[]){
     do {
        if (!prep[now]->v)return;
        if (s[prep[now]->v])continue;
        s[prep[now]->v] = 1;
        fill(prep[now]->v, prep);
     }while (prep[now]->pre && (prep[now] = prep[now]->pre));
     return;
}

int main(){
    int n, m, i, j;
    char f1 = 0, f2 = 0;

    scanf("%d%d", &n, &m);
    for (i = 1 ; i <= n ; ++i){
        scanf("%d", f + i);
        if (f[i] == 1)f1 = 1;
        else if (f[i] == 2)f2 = 1;
    }
    if (!f1 || !f2){
       while (n--)puts("0");
       return 0;
    }

    for (i = 0 ; i < m ; ++i)
        scanf("%d%d", &e[i][0], &e[i][1]);
    qsort(e, m, sizeof(int) * 2, cmp);
    for (i = 0, j = 1 ; i < m ; ++i)
        while (e[i][0] > j)v[j++] = i;
    while (j <= n)v[j++] = m;

    for (i = 1 ; i <= n ; ++i){
        if (f[i] != 1)continue;
        int l, r, q[100000];
        char c[100001] = {};
        memset(pre, 0, sizeof(pre));
        q[0] = i, c[i] = 1;
        prep[i] = &pre[0];
        for (l = 0, r = 1 ; l < r ; ++l){
            for (j = v[q[l] - 1] ; j < v[q[l]] ; ++j){
                if (f[e[j][1]] == 1)continue;
                if (c[e[j][1]]){
                   NODE *tmp = prep[e[j][1]];
                   do {
                      if (tmp->v == q[l])break;
                   }while (tmp->pre && (tmp = tmp->pre));
                   if (tmp->v == q[l])continue;
                   prep[e[j][1]]->next = calloc(1, sizeof(NODE));
                   prep[e[j][1]]->next->pre = prep[e[j][1]];
                   prep[e[j][1]] = prep[e[j][1]]->next;
                   prep[e[j][1]]->v = q[l];
                }
                else {
                     c[e[j][1]] = 1;
                     pre[r].v = q[l];
                     prep[e[j][1]] = &pre[r];
                     q[r++] = e[j][1];
                }
                if (s[e[j][1]] || f[e[j][1]] == 2){
                   s[e[j][1]] = 1;
                   fill(e[j][1], prep);
                }
            }
        }
    }
    for (i = 1 ; i <= n ; ++i)
        printf("%d\n", s[i]);
    return 0;
}


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

typedef struct node{
        int v;
        struct node *next;
} NODE;

void dfs(int n, NODE *e[], char v[]){
     NODE *tmp = e[n];
     v[n] = 1;
     while (tmp){
           if (!v[tmp->v])
              dfs(tmp->v, e, v);
           tmp = tmp->next;
     }
     return;
}

int main(){
    int n, m, i, j, x, y;
    char f[100000], f1 = 0, f2 = 0, v1[100000] = {}, v2[100000] = {};
    NODE *e[100000] = {}, *b[100000] = {}, *tmp;
    scanf("%d%d", &n, &m);
    for (i = 0 ; i < n ; ++i){
        scanf("%d", f + i);
        if (f[i] == 1)f1 = 1;
        else if (f[i] == 2)f2 = 1;
    }
    if (!f1 || !f2){
       while (n--)puts("0");
       return 0;
    }

    for (i = 0 ; i < m ; ++i){
        scanf("%d%d", &x, &y);
        --x, --y;
        tmp = calloc(1, sizeof(NODE));
        tmp->v = y, tmp->next = e[x], e[x] = tmp;
        tmp = calloc(1, sizeof(NODE));
        tmp->v = x, tmp->next = b[y], b[y] = tmp;
    }
    for (i = 0 ; i < n ; ++i)
        if (f[i] == 1)
           dfs(i, e, v1);
    for (i = 0 ; i < n ; ++i)
        if (f[i] == 2)
           dfs(i, b, v2);
    for (i = 0 ; i < n ; ++i)
        printf("%d\n", v1[i] && v2[i]);
    return 0;
}


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

typedef struct node{
        int v;
        struct node *pre, *next;
} NODE;

int e[100000][2], v[100001] = {};
char s[100001] = {}, f[100001];
NODE pre[100000] = {}, *prep[100001];

int cmp(const void *a, const void *b){
    int *x = (int*)a, *y = (int*)b;
    if (x[0] < y[0])return -1;
    if (x[0] > y[0])return 1;
    if (x[1] < y[1])return -1;
    if (x[1] > y[1])return 1;
    return 0;
}

void fill(int now, NODE *prep[]){
     do {/**/printf(" f: %d %d\n", now, prep[now]->v);
        if (!prep[now]->v)return;
        if (s[prep[now]->v])continue;
        s[prep[now]->v] = 1;
        fill(prep[now]->v, prep);
     }while (prep[now]->pre && (prep[now] = prep[now]->pre));
     return;
}

int main(){
    int n, m, i, j;
    char f1 = 0, f2 = 0;

    scanf("%d%d", &n, &m);
    for (i = 1 ; i <= n ; ++i){
        scanf("%d", f + i);
        if (f[i] == 1)f1 = 1;
        else if (f[i] == 2)f2 = 1;
    }
    if (!f1 || !f2){
       while (n--)puts("0");
       return 0;
    }

    for (i = 0 ; i < m ; ++i)
        scanf("%d%d", &e[i][0], &e[i][1]);
    qsort(e, m, sizeof(int) * 2, cmp);
    for (i = 0, j = 1 ; i < m ; ++i)
        while (e[i][0] > j)v[j++] = i;
    while (j <= n)v[j++] = m;

    for (i = 1 ; i <= n ; ++i){
        if (f[i] != 1)continue;
        int l, r, q[100000];
        char c[100001] = {};
        memset(pre, 0, sizeof(pre));
        q[0] = i, c[i] = 1;
        prep[i] = &pre[0];
        for (l = 0, r = 1 ; l < r ; ++l){
            for (j = v[q[l] - 1] ; j < v[q[l]] ; ++j){
                if (f[e[j][1]] == 1)continue;
                if (c[e[j][1]]){
                   /**/printf("c: %d %d %d %d\n", l, r, e[j][0], e[j][1]);
                   NODE *tmp = prep[e[j][1]];
                   do {
                      if (tmp->v == q[l])break;
                   }while (tmp->pre && (tmp = tmp->pre));
                   if (tmp->v == q[l])continue;
                   prep[e[j][1]]->next = calloc(1, sizeof(NODE));
                   prep[e[j][1]]->next->pre = prep[e[j][1]];
                   prep[e[j][1]] = prep[e[j][1]]->next;
                   prep[e[j][1]]->v = q[l];
                }
                else {
                   /**/printf("d: %d %d %d %d\n", l, r, e[j][0], e[j][1]);
                     c[e[j][1]] = 1;
                     pre[r].v = q[l];
                     prep[e[j][1]] = &pre[r];
                     q[r++] = e[j][1];
                }
                if (s[e[j][1]] || f[e[j][1]] == 2){
                  /**/printf("s: %d %d %d %d\n", l, r, e[j][0], e[j][1]);
                   s[e[j][1]] = 1;
                   fill(e[j][1], prep);
                }
            }
        }
    }
    for (i = 1 ; i <= n ; ++i)
        printf("%d\n", s[i]);
    return 0;
}


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

int main()
{
    int n=0,i=0,j=0,book[81]={0},max=0,now[81]={0},money=0,number=0,de=0;
    scanf("%d %d",&n,&max);
    for(i=0;i<n;i++)
    {
        scanf("%d",&book[i]);
        if(now[book[i]]==0 && number<max)
        {
            now[book[i]]=1;
            money++;
            number++;
        }
        else if(now[book[i]]==0 && number==max)
        {
            for(j=i;j<n;j++)
            {
                if(now[book[j]]==1)
                    de=book[j];
            }
            now[de]=0;
            now[book[i]]=1;
            money++;
        }
    }
    printf("%d\n",money);
    return 0;
}


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

int main()
{
    int n=0,i=0,j=0,book[81]={0},max=0,now[81]={0},money=0,number=0,de=0,k=0,chose=0;
    scanf("%d %d",&n,&max);
    for(i=0;i<n;i++)
        scanf("%d",&book[i]);
    for(i=0;i<n;i++)
    {
        if(now[book[i]]==0 && number<max)
        {
            now[book[i]]=1;
            money++;
            number++;
        }
        else if(now[book[i]]==0 && number==max)
        {
            for(j=i;j<n;j++)
            {
                if(now[book[j]]==1)
                    de=book[j];
            }
            for(j=0;j<81;j++)
            {
                chose=0;
                if(now[j]==1)
                {
                    //but=now[j];
                    for(k=i;k<n;k++)
                    {
                        if(j==book[k])
                            chose=1;
                    }
                    if(chose==0)
                        de=j;
                }

            }
            now[de]=0;
            now[book[i]]=1;
            money++;
        }
    }
    printf("%d\n",money);
    return 0;
}


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

int main()
{
    int n=0,i=0,j=0,book[81]={0},max=0,now[81]={0},money=0,number=0,de=0;
    scanf("%d %d",&n,&max);
    for(i=0;i<n;i++)
        scanf("%d",&book[i]);
    for(i=0;i<n;i++)
    {
        if(now[book[i]]==0 && number<max)
        {
            now[book[i]]=1;
            money++;
            number++;
        }
        else if(now[book[i]]==0 && number==max)
        {
            for(j=i;j<n;j++)
            {
                if(now[book[j]]==1)
                    de=book[j];
            }
            now[de]=0;
            now[book[i]]=1;
            money++;
        }
    }
    printf("%d\n",money);
    return 0;
}


#include<stdio.h>
int main(){
    int i,j,n,m,k,stock[81]={0},temp=0,count=0,ans = 0, a[81],check[81]={0};
    scanf("%d %d",&n ,&k);
    for(j=1;j<=n;j++)
        scanf("%d",&a[j]);
    stock[a[1]]++;
    ans++;
    count++;
    for(j=2;j<=n;j++){
        if(stock[a[j]] == 1) continue;
        if(count == k){
            for(i=0; i<81; i++)
                check[i] = 0;
            temp = count;
            for(i=j+1; i<=n; i++){
                if(temp == 1){
                    for(m=1; m<81; m++)
                        if(check[m] == 0 && stock[m] == 1){
                            stock[m] = 0;
                            count--;
                            break;
                        }
                    break;
                }
                if(stock[a[i]] == 1 && check[a[i]] == 0){
                    temp--;
                    check[a[i]] = 1;
                }
            }

                for(m=1; m<81; m++)
                    if(check[m] == 0 && stock[m] == 1){
                        stock[m] = 0;
                        count--;
                    }

        }
        stock[a[j]] = 1;
        count++;
        ans++;
        /*printf("%d\t",ans);
        for(i=0; i<81;i++)
            if(stock[i]) printf("%d ",i);
        printf("\n");*/
    }
    printf("%d\n",ans);
    return 0;
}


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

int main()
{
    int n=0,i=0,j=0,book[81]={0},max=0,now[81]={0},time[81]={0},money=0,number=0,de=0,k=0,chose=0;
    scanf("%d %d",&n,&max);
    for(i=0;i<n;i++)
        scanf("%d",&book[i]);
    for(i=0;i<n;i++)
    {
        if(now[book[i]]==0 && number<max)
        {
            now[book[i]]=1;
            money++;
            number++;
        }
        else if(now[book[i]]==0 && number==max)
        {
            for(j=0;j<81;j++)
                time[j]=0;
            for(j=i;j<n;j++)
            {
                if(now[book[j]]==1 && time[book[j]]==0)
                {
                    time[book[j]]=1;
                    de=book[j];
                }
            }
            for(j=0;j<81;j++)
            {
                chose=0;
                if(now[j]==1)
                {
                    //but=now[j];
                    for(k=i;k<n;k++)
                    {
                        if(j==book[k])
                            chose=1;
                    }
                    if(chose==0)
                        de=j;
                }

            }
            now[de]=0;
            now[book[i]]=1;
            money++;
        }
    }
    printf("%d\n",money);
    return 0;
}


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

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

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

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


#include <stdio.h>

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

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

	return 0;
}


#include <stdio.h>
int dp[51*10010];
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<stdio.h>

int n,x,y,k;

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

long long square(long long a,long long b,long long m)
{
     long long t;

     if(a==m)
      if(b==m)
        return m*(m-1)/2;
        else return (m-b-1)*b+b*(b+1)/2;
      else
        if(b==m)
          return (m-a-1)*a+a*(a+1)/2;
          else
            {
              t=a+b-m;
              if(t>0)
                return a*b-t*(t+1)/2;
                else return a*b;
            }
}

int check(int nn,int xx,int yy,int kk,int mm)
{
    long long left,right,down,up;
    long long n=(long long)nn,x=(long long)xx,y=(long long)yy,k=(long long)kk,m=(long long)mm;
    long long sum=0;

    left=min(m,x-1);
    right=min(m,n-x);
    down=min(m,y-1);
    up=min(m,n-y);

    sum=left+right+up+down+1;

    sum+=square(left,down,m);
    sum+=square(left,up,m);
    sum+=square(right,down,m);
    sum+=square(right,up,m);

    if(sum>=k)
      return 1;
      else return 0;
}

int erfen(int a,int b)
{
    int mid;

    if(a==b)
      return a;

    mid=(a+b)/2;
    if(check(n,x,y,k,mid))
      return erfen(a,mid);
      else return erfen(mid+1,b);
}

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

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

    //system("pause");
    return 0;
}


#include <stdio.h>

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

int main()
{
    int n, x, y, c;
    long long l, r, m;

    scanf("%d %d %d %d", &n, &x, &y, &c);

    x--;
    y--;

    l = -1;
    r = n * 2;
    m = (l + r) / 2;

    while (r - l > 1) {
        long long sum = m * m * 2 + m * 2 + 1;

        if (x < m) sum -= (m - x) * (m - x);
        if (y < m) sum -= (m - y) * (m - y);
        if (n - x - 1 < m) sum -= (m - n + x + 1) * (m - n + x + 1);
        if (n - y - 1 < m) sum -= (m - n + y + 1) * (m - n + y + 1);

        if (m - x - y - 1 > 0) {
            long long z = m - x - y - 1;

            sum += z * (z + 1) / 2;
        }

        if (m - x - n + y > 0) {
            long long z = m - x - n + y;

            sum += z * (z + 1) / 2;
        }

        if (m - y - n + x > 0) {
            long long z = m - y - n + x;

            sum += z * (z + 1) / 2;
        }

        if (m + x + y - n * 2 + 1 > 0) {
            long long z = m + x + y - n * 2 + 1;

            sum += z * (z + 1) / 2;
        }

        if (sum >= c) {
            r = m;
            m = (l + r) / 2;
        } else {
            l = m;
            m = (l + r) / 2;
        }
    }

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

    return 0;
}


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

long long count(int n, int x, int y, int r) {
	long long a = 2LL * r * r + 2 * r + 1;
	int w;

	if ((w = 1 - (x - r)) > 0)
		a -= (long long) w * w;
	if ((w = 1 - (y - r)) > 0)
		a -= (long long) w * w;
	if ((w = (x + r) - n) > 0)
		a -= (long long) w * w;
	if ((w = (y + r) - n) > 0)
		a -= (long long) w * w;
	if ((w = r - 1 - (x - 1) - (y - 1)) > 0)
		a += (long long) w * (w + 1) / 2;
	if ((w = r - 1 - (x - 1) - (n - y)) > 0)
		a += (long long) w * (w + 1) / 2;
	if ((w = r - 1 - (n - x) - (y - 1)) > 0)
		a += (long long) w * (w + 1) / 2;
	if ((w = r - 1 - (n - x) - (n - y)) > 0)
		a += (long long) w * (w + 1) / 2;
	return a;
}

int main() {
	int n, x, y, c, lower, upper, r;

	scanf("%d%d%d%d", &n, &x, &y, &c);
	lower = -1, upper = c;
	while (upper - lower > 1) {
		r = (lower + upper) / 2;
		if (count(n, x, y, r) >= c)
			upper = r;
		else
			lower = r;
	}
	printf("%d\n", upper);
	return 0;
}


#include<stdio.h>
int main()

{
    int n,a,b,c,i,count=0,j,k;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    if(2*c>n)c=n/2;
    if(b>n)b=n;
    if(c/2>n)c=2*n;
    for(i=c;i>=0;i--)
    {
        if(2*i==n){count++;
        continue;
        }
        for(j=b;j>=0;j--)
        {
            if(2*i+j==n)
            {
                count++;
                continue;
            }
            k=2*n-4*i-2*j;
            if(0<=k &&k<=a)count++;
        }

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


#include<stdio.h>
int main()

{
    int n,a,b,c,i,count=0,j,k;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    for(i=c;i>=0;i--)
    {
        if(2*i==n){count++;
        continue;
        }
        for(j=b;j>=0;j--)
        {
            if(2*i+j==n)
            {
                count++;
                continue;
            }
            for(k=0;k<=a;k+=2)
            {
                if(2*i+j+(k/2)==n)count++;
            }
        }

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


// Cola

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

#define ll long long

int count[20000];

void deal(int n, int a, int b, int c)
{
    int i, j;
    ll ans = 0;
    memset(count, 0, sizeof(count));
    for (i = 0; i <= b; i++)
    {
        for (j = 0; j <= c; j++)
        {
            count[i + 2 * j]++;
        }
    }
    for (i = 0; i <= a; i += 2)
    {
        ans += count[n - i / 2];
    }
    printf("%lld\n", ans);
}

int main(int argc, char **argv)
{
    int a, b, c, n;
    while (scanf("%d%d%d%d", &n, &a, &b, &c) == 4)
    {
        deal(n, a, b, c);
    }
    return 0;
}


#include<stdio.h>
int main()
{

    int n,a,b,c,sum;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    int count =0;
    int i,j;
    for(i=0;i<=a;i++)
    {
        if(i%2)
            continue;
        for(j=0;j<=b;j++)
        {
            sum=0;
            sum=(n)-(int)(i*0.5)-(j*1);
            if((sum%2 ==0)&&((sum/2)<=c))
                count++;
        }
    }
    printf("%d",count);
    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, 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;
}


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

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

int ar[MAX];
const long long MODSQ = (long long)MOD * MOD;

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

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

int main(){
    int n, k, i, j, c, d;
    long long x, y, z, u, v, res;

    while (scanf("%d %d", &n, &k) != EOF){
        if (n == 0 && k == 0) break;

        for (i = 0; i <= (k + 1); i++){
            ar[i] = expo(i, k);
            if (i){
                ar[i] += ar[i - 1];
                if (ar[i] >= MOD) ar[i] -= MOD;
            }
        }
        if (n <= (k + 1)) res = ar[n];
        else{
            res = 0;
            u = 1, v = 1;
            for (i = 0; i <= (k + 1); i++){
                u = (u * (n - i)) % MOD;
                if (i) v = ((v * -i) + MODSQ) % MOD;
            }

            for (i = 0, c = 1, d = k + 1; i <= (k + 1); i++, c++, d--){
                x = (u * ar[i]) % MOD;
                x = (x * expo(n - i, MOD - 2)) % MOD;
                y = ((x * expo(v, MOD - 2)) % MOD);
                v = (v * c) % MOD;
                if (d) v = (v * expo(d, MOD - 2)) % MOD;
                if (i & 1) y = MOD - y;
                res += y;
            }
        }
        printf("%lld\n", res % MOD);
    }
    return 0;
}


#include <stdio.h>
#define min(x,y) ((x) < (y) ? (x) : (y))

int n;

int gcd(int x, int y, int *ti) {
  return y ? (*ti += x/y, gcd(y, x%y, ti)) : x;
}

int main(void)
{
  int ans = 0x3f3f3f3f;
  int ti, i;

  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    ti = 0;
    if (gcd(n, i, &ti) == 1)
      ans = min(ans, ti);
  }

  printf("%d\n", ans-1);

  return 0;
}


#include<stdio.h>
int ss,s[1000];
int main(void){
    int n;scanf("%d",&n);
    int x=n-1;
    int i=2,m=n;
    while (m>1){
        if(m%i==0){s[ss]=i;ss++;}
        while(m%i==0)m/=i;
        i++;}
    for(i=2;i<=n;i++){
        int c=0;
        int j;for(j=0;j<ss;j++)
            if(i%s[j]==0){c=1;break;}
        if(c==1)continue;
        int cnt=0;
        int y=n,z=i;
        while(y>1&&cnt<x){
            int u=z,v=y-z;
            cnt++;
            if(u>=v){y=u;z=v;}
            else{y=v;z=u;}}
        if(cnt<x)x=cnt;}
    printf("%d\n",x);return 0;}


#include <stdio.h>

const int inf = 1000000000;

int count(int a, int b) {
	if (b == 0)
		if (a == 1)
			return 0;
		else
			return inf;

	return count(b, a%b) + a/b;
}

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

	int i, m = inf;
	for (i = 1; i <= n; i++) {
		int c = count(i, n);
		if (c < m)
			m = c;
	}

	printf("%d\n", m-1);

	return 0;
}


#include <stdio.h>

int gcm(int a, int b) // a<=bであること．
{
    if(a == 0)
        return b;
    else
        return gcm(b%a, a);
}

int rec(int a, int b) // a<bであること．
{
    if(a == 1)
        return b-1;
    return b/a + rec(b%a, a);
}

int main (int argc, const char * argv[]) {
    int i, a, b, min;
    scanf("%d", &a);
    min = a-1;
    for(i = 2; i <= a/2; i++){
        if(gcm(a, i) != 1)
            continue;
        if((b = rec(i, a)) < min)
            min = b;
    }
    printf("%d\n", min);
    return 0;
}


#include<stdio.h>

int numberOfWalls(int n,int c,int N ,int C, int dp[N+1][C+1]){
	int i,count = 0;
	if(dp[n][c]!=-1){
		return dp[n][c];
	}
	for(i=0;i<=n;i++){
		count+=numberOfWalls(n-i,c-1,N,C,dp);
		if(count>=1000003){
			count%=1000003;
		}
	}
	dp[n][c]=count;
	return count;
}

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

	printf("%d\n",numberOfWalls(n,c,n,c,dp)-1);
	return 0;
	}


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

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

long long fact[MAX], inv[MAX];

void Generate(){
    int i, x;
    fact[0] = 1, inv[MAX - 1] = 6;
    for (i = 1; i < MAX; i++) fact[i] = ((long long)i * fact[i - 1]) % MOD;
    for (i = MAX - 2; i >= 0; i--) inv[i] = ((long long)inv[i + 1] * (i + 1)) % MOD;
}

long long binomial(long long n, long long k){
    if (k > n) return 0;
    return (fact[n] * inv[n - k] * inv[k]) % MOD;
}

int main(){
    Generate();
    long long n, m, i, j, res;
    while (scanf("%lld %lld", &n, &m) != EOF){
        m--, res = 0;
        for (i = 0; i <= (n + m); i++) res += binomial(i, m);
        printf("%lld\n", (res - 1 + MOD) % MOD);
    }
    return 0;
}


#include<stdio.h>
#define MOD 1000000007

int dar[252][252], k, n, fact[252], inv[252];

int add(int a, int b){
  a += b;
  if(a >= MOD)a -= MOD;
  return a;
}

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}
int powmod(int base, long long p){
  int toret = 1;
  while(p){
    if(p&1)toret = mul(toret, base);
    base = mul(base, base);
    p >>= 1;
  }
  return toret;
}

int ncr(int n, int r){
  return mul(mul(fact[n], inv[r]), inv[n - r]);
}

int dp(int r, int c){
  //  printf("dp(%d, %d)\n", r, c);
  if(dar[r][c] == -1){
    int toret = 0;
    if(r == 0){
      dar[r][c] = (c == 0);
      return dar[r][c];
    }

    int sat = n - c;
    int i;
    for(i = 0;i <= c;i++)if(i + sat){
      int f1 = powmod(k - 1, c - i);
      f1 = mul(f1, ncr(c, i));
      int f2 = powmod(k, sat);
      if(i == 0){
	f2 = add(f2, MOD - powmod(k - 1, sat));
      }
      toret = add(toret, mul(dp(r - 1, c - i), mul(f1, f2)));
    }
    dar[r][c] = toret;
  }
  return dar[r][c];
}

int main(){
  scanf("%d %d", &n, &k);
  int i,j;
  fact[0] = 1;
  for(i = 1;i < 252;i++)fact[i] = mul(fact[i - 1], i);
  for(i = 0;i < 252;i++) inv[i] = powmod(fact[i], MOD - 2);
  for(i = 0;i <= n;i++)for(j = 0;j <= n;j++){
      dar[i][j] = -1;
    }
  printf("%d\n", dp(n, n));
  return 0;
}


#include<stdio.h>
#define MOD 1000000007

int dar[252][252], k, n, fact[252];

int add(int a, int b){
  a += b;
  if(a >= MOD)a -= MOD;
  return a;
}

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}
int powmod(int base, long long p){
  int toret = 1;
  while(p){
    if(p&1)toret = mul(toret, base);
    base = mul(base, base);
    p >>= 1;
  }
  return toret;
}

int inv(int x){
  return powmod(x, MOD - 2);
}
int ncr(int n, int r){
  return mul(mul(fact[n], inv(fact[r])), inv(fact[n - r]));
}

int dp(int r, int c){
  //  printf("dp(%d, %d)\n", r, c);
  if(dar[r][c] == -1){
    int toret = 0;
    if(r == 0){
      dar[r][c] = (c == 0);
      return dar[r][c];
    }

    int sat = n - c;
    int i;
    for(i = 0;i <= c;i++)if(i + sat){
      int f1 = powmod(k - 1, c - i);
      f1 = mul(f1, ncr(c, i));
      int f2 = powmod(k, sat);
      if(i == 0){
	f2 = add(f2, MOD - powmod(k - 1, sat));
      }
      toret = add(toret, mul(dp(r - 1, c - i), mul(f1, f2)));
    }
    dar[r][c] = toret;
  }
  return dar[r][c];
}

int main(){
  scanf("%d %d", &n, &k);
  int i,j;
  fact[0] = 1;
  for(i = 1;i < 252;i++)fact[i] = mul(fact[i - 1], i);
  for(i = 0;i <= n;i++)for(j = 0;j <= n;j++){
      dar[i][j] = -1;
    }
  printf("%d\n", dp(n, n));
  return 0;
}


/* https://codeforces.com/blog/entry/70162 */
#include <stdio.h>

#define N	250
#define MD	1000000007

long long power(int a, int k) {
	long long b = a, p = 1;

	while (k > 0) {
		if (k & 1)
			p = p * b % MD;
		b = b * b % MD;
		k >>= 1;
	}
	return p;
}

int ff[N + 1], gg[N + 1];

void init() {
	int i;
	long long f = 1;

	for (i = 0; i <= N; i++) {
		gg[i] = power(ff[i] = f, MD - 2);
		f = f * (i + 1) % MD;
	}
}

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

int main() {
	int n, k, r, ans;

	init();
	scanf("%d%d", &n, &k);
	ans = 0;
	for (r = 0; r <= n; r++)
		ans = (ans + (r % 2 == 0 ? 1 : -1) * choose(n, r) * power(power(k - 1, r) * (power(k, n - r) - power(k - 1, n - r)) % MD, n)) % MD;
	if (ans < 0)
		ans += MD;
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
#define MOD 1000000007

int dar[252][252], k, n, fact[252], inv[252], precomp[2][252];

int add(int a, int b){
  a += b;
  if(a >= MOD)a -= MOD;
  return a;
}

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}
int powmod(int base, long long p){
  int toret = 1;
  while(p){
    if(p&1)toret = mul(toret, base);
    base = mul(base, base);
    p >>= 1;
  }
  return toret;
}

int ncr(int n, int r){
  return mul(mul(fact[n], inv[r]), inv[n - r]);
}

int dp(int r, int c){
  //  printf("dp(%d, %d)\n", r, c);
  if(dar[r][c] == -1){
    int toret = 0;
    if(r == 0){
      dar[r][c] = (c == 0);
      return dar[r][c];
    }

    int sat = n - c;
    int i;
    for(i = 0;i <= c;i++)if(i + sat){
      int f1 = precomp[0][c - i];
      f1 = mul(f1, ncr(c, i));
      int f2 = precomp[1][sat];
      if(i == 0){
	f2 = add(f2, MOD - precomp[0][sat]);
      }
      toret = add(toret, mul(dp(r - 1, c - i), mul(f1, f2)));
    }
    dar[r][c] = toret;
  }
  return dar[r][c];
}

int main(){
  scanf("%d %d", &n, &k);
  if(k == 1){
    printf("1\n");
    return 0;
  }
  int i,j;
  fact[0] = 1;
  inv[0] = 1;
  precomp[0][0] = precomp[1][0] = 1;
  for(i = 1;i < 252;i++){
    fact[i] = mul(fact[i - 1], i);
    inv[i] = powmod(fact[i], MOD - 2);
    precomp[0][i] = powmod(k - 1, i);
    precomp[1][i] = powmod(k, i);
  }
  for(i = 0;i <= n;i++)for(j = 0;j <= n;j++){
      dar[i][j] = -1;
    }
  printf("%d\n", dp(n, n));
  return 0;
}


#include <stdio.h>

#define N	250
#define MD	1000000007

long long power(int a, int k) {
	long long b = a, p = 1;

	while (k > 0) {
		if (k & 1)
			p = p * b % MD;
		b = b * b % MD;
		k >>= 1;
	}
	return p;
}

int ff[N + 1], gg[N + 1];

void init() {
	int i;
	long long f = 1;

	for (i = 0; i <= N; i++) {
		gg[i] = power(ff[i] = f, MD - 2);
		f = f * (i + 1) % MD;
	}
}

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

int main() {
	static int pk[N * N + 1], pk_[N * N + 1];
	int n, k, r, c, i, ans;

	init();
	scanf("%d%d", &n, &k);
	pk[0] = pk_[0] = 1;
	for (i = 1; i <= n * n; i++) {
		pk[i] = (long long) pk[i - 1] * k % MD;
		pk_[i] = (long long) pk_[i - 1] * (k - 1) % MD;
	}
	ans = 0;
	for (r = 0; r <= n; r++)
		for (c = 0; c <= n; c++) {
			int x = choose(n, r) * choose(n, c) % MD
				* pk_[n * n - (n - r) * (n - c)] % MD * pk[(n - r) * (n - c)] % MD;

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


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

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

struct case1
{
 long next[35];
 long num;
}trie[50005]={{{0},0}};

long tot=1;

char str[35][35]={'\0'};
long a[35][35][35]={0};

long e[2000005]={0};
long last[2000005]={0};
long now[50005]={0};
long totm=0;

struct case2
{
 long max;
 long min;
 long win;
 long cost;
}tree[50005]={{0,0,0,0}};

long o=1;
long hash[50005]={0};

long find(long x,long st,long en)
{
 long p=1,i,j;
 long s=0;
 long max=0;

 for(;st<=en;st++)
   {
    s+=str[x][st]-'a'+1;
    if(str[x][st]-'a'+1>max)
     max=str[x][st]-'a'+1;
    if(!trie[p].next[str[x][st]-'a'])
     trie[p].next[str[x][st]-'a']=++tot;
    p=trie[p].next[str[x][st]-'a'];
   }
 if(trie[p].num==0)
  {
   trie[p].num=++o;
   tree[o].cost=s*max;
  }
 return trie[p].num;
}

void addedge(long x,long y)
{
 if(x<=0)
  x=1;
 if(y<=0)
  y=1;
 e[++totm]=y;
 last[totm]=now[x];now[x]=totm;
}

void dfs(long x)
{
 long i;

 if(tree[x].max)
  return;

 tree[x].max=0;
 tree[x].min=0;

 for(i=now[x];i;i=last[i])
   {
    dfs(e[i]);
    if(tree[e[i]].win==0)
     tree[x].win=1;
   }
 for(i=now[x];i;i=last[i])
   {
    if(tree[x].win==1&&tree[e[i]].win==1)
     continue;
    if(tree[e[i]].min+tree[e[i]].cost>tree[x].max||tree[e[i]].min+tree[e[i]].cost==tree[x].max&&tree[e[i]].max<tree[x].min)
     {
      tree[x].max=tree[e[i]].min+tree[e[i]].cost;
      tree[x].min=tree[e[i]].max;
     }
   }
}

int main()
{
 long n;
 long i,j;
 long l;
 long len;

 scanf("%ld",&n);
 for(i=1;i<=n;i++)
   scanf("%s",str[i]+1);

 for(i=1;i<=n;i++)
   {
    len=strlen(str[i]+1);
    for(l=1;l<=len;l++)
      for(j=1;j+l-1<=len;j++)
        {
         a[i][j][j+l-1]=find(i,j,j+l-1);
         addedge(a[i][j+1][j+l-1],a[i][j][j+l-1]);
         addedge(a[i][j][j+l-2],a[i][j][j+l-1]);
        }
   }

 for(i=1;i<=n;i++)
   {
    memset(hash,0,sizeof(hash));
    len=strlen(str[i]+1);
    for(j=1;j<=len;j++)
      for(l=j;l<=len;l++)
        hash[a[i][j][l]]=1;
    for(j=1;j<=o;j++)
      if(hash[j])
       tree[j].cost++;
   }

 dfs(1);
 if(tree[1].win)
  printf("First\n");
 else
  printf("Second\n");
 printf("%ld %ld\n",tree[1].max,tree[1].min);

 return 0;
}


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

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

struct case1
{
 long next[35];
 long num;
}trie[5005]={{{0},0}};

long tot=1;

char str[35][35]={'\0'};
long a[35][35][35]={0};

long e[500005]={0};
long last[500005]={0};
long now[5005]={0};
long totm=0;

struct case2
{
 long max;
 long min;
 long win;
 long cost;
}tree[5005]={{0,0,0,0}};

long o=1;
long hash[5005]={0};

long find(long x,long st,long en)
{
 long p=1,i,j;
 long s=0;
 long max=0;

 for(;st<=en;st++)
   {
    s+=str[x][st]-'a'+1;
    if(str[x][st]-'a'+1>max)
     max=str[x][st]-'a'+1;
    if(!trie[p].next[str[x][st]-'a'])
     trie[p].next[str[x][st]-'a']=++tot;
    p=trie[p].next[str[x][st]-'a'];
   }
 if(trie[p].num==0)
  {
   trie[p].num=++o;
   tree[o].cost=s*max;
  }
 return trie[p].num;
}

void addedge(long x,long y)
{
 if(x<=0)
  x=1;
 if(y<=0)
  y=1;
 e[++totm]=y;
 last[totm]=now[x];now[x]=totm;
}

void dfs(long x)
{
 long i;

 tree[x].max=0;
 tree[x].min=0;

 for(i=now[x];i;i=last[i])
   {
    dfs(e[i]);
    if(tree[e[i]].win==0)
     tree[x].win=1;
   }
 for(i=now[x];i;i=last[i])
   {
    if(tree[x].win==1&&tree[e[i]].win==1)
     continue;
    if(tree[e[i]].min+tree[e[i]].cost>tree[x].max||tree[e[i]].min+tree[e[i]].cost==tree[x].max&&tree[e[i]].max<tree[x].min)
     {
      tree[x].max=tree[e[i]].min+tree[e[i]].cost;
      tree[x].min=tree[e[i]].max;
     }
   }
}

int main()
{
 long n;
 long i,j;
 long l;

 scanf("%ld",&n);
 for(i=1;i<=n;i++)
   scanf("%s",str[i]+1);

 for(i=1;i<=n;i++)
   for(l=1;l<=strlen(str[i]+1);l++)
     for(j=1;j+l-1<=strlen(str[i]+1);j++)
       {
        a[i][j][j+l-1]=find(i,j,j+l-1);
        addedge(a[i][j+1][j+l-1],a[i][j][j+l-1]);
        addedge(a[i][j][j+l-2],a[i][j][j+l-1]);
       }

 for(i=1;i<=n;i++)
   {
    memset(hash,0,sizeof(hash));
    for(j=1;j<=strlen(str[i]+1);j++)
      for(l=j;l<=strlen(str[i]+1);l++)
        hash[a[i][j][l]]=1;
    for(j=1;j<=o;j++)
      if(hash[j])
       tree[j].cost++;
   }

 dfs(1);
 if(tree[1].win)
  printf("First\n");
 else
  printf("Second\n");
 printf("%ld %ld\n",tree[1].max,tree[1].min);

 return 0;
}


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

#define N	30
#define T	(30 * 31 / 2)
#define NU	(N * T)
#define NV	(NU * 3)

char *strndup_(char *s, int n) {
	char *s_ = malloc(n + 1);

	strncpy(s_, s, n);
	s_[n] = 0;
	return s_;
}

struct V {
	char *s;
	int i, h;
} vv_[NV], *vv[NV];

int compare(const void *a, const void *b) {
	struct V *u = *(struct V **) a;
	struct V *v = *(struct V **) b;
	int mu = strlen(u->s), mv = strlen(v->s);
	int c;

	if (mu != mv)
		return mu - mv;
	c = strcmp(u->s, v->s);
	return c != 0 ? c : u->i - v->i;
}

int score(char *s) {
	int n = strlen(s), i;
	int sum, max;

	sum = max = 0;
	for (i = 0; i < n; i++) {
		int a = s[i] - 'a' + 1;

		sum += a;
		if (max < a)
			max = a;
	}
	return sum * max;
}

int xx[NU + 1];
char ww[NU + 1];
int ss[NU + 1], tt[NU + 1];

void push(int p, int i) {
	int s = tt[i] + xx[i], t = ss[i];

	if (!ww[p]) {
		if (!ww[i])
			ww[p] = 1, ss[p] = s, tt[p] = t;
		else if (ss[p] < s || ss[p] == s && tt[p] > t)
			ss[p] = s, tt[p] = t;
	} else if (!ww[i] && (ss[p] < s || ss[p] == s && tt[p] > t))
		ss[p] = s, tt[p] = t;
}

int main() {
	static int pp[NU + 1], qq[NU + 1];
	int n, nv, k, i;

	scanf("%d", &n);
	nv = 0;
	for (i = 0; i < n; i++) {
		static char s[32];
		int m, l, r;

		scanf("%s", s), m = strlen(s);
		for (l = 0; l < m; l++)
			for (r = l; r < m; r++) {
				struct V *v, *p, *q;
				char *t = strndup_(s + l, r - l + 1);

				v = vv[nv] = &vv_[nv], nv++;
				v->s = t, v->i = i;
				p = vv[nv] = &vv_[nv], nv++;
				p->s = strndup_(t + 1, r - l), p->i = -1;
				q = vv[nv] = &vv_[nv], nv++;
				q->s = strndup_(t, r - l), p->i = -1;
			}
	}
	qsort(vv, nv, sizeof *vv, compare);
	k = 0;
	for (i = 0; i < nv; ) {
		char *s = vv[i]->s;
		int x, j;

		for (j = i; j < nv && strcmp(vv[j]->s, s) == 0; j++)
			vv[j]->h = k;
		x = score(s);
		while (i < j) {
			if (vv[i]->i != -1 && (i + 1 == j || vv[i]->i != vv[i + 1]->i))
				x++;
			i++;
		}
		xx[k++] = x;
	}
	for (i = 0; i < nv; i += 3) {
		struct V *v = &vv_[i + 0];
		struct V *p = &vv_[i + 1];
		struct V *q = &vv_[i + 2];

		pp[v->h] = p->h;
		qq[v->h] = q->h;
	}
	for (i = k - 1; i > 0; i--) {
		push(pp[i], i);
		push(qq[i], i);
	}
	printf(ww[0] ? "First\n" : "Second\n");
	printf("%d %d\n", ss[0], tt[0]);
	return 0;
}


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

int s1,s2;

int val(char s[], char t[], int i, int j)
{
    int max1 = -1,max = -1;
    for (int k = i; k < s1-(s2-j-1); k++){
        if(s[k]==t[j]){
            if(j < s2-1){
                int temp = val(s,t,k+1,j+1);
                if(temp!=-1){
                    if(temp > k-i) max1 = temp;
                    else max1 = k-i;
                }
                else break;
                if(max1> max) max = max1;
            }
            else{
                if(k - i > s1-k-1) max1 = k - i;
                else max1 = s1 -k -1;
                if (max1 > max) max = max1;
            }
        }
        if(max >= s1-s2) return max;
    }
    return max;
}

int main()
{
    char s[201],t[201];
    scanf("%s",s);
    scanf("%s",t);
    s1= strlen(s);
    s2= strlen(t);
    if(!strcmp(s,t)) printf("0");
    else printf("%d",val(s,t,0,0));
}


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

int s1,s2;

int val(char s[], char t[], int i, int j)
{
    int max1 = -1,max = -1;
    for (int k = i; k < s1; k++){
        if(s[k]==t[j]){
            if(j < s2-1){
                int temp = val(s,t,k+1,j+1);
                if(temp!=-1){
                    if(temp > k-i) max1 = temp;
                    else max1 = k-i;
                }
                else break;
                if(max1> max) max = max1;
            }
            else{
                if(k - i > s1-k-1) max1 = k - i;
                else max1 = s1 -k -1;
                if (max1 > max) max = max1;
            }
        }
        if(max >= s1-s2) return max;
    }
    return max;
}

int main()
{
    char s[201],t[201];
    scanf("%s",s);
    scanf("%s",t);
    s1= strlen(s);
    s2= strlen(t);
    if(!strcmp(s,t)) printf("0");
    else printf("%d",val(s,t,0,0));
}


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

int s1,s2;

int val(char s[], char t[], int i, int j)
{
    int max1 = -1,max = -1;
    for (int k = i; k < s1; k++){
        if(s[k]==t[j]){
            if(j < s2-1){
                int temp = val(s,t,k+1,j+1);
                if(temp!=-1){
                    if(temp > k-i) max1 = temp;
                    else max1 = k-i;
                }
                else break;
                if(max1> max) max = max1;
            }
            else{
                if(k - i > s1-k-1) max1 = k - i;
                else max1 = s1 -k -1;
                if (max1 > max) max = max1;
            }
        }
    }
    return max;
}

int main()
{
    char s[201],t[201];
    scanf("%s",s);
    scanf("%s",t);
    s1= strlen(s);
    s2= strlen(t);
    if(!strcmp(s,t)) printf("0");
    else printf("%d",val(s,t,0,0));
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define size 101
int max_(int x,int y)
{
	return x>y?x:y;
}
main()
{
	char s[size],t[size];
	scanf("%s",s);
	scanf("%s",t);
	int i,ans=0,j,p,pos,ss,tt;
	ss=strlen(s);
	tt=strlen(t);
	for(i=0;i<ss;++i)
	{
		for(j=i;j<ss;++j)
		{
			pos=0;
			for(p=0;p<ss;++p)
			{
				if(i<=p && p<=j)
				   continue;
				if(pos<tt && t[pos]==s[p])
				   pos++;
			}
			if(pos==tt)
			{
				ans=max_(ans,j-i+1);
			}
		}
	}
printf("%d",ans);
}


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

#define N 2000000
#define MOD 1000000007

int maxp[N + 1];
int lcm[N + 1];
int lcm_cnt[N + 1];
int p[200000];
int q[200000], qp;

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

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

int main(void) {
  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;
      }
    }
  }

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  qsort(p, n, sizeof(int), cmp);
  int one = 0;
  for (int i = 0; i < n; i++) {
    int x = p[i];
    if (lcm[x] == 0) {
      lcm[x] = 1;
      continue;
    }
    q[qp++] = x;
    x--;
    while (x != 1) {
      int p = maxp[x];
      int e = 0;
      while (x % p == 0) {
        x /= p;
        e++;
      }
      if (lcm[p] < e) {
        lcm[p] = e;
        lcm_cnt[p] = 1;
      } else if (lcm[p] == e) {
        lcm_cnt[p]++;
      }
    }
  }
  for (int i = 0; i < qp; i++) {
    int x = q[i] - 1;
    bool forall = true;
    while (x != 1) {
      int p = maxp[x];
      int e = 0;
      while (x % p == 0) {
        x /= p;
        e++;
      }
      if (lcm[p] == e && lcm_cnt[p] == 1) {
        forall = false;
      }
    }
    if (forall) {
      one = 1;
    }
  }
  long long ans = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < lcm[i]; j++) {
      ans *= i;
      ans %= MOD;
    }
  }
  ans += one;
  ans %= MOD;
  printf("%lld\n", ans);
  return 0;
}


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

#define N 2000000
#define MOD 1000000007

int maxp[N + 1];
int lcm[N + 1];
int p[200000];

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

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

int main(void) {
  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;
      }
    }
  }

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  qsort(p, n, sizeof(int), cmp);
  int one = 0;
  for (int i = 0; i < n; i++) {
    int x = p[i];
    if (lcm[x] == 0) {
      lcm[x] = 1;
      continue;
    }
    bool any = false;
    x--;
    while (x != 1) {
      int p = maxp[x];
      int e = 0;
      while (x % p == 0) {
        x /= p;
        e++;
      }
      if (lcm[p] < e) {
        lcm[p] = e;
        any = true;
      }
    }
    if (!any) {
      one = 1;
    }
  }
  long long ans = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < lcm[i]; j++) {
      ans *= i;
      ans %= MOD;
    }
  }
  ans += one;
  ans %= MOD;
  printf("%lld\n", ans);
  return 0;
}


/* https://codeforces.com/blog/entry/89260 */
#include <stdio.h>

#define M	16

int main() {
	static char used[M];
	int n, m;

	scanf("%d%d", &n, &m);
	while (n > 0) {
		if (used[n % m]) {
			printf("NO\n");
			return 0;
		}
		used[n % m] = 1;
		n /= m;
	}
	printf("YES\n");
	return 0;
}


#include <stdio.h>

#define M	16

int main() {
	static char used[M];
	int n, m;

	scanf("%d%d", &n, &m);
	while (n > 0) {
		if (used[n % m]) {
			printf("NO\n");
			return 0;
		}
		used[n % m] = 1;
		n /= m;
	}
	printf("YES\n");
	return 0;
}


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

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

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

        n /= m;
    }

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


#include <stdio.h>

int main() {
	int n, b;

	scanf("%d%d", &n, &b);
	while (n > 0) {
		if (n % b > 1) {
			printf("YES\n");
			return 0;
		}
		n /= b;
	}
	printf("NO\n");
	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;
            break;
        } else {
            digits[d] = 1;
        }

        n /= m;
    }

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


#include<stdio.h>
typedef long long unsigned llu;
typedef long long ll;
typedef unsigned u;
llu G(llu a,llu b){return b?G(b,a%b):a;}
ll lx,ly;
ll egcd(ll a,ll b)
{
	long long r,q,x=0,y=1;lx=1;ly=0;
	u ee=1;
	while(b!=0)
	{
		q=a/b;
		r=b;b=a%b;a=r;
		r=x;x=lx-q*x;lx=r;
		r=y;y=ly-q*y;ly=r;
		if((ee^=1)&&(q-(b==0)))printf("%I64iB",q-(b==0));
		else if((q-(b==0)))printf("%I64iA",q-(b==0));
	}
	return a;
}
int main()
{
	llu a,b;u i,j,k;
	scanf("%I64u%I64u",&a,&b);
	if(G(a,b)!=1){printf("Impossible\n");return 0;}
	egcd(a,b);
	putchar('\n');
	return 0;
}


#include <stdio.h>

long long gcd(long long a,long long b)
{
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}
int main()
{
    long long x,y,test;
    scanf("%I64d %I64d",&x,&y);
    test=gcd(x,y);
    //printf("%I64d",test);
    if(test>1)
    {
        printf("Impossible");
        return 0;
    }
    else
    {
        while(x && y)
        {
            if(x>y)
            {
                printf("%I64dA",(x-1)/y);
                x=x%y;
            }
            else
            {
                printf("%I64dB",(y-1)/x);
                y=y%x;
            }
        }
    }
    return 0;
}


#include <stdio.h>

long long gcd(long long a,long long b)
{
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}
int main()
{
    long long x,y,test;
    scanf("%I64d %I64d",&x,&y);
    test=gcd(x,y);
    printf("%I64d",test);
    if(test>1)
    {
        printf("Impossible");
        return 0;
    }
    else
    {
        while(x && y)
        {
            if(x>y)
            {
                printf("%I64dA",(x-1)/y);
                x=x%y;
            }
            else
            {
                printf("%I64dB",(y-1)/x);
                y=y%x;
            }
        }
    }
    return 0;
}


#include <stdio.h>

long long gcd(long a,long b)
{
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}
int main()
{
    long long x,y,test;
    scanf("%I64d %I64d",&x,&y);
    test=gcd(x,y);
    if(test>1)
        printf("Impossible");
    else
    {
        while(x && y)
        {
            if(x>y)
            {
                printf("%I64dA",(x-1)/y);
                x=x%y;
            }
            else
            {
                printf("%I64dB",(y-1)/x);
                y=y%x;
            }
        }
    }
    return 0;
}


#include <stdio.h>

long long gcd(long long a,long long b)
{
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}
int main()
{
    long long x,y,test;
    scanf("%I64d %I64d",&x,&y);
    test=gcd(x,y);
    if(test>=1)
        printf("Impossible");
    else
    {
        while(x && y)
        {
            if(x>y)
            {
                printf("%I64dA",(x-1)/y);
                x=x%y;
            }
            else
            {
                printf("%I64dB",(y-1)/x);
                y=y%x;
            }
        }
    }
    return 0;
}


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


#include<stdio.h>
int main()
{
long long int s=0,t,i=1;
double n;
scanf ("%lf",&n);
n--;
t=(long long int)(n/2+0.5);
while (t)
{
s+=t*i;
i*=2;
t=(long long int)(n/(2*i)+0.5);
}
printf ("%I64d\n",s);
return 0;
}


#include<stdio.h>

int main()
{
    long long int n;
    scanf("%lld",&n);
    printf("%lld\n",(n/2)+2*((n/2)+(n%2)-1));
    return 0;
}


//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}

int main(void){
    long long i,j,n,m,k,a[262144],b,c,w,r=0,l,t,u;
    double d;
    char s[262144];
    scanf("%lld",&n);n--;u=0;
    //l=strlen(s);
    k=llpow(2,50);
    for(i=50;i>=0;i--){
        r+=(k*((n/k)-u));
        u+=(n/k);k/=2;
    }
    //qsort(a,n,sizeof(int),sortfncsj);
    printf("%lld\n",r);
    return 0;
}


#include<stdio.h>

int main()
{
    long long int i=0,n,count=0,temp,mod;
    scanf("%lld",&n);
    while(1)
    {
        mod=n%(1<<(i+1));
        temp=n/(1<<(i+1));
        // printf("%lld %lld\n",temp , mod);
        if(mod>(1<<i))
            count+=(1<<i)*(temp+1);
        else{
                count+=(1<<i)*(temp);
            }
        if(temp==0)
            break;
        i++;
    }
    printf("%lld\n", count);
    return 0;
}