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

using namespace std;

long long power(int a, int b);

int main(void)
{
    int *xx, *yy;
    int n, m, bx, by, i;
    long long x, y;
    x = y = 0;
    scanf("%d %d", &n, &bx);
    xx = (int *)malloc(n*sizeof(int));
    for (i = n-1; i>-1; i--) scanf("%d", &xx[i]);
    scanf("%d %d", &m, &by);
    for (i = 0; i<n; i++) x += xx[i]*power(bx, i);
    yy = (int *)malloc(m*sizeof(int));
    for (i = m-1; i>-1; i--) scanf("%d", &yy[i]);
    for (i = 0; i<m; i++) y += yy[i]*power(by, i);
    if (x<y) {printf("<"); return 0;}
    if (x>y) {printf(">"); return 0;}
    if (x==y) {printf("="); return 0;}
}

long long power(int a, int b)
{
    int i;
    long long p;
    for (p = 1, i = 1; i<=b; i++)
        p *= a;
    return p;
}


#include<stdio.h>
int main()
{
    unsigned long long p,y,sign=1,Y,k,i;
    scanf("%llu%llu",&p,&y);
    unsigned long long count[y+1];
    for(i=0;i<y+1;i++)
    {
        count[i]=0;
    }
    k=y;
    for(;;)
    {
    for(i=2;i*i<=y&&i<=p;i++)
    {
    sign=0;
        if(y%i==0){
                count[y]++;
                y--;
                sign=1;
                i=1;
                }
        }
        if(sign==0)break;
        else if(sign=1){break;}
    }
        if(sign==1)printf("-1\n");
        else printf("%llu\n",y);
}


#include<stdio.h>

#define DEBUG 0

int main() {

    long long int n, a, b, p, q;
    long long int red, blue, choc, i;
    long long int rA, rB;

    scanf("%lld %lld %lld %lld %lld\n", &n, &a, &b, &p, &q);

    red = 0;
    blue = 0;
    for(i = 1; i <= n; i++) {
        rA = i % a;
        rB = i % b;

        if(DEBUG) printf("i %lld, rA %lld, rB %lld\n", i, rA, rB);

        if(rA == 0 && rB == 0) {
            if(p >= q) {
                red++;
                if(DEBUG) printf("red %lld\n", red);
            } else {
                blue++;
                if(DEBUG) printf("blue %lld\n", blue);
            }

        } else if(rA == 0) {
            red++;
            if(DEBUG) printf("red2 %lld\n", red);
        } else if(rB == 0) {
            blue++;
            if(DEBUG) printf("blue2 %lld\n", blue);
        }
    }

    choc = (red * p);
    if(DEBUG) printf("red * p %lld\n", choc);
    choc = choc + (blue * q);
    printf("%lld\n", choc);

    return 0;
}


#include<stdio.h>
int main ()
{
    int n,r=0,i;
    scanf("%d",&n);
    int f=1,flag=0;
    r=r+f;
    while (1)
    {
        if(r==n){
            flag=0;
            break;
        }
        else if(r>n)
        {
            flag=1;
            break;
        }
        f++;
    }

    if(flag==0)
        printf("YES");
    else if(flag==1)
        printf("NO");

        return 0;

}


#include<stdio.h>

int main()

{
	int a,b,c,d;
	scanf("%d%d",&a,&b);

	scanf("%d%d",&c,&d);

	float h;int s;
	if(c*8>=(b-a))
		printf("0");

	else if(c*8<(b-a) && c>=d)
	{
		h = (b-a-8*c)/(double)((c-d)*12);
		s = (b-a-8*c)/((c-d)*12);

		if(h>s)
			printf("%d\n",s+1);

		else if(h==s)
			printf("%d",s);
	}

	else if(c<d)
		printf("-1");
	return 0;
}


#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <float.h>
#include <limits.h>
#include <malloc.h>
#include <memory.h>
#include <complex.h>
#include <errno.h>
#include <time.h>
char s[5][105];
int xx[4][3]={{0,1,1},{0,1,1},{0,0,1},{0,0,1}},yy[4][3]={{0,0,1},{1,0,1},{0,1,1},{0,1,0}},
	i,j,a[5][105],l,ans;

void dfs(int x,int y)
{
	int i,j,f;

	if (y+(l-x)/2<=ans) return;
	if (x>=l)
	{
		ans=y>ans ? y : ans;
		return;
	}
	for (i=0;i<4;i++)
	{
		for (j=f=0;j<3;j++)
		if (a[xx[i][j]][x+yy[i][j]]||x+yy[i][j]>=l)
		{
			f=1;
			break;
		}
		if (!f)
		{
			for (j=0;j<3;j++) a[xx[i][j]][x+yy[i][j]]=1;
			dfs(x+1,y+1);
			for (j=0;j<3;j++) a[xx[i][j]][x+yy[i][j]]=0;
		}
	}
	dfs(x+1,y);
}

int main()
{
	scanf("%s%s",s[0],s[1]);
	l=strlen(s[0]);
	for (j=ans=0;j<2;j++)
	for (i=0;i<l;i++)
	if (s[j][i]=='0') a[j][i]=0; else a[j][i]=1;
	dfs(0,0);
	printf("%d\n",ans);
	return 0;
}


#include<stdio.h>
int main()

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

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

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

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

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

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

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

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

}


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

}


#include <stdio.h>
#include <string.h>
#define M 1000000009

typedef long long LL;
int n,m,sz,son[110][4],fail[110],term[110],par[110],l[110];
LL f[1010][110][20];
void init(int u,int d);
LL dp(int i,int u,int o);

int main(void)
{
    //freopen("gene.in","r",stdin);
    //freopen("gene.out","w",stdout);
    scanf("%d%d",&n,&m);
    memset(son,0,sizeof(son));
    memset(term,0,sizeof(term));
    sz=1;  l[1]=0;
    int i,j,u,t;
    char str[20];
    for(i=1;i<=m;i++)
    {
        scanf("%s",str);
        for(u=1,j=0;str[j];j++)
        {
            if(str[j]=='A') t=0;
            else if(str[j]=='C') t=1;
            else if(str[j]=='G') t=2;
            else t=3;
            if(!son[u][t])
            {
                l[++sz]=l[u]+1;
                son[u][t]=sz;
            }
            par[son[u][t]]=u;
            u=son[u][t];
        }
        term[u]=1;
    }
    memset(fail,-1,sizeof(fail));
    fail[1]=0;
    for(i=0;i<4;i++)
        fail[son[1][i]]=1;
    init(1,-1);
    memset(f,-1,sizeof(f));
    printf("%I64d\n",dp(0,1,0));
    return 0;
}

void init(int u,int d)
{
    int i,v;
    if(fail[u]<0)
        for( fail[u]=1,v=fail[par[u]] ; v ; v=fail[v] )
            if(son[v][d])
            {
                fail[u]=son[v][d];
                break;
            }
    for(i=0;i<4;i++)
        if(son[u][i])
            init(son[u][i],i);
}

LL dp(int i,int u,int o)
{
    if(f[i][u][o]>=0) return f[i][u][o];
    else if(i==n)
        return f[i][u][o] = o ? 0 : 1;
    f[i][u][o]=0;
    int j,v,w,t;
    for(j=0;j<4;j++)
    {
        for( w=0,v=u ; v&&l[v]>=o ; v=fail[v] )
            if(son[v][j])
            {
                w=son[v][j];
                break;
            }
        if(w)
        {
            for(t=w;l[t]>=o+1;t=fail[t])
                if(term[t]) break;
            f[i][u][o] = ( f[i][u][o] + dp(i+1,w,l[t]<o+1 ? o+1 : 0) )%M;
        }
    }
    return f[i][u][o];
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int valid(char c){
    if((c>='A' && c<='z')|| (c>='0'&&c<='9') || c=='_') return 1;
    return 0;
}
void no(){
    printf("NO\n");
    exit(0);
}
int main()
{
    //freopen("in.txt", "r", stdin);
    char id[110];
    fgets(id,110, stdin);

    char *user, *host, *res;

    if(id[0]=='@') no();

    user = strtok(id, "@");
    host = strtok(NULL, "/");
    if(host==NULL) {
        host=strtok(NULL, "\n");
        res=NULL;
    }
    else {
        res = strtok(NULL, "\n");
    }

    //printf("%s %s %s\n", user, host, res);

    if(user==NULL || host==NULL) no();
    if(strlen(user)>16 || strlen(host)>32) no();

    int i;

    if(user){
        for(i=0; user[i]!='\0'; i++){
            if(!valid(user[i])) no();
        }
    }
    int word=0;
    if(host){
        for(i=0; host[i]!='\0'; i++){
            if(valid(host[i])) word++;
            else if(host[i]=='.'){
                if(word<1 || word>16) no();
                word=0;
            }
            else{
                if(host[i]!='\n') no();
            }
        }
    }
    if(word==0) no();

    if(res){
        for(i=0; res[i]!='\0'; i++) {
            if(!valid(res[i])) no();
        }
    }
    //printf("%s %s %s\n", user, host, res);
    printf("YES\n");
    return 0;
}


#include <stdio.h>
#define ulli unsigned long long int

ulli factorial(int n){
  if(n==1) return 1;
  else return factorial(n-1)*n;
}

int main(){
  int n;
  scanf("%d", &n);
  int k = n/2;
  ulli ans;
  ans = factorial(n) / factorial(n-k);
  ans = ans * factorial(k-1)/(2*k);
  printf("%lld\n",ans);
  return 0;
}


#include<stdio.h>
long long int factorial(int n) ;

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

    while(t--)
    {
        int n;
        long long int sum, power;
        scanf("%d", &n);
        power = (factorial((n/2)-1) * factorial((n/2)-1));
        sum = ((factorial(n)/((factorial(n/2)) * factorial(n/2))/2) * power);

        printf("%lld", sum);
    }

    return 0;
}

long long int factorial(int n)
{
    if (n == 1 || n == 0)
        return 1;
    return n * factorial(n - 1);
}


#include <stdio.h>

#define MD	1000000007

int power(int n, int k) {
	int p;

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

int main() {
	int n, m, k, sum, x;

	scanf("%d%d", &n, &m);
	sum = 0;
	for (k = 0; k < n; k++) {
		x = power(m + m - 1, k); /* Binomial theorem */
		sum = (sum + x * m % MD * power(m, n - 1 - k)) % MD;
	}
	printf("%d\n", (sum + power(m, n)) % MD);
	return 0;
}


#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int n,m;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    n=max(a*3/10,(a-a*1.00/250*c));
    m=max(b*3/10,(b-b*1.00/250*d));
    if(n>m) printf("Misha\n");
    else if(n==m) printf("Tie\n");
    else printf("Vasya\n");
    return 0;
}


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

                    if(a[i]+b[j]==n) count++;
                    else continue;
                }
            }
        }
        else
        {
            for(int i=0;i<=g;i++)
            {
                for(int j=0;j<=b1;j++)
                {

                    if(b[i]+a[j]==n) count++;
                    else continue;
                }
            }
        }

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


#include<stdio.h>

int bigger(int n1, int n2);

int main(){
	int b, g, n;

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

	if(b >= n && g >= n) printf("%d", n + 1);
	else if(b >= n && g < n) printf("%d", 1 + g);
	else if(b < n && g >= n) printf("%d", 1 + b);
	else if(b + g > n) printf("%d",  (g + b - bigger(a, b)) - (n - bigger(g, b)) + 1 );
	else printf("1");

	return 0;
}

int bigger(int n1, int n2){
    return (-(n1 >= n2) & n1) + (-(n1 < n2) & n2);
}


