semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int s(int a,int b)
{
	int p,q;
	if(a>b)
	{
		p=a;q=b;
	}
	else
	{
		p=b;q=a;
	}
	p=p/2;
	if(p==q)return p;
	else s(p,q);
}
int main()
{
	int m,n,re;
	cin>>m>>n;
	if(m==n)cout<<m;
	else
	{
		re=s(m,n);
		   cout<<re<<endl;
	}
	return 0;
}
int result(int x,int y)
{
	int t=0;
	if(x==y)
		t=x;
	else if(x>y)
		t=result(x/2,y);
	else if(x<y)
		t=result(x,y/2);
	return t;
}
void main()
{
	int m=0,n=0;
	scanf("%d%d",&m,&n);
	printf("%d",result(m,n));
  
}
int main(int argc, char* argv[])
{
	int x,y,i,j,k=0,a[100],b[100];
	scanf("%d%d",&x,&y);
	a[1]=x;
	b[1]=y;
	for(i=1;a[i]>1;i++)
	{
		if(a[i]%2==0)
		{
			a[i+1]=a[i]/2;
		}
		else
		{
			a[i+1]=(a[i]-1)/2;
		}
	}
	for(j=1;b[j]>1;j++)
	{
		if(b[j]%2==0)
		{
			b[j+1]=b[j]/2;
		}
		else
		{
			b[j+1]=(b[j]-1)/2;
		}
	}
	for(i=1;a[i]>=1;i++)
	{
		for(j=1;b[j]>=1;j++)
		{
			if(b[j]==a[i])
			{
				printf("%d",b[j]);
				k=1;
				break;
			}
		}
		if(k==1)
		{
		break;
		}
	}
	return 0;
}
//
//  Created by Chu-Pan,Wong on Dec 1, 2013.
//  Copyright (c) 2013 ChuPan,Wong. All rights reserved.
//




int routex[1000];
int routey[1000];

