#include<stdio.h>

#define DEBUG 0
#define MAX 10
#define P_SIZE 5

#define ALICE X
#define BOB O
#define EMPTY .

char game[MAX][MAX];

char pattern[P_SIZE][P_SIZE] = {".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."};

int horizontal(int lin, int col, int p) {
    int i, j, k, temp;
    if(DEBUG) printf("HORIZONTAL\n");
    i = lin;
    j = col;
    temp = 0;
    for(k = 0; k < P_SIZE && j < MAX; k++) {
        if(DEBUG) printf("game %d %d %c\n", i, j, game[i][j]);
        if(DEBUG) printf("pattern %d %d %c\n", p, k, pattern[p][k]);
        if(game[i][j] == pattern[p][k]) {
            j++;
            temp++;
        }
    }

    if(DEBUG) printf("temp %d\n", temp);
    return temp == P_SIZE;
}

int vertical(int lin, int col, int p) {
    int i, j, k, temp;
    if(DEBUG) printf("VERTICAL:\n");
    i = lin;
    j = col;
    temp = 0;
    for(k = 0; k < P_SIZE && i < MAX; k++) {
        if(DEBUG) printf("game %d %d %c\n", i, j, game[i][j]);
        if(DEBUG) printf("pattern %d %d %c\n", p, k, pattern[p][k]);
        if(game[i][j] == pattern[p][k]) {
            i++;
            temp++;
        }
    }

    if(DEBUG) printf("temp %d\n", temp);
    return temp == P_SIZE;
}

int diagonalD(int lin, int col, int p) {
    int i, j, k, temp;
    if(DEBUG) printf("DIAGONAL DIR:\n");
    i = lin;
    j = col;
    temp = 0;
    for(k = 0; k < P_SIZE && i < MAX && j < MAX; k++) {
        if(DEBUG) printf("game %d %d %c\n", i, j, game[i][j]);
        if(DEBUG) printf("pattern %d %d %c\n", p, k, pattern[p][k]);
        if(game[i][j] == pattern[p][k]) {
            i++;
            j++;
            temp++;
        }
    }

    if(DEBUG) printf("temp %d\n", temp);
    return temp == P_SIZE;
}

int diagonalE(int lin, int col, int p) {
    int i, j, k, temp;
    if(DEBUG) printf("DIAGONAL ESQ:\n");
    i = lin;
    j = col;
    temp = 0;
    for(k = 0; k < P_SIZE && i < MAX && j >= 0; k++) {
        if(DEBUG) printf("g %d %d %c\n", i, j, game[i][j]);
        if(DEBUG) printf("p %d %d %c\n", p, k, pattern[p][k]);
        if(game[i][j] == pattern[p][k]) {
            i++;
            j--;
            temp++;
        }
    }

    if(DEBUG) printf("temp %d\n", temp);
    return temp == P_SIZE;
}

int main() {

    int i, j, k, res;

    for(i = 0; i < MAX; i++) {
        for(j = 0; j < MAX; j++) {
            scanf("%c", &game[i][j]);
        }
        scanf("\n");
    }

    res = 0;
    for(i = 0; i < MAX && !res; i++) {
        for(j = 0; j < MAX && !res; j++) {
            for(k = 0; k < P_SIZE && !res; k++) {
                if(DEBUG) printf("%d %d %d\n", i, j, k);
                res = horizontal(i, j, k) ||
                      vertical(i, j, k) ||
                      diagonalD(i, j, k) ||
                      diagonalE(i, j, k);
            }
            if(DEBUG) printf("\n");
        }
    }

    if(res) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    return 0;
}


#include<stdio.h>

unsigned long long int m=1000000007;
unsigned long long int bigmod(unsigned long long int x, unsigned long long int n)
{
    if(n==0) return 1;

    if(n%2==0)
    {
    unsigned long long int num= bigmod(x,n/2);
    return ((num%m)*(num%m))%m;
    }

    else
        return ((x%m)*(bigmod(x,n-1)%m))%m;

}

int main()
{
    unsigned long long int  sum1=0,sum2=0,sum=0,n,A,B,x;

    scanf("%llu %llu %llu %llu",&A,&B,&n,&x);

    if(A==1) printf("%llu\n",((x%m)+((B%m)*(n%m))%m)%m);
    else{

    sum1=bigmod(A,n)%m;
    sum2=(sum1-1)%m;

    sum1=((sum1%m)*(x%m))%m;
    sum2=((sum2%m)*(B%m))%m;

    sum2=((sum2%m)* (bigmod(A-1,m-2))%m)%m;

    sum=((sum1%m)+(sum2%m))%m;

    printf("%llu\n",sum%m);

    }
    return 0;
}


/*
 * 678D
 *
 * (A-1)y = (A-1)xA^n + BA^n - B
 */
#include <stdio.h>
#include <stdlib.h>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <limits.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 MAX(x,y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#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 ABS(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_CORRECT(x, mod) ((x) += ((x) < 0 ? (mod) : 0))
#define NUMTH_ENS (-1)
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 P LL(1000000007)
/* x, y, n must not be negitive */
#define modmul(x, y, n) ((((x) % (n)) * ((y) % (n))) % (n))
#define modpls(x, y, n) ((((x) % (n)) + ((y) % (n))) % (n))
int main(void)
{
	long long A, B, n, x;
	long long right, q, ans, d;
	scanf("%lld%lld%lld%lld", &A, &B, &n, &x);
	if (A == 1) {
		ans = modpls(x, modmul(B, n, P), P);
		goto print_answer;
	}
	q = numth_modexp(A, n, P);
	//printf("q: %lld\n", q);
	right = modmul(modmul(A - 1, x, P), q, P) + modmul(B, q, P) - B;
	//printf("right: %lld\n", right);
	NUMTH_CORRECT(right, P);
	numth_mle(A - 1, right, P, &ans, &d);
	assert(d == 1);
	print_answer:
	printf("%lld\n", ans);
	return 0;
}

static long long numth_do_gcd(long long a, long long b);
static void numth_do_gcd_e(long long grt, long long les, long long *d, long long *x, long long *y);

long long numth_modexp(long long a, long long b, long long n)
{
	static long long bit63 = (unsigned long long)0x8000000000000000;
	long long square = 1;
	int i;

	assert(b >= 0 && n > 0);

	//FIXME: '==' > '&'
	for(i = 63; i >= 0 && (b & bit63) == 0; --i)
		b <<= 1;
	for(; i >= 0; --i) {
		square = (square * square) % n;
		if (b & bit63)
			square = (square * a) % n;
		b <<= 1;
	}

	return square;
}

long long numth_gcd(long long a, long long b)
{
	if (a == 0 && b == 0)
		return 0;
	if (a < 0)
		a *= -1;
	if (b < 0)
		b *= -1;
	/* We DON'T need a > b */
	return numth_do_gcd(a, b);
}

/* 大数除小数, 小数除余数 */
static long long numth_do_gcd(long long a, long long b)
{
	long long r;

	if (!b)
		return a;

	for (r = a % b; r != 0; r = a % b) {
		a = b;
		b = r;
	}

	return b;
}

void numth_gcd_e(long long a, long long b, long long *d, long long *x, long long *y)
{
	if (a == 0 && b == 0) {
		*d = *x = *y = 0;
		return;
	}

	if (a < 0)
		a *= -1;
	if (b < 0)
		b *= -1;

	if (a < b)
		numth_do_gcd_e(b, a, d, y, x);
	else
		numth_do_gcd_e(a, b, d, x, y);
}

static void numth_do_gcd_e(long long a, long long b, long long *d, long long *x, long long *y)
{
	long long tmp;

	if (b == 0) {
		*d = a;
		*x = 1;
		*y = 0;
		return;
	}
	numth_do_gcd_e(b, a % b, d, x, y);
	tmp = *x;
	*x = *y;
	//TODO: overflow?
	*y = (tmp - (a / b) * (*y));
}

int numth_mle(long long a, long long b, long long n, long long *solution, long long *gcd)
{
	long long d, x, y;

	assert(n != 0);

	if (n < 0)
		n *= (-1);
	if (a < 0)
		a *= (-1);
	if (b < 0)
		b *= (-1);

	numth_gcd_e(a, n, &d, &x, &y);
	assert(d != 0); //d=0 if and only if a=b=0

	if (b % d)
		return NUMTH_ENS;

	*solution = ((b / d) * (x % n)) % n;
	NUMTH_CORRECT(*solution, n);
	*gcd = d;

	return 0;
}

int numth_divisors(long long k, long long divs[], long long *ndivs)
{
	long long i, n;

	assert(k > 0);

	n = 0;
	for (i = 1; i * i < k; ++i)
		if (k % i == 0)
			divs[n++] = i;

	if (i * i == k) {
		divs[n++] = i;
		i = n - 2;
	} else {
		i = n - 1;
	}

	for (; i >= 0; --i)
		divs[n++] = k / divs[i];

	*ndivs = n;

	return 0;
}


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

  long long int l,r,x,y,k,i,exp,cost,ct=0,ck=0;
  scanf("%lld %lld %lld %lld %lld",&l,&r,&x,&y,&k);

  for(i=x;i<=y;i++){
        if(l<=k*i&&r>=k*i){
            ck=1;
            break;
        }

  }
  if(ck==1){
    printf("YES");
  }
  else{
    printf("NO");
  }

return 0;
}


#include <stdio.h>

int main() {
	int l, r, x, y, k,i,tmp;
	scanf("%d %d %d %d %d", &l, &r, &x, &y, &k);

	for( i = l; i <= r; ++i) {
		if(i % k == 0) {
			 tmp = i / k;
			if(tmp >= x && tmp <= y) {
				printf("YES");
				return 0;
			}
		}
	}

	printf("NO");

	return 0;
}


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

#define N	100
#define S	5000
#define MD	998244353

int ch[S + N][N];

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

	ch[0][0] = 1;
	for (i = 1; i < n; i++) {
		ch[i][0] = 1;
		for (j = 1; j < k; j++)
			ch[i][j] = (ch[i - 1][j - 1] + ch[i - 1][j]) % MD;
	}
}

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

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

long long inv(long long a) {
	return power(a, MD - 2);
}