#include <stdio.h>
int main(void) {
    int l, r, s, p;
    bool res = false;
    for(int i = 0; i < 4; i++) {
        scanf("%d%d%d%d", &l, &r, &s, &p);
        if(p == 0) continue;
        else if(l | r | s == 1) res = true;
    }
    puts(res ? "YES" : "NO");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Written by Nishant Mittal aka nishantwrp */
int chordtoindex(char *a) {
if (*a == 'C') {
    a++;
    if (*a == '#') {
        return 2;
    } else {
    return 1;
    }
}
if (*a == 'D') {
    a++;
    if (*a == '#') {
     return 4;
    } else {
    return 3;
    }
}
if (*a == 'E') {
    return 5;
}
if (*a == 'F') {
    a++;
    if (*a == '#') {
     return 7;
    } else {
    return 6;
    }
}
if (*a == 'G') {
    a++;
    if (*a == '#') {
     return 9;
    } else {
    return 8;
    }
}
if (*a == 'A') {
    return 10;
}
if (*a == 'B') {
    return 11;
}
if (*a == 'H') {
    return 12;
}
return 0;
}
int distancefind(int a,int b) {
int count = 0;
int i = b;
while (i != a) {
    count++;
    if (i == 12) {
        i = 1;
    } else {
    i++;
    }
}
return count;
}
int main()
{
char chord1[3],chord2[3],chord3[3];
int pos1,pos2,pos3;
int i=0;
while(i<3) {
char tmp;
scanf("%c",&tmp);
if (tmp == ' ') {
    break;
}else {
chord1[i] = tmp;
}
i++;
}
int j=0;
while(j<3) {
char tmp;
scanf("%c",&tmp);
if (tmp == ' ') {
    break;
}else {
chord2[j] = tmp;
}
j++;
}
int k=0;
while(k<3) {
char tmp;
scanf("%c",&tmp);
if (tmp == '\n') {
    break;
}else {
chord3[k] = tmp;
}
k++;
}
int ansset = 0;
pos1 = chordtoindex(chord1);
pos2 = chordtoindex(chord2);
pos3 = chordtoindex(chord3);
//Minor
if (distancefind(pos2,pos1) == 3 && distancefind(pos3,pos2) == 4) {
    ansset = 1;
printf("minor");
}else if (distancefind(pos2,pos3) == 3 && distancefind(pos1,pos2) == 4) {
     ansset = 1;
printf("minor");
}else if (distancefind(pos1,pos2) == 3 && distancefind(pos3,pos1) == 4) {
     ansset = 1;
printf("minor");
}else if (distancefind(pos1,pos3) == 3 && distancefind(pos2,pos1) == 4) {
     ansset = 1;
printf("minor");
} else if (distancefind(pos3,pos1) == 3 && distancefind(pos2,pos3) == 4) {
     ansset = 1;
printf("minor");
} else if (distancefind(pos3,pos2) == 3 && distancefind(pos1,pos3) == 4) {
     ansset = 1;
printf("minor");
}//Major
if (distancefind(pos2,pos1) == 4 && distancefind(pos3,pos2) == 3) {
     ansset = 1;
printf("major");
}else if (distancefind(pos2,pos3) == 4 && distancefind(pos1,pos2) == 3) {
     ansset = 1;
printf("major");
}else if (distancefind(pos1,pos2) == 4 && distancefind(pos3,pos1) == 3) {
     ansset = 1;

}else if (distancefind(pos1,pos3) == 4 && distancefind(pos2,pos1) == 3) {
     ansset = 1;
printf("major");
}else if (distancefind(pos3,pos1) == 4 && distancefind(pos2,pos3) == 3) {
     ansset = 1;
printf("major");
}else if (distancefind(pos3,pos2) == 4 && distancefind(pos1,pos3) == 3) {
 ansset = 1;
printf("major");
}
if (ansset != 1) {
    printf("strange");
}
    return 0;
}


#include<stdio.h>
int main()
{
    long long int c,n,j=0;
    scanf("%lld",&n);
    for(c=2520;c<=n;c+=2520)
    {
        j++;
    }
    printf("%lld",j);
}


#include<stdio.h>

int main() {
      int b,g,n,ans=0;
	scanf("%d%d%d",&b,&g,&n);
	for (int i=0;i<=b;i++) {
	      j=n-i;

	      ans+=(j>=0 && j<=g);
	}
	printf("%d\n",ans);
}


#include<stdio.h>

int main()
{
   int n,b,g;
   int small;

   scanf("%d\n",&b);
   scanf("%d\n",&g);
   scanf("%d",&n);

   if (b>g)
   {
         big = b;
   		small = g;
   } else {
         big = g;
   		small = b;
   }

   if (small > n)
   {
   		printf("%d\n",n+1 );
   } else if (big > n)
   {
      printf("%d\n",small + 1 );
   }else{
      printf("%d\n", big + 1);
   }

   return 0;
}


#include <stdio.h>
int main(){
	int n;
	int arr[100];
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	printf("%d",arr[n-2]);
}


#include <stdio.h>
#include <stdlib.h>
int compare(const void *data1,const void *data2){
	int *ptr1 = (int *)data1;
	int *ptr2 = (int *)data2;
	return (data1 < data2)? 1 : -1;
}
int main(){
	int n;
	int arr[100];
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	qsort(arr,n,sizeof(int),compare);
	int flag = 0;
	for(int i = 0;i<n && flag == 0;i++){
		if(arr[i] %2 == 0){
			int fuck = arr[i];
			flag == 1;
		}
	}
	printf("%d\n",fuck);
}


#include<stdio.h>

int main()
{
  char s[]={'^','>','v','<'},c,t;
  int n,p,q;
  scanf("%c %c %d",&c,&t,&n);
  n%=4;
  if(n==2 || n==0)
    return printf("undefined"),0;
  for(int i=0;i<4;i++)
    if(s[i]==c)
      p=i;
    else if(s[i]==t)
      q=i;
  if((p+n)%4==q)
    printf("cw");return 0;
  else printf("ccw");
  return 0;
}


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

int main()
{
    char str[4], str1[10];
    gets(str);
    gets(str1);
    int a=0,i,s;
    for(i=0; str1[i]!='\0'; i++)
    {
        a = (a*10) + (int(str1[i])-48);
    }
    s=a%4;

    if(str[0]=='<')
    {
        if(str[2]=='^')
        {
            if(s==1)
                printf("cw\n");
            else if(s==3)
                printf("ccw\n");
            else
                printf("undefined\n");
        }
        else if(str[2]=='>')
        {
            printf("undefined\n");
        }
        else if(str[2]=='v')
        {
            if(s==1)
                printf("ccw\n");
            else if(s==3)
                printf("cw\n");
            else
                printf("undefined\n");
        }
        else if(str[2]=='<')
        {
            printf("undefined\n");
        }
    }

    else if(str[0]=='^')
    {
        if(str[2]=='>')
        {
            if(s==1)
                printf("cw\n");
            else if(s==3)
                printf("ccw\n");
            else
                printf("undefined\n");
        }
        else if(str[2]=='v')
        {
            printf("undefined\n");
        }
        else if(str[2]=='<')
        {
            if(s==1)
                printf("ccw\n");
            else if(s==3)
                printf("cw\n");
            else
                printf("undefined\n");
        }
        else if(str[2]=='^')
        {
            printf("undefined\n");
        }
    }

    else if(str[0]=='>')
    {
        if(str[2]=='v')
        {
            if(s==1)
                printf("cw\n");
            else if(s==3)
                printf("ccw\n");
            else
                printf("undefined\n");
        }
        else if(str[2]=='<')
        {
            printf("undefined\n");
        }
        else if(str[2]=='^')
        {
            if(s==1)
                printf("ccw\n");
            else if(s==3)
                printf("cw\n");
            else
                printf("undefined\n");
        }
        else if(str[2]=='>')
        {
            printf("undefined\n");
        }
    }

    else if(str[0]=='v')
    {
        if(str[2]=='<')
        {
            if(s==1)
                printf("cw\n");
            else if(s==3)
                printf("ccw\n");
            else
                printf("undefined\n");
        }
        else if(str[2]=='^')
        {
            printf("undefined\n");
        }
        else if(str[2]=='>')
        {
            if(s==1)
                printf("ccw\n");
            else if(s==3)
                printf("cw\n");
            else
                printf("undefined\n");
        }
        else if(str[2]=='v')
        {
            printf("undefined\n");
        }
    }
    return 0;
}


#include<stdlib.h>
main()
{
    int i=1,j,k=1;
    char s[100],a[26];
    scanf("%s",&s);
    while(s[i]!='\0')
    {
        for(j=0;j<k;j++)
        {
            if(a[j]!=s[i])
            {
                a[k]=s[i];
                k+=1;
            }
        }
    }
    if(k%2==0) printf("CHAT WITH HER!");
    else printf("IGNORE HIM!");
}


#include<stdio.h>
int main()
{
    long long n,a;
    scanf("%lld %lld",&n,&a);
    if(n%2!=0 ||n<a)
    break;
    else{
        printf("%lld\n",n-a);
    }
    return 0;
}


#include<stdio.h>
int main()
{
	long long int l1,r1,l2,r2,k;
	long int count=0;
	scanf("%lld%lld%lld%lld%lld",&l1,&r1,&l2,&r2,&k);
	if(l1==r1)
	{ count++;
	  printf("%ld",count);
	  return 0;
	}
	for( ;l2<=r1;l2++)
	{ if(l2!=k)
	  count++;
	}
	printf("%ld",count);
	return 0;
}


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

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

char t[10];
char s[300];

int num_need[256];
int num_have[256];

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

int main() {
    int i;

    scanf("%s %s", t, s);
    for (i = 0; t[i]; i++) num_need[t[i]]++;
    for (i = 0; s[i]; i++) num_have[s[i]]++;

    num_need['6'] += num_need['9'];
    num_need['9'] = 0;
    num_need['2'] += num_need['5'];
    num_need['5'] = 0;

    num_have['6'] += num_have['9'];
    num_have['9'] = 0;
    num_have['2'] += num_have['5'];
    num_have['5'] = 0;

    int res = 2000000000;

    for (i = 0; i < 256; i++)
        if (num_need[i])
            res = min(res, num_have[i] / num_need[i]), D("%c\n", i);

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

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int num[105];
int cmp(const void *a, const void *b)
{
	return *(int *)a-*(int *)b;
}
int main(void)
{
	int n, sum, temp, i;
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;i++){
			scanf("%d",&num[i]);
		}
		qsort(num,n,sizeof(num[0]),cmp);
		temp=num[0];
		for(i=1;i<n;i++){
			if(num[i]-num[i-1]<temp){
				temp=num[i]-num[i-1];
			}
		}
		sum=0;
		for(i=0;i<n;i++){
			if(num[i]%temp==0){
				sum+=temp;
			}
			else{
				sum+=num[i]%temp;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}


#include <iostream>
#include <math>

using namespace std;

int main()
{
	int n,x,y;
	int people_required = 0;
	int result = 0;
	cin>>n;
	cin>>x;
	cin>>y;
	double fraction = (y/100.0);
	fraction *=n;
	people_required = ceil(fraction);
	result = people_required -x;
	if(result<0)
	{
		cout<<0;
	}
	else
	{
		cout<<result;
	}
	return 0;
}


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

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

    int a, b, i;
    double ratio = (double)x/y;

    double sol = 10000000;
    double dist;
    for (i=1;i<=n;i++){
        int j = roundtol(ratio * i);
        if (ratio*i - floor(ratio*i) == 0.5){
            j = (int)(ratio*i);
        }
        dist = fabs(ratio - (double)j/i);
        if (sol>dist){
            sol = dist;
            b = i;
            a = j;
        }
    }

    printf("%d/%d\n", a, b);

    return 0;
}


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

int main (void) {
	int x, y, n, a = 1, b = 1, i, j;
	scanf ("%d %d %d", &x, &y, &n);
	for (j = 1; j <= n; ++j) {
		double z = x, A[] = {floor (z / y * j), ceil (z / y * j)};
		for (i = 0; (unsigned) i < sizeof A / sizeof *A; ++i) {
			if (fabs (z/y - A[i]/j) < fabs(z/y - (double)a/b)) {
				a = A[i];
				b = j;
			}
		}
	}
	printf ("%d/%d\n", a, b);
	exit (EXIT_SUCCESS);
}


#include <stdio.h>
#include<string.h>
void rev(char str[],int n);
int main(void)
{
	// your code goes here
    int n;
    scanf("%d",&n);
    char str[11];
    scanf(" %s",str);
    for(int i=2;i<=n;i++)
    {
        if((n%i)==0)
        rev(str,i);
    }
    printf("%s",str);
	return 0;
}
void rev(char str[],int n)
{
    for(int i=0;i<n/2;i++)
    {
        char temp=str[i];
        str[i]=str[n-i-1];
        str[n-i-1]=temp;
    }
}


#include<stdio.h>
#include<stdlib.h>
void toreverse(char string [],int x)
{

	char temp[x];
	for(int i=0;i<x;i++)
	{
		temp[i]=string[i];
	}

for(int i=0;i<x;i++)
string[i]=temp[x-i-1];

}

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

	char k;
	if(n==1)
	{
		scanf("%c",&k);
		printf("%c",k);
		exit(0);
		}

	scanf("%s",arr);
	int arr2[n/2];int c=1;
	for(int o=o;o<n/2;o++)
	arr2[o]=0;
	arr2[0]=1;

	for(int i=2;i<(n/2)+1;i++)
	{
		if(n%i==0)
		{
			arr2[c]=i;
			c+=1;
		}

	}
	arr2[c+1]=n;
	for(int i=0;i<c+2;i++)
	{

		if(arr2[i]!=0)
		toreverse(arr,arr2[i]);
		else break;

	}
	toreverse(arr,n);
	printf("%s",arr);

}


#include<stdio.h>
#include<ctype.h>
int main()
{
       int i;
       char str[1000];
       scanf("%s",str);
       for(i=0;str[i]!='\0';i++)
       {
            strcpy(str[i],tolower(str[i]));
       }
       for(i=0;str[i]!='\0';i++)
       {
            if(str[i]!='a' && str[i]!='e' && str[i]!='i' && str[i]!='o' &&str[i]!='e' && str[i]!='y')
             {
                     printf("%c",str[i]);
                     printf(".");
             }
        }
        return 0;
}


#include <stdio.h>
/* Written by Nishant Mittal aka nishantwrp */
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
int ans1,ans2,ans3;
int i = 1;
while(i<=a){
	if (a%i==0 && b%i==0) {
		int ax,bx,cx;
		bx = i;
		ax = a/i;
		cx = b/i;
		if (ax*cx==c){
			ans1 = ax;
			ans2= bx;
			ans3 = cx;
			break;
		}
	}
}
printf("%d",4*(ans1+ans2+ans3));
return 0;

}


#include <bits/stdc++.h>
using namespace std;
int a[105];
int main(void)
{
    int n,m,k,ans=9999999;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<=k && a[i]!=0)
             if(ans>(abs(m-i))) ans = abs(m-i);
    }

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


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

