#include<stdio.h>

int main()
{
	int t,n,i,j,temp,flag;
	scanf("%d",&t);
	while(t--)
	{
		flag=0;
		scanf("%d",&n);
		for(i=0;i<=25;i++)
		{
			for(j=0;j<=50;j++)
			{
				temp=3*i+7*j;
				if(temp==n)
				{
					flag=1;
					break;
				}
			}
			if(flag)
			{
				printf("YES\n");
				break;
			}
		}
		if(!flag)
			printf("NO\n");
	}
}


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

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

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

int main()
{
	int r,a,b,c,d=-1,i,x=10,q;
	scanf("%d%d",&a,&b);
	scanf("%d",&c);
	q=a,r=a;
	for(i=1;i<=1000000;i++)
	{
		r=r*10;
		q=r/b;
		r=r%b;
		if(q%10==c)
		{
			d=i;
			break;
		}
	}
	printf("%d\n",d );

	return 0;
}


#include<stdio.h>
int main(){
	int a,b,n;
	scanf("%d%d%d",&a,&b,&n);
	int r=a%b;
	int i=0;
	int c;
	int y=0;
	for(i=1;i<=b+1;i++){
		c= (r*10)/b;
		r=(r*10)%b;
		if(c==n){
			y=1;
			printf("%d",i);
			break;
		}
	}
	if(!y)printf("-1");

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

long long solve(long long n)
{
	long long i = 1;
	long long count = 0;
	long long div = 1;
	long long mult = 1;

	//4 = 4*1
	//10 = 9*1 + 1*2
	//11 = 9*1 + 2*2
	//100 = 9*1 + 90*2 + 1*3
	//1000 = 9*1 + 90*2 + 900*3 + 1*4
	//55 = 9*1 + 46*2

	while (n > 0)
	{
		if (n < 9*mult)
		{
			count = count + n * i;
			n = n - n;
		}
		else
		{
			n = n - (9 * mult);
			count = count + (9 * mult * i);
			mult = mult * 10;
			i++;
		}
	}

	return count;
}

int main()
{
	long long n;

	while (scanf("%lld", &n) != EOF)
	{
		printf("%lld\n", solve(n));
	} ;

	return 0;
}
/* 1510925265702 */


#include<stdio.h>
typedef long long ll;
int main()
{
    ll num,n,l=0,m;
    ll sum=0;
    scanf("%lld",&num);
    if(num<=9)
    printf("%lld",num);
    else
    {
    n=num;
    while(n)
    {
    n/=10;
    l++;
    }
    sum+=9;
    for(ll i=1;i<l-1;i++)
    {
    ll aa=1;
    for(ll j=1;j<=i;j++)
    aa*=10;
    sum+=(9*aa)*(i+1);
    }
    ll a=1;
    for(ll j=1;j<l;j++)
    a*=10;
    sum+=(num-a+1)*l;
    printf("%lld",sum);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,x,y;
    while(scanf("%d%d%d",&n,&x,&y)!=EOF)
    {
        int sum=n*y;
        if(sum%100!=0)
            sum=sum/100+1;
        else
            sum=sum/100;
        if(sum-x<0)
			printf("0\n");
		else
			printf("%d\n",sum-x);
    }
    return 0;
}


#include<stdio.h>

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

}


#include<stdio.h>
#include<string.h>
int main()
{
    int x;
    char a[100]={0},b[100]={0};
    scanf("%d %s %s",&x,a,b);
    if(strcmp(b,"week")==0)
        {
            switch(x)
            {
            case 1:
            case 2:
            case 3:
            case 4:
            case 7:
                printf("52");
                break;
            case 5:
            case 6:
                printf("53");
                break;
            }
        }
    else
    {
        switch(x)
        {
        case 30:
            printf("11");
            break;
        case 31:
            printf("7");
            break;
        default:
            printf("12");
            break;
        }
    }
    return 0;
}


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

int main(){

    int a,b,c=0,i,n;
    char str[100],s[100],k[100];

    scanf(" %[^\n]",str);

    sscanf(str,"%d %s %s",&a,k,s);

    if(! strcmp(s,"week")){

            n = 5;
        for(i=1;i<=366;i++){

            if(n == a) c++;
            if(n == 7) n =1;
            else n++;
        }
        printf("%d\n",c);

    }
    else if(! strcmp(s,"month")){

        if(a == 30) printf("11\n");
        else if(a==31) printf("7\n");
        else printf("12\n");
    }

    return 0;
}


#include<stdio.h>
int main()
{
long long int n,i,j,k,l=0,x=1;
scanf("%lld",&n);
for(i=1;i<=n;i++)
{
x=2*x;
l=l+x;
}
printf("%lld",l);
return 0;
}


#include<stdio.h>
long long int ara[60];
int main()
{
    long long int i,n,j,sum=0;
    scanf("%lld",&n);
    for(i=0,j=2;i<n;i++){
        sum+=j;
        j*=2;
    }
    printf("%lld\n",sum);
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define For(i,m,n) for(i=m;i<n;i++)
#define ForX(i,m,n,x) for(i=(m);i<(n);i+=(x))
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
#define MOD 1000000007
#define MAXN 1005

main()
{
    int t, s, i, j, n, x, d;
    scanf("%d%d%d",&n,&x,&d);
    if(x-d>1) printf("<< ");
    t=MAX(1,x-d); s=MIN(n,x+d);
    For(i,t,s+1){
        if(i!=x) printf("%d ",i);
        else printf("(%d) ",i);
    }
    if(x+d<n) printf(">>");
    puts("");
    return 0;
}


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


//
// Created by Maxim on 03/06/19.
//

#include<stdio.h>

#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif

int main(){
    int n,c,p[50],t[50],time=0,s1=0,s2=0;
    scanf("%d %d",&n,&c);
    for(int i=0;i<n;i++){scanf("%d",&p[i]);}
    for(int i=0;i<n;i++){scanf("%d",&t[i]);}
    for(int i=0;i<n;i++){time+=t[i];s1+=max(0,p[i]-c*time);}
    time=0;
    for(int i=n-1;i>-1;i--){time+=t[i];s2+=max(0,p[i]-c*time);}
    if(s1>s2){printf("Limak");}
    else if(s1<s2){printf("Radewoosh");}
    else{printf("Tie");}
}


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

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

const i32 mod = 1000000007;

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

void run (void) {
  const i32 n = read_int();
  i32 *factor = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 i = 1; i <= n; ++i) {
    factor[i] = i;
  }
  for (i32 i = 2; i * i <= n; ++i) {
    if (factor[i] < i) continue;
    for (i32 j = i * i; j <= n; j += i) {
      factor[j] = i;
    }
  }
  i32 *dp = (i32 *) calloc (n + 1, sizeof (i32));
  dp[1] = 0;
  for (i32 i = 2; i <= n; ++i) {
    i32 f[64];
    f[0] = 1;
    i32 len = 1;
    i32 t = i;
    while (t > 1) {
      i32 p = factor[t];
      while (t % p == 0) {
	t /= p;
      }
      for (i32 j = 0; j < len; ++j) {
	f[j + len] = f[j] * p;
      }
      len *= 2;
    }
    if (f[len - 1] != i) {
      dp[i] = dp[f[len - 1]];
      continue;
    }
    i32 prob[64];
    for (i32 j = 0; j < len; ++j) {
      prob[j] = (i64) (n / f[j]) * inv(n) % mod;
    }
    for (i32 j = len - 1; j >= 0; --j) {
      for (i32 k = j - 1; k >= 0; --k) {
	if ((j & k) == k) {
	  prob[k] = (prob[k] - prob[j] + mod) % mod;
	}
      }
    }
    i32 local = 1;
    for (i32 j = 0; j < len - 1; ++j) {
      local = (local + (i64) prob[j] * dp[f[j]]) % mod;
    }
    dp[i] = (i64) local * inv((1 - prob[len - 1] + mod) % mod) % mod;
  }
  i32 ans = 1;
  for (i32 i = 1; i <= n; ++i) {
    ans = (ans + (i64)dp[i] * inv(n)) % mod;
  }
  print_int(ans);
  puts("");
}

int main (void) {
  run ();
  return 0;
}


#include<stdio.h>
int main()
	{
	int n,i;
	long long int s=0;
	scanf("%d",&n);
	for(i=1;i<n;i++)
		s=s+(n-i)*i;//correct switch * wrong switch
	printf("%Ld",s+n);//s+n->for all correct switches
	return 0;
	}


#include <stdio.h>

main(){
	int num_of_lock=0;
	scanf("%d",&num_of_lock);
	printf("%d",calculate(num_of_lock,1));
}

int calculate(int num,int layer){
	if (num==1) return layer;
	return (num-1)*layer+calculate(num-1,layer+1);
}


#include<stdlib.h>
main()
{
    int n,i;
    scanf("%d",&n);
    if(n%4==0) printf("1 A");
    if(n%4==1) printf("0 A");
    if(n%4==2) printf("1 B");
    if(n%4==3) printf("2 A");
}


#include <stdio.h>
int main()
{int n;
	scanf("%d",&n);
	n=n%4;
	switch(n)
	{ case 1:
		printf("0 A\n");
		break;

		case 2 :
		printf("1 B\n");
		break;

		case 3:
		printf("2 A \n");
		break;

		case 0:
		printf("1 A\n");
		break;

	}

}


/* Problem: 344B - Simple Molecules */
/* Solver: Gusztav Szmolik */

#include <stdio.h>

int main ()
    {
    unsigned int a;
    unsigned int b;
    unsigned int c;
    unsigned short sol;
    unsigned int d;
    unsigned int r;
    unsigned int mbc;

    if (scanf("%u %u %u",&a,&b,&c) != 3)
        return -1;
    if (a < 1 || a > 1000000 || b < 1 || b > 1000000 || c < 1 || c > 1000000)
        return -1;
    sol = 1;
    d = (b > c ? b-c : c-b);
    if (a < d)
        sol = 0;
    else
        {
        r = a-d;
        mbc = (b > c ? c : b);
        if (r%2 || 2*mbc < r)
            sol = 0;
        }
    if (sol)
        {
        printf ("%u ",(b == mbc ? r/2 : r/2+d));
        printf ("%u ",mbc-r/2);
        printf ("%u\n",(b == mbc ? r/2+d : r/2));
        }
    else
        printf ("Impossible\n");
    return 0;
    }


#include <stdio.h>
int main ()
{
    double d, L, v1, v2;
    double t;
    scanf("%lf %lf %lf %lf", &d, &L, &v1, &v2);
    t = (L - d) / (v1 + v2);
    printf("%lf", t);
    return 0;
}

/* 1504025940563 */


#include<stdio.h>
int main()
{
	double d,v1,v2,l;
	scanf("%lf%lf%lf%lf",&d,&l,&v1,&v2);
	printf("%.10lf",(l-d)/(v1+v2));
return 0;
}


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

int main() {
	//code
    int n,i,j,c=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            int w=i^j;
            if(w>0&&w<=n&&(i+j)>(w)&&(i+w)>j&&(j+w)>i)
            {
               c++;
            }
        }
    }
    printf("%d\n",(c/6));
	return 0;
}


#include<stdio.h>
int main()
{
    long long int n,m,p=1,i;
    scanf("%lld %lld",&n,&m);
    if(n>59 || n>m)
    {
        printf("%lld",m);
    }
    else
    {
        for(i=1;i<=n;i=i+1)
        {
            p=p*2;
        }
        printf("%lld",m%p);
    }
}


#include<stdio.h>

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

    int answer = (n > 31 ? m : m%(1 << n));
    printf("%d ", answer);
    return 0;
}


#include <stdio.h>

long long cal(long long n) {
	for (long long i = 2; i * i <= n; ++i)
		if (n % i == 0)
			return i;
	return n;
}

int main() {
    long long n;
	scanf("%lld", &n);
	long long cnt = 0;
	if (n % 2 != 0){
		n -= cal(n);
		++cnt;
	}
	printf("%lld\n", cnt + n / 2);
	return 0;
}


#include<stdio.h>
int main()
{
    int j,count =0 ;
    long long n,ans,i;

    scanf("%lld",&n);
    if(n%2==0)
    {
        printf("%lld",n/2);
        return 0;
    }
    for(i=2; 1ll*i*i<=n; i++)
    {
        if(n%i==0)
        {
            count++;
            break;
        }
    }
    //printf("%d\n",count);
    if(count==0)
        i=n;
   // printf("%lld\n",i);
    ans=(n-i)/2;
    printf("%lld",1+ans);
    return 0;
}