int main(int argc, char** argv){
    int x,y;
    cin>>x>>y;
    int nx,ny;
    for (nx=0; x!=1; nx++) {
        routex[nx]=x;
        if (x%2==0) {
            x/=2;
        }
        else{
            x=(x-1)/2;
        }
    }
    for (ny=0; y!=1; ny++) {
        routey[ny]=y;
        if (y%2==0) {
            y/=2;
        }
        else{
            y=(y-1)/2;
        }
    }
    routex[nx]=routey[ny]=1;
    int res;
    while (routex[nx]==routey[ny]) {
        if (nx<0||ny<0) {
            break;
        }
        res = routex[nx];
        nx--; ny--;
    }
    cout<<res<<endl;
    return 0;
}
int main(int argc, char* argv[])
{
	int a,b;
	int temp;
	scanf("%d %d",&a,&b);
	do
	{
		if(a>b)
		  a=a/2;
		if(a<b)
		  b=b/2;
	}while(a!=b);
	printf("%d",a);
	return 0;
}
int zheng(int x,int i)
{
    int j;
    if(i!=1) 
    {
        for(j=1;j<i;j++)
            x=x/2;
    }
    return(x);
}
void main()
{
    int zheng(int x,int i);
    int x,y,i,j,temp=0;
    scanf("%d%d",&x,&y);
    if(x==y)
        printf("%d",x);
    else
    {
        for(i=1;i<=10;i++)
        {
            if(temp!=0)
               break;
            for(j=1;j<=10;j++)
            {
                if(zheng(x,i)==zheng(y,j))
                {
                    temp=zheng(y,j);
                    break;
                 }
             }
         }
         printf("%d",temp);
     }   
}
int main()
{
int x,y,xx[100]={0},yy[100]={0},i=1,j=1,k,l;
cin>>x>>y;
if(x==y)
  {
     cout<<x;
     return 0;      
  }
if(x==1||y==1)
{
   cout<<1;
   return 0;              
}
xx[0]=x;
yy[0]=y;   
while(x!=0)
{
  xx[i]=x/2;
  x/=2;
  i++;         
}
while(y!=0)
{
  yy[j]=y/2;
  y/=2;
  j++;         
}

for(k=0;k<i;k++)
{
  for(l=0;l<j;l++)
    if(xx[k]==yy[l])
      break;
  if(xx[k]==yy[l])
      break;
}
cout<<xx[k]; 
 
return 0; 
}
int main()
{
	int x, y, x_[100], y_[100], i=0, j=0, count_x=0, count_y=0;
	scanf("%d%d", &x, &y);
	if(x == y)
		printf("%d\n", x);
	else
	{	
		x_[0] = x; 	
		y_[0] = y;	
		for(i=0; x_[i]>0; i++)	
		{		
			x_[i+1]=x_[i]/2;	
			count_x++;	
		}	
		for(i=0; y_[i]>0; i++)	
		{	
			y_[i+1]=y_[i]/2;	
			count_y++;	
		}
		i = count_x;
		j = count_y;
		while(i >= 0 && j >= 0)	
		{		
			if(x_[i] == y_[j] && x_[i-1] != y_[j-1])			
				printf("%d\n", x_[i]);		
			i--;		
			j--;	
		}
	}
	return 0;
}
int main(int argc, char* argv[])
{
	int x[1000],y[1000];
	int i,j,k,p=1;
	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;
		if (x[i-1]%2==1)
            x[i]=(x[i-1]-1)/2;
	}
    	for (i=1;y[i-1]!=1;i++)
	{
		if (y[i-1]%2==0)
		    y[i]=y[i-1]/2;
		if (y[i-1]%2==1)
            y[i]=(y[i-1]-1)/2;
	}

	for (k=0;x[k-1]!=1 && p==1;k++)
	{	for (j=0;y[j-1]!=1;j++)
		{   if (x[k]==y[j]) 
	{
	           printf("%d\n",x[k]);
			   p=0;
	           break;	
	}
		}
	}

	return 0;
}
int main()
{
	int a,b,i,j,k,d[100],e[100],f[100];
	for(k=0;k<100;k++)
	{
		f[k]=0;
	}
		scanf("%d %d",&a,&b);
		if(a==1||b==1)
			printf("1");
		else{
		if(a!=b)
		{
	d[0]=a;e[0]=b;
	for(i=0;i<100;i++)
	{
		d[i+1]=d[i]/2;
	}
	for(j=0;j<100;j++)
	{
		e[j+1]=e[j]/2;
	}
	for(i=0;i<100;i++)
	{
		for(j=0;j<100;j++)
		{
			if(d[i]==e[j]&&d[i]!=0)
			{
			for(k=0;k<100;k++)
			{
				if(f[k]==0)
					f[k]=d[i];
			}
				break;
			}
		}
	}
	printf("%d",f[0]);
		}
		else printf("%d",a);
		}
	

	return 0;
}
int main()
{  int a[100],b[100],i=0,j=0,m,n,c=0,d=0;
scanf("%d %d",&n,&m);
while(n!=0)
{   a[i]=n;
	n=n/2;
	i++;
	c++;
}
while(m!=0)
{
	b[j]=m;
	m=m/2;
	j++;
	d++;
}
for(i=0;i<c;i++)
{
	for(j=0;j<d;j++)
	{
		if(a[i]==b[j])
		{
			goto loop;
		}
		else
		{
			continue;
		}
	}
}
loop:printf("%d\n",a[i]);

	

 return 0;

}
int Mi(int n)
{
    int i;
    int ans=1;
    for (i=0;i<n;i++)
    {
        ans=ans*2;
    }
    return ans;
}
int divide(int x)
{
    return x/2;
}
main()
{
      int x,y,n,i,m,j;
      int c=0;
      int a[11]={0},b[11]={0};
      scanf ("%d %d",&x,&y);
      for (n=0;;n++)
      {
          if (x>=Mi(n)&&x<Mi(n+1))
          {
               if (n>0)
               {
                 a[n]=x;
                 for (i=n-1;i>=0;i--)
                 {
                   a[i]=divide(a[i+1]);
                 }
               }
               else a[n]=x;
               break;
          }
      }
      for (m=0;;m++)
      {
          if (y>=Mi(m)&&y<Mi(m+1))
          {
               if (m>0)
               {
                 b[m]=y;
                 for (i=m-1;i>=0;i--)
                 {
                   b[i]=divide(b[i+1]);
                 }
               }
               else b[m]=y;
               break;
          }
      }
      for (i=n;i>=0;i--)
      {
          for (j=m;j>=0;j--)
          {
              if (a[i]==b[j]) 
              {
                   printf ("%d\n",a[i]);
                   c=c+1;
                   break;
              }
          }
          if (c==1) break;
      }
}
int main()
{int a[100],b[100],i,m,n; //?????????
cin>>a[1]>>b[1]; //?????
for(i=1;;i++)
{if(a[i]%2==0) a[i+1]=a[i]/2;
 else a[i+1]=(a[i]-1)/2;

 if(a[i+1]==1) break; //?????????

}
 m=i+1;

for(i=1;;i++)
{if(b[i]%2==0) b[i+1]=b[i]/2; //??????
 else b[i+1]=(b[i]-1)/2;

  if(b[i+1]==1) break;
}
  n=i+1;

for(i=1;i<=(m>n?n:m);i++)
{if(a[m-i]!=b[n-i]) cout<<a[m-i+1]; //?????????? ?????
 if(a[m-i]!=b[n-i]) break;

}

return 0;
}
void divide(int ,int s[],int q );
int main()
{
    int a,b,j,k,x[20]={-1,-1},y[20]={-2,-2};
    cin>>a>>b;
    divide(a,x,20);
    divide(b,y,20);
    for(int i1=1;i1<20;i1++)
    {
        if(x[i1]==1)
        {
        j=i1;
        break;
        }
    }
   //cout<<j<<endl;
    for(int i2=1;i2<20;i2++)
    {
        if(y[i2]==1)
        {
        k=i2;
        break;
       }   
    }
    //cout<<k<<endl;
    int p;
    for(p=0;;p++)
    {
        if(x[j-p]!=y[k-p])
        break;
        //cout<<p<<endl;
    }
   // cout<<p<<endl;
   // cout<<j-p+1<<endl;
    cout<<x[j-p+1]<<endl;
    ;
    return 0;
}
void divide(int t,int s[],int q)
{ 
  int i3=1;
  for(;t>1;i3++)
  {
     s[i3]=t;
     t=t/2;
  }
  s[i3]=t;  
}
void main()
{
	int x,y,m,n,i,j,flag=0;
	double t;
	int a[10],b[10];
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
	for(i=1;;i++)
	{
		t=pow(2,i);
		if(x/t<1)
		{
			m=(int)i;
			break;
		}
	}
	for(i=1;;i++)
	{
		t=pow(2,i);
		if(y/t<1)
		{
			n=(int)i;
			break;
		}
	}

	for(i=1;i<m;i++)
	{
		if(a[i-1]%2==0)
			a[i]=a[i-1]/2;
		else
			a[i]=(a[i-1]-1)/2;
	}
	for(i=1;i<n;i++)
	{
		if(b[i-1]%2==0)
			b[i]=b[i-1]/2;
		else
			b[i]=(b[i-1]-1)/2;
	}
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i]==b[j])
			{
				printf("%d",a[i]);
	            flag=1;
				break;
			}
		}
		if(flag==1)
			break;
	}	
}
int f(int a,int b)
{
	if (a==b) return a;
	if (a<b) return f(b,a);
	if (a%2==0) return f(a/2,b);
	if (a%2==1) return f((a-1)/2,b);
}
int main()
{
	int x,y;
	cin>>x>>y;
	if (x>=y) cout<<f(x,y)<<endl;
	else cout<<f(y,x)<<endl;
	return 0;

}
//????1062 ???
//??????
//?????2010-11-24
//???????x?y???xi 