int main()
{
    int n,m,k;

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

    --m;

    int i;
    int prices[n];

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

    int j =m-1;
    int z =m+1;

    while (j>=0 || z<n)
    {
        if (j>=0 && z<n)
        {
            if (prices[j]<=k &&prices[j]!=0 && prices[z]<=k && prices[z]!=0)
            {
                if (prices[j] <= prices[z])
                    printf("%d",(m-j)*10);

                else if (prices[j] >prices[z])
                    printf("%d",(z-m)*10);

                break;

            }
            else if (prices[j]<=k &&prices[j]!=0)
            {
                printf("%d",(m-j)*10);
                break;
            }

            else if (prices[z]<=k && prices[z]!=0)
            {
                printf("%d",(z-m)*10);
                break;
            }

            j--;
            z++;
        }

        else if (z<n)
        {
            if (prices[z]<=k && prices[z]!=0)
            {
                printf("%d",(z-m)*10);
                break;
            }
            z++;
        }

        elses
        {
            if (prices[j]<=k &&prices[j]!=0)
            {
                printf("%d",(m-j)*10);
                break;
            }

            j--;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long y,sum=0,sum1=0,dis[10001],n,m,k,vill[10001],vs[10001],v[10001],s=0;
    cin>>n;
    cin>>m;
    cin>>k;
    for(int i=0;i<n;i++)
    {
        cin>>vill[i];
    }
    sum1=(m-1)*10;

    for(int j=0;j<n;j++)
    {
        if(vill[j]<k&&vill[j]>0)
        {
            v[s]=vill[j];
            vs[s]=j;
            dis[s]=sum;
            s++;
        }
        sum=sum+10;
    }
    for(int z=0;z<s;z++)
    {
        dis[z]=abs(dis[z]-sum1);
    }
    sort(dis,dis+s);
    cout<<dis[0];
    return 0;
}


#include<stdio.h>

long long m=1000000007,a,b,n,x;

long long function()
{
    if(n<=0) return x;
    function(n--);
    x = (((a*x)%m)+b)%m;
}

int main()
{
    scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
    function();
    printf("%lld\n",x);
    return 0;
}


#include <stdio.h>
# define m 1000000007
long long int power(long long int x,long long int y)
{
	if(y==0)
	return 1;
	else if(y%2==0)
	{
		long long int z;
		z=power(x,y/2)%m;
		return (z*z)%m;
	}
	else
	{
		long long int z;
		z=power(x,y/2)%m;
		return ((x%m*z%m)%m*z)%m;
	}
}
int main()
{
	long long int n,a,b,x,i,ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
	for(i=0;i<n;i++)
	{
		ans=ans+(power(a,i)%m*b%m)%m;
		ans=ans%m;
	}
	ans=ans+(power(a,n)%m*x%m)%m;
	ans=ans%m;
	printf("%lld\n",ans);
	return 0;
}


#include <stdio.h>
# define m 1000000007
long long int power(long long int x,long long int y)
{
	if(y==0)
	return 1;
	else if(y%2==0)
	{
		long long int z;
		z=power(x,y/2)%m;
		return (z*z)%m;
	}
	else
	{
		long long int z;
		z=power(x,y/2)%m;
		return ((x%m*z%m)%m*z)%m;
	}
}
int main()
{
	long long int n,a,b,x,i,ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
       if(a!=1)
{
//	for(i=0;i<n;i++)
//	{
		ans=(power(a,n)-1)%m;
		if(ans<0)
		ans=ans+m;
		ans=(ans%m*b%m)%m;
		if(ans<0)
		ans+=m;
		if(a-1>0)
		ans=((ans%m)*power(a-1,m-2)%m)%m;
		 ans=ans%m;
//	}
	ans=(ans+(power(a,n)%m*x%m)%m)%m;
	ans=ans%m;}
else
ans=((n%m*b%m)%m+x)%m
	printf("%lld\n",ans);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    long long res=1;
    scanf("%d",&n);
    if(n%2)
    {
        printf("0");
    }
    else{
        for(;n>=2;n/=2) res*=2;
        printf("%d",res);
    }
    return 0;
}


#include <stdio.h>
int main(){
    int n, max=0;
    scanf("%d", &n);
    int a[n], c[101]={0};
    for(int i = 0; i < n; i++){
        scanf("%d", a[i]);
        c[a[i]]++;
        if(max < c[a[i]])
        max=c[a[i]];
    }
    printf("%d", max);
}


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

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

}


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

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

}


#include <stdio.h>
#include <stdlib.h>
int main()
{
    char array[100];
    int i=0,t,l=0;
    for (i=0; i<100; i++)
    {
        scanf("%c",array[i]);
        if (array[i]=='\n')
            break;
            l++;
        }
    for (t=0; t<l; t++)
    {
        if (array[t]=='H' ||array[t]=='Q'||array[t]=='9')
        {
            printf("YES");
            return 0;
        }
    }
    printf("NO");

    return 0;
}


#include <stdio.h>

int SEGMENTS(int s)
{
int Total , p , quired ;
p=2;
total = 1 ;
while(1)
{
Total= Total + p/2 ;
if (s<Total)
{
    quired = p ;
    break ;
}
p = p+1 ;
}
return quired ;

}

int main()
{
int t;
scanf("%d", &t) ;
int m = SEGMENTS(t) ;
printf("%d",m);

}


#include<stdio.h>
#include<string.h>
#define max 1000000+10
int prime[max];
int meiprime[max];
int suhe(int gu)
{
	int sum=0;
	while(gu)
	{
		sum+=gu%10;
		gu=gu/10;
	}
	return sum;
}
int main()
{
	int n,l,m,i,su,b,j;
	for(i=1;i<=max;i++)
	prime[i]=1;
	for(i=2;i<=max;i++)
	{
		if(prime[i]==1)
		{
			for(j=2*i;j<=max;j+=i)
			{
				prime[j]=0;
			}
		}
	}
	prime[1]=0;
	memset(meiprime,0,sizeof(meiprime));
	for(i=1;i<=max;i++)
	{
		if(prime[i]&&prime[suhe(i)])
		meiprime[i]=meiprime[i-1]+1;
		else
		meiprime[i]=meiprime[i-1];
	}
	b=1;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d %d",&l,&m);
		printf("Case #%d: %d\n",b,meiprime[m]-meiprime[l-1]);
		b++;
	}
	return 0;
}


#include <stdio.h>

int main(){
	long long n,min,max,i;
	scanf("%lld",&n);
	min=n*2/7;
	while (i<=n){
		if((i%7)<2){
			max=min+i%7;
		}
		else {
			max=min+2;
		}
		if((i*2)%7==6){
			min++;
		}
	}
	printf("%lld %lld",min,max);
	return 0;
}


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

int n,l,r;

int check(int a ,int b)
{
  int r;

  if(l<0) l=0;

  if(a%3==0)
  {
    r = r/3 - l/3 + 1;
  }
  else r = r/3 -l/3 ;

  return r;
}

int func(int n,int rem)
{
  if(n!=1)
  {
    if(rem==0)
    func(n,0) = check(l-1,r-1) * func(n-1,2) + check(l-2,r-2) * func(n-1,1) + check(l,r) * func(n-1,0);
    if(rem==1)
    func(n,1) = check(l,r) * func(n-1,0) + check(l-1,r-1) * func(n-1,2) + check(l-2,r-2) * func(n-1,1);
    if(rem==2)
    func(n,2) = check(l-2,r-2) * func(n-1,1) + check(l,r) * func(n-1,0) + check(l-1,r-1) * func(n-1,2);
  }
  else
  {
    if(rem==1)
    return check(l-1,r-1);
    if(rem==2)
    return check(l-2,r-2);
    if(rem==0)
    return check(l,r);
  }

}

int main()
{
  //int n,l,r,i;
  scanf("%d%d%d",&n,&l,&r);

  int res = func(n,0);
  printf("%d",res);

}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define mod 1000000007
long long n,l,r,x,y,z;

/*long long check(long long a ,long long b)
{
  long long c;

  c = b/3 - (a-1)/3;

  return c;
}*/

long long func(long long n,long long rem)
{
  if(n==1)
  {
    if(rem==1)
    return y;
    if(rem==2)
    return z;
    if(rem==0)
    return x;
  }

    if(rem==0)
    return (y*func(n-1,2) + z*func(n-1,1) + x*func(n-1,0))%mod;

    else if(rem==1)
    return (y*func(n-1,0) + z*func(n-1,2) + x*func(n-1,1))%mod;

    else
    return (y*func(n-1,1) + z*func(n-1,0) + x*func(n-1,2))%mod;

  if(n==1)
  {
    if(rem==1)
    return y;
    if(rem==2)
    return z;
    if(rem==0)
    return x;
  }

}

int main()
{
  //long long n,l,r,i;
  scanf("%I64d%I64d%I64d",&n,&l,&r);
  x=r/3-(l-1)/3;
  y=(r+2)/3-(l+1)/3;
  z=(r+1)/3-(l)/3;

  long long res = func(n,0);
  printf("%I64d",res);

}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    long x,y,x1,y1,x2,y2;
    scanf("%ld%ld",&x,&y);
    if(x>0 && y>0)
    {
        printf("0 %ld %ld 0",x+y,x+y);
    }
    else if(x<0 && y>0)
    {
        printf("%ld 0 0 %ld",-(labs(x)+y),(labs(x)+y));
    }
    else if(x<0 && y<0)
    {
        printf("%ld 0 0 %ld"-(labs(x)+labs(y)),-(labs(x)+labs(y)));

    }
    else
        printf("0 %ld %ld 0",-(x+labs(y)),(x+labs(y)));
    return 0;
}


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

typedef enum ESCAPE_STAGES {
	EST_DRAGON_WAKE_UP,
	EST_DRAGON_REACH_PRINCESS,
	EST_DRAGON_BACK,
	EST_DRAGON_MAKE_CLEAN,
} EscapeStages;

int main(int argc, char **argv) {

// 	int vp = 1;     // predkosc ksiezniczki w milach na godzine
// 	int vd = 100;	// predkosc smoka w milach na godzine
// 	int t = 10;	    // czas po którym smok spostrzega ze ksiezniczka uciekla
// 	int f = 10;	    // czas spedzony w skarbcu przez smoka na uporzadkowanie
// 	int c = 1000;	// liczba mil od cave'a smoka do zamku

	int vp;
	int vd;
	int t;
	int f;
	int c;

	if( scanf("%d", &vp) == -1 ) return -1;
	if( scanf("%d", &vd) == -1 ) return -1;
	if( scanf("%d", &t) == -1 ) return -1;
	if( scanf("%d", &f) == -1 ) return -1;
	if( scanf("%d", &v) == -1 ) return -1;

	EscapeStages es = EST_DRAGON_WAKE_UP;
	double princessDistance = 0;
	double dragonDistance = 0;
	int numberOfDroppedDiamond = 0;
	int vc = (vd-vp);

	// if dragons speed is smaller or equal then princess', return 0 diamonds
	if(vc<=0) {
		printf("0\n");
		return 0;
	}

	while( princessDistance < c ) {
		switch(es) {
			case EST_DRAGON_WAKE_UP:
				princessDistance += vp*f;
				es = EST_DRAGON_REACH_PRINCESS;
				break;
			case EST_DRAGON_REACH_PRINCESS:
				princessDistance += (double)vp*(double)(princessDistance/(double)vc);
				dragonDistance = princessDistance;
				if(princessDistance<c) numberOfDroppedDiamond++;
				es = EST_DRAGON_BACK;
				break;
			case EST_DRAGON_BACK:
				princessDistance += (double)(dragonDistance/(double)vd)*(double)vp;
				dragonDistance = 0;
				es = EST_DRAGON_MAKE_CLEAN;
				break;
			case EST_DRAGON_MAKE_CLEAN:
				princessDistance += f*vp;
				es = EST_DRAGON_REACH_PRINCESS;
				break;
		};
	}

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

    return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    long long dab, dbc, area,abx,aby,bcx,bcy,axl,ayl,bxl,byl,cxl,cyl;
    int ax,ay,bx,by,cx,cy;
    scanf("%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy);
    axl=ax; bxl=bx; cxl=cx; ayl=cy; byl= by; cyl=cy;
    abx=(ax-bx);
    aby=(ay-by);
    dab=abx*abx + aby*aby;
    bcx=(bx-cx);
    bcy=(by-cy);
    dbc=bcx*bcx + bcy*bcy;
    area= axl*byl + bxl*cyl + cxl*ayl - axl*cyl - cxl*byl - bxl*ayl;
    if(dab!=dbc || area==0 || (ax==cx && ay==cy))printf("No\n");
    else printf("Yes\n");
    return 0;
}


#include<stdio.h>
#include<math.h>
main()
{
    int a,d,count=0,j;
    scanf("%d",&a);
    int s[a],c[a];
    for(int i=0;i<a;i++)
    scanf("%d",&s[i]);

    for(int i=0;i<a;i++)
    {
        for(j=i+1;j<a;j++);
        {if(s[i]>s[j])
        {
              d=s[i];
              s[i]=s[j];
              s[j]=d;
        }
        }
    }
        for(int k=1;k<a;k+2)
        {
        count+=s[k]-s[k-1];
        }

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


#include <stdio.h>

/* http://codeforces.com/contest/411/submission/25959252 (Dukkha) */

int win(int a1, int b1, int a2, int b2) {
	return a1 > b2 && b1 > a2;
}

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

	scanf("%d%d%d%d%d%d%d%d", &a1, &b1, &a2, &b2, &a3, &b3, &a4, &b4);
	if ((win(a1, b2, a3, b4) && win(a1, b2, a4, b3))
			|| (win(a2, b1, a3, b4) && win(a2, b1, a4, b3))) {
		printf("Team 1\n");
		return 0;
	}
	if ((win(a3, b4, a1, b2) || win(a4, b3, a1, b2))
			|| (win(a3, b4, a2, b1) && win(a4, b3, a2, b1))) {
		printf("Team 2\n");
		return 0;
	}
	printf("Draw\n");
	return 0;
}


#include <stdio.h>

int main()
{
    int x1, x2, y1, y2, ymove, xmove;
    long int summ=0;

    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

    if (x1>x2)
        xmove = -1;
    if (x1==x1)
        xmove = 0;
    if (x1<x2)
        xmove = 1;

    if (y1>y2)
        ymove = -1;
    if (y1==y1)
        ymove = 0;
    if (y1<y2)
        ymove = 1;

    while (x1!=x2&&y1!=y2)
    {
        x1 += xmove;
        y1 += ymove;
        summ++;
    }

    if (y1!=y2)
    {
        summ+=(y2-y1)*ymove;
    }
    if (x1!=x2)
    {
        summ+=(x2-x1)*xmove;
    }

    printf("%d", summ);

    return 0;
}


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


#include <stdio.h>
int main()
{
	while(1)
	{
	int n,i;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++)
	{
	scanf("%d",&a[i]);
     }
	i=0;
	while(i<n)
	{
		if(a[i+1]>a[i])
		{
			i++;
		}
		else
		break;

	}
	while(i<n)
	{
		if(a[i+1]==a[i])
		{
			i++;
	    }
	    else
	    break;
	}

	while(i<n)
	{
		if(a[i+1]<a[i])
		{
			i++;
		}
		else
		break;
	}
if(i==n||i==n-1||n==1)
printf("YES");
else
printf("NO");
}
}