#include<stdio.h>

int main(void){
	int w1,h1,w2,h2,ans;
	scanf("%d%d%d%d",&w1,&h1,&w2,&h2);
	ans = 2*(h1+h2+w1)+4;
	printf("%d",ans);
	return 0;
}


#include <stdio.h>
#include <string.h>
void direita(char entrada[]){

char frase[100], letra;
scanf(" %[^\n]s", frase);
//printf("\n%s\n", frase);
int i, j, x = strlen(frase);

	for(i = 0; i < x; i++)
	{
		for(j = 0; j < 30; j++)
		{
			if(frase[i] == entrada[j])
			{
				printf("%c", entrada[j-1]);
				break;
			}
		}
	}

}

void esquerda(char entrada[]){

char frase[100], letra;
scanf(" %[^\n]s", frase);
int i, j, x = strlen(frase);

	for(i = 0; i < x; i++)
	{
		for(j = 0; j < 30; j++)
		{
			if(frase[i] == entrada[j])
			{
				printf("%c", entrada[j+1]);
				break;
			}
		}
	}
}

int main()
{

char teclado[40] = {"qwertyuiopasdfghjkl;zxcvbnm,./"}, comando;

comando = getchar();
//printf("\n%c\n", comando);

if(comando == 'R') direita(teclado);
else esquerda(teclado);
//printf("%s", teclado);

return 0;

}

/* 1512827954809 */


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


#include <stdio.h>

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

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

    int  ara[n],sum=0,cnt=0;

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

    for(i=0;i<n;i++) {
         sum = sum+ara[i];
         if(sum>m){
            cnt++;
            sum=0;
            --i;
         }
    }

    printf("%d",cnt+1);

}


#include<stdio.h>
#include<math.h>
int main (){
    int k,n,s,p;
    double all;
    scanf("%d%d%d%d",&k,&n,&s,&p);
    all=k*ceil((double)n/(double)s);
    printf("%d",(int)ceil(all/(double)p));
}


#include<stdio.h>
#include<string.h>
int main()
{
    int k, n, s, p, paper, pack, rest;
    scanf("%d %d %d %d", &k, &n, &s, &p);

    rest= (n-1)/s+1;

    paper= rest * k;

     pack= (paper-1)/p+1;

     printf("%d", pack);

    return 0;
}


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

int main()
{
    long long n;
    int  i=0 ;
    scanf("%lld",&n);
    while(n-i>0){
        n=n-i;
        i++;
    }
    printf("%lld",n);
    return 0;
}


#include<stdio.h>
long long n,last,s;
int main()
{
    scanf("%lld",&n);
    for(long long i=1;;i++)
    {
        last=s;
        s+=i;
        if(s>=n)break;
    }
    printf("%lld",n-last);
}


// aeitar runtime o.00 ken?

#include <stdio.h>

int main()
{
    int i,k,n,w,m,s=0;
    scanf("%d%d%d",&k,&n,&w);
    for(i=1;i<=w;i++){
        s=s+(i*k);
    }
    if((s-n)<=0){
        printf("%d\n",0);
    }
    else{
        printf("%d\n",s-n);
    }
    return 0;
}


#include<stdio.h>

int main()
{
    int a, b, c, d, t=0;
    scanf("%d %d %d",&a, &b, &c);
    if(!c && a==b)
        t=0;
    else if(!c && a!=b)
        t=1;
    else if((b-a)%c==0 && (b-a)/c>=0)
        t=0;
    else
        t=1;
    printf(t ? "NO\n" : "YES\n");
    return 0;
}


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

}


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

	  }

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


#include<stdio.h>

int main()
{
    int n,a,i,zero=0,max_zero=0,one=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        if(a==1)
        {
            one++;
            if(zero>0)
                zero--;
        }
        else
        {
            zero++;
            if(zero>max_zero)
                max_zero=zero;
        }
    }
    if(max_zero==0)
        max_zero--;
    printf("%d\n",one+max_zero);
    return 0;
}


#include<stdio.h>

int min(int x,int y,int z)
 {
   if(x<=y && x<=z)
      {
	   return x;
      }
   else if (y<=x && y<=z)
      {
	   return y;
      }
   else if(z<=y && z<=x)
      {
	   return z;
      }
   else
      { return y ;
	  }

 }
int main()
{
	int y,b,r;
	scanf("%d%d%d",&y,&b,&r);
	y++;
    r--;
    printf("%d",3*min(y,b,r));

return 0;
}


#include<stdio.h>
int main()
{
	int y,b,r,s,sum;
 	scanf("%d%d%d",&y,&b,&r);
	s=y;
	while(s>0)
	{
		if((s+1)<=b && (s+2)<=r)
		{
			sum=(s*3)+3;
			printf("%d",sum);
			break;
		}
		s--;
	}
	if(s==0)
	printf("0\n");
	return 0;
}


