#include<stdio.h>
#include<math.h>
#include<string.h>
int a[1000];
int main(){
int i,j,k,m,n;
    scanf("%d %d",&n,&m);
    for(i=0;i<=n;i++)a[i]=0;
    for(i=1;i<=m;i++){
            scanf("%d",&k);
            for(j=k;j<=n;j++){
                    if(a[j]==0)a[j]=k;
                    }
            }
    for(i=1;i<n;i++)printf("%d ",a[i]);
    printf("%d\n",a[i]);

}


#include<stdio.h>
int main()
{
    int k,c=1,s=0;
    scanf("%d",&k);
    while(k>0)
    {
        k+k-c;
        c+=1;
        s+=1;
    }
    printf("%d",s);
}


#include<stdio.h>
int main()
{long long int s=0,i=1,n,cnt=0,sum=0,l;
scanf("%I64d",&n);
while(1)
{

     sum=sum+(i*(i+1))/2;
    cnt++;
    i++;
   if((sum)==n)
   {
    break;}
    if(n<sum&&n>sum-n)
    {
        cnt=cnt-1;
        break;
    }

}
printf("%I64d",cnt);
}


#include <stdio.h>
int main()
{
    int a,sum=1,i=2,c=0;
    scanf("%d",&a);
    while(a!=0)
    {
            a -= sum;
            c++;
            sum +=i;
            i++;

    }
    printf("%d",c);

}


#include<stdio.h>
int main(void)
{
    int n,i,h;
    do{
        scanf("%d",&n);
    }
    while(n<10001 && n>0);
    while(i<n)
    {
     h++;
     i=i+(i*(i+1))/2 ;
    }
    printf("%d",h-1);

    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define pi acos(-1)

int main()
{
	int n,i=1,j,k,l,m,sum=0,count=0;
	scanf("%d", &n);
	if(n==1) printf("1\n");
	else if(n==0) printf("0\n");
	else
	{

		sum=i;
		while(1)
		{
			++count;
			i=i+2;
			sum=sum+i;
			if(sum==n) break;
		}

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


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

        i+=1;
    }
    if(k%2==0) printf("CHAT WITH HER!");
    else printf("IGNORE HIM!");
}


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

int main()
{   char str[120];
    int  dist, j;
    while(1){

    scanf("%s", &str);
    dist=0;

    for(char i='a'; i<='z' ; i++)
        for(j=0; str[j]!=NULL; j++)

    {
        if(i==str[j]){
            dist++;
            break;}
    }

    if(dist%2==0)
    printf("CHAT WITH HER!");
    else printf("IGNORE HIM!");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main ()
{
    char str[100];
    int i=0,j=0,len1=0,len2=0,k,kk,temp,c=0;
    gets(str);
    len1=strlen(str);
    for(k=0;k<len1;k++)
    {
        for(kk=0;kk<len1-1;kk++)
        {
            if(str[kk]>str[kk+1])
            {
              temp=str[kk];
              str[kk]=str[kk+1];
              str[kk+1]=temp;
            }
        }
    }
    while(str[i]!='\0')
    {
        if(str[i]!=str[i+1])
        {
        i++;
        c++;
        }
    }
    if((c+1)%2==0)
    printf("CHAT WITH HER!\n");
    else
    printf("IGNORE HIM!\n");
    return 0;
}


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


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

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

int main()
{
    //Declaracion de variables
    int OriginalLetters = 1, Tester = 1, ComparisonLetters = 0;
    int Cantidad = 1;
    char Cadena[102], Cadena2[102]; //Cadena Original, La Cadena2 permite comparar

    //Escaneo de Cadena
    scanf("%s",&Cadena);

    Cadena2[0] = Cadena[0];  // Para poder comparar ambas cadenas se necesita el caracter de la posicion 0 en la posicion 0 de la cadena 2

    while(Cadena[OriginalLetters] != '\0')
    {
          while(Cadena2[ComparisonLetters] != '\0' )
          {
                if(Cadena2[ComparisonLetters] == Cadena[OriginalLetters])
                {
                     Tester = 0;
                     ComparisonLetters = 102;
                }

                else
                   ComparisonLetters++;

          }

          if(Tester == 1)
          {

             Cadena2[OriginalLetters] = Cadena[OriginalLetters];
             Cantidad++;

          }
          Tester = 1;
          ComparisonLetters = 0;
          OriginalLetters++;

    }

    if(Cantidad % 2 == 0 )
    {
         printf("CHAT WITH HER!");
    }
    else
         printf("IGNORE HIM!");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=2,b=9,c=3,max;
    int result[6],j;
    result[0]=a+b+c;
    result[1]=a*b*c;
    result[2]=a+b*c;
    result[3]=(a+b)*c;
    result[4]=a*b+c;
    result[5]=a*(b+c);
    max=result[0];
    for(j=0;j<5;j++)
    {
        if(result[j]>max)
        {
            max=result[j];
        }
    }
    printf("%d",max);
    system("pause");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=2,b=6,c=8,max;
    int result[6],j;
    result[0]=a+b+c;
    result[1]=a*b*c;
    result[2]=a+b*c;
    result[3]=(a+b)*c;
    result[4]=a*b+c;
    result[5]=a*(b+c);
    max=result[0];
    for(j=0;j<5;j++)
    {
        if(result[j]>max)
        {
            max=result[j];
        }
    }
    printf("%d",max);
    system("pause");
    return 0;
}


#include<stdio.h>
int main()
{
    int n,k,i,a[200],count=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
       while(a[i]>a[k]&&a[i]>0)
       {
        count++;
       }
    }
    printf("%d",count);
}


#include<stdio.h>
int main()
{
    int a[100],k,n,count,t,i;
         scanf("%d%d",&n,&k);
                 for(i=0;i<n;i++)
                    scanf("%d",&a[i]);

                      if(a[k]!=0){
                         while(k<n)
                           {
                                if(a[k]==a[k+1])
                                     k++;

                           }
                           printf("%d",k+1);
                      }
                      else
                          printf("0");
                          return 0;

}


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


#include<stdio.h>
int main()
{
         int x,k,i,c=0;
         scanf("%d %d",&x,&k);
         int n[x];
         for(i=0;i<n;i++)
                scanf("%d",&n[i]);

         k=k-1;
         for(i=0;i<n;i++){
                if(n[i]>=n[k]) c++;
         }
         printf("%d\n",c);
}


#include <stdio.h>
#include <stdlib.h>
int check(int val,int x)
{
    if (val>=x){return (1);}
    else{return (0);}
}
int search(int t[],int n,int k)
{
    int lft=k,rgt=n,m,pos=0;
    int check(int,int);
    while(lft<=rgt)
    {
        m=(lft+rgt)/2;
        if (check(t[m],t[k-1]))
        {
            lft=m+1;
            pos=m;
        }
        else
            {
                rgt=m-1;
            }
    }
    return(pos);
}
void par(int *a, int *b)
{
    int check(int,int);
    int ver=1;
    do
    {
        scanf("%d %d",a,b);
        if(check(*b,1)&&check(50,*a)&&check(*a,*b)) {ver=0;}
    }while(ver);
}
void rem(int t[],int b)
{
    int i=0,ver;
    int check(int,int);
    do
        {
            ver=0;
            for(i=0;i<b;i++){
            scanf("%d",t+i);
            if(!check(100,t[i])||!check(t[i],0)) {ver=1;}
            }
        }while(ver);
}
int main()
{   int *tab;
    int n,k,p;
    void par(int *, int *);
    tab=malloc(sizeof(int)*n);
    void rem(int t[],int );
    par(&n,&k);
    rem(tab,n);
    if(tab[k-1]==0)
    {
       if(tab[0]==0){printf("%d",0);}
       else
            {
                p=1;
            p=search(tab,k-1,1);
            printf("%d",p);
            }
    }
    else
    {
        printf("%d",search(tab,n,k)+1);
    }
    return(0);
}


#include<stdio.h>

int main()
{
    float l, d, v, g, r  ,t , m ;
    int i ;
    scanf("%f%f%f%f%f",&l,&d,&v,&g,&r);

    t = (l-d)/v ;

    if(d/v <= g)
    {
        t += d/v ;
        printf("%f",t);
        return 0 ;
    }

    while(d >= 0)
    {
        m = v*g ;
        t += m/v ;
        d -= m ;
        if(d<=0)
        {
            printf("%f",t);
            return 0 ;
        }
        else
        {
            m = v*r ;
            t += m/v ;
            d -= m ;
        }
        if(d<=0)
        {
            printf("%f",t);
            return 0 ;
        }

    }

    return 0 ;
}


#include <stdio.h>

int main()
  {
  	float ans;
  	int l, d, v, g, r, i;
  	scanf("%d %d %d %d %d", &l, &d, &v, &g, &r);
  	i = d/v;
  	if(i*v != d)
  	  i++;
  	if(i % (g+r) <= g && i % (g+r) != 0)
  	  {
  	  	ans = (float) l/v;
	  }
	else
	  {
	  	ans = ( (float) (l-d)/v) + (d/v/(g+r)+1) * (g+r);
	  }
	printf("%f", ans);
	getchar();
	getchar();
	return 0;
  }


#include <stdio.h>
#define epslion .000001
int main() {
int  d,l,v,g,r,time;
float duration,durtol,resttol,oddtime,inc=0.0;
scanf("%d %d %d %d %d",&d,&l,&v,&g,&r);
 if(l>d){
  duration = (float)d/v;
  printf("%f",duration);
 }
 else {
   durtol = (float)l/v;
   time = durtol/(g+r);
   oddtime = durtol - time*(g+r);
   //printf("%f ",oddtime);
   if(oddtime > g) {
     inc =  (r+g - oddtime );
   }
   resttol = (float)(d-l)/v;
   printf("%f",resttol + inc + durtol);

 }

 return 0;

}


#include<stdio.h>

int main()

{
    int l,d,v,g,r;

    scanf("%d%d%d%d%d",&l,&d,&v,&g,&r);

    if((d/v)<=g)
    {
        printf("%d",(l/v));
    }

    else
    {
        printf("%d",(g + r + ((l-d)/v)));
    }
return 0;
}


#include<stdio.h>
double tra();
double l,d,v,g,r,t;
void main()
{
	scanf("%lf%lf%lf%lf%lf",&l,&d,&v,&g,&r);
	t=l/v+tra(d/v,g,r);
	printf("%.8lf",t);
}
double tra()
{
	double sum=0;
	for (int i=0;;i++)
	{
			if (i%2==0){sum+=g;}
	        else { sum+=r;}
	    		if (sum>=d/v)
	    		{
			if (i%2==0){return 0;}
			else {return sum-d/v;}
		      }
	 }
}


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

    int l,a,p,mk,min,tmp;
    int lm,ap,per;
    while(scanf("%d %d %d",&l,&a,&p))
    {

        lm=l;
        ap=a/2;
        per=p/4;
        if(lm<ap)
        {
            min=lm;

        }
        else
            min=ap;
        if(min>per)
            mk=per;
        else
            mk=min;

        printf("%d\n",7*mk);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int a,b,c,ans=0;
    scanf("%d %d %d",&a,&b,&c);
    while(1)
    {
         if(((a*2)<=b)&&((a*4)<=c))
        {
            ans=7*a;
            break;
        }

    }

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

}


#include<stdio.h>
#include<conio.h>
int main()
{
	int l,a,p,count=0;
	scanf("%d",&l);
scanf("%d",&a);
scanf("%d",&p);
	if((a<(2) && p<(4)) || l<1)
	printf("0\n");
	else {
	{
		int m=p/4;
		if(a>=m*2)
		count=7*m;
	}
	printf("%d\n",count);
}
	getch();
}


#include<stdio.h>

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

    if(b/2 < d)
        d = b/2;

    if(c/4 < c)
        d = c/4;

    printf("%d\n",d+2*d+4*d);

    return 0;
}


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


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int a[108];
int main()
{
    int n,c,i,ma;

    scanf("%d%d",&n,&c);
        for(i=0;i<n;i++) scanf("%d",a+i);
        ma=0;
        for(i=1;i<n;i++)
        {
            if(a[i-1]-a[i]>ma) ma=a[i-1]-a[i];
        }
        printf("%d\n",ma-c);

    return 0;
}


#include <stdio.h>

int main(void) {
    int n, c, x[101], i, max_i, max, ans;

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

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

    max_i=0;
    max=0;
    for(i=1; i<n; i++)
    {
        if(max<(x[i-1]-x[i]))
        {
            max=x[i-1]-x[i];
            max_i=i;
        }
    }

    if(max==0)
        ans=0;
    else
        ans=x[max_i-1]-x[max_i]-c;

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


#include<stdio.h>

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

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

 	int dayTake = 0,idx;
 	for(a = 0 ; a < day-1; a++)
 	{
 	  if(Data[a]- Data[a+1] > dayTake)
	    {
	    	dayTake = Data[a] - Data[a+1];
	    	idx = a;
	    }
 	}

 	// Debug
 	//printf("%d\n",dayTake);

 	if(dayTake == 0)
 	{
 		printf("%d\n",dayTake);
 	}

 	else
 	{
 		printf("%d\n",((Data[idx] - Data[idx+1]) - pay));
 	}

 	return 0;
 }


#include<stdio.h>
int main()
{
    int n,k,a[100],s=0,count=0,i;
    printf("\nEnter n and k");
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);

        if(a[i]>8)
            s=s+8;
        else
            s=s+a[i];
            while(s<=k)
                count++;

    }
    if(s==k)
        printf("\n%d",count);
    else
        printf("\n-1");
        return 0;
}


#include<stdio.h>
int main ()
{
	int c[5];
	int j;

	for (j=0;j<10;j++)    c[j]=j;

	for (j=0;j<10;j++)    printf("%d",c[j]);

	return 0;

}


#include<stdio.h>
void main()
{
int n,k,a[100],i,sum=0;
scanf("%d %d",&n,&k);
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
    sum=sum+8;
    if(sum>=k)
    {
        printf("%d",i);
        break;
    }
}
if(sum<k)
{
    printf("-1");
}
}