int main()
{
	int x,y,max,i,check[1001]={0,2,0};
	cin>>x>>y;
	if (x>y) max=x;else max=y;
	while (x!=1)//??x???? 
	{
		check[x]++;
		x=x/2;
	}
	while (y!=1)//??y???? 
	{
		check[y]++;
		y=y/2;
	}
	for (i=max;i>=1;i--)//?????? 
	  if (check[i]==2) {
  		cout<<i;
  		return 0;
  	}
}
int find(int,int);
int find(int x,int y)
{
	int a;
	if(x>y) a=find(x/2,y);
	else if(x<y) a=find(x,y/2);
	else a=x;
	return a;
}
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	printf("%d",find(x,y));
	return 0;
}
void main(){
	int x,y;
	int same(int m,int n);
	scanf("%d%d",&x,&y);
	printf("%d",same(x,y));
}

int same(int x,int y){
	while(x!=y){
		if(x>y) x=x/2;
		else y=y/2;
	}
	return x;
}
void main()
{
	int a,b,x[11],y[11],i,j,t;
	scanf("%d%d",&a,&b);
	t=0;
	x[0]=a;
	for(i=1;i<11;i++)
		  {
			  
	 	     x[i]=a/2;
		     a=a/2;
		  }
	y[0]=b;
    for(i=1;i<11;i++)
	{
		y[i]=b/2;
		b=b/2;
	}
	for(i=0;i<10;i++)
	{
		 for(j=0;j<10;j++)
		 {
			  if(x[i]==y[j]&&x[i]!=0&&y[j]!=0)
			  {
			      printf("%d",x[i]);
				  t=1;
				  break;
			  } 
		 } 
		 if(t==1)
		 break;
	}
}
int main()
{
	int m,n,temp=0;
	int a[1000],b[1000];
	int i,j;
	scanf("%d %d",&m,&n);
	a[0]=m;
	b[0]=n;
	for(i=1;;i++)
	{
		a[i]=a[i-1]/2;
		if(a[i]==1)	break;
	}
	for(i=1;;i++)
	{
		b[i]=b[i-1]/2;
		if(b[i]==1)	break;
	}
	for(i=0;i<1000;i++)
	{
		for(j=0;j<1000;j++)
			if(a[i]==b[j])
			{
				temp=1;
				break;
			}
		if(temp==1) break;
	}
	printf("%d",a[i]);
	return 0;
}
int P(int a,int b)
{
	if (a==b)
	{
		return a;
	}
	return P(a/2,b/2);
}
int main()
{
	int a,b;
	cin>>a>>b;

	int i,j;
	for (i=0;a>>i!=0;i++);
	for (j=0;b>>j!=0;j++);
	if (i>j)
	{
		a>>=(i-j);
	}
	else
	{
		b>>=(j-i);
	}
	cout<<P(a,b);
	return 0;
}
int col(int x)//? 
{
 int i;
 for(i=1;;i++)
 {if(x<=(pow(2,i)-1)) break;}
 return i;
}
int row(int x)//? 
{
  int temp;
  temp=col(x);
  return x-pow(2,temp-1)+1;  
}
int main()
{
 int a,b;
 scanf("%d %d",&a,&b);
 int cola,rowa,colb,rowb;
 cola=col(a);rowa=row(a);
 colb=col(b);rowb=row(b); 
 if(cola>colb)
 {
  while(cola>colb)
  {
   cola--;
   if(rowa%2==0) rowa=rowa/2;
    else rowa=(rowa+1)/2;
  }
 }
 if(cola<colb)
 {
  while(cola<colb)
  {
  colb--;
   if(rowb%2==0) rowb=rowb/2;
    else rowb=(rowb+1)/2;
  }
 }
 while(rowa!=rowb)
 {
  rowa=(rowa+1)/2;
  rowb=(rowb+1)/2;
  cola--;colb--; 
 }
 cout<<pow(2,cola-1)+rowa-1;
 return 0;
}
int n,m,i,x,y;
 int function(int n,int m)
 {
	 x=0,y=0;
	 if(n==1||m==1)
		 return 1;
	 if(n==m)
		 return n;
	 else
		{
			if(n%2==0&&m==n+1)
			 return n/2;
			if(m%2==0&&n==m+1)
			 return m/2;
			for(i=m;i>=2;i=i/2)
			{
				y=y+1;
			}
			for(i=n;i>=2;i=i/2)
			{
				x=x+1;
			}
			if(x==y)
				return function(n/2,m/2);
			if(x>y)
				 return function(n/2,m);
			if(x<y)
				return function(n,m/2);
	 }
 }
 int main()
 {
	 cin>>n>>m;
	 cout<<function(n,m)<<endl;
 }