#include<stdio.h>
int main()
{
  int t,a[100000],temp,n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int x=0;x<n;x++){
            int index=x;
        for(int y=x+1;y<n;y++){
            if(a[index]<a[y]){
                index=y;
            }
        }
        if(index!=x){
        temp=a[x];
        a[x]=a[index];
        a[index]=temp;
        }
    }
    int sum=0;
  for(int j=0;j<n;j=j+2){
    sum=sum+(a[j]-a[j+1]);
  }
  printf("%d",sum);

    return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long long int min(long long int a, long long int b)
{
    return a < b ? a : b;
}
int cmpfunc (const void * a, const void * b) {
    return ( *(int*)a - * (int*)b );
}
typedef long long ll;
void test();
int main()
{
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif*/
    int t;
    scanf("%d", &t);
    while (t--)
    {
        test();
    }
    return 0;
}
void test()
{
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    if (n % 2 == 0 && m % 2 == 0)
    {
        if (k % 2 == 0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    else if (n % 2 == 0 && m % 2 != 0)
    {
        if (k > (n * (m / 2)))
        {
            printf("NO\n");
        }
        else if (k % 2 == 0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    else if (n % 2 != 0 && m % 2 == 0)
    {
        int l = n * (m - 2) / 2, j = m / 2;
        if (k == n * (m / 2))
        {
            printf("YES\n");
        }
        else if (k > l && (k - l) % 2 != 0)
        {
            printf("YES\n");
        }
        else if (k >= m / 2 && k % j == 0 && (n - (k / j)) % 2 == 0)
        {
            printf("YES\n");
        }
        else if (k < m / 2)
        {
            printf("NO\n");
        }
        else
        {
            k = k - m / 2;
            if (k % 2 == 0)
            {
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }

        }

    }
}


#include<stdio.h>
#define MX 1000
long long int p,k,k1=1,sm,A[MX];
int main(){
    int i,j,sz;
    long long int ims;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    scanf("%lld%lld",&p,&k);
    for(sz=0;;sz+=2){
        ims=p%(k*k);
        p=p/(k*k);
        if(ims>=k){
            p++;
            A[sz]=ims%k;
            A[sz+1]=k-(ims/k);
        }
        else{
            A[sz]=ims;
        }
        if(p==0){break;}
    }
    printf("%d\n",sz+1);
    for(i=0;i<=sz;i++){
        printf("%lld ",A[i]);
    }
}


#include <stdio.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>

// if we write f(x) = Sum([0,n+1], bi * x^i) and q(x) = Sum([0,n], ai * x^i) and then so multiplication and equate left and right sides:
// b[n+1] = a[n]
// b[i]   = K*a[i] + a[i-1]
// b[0]   = K*a[0] + P
// from here it is easy to see that all ai should be integer (going n+1 -> 0 and knowing that bi are integers)

// TODO: ???
#define MAX_D 5000
static int64_t _a[MAX_D+2] = {}, _b[MAX_D+2] = {};

int main() {
    int64_t P,K; scanf("%" PRId64 " %" PRId64 "\n", &P,&K);

    // offset, to include P as a[-1]
    _a[0] = P; int D = 0;
    for( ; D <= MAX_D ; ++D) {
        // b[i] = K*a[i] + a[i-1] < K
        // say, a[i-1] = x*K+y (y < K), then we can write
        // b[i] = K*(a[i] + x) + y < K, and from there a[i] = -x, and b[i] = y
        // NB we want non-c modulo, but math (where rem is non-negative)
        int64_t x = _a[D] / K, y = _a[D] % K;
        if(y < 0) { y += K, --x; }
        _a[D+1] = -x, _b[D] = y;
        // TODO:
        if(_a[D] == 0) break;
    }

    printf("%d\n", D);
    for(int i = 0 ; i < D ; ++i) printf("%" PRId64 " ", _b[i]);
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <string.h>
int low,high;
int Low(int array[],int len)
{
    int i;
    //len = strlen(array);
    low = array[0];
    for(i = 1; i < len; i++)
    {
        if( array[i] < low)
        {
            low = array[i];
        }
       // printf("for loop in functio");
    }
}
int High(int array[],int len)
{
    int i;
    //len = strlen(array);
    high = array[0];
    for(i = 1; i < len; i++)
    {
        if(array[i] > high)
        {
            high = array[i];
        }
       // printf("for loop in functio");
    }
}

int main()
{
    int n,m,r,share_buyed,invest,sell,profit;
    scanf("%d %d %d", &n, &m, &r);
    int n_array[n],m_array[m];
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &n_array[i]);
    }
    for(int i = 0; i < m; i++)
    {
        scanf("%d", &m_array[i]);
    }
    int len = strlen(n_array);
    Low(n_array,n);
    int len2 = strlen(m_array);
    High(m_array,m);
    //printf("low is %d and high is %d n is %d m is %d len is %d len2 is %d\n",low,high,n,m,len,len2);
    share_buyed = r / low;
    invest = (share_buyed * low);
    sell = share_buyed * high;
    profit = sell -  invest;
    profit = r + profit;
    if(profit < r)
    {
        printf("%d\n",r);
    }
    else
    {
    printf("%d\n",profit);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
main()
{
	int n,m,r,i,max=-90,min=100010,sum=0,p;
	scanf("%d %d %d",&n,&m,&r);
	for(i=0;i<n;++i)
	{
		int a;
		scanf("%d",&a);
		if(a<min)
		   min=a;
	}
	for(i=0;i<m;++i)
	{
		int a;
		scanf("%d",&a);
		if(a>max)
		  max=a;
	}
p=r/min;
sum+=(r%min);
sum+=(p*max);
if(sum>r)
{
	printf("%d",sum);
}
else
{
	printf("%d",r);
}
}


#include <stdio.h>

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

	scanf("%d%d", &n, &k);
	for (m = 1; (long long) m * (m + 3) / 2 < n + k; m++)
		;
	printf("%d\n", n - m);
	return 0;
}


    #include <stdio.h>

    int main ()
    {
    	long long n,k,i,sum,d;
    	scanf("%I64d %I64d",&n,&k);
    	for (i=1; ; i++)
    	{
    		sum=(i*(i+1))/2;
    		d=sum-(n-i);
    		if (d==k) break;
    	}
    	printf("%I64d\n",n-i);

    	return 0;
    }


#include<stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		if((i * (i+1) / 2) == n)
		{
			printf("YES");
			return 0;
		}

	}
	printf("NO");
	return 0;

}


#include <stdio.h>

 double
sqrt2 (int m)
{

double sqrts = (10 + m / 10) / 2;

for (int i = 0; i < 25; i++)
    {

sqrts = (sqrts + m / sqrts) / 2;

}
return sqrts;

}

  int
main ()
{

int t;

scanf ("%d", &t);

int det = 1 - 4 * 1 * (-2 * t);

double x1 = (-1 + sqrt2 (det)) / 2;

double x2 = (-1 - sqrt2 (det)) / 2;

if ((x1 == (int) x1 || x2 == (int) x2) && (x1 > 0 || x2 > 0))
    {

printf ("YES");

}

  else
    printf ("NO");

}


#include<stdio.h>
#include<string.h>
int main()
{
	char numbers[101];
	scanf("%s",numbers);
	int count0 = 0;
	int count1 = 0;
	int occured =0;
	int i;
	for (i=0; i<strlen(numbers); i++)
	{
		if(numbers[i]== '0')
		{
		count1 = 0;
		count0++;
		}
		else if(numbers[i]=='1')
		{
		count0 = 0;
		count1++;
		}
		if (count0 >= 7 || count1 >= 7)
		occured =1;
	}
		if(occured ==1)
		printf("YES");
		else
		printf("NO");
		return 0;

}//main


#include<stdio.h>
int Find(int n)
{
	int i,j=0,list[1000],ans,temp,tem;
	temp=0;
	ans=1;
	tem=n;
	for(i=2;i*i<=n;i++)
		if(tem%i==0)
		{
			list[j++]=i;
			while(tem%i==0)
				tem/=i;
			}
	if(tem!=1)
	{
		list[j]=tem;
		j++;
		}
	tem=n;
	for(i=0;i<j;i++)
	{
		while(tem%list[i]==0)
		{
			temp++;
			tem/=list[i];
			}
		ans*=temp+1;
		temp=0;
		}
	return ans;
	}
int main(void)
{
	int a,b,c,i,j,k;
	__int64 ans=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=1;i<=a;i++)
		for(j=1;j<=b;j++)
			for(k=1;k<=c;k++)
				ans+=Find(i*j*k)%1073741824;
	printf("%I64d\n",ans);
	return 0;
	}


#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	long long int n,i,j,temp,ans,l,c=1;
	scanf("%lld",&n);

	if(n/10==0) ans =1;
	else
	{
		temp=n;

		for(l=0;;l++)
		{
			temp=temp/10;
			if(temp==0) break;
		}

		for(j=0;j<l;j++)
		{
			c=c*10;
		}

		ans=(((n/c)+1)*c)-n;
	}

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


#include<stdio.h>
#include<math.h>
int main()
{
    int y,r,temp,j,k,d,m=1,mm;
    double i,n;
    scanf("%d",&y);
    r=1;
    temp=y;
    if(y/10==0){
            n=y+1;
            d=n-y;
            printf("%d",d);
            return 0;
    }

    else{
        for(i=0;r!=0;i++){
            r=temp/10;
            if(r==0){
                    j=temp%10;
                    for(mm=0;mm<i;mm++)
                        m=m*10;
                n=(j+1)*m;
                d=(n-y);
                printf("%d",d);
                return 0;
            }
            temp=r;
        }
    }
    return 0;
}


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

int main()
{
	char banner[100] = "";

	scanf("%s", banner);

	char codeforces[] = "CODEFORCES";
	int len = strlen(codeforces); // Although we know it's 10

	int i;
	int index = 0;
	int achieved = 0;
	int status = 0;

	for (i = 0; i < strlen(banner); i++)
	{
		if (index == len && achieved != 0) // CODEFORCES already completed but still iterating; reset index with achieved data
			index = achieved; // index resetted, but must continue checking current letter

		if (banner[i] == codeforces[index])
		{
			if (status == 1)
			{
				status = 2;
			}
			index++;
		}
		else //if (banner[i] != codeforces[index])
		{
			if (status == 0) // 1st error. save accumulated data
			{
				achieved = index;
				status = 1;
			}
			else if (status == 2) // Another error, reset index by loading achieved data
			{
				index = achieved;
				status = 1;
			}
		}
	}

	if (status == 0 && index == len) // Ideal case, received word is CODEFORCES
		printf("YES\n");
	else if (status == 1 && achieved == len) // Completed CODEFORCES but got a substring after
		printf("YES\n");
	else if (status == 2 && index == len) // Got a substring but ended completing CODEFORCES
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}


#include<stdio.h>
int main()
{
    int s;
    scanf("%d",&s);
    char ch1[20][10]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
    char ch2[8][10]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
    if(s<=19){
        printf("%s",ch1[s]);
    }
    else{
        int temp=0,flag=0;
        flag=s/10;
        temp=s%10;
        if(temp==0){
            printf("%s",ch2[flag-2]);
        }
        else{
            printf("%s-%s",ch2[flag-2],ch1[temp]);
        }
    }
    return 0;
}


#include<stdio.h>

int main(){

int n,a,b,q=0;

scanf("%d", &n);

b=n%10;

a=n/10;

if(a == 2)
    printf("twenty");

else if(a == 3)
    printf("thirty");

else if(a == 4)
    printf("forty");

else if(a == 5)
    printf("fifty");

else if(a == 6)
    printf("sixty");

else if(a == 7)
    printf("seventy");

else if(a == 8)
    printf("eighty");

else if(a == 9)
    printf("ninety");

if(b != 0  )
    if(a!=0)
        if(a!=1)
            printf("-");

if(b == 2 && a!=1)
    printf("two");

else if(b == 1 && a!=1)
    printf("one");

else if(b == 3 && a!=1)
    printf("three");

else if(b == 4 && a!=1)
    printf("four");

else if(b == 5 && a!=1)
    printf("five");

else if(b == 6 && a!=1)
    printf("six");

else if(b == 7 && a!=1)
    printf("seven");

else if(b == 8 && a!=1)
    printf("eight");

else if(b == 9 && a!=1)
    printf("nine");

if(n==0)
    printf("zero");

if(n == 10)
    printf("ten");

else if(n == 11)
    printf("eleven");

else if(n == 12)
    printf("twelve");

else if(n == 13)
    printf("thirteen");

else if(n == 14)
    printf("fourteen");

else if(n == 15)
    printf("fifteen");

else if(n == 16)
    printf("sixteen");

else if(n == 17)
    printf("seventeen");

else if(n == 18)
    printf("eighteen");

else if(n == 19)
    printf("nineteen");

return 0;
}


#include<stdio.h>
int main()
{
    int a,b,c,d,i,sum=0;
    scanf("%d %d",&a,&b);
    if(a>b)
    {
        c=a-b;
    }

    else
    {
        c=b-a;
    }

    if(c%2==0)
    {
        d=c/2;
        for(i=1;i<=d;i++)
        {
            sum=(sum+i);
        }
        sum=2*sum;
        printf("%d\n",sum);
    }
    else
    {
        d=c/2;
        for(i=1;i<=d;i++)
        {
            sum=(sum+i);
        }
        sum=(2*sum)+(d+1);
        printf("%d\n",sum);
    }
}


#include<stdio.h>
int main()
{
   long int a,b,temp,temp1,temp2,sum=0,sum1=0;
   int i;
   scanf("%ld\n%ld",&a,&b);
   if(a>b){
   temp=a-b;
   }
   else if(a<b){
   temp=b-a;
   }

   if(temp==1)
   {
       printf("1");
   }
   else{
     temp1=temp/2;
     if(temp%2==0)
     {
         for(i=1;i<=temp1;i++)
            sum=sum+i;
            sum=sum+sum;
     }

     else{
        temp2=temp1+1;
        for(i=0;i<=temp1;i++)
            sum=sum+i;
         for(i=1;i<=temp2;i++)
            sum1=sum1+i;
     }

     printf("%ld",sum+sum1);
   }
   return 0;
}


#include <stdio.h>
#include <string.h>
int main(void) {
	char buff[105], *curr = buff, *start = buff;
	int ex, flag = 0;
	*curr++ = getchar();
	if (buff[0] == '0')
		flag = 1;
	getchar(); // '.'
	while ((*curr++ = getchar()) != 'e')
		;
	scanf("%d", &ex);
	*--curr = '\0';

	if (flag) {
		ex--;
		memmove(buff, buff + 1, curr - buff);
		--curr;
	}
	if (buff[0] == '0') {
		puts("0");
	} else {
		while (*--curr == '0')
			;
		if (ex < 0) {
			putchar('0');
			putchar('.');
			while (++ex < 0)
				putchar('0');
			while (start <= curr)
				putchar(*start++);
		} else {
			while (ex >= 0 && start <= curr) {
				putchar(*start++);
				ex--;
			}
			while (ex-- >= 0)
				putchar('0');
			if (start <= curr) {
				putchar('.');
				while (start <= curr)
					putchar(*start++);
			}
		}
	}

	return 0;
}


#include<stdio.h>

long long int calc(long long int n,long long int r){
    long long int sub = n - r,i;
    long long int result = 1;
    for(i=0;i<sub;i++){
        result = result * n;
        n--;
    }
    for(i=1;i<sub;i++){
        result = result / (i+1);
    }
    return result;
}
int main(){
    long long int n,k,i,start,arr[6],eq,total = 0;
    arr[0] = 0;
    arr[1] = 0;
    arr[2] = 1;
    arr[3] = 2;
    arr[4] = 9;
    arr[5] = 44;
    scanf("%lld %lld",&n,&k);
    start = n-k;
    for(i=n-k;i<n-1;i++){
        eq = calc(n,start);
        total += eq * arr[k];
        k--;
        start++;
    }
    printf("%lld",total+1);
    return 0;
}


#include <stdio.h>

int main (){
	int p,l,r,min;
	scanf("%d %d %d", &p, &l, &r);
	if (p < l){
		min = p;
	} else {
		min = l;
	}
	if (r*2 > min){
		printf("Second");
	} else {
		printf ("First");
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n,m,r;
	scanf("%d %d %d",&n,&m,
			&r
	     );
	int d=2*r;
	int row=n/d;
	int col=m/d;
	int y=row*col;
	if(y==0)
		printf("Second\n");
	else
		printf("First\n");
	return 0;
}


# include <stdio.h>

int n;
int a[16];
int flag=0;

//�ǹ��̲��Ǻ���
void dfs(int s,int sum){
	if(s==n){
		if(sum%360==0)flag=1;
		return ;

	}
	dfs(s+1,sum+a[s]);
	if(flag) return ;
	dfs(s+1,sum-a[s]);
	return ;
 }
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	dfs(0,0);

	if(flag){
		printf("YES");
	}else{
		printf("NO");
	}

	return 0;
}


#include<stdio.h>
int n;
int num[20];
int s=0;
int q=0;
void d(int x){
	if(x==n){
		if(s%360==0){
			printf("YES");
	       q++;
		}
		return;
	}

		s+=num[x];d(x+1);
		s-=num[x];
		if(q) return;
	    s-=num[x];
		d(x+1);
		s+=num[x];
		return;
	}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%d",&num[i]);
	d(0);
	if(!q)
	printf("NO");
}


#include <stdio.h>
int main() {
    int n,m;
    int i;
    scanf("%d%d",&n,&m);
    int a[n+1];
    for(i=0;i<n;i++)    a[i]=0;
    a[n]=1;
    int b[m];
    for(i=0;i<m;i++)    scanf("%d",&b[i]);
    for(i=0;i<m;i++){
        int t=b[i]-1;
        while(!a[t]){
            a[t]=b[i];
            t++;
        }
    }
    for(i=0;i<n;i++)    printf("%d ",a[i]);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int s[200];
    int n,m,bi,i,j;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(s,-1,sizeof(s));

        while(m--)
        {
            scanf("%d",&bi);
            i=bi;
            while(i<=n)
            {
                if(s[i]==-1)
                s[i]=bi;
                i++;
            }

        }
       j=1;
        while(j<n)
        {
            printf("%d ",s[j]);
            j++;
        }
        printf("%d\n",s[j]);
    }
}


#include <stdio.h>

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


#include <stdio.h>

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

int main() {
	long long n, n_, a, b, c;
	long long cnt1, cnt2, cnt3, cnt4;

	scanf("%lld", &n);
	scanf("%lld", &a);
	scanf("%lld", &b);
	scanf("%lld", &c);
	cnt1 = n / a;
	cnt3 = cnt1 / 2;
	n_ = n - cnt3 * a;
	cnt2 = n >= b ? 1 + (n - b) / (b - c) : 0;
	cnt3 += n_ >= b ? 1 + (n_ - b) / (b - c) : 0;
	n_ = n - cnt2 * (b - c);
	cnt4 = cnt2 + (n_ / a);
	printf("%lld\n", MAX(MAX(MAX(cnt1, cnt2), cnt3), cnt4));
	return 0;
}


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


#include<stdio.h>
long long mod=1e9+7;
long long int power(long long a,long long b)
{  long long ans=1;
while(b>0){
    if(b%2==1)ans=((ans%mod)*(a%mod))%mod;
     a=((a%mod)*(a%mod))%mod;
     b=b/2;}
     return ans;              }
int main()
{long long x,y;
    scanf("%lld %lld",&x,&y);
    long long int yes=power((power(2,y)-1),x);
   printf("%lld\n",yes);

 return 0;

}