#include<stdio.h>
void main()
{
    int n,i,count=0,s=0,r=0;
    long int k;
    scanf("%d%d",&n,&k);
    int a[n];
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        r+=a[i];
    }
    for (i=0;i<n;i++)
    {
        if(a[i]>=8)
            {
                if(i+1<n)
                    a[i+1]+=a[i]-8;
            s+=8;
            if(s<k)
            count+=1;
            else
            {count+=1;
            break;}
            }
        else
            {
                s+=a[i];
                a[i]=0;
                if(s<k)
                count+=1;
                else
                {
                    count+=1;
                    break;
                }
            }
    }
    if(count<=n&&s>=k)
    {
        printf("%d",count);
    }
    else
        printf("-1");

}


#include<stdio.h>
void main()
{
    int n,i,count=0,s=0,r=0;
    long int k;
    scanf("%d%d",&n,&k);
    int a[n];
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        r+=a[i];
    }
    for (i=0;i<n;i++)
    {
        if(a[i]>=8)
            {
                if(i+1<n)
                    a[i+1]+=a[i]-8;
            s+=8;
            if(s<k)
            count+=1;
            else
            {count+=1;
            break;}
            }
        else
            {
                s+=a[i];
                a[i]=0;
                if(s<k)
                count+=1;
                else
                {
                    count+=1;
                    break;
                }
            }
    }
    if(count<=n&&s>=k)
    {
        printf("%d",count);
    }
    else
        printf("-1");
}


/* Teng K. J. */
#include <stdio.h>
#define N 20000
void ignore(int n) {
    while (n-- > 0) getchar();
}
int main() {
    int n, cur = 0, dist;
    char dir;
    scanf("%d", &n);
    while (n-- > 0) {
        scanf("%d %c", &dist, &dir);
        switch (dir) {
        case 'N':
            ignore(5);
            if (cur == 0) goto no;
            cur -= (dist + N) % (2 * N) - N;
            if (cur < 0) cur = -cur;
            if (cur > N) cur = 2 * N - cur;
            break;
        case 'S':
            ignore(5);
            cur += (dist + N) % (2 * N) - N;
            if (cur < 0) cur = -cur;
            if (cur > N) cur = 2 * N - cur;
            break;
        case 'E': case 'W':
            ignore(4);
            if (cur == 0 || cur == N) goto no;
            break;
        }
    }
    if (cur != 0) goto no;
    puts("YES");
    return 0;
no:
    puts("NO");
    return 0;
}


#include <stdio.h>
int main()
{
	int n,i;
	scanf("%d", &n);
	int xcor=0,ycor=0;
	int flag=0;
	char string[n][10];
	for(i=0;i<n;i++)
	{
		int x;

		scanf("%d ", &x);
		scanf("%s", string[i]);

		if(xcor==0 && ycor==0)
		{
			if(string[i][0]!='S')
				{
					flag=1;
		}

		}
		if(ycor>0 || ycor<-20000)
		{
			flag=1;
		}
		if(ycor==-20000 && xcor==0)
		{
			if(string[i][0]!='N')
				{
					flag=1;
		}
		}
		if(string[i][0]=='N')
		{
			ycor+=x;
		}
		else if(string[i][0]=='S')
		{
			ycor-=x;
		}
		else if(string[i][0]=='E')
		{
			xcor+=x;
		}
		else if(string[i][0]=='W')
		{
			xcor-=x;
		}

		//printf("%d %d\n",xcor,ycor);
	}
	if(ycor>0 || ycor<-20000)
		{
			printf("NO");
			return 0;
		}
		if(flag==1)
		{
			printf("NO");
			return 0;
		}
	if(ycor==0 && flag!=1)
		printf("YES");
	else
		printf("NO");
	return 0;

}


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

int main()
{
    int n;
    scanf("%d", &n);
    int distance = 20000;  // distance to South pole
    while (n--) {
        char dir[6];
        int t;
        scanf("%d %s", &t, dir);
        if (distance == 20000 && strcmp(dir, "South") != 0) {
            printf("NO\n");
            return 0;
        }
        if (distance == 0 && strcmp(dir, "North") != 0) {
            printf("NO\n");
            return 0;
        }

        if (strcmp(dir, "South") == 0) {
            distance -= t % 40000;

        } else if (strcmp(dir, "North") == 0) {
            distance += t % 40000;
        }
    }

    if (distance == 20000) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}


#include<stdio.h>
int main()
{
	int n;
	int number;
	char ch[100];
	int sum=0;
	scanf("%d",&n);
	for(int i=0;i<=n-1;i++)
	{
		scanf("%d",&number);
		scanf("%s",ch);
		if(sum==20000)
	    {
	    	if(ch[0]!='N')
	    	sum=-100000;
		}
		if(i=0&&sum==0)
		{
			if(ch[0]!='S')
	    	sum=-100000;
		}
		if(ch[0]=='N')
			sum=sum-number;
		else if(ch[0]=='S')
			sum=sum+number;
		if(sum>20000||sum<0)
		   sum=-100000;
	}
	 if(sum==0)
	 printf("YES");
	 else
	 printf("N0");
}


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

long p[100003] = {0};
long q[100003] = {0};
long i,j,k;

int main()
{
    char a[103],b[103];
    scanf("%s %s",a,b);
    long get = 0;
    for(i = 0 ; i < strlen(a) ; i++)
    {
        int counter = 0;
        if(a[i] == b[0] && a[i+1] == b[1])
        {
            for(j = 0,k = i ; j < strlen(b) ; j++, k++)
            {
                if(a[k] != b[j])
                {
                    counter = 1;
                    break;
                }
            }
            if(counter == 0)
            {
                get = 1;
                printf("automaton");
                break;
            }
        }
    }
    if(get == 0)
    {
        for(i = 0 ; i < strlen(a) ; i++)
        {
            p[a[i]-97]++;
            q[b[i]-97]++;
        }
        if(strlen(a) == strlen(b))
        {
            long counter = 0;
            for(i = 0 ; i < strlen(a) ; i++)
            {
                if(p[i] != q[i])
                {
                    counter = 1;
                    break;
                }
            }
            if(counter == 0)
            {
                printf("array");
            }
            else
            {
                printf("need tree");
            }
        }
        else
        {
            long counter = 0;
            for(i = 0 ; i < strlen(b) ; i++)
            {
                if(p[b[i]-97] < q[b[i]-97])
                {
                    counter = 1;
                    break;
                }
            }
            if(counter == 0)
            {
                printf("both");
            }
            else
            {
                printf("need tree");
            }
        }
    }
    return 0;
}


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

long p[100003] = {0};
long q[100003] = {0};
long i,j,k;

int main()
{
    char a[103] = {'@'},b[103] = {'@'};
    scanf("%s %s",a,b);
    long get = 0;
    for(i = 0 ; i < strlen(a) ; i++)
    {
        int counter = 0;
        if(a[i] == b[0] && a[i+1] == b[1])
        {
            for(j = 0,k = i ; j < strlen(b) ; j++, k++)
            {
                if(a[k] != b[j])
                {
                    counter = 1;
                    break;
                }
            }
            if(counter == 0)
            {
                get = 1;
                printf("automaton");
                break;
            }
        }
    }
    if(get == 0)
    {
        for(i = 0 ; i < strlen(a) ; i++)
        {
            p[a[i]-97]++;
            q[b[i]-97]++;
        }
        if(strlen(a) == strlen(b))
        {
            long counter = 0;
            for(i = 0 ; i < strlen(a) ; i++)
            {
                if(p[i] != q[i])
                {
                    counter = 1;
                    break;
                }
            }
            if(counter == 0)
            {
                printf("array");
            }
            else
            {
                printf("need tree");
            }
        }
        else
        {
            long counter = 0;
            for(i = 0 ; i < strlen(b) ; i++)
            {
                if(p[b[i]-97] < q[b[i]-97])
                {
                    counter = 1;
                    break;
                }
            }
            if(counter == 0)
            {
                printf("both");
            }
            else
            {
                printf("need tree");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
char s[105];
char t[105];
int arr[135];
int count[135];
int main()
{

    int lens,lent,i,j;
    scanf("%s",s);
    scanf("%s",t);
    lens=strlen(s);
    lent=strlen(t);
    if(lens<lent)
        {printf("need tree");
          return 0;
        }
    if(lens>lent)
    {
        i=0;
        j=0;
        while(i<lens && j<lent)
            {
                if(s[i]==t[j])
                {
                    i++;
                    j++;
                }
                else
                    i++;
            }
          if(j==lent)
          {
              printf("automaton");
              return 0;
          }
    }
    for(i=0;i<lens;i++)
     {
         arr[s[i]]++;
     }
    for(i=0;i<lent;i++)
    {
        if(arr[t[i]]!=0)
            arr[t[i]]--;
        else
            {
                printf("need tree");
                return 0;
            }
    }
   if(i==lent && lens==lent)
        printf("array");
   else if(i==lent && lens>lent)
     printf("both");
}


#include <stdio.h>

char S[200], T[200];
int DP[200][200];
int X[1000], Y[1000];
int M, N;

int main()
{
	//FILE *input, *output;
	//input = fopen("suffix.in", "r");
	int i, j, k, b, d;
	char c;

	for(M=0; ; M++)
	{
		//fscanf(input, "%c", &c);
		scanf("%c", &c);
		if(c == '\n')
			break;
		S[M] = c;
		X[(char) c]++;
	}
	for(N=0; ; N++)
	{
		//fscanf(input, "%c", &c);
		scanf("%c", &c);
		if(c == '\n')
			break;
		T[N] = c;
		Y[(char) c]++;
	}

	if(M < N)
	{
		printf("need tree\n");
		return 0;
	}

	if(M == N)
	{
		for(i=0, b=0; i<1000; i++)
		{
			if(X[i] != Y[i])
				b = 1;
		}

		if(b == 0)
			printf("array\n");
		else
			printf("need tree\n");
		return 1;
	}

	for(i=0; i<N && i<M; i++)
	{
		for(j=0; j<N || j<M; j++)
		{
			if(T[i] != S[j])
				continue;
			if(i == 0)
			{
				DP[i][j] = 1;
				continue;
			}
			for(k=0; k<j; k++)
			{
				if(DP[i-1][k] == 1)
					DP[i][j] = 1;
			}
		}
	}

	if((N < M && DP[N-1][M-1] == 1))
	{
		printf("automaton\n");
		return 1;
	}

	for(i=0, d=0; i<1000; i++)
	{
		if(X[i] < Y[i])
			d = 1;
	}

	if(d == 0)
		printf("both\n");
	else
		printf("need tree\n");
	return 1;
}


#include<stdio.h>
#include<string.h>
char s[105];
char t[105];
int arr[135];
int count[135];
int main()
{

    int lens,lent,i,j;
    scanf("%s",s);
    scanf("%s",t);
    lens=strlen(s);
    lent=strlen(t);
    if(lens<lent)
        {printf("need tree");
          return 0;
        }
    if(lens>lent)
    {
        i=0;
        j=0;
        while(i<lens && j<lent)
            {
                if(s[i]==t[j])
                {
                    i++;
                    j++;
                }
                else
                    i++;
            }
          if(j==lent)
          {
              printf("automaton");
              return 0;
          }
    }
    for(i=0;i<lens;i++)
     {
         int k=s[i];
         arr[k]++;
     }
    for(i=0;i<lent;i++)
    {
         int q=t[i];
        if(arr[q]!=0)
            arr[q]--;
        else
            {
                printf("need tree");
                return 0;
            }
    }
   if(i==lent && lens==lent)
        printf("array");
   else if(i==lent && lens>lent)
     printf("both");
}


#include<stdio.h>

#define scan(a) scanf("%d",&a)

/// >........cpp code

int main()
{

  int h1,m1,h2,m2;

  fuad :

    scanf("%d %d",&h1,&m1);
    scanf("%d %d",&h2,&m2);

    int res1=h1*60+m1;
    int res2=h2*60+m2;

    int main_res=res2-res1;
    main_res/=2;

    int m_h=h1+main_res/60;

   if(m_h<10)
    printf("0%d:",m_h);
    else

    printf("%d:",m_h);

    m1=m1+main_res%60;
    if(m1<10)
    printf("0%d\n",m1);
    else
    printf("%d\n",m1);

    goto fuad;

  ///

    return 0;
}


#include<stdio.h>
void main()
{
int d,l,v,s;
float a,b,c;
scanf("%d",&d);
scanf("%d",&l);
scanf("%d",&v);
scanf("%d",&s);
a=l-d;
b=v+s;
c=a/b;
printf("%f",c);
return;
}


#include<stdio.h>
main()
{
int d,l,v,s;
float a,b,c;
scanf("%d",&d);
scanf("%d",&l);
scanf("%d",&v);
scanf("%d",&s);
a=l-d;
b=v+s;
c=a/b;
printf("%f",c);
return;
}


//1.5
//Satyam Chaurasia Abhishek Chauhan
#include<stdio.h>
int main()
{
	int l,d,v1,v2,eq1,eq2;
	float t;

	scanf("%d%d%d%d",d,l,v1,v2);
	eq1=(l-d);
	eq2=(v1+v2);
	t=eq1/eq2;
	printf("%f ",t);
return(0);
}


#include<stdio.h>
void main()
{
float d,l,v,s,a,b,c;
printf("plz enter d");
scanf("%f",&d);
printf("enter length");
scanf("%f",&l);
printf("enter v and s");
scanf("%f",&v);
scanf("%f",&s);
a=l-d;
b=v+s;
c=a/b;
printf("ur answer=%f",c);
return;
}


#include <stdio.h>

int main(void)
{
    int k, i;

    scanf("%d", &k);

    if (k == 1) {
        putchar('4');
    } else if (k > 36) {
        putchar('-');
        putchar('1');
    } else {
        for (i = 0; i < k / 2; i++) {
            putchar('8');
        }

        if (k & 1) {
            putchar('0');
        }
    }

    return 0;
}


#include<stdio.h>

int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	long long a[n],b[m];
	int i=0;
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	i=0;
	long long max;
	int maxi=i;
	for(i=1;i<n;i++){
		max=a[maxi];
		if(a[i]>max){
			maxi=i;
		}
	}
	max=a[maxi];
	long long temp;
	if(maxi){
		temp=a[0];
		a[0]=max;
		a[maxi]=temp;

	}
	i=1;
	maxi=i;
	for(i=2;i<n;i++){
		max=a[maxi];
		if(a[i]>max){
			maxi=i;
		}
	}
	max=a[maxi];
	for(i=0;i<m;i++){
		scanf("%lld",&b[i]);
	}
	int j=0;
	long long maxb;
	int maxbj=j;
	for(j=1;j<m;j++){
		maxb=b[maxbj];
		if(b[j]>maxb){
			maxbj=j;
		}
	}
	maxb=b[maxbj];
	printf("%lld",maxb*max);
	return 0;
}


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

}


#include <stdio.h>
int main(k){
    scanf("%i", &k);
    if(k>36) {printf("%i", -1); return;}
    for(int i=0 ; i<k/2 ; i++) printf("8");
    if(k%2) printf("6");
}


#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int T1,T2,x,y,z,t1,t2,t3;
	scanf("%d,%d,%d,%d,%d,%d",x,y,z,t1,t2,t3);
	T1=abs(z-x)*t2+abs(x-y)*t2+3*t1;
	T2=abs(x-y)*t1;
	if (T1<T2)
	     printf("YES");
	     else
	         printf("NO");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int i,a1,a2,a3,b1,b2,b3,n;
    double sum1,sum2,cup,medal;
    scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&b1,&b2,&b3);
    scanf("%d",&n);
    sum1=a1+a2+a3;
    sum2=b1+b2+b3;
    cup=ceil(sum1/5);
    medal=ceil(sum2/10);
    int total=cup+medal;
    if (total>n)
        printf("NO");
    else
        printf("YES");
    return;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a1,a2,a3,b1,b2,b3,n,sum1,sum2;
    int cup,medal;
    scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&b1,&b2,&b3);
    scanf("%d",&n);
    sum1=a1+a2+a3;
    sum2=b1+b2+b3;
    cup=(sum1+5-1)/5;
    medal=(sum2+10-1)/10;
    int  total=cup+medal;
    if (total<n)
        printf("YES");
    else
        printf("NO");
    return;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int a1,a2,a3,b1,b2,b3,n,sum1,sum2;
    double cup,medal;
    scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&b1,&b2,&b3);
    scanf("%d",&n);
    sum1=a1+a2+a3;
    sum2=b1+b2+b3;
    cup=(sum1+5-1)/5;
    medal=(sum2+10-1)/10;
    int  total=cup+medal;
    if (total<n)
        printf("YES");
    else
        printf("NO");
    return;
}


