semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int x[1000], y[1000], i, j=0;
	scanf("%d%d", &x[0], &y[0]);
	while(y[j]!=1)
	{
        j=j+1;
		y[j]=y[j-1]/2;
	}
	j=0;i=0;
	while (x[i]<y[j]) j++;
	while (x[i]!=y[j])
	{
		i=i+1;
		x[i]=x[i-1]/2;
        while (x[i]<y[j]) j++;
	}
    printf("%d\n",x[i]);
	return 0;
}
int f(int p)
{
	if(p==1) p=-1;
	if(p%2==0) p=0;
	if(p%2==1) p=1;
	return(p);
}

void main()
{
	int x,y,n,i,a[1000],b[1000],k,j;
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
	for(i=0; ;i++)
	{
		if(f(a[i])==-1) {k=i;break;}
		if(f(a[i])==0) a[i+1]=a[i]/2;
		if(f(a[i])==1) a[i+1]=(a[i]-1)/2;			
	}
	for(i=0; ;i++)
	{
		if(f(b[i])==-1) {j=i;break;}
		if(f(b[i])==0) b[i+1]=b[i]/2;
		if(f(b[i])==1) b[i+1]=(b[i]-1)/2;			
	}
	if(k<j)
		n=k;
	else
		n=j;
	for(i=0;i<=n;i++)
	{
		if(a[k-i]!=b[j-i])
		{
			printf("%d\n",a[k-i+1]);
			break;
		}
		
	}
	if(i==n+1)
		printf("%d\n",a[k-n]);
	
}
int work( int m,int n )
{    while ( m != n )   
       { if( m > n ) m /= 2;
        if( m < n  ) n /= 2;
        }
        printf("%d",m);
     
} 
int main()
{   int a , b,m;
    scanf("%d %d",&a,&b);
    work(a,b);

}
int f(int t)
{
	int c=0;
	if(t==0)
		c=1;
	if(t>0)
		c=f(t-1)*2;
	return c;
}
void main()
{
	int i,a[11],b[11],m,n,x,y;
	scanf("%d%d",&x,&y);
	for(i=0;i<11;i++)
	{
		if((x>=f(i))&&(x<f(i+1)))
		{
			a[i]=x-f(i)+1;
			n=i;
		}
	}
	for(i=n;i>0;i--)
	{
		if(a[i]%2==0)
			a[i-1]=a[i]/2;
		else a[i-1]=a[i]/2+1;
	}
	for(i=0;i<11;i++)
	{
		if((y>=f(i))&&(y<f(i+1)))
		{
			b[i]=y-f(i)+1;
			m=i;
		}
	}
	for(i=m;i>0;i--)
	{
		if(b[i]%2==0)
			b[i-1]=b[i]/2;
		else b[i-1]=b[i]/2+1;
	}
	if(x==y)
		printf("%d",x);

	if(m<n)
		m=n;
	for(i=0;i<=m;i++)
	{
		if(a[i]!=b[i])
		{
			printf("%d",f(i-1)+a[i-1]-1);
			break;
		}
	}
}
int main()
{
    int m,n,i,j,t,s;
    scanf("%d%d",&m,&n);
    s=0;
    for (i=1;i<=10;i++)
    {
        t=n;
        for(j=1;j<=10;j++)
        {
                          if (m==t) {printf("%d",m);s=2;break;}
                          t=t/2; 
                          
        }
        if (s==2) break;
        m=m/2;
    }

    return 0;
}
int tree(int num,int a)
{
	int back;
	if(a==1)
		back=num;
	else if(tree(num,a-1)%2==0)
		back=tree(num,a-1)/2;
	else back=(tree(num,a-1)-1)/2;
	return back;
}
int main()
{
	int x,y;
	int i,j;
	scanf("%d%d",&x,&y);
	for(i=1;tree(x,i)>0;i++)
		for(j=1;tree(y,j)>0;j++)
			if(tree(x,i)==tree(y,j))
			{
				printf("%d",tree(x,i));
				return 0;
			}
		printf("error");
		return 0;
}
int main()
{
	int x,y,i,j,s,t,v=0;
	int a[1000],b[1000];
	scanf("%d%d",&x,&y);
	for(i=0;x!=0;i++)
	{
		a[i]=x;
		x=x/2;
	}
	s=i;
	for(i=0;y!=0;i++)
	{
		b[i]=y;
		y=y/2;
	}
	t=i;
	for(i=0;i<s;i++)
	{
		for(j=0;j<t;j++)
		{
			if(a[i]==b[j])
			{
                v=1;
				break;
			}
		}
		if(v==1)
		{
			printf("%d",a[i]);
			break;
		}

	}
	return 0;
}
void main()
{
	int x, y, a[10]={0}, b[10]={0}, i, j, t;
	int *px, *py;
	void tree(int x, int *p);

	scanf("%d%d", &x, &y);

	px = a;
	py = b;
	tree(x, px);
	tree(y, py);
	t = 0;
	for(i=0; i<10; i++)
	{
		for(j=0; j<10; j++)
		{
			if(a[i]==b[j])
			{
				printf("%d", a[i]);
				t = 1;
				break;
			}
		}
		if(t == 1)
		     break;
	}

}

