semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int m,n,i,j,a[14]={100},b[14]={100};
	scanf("%d%d",&m,&n);
	a[0]=m;
	b[0]=n;
	for(i=0;a[i]>=1;i++)
	{
		a[i+1]=a[i]/2;

	}

	for(j=0;b[j]>=1;j++)
	{
		b[j+1]=b[j]/2;

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

	
	}
	}
}



int main()
{
	
	
	
	int x[101],y[101];
	int i,j,k,flag=0;
	int a,b;
	memset(x,0,sizeof(x));
    memset(y,0,sizeof(y));
	cin>>a>>b;
	line(a,x,1);
	line(b,y,1);
	for(i=1;x[i]!=0;i++)
	{
		for(j=1;y[j]!=0;j++)
		{
			if(x[i]==y[j])
			{
				cout<<x[i]<<endl;
				flag=1;
				break;
			}
			if(flag==1)
			{
				break;
			}
		}
	}

	

	

		
	


		








		

	
	return 0;

}
//************************//
//*?????????    *//
//*?????            *//
//*???2010.11.26      *//
//************************//
void h(int,int a[],int);
void m(int,int b[],int);
int main()
{
 int x,y,j,t,flag=1;
 int a[100],b[100];
 for(j=0;j<100;j++)
 {
   a[j]=0;
   b[j]=0;
 }
 cin>>x>>y;
 h(x,a,-1);
 m(y,b,-1);
 for(j=0;a[j]!=0;j++)
 {
   for(t=0;b[t]!=0;t++)
   {
     if(a[j]==b[t])
	 {
	   cout<<a[j]<<endl;
	   flag=0;
	   break;
	 }
   }
   if(flag==0)
	   break;
 }
 return 0;
}
void h(int n,int a[],int i)
 {
   i++;
   if(n==1)
	   a[i]=n;
   else
   {
	   if(n%2==0)
	   {
		   a[i]=n;
           h(n/2,a,i);
	   }
	   else
	   {
	       a[i]=n;
		   h((n-1)/2,a,i);
	   }   
   }
}
void m(int n,int b[],int k)
 {
   k++;
   if(n==1)
	   b[k]=n;
   else
   {
	   if(n%2==0)
	   {
		   b[k]=n;
           m(n/2,b,k);
	   }
	   else
	   {
	       b[k]=n;
		   m((n-1)/2,b,k);
	   }   
   }
}
//????????-1?/2?????/2
//???i??2^(i-1)????2^i????

//?2^n???
int times2(int i)
{
	int j;
	int s=1;
	if(i==0)
		return 1;
	else
	{
		for(j=1;j<=i;j++)
			s*=2;
		return s;
	}
}

//?k?????????
int level(int k)
{
	int i;
	for(i=1;;i++)
	{
		if((times2(i-1)<=k)&&(times2(i)>k))
		{
			return i;
		}
	}
}

//??????????
int up(int x)
{
	int y;
	if(x%2==0)
		y=x/2;
	else
		y=(x-1)/2;
	return y;
}

int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(level(x)==level(y))
	{
		while(x!=y)
		{
			x=up(x);
			y=up(y);
		}
	}
	else
		if(level(x)<level(y))
		{
			while(level(x)<level(y))
			{
				y=up(y);
			}
			while(x!=y)
			{
				x=up(x);
				y=up(y);
			}
		}
		else
		{
			while(level(y)<level(x))
			{
				x=up(x);
			}
			while(x!=y)
			{
				x=up(x);
				y=up(y);
			}
		}
	printf("%d",x);
	return 0;
}
//
//  main.cpp
//  Homework
//
//  Created by ??? on 13-11-17.
//  Copyright (c) 2013? ???. All rights reserved.
//


