#include<stdio.h>

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

    int a, b, c;
    long long ttl = 0;
    for (a = 1; a <= n; a++)
        for (b = a; b <= n; b++)
        {
            c = a ^ b;
            if (a == b || c == 0)
                continue;
            //printf("%2d %2d %2d %d\n", a, b, c, (a + b > c && a + c > b && b + c > a && c >= b && c <= n));
            if (a + b > c && a + c > b && b + c > a && c >= b && c <= n)
                ttl++;
        }
    printf("%lld\n", ttl);
    return 0;
}

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

int main()
{
	long long int n,i,j,p=0,q,ans=0;
	scanf("%lld",&n);

	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			p=i^j;
			if(p>j && p<=n && (i+p)>j && (i+j)>p && (j+p)>i)
				ans++;
		}
	}
	printf("%lld\n",ans);

	return 0;
}

#include<stdio.h>
#define ll long long int
int main()
{
	ll n;
	ll i;
	ll j;
	ll k;
	ll count=0;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		for(j=i;j<=n;j++)
		{
			k=i^j;

			if(k>0 && k<=n)
			{
				if(i+j>k && j+k>i && i+k>j)
				{
					if(i<=j && j<=k)
					{
					//	printf("This is i,j,k: %lld %lld %lld\n",i,j,k);
						count++;
					}
				}
			}
		}
	}
	printf("%lld\n",count);
	return 0;
}

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int tricheck(int a,int b,int c){
    if((abs(a-b)<c)&&(c<a+b) && (abs(b-c)<a)&&(a<b+c) && (abs(a-c)<b)&&(b<a+c)){
        return 1;
    }
    return 0;
}
int main(){
    int n;
    scanf("%d",&n);
    int x = 1 , y = 1, z = 1,counter = 0;
    clock_t ali = clock();
    for( x = n ; x >= 1 ;x--){
        for(y = x ; y > x/2 ; y--){
            if((x^y)<y && tricheck(x,y,x^y)){
                counter++;
            }
        }
    }
    printf("%d",counter);
}

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

main(){

    int n,i,j,k,pom;

    scanf("%d",&n);

    int br = 0;

    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){
            k = i ^ j;
            if(i + j > k && i + k > j && k + j > i && i <= j && j <= k && k <= n){
                br++;
            }
        }
    }

    printf("%d",br);

}

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

int main(void)
{
	int n, ans = 0, i, j, x;
	scanf("%d", &n);

	for (i = 1; i <= n; i++)
	{
		for (j = i; j <= n; j++)
		{
			x = i ^ j;
			if (x < j || i + j <= x || x > n) continue;
			ans++;
		}
	}
	printf("%d\n", ans);
}

#include <stdio.h>

int main(void) {
	int n,i,j,k,count=0;
	scanf("%d",&n);
	for(i=n;i>0;i--)
	{for(j=i-1;j>0;j--)
	{k=j^i;

	if(i>=j&&j>=k)
	{if(i<(j+k)&&j<(i+k)&&k<(i+j))
	{count++;

	}}

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

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

//int area(int a,int b,int c){
  //  int s,ara;
   //s=(a+b+c)/2;
   //ara=sqrt(s*(s-a)*(s-b)*(s-c));
   //return ara;
//}

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

              }

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

#include<stdio.h>
int n;
int main()
{
	int ans=0;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int a=i,b=j,c=i^j;

				if(c>=1&&c<=n&&((a+b)>c&&(a+c)>b&&(b+c)>a))
				{
			ans++;
				}

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

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int count=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=i; j<=n; j++)
        {
            int temp = i^j;
            if(temp<=n && i+j>temp && temp>i && temp>j)
            count++;
        }
    }
    printf("%d ",count);
}

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

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

#include<stdio.h>

int main()
{
	int i,j,n,temp,c=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=i;j<=n;j++)
		{
			temp=i^j;
			if(temp<j || (i+j)<=temp || temp>n)
				continue;
			c++;
		}
	}
	printf("%d\n",c);
}

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

int main()
{
    int n ,a,b,c,counter=0;

    scanf("%d",&n);

    if(n>2500)
        return;

        for(c=n;c>=6;c--)
        {
            for(b=c;(b>0.5*c);b--)
            {
                a=b^c;

                if(a<=b&&a>=1&&a+b>c)
                {
                    counter++;
                  //  printf("%d %d %d\n",a,b,c);
                }

            }

        }

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

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

#include <stdio.h>

int main()
{
  int n;
  scanf("%d", &n);
  unsigned a, b, c, counter;

  for(a=0;a<=n;a++)
    for(b=a;b<=n;b++)
      {
        c = 0 ^ a ^ b;
        if(c <= n && c >= b && a + b > c)
          counter++;
      }

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

#include <stdio.h>
//Vailate if num1, num2, num3 can construct a triangle
//return 1 if it can construct a triangle
//return 0 if it can't construct a triangle
int isTriangle(int num1, int num2, int num3) {
    if(num1 + num2 > num3)
        return 1;
    return 0;
}
int main() {
    int num1, num2, num3, count, max;
    scanf("%d", &max);
    for(num1 = 1, count = 0; num1 <= max; num1++)
        for(num2 = num1; num2 <= max; num2++) {
            num3 = num1 ^ num2;
            if(num3 >= num2 && num3 <= max && isTriangle(num1, num2, num3))
                count++;
        }
    printf("%d", count);
    return 0;
}

#include<stdio.h>
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int i,j,sum=0,c;
        for(i=1;i<n;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                c=i^j;
                if(c>=1&&c<=n&&c>j&&i+j>c&&i+c>j&&j+c>i)
                    sum++;
            }
        }
        printf("%d\n",sum);
    }

    return 0;
}

#include <stdio.h>
int main() {
    int n ,i ,j ,k, c;
    while( scanf("%d",&n)!=EOF ){
        c = 0;k=n;
        for( i=1 ; i<n-1 ; i++ )
            for( j=i+1 ; j<n ; j++ )
                for( k=j+1 ; k<=n ; k++ )
                    if((i^j)==k && i+j>k)c++;
        printf("%d\n", c);
    }
}

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

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

scanf("%d",&n);
for(i=1;i<=n;i++){
    for(j=i;j<=n;j++){
        for(z=j;z<=n;z++)
                {

                  if(!(i^j^z))
                    ans+= i+j>z ;

               }

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

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

#include<stdio.h>
typedef long long int ll;
int main()
{
  ll n,i,j,k,ans=0;
  scanf("%lld",&n);
  for(i=1;i<=n;i++)
  {
    for(j=i;j<=n;j++)
    {
      k=j^i;
      if(k>0 && k<=n && ((i+j>k)&&(j+k>i)&&(k+i>j)&&(i<=j)&&(j<=k)))
        ans++;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

# include <stdio.h>

int main()
{
int n,count=0;
scanf("%d",&n);
int a[n][n],b[n];
for(int i=0;i<n;i++)
b[i]=i+1;
for(int i=0;i<n;i++)
for(int j=i;j<n;j++)
{
a[i][j]=(i+1)^(j+1);
int min=0;
int max=n-1;
int mid=(max+min)/2;
while(max>=min)
{
if(b[mid]>a[i][j])
max=mid-1;
else
min=mid+1;
mid=(min+max)/2;
}
//printf("%d %d %d %d %d\n",mid,a[i][j],b[mid],i,j);
if(b[mid]==a[i][j] && b[mid]>=(i+1) &&b[mid]>=(j+1) && b[mid]+i>j && i+j+2>b[mid] && b[mid]+j>i )
count++;
//printf("count=%d\n",count);
}
printf("%d",count);
return 0;
}

#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int ans = 0;
    for(int a = 1; a <= n; ++a) {
        for(int b = a + 1; b <= n; ++b) {
            int c = a ^ b;
            if(a + b > c && a + c > b && c > b && c <= n) {
                ++ans;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

#include <stdio.h>

int valid(int a, int b,int c){
	if(a+b <= c)
		return 0;
	if(b+c <= a)
		return 0;
	if(a+c <= b)
		return 0;
	return 1;
}

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

#include<stdio.h>

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

	int i,j,k,count=0;
	for(i=1;i<=n;i++)
	{
		for(j = i ; j<=n;j++)
		{
			k  = i ^ j;
			if( k<=n && k+i >j &&  k+j >i && i+j > k && k>0)
			{	count++;
		//		printf("k : %d %d %d\n",i,j,k );
			}

		}
		//printf("i : %d\n",i );

	}
	printf("%d\n",count/3 );

	return 0;
}

#include <stdio.h>

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

  int counter=0;

  for(int a=1; a<=n; a++){
  	for(int b=a; b<=n; b++){
  		int c = a^b ;
  			if( c>=1 && c<=n && c >=b && a+b>c) {counter++;}
  	}
  }

  printf("%d" ,counter);

	return 0;
}

#include <stdio.h>
#define _MEASURE_   0

#if _MEASURE_
#include <time.h>
#endif

#define min(a,b) ((a)>(b)?(b):(a))
int xorSum(int a, int b)
{
    int c = 0, cnt = 1;
    while(a > 0 || b > 0)
    {
        if((a%2+b%2)%2 == 1)
            c += 1 * cnt;
        a /= 2; b /= 2;
        cnt *= 2;
    }
    return c;
}
int main()
{
    int n;
    scanf("%d", &n);
#if _MEASURE_
    clock_t t;
    t = clock();
#endif
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = i; j <= n; j++)
        {
            int k = xorSum(i,j);
            if(k <= n && k >= 1 && (i+j) > k && k > j && k > i)
                cnt++;
        }
    }
    printf("%d\n", cnt);
#if _MEASURE_
    t = clock() - t;
    printf("It took me (%f seconds).\n", ((float)t)/CLOCKS_PER_SEC);
#endif
}

#include<stdio.h>
int main()
{
	int n;
	while (~scanf("%d", &n))
	{
		int i, j, sum = 0, c;
		for (i = 1; i<n; i++)
		{
			for (j = i + 1; j <= n; j++)
			{
				c = i ^ j;
				if (c >= 1 && c <= n && c>j&&i + j>c&&i + c>j&&j + c>i)
					sum++;
			}
		}
		printf("%d\n", sum);
	}

	return 0;
}

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

#include <stdio.h>

int main(void) {
	int n, count = 0;

	scanf("%d", &n);

	for (int a = 1; a <= n; a++) {
		for (int b = a; b <= n; b++) {
			int c = a^b;

			if(c <= n && c >= b && a + b > c && b + c > a && c + a > b)
					count++;
		}
	}

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

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

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

#include<stdio.h>
int main()
{
    int n,i,j,k,xorangle=0;
    scanf("%d",&n);
    for(i=2;i<=n-2;i++)
    {
        for(j=i+1;j<=n-1;j++)
        {

            for(k=j+1;k<=n;k++)
            {
                if(i+j<=k)
                {
                    break;
                }
                else if((i^j)==k)
                {
                    xorangle++;
                }
            }
        }
    }
    printf("%d",xorangle);
    return 0;
}

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

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

int main(int argc,char* argv[])
{
    int i,j,temp,cpt=0,n;
    do{
        scanf("%d",&n);
    }while(n<1 && n>2500);
    for (i = 1;  i <= n; i++)
    {
        for (j = 1; j <= i; j++)
        {
            temp = i ^ j;
            if (temp > j || temp > i)
                continue;
            if (temp + j <= i)
                continue;
            cpt++;
        }
    }
    printf("%d",cpt);
    return 0;
}

//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}

int main(void){
    int i,j,n,m,k,a[262144],b,c,w,r=0,l,t;
    double d;
    char s[262144];
    scanf("%d%d",&n);
    //l=strlen(s);
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            a[0]=i;a[1]=j;a[2]=i^j;
            if(a[0]>a[1] || a[1]>a[2]){continue;}
            //qsort(a,3,sizeof(int),sortfncsj);
            if(a[2]>n || a[2] >= a[0]+a[1]){continue;}
            r++;
        }
    }
    //qsort(a,n,sizeof(int),sortfncsj);
    printf("%d\n",r);
    return 0;
}

/* Author Kh. Assaduzzaman Sohan  */

#include<stdio.h>
#include<string.h>
#include<math.h>
#define mod 100000007
//int x[100005]= {0};
int main()
{
    int n,i,j,x,y,Ans=0;

    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            x=i^j;
            if(x<=n && x>i && x>j && x<(i+j))
            {
                //printf("i=%d j=%d x=%d\n",i,j,x);
                    Ans++;
            }
        }

    }
    printf("%d",Ans/2);

    return 0;
}

#include<stdio.h>

int main()
{
   int t,i,j,k,cnt=0;

    scanf("%d",&t);

    for(i=1;i<=t;i++){
        for(j=i;j<=t;j++){
                k=i^j;
                if(j<=k && t>=k && (i^j^k)==0 && i+j>k ){
                   cnt++;
                }
            }
    }
    printf("%d\n",cnt);

   return 0;
}

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

#include<stdio.h>

int main()
{

	int n,cnt=0;

	scanf("%d",&n);
	int c,a,b;
	for(c=n;c>=1;c--)
	{
		for(a=1;a<=c;a++)
		{
			b=a^c;

			if(   (a+b)>c && a<c && b<c)
			{
				cnt++;
			}

		}
	}

	printf("%ld\n",cnt/2);

	return 0;
}

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

int n,ans;

int main()
{
    scanf("%d",&n);
    for (int i = 1;  i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            int temp = i ^ j;
            if (temp > j || temp > i)
                continue;
            if (temp + j <= i)
                continue;
            ans++;
        }
    }
    printf("%d\n",ans);

    return 0;
}

