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

// Функция сортировки нисходящим слиянием

void mergeSort(int *a, int l, int r)
{
  if (l == r) return; // границы сомкнулись
  int mid = (l + r) / 2; // определяем середину последовательности
  // и рекурсивно вызываем функцию сортировки для каждой половины
  mergeSort(a, l, mid);
  mergeSort(a, mid + 1, r);
  int i = l;  // начало первого пути
  int j = mid + 1; // начало второго пути
  int *tmp = (int*)malloc(r * sizeof(int)); // дополнительный массив
  for (int step = 0; step < r - l + 1; step++) // для всех элементов дополнительного массива
  {
    // записываем в формируемую последовательность меньший из элементов двух путей
    // или остаток первого пути если j > r
    if ((j > r) || ((i <= mid) && (a[i] < a[j])))
    {
      tmp[step] = a[i];
      i++;
    }
    else
    {
      tmp[step] = a[j];
      j++;
    }
  }
  // переписываем сформированную последовательность в исходный массив
  for (int step = 0; step < r - l + 1; step++)
    a[l + step] = tmp[step];
}

int main()
{
  int n, b[100001], flag = 0;

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

  mergeSort (b, 0, n-1);

  for (int i = 1; i < n-1; i++)
  {
    if (b[i]+b[i-1] > b[i+1])
    {
      printf("YES \n");
      flag = 1;
      break;
     }
  }

  if (flag == 0)
    printf("NO \n");

}


#include<stdio.h>

void main()
{
    int n,i,p1=1,p2=2,temp=3;
    scanf("%d",&n);
    int a[n];
    for (i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]==temp){
            printf("NO");
            exit(0);
        }
        temp=6-a[i]-temp;
    }
    printf("YES");
}


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

main()
{
    int k,i,n,num[10],player1=1,player2=2,waiter=3,winner,loser,possible=1;
    scanf("%d",&n);
    for (i=0;i<n;i++)
        {
        scanf("%d",&num[i]);
        }
    for (i=0;i<n;i++)
        {
        //printf("p1-%d p2-%d w-%d\n",player1,player2,waiter);
        winner=num[i];
        if (winner==loser) possible=0;
            else
            {
            if ((winner==1)&&(waiter==2)) loser=3;
            if ((winner==1)&&(waiter==3)) loser=2;
            if ((winner==2)&&(waiter==1)) loser=3;
            if ((winner==2)&&(waiter==3)) loser=1;
            if ((winner==3)&&(waiter==1)) loser=2;
            if ((winner==3)&&(waiter==2)) loser=1;
            player1=winner;
            player2=waiter;
            waiter=loser;
            }
        }
    if (possible==0) printf("NO"); else printf("YES");
}


#include<stdio.h>
int main(){
int a=1,b=2,c=3,n,i,x=3,ok=1,aux;
scanf("%d",&n);

while(n){
    scanf("%d",&i);
    if(i==x){ok=0;break;}
    else if(i==a){
        aux=b;
        b=x;
        x=aux;
    }
    else if(i==b){
        aux=a;
        a=x;
        x=aux;
    }
}
if(ok==1)printf("YES");
else printf("NO");
}


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

	FILE *prb=fopen("prb.in","r");
	int n,alex=1,bob=2,carl=3,num[110],t,m=0;
	fscanf(prb,"%d",&n);
	int i;
	for(i=1;i<=n;i++)
	{
		fscanf(prb,"%d",&num[i]);
	}
	for(i=1;i<=n;i++)
	{
	    if (num[i]==carl)
	    {
	    	m=1;
	    }

		if(num[i]==alex)
		{
			t=bob;
			bob=carl;
			carl=t;
		}
		else if(num[i]==bob)
		{
			t=alex;
			alex=carl;
			carl=t;
		}

	}
	if(m==0)
	printf("YES\n");
    else
    	printf("NO\n");

	return 0;

}


#include<stdio.h>
int main(void){
  int NOR,winner[NOR],i,cntAL=0,cntCA=0,cntBO=0;
  scanf("%d",&NOR);
  for(i=0;i<NOR;i++){
    scanf("%d",&winner[i]);
  }
  for(i=0;i<NOR;i++){
    if(winner[i]== 1)
       cntAL++;
    else if(winner[i]== 3){
       cntCA++;
    }
    else if(winner[i]== 2){
      cntBO++;
    }

    }
     if(cntAL>(NOR/2)|| cntBO>(NOR/2) || cntCA>(NOR/2)){
      printf("YES");
    }
      else
      printf("NO");
}


#include <stdio.h>

int number_of_chip( int n, int m );

int main (int argc, const char * argv[])
{

  int n = 0;
  int m = 0;
  scanf("%d", n);
  scanf("%d", m);
  number_of_chip(argv[0], argv[1]);
  return 0;
}

int number_of_chip( int n, int m )
{
  if ( n >= 1 && n <= 50 && m >= 1 && m <= 10e-4 )
  {
    int i = 0;

    while(1)
    {
      for ( i=0; i<n; i++ )
      {
        m -= (i+1);

        if ( m == 0 )
          return 0;

        if ( m < 0 )
        {
          m += (i+1);
          return m;
        }
      }
    }
    return m;
  }
  return -1;
}


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

int main(void)
{
    int i,n,m,out;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
         out=n*(n+1)/2;
         m=m%out;
         i=1;
         while(m>=i)
         {
             m-=i;
             i++;
             }

         printf("%d",m);
         }

         system("pause");
         return 0;
         }


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

int main()
{
    long long int n,m,i;
    scanf("%I64d %I64d",&n,&m);
    for(i=1;i<=n;i++)
    {
       if(m>=i)
        {
            m=m-i;
        }
        if(i==n)
        {
            i=0;
        }
        if(m<i)
        {
            break;
        }
    }
    printf("%I64d",m);
    return 0;
}


#include<stdio.h>
main()
{
 int m,n,i,k;
 scanf("%d%d",&m,&n);
    if (n==m)
    printf("0");
    else
    {
    x:
    k=0;
    for (i=1;i<=m;i++)
    {
    if (n>=i)
    n=n-i;
    k++;
    if (n<=i)
    break;
    }
    if (k==m)
    goto x;
    else
    {
        if (n<=i)
    {
        printf("%d",n);
    }
    else
     printf("0");
    }
    }
return 0;
}


#include <stdio.h>
#define MAX 100
int obrada(int a[MAX][MAX], int k, int m);
void main() {
	int a[MAX][MAX] = { 0 };
	int n, k, m, s = 0;
	a[0][0] = a[1][0] = 1;
	//scanf("%d", &n);
	//for (int i = 0; i < n; i++) {
		scanf("%d%d", &k, &m);
		s += obrada(a, k - 1, m - 1);
	//}
	printf("%d\n", s);
}

int obrada(int a[MAX][MAX], int k, int m)
{
	int p, b;
	if (k < m) p = k, k = m, m = p;
	if (a[k][m] == 0 && k != -1 && m != -1) {
		if (k == m == 100) a[k][m] += 1 + obrada(a, k, m - 2);
		else a[k][m] += 1 + obrada(a, k - 2, m + 1);
	}
	return a[k][m];
}


#include <stdio.h>

int main(void) {
	// your code goes here

	int a1,a2,n,i=0,j,k;
	scanf("%d%d",&a1,a2);

	while(a1>0&&a2>0)
	{i++;

	    if(a1>a2){

	        a1=a1-2;
	        a2=a2+1;
	    }
	    else{

	        a1=a1+1;
	        a2=a2-2;
	    }

	}

	printf("%d",i);

	return 0;
}


#include <stdio.h>
#define MAX 100
int obrada(int a[MAX][MAX], int k, int m);
int main() {
	int a[MAX][MAX] = { 0 };
	int n, k, m, s = 0;
	a[0][0] = a[1][0] = 1;
	//scanf("%d", &n);
	//for (int i = 0; i < n; i++) {
		scanf("%d%d", &k, &m);
		s += obrada(a, k - 1, m - 1);
	//}
	printf("%d\n", s);
	return 0;
}

int obrada(int a[MAX][MAX], int k, int m)
{
	int p, b;
	if (k < m) p = k, k = m, m = p;
	if (a[k][m] == 0 && k != -1 && m != -1) {
		if (k == m == 100) a[k][m] += 1 + obrada(a, k, m - 2);
		else a[k][m] += 1 + obrada(a, k - 2, m + 1);
	}
	return a[k][m];
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main() {

	int a1, a2;
	int res = 0;
	int d;
	int *pc, *pf, *t;

	scanf("%d%d", &a1, &a2);

	pf = &a1; pc = &a2;
	while (a1 > 2 || a2 > 2) {
		d = (*pf - 1) / 2;
		res += d;
		*pf -= 2 * d;
		*pc += d;
		t = pc; pc = pf; pf = t;
	}

	printf("%d", res + 1);
	getch();

}


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

int main()
{
	int a1,a2;
	scanf("%d %d",&a1,&a2);
	int dakika=1;
	if(a1+a2<=3)
	printf("0");
	else
	{
		while(1)
		{
			if((a1+a2==3) || (a1==2 && a2==2))
			{
				printf("%d",dakika);
				return 0;
			}
			if(a1<a2)
			{
				a2=a2-2;
				a1++;
			}
			else
			{
				a1=a1-2;
				a2++;
			}
			dakika++;
		}
	}
		return 0;
}


#include<stdio.h>
#include<conio.h>
void cat(int a,int b,int h1, int h2,int d)
{   int pos=0,k=0;
       pos=(a*8)+h1; /*oidin raat 10tay*/
    if(pos>=h2)
    {
        k=d;
        printf("%d",k);
        getch();
    }
    d++;
    pos-=(b*12); /*por din shokal 10tay*/
    pos=pos+a*4; /*pordin dupur 2tay*/
     if(pos>=h2)
    {
        k=d;
        printf("%d",k);
        getch();
    }
    cat(a,b,pos,h2,d);
}

void main()
{
    int a,b,h1,h2,d=0;
    scanf("%d%d",&h1,&h2);
    scanf("%d%d",&a,&b);
	if(a==b)
	{
	printf("%d",d);
	getch();
	}
	if(a<b)
	{
	d=-1;
	printf("%d",d);
	getch();

	}

cat(a,b,h1,h2,d);
getch();
}


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

int main () {

	int a, b;
	int h1, h2;
	int res;

	scanf("%d %d", &h1, &h2);
	scanf("%d %d", &a, &b);
// printf("%d %d\n", h1, h2);
// printf("%d %d\n", a, b);
	if (h1 + 8 * a >= h2) { //alcanca no 1 dia
		printf("0\n");
		return 0;
	}
	if (a < b) {
		printf("-1\n");
		return 0;
	}

	h1 += 8 * a;

	res = (h2 - h1) / ((a - b) * 12);

	h1 += res * (a - b) * 12;

	if (h1 >= h2) {
		if (h1 - 8 * a >= h2)
			res--;
		printf("%d\n", res);
	}
	h1 += (a - b) * 12;
	res++;
	if (h1 >= h2) {
		if (h1 - 8 * a >= h2)
			res--;
		printf("%d\n", res);
	}

	return 0;

}


#include<stdio.h>
int main()
{
	int a,b,c,d,e;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+8*c>=b)
	{
		printf("0\n");
		goto jump;
	}
	else if(c<d)
	{
		printf("-1\n");
		goto jump;
	}
	else
	{
		e=2*(b-a-8*c)/(c-d);
	}
	int f=e%24;
	if(f<=2)
	{
		printf("%d\n",e/24);
	}
	else
		printf("%d\n",e/24+1);
	jump:
	return 0;
}


#include <stdio.h>

main()
{
    long long int i;
    long long int a,b,temp;
    scanf("%I64d %I64d",&a,&b);
    for(i=1; (a != b) && a>0 && b>0; i++)
    {
        if( a % b == 0)
        {
            i += (a/b)-1;
            break;
        }
        a = a - b;
        if(a < b)
        {
            temp = a;
            a = b;
            b = temp;
        }
    }
    printf("%I64d\n",i);
    return 0;
}


#include<stdio.h>
static unsigned  long long count;

int  main()
{
  unsigned  long long b,l;
  count=0;
  scanf("%lld %lld",&b,&l);
  display(b,l);
  printf("%lld",count);
  return 0;
}
display(unsigned long long  b,unsigned long long  l)
{
  if(l==1)
    {
      count=count+b;
      return;
    }
  if(b==1)
    {
      count=count+l;
      return;
    }
  if(b==l)
    {
      count++;
    return;
    }
  else
    {
      count++;
      if(l>b)
    {
      return(display(b,l-b));
    }
      else
    {
      return(display(b-l,l));
    }
    }
}


#include <stdio.h>
#include<string.h>
#include<math.h>
int min(int a,int b)
{
	return a>b?b:a;
}

int main() {
	long long int a,b,c=0;
	scanf("%lld %lld",&a,&b);

	while(a>0 && b>0)
	{
		if(b==1)
		{
			c+=a;
			break;
		}

		c++;
		a=a-b;

		if(a<b)
		{
			long long int t=a;
			a=b;
			b=t;
		}
		//printf("%lld %lld\n",a,b);
	}

	printf("%lld\n",c);
return 0;
}


#include <stdio.h>
#include <conio.h>

long long a, b;
int main()
{
    scanf("%I64d %I64d",&a,&b);
    long long sqr_count=0;
    while(b>0)
    {
        sqr_count+=(a/b);
        long long temp2=(a%b);
        a=b;
        b=temp2;

    }
    printf("%I64d\n",sqr_count);
    getch();
    return 0;
}


#include <stdio.h>
#include <conio.h>

long long a, b;
int main()
{
    scanf("%I64d %I64d",&a,&b);
    long long sqr_count=0;
    while(b>0)
    {
        sqr_count+=(a/b);
        long long temp2=(a%b);
        a=b;
        b=temp2;

    }
    printf("%I64d",sqr_count);
    getch();
    return 0;
}