int main()
{
    int x,y,sx,sy,nx[11],ny[11];
    cin>>x>>y;
    nx[10]=x;
    ny[10]=y;
    
    for(int i=10;i>0;i--)
        nx[i-1]=nx[i]/2;
    for(int i=10;i>0;i--)
        ny[i-1]=ny[i]/2;

    for(sx=0;sx<11;sx++)
        if(nx[sx]!=0)
        {
            sx--;
            break;
        }
    for(sy=0;sy<11;sy++)
        if(ny[sy]!=0)
        {
            sy--;
            break;
        }

    for(int i=0;i<11;i++)
    {
        if(nx[sx]!=ny[sy])
            break;
        sx++;
        sy++;
    }
    
    cout<<nx[sx-1]<<endl;
    
    return 0;
}
/*
*???.cpp
*??
*2011?11?16?
*?????xi?
*/
int max(int a,int b)
{	
	if(a>b)
		return a;
	else
		return b;
}
int min(int c,int d)
{
	if(c<d)
		return c;
	else
		return d;
}
int main()
{
	int inter,x,y,t1,t2;
	cin>>x>>y;
	t1=x;
	t2=y;
	if(t1==t2)
		cout<<t1<<endl;
	else
		{
			while(1)
			{
				inter=t1;
				t1=max(t1,t2);
				t2=min(inter,t2);
				t1=t1/2;
				if(t1==t2)
					{cout<<t1<<endl;break;}
			}
		}
	return 0;
}
void main()
{
	int a,b,i,j,t,s;
	scanf("%d%d",&a,&b);
	t=a;
	if(a==1||b==1)
		printf("1");
	else
	{
		for(i=0;i<10;i++)
		{
			s=b;
			for(j=0;j<10;j++)
			{
				if(t==s)
					break;
				s=s/2;
			}
			if(t==s)
				break;
			t=t/2;
		}
		printf("%d",s);
	}
}
int div(int a)
{
	if(a%2==1)a=(a-1)/2;
	else a=a/2;
	return a;
}
int compare(int a, int b)
{
	if(a>b){
		a=div(a);
		compare(a,b);}
	else if (a<b){
		b=div(b);
		compare(a,b);}
	else return(a);
}
void main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	a=compare(a,b);
	printf("%d",a);
}
int a[12];
int b[12];
void path(int x,int y)
{
	int i,j,n1,n2,t=0;
	for(i=1;i<=10;i++)
	{
		if((int)pow(2.0,(double)(i-1))<=x&&x<(int)pow(2.0,(double)i)) 
		{	n1=i;
			break;
		}
	}
	a[1]=x;
	for(i=2;i<=n1;i++)
	{
		a[i]=(a[i-1]-(int)pow(2.0,(double)(n1-i+1))+2)/2+(int)pow(2.0,(double)(n1-i))-1;
	}
    for(j=1;j<=10;j++)
	{
		if((int)pow(2.0,(double)(j-1))<=y&&y<(int)pow(2.0,(int)j)) 
		{	n2=j;
			break;
		}
	}
	b[1]=y;
	for(j=2;j<=n2;j++)
	{
		b[j]=(b[j-1]-(int)pow(2.0,(double)(n2-j+1))+2)/2+(int)pow(2.0,(double)(n2-j))-1;
	}
	for(i=1;i<=n1;i++)
	{
		if(t==1) break;
		for(j=1;j<=n2;j++)
		{
			if(a[i]==b[j])
			{
				t=t+1;
				cout<<a[i]<<endl;
				break;
			}
		}
	}
}
int main()
{
	int x,y;
	cin>>x>>y;
	path(x,y);
	return 0;
}
int N[MAX];

int x_iter(int x){
  if(N[x-1]==1) return x;
  else{
    N[x-1]=1;
    x_iter(x/2);
  }
}