void tree(int x, int *p)
{
	int i;
	for(i=0; ; i++, p++)
	{
		*p = x;
		if(x!=1)
		{
			if(x%2 == 1)
				x = (x-1)/2;
			else
				x = x/2;
		}
		else
			break;
	}
}
int main()
{
      int m,n,i,j,y,k;
      scanf("%d %d",&m,&n);
      if(m==n)
        printf("%d",m);
      else
         {
           if(m<n)
            {
             i=m;
             m=n;
             n=i;
             }
           y=m;
		   k=n;
            for(i=0;i<100;i++)
                {			
                   y/=2;
                    if(y==k)
                    {
                       printf("%d",y);
                       break;
                    }
                    else
                     for(j=0;k>1;j++) 
                        {
                        k/=2;
                          if(y==k)
		      {printf("%d",y);
			 i=100;
                              break;}
		       }			    
                      if(k==1)
                          k=n;
                       
                }
}
}
main()
{
int x,y,i,j,m,n;
static int a[16];
static int b[16];
a[0]=10000;
b[0]=20000;
scanf("%d %d",&x,&y);
a[1]=x;
b[1]=y;
for(i=2;x>1;i++)
  { a[i]=x/2;
   x=x/2;}
m=i-1;
for(j=2;y>1;j++)
  { b[j]=y/2;
    y=y/2;}
n=j-1;
do{
    if(a[m]==b[n])
     m--;
     n--;
   }while(a[m]==b[n]);
printf("%d",a[m+1]);
}
/*
 * ditui2.cpp
 *   ???
 *  Created on: 2010-11-20
 *      Author: ???
 */

int main(){
	int x[1002],y[1002];                //???????
	int i,j,lengthx=0,lengthy=0,c=0;    //lengthx,lengthy??x?y??????c????????
	cin>>x[0]>>y[0];
	for(i=1;i<=1002;i++)
		{x[i]=x[i-1]/2;
		lengthx++;
		if(x[i]==0)  break;
		}
	for(i=1;i<=1002;i++)
		{y[i]=y[i-1]/2;
		lengthy++;
		if(y[i]==0)  break;
		}
	for(i=0;i<=lengthx-1;i++)
		{for(j=0;j<=lengthy-1;j++)
			if(x[i]==y[j])
				{c=x[i];break;}
		if(c!=0) break;
		}
	cout<<c;
	return 0;
}
int main()
{
	int a[10],b[10];
	int x,y,i,j,t;
	scanf("%d %d",&x,&y);
	if(x<y)
	{
        t=x;x=y;y=t;
	}
	for(i=0;i<10;i++)
	{
		a[i]=x;x/=2;
	}
	for(j=0;j<10;j++)
	{
		b[j]=y;y/=2;
	}
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(a[i]==b[j])
			{
				printf("%d\n",a[i]);
				return 0;
			}
		}
	}
	return 0;
}
int main()

{
	int x,y;
	scanf("%d %d",&x,&y);
	while(x!=y)
	{
		if(x>y && x%2==0){
			x=x/2;}
		else if(x>y && x%2!=0){
			x=(x-1)/2;}
		else if(y>x && y%2==0){
			y=y/2;}
		else if(y>x && y%2!=0){
			y=(y-1)/2;}
	}
	printf("%d",x);
	return 0;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int i,j,a[20]={n},b[20]={m};
	for(i=1;i<20;i++)
	{
		if(n==1)
			break;
		a[i]=n/2;
		n=n/2;
	}
	for(i=1;i<20;i++)
	{
		if(m==1)
			break;
		b[i]=m/2;
		m=m/2;
	}
	for(i=0;i<20;i++)
	{
		for(j=0;j<20;j++)
		{
			if(a[i]==b[j])
			{
				printf("%d\n",a[i]);
				return 0;
			}
		}
	}





	
	return 0;
}
int main()
{
	int a,b,c[11],d[11],n1=1,n2=1;
	int i,j,flag=0;
	scanf("%d %d",&a,&b);
	c[0]=a;
	d[0]=b;
	for(i=0;i<11;i++)
	{
		if(c[i]==1)
			break;
		if(c[i]%2==0)
			c[i+1]=c[i]/2;
		else
			c[i+1]=(c[i]-1)/2;
		n1+=1;
	}
	for(i=0;i<11;i++)
	{
		if(d[i]==1)
			break;
		if(d[i]%2==0)
			d[i+1]=d[i]/2;
		else
			d[i+1]=(d[i]-1)/2;
		n2+=1;
	}
	for(i=0;i<n1;i++)
	{
		for(j=0;j<n2;j++)
		{
			if(c[i]==d[j])
			{
				printf("%d",c[i]);
				flag=1;
				break;
			}
		}
		if(flag==1)
			break;
	}
	return 0;
}
int main()
{
	int a,b,i,j,k;
	cin>>a>>b;//?????
	int m[20];
	m[0]=a;m[10]=b;
	for(i=1;i<10;i++)
		m[i]=m[i-1]/2;//a?1???
	for(i=11;i<20;i++)
		m[i]=m[i-1]/2;//b?1???
	for(i=0;i<20;i++)
		for(j=i+1;j<20;j++)
			if(m[j]>m[i])
			{
				k=m[j];m[j]=m[i];m[i]=k;//???????????
			}
	for(i=0;i<20;i++)
		if(m[i]==m[i+1])
			{cout<<m[i];break;}//???????
	return 0;
}
int main()
{int x,y,i,t,j;
cin>>x>>y;
int a[100],b[100];
t=x;
a[0]=x;
for(i=1;t/2>0;i++)
	{a[i]=t/2;t=t/2;}
     a[i]=1;
     t=y;
     b[0]=y;
for(j=1;t/2>0;j++)
    {b[j]=t/2;t=t/2;}
     b[j]=1;
for(;;)
{if(i==-1)
	{cout<<a[0];break;}
 if(j==-1)
	 {cout<<b[0];break;}
if(a[i]!=b[j])
{cout<<a[i+1]<<endl;break;}
else {i--;j--;}}
	return 0;}