#include<stdio.h>
int a[51],ans;
void count(int h,int n,int flag){
	if(h==0)
		return ;
	if(flag==0){
		if(n <= a[h]/2){
			ans++;
//			printf("%d ",ans);
			count(h-1,n,1);
		}
		else{
			ans = ans + a[h];
//			printf("%d ",ans);
			count(h-1,n-a[h]/2,0);
		}
	}
	else{
		if(n > a[h]/2){
			ans++;
//			printf("%d ",ans);
			count(h-1,n-a[h]/2,0);
		}
		else{
			ans = ans + a[h];
//			printf("%d ",ans);
			count(h-1,n,1);
		}
	}
	return ;
}
int main(){
	int h,i,j,k,l,n,m;
	ans=0;
	a[0] = 1;
	for(i=1;i<=50;i++)
		a[i]=a[i-1]*2;
//	for(i=0;i<10;i++)
//		printf("%d ",a[i]);
	scanf("%d%d",&h,&n);
	count(h,n,0);
	printf("%d\n",ans);
	return 0;
}


#include <stdio.h>

int check(int n)
{
	if((n / 2) % 2 == 0) return 1;
	else return 0;
}

int answer(long long num,int n,int h)
{
	int i,j,total = 0,check,temp = 1,temp1 = 0;
	for(i = h;i > 0;i--)
	{
		temp = 1;
		if(i == 1 && (n % 2) == 0)
		{
			for(j = 0;j < h - i + 1;j++) temp *= 2;
			total += temp;
			continue;
		}
		if((n % 2 == 0 && (n / 2) % 2 == 0) || (n % 2 != 0 && ((n + 1) / 2) % 2 != 0))
		{
			if(i == h)
			{
				total += 2;
				continue;
			}
			for(j = 0;j < h - i + 1;j++) temp *= 2;
			total += temp;
		}
		else
			total++;
		temp1 = n;
		n /= 2;
		if(temp1 % 2 > 0)
			n++;
	}
	return total;
}

int main()
{
	int h,n,i,total = 0;
	long long time,num = 1;
	scanf("%d%d",&h,&n);
	for(i = 0;i < h;i++)
		num *= 2;
	total += answer(num,n,h);
	printf("%d",total);
	return 0;
}


#include <stdio.h>

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

  if (w == 0) return 0;

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

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

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

  return 0;
}


#include<stdio.h>
double pri(double w,double b);
double dra(double w,double b);
int main(){
int w,b;
scanf("%d%d",&w,&b);
printf("%.9lf\n",pri((double)w,(double)b));
}

double pri(double w,double b){
if(w==0)return 0;
else if(b==0) return 1;
return (w/(w+b))+(b/(w+b))*dra(w,b-1);
}

double dra(double w,double b){
if(b==0)return 0;
else if(w==1&&b==1)return 0;
else if(b==1)return 1/(1+w);
return (b/(b+w))*( (w/(b+w-1))*pri(w-1,b-1) + ((b-1)/(b+w-1))*pri(w,b-2) );
}


#include<stdio.h>
double pri(double w,double b);
double dra(double w,double b);
int main(){
int w,b;
scanf("%d%d",&w,&b);
printf("%.9lf\n",pri((double)w,(double)b));
return 0;
}

double pri(double w,double b){
if(w==0)return 0;
else if(b==0) return 1;
return (w/(w+b))+(b/(w+b))*dra(w,b-1);
}

double dra(double w,double b){
if(b==0)return 0;
else if(w==1&&b==1)return 0;
else if(b==1)return 1/(1+w);
return (b/(b+w))*( (w/(b+w-1))*pri(w-1,b-1) + ((b-1)/(b+w-1))*pri(w,b-2) );
}


#include <stdio.h>
int main()
{
    long long int n, k, i, sasha=0, lena=0;
    scanf("%lld %lld", &n, &k);
    i=0;
    while(n>=k)
    {
        n-=k;
        if(i%2==0)
            sasha++;
        else lena++;
    i++;
    }
    if(sasha>lena) printf("YES");
    else printf("NO");
}


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

#define N	500

char *color;
int dsu[N];

int find(int x) {
	return dsu[x] < 0 ? x : (dsu[x] = find(dsu[x]));
}

void join(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)
		return;
	if (dsu[x] < dsu[y])
		dsu[y] = x;
	else if (dsu[x] > dsu[y])
		dsu[x] = y;
	else {
		dsu[x]--;
		dsu[y] = x;
	}
}

int main() {
	int i, n, m, g1, g2, gcnt1, gcnt2, yes;
	static char cnt[N];
	static int uu[N], vv[N];

	scanf("%d%d", &n, &m);
	color = calloc((n + 1), sizeof(*color));
	for (i = 0; i < m; i++) {
		scanf("%d%d", &uu[i], &vv[i]);
		uu[i]--, vv[i]--;
		cnt[uu[i]]++;
		cnt[vv[i]]++;
	}
	for (i = 0; i < n; i++) {
		color[i] = '-';
		dsu[i] = -1;
		if (cnt[i] == n - 1)
			color[i] = 'b';
		cnt[i] = 0;
	}
	for (i = 0; i < m; i++)
		if (color[uu[i]] == '-' && color[vv[i]] == '-') {
			join(uu[i], vv[i]);
			cnt[uu[i]]++;
			cnt[vv[i]]++;
		}
	g1 = g2 = -1;
	gcnt1 = gcnt2 = 0;
	yes = 1;
	for (i = 0; i < n; i++)
		if (color[i] == '-') {
			int group = find(i);

			if (g1 == -1 || g1 == group) {
				g1 = group;
				color[i] = 'a';
				gcnt1++;
			} else if (g2 == -1 || g2 == group) {
				g2 = group;
				color[i] = 'c';
				gcnt2++;
			} else {
				yes = 0;
				break;
			}
		}
	for (i = 0; i < n; i++)
		if (color[i] == '-') {
			int group = find(i);

			if (g1 == group && cnt[i] != gcnt1 - 1) {
				yes = 0;
				break;
			} else if (g2 == group && cnt[i] != gcnt2 - 1) {
				yes = 0;
				break;
			}
		}
	printf("%s\n", yes ? "Yes" : "No");
	if (yes)
		printf("%s\n", color);
	return 0;
}


#include <stdio.h>

typedef struct scan
{
	int from;
	int to;
}scan;

int graph[550][550];
int color[550];
char out[550];

int cmp(const void *a, const void *b)
{
	scan a1 = * (scan *)a;
	scan b1 = * (scan *)b;
	if(a1.from > b1.from)
	    return 1;
	else if(a1.from < b1.from)
	    return -1;
	else
	    return a1.to - b1.to;
}

int ulta(int a)
{
	if(a==1)
		return 2;
	return 1;
}

int colorable(int n)
{
	int i, j;
	for(i=1;i<=n;i++)
	{
		int k=0;
		for(j=1;j<=n;j++)
			if(graph[i][j] == 0)
				k++;

		if(color[i]==0)
		{
			if(k==n)
				color[i] = 3;
			else
				color[i] = 1;
		}

		int green = ulta(color[i]);

		for(j=1;j<=n;j++)
		{
			if(graph[i][j] > 0)
			{
				if(color[j] == 0)
					color[j] = green;
				else if(color[j] == color[i])
					return 1;
			}
		}
	}
	return(0);
}

int print(int n)
{
	int i;
	for(i=1;i<=n;i++)
	{
		if(color[i]==1)
			out[i-1] = 'a';
		if(color[i]==2)
			out[i-1] = 'c';
		if(color[i]==3)
			out[i-1] = 'b';
	}
	out[n] = '\0';
	printf("%s\n", out);
	return(0);
}

int main(void)
{
	int n,m,i,j;
	scanf("%d", &n);
	scanf("%d", &m);
	scan input[1200];
	for(i=0;i<2*m;i+=2)
	{
		scanf("%d %d", &input[i].from, &input[i].to);
		input[i+1].from = input[i].to;
		input[i+1].to = input[i].from;
	}

	qsort(input, 2*m, sizeof(scan), cmp);

	for(i=0;i<550;i++)
		for(j=0;j<550;j++)
			graph[i][j]=0;

	int count=0;
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			while(i > input[count].from && count < 2*m)
				count++;
			while(j > input[count].to && count < 2*m)
				count++;

			if(count < 2*m)
			{
				int from = input[count].from;
				int to = input[count].to;

				if(from!=i || to!=j)
				{
					if(graph[j][i]==0 && graph[i][j]==0)
						graph[i][j]++;
				}
			}
			else
			{
				if(graph[j][i]==0 && graph[i][j]==0)
					graph[i][j]++;
			}
		}
	}

	int a = colorable(n);
	if(a==0)
	{
		printf("Yes\n");
		print(n);
	}
	else
		printf("No\n");

	return(0);
}


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

typedef long long int LL;

#define din(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define llin(n) scanf("%lld",&n)
#define llout(n) printf("%lld\n",n)
#define strin(n) scanf(" %s",n)
#define strout(n) printf("%s\n",n)
#define power(a, b) po(a, b)

int mod=1000000007;
int graph[550][550];
int color[550];
char out[550];

long long po(long long x, long long y)
{
	long long pro=1;
	while(y>0)
	{
		if(y&1 != 0)
			pro=((pro%mod)*(x%mod))%mod;
		x=(x*x)%mod;
		y=y>>1;
	}
	return pro%mod;
}

typedef struct scan
{
	int from;
	int to;
}scan;

int cmp(const void *a, const void *b)
{
	scan a1 = * (scan *)a;
	scan b1 = * (scan *)b;
	if(a1.from > b1.from)
	    return 1;
	else if(a1.from < b1.from)
	    return -1;
	else
	    return a1.to - b1.to;
}

int ulta(int a)
{
	if(a==1)
		return 2;
	return 1;
}

int colorable(int n)
{
	int i, j;
	for(i=1;i<=n;i++)
	{
		int k=0;
		for(j=1;j<=n;j++)
			if(graph[i][j] == 0)
				k++;

		if(color[i]==0)
		{
			if(k==n)
				color[i] = 3;
			else
				color[i] = 1;
		}

		int green = ulta(color[i]);

		for(j=1;j<=n;j++)
		{
			if(graph[i][j] > 0)
			{
				if(color[j] == 0)
					color[j] = green;
				else if(color[j] == color[i])
					return 1;
			}
		}
	}
	return(0);
}

int print(int n)
{
	int i;
	for(i=1;i<=n;i++)
	{
		if(color[i]==1)
			out[i-1] = 'a';
		if(color[i]==2)
			out[i-1] = 'c';
		if(color[i]==3)
			out[i-1] = 'b';
	}
	out[n] = '\0';
	strout(out);
	return(0);
}

int main(void)
{
	int n,m,i,j;
	scanf("%d", &n);
	scanf("%d", &m);
	scan input[1200];
	for(i=0;i<2*m;i+=2)
	{
		scanf("%d %d", &input[i].from, &input[i].to);
		input[i+1].from = input[i].to;
		input[i+1].to = input[i].from;
	}

	qsort(input, 2*m, sizeof(scan), cmp);

	for(i=0;i<550;i++)
		for(j=0;j<550;j++)
			graph[i][j]=0;

	int count=0;
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			while(i > input[count].from && count < 2*m)
				count++;
			while(j > input[count].to && count < 2*m)
				count++;

			if(count < 2*m)
			{
				int from = input[count].from;
				int to = input[count].to;

				if(from!=i || to!=j)
				{
					if(graph[j][i]==0 && graph[i][j]==0)
						graph[i][j]++;
				}
			}
			else
			{
				if(graph[j][i]==0 && graph[i][j]==0)
					graph[i][j]++;
			}
		}
	}

	int a = colorable(i, n);
	if(a==0)
	{
		printf("Yes\n");
		print(n);
	}
	else
		printf("No\n");

	return(0);
}


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

    int i,a,s=0,num,j,x;
    scanf("%d",&a);
    for(i=0;i<a;i++)
    {
        num=a;
        while(num>0)
        {
            s=s+num%i;
            num=num/i;
        }

    }
    x=a-2;
    for(i=0;i<=x;i++)
    while(s%i==0&&x%i==0)
    {
        s=s/i;
        x=x/i;
    }
    printf("%d/%d",s,x);

    return 0;
}


#include <stdio.h>

int main()
{
    int n, k, sum = 0, temp, val, i;
    scanf("%d%d", &n, &k);
    for(i = 0; i < n; i++){
        scanf("%d", &temp);
        sum += temp;
    }
    val = n * (2 * k - 1) - 2 * sum;
    printf("%d", val);
    return val;
}


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

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

bool visited[MAX][MAX][LIM][2];
int n, t, counter[1010], ar[MAX], dp[MAX][MAX][LIM][2];