#include<stdio.h>
int main()
{
   int n,i,j,k,a=0,b,c;
   scanf("%d",&n);
   for (i=1;i<=n;i++)
   {
       for(j=i;j<=n;j++)
       {
           for(k=j;k<i+j;k++)
           {
               if(k>n)
                break;
            {if(!(i^j^k))
                        a++;}
            }
       }
   }
   printf("%d",a);
   return 0;
}

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

int main()
{
	int n;
	scanf("%d", &n);
	int forests = 0;
	int i;
	int j;
	int k;
	double p;
	for(i = 1; i <= n; i++)
	{
		for(j = i; j <= n; j++)
		{
			k = i ^ j;
			if (k >= i && k >= j && k <= n)
			{
				p = ((double)(i + j + k)) / 2.0;
				double heron = p * (p - i) * (p - j) * (p - k);
				if(sqrt(heron) > 0)
				{
					forests++;
				}
			}
		}
	}

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

	return 0;
}

#include<stdio.h>
int main()
{
  int n,a,b,c,i,max,count=0,j,k;
  scanf("%d",&n);
  for ( i = 1; i <= n; ++i)
  {
    for ( j = i+1; j <= n; j++)
    {
      /* code */
      if(i>j)
        max=i;
      else
        max=j;
      for ( k = max+1;( (k < i+j)&& k<=n ) ;k++)
      {
        /* code */
        if(((i^j^k)==0) )
          {count++;
          }
      }
    }
  }
  printf("%d",count );
}

#include <stdio.h>

int isTri (int a , int b , int c)
{
    if (a+b>c && b+c>a && c+a>b)
        return 1;
    else
        return 0;
}

int main()
{
    int n,i,j,x,c;

    scanf("%d", &n);

    for (i = 1, c=0 ; i<n ; i++)
    {
        for (j = i+1 ; j <= n ; j++)
        {
            x = i^j;
            if (x>n)
                continue;
            if (isTri(i,j,x))
                ++c;
        }
    }
    printf("%d\n",c/3);
    return 0;
}

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

#include<stdio.h>

int main() {
    int n,cnt=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        for(int j=i;j<=n;j++) {
            for(int k=j;(k<i+j&&k<=n);k++) {
                if((i^j^k)==0) cnt++;
            }
        }
    }
    printf("%d",cnt);
    return 0;
}

#include <stdio.h>

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

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main() {
    int x,y,n,i,j,k,count=0;
    scanf("%d",&n);
    for(i=3;i<=n;i++)
    {
    	for(j=i+1;j<=n;j++)
    	{
    		x=i^j;
    		if(i+j>x && j+x>i && i+x>j && x<=n)
    		{
    			//printf("%d %d %d\n",i,j,x);
    			count++;
    		}
    	}
    }
    printf("%d",count/3);

    return 0;
}

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