int main() {
	/* dp[a][b]: b balls into a urns of size r - 1 */
	static int dp[1 + N][1 + S];
	/* dq[a][b]: dp[a][b] + dp[a][b - 1] + ... + dp[a][b - (r - 1)] */
	static int dq[1 + N][1 + S];
	int n, s, r, a, b, k, p, q;

	scanf("%d%d%d", &n, &s, &r);
	init(s + n, n);
	for (a = 0; a <= n; a++) {
		int sum;

		if (a == 0)
			dp[0][0] = 1;
		else
			for (b = 0; b <= s; b++)
				dp[a][b] = dq[a - 1][b];
		sum = 0;
		for (b = 0; b <= s; b++) {
			sum = (sum + dp[a][b]) % MD;
			if (b >= r)
				sum = (sum - dp[a][b - r] + MD) % MD;
			dq[a][b] = sum;
		}
	}
	p = 0;
	for (k = 1; k <= n && k * r <= s; k++)
		for (b = 0; b + k * r <= s; b++)
			p = (p + (long long) dp[n - k][b] * ch[s - b - k * r + k - 1][k - 1] % MD * ch[n - 1][k - 1] % MD * inv(k)) % MD;
	q = ch[s - r + n - 1][n - 1];
	printf("%lld\n", p * inv(q) % MD);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
long long tt[6]={10,100,1000,10000,100000,1000000};
int mylog(int n)
{
	int ans=0;
	while (n>=10)
	{
		ans++; n/=10;
	}
	return ans;
}
int main()
{
	int k,p,i,j;
	long long ans=0,now;
	scanf("%d%d",&k,&p);
	for (i=1;i<=k;i++)
	{
		long long t=0,t1=i;
		while (t1)
		{
			t=t*10+t1%10;
			t1/=10;
		}
		t=i*tt[mylog(i)]+t;
		ans+=t;
		ans%=p;
	}
	printf("%I64d\n",ans);
	return 0;
}


//practice with dukkha
#include<stdio.h>
long long int fx(int a)
{
	int arr[10];
	int c=0;
	long long int k=0;
	while(a!=0)
	{
		arr[c]=a%10;
		a/=10;
		c++;
	}
	for(int i=c-1;i>=0;i--)
		k=((k*10)+arr[i]);
	for(int i=0;i<c;i++)
		k=((k*10)+arr[i]);
	return k;
}
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	long long int sum=0;
	for(int i=1;i<=a;i++)
	{
		sum+=fx(i);
	}
	printf("%lld",sum%b);
	return 0;
}


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

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

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

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


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

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

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

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


#include <stdio.h>

typedef long long ll;
#define rll register ll
#define rint register int
#define rep(i,a,b) for(rint i=(a);i<(b);i++)
#define repe(i,a,b) for(rint i=(a);i<=(b);i++)
#define repr(i,a,b) for(rint i=(a)-1;(b)<=i;i--)

int writeBuffer[20];
void write(ll num) { if (num == 0) putchar('0'); else { rint size = 0; rll current; if (0 < num) current = num; else current = -num, putchar('-'); while (0 < current) writeBuffer[size++] = current%10+'0', current /= 10; while (0 < size) putchar(writeBuffer[--size]); } }
ll read() { rint sign = 1; rll num = 0; while (1) { rint ch = getchar(); if (ch == '-') { sign = -sign; continue; } if (ch <= 32) break; num = num*10+(ch-'0'); } return sign*num; }

ll target;
int ans;
void dfs(ll num, int depth) {
    if (target <= num) ans = depth;
    else {
        rint best = depth;
        for (rll temp=num;temp<target;temp*=9) best++;
        if (best < ans) {
            rint mask = 0;
            for (rll temp=num;temp;temp/=10) mask |= 1<<(temp%10);
            rep(k,2,10) if (mask&(1<<k)) {
                rll newNum = num*k;
                dfs(newNum, depth+1);
            }
        }
    }
}

int main() {
    rint n = read();
    rll x = read();
    target = 1;
    rep(i,1,n) target *= 10;

    ans = 1000;
    dfs(x, 0);

    if (ans == 1000) putchar('-'), putchar('1');
    else write(ans);
}


#define ll long long
#define min(a,b) (a < b ? a : b)
typedef struct node {
    struct node * head[10];
    short cnt; char ed;
} n;
n * mk() {
    n * temp = malloc(sizeof(n));
    for (int i = 0; i < 10; i++)
        temp->head[i] = 0;
    temp->cnt = 0, temp->ed = '0';
    return temp;
}
n * fnd (n * tr, ll v) {
    while (v) {
        if (!tr->head[v%10]) tr->head[v%10] = mk();
        tr = tr->head[v%10];
        v/=10;
    }
    if (tr->ed == '0') tr->ed = '1', tr->cnt = 100;
    return tr;
}
void del (n * tr) {
    for (int i = 0; i < 10; i++)
        if (tr->head[i]) {
            del (tr->head[i]);
            free(tr->head[i]);
        }
}
n tr;
int dfs (ll v, int s) {
    ll k = v; int len = 0;
    while (k) len++, k/=10;
    if (len == s) return 0;
    else if (len > s) return 100;
    n * chk = fnd( &tr, v ); k = v;
    if (chk->cnt != 100) return chk->cnt;
    while (k) {
        if (k%10 > 1) chk->cnt = min(chk->cnt, 1 + dfs(v * (k%10), s));
        k/=10;
    } return chk->cnt;
}
int main () {
    for (int i = 0; i < 10; i++) tr.head[i] = 0;
    int m; ll f;
    scanf("%d%lld",&m,&f);
    int ans = dfs(f,m);
    printf("%d\n",(ans == 100) ? -1 : ans);
    del(&tr);
}


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

typedef struct{
	int x, y;
} Point;

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

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

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

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

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

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


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

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

typedef struct {
	int x, y;
} point;

int main(void) {
	point a[4], b[4];
	point ac = {0}, bc = {0};
	int ra, rb;

	for (int i = 0; i < 4; i++) {
		scanf("%d%d", &a[i].x, &a[i].y);
		ac.x += a[i].x;
		ac.y += a[i].y;
	}
	ac.x /= 2;
	ac.y /= 2;
	for (int i = 0; i < 4; i++) {
		if ((ra = abs(ac.x - 2*a[i].x)) != 0) {
			break;
		}
	}

	for (int i = 0; i < 4; i++) {
		scanf("%d%d", &b[i].x, &b[i].y);
		bc.x += b[i].x;
		bc.y += b[i].y;
	}
	bc.x /= 2;
	bc.y /= 2;
	for (int i = 0; i < 4; i++) {
		if ((rb = abs(bc.x - 2*b[i].x)) != 0) {
			break;
		}
	}

	int dx = max(abs(ac.x - bc.x) - ra, 0);
	int dy = max(abs(ac.y - bc.y) - ra, 0);

	if (dx+dy <= rb) {
		puts("YES");
	} else {
		puts("NO");
	}
}


#include <stdio.h>
#define MOD 998244353

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

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

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

    scanf("%lld %lld", &size, &max);

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

    return 0;
}


#include<stdio.h>
const int m = 998244353;

int power( int x, int y ) {
	int a = 1;
	for( ; y>0; y>>=1, x=1ll*x*x %m )
		if( y&1 )
			a = 1ll*a*x %m;
	return a;
}

int fact( int n ) {
	int f = 1;
	for( int i=2; i<=n; ++i )
		f = 1ll*f*i %m;
	return f;
}

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	if( N == 2 ) { printf("0\n", M); return 0; }
	int ans = 1ll*(N-2)*power(2, N-3) %m;
	ans = 1ll*ans*fact(M) %m;
	ans = 1ll*ans*power(fact(M-N+1), m-2) %m;
	ans = 1ll*ans*power(fact(N-1), m-2) %m;
	printf("%d\n", ans);

}


#include<stdio.h>
#include<string.h>
int main(){
    char s[20];
    scanf("%s",s);
    int i,j,x=0;
    int L=strlen(s);
    for(i=0,j=L-1;i<(L/2),j>=(L/2);i++,j--){
        if(s[i]!=s[j]) x++;
    }
    if (x==1) printf("YES");
    else if(x==0 && L%2!=0)printf("YES");
    else printf("NO");

    return 0;
}


/*
 * 1.c
 *
 * Copyright 2019  <examuser@10CPU0064L>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 *
 */

#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
	char A[50];
	int flag=0,cnt;
	scanf("%s",A);
	cnt=strlen(A);
	int j=(cnt+1)/2;
	for(int i=0;i<j;i++)
	{
		if (A[i]==A[cnt-i-1])
		{flag=flag+1;}
	}
	if ((j-1)==flag)
	printf("YES");
	else if(j==flag && cnt%2!=0)
	printf("YES");
	else
	printf("NO");
	return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
    double x, y, z, n, min=1000000000, ansb;
    int i, a, b;
    scanf("%lf %lf %lf", &x, &y, &n);
    if(y<=n)
        a=(int)x, b=(int)y;
    else
    {
        for(i=1; i<=n; i++)
        {
            //printf("here");
            z=(x/y)*i;
            int p=floor(z+0.499999999);
            float temp=fabs((x/y)-(p*1.00)/i);
            if(temp<min)
            {
                min=temp;
                a=p;
                b=i;
            }
        }
    }
        i=a;
        if(b<i)
            i=b;
        for(i; i>1; i--)
        {
            //printf("i=%d\n", i);
            if(a%i==0 && b%i==0)
            {
                a/=i;
                b/=i;
                i--;
            }
        }
        printf("%d/%d\n", a, b);
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define UpFor(i,From,To) for(i=From;i<To;i++)
#define DownFor(i,From,To) for(i=From;i>To;i--)
#define Opfile_in(s) freopen(s,"r",stdin)
#define Opfile_out(s) freopen(s,"w",stdout)
#define Read(T) scanf("%d\n",&T)
#define Print(T) printf("%d\n",T)
#define LL long long
#define MAXN 214748364
int X,Y,N;
void init();
void doit();

int main()
{
    //Opfile_in("CF_temp.in");
    init();
    doit();
    return 0;
}
void init()
{
    scanf("%d%d%d",&X,&Y,&N);
}
void doit()
{
    int i,ansx=100000,ansy=1,k;
    UpFor(i,1,N+1)
    {
        k=(LL)i*X/Y;
        if(fabs(i*X-k*Y)*ansy<fabs(ansy*X-ansx*Y)*i)
        {
            ansx=k;ansy=i;
        }
        k++;
        if(fabs(i*X-k*Y)*ansy<fabs(ansy*X-ansx*Y)*i)
        {
            ansx=k;ansy=i;
        }
    }
    printf("%d/%d\n",ansx,ansy);
}


#include <stdio.h>

int chk(long long n) {
    if (n <= 3) return (n > 1);
    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

void solve() {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    if (a - b == 1 && chk(b + a)) printf("YES\n");
    else printf("NO\n");
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        solve();
    }
}


#include<stdio.h>
int main ()
{
	long long int a,b,t,c,d,flag;
	scanf("%lld",&t);

	while(t--)
	{
		scanf("%lld %lld",&a,&b);
		c=a+b;
		d=a-b;
		flag=0;

		if(d==1)
		{
			for(int i=2;i<1000000;++i)
			{
				if (c%i==0 && c>i)
				{
					flag=1;
					break;
				}
				else if (i>=c)
					break;
			}

			if (flag==1)
				printf("NO\n");
			else
				printf("YES\n");
		}
		else
			printf("NO\n");
	}

	return 0;
}


