#include <iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int  N,k,M,i,max=0;
	cin>>N>>M;
	int  a[N];
	for(i=0;i<N;i++)
	{
	    cin>>a[i];
	    if(a[i]>max)
	    max=a[i];
	}
	sort(a,a+N);
	for(i=0;i<N;i++)
	{
	    M=M-(max-a[i]);
	}
	k=M/N;
	if(k*N==M)
	cout<<a[N-1]+k<<" ";
	else
	cout<<a[N-1]+k+1<<" ";

	cout<<a[N-1]+M<<endl;
	return 0;
}


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

int searchMin(int capacity, int m, int n, int maxElement) {
	int kMin = 0;
	if (capacity >= m) kMin = maxElement;
	else if ((m - capacity) % n == 0) {
		kMin = maxElement + (m - capacity) / n;
	}
	else if ((m - capacity) % n != 0) {
		kMin = maxElement + 1 + (m - capacity) / n;
	}
	return kMin;
}

int main() {
	int n, m, maxElement, capacity, kMin, kMax;
	scanf("%d\n %d\n", &n);
	int* a = (int*)malloc(n * sizeof(int));
	maxElement = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d\n", &a[i]);
		if (a[i] > maxElement) maxElement = a[i];
	}
	kMax = maxElement + m;
	for (int i = 0; i < n; ++i) {
		capacity += (maxElement - a[i]);
	}
	kMin = searchMin(capacity, m, n, maxElement);
	printf("%d %d", kMIn, kMax);
	return 0;
}


#include <stdio.h>

int gcd (int a, int b) {
	return b ? gcd (b, a % b) : a;
}

int main() {
	long long a, b, x, y, l = 0, r = (long long)2e9, d;
	scanf("%I64d%I64d%I64d%I64d", &a, &b, &x, &y);
	d = gcd(x, y);
	x /= d; y /= d;
	printf("%I64d %I64d", x * min(a / x, b / y), y * min(a / x, b / y));

	return 0;
}


#include<stdio.h>
long long int lcm(long long int x,long long int y)
{
    long long int n1,n2;
    n1=x;n2=y;
    while(n1!=n2)
    {
        if(n1>n2)
        n1=n1-n2;
        else
        n2=n2-n1;
    }
    return(x*y/n1);
}
int main()
{long long int i,j,t,r,k,a1,x,y,a,b;
scanf("%I64d%I64d%I64d%I64d",&a,&b,&x,&y);
if(b>=(y*a)/x)
{if((a*y)%x==0)
printf("%I64d %I64d",a,y*a/x);
else
{t=lcm(x,y);
k=t/y;
a=(a/k)*k;
    printf("%I64d %I64d",a,y*a/x);
}
}
else
{
    if((b*x)%y==0)
    {a=x*b/y;
    printf("%I64d %I64d",a,b);}
    else
    {t=lcm(x,y);
k=t/x;
b=(b/k)*k;
    printf("%I64d %I64d",(b*x)/y,b);

    }
}
return 0;
}


#include <stdio.h>

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int binsearch(int a, int x) {
	int low, high, mid;

	low = 1;
	high = a / x;

	while (low <= high) {
		mid = (low + high) / 2;
		if (mid * x < a)
			low = mid + 1;
		else if (mid * x > a)
			high = mid - 1;
		else
			return mid;
	}
	return -1;
}

int main() {
	int a, b, x, y, g;
	long long i, j, k, n, m;

	scanf("%d%d%d%d", &a, &b, &x, &y);
	g = gcd(x, y);
	x /= g, y /= g;
	i = binsearch(a, x);
	j = binsearch(b, y);
	k = a / x < b / y ? a / x : b / y;
	n = i * x, m = i * y;
	if (n * m < j * x * j * y) {
		n = j * x;
		m = j * y;
	}
	if (n * m < k * x * k * y) {
		n = k * x;
		m = k * y;
	}
	if (n < 0)
		n = -n;
	if (m < 0)
		m = -m;
	if (a < x || b < y)
		printf("0 0\n");
	else
		printf("%lld %lld\n", n, m);
	return 0;
}


#include<stdio.h>
__int64 gcd(__int64 a,__int64 b)
{
    if(b==0)
        return(a);
    else return(gcd(b,a%b));
}
int main()
{
    __int64  a,b,x,y,i,j,p,d,low,high,mid,c=0,ma=0,ra,rb;
    scanf("%I64d%I64d%I64d%I64d",&a,&b,&x,&y);
    d=gcd(x,y);
    x=x/d;
    y=y/d;
    for(i=0;i<a;i++)
    {
        d=y*(a-i);
        low=0;
        high=b-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            p=x*(b-mid);
            if(p<d)
                high=mid-1;
            else if(p>d)
                low=mid+1;
            else if(p==d)
            {
                c++;
                if((a-i)*(b-mid)>ma)
                {
                    ma=(a-i)*(b-mid);
                    ra=a-i;
                    rb=b-mid;
                }
                break;
            }
        }
        if(c>0)
            break;
    }
    if(c==0)
        printf("0 0");
    else printf("%I64d %I64d",ra,rb);
        return(0);

}


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

void find_size(int a, int b, int x, int y, int *p, int *q)
{
	double r1 = (double) a / b, r2 = (double) x / y;
	if (r1 == r2) {
		*p = a;
		*q = b;
	}
	else if (r1 > r2) {
		double f = (double) x*b / y;
		if (ceilf(f) == f) {
			*p = f;
			*q = b;
		}
		else {
			find_size(f, b, x, y, p, q);
		}
	}
	else {
		double f = (double) a*y / x;
		if (ceilf(f) == f) {
			*p = a;
			*q = f;
		}
		else {
			find_size(a, f, x, y, p, q);
		}
	}
}

int main()
{

	int a, b, x, y, p, q;

	scanf("%i %i %i %i", &a, &b, &x, &y);
	find_size(a, b, x, y, &p, &q);
	printf("%i %i\n", p, q);

	return 0;
}


#include<stdio.h>
#define gi(x) scanf("%d",&x)
int main()
{
	int n;
	gi(n);
	int k1,k2,i,x;
	gi(k1);
	int a[1000001];
	int b[1000001];
	int y=k1;
	int g=0;
	int countone=k1;
	for(g=0;g<k1;g++)
		scanf("%d",&a[g]);
	gi(k2);
	for(g=0;g<k2;g++)
		scanf("%d",&b[g]);
	int counttwo=k2;
	int count=0;
	int oo=10000000;
	int r=0;
	while(count < oo && countone > 0 && counttwo > 0)
	{
		if(a[r] > b[r])
		{
			a[k1++]=b[r];
			a[k1++]=a[r];
			counttwo-=1;
			countone+=1;
		}
		else
		{
			b[k2++]=a[r];
			b[k2++]=b[r];
			countone-=1;
			counttwo+=1;
		}
		count++;
		r++;
	}
	if(count==oo)
		printf("-1\n");
	else if(countone==0)
		printf("%d 2\n",count);
	else
		printf("%d 1\n",count );
	return 0;
}


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

int g_count ;
struct stack {
  int header;
  int tail;
  int size;
  int *array;
};
void printer(int size , int grid[size]) {
  for (int i = 0 ; i < size  ; i++) {
    printf("%d ", grid[i]);
  }
  printf("\n");
}
void queue_add( struct stack *s, int element, int size) {
  s->tail++;
  s->array[(s->tail)%size] = element;
}
int queue_pop(struct stack *s, int size) {
  s->header++;
  return s->array[(s->header)%size];
}
int queue_size(struct stack *s , int size) {
  return (s->tail - s->header) ;
}
int main() {
  int n;

  scanf("%d", &n);
  struct stack s1;
  struct stack s2;
  scanf("%d", &s1.size);
  s1.array = malloc(s1.size * sizeof(int));
  s1.header = -1 , s1.tail = -1;
  for (int i = 0; i < s1.size ; i++) {
    int temp;
    scanf("%d", &temp);
    queue_add(&s1, temp, n);
  }

  scanf("%d", &s2.size);
  s2.header = -1 , s2.tail = -1;

  s2.array = malloc(s2.size * sizeof(int));
  for (int i = 0; i < s2.size ; i++) {
    int temp;
    scanf("%d", &temp);
    queue_add(&s2, temp, n);
  }
  int win = 0, stale = 0;

  int s2_back = s2.array[0];
  int s1_back = s1.array[0];
  g_count = 0;

  while ( win == 0 && stale == 0) {
    int save_size = queue_size(&s1, n);

    int a = queue_pop(&s1, n);
    int b = queue_pop(&s2, n);

      g_count++;
    if ( a > b) {
      queue_add(&s1, b, n);
      queue_add(&s1, a, n);

      //printer(n, s1.array);
     //  printer(n, s2.array);
    } else {
      queue_add(&s2, a, n);
      queue_add(&s2, b, n);
    //   printer(n, s1.array);
   //     printer(n, s2.array);

    }
    if ( s1.header == s1.tail) {
      win = 2;
    }
    if ( s2.header == s2.tail) {
      win = 1;
    }
    if ( a == s1_back  && b == s2_back  && save_size == s1.size && g_count> 900) {
      stale = 1;
    }
  }
  if ( stale == 1) {
    printf("-1\n");
  }
  else {
    printf("%d %d\n",g_count,win);
  }

}


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

int main()
{
    long long int n,sum=1,i,c=0;

    scanf("%I64d",&n);

    if(n==0) printf(1);
    else{
        for(i=6;;i+=6){
            sum+=i;
            c++;
            if(c==n) break;
        }
        printf("%I64d",sum);
    }

    return 0;
}


#include <stdio.h>
#include <math.h>
int main () {
    unsigned long long a;
    int b, i;
    scanf("%lld", a);
    printf("%lld", 1 + 6 * a);
    return 0;
}


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

int main()
{ int n,t;

    scanf("%d",n);

    t=(6^n-1)/(6-1);
    printf("%d",t);
    return 0;
}


#include<stdio.h>