/*
 * ???
 *
 *  Created on: 2012-11-24
 *      Author: zhuyongfu
 */


int binary(int m,int n){//??????????
	if(m == n)//???????????????
		return m;
	if(m < n / 2 + 1)//???????????????????
		return binary(m,n / 2);
	if(n < m / 2 + 1)
		return binary(m / 2,n);
	else//??????????????
		return binary(m / 2,n / 2);
	return 0;
}

int main(){
	int x,y;//?????????
	cin >> x >> y;
	cout << binary(x,y) << endl;
	return 0;
}
int main()
{
	int x1,x2;
	cin>>x1>>x2;
	if(x1==x2)
		cout<<x1<<endl;
	else
	{
		
  while(x1>=2*x2||x2>=2*x1)
  {
      if(x1>=2*x2)
			x1=x1/2;
		if(x2>=2*x1)
			x2=x2/2;
	}
  while(x1!=x2)
  {
	  x1=x1/2;
	  x2=x2/2;
	  		
  while(x1>=2*x2||x2>=2*x1)
  {
      if(x1>=2*x2)
			x1=x1/2;
		if(x2>=2*x1)
			x2=x2/2;
	}
  }
  cout<<x1<<endl;
	}
	return 0;
}
void main()
{
	int x,y,i,j,max,min,a[100],b[100];
	int t=0;
	scanf("%d%d",&x,&y);
max=(x>y)?x:y;min=(x<y)?x:y;
a[0]=max;b[0]=min;
for (i=0;i<=20;i++)
{a[i+1]=a[i]/2;
b[i+1]=b[i]/2;}
for (i=0;i<=20;i++)
{if(t==1) break;
	for (j=0;j<=20;j++)
	{if (a[i]==b[j])
{printf("%d",a[i]);
	t=1;}}}}