int main(){
  int x,y;
  cin>>x>>y;
  memset(N,0,sizeof(N));
  x_iter(x);
  cout<<x_iter(y);
  return 0;
}
int main()
{
	int x,y,i,j,t;
	int a[11],b[11];
	int p,q;
	for(i=1;i<11;i++)
	{
        a[i]=0;
        b[i]=0;
    }
	scanf("%d%d",&x,&y);
	if(x==y)
	printf("%d",x);
	else
	{
	a[0]=x;
	b[0]=y;
	for(i=0;;i++)
	{
		if((a[i]%2==0)&&(a[i]>1))
		  a[i+1]=a[i]/2;
		if(a[i]%2!=0)
		  a[i+1]=(a[i]-1)/2;
		if(a[i]==1)
			break;
	}
	for(j=0;;j++)
	{
		if((b[j]%2==0)&&(b[j]>1))
		  b[j+1]=b[j]/2;
		if(b[j]%2!=0)
		  b[j+1]=(b[j]-1)/2;
		if(b[j]==1)
			break;
	}
	p=i;
	q=j;
	for(i=0;i<=p/2;i++)
	{
       t=a[i];
       a[i]=a[p-i];
       a[p-i]=t;
    }
	for(i=0;i<=q/2;i++)
	{
       t=b[i];
       b[i]=b[q-i];
       b[q-i]=t;
    }
    for(j=0;;j++)
    {
        if(a[j]!=b[j])
        break;
    }
	printf("%d",a[j-1]);
    }
    return 0;
}
void ercha(int *p)
{
	while(*p!=1)
	{
        p++;
		*p=(*(p-1))/2;
	}
}
void main()
{
	int a[11]={0},b[11]={0},m,n,i,j;
	scanf("%d%d",&m,&n);
	a[0]=m;
	b[0]=n;
    ercha(a);
	ercha(b);
	for(i=0;i<11;i++)
	{
		if(a[i]>b[0]){continue;}
		else
		{
			for(j=0;j<10;j++)
			{
				if(a[i]==b[j])
				{
					printf("%d",a[i]);
					break;
				}
			}
			if(a[i]==b[j])break;
		}
	}
}
void main()
{
    int n,m,l,k,t,i,j,x,y;
    int a[1000],b[1000];
    scanf("%d%d",&n,&m);
    if(n<m)
    {
        l=n;n=m;m=l;
    }
    a[0]=0;
    k=1;
    a[k]=n;
    while(n!=1)
    {
        k=k+1;
        a[k]=n=n/2;
    }
    b[0]=1;
    t=1;
    b[t]=m;
    while(m!=1)
    {
        t++;
        b[t]=m=m/2;
    }
    for(i=k;i>=k-t;i--)
    {
        if(a[i]==b[i+t-k]&&a[i-1]!=b[i+t-k-1])
        {
            x=a[i];
            break;
        }
    }
    printf("%d",x);
}
int main()
{
	int a[100],b[100];
	int x,y,i=0,j=0,n1,n2;
	cin>>x>>y;
	while(x>=1)
	{
		a[i]=x;
		x=x/2;
		i=i+1;
	}
	n1=i;
	while(y>=1)
	{
		b[j]=y;
		y=y/2;
		j=j+1;
	}
	n2=j;
	for(i=0;i<n1;i++)
	{
		for(j=0;j<n2;j++)
		{	
			if(a[i]==b[j])
			{
				cout<<a[i]<<endl;
				goto loop;
			}
		}
	}
loop:return 0;
}
int main( )
{
   int x1,x2;
   scanf("%d %d",&x1,&x2);
   int i=1,j=1,m=1,k,l,t,a1[1000],a2[1000];
   if (x1==x2)
     printf("%d\n",x1);
   else if (x1==1||x2==1)
       printf("%d\n",m);
   else{
   a1[0]=x1;
   a2[0]=x2;
   do {
       a1[i]=a1[i-1]/2;
       i++;
      }while(a1[i-1]!=1);
   do {
       a2[j]=a2[j-1]/2;
       j++;
      }while(a2[j-1]!=1);
   for (k=0;k<i;k++)
     for (l=0;l<j;l++)
        if (a1[k]==a2[l])
          {
            printf("%d\n",a1[k]);
            return 0;
          }
   }

}
int common(int x,int y);
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	int result=common(x,y);
	printf("%d\n",result);
	return 0;
}
int common(int x,int y)
{
	if(x==y)
	{
		return x;
	}
	else if(x>y)
	{
		return common(x/2,y);
	}
	else
	{
		return common(x,y/2);
	}
}
int main(int argc, char* argv[])
{
	int x,y,a[11],b[11],i,j,m,n;
	i=0;
	j=0;
	int flag;
	flag=1;
	scanf("%d%d",&x,&y);
	do {a[i]=x;x=x/2;i=i+1;}
	while (x>=1);
		do {b[j]=y;y=y/2;j=j+1;}
		while (y>=1);
			for (m=0;m<11&&flag;m++)
			{
				for (n=0;n<11&&flag;n++)
				{
				if (a[m]==b[n]) 
				{
				printf("%d",a[m]);
				flag=0;
				}
				}
			}
	return 0;
}
/*
 * 111110_03_tree.cpp
 *
 *  Created on: 2011-11-10
 *      Author: Alfalfa
 */