#include <stdio.h>
#include <stdlib.h>
long long int yellow,blue,sum,huang,lan;
long long int x,y,z;
int main()
{

    scanf("%lld %lld",&yellow,&blue);
    scanf("%lld %lld %lld",&x,&y,&z);//既然用了long long，就用%lld
    huang=2*x+y;//计算我们还需要多少黄水晶
    lan=3*z+y;//计算我们还需要多少蓝水晶
    if(huang>yellow)//如果需要的大于我们已有的
        sum=sum+huang-yellow;//把差的加进sum里面
    if(lan>blue)
        sum=sum+lan-blue;//同理
    printf("%lld",sum);//输出
    system("pause");
    return 0;
}


#include<stdio.h>

int main()
{
	unsigned int A,B;
	unsigned int x,y,z;
	scanf("%d %d",&A,&B);
	scanf("%d %d %d",&x,&y,&z);
	unsigned int bule,yellow;
	bule=2*x+y;
	yellow=3*z+y;
	unsigned int  min,min_1,min_2;
	min_1=bule<A?0:(bule-A);
	min_2=yellow<B?0:(yellow-B);
	min=min_1+min_2;
	if(min>=min_1)
		printf("%u\n",min);
	else
	{
		unsigned int a=min_1%1000000000+min_2%1000000000;
		unsigned int b=min_1/1000000000+min_2/1000000000+a/1000000000;
		printf("%u",b);

		unsigned int v=1000000000;

		int i;
		for( i=0;i<=9;i++)
		{
			a=a%v;
			v=v/10;
			printf("%u",a/v);
		}
		printf("\n");
	}

	return 0;
}


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

}


#include<stdio.h>

int main()
{
    double n,m;
    scanf("%lf %lf",&n,&m);
    double x1,x2,x3;
    scanf("%lf %lf %lf",&x1,&x2,&x3);
    double count=0;
    double y;
    while(m<x3*3)
    {
        m++;
        count++;
    }
    m=m-x3*3;
    while(m<x2)
    {
        m++;
        count++;
    }
    m=m-x2;
    while(n<x2)
    {
        n++;
        count++;
    }
    n=n-x2;
    while(n<x1*2)
    {
        n++;
        count++;
    }
    n=n-x1*2;
    printf("%.0lf",count);
}


#include<stdio.h>
int main()
{
    long long int a,b;
    scanf("%lld %lld",&a,&b);
    long long int x,y,z;
    scanf("%lld %lld %lld",&x,&y,&z);
    long long int blue=3*z+y;
    long long int yellow=2*x+y;
    long long int req;
    if(a>yellow && b>blue)
        printf("0");
    if(a>yellow && b<blue)
        printf("%lld",3*z+y-b);
    if(a<yellow && b>blue)
        printf("%lld",2*x+y-a);
    if(a<=yellow && b<=blue)
    {
        req=3*z+2*y+2*x-a-b;
        printf("%lld",req);
    }
    return 0;
}


#include<stdio.h>
int main()
{
	long long int i,j,kacakadar,kacinci;
	scanf("%I64d %I64d",&kacakadar,&kacinci);
	long long int dizi[kacakadar+1];
	if(kacakadar%2==0)
	{
		if(kacinci<=kacakadar/2)
			printf("%I64d",1+(kacinci-1)*2);
		else
			printf("%I64d",2+(kacinci-(kacakadar/2+1))*2);
	}
	if(kacakadar%2==1)
	{
		if(kacinci<=(kacakadar/2)+1)
			printf("%I64d",1+(kacinci-1)*2);
		else
			printf("%I64d",2+(kacinci-(kacakadar/2+2))*2);

	}
	return 0;
}


#include<stdio.h>
main()
{
    unsigned long long int n,k;
    scanf("%llu",&n);
    scanf("%llu",&k);
    if (k <= (n + 1) / 2)
    {
        printf("%llu",k*2-1);
    }
    else
    {
        printf("%llu",(k-(n+1)/2)*2);
    }
}


#include <stdio.h>

int main()
{
long long int l1,r1,l2,r2,k,start=0,stop=0,flag=0;
scanf("%lld%lld%lld%lld%lld", &l1,&r1,&l2,&r2,&k);

if (l1<=l2 && l2<=r2 && r2<=r1)
{
//printf("FIRST\n");
start=l2;
stop=r2;
}

else if (l2<=l1 && l1<=r1 && r1<=r2)
{
//printf("second\n");
start=l1;
stop=r1;
}

else if (l1<=l2 && l2<=r1 && r1<=r2)
{
//printf("Third\n");
start=l2;
stop=r1;
}

else if (l2<=l1 && l1<=r2 && r2<=r1)
{
//printf("fourth\n");
start=l1;
stop=r2;
}

else
{
flag=1;
}

if (flag)
{
printf(0);
}

else if (start<=k && k<=stop)
{
printf("%lld",(stop-start));
}

else
{
printf ("%lld",(stop-start+1));
}

return(0);

}


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


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

int g_iAnsR = 0;
int g_iAnsG = 0;
int g_iAnsB = 0;

int exchange( int iRed , int iGreen , int iBlue )
{

	if( iRed == 1 && iGreen == 0 && iBlue == 0 )
		g_iAnsR++;

	if( iRed == 0 && iGreen == 1 && iBlue == 0 )
		g_iAnsG++;

	if( iRed == 0 && iGreen == 0 && iBlue == 1 )
		g_iAnsB++;

	// mix RR
	if( iRed >= 2 )
	{
		exchange( iRed - 1, iGreen , iBlue );
	}
	// mix RG
	if( iRed >= 1 && iGreen >=1 )
	{
		exchange( iRed - 1, iGreen - 1 , iBlue + 1 );
	}
	// mix RB
	if( iRed >= 1 && iBlue >=1 )
	{
		exchange( iRed - 1, iGreen + 1 , iBlue - 1 );
	}

	// mix GG
	if( iGreen >= 2 )
	{
		exchange( iRed , iGreen - 1 , iBlue );
	}

	// mix GB
	if( iGreen >= 1 && iBlue >=1 )
	{
		exchange( iRed + 1, iGreen - 1 , iBlue - 1 );
	}

	// mix BB
	if( iBlue >= 2 )
	{
		exchange( iRed , iGreen  , iBlue - 1 );
	}

	return 0;

}

/*

	RGB
	333

	233	323	332
	133	313	331
	024	204	240
		113	131
			040
	113

	004

	444
	344
	244

*/

int main()
{

	int iCnt;
	char aCards[201];
	int i;
	int iRed,iGreen,iBlue;

	scanf("%d", &iCnt );
	scanf("%s", aCards );

	iRed = iGreen = iBlue = 0;

	for( i = 0 ; i < iCnt ; i++ )
	{
		if( aCards[i] == 'R' )
			iRed++;
		else if( aCards[i] == 'G' )
			iGreen++;
		else if( aCards[i] == 'B' )
			iBlue++;
	}

	iRed = iRed % 10;
	iGreen = iGreen % 10;
	iBlue = iBlue % 10;

	exchange( iRed , iGreen, iBlue );

	// Blue , Green, Red order
	if( g_iAnsB )
		printf("B");

	if( g_iAnsG )
		printf("G");

	if( g_iAnsR )
		printf("R");

	printf("\n");

	return 0;
}


#include<stdio.h>

int ans[3] = {(0)};
void convert(char in[], int out[]){
 int i = 0;
 while(in[i]){
 	if (in[i] == 'R')
	 	out[0] += 1;
	else if (in[i] == 'G')
		out[1] += 1;
	else
 		out[2] += 1;
 	i++;

	}
 i = 0;
 while(i < 3){
 	if (out[i] > 1)
 		out[i] = 2;
 }
}

void play(int r, int g, int b){
	if(r + b + g == 1){
		if(r == 1)
			ans[0] = 1;
		else  if(g == 1)
			ans[1] = 1;
		else
			ans[2] = 1;
	}
	else{
		if(r >= 2)
			play(r - 1, g, b);
		if(g >= 2)
			play(r , g - 1, b);
		if(b >= 2)
			play(r , g, b - 1);
		if(r >= 1 && g >= 1)
			play(r - 1 , g -1, b + 1);
		if(r >= 1 && b >= 1)
			play(r - 1 , g + 1, b - 1);
		if(g >= 1 && b >= 1)
			play(r + 1 , g - 1, b - 1);
	}
}

void output(){

	if (ans[2])
		printf("B");
	if (ans[1])
		printf("G");
	if (ans[0])
		printf("R");

}
int main(){
	char in[201];
	int n, out[3] = {(0)};
	scanf("%d", &n);
	scanf("%s", &in);
	convert(in, out);

	play(out[0], out[1], out[2]);

	output();
	return 0;
}


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

int *rgb;

void solve(int r,int g,int b)
{
	//printf("%d %d %d\n",r,g,b);
	if(r+g+b==1)
	{
		if(r) rgb[0]=1;
		if(g) rgb[1]=1;
		if(b) rgb[2]=1;
	}
	else
	{
		if(r>1) solve(r-1,g,b);
		if(g>1) solve(r,g-1,b);
		if(b>1) solve(r,g,b-1);

		if(r && g) solve(r-1,g-1,b+1);
		if(r && b) solve(r-1,g+1,b-1);
		if(g && b) solve(r+1,g-1,b-1);
	}
}

void read()
{
	rgb=calloc(3,sizeof(int));

	int i,n;

	scanf("%d",&n);

	int r=0,b=0,g=0;
	char c;

	for(i=0;i<n;i++)
	{
		scanf("%c",&c);
		switch(c)
		{
			case 'B':
				b++;
				break;
			case 'G':
				g++;
				break;
			case 'R':
				r++;
				break;
			default:
				i--;
				break;
		}
	}

	solve(r,g,b);
}

void print()
{
	if(rgb[2]) putchar('B');
	if(rgb[1]) putchar('G');
	if(rgb[0]) putchar('R');
	putchar('\n');
}

int main()
{
	read();
	print();

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX(a,b)  ((a>b) ? a : b)
#define MIN(a,b)  ((a<b) ? a : b)
#define swap(a,b) { t=a; a=b; b=t; }
int n,i,j,h[100002],t,k,artis;
char a[101];
int main()
{
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf(" %c",a+i);
	}
	for(i=0;i<n;i++)
	{
		if(a[i]=='.')
			continue;
		for(j=i+1;j<n;j++)
		{
			if(a[i]=='.')
				continue;
			artis=j-i;
			t=0;
			for(k=j;k<n;k+=artis)
			{
				if(k>=n)
					break;
				if(a[k]=='*')
					t++;
			}
			if(t>=4)
			{
				printf("yes");
				return 0;
			}
		}
	}

	printf("no");
	return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{int a,b,c=0,d,e,f,i,j,k,p=1,q,r,sum=1;
 char s[200];
 int z[102];
 scanf("%d",&d);
 scanf("%s",&s);

 for(i=0;i<d;i++)
 {if(s[i]=='*')
  {z[c]=i;
   c=c+1;}
   }
 for(j=0;j<c-1;j++)
    {   sum=0;

        for(k=j+1;k<c;k++)
              {e=z[j+k]-z[j];
              f=z[j+k];
              while(f<=d)
              {
               f=f+e;

              if(s[f]=='*')
              {
                  sum=sum+1;
              }
              else
              {
                  break;
              }

          }}
          if(sum>=4)
          {
              break;
          }
    }
    if(sum>=4)
    {
        printf("yes\n");
    }
    else
    {
        printf("no\n");
    }
return 0;}


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

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

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

	char *found = strchr(line, '*');
	char c1, c2, c3, c4;
	int i, j;
	for ( i = found-line; i < n; i++ ) {
		if ( line[i] != '*' ) continue;

		for ( j = 1; j < n && i+4*j < n; j++ ) {
			c1 = *(line+i+j); c2 = *(line+i+2*j);
			c3 = *(line+i+3*j); c4 = *(line+i+4*j);
			if ( c1 != '.' && c2 != '.' && c3 != '.' && c4 != '.' ) {
				printf("yes\n");
				return;
			}
		}
	}

	printf("no\n");

	return 0;
}