/* ����ʯͷ��
[O]��A���Ӯ�Ĵ���
[] ��A����Ӯ�Ĵ���

1.ʯͷ
2.����
3.��
*/
#include<stdio.h>
int main()
{
	int n,a1,a2,a3,b1,b2,b3,maxwin1,maxwin2,maxwin3,maxwin,minwin1,minwin2,minwin3,minwin4,minwin;
	scanf("%d",&n);
	scanf("%d%d%d",&a1,&a2,&a3);
	scanf("%d%d%d",&b1,&b2,&b3);
	/**maxwin**/
	/*a1 beats b2*/
	if(a1>b2)
		maxwin1=b2;
	else
		maxwin1=a1;
	/*a2 beats b3*/
	if(a2>b3)
		maxwin2=b3;
	else
		maxwin2=a2;
	/*a3 beats b1*/
	if(a3>b1)
		maxwin3=b1;
	else
		maxwin3=a3;

	maxwin=maxwin1+maxwin2+maxwin3;

	/*minwin**/
	/*a1 cannot beat b1 b3*/
	if(a1-b1-b3<0)
		minwin1=0;
	else
		minwin1=a1-b1-b3;
	/*a2 cannot beat b1 b2*/
	if(a2-b1-b2<0)
		minwin2=0;
	else
		minwin2=a2-b1-b2;
	/*a3 cannot beat b2 b3*/
	if(a3-b2-b3<0)
		minwin3=0;
	else
		minwin3=a3-b2-b3;

	minwin=minwin1+minwin2+minwin3;
	printf("%d %d\n",minwin,maxwin);
	return 0;
}


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ll map_main()

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

#pragma endregion AVL

#pragma endregion kyopuro_templates

#pragma region vector

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

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

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

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

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

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

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

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

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

#pragma endregion vector

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

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

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

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

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

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

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

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

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

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

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


#include <stdio.h>

int Min(int a[3],int b[3]){
	int i , j = 1 , min = 0 ;
	for(i = 0 ; i < 3 ; i++){
		j++ ;
		if (j == 3) j = 0 ;
		if(a[i] > b[i] + b[j])	min += a[i] - b[i] - b[j] ;

	}
	return min ;
}

int Max(int a[3],int b[3]){
	int i , j = 0  , max = 0 ;
	for(i = 0 ; i < 3 ; i++){
		j++ ;
		if (j == 3) j = 0 ;
		if(a[i] > b[j])	max += b[j] ;
		else max += a[i];

	}
	return max ;
}

int main(){
	int n ;
	int a[3], b[3] , i;
	scanf("%d",&n);
	for(i = 0 ; i < 3 ; i++)	scanf("%d",&a[i]);
	for(i = 0 ; i < 3 ; i++)	scanf("%d",&b[i]);
	printf("%d %d",Min(a,b),Max(a,b));
}


//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.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 main(void){
  int n;
  int a1,a2,a3;
  int b1,b2,b3;
  scanf("%d",&n);
  scanf("%d%d%d",&a1,&a2,&a3);
  scanf("%d%d%d",&b1,&b2,&b3);
  int r1,r2;
  r2=min(a1,b2)+min(a2,b3)+min(a3,b1);
  int c=b1;b1=b2;b2=b3;b3=c;
  r1=max(0,a1-b2-b3)+max(0,a2-b3-b1)+max(0,a3-b1-b2);
  printf("%d %d\n",r1,r2);
  return 0;
}


#include <stdio.h>
int max(int num1, int num2);
int min(int num1, int num2);

int main()
{
    int n,a1,a2,a3,b1,b2,b3,win,lose,lost;
    scanf("%d %d %d %d %d %d %d",&n,&a1,&a2,&a3,&b1,&b2,&b3);
    win=min(a1,b2)+min(a2,b3)+min(a3,b1);
    lose=max(max(max(max(max(b1,b2),b3),a1),a2),a3);
    if ((lose==b1)||(lose==a3))
        lost=a3-(b2+b3);
    else
    if((lose==b2)||(lose==a1))
        lost=a1-(b1+b3);
    else
        lost=a2-(b1+b2);
    if(lost<0)
        lost=0;
    printf("%d %d",lost,win);
    return 0;

}
int max(int num1, int num2)
{
    return (num1 > num2 ) ? num1 : num2;
}
int min(int num1, int num2)
{
    return (num1 > num2 ) ? num2 : num1;
}


/* https://codeforces.com/contest/611/submission/19896636 (rainboy) */
#include <stdio.h>