int main(){
	int x,y,i,j,k1[1000],k2[1000],m=0,n=0;
	cin>>x>>y;
	for(i=0;x>=1;i++) //??????x?????? ????k1
	{
		k1[i]=x;
		x=(x-x%2)/2;
		m++;
	}
	for(i=0;y>=1;i++) //y????k2
	{
		k2[i]=y;
		y=(y-y%2)/2;
		n++;
	}
	for(i=0;i<m;i++) //?k1 k2???????
		for(j=0;j<n;j++)
			if(k1[i]==k2[j])
			{
				cout<<k1[i];
				i=1001;
			}
	return 0;
}
void main()
{
	int i=0,j,m,n,p[20],q[20],x[20],y[20];
	scanf("%d%d",&m,&n);
	for(i=0;i<=20;i++)
	{
		if(m>=1)
		{
		x[i]=m;
		m=m/2;
		}
		else
			break;
	}
	for(j=0;j<=i;j++)
		p[j]=x[i-j-1];
	for(i=0;i<=20;i++)
	{
		if(n>=1)
		{
		y[i]=n;
		n=n/2;
		}
		else
			break;
	}
	for(j=0;j<=i;j++)
		q[j]=y[i-j-1];
	for(i=0;i<=20;i++)
		if(p[i]!=q[i])
		{
			printf("%d",p[i-1]);
			break;
		}
}
int x,y;
int maxn;
int dfs(int n){
	int r=0;
	if(n==x||n==y)r++;
	if(n>maxn)return 0;
	r+=dfs(2*n)+dfs(2*n+1);
	if(r==2){
		cout<<n;
		exit(0);
	}
	return r;
}
int main(){
	cin>>x>>y;
	maxn=x>y?x:y;
	dfs(1);
	cout<<x;
}
int main()
{
	int a[1000],b[1000],x,y,i,j;
	cin>>x>>y;
	a[0]=x;
	b[0]=y;
	for(i=0;a[i]!=1;i++)
	{
		if(a[i]%2==0)
			a[i+1]=a[i]/2;
		else a[i+1]=(a[i]-1)/2;
	}
	for(i=0;b[i]!=1;i++)
	{
		if(b[i]%2==0)
			b[i+1]=b[i]/2;
		else b[i+1]=(b[i]-1)/2;
	}
	for(i=0;a[i]!=1;i++)
		for(j=0;b[j]!=1;j++)
			if(a[i]==b[j])
				goto lable;
lable:cout<<a[i]<<endl;
	return 0;
}
int main()
{
	int m,n,a[20]={0},b[20]={0},i,j,k,l,num=0;
	scanf("%d %d",&m,&n);
	a[0]=m;b[0]=n;
	for(i=1;a[i-1]>=2;i++)
		a[i]=a[i-1]/2;
    for(l=1;b[l-1]>=2;l++)
		b[l]=b[l-1]/2;
	for(j=0;j<i;j++)
	{for(k=0;k<l;k++)
		if(a[j]==b[k])
		{	printf("%d",a[j]);num++;
		break;
		}
     if(num)
		 break;
	}
	return 0;
}
int search(int x1,int x2)
{
	int i;
	for(i=0;i<=10;i++)
	{
	   if(x1>=pow(2,i)&&x1<pow(2,i+1)&&x2>=pow(2,i)&&x2<pow(2,i+1))
		   return x1;
	   else continue;
	   }
	  x1=x1/2; return search(x1,x2);
	

}
int equal(int x1,int x2)
{
   if(x1==x2)return x1;
   else 
   {x1=x1/2;x2=x2/2;return equal(x1,x2);}
	   
}

int main()
{
  int x1,x2,temp;
  cin>>x1>>x2;
  if(x1<x2)
	{
      temp=x1;
	  x1=x2;
	  x2=temp;
	  
	}
  x1=search(x1,x2);
  cout<<equal(x1,x2);
  return 0;


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

	 for(n=0;n<=j;n++)
     if (a[m]==b[n]) {cout<<a[m];goto lable;}
   
    }
    lable:
	return 0;
}
int log(int n)
{
    int i=-1,power=1;
    while(power<n+1)
    {
        power=power*2;
        i=i+1;
    }
    return i;
}
void back(int a[],int n)
{
    int i;
    a[0]=n;
    for(i=0;i<log(n)+1;i++)
        a[i+1]=a[i]/2; 
}
void main()
{
    int i,m,n;
    int a[11],b[11];
    scanf("%d %d",&m,&n);
    back(a,m);
    back(b,n);
    
    for(i=0;i<12;i++)
        if(a[log(m)-i]==b[log(n)-i]&&a[log(m)-1-i]!=b[log(n)-i-1])
        {
            printf("%d\n",a[log(m)-i]);
            break;
        }
}
int main()
{
    int i=0,j,a,b;
    scanf("%d%d",&a,&b);
    for(;a>0;a/=2) {
        j=b;
    for(;j>0;j/=2)
    {
        if(a==j) {
            printf("%d",a);
            i=1;break;}
    }
    if(i==1) break;}
    return 0;
}
int main()
{
    int x,y,t;
    cin>>x>>y;
    if (x>y)
    {
       t=x;x=y;y=t;
    }
    for (;(int)(log(x)/log(2))!=(int)(log(y)/log(2));)
      y=y/2;
    for (;(x!=y);)
    {
        x=x/2;
        y=y/2;
    }
    cout<<x;
}
/*??
1000012872
 */