int main(int argc, char* argv[])
{

	int x,y,a[1002],b[1002],i,j,m;
	scanf("%d%d",&x,&y);
	for (i=0;x>0;i++)
	{
		a[i]=x;
		x=x/2;
	}
	for (j=0;y>0;j++)
	{
		b[j]=y;
		y=y/2;
	}
		if(i>j)
	{
	for(m=0;m<j;m++)
	{
		if(a[i-j]==b[m])
			break;
		i++;
	}
	printf("%d",b[m]);
	}
	else 
	{
	for(m=0;m<i;m++)
	{
		if(a[m]==b[j-i])
			break;
		j++;
	}
	printf("%d",a[m]);
	}
	
	
		return 0;
	
	}
void main()
{
	int x,y,i,count1,count2;
	int a[20],b[20];
	scanf("%d%d",&x,&y);
	for(count1=0;x!=0;count1++)
	{
		a[count1]=x;
		x/=2;
	}
	for(count2=0;y!=0;count2++)
	{
		b[count2]=y;
		y/=2;
	}
	i=0;
	do
	{
		i++;
	}while(a[count1-i]==b[count2-i]);
	printf("%d",a[count1-i+1]);
}
int a,b,c,d,e,h,i,j,k;
int main()
{
	int cha(int a,int b);
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",cha(a,b));
	
	return 0;
}

int cha(int a,int b)
{
	if(a==b)
		return a;
	int t,q;
	if(a>b)
	{t=a;a=b;b=t;}
	q=b;
	while(a/2!=0)
	{
	
		while(q/2!=0)
		{
	
			if(a==q)
				break;
			q/=2;
		}
		
		if(a==q)
			break;
		a/=2;
		q=b;
	}
	return a;
}
/*?? - ???*/ 



int main()
{
	int x,y,t;
	cin>>x>>y;
	if(x>y)
	{
		t=x;x=y;y=t;
	}
	int floorx,floory;
	floorx=floor(log(x)/log(2));//??x,y???? 
	floory=floor(log(y)/log(2));
	int i;
	for(i=floory-1;i>=floorx;i--) 
	    y=y%2==0?y/2:(y-1)/2;//x??????????x????x/2?x????(x-1)/2 
	for(i=floorx;i>=0;i--)
	{
		if(x!=y)
		{
			x=x%2==0?x/2:(x-1)/2;
			y=y%2==0?y/2:(y-1)/2;
		}
		else 
		{
			cout<<x<<endl;
			return 0;
		}
	}
	return 0;
}
int main() {
	int x, y;
	cin >> x >> y;
	int roadx[15] = {0};
	int roady[15] = {0};
	int c1 = 0, c2 = 0;
	while(1) {
	     roadx[c1] = x;
		 x /= 2;
		 c1++;
		 if(x == 0) break;
	}
	while(1) {
	     roady[c2] = y;
		 y /= 2;
		 c2++;
		 if(y == 0) break;
	}
	int i = 0;
	while(1) {
		if(roadx[c1 - i - 1] != roady[c2 - i - 1]) {
			cout << roadx[c1 - i]; 
			break;
		}
		if(i == c1 - 1) {
			cout << roadx[0];
			break;
		}
		if(i == c2 - 1) {
			cout << roady[0];
			break;
		}
		i++;
	}
	getchar();
	getchar();
	return 0;
}
void main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	int a[1000],b[1000];
	int i=1,j=1;
	a[1]=x;
	b[1]=y;
	if(x==y)
		printf("%d",x);
	else
	{
	while(a[i]!=1)
	{
		i++;
		if(x%2==0)
		{
			a[i]=x/2;
			x=x/2;
		}
		else
		{
			a[i]=(x-1)/2;
			x=(x-1)/2;
		}
	}
	while(b[j]!=1)
	{
		j++;
		if(y%2==0)
		{
			b[j]=y/2;
			y=y/2;
		}
		else
		{
			b[j]=(y-1)/2;
			y=(y-1)/2;
		}
	}
	while(a[i]==b[j])
	{
		i--;
		j--;
	}
	printf("%d",a[i+1]);
	}
}
int tree(int i,int j)
{
    if(i==j) return i;
    if(i>j)
    {
        return tree(i/2,j);   
    }
    if(i<j)
    {
        return tree(j,i);   
    }
    
}
int main()
{
    int i,j;
    cin>>i>>j;
    cout<<tree(i,j);
    return 0;
}
int x,y;
int a[1001];
int b[1001];