int find(int x , int y)
{
	if (x == y)       //???????? 
		return x ;
	else if (x > y)
	{
		while (x > y)   //????t???????2t,2t+1??????2????????? 
			x = x / 2 ;   //??x<=y???????? 
		return find(x , y) ;	
	}
	else
	{
		while (y > x)  //y??x 
			y = y / 2 ;
		return find(x , y) ;	
	}
}
int main()
{
	int m , n ;
	cin >> m >> n ;
	cout << find(m , n) ;
	return 0 ;	
}
void main()
{
	int x0,y0,i,j,k,l=10000;
	int x[10],y[10]={0};

	scanf("%d%d",&x0,&y0);
	x[0]=x0;y[0]=y0;
	for(i=0;i<9;i++)
	{
		x[i+1]=x[i]/2;
	}
	for(i=0;i<9;i++)
	{
		y[i+1]=y[i]/2;
	}
	//	printf("%d",x[0]);
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(x[i]==y[j])
			{l=i;break;}
		}
	if(i==l)break;
	}
		printf("%d",x[i]);
}
int f1(int x)
{
      int n=1,i,p;
      for(i=0;i<12;i++)
{
      x=x/2;
      n++;
      if(x==1)break;
}
      return n;      
}
int f2(int x,int y)
{
     int i;
     for(i=0;i<y;i++)
     x=x/2;
     return x;
}
int main()
{
     int a,b,c,d,e,f;
     cin>>a>>b;
     e=f1(a);
     f=f1(b);
     for(c=0;c<e;c++)
     for(d=0;d<f;d++)
     if(f2(a,c)==f2(b,d))
{
     cout<<f2(a,c);
     c=e+1;
     d=f+1;
} 
     return 0;
}
int main()
{
	int x,y,i,j;
	int X[11],Y[11];
	cin>>x>>y;
	for(i=1;x>=1;i++){
		X[i]=x;
	    x=x/2;}
	for(j=1;y>=1;j++){
		Y[j]=y;
	    y=y/2;}
	for(j=j-1,i=i-1;;j--,i--)
		if(X[i]!=Y[j]){
			cout<<X[i+1]<<endl;
			break;}
	return 0;
}
int main()
{
	int x,y,a[10],b[10],m,n,i;
	scanf("%d%d",&x,&y);
	m=n=0;
	while (x!=0) 
	{
		a[m]=x;
		x/=2;
		m++;
	}
	while (y!=0) 
	{
		b[n]=y;
		y/=2;
		n++;
	}
	for (i=1;i<=10;i++)
		if (a[m-i]!=b[n-i]) break;
	printf("%d",a[m-i+1]);			
	return 0;
}
int main()
{
	int i;
	int *p,*q;
	int x,y;
    int a[10],b[10];

	scanf("%d%d",&x,&y);
	for(i=0;x;i++)
	{
		a[i]=x;
		x/=2;
		p=&a[i];
	}
	for(i=0;y;i++)
	{
		b[i]=y;
		y/=2;
		q=&b[i];
	}
	for(;;q--,p--)
		if(*q==*p&&*(q-1)!=*(p-1))
		{
			printf("%d\n",*p);
			break;
		}
	return 0;
}
/*
 * trees.cpp
 *
 *  Created on: 2012-11-17
 *      Author: Administrator
 */
int main()
{
	int x=0,y=0;
	cin>>x>>y;
	double row1=0,row2=0;
	row1=ceil(log2((double)(x+1)));
	row2=ceil(log2((double)(y+1)));
	while (row2>row1){
		y=y/2;
		row2=ceil(log2((double)(y+1)));
	}
	while (row1>row2){
			x=x/2;
			row1=ceil(log2((double)(x+1)));
		}
	while (x!=y){
		x=x/2;
		y=y/2;
	}
	cout <<x<<endl;
	return 0;
}
int main()
{
	int a,b;
	void search(int,int);
	scanf("%d %d",&a,&b);
	search(a,b);
}
void search(int a,int b)
{
	if(a==b) printf("%d",a);
	else if(a>b)  search(a/2,b);
	else search(a,b/2);
}
int main()
{
	int i,a,b,temp,t1,t2;
	scanf("%d %d",&a,&b);
	if(a<b){temp=a;a=b;b=temp;}
	t1=(int)(log(a)/log(2));t2=(int)(log(b)/log(2));
	for(i=t1;i>t2;i--){a=a/2;}
	for(;a!=b;)
	{a=a/2;b=b/2;}
	printf("%d\n",a);
	return 0;
}
/*
 * hs.2.cpp
 *
 *  Created on: 2010-11-22
 *      Author: l
 */