int f(int x,int y);//??????????????
int main()
{
	int x,y;
	cin>>x>>y;//x,y?????
	cout<<f(x,y);//????
	return 0;
}
int f(int x,int y)
{
	int m,n,p,q,i,j,c;
	
	    m=x;
	    n=y;
	    int a[x],b[y];//????????????????
	    a[0]=x;
	    for(i=1;i<=m;i++)
	    {
	      if(x>=2)
		   {
		     a[i]=x/2;
	           x=x/2;

	        }
	      else break;
	    }//?x????????????a????a[0]??????

	      p=i-1;//?p?????????
              b[0]=y;
               for(i=1;i<=n;i++)
               {
	                 if(y>=2)
	                   {
	                     b[i]=y/2;
	                     y=y/2;
	                    }
	                 else break;
               }//?y????????????b????b[0]??????
                q=i-1;//?q?????????

                for(i=p,j=q;i>=0,j>=0;i--,j--)
                	if(a[i]==b[j])
                	c=a[i];
                	return c;//????????????
	
	
	
}
/*
 * er_cha_shu.cpp
 * ?? - ???
 * ??????????1, 2, 3, ...???????????????????????????1?????????
 * ????????10????????(10, 5, 2, 1)??4????????(4, 2, 1)?????1????????
 * ???????1???????(1)???????x?y???????????????(x1, x2, ... ,1)?
 * (y1, y2, ... ,1)??????x = x1?y = y1?????????????i?j????xi ? yj???
 * ?xi = yj , xi + 1 = yj + 1, xi + 2 = yj + 2,... ??????????x?y???xi????yj??
 *  Created on: 2013-11-20
 *      Author: ???
 */
int find(int x , int y){ // ???????
	if(x == y) return x; // ??????????
	while( (x /= 2) > y ){} // ?????????? /2 ?????????????????????
	return find(y , x);
}
int main(){
	int x , y;
	cin >> x >> y;
	cout << ( x > y ? find(x , y) : find(y , x) ) << endl;
	return 0;
}
void main()
{
	int a,b,temp;
	scanf("%d %d",&a,&b);
	if(a<b)
	{
		temp=a;
		a=b;
		b=temp;
	}
	while(a!=b)
	{
		do
		{
			a/=2;
		}while(a>b);
		if(a<b)
		{
			temp=a;
			a=b;
			b=temp;
		}
	}
	printf("%d",a);
}
void main()
{
int x,y,i,m,n;
int a[15]={0},b[15]={0};

scanf("%d %d",&x,&y);
a[0]=x;
b[0]=y;

for(i=0;i<11;i++)
{
if(a[i]==0)
{
m=i-1;
break;
}
else
a[i+1]=a[i]/2;
}

for(i=0;i<11;i++)
{
if(b[i]==0)
{
n=i-1;
break;
}
else
b[i+1]=b[i]/2;
}

for(;;m--,n--)
{
if(a[m]!=b[n])
break;
}
if(a[0]==b[0])
printf("%d\n",a[0]);
else
printf("%d\n",a[m+1]);
}
/*
 * 1062 ???.cpp
 *
 *  Created on: 2010-11-21
 *      Author: ???
 */