int main()
{
	int i,j,m;
	scanf("%d %d",&x,&y);
	while(x>=1&&y>=1)
	{
		for(i=1;i<=1001;i++)
		{
			a[i]=x;
			x=x/2;
			b[i]=y;
			y=y/2;
		}
	}
	for(i=1;i<=1001;i++)
	{
		for(j=1;j<=1001;j++)
			if(a[i]==b[j])
			{
				printf("%d\n",a[i]);
				m=1;break;
			}
			if(m==1)
				break;
	}
	return 0;
}
int main()
{
	int x,y;
	cin>>x>>y;
	int i,j,X[20]={0},Y[20]={0};
	X[0]=x;Y[0]=y;
	for(i=1;i<20;i++)
	{
		X[i]=X[i-1]/2;
		Y[i]=Y[i-1]/2;
	}
	int flag = 0;
	for(i=0;i<20;i++)
	{
		for(j=0;j<20;j++)
		{
			if(X[i]==Y[j])
			{
			cout<<X[i];
			flag = 1;
			break;}
		}
		if(flag) break;
	}
	return 0;
}
// ?????.cpp : ??????????????
//



int main()
{
	int x,y,a[100],b[100],i,j,n,m,p;
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
	for(i=1;i<=100000;++i)
	{
		a[i]=x/2;
		x=x/2;
		if(a[i]==0) break;
	}
	n=i-1;
	for(i=1;i<=100000;++i)
	{
		b[i]=y/2;
		y=y/2;
		if(b[i]==0) break;
	}
	m=i-1;
	for(i=0;i<=n;++i)
	{
		for(j=0;j<=m;++j)
		{
			if(a[i]==b[j]) break;
		}
		if(a[i]==b[j]) break;
	}
	printf("%d\n",a[i]);
	return 0;
}
int origin(int a) 
{ 
	int i,j,k,n,p;
	for(i=0;i<=11;i++)
		if(pow(2,i)<=a&&pow(2,i+1)-1>=a)n=i+1;
	j=a-pow(2,n-1)+1;
	k=(j+1)/2;
    p=pow(2,n-2)+k-1;
	return p;
}
int main()
{
	int m[12],n[12];
	
	int n1,n2,i,j,min;
	int x,y;
	cin>>x>>y;
    for(i=0;i<=11;i++)
		if(pow(2,i)<=x&&pow(2,i+1)-1>=x)n1=i+1;
    for(i=0;i<=11;i++)
		if(pow(2,i)<=y&&pow(2,i+1)-1>=y)n2=i+1;
    
	if(n1==1||n2==1)cout<<1;
	else
	{
	m[n1]=x;
	n[n2]=y;
	m[n1+1]=-1;
	n[n2+1]=-2;
	if(x>y)min=x;
	else min=y;
	for(i=n1-1;i>=1;i--)
		m[i]=origin(m[i+1]);
	for(i=n2-1;i>=1;i--)
		n[i]=origin(n[i+1]);
	for(j=1;j<=min;j++)
		if(m[j]==n[j]&&m[j+1]!=n[j+1])
		{
			cout<<m[j]<<endl;
			break;
		}
	}
	
   return 0;
}
int f(int x ,int y)
{
	if(x==y)return x;
	if(x<y)return f(x,floor(y/2));
	if(x>y)return f(floor(x/2),y);
}
int main()
{
	int n=0;
	int X,Y=0;
cin>>X>>Y;
		cout<<f(X,Y)<<endl;
return 0;
}
int main()
{
	int x,y,a[1000],b[1000],k=0,l=0;
	cin>>x>>y;
	if(x==y)
	{
		cout<<x<<endl;
	}
	else
	{
		while(1)
		{
			a[k]=x;
			x=x/2;
			b[l]=y;
			y=y/2;
			if(a[k]==0&&b[l]==0)
				break;
			k++;
			l++;
		}
		for(int i=0;i<=k;i++)
		{
			for(int j=0;j<=l;j++)
			{
				if(a[i]==b[j])
				{
					cout<<a[i]<<endl;
					return 0;
				}
			}
		}
	}
	return 0;
	}