int isTriangle(int a,int b,int c)
{
    if(a+b>c)
    {
        if(b+c>a)
        {
            if(a+c>b)
            {
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    //printf("%d",3^5^6);
    int i,j,k,n,count=0;
    scanf("%d",&n);
    for(k=5;k<=n;k++)
    {
        for(j=3;j<=k;j++)
        {
            //for(i=n-k-j;i<=j;i++)
            //{
                i=k^j;
                        if(i<j){
                    if(isTriangle(i,j,k)==1)
                       {count++;
                    //printf("%d and %d and %d\n",i,j,k);
                    }}
              //  }

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

#include <stdio.h>

int main ()
{
    int n, a, b, c, ans = 0;

    scanf("%d", &n);

    for(a = 1; a <= n; a++)
    {
        for(b = 1; b <= n; b++)
        {
            c = a ^ b;
            if(a + b > c && a + c > b && b + c > a)
                if(a <= b && b <= c && c <= n && a >= 1) ans++;
        }
    }

    printf("%d", ans);

    return 0;
}

#include <stdio.h>

char Flag[2501];

int main()
{
    int n;
    scanf("%d", &n);
    int ans = 0;
    for(int a = 1; a <= n; ++a) {
        for(int b = a + 1; b <= n; ++b) {
            int c = a ^ b;
            if(a + b > c && a + c > b && c > b && c <= n) {
                if(!Flag[c]) {
                    Flag[c] = 1;
                    ++ans;
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

#include<stdio.h>

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

	int i,j,k,count=0;
	for(i=1;i<=n;i++)
	{
		for(j = i ; j<=n;j++)
		{
			k  = i ^ j;
			if( k<=n && k+i >= j &&  k+j >=i && i+j >= k )
				count++;
		}

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

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int G(int x){
    int a = x % 8;
    if(a == 0 || a == 1) return x;
    if(a == 2 || a == 3) return 2;
    if(a == 4 || a == 5) return x+2;
    if(a == 6 || a == 7) return 0;
    return 0;
}
int main() {
	//code
	int n,i,count;
	scanf("%d",&n);
	for(i=1;i<=n-3;i++)
	{
	    if(G(i+4)^G(i)==0)
	    {
	        count+=1;
	    }
	}
	printf("%d\n",(count%3));
	return 0;
}

#include <stdio.h>
int ar[2509];
int main()
{
   int i,j,k,n,count=0,x;
   scanf("%d",&n);
   for(i=1; i<=n; i++)
   {
     for (j=i; j<=n; j++)
     {
       x=i^j;
       if (ar[x^i]==1||ar[x^j]==1) continue;
       if(x+i>j && x+j>i && i+j>x && x<n)
       {
           //printf("active %d %d %d\n",i,j,x);
           count++;
          ar[i]=1; ar[j]=1;
       }
   }
   }
   printf("%d\n",count);
   return 0;
}

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

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

int main()
{
    int n ,a,b,c,counter=0;

    scanf("%d",&n);

    for(c=n;c>=n/2;c--)
    {
        for(b=c;(b>=1)&&(c<2*b);b--)
        {
            for(a=b;(a>=1)&&(a+b>c);a--)
            {
                if(a^b^c)
                    continue;

                   printf("%d %d %d\n",a,b,c);
                    counter++;
            }

        }
    }

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

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

int main()
{
    int n ,a,b,c,counter=0;

    scanf("%d",&n);

    for(c=n;c>=n/2;c--)
    {
        for(b=c;(b>=1)&&(c<2*b);b--)
        {
            for(a=b;(a>=1)&&(a+b>c);a--)
            {
                if(a^b^c)
                    continue;

                  // printf("%d %d %d\n",a,b,c);
                    counter++;
            }

        }
    }

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

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

int main()
{
    int n ,a,b,c,counter=0;

    scanf("%d",&n);

    for(c=n;c>=1;c--)
    {
        for(b=c;b>=1;b--)
        {

            for(a=b;(a>=1)&&(a+b>c)&&(a+c>b);a--)
            {
                if(a^b^c)
                    continue;
                else if((b+c>a))
                {
                   printf("%d %d %d\n",a,b,c);
                    counter++;
                }

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

#include<stdio.h>

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

    int a, b, c;
    long long ttl = 0;
    for (a = 1; a <= b; a++)
        for (b = a; b <= n; b++)
        {
            if (a == b)
                continue;
            c = a ^ b;
            //printf("%2d %2d %2d %d\n", a, b, c, (a + b > c && a + c > b && b + c > a && c >= b && c <= n));
            if (a + b > c && a + c > b && b + c > a && c >= b && c <= n)
                ttl++;
        }
    printf("%lld\n", ttl);
    return 0;
}

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

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

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

#include <stdio.h>

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

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

int main()
{
	int n;
	scanf("%d", &n);
	int forests = 0;
	int i;
	int j;
	int k;
	double p;
	for(i = 1; i <= n; i++)
	{
		for(j = i; j <= n; j++)
		{
			k = i ^ j;
			if (k >= i && k >= j)
			{
				p = ((double)(i + j + k)) / 2.0;
				double heron = p * (p - i) * (p - j) * (p - k);
				if(sqrt(heron) > 0)
				{
					forests++;
					printf("%d %d %d \n", i,j,k);
				}
			}
		}
	}

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

	return 0;
}

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

int main()
{
	int n;
	scanf("%d", &n);
	int forests = 0;
	int i;
	int j;
	int k;
	double p;
	for(i = 1; i <= n; i++)
	{
		for(j = i; j <= n; j++)
		{
			k = i ^ j;
			if (k >= i && k >= j && k <= n)
			{
				p = ((double)(i + j + k)) / 2.0;
				double heron = p * (p - i) * (p - j) * (p - k);
				if(sqrt(heron) > 0)
				{
					forests++;
					printf("%d %d %d \n", i,j,k);
				}
			}
		}
	}

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

	return 0;
}

#include<stdio.h>
int main()
{
  int n,a,b,c,i,max,count=0,j,k;
  scanf("%d",&n);
  for (int i = 1; i < n; ++i)
  {
    for (int j = i+1; j < n; ++j)
    {
      /* code */
      if(i>j)
        max=i;
      else
        max=j;
      for (int k = max+1; k < i+j; ++k)
      {
        /* code */
        if((i^j^k)==0)
          count++;
      }
    }
  }
  printf("%d\n",count );
}

#include<stdio.h>
int main()
{
  int n,a,b,c,i,max,count=0,j,k;
  scanf("%d",&n);
  for (int i = 1; i < n; ++i)
  {
    for (int j = i+1; j < n; ++j)
    {
      /* code */
      if(i>j)
        max=i;
      else
        max=j;
      for (int k = max+1; k < i+j; ++k)
      {
        /* code */
        if((i^j)==k)
          count++;
      }
    }
  }
  printf("%d\n",count );
}

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

int isTriangle(int a,int b,int c)
{
    if(a+b>c)
    {
        if(b+c>a)
        {
            if(a+c>b)
            {
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    //printf("%d",3^5^6);
    int i,j,k,n,count=0;
    scanf("%d",&n);
    for(k=5;k<=n;k++)
    {
        for(j=(n-k)/2;j<=k;j++)
        {
            //for(i=n-k-j;i<=j;i++)
            //{
                i=k^j;
                        if(i<j){
                    if(isTriangle(i,j,k)==1)
                       {count++;
                    //printf("%d and %d and %d\n",i,j,k);
                    }}
              //  }

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

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

int isTriangle(int a,int b,int c)
{
    if(a+b>c)
    {
        if(b+c>a)
        {
            if(a+c>b)
            {
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    //printf("%d",3^5^6);
    int i,j,k,n,count=0;
    scanf("%d",&n);
    for(k=5;k<=n;k++)
    {
        for(j=(n-k)/2;j<=k;j++)
        {
            //for(i=n-k-j;i<=j;i++)
            //{
                i=k^j;
                        if(i<j){
                    if(isTriangle(i,j,k)==1)
                       {count++;
                    printf("%d and %d and %d\n",i,j,k);}}
              //  }

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

#include<stdio.h>
#include<math.h>
int n;
int  s[2501][15]= {0};
int s1[15]= {0};
void  bit(int a)
{
    int t=0;
    int b=a;
    while(a!=0)
    {
        s[b][t]=a%2;
        a=a/2;
        t++;
    }
    /*for(int i=0;i<13;i++)
      printf("%d ",s[b][i]);
    printf("\n");*/
}
int  cmp(int a,int b)
{
    int c=0;
    for(int i=0; i<=12; i++)
    {
        if(s[a][i]!=s[b][i])
            c=c+pow(2,i);
    }
    // printf("%d\n",c);
    if(c>n)
        return 0;
    else if(a+b<=c||a+c<=b||b+c<=a)
        return 0;
    else
    {
       // if(a<b&&b<c)
       //     printf("%d %d %d\n",a,b,c);
        return 1;
    }

}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        bit(i);
    }
    int sum=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<i; j++)
        {
                if(cmp(i,j))
                    sum++;

        }
    }
    printf("%d\n",sum/6);
    return 0;
}

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

int main()
{
	long long int n,i,p=0,q,ans=0;
	scanf("%lld",&n);
	if(n<=3)
	{
		printf("No\n");
		return 0;
	}
	for(i=4;i<=n;i++)
	{
		q=i;
		p=0;
		while(q>0 && q%2==0 )
		{
			q=q/2;
			p++;
		}
		long long int r=0;
		while(q>0)
		{
			q=q/2;
			r++;
		}
		if(r>1)
		{
			ans+=p;
		}
	}
	printf("%lld\n",ans);

	return 0;
}

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

int main()
{
	long long int n,i,p=0,q,ans=0;
	scanf("%lld",&n);
	if(n<=3)
	{
		printf("No\n");
		return 0;
	}
	for(i=4;i<=n;i++)
	{
		q=i;
		p=0;
		while(q>0 && q%2==0 )
		{
			q=q/2;
			p++;
		}
		long long int r=0;
		while(q>0)
		{
			q=q/2;
			r++;
		}
		if(r>1)
		{
			ans+=pow(2,p)-1;
		}
	}
	printf("%lld\n",ans);

	return 0;
}

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

int area(int a,int b,int c){
    int s,ara;
   s=(a+b+c)/2;
   ara=sqrt(s*(s-a)*(s-b)*(s-c));
   return ara;
}

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

              }

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

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

int area(int a,int b,int c){
    int s,ara;
   s=(a+b+c)/2;
   ara=sqrt(s*(s-a)*(s-b)*(s-c));
   return ara;
}

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

              }

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


#include <stdio.h>

#define UNDECIDED -1
#define NOTFOUND -2

int as[20];
int hit[20];
int blow[20];
int appear[20];
int A[20], B[20];
int N;

int precheck(int num){
    int i,cnt=0;
    for(i=0;i<10;i++) appear[i]=0;
    appear[(num/1000)%10]++;
    appear[(num/100)%10]++;
    appear[(num/10)%10]++;
    appear[(num/1)%10]++;
    for(i=0;i<10;i++)if(appear[i]) cnt++;
    return cnt == 4;
}

int subcheck(int num, int idx){
    int i, sub=as[idx], h=0, b=0;
    for(i=0;i<10;i++)A[i]=B[i]=0;
    for(i=1;i<=1000;i*=10){
        if((num/i)%10 == (sub/i)%10){
            h++;
        }
        else{
            A[(num/i)%10]++;
            B[(sub/i)%10]++;
        }
    }
    for(i=0;i<10;i++)if(A[i]&&B[i]) b++;
    return h==hit[idx] && b==blow[idx];
}

int check(){
    int i,j,ok,cnt=0,ans;
    for(i=0;i<10000;i++)if(precheck(i)){
        ok = 1;
        for(j=0;j<N;j++)if(!subcheck(i,j)) ok = 0;
        if(ok){
            cnt++;
            ans = i;
        }
    }
    if(cnt==0) return NOTFOUND;
    else if(cnt==1) return ans;
    else return UNDECIDED;
}

void solve(){
    int result = check();
    if(result == UNDECIDED) puts("Need more data");
    else if(result == NOTFOUND) puts("Incorrect data");
    else printf("%04d\n", result);
}

int main(){
    int i;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d%d%d",as+i,hit+i,blow+i);
    solve();
    return 0;
}

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

int determine(int *guesses, int *bulls, int *cows, int n);
bool is_solution(int *K, int *guesses, int *bulls, int *cows, int n);
bool fits(int *K, int guess, int bulls, int cows);

int main() {
	int n = 0, k = 0, result = 0;
	int *guesses = NULL;
	int *bulls = NULL;
	int *cows = NULL;

	scanf("%d", &n);

	guesses = calloc(n, sizeof(int));
	bulls = calloc(n, sizeof(int));
	cows = calloc(n, sizeof(int));

	for(k=0; k<n; k++) {
		scanf("%d %d %d", &guesses[k], &bulls[k], &cows[k]);
	}

	result = determine(guesses, bulls, cows, n);

	switch(result) {
		case (-1):
			printf("Incorrect data");
			break;
		case (-2):
			printf("Need more data");
			break;
		default:
			if(result<1000)
				printf("0");
			printf("%d", result);
			break;
	}

	printf("\n");

	free(guesses);
	free(bulls);
	free(cows);

	return 0;
}

int determine(int *guesses, int *bulls, int *cows, int n) {
	int i0 = 0, i1 = 0, i2 = 0, i3=0, result=-1;
	int K[4];
	bool found = false;

	for(i3=0;i3<10;i3++){
		for(i2=0;i2<10;i2++){
			if(i2==i3) continue;
			for(i1=0;i1<10;i1++){
				if(i1==i2 || i1==i3) continue;
				for(i0=0;i0<10;i0++){
					if(i0==i1 || i0==i2 || i0==i3) continue;
					K[0]=i0;
					K[1]=i1;
					K[2]=i2;
					K[3]=i3;
					if(is_solution(K, guesses, bulls, cows, n)) {
						if(found)
							return (-2);
						else {
							result = K[0]+10*K[1]+100*K[2]+1000*K[3];
							found = true;
						}
					}
				}
			}
		}
	}

	return result;

}

bool is_solution(int *K, int *guesses, int *bulls, int *cows, int n) {
	bool cont = true;
	int j = 0;

	while(cont && j<n) {
		cont = fits(K, guesses[j], bulls[j], cows[j]);
		j++;
	}

	return cont;
}

bool fits(int *K, int guess, int bulls, int cows) {
	int Guess[4];
	bool selected[4];
	int j = 0, i = 0, weight = 1, weightx = 10, countb = 0, countc = 0;

	for(j=0; j<4; j++) {
		Guess[j] = (guess%weightx) / weight;
		weight = weightx;
		weightx *= 10;
	}

	for(j=0; j<4; j++) {
		if(Guess[j]==K[j])
			countb++;
	}

	if(bulls != countb)
		return false;

	for(j=0; j<4; j++)
		selected[j] = false;

	for(i=0; i<4; i++)
		for(j=0; j<4; j++) {
			if(i!=j && !selected[i] && Guess[i]==K[j]) {
				countc++;
				selected[i] = true;
			}
		}

	if(cows != countc)
		return false;

	return true;
}

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

int determine(int *guesses, int *bulls, int *cows, int n);
bool is_solution(int k, int *guesses, int *bulls, int *cows, int n);
bool fits(int k, int guess, int bulls, int cows);

int main() {
	int n = 0, k = 0, result = 0;
	int *guesses = NULL;
	int *bulls = NULL;
	int *cows = NULL;

	scanf("%d", &n);

	guesses = calloc(n, sizeof(int));
	bulls = calloc(n, sizeof(int));
	cows = calloc(n, sizeof(int));

	for(k=0; k<n; k++) {
		scanf("%d %d %d", &guesses[k], &bulls[k], &cows[k]);
	}

	result = determine(guesses, bulls, cows, n);

	switch(result) {
		case 0:
			printf("Incorrect data");
			break;
		case 1:
			printf("Need more data");
			break;
		default:
			printf("%d", result);
			break;
	}

	printf("\n");

	free(guesses);
	free(bulls);
	free(cows);

	return 0;
}

int determine(int *guesses, int *bulls, int *cows, int n) {
	int k = 0, j = 0, result = 0;

	k = 1000;

	while(k<=9999 && j<=1) {
		if(is_solution(k, guesses, bulls, cows, n)) {
			result = k;
			j++;
		}
		k++;
	}

	if(j==2)
		result = 1;

	return result;
}

bool is_solution(int k, int *guesses, int *bulls, int *cows, int n) {
	bool cont = true;
	int j = 0;

	while(cont && j<n) {
		cont = fits(k, guesses[j], bulls[j], cows[j]);
		j++;
	}

	return cont;
}

bool fits(int k, int guess, int bulls, int cows) {
	int Guess[4];
	int K[4];
	bool selected[4];
	int j = 0, i = 0, weight = 1, weightx = 10, countb = 0, countc = 0;

	for(j=0; j<4; j++) {
		Guess[j] = (guess%weightx) / weight;
		K[j] = (k%weightx) / weight;
		weight = weightx;
		weightx *= 10;
	}

	for(j=0; j<4; j++) {
		if(Guess[j]==K[j])
			countb++;
	}

	if(bulls != countb)
		return false;

	for(j=0; j<4; j++)
		selected[j] = false;

	for(i=0; i<4; i++)
		for(j=0; j<4; j++) {
			if(i!=j && !selected[i] && Guess[i]==K[j]) {
				countc++;
				selected[i] = true;
			}
		}

	if(cows != countc)
		return false;

	return true;
}


#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    if(n>9&&n<30&&n!=12)
    printf("No");
    else if(n>69&&n<80)
    printf("No");
    else if(n>89)
    printf("No");
    else if(n%10==1)
    printf("No");
    else if(n%10==7)
    printf("No");
    else if(n%10==9)
    printf("No");
    else
    printf("Yes");
    return 0;
}

/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:03/04/2019
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>

#include <stdio.h>
int main()
{
	int n,x,y;
	scanf("%d",&n);
	x=n/10;
	y=n%10;
	if(n==12) printf("YES");
	else if(x==1||x==2||x==7||x==9) printf("NO");
	else if(y==1||y==7||y==9) printf("NO");
	else printf("YES");
	return 0;
}

#include <stdio.h>

int main(){
    int n, first_digit, second_digit;
    scanf("%d", &n);
    first_digit = n%10;
    second_digit = (n-first_digit)/10;
    if (n>=1 && n<=99){
        if(first_digit==1 || first_digit==7 || first_digit==9){
            printf("NO");
        } else if(n!=12 && (second_digit == 1 || second_digit == 2 || second_digit == 7 || second_digit == 9)){
            printf("NO");
        } else{
            printf("YES");
        }
    }
    return 0;
}

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

int IsPrime(int n);

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (n < 10)
	{
		printf(n == 1 ? "NO\n" : "YES\n");
	}
	else if (n < 20)
	{
		if (n == 12)             printf("YES\n");
		else if (c % 5 == 0)     printf("YES\n");
		else                     printf("NO\n");
	}
	else
	{
		if (n == 37 || n == 41)     printf("NO");
		else if (n % 4 == 0 )       printf("NO\n");
		else                        printf("YES\n");
	}

	return 0;
 }

int IsPrime(int n)
{
	int i, ok = n > 1, m = sqrt(n);
	for (i = 2; i <= m && ok; ++i)
	{
		if (n % i == 0)
		{
			ok = 0;
		}
	}
	return ok;
}

#include <stdio.h>

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (c % 5 == 0) printf("YES\n");
	else            printf("NO\n");

	return 0;
 }

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

int IsPrime(int n);

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (n < 10)
	{
		if (n != 1)       printf("YES\n");
		else               printf("NO\n");
	}
	else
	{
		if (c % 5 == 0)     printf("YES\n");
		else                printf("NO\n");
	}

	return 0;
 }

int IsPrime(int n)
{
	int i, ok = n > 1, m = sqrt(n);
	for (i = 2; i <= m && ok; ++i)
	{
		if (n % i == 0)
		{
			ok = 0;
		}
	}
	return ok;
}

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

int IsPrime(int n);

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (n < 10)
	{
		printf(n == 1 ? "NO\n" : "YES\n");
	}
	else if (n < 20)
	{
		if (n == 12)             printf("YES\n");
		else if (c % 5 == 0)     printf("YES\n");
		else                     printf("NO\n");
	}
	else
	{
		if (n == 37)             printf("NO");
		else if (n % 4 == 0 ) printf("NO\n");
		else             printf("YES\n");
	}

	return 0;
 }

int IsPrime(int n)
{
	int i, ok = n > 1, m = sqrt(n);
	for (i = 2; i <= m && ok; ++i)
	{
		if (n % i == 0)
		{
			ok = 0;
		}
	}
	return ok;
}

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

int IsPrime(int n);

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (n < 10)
	{
		if (IsPrime(n))     printf("YES\n");
		else                printf("NO\n");
	}
	else
	{
		if (c % 5 == 0)     printf("YES\n");
		else                printf("NO\n");
	}

	return 0;
 }

int IsPrime(int n)
{
	int i, ok = n > 1, m = sqrt(n);
	for (i = 2; i <= m && ok; ++i)
	{
		if (n % i == 0)
		{
			ok = 0;
		}
	}
	return ok;
}

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

int IsPrime(int n);

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (n < 10)
	{
		if (n != 1)       printf("YES\n");
		else               printf("NO\n");
	}
	else
	{
		if (n == 12)             printf("YES\n");
		else if (c % 5 == 0)     printf("YES\n");
		else                     printf("NO\n");
	}

	return 0;
 }

int IsPrime(int n)
{
	int i, ok = n > 1, m = sqrt(n);
	for (i = 2; i <= m && ok; ++i)
	{
		if (n % i == 0)
		{
			ok = 0;
		}
	}
	return ok;
}

#include <stdio.h>

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (c % 5 == 0 || c == 2) printf("YES\n");
	else            printf("NO\n");

	return 0;
 }

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

int IsPrime(int n);

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (n < 10)
	{
		printf(n == 1 ? "NO\n" : "YES\n");
	}
	else if (n < 20)
	{
		if (n == 12)             printf("YES\n");
		else if (c % 5 == 0)     printf("YES\n");
		else                     printf("NO\n");
	}
	else
	{
		if (n == 37 || n == 41 || n == 49)     printf("NO");
		else if (n % 4 == 0 )       printf("NO\n");
		else                        printf("YES\n");
	}

	return 0;
 }

int IsPrime(int n)
{
	int i, ok = n > 1, m = sqrt(n);
	for (i = 2; i <= m && ok; ++i)
	{
		if (n % i == 0)
		{
			ok = 0;
		}
	}
	return ok;
}

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

int IsPrime(int n);

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (n < 10)
	{
		printf(n == 1 ? "NO\n" : "YES\n");
	}
	else if (n < 20)
	{
		if (n == 12)             printf("YES\n");
		else if (c % 5 == 0)     printf("YES\n");
		else                     printf("NO\n");
	}
	else
	{
		if (n % 4 == 0 ) printf("NO\n");
		else             printf("YES\n");
	}

	return 0;
 }

int IsPrime(int n)
{
	int i, ok = n > 1, m = sqrt(n);
	for (i = 2; i <= m && ok; ++i)
	{
		if (n % i == 0)
		{
			ok = 0;
		}
	}
	return ok;
}

#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    if(n>12&&n<30)
    printf("No");
    else if(n>69&&n<80)
    printf("No");
    else if(n>89)
    printf("No");
    else if(n%10==1)
    printf("No");
    else if(n%10==7)
    printf("No");
    else if(n%10==9)
    printf("No");
    else
    printf("Yes");
    return 0;
}

#include <stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n%5==0||n%6!=0)
    printf("Yes");
    else
    printf("No");
    return 0;
}

#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    if(n>=1 && n<=99){
            printf("Yes");
    }
    return 0;
}

#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    printf("Yes");
    return 0;
}

#include <stdio.h>

int main(){
    int n, first_digit, second_digit;
    scanf("%d", &n);
    first_digit = n%10;
    second_digit = (n-first_digit)/10;
    if(first_digit==1 || first_digit==7 || first_digit==9 ){
        printf("NO");
    } else if(second_digit == 1 || second_digit == 2 || second_digit == 7 || second_digit == 9 && n!=12){
        printf("NO");
    } else{
        printf("YES");
    }
    return 0;
}

#include <stdio.h>

int main() {
	int a;

	scanf("%d", &a);
	printf(a == 5 || a / 10 + a % 10 >= 10 ? "YES\n" : "NO\n");
	return 0;
}

#include <stdio.h>

int main() {
	int a;

	scanf("%d", &a);
	printf(a == 5 || a / 10 + a % 10 == 10 ? "YES\n" : "NO\n");
	return 0;
}

#include <stdio.h>

int main() {
	int a, cnt;

	scanf("%d", &a);
	cnt = 0;
	while (cnt < 10) {
		a = a % 10 * 10 + a / 10;
		cnt += a % 10;
	}
	printf(cnt == 10 ? "YES\n" : "NO\n");
	return 0;
}


#include <stdio.h>

long long sum(long long l, long long r) {
	return (r - l + 1) * (l + r) / 2;
}

long long count(long long f, long long k) {
	return f < k ? sum(1, f) + k - f : sum(f - k + 1, f);
}

int check(long long n, long long m, long long k, long long f) {
	return count(f, k) + count(f - 1, n - k) <= m;
}

long long binsearch(int n, int m, int k) {
	long long lower = 1, upper = m + 1;

	while (upper - lower > 1) {
		long long mid = (lower + upper) / 2;

		if (check(n, m, k, mid))
			lower = mid;
		else
			upper = mid;
	}
	return lower;
}

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

	scanf("%d%d%d", &n, &m, &k);
	printf("%lld\n", binsearch(n, m, k));
	return 0;
}

#include <stdio.h>
int main() {
unsigned long long int m,n,k,x,y,a,b;
unsigned long long int s;
scanf("%llu",&n);
scanf("%llu",&m);
scanf("%llu",&k);
a=0;
b=m;
x=(a+b)/2;
while (1)
{
    s=0;
    y=k-1;
    if(y>x-1)
        s+= y -(x-1) +x*(x-1)/2;
    else
        s+= (x-1+x-y)*y/2;
    y=n-k;
    if(y>x-1)
        s+= y -(x-1) +x*(x-1)/2 +x;
    else
        s+= (x-1+x-y)*y/2 +x;
        if (x==0) s=0;

    if (s==m||b<a)
    {
        printf("%llu",x); break;
    }
    else
    {
        if (s>m)
        {

            b=x-1;
            x=(a+b)/2;
        }
        else
        {
            a=x+1;
            x=(a+b)/2;
        }
    }
}
}

//n张床 n个人 自然金字塔形最优
#include<stdio.h>
#include<stdlib.h>
long long n, m, k; //不开long long见祖宗

int check( long long mid )
{
	long long l, r, cnt=0; //该方案需要的枕头数
	if( k-mid+1 >= 1 ) l = k-mid+1; //金字塔左边底的位置
	else l = 1; //如果到了左边界还没到底 左边界取1
	if( k+mid-1 <= n ) r = k+mid-1; //金字塔右边底的位置
	else r = n; //如果到了右边界还没到底 右边界取n
	cnt += ( k-l+1 ) * ( mid-k+l+mid ) / 2 + ( l-1 ); //左半部分等差求和加上平地部分
	cnt += ( r-k+1 ) * ( mid-r+k+mid ) / 2 + ( n-r ); //右半部分等差求和加上平地部分
	cnt -= mid; //上式加了两次mid 要减掉一次
	if( cnt<=m ) return 1;
	else return 0;
}

int main()
{
	long long left, right, mid; //二分法
	scanf("%lld %lld %lld", &n, &m, &k);
	left = 1; right = m-n+1; //初始范围
	while( left <= right ){
		mid = (left + right) / 2;
		if( check( mid ) ) left = mid+1; //还能得寸进尺
		else right = mid-1; //人家生气了
	}
	printf("%lld\n", right);
	//system("pause");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef long long int ll;
int main()
{
    ll n,m,k;
    scanf("%I64d %I64d %I64d",&n,&m,&k);
    ll l,r,s=0;
    r=k;
    l = k;
    m-=n;
    s=1;
    while(m)
    {
        if(l==1 && r==n)
            break;
            else if(m>=(r-l+1))
            {
                m-=(r-l+1);
                s++;
                l--;
                r++;
                r=n>r?r:n;
                l=1>l?1:l;
            }
            else
                break;
    }
        s+=m/(r-l+1);
        printf("%I64d",s);
        return 0;
}

#include <stdio.h>

long long n, m, k, ans, layer_left = 0, layer_right = 0;
long long left_dist, right_dist;

void add_layer()
{
	if (left_dist > layer_left)
	{
		m -= layer_left;
		layer_left++;
	}
	else
		m -= layer_left;

	if (right_dist > layer_right)
	{
		m -= layer_right;
		layer_right++;
	}
	else
		m -= layer_right;

	m -= 1;
}

int main()
{
	scanf("%I64d %I64d %I64d", &n, &m, &k);
	left_dist = k - 1; right_dist = n - k;
	m -= n;

	while (m >= layer_left + layer_right + 1)
	{
		if (left_dist == layer_left && right_dist == layer_right)
		{
			ans += m / n;
			m %= n;
		}
		else
		{
			add_layer();
			ans++;
		}
	}

	printf("%I64d", ans + 1);
}

#include<math.h>
#define Max(x,y)((x) > (y)?(x) :(y))
#define tru 1
#define false 0
typedef long long int int64;
int64  n,m,k,ans,St,End;
int64 sum(int64 x,int64 y)
{
    x = Max(x,0);
    return (x + y) * (y - x + 1) / 2;
}
char  solve(int64 mid)
{
    int64 need = sum(mid - k + 1 , mid) + sum(mid - n + k, mid) - mid;
    return need <= m;
}
int main()
{
    scanf("%I64d%I64d%I64d",&n,&m,&k);
    int64 mid;
    m -= n;
    St = 0;
    End = m;
    while(End - St >= 0)
    {
        mid = (St + End) >> 1;
        if(solve(mid))
        {
            ans = mid;
            St = mid + 1;
        }
        else
            End = mid - 1;
    }
    printf("%I64d\n",ans + 1);
	return 0;
}

#include<stdio.h>
#include<math.h>
#define Max(x,y)((x) > (y)?(x) :(y))

typedef long long int ll;
ll  n,m,k,ans,l,r;
ll sum(ll x,ll y)
{
    x = Max(x,0);
    return (x + y) * (y - x + 1) / 2;
}
char  solve(ll mid)
{
    ll need = sum(mid - k + 1 , mid) + sum(mid - n + k, mid) - mid;
    if(need <= m)
        return 1;
    return 0;
}
int main()
{
    scanf("%I64d%I64d%I64d",&n,&m,&k);
    m -= n;
    l = 0;
    r = m;
    while(r - l >= 0)
    {
        ll mid = (r + l) >> 1;
        if(solve(mid))
        {
            ans = mid;
            l = mid + 1;
        }
        else
            r = mid - 1;
    }
    printf("%I64d\n",ans + 1);
}

#include <stdio.h>
#include <string.h>
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	m-=n;
    int l=k,r=k,ans=1;
     while(m-(r-l+1)>=0&&(l!=1||r!=n)){
     	ans++;
        m-=(r-l+1);
        if(l>1)
        	l--;
        if(r<n)
        	r++;
     }
     if(m>0)
     	ans+=(m/n);
     printf("%d\n",ans);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
long long m,n,k;
int judge(long long x)
{
    long long ans;
    long long l,r;
    if (k<x)
        l=(x+x-(k-1))*k/2;
    else
        l=(1+x)*x/2+(k-x);
    if (n-k<x)
        r=(x+x-(n-k))*(n-k+1)/2;
    else
        r=(1+x)*(x)/2+n-(k+x)+1;
    if (m==k)
        ans=l;
    else if (m==1)
        ans=r;
    else
        ans=l+r-x;
        //printf("%lld,%lld,%lld\n",ans,l,r);
    if (ans==m)
    {
        printf("%lld\n",x);
        exit(0);
    }
    if (ans<m)
        return (1);
    else
        return (0);
}
int main ()
{
    scanf("%lld%lld%lld",&n,&m,&k);
    long long x,top,bot;
    top=(m-n+1);
    bot=1;
    x=(bot+top)/2;
    if (top-1==bot)
    {
        printf("2\n");
        exit(0);
    }
    if (n==1)
    {
        printf("%lld\n",m);
        exit(0);
    }
    while (top-1>bot)
    {
        if (judge(x)==1)
            bot=x;
        else
            top=x;
        x=(bot+top)/2;
    }
    printf("%lld\n",bot);
    return 0;
}
/*if(m==k)
       ans=(x+x-(k-1))*k/2;
    else if (k==1)
        ans=(x+x-(n-k))*(n-k+1)/2;
    else
        ans=(x+x-(k-1))*k/2+(x+x-(n-k))*(n-k+1)/2-x;
*/

#include <stdio.h>
int main()
{
    int l,r,n,m,k,sum,t;
    scanf("%d %d %d",&n,&m,&k);
    m=m-n;
    sum=1;
    l=k;
    r=k;
    t=1;
    while(m>=t)
    {
        sum++;
        m=m-t;
        if(l>1)
        {
            l--;
            t++;
        }
        if(r<n)
        {
            r++;
            t++;
        }
        if(l==1&&r==n)
        {
            sum=sum+m/n;
            break;
        }
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
long long int n,m,k;
int f(int b)
{
    long long int a=b;
    long long int s=a;
    if(a<=k)
        s+=a*(a-1)/2;
    else
        s+=(2*a-k)*(k-1)/2;
    if(n-k+1>=a)
        s+=a*(a-1)/2;
    else
        s+=(2*a-n+k-1)*(n-k)/2;
    if(s>m)
        return -1;
    else
        return 1;
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    m-=n;
    int a=0,b=m+1;
    do
    {
        if(f((a+b)/2)>0)
            a=(a+b)/2;
        else b=(a+b)/2;
    }
    while(b-a>1);
    printf("%d",a+1);
    return 0;
}

#include<stdio.h>
long n,m,k,ans=1,Reduc_;

int main(){
    scanf("%ld%ld%ld",&n,&m,&k);
    m -= n;
    Reduc_ = 1;
    if(m == 0)
{
puts("1");
return 0;
}
    while(m>0){
        if(k+ans<=n)++Reduc_;
        if(k-ans>=1)++Reduc_;
        m -= Reduc_;
        ++ans;
    }
    printf("%d\n",ans);
    return 0;
}

#include<stdio.h>
int main()
{
	long long int n,m,k;
	scanf("%I64d%I64d%I64d",&n,&m,&k);
	long long int left=k,right=k,val=1,i=1;
	m=m-n;
	while(m>=i)
	{
		val++;
		m=m-i;
		if(left>1)
		{
			left--;
			i++;
		}
		if(right<n)
		{
			right++;
			i++;
		}
		if(left==1 && right==n)
{
	val=val+m/n;
	break;
}

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

#include <stdio.h>

int main(void) {
    int left = 0, right = 0;
    int n = 0, m = 0, k = 0;
    int i = 1, val = 1;

    scanf("%d %d %d", &n, &m, &k);
    left = right = k;
    m -= n;

    while (m >= i) {
        val++;
        m -= i;
        if (left > 1) {
            left--;
            i++;
        }

        if (right < n) {
            right++;
            i++;
        }

        if (left == 1 && right == n) {
            val = val + m / n;
            break;
        }
    }

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

    return 0;
}

#include<stdio.h>
int n, m, k, res = 1, l = 1;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  m -= n;
  while(m > 0) {
    if(k - res >= 1) ++l;
    if(k + res <= n) ++l;
    ++res; m -= l;
  }
  printf("%d\n", res);
  return 0;
}

#include <stdio.h>
int n ,m ,k ,c=1 ,alm=1;
int main() {

    scanf("%d%d%d",&n,&m,&k);
        m -= n;
        while( m>0 ){
            if( k+alm <= n )c++;
            if( k-alm > 0 )c++;
            m -= c;
            alm++;
        }
        printf("%d\n", alm);

}

/* Coached by Dukkha */
#include <stdio.h>

long long triangle(int k, int x) {
	if (k > x)
		k = x;
	return (long long) (x + x - k + 1) * k / 2;
}

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

	scanf("%d%d%d", &n, &m, &k);
	m -= n;
	lower = 0, upper = m + 1;
	while (upper - lower > 1) {
		int x = (lower + upper) / 2;

		if (triangle(k, x) + triangle(n - k, x - 1) <= m)
			lower = x;
		else
			upper = x;
	}
	printf("%d\n", lower + 1);
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <math.h>
#define max(a,b) (a > b) ? a : b
#define min(a,b) (a < b) ? a : b
int main()
{
	int i,j,k,n,m,res,mid,ans;
	long long l,r;
	scanf("%d%d%d",&n,&m,&k);
	res = m - n;
	mid = (int)sqrt((double)(1+8*(double)res)) - 1;
	mid /= 2;
	if(mid == 0)
	{
		for(i = mid;i <= res;i++)
		{
			if(i > k - 1) l = (2*i-k+1)*(long long)k/2;
			else l = (1+i)*(long long)i / 2;
			if(i >= (n-k))r = (2*i-n+k)*(long long)(n-k+1)/2;
			else r = (1+i)*(long long)i/2;
			if(l+r-i > res)break;
		}
		printf("%d\n",i);
		return 0;
	}
	for(i = mid;i <= res;i += mid)
	{
		if(i > k - 1) l = (2*i-k+1)*(long long)k/2;
		else l = (1+i)*(long long)i / 2;
		if(i >= (n-k))r = (2*i-n+k)*(long long)(n-k+1)/2;
		else r = (1+i)*(long long)i/2;
		if(l+r-i > res)break;
	}
	j = i;
	for(i = j-mid;i <= j;i++)
	{
		if(i > k - 1) l = (2*i-k+1)*(long long)k/2;
		else l = (1+i)*(long long)i / 2;
		if(i >= (n-k))r = (2*i-n+k)*(long long)(n-k+1)/2;
		else r = (1+i)*(long long)i/2;
		if(l+r-i > res)break;
	}
	printf("%d\n",i);
	return 0;
}

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

int main()
{
	long long int m,  n, k, i, t;
	long long int s1=0, s2=0;
	scanf("%I64d %I64d %I64d", &n, &m, &k);
	t = m;
	for (i = m/n; i <= m; i++)
	{
		if (k >= i)
			s1 = (2*i - i + 1)*i/2 + k - i;
		else
			s1 = (2*i - k + 1)*k / 2;
		if ((n-k+1) >= i)
			s2 = (2*i - i + 1)*i / 2 + (n - k + 1) - i;
		else
			s2 = (2*i - (n - k + 1) + 1)*(n - k + 1) / 2;

		if ((s1+s2-i)> m)
		{
			t = i - 1;
			break;
		}

	}

	printf("%I64d ",t);
	return 0;
}

#include <stdio.h>

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

int main()
{
	int N,M,K;
	scanf("%d%d%d",&N,&M,&K);
	K--;
	M-=N;
	int off=1;
	int ans=1;
	// int v1,v2=0;
	while(min(N,K+off)-max(0,K-off+1)<=M)
	{
		ans++;
		M-=min(N,K+off)-max(0,K-off+1);
		if(max(0,K-off+1)==0 && min(N,K+off)==N)
			break;
		off++;
	}
	ans+=M/N;
	printf("%d",ans);
	return 0;
}

#include <stdio.h>

int check(long long n, long long m, long long k, long long f) {
	long long x = f < k ? (f * (f + 1) / 2 + k - f) : (k * (f + f - k + 1) / 2);
	long long y = f - 1 < n - k ? ((f - 1) * f / 2 + (n - k) - (f - 1)) : ((n - k) * (f - 1 + f - 1 - (n - k) + 1) / 2);

	return x + y <= m;
}

long long binsearch(int n, int m, int k) {
	long long lower = 1, upper = m + 1;

	while (upper - lower > 1) {
		long long mid = (lower + upper) / 2;

		if (check(n, m, k, mid))
			lower = mid;
		else
			upper = mid;
	}
	return lower;
}

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

	scanf("%d%d%d", &n, &m, &k);
	printf("%lld\n", binsearch(n, m, k));
	return 0;
}

#include<stdio.h>

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

int main()
{
    int n, m, k, a, cnt, l, r;
    scanf("%d %d %d", &n, &m, &k);
    if(n==1)
    {
        printf("%d\n", m);
    }
    else if(n==2)
    {
        printf("%d\n", (m/2)+(m%2));
    }
    else
    {
        m-=n;
        a=1;
        cnt=0;
        l=k-1;
        r=n-k;
        while(m>0)
        {
            a++;
            m--;
            cnt++;
            m-=mini(l, cnt);
            m-=mini(r, cnt);
        }
        printf("%d\n", a);
    }
    return 0;
}

#include<stdio.h>

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

int main()
{
    int n, m, k, a, cnt, l, r;
    scanf("%d %d %d", &n, &m, &k);
    if(n==1)
    {
        printf("%d\n", m);
    }
    else
    {
        m-=n;
        a=1;
        cnt=0;
        l=k-1;
        r=n-k;
        while(m>0)
        {
            a++;
            m--;
            cnt++;
            m-=mini(l, cnt);
            m-=mini(r, cnt);
        }
        printf("%d\n", a);
    }
    return 0;
}

#include<stdio.h>

#define pr(a) printf("%I64d ",a);

long long  scount(long long n,long long m)
{
    long long p = n-m+1;
    return ((n+p)*(n-p+1))/2;
}

int main()
{
    long long n,m,k,rez,levo,desno,range=0,br;
    scanf("%I64d%I64d%I64d",&n,&m,&k);
    desno = n-k;
    levo = n-desno-1;
    m -= n;
    rez = 1;
    if(levo>desno)
    {
        br = scount(levo+1,levo+1);
        br += scount(levo,desno);
    }
    else
    {
        br = scount(desno+1,desno+1);
        br += scount(desno,levo);
    }
    if(m>br)
    {
        rez += levo>desno?levo+1:desno+1;
        m -= br
        ;
        rez += m/n;
    }
    else if(m==br)
    {
        rez += levo>desno?levo+1:desno+1;
    }
    else
    {
        while(m)
        {
            m--;
            if(desno < range)
                if(m>=desno) m-=desno;
                else break;
            else
                if(m>=range) m-=range;
                else break;
            if(levo < range)
                if(m>=levo) m-=levo;
                else break;
            else
                if(m>=range) m-=range;
                else break;
            if(levo-range > 0 || desno-range > 0) range++;
            rez++;
        }
    }
    printf("%I64d",rez);
    return 0;
}

#include <stdio.h>

int main(void) {
	// your code goes here
	long int n,m,k;
	scanf("%ld %ld %ld",&n,&m,&k);
	long int div = m/n;
	if (div==0){
	    div = 1;
	}
	long int sum = 0;
	long int ans = div-1;
	long int l = k-1;
	long int r = n-k;
	while (sum<m){
	    sum = 0;
	    ans++;
	    if (r>ans-1){
	        sum += (((ans-1)*ans)/2) + r - (ans-1);
	    }
	    else{
	        sum += ((ans-1+ans-r)*r)/2;
	    }
	    if (l>ans-1){
	        sum += (((ans-1)*ans)/2) + l - (ans-1);
	    }
	    else{
	        sum += ((ans-1+ans-l)*l)/2;
	    }
	    sum += ans;
	    if (sum==m){
	        break;
	    }
	    else if (sum>m){
	        ans--;
	        break;
	    }
	}
    printf("%ld\n",ans);
	return 0;
}

#include<stdio.h>
int main()
{
	long n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	if(m==n)
	{
		puts("1");
		return 0;
	}
	long cnt=1,r;
	while(m>0)
	{
		if(k+cnt>=n)
		r++;
		if(k-cnt>=1)
		r++;
		m-=r;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
 }

#include<stdio.h>
long n,m,k,ans=1,Reduc_;
int main(){
    scanf("%ld%ldl%d",&n,&m,&k);
    m -= n;
    Reduc_ = 1;
    if(m == 0) return puts("1"),0;
    while(m>0){
        if(k+ans<=n)++Reduc_;
        if(k-ans>=1)++Reduc_;
        m -= Reduc_;
        ++ans;
    }
    printf("%ld\n",ans);
    return 0;
}

#include<stdio.h>
int main()
{
	long n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	if(m==n)
	{
		puts("1");
		return 0;
	}
	m-=n;
	long cnt=1,r=1;
	while(m>0)
	{
		if(k+cnt>=n)
			r++;
		if(k-cnt>=1)
			r++;
		m-=r;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
 }

#include<stdio.h>
long n,m,k,ans=1,Reduc_;
int main(){
    scanf("%ld%ldl%d",&n,&m,&k);
    m -= n;
    Reduc_ = 1;
    if(m == 0)
    {
    	puts("1");
    	return 0;
	}
    while(m>0){
        if(k+ans<=n)++Reduc_;
        if(k-ans>=1)++Reduc_;
        m -= Reduc_;
        ++ans;
    }
    printf("%ld\n",ans);
    return 0;
}

#include<stdio.h>
int main()
{
	long n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	if(m==n)
	{
		puts("1");
		return 0;
	}
	long cnt=1;
	m-=n;
	m--;
	cnt++;
	long right=n-k,left=k-1;//k的左右几个数
	//long r=right,l=left;
	while(1)
	{
		if(cnt==2)
		{
			if(k==1||k==n)
			{
				if(m<2)
					break;
				else
				{
					m-=2;
					cnt++;
				}
			}
			else
			{
				if(m<3)
				break;
				else{
					m-=3;
					cnt++;
				}
			}
		}
		else
		{
			if(m<n)
			break;
			else
			{
				m-=n;
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
 }

#include<stdio.h>
int main()
{
	long long int n,m,k,i=1,val=1;
	scanf("%I64d%I64d%I64d",&n,&m,&k);
	long long int right=k,left=k;
	m=m-n;
	while(m>=i)
	{
		val++;
		m-=i;
		if(left>1);
		{
		left--;
		i++;
	}
	if(right<n)
	{
		right++;
		i++;
	}
	if(left==1 && right==n)
	{
		val=val+m/n;
		break;
	}
	}
	printf("%I64d",val);
}

#include<stdio.h>
int main()
{
	long long int n,m,k,i=1,val=1;
	scanf("%I64d%I64d%I64d",&n,&m,&k);
	long long int right=k,left=k;
	m=m-n;
	while(m>=i)
	{
		val++;
		m-=i;
		if(left>1);
		{
		left--;
		i++;
	}
	if(right<n)
	{
		right++;
		i++;
	}
	if(left==1 && right==n)
	{
		val=val+n/m;
		break;
	}
	}
	printf("%I64d",val);
}

#include <stdio.h>

typedef unsigned long long UINT64;

int main(void) {
    UINT64 n = 0, m = 0, k = 0;
    UINT64 x = 0, r = 0;

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

    x = 2 * m + (k * (k - 1)) + (n - k) * (n - k + 1);
    r = 2 * n;

    if (x % r == 0) {
        x = x / r - 1;
    } else {
        x /= r;
    }

    printf("%llu\n", x);

    return 0;
}

#include <stdio.h>

typedef unsigned long long UINT64;

int main(void) {
    UINT64 n = 0, m = 0, k = 0;
    UINT64 x = 0;

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

    x = 2 * m + (k * (k - 1)) + (n - k) * (n - k + 1);
    x /= 2 * n;

    printf("%llu\n", x);

    return 0;
}

#include <stdio.h>

typedef unsigned long long UINT64;

int main(void) {
    UINT64 n = 0, m = 0, k = 0;
    UINT64 x = 0, r = 0;

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

    x = 2 * m + (k * (k - 1)) + (n - k) * (n - k + 1);
    r = 2 * n;

    if (x % r == 0) {
        x = x / r - 1;
    }

    printf("%llu\n", x);

    return 0;
}

#include <stdio.h>

typedef unsigned long long UINT64;

int main(void) {
    UINT64 i = 0;
    UINT64 n = 0, m = 0, k = 0;
    UINT64 x = 0, r = 0;

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

    x = 2 * m + (k * (k - 1)) + (n - k) * (n - k + 1);
    x /= 2 * n;

    while (x < k - i) {
        x--;
        i++;
        if (x <= 0) {
            x = 1;
            break;
        }
    }

    printf("%llu\n", x);

    return 0;
}

#include <stdio.h>

typedef unsigned long long UINT64;

int main(void) {
    UINT64 n = 0, m = 0, k = 0;
    UINT64 x = 0, r = 0;

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

    x = 2 * m + (k * (k - 1)) + (n - k) * (n - k + 1);
    r = 2 * n;

    if (x % r == 0) {
        x /= r;
        if (k - 1 == x || n - k == x) {
            x--;
        }
    } else {
        x /= r;
    }

    printf("%llu\n", x);

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <math.h>
#define max(a,b) (a > b) ? a : b
#define min(a,b) (a < b) ? a : b
int main()
{
	int i,j,k,n,m,l,r,res,mid,ans;
	scanf("%d%d%d",&n,&m,&k);
	res = m - n;
	mid = (int)sqrt(1+8*res) - 1;
	mid /= 2;
	for(i = mid;i <= res;i++)
	{
		if(i > k - 1) l = (2*i-k+1)*k/2;
		else l = (1+i)*i / 2;
		if(i >= (n-k))r = (2*i-n+k)*(n-k+1)/2;
		else r = (1+i)*i/2;
		if(l+r-i > res)break;
	}
	printf("%d\n",i);
	return 0;
}

#include<stdio.h>

long long  scount(long long x,long long y)
{
    long long i,sum=0;
    for(i=0;i<y;i++);
        sum += x--;
    return sum;
}

int main()
{
    long long n,m,k,rez,levo,desno,range=0,br;
    scanf("%I64d%I64d%I64d",&n,&m,&k);
    desno = n-k;
    levo = n-desno-1;
    m -= n;
    rez = 1;
    if(levo>desno)
    {
        br = scount(levo+1,levo+1);
        br += scount(levo+1,desno);

    }
    else if(desno>levo)
    {
        br = scount(desno+1,desno+1);
        br += scount(desno+1,levo);
    }
      if(m>br)
        {
            rez += m/br;
            m = m%br;
        }
    while(m)
    {
        m--;
        if(desno < range)
            if(m>=desno) m-=desno;
            else break;
        else
            if(m>=range) m-=range;
            else break;
        if(levo < range)
            if(m>=levo) m-=levo;
            else break;
        else
            if(m>=range) m-=range;
            else break;
        if(levo-range > 0 || desno-range > 0) range++;
        rez++;
    }
    printf("%I64d",rez);
    return 0;
}

#include<stdio.h>

long long  scount(long long n,long long m)
{
    return n*(n+1)/2 - m*(m-1)/2;
}

int main()
{
    long long n,m,k,rez,levo,desno,range=0,br;
    scanf("%I64d%I64d%I64d",&n,&m,&k);
    desno = n-k;
    levo = n-desno-1;
    m -= n;
    rez = 1;
    if(levo>desno)
    {
        br = scount(levo+1,levo);
        br += scount(levo+1,desno-1);
    }
    else
    {
        br = scount(desno+1,desno);
        br += scount(desno+1,levo-1);
    }

    if(br<=m)
    {
        rez += levo>desno?levo+1:desno+1;
        m-=br;
        rez += m/n;
        m = m%n;
        range = levo>desno?levo:desno;
    }
    while(m)
    {
        m--;
        if(desno < range)
            if(m>=desno) m-=desno;
            else break;
        else
            if(m>=range) m-=range;
            else break;
        if(levo < range)
            if(m>=levo) m-=levo;
            else break;
        else
            if(m>=range) m-=range;
            else break;
        if(levo-range > 0 || desno-range > 0) range++;
        rez++;
    }
    printf("%I64d",rez);
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

long long n, m, k, ans, layer_left = 0, layer_right = 0;
long long left_dist, right_dist, l, r;

void add_layer()
{
	if (left_dist > layer_left)
	{
		m -= layer_left;
		layer_left++;
	}
	else
		m -= layer_left;

	if (right_dist > layer_right)
	{
		m -= layer_right;
		layer_right++;
	}
	else
		m -= layer_right;

	m -= 1;
}

int main()
{
	scanf("%I64d %I64d %I64d", &n, &m, &k);
	l = k - 1, r = n - k;
	m -= n;

	/*while (m >= layer_left + layer_right + 1)
	{
		if (layer_left == left_dist && layer_right == right_dist)
		{

		}
		add_layer();
		ans++;
	}*/

	ans = (m + (r + 1) * r / 2 + (l + 1) * l / 2) / n;

	printf("%I64d", ans + 1);
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

long long n, m, k, ans, layer_left = 0, layer_right = 0;
long long left_dist, right_dist, l, r;

void add_layer()
{
	if (left_dist > layer_left)
	{
		m -= layer_left;
		layer_left++;
	}
	else
		m -= layer_left;

	if (right_dist > layer_right)
	{
		m -= layer_right;
		layer_right++;
	}
	else
		m -= layer_right;

	m -= 1;
}

int main()
{
	scanf("%I64d %I64d %I64d", &n, &m, &k);
	l = k - 1, r = n - k;
	//m -= n;

	/*while (m >= layer_left + layer_right + 1)
	{
		if (layer_left == left_dist && layer_right == right_dist)
		{

		}
		add_layer();
		ans++;
	}*/

	ans = (m + (r + 1) * r / 2 + (l + 1) * l / 2) / n;

	printf("%I64d", ans);
}

#include <stdio.h>
#include <string.h>
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	m-=n;
    int l=k,r=k,ans=1;
     while(m-(r-l+1)>0&&(l!=1||r!=n)){
     	ans++;
        m-=(r-l+1);
        if(l>1)
        	l--;
        if(r<n)
        	r++;
     }
     if(m>0)
     	ans+=(m/n);
     printf("%d\n",ans);
	return 0;
}

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

int main(){
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  k=((n-k+1)>k)?(n-k+1):k;
  int y=n-k;
  long long x,ans=0;
  x= (long long)(k*(k+1))/2 + (long long)((y*(y+1))/2);
  if(m>=x)
    ans=k + (m-x)/n;
  else
    ans= (m-1)/n + 1;
     printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
long long m,n,k;
int judge(long long x)
{
    long long ans;
    if(m==k)
       ans=(x+x-(k-1))*k/2;
    else if (k==1)
        ans=(x+x-(n-k))*(n-k+1)/2;
    else
        ans=(x+x-(k-1))*k/2+(x+x-(n-k))*(n-k+1)/2-x;
    if (ans==m)
    {
        printf("%lld\n",x);
        exit(0);
    }
    if (ans<m)
        return (1);
    else
        return (0);
}
int main ()
{
    scanf("%lld%lld%lld",&n,&m,&k);
    long long x,top,bot;
    top=(m-n+1);
    bot=1;
    x=(bot+top)/2;
    if (top-1==bot)
    {
        printf("2\n");
        exit(0);
    }
    while (top-1>bot)
    {
        if (judge(x)==1)
            bot=x;
        else
            top=x;
        x=(bot+top)/2;
    }
    printf("%lld\n",bot);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
long long m,n,k;
int judge(long long x)
{
    long long ans;
    if(m==k)
       ans=(x+x-(k-1))*k/2;
    else if (k==1)
        ans=(x+x-(n-k))*(n-k+1)/2;
    else
        ans=(x+x-(k-1))*k/2+(x+x-(n-k))*(n-k+1)/2-x;
    if (ans==m)
    {
        printf("%lld\n",x);
        exit(0);
    }
    if (ans<m)
        return (1);
    else
        return (0);
}
int main ()
{
    scanf("%lld%lld%lld",&n,&m,&k);
    long long x,top,bot;
    top=(m-n+1);
    bot=1;
    x=(bot+top)/2;
    if (top-1==bot)
    {
        printf("2\n");
        exit(0);
    }
    if (n==1)
    {
        printf("%lld\n",m);
        exit(0);
    }
    while (top-1>bot)
    {
        if (judge(x)==1)
            bot=x;
        else
            top=x;
        x=(bot+top)/2;
    }
    printf("%lld\n",bot);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
long long m,n,k;
int judge(long long x)
{
    long long ans;
    if(m==k)
       ans=(x+x-(k-1))*k/2;
    else if (k==1)
        ans=(x+x-(n-k))*(n-k+1)/2;
    else
        ans=(x+x-(k-1))*k/2+(x+x-(n-k))*(n-k+1)/2-x;
    if (ans==m)
    {
        printf("%lld\n",x);
        exit(0);
    }
    if (ans<m)
        return (1);
    else
        return (0);
}
int main ()
{
    scanf("%lld%lld%lld",&n,&m,&k);
    long long x,top,bot;
    top=(m-n+1);
    bot=1;
    x=(bot+top)/2;
    while (top-1>bot)
    {
        if (judge(x)==1)
            bot=x;
        else
            top=x;
        x=(bot+top)/2;
    }
    printf("%lld\n",top-1);
    return 0;
}

#include<stdio.h>
int m,n,k;
int judge(int x)
{
    int ans;
    if(m==k)
       ans=(x+x-(k-1))*k/2;
    else if (k==1)
        ans=(x+x-(n-k))*(n-k+1)/2;
    else
        ans=(x+x-(k-1))*k/2+(x+x-(n-k))*(n-k+1)/2-x;
    if (ans<=m)
        return (1);
    else
        return (0);
}
int main ()
{
    scanf("%d%d%d",&n,&m,&k);
    int x,top,bot;
    top=(m-n+1);
    bot=1;
    x=(bot+top)/2;
    while (top>bot)
    {
        if (judge(x)==1)
            bot=x+1;
        else
            top=x-1;
        x=(bot+top)/2;
    }
    printf("%d\n",bot-1);
    return 0;
}

#include <stdio.h>
int main() {
unsigned long long int m,n,k,x,y,a,b;
unsigned long long int s;
scanf("%llu",&n);
scanf("%llu",&m);
scanf("%llu",&k);
a=0;
b=m;
x=(a+b)/2;
while (1)
{
    s=0;
    y=k-1;
    if(y>x-1)
        s+= y -(x-1) +x*(x-1)/2;
    else
        s+= (x-1+x-y)*y/2;
    y=n-k;
    if(y>x-1)
        s+= y -(x-1) +x*(x-1)/2 +x;
    else
        s+= (x-1+x-y)*y/2 +x;
        if (x==0) s=0;
        printf("%llu %llu \n",x,s);
    if (s==m||b<a)
    {
        printf("%llu",x); break;
    }
    else
    {
        if (s>m)
        {

            b=x-1;
            x=(a+b)/2;
        }
        else
        {
            a=x+1;
            x=(a+b)/2;
        }
    }
}
}

/* Coached by Dukkha */
#include <stdio.h>

int triangle(int k, int x) {
	return (x + x - k + 1) / 2 * k;
}

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

	scanf("%d%d%d", &n, &m, &k);
	lower = -1, upper = m;
	while (upper - lower > 1) {
		int x = (lower + upper) / 2;

		if (triangle(k, x) + triangle(n - k, x - 1) <= m)
			lower = x;
		else
			upper = x;
	}
	printf("%d\n", lower);
	return 0;
}

/* Coached by Dukkha */
#include <stdio.h>

long long triangle(int k, int x) {
	return (long long) (x + x - k + 1) * k / 2;
}

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

	scanf("%d%d%d", &n, &m, &k);
	m -= n;
	lower = 0, upper = m + 1;
	while (upper - lower > 1) {
		int x = (lower + upper) / 2;

		if (triangle(k, x) + triangle(n - k, x - 1) <= m)
			lower = x;
		else
			upper = x;
	}
	printf("%d\n", lower + 1);
	return 0;
}

/* Coached by Dukkha */
#include <stdio.h>

long long triangle(int k, int x) {
	return (long long) (x + x - k + 1) * k / 2;
}

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

	scanf("%d%d%d", &n, &m, &k);
	lower = 0, upper = m + 1;
	while (upper - lower > 1) {
		int x = (lower + upper) / 2;

		if (triangle(k, x) + triangle(n - k + 1, x) - x <= m)
			lower = x;
		else
			upper = x;
	}
	printf("%d\n", lower);
	return 0;
}

/* Coached by Dukkha */
#include <stdio.h>

long long triangle(int k, int x) {
	return (long long) (x + x - k + 1) * k / 2;
}

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

	scanf("%d%d%d", &n, &m, &k);
	lower = 0, upper = m + 1;
	while (upper - lower > 1) {
		int x = (lower + upper) / 2;

		if (triangle(k, x) + triangle(n - k, x - 1) <= m)
			lower = x;
		else
			upper = x;
	}
	printf("%d\n", lower);
	return 0;
}

/* Coached by Dukkha */
#include <stdio.h>

long long triangle(int k, int x) {
	return (long long) (x + x - k + 1) * k / 2;
}

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

	scanf("%d%d%d", &n, &m, &k);
	lower = -1, upper = m;
	while (upper - lower > 1) {
		int x = (lower + upper) / 2;

		if (triangle(k, x) + triangle(n - k, x - 1) <= m)
			lower = x;
		else
			upper = x;
	}
	printf("%d\n", lower);
	return 0;
}


#include <stdio.h>

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

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

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

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

    return 0;
}

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

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

void popuniSve() {
    int i,j;

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

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

int main() {
    int i,j;

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

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

/* Teng K. J. */

#include <stdio.h>

#define N 9
char map[N][N];

void fill(int i, int j) {
	int r = i * 3;
	int c = j * 3;
	int re = r + 3, ce = c + 3;
	while (r < re) {
		c = j * 3;
		while (c < ce) {
			if (map[r][c] == '.') {
				map[r][c] = '!';
			}
			c++;
		}
		r++;
	}
}

int check(int i, int j) {
	int r = i * 3;
	int c = j * 3;
	int re = r + 3, ce = c + 3;
	while (r < re) {
		c = j * 3;
		while (c < ce) {
			if (map[r][c] == '.') {
				return 1;
			}
			c++;
		}
		r++;
	}
	return 0;
}

int main() {
	int i, j, r, c;

	for (i = 0; i < N; ++i) {
		for (j = 0; j < N; ++j) {
			map[i][j] = getchar();
			if (j % 3 == 2) getchar();
		}
		if (i % 3 == 2 && i != 8) getchar();
	}
	scanf("%d%d", &i, &j);
	r = (i - 1) % 3;
	c = (j - 1) % 3;

	if (check(r, c)) {
		fill(r, c);
	} else {
		for (i = 0; i < 3; ++i) {
			for (j = 0; j < 3; ++j) {
				fill(i, j);
			}
		}
	}

	for (i = 0; i < N; ++i) {
		for (j = 0; j < N; ++j) {
			putchar(map[i][j]);
			if (j % 3 == 2) putchar(j == 8 ? '\n' : ' ');
		}
		if (i % 3 == 2 && i != 8) putchar('\n');
	}

	return 0;
}

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define eps 1e-4
#define PI acos(-1.0)
char s[10][15];
int sti[4]={0,1,4,7},eni[4]={0,3,6,9};
int stj[4]={0,0,4,8},enj[4]={0,2,6,10};
void printall2()
{
	for (int i=1;i<=9;i++)
	{
		for (int j=0;j<=10;j++)
			if (s[i][j]=='.') printf("!");
			else printf("%c",s[i][j]);
		printf("\n");
		if (!(i%3)) printf("\n");
	}
}
void printall1()
{
	for (int i=1;i<=9;i++)
	{
		for (int j=0;j<=10;j++)
			printf("%c",s[i][j]);
		printf("\n");
		if (!(i%3)&&i!=9) printf("\n");
	}
}
int main()
{
	for (int i=1;i<=3;i++) gets(s[i]);
	gets(s[0]);
	for (int i=4;i<=6;i++) gets(s[i]);
	gets(s[0]);
	for (int i=7;i<=9;i++) gets(s[i]);
	int n,m;
	scanf("%d%d",&n,&m);
	n%=3; m%=3;
	if (!n) n=3;
	if (!m) m=3;
	int flag=0;
	for (int i=sti[n];i<=eni[n];i++)
		for (int j=stj[m];j<=enj[m];j++)
			if (s[i][j]=='.')
			{
				flag++;
				s[i][j]='!';
			}
	if (flag) printall1();
	else printall2();
	return 0;
}

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

int Map[10][10], i, j, x, y, b;
char c;

int ctoint(char a)
{
    switch (a)
    {
        case '.' : return 0; break;
        case 'x' : return 1; break;
        case 'o' : return 2; break;
        case '!' : return 3; break;
    }
    return -1;
}

char inttoc(int a)
{
    switch (a)
    {
        case 0 : return '.'; break;
        case 1 : return 'x'; break;
        case 2 : return 'o'; break;
        case 3 : return '!'; break;
    }
    return 0;
}

int main()
{
    for (i = 1; i <= 9; i++)
    {
        for (j = 1; j <= 9; j++)
        {
            scanf("%c", &c);
            Map[i][j] = ctoint(c);
            if (j % 3 == 0) scanf("%c", &c);
        }
        if ((i % 3 == 0) && (i != 9)) scanf("\n");
    }
    scanf("%d %d", &x, &y);

    while (x > 3) x -= 3;
    while (y > 3) y -= 3;

    b = 0;

    for (i = x*3 - 2; i <= x*3; i++)
        for(j = y*3 - 2; j <= y*3; j++)
            if (Map[i][j] == 0)
            {
                Map[i][j] = 3;
                b = 1;
            }

    if (!b)
    {
        for (i = 1; i <= 9; i++)
            for (j = 1; j <= 9; j++)
                if (Map[i][j] == 0) Map[i][j] = 3;
    }

    for (i = 1; i <= 9; i++)
    {
        for (j = 1; j <= 9; j++)
        {
            printf("%c", inttoc(Map[i][j]));
            if ((j % 3 == 0) && (j != 9)) printf(" ");
            if (j == 9) printf("\n");
        }
        if ((i % 3 == 0) && (i != 9)) printf("\n");
    }
    return 0;
}

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

int main(void)
{
    char input[9][9];
    int lastChip[2];

    int i, j;
    int isCellAvailable=0;

    for(i=0; i<9; i++)
    {
        for(j=0; j<9; j++)
        {
            scanf("%c", &input[i][j]);
            if(input[i][j]==' ' || input[i][j]=='\n')
            {
                j--;
            }
        }
    }

    scanf("%d %d", &lastChip[0], &lastChip[1]);

    lastChip[0]--;
    lastChip[1]--;

    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            if(input[(lastChip[0]%3*3)+i][(lastChip[1]%3*3)+j]=='.')
            {
                input[(lastChip[0]%3*3)+i][(lastChip[1]%3*3)+j]='!';
                isCellAvailable=1;
            }
        }
    }

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

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

    return 0;
}

#include <stdio.h>

int main() {
    char field[9][9]; int x,y;
    for(int i = 0 ; i < 9 ; ++i) for(int j = 0 ; j < 9 ; j += 3) scanf(" %c%c%c ", &field[i][j+0], &field[i][j+1], &field[i][j+2]);
    scanf("%d %d\n", &x, &y); --x, --y; int fr = x%3, fc = y%3;

    int free_count = 0;
    for(int i = 0, ii = fr*3 ; i < 3 ; ++i, ++ii) for(int j = 0, jj = fc*3 ; j < 3 ; ++j, ++jj) {
        free_count += field[ii][jj] == '.' ? 1 : 0;
    }

    const int rs = free_count ? fr*3 : 0, rc = free_count ? 3 : 9, cs = free_count ? fc*3 : 0, cc = free_count ? 3 : 9;
    for(int i = 0, ii = rs ; i < rc ; ++i, ++ii) for(int j = 0, jj = cs ; j < cc ; ++j, ++jj)
        if(field[ii][jj] == '.') field[ii][jj] = '!';

    for(int i = 0 ; i < 9 ; ++i) {
        for(int j = 0 ; j < 9 ; j += 3)
            printf("%c%c%c%c", field[i][j+0], field[i][j+1], field[i][j+2], j == 6 ? '\n' : ' ');
        if(i % 3 == 2) printf("\n");
    }

    return 0;
}

#include <stdio.h>
int main(int argc, char const *argv[])
{
    char field[9][3][5];
    for (int i = 0; i < 9; i+=3)
    {
        for (int j = 0; j < 3; ++j)
        {
            scanf("%s",field[i][j]);
            scanf("%s",field[i+1][j]);
            scanf("%s",field[i+2][j]);
        }

    }
    int cur_x,cur_y,field_x,field_y,field_pos;
    scanf("%d%d",&cur_x,&cur_y);
    cur_x-=1;
    cur_y-=1;
    field_x=(cur_x%3);//0 is top,1 is middle ,2 is down
    field_y=(cur_y%3);//0 is left,1 is mid, 2 is right
    field_pos=field_x*3+field_y;
    int flag=0;//1 is this field ok
    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            if (field[field_pos][i][j]=='.')
            {
                field[field_pos][i][j]='!';
                flag=1;
            }
        }
    }

    // printf("%d\n",field_pos);
    if (flag==0)
    {
        for (int i = 0; i < 9; ++i)
        {
            for (int k = 0; k < 3; ++k)
            {
                for (int j = 0; j < 3; ++j)
                {
                    if (field[i][k][j]=='.')
                    {
                        field[i][k][j]='!';
                    }
                }
            }
        }
    }

    //print table
    for (int i = 0; i < 9; i+=3)
    {
        for (int j = 0; j < 3; ++j)
        {
            printf("%s ",field[i][j]);
            printf("%s ",field[i+1][j]);
            printf("%s\n",field[i+2][j]);
        }
        printf("\n");
    }
    return 0;
}

//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int i,j,k,x,y,a[262144],f=0;
    char s[16][4][4];
    for(i=1;i<=9;i++){
        for(j=1;j<=3;j++){scanf("%s",s[i][j]);}
        //printf("%s\n",s[i][3]);
    }
    scanf("%d%d",&x,&y);
    x%=3;y%=3;
    if(x==0){x=3;}
    if(y==0){y=3;}
    for(i=3*x-2;i<=3*x;i++){
            for(k=0;k<3;k++){if(s[i][y][k] == '.'){f=1;s[i][y][k]='!';}}
    }
    for(i=1;i<=9;i++){
        if(f==1){break;}
        for(j=1;j<=3;j++){
            for(k=0;k<3;k++){if(s[i][j][k] == '.'){s[i][j][k]='!';}}
        }
    }
    for(i=1;i<=9;i++){
            for(k=1;k<=3;k++){printf("%s",s[i][k]);if(k==3){printf("\n");}else{printf(" ");}}
        if(i%3==0){printf("\n");}
    }
    return 0;
}

/* Teng K. J. */

#include <stdio.h>

#define N 9
char map[N][N];

void fill(int i, int j) {
	int r = i * 3;
	int c = j * 3;
	int re = r + 3, ce = c + 3;
	while (r < re) {
		c = j * 3;
		while (c < ce) {
			if (map[r][c] == '.') {
				map[r][c] = '!';
			}
			c++;
		}
		r++;
	}
}

int check(int i, int j) {
	int r = i * 3;
	int c = j * 3;
	int re = r + 3, ce = c + 3;
	while (r < re) {
		while (c < ce) {
			if (map[r][c] == '.') {
				return 1;
			}
			c++;
		}
		r++;
	}
	return 0;
}

int main() {
	int i, j, r, c;

	for (i = 0; i < N; ++i) {
		for (j = 0; j < N; ++j) {
			map[i][j] = getchar();
			if (j % 3 == 2) getchar();
		}
		if (i % 3 == 2 && i != 8) getchar();
	}
	scanf("%d%d", &i, &j);
	r = (i - 1) % 3;
	c = (j - 1) % 3;

	if (check(r, c)) {
		fill(r, c);
	} else {
		for (i = 0; i < 3; ++i) {
			for (j = 0; j < 3; ++j) {
				fill(i, j);
			}
		}
	}

	for (i = 0; i < N; ++i) {
		for (j = 0; j < N; ++j) {
			putchar(map[i][j]);
			if (j % 3 == 2) putchar(j == 8 ? '\n' : ' ');
		}
		if (i % 3 == 2 && i != 8) putchar('\n');
	}

	return 0;
}