#include<stdio.h>
int main()
{
    long long int i,a,b,c,d,e;
    int count;
    scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
    for(i=1;i<e;i++){
        if(i%a==0 || i%b==0 || i%c==0 || i%d==0)
            count++;
    }
    printf("%d",count);
    return 0;
}


#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>
main()
{
	int a,b,c=0,n,m,max;
	while(scanf("%d %d",&n,&m))
	{
	max=n;
	if(max<m)max=m;
	for(c=0,a=0;a<=max;a++)
		for(b=0;b<=max;b++)
		{
			if(a*a+b!=n)continue;
		if(a+b*b==m)c++;
		}
	printf("%d\n",c);
	}
}


#include<stdio.h>
int main()
{
    int n,m,l,count=0,i,j;
    scanf("%d%d",&n,&m);
    if (n>m){

        l=n*n;
    }
    else {
        l=m*m;
    }

    for (i=0;i<=l;i++){
    for (j=0;j<=l;j++){
        if ((i*i)+j==n && i+(j*j)==m){
               count++;
        }
    }
    }
    printf("%d",count);
    return 0;

}


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

     int a,b,c;

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

     int i,m;
    int counter=0;
     for(i=0;i<=a*b;i++){
            for(m=0;m<=a*b;m++){
                    if( ((i*i) + m == a) && ( i + (m*m))==b)
                        counter++;

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

    }


#include<stdio.h>
#include<stdlib.h>
int min(int a,int b)
{
    if(a<b)
       return a;
    else
        return b;
}
int main(void)
{
      int n,m,a,b,flag,f;
      while(scanf("%d %d",&n,&m)!=EOF)
      {
          flag=0;
          f=min(n,m);
          for(a=0;a<=f;a++){
            for(b=0;b<min(n,m);a++)
            {
                 if((a*a+b==n)&&(a+b*b==m))
                     flag++;
            }}
          printf("%d\n",flag);
      }
      system("pause");
      return 0;
}


#include <stdio.h>

int main() {
    int a,m,mod,t,i;
    int vis[100005];
    scanf("%d",&a);
    scanf("%d",&m);
    for(i=0;i<m;i++)
    vis[i]=0;
    mod=a%m;
    while(mod!=0)
    {
    	if(vis[mod]!=0)
    	break;
    	vis[mod]=1;
    	a=a+mod;
    	mod=a%m;
    }
    if(mod==0)
    printf("Yes\n");
    else if(vis[mod]!=0)
    printf("No\n");
	return 0;
}


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

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

   char s[100010] = {0};
   int r = x, yes = 0;
   do{
      if(r % m == 0){
         yes = 1;
         break;
      }else{
         if(s[r % m] == 0){
            s[r % m] = 1;
         }else break;
      }
      r += r % m;
   }while(1);

   puts( yes ? "Yes" : "No" );

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


#include <stdio.h>
int arr[1000001];
int main(void) {
    // your coe goes here
    int a,b,i;
    for(i=1;i<1000001;i++)
    arr[i]=0;
    while(1)
    {
        if(a%b==0)
        {

            printf("Yes\n");
            break;
        }
        if(arr[a%b]==1)
        {
        printf("No\n");
        break;
        }
        arr[a%b]=1;
        a=a+(a%b);
        printf("%d ",a);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,m,flag=0,p,a,count[100001],i;
    scanf("%d %d",&n,&m);
    for(i=0;i<=100000;i++)
    {
        count[i]=0;
    }
    a=n;
    p=n%m;
    while(count[p]!=1)
    {
        count[p]=1;
        if(p==0)
        {
            flag=1;
            break;
        }
        else
        {
            a=a+p;
            p=a%m;
          //  count[p]=1;
        }
    }
    if(flag==1)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


#include<stdio.h>

int main()
{
    int a,m,mod,ta;

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

    ta=a;

    do
    {
        mod=ta%m;

        if(mod==0)
        {
            printf("Yes");
            break;
        }

        ta=ta+mod;

        if(ta==m)
        {
            printf("Yes");
            break;
        }

        mod=ta%m;

        if(mod==0)
        {
            printf("Yes");
            break;
        }

        if(ta>mod)
        {
            printf("No");
            break;
        }

    }

    while(mod);

    return 0;

}


#include<stdio.h>

int main()
{
    long long a,b,c;

    scanf("%lld %lld %lld",&a,&b,&c);
    if((a==b&&c==0)||( (b-a)% c == 0&&(b-a)/c >=0 ))
            printf("YES\n");
    else printf("NO\n");

    return 0;
}


#include<stdio.h>
int main()
{long long int a,b,c;
    scanf("%lld%lld%lld",&a,&b,&c);
    if(c==0)
    {
        if(a==b)printf("YES\n");
        else printf("NO\n");
    }
    if((b-a)%c==0)
    {
        printf("YES\n");
    }
    else printf("NO\n");
    return 0;
}


#include<stdio.h>
#include<math.h>
 main()
 {
     unsigned long long int a,b,c,d,e;

     while(scanf("%llu%llu%llu",&a,&b,&c)!=EOF){
    e=b-a;
    if(e!=0 && c==0)
        printf("NO\n");
    else if(e==0 && c==0)
        printf("YES\n");
    else if(e%c==0)
        printf("YES\n");
    else
        printf("NO\n");

} }


#include<stdio.h>
int main()
{
    long long a,b,c,s,i,j,k,l=1;
    scanf("%lld%lld%lld",&a,&b,&c);
    s=a;
    if(c>0)
    {
    for(;;)
    {
        if(s==b)
        break;
        s=s+c;
        if(s>b)
        {
            l=0;
            break;
        }
    }
    }
    else if(c==0)
    {
        if(a!=b)
        l=0;

    }
    else
    {
        for(;;)
        {
            if(s==b)
            break;
            s=s+c;
            if(s<b)
            {
                l=0;
                break;
            }
        }
    }
    if(l==0)
    printf("NO");
    else
    printf("YES");
}


#include <stdio.h>
int main()
{
    int t,x,sum,i,j,k,flag;
    scanf("%d",&t);
	while(t--)
	{
		sum=0;flag=0;
    	scanf("%d",&x);
    	for(i=1;i<10;i++)
	{
		t=i;
		for(j=1;j<5;j++)
		{
			if(flag!=0) t=t*10+i;
			flag++;
			sum+=j;
			if(x==1) goto out;
			else if((t-1)/10==x) goto out;
		}
	}
	out:
		printf("%d\n",sum);
	}
    return 0;
}


#include <stdio.h>
int main()
{
    int t,x,sum,i,j,k,flag;
    while(~scanf("%d",&t))
    {
	while(t--)
	{
		sum=0;flag=0;
    	scanf("%d",&x);
    	for(i=1;i<10;i++)
	{
		t=i;
		for(j=1;j<5;j++)
		{
			if(flag!=0) t=t*10+i;
			flag++;
			sum+=j;
			if(x==1) goto out;
			else if((t-1)/10==x) goto out;
		}
	}
	out:
		printf("%d\n",sum);
	}
    }
    return 0;
}


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

int primes[1000];
int p_ind;

unsigned char * declare_bool(int n)
{
	return (unsigned char *)(malloc(n/8+(n%8!=0)));
}

void assign_bool(unsigned char *array, int pos, int val)
{
	 int i, ii, temp;
	i = pos/8;
	ii = pos-(i*8);
	temp = 255;/**128 64 32 16 8 4 2 1**/
	if(val)
	{
		array[i] = array[i]|(1<<(7-ii));
	}else{
		temp = temp^(1<<(7-ii));
		array[i] = array[i]&temp;
	}
}

unsigned char access_bool(unsigned char *array, int pos)
{
	int i, ii;
	i = pos/8;
	ii = pos-(i*8);
	if(array[i]&(1<<(7-ii)))
		return 1;
	else
		return 0;
}

void sieve()
{
	unsigned char *is_not_prime;
	is_not_prime = declare_bool(1001);
	int i;
	p_ind = 0;
	assign_bool(is_not_prime, 0, 1);
	assign_bool(is_not_prime, 1, 1);
	for(i=2; i<1001; i++)
		assign_bool(is_not_prime, i, 0);
	for(i=0; i<1001; i++)
	{
		if(!access_bool(is_not_prime, i))
		{
			primes[p_ind++] = i;
			int j;
			for(j=i+i; j<=1000; j+=i)
			{
				assign_bool(is_not_prime, j, 1);
			}
		}
	}
}

int main()
{
	int n, i, p_d_i, selected_i;
	int op, nn;
	scanf("%d", &n);
	sieve();
	op = 0;
	nn = 1;
	int *prime_divisors = malloc(p_ind*4);
	p_d_i = 0;
	for(i=0; i<p_ind; i++)
	{
		if(n%primes[i]==0)
		{
			nn*=primes[i];
			prime_divisors[p_d_i++] = primes[i];
		}
		if(primes[i]*primes[i]>n)
			break;
	}
	int *exp = malloc(p_d_i*4);
	for(i=0; i<p_d_i; i++)
		exp[i] = 0;
	selected_i = 0;
	while(n>1)
	{
		if(n%prime_divisors[selected_i]==0)
		{
			exp[selected_i]++;
			n/=prime_divisors[selected_i];
		}
		else
			selected_i++;
	}
	int max_exp;
	max_exp = 0;

	for(i=0; i<p_d_i; i++)
	{
		if(exp[i]>max_exp)
			max_exp = exp[i];
	}
	for(i=0; i<p_d_i; i++)
	{
		if(exp[i]!=max_exp)
		{
			op++;
			break;
		}
	}
	if(op==0 && max_exp!=(1<<((int)log2(max_exp))))
		op++;
	op+=((ceil(log2(max_exp))));
	printf("%d %d", nn, op);
	return 0;

}


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

int primes[10000];
int p_ind;

unsigned char * declare_bool(int n)
{
	return (unsigned char *)(malloc(n/8+(n%8!=0)));
}

void assign_bool(unsigned char *array, int pos, int val)
{
	 int i, ii, temp;
	i = pos/8;
	ii = pos-(i*8);
	temp = 255;/**128 64 32 16 8 4 2 1**/
	if(val)
	{
		array[i] = array[i]|(1<<(7-ii));
	}else{
		temp = temp^(1<<(7-ii));
		array[i] = array[i]&temp;
	}
}

unsigned char access_bool(unsigned char *array, int pos)
{
	int i, ii;
	i = pos/8;
	ii = pos-(i*8);
	if(array[i]&(1<<(7-ii)))
		return 1;
	else
		return 0;
}

void sieve()
{
	unsigned char *is_not_prime;
	is_not_prime = declare_bool(10001);
	int i;
	p_ind = 0;
	assign_bool(is_not_prime, 0, 1);
	assign_bool(is_not_prime, 1, 1);
	for(i=2; i<10001; i++)
		assign_bool(is_not_prime, i, 0);
	for(i=0; i<10001; i++)
	{
		if(!access_bool(is_not_prime, i))
		{
			primes[p_ind++] = i;
			int j;
			for(j=i+i; j<=10000; j+=i)
			{
				assign_bool(is_not_prime, j, 1);
			}
		}
	}
}

int main()
{
	int n, i, p_d_i, selected_i;
	int op, nn;
	scanf("%d", &n);
	sieve();
	op = 0;
	nn = 1;
	int *prime_divisors = malloc(p_ind*4);
	p_d_i = 0;
	for(i=0; i<p_ind; i++)
	{
		if(n%primes[i]==0)
		{
			nn*=primes[i];
			prime_divisors[p_d_i++] = primes[i];
		}

	}
	int *exp = malloc(p_d_i*4);
	for(i=0; i<p_d_i; i++)
		exp[i] = 0;
	selected_i = 0;
	while(n>1 && p_d_i>0)
	{
		if(n%prime_divisors[selected_i]==0)
		{
			exp[selected_i]++;
			n/=prime_divisors[selected_i];
		}
		else
			selected_i++;
	}
	int max_exp;
	max_exp = 0;

	for(i=0; i<p_d_i; i++)
	{
		if(exp[i]>max_exp)
			max_exp = exp[i];
	}
	for(i=0; i<p_d_i; i++)
	{
		if(exp[i]!=max_exp)
		{
			op++;
			break;
		}
	}
	if(op==0 && max_exp!=(1<<((int)log2(max_exp))))
		op++;
	op+=((ceil(log2(max_exp))));
	if(p_d_i==0)
	{
		nn = n;
		op = 0;
	}
	printf("%d %d", nn, op);
	return 0;

}


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

int primes[10000];
int p_ind;

unsigned char * declare_bool(int n)
{
	return (unsigned char *)(malloc(n/8+(n%8!=0)));
}

void assign_bool(unsigned char *array, int pos, int val)
{
	 int i, ii, temp;
	i = pos/8;
	ii = pos-(i*8);
	temp = 255;/**128 64 32 16 8 4 2 1**/
	if(val)
	{
		array[i] = array[i]|(1<<(7-ii));
	}else{
		temp = temp^(1<<(7-ii));
		array[i] = array[i]&temp;
	}
}

unsigned char access_bool(unsigned char *array, int pos)
{
	int i, ii;
	i = pos/8;
	ii = pos-(i*8);
	if(array[i]&(1<<(7-ii)))
		return 1;
	else
		return 0;
}

void sieve()
{
	unsigned char *is_not_prime;
	is_not_prime = declare_bool(10001);
	int i;
	p_ind = 0;
	assign_bool(is_not_prime, 0, 1);
	assign_bool(is_not_prime, 1, 1);
	for(i=2; i<10001; i++)
		assign_bool(is_not_prime, i, 0);
	for(i=0; i<10001; i++)
	{
		if(!access_bool(is_not_prime, i))
		{
			primes[p_ind++] = i;
			int j;
			for(j=i+i; j<=10000; j+=i)
			{
				assign_bool(is_not_prime, j, 1);
			}
		}
	}
}

int main()
{
	int n, i, p_d_i, selected_i;
	int op, nn;
	scanf("%d", &n);
	sieve();
	op = 0;
	nn = 1;
	int *prime_divisors = malloc(p_ind*4);
	p_d_i = 0;
	for(i=0; i<p_ind; i++)
	{
		if(n%primes[i]==0)
		{
			nn*=primes[i];
			prime_divisors[p_d_i++] = primes[i];
		}

	}
	int *exp = malloc(p_d_i*4);
	for(i=0; i<p_d_i; i++)
		exp[i] = 0;
	selected_i = 0;
	while(n>1)
	{
		if(n%prime_divisors[selected_i]==0)
		{
			exp[selected_i]++;
			n/=prime_divisors[selected_i];
		}
		else
			selected_i++;
	}
	int max_exp;
	max_exp = 0;

	for(i=0; i<p_d_i; i++)
	{
		if(exp[i]>max_exp)
			max_exp = exp[i];
	}
	for(i=0; i<p_d_i; i++)
	{
		if(exp[i]!=max_exp)
		{
			op++;
			break;
		}
	}
	if(op==0 && max_exp!=(1<<((int)log2(max_exp))))
		op++;
	op+=((ceil(log2(max_exp))));
	printf("%d %d", nn, op);
	return 0;

}


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

#define SIZE 1000

void factorization (int n, int p[], int k[], int *sz)
{
	int d;

	*sz = 0;

	for (d = 2; d * d <= n; d++)
		if (n % d == 0)
		{
			p[*sz] = d;

			while (n % d == 0)
			{
				k[*sz]++;
				n /= d;
			}

			(*sz)++;
		}

	if (n != 1)
	{
		p[*sz] = n;
		k[(*sz)++] = 1;
	}
}

int is_power_of_two (int n)
{
	while (n % 2 == 0)
		n /= 2;

	return n == 1;
}

int is_need_mult (int p[], int k[], int sz)
{
	int i;

	if (is_power_of_two (k[0]))
		for (i = 1; i < sz; i++)
			if (k[i] != k[i - 1])
				return 1;
			else
				k[i] = k[i];
	else
		return 1;

	return 0;
}

int oper (int p[], int k[], int sz)
{
	int i, cnt = 0, max = 0;

	for (i = 0; i < sz; i++)
		if (k[i] > max)
			max = k[i];

	i = 0;

	while (1 << i < max)
		i++;

	cnt = i;

	if (is_need_mult (p, k, sz))
		cnt++;

	return cnt;
}

int min_num (int p[], int sz)
{
	int i, min = 1;

	for (i = 0; i < sz; i++)
		min *= p[i];

	return min;
}

int main()
{
	int n, i, sz, oper_cnt, p[SIZE] = {0}, k[SIZE] = {0};

	scanf ("%d", &n);

	factorization (n, p, k, &sz);

	oper_cnt = oper (p, k, sz);

	printf ("%d %d\n", min_num (p, sz), oper_cnt);

	return 0;
}


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

int main()
{

int trouve=0;
long long y;
scanf("%I64d",&y);
int s;
while(trouve == 0)
{

	while(y!=0)
	{
		y=y/10;
		s+=y%10;
	if(s==10)
	{
		printf("%I64d",y);
		trouve=1;
		break;
	}
	else
		y++;
	}

}
return 1;
}


#include <stdio.h>
int calcul(int a){
    int k=0;
if (a/10==0){
    return(k+a%10);
}
else {
return(k+(a%10)+calcul((a-(a%10))/10));}
}
int main(){
long long a,k;
int i,c=19,t[1000];

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

while(calcul(c)!=10){
        c++;
}
t[i]=c;
c++;
}
printf("%d",t[k-1]);

}


#include <stdio.h>
int t[1000];
int calcul(int a){
    int k=0;
if (a/10==0){
    return(k+(a%10));
}
else {
return k+(a%10)+calcul((a-(a%10))/10);}
}
int main(){
int a,k;
int i,c=19;

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

while(calcul(c)!=10){
        c++;
}
t[i]=c;
c++;
}
printf("%d",t[k-1]);

}


#include <stdio.h>

int main()
{
    long long n, a, b, c, ans;
    scanf("%I64d %I64d %I64d %I64d", &n, &a, &b, &c);
    if(b - c >= a) {
        ans = n / a;
    } else {
        if(n < b) {
            ans = n / a;
        } else {
            ans = 0;
            while(1) {
                long long cnt = n / b;
                if(cnt == 0) {
                    break;
                }
                ans += cnt;
                n = n + (c - b) * cnt;
            }
            ans += n / a;
        }
    }
    printf("%I64d\n", ans);
    return 0;
}


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

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

long long n, a, b, c;

long long run(long long n){
    long long x, y, z, w, res = 0;
    x = b - c;
    if (a < x || b > n) res = n / a;
    else{
        while (n >= b){
            y = n / b;
            res += y;
            n -= (y * b);
            n += (y * c);
        }

        z = n / a;
        res += z;
    }
    return res;
}

int main(){
    while (scanf("%lld", &n) != EOF){
        scanf("%lld %lld %lld", &a, &b, &c);
        long long res = run(n);
        printf("%lld\n", res);
    }
    return 0;
}


#include<stdio.h>

int main()
{
	long long int n,a,b,c,gla,bol,num,mon;

	while(scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c) != EOF)
	{

		bol = 0;
		if( b-c > a)
	    	bol = n / a;
		else
		{
			for(gla = 0; n >= b;)
		    {
			    gla=n / b;
		    	n=n + (c - b) * gla;
		    	bol=bol + gla;
		    }

		    bol = bol + n / a;

		}
		printf("%I64d\n",bol);
	}

	return 0;
}


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