int F(int i, int l, int r, int flag){
    if (i > n){
        if (r == t || r == LIM){
            if (!flag) return (counter[ar[l]] * (t - r));
            else return 0;
        }
        else return F(0, l, r + 1, flag);
    }
    if (visited[i][l][r][flag]) return dp[i][l][r][flag];

    int x, res = F(i + 1, l, r, flag);
    if (ar[i] >= ar[l]){
        x = 1 + F(i + 1, i, r, flag);
        if (x > res) res = x;
    }
    if (!flag && t > LIM){
        x = F(i, l, r, 1) + (counter[l] * (t - LIM));
        if (x > res) res = x;
    }

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

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

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

        ar[0] = 0;
        clr(counter);
        for (i = 1; i <= n; i++){
            scanf("%d", &ar[i]);
            counter[ar[i]]++;
        }

        clr(visited);
        int res = F(1, 0, 1, 0);
        printf("%d\n", res);
    }
    return 0;
}


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

// observations:
// mixed holes (any size) will always be 1 complexity no matter what, so they get leftovers at end
// even/odd holes (any size) will always add 0 or 2 (unless on the end)
//     ^ these should definitely be filled from small to large (should i sort then?)
// only question is how to handle the ends with regard to order of filling
// i think you'd want to remove as many 2's as possible then try to fill 1's (might require some backtracking)

typedef struct {
    short parity;
    int size;
} Hole;

int compare(const void *a, const void *b) {
    return ( ((Hole *)a)->size - ((Hole *)b)->size );
}

int main() {
    int n, i;
    int nums[105];
    //int evencnt, mixcnt, oddcnt;  //holes
    //int endholeparity[2] = {0,0};
    int parity[2] = {0,0};         //existing evens,odds
    int complexity = 0;

    int ss,ee;
    Hole start_hole;
    Hole end_hole;
    Hole same_holes[55];
    int same_holes_cnt  = 0;

    int last = -1;

    scanf("%d", &n);
    for (i=0; i < n; i++) {
        scanf("%d", &nums[i]);
        if (nums[i] != 0 && (nums[i] % 2) + last == 1) {
            complexity += 1;
        }
        if (nums[i] != 0) {
            parity[nums[i] % 2]++;
            last = nums[i] % 2;
        }
        else {
            last = -1;
        }
    }
    //printf("base complexity: %d\n", complexity);

    parity[0] = n/2 - parity[0];       //existing/placed -> missing/available evens
    parity[1] = (n+1)/2 - parity[1];

    //printf("Have %2d evens\n     %2d odds\n", parity[0], parity[1]);

    for (i=0; nums[i] == 0 && i < n; i++);
    if (i == n) {     // all zeros
        if (n == 1)
            printf("0\n");
        else
            printf("1\n");
        return 0;
    }
    ss = i;
    start_hole.size = i;
    start_hole.parity = nums[i] % 2;
    for (i=n-1; nums[i] == 0 && i >= 0; i--);
    ee = i;
    end_hole.size = (n-1) - i;
    end_hole.parity = nums[i] % 2;

    //printf("start_size: %2d\n", start_hole.size);
    //printf("end_size:   %2d\n", end_hole.size);

    int cur_start = 0;

    for (i = ss; i <= ee; i++) {
        if (nums[i] == 0) {
            Hole hnew;
            cur_start = i;
            while (nums[++i] == 0 && i <= ee);
            hnew.size = i - cur_start; // ee guaranteed nonzero so no off by one
            hnew.parity = nums[cur_start-1] % 2;
            if (nums[i] % 2 != hnew.parity)
                complexity++;
            else
                same_holes[same_holes_cnt++] = hnew;
        }
    }
    //printf("Found %d holes\n", same_holes_cnt);
    qsort(same_holes, same_holes_cnt, sizeof(Hole), compare);
    for (i=0; i < same_holes_cnt; i++) {
        Hole tt = same_holes[i];
        if (parity[tt.parity] >= tt.size) {
            parity[tt.parity] -= tt.size;
        }
        else {
            complexity += 2;
            //printf("adding complexity\n");
        }
    }
    if (start_hole.size <= end_hole.size && end_hole.size != 0) {
        if (parity[start_hole.parity] < start_hole.size)
            complexity += 1;
        else
            parity[start_hole.parity] -= start_hole.size
        if (parity[end_hole.parity] < end_hole.size)
            complexity += 1;
        else
            parity[end_hole.parity] -= end_hole.size
    }
    else if (end_hole.size < start_hole.size) {
        if (parity[end_hole.parity] < end_hole.size)
            complexity += 1;
        else
            parity[end_hole.parity] -= end_hole.size
        if (parity[start_hole.parity] < start_hole.size)
            complexity += 1;
        else
            parity[start_hole.parity] -= start_hole.size
    }
    printf("%d\n", complexity);
    return 0;
}


#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#define rep(E, F) for (E = 0; E < (F); E++)
#define INF 1000000000

int mabs(int a) { if (a > 0) { return a; } return -a; }
int min(int a, int b) { if (a > b) { return b; } return a; }
int max(int a, int b) { if (a < b) { return b; } return a; }
int get_int();
double get_double();
int get_string(char* b, char t);
int n;
int d[2][100][100][100], a[100];
int chi(int a, int b) { return a == b ? 0 : 1; }

int foo(int b, int x, int y, int z)
{
	if (x == n) return 0;
	if (z < 0 || y < 0) return INF;
	if (d[b][x][y][z] != -1) return d[b][x][y][z];
	if (a[x] != -1 && a[x] != b) return INF;
	if (a[x] != -1) return d[b][x][y][z] = min(chi(0, b) + foo(0, x + 1, y, z), chi(1, b) + foo(1, x + 1, y, z));
	return d[b][x][y][z] = min(chi(0, b) + foo(0, x + 1, y - 1, z), chi(1, b) + foo(1, x + 1, y, z - 1));
}

int main()
{
	int i, j, k;
	n = get_int();
	rep(i, n) rep(j, n) rep(k, n) d[0][i][j][k] = d[1][i][j][k] = -1;
	int d[2] = {n/2, (n + 1)/2};
	rep(i, n) a[i] = get_int();
	rep(i, n) { rep(j, n) if (a[j] == i + 1) break; if (j < n) d[(i + 1)%2]--; }
	rep(i, n) if (a[i] == 0) a[i] = -1; else a[i] %= 2;
	int r = min(foo(0, 0, d[0], d[1]), foo(1, 0, d[0], d[1]));
	assert(r < INF);
	printf("%d\n", r);
	return 0;
}

int get_string(char* b, char t)
{
	int i = 0; b[i++] = getchar();
	while (b[i - 1] != t) b[i++] = getchar();
	b[i - 1] = '\0';
	return i - 1;
}

int get_int()
{
	int sgn = 1, ret = 0;
	char c  = getchar();
	while (1)
	{
		if (c == EOF) return EOF;
		if (c >= '0' && c <= '9') break;
		if (c == '-')
		{
			c = getchar();
			if (c < '0' || c > '9') continue;
			sgn = -1;
			break;
		}
		c = getchar();
	}

	while (1)
	{
		ret = ret*10 + c - '0';
		c = getchar();
		if (c < '0' || c > '9') return sgn*ret;
	}
}

double get_double()
{
	double ret = 0;
	char c     = getchar();
	int sgn;

	while (1)
	{
		if (c == EOF)
		{
			return EOF;
		}
		if (c >= '0' && c <= '9')
		{
			sgn = 1;
			break;
		}
		if (c == '-')
		{
			c = getchar();

			if (c < '0' || c > '9')
			{
				continue;
			}

			sgn = -1;
			break;
		}
		c = getchar();
	}

	while (1)
	{
		ret = ret*10 + c - '0';

		c = getchar();

		if (c == '.')
		{
			double pos = 0.1;

			c = getchar();
			while (c >= '0' && c <= '9')
			{
				ret += pos*(c - '0');
				pos /= 10;
				c = getchar();
			}

			return sgn*ret;
		}
		else if (c < '0' || c > '9')
		{
			return sgn*ret;
		}
	}
}


#include <stdio.h>

int main (void)
{
	int n ,m ,k ;
	scanf("%d %d %d",&m,&k);
	if (m<=n && k<=n)
		printf("yes");
	else
		printf("no");
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int len;

int main()
{
  int n,grade;
  float sum=0,avg;
  int temp;
  scanf("%d",&n);
  int a[n];

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

  int index,count=0;
avg=(1.000*sum)/n;

grade=avg;
if(grade+0.5<=avg && grade!=avg) grade=grade+1;
//printf("%d",grade);
while(grade!=5)
{
  sum=0;
  temp=a[0];
  for(int i=0;i<n;i++)
  {
    if(a[i]<temp)
    {
      temp=a[i];
      index=i;
    }
}
    a[index]=5;
    count++;
    for(int i=0;i<n;i++)
    {
      sum=sum+a[i];
    }
    avg=(1.000*sum)/n;
    grade=avg;
    if(grade+0.5<=avg) grade=grade+1;
  }

  printf("%d",count);

}


#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int ar[n];
    float sum=0.0;
    for(int i=0;i<n;i++){
        scanf("%d",&ar[i]);
        sum+=ar[i];
    }
    int temp;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(ar[i]<ar[j]){
                temp=ar[i];
                ar[i]=ar[j];
                ar[j]=temp;
            }
        }
    }
    int i=0,count=-1;
    do{
        if(sum/n>=4.5){
            count++;
            break;
        }
        else{
            if(ar[i]!=5){
                sum=sum-ar[i]+5;
                ar[i]=5;
            }
        }
    }while(i<n);
    printf("%d",count);
}


#include <stdio.h>
int main(void)
{
    long long int b,count = 0;
    int i;
    scanf("%lld",&b);
    if(b==1)
    {
        printf("1");
    }
    else
    {
        for(i=1;i*i<b;i++)
        {
            if(b%i==0)
            count+=2;
        }
        if(i*i==b)
        {
            count++;
        }
        printf("%lld",count);

    }
}


{
    long long int b,count = 0,i;
    scanf("%lld",&b);
    if(b==1)
    {
        printf("1");
    }
    else
    {
        for(i=1;i*i<b;i++)
        {
            if(b%i==0)
            count+=2;
        }
        if(i*i==b)
        {
            count++;
        }
        printf("%lld",count);

    }
}


#include<stdio.h>
int main()
{long long  int t,s,x,i,d,e;
scanf("%I64d %I64d %I64d",&t,&s,&x);
for(i=1;;i++)
{
d=t+i*s;
e=t+i*s+1;
if(d==x ||e==x)
{ printf("YES\n");
 exit(1);
}
if(d>x)
{ printf("NO\n");
 exit(1);
}

d=0;
e=0;}
return 0;
}


#include<stdio.h>
int main()
{
    long i,j,n,sum=0;
    scanf("%ld", &n);
    int integer[n];
        for(i=0; i<n; i++)
     {
          integer[i]=i+1;
          sum+=integer[i];
     }
     sum%2==0?printf("0"):printf("1");
     return 0;
}


#include <stdio.h>

int main ()
{
    int n, i;
    scanf ("%d", &i);
    if (i == 0) {
        printf ("1");
        return;
    }
    while (i > 4) i -= 4;
    if (i == 4) printf ("6");
    else if (i == 3) printf ("2");
    else if (i == 2) printf ("4");
    else if (i == 1) printf ("8");

    return 0;
}


#include<stdio.h>

int main()
{
    int n,m,count=0;
    scanf("%d%d",&n,&m);
    if(n<=1 && n<=1)
    {
        printf("0");
        return;
    }
    else if(n<=m)
    {
        while(n<=m)
        {
            if(n==0 || n>m)
                break;
            n--;
            m-=2;
            count++;
        }
        if(n==0 || n==1)
        {
            printf("%d",count);
        }
        else
        {
            while(n>1)
            {
                n-=2;
                m--;
                count++;
            }
            printf("%d",count);
        }
    }
    else
    {
        while(m<=n)
        {
            if(m==0 || m>n)
                break;
            m--;
            n-=2;
            count++;
        }
        if(m==0 || m==1)
        {
            printf("%d",count);
        }
        else
        {
            while(m>1)
            {
                m-=2;
                n--;
                count++;
            }
            printf("%d",count);
        }
    }
}


#include<srdio.h>
int main()
{
    int n,m,r,d=2,s;
    scanf("%d",&n);
    for(m=1;m*m<=n;m++)
    {
        if(m*m==n)
        {
            r=4*(m);
        }
        else
        {
        d++;
        s=4*d;
        }
    }
printf("%d",r||s);
return 0;
}


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

int main(){

    int n,m,x;
    scanf("%d%d",&n,&m);
    if(n==1){
        printf("1\n");
        exit(1);
    }
    if(n%2){
        x=n/2+1;
        if(m<x)
            printf("%d\n",m+1);
        else
            printf("%d\n",m-1);
    }
    else{
        x=n/2;
        if(m<=x)
            printf("%d\n",m+1);
        else
            printf("%d\n",m-1);
    }

    return 0;
}


#include<stdio.h>
int gcd(int a,int b)
{
	return (a==0) ? b : gcd(b%a,b);
}
/*int gcd(int a, int b)
{
	if (a == b)
	{
		return a;
	}
	if (a > b)
	{
		return gcd(a-b, b);
	}
	return gcd(a, b-a);
}
int gcd(int n1,int n2)
{

	while(n1!=n2)
	{
		if(n1>=n2-1)
		{
			n1=n1-n2;
		}
		else
		{
			n2=n2-n1;
		}
	}
	return n1;
}*/
int main()
{
	int a,b,n,i=0;
	scanf("%d %d %d",&a,&b,&n);
	while(n>=0)
	{
		++i;
		n-=gcd((i&1) ? a : b,n);
	}
	if(i&1)
	{
		printf("1");
	}
	else
	{
		printf("0");
	}
	return 0;
}


#include<stdio.h>
char main()
{
        int n,m;
        scanf("%d %d",&n,&m);
        printf("%d",n+m);
        return 'c';
}


#include <stdio.h>