int main() {
	long long a, b, i, j, cnt;

	scanf("%lld%lld", &a, &b);
	cnt = 0;
	for (i = 0; i <= 60; i++) {
		long long c;

		c = (1LL << i) - 1;
		for (j = 0; j < i - 1; j++) {
			long long d;

			d = c - (1LL << j);
			if (d >= a && d <= b)
				cnt++;
		}
	}
	printf("%lld\n", cnt);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
long long int funk(long long int x,long long int b){
long long int m=1;

long long int a;

for(a=1;a<=b;a++){
m=m*x;
}
return m;

}
main(){

    long long int a,b,c;
  long long  int increase;
   long long int unos,unos1;
    scanf("%lld%lld",&unos,&unos1);
  long long  int x;
   long long int counter=0;

    for(a=64;a>=1;a--){
            x=funk(2,a)-1;
            increase=1;
            for(b=1;b<a;b++)
            {

                    if( ((x-increase)>=unos) && ((x-increase) <=unos1) ){
                           counter++;
                           //printf("%lld %lld %lld\n",a,x,increase);
                    }
            increase=increase*2;
            }

    }

    printf("%lld",counter);

}


#include <stdio.h>

#define MOD 998244353LL

long long f[200001];

long long power(long long x, long long n){
    long long res;
    if(n==0){
        return 1;
    }
    if(n==1){
        return x%MOD;
    }

    res=power(x, n/2);
    res%=MOD;
    res*=res;
    res%=MOD;
    if(n & 1LL){
        res*=x;
        res%=MOD;
    }
    return res%MOD;
}

long long fibo(){
    int i;
    for(i=3; i<=200000; ++i){
        f[i]=f[i-2]+f[i-1];
        f[i]%=MOD;
    }
}

int main(void){
    long long N, res;

    scanf("%lld", &N);
    if(N==1){
        printf("%lld", power(2, MOD-2)%MOD);
        return 0;
    }
    else if(N==2){
        printf("%lld", power(4, MOD-2)%MOD);
        return 0;
    }
    f[1]=f[2]=1;
    fibo();

    res=((f[N]%MOD)*(power(power(2, N)%MOD, MOD-2)%MOD))%MOD;
    //(2*N-5)/2^N
    printf("%lld", res);

    return 0;
}

/*
x^MOD == x (mod MOD)
x^(MOD-1) == 1 (mod MOD)
x * x^(MOD-2) == 1 (mod MOD)

2*N-5 mod MOD * (2^N)^-1 mod MOD
*/


#include <stdio.h>

#define MD	998244353

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

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

int main() {
	int n, i, x, y, z;

	scanf("%d", &n);
	x = 1, y = 0, z = 1;
	for (i = 0; i < n; i++)
		z = x, x = (y + z) % MD, y = z;
	printf("%lld\n", z * power(2, MD - 1 - n) % MD);
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	int n,a,b;
	scanf("%d %d %d",&n,&b,&a);
	char s[5];
	scanf("%s",s);
	scanf("%s",s);
	int d=1;
	if(strcmp(s,"head")==0)
		d=-1;
	char m[210];
	scanf("%s",m);
	int l=strlen(m);
	int i=0;
	for(i=0;i<l;i++)
	{
//		printf("%d %d %d\n",i,a,b);
				if(b==a)
				{printf("Controller %d\n",i);return 0;
				}
		if(m[i]=='0')
		{
			int diff=b-a;
			if(diff<0)
			{
				b--;
				if(b<=0)
					b+=1;
				if(b==a)
				{printf("Controller %d\n",i);return 0;
				}
				if(d<0)
					a--;
				else
					a++;
				if(a==1||a==n)
					d=d*-1;
			}
			else
			{
				b++;
				if(b>n)
					b--;
				if(b==a)
				{	printf("Controller %d\n",i);return 0;}
				if(d<0)
					a--;
				else
					a++;
				if(a==1||a==n)
					d=d*-1;

			}
		}
		if(m[i]=='1')
		{
			if(d<0)
			{
				a--;
				b=n;
			}
			else
			{
				a++;
				b=1;
			}
			if(a==1||a==n)
				d=d*-1;
		}

	}
	printf("Stowaway\n");
	return 0;
}


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

//input definitions
#define sd(x) scanf("%d",&x);
#define slld(x) scanf("%lld",&x);
#define ss(x) scanf("%s",x);
#define sf(x) scanf("%f",&x);
#define slf(x) scanf("%lf",&x);

//output definitions
#define pd(x) printf("%d",x);
#define plld(x) printf("%lld",x);
#define ps(x) printf("%s",x);
#define pf(x) printf("%f",x);
#define plf(x) printf("%lf",x);
#define pnl printf("\n");
#define psp printf(" ");

//define datatypes
typedef long long int ll;

//loops
#define upto(x) for(;i<=x;i++)
#define fl(i,a,b,c) for(i=a;i<=b;i+=c)
#define wl(x) while(x--)

//Function to compute GCD
ll gcd(ll a,ll b){
	if(a%b == 0)
		return b;
	return gcd(b,a%b);
}

//Function initialize prime numbers
int isPrime[1000006];
int initPrime(){
	int i,j;
	for(i=2;i<1000006;i++)
		isPrime[i] = 1;
	isPrime[0] = isPrime[1] = 0;
	for(i=2;i < 1000006;i++){
		for(j=2;i*j < 1000006;j++)
			isPrime[i*j] = 0;
	}
}

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

int main(void) {
	ll n,i,j,k,l;
	slld(n)
	if(n == 1)
		pd(1)
	else if(n == 2)
		pd(2)
	else if(n == 3)
		pd(6)
	else{
		if(n&1){
			plld(n*(n-1)*(n-2))
		}
		else{
			if(n%3==0){
				plld((n-1)*(n-2)*(n-3))
			}
			else{
				plld(n*(n-1)*(n-3))
			}
		}
	}
	pnl
	return 0;
}


#include<stdio.h>
int main()
{
  long long int n,k,count=0;
  scanf("%lld %lld",&n,&k);
  long long int i,m=-1;
  for(i=1;i<=k;i++)
  {
        if(m<n%i)
            {count++;
            m=n%i;}
        else
          {printf("No");
            return 0;
          }

  }
  if(count==k)
  printf("Yes" );
  else
    printf("No");
}


#include <stdio.h>
#define ll long long
int main()
{
	ll n,k;
	scanf("%lld %lld", &n,&k);
	if(k>50){
		printf("No");
		return 0;
	}
	for(int i=1;i<=k;i++)
		for(int j=i+1;j<=k;j++){
			if(n%i==n%j){
				printf("No");
				return 0;
			}
		}
		printf("Yes");
}


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

long long int solve(int N)
{
	int i;
	long long int x;
	long long int mod = 1000000007;
	long long int f = 1;
	long long int p = 1;

	for(i=1;i<=N;i++)
	{
		f *= i;
		f %= mod;
	}

	for(i=1;i<N;i++)
	{
		p *= 2;
		p %= mod;
	}

	return (f-p+mod)%mod;
}

int main()
{
	// variable in description
	//int T;
	int N;
	// variable to support
	long long int ans;

	// variable to judge
	int i;
	int j;
	int k;

	scanf("%d",&N);

	ans = solve(N);

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

	return 0;
}


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

int main() {
	int n;
	scanf("%d", &n);
	int ans = 1;
	for( int i=1; i<=n; ++i )
		ans = 1ll*ans*i %m;
	int p2 = 1;
	for( int i=1; i<n; ++i )
		p2 = 1ll*p2*2 %m;

	printf("%d\n", (ans - p2 + m)%m );
}


#include <stdio.h>

const long long mod = 1e9 + 9;

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


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

typedef long long ll;

#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define abs(k) (((k)>0)?(k):(-(k)))
int modint(int a,int b) {return(((a)>=0)?((a)-(b)*((a)/(b))):((a)-(b)*((a)/(b)+1)));}
ll modll(ll a,ll b) {return(((a)>=0)?((a)-(b)*((a)/(b))):((a)-(b)*((a)/(b)+1)));}
#define mod(a,b) a=modint(a,b)
#define llmod(a,b) a=modll(a,b)
#define mset(a) memset(a,0,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
#define inf (1e9)
#define linf (1e18)
#define pi 3.14159265358979323846

void fileio_in_out()
{
     freopen(".in","r",stdin);
     freopen(".out","w",stdout);
}

void fileio_txt()
{
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
}

//==================================================

#define modnum (inf+9)

ll n,m,k=1,ans=1,t=2;
int i,j,l;

int main()
{
    //fileio_in_out();
    //fileio_txt();

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

    while(m>0)
      {
        if(m&1)
          k=modll(k*t,modnum);
        t=modll(t*t,modnum);
        m>>=1;
      }

    for(i=1;i<=n;i++)
      ans=modll(ans*(k-i),modnum);

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

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


#include<stdio.h>
#define h 1000000000000000009
tmp=-1;
long long bsc(long long  l, long long  r, long long m)
{
   if (r >= l)
   {
        long long  mid = l + (r - l)/2, cnt=0, i=2;
        for(i=2; ;i++){
            if(i*i*i<=mid){
                cnt+=mid/(i*i*i);
                if (cnt > m)  return bsc(l, mid-1, m);
            }
            else
                break;
        }

        if (cnt == m) {
            if(l==r){
                //printf("%lld\n",mid);
                //printf("fin %lld\n",mid);
                //printf("mm\n");
                return mid;
            }
            else{
                //printf("eq\n");
                return bsc(l, mid, m);
            }
        }
        //else if (cnt > m)  return bsc(l, mid-1, m);

        //else {
            //printf("big\n");
            return bsc(mid+1, r, m);
        //}
    }
    //printf("kk\n");
    return -1;
}

int main()
{
    long long i,j,m,ans;
    scanf("%lld",&m);
    ans=bsc(1, h, m);
    printf("%lld\n",ans);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
long long solve(long long n)
{
	long long int k=2;
	long long cnt=0;
	while(k*k*k<=n){
		cnt+=n/(k*k*k); k++;
	}
	return cnt;
}
int main(){
	long long a,b,c,d,e;
	scanf("%lld",&a);

	long long f =0; long long r = 5e15;

	while(f<r){
		long long res = solve((f+r)/2);
		if(res>=a)
			r=(f+r)/2;
		else f=(f+r)/2+1;
	}
	if(solve(r)==a){
		printf("%lld",r);
	}
	else printf("-1");

}


#include <stdio.h>

int main() {

	int vp, vd, t, f, c;
	scanf("%d%d%d%d%d", &vp, &vd, &t, &f, &c);

	if (vp > vd) {
		puts("0");
		return 0;
	}

	double tt = t;
	int cc = 0;
	while (1) {
		double t = vp*tt / (vd - vp);

		if (!(vd*t + 1e-9 < c))
			break;

		cc++;
		tt += 2*t + f;

	}

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

	return 0;
}


/* https://codeforces.com/contest/148/submission/19734187 (Dukkha) */
#include <stdio.h>

int main() {
	int vp, vd, t, f, c, v, ans;
	double x;

	scanf("%d%d%d%d%d", &vp, &vd, &t, &f, &c);
	v = vd - vp;
	if (v <= 0) {
		printf("0\n");
		return 0;
	}
	x = t * vp;
	ans = 0;
	while (x + x / v * vp < c) {
		ans++;
		x += (x / v * 2 + f) * vp;
	}
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>

#define N	100
#define C	26
#define INF	1000000000000LL

int main() {
	static long long dp[N + 1][N + 1];
	static int next[N][C];
	static char cc[N + 1];
	int n, h, i, j, c;
	long long k, x, ans;

	scanf("%d%lld", &n, &k);
	scanf("%s", cc);
	for (i = n - 1; i >= 0; i--)
		for (c = 0; c < C; c++)
			next[i][c] = cc[i] == c + 'a' ? i + 1 : i + 1 == n ? -1 : next[i + 1][c];
	dp[0][0] = 1;
	for (h = 0; h < n; h++)
		for (i = 0; i < n; i++)
			if ((x = dp[h][i]))
				for (c = 0; c < C; c++)
					if ((j = next[i][c]) != -1 && (dp[h + 1][j] += x) > INF)
						dp[h + 1][j] = INF;
	ans = 0;
	for (h = n; h >= 0; h--)
		for (i = 0; i <= n; i++) {
			x = dp[h][i];
			if (k > x) {
				ans += x * (n - h);
				k -= x;
			} else {
				ans += k * (n - h);
				k = 0;
				printf("%lld\n", ans);
				return 0;
			}
		}
	printf("-1\n");
	return 0;
}


//489nastyastudiesinformatics
#include<stdio.h>
typedef long long ll;
void swap(ll *a,ll *b)
{
  *a^=*b;
  *b^=*a;
  *a^=*b;
}
ll gcd(ll a, ll b)
{
  while(b)
  {
    a %= b;
    swap(&a,&b);
  }
  return a;
}
int main()
{
  ll l,r,x,y;
  scanf("%lld %lld %lld %lld",&l,&r,&x,&y);
  if(y%x)
  {
    printf("0\n");
    return 0;
  }
  y=y/x;
  ll i,c;
  for( i=1,c=0 ;i*i<=y;i++)
    if(y%i==0 && x*i>=l && (x*y)/i<=r && gcd(i,y/i)==1)
    //or gcd(x*i,x*(y/i))==x,then lcm will also be y(a*b=x*y)
      c += 1 + (y!=1);
  printf("%lld\n",c);
  return 0;
}


#include <stdio.h>
int gc,lm;
int check(int a, int b)  // checking gcd lcm
{
  int r,min,max;
  if (a>=b) {max=a; min=b;}
  else {max=b; min=a;}
  while (1)
  {
    r=max%min;
    if (r==0) break;
    max=min;
    min=r;
  }
  r=(a/min)*b;
  if (gc==min && lm==r) return 1;
  else return 0;
}
int main()
{
   int h,l,i,j,k=0,r,count=0;
   int ar[40000];
   scanf("%d %d %d %d",&l,&h,&gc,&lm);
   for (i=1; i*i<=lm; i++)
   {
     if (i>h) break;
     if (lm%i==0)
     {
      r=lm/i;
      if (r==i)
      {
        if (r>=l && r<=h)
        ar[++k]=r;
      }
      else
      {
        if (r>=l && r<=h) ar[++k]=r;
        if (r>=l && i<=h) ar[++k]=i;
      }
     }
   }
   for (i=1; i<=k; i++)
   {
     for (j=i; j<=k; j++)
     {
       r=check(ar[i],ar[j]);
       if (r)
       {
         if (ar[i]==ar[j]) count++;
         else count+=2;
       }
     }
   }
   printf("%d\n",count);

}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
   int a[101]={0},b[101]={0},ans[101]={0};
   int i,j,k,temp,la,lb,max;
   char t[101]={'0'};
   k=0;
   scanf("%s",t);
   max=0;
   la=strlen(t);
   for (i=la;i>=1;i--)
   {
     a[la-i+1]=t[i-1]-'0';
     if (a[la-i+1]>max) max=a[la-i+1];
   }
   scanf("%s",t);
   lb=strlen(t);
   for (i=lb;i>=1;i--)
   {
     b[lb-i+1]=t[i-1]-'0';
     if (b[lb-i+1]>max) max=b[lb-i+1];
   }
   max++;
   if (la>lb) k=la;
           else   k=lb;
    temp=0;
   for (i=1;i<=k;i++)
    {
       ans[i]=a[i]+b[i]+temp;
       temp=ans[i] / max;
       ans[i]=ans[i] % max;
    }
   if (temp!=0) {k++; ans[k]=temp;}
    printf("%d",k);
   return 0;
}


#include <stdio.h>

int par[2000];

int find(int x)
{
    if (par[x] == x) return x;

    return par[x] = find(par[x]);
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);

    if (x == y) return;

    par[x] = y;
}

int same(int x, int y)
{
    x = find(x);
    y = find(y);

    if (x == y) {
	return 1;
    } else {
	return 0;
    }
}

int main()
{
     int n, m, k, mod = 1000000007, i, j;
     long long ans = 1;
     int a[2000] = {0};

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

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

     for (i = 0; i <= n - k; i++) {
	  for (j = 0; j <= k / 2; j++) {
	       unite(i + j, i + k - j - 1);
	  }
     }

     for (i = 0; i < n; i++) a[find(i)]++;

     for (i = 0; i < n; i++) {
	  if (a[i] > 0) {
	       ans = ans * m % mod;
	  }
     }

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

     return 0;
}


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

int main(void) {
    int r, x1, y1, x2, y2, i;
    long long d2;
    scanf("%d %d %d %d %d", &r, &x1, &y1, &x2, &y2);
    d2 = (long long)abs(x1 - x2) * abs(x1 - x2) + (long long)abs(y1 -y2) * abs(y1 - y2);
    for (i = 0; (long long)2*2*r*r*i*i < d2; ++i);
    printf("%d\n", i);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    double r,x1,y1,x2,y2,ans,tot,d,l,h,m;
    int ansf;
    scanf("%lf %lf %lf %lf %lf",&r,&x1,&y1,&x2,&y2);
    tot=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    l=0;
    h=tot;
    m=(h+l)/2;
    while(1)
    {
        m=(h+l)/2;
        if(m*m>tot)
        {
            if(m*m-tot<0.00000001)
            break;
            else
            h=m;
        }
        else if(m*m<tot)
        {
            if(tot-m*m<0.00000001)
            break;
            else
            l=m;
        }
        else
        break;
    }
    tot=m;
    //printf("%lf ",tot);
    //printf("%lf ",tot);
    d=2*r;
    ans=(tot+0.99999999999*d)/d;
    //printf("%lf ",ans);
    ansf=ans;
    printf("%d",ansf);
    return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
	long long int num,coins=0,a=3;
	scanf ("%lli",&num);
	while ((num%a)==0)
	{
		a=a*3;
	}
	coins=(num/a)+1;
	printf ("%lli",coins);
	return 0;
}


#include<stdio.h>
int main()
{
	int long long p;
	scanf("%lld",&p);
	while(p%3==0)
	p/=3;

	printf("%lld",(p/3)+1);
	return 0;
}


#include <stdio.h>
long long int a[10000];
int k =0;
long long int fastexp(int x,int y)
{
	long long int ans = 1;
	while(y!=0)
	{
		int r = y&1;
		if(r==1)
			ans = ans*x;
		x = x*x;
		y = y>>1;
	}
	return ans;
}
void calc(long long int sum,int d)
{
	if(d==-1 && sum!=0)
	{
		a[k] = sum;
		k++;
		return;
	}
	else if(sum==0 && d==-1)
		return;
	long long int p = fastexp(10,d);
	if(sum==0)
	calc(sum + 0*p,d-1);
	calc(sum + 4*p,d-1);
	calc(sum + 7*p,d-1);
}

int main(void)
{
	calc(0,9);
	long long int l;
	long long int r;
	scanf("%lld %lld",&l,&r);
	int counter = 0;
	long long int ans = 0;
	while(l<=r)
	{
		if(a[counter]<=r)
		{
			if(l<=a[counter])
			{
				ans = ans + (a[counter]-l+1)*a[counter];
				l = a[counter]+1;
			}
		}
		else
		{
			if(l==r)
				ans = ans + a[counter];
			else if(l<=a[counter-1])
				ans = ans + (r-a[counter-1])*a[counter];
			else
			{
				ans = ans + (r-l+1)*a[counter];
			}
			l = r +1;
		}
		counter++;
	}
	printf("%lld\n",ans);
}


#include<stdio.h>
int main(){
    long long n;
    scanf("%lld", &n);
    printf("%lld\n", (9*n-3)<<(2*n-6));
    return 0;
}


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

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

int n, m;
long long dp[205][205][5][2];
bool visited[205][205][5][2];

long long F(int i, int c, int l, int flag){
    if (c > n) return 0;
    if (c == n) flag = 1;
    if (i == m) return flag;
    if (visited[i][c][l][flag]) return dp[i][c][l][flag];

    int j;
    long long res = 0;
    for (j = 0; j < 4; j++){
        if (j == l) res += F(i + 1, c + 1, l, flag);
        else res += F(i + 1, 1, j, flag);
    }

    visited[i][c][l][flag] = true;
    return (dp[i][c][l][flag] = res);
}

int main(){
    while (scanf("%d", &n) != EOF){
        clr(visited);
        m = (n << 1) - 2;
        long long res = F(0, 0, 4, 0);
        printf("%lld\n", res);
    }
    return 0;
}


#include <stdio.h>
long long int gcd(long long int a,long long int b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
int main(void) {
    long long int t,a,b,temp,l,g,ans=0;
    scanf("%lld %lld %lld",&t,&a,&b);
    if(a==b)
    {
        printf("1/1");
        return 0;
    }
    if(b>a)
    {
        temp=a;
        a=b;
        b=temp;
    }
    g = gcd(a,b);
    if(b/g>t/a)
    {
        if(b-1>t)
        ans=t;
        else
        ans=b-1;
        g=gcd(ans,t);
        ans=ans/g;
        t=t/g;
        printf("%lld/%lld",ans,t);
        return 0;
    }
    l = (a/g)*b;

    ans += t/l;

    ans += (t/l)*(b-1);
    //printf("%lld   ",ans);
    if(t%l<b-1)
    ans+=t%l;
    else
    ans+=b-1;
    //printf("%lld",ans);
    g=gcd(t,ans);
    t=t/g;
    ans=ans/g;
    printf("%lld/%lld",ans,t);
    return 0;
}


#include<stdio.h>
typedef long long ll;
ll gcd(ll x,ll y)
{
    if(x%y==0)
        return y;
    return gcd(y,x%y);
}
ll max(ll x,ll y)
{
    return x>y?x:y;
}
ll min(ll x,ll y)
{
    return x<y?x:y;
}
int main()
{
    ll k,t,a,b,x,y,m,l;
    scanf("%lld%lld%lld",&t,&a,&b);
    x=max(a,b);
    y=min(a,b);
    if(t<x && y==1)
    {
        printf("0/1");
        return 0;
    }
    m=gcd(x,y);
    if((((x/m)*(y/m))*m)/(x/m)==y)
    {
        k=((x/m)*(y/m))*m;
        l=t/k;
        a=y*l;
        //printf("%lld %lld %lld\n",l,t,k);
        b=t%k;
        if(b<y)
            a+=b;
        else
            a+=y-1;
        b=gcd(t,a);
        printf("%lld/%lld",a/b,t/b);
    }
    else if(t>=y)
    {
        b=gcd(t,y-1);
        printf("%lld/%lld",(y-1)/b,t/b);
    }
    else
        printf("1/1");
    return 0;
}


#include <stdio.h>
int dd,mm,yy,arr[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int yer(int d,int m,int y){
    if(m>12)
    return 0;
    if(d>arr[m])
    return 0;
    if(d==29&&m==2&&y%4!=0)return 0;
    if(18*365+d+m*30+y*365<=dd+mm*30+yy*365){
        printf("YES\n");
        return 1;}
    return 0;
}
int main (){
    int d,m,y;
    scanf("%d.%d.%d",&dd,&mm,&yy);
	 scanf("%d.%d.%d",&d,&m,&y);
    if(yer(d,m,y))
    return 0;
    if(yer(d,y,m))
    return 0;
    if(yer(y,d,m))
    return 0;
    if(yer(y,m,d))
    return 0;
    if(yer(m,y,d))
    return 0;
    if(yer(m,d,y))
    return 0;
    printf("NO\n");
}


#include <stdio.h>

int sum(long long x)
{
    int sum = 0;
    while(x > 0)
    {
        sum += x%10;
        x /= 10;
    }
    return sum;
}

int main()
{
    long long x; scanf("%lld", &x);
    long long powten = 10, tmp, max = x;
    int maxsum = sum(x);
    while(x >= powten)
    {
        tmp = x - x%powten - 1;
        int tmpsum = sum(tmp);
        if(tmpsum > maxsum)
        {
            maxsum = tmpsum;
            max = tmp;
        }
        powten *= 10;
    }
    printf("%lld\n", max);
    return 0;
}


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


#include<stdio.h>

int main()
{
    int a, b, m, ro, i=0, key, done=0, *hasher;

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

    hasher = (int*)malloc(m * sizeof(int));

    for(i=0;i<m;i++)
        hasher[i] = 0;

    while(!done)
    {
        key = (a * ro + b)%m;

        if(hasher[key] != 0)
        {
            printf("%d\n", i-hasher[key]);
            done = 1;
        }
        else
        {
            hasher[key] = i;
        }
        ro = key;
        i++;
    }
    return 0;
}


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

int main(){
	int a,b,f,k;
	scanf("%d%d%d%d",&a,&b,&f,&k);
	int s=b-f;//сколько осталось бензина когда приехали к остановке
	int ans=0;
	f=a-f;//расстояние, которое мы преодолеваем
	for(k--;k;k--)
	{
		if(s<0)//нам не хватит полного бака чтобы проехать маршрут
		{
			printf("-1");
			return 0;
		}
		if(2*f>s)//если не можем проехать туда и обратно до заправки - заправляемся
		{
			s=b;
			ans++;
		}
		s-=2*f;
		f=a-f;
	}
	if(s<0)
	{
		printf("-1");
		return 0;
	}
	if(f>s)
	{
		s=b;
		ans++;
	}
	s-=f;
	if(s<0)
	{
		printf("-1");
		return 0;
	}
	printf("%d",ans);
	return 0;
}


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

#define max(a ,b)	(a > b ? a : b)
#define min(a ,b)	(a < b ? a : b)
#define MAX 200001
/*
int a[101];
int main() {
	int n ,i ,x ,y;
	scanf("%d" ,&n);
	for(i = 0;i<n;i++){
		scanf("%d" ,&x);
		a[x]++;
	}
	int total = 0;
	for(i = 1;i<=100;i++)	if(a[i])	total++;
	if(total == 2){
		int first = 0 ,second = 0;
		for(i = 1; i<=100;i++){
			if(a[i]){
				if(first){	second = a[i];	y = i;	}
				else{ first = a[i];	x = i;	}
			}
		}
		if(first == second){	printf("YES\n%d %d" ,x ,y);	}
		else printf("NO\n");
	}else printf("NO\n");
	return 0;
}
*/
/*char s[201];
int c[26];
int main() {
	int n ,i ,j;
	scanf("%d" ,&n);
	scanf(" %s" ,s);
	int ans = 0 ,x = 0;
	i = 0;
	while(i < n) {
		if(islower(s[i])){
			if(!c[s[i]-'a']){
				x++;
				c[s[i] - 'a'] = 1;
			}
		}else{
			ans = max(ans ,x);
			x = 0;
			memset(c ,0 ,sizeof(c));
		}
		i++;
	}
	ans = max(ans ,x);
	printf("%d" ,ans);
	return 0;
}*/

int main(){
	int a ,b ,f ,k ,i;
	scanf("%d%d%d%d" ,&a ,&b ,&f ,&k);
	if(k == 1){
		if(b < f || b < a-f){	printf("-1");	return 0;	}
	}
	if(k == 2){
		if(b < f || b < 2*(a-f)){	printf("-1");	return 0;	}
	}
	if(k >= 3){
		if(b < 2*f || b < 2*(a-f)){	printf("-1");	return 0;}
	}
		int ans = 0 ,rem = b;
		for(i = 0 ; i < k ; i++){
			if(i == k-1){
				if(i%2 == 0 && rem < f){	printf("-1");	return 0;}
				if(i%2 == 1 && rem < a - f){	printf("-1");	return 0;}
				if(rem < a)	ans++;
			}else{
				if(i % 2 == 0){
					if(rem < f){
						printf("-1");	return 0;
					}
					if(rem >= 2*a - f)	rem -= a;
					else ans++ ,rem = b - (a - f);
				}else {
					if(rem < a - f){
						printf("-1");	return 0;
					}
					if(rem >= a + f)	rem -= a;
					else	ans++ ,rem = b - f;
				}
			}
		//	printf("%d " ,rem);
		}
		printf("%d" ,ans);
	return 0;
}

/*
int a[MAX] ,p[MAX] ,c[MAX];
int main() {
	int n ,i;
	scanf("%d" ,&n);
	memset(p ,-1 ,sizeof(p));
	for(i = 1 ; i <= n ; i++){
		scanf("%d" ,a+i);
		if(p[a[i]] == -1)	p[a[i]] = i;
		c[a[i]]++;
	}
	int ans = 0 , r = 0;
	for(i = 1;i<=n;i++){
		if(c[i] == 0){
			r++;
			while(r <= n && c[i] == 0) {
				if(c[a[r]] > 1){
					if(p[a[r]] == r &&  a[r] < i){
						r++;
						continue;
					}
					ans++;
					a[r] = i;
					c[i] = 1;
					c[a[r]]--;
					r--;
				}
				r++;
			}
		}
	}
	printf("%d\n" ,ans);
	for(i = 1; i <=n;i++)	printf("%d " ,a[i]);
	return 0;
}
*/


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

#define N	13

long long lucky(int b) {
	return b == 1 ? 0 : lucky(b / 2) * 10 + (b % 2 == 0 ? 4 : 7);
}

int is_lucky(int y) {
	return y == 0 ? 1 : is_lucky(y / 10) && (y % 10 == 4 || y % 10 == 7);
}

int ff[N];

void init() {
	int i, f;

	f = 1;
	for (i = 0; i < N; i++) {
		ff[i] = f;
		f *= i + 1;
	}
}

int get(int n, int k, int i) {
	static char used[N];
	int h, j;

	memset(used, 0, n * sizeof *used);
	for (h = 0; h < n; h++) {
		int f = ff[n - 1 - h], s = k / f;

		for (j = 0; j < n; j++)
			if (!used[j] && s-- == 0) {
				if (h == i)
					return j;
				used[j] = 1;
				break;
			}
		k %= f;
	}
	return -1;
}

int main() {
	int n, n_, k, b, ans;
	long long f;

	init();
	scanf("%d%d", &n, &k);
	f = 1;
	n_ = 1;
	while (f < k)
		f *= ++n_;
	if (n_ > n) {
		printf("-1\n");
		return 0;
	}
	ans = 0;
	for (b = 2; ; b++) {
		long long x = lucky(b);
		int y;

		if (x > n)
			break;
		if (x <= n - n_) {
			ans++;
			continue;
		}
		y = n - n_ + get(n_, k - 1, x - (n - n_) - 1) + 1;
		if (is_lucky(y))
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}


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

int l = 1, r, answ, t = 1;
long long a[11];
long long ans[2048];
int b[13], use[13];
int n, m, k;

int
analyze(void)
{
    int i, nonzero = 0;
    long long tmp = 0;
    for(i = 10; i >= 0; --i){
        if(a[i] == 0 && nonzero){
            return 1;
        }
        tmp = tmp * 10 + a[i];
        if (a[i] != 0){
            nonzero = 1;
        }
    }
    if(tmp >= r){
        ans[n++] = tmp;
        return 0;
    }
    if(tmp >= l){
        ans[n++] = tmp;
    }
    return 1;
}

void
go(int i)
{
    if(!t){
        return;
    }
    if (i == -1){
        t = analyze();
        return;
    }
    a[i] = 0;
    go(i - 1);
    a[i] = 4;
    go(i - 1);
    a[i] = 7;
    go(i - 1);
}

void
gen(int n, int p, int k){
if(p > 0){
    int i, ans = 1;
    for(i = 1; i <= p - 1; ++i){
        ans *= i;
    }
    int tmp = k / ans;
    if(k % ans == 0){
        --tmp;
    }
    if (tmp >= n){
        printf("-1");
        m = -1;
        return;
    }
    for(i = 0; ; ++i){
        if(use[i] == 0){
            if(tmp > 0){
                --tmp;
            } else {
                use[i] = 1;
                b[n - p] = i;
                break;
            }
        }
    }
    gen(n, p - 1, k % ans ? k % ans : ans);
}
}

int
main(void)
{
    scanf("%d%d", &m, &k);
    r = m;
    go(10);
    answ = 0;
    int i, j, q;
    for(i = 0; ans[i] <= m - 13; ++i){
        ++answ;
    }
    gen(min(13, m), min(13, m), k);
    if(m == -1){
        return 0;
    }
    for(i = 0; i < min(13, m); ++i){
        b[i] += max(1, m - 12);
    }
    for(i = max(1, m - 12); i <= m; ++i){
        for(j = 0; j < n; ++j){
            if(ans[j] == i){
                for(q = 0; q < n; ++q){
                    if(b[i - max(1, m - 12)] == ans[q]){
                        ++ answ;
                    }
                }
            }
        }
    }
    printf("%d", answ);
    return 0;
}


#include <stdio.h>

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

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

int main(void) {
  long long n, m, x, y, a, b;
  scanf("%lld %lld %lld %lld %lld %lld", &n, &m, &x, &y, &a, &b);

  long long d = gcd(a, b);
  a /= d;
  b /= d;

  int ans[4];
  long long lo = 1, hi = n;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;

    long long lx = mid * a;
    long long ly = lx * b / a;

    long long x0 = MAX(0, x - lx);
    long long y0 = MAX(0, y - ly);

    if (x0 + lx <= n && y0 + ly <= m) {
      lo = mid + 1;
      ans[0] = x0, ans[1] = y0;
      ans[2] = x0 + lx, ans[3] = y0 + ly;
    } else {
      hi = mid - 1;
    }
  }

  int lx = ans[2] - ans[0];
  if (x >= ans[0] + (lx+1)/2) {
    int r = x - (ans[0] + (lx+1)/2);
    int w = n - ans[2];
    ans[0] += MIN(r, w);
    ans[2] += MIN(r, w);
  }

  int ly = ans[3] - ans[1];
  if (y >= ans[1] + (ly+1)/2) {
    int r = y - (ans[1] + (ly+1)/2);
    int w = m - ans[3];
    ans[1] += MIN(r, w);
    ans[3] += MIN(r, w);
  }

  for (int i = 0; i < 4; i++) {
    printf("%i ", ans[i]);
  }
  puts("");

  return 0;
}


#include<stdio.h>
#define min(a,b) a<b?a:b
long long int gcd(long long int a, long long int b)
{
    if(b==0)
	return a;
    else
	return gcd(b,a%b);
}
int main()
{
    long long int n,m,x,y,a,b,x1,y1,x2,y2;
    scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x,&y,&a,&b);
    long long int wi,br,gc=gcd(a,b);
    a=a/gc;
    b=b/gc;
    long long int p=min((n/a),(m/b));
    wi=a*p;
    br=b*p;
    if(wi%2==0)
    {
	if(x+(wi/2)<=n)
	{
	    if(x-(wi/2)>=0)
	    {
		x2=x+(wi/2);
		x1=x-(wi/2);
	    }
	    else
	    {
		x1=0;
		x2=wi;
	    }
	}
	else
	{
	    x2=n;
	    x1=n-wi;
	}
    }
    else
    {
	if(x+(wi/2)<=n)
	{
	    if(x-(wi/2)-1>=0)
	    {
		x2=x+(wi/2);
		x1=x-(wi/2)-1;
	    }
	    else
	    {
		x1=0;
		x2=wi;
	    }
	}
	else
	{
	    x2=n;
	    x1=n-wi;
	}
    }
    if(br%2==0)
    {
	if(y+(br/2)<=m)
	{
	    if(y-(br/2)>=0)
	    {
		y2=y+(br/2);
		y1=y-(br/2);
	    }
	    else
	    {
		y1=0;
		y2=br;
	    }
	}
	else
	{
	    y2=m;
	    y1=m-br;
	}
    }
    else
    {
	if(y+(br/2)<=m)
	{
	    if(y-(br/2)-1>=0)
	    {
		y2=y+(br/2);
		y1=y-(br/2)-1;
	    }
	    else
	    {
		y1=0;
		y2=br;
	    }
	}
	else
	{
	    y2=m;
	    y1=m-br;
	}
    }
    printf("%lld %lld %lld %lld\n",x1,y1,x2,y2);
    return 0;
}


#define M 1000000007
inline int p(int s, int n){int a=1;for(;n;n&1?a=1ll*a*s%M:0,s=1ll*s*s%M,n>>=1);return a;}
main(n,m){scanf("%d%d",&n,&m),++n;return!printf("%d",1ll*(n-m)*p(n,M-2)%M*p(n<<1,m)%M);}


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

int main()
{
	int n;
	scanf("%d",&n);
	char s1[n+1];
	int s[n+1];
	scanf("%s",s1);
	int length=strlen(s1),total_sum=0,sum=0,temp=0,k=0,j,flag=0;
	for(int i=0;i<length;i++){
		if(s1[i]-'0'!=0){
			s[k++]=s1[i]-'0';
		}
	}
	length=k;
	for(int i=0;i<length;i++)total_sum+=s[i];
	for(j=2;j<=length;j++){
		flag=0;
		if(total_sum%j!=0) continue;
		sum=total_sum/j;
		k=0;
		while(k<length){
			temp=0;
			while(temp<sum && k<length){
				temp+=s[k];
				k++;
			}
			if(temp!=sum){flag=1;break;}
		}
		if(!flag)break;
	}
	if(length==0) printf("YES\n");
	else if(!flag && j <=length)printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning (disable:4996)

int main() {
	int digit = 0;
	char num[100] = { 0 };
	int sum = 0;
	int flag = 0;

	scanf("%d", &digit);
	getchar();
	scanf("%s", num);

	for (int i = 0; i < strlen(num); i++) {
		sum += num[i] - '0';
	}

	if (sum == 0 && digit > 1) {
		flag = 1;
	}
	else {
		for (long long int i = 1; i < sum; i++) {
			if (sum % i == 0) {
				long long int count = 0;
				int x = 0;

				while (1) {
					count += (num[x] - '0');
					if (count <= i) {
						x++;
						flag = 1;
						if (count == i) {
							count = 0;
						}
						if (x == digit) {
							break;
						}
					}
					else {
						flag = 0;
						break;
					}
				}

				if (flag == 1) {
					break;
				}
			}
		}
	}

	if (flag == 0) {
		printf("NO\n");
	}
	else if (flag == 1) {
		printf("YES\n");
	}

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


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

#define MDI 1000000009
#define MOD(a) ((a) % MDI)
#define MOO(a) ((a) > 0 ? (a) % MDI : MDI + (a))
#define LL long long

void putlld(LL a)
{
  if(a > 9)
    putlld(a / 10);
  putchar(a % 10 + '0');
}

int nn[499999];

int main(void)
{
  int i, n;
  LL h = 0, g, t;
  scanf("%d", &n);
  t = (n >> 1) - 1;
  for(i = 0, nn[0] = 4; i < t - 1; i++)
    nn[i + 1] = MOD(nn[i] << 1);
  for(i = t - 1; i >= 0; i--){
    g = nn[i] - 3;
    h = MOD((h + 4) * g);
  }
  h = MOD(((h * h + (h << 2)) << 1) + 10);
  putlld(h);
  putchar('\n');
  return 0;
}


#include <stdio.h>

#define MD	1000000009

int main() {
	int n, l, ans, cnt, x, y, z;

	scanf("%d", &n), n /= 2;
	cnt = 2, x = 1, y = 1, z = 2;
	for (l = 2; l <= n; l++) {
		cnt = (cnt + x * 4LL) % MD;
		z = z * 2 % MD;
		y = (y + z) % MD;
		x = (long long) x * y % MD;
	}
	ans = ((long long) cnt * cnt + 1) * 2 % MD;
	printf("%d\n", ans);
	return 0;
}


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

#define M 10000

int main(void) {
	int a,b,c,ab,ac,bc,i,j,k;
	scanf("%d %d %d", &ab, &ac, &bc);
	for (i=1; i<=M; ++i) if (ab%i==0) {
		for (j=ab/i, k=1; k<=M; ++k) {
			if (i*k==ac && j*k==bc) {
				a=i; b=j; c=k;
				goto done;
			}
		}
	}
	exit(EXIT_FAILURE);
	done:
	printf("%d\n", 4*(a+b+c));
	exit(EXIT_SUCCESS);
}


#include <stdio.h>

int m[3];

void bubbleSort(int n) {
  int i, j;
  int x;
  for(i=0; i < n; i++) {
    for(j = n-1; j > i; j--) {
      if (m[j-1] > m[j]) {
        x=m[j-1];
        m[j-1]=m[j];
        m[j]=x;
        }
    }
  }
}

int sq (int a){
    int q;
    int ret;
    for (q=0; q<a; q++){
        if (q*q>=a) return q;
    }
}

int main() {
    int i=0, j=0;
    int a, b, c;
    int temp;
    int ans;
    for (i=0; i<3; i++) scanf ("%d", &m[i]);
    bubbleSort (3);
    temp=sq(m[0]);
    for (a=1; a<=temp; a++){
        if (m[0]%a==0){
            c=m[0]/a;
            if (m[1]%c == 0){
                b=m[1]/c;
                if (b*a == m[2]){
                    ans=4*(a+b+c);
                    printf ("%d\n", ans);
                    return 0;
                }
            }
            if (m[2]%c == 0){
                b=m[2]/c;
                if (b*a == m[1]){
                    ans=4*(a+b+c);
                    printf ("%d\n", ans);
                    return 0;
                }
            }
        }
    }
    return 0;
}


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

int search(int arr[], int n, int x);
void mergeSort(int arr[], int l, int r);
void merge(int arr[], int l, int m, int r);

int main(void){
	int n;
	char s[101];
	scanf("%i", &n);
	scanf("%s", s);
	n--;
	int count = 0;
	int moves = 0;
	for(int i=n/2; i>0; i--){
	    int flag = 1;
	    for(int j=i; j>=0; j--){
	        if(s[j] != s[i+j+1]){
	            flag = 0;
	            break;
	        }
	    }
	    if(flag == 1){
	        count = i;
	        break;
	    }
	}

	moves += 2;
	n++;
	moves += n-((count+2));
    printf("%i\n", moves);
}

int search(int arr[], int n, int x)
{
    int i;
    for (i = 0; i < n; i++)
        if (arr[i] == x)
            return i;
    return -1;
}

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

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

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

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

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

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

void mergeSort(int arr[], int l, int r)
{
    if (l < r) {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l + (r - l) / 2;

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

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


#include<stdio.h>
int main() {
	int i, j, k, len, flag = 0;
	char str[100];
	scanf("%d", &len);
	scanf("%s", str);
	j = k = len / 2;

	while(k > 0){
		j = k;
		i = 0;
		while(str[i] == str[j] && j > i){
			if(i + 1 == k){
				flag = 1;
				break;
			}
			i++;
			j++;
		}
		if(flag == 1)
			break;
		k--;
	}
	if(flag == 1)
		printf("%d\n", len + 1 - k);
	else
		printf("%d\n", len);
}


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

#define N	200000
#define M	200000

int main() {
	static char aa[N + 1], bb[M + 1];
	static int pp[M + 1], qq[M + 1];
	int n, m, i, i1, i2, j, max;

	scanf("%s%s", aa, bb), n = strlen(aa), m = strlen(bb);
	for (i = 0, j = 0; i <= n; i++) {
		pp[i] = j;
		if (i < n && j < m && aa[i] == bb[j])
			j++;
	}
	for (i = n, j = m - 1; i >= 0; i--) {
		if (i < n && j >= 0 && aa[i] == bb[j])
			j--;
		qq[i] = j;
	}
	max = 0;
	for (i1 = 0, i2 = 0; i1 <= n; i1++) {
		while (i2 <= n && pp[i1] > qq[i2])
			i2++;
		if (max < i2 - 1 - i1)
			max = i2 - 1 - i1;
	}
	printf("%d\n", max);
	return 0;
}


#include<math.h>
#include<stdio.h>
int h[10000001];

main()
{
    long long int i,j,k,a,n,m,sum=0,max;
    scanf("%lld %lld",&a,&n);
    for(i=1;i*i<=a+n;i++)
    {
        k=i*i;
        for(j=k;j<=a+n;j=j+k)
        {
            h[j]=k;
        }
    }
    for(i=a;i<a+n;i++)
    {
        m=i/h[i];

        //printf("%lld\n",max);
        sum+=m;
    }
    printf("%lld\n",sum);
    return 0;

}


/* https://codeforces.com/contest/1204/submission/59190157 (rainboy) */
#include <stdio.h>

int main() {
	int n, l, r;

	scanf("%d%d%d", &n, &l, &r);
	printf("%d %d\n", ((1 << l) - 1) + (n - l), ((1 << r) - 1) + ((n - r) << r - 1));
	return 0;
}


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

typedef long long ll;

#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define abs(k) (((k)>0)?(k):(-(k)))
int modint(int a,int b) {return(((a)>=0)?((a)-(b)*((a)/(b))):((a)-(b)*((a)/(b)+1)));}
ll modll(ll a,ll b) {return(((a)>=0)?((a)-(b)*((a)/(b))):((a)-(b)*((a)/(b)+1)));}
#define mod(a,b) a=modint(a,b)
#define llmod(a,b) a=modll(a,b)
#define mset(a) memset(a,0,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
#define inf (1e9)
#define linf (1e18)
#define pi 3.14159265358979323846

void fileio_in_out()
{
     freopen(".in","r",stdin);
     freopen(".out","w",stdout);
}

void fileio_txt()
{
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
}

//==================================================

#define modnum (inf+9)

int n,h,x,y,z,ww,xx,yy,zz;
int i,j,k,l;
ll dp[33][33][33][2][2],ans=0,t;

int main()
{
    //fileio_in_out();
    //fileio_txt();

    scanf("%d%d",&n,&h);

    mset(dp);
    dp[0][0][0][0][1]=1;
    for(k=0;k<n;k++)
      for(x=0;x<=h;x++)
        for(y=0;y<=h;y++)
          for(z=0;z<=h;z++)
            for(j=0;j<=1;j++)
              {
                i=k%2;
                t=dp[x][y][z][i][j];
                llmod(t,modnum);
                dp[x][y][z][i][j]=0;

                i^=1;
                xx=min(x+1,h);
                yy=min(y+1,h);
                zz=min(z+1,h);
                ww=j?1:h;

                dp[xx][yy][zz][i][j]+=t;
                dp[yy][zz][ww][i][(x<h)]+=t;
                dp[xx][zz][ww][i][(y<h)]+=t;
                dp[xx][yy][ww][i][(z<h)]+=t;
              }

    i=n%2;
    for(x=0;x<=h;x++)
      for(y=0;y<=h;y++)
        for(z=0;z<=h;z++)
          for(j=0;j<=1;j++)
            if(x<h||y<h||z<h||j)
              {
                ans+=dp[x][y][z][i][j];
                llmod(ans,modnum);
              }

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

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


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

#define ll long long
int GCD(int a,int b){int r; while(a){r=b; b=a; a=r%a;} return b;}

int main(){
  int i,j,k,l,m,n;
  int t1,t2,x1,x2,t0;
  double opt, tmp;
  int r1, r2;
  ll y1, y2, yy1, yy2;

  while(scanf("%d%d%d%d%d",&t1,&t2,&x1,&x2,&t0)==5){
    opt = 1e100;

    if(t1==t0 && t2==t0){
      printf("%d %d\n",x1,x2);
      continue;
    }
    if(t1==t0){
      printf("%d 0\n",x1);
      continue;
    }
    if(t2==t0){
      printf("0 %d\n",x2);
      continue;
    }

    y2 = 1;
    REP(y1,0,x1+1){
      while(t1*y1+t2*y2 < t0*(y1+y2)){
        y2++;
        if(y2 > x2) break;
      }
      if(y2 > x2) break;

      k = GCD(y1, y2);
      if(k>1) continue;

      tmp = (t1*y1+t2*y2) / (double)(y1+y2);
      if(opt > tmp){
        opt = tmp;

        k = 1000000000;
        if(y1 && k > x1 / y1) k = x1 / y1;
        if(y2 && k > x2 / y2) k = x2 / y2;

        r1 = y1 * k;
        r2 = y2 * k;
      }
    }

    printf("%d %d\n",r1,r2);
  }

  return 0;
}


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

#define N	200000
#define K	447	/* K = floor(sqrt(N)) */

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

int main() {
	static int aa[N], *ii[N], kk[N], ii1[N + 1], ii2[K + 2], ll[N], ll_[N];
	int n, i, k, a, a_, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]), aa[i]--;
		kk[aa[i]]++;
	}
	for (a = 0; a < n; a++)
		ii[a] = (int *) malloc(kk[a] * sizeof *ii[a]), kk[a] = 0;
	memset(ii1, -1, (K + 2) * sizeof *ii1), memset(ii2, -1, (K + 2) * sizeof *ii2);
	ans = 0, a_ = -1;
	for (i = 0; i < n; i++) {
		a = aa[i];
		ii[a][kk[a]++] = i;
		if (a_ == -1 || kk[a_] < kk[a])
			a_ = a;
		for (k = 1; k <= kk[a] && k <= K + 1; k++)
			if (ii1[k] < ii[a][kk[a] - k])
				ii2[k] = ii1[k], ii1[k] = ii[a][kk[a] - k];
			else if (ii2[k] < ii[a][kk[a] - k])
				ii2[k] = ii[a][kk[a] - k];
		for (k = 1; k <= K; k++)
			if (ii2[k] > ii1[k + 1])
				ans = max(ans, i - ii1[k + 1]);
		ll[i] = ii1[K + 1];
	}
	for (i = 0; i < n; i++)
		ll_[i] = i + 1;
	for (a = 0; a < n; a++)
		if (a != a_ && kk[a] > K) {
			int d;

			memset(ii1, -1, (n + 1) * sizeof *ii1), ii1[0] = 0;
			d = 0;
			for (i = 0; i < n; i++) {
				if (aa[i] == a_)
					d++;
				else if (aa[i] == a)
					d--;
				if (d >= 0) {
					if (ii1[d] == -1)
						ii1[d] = i + 1;
					ll_[i] = min(ll_[i], ii1[d]);
				}
			}
		}
	for (i = n - 1; i >= 0; i--) {
		if (ll_[i] <= ll[i])
			ans = max(ans, i - ll_[i] + 1);
		if (ll_[i] == 0)
			break;
	}
	printf("%d\n", ans);
	return 0;
}


#include"stdio.h"
#include"string.h"
#include"math.h"
#include"stdlib.h"
#include"ctype.h"
#include"limits.h"
#include"time.h"

int main()
{
	clock_t lnh=clock();
	int n,m,x=1,c;
	scanf("%d%d",&n,&m);
	int a[100]={0},d[100]={0},ac[100]={0},i,j,l[m];
	for(i=0;i<m;scanf("%d",&l[i++]));

	for(i=0;i<m-1;i++)
	{
		c=l[i+1]-l[i]+n*(l[i]>=l[i+1]);
		d[c-1]=1;
		if(a[l[i]-1]!=c && a[l[i]-1])
		x=0;
		else
		a[l[i]-1]=c;
	}

	for(i=j=0;i<n;i++)
	if(!a[i])
	{
		for(;d[j] && j<n;j++);
		if(j==n)
		break;
		a[i]=++j;
	}

	for(i=0;i<n;i++)
	if(a[i])
	ac[a[i]-1]++;

	for(i=0;i<n;i++)
	if(!a[i] || ac[i]>1)
	x=0;
	if(!x)
	printf("-1");
	else
	{
		for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
		printf("%d",a[i]);
	}
	printf("\n");

	clock_t cls=clock();	//printf("%fms\n",(double)((cls-lnh)*1000)/CLOCKS_PER_SEC);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define min(a,b) (a < b ? a : b)
typedef long long ll;
ll n, m, a[1000], l[200], vis[200], vist[200];

bool solve(){
    ll i, j;
    /*
    for(i = 1; i < m; i++){
        if(l[i + 1] > l[i]){
        	if(a[l[i]] && a[l[i]] != l[i + 1] - l[i]) return false;
            if(vis[l[i]] != l[i + 1] - l[i] && vis[l[i]]) return false;
            a[l[i]] = l[i + 1] - l[i];
            vis[l[i]] = a[l[i]];// a === vis.
        }
        else if(l[i + 1] == l[i]){
        	if(a[l[i]] && a[l[i]] != n) return false;
            if(vis[l[i]] && vis[l[i]] != n) return false;
            a[l[i]] = n;
            vis[l[i]] = n;
            break;
        }
        else{
        	if(a[l[i]] && a[l[i]] != n - l[i] + l[i + 1]) return false;
            if(vis[l[i]] && vis[l[i]] != n - l[i] + l[i + 1]) return false;
            a[l[i]] = n - l[i] + l[i + 1];
            vis[l[i]] = a[l[i]];
        }
    }*/
    for(i = 1; i < m; i++){
    	ll tmp = l[i + 1] - l[i];
    	if(tmp <= 0) tmp += n;
     	if(vis[l[i]] != tmp && vis[l[i]]) return false;
        a[l[i]] = tmp;
        vis[l[i]] = a[l[i]];// a === vis.
    }
  //  memset(vis, 0, sizeof(vis));
  //  for(j = 1; j <= n; j++)	if(a[j]) vis[a[j]] = 1;

	//check pmt.
	//for(i = 1; i <= n; i++)
	//	for(j = 1; j <= n; j++) if(i != j && a[j] == a[i]) return false;

	ll deitian = 0;
	for(i = 1; i <= n; i++) vist[vis[i]]++;
	for(i = 1; i <= n; i++){
		if(vist[i] >= 2){
			return false;
		}
		else if(!vist[i]){
			deitian = 1;
		}
	}
	if(deitian){
		for(j = 1; j <= n; j++){
	        if(!vis[j]){
	            for(ll k = 1; k <= n; k++){
	                if(!vist[k]){
	                    a[j] = k;
	                    vist[k] = 1;
	                    break;
	                }
	            }
	        }
  		}
	}
	return true;
}

int main(void){
    ll i, j, k;
    scanf("%lld%lld", &n, &m);
    for(i = 1; i <= m ; i++) scanf("%lld", l + i);
    if (solve()) for(i = 1; i <= n; i++) printf("%lld ", a[i]);
    else puts("-1\n");
    return 0;
}

/*
#include <bits/stdc++.h>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))

typedef long long ll;
const int maxn= 105;

int a[maxn];
int ans[maxn];
int num[maxn];

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m) == 2)
    {
        mst(ans,-1);
        mst(num,0);
        mst(a,0);
        scanf("%d",&a[0]);
        int flag=0;
        for(int i=1; i<m; i++)
        {
            scanf("%d",&a[i]);
            int temp=a[i]-a[i-1];
            if(temp<=0) temp+=n;
            if(ans[a[i-1]]==-1||ans[a[i-1]]==temp)
            {
                ans[a[i-1]]=temp;
            }
            else
            {
                flag=1;
            }
        }
        if(flag==1)
        {
            puts("-1");
            continue;
        }
        for(int i=1; i<=n; i++)
        {
            if(ans[i]!=-1)
                num[ans[i]]++;
        }
        for(int i=1; i<=n; i++)
        {
            if(num[i]>1)
            {
                flag=1;
                break;
            }
            if(num[i]==0&&flag!=1)
            {
                flag=2;
            }
        }
        if(flag==1)
        {
            puts("-1");
            continue;
        }
        if(flag==2)
        {
            for(int i=1;i<=n;i++)
            {
                if(ans[i]==-1)
                {
                    for(int j=1; j<=n; j++)
                    {
                        if(num[j]==0)
                        {
                            ans[i]=j;
                            num[j]=1;
                            break;
                        }
                    }
                }
            }
        }
        for(int i=1;i<n;i++)
        {
            printf("%d ",ans[i]);
        }
        printf("%d\n",ans[n]);
    }
    return 0;
}*/


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

int check_host( char * hostname )
{
	int i = 0, len, max_len = 0, min_len = 1000;
	while( i <= strlen(hostname) )
	{
		len = 0;
		while ( hostname[i] != '.' && hostname[i] != 0 )
			len++, i++;
		if ( len > max_len ) max_len = len;
		if ( len < min_len ) min_len = len;
		i++;
	}
	if ( !min_len || max_len > 16 )
		return 1;
	else
		return 0;
}

int check_res( char * resource )
{
	int i = 0, len, max_len = 0, min_len = 1000;
	while( i <= strlen(resource) )
	{
		len = 0;
		while ( resource[i] != '/' && resource[i] != 0 )
			len++, i++;
		if ( len > max_len ) max_len = len;
		if ( len < min_len ) min_len = len;
		i++;
	}
	if ( !min_len || max_len > 16 )
		return 1;
	else
		return 0;
}

int main()
{
	char str[201], username[201], hostname[201], resource[201];
	int i, j, len;
	char res, at, point, next;
	next = at = res = point = 0;
	scanf("%s",str);
	len = strlen(str);
	for ( i = 0; i < len; i++ )
		if ( str[i] == '@' )
		{
			at = 1;
			break;
		}
	if ( !at )
	{
		printf("NO\n");
		exit(0);
	}
	j = i;
	for ( i = j + 1; i < len; i++ )
	{
		if ( str[i] == '.' )
			point = 1;
		if ( str[i] == '/' )
			res = 1;
	}
	for ( i = 0, j = 0; str[i] != '@'; i++, j++ )
		username[j] = str[i];
	username[i] = 0;
	if ( res )
	{
		for ( ++i, j = 0; str[i] != '/'; i++, j++ )
			hostname[j] = str[i];
		hostname[j] = 0;
		for ( ++i, j = 0; str[i] != 0; i++, j++ )
			resource[j] = str[i];
		resource[j] = 0;
	}
	else
	{
		for ( ++i, j = 0; str[i] != 0; i++, j++ )
			hostname[j] = str[i];
		hostname[j] = 0;
		resource[0] = 0;
	}
	for ( i = 0; i < strlen(username); i++ )
		if ( !( isalnum(username[i]) || username[i]=='_' ) )
			next = 1;
	for ( i = 0; i < strlen(hostname); i++ )
		if ( !( isalnum(hostname[i]) || hostname[i]=='_' || hostname[i]=='.' ) )
			next = 1;
	for ( i = 0; i < strlen(resource); i++ )
		if ( !( isalnum(resource[i]) || resource[i]=='_' || resource[i]=='/' ) )
			next = 1;
	if ( strlen(username) > 16 || strlen(username) == 0 )
		next = 1;
	if ( strlen(hostname) > 32 || strlen(hostname) == 0 || check_host( hostname ) )
		next = 1;
	if ( res && check_res( resource ) )
		next = 1;
	( next ) ? printf("NO\n") : printf("YES\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#define mod 1000000007

#ifdef __cplusplus
extern "C" {
#endif
__attribute__((always_inline, optimize(3)))
__inline__ void add(int *x, int y) {
	(*x += y) >= mod && (*x -= mod);
}
__attribute__((always_inline, optimize(3)))
__inline__ int mul(int x, int y) {
	return (long long)x * y - (long long)x * y / mod * mod;
}
__attribute__((always_inline, optimize(3)))
__inline__ int f(int n, int x, int y) {
	int tmp = 1 << x;
	y && (tmp *= 3);
	return n / tmp;
}
#ifdef __cplusplus
}
#endif
int main() {
	int n, p = 0; scanf("%d", &n);
	static int dp[1000005][21][2] = { };
	while ((1 << p) <= n) ++ p; dp[1][-- p][0] = 1;
	if ((3 << p - 1) <= n) dp[1][p - 1][1] = 1;
	for (int i = 1; i < n; ++ i)
		for (int x = 0; x <= p; ++ x)
			for (int y = 0; y < 2; ++ y) {
				add(dp[i + 1][x] + y, mul(dp[i][x][y], f(n, x, y) - i));
				x && (add(dp[i + 1][x - 1] + y, mul(dp[i][x][y], f(n, x - 1, y) - f(n, x, y))), 0);
				y && (add(dp[i + 1][x] + y - 1, mul(dp[i][x][y], f(n, x, y - 1) - f(n, x, y))), 0);
			}
	printf("%d\n", dp[n][0][0]);
	return 0;
}


#include<stdio.h>
typedef unsigned int u_int;
int main(void){
  u_int m,n,a,b,a_pos,b_pos,a_line,b_line,k;
  scanf("%u %u %u %u",&m,&n,&a,&b);
  a_pos=(a-1)%n+1;
  b_pos=(b-1)%n+1;
  a_line=(a-1)/n;
  b_line=(b-1)/n;
  if(b==m) b_pos=n;
  if(a_line==b_line){
    k=1;
  }else if(a_pos==1 && b_pos==n){
    k=1;
  }else if(a_pos==1 || b_pos==n){
    k=2;
  }else if(b_pos+1==a_pos){
    k=2;
  }else if(a_line+1==b_line){
    k=2;
  }else{
    k=3;
  }
  printf("%d\n",k);
  return 0;
}