long long max1(long long n, long long a, long long b, long long c) {

	long long res = 0, t;
	while (n >= b) {
		t = n / b;
		res += t;
		n = n % b + t * c;
	}

	res += n / a;

	return res;

}

int main () {

	long long n, a, b, c;
	long long max = 0;

	long long good;

	scanf("%I64d %I64d %I64d %I64d", &n, &a, &b, &c);

	good = b - c;

	if (n < b) {
		max = n / a;
	} else if (n < a) {
		max = max1(n, a, b, c);
	} else {

		if (good < a) {

			max = max1(n, a, b, c);

		} else {
			max = n / a;
		}
	}

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

	return 0;

}


#include<stdio.h>
int main()
{
	long long int n,a,b,c,ans=0,x,y,r;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n<a && n<b)
	ans=0;
	else{
		if(a<=b-c)
		ans=n/a;
		else{
			x=((n-b)/(b-c))+1;
			r=n-(b-c)*x;
			ans=x+r/a;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include <stdio.h>

#define MAX_N 101

typedef struct {
    int values[6];
} perf_count;

int abs(int x) {
    return x < 0 ? -x : x;
}

// assumption: academic performance is in [1..5]
perf_count read_academic_perf_fast(int n) {
    char line[MAX_N * 2];
    // n times: read ac.perf. (one char) + one space / final '\n'
    fread(line, sizeof(char), n * 2, stdin);
    // "parse" & count:
    perf_count result = {.values = {0}};
    for (int i = 0; i < n; ++i) {
        int perf = line[i*2] - '0';
        result.values[perf] += 1;
    }
    return result;
}

int solve(perf_count a_count, perf_count b_count) {
    int sum = 0;
    for (int i = 1; i <= 5; ++i) {
        int d = abs(a_count.values[i] - b_count.values[i]);
        if (d % 2 == 1) {
            return -1;
        }
        sum += d;
    }
    return sum / 4;
}

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

    perf_count a_count = read_academic_perf_fast(n);
    perf_count b_count = read_academic_perf_fast(n);

    int ans = solve(a_count, b_count);

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

    return 0;
}


/*
    �Ȃ��Α��Ȃ�Ƃ��Ȃ�I
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#define LLU unsigned long long int
#define LL long long int
#define LD long double

#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define debug printf("asd\n")
#define newline printf("\n")

#define amt(a) int a;scanf("%d",&a)
#define dlld(a,b) long long int a,b;scanf("%I64d %I64d",&a,&b)
#define scd(a) int a;scanf("%d",&a)
#define sclld(a) long long int a;scanf("%I64d",&a)
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define arr(a,b) int *a=(int *)malloc(n*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(n*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	amt(n);
	int a[20000],b[20000];
	int c[7],d[7];
	for(int i=0 ; i<6 ; i++)
	{
		c[i]=0;
		d[i]=0;
	}
	for(int i=0 ; i<n ;i++)
	{
		scanf("%d",&a[i]);
		c[a[i]]++;
	}
	for(int i=0 ; i<n ; i++)
	{
		scanf("%d",&b[i]);
		d[b[i]]++;
	}

	int e=0;
	int f=0,g=0;
	if(n==1)
	{
		f+=a[0];
		g+=b[0];
	}
	else if(n>1)
	{
		/*for(int i=1 ; i<=5 ; i++)
		{
			printf("%d %d\n",c[i],d[i]);
		}*/
		for(int i=1 ; i<=5 ; i++)
		{
			while(c[i]!=d[i])
			{
				if(c[i]>d[i])
				{
					c[i]--;
					d[i]++;
				}
				else if(c[i]<d[i])
				{
					c[i]++;
					d[i]--;
				}
				e++;
			}
			f+=c[i]*i;
			g+=d[i]*i;
		}
		e/=2;
	}

	if(f==g)
	prd(e);
	else
	prd(-1);
	return 0;
}


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

int main(){

    int i=1, n, j;
    char*string;

    scanf("%d",&n);
    string=(char*)calloc(n+1, sizeof(char));

    scanf("%s", string);

    do{
        if((string[i]=='a' || string[i]=='o' || string[i]=='u' || string[i]=='e' || string[i]=='i' || string[i]=='y') && (string[i-1]=='a' || string[i-1]=='o' || string[i-1]=='u' || string[i-1]=='e' || string[i-1]=='i' || string[i-1]=='y')){
                for(j=i; j<n; j++){
                        string[j]=string[j+1];
                }
        }
        else
            i++;

    }while(i!=n);
    printf("%s", string);
    return(0);
}


#include <stdio.h>
#include <unistd.h>

void	ft_putchar(char c)
{
	write (1, &c, 1);
}

int	ft_is_vowel(char letter)
{
	if (letter == 'a' || letter == 'e' || letter == 'i'
		|| letter == 'o' || letter == 'u' ||letter == 'y')
		return (1);
	else
		return (0);
}

char	ft_word_correction(char *s, int size)
{
	int i;
	int j;
	int flag;

	i = 0;
	j = 0;
	flag = 0;
	while(i < size)
	{
		if (ft_is_vowel(s[i]) == 1)
		{
			flag += 1;
			if (flag < 2)
				ft_putchar(s[i]);
		}
		if (ft_is_vowel(s[i]) == 0)
		{
			ft_putchar(s[i]);
			flag = 0;
		}
		i++;
	}
	ft_putchar('\n');
}

int	main(void)
{

	int n;
	char *s;

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

	ft_word_correction(s, n);
	return (0);
}


#include<stdio.h>
#include <math.h>
int main( )
{
    int x1,y1,x2,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    int x, y;
    x = abs(x1 - x2);
    y = abs(y1 - y2);
    if(x == 0 || y == 0)
        printf("1");
    else
        printf("2");
    if(abs(x - y) % 2 != 0)
        printf(" 0");
    else if(x == y)
        printf(" 1");
    else
        printf(" 2");
    if(x < y)
        printf(" %d\n",y);
    else
        printf(" %d\n",x);
}


#include<stdio.h>
main()
{
    long long n,tn;
 scanf("%lld",&tn);
 for(n=1;n<=tn;n++)
 {

    if(n*(n+1)/2==tn)
    {

        printf("YES");
        return;
    }
 }

  printf("NO");

 return 0;
}


#include <stdio.h>