int main()
{
	int i, n, k, flag, Gpos, Tpos;
	char field[101];

	scanf("%d %d %s", &n, &k, field);

	for(i=0; field[i]!='\0'; i++)
	{
		if(field[i]=='G')
			Gpos=i;
		else if(field[i]=='T')
			Tpos=i;
	}

	if(Gpos>Tpos)
		k*=-1;

	while(1)
	{
		if(Gpos+k>=n)
		{
			flag=0;
			break;
		}
		else if(field[Gpos+k]=='#')
		{
			flag=0;
			break;
		}
		else if(field[Gpos+k]=='.')
			Gpos+=k;
		else if(field[Gpos+k]=='T')
		{
			flag=1;
			break;
		}
	}

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

	return 0;
}


#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#define DIJKSTRA
#ifndef _TJYTLXWXHYZQFW_HEAP_H
#define _TJYTLXWXHYZQFW_HEAP_H
#include <assert.h>
#include <stdlib.h>
struct heap {
        int cap, last;
        void **cell;
	int (*cmp)(const void *, const void *);
	#ifdef DIJKSTRA
	void (*set)(void *, const int);
	void (*swap)(void *, void *);
	#endif
};
struct heap *heap_new(int cap, int (*cmp)(const void *, const void*)
	#ifdef DIJKSTRA
	,void (*set)(void *, const int), void (*swap)(void *, void *)
	#endif
)
{
        struct heap *h;
        assert(h = malloc(sizeof(struct heap)));
        h->cap = ++cap;
	h->last = 0;
        assert(h->cell = malloc(sizeof(void*) * cap));
	h->cmp = cmp;
	#ifdef DIJKSTRA
	h->set = set;
	h->swap = swap;
	#endif
        return h;
}
void heap_destroy(struct heap *h)
{
        if (h)
                free(h->cell);
        free(h);
}
void heap_pdown(int x, struct heap *h)
{
        int c, d;
        void *tmp;
        while ((c = 2 * x) <= h->last) {
                d = c + 1;
                if (d <= h->last && h->cmp(h->cell[d], h->cell[c]) < 0)
                        c = d;
                if (h->cmp(h->cell[x], h->cell[c]) < 0)
                        break;
                tmp = h->cell[c];
                h->cell[c] = h->cell[x];
                h->cell[x] = tmp;
		#ifdef DIJKSTRA
		h->swap(h->cell[c], h->cell[x]);
		#endif
                x = c;
        }
}
void heap_pup(int x, struct heap *h)
{
        int p;
        void *tmp;
        while ((p = x / 2) >= 1) {
                if (h->cmp(h->cell[p], h->cell[x]) < 0)
                        break;
                tmp = h->cell[x];
                h->cell[x] = h->cell[p];
                h->cell[p] = tmp;
		#ifdef DIJKSTRA
		h->swap(h->cell[x], h->cell[p]);
		#endif
                x = p;
        }
}
int heap_insert(void *e, struct heap *h)
{
        if (h->last >= h->cap)
                return -1;
        h->cell[++h->last] = e;
	#ifdef DIJKSTRA
	h->set(h->cell[h->last], h->last);
	#endif
        heap_pup(h->last, h);
        return 0;
}
void *heap_del(struct heap *h)
{
        void *ret;
        if (h->last <= 0)
                return NULL;
        ret = h->cell[1];
        h->cell[1] = h->cell[h->last--];
	#ifdef DIJKSTRA
	h->set(h->cell[1], 1);
	#endif
        heap_pdown(1, h);
        return ret;
}
#endif

#define LEN 20000001
struct node {
	long long cost;
	char color;
	long long id;
	int hidx;
};
int compare(const void *x, const void *y)
{
	return ((struct node *)x)->cost - ((struct node *)y)->cost;
}
void sethidx(void *node, const int idx)
{
	((struct node *)node)->hidx = idx;
}
void swaphidx(void *x, void *y)
{
	int tmp;
	tmp = ((struct node *)x)->hidx;
	((struct node *)x)->hidx = ((struct node *)y)->hidx;
	((struct node *)y)->hidx = tmp;
}
long long len;
#define OOS(x) ((x) < 0 || (x) > len)
long long x, y;
struct node nodes[LEN];
void handle(int id, long long cost, struct heap *h)
{
	struct node *next;
	if (OOS(id))
		return;
	next = &nodes[id];
	if (next->color == 2)
		return;
	if (cost >= next->cost)
		return;
	next->cost = cost;
	if (next->color == 0) {
		heap_insert(next, h);
		next->color = 1;
	} else {
		heap_pup(next->hidx, h);
	}
}
long long dijkstra(void)
{
	struct heap *h;
	struct node *node;
	h = heap_new(LEN, compare, sethidx, swaphidx);
	heap_insert(&nodes[0], h);
	nodes[0].color = 1;
	nodes[0].cost = 0;
	while ((node = heap_del(h)) != NULL) {
		node->color = 2;
		if (node->id == len)
			return node->cost;
		handle(node->id + 1, node->cost + x, h);
		handle(node->id - 1, node->cost + x, h);
		handle(node->id * 2, node->cost + y, h);
	}
	return -1;
}
int main(void)
{
	long long i, imax;
	scanf("%lld%lld%lld", &len, &x, &y);
	for (imax = len * 2, i = 0; i <= imax; ++i) {
		nodes[i].id = i;
		nodes[i].cost = LLONG_MAX;
		nodes[i].color = 0;
	}
	printf("%lld\n", dijkstra());
	return 0;
}


#include <stdio.h>

int main()
{
    int s,v1,v2,t1,t2,r1,r2;
    while(scanf("%d %d %d %d %d",&s,&v1,&v2,&t1,&t2)){
    r1=(t1*2)+(v1*s);
    r2=(t2*2)+(v2*s);
    if(r1==r2)
        printf("Friendship\n");
    else if(r1<r2)
        printf("First\n");
    else if(r2<r1)
        printf("Second\n");
}
    return 0;
}


#include <stdio.h>

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

int main()
{
    long long w, m, k, sum = 0, time = -1;
    scanf("%lld%lld%lld", &w, &m, &k);
    while (w >= sum)
    {
        time++;
        sum += i(m++) * k;
    }
    printf("%lld", time);
    return 0;
}


#include <stdio.h>

int main(void){
	long long int l, r, x, y, k;
	scanf("%lld%lld%lld%lld%lld",&l,&r,&x,&y,&k);
	long long int a = 1;
	a = x;
	while(1){
		if(k*a < l || a < x){
			a++;
		} else{
			break;
		}
	}
	long long int flag = 0;
	while(k*a <= r && a <= y){
		if(k*a <= r && a <= y){
			flag = 1;
			break;
		}
		a++;
	}
	if(flag == 1){
		printf("YES\n");
	} else{
		printf("NO\n");
	}
	return 0;


#include <stdio.h>
using namespace std;

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

	for (int i=x;i<=y;i++){
		double tar = i*k;
		int tari = (int)tar;
		if (tari-tar==0){
			if (tari<=r&&tari>=l){
				printf("YES");
				return 0;
			}
		}
	}
	printf("NO");
	return 0;
}


#include <stdio.h>

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

	for(i= x; i<=y ; i++)
	{
		long long int val;
		val = i*k;
		if(val>=l && val<=r)
		{
			printf("YES");
			return 0;
		}
	}
		printf("NO);
		return 0;
}


#include <stdio.h>

int main(){
	int l,r,x,y,k;
	scanf("%d%d%d%d%d", &l, &r, &x, &y, &k);
	for(float i=x; i<=y;i++)
		if(k*i>=l && k*i<=r && (k*i)%1==0)
		{
			printf("YES\n");
			return 0;
		}
	printf("NO\n");
	return 0;
}


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

typedef struct p{
	int x, y;
}ponto;

float isColinear(ponto a, ponto b, ponto c){
	return ( (a.x == b.x && a.y == b.y)||
		(c.x == c.x && a.y == c.y)||
		(b.x == c.x && b.y == c.y)||
		(b.y-a.y)/(b.x-a.x) == (c.y-a.y)/(c.x-a.x));
}

// retorna o angulo no vértice "a"
float isRightAngle(ponto a, ponto b, ponto c){
	if( isColinear(a, b, c)){
		return 0;
	}

	int del_x1 = (b.x - a.x),
		del_x2 = (c.x - a.x),
		del_y1 = (b.y - a.y),
		del_y2 = (c.y - a.y);

	return (del_x1*del_x2 + del_y1*del_y2) == 0;
}

// triangulo, t, é um vetor de pontos
int check(ponto *t){
	if(isRightAngle(t[0], t[1], t[2]) ||
		isRightAngle(t[1], t[0], t[2]) ||
		isRightAngle(t[2], t[1], t[0]))
		return 0;

	int i;
	ponto triangulos[12]; // contém as 4 configurações possívels para o triangulo em cada ponto
	// circula os inteiros vizinhos, começando à esquerda, sentido antihorário
	for (i = 0; i < 3; i++){
		triangulos[4*i] = t[i]; triangulos[4*i].x -=1;
		triangulos[4*i+1] = t[i]; triangulos[4*i+1].y -=1;
		triangulos[4*i+2] = t[i]; triangulos[4*i+2].x +=1;
		triangulos[4*i+3] = t[i]; triangulos[4*i+3].y +=1;
	}

	for(i=0; i<4; i++){
		if(isRightAngle(triangulos[i], t[1], t[2]) ||
			isRightAngle(t[1], triangulos[i], t[2]) ||
			isRightAngle(t[2], t[1], triangulos[i]))
			return 1;
		if(isRightAngle(t[0], triangulos[i+4], t[2]) ||
			isRightAngle(triangulos[i+4], t[0], t[2]) ||
			isRightAngle(t[2], triangulos[i+4], t[0]) )
			return 1;
		if(isRightAngle(t[0], t[1], triangulos[i+8]) ||
			isRightAngle(t[1], t[0], triangulos[i+8]) ||
			isRightAngle(triangulos[i+8], t[1], t[0]) )
			return 1;
	}

	return -1;

}

void main(){
	ponto p[3], origem;
	scanf("%d %d %d %d %d %d", &p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y);
	if( isColinear(p[0], p[1], p[2])){
		printf("NEITHER\n");
		return;
	}

	switch(check(p)){
		case 0:
			printf("RIGHT\n");
		break;
		case 1:
			printf("ALMOST\n");
		break;
		default:
			printf("NEITHER!\n");
	}
}


#include <stdio.h>

int main() {
  long long number;
  long long nap_time;
  long long messiness = 0;

  scanf("%lld", &number);
  scanf("%lld", &nap_time);

  if (nap_time >= (number / 2)) {
    messiness = ((number) * (number - 1)) / 2;
    printf("%lld\n", messiness);
  } else {
    for (long long i = 0; i < nap_time && (number - i - 1) > 0; i++) {
      messiness += (number - i - 1);
    }
    printf("%lld\n", messiness);
  }
  return 0;
}


#include <stdio.h>

#define N_MAX 100000
int shed[N_MAX] = {0,};
int messi_max = 0;

long operations = 0;

void initialize(int n)
{
	int i;

	for(i = 0 ; i < n ; i++)
		shed[i] = i + 1;
}

int find_messiness(int n)
{
	int i,j;
	int messiness = 0;

	for(i = 0 ; i < n ; i++){
		for(j = i + 1 ; j < n ; j++){
			operations++;
			if(shed[i] > shed[j])
				messiness++;
		}
	}

	return messiness;
}

/*int GetAnswer(int n, int k)
{
	int i;
	int p,q;
	int messiness = 0;
	int local_mess;
	int tmp;

	if(n == 1)
		return 0;

	local_mess = find_messiness(n);
	operations++;

	if(operations % 10 == 0)
		printf("Operations: %ld\n",operations);

	if(local_mess > messi_max)
		messi_max = local_mess;

	if(k == 0)
		return messi_max;

	// For each pair, check if its already messed up
	// If not ... make move
	// Make move: mess, reduce timer by 1
	// Bactrack
	// Unmake move
	for(p = 0 ; p < n ; p++){
		for(q = n - 1 ; q > p ; q--){
			if(shed[p] <= shed[q]){
				// Not messed up
				tmp = shed[q];
				shed[q] = shed[p];
				shed[p] = tmp;
				messiness = GetAnswer(n,k-1);
				// Unmake move
	        	tmp = shed[q];
			    shed[q] = shed[p];
			    shed[p] = tmp;
			}
		}
	}

	return messi_max;
}*/

int find_mess(int n, int k)
{
	int i,j;
	int messiness = 0;

	if(n == 1)
		return 0;

	for(i = 1 ; i <= 2*k ; i++){
		if(n - i >= 0)
			messiness += (n - i);
		//printf("i: %d ... messiness: %d\n",i,messiness);
	}

	return messiness;
}

int GetAnswer(int n, int k)
{
	int i;
	int messiness = 0;
	int p,q;
	int tmp;
	int prev_p, prev_q;

	if(n == 1)
		return 0;

	prev_p = 0;
	prev_q = n - 1;

	// Swap maximally separated entities if it increases messiness
	for(i = 0 ; i < k ; i++){
		for(p = prev_p ; p < n ; p++){
			for(q = prev_q ; q > p ; q--){
				if(shed[p] < shed[q]){
					// Swap and break
					tmp = shed[q];
					shed[q] = shed[p];
					shed[p] = tmp;
					//printf("i: %d ... messiness: %d\n",i+1,find_messiness(n));
					goto RESULT;
				}
			}
		}
RESULT:
        prev_p = p;
	    prev_q = q;
	}

	//messiness = find_messiness(n);
	//printf("m1: %d ... m2: %d\n",find_messiness(n),find_mess(n,k));
	messiness = find_mess(n,k);

	return messiness;
}

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

	/* handle the program options */
	//freopen("C:/Users/Subh/Desktop/Work/Coding/C_code/test43.txt","rt",stdin);

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

	initialize(n);
	messi_max = 0;
	operations = 0;
	//printf("Operations: %ld\n",operations);
	//printf("Messiness after initialization is %d\n",find_messiness(n));

	/* The code of your application goes here */
	//answer = GetAnswer(n, k);
	answer = find_mess(n,k);

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

	return 0;
}


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