int main()
{
	int x[11],y[11],i,j,l1,l2;
	cin>>x[1]>>y[1];
	i=1;
	while (x[i]!=1)
	{
	   if (x[i]%2==0)
	   {i=i+1;x[i]=x[i-1]/2;}
	   else
	   {i=i+1;x[i]=(x[i-1]-1)/2;}
	}
	l1=i;
	i=1;
	while (y[i]!=1)
	{
	   if (y[i]%2==0)
	   {i=i+1;y[i]=y[i-1]/2;}
	   else
	   {i=i+1;y[i]=(y[i-1]-1)/2;}
	}
	l2=i;
	for (i=1;i<=l1;i++)
	{
		for (j=1;j<=l2;j++)
		{
			if (x[i]==y[j])
				{cout<<x[i];break;}

		}
		if (x[i]==y[j])
			break;
	}
	return 0;
}
void main()
{
int x,y,i,j;
scanf("%d %d",&x,&y);
for(;;)
{
if(x>y)
{
 if(x%2==0) x=x/2;
 else x=(x-1)/2;
}
else if(x<y)
  
{
 if(y%2==0) y=y/2;
 else y=(y-1)/2;

}
if(x==y) break;
}
printf("%d",x);
}
void main()
{
	int x[11],y[11],i,j,m;
	int *p1,*p2;
	scanf("%d%d",&x[0],&y[0]);
	p1=&x[0];
    p2=&y[0];
	if(*p1==*p2||*p1==1||*p2==1){
		printf("%d",*p1);
	}
	else{
    for(i=0;i<13;i++){
	*(p1+1)=*p1/2;
	p1++;
		if(*p1==1){
			break;
		}
	}
	for(j=0;j<13;j++){
	*(p2+1)=*p2/2;
	p2++;
		if(*p2==1){
			break;
		}
	}
	for(m=0;m<13;m++){
		if(*p2!=*p1)
		{
	printf("%d",*(p2+1));
	break;
		}
		p1=p1-1;
		p2=p2-1;
	}
	}
}
//???
int main()
{
	int a[11],b[11],sum[11]={0,1,3,7,15,31,63,127,255,511,1023};
	int x,y,i,x0,y0;
	cin>>x>>y;
	for (i=0;i<11;i++)//??x?y????
	{
		if (x>sum[i]&&x<=sum[i+1])
			x0=i+1;
		if (y>sum[i]&&y<=sum[i+1])
			y0=i+1;
	}
	a[x0]=x;
	b[y0]=y;
	for (i=x0-1;i>0;i--)//??x???
	{
		a[i]=a[i+1]/2;
	}
	for (i=y0-1;i>0;i--)//??y???
	{
		b[i]=b[i+1]/2;
	}
	if (x0>=y0)
	{
		for (i=x0;i>0;i--)
		{
			if (a[i]==b[i])
			{
				cout<<a[i]<<endl;
				break;
			}
		}
	}
	else
	{
		for (i=y0;i>0;i--)
			{
				if (a[i]==b[i])
				{
					cout<<a[i]<<endl;
					break;
				}
			}
	}
	return 0;
}
/* homework2.cpp
 *
 *  Created on: 2012-11-10
 *      Author: Lixurong
 */


int gcd( int m, int n );

int main()
{
	int x, y;
	cin >> x >> y;
	cout << gcd( x, y );
	return 0;
}

int gcd( int m, int n )
{
	if( n>m )
		return gcd( m, n/2 );
	else if( m>n)
		return gcd( m/2, n );
	else
		return m;
}
int main() {
	int x, a[2][10], i, j, k, len[2], f;
	x = i = j = k = f = 0;
	memset(a, 0, sizeof(a));
	memset(len, 0, sizeof(len));
	for (j=0; j<2; j++) {
		scanf("%d", &x);
		i=0;
		do {
			a[j][i] = x;
			if (x % 2 == 1)
				x--;
			x /= 2;
			i++;
		} while (x != 1 && x != 0);
		a[j][i] = 1;
		len[j] = i;
		/*
		for (; i>=0; i--)
			printf("%d ", a[j][i]);
		printf("\n");
		*/
	}
	if (a[0][0] == a[1][0]) {
		printf("%d", a[0][0]);
		f = 1;
	}
	else {
		for (i=len[0], j=len[1]; i>=0 && j>=0; i--, j--) {
			if (a[0][i] != a[1][j]) {
				printf("%d", a[0][i+1]);
				f = 1;
				break;
			}
			if (i == 0) {
				printf("%d", a[0][0]);
				break;
			}
			if (j == 0) {
				printf("%d", a[1][0]);
				break;
			}
		}
	}
	//getchar();getchar();
	return 0;
}
int min(int x,int y){
    if (x>y) {
        return y;
    }
    else return x;
}
int max(int x,int y){
    if (x<y) {
        return y;
    }
    else return x;
}
int main(){
    int x,y,a,b,logofa;
    cin>>x>>y;
    a=min(x,y);
    b=max(x,y);
    logofa=(log(a)/log(2.0));
    while (b>=(pow(2.0, logofa+1))) {
        b=b/2;
    }
    while (a>0) {
        if (a==b) {
            cout<<a;
            break;
        }
        a=a/2;
        b=b/2;
        
    }
        
}
/*
?? - 1062 ???	
??


??????????1, 2, 3, ...???????????????????????????1???????
??????????10????????(10, 5, 2, 1)??4????????(4, 2, 1)?????1?????
?????????1???????(1)???????x?y???????????????(x1, x2, ... ,1)?
1, y2, ... ,1)??????x = x1?y = y1?????????????i?j????xi ? yj????xi = yj ,
i + 1 = yj + 1, xi + 2 = yj + 2,... ??????????x?y???xi????yj??
????
??????????????x?y???????????1000?
????
?????????xi?
????
10 4
????
2
*/
void main()
{
	int jiaodian(int,int);
	int x,y,a;
	scanf("%d%d",&x,&y);
	a=jiaodian(x,y);
	printf("%d\n",a);
}