int main()
{
    int n;
    long t ;
    scanf("%d",&n);
    t=6^(n-1)/5;
    printf("%ld",t);
    return(0);


#include <stdio.h>
#include <math.h>
int main () {
    unsigned long long a;
    int b, i;
    scanf("%lld", &a);
    if (a < 2) {
    if (a == 0)
        printf("1");
    if (a == 1)
        printf("7");
    }
    else
    printf("%lld", a*(a+1)/2*6 + 1;
    return 0;
}


#include<stdio.h>
int main()
{
	int n,m,times,newn,newm,ans;
	scanf("%d%d%d",&n,&m,&times);
	times--;
	newn=n-2*times;
	newm=m-2*times;
	if(newn==0 || newm==0)
	{
		printf("0\n");
		return 0;
	}
	if(newn-2>0 && newm-2>0)
	ans=(	(newn*newm)	-	((newn-2)*(newm-2))	)/2;
	else
	ans=(newn*newm)/2+(newn*newm)%2;
	printf("%d\n",ans);
}


#include<stdio.h>
#include<string.h>
int main()
{
	char a[100100],c;
	int i,sum;
	int num[26],flag1,flag2,num1,sum1,k,h,total;
	while(scanf("%s",a)!=EOF)
	{
		sum=0;
		memset(num,0,sizeof(num));
		for(i=0;a[i];i++)
			if(a[i] != '0')
				break;
		if(a[i] ==0)
		{
			printf("1\n");
			continue;
		}
		flag1=0;
		flag2=0;
		num1=0;
		if(a[i] == '?')
			flag1=1;
		else if(a[i]>='A' && a[i] <='J')
		{
			flag2=1;
			c=a[i];
		}
		for(;a[i];i++)
		{
			if(a[i]>='A' && a[i]<='J')
			{
				if(num[a[i] -'A'] == 0)
					num1++;
				num[a[i] -'A']++;
			}
			else if(a[i] == '?')
				sum++;
		}
		if(flag1 == 1)
			total = sum *9;
		else
			total = sum*10;
		if(flag2 == 1)
		{
			h=2;
			sum1=9;
			k=9;
			for(;h<=num1;h++)
			{
				sum1*=k;
				k--;
			}
			total *= sum1;
		}
		else
		{
			sum1=1;
			k=10;
			for(h=1;h<=num1;h++)
			{
				sum1*=k;
				k--;
			}
			total *= sum1;
		}
		if(total ==0)
			printf();
		printf("%d\n",total);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#define MAX 100000

int main()
{
	char hint[MAX], c ;
	int let_flag[10], i, pos, n ;

	scanf(" %s",hint) ;

	n = 1 ;
	pos = 10 ;

	for(i=0;i<10;++i)
		let_flag[i] = 0 ;

	for(i=0;i<strlen(hint);++i)
	{
		c = hint[i] ;
		if((c>='A')&&(c<='J'))
		{
			if(let_flag[c-65]==0)
			{
				let_flag[c-65] = 1 ;
				if(i==0)
					n *= 9 ;
				else
					n *= pos ;
				pos-- ;
			}
		}
		else if(c=='?')
		{
			if(i==0)
				n *= 9 ;
			else
				n *= 10 ;
		}
	}

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


#include<stdio.h>
#include<string.h>
#define MAX 100000

int main()
{
	char hint[MAX], c ;
	int let_flag[10] = {0}, i, pos, n ;

	scanf(" %s",hint) ;

	n = 1 ;
	pos = 10 ;

	for(i=0;i<strlen(hint);++i)
	{
		c = hint[i] ;
		if((c>='A')&&(c<='J'))
		{
			if(let_flag[c-65]==0)
			{
				let_flag[c-65] = 1 ;
				if(i==0)
					n *= 9 ;
				else
					n *= pos ;
				pos-- ;
			}
		}
		else if(c=='?')
		{
			if(i==0)
				n *= 9 ;
			else
				n *= 10 ;
		}
	}

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


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

int main()
{
	char hint[100], c ;
	int let_flag[10], i, pos, n ;

	scanf(" %s",hint) ;

	n = 1 ;
	pos = 10 ;

	for(i=0;i<10;++i)
		let_flag[i] = 0 ;

	for(i=0;i<strlen(hint);++i)
	{
		c = hint[i] ;
		if((c>='A')&&(c<='J'))
		{
			if(let_flag[c-65]==0)
			{
				let_flag[c-65] = 1 ;
				if(i==0)
					n *= 9 ;
				else
					n *= pos ;
				pos-- ;
			}
		}
		else if(c=='?')
		{
			if(i==0)
				n *= 9 ;
			else
				n *= 10 ;
		}
	}

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


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

int main()	{
	int midLen, len1, len2;
	int i, letterArr[26]={0}, pos, lenToKey;
	char str[30], key, grid1[14]={0}, grid2[14]={0}, *cp1, *cp2;
	scanf("%s", str);
	for(i=0; i<27; i++)	{
		if(letterArr[str[i]-'A'])	break;
		else letterArr[str[i]-'A']++;
	}
	key = str[i];
	cp1 = strchr(str, key);
	cp2 = strchr(cp1+1, key);
	midLen = (int)(cp2-cp1-1);
	if(midLen == 0)	{
		printf("Impossible");	return 0;
	}
	len1 = midLen/2;
	len2 = midLen-len1;
	for(pos=13-len1-1, i=0; i<=len1; i++)	{
		grid1[pos++] = *(cp1+i);
	}
	pos = 13-len1-1;
	for(pos=12, i=len2; i>0; i--)	{
		grid2[pos--] = *(cp2-i);
	}
	lenToKey = cp1-str+1;
	if(lenToKey+len1>=13)	{
//		puts("EnteredAt1st");
		pos = 13-len1-1;
		while(pos>=0)	grid1[--pos] = *(--cp1);
		i=0;
//		puts("Ok");
		while(cp1>str)	grid2[i++] = *(--cp1);
		cp2++;	pos = 13-len2;
		while(*cp2)	grid2[--pos] = *(cp2++);
		printf("%s\n%s", grid1, grid2);
		return 0;
	}
	else	{
		pos = 13-len2;
		while(pos>=0)	grid2[--pos] = *(cp2++);
		i=0;
		while(*cp2)	grid1[i++] = *(cp2++);	pos=0;
		while(i<13)	grid1[i++] = str[i];
		printf("%s\n%s",grid1, grid2);
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-9
#define ll long long int
#define N 500500
char first1[N];
char in[N];
char first2[N];
char second1[N];
char second2[N];
int main(){
   gets(in);
   int remem=-1;int start;
   for(int i=0;i<strlen(in);i++){
      for(int w=0;w<strlen(in);w++){
         if(i!=w){
            if(in[i]==in[w] && remem==-1){
               remem=w-i+1;
               start=i;
            }
         }
      }
   }
   if(remem<=3){
      printf("Impossible");
      return 0;
   }
   int k=0;int i;
   i=start;
   int ub=remem%2==0?remem/2-1:remem/2;
   for(int w=0;w<(remem)/2;w++){
      if(i>26)
      i=0;
      first2[k++]=in[i++];
   }
   k=0;
   for(int w=0;w<ub;w++){
      if(i>26)
      i=0;
      second2[k++]=in[i++];
   }
   i++;k=0;
   for(int w=0;w<(13-(remem/2));w++){
      if(i>26)
      i=0;
      first1[k++]=in[i++];
   }
   k=0;
   for(int w=0;w<13-(ub);w++){
      if(i>26)
      i=0;
      second1[k++]=in[i++];
   }
   for(int i=0;i<strlen(second2)/2;i++){
      char t=second2[i];
      second2[i]=second2[strlen(second2)-i-1];
      second2[strlen(second2)-i-1]=t;
   }
   for(int i=0;i<strlen(first1)/2;i++){
      char t=first1[i];
      first1[i]=first1[strlen(first1)-i-1];
      first1[strlen(first1)-i-1]=t;
   }
   printf("%s%s\n%s%s",first1,first2,second1,second2);
}


#include<stdio.h>
char s[30];
int a[30];
int main()
{
    scanf("%s",s);
    int target=s[0]-'A'+1;
    int last=target;
    a[0]=target;
    for(int i=1;s[i]!='\0';i++)
    {
        int temp=s[i]-'A'+1;
        a[i]=temp;
        if(temp==last)
        {
            printf("Impossible\n");
            return 0;
        }
        last=temp;
    }
    for(int i=0;i<=26;i++)
    {
        for(int j=i+1;j<=26;j++)
            if(a[i]==a[j])
                target=a[i];
    }
    int flag=0;
    int start,end;
    start=end=0;
    for(int i=0;i<27;i++)
    {
        if(a[i]==target&&flag==0)
            start=i,flag=1;
        else if(a[i]==target&&flag!=0)
            end=i;
    }
    int mid=(end-start-1)/2+start;
    //printf("%d %d %d\n",mid,start,end);
    if(mid>=13){
        if((end-start-1)%2!=0) mid++;
        for(int i=mid-12;i<=mid;i++)
            printf("%c",a[i]+'A'-1);
        printf("\n");
        for(int i=mid-13;i>=0;i--)
            printf("%c",a[i]+'A'-1);
        for(int i=26;i>mid;i--)
        {
            if(i==end) continue;
            printf("%c",a[i]+'A'-1);
        }
        printf("\n");
    } else
    {
        if((end-start-1)%2==0) mid++;
        for(int i=mid+1;i<=mid+13;i++)
        {
            //if(i==end) continue;
            printf("%c",a[i]+'A'-1);
        }
        printf("\n");
        for(int i=mid;i>=0;i--)
        {
            if(i==start) continue;
            printf("%c",a[i]+'A'-1);
        }
        for(int i=26;i>mid+13;i--)
        {
            printf("%c",a[i]+'A'-1);
        }
        printf("\n");
    }

    return 0;
}


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

int main()	{
	int midLen, len1, len2;
	int i, letterArr[26]={0}, pos, lenToKey;
	char str[30], key, grid1[14]={0}, grid2[14]={0}, *cp1, *cp2;
	scanf("%s", str);
	for(i=0; i<27; i++)	{
		if(letterArr[str[i]-'A'])	break;
		else letterArr[str[i]-'A']++;
	}
	key = str[i];
	cp1 = strchr(str, key);
	cp2 = strchr(cp1+1, key);
	midLen = (int)(cp2-cp1-1);
	if(midLen == 0)	{
		printf("Impossible");	return 0;
	}
	len1 = midLen/2;
	len2 = midLen-len1;
	for(pos=13-len1-1, i=0; i<=len1; i++)	{
		grid1[pos++] = *(cp1+i);
	}
	pos = 13-len1-1;
	for(pos=12, i=len2; i>0; i--)	{
		grid2[pos--] = *(cp2-i);
	}
	lenToKey = cp1-str+1;
	if(lenToKey+len1>=13)	{
//		puts("EnteredAt1st");
		pos = 13-len1-1;
		while(pos>=0)	grid1[--pos] = *(--cp1);
		i=0;
//		puts("Ok");
		while(cp1>str)	grid2[i++] = *(--cp1);
		cp2++;	pos = 13-len2;
		while(*cp2)	grid2[--pos] = *(cp2++);	grid1[13] = 0; grid2[13] = 0;
		printf("%s\n%s", grid1, grid2);
		return 0;
	}
	else	{
//		puts("EntererdAt2nd");
		pos = 13-len2;
		while(pos>=0)	grid2[--pos] = *(cp2++);
		i=0;
		while(*cp2)	grid1[i++] = *(cp2++);	pos=0;
		while(i<13)	grid1[i++] = str[i];	grid1[13] = 0; grid2[13] = 0;
		printf("%s\n%s",grid1, grid2);
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-9
#define ll long long int
#define N 500500
char in[N];
char first[N];
char second[N];
int main(){
   gets(in);
   if(in[19]!=in[6]){
      printf("Impossible");
      return 0;
   }
   second[0]=in[strlen(in)-1];
   int k=1;
   int len=strlen(in);
   for(int i=0;i<6;i++){
      second[k++]=in[i];
   }
   int s=12;
   int go=13;
   for(int i=0;i<6;i++){
      second[s--]=in[go++];
   }
   s=0;
   go=25;
   for(int i=0;i<6;i++){
      first[s++]=in[go--];
   }
   go=6;
   for(int i=0;i<=6;i++){
      first[s++]=in[go++];
   }

   for(int i=0;i<strlen(first);i++){
      merge[0][i]=first[i];
   }
   for(int i=0;i<strlen(second);i++){
      merge[1][i]=second[i];
   }
   puts(first);
   puts(second);

}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long arr[1000001];
char str[1000001];
int func(const void *a, const void *b)
{
	return (*(int*)a-*(int*)b);
}
long long max(long long a, long long b)
{
	return (a>b)?a:b;
}
long long min(long long a, long long b)
{
	return (a>b)?b:a;
}
int main()
{
	long long int n, i, j, k, count=0, ans=0, p, x,y;
	long long temp=0;
	scanf("%lld %lld %lld", &p, &x, &y);
	//	scanf("%s", str);
	i=(x/50)%475;
	long long flag=0;
	for(j=1;j<=25;j++)
	{
		i=(i*96+42)%475;
//		printf("%lld\n",26+i);
		if(i+26==p)
			flag=1;
	}
	if(flag)
		printf("0\n");
	else
	{
		for(i=x+50;i<=25000;i=i+50)
		{
			k=(i/50)%475;
			for(j=1;j<=25;j++)
			{
				k=(k*96+42)%475;
				if(k+26==p)
				{
					ans=(i-x+50)/100;
					flag=1;
					break;
				}
			}
			if(flag)
				break;
		}
		if(flag)
			printf("%lld\n",ans);
		else
			printf("0\n");

		return 0;
	}
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int func(int x,int p)
{
	int i=(x/50)%475,j=25;
	for(j=0;j<25;j++)
	{
		i=(i*96+42)%475;
		if(26+i==p)
		{
			return 1;
		}
	}
	return 0;
}

int main( )
{
	int p,x,y,i=0,j,c=25,a[500];
	scanf("%d %d %d",&p,&x,&y);
	for(i=x;i>=y;i-=50)
	{
		if(func(i,p))
		{
			return !printf("0\n");
		}
	}
	for(i=50;;i+=50)
	{
		if(func(x+i,p))
		{
			return !printf("%d\n",(i+50/100));
		}
	}
	return 0;
}


#include <stdio.h>

int good(int i, int p) {
	int k;

	for (k = 0; k < 25; k++) {
		i = (i * 96 + 42) % 475;
		if (i + 26 == p)
			return 1;
	}
	return 0;
}

int main() {
	int p, y, x, i, a, b, min, res;

	scanf("%d%d%d", &p, &x, &y);
	a = y / 50;
	b = x / 50;
	min = 1000;
	for (i = a; i <= b + 475; i++) {
		res = i < b ? 0 : (i - b + 1) / 2;
		if (good(i % 475, p) && min > res)
			min = res;
	}
	printf("%d\n", min);
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
int main()//C
{
    long long c,hr,hb,wr,wb,i,k,ans,x;
    scanf("%I64d%I64d%I64d%I64d%I64d",&c,&hr,&hb,&wr,&wb)
        if(c<wr&&c<wb){
            printf("0\n");
            continue;
        }
        if(c<wb&&c>=wr){
            printf("%d\n",c/wr*hr);
            continue;
        }
        if(c<wr&&c>=wb){
            printf("%d\n",c/wb*hb);
            continue;
        }
        ans=0;
        for(i=0;i*i<=c;i++){
            if(c-i*wb>=0)
                ans=(ans>i*hb+(c-i*wb)/wr*hr?ans:i*hb+(c-i*wb)/wr*hr);
            if(c-i*wr>=0)
                ans=(ans>i*hr+(c-i*wr)/wb*hb?ans:i*hr+(c-i*wr)/wb*hb);
        }
        printf("%d\n",ans);
    return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
    long long int c,hr,hb,wr,wb,happy=0,qr,qb,ans=0,temp;
    int i,j;
    scanf("%I64d",&c);
    scanf("%I64d",&hr);
    scanf("%I64d",&hb);
    scanf("%I64d",&wr);
    scanf("%I64d",&wb);
    if(wr>=sqrt(c))
    {
        for(i=0;i<=c/wr;i++)
        {
            temp=i*hr+((c-i*wr)/wb)*hb;
            //printf("temp:%I64d\n",temp);
            if(temp>ans)
                ans=temp;
        }
    }
    else if(wb>=sqrt(c))
    {
        for(i=0;i<=c/wb;i++)
        {
            temp=i*hb+((c-i*wb)/wr)*hr;
            //printf("temp:%I64d\n",temp);
            if(temp>ans)
                ans=temp;
        }
    }
    else if(wr<sqrt(c) && wb<sqrt(c))
    {
        if(hr*wb<=hb*wr)
        {
            for(i=0;i<=wb;i++)
            {
                temp=i*hr+((c-i*wr)/wb)*hb;
                if(temp>ans)
                    ans=temp;
            }
        }
        else
        {
            for(i=0;i<=wr;i++)
            {
                temp=i*hb+((c-i*wb)/wr)*hr;
                if(temp>ans)
                    ans=temp;
            }
        }
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<stdio.h>

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

int main(void){
    long long int  C,Hr,Hb,Wr,Wb;
    long long int ans = 0;
    int i;

   scanf("%lld %lld %lld %lld %lld",&C,&Hr,&Hb,&Wr,&Wb);

    for(i=0;i<1000000;i++)
		if(Wr * i <= C)
			ans = max(ans, Hr * i + (C - Wr * i) / Wb * Hb);

    for(i=0;i<1000000;i++)
		if(Wb * i <= C)
			ans = max(ans, Hb * i + (C - Wb * i) / Wr * Hr);

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

    return 0;
}


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

int main() {
	int c, hr, hb, wr, wb, sq;
	long long max, r, b;

	scanf("%d%d%d%d%d", &c, &hr, &hb, &wr, &wb);
	if (hr * wb > hb * wr) {
		int tmp;

		tmp = hr, hr = hb, hb = tmp;
		tmp = wr, wr = wb, wb = tmp;
	}
	sq = sqrt(c), max = 0;
	if (wb > sq)
		for (b = 0; b * wb <= c; b++) {
			r = (c - b * wb) / wr;
			if (max < r * hr + b * hb)
				max = r * hr + b * hb;
		}
	else
		for (r = 0; r < wb && r * wr <= c; r++) {
			b = (c - r * wr) / wb;
			if (max < r * hr + b * hb)
				max = r * hr + b * hb;
		}
	printf("%lld\n", max);
	return 0;
}


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


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

int main(){
    int sx=0,sy=0,p=1,a,b,i,num_len,dx,dy;
    char s[110];
    int pos_x[110];
    int pos_y[110];
    scanf("%d %d %s",&a,&b,s);
    pos_x[0]=pos_y[0]=0;
    num_len=strlen(s);
    for(i=0;i<num_len;i++){
        switch(s[i]){
        case 'U':
            sy++;
            break;
        case 'D':
            sy--;
            break;
        case 'R':
            sx++;
            break;
        case 'L':
            sx--;
            break;
        default: ;
        }
        pos_x[i+1]=sx;
        pos_y[i+1]=sy;
    }
    dx=pos_x[num_len];
    dy=pos_y[num_len];
    for(i=0;i<=num_len;i++){
        if(dx && dy){
            if((float)(a-pos_x[i])/dx==(float)(b-pos_y[i])/dy && dx*(a-pos_x[i])>=0) {printf("Yes"); return 0;}
        }
        else if(dx){
            if(b-pos_y[i]==0 && (a-pos_x[i])%dx==0 && dx*(a-pos_x[i])>=0) {printf("Yes"); return 0;}
        }else{
            if(a-pos_x[i]==0 && (b-pos_y[i])%dy==0 && dy*(b-pos_y[i])>=0) {printf("Yes"); return 0;}
        }
    }
    printf("No");
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)n;++i)
typedef long long ll;

const int dy[] = {1,0,-1,0};
const int dx[] = {0,1,0,-1};

int d[100];
char s[105];
int vx[105], vy[105];
int ix, iy;
int main() {
	int a,b;
	while(scanf("%d%d", &a, &b) == 2) {
		scanf("%s",s);
		ll y=0,x=0;
		int n = strlen(s);
		REP(i,n) {
			d[i] = strchr("URDL", s[i]) - s;
		}
		ix = 0;
		iy = 0;
		vx[ix++] = 0;
		vy[iy++] = 0;
		REP(i,n) {
			y += dy[d[i]];
			x += dx[d[i]];
			vy[iy++] = y;
			vx[ix++] = x;
		}
		ll Y = y;
		ll X = x;
		int ok = 0;
		REP(i,n) {
			REP(j,n) {
				ll yy = vy[j];
				ll xx = vx[j];
				ll y = b-yy;
				ll x = a-xx;
				if (Y && y % Y == 0) {
					if (X*(y/Y) == x) {
						ok = 1;
					}
				}
				if (Y == 0 && y == 0) {
					if (x == 0 || (X && x % X == 0)) {
						ok = 1;
					}
				}
			}
		}
		printf("%s\n",ok?"Yes":"No");
	}
}


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

int main(){
    int sx=0,sy=0,p=1,a,b,i,num_len,dx,dy;
    char s[110];
    int pos_x[110];
    int pos_y[110];
    scanf("%d %d %s",&a,&b,s);
    pos_x[0]=pos_y[0]=0;
    num_len=strlen(s);
    for(i=0;i<num_len;i++){
        switch(s[i]){
        case 'U':
            sy++;
            break;
        case 'D':
            sy--;
            break;
        case 'R':
            sx++;
            break;
        case 'L':
            sx--;
            break;
        default: ;
        }
        pos_x[i+1]=sx;
        pos_y[i+1]=sy;
    }
    dx=pos_x[num_len];
    dy=pos_y[num_len];
    for(i=0;i<=num_len;i++){
        if(dx && dy){
            if((float)(a-pos_x[i])/dx==(float)(b-pos_y[i])/dy && ((dx>0 && (a-pos_x[i])>=0)||(dx<0 && (a-pos_x[i])<=0))) {printf("Yes"); return 0;}
        }
        else if(dx){
            if(b-pos_y[i]==0 && (a-pos_x[i])%dx==0 && ((dx>0 && (a-pos_x[i])>=0)||(dx<0 && (a-pos_x[i])<=0))) {printf("Yes"); return 0;}
        }else{
            if(a-pos_x[i]==0 && (b-pos_y[i])%dy==0 && ((dy>0 && (b-pos_y[i])>=0)||(dy<0 && (b-pos_y[i])<=0))) {printf("Yes"); return 0;}
        }
    }
    printf("No");
    return 0;
}


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

    int a[n];
    char temp;

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

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

    for(int i=0;i<n;i=i+2){
        need+=a[i+1]-a[i];
    }

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


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

    for(int i=0;i<a;i++)
    {
        for(int j=i+1,k=0;j<a;j++,k++);
        {
            c[k]=abs(s[i]-s[j]);
            d=c[0];
            if(d>c[k])
            d=c[j-1];
        }
        for(int k=0;k<d;k++)
        count++;
    }
    printf("%d",count);
    return 0;
}


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

int main(){
	int w1,h1,w2,h2;
	scanf("%d%d%d%d",&w1,&h1,&w2,&h2);
	int num=w1+2+h1+h1+2+(w1-w2)+h2+h2+w2;
	printf("%d",num);
}


#include <iostream>

using namespace std;

int main()
{
   long long w1,w2,h1,h2;
   cin>>w1>>h1>>w2>>h2;
   long long ans = 2*w1 + 2*h1 + 2*h2 + 4;
   cout<<ans;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="A. Sea Battle" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/A. Sea Battle" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/A. Sea Battle" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
		</Compiler>
		<Unit filename="main.c">
			<Option compilerVar="CC" />
		</Unit>
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include<stdio.h>
#include<string.h>
int main(){
    int len;
    char a[101];
    scanf("%s",a);
        len=strlen(a);
        if(len<3||(len==3&&strcmp(a,"127")<=0))printf("byte\n");
        else if(len<5||(len==5&&strcmp(a,"32767")<=0))printf("short\n");
        else if(len<10||(len==10&&strcmp(a,"2147483647")<=0))printf("int\n");
        else if(len<19||(len==19&&strcmp(a,"9223372036854775807")<=0))printf("long\n");
        else printf("BigInteger\n");
    }
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="petya and java" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/petya and java" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/petya and java" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
		</Compiler>
		<Unit filename="main.c">
			<Option compilerVar="CC" />
		</Unit>
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include <stdio.h>

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

	char b[length];
	for (int i = 0; i < length; i++) {
		scanf("%c", &b[i]);
	}

	int result = 0;
	for (int i = 0; i < length; i++) {
		if (b[i] == '0') {
			result++;
			break;
		}
		else if (b[i] == '1') {
			result++;
		}
	}

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


#include <stdio.h>
char x[1001]= {'\0'};
int main()
{
    int n,x,i,a=0;
    scanf("%d %s",&n,x);

    for(i=0;i<n;i++){
        if(x[i]=='1') a++;
        if(x[i]==0) break;
    }
    if(a==n) printf("%d",a);
    else printf("%d",a+1);

    return 0;
}


#include <stdio.h>
#include <math.h>
int main () {
	int input;
	float result=0;

	scanf("%d",&input);fflush(stdin);
	char binary[100];

	scanf("%s",binary);fflush(stdin);

	for (int i=0;i<input;i++){
		if (binary[i]=='1'){
			result += pow(2.0,i);
		}
	}
	result+=1;

	char binary2[100];
	for(int i=0;i<input;i++){
		if ((int)result%2==1)
			binary2[i]='1';
		else if((int)result%2==0)
			binary2[i]='0';

		result/=2;
	}
	binary2[input]='\0';

	int output=0;
	for(int i=0;i<input;i++){
		if(binary[i]!=binary2[i])
			output++;
	}
	printf("%d",output);
	return 0;
}


#include <stdio.h>

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

	char b[length];
	for (int i = 0; i < length; i++) {
		scanf("%s", &b[i]);
	}

	int result = 0;
	for (int i = 0; i < length; i++) {
		if (b[i] == '0') {
			result++;
			break;
		}
		else if (b[i] == '1') {
			result++;
		}
	}

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


#include<stdio.h>
main()
{
    int i,n;
    char a;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%c",&a);
        if(a!='1')
           break;
    }
    if(i==n+1)
       printf("%d",n);
    else
       printf"%d",i);
}


#include<stdio.h>
int main(){
    char cad[10];
    scanf("%s",cad);
    printf("7");
    return 0;
}


#include<stdio.h>
int main(){
    int i,r;
    char s[10];
    scanf("%s",s);
    for(i=r=1;i<7;i++){
        if(s[i]==1){
            r+=10;
        }else{
            r+=s[i]-'0';
        }
    }
    printf("%d",r);
    return 0;
}


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

int stat[26], sumT;

int checkSubStrings(){
    int i, status = 0;
    for (i = 0; i < 26; i++){
        status += stat[i];
    }
    return status + sumT;
}

int main()
{
    char s[50005];
    scanf("%s", &s);
    int len = strlen(s), i, j, k;
    sumT = 0;
    if (len < 26) printf("-1\n");
    else{
        for (i = 0; i < 26; i++){
            if (s[i] != '?'){
                stat[s[i] - 65] = 1;
            }else sumT++;
        }
//        printf("SubStrings = %d\n", checkSubStrings());
        i = 0;
        while ((checkSubStrings() != 26) && (i <= (len - 26))){
            if (s[i] != '?') stat[s[i] - 65] = 0;
            else sumT--;
            if (s[i + 26] != '?') stat[s[i + 26] - 65] = 1;
            else sumT++;
            i++;
        }
//        printf("I = %d\n", i);
        if (checkSubStrings() != 26) printf("-1\n");
        else {
            for (j = i; j < i + 26; j++){
                if (s[j] == '?'){
                    k = 0;
                    while (k < 26){
                        if (!stat[k]) {
                            s[j] = k + 65;
                            stat[k] = 1;
                            break;
                        }
                        k++;
                    }
                }
            }
            for (j = 0; j < len; j++)
                if (s[j] == '?') s[j] = 'A';
            printf("%s\n", s);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    long int n,que=0,count=0,i=0,j=0,p,res=0,k,l;
    char str[50010];
    scanf("%s",&str);
        long int arr[27]={0};
        for(i=0,j=0;j<strlen(str);)
        {
            if(str[j]=='?')
            {
                que++;
                j++;
            }
            else
            {
                if(arr[str[j]-'A'])
                {
                    while(i<j)
                    {
                        if(str[i]==arr[str[j]-'A']+'A')
                        {
                            i++;
                            break;
                        }
                        if(str[i]=='?')
                            que--;
                        else
                        {
                            arr[str[i]-'A']=0;
                            count--;
                        }
                        i++;
                    }
                    //break;
                }
                else
                {
                    arr[str[j]-'A']=1;
                    j++;
                    count++;
                }
                if(count+que==26)
                    break;
            }
        }
            if(count+que==26)
            {
                l=0;
                res=1;
                for(k=i;k<=j;k++)
                {
                    if(str[k]=='?')
                    {
                        for(;l<26;l++)
                        {
                            if(arr[l]==0)
                            {
                                str[k]=l+'A';
                                l++;
                                break;
                            }
                        }
                    }
                }
            }
        for(j=0;j<strlen(str);j++)
        {
            if(str[j]=='?')
                str[j]='A';
        }
    if(res)
        printf("%s",str);
    else
        printf("-1\n");
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void test(char* str)
{
	for(int i=0;i<26;i++)
	{
		if(str[i]=='\0')
		{
			printf("-1");
			exit(0);
		}
		for(int j=0;j<i;j++)
		{
			if(str[j]==str[i]&&str[i]!='?')
			{
				test(str+j);
				return ;
			}
		}
	}
	int a[26]={0};
	for(int i=0;i<26;i++)
	{
		if(str[i]!='?')
		{
			a[str[i]-'A']=1;
		}
	}
	for(int i=0;i<26;i++)
	{
		if(str[i]=='?')
		{
			for(int j=0;j<26;j++)
			{
				if(a[j]==0)
				{
					a[j]=1;
					str[i]=j+'A';
					break;
				}
			}
		}
	}
}
int main(void)
{
	char str[50001];
	gets(str);
	test(str);
	for(char* p=str;*p;p++)
	{
		if(*p=='?')
		{
			putchar('A');
		}
		else
			putchar(*p);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    long int n,que=0,count=0,i=0,j=0,p,res=0,k,l;
    char str[50010];
    scanf("%s",&str);
        long int arr[27]={0};
        for(i=0,j=0;j<strlen(str);)
        {
            if(str[j]=='?')
            {
                que++;
                j++;
            }
            else
            {
                if(arr[str[j]-'A'])
                {
                    while(i<j)
                    {
                        if(str[i]==arr[str[j]-'A']+'A')
                        {
                            i++;
                            break;
                        }
                        if(arr[i]=='?')
                            que--;
                        else
                        {
                            arr[str[i]-'A']=0;
                            count--;
                        }
                        i++;
                    }
                    //break;
                }
                else
                {
                    arr[str[j]-'A']=1;
                    j++;
                    count++;
                }
                if(count+que==26)
                    break;
            }
        }
            if(count+que==26)
            {
                l=0;
                res=1;
                for(k=i;k<=j;k++)
                {
                    if(str[k]=='?')
                    {
                        for(;l<26;l++)
                        {
                            if(arr[l]==0)
                            {
                                str[k]=l+'A';
                                l++;
                                break;
                            }
                        }
                    }
                }
            }
        for(j=0;j<strlen(str);j++)
        {
            if(str[j]=='?')
                str[j]='A';
        }
    if(res)
        printf("%s",str);
    else
        printf("-1\n");
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    long int n,que=0,count=0,i=0,j=0,p,res=0,k,l;
    char str[50010];
    scanf("%s",&str);
        long int arr[27]={0};
        for(i=0,j=0;j<strlen(str);)
        {
            if(count+que==26)
                    break;
            if(str[j]=='?')
            {
                que++;
                j++;
            }
            else
            {
                if(arr[str[j]-'A'])
                {
                    while(i<j)
                    {
                        if(str[i]==[str[j])
                        {
                            i++;
                            break;
                        }
                        if(str[i]=='?')
                            que--;
                        else
                        {
                            arr[str[i]-'A']=0;
                            count--;
                        }
                        i++;
                    }
                    j++;
                }
                else
                {
                    arr[str[j]-'A']=1;
                    j++;
                    count++;
                }
            }
        }
        printf("%ld %ld\n",i,j);
            if(count+que==26)
            {
                l=0;
                res=1;
                for(k=i;k<=j;k++)
                {
                    if(str[k]=='?')
                    {
                        for(;l<26;l++)
                        {
                            if(arr[l]==0)
                            {
                                str[k]=l+'A';
                                l++;
                                break;
                            }
                        }
                    }
                }
            }
        for(j=0;j<strlen(str);j++)
        {
            if(str[j]=='?')
                str[j]='A';
        }
    if(res)
        printf("%s",str);
    else
        printf("-1\n");
    return 0;
}


#include<stdio.h>

int tab[110];
int abs(int a){
	int b;
	(a>0) ? b=a : b=-a;
	return b;
}
int main(){
	int n,k,presum=0,sum=0,des,max=0;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",tab+i);
	}
	for(int i=0;i<n;i++){
		presum+=tab[i];
	}
	for(int i=0;i<k;i++){
		for(int j=0;i+j*k<n;j++){
			sum+=tab[i+j*k];
		}
		des=presum-sum;
		if(max<abs(des))	max=abs(des);
		sum=0;
	}
	printf("%d",max);
}


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


#include <iostream>

using namespace std;

int main (void)
{
    int n, k;

    cin>>n>>k;

    int a[n];

    for(int i = 0; i < n; i++)
        cin>>a[i];

    int max = 0;

    for(int b = 0; b < k; b++){
            int infor = 0;
            int social = 0;
        for(int i = 0; i < n; i++){
            if((i-b)%k!=0){
                if(a[i] == -1)
                    social++;
                else
                    infor++;
            }
        }
        if(max<fabs(infor-social))
            max = fabs(infor-social);
    }
    cout<<max<<endl;
    return 0;
}


<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>15.0</VCProjectVersion>
    <ProjectGuid>{7C2D7A28-1431-4F1D-BD6D-B1DA49A551D4}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>ARomanandBrowser</RootNamespace>
    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <SubSystem>Console</SubSystem>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <SubSystem>Console</SubSystem>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <SubSystem>Console</SubSystem>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <SubSystem>Console</SubSystem>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="소스.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>


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

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


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int ar, al, br, bl;
	ar = 0;
	al = 0;
	br = 0;
	bl = 0
	scanf("%d%d",&ar, &al);
	scanf("%d%d",&br, &bl);
	if( (abs(ar - bl) < 3) || (abs(al - br) < 3) )
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}


#include<stdio.h>

int main()
{
    int b_r, b_l, g_r, g_l;

    scanf("%d %d %d %d", &g_r, &g_l, &b_r, &b_l);

    int tot1=abs(b_r - g_l);
    int tot2=abs(b_l - g_r);

    if(g_l-b_r<2 || b_r>g_l) && ((b_l / 3<=g_r)))
        printf("YES\n");

    else if((g_r-b_l<2 || b_l>g_r) && ((b_r / 3<= g_l)))
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 7

int mano_venus(char* venusString);
int mano_marte(char* marteString);
void comfortable(int venusiana, int marciano);

int main(int argc, char const *argv[])
{
    char venus[MAX], marte[MAX];
    int hand_venus, hand_mars;

    gets(venus);
    gets(marte);

    hand_venus = mano_venus(venus);
    hand_mars = mano_marte(marte);

    //if (hand_venus != -1 && hand_mars != -1)
    //{
       comfortable(hand_venus, hand_mars);
    //}

    return 0;
}

void comfortable(int venusiana, int marciano)
{
    if ((venusiana - marciano) == 0 || abs(venusiana - marciano) == 1)
    {
        printf("YES");
    }else{
        printf("NO");
    }
}

int mano_venus(char* venusString)
{
    char auxVenus[MAX];
    strcpy(auxVenus, venusString);

    char* manoVenusIzq = strtok(venusString, " ");
    char* manoVenusDer = strtok(NULL, " ");

    if (atoi(manoVenusIzq) > 0 && atoi(manoVenusIzq) <= 100)
    {
        if (atoi(manoVenusDer) > 0 && atoi(manoVenusDer) <= 100)
        {
            return atoi(manoVenusIzq);
        }
    }

    return -1;
}

int mano_marte(char* marteString)
{
    char* manoMarteIzq = strtok(marteString, " ");
    char* manoMarteDer = strtok(NULL, " ");

    if (atoi(manoMarteIzq) > 0 && atoi(manoMarteIzq) < 100)
    {
        if (atoi(manoMarteDer) > 0 && atoi(manoMarteDer) < 100)
        {
            return atoi(manoMarteDer);
        }
    }

    return -1;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
#define LL long long
uLL exgcd64(uLL a,uLL b,uLL *x,uLL *y)
{
	static uLL gcd;
	if (a==0)
	{
		*x=0;*y=1;
		return b;
	}
	else
	{
		gcd=exgcd64(b%a,a,y,x);
		*x-=(b/a)*(*y)+b;
		*y+=a;
		return gcd;
	}
}
int main()
{
	//freopen("in.in","r",stdin);
	LL i,j,k,n,m,a,b,c,d,x,y,vx,vy;
	scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x,&y,&vx,&vy);
	if ((vx==0)||(vy==0))
	{
		if (vx==0)
		{
			if ((x==0)||(x==n))
			{
				if (vy<0) {printf("%lld 0\n",x);}
				else {printf("%lld %lld\n",x,m);}
			}
			else
			{
				printf("-1\n");
			}
		}
		if (vy==0)
		{
			if ((y==0)||(y==m))
			{
				if (vx<0) {printf("0 %lld\n",y);}
				else {printf("%lld %lld\n",n,y);}
			}
			else
			{
				printf("-1\n");
			}
		}
	}
	else
	{
		if (vx<0)
		{
			x=n-x;
		}
		if (vy<0)
		{
			y=m-y;
		}
		c=exgcd64(m,n,&a,&b);
		d=x-y;
		if (d<0) {d=(d%m+m)%m;}
		if (d%c!=0) {printf("-1\n");}
		else
		{
			c=(d/c)*b;
			if (c==0) {c+=m;}
			d=(c*n-(x-y))/m;
			//printf("%lld %lld %lld %lld\n",d,c,a,b);
			c=c&1;d=d&1;
			if (vx<0) {c=c^1;}
			if (vy<0) {d=d^1;}
			c=c*n;d=d*m;
			printf("%lld %lld\n",c,d);
		}
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
#define LL long long
uLL exgcd64(uLL a,uLL b,uLL *x,uLL *y)
{
	static uLL gcd;
	if (a==0)
	{
		*x=0;*y=1;
		return b;
	}
	else
	{
		gcd=exgcd64(b%a,a,y,x);
		*x-=(b/a)*(*y)+b;
		*y+=a;
		return gcd;
	}
}
int main()
{
	freopen("in.in","r",stdin);
	LL i,j,k,n,m,a,b,c,d,x,y,vx,vy;
	scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x,&y,&vx,&vy);
	if ((vx==0)||(vy==0))
	{
		if (vx==0)
		{
			if ((x==0)||(x==n))
			{
				if (vy<0) {printf("%lld 0\n",x);}
				else {printf("%lld %lld\n",x,m);}
			}
			else
			{
				printf("-1\n");
			}
		}
		if (vy==0)
		{
			if ((y==0)||(y==m))
			{
				if (vx<0) {printf("0 %lld\n",y);}
				else {printf("%lld %lld\n",n,y);}
			}
			else
			{
				printf("-1\n");
			}
		}
	}
	else
	{
		if (vx<0)
		{
			x=n-x;
		}
		if (vy<0)
		{
			y=m-y;
		}
		//printf("%lld %lld %lld %lld\n",n,m,x,y);
		c=exgcd64(m,n,&a,&b);
		d=x-y;
		if (d<0) {d=(d%m+m)%m;}
		if (d%c!=0) {printf("-1\n");}
		else
		{
			d=(d/c)*(b/c)%(m/c);
			if (d==0) {d+=m/c;}
			c=d;
			d=(c*n-(x-y))/m;
			//printf("%lld %lld %lld %lld\n",c,d,n,m);
			c=c&1;d=d&1;
			if (vx<0) {c=c^1;}
			if (vy<0) {d=d^1;}
			c=c*n;d=d*m;
			printf("%lld %lld\n",c,d);
		}
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
#define LL long long
uLL exgcd64(uLL a,uLL b,uLL *x,uLL *y)
{
	static uLL gcd;
	if (a==0)
	{
		*x=0;*y=1;
		return b;
	}
	else
	{
		gcd=exgcd64(b%a,a,y,x);
		*x-=(b/a)*(*y)+b;
		*y+=a;
		return gcd;
	}
}
int main()
{
	freopen("in.in","r",stdin);
	LL i,j,k,n,m,a,b,c,d,x,y,vx,vy;
	scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x,&y,&vx,&vy);
	if ((vx==0)||(vy==0))
	{
		if (vx==0)
		{
			if ((x==0)||(x==n))
			{
				if (vy<0) {printf("%lld 0\n",x);}
				else {printf("%lld %lld\n",x,m);}
			}
			else
			{
				printf("-1\n");
			}
		}
		if (vy==0)
		{
			if ((y==0)||(y==m))
			{
				if (vx<0) {printf("0 %lld\n",y);}
				else {printf("%lld %lld\n",n,y);}
			}
			else
			{
				printf("-1\n");
			}
		}
	}
	else
	{
		if (vx<0)
		{
			x=n-x;
		}
		if (vy<0)
		{
			y=m-y;
		}
		//printf("%lld %lld %lld %lld\n",n,m,x,y);
		c=exgcd64(m,n,&a,&b);
		d=x-y;
		if (d<0) {d=(d%m+m)%m;}
		if (d%c!=0) {printf("-1\n");}
		else
		{
			c=(d/c)*(b/c)%m/c;
			if (c==0) {c+=m;}
			d=(c*n-(x-y))/m;
			//printf("%lld %lld %lld %lld\n",c,d,n,m);
			c=c&1;d=d&1;
			if (vx<0) {c=c^1;}
			if (vy<0) {d=d^1;}
			c=c*n;d=d*m;
			printf("%lld %lld\n",c,d);
		}
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
#define LL long long
uLL exgcd64(uLL a,uLL b,uLL *x,uLL *y)
{
	static uLL gcd;
	if (a==0)
	{
		*x=0;*y=1;
		return b;
	}
	else
	{
		gcd=exgcd64(b%a,a,y,x);
		*x-=(b/a)*(*y)+b;
		*y+=a;
		return gcd;
	}
}
int main()
{
//	freopen("in.in","r",stdin);
	LL i,j,k,n,m,a,b,c,d,x,y,vx,vy,e;
	scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x,&y,&vx,&vy);
	if ((vx==0)||(vy==0))
	{
		if (vx==0)
		{
			if ((x==0)||(x==n))
			{
				if (vy<0) {printf("%lld 0\n",x);}
				else {printf("%lld %lld\n",x,m);}
			}
			else
			{
				printf("-1\n");
			}
		}
		if (vy==0)
		{
			if ((y==0)||(y==m))
			{
				if (vx<0) {printf("0 %lld\n",y);}
				else {printf("%lld %lld\n",n,y);}
			}
			else
			{
				printf("-1\n");
			}
		}
	}
	else
	{
		if (vx<0)
		{
			x=n-x;
		}
		if (vy<0)
		{
			y=m-y;
		}
		//printf("%lld %lld %lld %lld\n",n,m,x,y);
		c=exgcd64(m,n,&a,&b);
		e=c;
		d=x-y;
		if (d<0) {d=(d%m+m)%m;}
		if (d%c!=0) {printf("-1\n");}
		else
		{
			//printf("%lld %lld %lld\n",b%c,d,((d/c)*(b/1)%(m/c)*n)%m);
			d=(d/c)*(b)%(m/c);
			if (d==0) {d+=m/c;}
			c=d;
			d=(c*n-(x-y))/m;
/*			if (d<0)
			{
				a=(-d)/c+1;
				c+=a*(m/e);
				d+=a*(n/e);
			}*/
			//printf("%lld %lld %lld %lld\n",c,d*m,(c*n-(x-y))%m,x-y);
			c=c&1;d=d&1;
			if (vx<0) {c=c^1;}
			if (vy<0) {d=d^1;}
			c=c*n;d=d*m;
			printf("%lld %lld\n",c,d);
		}
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
#define LL long long
uLL exgcd64(uLL a,uLL b,uLL *x,uLL *y)
{
	static uLL gcd;
	if (a==0)
	{
		*x=0;*y=1;
		return b;
	}
	else
	{
		gcd=exgcd64(b%a,a,y,x);
		*x-=(b/a)*(*y)+b;
		*y+=a;
		return gcd;
	}
}
int main()
{
//	freopen("in.in","r",stdin);
	LL i,j,k,n,m,a,b,c,d,x,y,vx,vy,e;
	scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x,&y,&vx,&vy);
	if ((vx==0)||(vy==0))
	{
		if (vx==0)
		{
			if ((x==0)||(x==n))
			{
				if (vy<0) {printf("%lld 0\n",x);}
				else {printf("%lld %lld\n",x,m);}
			}
			else
			{
				printf("-1\n");
			}
		}
		if (vy==0)
		{
			if ((y==0)||(y==m))
			{
				if (vx<0) {printf("0 %lld\n",y);}
				else {printf("%lld %lld\n",n,y);}
			}
			else
			{
				printf("-1\n");
			}
		}
	}
	else
	{
		if (vx<0)
		{
			x=n-x;
		}
		if (vy<0)
		{
			y=m-y;
		}
		//printf("%lld %lld %lld %lld\n",n,m,x,y);
		c=exgcd64(m,n,&a,&b);
		e=c;
		d=x-y;
		if (d<0) {d=(d%m+m)%m;}
		if (d%c!=0) {printf("-1\n");}
		else
		{
			//printf("%lld %lld %lld\n",b%c,d,((d/c)*(b/1)%(m/c)*n)%m);
			d=(d/c)*(b)%(m/c);
			if (d==0) {d+=m/c;}
			c=d;
			d=(c*n-(x-y))/m;
			if (d<0)
			{
				a=(-d)/c+1;
				c+=a*(m/e);
				d+=a*(n/e);
			}
			//printf("%lld %lld %lld %lld\n",c,d*m,(c*n-(x-y))%m,x-y);
			c=c&1;d=d&1;
			if (vx<0) {c=c^1;}
			if (vy<0) {d=d^1;}
			c=c*n;d=d*m;
			printf("%lld %lld\n",c,d);
		}
	}
	return 0;
}


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

    if(a>b)
     {t=a;
     a=b;
     b=t;}

   if(b>c)
   { t=b;
      b=c;
      c=t;}
   if(a>b)
   {  t=a;
      a=b;
      b=t;
      }

   if(a==0&&b==0)
    printf("0");
    else
    {  if((b-a)%2==0)
      printf("%I64d",b);
      else
      printf("%I64d",c);
      }
      return 0;
}


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

long long int bSearch(long long n,long long int e)  {
	long long int m = n ;
	int a = 0;
	while(m){
		a++;
		m /= 2;
	}
    long long mid, left = 1, right = (long long) (pow(2.0,a)-1);
    long long num = 0;
    while(left <= right)  {
        mid = (left + right) >> 1;
        if(mid >= e)
        	right = mid - 1;
        else {
        	num += n / 2 + n % 2;
        	left = mid + 1;
        }
        n /= 2;
    }
    return num;
}

int main(){
	long long n , l , r ;
	while(scanf("%lld%lld%lld",&n,&l,&r)!=EOF){
		long long sum;
		sum = bSearch(n,r+1)-bSearch(n,l) ;
		printf("%lld\n",sum);
	}
	return 0;
}


#include<stdio.h>
#define MAXN 100010
long long a[MAXN],b[MAXN];
int sign,flag;
int main(){
	void crash(long long a[],long long b[]);
	long long n;
	int r,l;
	int i,count；
	for(i=0;i<MAXN;i++){
		a[i]=-1;
		b[i]=-1;
	}
	scanf("%lld %d %d",&n,&r,&l);
	a[0]=n/2
	a[1]=n%2;
	a[2]=n/2;
	crash(a,b);
	count=0;
	if(sign>0){
		for(i=r-1;i<=l-1;i++){
			if(a[i]==1){
				count++;
			}
		}
    }
	else{
		for(i=r-1;i<=l-1;i++){
			if(b[i]==1){
				count++;
			}
		}
	}
	printf("%d",count);
	return 0;
}

void crash(long long a[],long long b[]){
	sign=1,flag=0;
	int i,quo,mod,count;
	for(i=0,count=0;a[i]!=-1;i++){
		if(a[i]!=1&&a[i]!=0){
			quo=a[i]/2;
			mod=a[i]%2;
			b[count]=quo;
			b[count+1]=mod;
			b[count+2]=quo;
			count=count+3;
			flag=1;
		}
		else{
			b[count]=a[i];
			count++;
		}
	}
	sign=sign*(-1);
	if(flag==1){
		crash(b,a);
	}
}


#include <cstdio>

typedef long long ll;

ll solve(ll n, ll l, ll r, ll x, ll y) {
    if (r < x || l > y || n == 0) return 0;
    if (n == 1) return 1;
    ll mid = (x + y) / 2;
    return solve(n / 2, l, r, x, mid - 1) + solve(n % 2, l, r, mid, mid) + solve(n / 2, l, r, mid + 1, y);
}

int main() {
    ll n, l, r;
    ll ans;
    scanf("%lld %lld %lld", &n, &l, &r);
    ll max = 1; while (max <= n) { max *= 2; }
    ans = solve(n, l, r, 1, max);
    printf("%lld\n", ans);
    return 0;
}


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

long long int bSearch(long long n,long long int e)  {
	long long int m = n ;
	int a = 0;
	while(m){
		a++;
		m /= 2;
	}
    long long mid, left = 1, right = (int) (pow(2.0,a)-1);
    long long num = 0;
    while(left <= right)  {
        mid = (left + right) >> 1;
        if(mid >= e)
        	right = mid - 1;
        else {
        	num += n / 2 + n % 2;
        	left = mid + 1;
        }
        n /= 2;
    }
    return num;
}

int main(){
	long long n , l , r ;
	while(scanf("%lld%lld%lld",&n,&l,&r)!=EOF){
		long long sum;
		long long a;
		sum = bSearch(n,r+1)-bSearch(n,l) ;
		printf("%lld\n",sum);
	}
	return 0;
}


#include <iostream>

using namespace std;
typedef __int64 ll;

//L,R是查询区间，l,r是计算出的分解以后的长度
ll query(ll L ,ll R,ll l,ll r, ll n)
{
      if(l == r)
      return n;

      //分治
      ll mid = (l+r)>>1;
      ll ans = 0;

      //在左侧进行递归
      if(L <= mid - 1)
            ans += query(L,R,l,mid - 1,n>>1);
      //在右侧进行递归查找
      if(R >= mid + 1)
            ans += query(L,R,mid + 1,r,n>>1);
      //这个时候对mid进行处理，判断条件是mid在查询范围区间内
      if(mid <= R && mid >= L)
            ans += n%2;

      return ans;
}

//该函数是用来求分解n以后的位数
//也可以看出一个规律，某个数的展开以后的位数是刚好大于二次幂的值减去1，比如3的展开为4-1，4的展开为8-1
ll f(ll n)
{
      if(n == 1 || n == 0)
            return 1;
      return 2 * f(n >> 1) + 1;
}

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

    cin >> n >> l >> r;

    cout << query(l,r,1,f(n),n) << endl;

    return 0;
}


#include "stdio.h"
int number[100000000];
int main()
{
    int n,k;
    while(scanf("%d",&n)!=EOF)
    {
        int sum = 0;
        int num = 0;
        for(int i = n/2;i<n;i++)
        {
            sum += i;
            int count =0;
            int a = i;
            while(a!=0)
            {
               count++;
               a /= 10;
            }
            int max = 1;
            for(int j = 0;j<count;j++)
            {
                max *= 10;
            }
            int b = i;
            while(max!=0)
            {
                sum += b/max;
                b = b%max;
                max /= 10;
            }
            if (sum==n)
            {
                num++;
                number[num] = i;
            }
        }
        printf("%d\n",num);
        for(int i = 0;i<num;i++)
        {
            printf("%d\n",number[i]);
        }
    }


#include "stdio.h"

int main()
{
    int n,k;
    int number[1000000000];
    while(scanf("%d",&n)!=EOF)
    {
        int sum = 0;
        int num = 0;
        for(int i = 10;i<n;i++)
        {
            sum += i;
            int count =0;
            int a = i;
            while(a!=0)
            {
               count++;
               a /= 10;
            }
            int max = 1;
            for(int j = 0;j<count;j++)
            {
                max *= 10;
            }
            int b = i;
            while(max!=0)
            {
                sum += b/max;
                b = b%max;
                max /= 10;
            }
            if (sum==n)
            {
                num++;
                number[num] = i;
            }
        }
        printf("%d\n",num);
        for(int i = 0;i<num;i++)
        {
            printf("%d\n",number[i]);
        }
    }


#include "stdio.h"
int number[1000000000];
int main()
{
    int n,k;
    while(scanf("%d",&n)!=EOF)
    {
        int sum = 0;
        int num = 0;
        for(int i = 10;i<n;i++)
        {
            sum += i;
            int count =0;
            int a = i;
            while(a!=0)
            {
               count++;
               a /= 10;
            }
            int max = 1;
            for(int j = 0;j<count;j++)
            {
                max *= 10;
            }
            int b = i;
            while(max!=0)
            {
                sum += b/max;
                b = b%max;
                max /= 10;
            }
            if (sum==n)
            {
                num++;
                number[num] = i;
            }
        }
        printf("%d\n",num);
        for(int i = 0;i<num;i++)
        {
            printf("%d\n",number[i]);
        }
    }


#include<stdio.h>
int main()
{ int n,k=0,d,j,s,i;
int *t;
scanf("%d",&n);
int t[n];
for(i=1;i<n;i++)
{s=i;
d=i;
do
{s=s+(d%10);
d=d/10; }
while(d!=0);
if(s==n)
{t[k]=i;
k++;}}
printf("%d",k);
printf("\n");
for(j=0;j<k;j++)
printf("%d ",t[j]);
return 0;}


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

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


#include <stdio.h>
int dp[1<<24];
void solve(const int n, const int x, const int y) {
    dp[1] = x;
    for(int i = 1; i <= n; i++)
        if(i & 1) dp[i] = dp[i - 1] + x;
        else dp[i] = dp[i >> 1] + y < dp[i - 1] + x ? dp[i >> 1 + y] : dp[i - 1] + x;
    return dp[n];
}

int main(void) {
    int n, x, y;
    scanf("%d%d%d", &n, &x, &y);
    printf("%d", solve(n, x, y));
    return 0;
}


#include <stdio.h>
int dp[1<<24];

void solve(int n, int x, int y) {
    dp[1] = x;
    for(int i = 1; i <= n; i++)
        if(i & 1) dp[i] = dp[i - 1] + x;
        else dp[i] = min(dp[i >> 1] + y, dp[i - 1] + x);
    return dp[n];
}

int main(void) {
    int n, x, y;
    scanf("%d%d%d", &n, &x, &y);
    printf("%d", solve(n, x, y));
    return 0;
}


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

//////////////////////////////////////////
//    ˼·��                            //
//          ������                      //
//    by :                              //
//         ˧����                       //
//////////////////////////////////////////

double final(double n,double a,double b) {
	double t;     //��ʱ��
	double t0;    //��kg+1��·�����ĵ�ʱ��   ��·һ
	double t1;    //��kg-1��·�����ĵ�ʱ��   ��·��
	int tk = 0;   //��kg+1��·���³��� 2 �Ĵ���
	int tk2 = 0;  //��kg+1��·���¼Ӽ� 1 �Ĵ���
	int dk = 0;   //��kg-1��·���³��� 2 �Ĵ���
	int dk2 = 0;  //��kg-1��·���¼Ӽ� 1 �Ĵ���
	long kg = n;  //��ֹ n ֵ���ı�
	long hg2 = 0; // kg �����Ʒ����������·һ������� hg ֵ�ĸı�
	long hg =0;   // kg �����Ʒ����ֹ kg ֵ�ĸı�
	int tag = 0;  // ��ǰ kg �ǲ��������ı�ʶ ������kg == 1��  ż����kg == 0��
	int tag2 = 0; // ��ǰ hg �ǲ��������ı�ʶ ������hg == 1��  ż����hg == 0��
	int k1 = 0;   // ���ڼ�¼������·�� 2 �Ĵ���
	int k2 = 0;   // ���ڼ�¼������·�Ӽ� 1 �Ĵ���
	for(; kg >= 2; k1++) {
		if(kg%2 != 0) {
			tag = 1;
			if(tag == 1 && (kg-kg/2-1)*a < b) //Ч�ʶԱȾ���Ҫ��Ҫ����
				break;
			hg2 = kg;
			hg = (kg+1)/2;                    //��������·һ���õ�һ��ʱ��
			for(;hg>=2;tk++){
				if(hg%2 != 0)
					tag2 = 1;
				if(tag2 == 1 && (hg-hg/2-1)*a < b)  //Ч�ʶԱȾ���Ҫ��Ҫ����ѭ��
					break;
				if(tag2 == 0 && (hg-hg/2)*a < b)    //Ч�ʶԱȾ���Ҫ��Ҫ����ѭ��
					break;
				if(hg%2 != 0)
					tk2++;
				hg = hg/2;
				tag2 = 0;
			}
			t0 = b*tk + a*hg + a*tk2;         //��һ��ʱ��
			tag2 = 0;
			hg = (hg2-1)/2;                   //������·�����õ��ڶ���ʱ��
			for(;hg>=2;dk++){
				if(hg%2 != 0)
					tag2 = 1;
				if(tag2 == 1 && (hg-hg/2-1)*a < b)  //Ч�ʶԱȾ���Ҫ��Ҫ����ѭ��
					break;
				if(tag2 == 0 && (hg-hg/2)*a < b)    //Ч�ʶԱȾ���Ҫ��Ҫ����ѭ��
					break;
				if(hg%2 != 0)
					dk2++;
				hg = hg/2;
				tag2 = 0;                     // tk dk tag ϵ�в���ÿ��ѭ����������
			}
			t1 = b*dk + a*hg + a*dk2;         //�ڶ���ʱ��
			if(t0 <= t1)
				kg+=1;                        //��������·һ
			else
				kg-=1;                        //��������·��
			}
			tk = tk2 = dk = dk2 = hg2 = 0;    // tk dk tag ϵ�в���ÿ��ѭ����������
		}
		if(tag == 1) {
			k2++;
		}
		if((kg-kg/2)*a <= b)                  //Ч�ʶԱȾ���Ҫ��Ҫ����ѭ��
			break;
		kg = kg/2;
		tag = 0;
	}
	t = b*k1 + k2*a + kg*a;                   //�õ�����ȷ������ʱ��
	return t;
}

int main() {
	long n,a,b;                               //ʹ�� long double ������Ϊ�˷�ֹ���
	scanf("%d%d%d",&n,&a,&b);
	printf("%.0f\n",final(n,a,b));
	return 0;
}


/*
 * 710E
 */

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

#define DIJKSTRA
#ifndef _TJYTLXWXHYZQFW_HEAP_H
#define _TJYTLXWXHYZQFW_HEAP_H

#include <assert.h>
#include <stdlib.h>

/** 优先队列结构 */
struct heap {
	/**
	 * cap - 优先队列的容量
	 * last - 优先队列中最后一个元素的下标
	 */
        int cap, last;

	/* 指针数组,指向优先队列中的元素 */
        void **cell;

	/* 比较函数,用于比较队列元素的大小 */
	int (*cmp)(const void *, const void *);

	#ifdef DIJKSTRA
	/* 设置一个元素在cell中的下标 */
	void (*set)(void *, const int);
	/* 交换两个元素在cell中的下标 */
	void (*swap)(void *, void *);
	#endif
};

/**
 * 创建优先队列
 *
 * @param cap - 优先队列的容量,也是cell数组可用下标的最大值
 * @param cmp - 优先队列中元素的比较方法
 * @return - 指向优先队列结构的指针
 */
struct heap *heap_new(int cap, int (*cmp)(const void *, const void*)
	#ifdef DIJKSTRA
	,void (*set)(void *, const int), void (*swap)(void *, void *)
	#endif
)
{
        struct heap *h;

        assert(h = malloc(sizeof(struct heap)));
	/* 由于cell[0]不存放元素,故实际分配的元素是(cap + 1)个 */
        h->cap = ++cap;
	/* linux会替你掩饰你犯下的**忘掉初始化**的错误, OJ不会 */
	h->last = 0;
        assert(h->cell = malloc(sizeof(void*) * cap));
	/* comparison function */
	h->cmp = cmp;

	#ifdef DIJKSTRA
	h->set = set;
	h->swap = swap;
	#endif

        return h;
}

/**
 * 释放优先队列
 *
 * @param h - 要被摧毁的队列
 *
 * 这个过程不会摧毁队列元素,因为队列本身对
 * 存储于其中的元素一无所知
 */
void heap_destroy(struct heap *h)
{
        if (h)
                free(h->cell);
        free(h);
}

/**
 * 下滤
 *
 * @param x - 要被下滤的元素的下标
 * @param h - 指向优先队列的指针
 *
 *
如果x的两棵子树是优先队列,那么下滤结束后,以x为根的树是优先队列

 *
在最大堆中突然增大的元素或者在最小堆中突然变小的元素需要被下滤

 */
void heap_pdown(int x, struct heap *h)
{
        int c, d;
        void *tmp;

        while ((c = 2 * x) <= h->last) {
                d = c + 1;
                if (d <= h->last && h->cmp(h->cell[d], h->cell[c]) < 0)
                        c = d;
                if (h->cmp(h->cell[x], h->cell[c]) < 0)
                        break;

                tmp = h->cell[c];
                h->cell[c] = h->cell[x];
                h->cell[x] = tmp;
		#ifdef DIJKSTRA
		h->swap(h->cell[c], h->cell[x]);
		#endif

                x = c;
        }
}

/**
 * 上滤
 *
 * @param x - 要被上滤的元素的下标
 * @param h - 指向优先队列的指针
 */
void heap_pup(int x, struct heap *h)
{
        int p;
        void *tmp;

        while ((p = x / 2) >= 1) {
                if (h->cmp(h->cell[p], h->cell[x]) < 0)
                        break;

                tmp = h->cell[x];
                h->cell[x] = h->cell[p];
                h->cell[p] = tmp;
		#ifdef DIJKSTRA
		h->swap(h->cell[x], h->cell[p]);
		#endif

                x = p;
        }
}

/**
 * 插入
 *
 * @param e - 指向被插入元素的指针
 * @param h - 指向优先队列的指针
 * @return 插入结果: 0 - 成功, -1 - 失败
 */
int heap_insert(void *e, struct heap *h)
{
        if (h->last >= h->cap)
                return -1;

        h->cell[++h->last] = e;
	#ifdef DIJKSTRA
	h->set(h->cell[h->last], h->last);
	#endif
        heap_pup(h->last, h);

        return 0;
}

/**
 * 删除最大/最小元
 *
 * @param h - 指向优先队列的指针
 * @return - 指向被删除的元素的指针; NULL - 队列为空
 */
void *heap_del(struct heap *h)
{
        void *ret;

        if (h->last <= 0)
                return NULL;

        ret = h->cell[1];
        h->cell[1] = h->cell[h->last--];
	#ifdef DIJKSTRA
	h->set(h->cell[1], 1);
	#endif
        heap_pdown(1, h);
        return ret;
}

#endif

#define LEN 10000001

struct node {
	long long cost;
	char color;
	int id;
	int hidx;
};

int compare(const void *x, const void *y)
{
	/* 用了long long简直到处是陷阱 */
	return ((struct node *)x)->cost - ((struct node *)y)->cost < 0 ? -1 : 1;
}

void sethidx(void *node, const int idx)
{
	((struct node *)node)->hidx = idx;
}

void swaphidx(void *x, void *y)
{
	int tmp;

	tmp = ((struct node *)x)->hidx;
	((struct node *)x)->hidx = ((struct node *)y)->hidx;
	((struct node *)y)->hidx = tmp;
}

long long len;
#define OOS(x) ((x) < 0 || (x) > len)
long long x, y;
struct node nodes[LEN];

void handle(int id, long long cost, struct heap *h)
{
	struct node *next;

	if (id > len) {
		next = &nodes[len];
		cost += x * (id - len);
	} else if (id >= 0) {
		next = &nodes[id];
	} else {
		return;
	}

	if (next->color == 2)
		return;

	if (cost >= next->cost)
		return;

	next->cost = cost;
	if (next->color == 0) {
		heap_insert(next, h);
		next->color = 1;
	} else {
		heap_pup(next->hidx, h);
	}
}

long long dijkstra(void)
{
	struct heap *h;
	struct node *node;

	h = heap_new(len, compare, sethidx, swaphidx);
	heap_insert(&nodes[0], h);
	nodes[0].color = 1;
	nodes[0].cost = 0;

	while ((node = heap_del(h)) != NULL) {
		node->color = 2;
		if (node->id == len)
			return node->cost;

		handle(node->id + 1, node->cost + x, h);
		handle(node->id - 1, node->cost + x, h);
		handle(node->id * 2, node->cost + y, h);
	}

	/* impossible */
	return -1;
}

int main(void)
{
	long long i, imax;

	scanf("%lld%lld%lld", &len, &x, &y);

	for (imax = len * 2, i = 0; i <= imax; ++i) {
		nodes[i].id = i;
		nodes[i].cost = LLONG_MAX;
		nodes[i].color = 0;
	}

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

	return 0;
}


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

enum {
    L, R, N = 101
};

const int INF = 100100;

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

char cmd[N];
int n, len;
int d[N][N][55][2][2];

int sim(int left, int right) {
    int i, pos = 0, dx = 1;
    for(i = left; i <= right; i++) {
        if(cmd[i] == 'T')
            dx = -dx;
        else
            pos += dx;
    }
    return pos;
}

int rec(int left, int right, int nCmd, int dir, int isLow) {
    if(nCmd < 0)
        return INF;
    if(d[left][right][nCmd][dir][isLow] != -INF)
        return d[left][right][nCmd][dir][isLow];
    int *ret = &d[left][right][nCmd][dir][isLow];
    *ret = INF;
    if(left > right) {
        *ret = INF;
    }
    if(nCmd == 0) {
        *ret = sim(left, right);
    }
    if(left == right) {
        if((cmd[left] == 'T' && nCmd % 2 == 0) ||
                (cmd[left] == 'F' && nCmd % 2))
            *ret = 0;
        else
            *ret = 1;
    }
    if(*ret != INF)
        return *ret;
    int i, turns, nd, ni, nd2, ni2;
    for(i = left; i <= right; i++) {
      for(turns = 0; i != right && turns <= nCmd; turns++) {
        for(nd = L; nd <= R; nd++)
          for(ni = 0; ni < 2; ni++)
            for(nd2 = L; nd2 <= R; nd2++)
              for(ni2 = 0; ni2 < 2; ni2++) {
                  int val = rec(left, i, turns, nd, ni) +
                    rec(i + 1, right, nCmd - turns, nd2, ni2);
                  if(rec(left, i, turns, nd, ni) == INF ||
                          rec(i + 1, right, nCmd - turns, nd2, ni2) == INF)
                      continue;
                  if((isLow == 0 && dir == R) ||
                          isLow == 1 && dir == L)
                    *ret = max(*ret, val);
                  else
                    *ret = min(*ret, val);
              }
      }
      for(turns = 0; turns <= nCmd; turns++)
        for(nd = L; nd <= R; nd++)
          for(ni = 0; ni < 2; ni++)
            for(nd2 = L; nd2 <= R; nd2++)
              for(ni2 = 0; ni2 < 2; ni2++) {
                int ch;
                for(ch = 0; ch < 2; ch++) {
                  int val = rec(left, i - 1, turns - ch, nd, ni);
                  if(val == INF)
                      continue;
                  if(cmd[i] == 'F') {
                      val -=
                        rec(i + 1, right, nCmd - turns - (1 - ch), nd2, ni2);
                      if(rec(i + 1, right, nCmd - turns - (1 - ch), nd2, ni2) == INF)
                          continue;
                  }
                  else {
                      if(rec(i + 1, right, nCmd - turns - (1 - ch), nd2, ni2) == INF)
                          continue;
                      val += rec(i + 1, right, nCmd - turns - (1 - ch), nd2, ni2) + 1;
                  }
                  if(0 && val == 2 && left == 2 && right == 3)
                      printf("%d bord %d %d turns %d\n", val, i, ch, turns);
                  if((isLow == 0 && dir == R) ||
                          isLow == 1 && dir == L)
                    *ret = max(*ret, val);
                  else
                    *ret = min(*ret, val);
                }
              }

    }
    if(*ret == -INF)
        *ret = INF;
    if(0)
    printf("left %d; right %d; cmd %d; dir %d; low %d; -> %d\n",
            left, right, nCmd, dir, isLow, *ret);
    return *ret;
}

int main() {
    scanf("%s %d", cmd, &n);
    len = strlen(cmd);
    int ans = 0, i, j, k, r, e;
    for(i = 0; i < N; i++)
        for(j = 0; j < N; j++)
            for(k = 0; k < 55; k++)
                for(r = 0; r < 2; r++)
                    for(e = 0; e < 2; e++)
                        d[i][j][k][r][e] = -INF;
    for(i = n & 1; i <= n; i += 2) {
        ans = max(ans, -rec(0, len - 1, i, L, 0));
        if(rec(0, len - 1, i, R, 0) != INF)
            ans = max(ans, rec(0, len - 1, i, R, 0));
    }
    printf("%d\n", ans);
    return 0;
}


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

#define author int
#define sph_mp main()
#define fr(i, a, b) for((i) = (a) ; (i) < (b) ; (i)++)
#define frr(i, a, b) for((i) = (a) ; (i) >= (b) ; (i)--)

int l, r, x, y;
int a[1000], ai = 0;

// Function to print the divisors
void printDivisors(int n)
{
    // Note that this loop runs till square root
    int i;
    for (i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            // If divisors are equal, print only one
            if (n/i == i)
            	{
            		a[ai] = i;
            		ai++;
				}
//                printf("%d ", i);

            else // Otherwise print both
            	{
            		a[ai] = i;
            		a[ai+1] = n/i;
            		ai += 2;
				}
//                printf("%d %d ", i, n/i);
        }
    }
}

int valid(int x) {
	return l <= x && x <= r;
}

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

// Function to return LCM of two numbers
int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}

/* Driver program to test above function */
author sph_mp {
	scanf("%d %d %d %d", &l, &r, &x, &y);
	printDivisors(y);
	int res = 0;
	int i, j;
	fr(i, 0, ai)
		fr(j, 0, ai) {
			if(valid(a[i]) && valid(a[j])) {
				if(gcd(a[i], a[j]) == x && lcm(a[i], a[j]) == y)
					{
//						printf("%d %d\n", a[i], a[j]);
						res++;
					}
			}
		}
	printf("%d", res);
    return 0;
}


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

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

int main()
{
	int i;
	long long int l,r,x,y,pro,a,b;
	scanf("%lld%lld%lld%lld",&l,&r,&x,&y);

	a=x;
	b=x;
	y=y/x;
	pro = sqrt(y);
	int ans=0;
	for(i=1;i<=pro;i++)
	{
		if(y%i==0 && gcd(y/i,i)==1)
		{
			if(y/i==i)
			{
				if(x*i>=l && x*i<=r)
					ans++;
			}
			else
			{
				if((x*i>=l && x*i<=r )	&& (x*(y/i)>=l && x*(y/i)<=r))
					ans+=2;
			}
		}

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

	return 0;
}


#include<stdio.h>
int l,r,x,y;
int gcd(int p,int q){
	int r;
	while(q!=0){
		r=p%q;
		p=q;
		q=r;
	}
	return p;
}
void run(){
	int i,j,k,c;
	while(scanf("%d%d%d%d",&l,&r,&x,&y)!=EOF){
		if(y%x!=0){
			printf("0\n");
			continue;
		}
		j=y/x;
		c=0;
		for(i=1;i<100007&&i<=j;i++){
			if(j%i==0){
				k=j/i;
				if(k<i){
					break;
				}
				if(i*x>=l&&i*x<=r&&k*x>=l&&k*x<=r){
					if(gcd(i,k)==x){
						c+=i==k?1:2;
					}
				}
			}
		}
		printf("%d\n",c);
	}
}
main(){
#ifndef	ONLINE_JUDGE
	freopen("4892b_min.in","rb",stdin);
	freopen("4892b_.out","wb",stdout);
#endif
	run();
	return 0;
}


#include<stdio.h>       //r
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#define INF 0x3f3f3f
#define MAX 100100
#define LL long long
using namespace std;
int main()
{
    LL n,m,j,i;
    while(cin>>n!=EOF)
    {
        if(n&1)
            printf("1\n");
        else
            printf("2\n");
    }
    return 0;
}


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


include<stdio.h>
int main()
{
    long long n;
    scanf("%I64d",&n);
    if(n%2==0)printf("2");
    else printf("1");
}


#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n%2==0)
	 cout<<"2";
	else
	 cout<<"1";
	 return 0;
}


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


#include<stdio.h>
int main()
{
    char c='Z',d;int ans=0;
    while(scnaf("%c",&d)+1)
    if(d>c)c=d,ans=1;
    else ans++;
    while(ans--)cout<<c;
}


#include<stdio.h>
int main()
{
    char c='Z',d;int ans=0;
    while(scanf("%c",&d)+1)
    if(d>c)c=d,ans=1;
    else if(c==d) ans++;
    while(ans--)cout<<c;
}


#include<stdio.h>
int main()
{
    int h,w,c;
    scanf("%d %d",&h,&w);
    long long s1;
    s1 = h+w;
    for(i=1;i<=n;i++)
    s1 = (2*s1)%mod;
    printf("%I64d\n",s1);
}


#include<stdio.h>
#define mod 998244353
int main()
{
    int h,w,i;
    scanf("%d %d",&h,&w);
    long long p,p1,s3;
    p = 2;
    for(i=2;i<=h;i++)
    {
        p = ((p%mod)*(p%mod))%mod;
    }
    p1 = 2;
    for(i=2;i<=n;i++)
    {
        p1 = ((p1%mod)*(p1%mod))%mod;
    }
    s3 = ((p1%mod)*(p%mod))%mod;
    printf("%I64d\n",s3);
    return 0;
}


#include<stdio.h>
#define mod 998244353
int main()
{
    int h,w;
    scanf("%d %d",&h,&w);
    long long ans = ((1<<h)%mod)*(1<<w)%mod)%mod);
    printf("%I64d\n",ans);
    return 0;
}


import java.io.*;
import java.util.*;
import java.lang.Math;

public class CodeForces {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) throws IOException {
        int w = scanner.nextInt();
        int h = scanner.nextInt();
        long ans = (long) (4*Math.pow(2,w-1)*Math.pow(2,h-1))%998244353;
        scanner.close();
        System.out.println(ans);
    }
}


#include<stdio.h>
#define mod 998244353
int main()
{
    int h,w;
    scanf("%d %d",&h,&w);
    long long ans = (((1<<h)%mod)*(1<<w)%mod))%mod);
    printf("%I64d\n",ans);
    return 0;
}


#include <stdio.h>

long long f[60];
int i,j;
int n,k;
int p[60];

void dfs(int,int,long long);

int main()
{
    scanf("%d%d",&n,&k);
    f[0]=f[1]=1;
    for(i=2;i<=n;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    dfs(1,n,k);
    for(i=1;i<n;i++)
        printf("%d ",p[i]);
    printf("%d\n",p[i]);
    return 0;
}

void dfs(int i,int j,long long tmp)
{
    int k,w,ww;
    /*printf("%d %d %lld\n",i,j,tmp);*/
    if(i==n+1) return;
    for(k=1;k<=2 && k<=j;k++)
    {
        if(f[j-k]>=tmp)
        {
            w=i+k-1;
            ww=i+k-1;
            while(i<=ww)
            {
                p[i]=w;
                i++;
                w--;
            }
            dfs(i,j-k,tmp);
            return;
        }
        else tmp-=f[j-k];
    }
}


#include <stdio.h>

long long f[60];
int i,j;
int n,k;
int p[60];

void dfs(int,int,long long);

int main()
{
    scanf("%d%lld",&n,&k);
    f[0]=f[1]=1;
    for(i=2;i<=n;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    dfs(1,n,k);
    for(i=1;i<n;i++)
        printf("%d ",p[i]);
    printf("%d\n",p[i]);
    return 0;
}

void dfs(int i,int j,long long tmp)
{
    int k,w,ww;
    /*printf("%d %d %lld\n",i,j,tmp);*/
    if(i==n+1) return;
    for(k=1;k<=2 && k<=j;k++)
    {
        if(f[j-k]>=tmp)
        {
            w=i+k-1;
            ww=i+k-1;
            while(i<=ww)
            {
                p[i]=w;
                i++;
                w--;
            }
            dfs(i,j-k,tmp);
            return;
        }
        else tmp-=f[j-k];
    }
}


#include <stdio.h>

long long f[60];
int i,j;
int n,k;
int p[60];

void dfs(int,int,long long);

int main()
{
    scanf("%d%d",&n,&k);
    f[0]=f[1]=1;
    for(i=2;i<=n;i++)
    {
        f[i]=f[i-1]*2;
    }
    dfs(1,n,k);
    for(i=1;i<n;i++)
        printf("%d ",p[i]);
    printf("%d\n",p[i]);
    return 0;
}

void dfs(int i,int j,long long tmp)
{
    int k,w,ww;
    /*printf("%d %d %lld\n",i,j,tmp);*/
    if(i==n+1) return;
    for(k=1;k<=j;k++)
    {
        if(f[j-k]>=tmp)
        {
            w=i+k-1;
            ww=i+k-1;
            while(i<=ww)
            {
                p[i]=w;
                i++;
                w--;
            }
            dfs(i,j-k,tmp);
            return;
        }
        else tmp-=f[j-k];
    }
}


#include<stdio.h>
#include<stdlib.h>
int main(){
	int n,i;
	long long k,*left;
	scanf("%d %I64d",&n,&k);
	if(n<3){
		if(k==1){
			printf("1");
			if(n==1)
				printf("\n");
			else
				printf(" 2\n");
		}
		else
			printf("2 1\n");
		return 0;
	}
	left=(long long *)malloc(sizeof(long long)*n);
	left--;
	left[n]=-1;
	left[n-1]=0;
	left[n-2]=1;
	for(i=n-3;i>0;i--){
		left[i]=left[i+1]+left[i+3]+2;
	}
	k--;
	for(i=1;i<n;i++){
		if(k>left[i]){
			printf("%d %d ",i+1,i);
			k-=left[i]+1;
			i++;
		}
		else
			printf("%d ",i);
	}
	if(i==n)
		printf("%d ",n);
	printf("\n");
	return 0;
}


#include<stdio.h>
typedef long long unsigned llu;
typedef unsigned u;
void F(u n,llu l,u p)
{
	if(!n){printf("%u\n",p);return;}
	u i=1,j=n-1;
	while((1llu<<j)<l){l-=(1llu<<j--);++i;}
	for(j=i;j--;)printf("%u ",j+p);
	if(n>=i)F(n-i,l,p+i);
	return;
}
int main()
{
	u n;llu l;
	scanf("%u%I64u",&n,&l);
	F(n-1,l,1);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define MAX 107
#define MIN 1000007

int main()
{
	int x, n, i, a[MAX], j, ans = MIN;
	scanf("%d", &n);
	for(i=0;i<n;++i)
	{
		scanf("%d", &a[i]);
	}
	for(i=1;i<=n;++i)
	{
		x = 0;
		for(j=0;j<n;++j)
		{
			x += (abs(j + 1 - i) + j + abs(i - 1)) * 2 * a[j];
		}
		ans = ans > x ? x : ans;
	}
	printf("%d\n", ans);
	return 0;
}


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

    }
    for(i=0;i<n;i++)
    {
        j+=i*k[i];
    }
    printf("%d", j*4);
    return 0;

}


#include <cstdio>

int n;
int A[110];
int ab(int a){
    if(a<0)return -a;
    return a;
}
int main(){
   // freopen("input.txt","r",stdin);
    scanf("%d",&n);
    int i,x;
    for(i=1;i<=n;i++){
        scanf("%d",&A[i]);
    }
    int val=0,tv=0,mn=2147483647;
    for(x=1;x<=n;x++){
        tv=0;
        for(i=1;i<=n;i++){
            val=0;
            val+=ab(i-x)+i+x-2;
            val+=x+i-2+ab(x-i);
            tv+=(A[i]*val);
        }
        if(mn>tv)mn=tv;
    }
    printf("%d\n",mn);
}


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

    for(i=1;i<=n;i++)
    {
        u=(i-1)*4;
        units=units+u*a[i];
    }
    printf("%d",units);
    return 0;
}


#include <stdio.h>
#include<math.h>
void main()
{
	int n,max=0,mi=0,sum=0,sum1=0;
	scanf("%d",&n);
	int a[n];
	for(int i=0; i<n; i++)
	{
		scanf("%d",&a[i]);
		if(max<a[i])
		{
			max=a[i];
			mi=i;
		}
	}
	int b=n-1;
	for(int j=0; j<n; j++)
	{
		sum= (j-mi) + (j-0) + 2*(mi-0) + abs(0-j) + abs(mi-j);
		sum1= sum1 + sum*a[j];
		sum=0;
	}
	printf("%d",sum1);

}


#include<stdio.h>
int main(){
	int a,b,c,d,e;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	printf("%d",min(a,min(b,min(c/2,min(d/7,e/4)))));
	return 0;
}


#include<stdio.h>
#define min(a,b) (a>b) (b):(a)
int main(){
	int a,b,c,d,e,s=0;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	printf("%d",min(a,min(b,min(c/2,min(d/7,e/4)))));

	return 0;
}


#include<stdio.h>
int srx[6],sry,i;
int min(int x,int y)
{
    if(x<y)
    return x;
    return y;
}
int main()
{
    for(i=1;i<=5;i++)
    scanf("%d",&srx[i]);
    srx[3]/=2;
    srx[4]/=7;
    srx[5]/=4;
    sry=min(min(min(min(srx[1],srx[2]),srx[3]),srx[4]),srx[5]);
    printf("%d",sry);
    return 0;
}


#include <stdio.h>

int main()
{
    int af, ar, am, mi, vit;
    scanf("%d %d %d %d %d", &af, &ar, &am, &mi, &vit);
    am= am/2;
    mi=mi/7;
    vit=vit/4;
    if(vit<=af && vit<=ar && vit<=am && vit<=mi)
    {
        printf("%d", vit);
    }
    else if(af<=ar && af<=am && af<=mi && af<=vit)
    {
        printf("%d", af);
    }
    else if(ar<=af && ar<=am && ar<=mi && ar<=vit)
    {
        printf("%d", ar);
    }
    else if(am<=af && am<=ar && am<=mi && am<=vit)
    {
        printf("%d", am);
    }
    else if(mi<=af && mi<=ar && mi<=am && mi<=vit)
    {
        printf("%d", mi);
    }

    main();
}


#include<stdio.h>
int main()
{
    int arr[5],i,arr2[]={1,1,2,7,4};
    int min=1000;
    for(i=0;i<5;i++)
    {

    scanf("%d",&arr[i]);
    if(arr[i]/arr2[i]<min)
    min=arr[i]/arr2[i];

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


#include <string.h>
#include <stdio.h>
int main()
{
     int k;
     scanf("%d\n",&k);
     int i,j,l;
     char ch[4][4],str;
     for(i=0;i<4;i++)
     {
          scanf("%s",ch[i]);
     }
     int cnt[9];
     for(str='1';str<='9';str++)
     {
          cnt[str]=0;
     }
     char q,w;
     for(i=0;i<4;i++)
     {
          for(j=0;j<4;j++)
          {
               q=ch[i][j];
               if(q!='.')
               {
                    cnt[q]++;
               }
          }
     }
     for(str='1';str<='9';str++)
     {
          if(cnt[str]<=2*k)
          l++;
          else
          {
               o=1;
               break;
          }
     }
     if(o==1)
     printf("NO");
     if(l==9)
     printf("YES");
}


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

int main()
{
    int k,i,a[10]={0};
    char s[5];
    scanf("%d",&k);
    k=k*2;
    for(i=0;i<4;i++)
    {
        scanf("%s",s);
        if(s[0]!='.')
		{
			a[s[0]-'0']++;
		}
        if(s[1]!='.')
		{
			a[s[1]-'0']++;
		}
        if(s[2]!='.')
		{
			a[s[2]-'0']++;
		}
        if(s[3]!='.')
		{
			a[s[3]-'0']++;
		}
    }
    for(i=0;i<10;i++)
    {
		if(a[i]>k)
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


#include <string.h>
#include <stdio.h>
int main()
{
     int k;
     scanf("%d\n",&k);
     int i,j,k,l;
     char ch[4][4],str;
     for(i=0;i<4;i++)
     {
          scanf("%s",ch[i]);
     }
     int cnt[9];
     for(str='1';str<='9';str++)
     {
          cnt[str]=0;
     }
     char q,w;
     for(i=0;i<4;i++)
     {
          for(j=0;j<4;j++)
          {
               q=ch[i][j];
               if(q!='.')
               {
                    cnt[q]++;
               }
          }
     }
     for(str='1';str<='9';str++)
     {
          if(cnt[str]<=2*k)
          l++;
          else
          {
               o=1;
               break;
          }
     }
     if(o==1)
     printf("NO");
     if(l==9)
     printf("YES");
}


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

using namespace std;

int main(void)
{
    int k,i,j,conv,flag,q;
    scanf("%d",&k);
    int a[9]={0};
    flag=0;
    char str[5];
    for(i=0; i<4; i++)
    {
                  scanf("%s",str);
              //    printf("\n%s",str);
                  for(q=0; q<4; q++)
                  {
                  conv=str[q];
            //      printf("\n c=%c d=%d",str[q],conv);
                  switch(conv)
                  {
                            case 49 : a[0]++;
                                      break;
                            case 50 : a[1]++;
                                      break;
                            case 51 : a[2]++;
                                      break;
                            case 52 : a[3]++;
                                      break;
                            case 53 : a[4]++;
                                      break;
                            case 54 : a[5]++;
                                      break;
                            case 55 : a[6]++;
                                      break;
                            case 56 : a[7]++;
                                      break;
                            case 57 : a[8]++;
                                      break;
                            case 46 : break;
                  }
               //   }
             }
    }
    k*=2;
    for(i=0; i<9; i++)
    {
             if(a[i]>k)
             {
                 flag=1;
                 break;
             }
             if(flag==1)
                break;
    }
    if(flag==1)
        printf("NO");
    else
        printf("YES");
  //  getch();
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char A[100];
    int n,i,j,k=0,m,l;

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

    for(i=n;i>=0;i--)
    {
        l=0;
        if(i%2==0)
        {
            j=i/2;
            m=j;
            for(k=0;k<j;k++)
            {
                if(A[k]==A[m]) l++,m++;
            }
            if(j==0)
            {
                printf("%d",n);
                return 0;
            }
            else if(j==l)
            {
                printf("%d",(n-l)+1);
                return 0;
            }
        }
    }
}


#include<stdio.h>

int main(){

	int n,i,j,k,count=0,l=0,sum=0;
	char s[100],s1[100];

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

	gets(s);

	l=strlen(s);

	//printf("l:%d\n",l);
	if(l%2!=0)
		j=l-1;
	else
		j=l;

	while(j>=1){

	//	printf("\nj:%d\n",j);
		for(i=0;i<(j/2);i++){

	//		printf("s[%d]:%c,s[%d]:%c,",i,s[i],(i+(j/2)),s[i+(j/2)]);
			if(s[i]!=s[i+(j/2)])
				break;
			else
				count++;
	//		printf("count:%d\n",count);
		}

		if(count==(j/2)){
			sum=count;
			break;
		}
		count=0;

		j=j-2;
	}

	if(sum!=0)
		printf("%d\n",(sum+1)+(l-(2*sum)));
	else
		printf("%d\n",strlen(s));

	return 0;
}


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

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


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


#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
long long int e[3];
long long int a,b,c,d;
long long int min,max,temp,mid;
long long int diff1,diff2;
long long int ans1=0,ans2=0;
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
e[0]=a;
e[1]=b;
e[2]=c;
for(i=0;i<2;i++)
  {for(j=0;j<2;j++)
    {if(a[j]>a[j+1])
     {temp=a[j];
     a[j]=a[j+1];
     a[j+1]=temp;
     }
    }
  }
 diff1=(e[1]-e[0]);
 diff2=(e[2]-e[1]);
 if(diff1<d)
 ans1=d-diff1;
 if(diff2<d)
 ans2=d-diff2;
 ans=ans1+ans2;
 printf("%lld",ans);
}


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

int main()
{
    long long a,b;
    scanf("%I64d %I64d",&a,&b);
    if(a>[b){
        printf("%I64d\n",b/2);
        return 0;
    }
    else if((2*a-1)>=b){
            printf("%I64d",((b/2)-(b-1-a)));
        }
    else printf("0\n");
    return 0;
}


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


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

int main()
{
    long long a,b;
    scanf("%I64d %I64d",&a,&b);
    if(a>[b){
        printf("%I64d\n",b/2);
        return 0;
    }
    else if((2*a-1)>=b){
            if((2*a-1)==b)
                printf("1\n");
            else printf("%I64d",((b/2)-(b-1-a)));
        }
    else printf("0\n");
    return 0;
}


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

main(){
    long long a, b;
    cin>>a>>b;

    if(b<a){
        cout<<b/2<<endl;
        return 0;
    }

    if((b/2) > a){
        cout<<"0"<<endl;
        return 0;
    }

    long long c= (b-1)/2 +1;

    cout<< a-c+1 << endl;

}