main()
{
  char tmp[100];
  int j=0,t;
  int se,na;
  scanf("%d",&t);

  while(1)
    {
      sprintf(tmp,"%d",t);
      j = strlen(tmp);
      if(tmp[j-1]!='4' && tmp[j-1]!='7')
	{
	  t++;
	  continue;
	}
      j=0;
      se=0;
      na=0;
      while(tmp[j]!='\0')
	{
	  if(tmp[j]=='4')
	    se++;
	  else if(tmp[j]=='7')
	    na++;
	 else
	   {
	     se=-1;
	     break;
	   }
	  j++;
	}
      if(se==na)
	break;
      j = strlen(tmp)-1;
      if(tmp[j]=='4')
	{
	  t+=3;
	}
      else t+=7;

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

}


#include<cstdio>
using namespace std;

int main(){
	char c[7]={'^','>','v','<','^','>','v'};
	int n,i,t,s;
	char u,v;
	scanf("%c %c",&u,&v);
	getchar();
	scanf("%d",&n);
	n=n%4;
	if(n==0||n==2){
		printf("undefined");
		return 0;
	}
	for(i=0;i<4;i++){
		if(c[i]==u) t=i;
		if(c[i]==v) s=i;
	}
	int tm=t-n+4;
//	printf("**%d %d %d %d**",t,s,n,tm);
//	printf("%c",c[tm%4]);
	if(c[t+n]==v){
		printf("cw\n");
	} else if(c[tm%4]==v){
		printf("ccw\n");
	}
	return 0;
}


#include<stdio.h>
int check(char str[],int i,int j,int n)
{
	int len=j-i+1;
	int k=0;
	while(k!=len)
	{
		if(str[k+i]!=str[k+i+len])
		return 0;
		k++;
	}
	return 1;
}
int main()
{
	int n;
	scanf("%d",&n);
	char str[n+1];
	scanf("%s",str);
	char str1[2*n];
	int temp=0;
	while(temp!=n)
	{
		str1[temp]=str[temp];
		temp++;
	}
	while(temp!=2*n)
	{
		str1[temp]=' ';
		temp++;
	}
	int mid = n/2-1;
	int i=0,j=0;
	int len=0,start=0,end=0;
	for(i=0;i<n-1;i++)
	{
		for(j=i+1;j<n;j++)
		{
			int che=check(str1,i,j,2*n);
			if(che==1)
			{
				if(len<j-i+1)
				{
					len=j-i+1;
					start=i+len;
					end=j+len;
				}
			}
		}
	}
	int minlen=0;
	if(len!=0)
	{
	minlen=start+1+n-end-1;
	}
	else
	{
	minlen=n;
	}
	printf("%d",minlen);
}


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

unsigned long long int pgcd(unsigned long long int x,unsigned long long int y)
    {
        if ((x==1) || (y==1)) return 1;
        if (x==y) return x;
        if (x<y) return pgcd(x,y%x);
        return pgcd(x%y,y);
    }

main()
    {
        unsigned long long int t,w,b,ww,bb,m,a,r,p,q,d,s;
        scanf("%llu%llu%llu",&t,&w,&b);
        if (w<b) m = w;
        else m = b;
        d = pgcd(w,b);
        ww = w / d;
        bb = b / d;
        if (t<ww)
            {
                a = 0;
                r = t;
            }
        else
            {
                s = ww;
                if ((t/s)<bb)
                    {
                        a = 0;
                        r = t;
                    }
                else
                    {
                        s = ww * bb;
                        if ((t/s)<d)
                            {
                                a = 0;
                                r = t;
                            }
                        else
                            {
                                s = ww * bb * d;
                                a = t / s;
                                r = t % s;
                            }
                    }
            }
        if (m<=r) p = ((a + 1) * m) - 1;
        else p = (a * m) + r;
        q = t;

        d = pgcd(p,q);
        p = p / d;
        q = q / d;
        printf("%llu/%llu",p,q);
    }


#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	int cnt1, cnt2, x, y, v;
	cin >>cnt1>>cnt2>>x>>y;
	v = cnt2 + cnt1 + cnt1/x + cnt2/y;
	v -= (cnt1>cnt2)? cnt1/(x*y) : cnt2/(x*y);
	cout <<v;
	return 0;
}


//friends and presents Federico Bellini
#include <stdlib.h>
#include <stdio.h>

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

    scanf("%i %i", &a, &b);
    scanf("%i %i", &x, &y);

    int i = 0;
    while(a > 0 || b > 0){
        ++i;

        if((i%x != 0) && (i%y != 0)){
            if(a>b && a>0) a--;
            else b--;
        }
        else if((i%x != 0) && (a>0)){
            a--;

        }
        else if((i%y != 0) && (b>0)){
            b--;
        }
    }

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


//friends and presents Federico Bellini
#include <stdlib.h>
#include <stdio.h>

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

    scanf("%i %i", &a, &b);
    scanf("%i %i", &x, &y);

    int i = 0;
    while(a > 0 || b > 0){
        ++i;

        if((i%x != 0) && (i%y != 0)){
            if(a>b && a>0) a--;
            else b--;
        }
        else if((i%x != 0) && (a>0)){
            a--;

        }
        else if((i%y != 0) && (b>0)){
            b--;
        }
    }

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

    return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;

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

    ans = c1+c2;
    while(ans - ans/x < c1)
    {
        ans += c1 - (ans - ans/x);
    }
    while(ans - ans/y < c2)
    {
        ans += c2 - (ans - ans/y);
    }
    while(ans - ans/(x*y) < c1+c2)
    {
        ans += (c1+c2) - (ans - ans/(x*y));
    }
    printf("%d\n", ans);
}


#include<stdio.h>
int a[30001];
long long int lcm(long long int x,long long int y)
{
	long long int pro=1,p,q,c,i;
	if(x>y)
	{
		c=x;
		x=y;
		y=c;
	}
	if(y%x==0)
		return y;
	else if((a[x]==0||a[y]==0))
		return x*y;
	else
	{
		//prime factorisation
		for(i=2;i<y;i++)
		{
			while(x%i==0||y%i==0)
			{
				p=x/i;
				q=y/i;
				pro*=i;
				if(a[p]==0||a[q]==0)
					return pro*p*q;
				else
				{
					x=p;
					y=q;
				}
			}
		}
	}
}

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

int main()
{
	int i,j;
	a[0]=1;a[1]=1;
	long long int p,q,l,f1,f2,mid2,both,start=1,end=1000000,k,mid,cnt1,cnt2,x,y;
	for(i=2;i<=30000;i++)//ceiving
		if(a[i]!=1)
			for(j=2*i;j<=30000;j+=i)
				a[j]=1;

	scanf("%lld%lld%lld%lld",&cnt1,&cnt2,&x,&y);
	l=lcm(x,y);
	i=0;j=0;
	while(1)
	{
		mid=(start+end)/2;
		f1=mid/x;//divisible  by x
		f2=mid/y;//divisible by y
		both=mid/l;//divi by both
		p=max(0,cnt1-(f2-both));//gives no. of nums divisible only by y
		q=max(0,cnt2-(f1-both));//only by x;
		k=mid-(f1+f2-both);
		if(p+q==k)
		{
			end=mid;
			mid2=mid;
			i=1;
			j=0;
			//return 0;
		}
		else if(p+q>k)
		{
			start=mid;
			j=1;
		}
		else if(p+q<k)
		{
			end=mid;
			j=1;
		}
		if(i==1&&j==1)
		{
			printf("%lld\n",mid2);
			return 0;
		}
	}
	printf("%lld\n",mid);
}


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

# define F first
# define S second
# define mp make_pair
# define pii pair<int,int>

# define long long long
# define pb push_back
# define sz(a) (int)(a.size())

# define y1     tipa_y1
# define left   tipa_left
# define right  tipa_right

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 4611686018427387903;
const int Sz = 1110111;

int n, k;

char a[11011];

int len = 0, mx = 0;

int main()
{
  scanf ("%d %d", &n, &k);
  for (int i = 1;i <= n;i ++) {
    scanf (" %c", &a[i]);
    if (a[i] == 'N')
      len ++;
    else
    {
      len = 0;
    }
    if (mx < len)
      mx = len;
  }
  if (mx > k)
    printf ("NO");
  else
  {
    len = 0;
    bool ok = 0;
    for (int i = 1;i + k - 1 <= n;i ++) {
      if (i == 1 || a[i - 1] != 'N') {
        bool y = 1;
        for (int j = i;j <= i + k - 1;j ++) {
          if (a[j] == 'Y')
            y = 0;
        }
        if (i + k <= n && a[i + k] == 'N')
          y = 0;
        if (y)
        {
          ok = 1;
          break;
        }
      }
    }
    if (ok)
      printf ("YES");
    else
      printf ("NO");
  }

  return 0;
}

// Coded by Z...


#include<stdio.h>
#define Inf 1LL<<61
#define ll long long
#define NewLine cout<<endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0)
#define REP(i,a,b)for(int i=a;i<b;i++)
#define RREP(i,a,b)for(int i=a;i>b;i--)
#define R(i,b) REP(i,0,b)
#define r(b)REP(_,0,b)
#define RR(i,b) RREP(i,b,-1)
#define R1(i,b) REP(i,1,b)
#define pb push_back
#define IN ll k,q;cin>>k>>q;cin.get()
#define CInt(x)cin>>x;cin.get()
#define CBuff(x)cin.getline(x, sizeof(x))
#define Outl(x)cout << x << '\n'
#define all(x) begin(x),end(x)
using namespace std;

int n, k;
char b[110];
int N[110], m = 0;
int main()
{
	scanf("%d%d", &n, &k);
	scanf("%s", &b);int l = 0;
	R(i, n) {
		if (b[i] == 'N') {
			l++;
		}
		else {
			if (l > 0)
				N[m++] = l;l = 0;
		}
	}l = 0;
	R(i, n) {
		if (b[i] == 'N'|| b[i] == '?') {
			l++;
		}
		else {
			if (l > 0)
				N[m++] = l;l = 0;
		}
	}int u = 0, d = 0;
	R(i, m) {
		if (N[i] >= k)u = 1;
		if (N[i] <= k)d = 1;
	}if (u&&d)printf("YES");else printf("NO");


#include <stdio.h>
#include <windef.h>

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

    char s[n + 1];
    scanf("%s", s);

    char last = '.';
    int cnt = 0, mxN = 0;
    for(int i = 0; i < n; ++i) {
        if(s[i] == last) {
            cnt++;
        } else {
            last = s[i];
            cnt = 1;
        }
        if(last == 'N') {
            mxN = max(mxN, cnt);
        }
    }

    if (mxN <= k) {
        for (int i = 0; i + k <= n; ++i) {
            bool f = true;
            for (int j = i; j < i + k; ++j)
                f &= s[i] != 'Y';

            if (i != 0)
                f &= s[i - 1] != 'N';
            if (i + k != n)
                f &= s[i + k] != 'N';

            if (f) {
                puts("YES");
                return 0;
            }
        }
    }

    puts("NO");
}


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

char a[101];

int main()
{
    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

   	int n, k, sch = 0, ans = 0;
   	scanf("%d%d%s", &n, &k, a);

   	a[n] = 'E';

   	for (int i = 0; i <= n; i++)
   	{
   		if (a[i] != a[i - 1])
   		{
   			ans = max(ans, sch);
   			sch = 0;
   		}
   		if (a[i] == 'N') sch++;
   	}

   	if (ans > k)
   	{
   		printf("NO");
   		return 0;
   	}

   	ans = sch = 0;

   	for (int i = 0; i <= n; i++)
   	{
   		if (a[i] != a[i - 1])
   		{
   			ans = max(ans, sch);
   			sch = 0;
   		}
   		if (a[i] == 'N' || a[i] == '?') sch++;
   	}

   	if (ans >= k)
   		printf("YES");
   	else printf("NO");
   	return 0;
}


    #include <stdio.h>
	int mod=1000000007;
    long long int power(long long int base,long long int exponent)
    {
    	long long int res=1;
    	while(exponent)
    	{
    		if(exponent%2)
    			res=(res*base)%mod;
    		base=(base*base)%mod;
    		exponentexponent/=2;
    	}
    	return res%mod;
    }

    long long int geometricsum(long long int r,long long int n)
    {
    	if(r==1)
    		return n%mod;
    	return (1-power(r,n))*power(1-r,mod-2)%mod;
    }

    int main()
    {
    	long long int a,b,n,x;
    	scanf("%lld %lld %lld %lld", &a,&b,&n,&x);
    	long long int answer=(power(a,n)*x+b*geometricsum(a,n))%mod;
    	printf("%lld", answer);
    	return 0;

    }


#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007 ;
ll MOD2 = 1000000006 ;