#include<stdio.h>
#include<stdlib.h>
typedef long long slong;
slong mod=1e9+7;
slong quick_power(slong a,slong b){
    slong res=1;
    while(b!=0){
        if(b&1){
            res=res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
main(){
    slong n,m;
    scanf("%lld%lld",&n,&m);
    printf("%lld",quick_power((quick_power(2,m)-1),n));
    //system("pause");
}


#include <stdio.h>
int main()
{
	int n, i;
	int days[7];
	scanf("%d", &n);
	for(i=0; i<7; i++)
	{
		scanf("%d", &days[i]);
		n-=days[i];
		if(n<=0)
			break;
	}
	while(n>0)
	{
		if(i<6)
                        i++;
                else
                        i = 0;
		n-=days[i];
	}
	//printf("%d\n", (n==0) ? i : i+1);
	printf("%d\n", i+1);
	return 0;
}


#include <stdio.h>
#include<string.h>
#include<stdlib.h>
long long int max(long long int a,long long int b){
    if(a>b){
        return a;
    }
    return b;
}
long long int cmp(const void *a,const void *b){
    return *(long long int *)b-*(long long int*)a;
}
int main()
{
   long long int i,j,test,k,m,l,r,flag=0,max=0,n,m1,m2,x,sum=0,ans=0,count, a[10000]={0},b[1000]={0};
scanf("%lld",&n);
sum=0;
for(i=0;i<8;i++){
    scanf("%lld",&a[i]);
    sum+=a[i];
}
//printf("%lld\n",sum);
count=1;
i=0;
    while(n-a[i]>0 && i<7){
        count++;
     //  printf("%lld %lld\n",a[i],sum);
        n=n-a[i];
        i++;
        if(count==8){
            count=1;
        }
        if(i==7){
            i=0;
        }
    }

    printf("%lld",count);

    return 0;
}


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

}


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

int main()
{
    long long int a,b;
    scanf("%lld %lld", &a, &b);
    if((a/b)%2 == 0)
        printf("NO");
    else
        printf("YES");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int isfloat(float num);
int solve_equation(double per);

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


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


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

int main()
{
    float hours, minuites, seconds, hour1, hour2, help ;

    //printf("Enter the hours: \n ");
    scanf("%f",&hours);
  //  printf("Enter the minuites:\n ");
    scanf("%f",&minuites);
   // printf("Enter the seconds: \n ");
    scanf("%f",&seconds);
   // printf("Enter the first hour: \n ");
    scanf("%f",&hour1);
   // printf("Enter the second hour: \n ");

    scanf("%f",&hour2);

    hours *= 5;
    hour1 *= 5;
    hour2 *= 5;

    minuites = minuites + (seconds / 60);
    hours = hours + (minuites / 60) + (seconds / 60);

    if(hour1 > hour2 ){
        help = hour1;
        hour1 = hour2;
        hour2 = help;
    }

    if((seconds >= hour1 && seconds <= hour2) ||(minuites >= hour1 && minuites <= hour2) || (hours >= hour1 && hours <= hour2)){
            if((seconds > hour1 && minuites > hour1 && hours > hour1) && (seconds < hour2 && minuites < hour2 && hours < hour2)){
                    printf("YES");
            }
            else{
            printf("NO");
            }
    }
    else{
        printf("YES");
    }
    return 0;
}


 #include<stdio.h>
#include<string.h>
int main(){
	char a[201];
	scanf("%s",a);
	int i,j,k,p;
	p=strlen(a);
	i=0;
	while(i<p){
		if(a[i]=='W' && a[i+1]=='U' && a[i+2]=='B')
		{i+=3;
			printf(" ");
		}
		else
		{printf("%c",a[i]);
			i++;
		}
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    char don[1000];
    scanf("%s",&don);
    int i,count=0,j,k,l,len=0;
    len=strlen(don);
    for(i=0; i<len; i++)
    {
        if(don[i]=='Q')
        {
            for(j=i+1; j<len; j++)
            {
                if(don[j]=='A')
                {
                    for(l=j; l<len; l++)
                    {
                        if(don[l]=='Q')
                        {
                            count++;
                        }
                    }
                }
            }
        }
    }
    printf("%d",count);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{ char s[100];
	long long int l,i,o,j,t=0;
	scanf("%s",s);
	l=strlen(s);
	if(l<2) printf("0"); else {
	for(i=0; i<l; i++) {if(s[i]=='1') t++;
	}
	if(t==1) printf("%lli",(l)/2);
	else {if(l%2==0) printf("%lli",l/2); else printf("%lli",(l+1)/2);
	}
	}}


/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:21/08/2019
*/
//#include<algorithm>
//using namespace std;
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define REP(i,n)        for(long long i=0;i<(n);i++)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);i--)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((int)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)            strlen(a)
#define MOD             1000000007
#define MAX             10000000005
#define MIN             -10000000005
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))

const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);

int main()
{
	char str[105];
	SCS(str);
	ll len=SZ(str);
	FORD(i,len-1,1)
	{
		if(str[i]=='1')
		{
			len++;
			break;
		}
	}
	PF1(len/2);
    return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
    if( *(ll*)a - *(ll*)b < 0 ) return -1;
    if( *(ll*)a - *(ll*)b > 0 ) return 1;
        return 0;
}
long long maxv(long long a,long long b)
{
    if(a>b) return a;
        return b;
}
long long minv(long long a,long long b)
{
    if(a<b) return a;
        return b;
}
long long gcd(long long u,long long v)
{
    if (v == 0) return u;
       return gcd(v, u%v);
}


#include<stdio.h>

int main ()
{
	int n,m,a[105],b[105],min=1,max=1,temp,sum=0,num,num3,num2;
	scanf("%d",&n);
	scanf("%d",&m);

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

		for (int j=1;j<n-i;++j)
		{
			if (a[j]<a[j-1])
			{
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;
			}
		}

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

	max=a[n-1];
	min=a[0];

	//printf("gdhhejje%d %d\n",max,min);

	if ((min+m)<=max)
	{
		printf("%d %d",max,(max+m));
	}
	else
	{
		for (int i=0;i<n;++i)
		{
			if(a[i]<max)
			{
				sum+=(max-a[i]);
			}
		}

		if (sum>=m)
		{
			printf("%d %d",max,(max+m));
		}
		else
		{
			num2=m-sum;
			if(num2%n==0)
			{num3=(num2/n);}
			else{num3=(num2/n)+1;}

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


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

        if(k==n)
        {
            c++;
            printf("YES");
            break;
        }
        k*=2;
    }
    if(c==0)
    printf("NO");
    return(0);
}


#include <stdio.h>
int main()
{
  int n,i,j,state=1;
  scanf("%d",&n);
  int circle[n];
  int flea=1;
  for(i=0;i<n;i++)
  circle[i]=0;
  circle[0]=1;
  for(i=1;i<=n;i++)
    {
      flea=flea+i;
      if(flea%n==0)
	  flea=n;
      else
	flea=(flea%n);
      circle[flea-1]=1;
    }

  for(j=0;j<n;j++)
    {
      if(circle[j]!=1)
	{
	  state=0;
	  break;
	}
    }

  if(state==1)
    puts("YES");
  else if(state==0)
    puts("NO");
  return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char a[100];
    int b[27],i,n=0,c;
    for(i=1;i<27;i++)
    {
        b[i]=0;
    }
    scanf("%s",a);
    for(i=0;i<strlen(a);i++)
    {
        c=(int)a[i]-96;
        if(b[c]==0)
        {
            b[c]=1;
            n++;
        }
    }
    if(n%2==0)
    {
        printf("CHAT WITH HER!\n");
    }
    else
    {
        printf("IGNORE HIM!\n");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	char ch[120];
	int hc[26];
	int chlen, i, j=0;
	while (scanf("%s", ch) != EOF)
	{
		for (i = 0; i < 26; ++i)
			hc[i] = 0;
		chlen = strlen(ch);
		for (i = 0; i < chlen; ++i)
			hc[ch[i] - 97] += 1;
		for (i = 0; i < 26; ++i)
			if (hc[i] >= 1)
				j += 1;
		if (j % 2 == 0)
			printf("CHAT WITH HER!\n");
		if (j % 2 != 0)
			printf("IGNORE HIM!\n");
		j = 0;
	}
	return 0;
}


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

    return 0;

}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    char a[500];
    int b,p=0,q=0,n,c,i;
    scanf("%d",&n);
    scanf("%s",&a);
    for(i=0; i<n;i++){
        if(a[i]=='+')
                q++;
            else{
                q--;
                if(q<0)
                    q=0;
            }
        }
    printf("%d",q);
}


#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 n,k,b;
    scanf("%lld%lld",&n,&k);
    n=(n+1)/2;
    b=k>n?2*(k-n):(2*k)-1;
    printf("%lld",b);
    return 0;
}


#include<stdio.h>

int main(){
	//freopen("in.txt", "r", stdin);
	int result, totaltime, scorea, scoreb, costa, costb;
	scanf("%d%d%d%d%d%d", &result, &totaltime, &scorea, &scoreb, &costa, &costb);
	if(scorea == result || scoreb == result || result == 0 || scorea > result && (scorea - result)%costa == 0 && (scorea - result)/costa < totaltime || scoreb > result && (scoreb - result)%costb == 0 && (scoreb - result)/costb < totaltime){
		printf("YES\n");
		return 0;
	}
	if(scorea + scoreb >= result){
		int i, cura = scorea, curb;
		for(i=0;i<totaltime;++i){
			if(cura <= result){
				curb = result - cura;
				if(curb<=scoreb && (scoreb - curb)%costb == 0 && (scoreb - curb)/costb < totaltime){
					printf("YES\n");
					return 0;
				}
			}
			cura-=costa;
		}
	}
	printf("NO\n");
	return 0;
}


#include <stdio.h>

int main()
{
    int y=0, w=0, max = 0, A = 0, B = 0;
    scanf("%d %d", &y, &w);

	max = (y>=w)?y:w;
	A = (6 - max) + 1;

	switch (A)
	{
		case 6: A= 1; B = 1; break;
		case 4: A= 2; B = 3; break;
		case 3: A= 1; B = 2; break;
		case 2: A= 1; B = 3; break;
		case 0: A= 0; B = 1; break;
		default : B = 6;
	}

    printf("%d/%d", A,B);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,k,a,yak,wak;
    scanf("%d %d",&yak,&wak);
    if(yak>=wak){
        k=(6-yak)+1;
        switch(k){
    case 5:
        printf("5/6");
        break;
    case 4:
        printf("2/3");
        break;
    case 3:
        printf("1/2");
        break;
    case 2:
        printf("1/3");
        break;
    case 1:
        printf("1/6");
        break;
    case 0:
        printf("0/1");
        break;
    default:
        printf("1/1");
        }
    }
    else if(yak<=wak){
        k=(6-wak)+1;
        switch(k){
    case 5:
        printf("5/6");
        break;
    case 4:
        printf("2/3");
        break;
    case 3:
        printf("1/2");
        break;
    case 2:
        printf("1/3");
        break;
    case 1:
        printf("1/6");
        break;
    case 0:
        printf("0/1");
        break;
    default:
        printf("1/1");
        }
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int voter[100];
    int pupil;
    int i,j,k;
    int opo=0;
    int res=0;

        scanf("%d",&pupil);

        for(i=0; i<pupil; i++)
        {
            scanf("%d",&voter[i]);
            opo = opo + voter[i];
        }

        for(i=0; i<pupil; i++)
        {
            for(j=i+1; j<pupil; j++)
            {
                if(voter[i]>=voter[j])
                {
                    int temp;
                    temp = voter[i];
                    voter[i] = voter[j];
                    voter[j] = temp;
                }
            }
        }

        k = voter[pupil-1]-1;

        while(k+=1)
        {
            for(i=0; i<pupil; i++)
            {
                res = res + (k-voter[i]);
            }

            if(res>opo)
            {
                printf("%d",k);
                return 0;
            }
            else
            {
                res = 0;
            }

        }
        return 0;

}


#include <stdio.h>

int main(){
    int i,n,a[100],sum=0,new_sum=0,max,val;

    scanf("%d",&n);

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

    max=a[0];

    for(i=0;i<n;i++){
        if(max<a[i]){
            max=a[i];
        }
    }

    for(i=0;i<n;i++){
        val=max-a[i];
        new_sum=new_sum+val;
    }

   // printf("%d\n",new_sum);

    if(new_sum>sum){
        printf("%d\n",max);
    }

    else{
        cal:
        new_sum=0;
        max=max+1;
        for(i=0;i<n;i++){
            val=max-a[i];
            new_sum=new_sum+val;
        }
        if(new_sum>sum){
            printf("%d\n",max);
        }
        else{
            goto cal;
        }
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int count=0;
		int arr[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				scanf("%d",&arr[i][j]);
			}
		}
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				if(arr[i][j]==1)
				{
					count++;
				}
			}
		}
		//printf("count=%d\n",count);
		if(count>=1 && count<4)
		{
			printf("1\n");
		}
		else if(count==0)
		{
			printf("0\n");
		}
		else
		{
			printf("2\n");
		}
	}
	return 0;
}