#include<stdio.h>

int main()
{
    int n,i,count=0,j,k;
    scanf("%d",&n);
    char str[n];
    int ara[n];
    scanf("%s",str);
    for(i=0,j=0;i<n;i++){
        if(str[i]=='*'){
            count+=1;
            ara[j]=i;
            j++;
        }
    }
    //printf("%d",j);
    int ara_dif[21]={0};
    if(count<5){
        printf("no");
    }
    else{
        for(i=0;i<j-1;i++){
            for(k=i+1;k<j;k++){
               ara_dif[ara[k]-ara[i]]++;
            }
        }
        for(i=0;i<21;i++){
            if(ara_dif[i]>=4){
                printf("yes");
                break;
            }
        }
        if(i==21)printf("no");
    }
    return 0;
}


#include <stdio.h>

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

    res = ((int)n/2)*3 + n%2;

    printf("%d", res);

}


#include <stdio.h>

int main(void)
{
    int n;
    scanf("%d",&n);
    int max=1,tmp=0;
    int i,j;
    for(i=1;i<=n-1;i++){

        for(j=1;j<=n-i;j++){
            if(n-i>=n-j) tmp=n+i;
            else tmp=n+j;
            if(max<tmp) max=tmp;

        }

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


#include<stdio.h>
int main()
{
long long int n,a[100000],i,j,max;
scanf("%I64d",&n);
for(i=1;i<=n;i++)
{if(i<=n/2)
a[i]=n+i;
else
a[i]=(2*n)-i;}
max=a[1];
for(j=1;j<=n;j++)
{if(a[j]>max)
max=a[j];}
printf("%I64d",max);
return(0);}


#include<stdio.h>
# include <ctype.h>
#include<conio.h>
main()
{
    int n;
    scanf("%d",&n);
    printf("%d",(2*n)-(n/2)) ;
     getch();
    return 0;
}


#include <stdio.h>

int main(void) {
	int n;

	scanf("%d", &n);
	printf("%d\n", (3 * n) / 2);

	getch();

	return 0;
}


#include<stdio.h>
int main()
{
	int a, b, x, xa, xb;
	scanf("%d %d %d", &a, &b, &x);
	xa=0;
	xb=0;
	for(int i=0; i<=x-1; i++){
		if(xa==xb){
			printf("0");
			xa++; a--;
		}
		else if(xa>xb){
			printf("1");
			xb++; b--;
		}
	}
	if(xa==xb){
		for(int i=0; i<b; i++) printf("1");
		for(int i=0; i<a; i++) printf("0");
	}
	if(xa>xb){
		for(int i=0; i<a; i++) printf("0");
		for(int i=0; i<b; i++) printf("1");
	}
}


#include<stdio.h>
#include<stdlib.h>
void main()
{
long long n;long long i;long long j;long long count;count=0;
scanf("%lld",&n);

long long x[n];long long y[n];
long long *p;

p=(long long*)calloc(90000000,sizeof(long long));
for(i=0;i<90000000;i++)
	p[i]=0;

for(i=0;i<n;i++){
scanf("%lld",&x[i]);
p[x[i]]=1;}

for(i=0;i<n;i++){
scanf("%lld",&y[i]);
p[y[i]]=1;}

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(p[(x[i]^y[j])]==1){
count++;}
}
}

if(count%2==0)
printf("Karen\n");
else
printf("Koyomi\n");
exit(0);}


#include<stdio.h>
#define N 1000000
int t[N+N]={};
int main()
{
  int n,cpt=0;
  int x[n];
  int y[n];
    printf("deeeeee");
    scanf("%d",&n);
    for(int i=0; i<n;i++)
        {scanf("%d",x[i]);
        t[x[i]]++;
        t[x[i]]=1;}

    for(int j=0; j<n;j++)
         {scanf("%d",y[j]);
         t[y[j]]++;
         t[y[j]]=1;}

    for(int i=0;i<n;i++)
       {
           for(int j=0;j<n;j++)

            {if (t[x[i]^y[j]])
                cpt++;}

       }

  if (cpt%2==0)
    printf("karen");
  else
    printf("kayomi");

    return 0;
}


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

int main()
{

	double total_time;
	clock_t start, end;
	start = clock();
	//time count starts
	srand(time(NULL));

    int n,a[2000],i,j,k,t,count=0;
    scanf ("%d", &n);
    int x[n*2];
    for (i=0; i<n*2; i++)
    {
        scanf ("%d", &x[i]);
    }
    for(i=0; i<n; i++)
    {
        for (j=0; j<n; j++)
        {
            t = x[i] ^ x[n+j];
            for(k=0; k<n*2; k++)
            {
                if(t==x[k])
                {
                    count++;
                    break;
                }
            }

        }
    }
    if(count%2 ==0)
    {
        printf ("Karen");
    }
    else
    {
        printf ("Koyomi");
    }

    end = clock();
	//time count stops
	total_time = ((double) (end - start)) / CLK_TCK;
	//calulate total time
	printf("\nTime taken to print 25000 random number is: %f", total_time);
	getch();
	return 0;
}


#include <stdio.h>
#include <math.h>
int main () {
    unsigned long long a;
    int b, i;
    scanf("%d", b);
    for (i = 0; i < b; i++) {
        a += pow(2, i);
    }
    printf("%lld", a);
}


#include <stdio.h>
#include <math.h>
int main () {
    unsigned long long a;
    int b, i;
    scanf("%d", b);
    for (i = 0; i < b; i++) {
        a += pow(2, i);
    }
    printf("%lld", a);
    return 0;
}


#include <stdio.h>
#include <math.h>
int main () {
    unsigned long long a = 0;
    int b, i;
    scanf("%d", b);
    for (i = 0; i <= b; i++) {
        a += pow(2, i);
    }
    printf("%lld", a - 1);
    return 0;
}


#include <stdio.h>
#include <math.h>
int main () {
    unsigned long long a = 0;
    int b, i;
    scanf("%d", b);
    for (i = 0; i < b; i++) {
        a += pow(2, i);
    }
    printf("%lld", a);
    return 0;
}


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

void main()
{
    int num,i,sum=0;
    scanf("%d",&num);
    for(i=num;i>=1;i--)
    {
        sum =sum+powl(2,i);
    }
    printf("%d",sum);

}


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


#include <stdio.h>
int main()
{
 int n,a,b,c,x;
 scanf("%d",a);
 scanf("%d",b);
 scanf("%d",c);
 scanf("%d",n);
 x=a+b-c;
   if(n-x>=1&&a>=c&&b>=c)
       printf("%d",n-x);
   else
       printf("-1");
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a,b,c,n;
	scanf("%d%d%d%d",&a,&b,&c,&n);
	int a1=a,b1=b,c1=c,n1=n;
	a1=a-c1;
	b1=b-c1;
	int r;
	if(a1<=0 || b1<=0)
	{
		printf("-1\n");
		exit(0);
	}
	r=n-(a1+b1+c1);
	if(r<=0)
	{
		printf("-1\n");
	}
	else
	{
		printf("%d\n",r);
	}
}


#include<stdio.h>
int main()
{
    int a, b, c, n, ans;
    scanf("%d %d %d %d", &a, &b, &c, &n);
    ans = n - (a-c+b);
    if(ans > 0 && a > c && b > c)
        printf("%d", ans);

    else
        printf("-1");

}