int main(int argc, char const *argv[])
{
    ll A,B,n,x;
    scanf("%lld %lld %lld %lld",&A,&B,&n,&x);
    ll answer = 0;
    ll apart = 1;
    ll itna = n%(MOD2);
    if(itna==0)
    {
        printf("%lld\n",x%MOD);
    }
    else
    {
    ll second = 1;
    for (ll i = 2; i <= itna; i++)
    {
        apart = (apart*(A%MOD))%MOD ;
        second = (second+apart)%MOD;
    }
    second  = ((second%MOD)*(B%MOD))%MOD ;
    ll fed = ((apart%MOD)*(A%MOD))%MOD ;
    fed = (fed%MOD*(x%MOD))%MOD ;
    answer = (answer+second+fed)%MOD ;
    printf("%lld\n",answer);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
long long int power(long long int x,long long int y)
{
	int hel=1;
	x= x%1000000007;
	while(y>0)
	{
		if((y&1)==1)
		{
			hel=(hel*x)%1000000007;
		}
		x= (x*x)%1000000007;
		y= y>>1;
	}
	return hel%1000000007;
}
long long int cal(long long int x,long long int y)
{
	if(x==1)
	{
		return y%1000000007;
	}
	else
	{
		return (power(x,y)-1);
	}
}

int main()
{
	long long int a,b,n,x,sum;
	scanf("%lld%lld%lld%lld",&a,&b,&n,&x);
	sum=(power(a,n)*x+(b*cal(a,n)/(a-1)))%1000000007;
	printf("%lld\n",sum);
	return 0;
}


#include<stdio.h>
int main(void)
{
  int number,count,sum=0;
  while(scanf("%d",&number)!=EOF)
    {
         while(number)
           count++;
           number>>=1;
            }
      printf("%d",count);
    }
return 0;
}


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


#include<stdio.h>
int main(){
    int num, i;
    scanf("%d", &num);3
    for(i = 2;i < num;i++){
        if(num % i == 0){
            printf("%d%d\n", i, num/i);
            break;
        }
    }
    return 0;
}


#include <stdio.h>

int main(void)
{
    int x, i = 2;

    scanf("%d", &x);

    while(1) if(!(x%i++)) printf("%d%d\n", i-1, x/(i-1));

    return 0;
}


#include <stdio.h>

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

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

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

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


#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
int max(int a, int b)
{
	if(a> b) return a;
	else return b;
}
main()
{
	int x, y, a1, b1, a2, b2;
	scanf("%d%d%d%d%d%d", &x, &y, &a1, &a2, &b1, &b2);
	if(a1 + b1 <= x && max(a2, b2)<= y || a1 + b2 <= x && max(a2, b1)<= y|| a2+ b2 <= x && max(a1, b1)<= y || a2 + b1 <= x && max(a1, b2)<= y || a1 + b1 <= y && max(a2, b2)<= x || a1 + b2 <= y && max(a2, b1)<= x ||a2 + b1<= y && max(a1, b2)<= x|| a2 + b2 <= y && max(a1, b1)<= x)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}


#include<stdio.h>
int min(int a,int b){
    if(a<=b)
        return a;
    else
        return b;
}
int max(int a,int b){
    if(a<=b)
        return b;
    else
        return a;
}

int main()
{
    int a1,a2,b1,b2,a,b,k;
    scanf("%d%d",&a,&b);
    scanf("%d%d",&a1,&b1);
    scanf("%d%d",&a2,&b2);
    int x=max(a1,b1);
    int y=a1+(b1-x);
    int x1=max(a2,b2);
    int y2=a2+(b2-x1);
    int z=max(a,b);
    k=a+(b-z);
    if(x+x1<=z&&max(y,y2)<=k||x+x1<=k&&max(y,y2)<=z)
        printf("YES");
    else if(x+y2<=z&&max(x1,y)<=k||x+y2<=k&&max(x1,y)<=z)
        printf("YES");
    else if(y+x1<=z&&max(x,y2)<=k||x+y2<=k&&max(x1,y)<=z)
        printf("YES");
    else if(y+y2<=z&&max(x,x1)<=k||y+y2<=k&&max(x,x1)<=z)
        printf("YES");
    else
        printf("NO");

    return 0;


#include <stdio.h>
#define MAX 1000000007
long long int ncr(int n, int k)
{
    if(k > n)
        return 0;
    if(k == n)
        return 1;
    long long int r = n;
    int i;
    for(i=2;i<=k;++i)
    {
        r *= (n-i+1);
        r = r/i;
    }
    return r;
}
int main()
{
    int n,i, sum = 0, ans = 0;
    scanf("%d", &n);
    sum = n+2;
    for(i = 1; i <=n; i++){
        ans = ans + ncr(n+1,i);
    }
    ans = (ans+n)%MAX;
    if(n == 2){
        ans = 4;
    }
    printf("%d", ans);
    return 0;
}


#include<stdio.h>
int main()
{
	int n,k,i,j=0,max=0;
	scanf("%d%d",&n,&k);
	int a[n];
	for(i=0;i<n;i++)
	{
		if(k%a[i]==0)
		{
			j=a[i];
			if(j>max)
			max=j;
		}
	}
	printf("%d",k/max);
	return 0;
}


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

int main(int argc, char *argv[])
{
    int k, a, b, c;
    int ans;
    while(scanf("%d %d %d %d", &k, &a, &b, &c) != EOF)
    {
        ans = 0;
        while(1)
        {
            if(b < k - 1)
            {
                a = a - (b + 1)*c;
                ans++;
                break;
            }
             if(b > k - 1)
            {
                b = b - k + 1;
                if((a- k * c) > 0)
                {
                    a = a - k * c;
                    ans++;
                }
            }
        }
        while(a > 0)
        {
            ans++;
            a -= k;
        }
        if(a > 0)
            ans++;
        printf("%d\n", ans);
    }
    return 0;
}


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

using namespace std;

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

	scanf("%lld",&n);

	printf("%lld",(n-2)*(n-2));

	return 0;
}


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


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

int m, n, a, a1; count_m = 1, count_n = 1;

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

    a1 = a;

    while (a1 < m)
    {
        a1+=a1;
        count_m++;
    }

    while (a < n)
    {
        a += a;
        count_n++;
    }
    printf("%d", count_m * count_n);
}


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


#include<stdio.h>
int main ()
{
    int a,b,c,d,sum=0;
    scanf("%d%d",&a,&b);
    c=a;
    while(1)
    {
       c=c/b;
        d=c%b;
        sum=sum+c;
        c=c+d;
        if(c<b) break;

    }
    printf("%d",a+sum);
}


#include<stdio.h>
#define MIN(a,b) ((a)>(b)?(b):(a))
int main()
{
    int x,hh,mm,hourCount=0,snoozeCount=0,temp;
    scanf("%d%d%d",&x,&hh,&mm);
    if(hh%10==7 || hh/10==7 || mm%10==7 || mm/10==7)
        printf("0");
    else
    {
       // printf("the time  is %d:%d\n",hh,mm);

        while(hourCount<24)
        {
            mm-=x;
          //  printf("the time before is %d:%d\n",hh,mm);
            snoozeCount++;
            if(mm<0)
            {
                temp=mm;
                //printf("the temp is %d\n",temp);

                mm=60+temp;
                hh--;
                if(hh<0)
                {
                    hh=23;
                    hourCount++;
                }
            }
           // printf("the time after is %d:%d\n",hh,mm);

            if(hh%10==7 || hh/10==7 || mm%10==7 || mm/10==7)
            {
                printf("%d",snoozeCount);
                return;
            }

        }
    }

}


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

int main()
{
	int n;
	scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	int n1 = n * (n - 1) / 2;
	int st[n1];
	int k = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			st[k] =  abs(a[j] - a[i]);
			k++;
		}
	}
	int min = st[0];
	for (int i = 0; i < n1; i++)
	{
		if (st[i] < min)
			min = st[i];
	}
	int kt = 0;
	for (int i = 0; i < n1; i++)
	{
		if (((st[i] / min) > 2) || ((st[i] % min) != 0))
			kt++;
	}
	if (kt == 0)
		printf("%d", min);
	else
		printf("%d", -1);
	return 0;
}


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

#define MDI 1000000009
#define MOD(a) ((a) % MDI)
typedef long long LL;

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

int main(void)
{
  int i, j, k;
  LL h = 0, g, n, f, t;
  scanf("%d", &n);
  n /= 2;
  t = n - 2;
  for(i = 0; i < t; i++){
    f = t - i;
    g = MOD(MOD(2 << (f + 1) - 1) << 2);
    h = MOD(4 + h + MOD(g << 2) + MOD(h * g));
  }
  if(n > 1)
    h = MOD(4 + h);
  h = MOD(MOD(MOD(h * h) + 5 + MOD(h << 2) << 1));
  putlld(h);
  putchar('\n');
  return 0;
}

#undef WERTYUIOPASDFGHJKLZXCVBN
#ifdef WERTYUIOPASDFGHJKLZXCVBN
/*
 * it starts and ends in the same place — the granny's house;
 * the route goes along the forest paths only (these are the segments marked black in the picture);
 * the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway);
 * the route cannot cross itself;
 * there shouldn't be any part of dense forest within the part marked out by this route;
 I:
 2
 O:
 10
 I:
 4
 O:
 74
 */
#endif


#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[600000];

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


#include<stdio.h>

int a[100],i,j,max,h,l,n,b;
int main()
{
FILE *fin,*fout;

fin=fopen("garden.in","r");
fscanf(fin,"%d",&n);
fscanf(fin,"%d",&l);
for(i=0;i<n;i++)
{
fscanf(fin,"%d",&a[i]);
}
fclose(fin);
i=0;
j=0;
b=0;
max=0;
while(i<n)
{
if(l%a[i]==0){b=l/a[i];}
else
    b=0;
if(b>max) max=b;
i++;
}
h=l/max;
fout=fopen("garden.out","w");
fprintf(fout,"%d",h);
 fclose(fout);
 return 0;
}


#include<stdio.h>
int solvemin(int m1,int m,int s){
	int temp,temp1,res1,min,iffound=0,m_save=m-1;
	if(m==0){
		if(s>0){
			return -1;
		}
		if(s==0){
			return 0;
		}
	}else if(m>0){
		if(m1==m){
			for(temp=1;temp<10;temp++){
				min = temp;
				res1=solvemin(m1,m-1,s-temp);
				if(res1!=-1){
					int i=0;
					m_save=m-1;
					while(m_save>0){
						min=min*10;
						m_save--;
						//printf("%d %d\n",min,m);
					}
					min = min+res1;
					iffound=1;
					break;
				}
			}
			if(iffound==1){
				return min;
			}else{
				return -1;
			}
		}else{
			for(temp=0;temp<10;temp++){
				min = temp;
				res1=solvemin(m1,m-1,s-temp);
				if(res1!=-1){
					int i=0;
					m_save=m-1;
					while(m_save>0){
						min=min*10;
						m_save--;
						//printf("%d %d\n",min,m);
					}
					min = min+res1;
					iffound=1;
					break;
				}
			}
			if(iffound==1){
				return min;
			}else{
				return -1;
			}
		}
	}
}
int solvemax(int m1,int m,int s){
	int temp,temp1,res1,min,iffound=0,m_save=m-1;
	if(m==0){
		if(s!=0){
			return -1;
		}
		if(s==0){
			return 0;
		}
	}else if(m>0){
		if(s==0){
			return 0;
		}else{
			for(temp=9;temp>0;temp--){
				min = temp;
				res1=solvemax(m1,m-1,s-temp);
				if(res1!=-1){
					int i=0,res_save=res1;
					while(m_save>0){
						min=min*10;
						m_save--;
					}
					min = min+res1;
					iffound=1;
					break;
				}
			}
			if(iffound==1){
				return min;
			}else{
				return -1;
			}
	    }
	}
}
main(){
	int s,m,temp,temp1,res1,res2;
	scanf("%d %d",&m,&s);
	if(s>0){
		res1 = solvemin(m,m,s);
		res2 = solvemax(m,m,s);
		printf("%d %d",res1,res2);
	}else{
		printf("-1 -1");
	}
}


#include<stdio.h>
#include<string.h>
int main() {
  /*two integers read into a char array!*/
  char a[10];
  char b[10];
  scanf("%s",a);
  scanf("%s",b);
  int na=strlen(a);
  int nb=strlen(b);
  int i,j,k;
  for(k=0;k<na;k++) {
    a[k]=a[k]-'0';
  }

  for(k=0;k<nb;k++) {
    b[k]=b[k]-'0';
  }
    int find_zero=0;
  for(i=0;i<na;i++) {
    if(a[i]==0) {find_zero=1; break;}
  }
  /*one piece code do one thing.*/
  for(i=0;i<nb;i++) {
    if(b[i]==0) {find_zero=1;break;}
  }
  int more10=0;
  /*保证i比j大*/
  if(na>nb) {
    i=na-1;
    j=nb-1;
  } else {
    i=nb-1;
    j=na-1;
  }
  int last_more10=0;
  while(1) {
    /*没有进位就可以保证相同，这是在有零的情况下成立*/
    if(a[i]+b[j]>=10){
      more10=1;
      if(j==0) { last_more10=1; break; }
      else a[i-1]+=(a[i]+b[j])/10;
    }
    i--;
    j--;
  }

    if(find_zero) {
      if(more10) printf("NO\n");
      else printf("YES\n");
    }else {
      if(last_more10) {
        printf("NO\n");
      } else printf("YES\n");
  }
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
main()
{
int h, r, ans;
scanf("%d",&r);
scanf("%d",&h);
ans = 2*h/r;
ans += ((2*m>=r)?2:1)
ans += ((2.0*m>=(sqrt(3.0)*r))?1:0);
printf("%d",ans);
return 0;
}


#include<stdio.h>
#include <stdlib.h>
int M(int a,int b)｛
return a>b?a:b;
｝
int main()｛
int a,b,c,d,e,f;
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
int x;
if(c<d)c^=d^=c^=d;
if(e<f)e^=f^=e^=f;
if(c<e){c^=e^=c^=e;d^=f^=d^=f;}
for(x=0;x<2;x++){
 if(c<=a){if(d+f<=b)goto rt;goto next;}
 if(d<=a){if(c+f<=b)goto rt;goto next;}
 if(M(e,f)<=a){if(d+c<=b)goto rt;goto next;}
next:
 a^=b^=a^=b;
}
printf("NO\n");
return 0;
rt:printf("YES\n");return 0;
｝