int jiaodian(int x,int y)
{
	int a,temp;
	if(x<y)
	{
		temp=x;
		x=y;
		y=temp;
	}
	if(x==y)
		a=x;
	else
		a=jiaodian(x/2,y);
	return a;
}
void main()
{
    void shuzu(int k,int a[10]);
	void zhao(int a[10],int b[10]);
    int n,m,a[10],b[10];
	scanf("%d%d",&n,&m);
	shuzu(m,a);
	shuzu(n,b);
	zhao(a,b);
}
 
void shuzu(int k,int a[10])
{
	int i;
	a[0]=k;
	
	for(i=1;i<10;i++){
	 if(k%2==0)
		a[i]=k/2;
	 else
		 a[i]=(k-1)/2;
	 k=a[i];
	}
}
void zhao(int a[10],int b[10])
{
	int i,j,a0,b0;
	for(i=0;i<10;i++){
	    if(a[i]==1) a0=i;
		if(b[i]==1) b0=i;
	}
	for(i=a0,j=b0;;i--,j--)
		if(a[i]!=b[j]){
			printf("%d\n",a[i+1]);
		break;
		}
}
int f(int a){
	int t;
	if(a%2==0){
		t=a/2;
	}
	else{
		t=(a-1)/2;
	}
	return(t);
}
int main()
{
	int m,n,i,j,p,q,r;
	int a[100],b[100];
	i=0;j=0;
	scanf("%d%d",&m,&n);
	while(m>=1){
		a[i]=m;
		i++;
		m=f(m);
	}
	while(n>=1){
		b[j]=n;
		j++;
		n=f(n);
	}
	for(p=0;p<i;p++){
		r=0;
		for(q=0;q<j;q++){
			if(a[p]==b[q]){
				printf("%d",a[p]);
				r++;
				break;
			}
		}
		if(r>0){
			break;
		}
	}
	return 0;
}
int main()
{
	int x,y,i,j;
	int a[100]={0},b[100]={0};
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
	for(i=1;;i++)
	{
		if (a[i-1]==1) break;
		a[i]=a[i-1]/2;
	}
	for(i=1;;i++)
	{
		if (b[i-1]==1) break;
		b[i]=b[i-1]/2;
	}
	for(i=0;;i++)
	{
		for(j=0;j<100;j++)
		{
			if (a[i]==b[j])
			{
				printf("%d\n",a[i]);
				goto end;
			}
		}
	}
end:
	return 0;
}
int go(int x){

	int y= 0;

	if(x%2== 1)
		y= (x- 1)/ 2;
	else
		y= x/ 2;
	return y;
}

int main(){

	int a[10]= {0}, b[10]= {0}, same= 1, p= 0;

	cin>>a[0]>>b[0];

	int i= 0, j= 0, k= 0;

	while((a[i]> 1) || (b[i]> 1)){
		p= 0;

		for(j= 0; j<= i; j++){
			if(p== 0){
				for(k= 0; k<= i; k++){
					if(a[j]== b[k]){
						same= a[j];
						p= 1;
					}
				}
			}
		}

		a[i+1]= go(a[i]);
		b[i+1]= go(b[i]);
		

		i++;
	}

	cout<<same;

}
void main()
{
	int a,b,i,j,m,q;
	int c[12];
	int d[12];
	int e[12];
	int f[12];
	scanf("%d %d",&a,&b);
	 c[11]=a;
	for(i=10;i>=0;i--)
	{
		m=a%2;
		if(m==0)
		{c[i]=a/2;}
     	else if(m==1)
		{ c[i]=(a-1)/2;}
	    a=c[i];
	}
	
	d[11]=b;
	for(i=10;i>=0;i--)
	{
		m=b%2;
		if(m==0)
		{d[i]=b/2;}
     	else if(m==1)
		{ d[i]=(b-1)/2;}
	    b=d[i];
	}
	
	j=0;
	for(i=0;i<12;i++)
		{
			
			if(c[i]!=0)
			{e[j]=c[i];
			j=j+1;}
			else 
				continue;
		}
	
    j=0;
	for(i=0;i<12;i++)
		{
			
			if(d[i]!=0)
			{f[j]=d[i];
			j=j+1;}
			else 
				continue;
		}
	
	for(i=0;i<11;i++)
	{
		if(e[i]==f[i])
		{
			if(e[i]<=c[11]&&0<e[i])
				q=e[i];
			else 
				q=e[i-1];
		}
		else break;
	}
	printf("%d",q);
	
}
int main()
{
    int x,y,i,a[20],b[20],p=1,q=1;
    scanf("%d %d",&x,&y);
    a[0]=x;
    for(i=1;i<20;i++)
    {
        a[i]=a[i-1]/2;
        if(a[i]==0)
        {
            break;
        }
        p=p+1;
    }
    b[0]=y;
    for(i=1;i<20;i++)
    {
        b[i]=b[i-1]/2;
        if(b[i]==0)
        {
            break;
        }
        q=q+1;
    }
    for(i=0;i<20;i++)
    {
        if(p==1||q==1)
        {
            printf("%d",a[0]);
            break;
        }
        if(p!=1||q!=1)
        {
            if((a[p-1-i]==b[q-1-i])&&(a[p-1-i-1]!=b[q-1-i-1]))
        {
            printf("%d",a[p-1-i]);
            break;
        }
        }
    }
    return 0;
}
main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==b){printf("%d\n",a);}
    else if(a==1||b==1){printf("1\n");}
    else
    {
    int f,i=0,j=0,n,m,t=0;
    int w[500],v[500];
    f=a;
    //if(f==0){w[0]=a;}
    //else{
           w[0]=f;
           //}
    while(f!=0)
    {
      f=f/2;i++;
      w[i]=f;         
    } 
   //printf("%d\n",i);
    f=b;
     //if(f==0){v[0]=b;}
    //else{
           v[0]=f;
           //}
    while(f!=0)
    {
      f=f/2;j++;
      v[j]=f;         
    }
   // printf("%d\n",j);
    if(i<j)
    {   
      for(n=0;n<i;n++)
      {
       for(m=0;m<j;m++)
       {
          if(v[m]==w[n]){printf("%d\n",w[n]);t++;break;}             
       }
       if(t>0){break;}             
      }
    }
    else
    {
       for(n=0;n<j;n++)
      {
       for(m=0;m<i;m++)
       {
          if(w[m]==v[n]){printf("%d\n",v[n]);t++;break;}             
       } 
       if(t>0){break;}             
      } 
    }
}
   getchar();