#include <stdio.h>
#include <string.h>
int main ()
{
    char a[200], b[200], c[200];
    int i, j; char temp;
    gets(a);
    gets(b);
    strcat(a,b);
    gets(c);
    int lena=strlen(a), lenc=strlen(c);
    for (i=0; i<lena; i++){
        for (j=i+1; j<lena; j++){
            if (a[i]>a[j]){
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    for (i=0; i<lenc; i++){
        for (j=i+1; j<lenc; j++){
            if (c[i]>c[j]){
                temp=c[i];
                c[i]=c[j];
                c[j]=temp;
            }
        }
    }
    if (strcmp(a,c)==0) printf ("YES");
    else printf ("NO");
    return 0;
}


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

int main(){

int i,j,k,l,swap,a=0,swapa;
char str1[101],str2[101],arr[201],are[201],temp,tempa;

gets(str1);
gets(str2);
gets(are);

for(i=0;i<101;i++){

    if(str1[i] == 0)
        break;

    arr[i] = str1[i];

        }

k=i;

for(j=0;j<101;j++){

    if(str2[j] == 0)
        break;

    while(1){

        arr[k] = str2[j];
        k++;
        break;
    }

}

while(1){

    swap = 0;
    for(i=0;i<k-1;i++){

    if(arr[i] > arr[i+1]){

        temp = arr[i];
        arr[i] = arr[i+1];
        arr[i+1] = temp;
        swap = 1;

    }

}
if(swap == 0)
    break;

}

for(l = 0;l<201;l++){
    if(are[l] == 0)
        break;

}

if(l!=k){
    printf("NO");
    return 0;;
}

while(1){

    swapa = 0;

for(i=0;i<l-1;i++){

    if(are[i] > are[i+1]){

        tempa = are[i];
        are[i] = are[i+1];
        are[i+1] = tempa;
        swapa = 1;

    }

}
if(swapa == 0)
    break;

}

a = strncmp(are,arr,k);

if(a == 0)
    printf("YES");

else
    printf("NO");

return 0;
}


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

#define LEN 250
#define L 26

int repeats(char stringArr[LEN],int R[L]){
    int i;

    for (i=0;i<strlen(stringArr)-1;i++)
        R[stringArr[i]-'A']++;
    return 0;
}
int main(){
    char name1[LEN],name2[LEN],letters[LEN];
    int N_1[L]={0},N_2[L]={0},N_l[L]={0};
    int i=0,flag=1;
    fgets(name1,LEN,stdin);
    fgets(name2,LEN,stdin);
    fgets(letters,LEN,stdin);

    repeats(name1,N_1);
    repeats(name2,N_2);
    repeats(letters,N_l);

    while (flag==1 && i<L){
        if (N_l[i]!= N_1[i]+N_2[i]) flag=0;
        i++;
    }
    if (flag==1) printf("YES");
    else printf("NO");
    return 0;
}


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

int main()
{
    int n,k,b,t;
    int time;
    scanf("%d%d%d%d",&k,&b,&n,&t);
    while(k!=0){
        time=(t/k)-b;
            if(time>n)printf("0\n");
            else printf("%d\n",n-time);
    scanf("%d%d%d%d",&k,&b,&n,&t);
    }
    return 0;
}


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

int main()
{
    int k , b , n , t , number = 0 , sum = 1 , counter , sum2;
    scanf("%d %d %d %d",&k,&b,&n,&t);
    for (counter = 0 ; counter < n ; counter++)
    {
        sum = k * sum + b;
    }
    sum2 = k * t + b;
    if (sum2 < sum)
    {
        number = 1;
    }
    while (sum2 < sum)
    {
        number++;
        sum2 = sum2 * k + b;
    }
    printf("%d",number);
}


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

int main()
{
    long long b,k,n,t,a[100000];
    int i=0;
    int sec=0;
    scanf("%lld",&k);
    scanf("%lld",&b);
    scanf("%lld",&n);
    scanf("%lld",&t);
    a[0]=1;
    for (i=1 ; a[i-1]<t ; i++)
    {
        a[i]=k*(a[i-1])+b;
        sec++;
    }
    if (sec>n)
        printf("0");
    else if (a[i]==t)
        printf("%lld",n-sec);
    else
        printf("%lld",n-(sec-1));
}


#include<stdio.h>
main()
{
    int counter=-1,pop=1,k,b,t,n;
    scanf("%d %d %d %d",&k,&b,&n,&t);
    while(pop<=t)
    {
        pop=pop*k+b;
        counter++;
        //printf("%d\n",pop);
    }
    if(counter>n){
        printf("0");
        return 0;
    }
    printf("%d",n-counter);
}


#include <stdio.h>

typedef long long ll;

int main() {
    int k,b,n,t,i;
    ll z;
    scanf("%d %d %d %d",&k,&b,&n,&t);
    z=1;
    for(i=0;z<t;i++) z=k*z+b;
    if(i>n) puts("0");
    else printf("%d\n",n-i+1);
    return 0;
}


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

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

 if(n==1){
    printf("-1");
    return 0;
 }
 for(i=0;i<n;i++){
        scanf("%d",&a[i]);

 }
 if(a[n-1]==15){
    printf("DOWN");
 }
 else if(a[n-1]>a[n-2]){
    printf("UP");
 }
 else if(a[n-1]<a[n-2]){
    printf("DOWN");
 }

}


#include <stdio.h>
int main(){
	int i,n,a,alast,abeforelast;
	scanf("%d",&n);
	if(n==1){
		scanf("%d",&a);
		printf("-1");
		return 0;
	}
	for(i=0;i<n-1;i++){
		scanf("%d",&a);
	}
	scanf("%d",&alast);
	abeforelast=a;

	if(abeforelast<alast){
		if(alast<15){
			printf("UP");
			return 0;
		}
		else if(alast==15){
			printf("DOWN");
			return 0;
		}
	}
	else if(abeforelast>alast){
		if(alast>0){
			printf("DOWN");
			return 0;
		}
		else if(alast==0){
			printf("UP");
			return 0;
		}
	}
	return 0;
}


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


#include<stdio.h>
int main()
{
	int i,n;
	int find=2;
	int day[93];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{	scanf("%d",&day[i]);
	}
	if(n==1)
	printf("-1");
	i=1;
	while(i<n)
	{
		if(day[i]<day[i+1]&&day[i]!=15&&day[i+1]!=15)
		{find=1;
		}
		else if(day[i]==15||day[i]>day[i+1]||day[i=1]==15)
		{find=0;
		}
		i++;
		}
	if(find==1)
		printf("UP");
	if(find==0)
		printf("DOWN");

}


#include <stdio.h>
#include <string.h>
int main()
{
     char a,b,c,d,e;
     int i,j,k,l;
     scanf("%d:%d",&i,&j);

     for(l=0; ;l++)
     {
          if(j>59)
          {
               i++;
               j=0;
          }
         else if(i==24 && j==0)
          break;
     else     if(i%10==j/10)
          break;

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


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

int main()
{
    int h, m, i, j, ne, ekok, dosok;
    char ch;
    scanf("%d%c%d", &h, &ch, &m);
    ekok = h  % 10;
    dosok = h / 10;
    ne = ekok * 10 + dosok;
    if(h == 23 && m <= 32) {
            printf("%d\n", 32 - m);
    }
    else if(h == 23 && m > 32) printf("%d\n",60 - m);
    //printf("%d", ne);
    if(ne >= m && h != 23){
        printf("%d\n", ne - m);
    }
    else if(ne<m && h!=23){
        ekok = (h+1) % 10;
        dosok = (h+1) / 10;
        ne = ekok * 10 + dosok;
        printf("%d\n",60-m + ne);
        }//printf("%d", m - ne + 60);
}


#include<stdio.h>
int isPalindrome(int x)
{
	if(x%10==x/1000 && (x/100)%10==(x%100)/10)
		return 1;
	else
		return 2;
}
int main()
{
	char str[5];
	scanf("%s",str);
	int i;
	int x;
	for(i=0;i<5;i++)
		str[i]=str[i]-'0';
	x=str[0]*1000+str[1]*100+str[3]*10+str[4];
	if(x/100==23)
	{
		printf("%d",60-x%100);
		return 0;
	}
	int count=0;
	while(1)
	{
		if(isPalindrome(x)==1)
		{
			printf("%d",count);
			return 0;
		}
		else
		{
			count++;
			if(x%100<=58)
				x++;
			else
				x=x+100-(x%100);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char time[5],time1[3],time3[3],org[3];
    int i=0,num1=0,num2=0,num3=0,total,c=0;
    scanf("%s",time);
    for(i=0;i<2;i++)
    {
        time1[i]=time[1-i];
        time3[i]=time[3+i];
       // printf("%c",time3[i]);
        org[i]=time[i];
        if(time[i]!=time[4-i])
        c=1;
    }
   // printf(" i=%d\n",i);
    time1[i]='\0';
    time3[i]='\0';
   // printf(" Hi %s\n",time3);
    org[i]='\0';
    num1=atoi(time1);
    num2=atoi(time3);
    num3=atoi(org);
  //  printf("%d %d\n",num1,num2);
    if(c==0)
    printf("%d",0);
    else if(num1>num2 && (num1<=59))
    printf("%d",(num1-num2));
    else
    {
        if(num1==num2)
        printf("%d",0);
        else if(num3==23)
        printf("%d",(60-num2));
        else
        {
            num3++;
            org[0]=48+num3%10;
            org[1]=48+num3/10;
            org[2]='\0';
         //   printf("Bye %c\n",org);
            num3=atoi(org);
            printf("%d",(60-num2)+num3);
        }
    }
    return 0;
}


#include<stdio.h>
int main()
{
    long long int n,x,i,count=0,s;
    scanf("%I64d%I64d",&n,&x);
    s=x/n;
    for(i=s; i<=n; i++)
    {
        if(x%i==0 && (x/i)<=n)
            count++;
    }
    printf("%I64d",count);
}


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

main()
{

    long n,x,i,j,k=0;

    scanf("%li %li",&n,&x);

    for(i=0;i<=n;i++)
        for(j=0;j<=n;j++)
            if(i*j==x) k++;

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

     system("pause");
    return 0;
}


#include <stdio.h>
int main()
{
    int M,N,x, y;
    scanf("%d %d", &M, &N);
    y=M*N/2;
    for (x=1; x<=y; x=x+1)
     { if (x=y && N!=1)printf("%d", x); }
    return 0;
}


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

int main()
{
    int M, N, x, i ;
    for(i=0;M>=16 || N>=16 || M<=1 || N<=1 || N<=M;i=i+0){

    scanf("%d%d",&M, &N);
    }
    x=(M*N) / 2;

    printf("%d", x);

     return 0;
}


#include <stdio.h>
int main()
{
    int m,n;
    while(1) {
        scanf("%d %d",&m,&n);
        printf("%d\n", (m*n) / 2);
    }
    return 0;
}


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

int main()
{
    int M, N, x,i;
    for(i=0;M>=16 || N>=16 || M<=1 || N<=1 || N<=M;i=i+0){

    scanf("%d%d",&M, &N);
    }
    x=M*N;
    printf("%d", x/2);

     return 0;
}


#include <stdlib.h>
#include <stdio.h>
int main(){
    int M, N, resultado;
    for(;;){
		scanf("%d %d", &M, &N);
		resultado = (M*N)/2;
		printf("%d\n", resultado);
	}
}
/* 1498226413884 */


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

int main(void)
{
	int array[5][5];
	int i,j;
	int sum=0;

	for (i = 0; i < 5; i++)
	{	for (j = 0; j < 5; j++)
		{
			scanf("%d",array[i][j]);
		}
	}

	if(array[3][3]!=1){
	for (i = 0; i < 5; ++i)
	{	for (j = 0; j < 5; ++j)
		{	if(array[i][j]==1)
			{
				sum=(3-i)+(3-j);
				i+=3-i;
				j+=3-j;
				break;

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

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
main()
{

    int matrice[5][5];
    int i,j,nbr=6;
for(i=0;i<5;i++)
{
scanf("%d %d %d %d %d",&matrice[i][0],&matrice[i][1],&matrice[i][2],&matrice[i][3],&matrice[i][4]);
}
    for(i=0;i<5;i++)
    {
        for(j=0;j<5;j++)
        {
            if(matrice[i][j]==1)
            {
                if(i<2)
               nbr=2-i;
               else
               nbr=i-2;
                if(j<2)
               nbr+=2-j;
               else
               nbr+=j-2;

            }
        }

    }
    printf("%d",nbr);
    getch();
}


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

    int matrice[5][5];
    int i,j,nbr=6;

    for(i=0;i<5;i++)
    {
        for(j=0;j<5;j++)
        {

            matrice[i][j]=getch();

            if(matrice[i][j]=='1')
            {
               nbr=abs(i-2)+abs(j-2);

            }
        }

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


#include <stdlib.h>
#include <stdio.h>
int main ()
{
	int cont,num,cant_num,prev,good,best;
	scanf("%d",&cant_num);
	best=0;
	prev=0;
	good=0;
	for(cont=0;cont<cant_num;cont++)
	{
		scanf("%d",&num);
		good++;
		if(num<prev)
		{
			if(best<good)
			{
				best=good;
			}
			good=0;
		}
		prev=num;
	}
	printf("%d",best);
	scanf("%d","&num");
}


#include <stdio.h>

int main() {
    int N;
    int K;
    scanf("%d %d", &N, &K);
    int* counters = malloc(100 * sizeof(int));
    for (int i = 0; i < 100; i++) {
        *(counters + i * sizeof(int)) = 0;
    }
    int t;
    for (int i = 0; i < N; ) {
        scanf("%d", &t);
        *(counters + t * sizeof(int)) = ++i;
    }
    int distincts = 0;
    for (int i = 0; i < 100; i++) {
        if (*(counters + i * sizeof(int)))
            distincts++;
    }
    int p= 0;
    if (distincts >= K) {
        printf("YES\n");
        for (int i = 0; i < 100 && p < K; i++) {
            if (*(counters + i * sizeof(int))) {
                printf("%d ", *(counters + i * sizeof(int)));
                p++;
            }
        }
    }
    else {
        printf("NO");
    }
}


#include <stdio.h>

int main() {
    int N;
    int K;
    scanf("%d %d", &N, &K);
    int* counters = malloc(100 * sizeof(int));
    for (int i = 0; i < 100; i++) {
        *(counters + i * sizeof(int)) = 0;
    }
    int t;
    for (int i = 0; i < N; ) {
        scanf("%d", &t);
        *(counters + t * sizeof(int)) = ++i;
    }
    int distincts = 0;
    for (int i = 0; i < 100; i++) {
        if (*(counters + i * sizeof(int)))
            distincts++;
    }
    int p = 0;
    if (distincts >= K) {
        printf("YES\n");
        for (int i = 0; i < 100 && p < K; i++) {
            if (*(counters + i * sizeof(int))) {
                printf("%d ", *(counters + i * sizeof(int)));
                p++;
            }
        }
    }
    else {
        printf("NO");
    }
}


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

int main(void)
{
    bool exists = false;
    int n, k, membc = 0, npoint;
    scanf("%d",&n);
    scanf("%d",&k);
    int teamind[k];
    int teamp[k];
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &npoint);
        exists = false;
        for(int j = 0; j < membc && membc < k; j++)
        {
            if(teamp[j] == npoint) exists = true;
        }
        if(exists == false)
        {
            teamp[membc] = npoint;
            teamind[membc] = i + 1;
            membc++;
        }
    }
    if(membc < k) printf("NO");
    else
    {
        printf("YES\n");
        for(int i = 0; i < k; i++)
        {
            printf("%d ", teamind[i]);
        }
    }
}


#include<stdio.h>
#include<string.h>
int main(void)
{
    int n,k,i,j,l,m;
    scanf("%d%d",&n,&k);
    int a[n],team[k];
    for(i=0;i<n;i++) scanf("%d",&a[i]);

    team[0]=1;
    m=1,l=0;

    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]==a[j])
                a[j]=-1;
            else
                team[m++]=j+1;
        }
    }
    for(i=0;i<n;i++)
        if(a[i]!=-1)
            l++;
    if(l<k)
    {
        printf("NO");
        exit(0);
    }
    printf("YES\n");
    for(m=0;m<k;m++) printf("%d ",team[m]);

    return 0;
}


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

int main() {
	int i=0, n=0, j=0, x;
	char a[100];
	gets (a);
	x = strlen(a)-1;
	while(i < x) {
		if(a[i]== a[i-1]) {
		if(a[i]=='1') n++;
		else if (a[i]=='0') j++;
		else return 0;
	}
	else {
		if (a[i]=='1') j=0;
		else i=0;
	}
		i++;
	}
	if (n >=7 || j>=7) printf("YES");
	else printf("NO");
}


#include<stdio.h>
int main()
{
    char s[100];
    int i,d,c1=0,c2=0;
    gets(s);
     d=strlen(s);
    for(i=0;i<d;i++)
    {
        if(s[i]=='1')
            c1++;
        else
            c2++;
    }
    if(c1>=7||c2>=7)
    printf("YES");
    else
        printf("NO");
        getch();
    return 0;

}


#include<stdio.h>
int main()
{
    char s[100];
    int i,c1=0,c2=0;
    gets(s);
    strlen(s);
    for(i=0;i<strlen(s);i++)
    {
        if(s[i]=='1')
            c1++;
        else if(s[i]=='0')
            c2++;
    }
    if(c1>=7||c2>=7)
    printf("YES");
    else
        printf("NO");
        getch();
    return 0;

}


#include<stdio.h>
#include<string.h>
char c[6][500];
int main()
{
    long len1,len2,len3,len4;
    gets(c[1]);
    gets(c[2]);
    gets(c[3]);
    gets(c[4]);
    len1=strlen(c[1])-2;
    len2=strlen(c[2])-2;
    len3=strlen(c[3])-2;
    len4=strlen(c[4])-2;
    if(len1>=len2*2&&len1>=len3*2&&len1>=len4*2)
        printf("A");
    else if(len2>=len1*2&&len2>=len3*2&&len2>=len4*2)
        printf("B");
    else if(len3>=len2*2&&len3>=len1*2&&len3>=len4*2)
        printf("C");
    else if(len4>=len2*2&&len4>=len3*2&&len4>=len1*2)
        printf("D");
    else if(len1<=len2/2&&len1<=len3/2&&len1<=len4/2)
        printf("A");
    else if(len2<=len1/2&&len2<=len3/2&&len2<=len4/2)
        printf("B");
    else if(len3<=len2/2&&len3<=len1/2&&len3<=len4/2)
        printf("C");
    else if(len4<=len2/2&&len4<=len3/2&&len4<=len1/2)
        printf("D");
    else printf("C");
    return 0;

}


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

#define sc      scanf
#define pr      printf
#define dnum    100001

char str[4][110];
int len[4];

int main()
{
    int n,m,i,j,min,max;

    sc("%s%s%s%s",str[0],str[1],str[2],str[3]);

    for(i = 0; i< 4; ++i)
    {
        len[i] = strlen(str[i])-2;
    }

    for(i = 0; i < 4; ++i)
    {
        min = 0;
        max = 0;
        for(j = 0; j < 4; ++j)
        {
            if(i != j)
            {
                if(len[i]*2 <= len[j])
                {
                    min++;
                }

                if(len[i] >= len[j]*2)
                {
                    max++;
                }
            }
        }

        if(max == 3 || min == 3)break;
    }

    if(max != 3 && min != 3)
    {
        printf("C\n");
    }
    else
    {
        printf("%c\n",i+'A');
    }

    return 0;
}


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

int main()
{
    char a[200];
    char b[200];
    char c[200];
    char d[200];
    char x;
    int i;
    int len[4];

    scanf("%c", &x);
    scanf("%c", &x);
    scanf("%s\n", a);
    //getch();
    scanf("%c", &x);
    scanf("%c", &x);
    scanf("%s\n", b);
    //getch();
    scanf("%c", &x);
    scanf("%c", &x);
    //getch();
    scanf("%s\n", c);
    //getch();
    scanf("%c", &x);
    scanf("%c", &x);
    //getch();
    scanf("%s", d);
    //printf("%s\n%s\n%s\n%s\n", a, b, c, d);
    len[0] = strlen(a);
    len[1] = strlen(b);
    len[2] = strlen(c);
    len[3] = strlen(d);

    int min = 101;
    int max = -1;
    int mini;
    int maxi;
    for (i = 0; i < 4; i++) {
        if (len[i] > max) {
            max = len[i];
            maxi = i;
        }
        if (len[i] < min) {
            min = len[i];
            mini = i;
        }
    }
    int flag1 = 1;
    int flag = 1;
    for (i = 0; i < 4; i++) {
        if (i != mini) {
        if (min > (len[i]/2)) {
            flag = 0;
            break;
        }
        }
    }
    if (flag) {
        if (mini == 0) {
            printf("A");
        } else if (mini == 1) {
            printf("B");
        } else if (mini == 2) {
            printf("C");
        } else {
            printf("D");
        }
        flag1 = 0;
    }
    flag = 1;
    for (i = 0; i < 4; i++) {
        if (i != maxi)
        if (max < (2*len[i])) {
            flag = 0;
            break;
        }
    }
    if (flag) {
        if (maxi == 0) {
            printf("A");
        } else if (maxi == 1) {
            printf("B");
        } else if (maxi == 2) {
            printf("C");
        } else {
            printf("D");
        }
        flag1 = 0;
    }
    if (flag1) {
        printf("C");
    }

    return 0;
}


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10]={0} , i , j , n , flag;

for(i=0;i<6;i++)
{
scanf("%d" , &n);
for(j=1;j<10;j++)
{
if(n==j)
{
a[n]++;
break;
}
}
 }

for(i=1;i<10;i++)
{
if(a[i]==4)
{
for(j=1;j<10;j++)
{
if(a[j]==2)
{
flag=1;
break;
}

else
{
flag=0;
}
}
break;
}

else if(a[i]==6)
{
flag=1;
break;
}

else
flag=2;
}

if(flag==1)
printf("Elephant");
else if(flag==0)
printf("Bear");
else  if(flag==2)
printf("Alien");

getch();
}


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

int main()
{
    int i,arr[6],count[10]={0},c1=0,c2=0;
    for(i=0;i<6;i++)
    {
       scanf("%d",&arr[i]);
       count[arr[i]]++;
    }
    for(i=1;i<10;i++)
    {
       if(count[i]==4)
       {    c1=1; break; }
    }
    if(!c1)
    {
       printf("Alien");
      // getch();
    }
    else
    {
       for(i=1;i<10;i++)
       {
           if(count[i]==2)
           {    c2=1; break; }
       }
   /* for(i=1;i<10;i++)
    {
       if(count[i]==1)
       {    temp[k]=1; k++; }
    }*/
       if(c1&&c2)
       {
           printf("Elephant");
       }
       else
       {
           printf("Bear");
       }
    }
    getch();
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
       return ( *(int*)a - *(int*)b );
}

int main()
{
    int a[6],count=0,i,count1=0;
    for(i=0;i<6;i++)
    {
        scanf("%d",&a[i]);
    }

    qsort(a, 6, sizeof(int), cmpfunc);

    for(i=1;i<6;i++)
    {
        if(a[i] != a[i-1])
            count++;
        if(a[i] == a[i-1])
            count1++;
    }
    if(count<=1 && count1>=3)
        printf("Elephant\n");
    else if(count==2 && count1>=3)
        printf("Bear\n");
    else
        printf("Alien\n");
    return 0;
}


#include <stdio.h>

int main()
{
	int N,A,B,C;
	char Error=0;
	scanf("%d",&N);
	while(N)
	{
		A=N%10;
		B=N%100;
		C=N%1000;
		if(A==1)
		{
			N/=10;
		}
		else if(B==14)
		{
			N/=100;
		}
		else if(C==114)
		{
			N/=1000;
		}
		else
		{
			Error=1;
			break;
		}
	}
	puts(Error?"NO":"YES");
	return 0;
}


#include<stdio.h>

long long n,rev;

void s1(int);
void s2(int);
void s3(int);
void s4(int);

void s1(int rev)
{
     if(!rev)
     {
      printf("YES");
      return;
      }
      else if(rev%10==4)
      s2(rev/10);
      else
      s1(rev/10);
}

void s2(int rev)
{
     if(!rev)
     {
      printf("YES");
      return;
      }
      else if(rev%10==4)
      s3(rev/10);
      else
      s1(rev/10);
}
void s3(int rev)
{
     if(!rev)
     {
      printf("YES");
      return;
      }
      else if(rev%10==4)
      s4(rev/10);
      else
      s1(rev/10);
}

void s4(int rev)
{
     printf("NO");
     return;
}

int main()
{
    scanf("%I64d",&n);
    while(n)
    {
            if(n%10!=1&&n%10!=4)
            {
                       printf("NO");
                       getch();
                       return 0;
            }
            rev=rev+n%10;
            rev*=10;
            n/=10;
    }
    rev/=10;
    if(rev%10==1)
                 s1(rev/10);
    else
        s4(rev/10);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char str[101];
    int l, i, count = 0, count1 = 0;
    scanf("%s", str);
    l = strlen(str);
    for(i = 0; i < l; i++)
    {
        if(str[i] == '-')
            count++;
        else
            count1++;
    }
    if(count1 == 0)
        printf("YES\n");
    else if(count%2 == 0 || count == 0)
        printf("YES\n");

    else
        printf("NO\n");
}


#include <stdio.h>

int main()
{
    char s[100];
    int p=0,l=0,i=0;
    scanf("%s",s);
    while(s[i]!='\0');
    {
        if(s[i]=='o')
            p++;
        else
        l++;
        i++;
    }
    if(l==0||p==0)
    printf("YES");
    else if(l%p==0)
    printf("YES");
    else
    printf("NO");
    return 0;

}


#include <stdio.h>

int main()
{
    char s[100];
    int p=0,l=0,i=0;
    scanf("%s",s);
    while(s[i]!=NULL);
    {
        if(s[i]=='o')
            p++;
        else
        l++;
    }
    if(l==0||p==0)
    printf("YES");
    else if(l%p==0)
    printf("YES");
    else
    printf("NO");
    return 0;

}


#include <stdio.h>

int main()
{
    char s[105];
    int p=0,l=0,i=0;
    scanf("%s",s);
    while(s[i]!='\0');
    {
        if(s[i]=='o')
            p++;
        else
        l++;
    }
    if(l==0||p==0)
    printf("YES");
    else if(l%p==0)
    printf("YES");
    else
    printf("NO");
    return 0;

}


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

int compare(char a[], char b[])
{
    int i, j;

    int ara[26];
    for(i = 0; i < 26; i++){
        ara[i] = 0;
    }

    for(i = 0; a[i] != '\0'; i++) if(ara[a[i]-'a'] == 0) ara[a[i]-'a']++;
    for(i = 0; b[i] != '\0'; i++) if(ara[b[i]-'a'] == 1) ara[b[i]-'a']--;
    for(i = 0; i < 26; i++) if(ara[i]) break;

    if(i == 26) return 1;
    else return 0;

}

int main()
{
    int i, j, n, count;

    scanf("%d", &n);

    char root[n][1001], word[1001];

    root[0][0] = '\0';

    for(i = 0, count = 0; i < n; i++){
        scanf(" %s", word);

        for(j = 0; root[j][0] != '\0'; j++){
            if(compare(word, root[j])){
                break;
            }
        }
        if(root[j][0] == '\0'){
            count++;
            strcpy(root[j], word);
            root[j+1][0] = '\0';
        }
    }

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

    return 0;
}


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

int main()
{
    int n,pos,l,r,i,ans=0,start,end;
    scanf("%d%d%d%d",&n,&pos,&l,&r);
     if(pos<l)
            {for(i=pos;i<=l;i++)
            {
                ans++;
            }
            if(r!=n)
            {
               for(i=l;i<=r;i++)
            {
                ans++;
            }
            printf("%d",ans);
            return 0;
            }
            printf("%d",ans);
            return 0;
            }
    if(pos>r)
    {
            {for(i=pos;i>=r;i--)
            {
                ans++;
            }
            if(l!=1)
            {
               for(i=r;i>=l;i--)
            {
                ans++;
            }
            printf("%d",ans);
            return 0;
            }
            printf("%d",ans);
            return 0;}
    }
    int sum=0;
    for(i=l;i<=pos;i++)
    {
        sum++;
    }
    int sum1=0;
    for(i=pos;i<=r;i++)
    {
        sum1++;
    }
    while(pos<=r&&r!=n&&sum>=sum1)
    {

            pos+=1;
            ans++;
    }
    if(pos==r+1)
    {
        pos-=1;
    }
    while(pos>=l&&l!=1)
    {
            pos-=1;
            ans++;
    }
    if(pos==l-1)
    {
        pos+=1;
    }
    if(sum1>sum)
    {
        while(pos<=r&&r!=n)
    {

            pos+=1;
            ans++;
    }
    }
    printf("%d",ans);
    return 0;
}


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

int main() {

    int i,j,n,k,max,pos,l,r,ans;
    scanf("%d %d %d %d",&n,&pos,&l,&r);
    if(l==1 && r==n){
        printf("0");
    }else{
        if(l==r){
            ans=abs(pos-l);
            if(l==1 ||l==n){
                printf("%d",ans+1);
            }else{
            printf("%d",ans+2);
            }
        }else if(l==1){
            ans=abs(pos-r);
            printf("%d",ans+1);
        }else if(r==n){
            ans=abs(pos-l);
            printf("%d",ans+1);
        }else{
            if(abs(pos-l)>=abs(pos-r)){
                ans=abs(pos-r);
                ans+=abs(r-l);
            }else{
                ans=abs(pos-l);
                ans+=abs(r-l);
            }
            printf("%d",ans+2);
        }
    }
    return 0;
}


#include<stdio.h>
int main()
{
  int n,pos,a,b,l,r,min,max,count=0;
  scanf("%d%d%d%d",&n,&pos,&l,&r);
  a = 1;
  b = n;
  if ((l!=a)||(b!=r))
{
   if((r-pos)<(pos-l))
    {
      if(b!=r)
      {
       while(pos!=r)
        {
          min = b*(b<(pos+1)) + (pos+1)*((pos+1)<b);
          pos = min;
          count++;
        }
       }
       b = r;
       count++;
       if(a!=l)
       {
       while(pos!=l)
        {
          max = a*(a>(pos-1)) + (pos-1)*((pos-1)>a);
          pos = max;
          count++;
        }
       a = l;
       count++;
       }
      }
      if(((pos-l)<(r-pos))||((pos-l)==(r-pos)))
    {
       if(a!=l)
       {
       while(pos!=l)
        {
          max = a*(a>(pos-1)) + (pos-1)*((pos-1)>a);
          pos = max;
          count++;
        }
       a = l;
       count++;
       }
      if(b!=r)
      {
       while(pos!=r)
        {
          min = b*(b<(pos+1)) + (pos+1)*((pos+1)<b);
          pos = min;
          count++;
        }
       }
       b = r;
       count++;
      }
 }
       printf("%d",count);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main(){
	int n,pos,l,r,res;
	while(scanf("%d%d%d%d",&n, &pos, &l, &r)){
		if(l==1 && r==n){
			res=0;
		}
		else if(l==1){
			res=abs(pos-r)+1;
		}
		else if(r==n){
			res=abs(pos-l)+1;
		}
		else{
			if(l<=pos && pos<=r){
				res=pos-2*l+r+2;
				//printf("1\n");
			}
			else if(l>pos){
				res=r-pos+2;
				//printf("1\n");
			}
			else if(r<pos){
				res=pos-l+2;
				//printf("1\n");
			}
		}
		printf("%d\n",res);
	}
	return 0;
}


#include<stdio.h>
int main()
{
int r,g,b,countr,countb,countg,remainr,remainb,remaing,count=0;
scanf("%d%d%d",&r,&g,&b);
countr=r/3;
remainr=r%3;
countg=g/3;
remaing=g%3;
countb=b/3;
remainb=b%3;
while(remainr!=0||remainb!=0||remaing!=0)
{
remainr=remainr-1;
remaing=remaing-1;
remainb=remainb-1;
count++;
}
printf("%d",countr+countb+countg+count);
return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int func(const void*a, const void*b)
{
	return (*(int*)a-*(int*)b);
}
int main()
{
	long long int r, g, b,count=0;
	scanf("%lld %lld %lld", &r, &g, &b);
	long long arr[3];
	while(r%3 + g%3 + b%3>=3)
	{
		r--;g--;b--;
		count++;
	}
	count+=r/3 + g/3 + b/3;
	r=r%3;g=g%3;b=b%3;
	arr[0]=r;arr[1]=g;arr[2]=b;
	qsort(arr,3,sizeof(long long),func);
	long long smallest=arr[0];
	count+=smallest;
	printf("%lld\n",count);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int min(int a,int b,int c)
{
    int min_=a;
    if(min_>b)
    {
        min_=b;
    }
    if(min_>c)
    {
        min_=c ;
    }
    return min_ ;
}
int non_div(int a, int b, int c)
{
    int k=0 ;
    if(a%3!=0)
    {
        k++;
    }
    if(b%3!=0)
    {
        k++;
    }
    if(c%3!=0)
    {
        k++;
    }
    return k ;
}
int main()
{
    int r,b,g,a,c,d,e,k,m,i=0;
    scanf("%d",&r);
    scanf("%d",&b);
    scanf("%d",&g);
    k=non_div(r,b,g);

    if(r==0 )
    {
        printf("%d",b/3+g/3);
        return 0;
    }
    if(g==0)
    {
        printf("%d",r/3+b/3);
        return 0;
    }
    if(b==0)
    {
        printf("%d",r/3+g/3);
        return 0;
    }
    if(k>=2)
    {
        while(k>=2)
        {
            r--;
            b--;
            g--;
            i++;
            k=non_div(r,b,g); }

         printf("%d",r/3+b/3+g/3+i);
         return 0;
            }
    else
    {
        a=min(r,b,g);
        c=r-a;
        d=b-a;
        e=g-a;
        printf("%d",c/3+d/3+e/3+a);

        return 0 ;
    }

}


#include<stdio.h>
int maxx(int i,int j,int k)
{
    i=i>j?j:i;
    return i>k?k:i;
}
int main()
{
    __int64 ans,a,b,c,aa,bb,cc,cout;
    while(~scanf("%I64d %I64d %I64d",&a,&b,&c))
    {
        ans=a/3+b/3+c/3;
        aa=a%3,bb=b%3,cc=c%3;
        cout=0;
        if(aa*bb*cc==0)
            if((aa*bb==4)||(bb*cc==4||aa*cc==4))
            ans+=1;
        ans+=maxx(aa,bb,cc);
        printf("%I64d\n",ans);
    }
    return 0;
}


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

    int w;

    printf ("Enter the weight of watermelon: ");
    scanf ("%d",&w);

    if(w>=1&&w<=100)
    {
        if(w==2)
        {
            printf ("NO");
        }
        else if(w%2==0)
        {

            printf ("YES");
        }
        else
            printf ("NO");
    }
    else
        printf ("the weight of the watermelon isn't right .");

    return main();
}


#include<stdio.h>
int main()
{
    unsigned int n;
scanf("%u",&n);
while(n>2)
{
 if(n%2==0)
    printf("YES");
else
printf("NO");
}
return 0;
}


#include<stdio.h>
int main()
{
    int n;
    while(scanf("%d",&n))
    {
        if(n>2 && n%2==0)
        printf("YES\n");
        else
        printf("NO\n");
    }
}


#include<stdio.h>
void main(){
    long w,count=0;
    scanf("%d",&w);
        for(int i=w;i>1;i/2)
        count++;
        if(count%2==0)
        printf("YES");
}


#include<stdio.h>
int main()
{
    int n;
    while(1);
    {scanf("%d",&n);
        if( n%2==0)
        printf("YES\n");
        else
        printf("NO\n");
        }
    }


#include<stdio.h>
#include<string.h>
main()
{
    int i=0,count,j,k;
    char name[55];
    scanf("%s",&name);
    while(name[i]!='\0')
        {
            if(name[i]=='a')
            count++;
        }
        j=strlen(name);
        if(count>j/2)
        printf("%d",j);
        else
        k=j/2-count;
        printf("%d",k);

}


#include<stdio.h>
#include<string.h>
int main()
{
	char s[50];
	int i,p=0,q;
	gets(s);
	q=strlen(s);
	for(i=0;q;i++)
	{
		if(s[i]==97)
		p=p+1;
	}
	for(i=0;i<q;i++)
	{
	if(p<=(q/2))
	q=q-1;
	else
	break;

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


#include <stdio.h>
#include <stdlib.h>
//#include <string.h> // ��� strstr
#include <locale.h>   // setlocale
#include <windows.h>  // SetConsoleCP,SetConsoleOutputCP

/* Primer 1 */
void main(void)
{
    SetConsoleCP(866);
    SetConsoleOutputCP(866);

    setlocale( LC_ALL, "Russian" );

    int N;            // �����������
    int L;            // �� ��� �������������
    int K;            // ����� �������� ������� ������������� � ������ ������ �����������

    printf("�����������: ");
    scanf("%d",&N);
    printf("\n");

    K=0;
    L=1;
    int LMax,Ns;
    LMax=N/2;
    while(L<=LMax)
    {
        Ns=(N-L)/L;   // ����� ����������� � ������������
        if (L+Ns*L==N)
        {
            printf("������������� %d, � ������� ����������� %d\n",L,Ns);
            K++;
        }
        L++;
    }
    printf("\n�������� ������� ������������� � ������ ������ �����������: %d\n",K);

    getchar();
}


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

int main()
{
    char str[51];
    gets(str);
    int i,length,j,k;
    length=strlen(str);
    j=length;
    int s=0;

    for(i=1;i<=length;i++)
    {
        if(str[i]=='a')
        s++;
    }
    for(j=length;;j--)
    {
        if(s>=(length/2)+1)
        break;
    }
    printf("%d",j);
    return 0;
}


#include<stdio.h>
#include<string.h>
void main(void)
{
char s[50];
int i,n,nX,count=0,aP;
scanf("%s",s);
n=strlen(s);
aP=n/2 + 1;
for(i=0;i<n;i++)
 if(s[i]=='a')
  count++;

nX=n-count;

if(aP<=count)
 {
 printf("%d",n);
 }
 else
 {
 n=nX-count+1;
 printf("%d",n);
 }

getch();
}


#include<stdio.h>

void main()
{
	int n, m, a, b;
	scanf("%d %d %d %d", &n, &m, &a, &b);
	if(b/m<a)
		printf("%d\n", (n/m)*b + (n%m)*a);
	else
		printf("%d\n", a*n);
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    int n,m,a,b;
    int i,j;
    scanf("%d",&n);
    scanf("%d",&m);
    scanf("%d",&a);
    scanf("%d",&b);
    int mincost[n];
    int cost=0;
    int z=0;
    if(a<b)
    {
        for(i=0;i<=1000;i++)
        {
            for(j=0;j<=1000;j=j+m)
            {
                if(i+j==n)
                {
                    cost=((a*i)+(b*(j/m)));
                    mincost[z]=cost;
                    z++;
                }
            }
        }
    }
    else if(b<a)
    {
        for(j=0;j<=1000;j=j+m)
        {
            if(j>=n)
            {
                cost=(b*(j/m));
                mincost[z]=cost;
                z++;
            }
        }
    }
    int min=mincost[0];
    for(i=0;i<z;i++)
    {
        if(min>mincost[i])
        {
            min=mincost[i];
        }
    }
    printf("%d",min);
}


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

int main()
{
    int n,m,a,b,s;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if((float)a<=(float)b/(float)m) { printf("%d",n*a); return 1;}
    if(n*a>=b&&n<=m) {printf("%d",b); return 2;}
    else printf("%d",((n/m)*b)+((((n%m)*a)>b)?b:((n%m)*a)));
    //printf("%d",((float)a<=(float)b/m)?n*a:((n>m)?(n/m)*b:1)+((((n%m)*a)>b)?1:(n%m)*a));
    return 3;
}


#include<stdio.h>

void main()
{
	long int n, m, a, b, ans;
	scanf("%ld %ld %ld %ld", &n, &m, &a, &b);
	if(b/m<a)
		ans=(n/m)*b + (n%m)*a;
	else
		ans=a*n;
	printf("%ld\n", ans);
}


#include<stdio.h>
void main() {
    int n,m,a,b;
    scanf("%d %d %d %d",&n,&m,&a,&b);
    float cp;
    cp = (float)b/m;
    if ( cp < (float)a ) {
        printf("%d",(n/m)*b+(n-(n/m))*a);
    }
    else if( cp >= (float)a ) {
        printf("%d",n*a);
    }
}


#include<stdio.h>
#include<math.h>
#define x 3.141592
main()
{
 float n,R,r,a;
 scanf("%f%f%f",&n,&R,&r);
if(R!=r)
{
 a=asin(r/(R-r));
 if((n*a)<=x)
 {
   printf("YES");
 }
 else
 {
   printf("NO");
 }
}
else
{
    if(n==1)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
}
return(0);
}


#include<stdio.h>
#include<math.h>
#define x 3.141592
main()
{
 float n,R,r;double a;
 scanf("%f%f%f",&n,&R,&r);
if(R<r)
{
    printf("NO");
}
if((R-2*r)>0)
{
 a=atan(r/sqrt(R*(R-2*r)));
 if((n*a)<=x)
 {
   printf("YES");
 }
 else
 {
   printf("NO");
 }
}
if(R>=r && (R-2*r)<0)
{
    if(n==1)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
}
if(R==2*r)
{
    if(n==2)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
}
return(0);
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
const double PI = 3.1415926535897932384626433832795;
int main (){
	int n,R,r;
	scanf("%d%d%d",&n,&R,&r);
	if ( r> R ) {
		printf( "NO\n");
		return 0;}
	if ( ( 2*r >R) && ( n> 1) ) {
			printf( "NO\n");
		return 0 ;
	}
	double alpha;
	alpha=2*asin( (double) r/(2.0* (double) (R-r) ) );
	if  ( ( 2*PI/n) <alpha) printf("NO\n");else printf("YES\n");
	return 0;
}


#include <stdio.h>
#include <conio.h>
int main(){
int R,r,n,l,L;
scanf("%d%d%d",&n,&R,&r);
    l=(r*2*n)-((R-r)*2);
    L=2*R;
    if((L-l)>=0)
    	printf("Yes");
    	else
    	printf("No");

system ("pause");
	return 0;

}


//Bismillahir Rahmanir Rahim
#include<stdio.h>
#include<string.h>
int main()
{
	char flight[1000000];
	int i,t,x,y,j;
	while(scanf("%d",&t)){
		scanf("%s",&flight);
		x=0;
		y=0;
		for(j=0;j<t-1;j++){
			if(flight[j]=='S' && flight[j+1]=='F'){
					x++;
			}
			else if(flight[j]=='F' && flight[j+1]=='S'){
							y++;
				}
			}
		if(x>y){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}


#include<stdio.h>

int main()
{
    int c=0;
    int num, FS,SF,iter;
    char city[101];
    scanf("%d",&num);
    scanf("%s",city);
    for(iter=0;iter+1<strlen(city);iter);
     {
         if(city[iter]=='F'&&city[iter+1]=='S')
          FS++;
         else if(city[iter]=='S'&&city[iter+1]=='F')
          SF++;
     }
     if(SF>FS)
      printf("YES");
     else
      printf("NO");

}


#include "stdio.h"
int main(int argc, char const *argv[])
{
	int i=0,day,s=0,f=0;
	char list[50];
	scanf("%d",&day);
	scanf("%s",list);
	while(list[i+1]!='\0'){
		if (list[i]=='S' && list[i+1]=='F')
		{
			s+=1;
			/* code */
		}else if (list[i]=='F' && list[i+1]=='S')
		{
			f+=1;
			/* code */
		}else{
			continue;
		}
	}
	if (s>f)
	{
		printf("YES\n");
		/* code */
	}else{
		printf("NO\n");
	}
	return 0;
}


#include<stdio.h>
char aa[100000];
int main()
{
    int a,i;

   while(1)
   {
    scanf("%d",&a);
    for(i=1;i<=a;i++)
    {
        scanf(" %c",&aa[i]);
    }
    if(aa[1]=='S'&&aa[a]=='F') printf("YES\n");
    else printf("NO\n");

   }
}


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

int main()
{
    int n;
    char s[101];
    int sf, fs ;
    while (scanf("%d", &n))
    {
        scanf("%s", s);
        sf = 0;
        fs = 0;
        for (int i = 1; i < strlen(s); i++)
        {
            if (s[i-1] == 'S' && s[i] == 'F'){
                sf++;
            } else if (s[i-1] == 'F' && s[i] == 'S'){
                fs++;
            }
        }
        if (sf > fs){
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}


#include <stdio.h>
int main() {
	int i,j,n,m,q=0;
	long long int k,c=2,s,r;
	scanf("%d %d %lld",&n,&m,&k);
	long long int b[n][m];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			b[i][j]=c;
			c+=2;
			if((b[i][j]-1)==k||(b[i][j]==k))
			{
				s=i;
				r=j;
				q++;
				break;
			}
		}
		if(q>0)
			break;
	}
	if(k%2==0)
		printf("%lld %lld R",s,r);
	else
		printf("%lld %lld L",s,r);
	return 0;
}


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

/*
 *
 */
int main() {

    int n, m, k, i, l=0;
    float sum=0.0;

    //printf("Give the colum, the row.\n");
    scanf("%d %d", &n, &m);

    do{
        //printf("Give the position to sit.\n");
        scanf("%d", &k);
    }while(k<0 || k>(2*n*m+1));

    for(i=1; i<=m; i++){
        if(k<i*n*2-2*i){
            l++;
            //printf("l=%d\n",l);
        }
        if(i==m && k>i*n*2-2*i){
            l=m;
        }
    }
    for(i=1; i<=n; i++){
        if(k<=2*m*i){
            if(k%2==0){
                printf("%d %d R\n", i, l);
                return;
            }else{
                printf("%d %d L\n", i, l);
                return;
            }
        }
    }
}


// Bear and the three balls
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

	// solución por fuerza bruta: comparar cada bola con otras dos, si antres de terminar el ciclo hay dos que difieren en menos de 2 en valor absoluto, se puede
	// Si se acaba el ciclo sin encontrar nada, se imprime NO

	int particion (int a[],int ini, int fin);
	void quicksort (int a[],int ini, int fin);
	void swap (int a[],int x,int y);

int main(void){
	int n;
	int *vec;
	int i, cont = 0;

	scanf ( "%d", &n );

	vec = (int*)malloc(n*sizeof(int));

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

	quicksort( vec, 0, n - 1 );

	/*for ( i = 0; i < n; i++ ){
		printf ( "%d - ", vec[i] );
	}*/

	for ( i = 1; i < n; i++ ){
		if ( vec[i - 1] == (vec[i] - 1) )
			cont++;
		else if ( vec[i - 1] != vec[i] )
			cont = 0;
		if ( cont == 2 ){
			printf ( "YES" );
			exit(1);
		}
	}
	printf ( "NO" );

	return 0;
}

void quicksort (int a[],int ini, int fin)		//cada vez que se llama a quicksort un nuevo pivot va colocandose en su posicion
{
	int piv;
	if (ini<fin)
	{	//cont++;
		piv=particion(a,ini,fin);
		quicksort(a,ini,piv-1);				//como el pivot ya esta en su ubicacion se divide en dos y se vuelve a llamar
		quicksort(a,piv+1,fin);				//a quicksort pero sin tocar el pivot
	}
}

int particion (int a[],int ini, int fin)		//particion ubica al pivot en su posicion y devulve esa posicion
{
	int pivot,i,j;
	pivot=a[fin];
	i=ini;
	for (j=ini;j<fin;j++)
	{
		if (a[j]<pivot)
		{
			swap(a,j,i);
			i++;
		}
	}
	swap(a,i,fin);
	return i;
}

void swap (int a[],int x,int y)
{
	int aux;
	aux=a[x];
	a[x]=a[y];
	a[y]=aux;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    int n,i,j,k,s=0,yes=0;
    scanf("%d",&n);
    int A[n];
    for (i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
    }
    for (i=0;i<n-2;i++)
    {
        for (j=i+1;j<n-1;j++)
        {
            if (fabs(A[i]-A[j])>0&&fabs(A[i]-A[j])<=2&&A[i]!=A[j])
            {
                for (k=j+1;k<n;k++)
                {
                   if (fabs(A[i]-A[k])>0&&fabs(A[i]-A[k])<=2&&A[i]!=A[k]&&A[k]!=A[j])
                   {
                       yes=1;
                       break;
                   }
                }
            }
        }
    }
    if (yes==1)
    {
        printf("YES");
    }
    else
        printf("NO");
    return 0;
}


#include<stdio.h>
int main() {
    int n;
    while(scanf("%d",&n))
    {
        int a[n];
    int i;
    for(i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    int j;
    int swap;
    for (i = 0 ; i < ( n - 1 ); i++)
        {
        for (j = 0 ; j < n - i - 1; j++)
        {
            if (a[j] > a[j+1]) {
                  swap=a[j];
                a[j] = a[j+1];
                a[j+1]= swap;
            }
        }
    }
    int y=0;
    int x=1;
    int temp=a[0];
   for(i=1;i<n;i++)
   {
   if(a[i]==temp+1)
   {
       x++;
       temp=a[i];
   }
   else
   {
       temp=a[i];
   }
    if(x==3)
    {
        printf("YES\n");
        y=1;
        break;
    }

   }
   if(y==0)
    printf("NO\n");
    }

    return 0;
}


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


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

    printf("%d",n-a<=b+1?n-a:b+1);
}


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


#include <stdio.h>
int main()
{
	long long int n,k=0;
	int d;
	scanf("%lld",&n);
	{
		while(n!=0)
		{

			d=n/10;
			if(d==4||d==7)
			{
				k++;
			}

		}
	}
	if((k==4 || k==7)&&k!=0)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}


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

int main()
{
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    if(b>a)
    {
        if((a+b)<n)
        {
            printf("%d",n-b);
        }
        else if(a+b==n)
        {
            printf("%d",a+1);
        }
        else if((a+b)>n)
        {
            printf("%d",a+1);
        }
    }
    else if(a>b)
    {
        if((a+b)<n)
        {
            printf("%d",n-b);
        }
        else if(a+b==n)
        {
            printf("%d",a+1);
        }
        else if((a+b)>n)
        {
            printf("%d",a+1);
        }
    }
    else if(a==b)
    {
        if((a+b)<n)
        {
            printf("%d",n-b);
        }
        else if(a+b==n)
        {
            printf("%d",a+1);
        }
        else if((a+b)>n)
        {
            printf("%d",a+1);
        }
    }
    getch();
    return 0;
}


#include <stdio.h>

int gcd(int a, int b){
    while(b != 0){
        int temp = b;
        b = a%b;
        a = temp;
    }
    return a;
}

int main(void){
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int x = a*c/gcd(a, c);
    int y = b*d/gcd(b, d);
    int area1, area2, g;
    if((x*b)/a >= (x*d)/c){
        area1 = (x*x*b)/a;
        area2 = (x*x*d)/c;
        g = gcd(area1, area2);
        area1 /= g; area2 /= g;
        printf("%d/%d\n", area1-area2, area1);
    }
    else{
        area1 = (y*y*a)/b;
        area2 = (y*y*c)/d;
        g = gcd(area1, area2);
        area1 /= g; area2 /= g;
        printf("%d/%d\n", area1-area2, area1);
    }
    return 0;
}


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

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

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

int reduce(a, b)
{
	int i = mint(a,b);
	while (i >= 2)
	{
		if (a % i == 0 && b % i == 0)
			return (i);
		i--;
	}
	return (1);
}

int main()
{
	int a;
	int b;
	int c;
	int d;
	int x;
	int y;
	int l;
	int k;
	int z;
	int alpha;
	int beta;
	int big;
	int small;

	scanf("%d %d %d %d", &a, &b, &c, &d);
	x = mint(a, b);
	y = maxt(a, b);
	l = mint(c, d);
	k = maxt(c, d);
	alpha = (x *l);
	beta = (y * k);
	z = reduce(alpha, beta);
	alpha = alpha  / z;
	beta = beta / z;
	printf("%d/", beta -alpha);
	printf("%d", beta );
}


#include<stdio.h>
int main()
{
   int a,b,c,d,cnt;
   scanf("%d %d %d %d",&a,&b,&c,&d);
   if(c>d)
    {
        a*=c;
        b*=c;
    }
    else
    {
        a*=d;
        b*=d;
    }
   if((float)a/c>(float)b/d)
   {
       a*=d;
       c*=b;
       cnt=a-c;
       printf("%d/%d",cnt/hcf(cnt,a),a/hcf(cnt,a));
   }
   else
   {
       b*=c;
       d*=a;
    cnt=b-d;
     printf("%d/%d",cnt/hcf(cnt,b),b/hcf(cnt,b));
   }
   return 0;
}
int hcf(int a,int b)
{
    while(a!=b)
    {
        if(a>b)
            a-=b;
        else
            b-=a;
    }
    return a;
}


#include<stdio.h>
#include<string.h>
int gcd(int a, int b)
 {
 while(a != b) {
 if (a < b) b -= a;
 else a-= b;
 }
 return a;
 }
int main(){
    int p,q;
    __int64 a,b,c,d,e,f,gd;
    scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d);
    e=a*c*d;
    f=b*c*d;
    if(a*d<=b*c){
        p=b*c-a*d;
        q=b*c;
    }
    else{
        p=a*d-b*c;
        q=a*d;
    }
    gd=gcd(p,q);
    p=p/gd;
    q=q/gd;
    printf("%d/%d\n",p,q);
    return 0;
}


#include <stdio.h>
int count(int n,int m)
{
    int r;
    while(m)
    {
        r = n%m;
        n = m;
        m = r;
    }
    return n;
}

int main()
{
    int a,b,c,d,p,q,k;
    while(scanf("%d %d %d %d",&a,&b,&c,&d))
    {
        p = a*d;
        q = b*c;
        if(p>q)
            k=p;p=q;q=k;
        k = count(q,p);
        p = p/k;
        q = q/k;
        printf("%d/%d\n",q-p,q);
    }
    return 0;
}


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

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

    int *L=malloc(n1*sizeof(int));int* R=malloc(n2*sizeof(int));

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    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;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}
int flag=0;
 void find(int size,int *a,int comp)
{
    if(size==1){
        if((a[0]+comp)%360==0||(a[0]-comp)%360==0) flag=1;

    }
    else{
        find(size-1,a,comp+a[size-1]);
        find(size-1,a,comp-a[size-1]);
    }
}
int main()
{
int n;
scanf("%d",&n);
int *a=malloc(n*sizeof(int));
int i;
for(i=0;i<n;i++)
    scanf("%d",&a[i]);

find(n-1,a,a[n-1]);
if(flag==1) printf("YES");
else printf("NO");
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n, s = 0, a[20];
long long ji[40][400] = {0};
void f(int i, int sum)
{
    if (s != 0)
        return ;
    int m, n;
    m = sum + a[i], n = sum - a[i];
    ji[i][sum]++;
    if (m > 360)
        m -= 360;
    if (n < 0)
        n += 360;
    if (i == n)
        if (sum == 0)
            s++;
    if (ji[i + 1][m] == 0)
        f(i + 1, m);
    if (ji[i + 1][n] == 0)
        f(i + 1, n);
}
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    f(0, 0);
    if (s == 0)
        printf("NO");
    else
        printf("YES");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n,s = 0, a[20];
void f(int i, int sum)
{
    int m,n;
    m=sum+a[i],n=sum-a[i];
    if(m>360)
        m-=360;
    if(n<0)
        n+=360;
    if(i==n)
        if(sum==0)
            s++;
    f(i+1,m);
    f(i+1,n);
}
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    f(0, 0);
    if (s == 0)
        printf("NO");
    else
        printf("YES");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n,s = 0, a[20];
void f(int i, int sum)
{
    if(s!=0)
        return ;
    int m,n;
    m=sum+a[i],n=sum-a[i];
    if(m>360)
        m-=360;
    if(n<0)
        n+=360;
    if(i==n)
        if(sum==0)
            s++;
    f(i+1,m);
    f(i+1,n);
}
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    f(0, 0);
    if (s == 0)
        printf("NO");
    else
        printf("YES");
    return 0;
}


#include<stdio.h>
int a[16];
int flag=0;
void check(int sum,int i,int t)
{
	int a1;
	a1=sum+a[i];
	int b;
	b=sum-a[i];
	if(i==t&&(a1==0||b==0))
	{flag=1;
		return ;
	}
	if(i==t)
		return ;
	check(a1,i+1,t);
		check(b,i+1,t);
}
int main(void)
{
	int t,sum=0;
scanf("%d",&t);
for(int i=0;i<t;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	if(sum%360==0)
		printf("YES");
	else{
		check(0,0,t);
		if(flag==1)
			printf("YES");
		else
			printf("NO");
	}
	return 0;
}


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

int main()
{
    long long int x, rem, steps = 0;
    long long int count_5=0, count_4=0, count_3=0, count_2=0, count_big=0;

    scanf("%lld", &x);
    while (x!=0)
    {

    if (x>=5)
    {
        x = x - 5;
        steps = steps + 1;
        count_5 += 1;
    }

    else if (x>=4)
    {
        x = x - 4;
        steps += 1;
        count_4 += 1;
    }

    else if (x>=3)
    {
        x = x - 3;
        steps+=1;
        count_3 += 1;
    }

    else if (x>=2)
    {
        x = x - 2;
        steps+=1;
        count_2 += 1;
    }
    else if (x>=1)
    {
        steps += 1;
        count_big += x;
    }

}
printf("%lld",steps);

    return 0;
}


#include<stdio.h>
int main()
{
    int x,i,s,m=0;
    scanf("%d",&x);
    for(i=0;i<=x;)
    {
        s=x-i;
        if(s>=5)
        i+=5;
        else if(s==4)
        i+=4;
        else if(s==3)
        i+=3;
        else if(s==2)
        i+=2;
        else if(s==1)
        i+=1;
        m++;
    }
    printf("%d",m);
    return 0;
}


#include<stdio.h>
int n;
int min(int a,int b)
{
	if(a>b)
	return b;
	return a;
}
/*int solve(int currstate,int ans)
{
	if(currstate==n)
	return ans;
	else
	return min(solve(currstate+1,ans+1),min(min(solve(currstate+2,ans+1),solve(currstate+3,ans+1))));
}*/
int main()
{
	scanf("%d",&n);
	if(n<=5)
	printf("1\n");
	else
	printf("%d\n",n/5+1);
	return 0;
}


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

int main(){
	int n,*t,i,j,k;
	scanf("%d",&n);
	t=(int*)malloc(n*sizeof(int));
	if(n<3){
		printf("NO");
		return 1;
	}
	for(i=0;i<n;i++)
		scanf("%d",&t[i]);
	for(i=0;i<n;i++)
		for(j=i+1;j<n-1;j++)
			for(k=j+1;k<n;k++)
				if(t[i]<t[j]+t[k] && t[i]+t[j]>t[k] && t[j]<t[i]+t[k] )
					{printf("YES");
					 return 1;
					}

	printf("NO");
}


#include<stdio.h>

void merge(int x[],int first,int mid, int last)
{
    int i=first, j=mid+1, k=first, y[last-first+1];

    while(i<=mid&&j<=last)
    {
        if(x[i]<=x[j]) {y[k++]=x[i++];}
        else {y[k++]=x[j++];}

    }

    while(j<=last) y[k++]=x[j++];
    while(i<=mid) y[k++]=x[i++];

    for(k=first; k<=last; k++)  x[k]=y[k];
}

void sort(int x[],int first,int last)
{
    if(first<last)
    {
        int mid=(first+last)/2;

        sort(x,first,mid);
        sort(x,mid+1,last);
        merge(x,first,mid,last);
    }

    else return;
}

int main()

{
    int n,i,j,min,k;

    scanf("%d",&n);

    int x[n];

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

    sort(x,0,n-1);

    for(i=0;i<n-2;i++)
    {
        if(x[i]+x[i+1]>x[i+2]){printf("YES"); break;}
    }

    if(i==n-2) printf("NO");
}


#include<stdio.h>

void merge(int x[],int first,int mid, int last)
{
    int i=first, j=mid+1, k=first, y[last-first+1];

    while(i<=mid&&j<=last)
    {
        if(x[i]<=x[j]) {y[k]=x[i]; i++;}
        else {y[k]=x[j]; j++;}
        k++;
    }

    if(i>mid) { while(j<=last) {y[k]=x[j]; j++; k++; }}
    else { while(i<=mid) {y[k]=x[i]; i++; k++; }}

    for(k=first; k<=last; k++)  x[k]=y[k];
}

void sort(int x[],int first,int last)
{
    if(first<last)
    {
        int mid=(first+last)/2;

        sort(x,first,mid);
        sort(x,mid+1,last);
        merge(x,first,mid,last);
    }
}

int main()

{
    int n,i,j,min,k;

    scanf("%d",&n);

    int x[n];

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

    sort(x,0,n-1);

    for(i=0;i<n-2;i++)
    {
        if(x[i]+x[i+1]>x[i+2]){printf("YES"); break;}
    }

    if(i==n-2) printf("NO");
}


#include <stdio.h>

void r_pivot(int *a, int *b)
{
    int i, *r=a+(rand()%(b-a+1));
    i=*r;*r=*a;*a=i;
}

int partition(int *a,int *b)
{
    r_pivot(a,b);
    int *pvt=a, j;
    a--;b++;
    while(1)
    {
        while(1)
        {
            a++;
            if(*a>=*pvt)break;
        }
        while(1)
        {
            b--;
            if(*b<=*pvt)break;
        }
        if(a>b) return b;
        else {j=*a;*a=*b;*b=j;}
    }

}

void sort(int *a, int *b)
{
    if(a<b)
    {
        int *p=partition(a,b);
        sort(a,p);
        sort(p+1,b);
    }
}

int main()
{
    int n, i, j=0;
    scanf("%d",&n);
    long int a[n];
    for(i=0;i<n;i++)
        scanf("%ld",&a[i]);
    sort(&a[0],&a[n-1]);
    for(i=0;i<n-2;i++)
        if(a[i]+a[i+1]>a[i+2]){j=1;break;}
    printf(j?"YES\n":"NO\n");
}