int main()
{
	int m , n;
	cin>>m>>n;
	if (m==n) cout<<m<<endl;
	else
	{
	int a[20] ,b[20];
	for (int i=0;i<20;i++)
	{
	   a[i]=0;
	   b[i]=0;
	}
	   a[0]=m;b[0]=n;
	   int j=0;
	   while (m>1)//??m?????????????
	   {
	     if (m%2==0) //??m?????
		 {
			 a[j+1]=m/2;
			 m=m/2;//?m???????????????
		 }
	     else 
	    {
			 a[j+1]=(m-1)/2;
			 m=(m-1)/2;
		 }
	         j=j+1;
	   }
	    int k=0;
	   while (n>1)
	   {
	     if (n%2==0) 
		 {
			 b[k+1]=n/2;
			 n=n/2;
		 }
	     else 
	    {
			 b[k+1]=(n-1)/2;
			 n=(n-1)/2;
		 }
	         k=k+1;
	   }
	   while (a[j]==b[k])//???????????????
	   {
	      j=j-1;
		  k=k-1;
	   }
	   cout<<a[j+1]<<endl;
	}
    return 0;
}
//
//  main.cpp
//  HomeWork_11.14.Functions
//  ???
//  Created by ??? on 11/19/12.
//  Copyright (c) 2012 airjcy. All rights reserved.
//

//#include <string>

int findSameNode(int x,int y)
{
    if (x == y) {
        return x;
    }
    else
    {
        if (x > y) {
            return findSameNode(x / 2, y);
        }
        else
        {
            return findSameNode(x, y / 2);
        }
    }
}


int main(int argc, const char * argv[])
{
    int x,y;
    cin >> x >> y;
    cout << findSameNode(x, y);
    
}
int way(int x,int a[10])
{
	int i=0;
	while(x>0)
	{
		a[i]=x;
		x=x/2;
		i++;
	}
	return(i);
}
int num(int a[10],int x,int b[10],int y)
{
	int p=0,t=0,i,j;
	for(i=x,j=y;i>0&&j>0;i--,j--)
	if(a[i-1]!=b[j-1])
	{
		t=a[i];
		p++;
		break;
	}
	if(p==0)
	if(x>y) t=b[0];
	else t=a[0];
	return(t);
}
int main()
{
	int x,y,a[10],b[10],m,n,t,i,j;
	scanf("%d%d",&x,&y);
	m=way(x,a);
	n=way(y,b);
	t=num(a,m,b,n);
	printf("%d",t);
	return 0;
}
int so(int x)
{
  int i,soo=1;
  for(i=1;i<10;i++)
  { 
	  if((x/2)!=0)
  {x=(int)x/2; soo++;}
      else break; 
  }
      return(soo);
}

void main()
{
      int a,b,i,t,w,r,n;
      int c[1001],d[1001];

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


      i=so(a);t=so(b);
      for(c[0]=a,w=0;w<i-1;w++)
	  {   
              if(c[w]%2==0)
             c[w+1]=c[w]/2;
          else c[w+1]=(c[w]-1)/2;
	  }
   
    for(d[0]=b,r=0;r<t-1;r++)
    {   
             if(d[r]%2==0)
             d[r+1]=d[r]/2;
          else d[r+1]=(d[r]-1)/2;
	}

if(c[0]==d[0])
printf("%d",c[0]);
else {       
 for(n=0;n<=t;n++)
			if(c[i-n-1]!=d[t-n-1])
			{
				printf("%d",c[i-n]);
                break;
			}
		
 }
}
int up(int m)
{
	return (m%2==0)?m/2:(m-1)/2;
}
int main()
{
	int m,n;
	cin>>m>>n;
	int powerm,powern;
	if (m<n) { int temp=m; m=n; n=temp;}
	for (powerm=0;(m>>powerm)>0;powerm++) ;
	for (powern=0;(n>>powern)>0;powern++) ;
	while (powerm>powern)
	{
		m=up(m);
		powerm--;
	}
	while (m!=n)
	{
		m=up(m);
		n=up(n);
	}
	cout<<m<<endl;
	return 0;
}
int jie(int a,int b)
{
	if((a==1)||(b==1))  //??????1????1
		return 1;
	b=b/2;      //????????????2???????
	if(a>b)
		return jie(b,a);
	else if(a<b)
		   return jie(a,b);  //????????????
	     else if(a==b)
			 return a;      //???????????
}
int main()
{
	int m,n,c;
	cin>>m>>n;
	if(m>n)
		c=jie(n,m);
	else if(m<n)
		   c=jie(m,n);
	    else if(m==n)
			c=m;
	cout<<c<<endl;
return 0;
}
int main()
{
	int num1[20],num2[20];
	int m,n;
	int len1,len2;
	cin>>m>>n;
	int temp = m;
	for(len1 = 0;temp>=1;len1++){
		num1[len1] = temp;
		temp /=2;
	}
	temp = n;
	for(len2 = 0;temp>=1;len2++){
		num2[len2] = temp;
		temp/= 2;
	}
	int i=1;
	while(num1[len1-i]==num2[len2-i])
		i++;
	cout<<num1[len1-i+1]<<endl;
	return 0;
}
int main()
{
	int x,y;
	cin>>x>>y;
	int a[12]={0},i,j,b[12]={0},point;
	a[0]=x;
	b[0]=y;
	for (i=1;i<12;i++)
	{
		a[i]=a[i-1]/2;
		b[i]=b[i-1]/2;
	}
	for (i=11;i>=0;i--)
		for (j=11;j>=0;j--)
			if (a[i]==b[j]) point=a[i];
	cout << point << endl;
	return 0;
}
/*
 * r.cpp
 *
 *  Created on: 2013-11-18
 *      Author: shu
 */