#include <stdio.h>
int main()
{
    int t;
    scanf("%d", &t);
    while(t--){
        int a,b,c,d,e;
        scanf("%d%d", &a,&b);
        scanf("%d%d", &c,&d);
        e=a+b+c+d;
        if(e==1){
            printf("1\n");
        }
        else if(e==2){
            printf("1\n");
        }
        else if(e==3){
            printf("1\n");
        }
        else{
            printf("%d\n", e/2);
        }
    }

    return 0;
}


#include<stdio.h>
int main()
{
    int i, j, k, l, d, temp, x, y, n, t, v_1, v_2, ans;
    int ara[1000];
    scanf("%d %d", &v_1, &v_2);
    scanf("%d %d", &t, &d);
    ara[1] = v_1;
    ara[t] = v_2;

    for(i = 2, ans = 0; i <= t - 1; i++){
        ara[i]= ara[i - 1] + d;
        if(((t - i) * d) < (ara[i] - ara[t])){
            ara[i] = ara[i] - (ara[i] - ara[t]) + (t - i) * d;
        }
        ans = ans + ara[i];
    }
    ans =ans + ara[1] + ara[t];

    printf("%d", ans);

    return 0;
}


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

#define SET(a,b) memset(a,b,sizeof(a))
#define scan(n) scanf("%d",&n)
#define print(n) printf("%d\n",n)
#define scanl(n) scanf("%lld",&n)
#define printl(n) printf("%lld\n",n)

//stacks
/*void push(int n,int ar[],int i)
{
        ar[i]=n;
        i++;
}
void pop(int ar[],int i)
{
        if(i>0)
        {
                ar[i-1]=0;
                i--;
        }
}*/

//queues
/*void qpush(int ar[],int val,int head,int tail,int range)
{
        if(head==tail)
        {
                ar[head]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        else
        {
                ar[tail]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        if(tail==head)
        {
                if(head+1==range)
                        head=0;
                else
                        head++;
        }
}

void qpop(int head,int tail,int range)
{
        if(head+1==range)
                head=0;
        else
                head++;
}*/

//pow
/*int fun(int a,int b,int m)
{
        if(b==0)
                return 1;
        int d,x;
        d=fun(a,b/2,m);
        x=(d*d)%m;
        if(b%2==0)
                return x;
        else
                return (x*a%m)%m;
}
*/
//bst
/*typedef struct tree
{
        int val;
        struct tree *l;
        struct tree *r;
}node;
//node *head;
node *insert(int x,node *root)
{
        if(root==NULL)
        {
                root=(node *)malloc(sizeof(node));
                root->val=x;
        }
        else
        {
                if(x<=root->val)
                {
                        if(root->l==NULL)
                        {
                                root->l=(node *)malloc(sizeof(node));
                                root->l->val=x;
                        }
                        else
                                root->l=insert(x,root->l);
                }
                else
                {
                        if(root->r==NULL)
                        {
                                root->r=(node *)malloc(sizeof(node));
                                root->r->val=x;
                        }
                        else
                        {
                                root->r=insert(x,root->r);
                        }
                }
        }
        return root;
}
node *find(int x,node *root)
{
        if(root==NULL)
        {
                return 0;
        }
        else
        {
                if(x==root->val)
                        return root;
                else if(x<root->val)
                {
                        if(root->l==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->l);
                        }
                }
                else
                {
                        if(root->r==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->r);
                        }
                }
        }
}

void inorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        if(root->l==NULL)
        {
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
        else
        {
                inorder(root->l);
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
}
void preorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                printf("%d",root->val);
                preorder(root->l);
                preorder(root->r);
        }
}

void postorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                postorder(root->l);
                postorder(root->r);
                printf("%d",root->val);
        }
}
*/
//adjacency list
/*typedef struct ll
{
        int val;
        struct ll *next;
}nd;

//n *ar[100001];
void insert(int a,int b)
{
        if(ar[a]==NULL)
        {
                ar[a]=(nd *)malloc(sizeof(nd));
                ar[a]->val=b;
                ar[a]->next=NULL;
        }
        else
        {
                nd *temp=(nd *)malloc(sizeof(nd)),*t;
                temp->val=b;
                temp->next=ar[a];
                ar[a]=temp;
        }
}

//dfs
//int state[100001];
void dfs(int a)
{
        state[a]=1;
        count++;
        nd *temp=ar[a];
        while(temp!=NULL)
        {
                if(state[temp->val]!=1)
                        dfs(temp->val);
                temp=temp->next;
        }
        return;
}*/

//dijkstra + heaps
/*typedef struct ll2
{
        int val;
        int weight;
        struct ll2 *next;
}nde;
*/
//nde *ar[500005];
//int state[500005];

/*void insert(int a,int b,int w)//insert to adjacency list
  {
  if(ar[a]==NULL)
  {
  ar[a]=(node *)malloc(sizeof(node));
  ar[a]->val=b;
  ar[a]->weight=w;
  ar[a]->next=NULL;
  }
  else
  {
  node *temp=(node *)malloc(sizeof(node)),*t;
  temp->val=b;
  temp->weight=w;
  temp->next=ar[a];
  ar[a]=temp;
  }
  }*/

//int pt[500005],d[500005];
//int heap[500005][2];
//int ptr;
/*void decpty(int val,int pos)//decrease priority
{
        heap[pos][0]=val;
        int x=pos;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

void hinsert(int val,int val2)//insert to heap
{
        heap[ptr][0]=val;
        heap[ptr][1]=val2;
        pt[val2]=ptr;
        int x=ptr;
        ptr++;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

int hdeletemin()//delete min elem from heap
{
        int ret;
        ret=heap[1][1];
        pt[heap[1][1]]=-1;
        pt[heap[ptr-1][1]]=1;
        heap[1][0]=heap[ptr-1][0];
        heap[1][1]=heap[ptr-1][1];
        ptr--;
        int x=1;
        while(x<ptr)
        {
                if(2*x+1>=ptr)
                {
                        if(2*x<ptr)
                        {
                                if(heap[2*x][0]<heap[x][0])
                                {
                                        pt[heap[x][1]]=2*x;
                                        pt[heap[2*x][1]]=x;
                                        int temp=heap[x][0];
                                        int temp2=heap[x][1];
                                        heap[x][0]=heap[2*x][0];
                                        heap[x][1]=heap[2*x][1];
                                        heap[2*x][0]=temp;
                                        heap[2*x][1]=temp2;
                                        x=2*x;
                                }
                                else
                                        break;
                        }
                        else
                                break;
                }
                else if(heap[x][0]<=heap[2*x][0] && heap[x][0]<=heap[2*x+1][0])
                        break;
                else
                {
                        if(heap[2*x][0]<=heap[2*x+1][0])
                        {
                                pt[heap[x][1]]=2*x;
                                pt[heap[2*x][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x][0];
                                heap[x][1]=heap[2*x][1];
                                heap[2*x][0]=temp;
                                heap[2*x][1]=temp2;
                                x=2*x;
                        }
                        else
                        {
                                pt[heap[x][1]]=2*x+1;
                                pt[heap[2*x+1][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x+1][0];
                                heap[x][1]=heap[2*x+1][1];
                                heap[2*x+1][0]=temp;
                                heap[2*x+1][1]=temp2;
                                x=2*x+1;
                        }
                }
        }
        return ret;
}

void dikstra(int u,int v)
{
        while(ptr!=1)
        {
                int v=hdeletemin();
                node *temp=ar[v];
                while(temp!=NULL)
                {
                        int w=temp->val;
                        if(d[v]+temp->weight < d[w])
                        {
                                d[w]=d[v]+temp->weight;
                                decpty(d[w],pt[w]);
                        }
                        temp=temp->next;
                }
        }
}*/

/*int main()
  {
  int n,m,u,v,w,i;
  scanf("%d%d",&n,&m);
  for(i=0;i<=n;i++)
  state[i]=0;
  while(m--)
  {
  scanf("%d%d%d",&u,&v,&w);
  insert(u,v,w);
  }
  scanf("%d%d",&u,&v);
  ptr=1;
  hinsert(0,u);
  d[u]=0;
  for(i=1;i<=n;i++)
  {
  if(i!=u)
  {
  hinsert(1000000000,i);
  d[i]=1000000000;
  }
  }
  dikstra(u,v);
  if(d[v]==1000000000)
  printf("NO\n");
  else
  printf("%d\n",d[v]);
  return 0;
  }*/

//kruskal + dsu

//int dsu[N];
/*int find(int x)
{
        if(dsu[x]==x)return x;
        return dsu[x] = find(dsu[x]);
}

void Union(int a,int b)
{
        if(a==b)
                return;
        dsu[a] = b;
}

typedef struct edge
{
        int u,v;
        int weight;
}edge;
*/
//edge e[N];
/*int cmp(const void *a,const void *b)
  {
  return ((edge*)a)->weight - ((edge*)b)->weight;
  }*/
/*int main()
  {
  int i;
  int n,m;
  scanf("%d %d\n",&n,&m);
  for(i=0;i<m;i++)
  scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].weight);
  for(i=1;i<=n;i++)
  dsu[i]=i;
  qsort(e,m,sizeof(edge),cmp);
  long long int sum=0;
  for(i=0;i<m;i++)
  {
  int a,b;
  if((a=find(e[i].u))!=(b=find(e[i].v)))
  {
  sum+=e[i].weight;
  Union(a,b);
  }
  }
  printf("%lld\n",sum);
  return 0;
  }*/

//qsort

/*int cmpfunc(const void *a,const void *b)
{
        return (*(int *)a - *(int *)b);
}*/
//qsort(ar,n,sizeof(int),cmpfunc);

//-------------------------------------------------------------------------------------------------------------------------------------

int main()
{
        int ar[101],d,t,v,range[101],i;
        scan(ar[0]);
        scan(v);
        scan(t);
        scan(d);
        ar[t-1]=v;
        range[t-1]=v;
        for(i=t-2;i>=1;i--)
        {
                range[i]=range[i+1]+d;
        }
        int ans=0;
        for(i=1;i<t-1;i++)
        {
                if(ar[i-1]+d<=range[i])
                        ar[i]=ar[i-1]+d;
                else
                        ar[i]=range[i];
                ans+=ar[i];
        }
        ans+=ar[0];
        ans+=v;
        print(ans);
        return 0;
}


#include <stdio.h>

int main(void)
{
    int n, i, max = 0, position, count = 0;
    int a[100];

    scanf("%d %d", &n, &a[0]);
    for (i = 1; i < n; i ++)
    {
        scanf("%d", &a[i]);
        if (a[i] > max)
        {
            max = a[i];
            position = i;
        }
    }

    while (a[0] <= max)
    {
        a[0]++;
        a[position]--;
        count++;
        max = 0;
        for (i = 1; i < n; i ++)
            if (a[i] > max)
            {
                max = a[i];
                position = i;
            }
    }

    printf("%d", count);

    return 0;
}


#include <stdio.h>