int jd(int x)
{if(x==1)
	return 1;
else{
		if(x%2)

		return (x-1)/2;
	else
		return x/2;
		}
}//????jd???x???x?????
int main(){
	int x,y;
	cin>>x>>y;
	int lx=1,ly=1,s,t,p=0;
	int i,j;
	s=x;
	for(lx=1;;lx++)
	{if(s!=1)
		s=jd(s);
	else break;
	}//??x???????
	t=y;//
for(ly=1;;ly++){
	if(t!=1)
		t=jd(t);
	else break;//??y???????
}

s=x;
t=y;
	for(i=1;i<=lx;i++)
	{t=y;
		for(j=1;j<=ly;j++)
		{
			if(s==t)
			{p=1;
				cout<<t<<endl;
	break;	}
		else t=jd(t);}
		if(p)
			break;
	s=jd(s);
	}//?????????????????????????????



	return 0;
}
/*
 * tree.cpp
 *
 *  Created on: 2011-11-9
 *      Author: wangshiheng
 */
int main()
{
	int x,y,t;
	cin>>x>>y;
	while (x!=y)  //?????????????2????????????????????????
	{
		if (x<y)	{t=x;x=y;y=t;}
		x/=2;
	}
	cout<<x;
	return 0;
}
void main()
{
	int x,y;
	int i=0,j=0,k;
	int a[1000],b[1000];
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
	while(a[i]!=1)
	{
		i=i+1;
		a[i]=a[i-1]/2;
	}
	while(b[j]!=1)
	{
		j=j+1;
		b[j]=b[j-1]/2;
	}

	if(i<=j)
	{
		for(k=0;k<i+1;k++)
		{
			if(a[k]==b[j-i+k])
			{	printf("%d",a[k]);
			break;
			}
			
		}
	}
	else
	{
		for(k=0;k<j+1;k++)
		{
			if(a[i-j+k]==b[k])
			{		printf("%d",b[k]);
			break;
			}
		}
	}
}
void main()
{
	int x[12],y[12];
	scanf("%d%d",&x[1],&y[1]);
	int i,j,k;
	i=1;
	while(x[i]>=1)
	{
		if(x[i]%2==0)
			x[i+1]=x[i]/2;
		else
			x[i+1]=(x[i]-1)/2;
		i++;
	}
	i=1;
	while(y[i]>=1)
	{
		if(y[i]%2==0)
			y[i+1]=y[i]/2;
		else
			y[i+1]=(y[i]-1)/2;
		i++;
	}
	for(j=1;j<11;j++)
	{
		for(k=1;k<=i;k++)
			if(x[j]==y[k])
			{
				printf("%d",x[j]);
				break;
			}
		if(x[j]==y[k]) break;
	}
}
/*
 * pr8.cpp
 *
 *  Created on: 2011-11-15
 *      Author: Gan Hua
 */
int main()
{
	int x,y,i=1,min,max;
	cin>>x>>y;
	min=x;max=y;
	if(y<x)
		{min=y;max=x;}
	for(min=min;min>0;min=min/2)
		if(i)
		for(max=max;max>=min;max=max/2)
			if(max==min)
				{cout<<max;i=0;}}
int step(int,int);
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<step(x,y)<<endl;
}
int step(int a , int b )
{
	if ( a > b )
	{
		if ( a % 2 == 0 )
			return step( a/2 , b );
		else
			return step( (a - 1) / 2 , b );
	}
	else if ( a < b )
	{
		if ( b % 2 == 0 )
			return step( a , b/2 );
		else
			return step( a , ( b-1) / 2 );
	}
	else
		return a;
}
void main()
{
	int chang (int array[100]);
	int a[100]={0},b[100]={0};
	int x,y,i,j;
	int m,n;
	int k=0;
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
	for(i=1;;i++)
	{
		if(x>1)
		{
			a[i]=x/2;
			x=x/2;
		}
		else break;
	}
	for(j=1;;j++)
	{
		if(y>1)
		{
			b[j]=y/2;
			y=y/2;
		}
		else break;
	}
	m=chang(a);
	n=chang(b);
		for(i=0;i<m;i++)
		{
			for(j=0;j<n;j++)
			{
				if(k!=0)
					break;
				if(a[i]==b[j])
				{
					k=b[j];
				    break;
				}
			}
		}
	printf("%d",k);
}
int chang (int array[100])
{
	int i,k=0;
	for(i=0;;i++)
	{
		if((array[i]!=0)&&(array[i+1]==0))
		{
			k=i+1;
			break;
		}
	}
	return(k);
}
int K(int i,int j)
{
	int m=1;
	for(int k=0;k<j;k++)
	{
		m=m*i;
	}
	return m;
}
int main()
{
	int x,y,q[10],w[10],g=0;
	cin>>x>>y;
	for(int i=0;i<10;i++)
	{
		q[i]=x/K(2,i);
		for(int j=0;j<10;j++)
		{
			w[j]=y/K(2,j);
			if(q[i]==w[j])
			{
				cout<<q[i];
				g=1;
				break;
			}
		}
		if(g==1)
			break;
	}
	return 0;
}
int pre(int num)
{
	if(num==1)
		return 0;
	else
	{
		if(num%2)
			return (num-1)/2;
		else
			return num/2;
	}
}