int min(int a,int b){
	if(a>=b)return b;
	else return a;
}
int f(int x,int y){
	int wx[10]={1,1,1,1,1,1,1,1,1,1},wy[10]={1,1,1,1,1,1,1,1,1,1};
	int i=0,j=0,t1,t2;
	wx[0]=x;wy[0]=y;                 //?
     while(wx[i]!=1){                //?
    	wx[i+1]=floor(wx[i]/2);          //x
    	i++;                         //y
     } t1=i;                              //?
     i=0;
     while(wy[i]!=1){                 //?
        	wy[i+1]=floor(wy[i]/2);       //?
        	i++;                      //?
         }t2=i;
     i=j=0;
      j=min(t1,t2);
      while(j>=0){
    	  if(wx[t1]!=wy[t2]){
    		  return wx[t1+1];
    		  break;
    	  }
    	  t1--;
    	  t2--;
    	  j--;
      }
}
int main(){
	int x1,y1;
	cin>>x1>>y1;
	cout<<f(x1,y1)<<endl;
	return 0;
}
int main()
{
	int a[1000];
	int b[1000];
	int x0,y0,x,y,i,n,j,flag;
	scanf("%d%d",&x,&y);
	i=0;
	a[0]=x;
	while(i>=0)
	{
		n=a[i]/2;
		if(n==0) break;
		i++;
		a[i]=n;
	}
	x0=i;
	i=0;
	b[0]=y;
	while(i>=0)
	{
		n=b[i]/2;
		if(n==0) break;
		i++;
		b[i]=n;
	}
	y0=i;
	flag=0;
	for(i=0;i<=x0;i++)
	{
		for(j=0;j<=y0;j++)
		{
			if(a[i]==b[j])
			{
				flag=1;
				break;
			}
		}
	if(flag==1) break;
	}
	printf("%d",a[i]);
	
	return 0;
}
int up(int x) {
	return x/2;
}

int meet(int x, int y) {
	if (x == y)
		return x;
	
	int depthx = log2(x);
	int depthy = log2(y);
	if (depthx < depthy)
		return meet(x, up(y));
	else if (depthx > depthy)
		return meet(up(x), y);
	else
		return  meet(up(x), up(y));
}

int main() {
	int x, y;
	cin >> x >> y;
	cout << meet(x, y);
}
void main()
{
	int a[11],b[11],i,j;
	scanf("%d %d",&a[0],&b[0]);
	for(i=1;i<11;i++)
	{
		a[i]=(int)(a[i-1]/2);
	}
	for(j=1;j<11;j++)
	{
		b[j]=(int)(b[j-1]/2);
	}
	for(i=0;i<11;i++)
	{
		for(j=0;j<11;j++)
		{
			if(a[i]==b[j])
			{printf("%d\n",a[i]);i=11;j=11;}
		
		}
	}
}
int a[11],b[11],num1=1,num2=1;
void f1(int x){
	a[1]=x;
	if(x!=1){
		do{
			num1++;
			a[num1]=x/2;
			x=a[num1];
		}while(a[num1]!=1);
		a[num1]=1;
	}
}
void f2(int y){
	b[1]=y;
	if(y!=1){
		do{
			num2++;
			b[num2]=y/2;
			y=b[num2];
		}while(b[num2]!=1);
		b[num2]=1;
	}
}
int main(){
	int x,y,p=0;
	cin>>x>>y;
	f1(x);
	f2(y);
	for(int i=1;i<=num1;i++){
		for(int j=1;j<=num2;j++){
			if(a[i]==b[j]){
				cout<<a[i]<<endl;
				p++;
				break;
			}
		}
		if(p!=0)
			break;
	}
	return 0;
}
int main()
{    void zhao(int n,int y,int a[]);
    int x=0,y=0,a[100]={0},t=0,i=0,n=0,k=0;
	scanf("%d%d",&x,&y);
	if(x>y)
	 {t=y;
	 y=x;
	 x=t;}
	 a[0]=x;
	for(i=1;;i++)
	{ a[i]=a[i-1]/2;
	  if(a[i]/2==0)
	  { break;}
	  }
	  n=i;
	  zhao(n,y,a);
	  	
    //getchar();
    //getchar();
	return 0;
}
void zhao(int n,int y,int a[])
{ int i=0,t=0;
  for(i=0;i<=n;i++)
  { if(a[i]==y)
      { printf("%d",y);
        t=1;
        break;
        	  
	  }
		}
 
	  if(y/2!=0&&t==0)
	  zhao(n,y/2,a);
	  
}
int main()
{
    int i,j,m,n,x,y;
    int a[1000]={0},b[1000]={0};
    scanf("%d",&x);
    scanf("%d",&y);
    a[0]=0;b[0]=1;
    for(i=1;;i++)
    {
                 a[i]=x;
                 x=x/2;
                 if(a[i]==1)break;
    }
    m=i;
    for(i=1;;i++)
    {
                 b[i]=y;
                 y=y/2;
                 if(b[i]==1)break;
    }
    n=i;
    for(i=m,j=n;;i--,j--)
    {
                         if(a[i]==b[j]&&a[i-1]!=b[j-1])
                         {
                                                       printf("%d",a[i]);
                                                       break;
                         }
    }
     return 0;
}
int refine(int a)
{
  if(a%2==1) return((a-1)/2);
  else return(a/2);
}