int main(void) {

   double dig = 0;
   double sum = 0;
   int i = 0;
   int sum1 = 0;
   int nine = 0;
   int strg = 0;
   int zero = 0;
   scanf("%lf %lf",&dig,&sum);

   if((sum/9<=dig&&sum!=0)||(sum==0&&dig==1)){
        sum1 = (int)sum;
   //mini
   nine = (sum1-1)/9;
   strg = (sum1-1)%9;
   zero = (dig-1)-nine;
   if(dig-nine==1){printf("%d",strg+1);
   for(i=0;i<zero;i++){
    printf("0");
   }
   }else{printf("1");
   for(i=0;i<zero-1;i++){
    printf("0");

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

   for(i=0;i<nine;i++){
    printf("9");
   }

    //maxi
     printf(" ");
    for(i=0;i<sum1/9;i++){
        printf("9");
    }
    if(sum1/9!=dig){printf("%d",sum1%9);}
   for(i=0;i<dig-(sum1/9)-1;i++){
    printf("0");
   }

   }else{printf("-1 -1");}
    return 0;
}


/* upsolve with kaiboy */
#include <stdio.h>
#include <string.h>

#define N	1000000
#define M	1000000
#define K	20

int aa[N + 1], kk[N + 1];

void init() {
	int a, b, b_, k;

	for (a = 2; a <= N; a++) {
		if (aa[a])
			continue;
		b = 1, b_ = N / a, k = 0;
		while (b <= b_) {
			b *= a, k++;
			aa[b] = a, kk[b] = k;
		}
	}
}

int main() {
	static char used[M * K + 1];
	static int cc[K + 1];
	int n, m, a, b, b_, j, k, cnt;
	long long ans;

	init();
	scanf("%d%d", &n, &m);
	cnt = 0;
	for (k = 1; k <= K; k++) {
		for (j = 1; j <= m; j++)
			if (!used[j * k])
				used[j * k] = 1, cnt++;
		cc[k] = cnt;
	}
	ans = 1;
	for (a = 2; a <= n; a++)
		if (aa[a] == a) {
			b = 1, b_ = n / a, k = 0;
			while (b <= b_)
				b *= a, k++;
			ans += cc[k];
		}
	printf("%lld\n", ans);
	return 0;
}


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

#define N	1000000
#define M	1000000
#define K	20

int aa[N + 1], kk[N + 1];

void init() {
	int a, b, b_, k;

	for (a = 2; a <= N; a++) {
		if (aa[a])
			continue;
		b = 1, b_ = N / a, k = 0;
		while (b <= b_) {
			b *= a, k++;
			aa[b] = a, kk[b] = k;
		}
	}
}

int main() {
	static char used[M * K + 1];
	static int cc[K + 1];
	int n, m, a, b, b_, j, k, cnt;
	long long ans;

	init();
	scanf("%d%d", &n, &m);
	cnt = 0;
	for (k = 1; k <= K; k++) {
		for (j = 1; j <= m; j++)
			if (!used[j * k])
				used[j * k] = 1, cnt++;
		cc[k] = cnt;
	}
	ans = 1;
	for (a = 2; a <= n; a++)
		if (aa[a] == a) {
			b = 1, b_ = n / a, k = 0;
			while (b <= b_)
				b *= a, k++;
			ans += cc[k];
		}
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>

int main()
{
    int sh, sm, th, tm, ph, pm;
    scanf("%d:%d", &sh, &sm);
    scanf("%d:%d", &th, &tm);
    ph=sh-th;
    pm=sm-tm;
    if(pm<0)
    {
        pm+=60;
        ph-=1;
    }
    if(ph<0)
        ph+=24;
    printf("%02d:%02d\n", ph, pm);

    return 0;
}


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

int main(){

int horasF, minutosF, horasI, minutosI, horas, minutos;

scanf("%d:%d", &horasF, &minutosF);
scanf("%d:%d", &horasI, &minutosI);

if(horasF == horasI && minutosI == minutosF){
        horas = 0;
        minutos = 0;

}

if(horasI == horasF){

        horas = 0;

        if(minutosI < minutosF)
                minutos = minutosF - minutosI;
        if(minutosI > minutosF){
                minutos = 60 + ( minutosF - minutosI );
                horas = 23;
        }
        if(minutosI == minutosF)
                minutos = 0;
}

if(horasI > horasF){
        if(minutosI < minutosF){
                minutos = minutosF - minutosI;
                horas = 24 + ( horasF - horasI);
        }
        if(minutosI > minutosF){
                minutos = 60 + ( minutosF - minutosI );
                 horas = 23+( horasF - horasI);
        }
        if(minutosI == minutosF){
                minutos = 0;
                horas = 24 + ( horasF - horasI);
        }

}

if(horasI < horasF){
        horas = horasF - horasI;
        if(minutosI < minutosF)
                minutos = minutosF - minutosI;
        if(minutosI > minutosF){
                minutos = 60 + ( minutosF - minutosI );
                horas = horasF - horasI -1;
        }
        if(minutosI == minutosF)
                minutos = 0;

}

if( horas<10 && minutos <10)
        printf("0%d:0%d\n", horas, minutos);
else if( horas<10 )
        printf("0%d:%d\n", horas, minutos);
else if( minutos<10 )
        printf("%d:0%d\n", horas, minutos);
else
         printf("%d:%d\n", horas, minutos);

return 0;
}


#include<stdio.h>
int main()
{
    int z,y,x,j;
    scanf("%d %d %d",&x,&y,&z);

     if(x>y && x-y>z)
     printf("+\n");
    else if(y>x && y-x>z)
        printf("-\n");
    else if(x==y && z==0)
        printf("0\n");
    else if(x==0 && y==0 && z==0)
         printf("0\n");
    else
    printf("?\n");

}


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

struct candy{
	int qnt;
	int laps;
	int sobra;
};

int main(){
	int i;
	int n, m;
	struct candy vetor[100];
	int maxlaps;
	int result;
	int flag=0;

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

	for(i = 0; i < n; i++){
		scanf("%d", &vetor[i].qnt);
		vetor[i].laps = vetor[i].qnt / m;

//		printf("Laps posicao %d = %d\n", i, vetor[i].laps);

		if(i == 0){
			maxlaps = vetor[i].laps;
		}
		else if(vetor[i].laps > maxlaps){
			maxlaps = vetor[i].laps;
		}
	}

//	printf("maxlaps = %d\n", maxlaps);

	for(i = 0; i < n; i++){
		if(vetor[i].laps == maxlaps){
			if(vetor[i].qnt % m > 0){
				result = i;
				flag = 1;
			}
			else if(vetor[i].qnt % m == 0 && flag == 0){
				result = i;
			}
		}
		else if(vetor[i].laps == maxlaps - 1 && flag == 0){
			if(vetor[i].qnt % m > 0){
				result = i;
			}
		}
	}

	printf("%d", result+1);

	return 0;
}


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


#include<stdio.h>
#define N 26
int main() {
	int n;
	scanf("%d",&n);
	int a[N];
	int i,j;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	//26*10^9应该超过了32bit int的取值范围
	//所以这个最多字母应该是一个long long型
	//sort
	for(i=0;i<n-1;i++){
		int max=i;
		for(j=i+1;j<n;j++){
			if(a[j]>a[max])max=j;
		}
		if(max!=i){
			//swap max i
			int tmp=a[max];
			a[max]=a[i];
			a[i]=tmp;
		}
	}
	/*
	for(i=0;i<n;i++){
		printf(" %d",a[i]);
	}
	printf("\n");
	*/
	long long max_length=a[0];
	int current_max=a[0];
	i=1;
	while(i<n){
		if(current_max<=0)break;
		if(a[i]>=current_max){
			max_length+=(current_max-1);
			current_max=current_max-1;
		}else{
			max_length+=a[i];
			current_max=a[i];
		}
		i++;
	}
	printf("%lld\n",max_length);

	return 0;
}


#include<stdio.h>
void merge(int [],int ,int ,int );
void part(int [],int ,int );
int main()
{
    int n;
    scanf("%d",&n);
    int i,a[n];
    long long sum=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    part(a,0,n-1);
    for(i=n-2;i>-1;i--)
    {
        if(a[i]>=a[i+1])
        {
            a[i]=a[i+1]-1;
        }
        if(a[i]<0)
            a[i]=0;
        sum=sum+a[i];
    }
    printf("%lld",sum+a[n-1]);
    return 0;
}
void part(int arr[],int min,int max)
{
 int mid;
 if(min<max)
 {
   mid=(min+max)/2;
   part(arr,min,mid);
   part(arr,mid+1,max);
   merge(arr,min,mid,max);
 }
}

void merge(int arr[],int min,int mid,int max)
{
  int tmp[100];
  int i,j,k,m;
  j=min;
  m=mid+1;
  for(i=min; j<=mid && m<=max ; i++)
  {
     if(arr[j]<=arr[m])
     {
         tmp[i]=arr[j];
         j++;
     }
     else
     {
         tmp[i]=arr[m];
         m++;
     }
  }
  if(j>mid)
  {
     for(k=m; k<=max; k++)
     {
         tmp[i]=arr[k];
         i++;
     }
  }
  else
  {
     for(k=j; k<=mid; k++)
     {
        tmp[i]=arr[k];
        i++;
     }
  }
  for(k=min; k<=max; k++)
     arr[k]=tmp[k];
}


#include<stdio.h>

int main()
{
    unsigned long long k,a;
    int i,j,t=0,q[10];
    scanf("%llu",&k);
    char p[11]="codeforces";
    for(i=0;i<10;i++)
        q[i]=1;

    while(1)
    {
        a=1;
        for(i=0;i<10;i++)
            a*=q[i];

        if(a>=k)
            break;

        if(t==10)
            t=0;

        q[t]++;
        t++;
    }

    for(i=0;i<10;i++)
        for(j=0;j<q[i];j++)
            printf("%c",p[i]);
}


///I am Groot |*|
#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{
    long long int t,c=1,l=1,n=1,cnt=0;
    scanf("%lld",&t);
    while(c<t)
    {
        n++;
        for(int i=0; i<10; i++)
        {
            cnt++;
            c=(c/l)*n;
            if(c>=t)
                break;
        }
        l++;
    }
    long long int a=cnt/10;
    char s[10]="codeforces";
    for(int i=0; i<cnt%10; i++)
    {
        for(int  j=0; j<a+2; j++)
        {
            printf("%c",s[i]);
        }
    }
    for(int i=cnt%10; i<10; i++)
    {
        for(int  j=0; j<a+1; j++)
        {
            printf("%c",s[i]);
        }
    }
}


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

//int f(int w, int h, int k);

int main() {
  int w, h, k;
  scanf("%i %i %i", &w, &h, &k);
  printf("%i\n", 2*k*(w+h)-4*k-8*(k-1)*k );
  return 0;
}
/*
int f(int w, int h, int k){
  if(!k)
    return 0;
  else
    return (2*w+2*(h-2)) + f(w-4, h-4, k-1);
}*/


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

//int f(int w, int h, int k);

int main() {
  int w, h, k, ris;
  scanf("%i %i %i", &w, &h, &k);
  ris = 2*k*((w+h)-4*(k-1)-2);
  printf("%i\n", ris);
  return 0;
}
/*
int f(int w, int h, int k){
  if(!k)
    return 0;
  else
    return (2*w+2*(h-2)) + f(w-4, h-4, k-1);
}*/


#include<stdio.h>
#include<string.h>
int main()
{
	int r,c,k,flag,tempw,tempb,mova=10,movb=10;
	char s[10][10];
	for(r=1;r<=8;r++)
	{
		scanf("%s",s[r]);
		getchar();
	}
	for(r=1;r<=8;r++)
	{
		for(c=0;c<8;c++)
		{
			tempw=10;
			tempb=10;
			flag=0;
			if(s[r][c]=='W')
			{
				for(k=r-1;k>=1;k--)
				{
					if(s[k][c]=='B'||s[k][c]=='W')
					{
						flag=1;
						break;
					}
				}
				if(flag==0)
				{
					tempw=r-1;
				}
				if(tempw<mova)
				{
					mova=tempw;
				}
	//			printf("W>> %d    %d,%d--%d\n",flag,r,c,tempw);
			}
			if(s[r][c]=='B')
			{
				for(k=r+1;k<=8;k++)
				{
					if(s[k][c]=='B'||s[k][c]=='W')
					{
						flag=1;
						break;
					}
				}
				if(flag==0)
				{
					tempb=8-r;
				}
			//	printf("B>> %d    %d,%d--%d\n",flag,r,c,tempb);
				if(tempb<movb)
				{
					movb=tempb;
				}
			}

		}
	}
//	printf("%d %d\n",mova,movb);

	if(mova<=movb)
	printf("A");
	else
	printf("B");
	return 0;

}


#include <stdio.h>

char p[10][10];
int x, y;

void ispisi() {
    int i,j;
    for(i = 0; i < 9; ++i) {
        for(j = 0; j < 9; ++j) {
            if(j==3 || j == 6) {
                printf(" %c",p[i][j]);
            } else {
                printf("%c",p[i][j]);
            }
        }
        printf("\n");
        if(i == 2 || i == 5) printf("\n");
    }
}

int provjeri(int x, int y) {
    int i, j;

    for(i = x*3; i < x*3+3; ++i) {
        for(j = y*3; j < y*3+3; ++j) {
            if(p[i][j] == '.') return 1;
        }
    }

    return 0;
}

void popuniPolje(int x, int y) {
    int i,j;

    for(i = x*3; i < x*3+3; ++i) {
        for(j = y*3; j < y*3+3; ++j) {
            if(p[i][j] == '.') p[i][j] = '!';
        }
    }
}

void popuniSve() {
    int i,j;

    for(i = 0; i < 9; ++i) {
        for(j = 0; j < 9; ++j) {
            if(p[i][j] == '.') p[i][j] = '!';
        }
    }
}

void popuni(int x, int y){
    if(provjeri(x,y)) {
        popuniPolje(x,y);
    } else {
        popuniSve();
    }
}

int main() {
    int i,j;

    for(i = 0; i < 9; ++i) {
        for(j = 0; j < 9; ++j) {
            scanf(" %c",&p[i][j]);
        }
    }
    scanf("%d %d", &y, &x);
    x--;
    y--;

    popuni(y%3,x%3);
    ispisi();
    return 0;
}


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

int main()
{
    long long int n,m,i,j,k;
    long long int a[100000];
    while(~scanf("%lld%lld",&m,&n))
    {
        i=0;
        while(n>m)
        {
             a[i]=n;
            if(n%10==1)
                n/=10;
            else if(n%2==0)
            n/=2;
            else
            {
                printf("NO\n");
                break;
            }
          i++;
        }
        if(n==m)
        {
            printf("YES\n");
            printf("%lld\n",i+1);
            printf("%lld",m);
            for(j=i-1;j>=0;j--)
                printf(" %lld",a[j]);
            printf("\n");
        }
        else if(n<m)
            printf("NO\n");
    }
    return 0;
}


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

int len[7][2];
int index3;
int MinX(int a,int b)
{
	return a = a>b?b:a;
}

void compare(int a,int b,int c)
{

	int middle =0;
	if(a>b)
	{
        middle = 11 - a;
		len[index3][0] = middle + b +1;

	}
	else
	{
        len[index3][0] =  b - a;
	}
    if(b>c)
	{
        middle = 11 - b;
		len[index3][1] = middle + c +1;

	}
	else
	{
        len[index3][1] =  c - b;
	}
	index3++;
}

int main()
{
	int i,j,k,flag1,flag2;
	char data[13][3]={"C","C#","D","D#","E","F","F#","G","G#","A","B","H"};
	char X[3],Y[3],Z[3];
	int index1,index2,op1,op2,op3;
	while(scanf("%s%s%s",X,Y,Z)!=EOF)
	{
		index3=0;
		for(i=0;i<12;i++)
		{
			if(!strcmp(data[i],X))
			{
				op1 = i;
				break;
			}
		}
		index1 = 0;index2 = 0;
		flag1 = 0; flag2  = 0;
		while(1)
		{
			if(index1 == 12)
				index1 = 0;
			if(index2 == 12)
				index2 = 0;
			if(!strcmp(data[index1],Y))
			{
				op2 = index1;
				flag1 = 1;
			}
			else
				index1++;
			if(!strcmp(data[index2],Z))
			{
				op3 = index2;
				flag2 = 1;
			}
			else
				index2++;
			if(flag1 && flag2)
				break;
		}
		flag1 = 0;flag2 = 0;
		compare(op1,op2,op3);
		compare(op1,op3,op2);
		compare(op2,op1,op3);
		compare(op2,op3,op1);
		compare(op3,op1,op2);
		compare(op3,op2,op1);
		for(i = 0;i<6;i++)
		{
			if(len[i][0] == 4 && len[i][1] == 3)
			{
				printf("major\n");
				flag1 =1;
				break;
			}
		}
		for(i = 0;i<6;i++)
		{
			if(len[i][0] == 3 && len[i][1] == 4)
			{
				printf("minor\n");
				flag2 =1;
				break;
			}
		}
		if(flag1 ==0 && flag2 ==0)
			printf("strange\n");
	}
	return 0;
}


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


#include <stdio.h>

int main(){

	long long n;
	scanf("%lld", &n);
	printf("25\n");
	return 0;
}


#include <stdio.h>

int main() {
    long long n;
    scanf("%lld", &n);
    printf("25\n");
}


#include<stdio.h>
#include<string.h>
int co1[30],co2[30];
int main()
{
	char s[110],t[110];
	int i,j;
	scanf("%s %s",s,t);
	for(i=0;i<strlen(s);i++)
		co1[s[i]-97]++;
	for(i=0;i<strlen(t);i++)
	co2[t[i]-97]++;
	if(strlen(s)>strlen(t))
	{
		i=0;j=0;int flag=0;
		while(i<strlen(t))
		{
			if(s[j]==t[i])
			{
				j++;i++;
			}
			else
			{
				j++;
			}
			if(j==strlen(s) && i!=strlen(t))
			{
				flag=1;break;
			}
		}
		if(flag==0)
		{
			printf("automaton\n");
		}
		else
		{
		for(i=0;i<26;i++)
		{
			if(co1[i]<co2[i])
			{
				flag=100;
				break;
			}
		}
		if(flag==100)
		printf("need tree\n");
		else
		printf("both\n");
		}
	}
	else if(strlen(s)==strlen(t))
	{int blag=0;
		for(i=0;i<26;i++)
		{
			if(co1[i]!=co2[i])
			{
				blag=1;break;
			}
		}
		if(blag==0)
		printf("array\n");
		else
		printf("need tree\n");
	}
	else
	printf("need tree\n");
	return 0;
}


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

int main() {
	int i, j, ls, lt, good;
	static char s[101], t[101];
	static int cnt[26];

	scanf("%s", s);
	scanf("%s", t);
	ls = strlen(s);
	lt = strlen(t);
	j = 0;
	for (i = 0; i < ls; i++) {
		if (s[i] == t[j])
			j++;
		if (j == lt) {
			printf("automaton\n");
			return 0;
		}
	}
	for (i = 0; i < ls; i++)
		cnt[s[i] - 'a']++;
	for (i = 0; i < lt; i++)
		cnt[t[i] - 'a']--;
	good = 1;
	for (i = 0; i < lt; i++)
		if (cnt[t[i] - 'a'] < 0) {
			good = 0;
			break;
		}
	if (!good)
		printf("need tree\n");
	else
		printf("%s\n", ls == lt ? "array" : "both");
	return 0;
}


#include <stdio.h>

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

int
main() {
  int a, ta, b, tb;
  int time_h, time_m;
  scanf("%d %d", &a, &ta);
  scanf("%d %d", &b, &tb);
  scanf("%d:%d", &time_h, &time_m);
  int m = (time_h - 5) * 60 + time_m;
  int bus_b = 0;
  for(int i = 0; i < (24 - 5) * 60; ++i) {
    if (i >= tb && (i - tb) % b == 0) {
      --bus_b;
    }
    if (i == m) {
      for(int j = i; j < min((24 - 5) * 60, m + ta); ++j) {
        if (j % b == 0) {
          ++bus_b;
        }
      }
      break;
    }
    if (i % b == 0) {
      ++bus_b;
    }
  }
  printf("%d\n", bus_b);
  return 0;
}


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

int main()
{
	int n, k;
	char s[101];
	int p[100][26]={0,};
	int i, j, f=0;

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

	for(i=0;i<n;i++)
	{
		for(j=0;j<k;j++)
		{
			if(p[j][s[i]-'a'] == 0)
			{
				p[j][s[i]-'a'] = 1;
				break;
			}
		}
		if(j == k)
			f = -1;
	}

	if(f == -1)
		printf("NO\n");
	else
		printf("YES\n");

	return 0;
}


#include<stdio.h>
#include<string.h>
main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int c[27]={};
    char s[n+1];
    scanf("%s",s);
    int true=1;
    int i,l=strlen(s);
    for(i=0;i<l;i++)
    {
        c[s[i]-'a']++;
    }
for(i=0;i<26;i++)
{
    if(c[i]>k){
        true=0;
        break;
        }
}
if(true==1)
printf("YES\n");
else
    printf("NO\n");
}


#include <stdio.h>
int main(){
	int n,t,k,d;
	scanf("%d %d %d %d",&n,&t,&k,&d);
	if(d<((n-1)/k)*t){
        printf("YES\n");
	}
	else{
        printf("NO\n");
	}
	return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
	int n, t, k, d;
	scanf("%d%d%d%d", &n, &t, &k, &d);
	if ((d < (n - 1) / k * t))
	{
		printf("YES\n");

	}
	else
		printf("NO\n");

	return 0;
}


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

int main() {

	char s[101];
	scanf("%s",s);
	int i,count = 0;
	int n = strlen(s);
	int h = 1;

	for(i=0;i<n;i++) {
		if(s[i] == s[i+1] && h<5) h++;
		else {
			h = 1;
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}


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

int main()
{
  char s[1000];
  int x,i=0,c=0,k=0;
  scanf("%s",s);
  x=strlen(s);
  while(i<x){
     while(i<x){
        if(k==4){c++; break;}
        else if(s[i]==s[i+1]){k++;i++;}
        else if(s[i]!=s[i+1]){c++; break;}
     }
     i++;
     k=0;

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


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

int grundy[100100], mini[100100];

int solve(int n){
  int i,j,k;
  int m;
  int up, down;
  int chk[1000];
  int fin = 0;

  if(grundy[n]>=0) return grundy[n];
  mini[n] = -1;

  rep(i,1000) chk[i]=0;

  for(k=2;;k++){
    up = 2*n - k*k + k;
    down = 2*k;

    if(up < down) break;
    if(up%down) continue;

    m = 0;
    up /= down;
    rep(i,k) m ^= solve(up+i);
    if(m<1000) chk[m] = 1;

    if(m==0 && fin==0) fin=1, mini[n] = k;
  }

  rep(i,1000) if(chk[i]==0) break;
  return grundy[n] = i;
}

int main(){
  int i,j,k,l,m,n;

  rep(i,100100) grundy[i] = -1;

  while(scanf("%d",&n)==1){
    solve(n);
    printf("%d\n",mini[n]);
  }

  return 0;
}


#include<stdio.h>
int main()
{
    int n, x, ans = 0;;
    scanf("%d%d", &n, &x);
    for (int i = 1; i <= n; i++)
    {
        if ((x%i==0) && (x / i) <= n)
            ans++;
    }

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


#include <stdio.h>

int main(int argc, char const *argv[])
{
    int n,x;
    scanf("%d %d",&n,&x);
    int i,j,ct1=0,ct2=0;
    int fact[100000];
    int l=(x<n)?x:n;
    for(i=1;i<=l;i++)
    {
        if(x%i == 0)
        {
            fact[ct1]=i;
            ct1++;
        }
    }

    for(i=0;i<ct1;i++)
    {
        for(j=0;j<ct1;j++)
        {
            int to=fact[i]*fact[j];
            if(to==x)
                ct2++;
            if(to>x)
                break;
        }
    }
    printf("%d\n",ct2 );
    return 0;
}


//a
#include <stdio.h>
int main()
{
	long long int  n,k;
	scanf("%lld%lld",&n,&k);
	long long int x;
	x=n/(2*(k+1));
	printf("%lld %lld %lld\n",x,k*x,n-(k+1)*x );
	return 0;
}


#include<stdio.h>
int main()
{
    long long int n,k,a,b,c,d;
    scanf("%lld%lld",&n,&k);
    a=n/2;
    b=a/(k+1);
    c=b*k;
    d=n-(b+c);
    printf("%lld %lld %lld\n",b,c,d);
    return 0;
}


#include<stdio.h>

void swap(char *p, char *q)
{
	char tmp = *p;
	*p = *q;
	*q = tmp;
}

int main()
{
	char list[60];
	int n, i, j, t;

	while (scanf("%d %d", &n, &t) != EOF)
	{
		getchar();
		for (i = 0; i < n; i++)
		{
			scanf("%c", &list[i]);
		}
		list[i] = '\0';
		for (i = 0; i < t; i++)
		{
			for (j = 0; j < n; j++)
			{
				if (list[j] == 'B' && list[j + 1] == 'G')
				{
					swap(list + j, list + j + 1);
					j++;
					if (j >= n)
						break;
				}
			}
		}
		puts(list);
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
		int n,t,i=0,j;
		scanf("%d%d",&n,&t);
		char seq[n+1];
		scanf("%s",seq);

		 while(t--)
		{
			i=0;
			while(i<n-1)
			{
				if(seq[i]=='B')
				{
					if(seq[i+1]=='G')
					{char temp=seq[i];
					seq[i]=seq[i+1];
					seq[i+1]=temp;
					i++;
					}
				}
				i++;
			}

		}

		printf("%s",seq);
	return 0;
}


#include<stdio.h>
int main()
{
    int n,i,length=0,max_length=0,j=0,word=0,z=0;
    scanf("%d",&n);
    char str[n+1];
    scanf(" %s",str);

    for(i=0;i<n;i++)
    {
        if(((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))&&z==0)
            length++;
        else if(z==0&&str[i]=='_')
        {
            length=0;
        }
        else if(str[i]==')')
            z=0;
        else if(str[i]=='('||z>0)
        {
            length=0;
            z++;
            if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
            {
                if(j==0)
                {
                    word++;
                    j++;
                }
            }
            else
            {
                j=0;
            }
        }
        if(length>max_length)
            max_length=length;
    }

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


#include <stdio.h>

int main(){
  int n, in_par = 0, aux, in = 0, out = 0;
  scanf("%d", &n);
  char word[n+1];
  scanf("%s", word);
  for(int i = 0; i < n; i++){
    if(in_par){
      aux = 0;
      while(word[i] != ')'){
        if(word[i] != '_'){
          while(word[i] != '_' && word[i] != ')')
            i++;

          in++;
        }
        else{
          i++;
        }
      }
      in_par = 0;
    }
    else{
      aux = 0;
      while(word[i] != '_' && word[i] != '(' && i < n){
        aux++;
        i++;
      }
      if(word[i] == '(')
        in_par = 1;

      if(aux > out)
        out = aux;
    }
  }
  printf("%d %d\n", out, in);
  return 0;
}


#include <stdio.h>
int main() {
  char s[11]; int i,sum=0;
  scanf("%s",s);
  for (i=0;s[i];i++) {
    sum<<=1;
    sum+=s[i]=='4'?1:2;
  }
  printf("%d\n",sum);
  return 0;
}


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

#ifndef NULL
    #define NULL ((void *) 0)
#endif

void           allocate_error(size_t error_line);
unsigned short readline_hu(FILE * file);
int            compare(const void * a, const void * b);

int main() {

    unsigned short   n;
    unsigned short   index;
    unsigned short index2;
    unsigned short * h;
    unsigned short * g;
    unsigned short   counter;
    void *           ret;

    n       = readline_hu(stdin);
    h       = malloc(sizeof(unsigned short) * (n * 2));
    g       = malloc(sizeof(unsigned short) * (n * 2));
    index   = 0;
    index2 = 0;
    counter = 0;

    // ----- ERROR -----
    if (h == NULL || g == NULL)
        allocate_error(__LINE__);
    // ----- ERROR -----

    for (index = 0; index < n; index++) {

        // Save home and guest color
        h [index] = readline_hu(stdin);
        g [index] = readline_hu(stdin);
    }

    qsort(h, n, sizeof(unsigned short), compare);
    qsort(g, n, sizeof(unsigned short), compare);

    // Look how often the same appears

    for (index=0; index<n; index++) {

        for (index2=0; index2<n; index2++) {

            if (h[index] == g[index2])
                counter++;
        }
    }
    printf("%hu\n", counter);

    free(h);
    free(g);

    return EXIT_SUCCESS;
}

// -----===== Useful - selfmade functions =====-----
void allocate_error(size_t error_line) {
    printf("-----===== ERROR IN LINE %lu =====-----\n", error_line);
    printf("Couldn't allocate memory!\n");
    perror("");
    exit(-1);
}

unsigned short readline_hu(FILE * file) {

    char           buffer [6];
    unsigned short buffer_index = 0;
    int            character;

    // Get the digits of the number
    while (isdigit(character = getc(file)) && buffer_index < 5)
        buffer [buffer_index++] = (char) character;

    // Set the end of the line
    buffer [buffer_index] = '\0';

    // Convert string into unsigned short
    return (unsigned short) strtoul(buffer, NULL, 10);
}

int compare(const void * a, const void * b) {

    if (*(unsigned short *) a < *(unsigned short *) b)
        return -1;

    else if (*(unsigned short *) a == *(unsigned short *) b)
        return 0;

    else
        return 1;
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int matrix[26][26]={0};
	char s[101];
	int n;
	scanf("%d%*c",&n);
	gets(s);
	for (int i=0;i<n-1;i++)
	{
		matrix[s[i]-'A'][s[i+1]-'A']++;
	}
	int *pmax=&matrix[0][0];
	int imax=0,jmax=0;
	for (int i=0;i<26;i++)
	{
		for (int j=0;j<26;j++)
		{
			if (matrix[i][j]>*pmax)
			{
				pmax=&matrix[i][j];
				imax=i;
				jmax=j;
			}
		}
	}
	printf("%c%c",imax+'A',jmax+'A');
	return 0;
}


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

int main()
{
    int count;
    int n;
    int max=0;
    int i,j;
    char test[2],ans[2];

    scanf(" %d", &n);
    char arr[100];

    scanf(" %s", arr);
    ans[0]=arr[0];
    ans[1]=arr[1];

    for(i=0;i<n-1;i++){
        test[0]=arr[i];
        test[1]=arr[i+1];
        count=0;
        for(j=0;j<n-1;j++){
            if(test[0]==arr[j]){
                if(test[1]==arr[j+1]){
                    count++;
                }
            }
        }
        if(count>max){
            max=count;
            ans[0]=test[0];
            ans[1]=test[1];
        }
    }

    printf("%c%c",ans[0],ans[1]);

    return 0;
}


#include<stdio.h>

main()
{
    int ev,od,count1=0,count2=0,i;
    scanf("%d%d",&ev,&od);

    if( ev !=0 || od !=0)
   {
        for(i=1;i<=ev+od;i++)
    {
        if(i%2==0)
        {
            count1=count1+1;
        }
        else
        {
            count2=count2+1;
        }
    }

    if((count1==ev && count2==od) || (count2==ev && count1==od))
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
   }
   else
   {
       printf("NO");
   }
}


#include<stdio.h>
int main()
{
	int a,b;

	scanf("%d%d",&a,&b);
	if(a==0 && b==0){
		printf("NO\n");return 0;
	}
	if(a-b>=-1&&a-b<=1)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


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

#define N	1000000
#define MD	1000000007

long long ff[N], gg[N], pn[N], pm[N];

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

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

void init(int n, int m) {
	long long f, p;
	int i;

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

long long cayley(int n, int k) {
	return k == n ? 1 : k * pn[n - k - 1] % MD;
}

int main() {
	int n, m, a, b, k;
	long long ans;

	scanf("%d%d%d%d", &n, &m, &a, &b);
	init(n, m);
	ans = 0;
	for (k = 0; k <= n - 2 && k < m; k++) {
		/* choose(n - 2, k) * factorial(k) */
		long long path = ff[n - 2] * gg[n - 2 - k] % MD;
		/* choose(m - 1, k) * power(m, n - k - 2) */
		long long edges = ff[m - 1] % MD * gg[k] % MD * gg[m - 1 - k] % MD
			* pm[n - k - 2] % MD;

		ans = (ans + path * cayley(n, k + 2) % MD * edges) % MD;
	}
	printf("%lld\n", ans);
	return 0;
}


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


#include<stdio.h>
int main()
{
    long long int m, n, ans;

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

    if(n==1 && m==1)
        ans=0;
    else if(n==1 && m>1)
        ans=m-1;
    else if(n>1 && m==1)
        ans=n-1;
    else if(n>1 && m>1)
        ans=(m-1)*n;
    printf("%lld\n", ans);
}


#include <stdio.h>

int k = 998244353;
int main() {
    int m, n;
    scanf("%d%d", &m, &n);
    int t = m + n, r = 1;
    while (t--) {
        r = (r * 2) % k;
    }
    printf("%d\n", r);
    return 0;
}


#include<stdio.h>

#define MOD(a) ((a)%998244353)

int main(){
	int w, h, i, sum=4;
	scanf("%d %d", &w, &h);
	for(i=1;i<w;++i) sum=MOD(sum*2);
	for(i=1;i<h;++i) sum=MOD(sum*2);
	printf("%d\n", sum);
	return 0;
}


#include<stdio.h>
int main(){
    int indexa,indexb,i,j,k,m,n,sign,loop;
    int arr[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
    int brr[25];
    while(scanf("%d",&n) != EOF){
        sign = 0;
        for(i = 0;i < n;i++)
            scanf("%d",&brr[i]);
        for(i = 1;i <= 12;i++){
            indexb = 0;
            indexa = i;
            k = n;
            loop = 0;
            while(k--){
                if(indexa == 2){
                    if(brr[indexb] == 28 || brr[indexb] == 29){
                        if(brr[indexb] == 29 && loop == 1){
                            sign = 0;
                            break;
                        }
                        if(brr[indexb] == 29 && loop == 0)
                            loop = 1;
                        indexb++;
                        indexa++;
                        sign = 1;

                        continue;
                    }
                    sign = 0;
                    break;
                }
                if(arr[indexa] != brr[indexb]){
                    sign = 0;
                    break;
                }
                if(arr[indexa] == brr[indexb]){
                    indexa++;
                    indexb++;
                    if(indexa > 12)
                        indexa = 1;
                    sign = 1;
                }
            }
            if(sign == 1)
                break;
        }
        if(sign == 1)
            printf("Yes\n");
        if(sign == 0)
            printf("No\n");
    }
    return 0;
}


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


#include<stdio.h>
int main()
{
 int n,a,b,c,x;
 scanf("%d%d%d%d",&a,&b,&c,&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 fun(int ,int ,int );
int min(int ,int );
int min(int x,int y)
{
    return (x<y)?x:y;
}
int fun(int a,int b,int c)
{
    int cnt=0,tmp;
    tmp=min(min(a,b),c);
    a=a-tmp;
    b=b-tmp;
    c=c-tmp;
    cnt=cnt+tmp;
    cnt=cnt+a/3+b/3+c/3;
    a=a%3;
    b=b%3;
    c=c%3;
    if(a+b+c==4&&tmp!=0)
    {
        cnt++;
    }
    return cnt;
}
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d\n",fun(a,b,c));
    return 0;
}


#include <stdio.h>

main()
{
    int i, money, no_of_change, total= 0;
    scanf("%i", &money);

    while(money){
        if(money/100){
            no_of_change= money/100;
            money= money%100;
            total= total+no_of_change;
        }
        else if(money/20){
            no_of_change= money/20;
            money= money%20;
            total= total+no_of_change;
        }
        else if(money/10){
            no_of_change= money/10;
            money= money%10;
            total= total+no_of_change;
        }
        else if(money/5){
            no_of_change= money/5;
            money= money%5;
            total= total+no_of_change;
        }
        else if(money/1){
            no_of_change= money/1;
            money= money%1;
            total= total+no_of_change;
        }
    }
    printf("%i", total);
}


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

double area(int a)
{
    return (sqrt(3)*a*a)/4;
}

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

    double n_triangle = area(b+a+c) - area(a) - area(c) - area(e);

    printf("%.0lf\n", n_triangle / area(1));

    return 0;
}


#include <stdio.h>
int main()
{
    int a, b, c, d, e, f;
    scanf ( "%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f );
    int len = e+d+c;
    int ans = len*len;
    ans = ans - c*c - a*a - e*e;
    printf ( "%d\n", ans );
    return 0;
}


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

double square,triangle,d_tri;

int putting_pole(double remain,int count);

int main(void){
  int r,h,maxnum,n,count;
  double l;
  scanf("%d %d",&r,&h);
  square=r;
  triangle=sqrt(3)*r/2;
  d_tri=2*triangle;
  l=h-triangle;
  count=3;
  //printf("3:%f\n",l);
  n=putting_pole(l,count);
  maxnum=n;
  l=h-(double)r/2;
  count=2;
  //printf("2:%f\n",l);
  n=putting_pole(l,count);
  if(n>maxnum) maxnum=n;
  if(!n) maxnum=1;
  printf("%d\n",maxnum);
  return 0;
}

int putting_pole(double remain,int count){
  int x,y,z;
  int max=0,num;

  if(remain<0) return 0;

  for(x=remain/d_tri;x>=0;x--){
    y=(remain-x*d_tri)/square;
    z=(remain-x*d_tri-y*square>=triangle)?1:0;
    num=3*x+2*y+z;
    if(num>max) max=num;
  }
  return max+count;
}


#include<stdio.h>
#include<math.h>
typedef unsigned u;
typedef double d;
int main()
{
	d R,h,r,K;
	u ans,k;
	scanf("%lf%lf",&R,&h);
	r=R/2;
	K=(h+r)/R;
	k=(u)K;
	ans+=k<<1;
	K=h+R-R*k+r;
	if(K>=r+r*sqrt(3))ans++;
	printf("%u\n",ans);
	return 0;
}


#include <stdio.h>

int main() {
	long long l1, r1, l2, r2, k;
	scanf("%lld %lld %lld %lld %lld", &l1, &r1, &l2, &r2, &k);

	long long strt, end, cnt;
	strt = (l1 > l2) ? l1 : l2;
	end = (r1 < r2) ? r1 : r2;

	if(end < strt) {
		printf("0\n");
		return 0;
	}
	cnt = end - strt + 1;
	if(k >= strt && k <= end)
		cnt--;

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

	return 0;
}