void main()
{
	int n,m,x[100]={0},y[100]={0},i,j,k,d;
	scanf("%d%d",&n,&m);
	x[0]=n;
	y[0]=m;
	for(i=1;;i++)
	{
		x[i]=pre(x[i-1]);
		if(x[i]==0)
			break;
	}
	for(j=1;;j++)
	{
		y[j]=pre(y[j-1]);
		if(y[j]==0)
			break;
	}
	for(k=0;k<i;k++)
		for(d=0;d<j;d++)
			if(x[k]==y[d])
			{
				printf("%d",x[k]);
				goto L;
			}

L:
	printf("\n");
}
void main()
{
 int a,b,i,j,k,n,x[20],y[20];
 scanf("%d%d",&a,&b);
 x[0]=a,y[0]=b;
 for(i=1;i<15;i++)
 {
  if(a==1) goto loop;
  if(a%2!=0)
  {
   a=(a-1)/2;
   x[i]=a;
  }
  else if(a%2==0)
  {
   a=a/2;
   x[i]=a;
   }
 }
 loop:
 for(n=1;n<15;n++)
 {
  if(b==1) goto loap;
  if(b%2!=0)
  {
   b=(b-1)/2;
   y[n]=b;
  }
  else if(b%2==0)
  {
   b=b/2;
   y[n]=b;
   }
 }
  loap:
  for(j=0;j<i;j++)
  {
   for(k=0;k<n;k++)
   {
    if(x[j]==y[k])
   {
    printf("%d",x[j]);
    break;
   }
    }
if(x[j]==y[k])
   {
    break;
   }
  }
}
void main()
{
	int i,j,k,n,m,r1,r2,a1,b1,x,y,a[100]={0},b[100]={0},r,result=1;
	scanf("%d %d",&x,&y);
    
	for(i=x,k=0;i>=1;i=i/2,k++)
		a[k]=i;
	 
	for(i=y,k=0;i>=1;i=i/2,k++)
		b[k]=i;

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


int main(){int i,j;
int a[300],b[300],ac=0,bc=0,xun,h;
scanf("%d%d",&i,&j);

a[0]=i;b[0]=j;
for(xun=1;;xun++){if(a[xun-1]!=1){a[xun]=toup(a[xun-1]);ac=ac+1;}else{break;}                   }
for(xun=1;;xun++){if(b[xun-1]!=1){b[xun]=toup(b[xun-1]);bc=bc+1;}else{break;}                   }

for(h=1;;h++){if(a[ac-h]!=b[bc-h]){ printf("%d",a[ac-h+1]);break;}        }
return 0;}
void main()
{
	int i,j;//????
	int x;//?????
	int y; //?????
	int t=0;//????????
	int a[15]={0};//??x???????
	int b[15]={0};//??y???????
	int c[15]={0};//????xy?????????
	scanf("%d%d",&x,&y);
	a[0]=x;
    b[0]=y;
	for(i=0;i<14;i++)
	{
		a[i+1]=a[i]/2;
		b[i+1]=b[i]/2;
	}
		for(i=0;a[i]!=0;i++)
		    for(j=0;b[j]!=0;j++)
				if(a[i]==b[j])
			       c[i]=a[i];
				for(i=0;i<15;i++)
					if(t<c[i])
						t=c[i];
					printf("%d\n",t);
}
void main()
{
	int n,m,x,y,i,j,z=0;
	int a[100],b[100];
	scanf("%d %d",&n,&m);
	a[0]=n;
	for(i=0;a[i]!=1;)
	{
		i++;
		a[i]=(int)(a[i-1]/2);
	}
	x=i;
    b[0]=m;
	for(i=0;b[i]!=1;)
	{
		i++;
		b[i]=(int)(b[i-1]/2);
	}
	y=i;
	for(i=0;i<=x;i++)
	{
		for(j=0;j<=y;j++)
		{
			if(a[i]==b[j])
			{
				z=1;
				goto loop;
			}
		}
	}
loop:if(z==1)
	 {
		 printf("%d\n",a[i]);
	 }
}
int main(){
	int x,y;
	cin>>x>>y;
	while(x!=y){
	if(x>y)x=x/2;
	else y=y/2;
	}
	if(x==y)cout<<x<<endl;
	return 0;
}
int main()
{
	int x,y,i,j;
	int a[20],b[20];
	scanf("%d %d",&x,&y);
	{a[0]=x;b[0]=y;
     for(i=1;i<=10;i++)
	 {if(x%2!=0)  {x=(x-1)/2; a[i]=x;continue;}
	 if(x%2==0)  {x=x/2;   a[i]=x;}}
	for(j=1;j<=10;j++)
	{if(y%2!=0)  {y=(y-1)/2; b[j]=y;continue;}
	if(y%2==0)  {y=y/2;   b[j]=y;}}
	for(i=0;i<=10;i++)
	{for(j=0;j<=10;j++)
	if(a[i]==b[j])  {printf("%d\n",a[i]);i=11;j=11;}}}
	return 0;
}
void main()
{

	int x,y,i,j,num1,num2;
	int xline[11],yline[11];


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

	xline[0]=x;
	yline[0]=y;

	i=1;
	while (x>1)
	{
		x=x/2;
        xline[i]=x;
		i=i+1;
	}
    num1=i-1;

	i=1;
	while(y>1)
	{
		y=y/2;
		yline[i]=y;
		i=i+1;
	}
	num2=i-1;

	for(i=0;i<=num1;i++)
	{
		for(j=0;j<=num2;j++)
			if (xline[i]==yline[j])
			{
				printf("%d\n", xline[i]);
				i=num1+1;
			}
	}
}
int main(int argc, char* argv[])
{
	int x,y;
	scanf("%d%d",&x,&y);
	while(x!=y)
	{
	if(x>y)
		x/=2;
	else
		y/=2;
	}
	printf("%d",x);
	
	return 0;
}
int main(){
	int x,y,i;//???????i??????
	cin>>x>>y;//??????x,y
	for(i=0;;i++){//??????????
		if(x==y){cout<<x<<endl;break;}//?x,y?????????????
		if(x>y){x=x/2;continue;}//????????????2???????????
		if(x<y) y=y/2;
	}
	return 0;//????
}
void main()
{
	int i,j,x,y,t,m,n,p;
	int a[10000],b[10000];
	scanf("%d %d",&a[0],&b[0]);
	for(i=0;i<10000;i++)
	{
		if(a[i]==1) 
		{
			x=i+2;
			break;
		}
		else a[i+1]=a[i]/2;
	}
	for(i=0;i<10000;i++)
	{
		if(b[i]==1) 
		{
			y=i+2;
			break;
		}
		else b[i+1]=b[i]/2;
	}
	m=x/2;
	for(i=0;i<m;i++)
	{
		t=a[i];
		a[i]=a[x-i-1];
		a[x-i-1]=t;
	}
	n=y/2;
	for(i=0;i<n;i++)
	{
		t=b[i];
		b[i]=b[y-i-1];
		b[y-i-1]=t;
	}
	for(i=0;i<x;i++)
	{
		if(a[i]==b[i]) p=a[i];
	}
	printf("%d",p);
}
void main()
{
	int f1(int n,int m);
	int m,n;
	scanf("%d%d",&n,&m);
	printf("%d\n",f1(n,m));
}

int f1(int n,int m)
{
	if(n==m)
		return n;
	else if(n>m)
	{
		if(n%2==0)
			return f1(n/2,m);
		else
			return f1((n-1)/2,m);
	}
	else
	{
		if(m%2==0)
			return f1(n,m/2);
		else
			return f1(n,(m-1)/2);
	}
}
int path(int m,int n)
                                       //??????m,n???? 
{   
  if(m==n)                             //?????????? 
    return m;             
  if(m>n)
     m=m/2;  
  else if(m<n) 
  n=n/2;                              //?????????????????? 
  return path(m,n);                   //?? ???? 
}
int main()
{ 
  int x,y;
  cin>>x>>y;                         //??x?y
  cout<< path(x,y);                  //???? 

return 0;
}
/*
 *  ???.cpp
 *  Created on: 2012-11-19
 *  Author:???
 */
int f(int a, int b) {
	if (a == b)
		return a;
	if (a > b) {
		a = a % 2 == 0 ? a / 2 : (a - 1) / 2;
		return f(a, b);
	} else {
		b = b % 2 == 0 ? b / 2 : (b - 1) / 2;
		return f(a, b);
	}
}
int main() {
	int a, b;
	cin >> a >> b;
	cout << f(a, b) << endl;
	return 0;
}
int main()
{
    int x,y,i=1,j=1,a[20],b[20],k,s,f=0;
    scanf("%d%d", &x,&y);
    a[1]=x;b[1]=y;
    while(x>0){
               i++;
               a[i]=x/2;
               x=x/2;
               }
    while(y>0){
               j++;
               b[j]=y/2;
               y=y/2;
               }
    for(k=1;k<=i;k++){
                      for(s=1;s<=j;s++){
                                        if(a[k]==b[s]){
                                                      if(f==0){printf("%d", a[k]);
                                                               f=1;
                                                               }
                                                      } 
                                        }
                      }
    return 0;
    }