int main()
{
  int a,b,i;
  scanf("%d%d",&a,&b);
  while(a!=b)
  {
    if(a>b) a=refine(a);
    else b=refine(b);
  }
  printf("%d",a);
  return 0;
}
int main(){
	int i,j,x,y,a[1010];
	scanf("%d%d",&x,&y);
	memset(a,0,sizeof(a));
	for(i=x;i>0;i/=2){
		a[i]=1;
	}
	for(i=y;i>0;i/=2){
		if(a[i]){
			printf("%d",i);
			break;
		}
	}
	return 0;
}
int f(int n)
{
	int i,s=1;
	for(i=1;i<=n;i++)
	{
		s=s*2;
	}
	return s;
}
int main ( )
{
	int x,y,i,j,nx,ny;
	int x_row[10],y_row[10];
	scanf("%d %d\n",&x,&y);
	for(i=1;1;i++)
	{
		if(x<f(i))
			break;
	}
	nx=i;
	for(i=1;1;i++)
	{
		if(y<f(i))
			break;
	}
	ny=i;
	x_row[0]=x;
	y_row[0]=y;
	for(i=1;1;i++)
	{
		x_row[i]=f(nx-i-1)-1+(x_row[i-1]-f(nx-i)+1+(x_row[i-1]-f(nx-i)+1)%2)/2;
		if(x_row[i]==1)
			break;
	}
	for(i=1;1;i++)
	{
		y_row[i]=f(ny-i-1)-1+(y_row[i-1]-f(ny-i)+1+(y_row[i-1]-f(ny-i)+1)%2)/2;
		if(y_row[i]==1)
			break;
	}
	for(i=0;i<nx;i++)
	{
		for(j=0;j<ny;j++)
		{
			if(y_row[j]==x_row[i])
				break;
		}
		if(y_row[j]==x_row[i])
			break;
	}
	printf("%d\n",y_row[j]);
	return 0;
}
int main()
{
	int x,y,i,j,c,d,t=0,m,a[12],b[12];
    scanf("%d%d",&x,&y);
    a[0]=x;
	b[0]=y;
	for(i=1;;i++)
	{
		a[i]=a[i-1]/2;
		if(a[i]==1)
		{   
			c=i;
			break;
		}
	}
	for(j=1;;j++)
    {
		b[j]=b[j-1]/2;
		if(b[j]==1)
		{   d=j;
			break;
		}
	}
	for(i=0;i<=c;i++)
	{   
		if(t==1)
			break;
		for(j=0;j<=d;j++)
		{
			if(a[i]==b[j])
			{   
				m=a[i];
				t=1;
				break;

			}
		}
	}
	printf("%d\n",m);
   return 0;
}
int step(int x1,int y1)
{
	if(x1==y1) return x1;
	if(x1>y1)
	{if(x1%2==0) return step(x1/2,y1);
	else return step((x1-1)/2,y1);
	}
	if(x1<y1)
	{if(y1%2==0) return step(x1,y1/2);
	else return step(x1,(y1-1)/2);
	}
}
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<step(x,y)<<endl;
	return 0;
}
int main()
{
	int a[20]={0},b[20]={0},x,y,i;
	int judge(int *p,int *q);
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
for(i=1;x>1;i++,x=x/2)
a[i]=x/2;
a[i]=1;
for(i=1;y>1;i++,y=y/2)
b[i]=y/2;
b[i]=1;
printf("%d\n",judge(a,b));

return 0;
}
int judge(int *p,int *q)
{
for(;*p!=0;p++);
p--;
for(;*q!=0;q++);
q--;
for(;*p==*q;p--,q--);
q++;
return (*q);



}
int er(int x,int y)
{
	if(x>y)
		return er(x/2,y);
	if(x<y)
		return er(x,y/2);
	if(x==y)
		return x;
}
void main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d",er(x,y));
}
int main()
{
	int A,B,i,j,a[20],b[20],n1,n2,sign=0;  //?????????A?B???????i?j????????a?b??????????n1?n2??????????sign?????
	cin>>A>>B;   //??????
	for(i=1;A>1;i++)   //??A???
	{
		a[i]=A;    //?????A??
		if(A%2==0)   //??A??????????????A/2??????A-1)/2
			A=A/2;
		else
			A=(A-1)/2;
	}
	a[i]=A;          //????????1
	n1=i;    //???????
	for(i=1;B>1;i++)   //??B????????
		{
			b[i]=B;
			if(B%2==0)
				B=B/2;
			else
				B=(B-1)/2;
		}
	b[i]=B;
	n2=i;
	for(i=1;i<=n1&&sign==0;i++)   //?????????????????
		for(j=1;j<=n2&&sign==0;j++)
			if(b[j]==a[i])
				sign=1;   //????????????1?????
		cout<<a[i-1];   //????
	return 0;
}
int main()
{
	int x,y,a[11],b[11],num1,num2;
	cin>>x>>y;
	int i=0;
	a[i]=x;
	while(x>1)
	{
		x=x/2;
		i++;
		a[i]=x;
	}
	num1=i+1;
	int j=0;
	b[j]=y;
	while(y>1)
	{
		y=y/2;
		j++;
		b[j]=y;
	}
	num2=j+1;
	int flag=0;
	for(i=0;i<num1;i++)
	{
		for(j=0;j<num2;j++)
		{
			if(a[i]==b[j])
			{
				flag=1;
				cout<<a[i]<<endl;
				break;
			}
		}
		if(flag==1)
			break;
	}
	return 0;
}
int main()
{
	int x,y,i,l2x,l2y,xx[10],yy[10];
	cin>>x>>y;
	l2x=log(x)/log(2);
	l2y=log(y)/log(2);
	if(x==8)	l2x=3;
	if(y==8)	l2y=3;
	xx[l2x]=x-pow(2,l2x);
	yy[l2y]=y-pow(2,l2y);
	for(i=l2x-1;i>=0;i--)	xx[i]=xx[i+1]/2;
	for(i=l2y-1;i>=0;i--)	yy[i]=yy[i+1]/2;
	i=l2x;
	if(l2x>l2y)	i=l2y;
	for(;i>=0;i--)
	{
		if(xx[i]==yy[i])
		{
			cout<<(pow(2,i)+xx[i])<<endl;
			break;
		}
	}
	return 0;
}
void main()
{
	int a,b,i,t1,t2,p[12]={0},q[12]={0};

	scanf("%d%d",&a,&b);
	
	if(!(a==b))
	{for(i=0;i<12;i++)
	{
		if(a/((int)pow(2,i))==0)
		{
			t1=i;
			break;
		}
	}
	for(i=0;i<12;i++)
	{
		if(b/((int)pow(2,i))==0)
		{
			t2=i;
			break;
		}
	}
	p[t1]=a;
	q[t2]=b;
	for(i=t1;i>=0;i--)
	{
		p[i-1]=p[i]/2;
	}
	for(i=t2;i>=0;i--)
	{
		q[i-1]=q[i]/2;
	}
	for(i=0;i<12;i++)
	{
		if(q[i]!=p[i])
		{
			printf("%d",p[i-1]);
			break;
		}
	}   
	}
	if(a==b)
		printf("%d",a);
}
void main()
{
	int x[1100],y[1100],i,j,m,n,t;
	scanf("%d %d",&x[0],&y[0]);
	for(i=1;x[i-1]>1;i++)
	{
		if(x[i-1]%2==0)
			x[i]=x[i-1]/2;
		else
			x[i]=(x[i-1]-1)/2;
	}
	m=i-1;
	for(j=1;y[j-1]>1;j++)
	{
		if(y[j-1]%2==0)
			y[j]=y[j-1]/2;
		else
			y[j]=(y[j-1]-1)/2;
	}
	n=j-1;
	for(i=m,j=n;i>=0 && j>=0;i--,j--)
	{
		if(x[i]!=y[j])
		{
			t=i+1;
			break;
		}
		else
			if(i==0 || j==0)
				t=i;
	}
	printf("%d",x[t]);
}
int main()
{//de
	void seq(int m,int*seqm);
	int a,b;
	int seqa[10],seqb[10];
	int i,t;
//in
	scanf("%d%d",&a,&b);
//pro
	seq(a,seqa);
	seq(b,seqb);
//ou
	for(i=0;seqa[i]==seqb[i];i++)t=seqa[i];
	printf("%d",t);
	return 0;
}

void seq(int m,int*seqm)
{
	int i,j;
	int temp[10];
	temp[0]=m;
	for(i=1;m>1;i++)
		temp[i]=m=m/2;
	for(j=i;j>=0;j--)
		seqm[j-1]=temp[i-j];



}