int main()
{
	int n, i;
	scanf(" %d", &n);
	if(n<56)
	{
		for(i=1; i<11; i++)
			if(i*(i+1)/2 == n)
			{
				printf("YES\n");
				break;
			}
	}
	else if(n<211)
	{
		for(i=11; i<21; i++)
			if(i*(i+1)/2 == n)
			{
				printf("YES\n");
				break;
			}
	}
	else if(n<497)
	{
		for(i=21; i<32; i++)
			if(i*(i+1)/2 == n)
			{
				printf("YES\n");
				break;
			}
	}
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>

int ara[78999999];
int main()
{
    long long int i,j,k,l,m,n,x=0;
    for(i=1,j=1;i<=500;i++,j++){
            x+=j;
        ara[x]=1;

    }

    scanf("%I64d",&n);
    if(ara[n]==1)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;

}


#include <stdio.h>

int CanWeStart(int tank_size, int gas_station, int endpoint);
void GotoEnd(int * tank, int tank_size, int gas_station, int endpoint, int * journey, int * count);
void Goto0(int * tank, int tank_size, int gas_station, int endpoint, int * journey, int * count);

int main(void)
{
    int endpoint, tank, gas_station , journey, tank_size, count;
    scanf("%d %d %d %d",&endpoint, &tank, &gas_station, &journey);
    tank_size = tank;
    count = 0;

    if( CanWeStart(tank_size, gas_station, endpoint) == 0 )
    {
        printf("-1");
        return 0;
    }

    while(journey>0)
    {
        GotoEnd(&tank, tank_size, gas_station, endpoint, &journey, &count);
        if(journey == 0)
            break;
        Goto0(&tank, tank_size, gas_station, endpoint, &journey, &count);
    }

    printf("%d",count);

    return 0;
}

int CanWeStart(int tank_size, int gas_station, int endpoint)
{
    if( tank_size < 2*(endpoint-gas_station) || tank_size < 2*gas_station )
        return 0;
    else
        return 1;
}

void GotoEnd(int * tank, int tank_size, int gas_station, int endpoint, int * journey, int * count)
{
    int YN;
    *tank -= gas_station;
    if( *journey == 1)
    {
        if( (*tank -(endpoint-gas_station)) >= 0 )
            YN = 0;
        else
            YN = 1;
    }
    else
    {
        if( (*tank - 2*(endpoint-gas_station)) >=0 )
            YN = 0;
        else
            YN = 1;
    }
    if(YN == 1)
    {
        *tank = tank_size;
        *count += 1;
    }

    *tank -= (endpoint-gas_station);
    *journey -= 1;
}

void Goto0(int * tank, int tank_size, int gas_station, int endpoint, int * journey, int * count)
{
    int YN;
    *tank -= (endpoint-gas_station);
    if( *journey == 1)
    {
        if( (*tank -gas_station) >= 0 )
            YN = 0;
        else
            YN = 1;
    }
    else
    {
        if( *tank -(2*gas_station) >=0 )
            YN = 0;
        else
            YN = 1;
    }
    if(YN == 1)
    {
        *tank = tank_size;
        *count += 1;
    }

    *tank -= gas_station;
    *journey -= 1;
}


#include<stdio.h>
#include<math.h>
int main()
{
    long long a,b,f,k,u,n,j=0;
    int i=0;
    scanf("%lld %lld %lld %lld",&a,&f,&b,&k);
    u=f;
    n=a*k;
    for(;n>0;)
    {
        if(n==a*k)
        {
            if(f>=b || f>=a-b)
            {
                u-=b;
                n-=b;
            }
            else
            {
                printf("-1");
                return 0;
            }

        }
        if(i==0)
        {
            if(n==a-b)
            {
                if(u>=a-b) break;
                else
                {
                    j++;
                    break;
                }
            }
            if(f<(a-b)*2)
            {
                printf("-1");
                return 0;
            }
            else
            {
                if(u<(a-b)*2)
                {
                    u=f;
                    j++;
                }
                u-=(a-b)*2;
                n-=(a-b)*2;
            }
            if(n==b)
            {
                if(u>=b) break;
                else
                {
                    j++;
                    break;
                }
            }
            if(f<(b)*2)
            {
                printf("-1");//there is a prob
                return 0;
            }
            else
            {
                if(u<(b)*2)
                {
                    u=f;
                    j++;
                }
                u-=(b)*2;
                n-=(b)*2;
            }

        }

    }
    if(j!=0) printf("%lld",j);
    return 0;
}


#include <stdio.h>

int main(void)
{
	int a, b, f, k, j, cnt = 0, rest;
	scanf("%d %d %d %d", &a, &b, &f, &k);
	rest = b;
	for (j = 1; j <= k; j = j + 1)
	{
		int d = j & 1;
		if (j < k)
		{
			if (d)
			{
				if (rest < f)
				{
					cnt = -1;
					break;
				}
				else if (rest >= f)
				{
					if (rest >= (a << 1) - f)
					{
						rest = rest - (a << 1) + f;
					}
					else if (rest < (a << 1) - f)
					{
						if (b < ((a - f) << 1))
						{
							cnt = -1;
							break;
						}
						else if (b >= ((a - f) << 1))
						{
							cnt += 1;
							rest = b - ((a - f) << 1);
						}
					}
				}
			}
			else if (d == 0)
			{
				if (rest < (f << 1) && b < (f << 1))
				{
					cnt = -1;
					break;
				}
				else if (rest < (f << 1) && b >= f)
				{
					cnt += 1;
					rest = b - f;
				}
				else if (rest >= (f << 1))
				{
					rest = rest - f;
				}
			}
		}
		else if (j == k)
		{
			if (d)
			{
				if (rest < f)
				{
					if (b < f)
						cnt = -1;
					else if (b >= f)
						cnt += 1;
				}
				else if (rest >= f)
				{
					if (b < f)
						cnt = -1;
				}
			}
			else if (d == 0)
			{
				if (rest < f && b < f)
					cnt = -1;
				else if (rest < f && b >= f)
					cnt += 1;
			}
		}
	}
	printf("%d", cnt);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
int main(){
int a,b,f,k;
scanf("%d%d%d%d",&a,&b,&f,&k);
int counter=-1;
int position=0;
int fuel = b;
int wway=-1;
int fuelcounter=0;
int test=0;
while(counter<k)
{
    if(position==a || position==0){
        wway *= -1;
        counter++;
        if(counter==k)
            break;

    }
    if(position==f){
        if(wway==1){
            if(fuel>=2*(a-f)){
            }else{
                if(counter+1<k){
                    fuel=b;
                    fuelcounter++;
                }else{
                    if(fuel>=a-f){
                    }else{
                        fuel=b;
                        fuelcounter++;
                    }
                }
            }
        }else{
            if(fuel>=2*f){
            }else{
                if(counter+1<k){
                    fuel=b;
                    fuelcounter++;
                }else{
                    if(fuel>=f){
                    }else{
                        fuel=b;
                        fuelcounter++;
                    }
                }
            }

        }
    }
    if(fuel==0){
        test=1;
        break;
    }
    position += wway;
    fuel--;
}

    if(test==1){
        printf("-1");
    }else{
        printf("%d",fuelcounter);
    }

}


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

typedef struct		s_btree
{
	struct s_btree	*left;
	struct s_btree	*right;
	int				value;
	int				lvl;
}					t_btree;

t_btree	coada[20000000];

t_btree	*ft_create_node(int data)
{
	t_btree	*new;

	new = (t_btree*)malloc(sizeof(t_btree));
	new->left = NULL;
	new->right = NULL;
	new->value = data;
	return (new);
}

int		st, dr;
int		ok, result;

void	bfs(t_btree *node, int m)
{
	t_btree	*new;

	if (node->value == m)
	{
		result = node->lvl;
		ok = 0;
	}
	else
	{
		new = ft_create_node(node->value - 1);
		new->lvl = node->lvl + 1;
		dr++;
		coada[dr] = *new;
		new = ft_create_node(node->value * 2);
		new->lvl = node->lvl + 1;
		dr++;
		coada[dr] = *new;
	}
}

int		main(void)
{
	int		n, m;
	t_btree	*root;

	ok = 1;
	scanf("%d %d", &n, &m);
	root = ft_create_node(n);
	root->lvl = 0;
	st = dr = 1;
	coada[st] = *root;
	while (ok && st <= dr)
	{
		bfs(&coada[st], m);
		st++;
	}
	printf("%d\n", result);
	return (0);
}


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

/*

Vasya has found a strange device. On the front panel of
a device there are: a red button, a blue button and a
display showing some positive integer. After clicking
the red button, device multiplies the displayed number
by two. After clicking the blue button, device subtracts
one from the number on the display. If at some point
the number stops being positive, the device breaks down.
The display can show arbitrarily large numbers.
Initially, the display shows number n.

Bob wants to get number m on the display. What minimum
number of clicks he has to make in order to achieve this result?

Input
The first and the only line of the input contains
two distinct integers n and m (1 <= n, m <= 10000),
separated by a space.

Output
Print a single number � the minimum number of times one
needs to push the button required to get the number m out
of number n.

*/

typedef struct Pair {
    int data;
    int distance;
} Pair;

struct QueueElem{
    Pair pair;
    struct QueueElem* next;
};

Pair makePair(int f, int s){
    Pair p = {f, s};
    return p;
}

typedef struct QueueElem Elem;

struct Queue{
    Elem *front; // sa fronta uklanjam
    Elem *rear; // na rear dodajem
};

typedef struct Queue Queue;

void init(Queue *q){
    q->front = NULL;
    q->rear = NULL;
}

void destroy(Queue *q){ // treba svaki Elem brisat jer je pravljen sa malloc
    free(q->front);
    free(q->rear);
}

int isEmpty(Queue *q){
    return (q->front == NULL && q->rear == NULL);
}

//void print(Queue *q){
//    for(Elem *curr = q->front; curr != NULL; curr = curr->next){
//        printf("%d ", curr->data);
//    }
//    printf("\n");
//}

void enqueue(Queue *q, Pair p){
    Elem *newElem = malloc(sizeof(Elem));
    newElem->pair = p;
    newElem->next = NULL;

    if(q->rear == NULL){
        q->front = newElem;
        q->rear = newElem;
    }
    else{
        q->rear->next = newElem;
        q->rear = newElem;
    }
}

Pair dequeue(Queue *q){
    if(isEmpty(q)){
        return makePair(-10000, -10000);
    }
    Pair temp = q->front->pair;

    Elem *tmp = q->front;
    q->front = q->front->next;
    free(tmp);
    //tmp = NULL;

    if(q->front == NULL){
        q->rear = NULL;
    }
    return temp;
}

Pair peek(Queue *q){
    if(q->front != NULL) return q->front->pair;
    else return makePair(-10000, -10000);
}

// a greedy BFS sounds fine, maybe for small inputs, we'll see
// what code forces says

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

    Queue q1;
    Queue *q = &q1;
    init(q);
    enqueue(q, makePair(n, 0));

    while(!isEmpty(q)){
        Pair curr = dequeue(q);
        if(curr.data == m){
            printf("%d", curr.distance);
            return;
        }
        enqueue(q, makePair(curr.data*2, curr.distance+1));
        if(curr.data-1 >= 0){
            enqueue(q, makePair(curr.data-1, curr.distance+1));
        }
    }
}

int main()
{
    solve();
    return 0;
}


#include<stdio.h>
static int arr[10001][10001];
static int a,b;
static int dp[10001][10001];
int bluered(int n, int m)
{
        if(arr[n][m]==-1)
                return 100001;
        arr[n][m]=-1;
        if(dp[n][m]!=-1)
                return dp[n][m];
        if(n==a && m==b){
                dp[n][m]=1;
                return 1;}

        if(n==m){
                dp[n][m]=0;
                return 0;}
        if(m<n){
                dp[n][m]=n-m;
                return n-m;}
        int count1=1,count2=1;

        count1=count1+ (bluered(n*2,m));
        if(n>1){
        count2=count2+(bluered(n-1,m));}
        if(n<=1){
                dp[n][m]=count1;
        return count1;  }
        if(count1<count2)
        {dp[n][m]=count1;
                return count1;}
        else{
                dp[n][m]=count2;
                return count2;
        }
}

int main()

{
        int i,j;
        for(i=0;i<1001;i++)
        {
                for(j=0;j<1001;j++){
                        arr[i][j]=0;
                        dp[i][j]=-1;
                }
        }
        int a,b;
        scanf("%d %d",&a,&b);
        int count=0;
        count+=bluered(a,b);
        printf("%d",count);
        return 0;
}


/*
 * Copyright (c) 2017-2019 Bailey Thompson
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef CONTAINERS_DEQUE_H
#define CONTAINERS_DEQUE_H

#include <stdlib.h>

/**
 * The deque data structure, which is a doubly-ended queue.
 */
typedef struct internal_deque *deque;

/* Starting */
deque deque_init(size_t data_size);

/* Utility */
int deque_size(deque me);
int deque_is_empty(deque me);
int deque_trim(deque me);
void deque_copy_to_array(void *arr, deque me);

/* Adding */
int deque_push_front(deque me, void *data);
int deque_push_back(deque me, void *data);

/* Removing */
int deque_pop_front(void *data, deque me);
int deque_pop_back(void *data, deque me);

/* Setting */
int deque_set_first(deque me, void *data);
int deque_set_at(deque me, int index, void *data);
int deque_set_last(deque me, void *data);

/* Getting */
int deque_get_first(void *data, deque me);
int deque_get_at(void *data, deque me, int index);
int deque_get_last(void *data, deque me);

/* Ending */
int deque_clear(deque me);
deque deque_destroy(deque me);

#endif /* CONTAINERS_DEQUE_H */

/*
 * Copyright (c) 2017-2019 Bailey Thompson
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <string.h>
#include <errno.h>

static const int BLOCK_SIZE = 8;
static const double RESIZE_RATIO = 1.5;

struct internal_deque {
    size_t data_size;
    int start_index;
    int end_index;
    int block_count;
    struct node *block;
};

struct node {
    void *data;
};

/**
 * Initializes a deque.
 *
 * @param data_size the size of each element in the deque; must be positive
 *
 * @return the newly-initialized deque, or NULL if it was not successfully
 *         initialized due to either invalid input arguments or memory
 *         allocation error
 */
deque deque_init(const size_t data_size)
{
    struct internal_deque *init;
    struct node *block;
    if (data_size == 0) {
        return NULL;
    }
    init = malloc(sizeof(struct internal_deque));
    if (!init) {
        return NULL;
    }
    init->data_size = data_size;
    init->start_index = BLOCK_SIZE / 2;
    init->end_index = init->start_index + 1;
    init->block_count = 1;
    init->block = malloc(sizeof(struct node));
    if (!init->block) {
        free(init);
        return NULL;
    }
    block = init->block;
    block->data = malloc(BLOCK_SIZE * init->data_size);
    if (!block->data) {
        free(init->block);
        free(init);
        return NULL;
    }
    return init;
}

/**
 * Determines the size of the deque. The size is the number of data spaces being
 * used. The size starts at zero, and every time an element is added, it
 * increases by one.
 *
 * @param me the deque to check the size of
 *
 * @return the size of the deque
 */
int deque_size(deque me)
{
    return me->end_index - me->start_index - 1;
}

/**
 * Determines if the deque is empty. It is empty if it has no elements.
 *
 * @param me the deque to check if empty
 *
 * @return 1 if the deque is empty, otherwise 0
 */
int deque_is_empty(deque me)
{
    return deque_size(me) == 0;
}

/**
 * Trims the deque so that it does not use memory which does not need to be
 * used.
 *
 * @param me the deque to trim
 *
 * @return 0       if no error
 * @return -ENOMEM if out of memory
 */
int deque_trim(deque me)
{
    int i;
    /* The start and end blocks are written like this because in C89    */
    /* negative integer division and modulo are implementation-defined. */
    const int start_block =
            me->start_index == -1 ? 0 : me->start_index / BLOCK_SIZE;
    const int end_block =
            me->end_index == 0 ? 0 : (me->end_index - 1) / BLOCK_SIZE;
    const int new_block_count = end_block - start_block + 1;
    void *const new_block = malloc(new_block_count * sizeof(struct node));
    if (!new_block) {
        return -ENOMEM;
    }
    for (i = 0; i < start_block; i++) {
        const struct node block_item = me->block[i];
        free(block_item.data);
    }
    for (i = end_block + 1; i < me->block_count; i++) {
        const struct node block_item = me->block[i];
        free(block_item.data);
    }
    memcpy(new_block,
           &me->block[start_block],
           new_block_count * sizeof(struct node));
    free(me->block);
    me->block = new_block;
    me->block_count = new_block_count;
    me->start_index -= start_block * BLOCK_SIZE;
    me->end_index -= start_block * BLOCK_SIZE;
    return 0;
}

/**
 * Copies the deque to an array. Since it is a copy, the array may be modified
 * without causing side effects to the deque data structure. Memory is not
 * allocated, thus the array being used for the copy must be allocated before
 * this function is called. The size of the deque should be queried prior to
 * calling this function, which also serves as the size of the newly-copied
 * array.
 *
 * @param arr the initialized array to copy the deque to
 * @param me  the deque to copy to the array
 */
void deque_copy_to_array(void *const arr, deque me)
{
    int i;
    for (i = 0; i < deque_size(me); i++) {
        deque_get_at((char *) arr + i * me->data_size, me, i);
    }
}

/**
 * Adds an element to the front of the deque. The pointer to the data being
 * passed in should point to the data type which this deque holds. For example,
 * if this deque holds integers, the data pointer should be a pointer to an
 * integer. Since the data is being copied, the pointer only has to be valid
 * when this function is called.
 *
 * @param me   the deque to add an element to
 * @param data the element to add
 *
 * @return 0       if no error
 * @return -ENOMEM if out of memory
 */
int deque_push_front(deque me, void *const data)
{
    struct node block_item;
    int block_index;
    int inner_index;
    if (me->start_index == -1) {
        block_index = -1;
        inner_index = BLOCK_SIZE - 1;
    } else {
        block_index = me->start_index / BLOCK_SIZE;
        inner_index = me->start_index % BLOCK_SIZE;
    }
    if (inner_index == BLOCK_SIZE - 1) {
        struct node *block_item_reference;
        if (block_index == -1) {
            int i;
            const int old_block_count = me->block_count;
            const int new_block_count =
                    (int) (RESIZE_RATIO * me->block_count) + 1;
            const int added_blocks = new_block_count - old_block_count;
            void *temp = realloc(me->block,
                                 new_block_count * sizeof(struct node));
            if (!temp) {
                return -ENOMEM;
            }
            me->block = temp;
            me->block_count = new_block_count;
            memmove(&me->block[added_blocks],
                    me->block,
                    old_block_count * sizeof(struct node));
            block_index = added_blocks - 1;
            me->start_index += added_blocks * BLOCK_SIZE;
            me->end_index += added_blocks * BLOCK_SIZE;
            for (i = 0; i < added_blocks; i++) {
                struct node *const block_item_copy = &me->block[i];
                block_item_copy->data = NULL;
            }
        }
        block_item_reference = &me->block[block_index];
        if (!block_item_reference->data) {
            block_item_reference->data = malloc(BLOCK_SIZE * me->data_size);
            if (!block_item_reference->data) {
                return -ENOMEM;
            }
        }
    }
    block_item = me->block[block_index];
    memcpy((char *) block_item.data + inner_index * me->data_size, data,
           me->data_size);
    me->start_index--;
    return 0;
}

/**
 * Adds an element to the back of the deque. The pointer to the data being
 * passed in should point to the data type which this deque holds. For example,
 * if this deque holds integers, the data pointer should be a pointer to an
 * integer. Since the data is being copied, the pointer only has to be valid
 * when this function is called.
 *
 * @param me   the deque to add an element to
 * @param data the element to add
 *
 * @return 0       if no error
 * @return -ENOMEM if out of memory
 */
int deque_push_back(deque me, void *const data)
{
    struct node block_item;
    const int block_index = me->end_index / BLOCK_SIZE;
    const int inner_index = me->end_index % BLOCK_SIZE;
    if (inner_index == 0) {
        struct node *block_item_reference;
        if (block_index == me->block_count) {
            int i;
            const int new_block_count =
                    (int) (RESIZE_RATIO * me->block_count) + 1;
            void *temp = realloc(me->block,
                                 new_block_count * sizeof(struct node));
            if (!temp) {
                return -ENOMEM;
            }
            me->block = temp;
            me->block_count = new_block_count;
            for (i = block_index; i < me->block_count; i++) {
                struct node *const block_item_copy = &me->block[i];
                block_item_copy->data = NULL;
            }
        }
        block_item_reference = &me->block[block_index];
        if (!block_item_reference->data) {
            block_item_reference->data = malloc(BLOCK_SIZE * me->data_size);
            if (!block_item_reference->data) {
                return -ENOMEM;
            }
        }
    }
    block_item = me->block[block_index];
    memcpy((char *) block_item.data + inner_index * me->data_size, data,
           me->data_size);
    me->end_index++;
    return 0;
}

/**
 * Removes the front element from the deque and copies it to a data value. The
 * pointer to the data being obtained should point to the data type which this
 * deque holds. For example, if this deque holds integers, the data pointer
 * should be a pointer to an integer. Since this data is being copied from the
 * array to the data pointer, the pointer only has to be valid when this
 * function is called.
 *
 * @param data the value to copy to
 * @param me   the deque to remove from
 *
 * @return 0       if no error
 * @return -EINVAL if invalid argument
 */
int deque_pop_front(void *const data, deque me)
{
    int block_index;
    int inner_index;
    struct node block_item;
    if (deque_is_empty(me)) {
        return -EINVAL;
    }
    me->start_index++;
    block_index = me->start_index / BLOCK_SIZE;
    inner_index = me->start_index % BLOCK_SIZE;
    block_item = me->block[block_index];
    memcpy(data, (char *) block_item.data + inner_index * me->data_size,
           me->data_size);
    return 0;
}

/**
 * Removes the back element from the deque and copies it to a data value. The
 * pointer to the data being obtained should point to the data type which this
 * deque holds. For example, if this deque holds integers, the data pointer
 * should be a pointer to an integer. Since this data is being copied from the
 * array to the data pointer, the pointer only has to be valid when this
 * function is called.
 *
 * @param data the value to copy to
 * @param me   the deque to remove from
 *
 * @return 0       if no error
 * @return -EINVAL if invalid argument
 */
int deque_pop_back(void *const data, deque me)
{
    int block_index;
    int inner_index;
    struct node block_item;
    if (deque_is_empty(me)) {
        return -EINVAL;
    }
    me->end_index--;
    block_index = me->end_index / BLOCK_SIZE;
    inner_index = me->end_index % BLOCK_SIZE;
    block_item = me->block[block_index];
    memcpy(data, (char *) block_item.data + inner_index * me->data_size,
           me->data_size);
    return 0;
}

/**
 * Sets the first value of the deque. The pointer to the data being passed in
 * should point to the data type which this deque holds. For example, if this
 * deque holds integers, the data pointer should be a pointer to an integer.
 * Since the data is being copied, the pointer only has to be valid when this
 * function is called.
 *
 * @param me   the deque to set the value of
 * @param data the data to set
 *
 * @return 0       if no error
 * @return -EINVAL if invalid argument
 */
int deque_set_first(deque me, void *const data)
{
    return deque_set_at(me, 0, data);
}

/**
 * Sets the value of the deque at the specified index. The pointer to the data
 * being passed in should point to the data type which this deque holds. For
 * example, if this deque holds integers, the data pointer should be a pointer
 * to an integer. Since the data is being copied, the pointer only has to be
 * valid when this function is called.
 *
 * @param me    the deque to set the value of
 * @param index the index to set at
 * @param data  the data to set
 *
 * @return 0       if no error
 * @return -EINVAL if invalid argument
 */
int deque_set_at(deque me, int index, void *const data)
{
    int block_index;
    int inner_index;
    struct node block_item;
    if (index < 0 || index >= deque_size(me)) {
        return -EINVAL;
    }
    index += me->start_index + 1;
    block_index = index / BLOCK_SIZE;
    inner_index = index % BLOCK_SIZE;
    block_item = me->block[block_index];
    memcpy((char *) block_item.data + inner_index * me->data_size, data,
           me->data_size);
    return 0;
}

/**
 * Sets the last value of the deque. The pointer to the data being passed in
 * should point to the data type which this deque holds. For example, if this
 * deque holds integers, the data pointer should be a pointer to an integer.
 * Since the data is being copied, the pointer only has to be valid when this
 * function is called.
 *
 * @param me   the deque to set the value of
 * @param data the data to set
 *
 * @return 0       if no error
 * @return -EINVAL if invalid argument
 */
int deque_set_last(deque me, void *const data)
{
    return deque_set_at(me, deque_size(me) - 1, data);
}

/**
 * Gets the first value of the deque. The pointer to the data being obtained
 * should point to the data type which this deque holds. For example, if this
 * deque holds integers, the data pointer should be a pointer to an integer.
 * Since this data is being copied from the array to the data pointer, the
 * pointer only has to be valid when this function is called.
 *
 * @param data the data to set
 * @param me   the deque to set the value of
 *
 * @return 0       if no error
 * @return -EINVAL if invalid argument
 */
int deque_get_first(void *const data, deque me)
{
    return deque_get_at(data, me, 0);
}

/**
 * Gets the value of the deque at the specified index. The pointer to the data
 * being obtained should point to the data type which this deque holds. For
 * example, if this deque holds integers, the data pointer should be a pointer
 * to an integer. Since this data is being copied from the array to the data
 * pointer, the pointer only has to be valid when this function is called.
 *
 * @param data  the data to set
 * @param me    the deque to set the value of
 * @param index the index to set at
 *
 * @return 0       if no error
 * @return -EINVAL if invalid argument
 */
int deque_get_at(void *const data, deque me, int index)
{
    int block_index;
    int inner_index;
    struct node block_item;
    if (index < 0 || index >= deque_size(me)) {
        return -EINVAL;
    }
    index += me->start_index + 1;
    block_index = index / BLOCK_SIZE;
    inner_index = index % BLOCK_SIZE;
    block_item = me->block[block_index];
    memcpy(data, (char *) block_item.data + inner_index * me->data_size,
           me->data_size);
    return 0;
}

/**
 * Gets the last value of the deque. The pointer to the data being obtained
 * should point to the data type which this deque holds. For example, if this
 * deque holds integers, the data pointer should be a pointer to an integer.
 * Since this data is being copied from the array to the data pointer, the
 * pointer only has to be valid when this function is called.
 *
 * @param data the data to set
 * @param me   the deque to set the value of
 *
 * @return 0       if no error
 * @return -EINVAL if invalid argument
 */
int deque_get_last(void *const data, deque me)
{
    return deque_get_at(data, me, deque_size(me) - 1);
}

/**
 * Clears the deque and sets it to the original state from initialization.
 *
 * @param me the deque to clear
 *
 * @return 0       if no error
 * @return -ENOMEM if out of memory
 */
int deque_clear(deque me)
{
    void *temp_block_data;
    int i;
    struct node *block;
    struct node *const temp_block = malloc(sizeof(struct node));
    if (!temp_block) {
        return -ENOMEM;
    }
    temp_block_data = malloc(BLOCK_SIZE * me->data_size);
    if (!temp_block_data) {
        free(temp_block);
        return -ENOMEM;
    }
    for (i = 0; i < me->block_count; i++) {
        const struct node block_item = me->block[i];
        free(block_item.data);
    }
    free(me->block);
    me->start_index = BLOCK_SIZE / 2;
    me->end_index = me->start_index + 1;
    me->block_count = 1;
    me->block = temp_block;
    block = me->block;
    block->data = temp_block_data;
    return 0;
}

/**
 * Destroys the deque. Performing further operations after calling this function
 * results in undefined behavior.
 *
 * @param me the deque to destroy
 *
 * @return NULL
 */
deque deque_destroy(deque me)
{
    int i;
    for (i = 0; i < me->block_count; i++) {
        const struct node block_item = me->block[i];
        free(block_item.data);
    }
    free(me->block);
    free(me);
    return NULL;
}

/**************************************************************************************/

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

struct pair {
	int n;
	int curCost;
};

static int minCost(int start_n, int m)
{
	struct pair pair = { .n = start_n, .curCost = 0 };
	deque d = deque_init(sizeof(struct pair));
	deque_push_back(d, &pair);
	while (!deque_is_empty(d)) {
		deque_pop_front(&pair, d);
		int n = pair.n;
		int curCost = pair.curCost;
		if (n > 2 * m || n < 1) {
			continue;
		}
		if (n == m) {
			return curCost;
		}
		pair.curCost = curCost + 1;
		pair.n = n - 1;
		deque_push_back(d, &pair);
		pair.n = 2 * n;
		deque_push_back(d, &pair);
	}
	return -12;
}

int main(void)
{
	int n;
	int m;
	scanf("%d %d", &n, &m);
	if (n >= m) {
		printf("%d\n", n - m);
		return 0;
	}
	int min = minCost(n, m);
	printf("%d\n", min);
}


#include<stdio.h>
#include<conio.h>
int main()
{
	long  int a,n,s=0,b,n1;
	int rev=0;
	scanf("%ld",&n);
	a=n;
	//b=n;
	while(a!=0)
	{
		n=a;
		n=n%10;
		if(n>=5&&n<=9)
		{
			n=9-n;
			s=s*10+n;
		}
		else
		{
			s=s*10+n;
		}
		a=a/10;
	}
	while(s!=0)
	{
		rev=rev*10+s%10;
		s=s/10;
	}

	printf("%ld",rev);

}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <malloc.h>
#include <stdbool.h>
#include <time.h>
#include <ctype.h>
#define maxn 10000000 + 10

typedef long long ll;

int Arr[maxn];

int main()
{
    ll n, i, tmp, tot, cnt, _sum;
    int tmp1;
    while( ~scanf( "%I64d", &n ) )
    {
        tot = cnt = _sum = 0;
        tmp = n;
        while(tmp)
        {
            tot ++;
            tmp /= 10;
        }
        _sum = pow( (double)10, (double)tot );

        for( i = 1; i <= tot; i ++ )
        {

            tmp1 = n / ( _sum / 10 );
			if( i == 1 && tmp1 == 9 )
			{
				tmp1 = 9;
			}
			else
				tmp1 = abs( 9 - tmp1 ) < tmp1 ? abs( 9 - tmp1 ) : tmp1;
			//printf( "%d", tmp1 );
			Arr[ cnt ++ ] = tmp1;
        	n = n - n / ( _sum / 10 ) * ( _sum / 10 );
        	_sum /= 10;
        }
        for( i = 0; i < cnt; i ++ )
            printf( "%d", Arr[i] );
		printf( "\n" );

    }
    return 0;
}


#include <stdio.h>

int main(void)
{
		long long int i = 0;
		char c;
		int count = 0;

		while ((c = getchar()) == 9){
				i = (i*10) + 9;

		while(c != '\n'){
				i *= 10;
				if (c - '0' > 4 && c != '9')
						i += 9 - (c - '0');
				else
						i += (c - '0');
				c = getchar();
		}
		printf("%I64d\n", i);
		return 0;
}


#include<math.h>
main()
{
        float n,m,a;
         int h;
         scanf("%f%f%f",n,m,a);
       for(n>0,m>0,a>0)
       {
         h=ceil(n/a)*ceil(m/a);
       printf("%d",h);
}


#include<iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	long long int ans = ((a%c == 0) ? (a / c) : (a / c + 1))*((b%c == 0) ? (b / c) : (b / c + 1));
	cout << ans << endl;
	return 0;
}


#include<stdio.h>
int main(){
    double n,m,a;
    scanf("%d",&n);
    scanf("%d",&m);
    scanf("%d",&a);

    int x=n%a;
    int y=m%a;
    double x1,y1;
    if(x==0){
        x1=n/a;

    }
    else{
        x1=n/a+1;
    }

    if(y==0){
        y1=m/a;
    }
    else{
        y1=m/a+1;
    }
    double result=x1*y1;
    printf("%d",result);

    return 0;
}


#include<math.h>
main()
{
 float n,m,a;
int h;
scanf("%f%f%f",&n,&m,&a);
for(n>0,m>0,a>0)
{
h=ceil(n/a)*ceil(m/a);
}
printf("%d",h);
}


#include <stdio.h>
#include<conio.h>
int main ()
{
    int n;
    int m;
    int a;

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

    long long flagsByRow;

    if (n % a == 0) {
        flagsByRow = n / a;

    } else {
        flagsByRow = n / a;
        flagsByRow++;

    }

    long long flagsByColumn;

    if (m % a == 0) {
        flagsByColumn = m / a;

    } else {
        flagsByColumn = m / a;
        flagsByColumn++;

    }

    cout << flagsByRow * flagsByColumn << endl;

    return 0;
}


#include<stdio.h>
#include<math.h>
int main(){
    int k,j,l,m,n,o,p,q;
    int r;
    q=0;
    scanf("%d",&n);
    for(j=4;j<500;j++){
        o=0;
        p=0;

        for(r=j;r>0;){
        k=r%10;
        r=r/10;
        if(k==4 || k==7){
            m=k*pow(10,p);
            o=o+m;
            p++;
            if(n%o==0){
                printf("YES");
                q++;
                return 0;
            }
        }
            else
            break;

        }
    }
    if(q==0)
    printf("NO");
    return 0;


#include<stdio.h>

int islucky(int n){

    while(n!=0){
        if(n%10==7||n%10==4){
            i=0;
        }
        else
        {
            i=1;
            break;
        }
    }
    if(i=0)
    return 1;
    else
    return 0;
}

int main(){
unsigned int n;
scanf("%d",&n);
int i,j;
for(i=1;i<=n;i++){
    if(islucky(i)){
        if(n%i == 0){
        printf("YES");
        return 0;}
        else{
        printf("NO");
        return 0;}
    }
}
if(i==n+1)
printf("NO");

}


include<stdio.h>
#include<string.h>
int main()
{
    char a[250];
    int n,i;
    scanf("%s",&a);
    n=strlen(a);
    for(i=0;i<n;i++)
    {
        if(a[i]=='.')
        {
            printf("0");
        }
        else if(a[i]=='-' && a[i+1]=='.')
        {
            printf("1");
        }
        else if(a[i]=='-' && a[i+1]=='-')
        {
            printf("2");
        }
        else
        break;
    }
    return 0;
}


#include<stdio.h
int main()
{
    int n,count=0,max=0,maxn,i,j;
    scanf("%d",&n);
    char s[n+1];
    scanf("%s",s);
    for(i=1;i<n;i++){
    count=0;
    for(j=i;j<n;j++)
        if(s[i-1]==s[j-1]&&s[i]==s[j])
        count++;
        if(count>max){
            max=count;
            maxn =i ; }
    }
    printf("%c%c",s[maxn-1],s[maxn]);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;

#define N   100

int main()
{
    static char cc[N];
    static int kk[676];
    int n, i, max, amax;
    scanf("%d", &n);
    scanf("%s", cc);
    max = 0;
    amax = 0;
    for (i = 1; i < n; i++)
    {
        int a = (cc[i - 1] - 'A') * 26 + (cc[i] - 'A');
        if (max < ++kk[a])
        {
            max = kk[a];
            amax = a;
        }
    }
    printf("%c%c\n", amax / 26 + 'A', amax % 26 + 'A');
    return 0;
}


#include <stdio.h>

int main() {
    char s[101],ans[3];
    int n,max = 0;
    scanf("%d", &n);
    scanf("%s", s);
    ans[2] = '\0'
    for(int j = 0; j <= n ; j++) {
        char a = s[j], b = s[j+1];
        int k=0;
        for (int i = 0; i <= n; ++i) {
            if (s[i] == a && s[i + 1] == b) k++;

        }
        if (k > max){
            ans[0] =  a;
            ans[1] = b;
            max = k;
        }

    }

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


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

int main()
{
	int i, j, n, num = 0, max = 0;
	char string[100], subString[100][2], maxString[2];
	scanf("%d", &n);
	gets("%s", string);
	for (i = 0; i < n; i++) {
		subString[i][0] = string[i];
		subString[i][1] = string[i+1];
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++) {
			if (j != i) {
				if (strcmp(subString[i], subString[j]) == 0) {
					num++;
				}
			}
		}
		if (num > max) {
			max = num;
			strcpy(maxString, subString[i]);
		}
	}

	printf("%s\n", maxString);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int m, n;
    long long int r, x, y, x1, y1, z;
    double s;
    scanf("%I64d %I64d %I64d %I64d %I64d", &r, &x, &y, &x1, &y1);
    s= sqrt( abs(x1-x)*abs(x1-x) + abs(y1-y)*abs(y1-y) );
    n= s/(2*r);
    if(n*2*r == s)
    else n++
    printf("%d",n);
    return 0;
}


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

int main()
{
long long int r,x,y,x1,y1,res;
 scanf("%I64d %I64d %I64d %I64d %I64d",&r,&x,&y,&x1,&y1);
 res=ceil(((llabs(y-y1)+llabs(x-x1))/(2*r)));
if printf("%I64d",res);

    return 0;
}


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

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	long long r,x,y,x1,y1,i;
	int s=0;
	scanf("%lld%lld%lld%lld%lld",&r,&x,&y,&x1,&y1);
	i=(long long)(pow((double)(x1-x),2.0)+pow((double)(y1-y),2.0));
    i=(long long)(sqrt((double)i));
    if(x == x1 && y == y1)
    {
		printf("0");
    }

	else if (x >= x1 && y >= y1)
	{
			i=i/(2*r);
		 	printf("%d",i+1);
	}
	else if(x <= x1 && y <= y1)
		{

           if(x == y && x1 == y1)
	        	{

			   		while(i >= r)
					{

					r=r+r;
					s++;
					}
				printf("%d\n",s);
				}

				else if((y1 > y && y1%r==0)||(x1 > x && x1%r==0))
				{
				while (i > r)
				{
				r=r+r;
				 s++;
				}
				printf("%d",s);
				}

				else if(i > r)
				{

			   		while(i >= r)
					{

					r=r+r;
					s++;
					}
				printf("%d\n",s);
				}
					else if((x == x1 && y1 >= y)||(y == y1 && x1 >= x))
				{

				while(i >= r)
					{

					r=r+r;
					s++;
					}
				printf("%d\n",s+1)
				}

			else
			{
				while ( i <= r)
				{
				   r=r-r;
				 	s++;
				}
				printf("%d",s);
			}

		}
		else if ((x >= x1 && y <= y1) || (x <= x1 && y >= y1))
		{
		 	i=i/(2*r);
		 	printf("%d",i+1);
		}

	return 0;
}


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

int main(){
    long int r, x1, y1, x2, y2;
    scanf("%ld %ld %ld %ld %ld", &r, &x1, &y1, &x2, &y2);
    printf("%ld", ceil(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/(2*r)))
    return 0;
}


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

int main()
{
    float x1,y1,x2,y2,r;
    float Dis;
    int times;
    float out;
    scanf("%f %f %f %f %f",&r,&x1,&y1,&x2,&y2);
    Dis = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
    out = Dis/2r;
    if ((int)out == (float)out){
        times = out ;
    }
    else
        times = out+1;

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


#include <stdio.h>
#include <stdlib.h>
int a[35], n, m, arr1[1<<18], arr2[1<<18];
int idx1, idx2;
int max(int a, int b){if (a<b) return b; return a;}
int mycmp(const void* a, const void* b) { return *(int *)a - *(int *)b;}
void dfs(int i, int sum, int type){
  if (type && i==n) {arr2[idx2++] = sum; return;}
  else if (!type && i==n/2) {arr1[idx1++]= sum; return ; }

  dfs(i+1, (sum+a[i])%m , type);
  dfs(i+1, sum, type);
}
int main(){
  scanf("%d %d", &n, &m);
  for (int i=0; i<n; i++){
    scanf("%d", &a[i]);
    a[i]%=m;
  }
  qsort (a, n, sizeof(int), mycmp);

  dfs(0, 0, 0);
  dfs(n/2, 0, 1);
  arr1[idx1++]=0;
  arr2[idx2++]=0;

  for (int i=0; i<idx1; i++) arr1[i]%=m;
  for (int i=0; i<idx2; i++) arr2[i]%=m;

  qsort(arr1, idx1, sizeof(int), mycmp);
  qsort(arr2, idx2, sizeof(int), mycmp);

  int l=0, r=0;
  while (arr1[l]==0) l++;
  while (arr2[r]==0) r++;

  int ans=0;
  for (int i=l; i<idx1; i++){
    for (int j=r; j<idx2; j++){
      int tmp= (arr1[i]+arr2[j])%m;
      if (tmp > ans) ans=tmp;
      while(arr2[j]==arr2[j+1]) j++;
    }
    while(arr1[i]==arr1[i+1]) i++;
  }

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


#include <stdio.h>
#include <stdlib.h>
int a[35], n, m, arr1[1<<18], arr2[1<<18];
int idx1, idx2;
int max(int a, int b){if (a<b) return b; return a;}
int mycmp(const void* a, const void* b) { return *(int *)a - *(int *)b;}
void dfs(int i, int sum, int type){
  if (type && i==n) {arr2[idx2++] = sum; return;}
  else if (!type && i==n/2) {arr1[idx1++]= sum; return ; }

  dfs(i+1, (sum+a[i])%m , type);
  dfs(i+1, sum, type);
}
int main(){
  scanf("%d %d", &n, &m);
  for (int i=0; i<n; i++){
    scanf("%d", &a[i]);
    a[i]%=m;
  }
  qsort (a, n, sizeof(int), mycmp);

  dfs(0, 0, 0);
  dfs(n/2, 0, 1);
  arr1[idx1++]=0;
  arr2[idx2++]=0;

  for (int i=0; i<idx1; i++) arr1[i]%=m;
  for (int i=0; i<idx2; i++) arr2[i]%=m;

  qsort(arr1, idx1, sizeof(int), mycmp);
  qsort(arr2, idx2, sizeof(int), mycmp);

  int ans=0;
  for (int i=0; i<idx1; i++){
    for (int j=0; j<idx2; j++){
      int tmp= (arr1[i]+arr2[j])%m;
      if (tmp > ans) ans=tmp;
      while(arr2[j]==arr2[j+1]) j++;
    }
    while(arr1[i]==arr1[i+1]) i++;
  }

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


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LL long long
#define uLL unsigned long long
long ms[2000000];
void print(LL *a,long size) {long i;for (i=1;i<size;i++) {printf("%lld ",a[i]);}printf("%lld\n",a[i]);}
void mergesort(LL*ds,long size)
{
	long i,j,k,s,b,e;
	for (k=1;k<=size;k=k<<1)
	{
		for (i=1;i+k<=size;i+=k<<1)
		{
			s=i;b=i+k;e=b+k-1;
			if (e>size) {e=size;}
			for (j=1;(s<i+k)&&(b<=e);j++)
			{
				if (ds[s]<=ds[b])
				{
					ms[j]=ds[s++];
				}
				else
				{
					ms[j]=ds[b++];
				}
			}
			for (b=i+k-1;b>=s;b--)
			{
				ds[e--]=ds[b];
			}
			for (b=1;b<j;b++)
			{
				ds[i+b-1]=ms[b];
			}
		}
	}
}
long gray(long a)
{
	return ((a<<1)^a)>>1;
}
inline uLL bsf64(uLL a)
{
	asm("bsfq %0,%0":"+r"(a));
	return a;
}
inline uLL bsr64(uLL a)
{
	asm("bsrq %0,%0":"+r"(a));
	return a;
}
inline LL max(LL a,LL b) {if (b>a) {a=b;}return a;}
inline LL min(LL a,LL b) {if (a>b) {a=b;}return a;}
LL ans1[1000000],ans2[1000000];
long num[1000],num2[1000];
int main()
{
//	freopen("in.in","r",stdin);
	long i,j,k,a,b,c,l,p,q,baka,r,m,n,mid;
	scanf("%ld %ld\n",&n,&m);
//	printf("%ld %ld\n",n,m);
	for (i=1;i<=n;i++)
	{
		scanf("%ld",&num[i]);
	}
	if (n>10) {q=n>>1;} {q=n;}
	*ans1=(LL)1<<q;ans1[1]=0;
	for (i=1;i<=q;i++) {num2[i]=num[i];}
	for (i=1;i<=*ans1;i++)
	{
		a=gray(i);b=gray(i-1);
		k=a^b;
		if (a&k) {ans1[i]=ans1[i-1]+num2[bsr64(k)];}
		if (b&k) {ans1[i]=ans1[i-1]+m-num2[bsr64(k)];}
		ans1[i]=ans1[i]%m;
	}
//	print(ans1,*ans1);
	//////////////////
	q=n-q;
	for (i=1;i<=q;i++) {num2[i]=num[n-i+1];}
	*ans2=(LL)1<<q;ans2[1]=0;
	for (i=1;i<=*ans2;i++)
	{
		a=gray(i);b=gray(i-1);
		k=a^b;
		if (a&k) {ans2[i]=ans2[i-1]+num2[bsr64(k)];}
			if (b&k) {ans2[i]=ans2[i-1]+m-num2[bsr64(k)];}
		ans2[i]=ans2[i]%m;
	}
	mergesort(ans1,*ans1);
	baka=0;
	for (i=1;i<=*ans2;i++)
	{
		l=1;r=*ans1;a=m-1-ans2[i];
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (ans1[mid]<a)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if (l<=*ans1) {b=(ans2[i]+ans1[l])%m;baka=max(b,baka);}
		if (r>0) {b=(ans2[i]+ans1[r])%m;baka=max(b,baka);}
		l=1;r=*ans1;a=2*m-1-ans2[i];
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (ans1[mid]<a)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if (l<=*ans1) {b=(ans2[i]+ans1[l])%m;baka=max(b,baka);}
		if (r>0) {b=(ans2[i]+ans1[r])%m;baka=max(b,baka);}
	}
	printf("%lld\n",baka);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LL long long
#define uLL unsigned long long
long ms[2000000];
void print(LL *a,long size) {long i;for (i=1;i<size;i++) {printf("%lld ",a[i]);}printf("%lld\n",a[i]);}
void mergesort(LL*ds,long size)
{
	long i,j,k,s,b,e;
	for (k=1;k<=size;k=k<<1)
	{
		for (i=1;i+k<=size;i+=k<<1)
		{
			s=i;b=i+k;e=b+k-1;
			if (e>size) {e=size;}
			for (j=1;(s<i+k)&&(b<=e);j++)
			{
				if (ds[s]<=ds[b])
				{
					ms[j]=ds[s++];
				}
				else
				{
					ms[j]=ds[b++];
				}
			}
			for (b=i+k-1;b>=s;b--)
			{
				ds[e--]=ds[b];
			}
			for (b=1;b<j;b++)
			{
				ds[i+b-1]=ms[b];
			}
		}
	}
}
long gray(long a)
{
	return ((a<<1)^a)>>1;
}
inline uLL bsf64(uLL a)
{
	asm("bsfl %0,%0":"+r"(a));
	return a;
}
inline uLL bsr64(uLL a)
{
	asm("bsrl %0,%0":"+r"(a));
	return a;
}
inline LL max(LL a,LL b) {if (b>a) {a=b;}return a;}
inline LL min(LL a,LL b) {if (a>b) {a=b;}return a;}
LL ans1[1000000],ans2[1000000];
long num[1000],num2[1000];
int main()
{
//	freopen("in.in","r",stdin);
	long i,j,k,a,b,c,l,p,q,baka,r,m,n,mid;
	scanf("%ld %ld\n",&n,&m);
//	printf("%ld %ld\n",n,m);
	for (i=1;i<=n;i++)
	{
		scanf("%ld",&num[i]);
	}
	if (n>10) {q=n>>1;} {q=n;}
	*ans1=(LL)1<<q;ans1[1]=0;
	for (i=1;i<=q;i++) {num2[i]=num[i];}
	for (i=1;i<=*ans1;i++)
	{
		a=gray(i);b=gray(i-1);
		k=a^b;
		if (a&k) {ans1[i]=ans1[i-1]+num2[bsr64(k)];}
		if (b&k) {ans1[i]=ans1[i-1]+m-num2[bsr64(k)];}
		ans1[i]=ans1[i]%m;
	}
//	print(ans1,*ans1);
	//////////////////
	q=n-q;
	for (i=1;i<=q;i++) {num2[i]=num[n-i+1];}
	*ans2=(LL)1<<q;ans2[1]=0;
	for (i=1;i<=*ans2;i++)
	{
		a=gray(i);b=gray(i-1);
		k=a^b;
		if (a&k) {ans2[i]=ans2[i-1]+num2[bsr64(k)];}
			if (b&k) {ans2[i]=ans2[i-1]+m-num2[bsr64(k)];}
		ans2[i]=ans2[i]%m;
	}
	mergesort(ans1,*ans1);
	baka=0;
	for (i=1;i<=*ans2;i++)
	{
		l=1;r=*ans1;a=m-1-ans2[i];
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (ans1[mid]<a)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if (l<=*ans1) {b=(ans2[i]+ans1[l])%m;baka=max(b,baka);}
		if (r>0) {b=(ans2[i]+ans1[r])%m;baka=max(b,baka);}
		l=1;r=*ans1;a=2*m-1-ans2[i];
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (ans1[mid]<a)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if (l<=*ans1) {b=(ans2[i]+ans1[l])%m;baka=max(b,baka);}
		if (r>0) {b=(ans2[i]+ans1[r])%m;baka=max(b,baka);}
	}
	printf("%lld\n",baka);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int a[35], n, m, arr1[1<<20], arr2[1<<20];
int idx1, idx2;
int max(int a, int b){if (a<b) return b; return a;}
int mycmp(const void* a, const void* b) { return *(int *)a - *(int *)b;}
void dfs(int i, int sum, int type){
  if (type && i==n) {arr2[idx2++] = sum; return;}
  else if (!type && i==n/2) {arr1[idx1++]= sum; return ; }

  dfs(i+1, (sum+a[i])%m , type);
  dfs(i+1, sum, type);
}
int main(){
  scanf("%d %d", &n, &m);
  for (int i=0; i<n; i++){
    scanf("%d", &a[i]);
    a[i]%=m;
  }
  qsort (a, n, sizeof(int), mycmp);

  dfs(0, 0, 0);
  dfs(n/2, 0, 1);
  arr1[idx1++]=0;
  arr2[idx2++]=0;

  for (int i=0; i<idx1; i++) arr1[i]%=m;
  for (int i=0; i<idx2; i++) arr2[i]%=m;

  qsort(arr1, idx1, sizeof(int), mycmp);
  qsort(arr2, idx2, sizeof(int), mycmp);

  int ans=0;
  for (int i=0; i<idx1; i++){
    for (int j=0; j<idx2; j++){
      int tmp= (arr1[i]+arr2[j])%m;
      if (tmp > ans) ans=tmp;
      while(j<idx2-1 && arr2[j]==arr2[j+1]) j++;
    }
    while( i<idx1-1 && arr1[i]==arr1[i+1]) i++;
  }

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


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

#define si(a) scanf("%d",&a);
#define sl(a) scanf("%lld",&a);
#define ss(a) gets(a);
#define rep(i,start,n) for(i=start;i<n;i++)
#define debugl(a) printf("%lld\n",a);
#define debugi(a) printf("%d\n",a);

int main()
{
    long long int t;
    sl(t);
    if(n%2==0)printf("%lld",(n/2) -1);
    else if(n%2==1)printf("%lld",(n/2));

}


include<stdio.h>

int main()
{
    int n,a;
    scanf("%d",&n);
    if(n%2==0)
    {
        a=(n-2)/2;
    }
    else
    {
        a=(n-1)/2;
    }
    printf("%d",a);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    cout<<(n-1)/2;<<endl;
    return 0;
}


#include <stdio.h>
int main
{ long int n,m;
  scanf("%d",&n)
  if(n%2=0)
    m=(n/2)-1;
  else
    m=n/2;

  printf("%ld",m);

  return 0;
}


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


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

int PN;
int prime[500];
int sp[500];
int ptest(int);
int main(){
    int n,k;
    int i;
    int cnt=0;
    scanf("%d%d",&n,&k);
    prime[p++]=2;
    for(i=3;i<=n;i+=2){
        if(ptest(i)) prime[p++]=i;
    }
    PN=p;
    for(i=0;i<PN-1;i++){
        sp[i]=prime[i]+prime[i+1];
    }
    i=0;
    while(sp[i++]<=n-1 && i<PN) cnt++;
    if(cnt>=k) printf("YES");
    else printf("NO");
    return 0;
}

int ptest(int n){
    int i;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0) return 0;
    }
    return 1;
}


#include<stdio.h>
#include<math.h>
int prime_arr(int *arr)
{
  int i,j,s;
  for(i=2;i<1000;i++)
  {
    s=sqrt(i);
    for(j=2;j<=s;j++)
      if(i%j==0)
        break;
    if(j>s)
      arr[c++]=i;
  }
  return c;
}
int main()
{
  int i,j,n,k,p;
  int primes[1000];
  p=prime_arr(primes);
  scanf("%d %d",&n,&k);
  for(i=5;i<=n;i++)
  {
    for(j=2;j<p;j++)
      if(arr[i]==arr[j]+arr[j-1]+1)
        k--;
    if(!k)
      break;
  }
  if(!k)
    printf("YES");
  else
    printf("NO");
  return 0;
}


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

int SieveOfEratosthenes(int n)
{
    int a[1000],k=0,count=0;

    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {

            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++){
       if (prime[p]) {
       a[k]=p;
        k++;}
    }
        for(int i=0;i<k-1;i++)
        {

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

    return count;

}

// Driver Program to test above function
int main()
{
    int n ,m;
    cin>>n>>m;

 if(SieveOfEratosthenes(n)>=m)
 cout<<"YES";
 else
 cout<<"NO";

    return 0;
}


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

int n;
int k;
int count;
int prime[1000];

int isPrime(int x)
{
    int i = 0;
    for (i = 2; i < (int)sqrt(x); i++)
        if (x % i == 0)
            return 0;
    return 1;
}

void buildPrime()
{
    for (int i = 2; i <= 1000; i++)
        if (isPrime(i))
        {
            prime[count] = i;
            ++count;
        }
}

int main(int argc, const char * argv[]) {

    count = 0;

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

    buildPrime();

    int i  = 0;
    int w = 0;
    int sum = 0;

    for (i = 0; i < count -1; i++)
    {
        sum = prime[i] + prime[i+1] + 1;
        if (sum > n)
            break;
        else
            if (isPrime(sum))
                ++w;
    }

    if (w >= k)
        printf("YES");
    else
        printf("NO");

    return 0;
}


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

using namespace std;
int hh, mm, a, p;
char sim;

int main()
{
	scanf("%d:%d %d", &hh, &mm, &a);

	p = hh * 60 + mm + a;
	mm = p % 60;
	hh = p / 60;
	printf("%02d:%02d", hh, mm);

	return 0;
}


#include <iostream>

using namespace std;
int hh, mm, a, k, l;
char c;
int main(){
	cout << "Input time hh:mm " << endl;
	cin >> hh >> c >> mm;
	cout << "Input time + " << endl;
	cin >> a;
	k = hh * 60 + mm + a;
	mm = k % 60;
	hh = k / 60;
	if (hh > 23) {
		hh = hh % 24;
	}
	cout << "Time " << endl;
	if ((hh < 10)&(mm < 10)){
		cout << "0" << hh << c << "0" << mm;
		return 0;
	}
	if((hh < 10)&(mm >= 10)){
		cout << "0" << hh << c << mm;
		return 0;
	}
	if((hh >= 10)&(mm < 10)){
		cout << hh << c << "0" << mm;
		return 0;
	}
	cout << hh << c << mm;
return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int *mn ,maj ,*h;
    std::cout<<"donner l'horloge"<<std::endl;
    std::cout<<"donner les minute a ajouter"<<std::endl;
    if(*mn<59)
        *mn=*mn+1;
    else
    {
        *mn=0;
        if(*h<23)
            *h=*h+1;
        else
            *h=0;
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* palindromo(char *duerme);
char *calcular(int hora, int minuto);

char * transformar(int hora, int minuto);

int main ()

{
    char duerme[51],*despierta;
    scanf("%s",duerme);
    despierta = palindromo(duerme);

    printf("%s",despierta);

    return NULL;
}

char* palindromo(char *duerme)
{
    char *despierta = NULL,aux_h[3],aux_m[3];
    int i,minuto,hora;

    for( i = 0; i<2 ;i++)
    {
        aux_h[i] = duerme[i];
        aux_m[i] = duerme[i+3];
    }
    aux_h[2]= '\0'; aux_m[2] = '\0';

    hora = atoi(aux_h);
    minuto =atoi(aux_m);

    despierta = calcular(hora,minuto);

    return despierta;
}

char *calcular(int hora, int minuto)
{
    int i,hora_decena, hora_unidad, minuto_decena, minuto_unidad;

    char *despierta = NULL, *retorno = "00:00";
    if(hora >= 23 && minuto > 31)
    {

        despierta = retorno;

    }
    else
    {

        hora_decena = (hora/10);        minuto_decena = minuto/10;
        hora_unidad = (hora%10);     minuto_unidad = (minuto%10);
        if( minuto <  hora_decena + (hora_unidad*10 ) )
        {

            minuto = hora_decena + (hora_unidad*10);

            despierta = transformar(hora,minuto);

            return despierta;

        }
        if( minuto >= hora_decena + (hora_unidad*10 ))
        {

            hora = hora+1;
            minuto = hora/10 + ( (hora%10 )* 10);
            despierta = transformar(hora,minuto);
            return despierta;
        }

    }
    return despierta;
}

char * transformar(int hora, int minuto)
{
    char *despierta , aux_h[2], *aux_m[20];

    itoa(hora, aux_h , 10);

    itoa(minuto , aux_m , 10);

    strcat(despierta,aux_h);
    despierta[2]= ':';
    despierta[3] = '\0';
    strcat(despierta,aux_m);
    if(despierta[0] > '9')
    {
        despierta[0] = '0';
    }
    else1
    {
        if(despierta[0] < '1')
        {
            despierta[0] = '00';
        }
    }

    return despierta;
}


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

int funcelias (char a);

int main()
{
	int i,j=0,k,f,l ;
	int aux[4];
	char hora[6];
	int flag=0 ;
	scanf("%s", hora) ;

	for(i=0;'\0'!=hora[i];i++){

		if(funcelias(hora[i])!=-1){
			aux[j]=funcelias(hora[i]);
			j++;
		}
	}
	while(flag!=1){

		for(i=aux[0] ; i<3 && flag==0; i++)
		{
			for(k=aux[1] ; k<4 && flag==0; k++)
			{
				for(j=aux[2] ; j<6 && flag==0; j++)
				{
					for(l=aux[3]+1 ; l<10 && flag==0; l++)
					{
						if(i==l and k==j)
						{
							flag=1 ;
							printf("%d%d:%d%d",i,k,j,l) ;
						}
					}
					aux[3]=-1;
				}
				aux[2]=0;
			}
			aux[1]=0;

		}
		aux[0]=0;

	}

	return 0 ;
}
int funcelias (char a)
{
	int i;

	char numero[]= {'0','1','2','3','4','5','6','7','8','9'}	;
	for(i=0; i<10; i++)
	{

		if(a==numero[i])
		{
			return i;
		}

	}
	return -1;
}


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

#define MAX( a, b ) ( ( a > b) ? a : b )
#define MIN( a, b ) ( ( a < b) ? a : b )
#define FOR(ii,aa,bb) for(ii=aa;ii<bb;ii++)
#define and &&
#define or ||
int main () {

int x=0,n=0,s=0,i,j,a[10];
char b;
scanf("%d",&x);
scanf("%c",&b);
scanf("%d",&s);
n+=((x%10)*10)+x/10;
if(s<n){
  printf("%d:%d",x,n);
  return 0;}
if(x<23 and n+10<60){
  printf("%d:%d",x+1,n+10);
  return 0;}
if(n+10>=60){
  printf("20:02");
  return 0;}
printf("00:00");

  return 0;


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

int main()
{
    int hora,Min;

    scanf("%d:%d",&hora,&Min);
    int Aux;
    float H;

    if((hora>0 && hora <=5 && Min<50 )||(hora>=10 && hora<=15 && Min<51)||(hora>=20 && hora<=23 && Min<32)){
        Aux=hora/10;
        H=(((float)hora/10)-Aux)*100+Aux;
        if(Min<H)
            printf("%d:%.0f",hora,H);
        else{
            hora++;
            H=H+10;
            printf("%d:%.0f",hora,H);
        }
    }
    else if ((hora>=6 && hora<=9) || hora=05 && min>50 )
        printf("10:01");
    else if ((hora>=16 && hora<=19) || hora=15 && min>51 )
        printf("20:02");
    else
        printf("00:00");

    return 0;
}


#include<stdio.h>
#include<string.h>
int N,K,dp[2003][2003];
int find(int cur,int cnt)
{
	if(cnt>K)
	{
		return 1;
	}
	if(dp[cur][cnt]>-1)
	{
		return dp[cur][cnt];
	}
	dp[cur][cnt]=0;
	for(int i=1;cur*i<=N;i++)
	{
		dp[cur][cnt]=(dp[cur][cnt]+find(cur*i,cnt+1))%1000000009;
	}
	return dp[cur][cnt];
}
int main()
{
	while(scanf("%d %d",&N,&K)==2)
	{
		memset(dp,-1,sizeof(dp));
		printf("%d\n",find(1,1));
	}
	return 0;
}


#include<stdio.h>
  long long int dp[2002][2002];
  long long int par(long long int n,long long int k)
{
  if(dp[n][k]==-1)
  {
    if(k==0)
      {
	dp[n][k]=0;
       	return 0;
      }
  if(n==1)
    {
      dp[n][k]=1;
         return 1;
    }
  long long int i,num=k;
  long long int sum=0;
  for(i=1;i*i<=n;i++)
    {
      num=k;
      while(num--)
	sum+=par(i,num)%1000000007;

    }
  dp[n][k]=(sum+1)%1000000007;
	 return (sum+1)%1000000007;
  }
  else
    return dp[n][k];

}
 long long int good(long long int n,long long int k)
{
  if(n==0)
    return 0;
  if(n==1)
    return 1;
  return good(n-1,k)%1000000007+par(n,k)%1000000007;
  }
int main()
{
  long long int n,k,i,j;
  scanf("%lld %lld",&n,&k);
  for(i=0;i<2002;i++)
    for(j=0;j<2002;j++)
      dp[i][j]=-1;
    long long int ans=good(n,k);
    if(k==0)
      ans=0;
    int ans1=(int)ans%1000000007
  printf("%d\n",ans1);
  return 0;
}


#include<stdio.h>
int mod=1000000007;
int dp[2001][2001];
int f(int n,int k);
int upd[2001][2001];
int uf(int n,int k)
{
	if(udp[n][k]==0)
		return udp[n][k];
	else
	return f(n,k)-f(n-1,k);
}
int f(int n,int k)
{

	if(dp[n][k]!=0)
	{
		return dp[n][k];
	}

	if(n==1)
		dp[n][k]=1;
	else if(k==1)
		dp[n][k]=n;
	else{
	int i,p=0,j=0;
	int div;
	for(i=n/2;i>=0;i--)
	{
		if(n%i==0)
		{
			div=i;
			break;
		}
	}
	int non[div];
	for(i=2;i<div;i++)
	{
		if((n%i)!=0)
		{
			non[p]=i;
			p++;
		}
	}
	int c=0;
	int b=0;
	for(i=1;i<k;i++)
	{
		for(j=0;j<p;j++)
		{
			c=(c%mod + (uf(non[j],k-i))%mod)%mod;
		}

		b=(b%mod+(f(div,k-i))%mod-c)%mod;
	}

	dp[n][k]=((f(n-1,k))%mod+b%mod+1)%mod;
	}
	return dp[n][k];

}

int main()
{
	int n,k,div,i;
	scanf("%d%d",&n,&k);
	printf("%d\n",f(n,k));
/*	for(i=n/2+1;i>=0;i--)
	{
		if(n%i==0)
		{
			div=i;
			break;
		}
	}
	printf("%d",div);*/
	return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    int,ans;
    float n,x,y,p1;
    scanf("%f %f %f",&n,&x,&y);
    p1=(x/n)*100;
    if(p1<y)
    {
       y=y-p1;
       ans=y*n;
       if(ans%100==0);
       ans=ans/100;
       else
       ans=(ans/100)+1;

    }
    else
    ans=0;
    printf("%d",ans);
    return 0;
}


#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    int n,x,y;
    double p;
    scanf("%d %d %d",&n,&x,&y);
    p= (n*y)/100;
    x= int (ceil(p))-x;
    if(x>0)
    printf("%d",x);
    else
      printf("0");

    getch();
}


#include<stdio.h>
#include <math.h>
int main()
{int n,x,y;
float c;
    scanf("%d %d %d",&n,&x,&y);
    c=float (n*y)/100;
    x=int(ceil(c))-x;
    if(x>0)
    printf("%d",x);
    else
    printf("0");
    return 0;
}


#include <stdio.h>
//#include<conio.h>
int main()
{
     int n,x,y,p=0;
     scanf("%d %d %d",&n,&x,&y);
     while ((x+p)*100<n*y) p++;
     printf("%d\n",p);]
     //getch();
     return 0;
}


#include<stdio.h>
int main()
{
    float ans;
    float n,x,y,p1;
    scanf("%f %f %f",&n,&x,&y);
    p1=(x/n)*100;
    if(p1<y)
    {
       y=y-p1;
       ans=(y*n)/100;
       if(ans<1)
       ans=1;
       ans=ceil(ans)

    }
    else
    ans=0;
    printf("%d",ans);
    return 0;
}


int main()
 #include<stdio.h>
 #include<string.h>
 { char* out=NULL,ch,str,f=NULL;
  char k;

  scanf("%s",ch);
  strcpy(str,ch);

       while(str)
       { k= toupper(str[0]);
       if!((k=='E')|| (k=='O')|| (k=='I')|| (k=='U')|| (k=='A'))
          { sprinf(out,".%c",k);
          strcat(f,out);
          }
        str++;
       }
 printf("%s",f);
 return 0;
 }


#include<stdio.h>
int main()
{
    int n,min=100,i,A[100],temp;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
        if(A[i]<min)
            min=A[i];
    }
    for(i=0;i<n;i++)
    {
        do{
            A[i]%=min;
            if(A[i])
            {
                temp=min;
                min=A[i];
                A[i]=min;
            }
        }while(A[i]);
    }
    printf("%d",min*n);
    return 0;


#include<stdio.h>
#include<string.h>
const int N = 105;
int n, num[N];
int gcd(int a, int b)
{
    if (b==0)
	return a;
    return gcd(b,a%b);
}
int main ()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++) scanf("%d",&num[i]);
    int t=num[0];
    for (int i=1;i<n;i++) t=gcd(t,num[i]);
    printf("%d\n",t*n);
    return 0;
}


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

const int N = 105;
int n, num[N];

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main () {
	int i;
	while(scanf("%d", &n)!=NULL){
	for ( i = 0; i < n; i++) scanf("%d", &num[i]);
	int t = num[0];
	for ( i = 1; i < n; i++) t = gcd(t, num[i]);
	printf("%d\n", t * n);
	}
	return 0;
}


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

for(i=0;i<n;i++)m+=a[i];
printf("%d",m);
return 0;/aaa
}


#include<stdio.h>
int main()
{
    int n,d,i,j,temp,min=200,ans=200;
    scanf("%d%d",&n,&d);
    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[j]<a[i])
            {
                temp=a[j];
                a[j]=a[i];
                a[i]=temp;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        min=200;
        for(j=i+1;j<n;j++)
        {
            if(a[j]-a[i]>d)
            {
                min=n-j+i;
                break;
            }
            min=n+i-j-1;
        }
        if(min<ans)
            ans=min;
    }
    if(ans==200)
        ans=0;
    printf("%d\n",ans);
    return 0;
}


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

void merge(int arr[], int l, int m, int r) {
	int i = 0; // Initial index of first subarray
	int j = 0; // Initial index of second subarray
	int k = l; // Initial index of merged subarray
	int n1 = m - l + 1;
	int n2 = r - m;

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

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

	/* merge the temp arrays back into arr[l..r] */
	while (i < n1 && j < n2) {
		if (L[i] <= R[j]) {
			arr[k] = L[i];
			i++;
		} else {
			arr[k] = R[j];
			j++;
		}
		k++;
	}

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

void mergeSort(int arr[], int l, int r) {
	if (l < r) {
		int m = l + (r - l) / 2;

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

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

int main(void) {
    int n, d, min[10000];
    int k = 0; // for array min[]
    scanf("%d %d", &n, &d);
    int a[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    mergeSort(a, 0, n - 1);

    if (d == 0 || (a[n - 1] - a[0] =< d) || n == 1) {
        printf("0\n");
        return 0;
    }

    for (int i = n - 1; i >= 0; i--) {
        for (int j = i; j >= 0; j--) {
            if (a[i] - a[j] == d) {
                min[k++] = (n - 1) - (i - j + 1);
            }
        }
    }

    mergeSort(min, 0, k - 1);

    printf("%d\n", min[0] + 1);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int comp (const void * elem1, const void * elem2)
{
    int f = *((int*)elem1);
    int s = *((int*)elem2);
    if (f > s) return  1;
    if (f < s) return -1;
    return 0;
}
int main()
{
    int n,d;
    scanf("%d %d",&n,&d);
    int points[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&points[i]);
    }
    qsort (points, sizeof(points)/sizeof(*points), sizeof(*points), comp);
    int c1=0,c2=0;

    for(int i=n-1;i>0;i--)
    {
        if(points[i]-points[0]>d)
            c1++;
        else
            break;
    }
    for(int i=0;i<n-1;i++)
    {
        if(points[n-1]-points[i]>d)
            c2++;
        else
            break;
    }if(c1>c2)
    printf("%d",c2);
    else
        printf(%d,c1);

    return 0;
}


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

int minNumPtsRemove(int n,int d,int *p)
{
    int cumilativeCount[100 + d]= {};
    int pts=0,maxPts=0,i=0;
    for(i=0;i<n;i++)
        cumilativeCount[p[i]] ++;
    for(i=1;i<100+d;i++)
        cumilativeCount[i] += cumilativeCount[i-1];
    for(i=0;i<100;i++)
    {
        pts=cumilativeCount[i+d+1]-cumilativeCount[i];
        if(pts>maxPts)
        {
            maxPts = pts;
        }
    }
    return n-maxPts;
}

int main()
{
	int n,d;
	scanf("%d %d ",&n,&d);
	int p[n];
	for(int i=0;i<n;i++)
	    scanf("%d",&p[i]);
	printf("%d\n",minNumPtsRemove(n,d,p));
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int arr[101];
int n,dis;
int min(int x,int y)
{
	return x<y?x:y;
}
int comparator (const void * b, const void * a)
{
  return ( *(int*)b - *(int*)a );
}
int recur(int start,int end)
{
	if(start==end)
	 return 0;
	if(arr[end]-arr[start]<=dis)
	 return 0;
	int q1=recur(start+1,end);
	int q2=recur(start,end-1);
	return 1+min(q1,q2);
}
int main()
{
	scanf("%d %d",&n,&dis);
	//printf("%d\n",dis);
	int i,j,k;
	for(i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}

	qsort(arr,n,sizeof(int),comparator);

	printf("%d\n",recur(0,n-1));
}