getchar();
getchar();  
}
int tree(int x,int y){
	if(x<y)return tree(x,(y-y%2)/2);
	if(x>y)return tree((x-x%2)/2,y);
	if(x==y)return x;
}

int main() {
	int a,b;
	cin>>a>>b;
	cout << tree(a,b) << endl;
	return 0;
}
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	while(x>=1&&y>=1){
		 if (x==y) 
		 {printf("%d",x);
          break;
		 }
		 if(x<y) {
			 while(x<y){
             y=y/2;
			 }
		 }
		 else {
			 while(x>y){
             x=x/2;
			 }
		 }
	}
    return 0;
}
int main(){
int x,y,m;
scanf("%d %d",&x,&y);
m=y;
while(x>=1){
	while(y>=1){
	   if(y==x){
		   printf("%d",y); return 0;
	   }
	   y=y/2;
	   //printf("%d %d\n",x,y);
	}
	x=x/2;
	y=m;
}
return 0;
}
/*
 *  1000012850_32.1.cpp
 *  ????????????
 *  Created on: 2010-11-20
 *      Author: William
 */
int main()      //???
{
	int a[12], b[12], i, j, k;
	cin>>a[0]>>b[0];
	if(a[0]!=1)
	{for(i=1;;i++)
	{
		a[i]=((a[i-1]-(a[i-1]%2))/2);
		if(a[i]==1)
			break;
	}}
	if(b[0]!=1)
	{for(i=1;;i++)
	{
		b[i]=((b[i-1]-(b[i-1]%2))/2);
		if(b[i]==1)
			break;
	}}
	for(i=0;i<12;i++)
		{
		   for(j=0;j<12;j++)
		     {
			   k=0;
			   if(a[i]==b[j])
			   {
				   k=1;
			       break;
			   }
		      }
		   if(k==1)
			   break;
		}
	cout<<a[i];
	return 0;
}
void main()
{
  int x,y,cx,cy,t;
  scanf("%d%d",&x,&y);
  t=2;cx=1;
  while(x>=t)
  {
    t=t*2;
	cx++;
  }
  t=2;cy=1;
  while(y>=t)
  {
    t=t*2;
	cy++;
  }
  while(!(x==y))
  {
    if(cx>=cy)
	{
      x=x/2;
	  cx--;
	}
	else
	{
      y=y/2;
	  cy--;
	}
  }
  printf("%d\n",x);
}
/*
 * 1000062703.cpp
 *
 *  Created on: 2010-11-12
 *      Author: Administrator
 */
int cha(int a,int b){
	if(a>b)
		return(cha(a/2,b));
	if(a<b)
		return(cha(a,b/2));
	if(a==b)
		return a;
}
int main(){
	int x,y;
	cin>>x>>y;
	cout<<cha(x,y)<<endl;
	return 0;
}