semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
/*
 * ???.cpp
 *
 *  Created on: 2010-11-23
 *      Author: acer
 */

int main()
{
	int a,b,i=0,j=0,k;					//ab?????????ij??????????
	int a_line[20],b_line[20];			//?????????ab???
	cin>>a>>b;
	while(a!=0)							//?????
	{
		a_line[i]=a;
		a=a/2;
		i++;
	}
	while(b!=0)
	{
		b_line[j]=b;
		b=b/2;
		j++;
	}
	if(i>j)								//??ab???????
	{
		for(k=0;k<j;k++)
			if(a_line[i-j+k]==b_line[k])//????????????????Break
			{
				cout<<b_line[k];
				break;
			}
	}
	else								//???????
		for(k=0;k<j;k++)
			if(b_line[j-i+k]==a_line[k])
			{
				cout<<a_line[k];
				break;
			}
	return 0;
}
int f(int i)
{
	int c;
	if(i==0)
		c=1;
	else
		c=f(i-1)*2;
	return(c);
}
main()
{
	int m;
	int n;
	int i;
	int j;
	int c=0;
	int k=0;
	int a[11]={0};
	int b[11]={0};
	scanf("%d %d",&m,&n);
	a[0]=m;
	b[0]=n;
	for(i=1;i<10;i++)
	{
		if(m/f(i)==0)
			break;
		a[i]=m/(f(i));
	}
	for(i=1;i<10;i++)
	{
		if(n/f(i)==0)
			break;
		b[i]=n/(f(i));
	}
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(a[i]==b[j])
			{
				k=i;
				c=1;
				break;
			}
		}
		if(c>0)
			break;
	}
	printf("%d",a[i]);
}
int next(int x)
{
	int z;
	if(x%2==0)
		z=x/2;
	else
		z=(x-1)/2;
    return(z);
}
int main()
{
	int x,y;
	int i,j,num1=1,num2=1;
	int z[11],k=0;
	int a[100],b[100];
    scanf("%d%d",&x,&y);

	a[0]=x;
	b[0]=y;
	for(i=1;;i++)
	{
        a[i]=next(x);
		x=a[i];
		num1++;
		if(a[i]==1||a[i-1]==1)
			break;
	}
    for(i=1;;i++)
	{
        b[i]=next(y);
		y=b[i];
		num2++;
		if(b[i]==1||b[i-1]==1)
			break;
	}

	for(i=0;i<num1;i++)
		for(j=0;j<num2;j++)
		{
			if(a[i]==b[j])
			{
				z[k]=a[i];
			    k++;
			}
			
		}
	printf("%d\n",z[0]);

}
int fuc(int b[100],int m)
{
	int i,t;
	b[0]=m;
	for(i=1;b[i-1]!=1;i++)
	{	b[i]=(b[i-1]-b[i-1]%2)/2;
	}
	return (i-1);
}
void main()
{
	int i,j,m,n,a[100],b[100];
	scanf("%d %d",&m,&n);
	i=fuc(a,m);
	j=fuc(b,n);
	for(;a[i]==b[j];i--,j--);
	printf("%d",a[i+1]);
}
int main() {
	int x,y;
	cin>>x>>y;
	int i,j;
	int p,q;
	int k=0;
	p=0;q=0;
	int c=1;
	int d=1;
	int a[11],b[11],f[11];
    for (i=1;i<=10;i++)
		{c=c*2;
	    if (c>x)
	    	{p=i;break;}}
	for (i=1;i<=10;i++)
	{
		d=d*2;
		if (d>y)
			{q=i;break;}
	}
	for (i=0;i<=p;i++)
	{
		a[i]=x;
		x=x/2;
	}
	for (i=0;i<=q;i++)
	{
		b[i]=y;
		y=y/2;
	}
	for (i=0;i<=p;i++)
		for (j=0;j<=q;j++)

			if (a[i]==b[j]&&a[i]!=0)
				{ f[k]=a[i];k++;}
cout<<f[0]<<endl;


	return 0;
}
void main()
{
	int m,n,i,j,root=0,a[10]={0},b[10];
	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;a[i]>1;i++)
	{
		for(j=0;b[j]>1;j++)
		{
			if(a[i]==b[j])
			{
				root=a[i];
				break;
			}
		}
		if(root!=0)break;
	}
	if(root==0)root=1;
		printf("%d",root);
}
void main()
{
	int a[2][10]={0};
	int i,j;

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

	for(i=1;a[0][i]==0;i++)
	{
		a[0][i]=a[0][i-1]/2;
	}
		 
	for(j=1;a[1][j]==0;j++)                          
	{
		a[1][j]=a[1][j-1]/2;
	}

	for(i=0;a[0][i]!=0;i++)
	{
		for(j=0;a[1][j]!=0;j++)
		{
			if(a[0][i]==a[1][j])
			{
				goto k;
			}
		}
	}

   k:printf("%d",a[1][j]);
}
int main ()
{
	int i,j,x,y,p,q,m,n;
	cin>>x>>y;
	for(i=0;i<11;i++)
	{
		if(pow(2.0,i)>x)   {p=i;m=x-pow(2.0,i-1)+1;break;}
	}
	for(i=0;i<11;i++)
	{
		if(pow(2.0,i)>y)    {q=i;n=y-pow(2.0,i-1)+1;break;}
	}
	for(;;)
	{
		if(p==q)
		{
			if(m==n)   {cout<<pow(2.0,p-1)+m-1;return 0;}
			else
			{
				for(;;)
				{
					p--;q--;
				    if(m%2==0)  m=m/2;
			        else if(m%2==1)  m=m/2+1;
					if(n%2==0)  n=n/2;
			        else if(n%2==1)  n=n/2+1;
					if(m==n)break;
				}
			}
		}
		else if(p>q)
		{
			p--;
			if(m%2==0)  m=m/2;
			else if(m%2==1)  m=m/2+1;
		}
		else
		{
			q--;
			if(n%2==0)  n=n/2;
			else if(n%2==1)  n=n/2+1;
		}
	}
	return 0;
}
int main()
{
	int x,y,i,j,sign=0;
	int a[1000]={0},b[1000]={0};
	scanf("%d%d",&x,&y);

	if(x<y)
	{	a[0]=x;b[0]=y;}
	else
	{	a[0]=y;b[0]=x;}

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

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

	for(i=0;a[i]!=0;i++)
	{
		for(j=0;b[j]!=0;j++)
		{
			if(a[i]==b[j])
			{
				printf("%d\n",a[i]);
				sign=1;
				break;
			}
		}
		if(sign==1)
			break;
	}
	return 0;
}
int main()

{

	int a[100]={0},b[100]={0},x,y,i,j;

	cin>>x>>y;

	a[1]=x;

	b[1]=y;
	
	for(i=1;a[i]>=1;i++)

	{

		a[i+1]=a[i]/2;

	}

	for(j=1;b[j]>=1;j++)

	{

		b[j+1]=b[j]/2;

	}

	int m,n,panduan=0;

	for(m=1;m<=i-1;m++)

	{

		for(n=1;n<=j-1;n++)

		{

			if(a[m]==b[n])

			{

				panduan=1;

					break;

			}

		}

		if(panduan==1)

			break;

	}

	cout<<a[m];

	return 0;

}
struct node{
	int x;
	int layer;
	int t;
}a[3];//????????????????????????

void main()
{
	int i,j,tmp,sign=0,sign1=0,sign2=0;
	scanf("%d %d",&a[1].x,&a[2].x);
	if(a[1].x==a[2].x) printf("%d\n",a[1].x);
	else
	{
		if(a[1].x==1||a[2].x==1) printf("1\n");
		else
		{
			if(a[1].x<a[2].x) {tmp=a[1].x;a[1].x=a[2].x;a[2].x=tmp;}//?????
			for(i=1;i<=10;i++)
			{
				if(a[1].x>=pow(2,i)&&a[1].x<pow(2,i+1)) {a[1].layer=i+1;sign1=1;}
				if(a[2].x>=pow(2,i)&&a[2].x<pow(2,i+1)) {a[2].layer=i+1;sign2=1;}
				if(sign1)
					if(sign2) break;
			}//????????
			a[1].t=a[1].x;
			a[2].t=a[2].x;
			for(i=a[1].layer,j=a[2].layer;i>=1;)
			{
				if(a[1].t%2) a[1].t=(a[1].t-1)/2;
				else a[1].t=a[1].t/2;
				i--;
				if(i==a[2].layer){
					if(a[1].t==a[2].t) {printf("%d\n",a[1].t);sign=1;break;}}
				else 
					if(i<a[2].layer)
					{
						do{
							if(a[2].t%2) a[2].t=(a[2].t-1)/2;
							else a[2].t=a[2].t/2;
							j--;
						}while(j>i);
						if(a[2].t==a[1].t) {printf("%d\n",a[1].t);sign=1;break;}
					}
			}
		}
	}
}
void main()
{
	int a[100]={0},b[100]={0},c[10];
	int i,j,x=0,y=0,k=0;
	scanf("%d %d",&a[0],&b[0]);
	for(i=0;i<100;i++)
	{
		if(a[i]>=2)
		{
			a[i+1]=a[i]/2;
			x++;
		}
	}
	for(j=0;j<100;j++)
	{
		if(b[j]>=2)
		{
			b[j+1]=b[j]/2;
			y++;
		}
	}
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
			if(a[i]==b[j]&&a[i]!=0&&b[j]!=0)
			{c[k]=a[i];
			k++;
				
				
			}
	}
	printf("%d",c[0]);
}
void main()
{
	void change(int *p1,int *p2);
    int a,b;
	scanf("%d %d",&a,&b);
	while(a!=b)
	{
		if(a>b) 
		{
			change(&a,&b);
		}
		b=b/2;
	}
	printf("%d\n",a);
}

void change(int *p1,int *p2)
{
	int temp;
	temp=*p1;
	*p1=*p2;
	*p2=temp;
}
int main()
{
    int x,y,x0,y0,result,flag=0;
    
    scanf("%d %d",&x,&y);
    
    x0=x;y0=y;
    for (x=x0;x>=1;x/=2)
        for (y=y0;y>=1;y/=2)
            if (x==y&&flag==0)
            {
               result=x;
               flag=1;
            }
    
    printf("%d\n",result);
    getchar();getchar();
    
    return 0;
    
}
void main()
{
	int a,b,i,x1[100],x2[100],j,m,k,flag=0;
	scanf("%d %d",&a,&b);
	x1[0]=a;
	x2[0]=b;
	for(i=1;;i++)
	{
		x1[i]=x1[i-1]/2;
		if(x1[i]==0)
		break;
	}
    for(j=1;;j++)
	{
		x2[j]=x2[j-1]/2;
		if(x2[j]==0)
		break;
	}
	for(k=0;k<=i;k++)
	{
		for(m=0;m<=j;m++)
		{
			if(x1[k]==x2[m])
			{
				printf("%d",x1[k]);
				flag=1;
				break;
			}
			
		}
      if(flag==1)
		  break;
	}

}
int  common(int x,int y); 
int main()
{
	int x,y;
	while(cin>>x>>y)
	{
		cout<<common(x,y);
	}
	return 0;
}
int common(int x,int y)
{
	if(x==y)
	return x;
	else
	{
		int p;
		if(x>y)
		return common((int)x/2,y);
		else
		return common(x,(int)y/2);
	}
}
int m,n;
int f(int a,int b)           //????????????????????????????2??????
{
    while(a>=2*b)
    {
        a=a/2;
    }
    while(b>=2*a)
    {
        b=b/2;    //???????a?b??????????????????????????ab???????
    }
    if(a>b)                       //??a??b??????????ab???????a?b?????
    {
        while(a!=b&&a/2!=b)        //?????a?a/2????b
        {
            a=a/2;
            b=b/2;
        }
        return b;
    }
    if(b>a)
    {
        while(a!=b&&a!=b/2)         //??
        {
            a=a/2;
            b=b/2;
        }
        return a;
    }
    if(a==b)   return a;

}
int main()
{
    cin >> m >> n ;
    cout<<f(m,n)<<endl;       //??????????
    return 0;
}
int k=0;
void findrouteA(int *ay,int n,int m);

int main()
{
	int a,b;
	int ay[10]={0},by[10]={0};//????a,b???
	int i,j;
	int end1,end2;
	int an,am,bn,bm;//??a,b?????????
	scanf("%d%d",&a,&b);
	for(i=1,j=1;j<a+1;i++,j+=j);
	an=i-1;
	am=a-( int )pow(2,i-2)+1;

	for(i=1,j=1;j<b+1;i++,j+=j);
	bn=i-1;
	bm=b-( int )pow(2,i-2)+1;//you cuo

	
	findrouteA(ay,an,am);
	end1=k-1;
	k=0;
	findrouteA(by,bn,bm);
	end2=k-1;


	for(end1,end2;ay[end1]==by[end2];end1--,end2--);
	printf("%d",ay[end1+1]);
	return 0;
}
void findrouteA(int *ay,int n,int m)
{
	if(n==1)
		ay[k++]=1;
	else
	{
		ay[k++]=( int )pow(2,n-1)-1+m;
		findrouteA(ay,n-1,( int )(m+1)/2);
	}
}
int main(){
	int a[100],b[100],i=0,j=0;
	cin>>a[0]>>b[0];
	while(a[i]>1)
	{a[i+1]=a[i]/2;
	 i++;
	}
	while(b[j]>1)
	{b[j+1]=b[j]/2;
	j++;
	}

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

}
int f(int a,int b)
{
	int w;
	if(a==b)
		w=a;
	if(a>b)
		w=f(a/2,b);
	if(a<b)
		w=f(a,b/2);
	return w;

}
void main()
{
	int x,y,a[11]={2},b[11]={3},i=0,j=0,t,n=0,k;
	scanf("%d%d",&x,&y);
	while(x>0)
	{
		a[i+1]=x%2;
		x=(x-x%2)/2;
		i++;
	}
	while(y>0)
	{
		b[j+1]=y%2;
		y=(y-y%2)/2;
		j++;
	}
	t=i;
	while(a[i]==b[j])
	{
		i--;
		j--;
	}
	for(k=t;k>=i+1;k--)
		n=n*2+a[k];
	printf("%d",n);
}
int main(int argc, char* argv[])
{
	int n1,n2,j=1,k=1,a[1000],b[1000],i=1,m=1,number,break1;
	scanf("%d%d",&n1,&n2);
	if (n1==1||n2==1)
		printf("1\n");
	else
	{
		a[0]=n1;
	    b[0]=n2;
		while(n1>1)
		{
		if (n1%2==0)
		{	
			n1=n1/2;
		    a[i]=n1;
			i++;
		}
		else {n1=(n1-1)/2;a[i]=n1;i++;}
		j++;
		}
		while(n2>1)
		{
		if (n2%2==0)
		{	
			n2=n2/2;
		    b[m]=n2;
			m++;
		}
		else {n2=(n2-1)/2;b[m]=n2;m++;}
		k++;
		}
		for (i=0;i<j;i++)
		{
			for (m=0;m<k;m++)
			{
				if (a[i]==b[m])
				{
					number=a[i];
				break1=0;
				break;
				}
			}
               if (break1==0)
					break;
		}
				printf("%d",number);
	}
	return 0;
}
void main()
{
	int x,y;
	int a[2000]={0};
	int b[2000]={0};
	int i,j,k;
	int p;
	int l=0;
	a[0]=1;
	b[0]=1;

/*	for(p=0;p<1000;p++)
	{
		a[p]=1;
		b[p]=1;
	}
*/

	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;
	}

	for(k=0;k<=i&&k<=j;k++)
	{
		if(a[i-k]==b[j-k])
			continue;
		else
		{
			printf("%d",a[i-k+1]);
			l=1;
			break;
		}
	}
	if(l==0)
		printf("%d",a[i-k+1]);
}
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	while(x!=y)
	{
		if(x>=2*y)
		{
			x=x/2;
		}
		else if(y>=2*x)
		{
			y=y/2;
		}
		else
		{
			x=x/2;
			y=y/2;
		}
	}
	printf("%d",x);
	return 0;
}
int cmp(int x,int y)//????cmp
{
	if(x==y)//???????x
		return x;
	else//??????????2????????
	{
		if(x>y)
		{
			x=x/2;
		}
		if(x<y)
		{
			y=y/2;
		}
		cmp(x,y);
	}
}
int main()//???
{
	int x,y;//??????x,y
	cin>>x>>y;//????
	cout<<cmp(x,y);//?????????
	return 0;
}
int t,m,n,i,j,k,xx,x1,x2,x,y,s,n0;


void init(int a[],int b[])
{    freopen("tt.in","r",stdin);
     scanf("%d%d",&m,&n);
	 for (i=1;i<=m;i++) 
		 
			 scanf("%d",&a[i]);
	 for (i=1;i<=n;i++) 
		 
			 scanf("%d",&b[i]);
			 
	 }

void output(int a[],int k)
{
 int i;
	freopen("tt.out","w",stdout);
	for(i=1;i<=k;i++) if (i==1) printf("%d",a[i]); else printf(" %d",a[i]);
}
 void proce(int x,int y)
{
	if (x==y) printf("%d\n",x);
	else 
	if (x>y) proce(x/2,y);
	else
	proce(x,y/2);
	
	
	
}
	
int main()
{
//freopen("tt.in","r",stdin);
//freopen("tt.out","w",stdout);
	scanf("%d%d",&x,&y);
	
	proce(x,y);
	
	 
return 0;
}
int main ()
{
int x[1000],y[1000],i,j,a,b,m,n,p=0;
 scanf ("%d %d",&a,&b);
 x[0]=a;y[0]=b;
if (a==1||b==1)
{
  printf("1");
}
else if (a==b)
{ 
	printf("%d",a);

} 

else{
for (i=1;a>0;i++)
{
  if (a%2==0)
  {
    x[i]=(a/2);
    a=a/2;
   }
  if (a%2!=0&&a!=1)
  {
    x[i]=(a-1)/2;
	a=x[i];
  }
if (a==1)
	 { x[i]=1;  a-=1; }
  m=i;
}

for (j=1;b>0;j++)
{
  if (b%2==0)
  {
    y[j]=(b/2);
    b=b/2;
   }
  if (b%2!=0&&b!=1)
  {
    y[j]=(b-1)/2;
	b=y[j];
  }
 if (b==1)
 {
   y[j]=b;
   b-=1;
 }
  n=j;
}




  for (i=0;i<=m;i++)
  {
   for (j=0;j<=n;j++)
   {
     if (x[i]==y[j])
	 {
	    printf("%d",x[i]);
        p=1;
	 }
    if (p==1)
		break;
   }
   if (p==1)
	   break;
  }
}

return 0;
}
int main ()
{
	int a,b;
	cin >> a >>b ;
	int x[11],y[11],xi[11],yi[11];
	int i,j,k;
	for (i=0;i<=11;i++)
	{
		x[0]=a;
		if (x[i]==1) break;
		else x[i+1]=x[i]/2;
	}
	for (j=0;j<=i;j++)
		xi[j]=x[i-j];
	for (i=0;i<=11;i++)
	{
		y[0]=b;
		if (y[i]==1) break;
		else y[i+1]=y[i]/2;
	}
	for (j=0;j<=i;j++)
		yi[j]=y[i-j];
	for (k=0;k<=i;k++)
	{
		if (xi[k]-yi[k]!=0) break;
	}
	cout << xi[k-1];
	return 0;
}
int find(int,int);
int main()
{
    int ans;
    int x,y;
    cin>>x>>y;
    ans=find(x,y);
    cout<<ans<<endl;
    return 0;
}
int find(int x,int y)
{
    if(x==y) return x;
    if(x>y) return find(y,x);
    else return find(x,y/2);
}
int main()
{
	
	int i,j,a,e,f,d,h,g;
    int k,m,n;
	int y[1000],x[1000],z[1000];
	scanf("%d%d",&m,&n);
	for(i=1;m>0;i++){
		x[i]=m;
		m=m/2;
	}
	for(j=1;n>0;j++){
		y[j]=n;
		n=n/2;
	}
	for(k=1;k<i;k++){
		for(h=1;h<=j;h++){
			if(x[k]==y[h]){
				printf("%d",x[k]);
				goto A;
			}
	}
	}
	A:
	
		return 0;
}
int main()
{
	int a[10],b[10],m,n,i,ceng1,ceng2;
	scanf("%d%d",&m,&n);
	for(i=0;i<=9;i++)
		a[i]=-1;
	for(i=0;i<=9;i++)
		b[i]=-2;
	a[0]=m;
	b[0]=n;
	if(m==1||n==1)
		printf("1");
	else
	{
		for(i=1;i<=9;i++)
		{
			a[i]=a[i-1]/2;
			if(a[i]==1)
			{
				ceng1=i;
				break;
			}
		}
		for(i=1;i<=9;i++)
		{
			b[i]=b[i-1]/2;
			if(b[i]==1)
			{
				ceng2=i;
				break;
			}
		}
		for(i=1;i<=10;i++)
		{
			if(a[ceng1+1-i]==b[ceng2+1-i]&&a[ceng1-i]!=b[ceng2-i])
			{
				printf("%d",a[ceng1+1-i]);
				break;
			}
		}
	}
	return 0;
}
int com(int x, int y)
{
	int t;
	if(x==y) t=x;
	else 
		t=(x>y)?com(x/2,y):com(x,y/2);
	return t;
}
void main ()
{
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d\n",com(x,y));
}
/*
 *erchashu.cpp
 *?????????????
 *Created on: 2011-11-11
 *Author: ???
 */
int main(){
	int a,b;
	cin>>a>>b;
	while(a!=b){
		if(a>b) a=(a-a%2)/2;//??
		else b=(b-b%2)/2;
	}
	cout<<a<<endl;
	return 0;
}
int main()
{
    int x,y,a[12],b[12];
    cin>>x>>y;
    a[0]=b[0]=1;
    while (x!=1)
    {
        a[a[0]]=x;
        a[0]++;
        x=x/2;
    }
    a[a[0]]=1;

    while (y!=1)
    {
        b[b[0]]=y;
        b[0]++;
        y=y/2;
    }
    b[b[0]]=1;

    int k=0;
    while (a[a[0]-k]==b[b[0]-k]) k++;

    if (a[0]-k+1==0) cout<<a[1];
    else cout<<a[a[0]-k+1];
    return 0;
}
int main(int argc, char* argv[])
{
	int a, b, c, d;
	scanf("%d %d",&a,&b);
	c=1;
	while(c==1)
	{
		if(a>b)
			a=a/2;
		if(a<b)
			b=b/2;
		if(a==b)
		{
			c=0;
			printf("%d",a);
		}
	}
	return 0;
}
void shu(int c[],int k)
{
	if(c[k-1]!=1)
	{
	
	if(c[k-1]%2==0)
	{
		c[k]=c[k-1]/2;
		k++;
		shu(c,k);
	}
	else
	{
		c[k]=(c[k-1]-1)/2;
		k++;
		shu(c,k);
	}
}

	
}
int main()
{
	int a[100]={0},b[100]={0},i,j,s=0,q;
	cin>>a[1];
	cin>>b[1];
	shu(a,2);
	shu(b,2);
	for(i=1;i<=99;i++)
	{
		for(j=1;j<=99;j++)
		{
			if(a[i]==b[j]&&a[i]>0)
			{
				cout<<a[i];
				s=1;
				break;
			}
		}
		if(s==1)
		break;
	}
	cin>>q;
	return 0;
}
void main()
{
	int x[100],y[100],i,j,p,q,k,temp=0;
	scanf("%d%d",&x[0],&y[0]);
	for(i=0;x[i]!=0;i++)
	{
		
		x[i+1]=x[i]/2;
	}
    for(p=0;y[p]!=0;p++)
	{
     
		y[p+1]=y[p]/2;
	}
	for(q=0;q<=i;q++)
	{
		for(j=0;j<=p;j++)
		{
			if(x[q]==y[j])
			{
				temp=1;
				k=q;
				break;
			}
		}
		if(temp==1)
			break;
	}
	printf("%d",x[k]);
}
/*
 * ???????.cpp
 * ??????????x?y???????????1000
 *      ?????????????????
 * ????: 2010-11-20
 * ??: ??
 */



int main() {
	//??x?y
	int x, y;
	cin >> x;
	cin >> y;

	//?xArray?yArray??x?y????2??
	int xArray[11], yArray[11];
	int i, j;
	for (i = 0; i < 11; i++) {
		xArray[i] = x;
		yArray[i] = y;
		x /= 2;
		y /= 2;
	}

	//????????xArray?yArray???????????????
	for (i = 0; i < 11; i++) {
		for (j = 0; j < 11; j++) {
			//??????????????????
			if (xArray[i] == yArray[j]) {
				cout << xArray[i] << endl;
				i = j = 11;
			}
		}
	}
	return 0; //????
}
int f(int n,int m)
{
	if(n==m)
		return n;
	else
	{
		if(n/2>m)
			return f(n/2,m);
		else
			return f(m,n/2);
	}
}
int main()
{
    int n,m;
	cin>>n>>m;
	if(n<m)
	{
			n = n^m;
			m = n^m;
			n = n^m;
	}
		
	cout<<f(n,m)<<endl;
    return 0;
}
int main()
{
    int x,y,i,j,n=1,m=1,a[15],b[15],p=0;
    cin>>x>>y;//????
    a[0]=x;b[0]=y;
    for(i=1;a[i-1]!=1;i++) {a[i]=a[i-1]/2;n++;}//???????
     for(i=1;b[i-1]!=1;i++) {b[i]=b[i-1]/2;m++;}
     if(x>=y)//??????????????
     {
         for(j=0;j<m;j++)
          {for(i=0;i<n;i++)
          {
              if(a[i]==b[j]) {cout<<a[i];p=1; break;}
          }
           if(p) break;
          }
     }
     else { for(i=0;i<n;i++)
          {for(j=0;j<m;j++)
          {
              if(a[i]==b[j]) {cout<<a[i];p=1; break;}
          }
           if(p) break;
          }
          }
          return 0;
}
/*
 * ????ercha.cpp
 * ?????x,y,?xi.
 * ????: 2012-11-30
 * ??: ?   ?
 */



int main()
{
	int x = 0, y = 0;//?????????
	cin >> x >> y;//??????
	while ( x != y )
	{
		if ( x > y )  x = x/2;//??x>y,??x?????
		else y = y/2;//???y?????
	}
	cout << x << endl;//?????
	return 0;//????
}
void main()
{
	int x,y;
	int i,j,k;
	int a[100],b[100];

	scanf("%d %d",&x,&y);
	for(i=0;x>0;i++)
	{
		a[i]=x;
		x=x/2;
	}
	i=i-1;
	for(j=0;y>0;j++)
	{
		b[j]=y;
		y=y/2;
	}
	j=j-1;
	for(k=0;k<=i&&k<=j;k++)
	{if(a[i-k]!=b[j-k])
	break;}
	if(a[i-k]!=b[j-k])
		printf("%d",a[i-k+1]);
	else if(k==i+1)
		printf("%d",a[0]);
	else if(k==j+1)
		printf("%d",b[0]);




}
int main()
{
	int x,y,a[40]={0},b[40]={0},x1,y1,i,j;
	scanf("%d%d", &x, &y);
	if(x==y)
	{
		printf("%d\n", x);
		return 0;
	}
	if(x==1 || y==1)
	{
		printf("1\n");
		return 0;
	}
	x1=sqrt(x);
	y1=sqrt(y);
	a[0]=x;
	b[0]=y;
	for(i=1;i<=x1;i++)
	{
		a[i]=a[i-1]/2;
	}
	for(i=1;i<=y1;i++)
	{
		b[i]=b[i-1]/2;
	}
	for(i=0;i<=x1;i++)
	{
		for(j=0;j<=y1;j++)
		{
			if(b[j]==a[i])
			{
				printf("%d\n", a[i]);
				return 0;
			}
		}
	}
}
int  cnt_row(int a);								//??????()
int main()  										//???
{
	int x , y , i ,p;
	cin >> x >> y;						//???????x?y
	if(x<y)
	{
		int temp;
		temp=x;
		x=y;
		y=temp;
	}
	p=cnt_row(x)-cnt_row(y);			//???x?y?????????????
	for(i=0; i<p; i++)
		x=x/2;
	while(x!=y)							//xy???????????????????
	{
		if(x%2==0)
		   x=x/2;
		else
			x=(x-1)/2;
	if(y%2==0)
		   y=y/2;
		else
			y=(y-1)/2;
	}
	cout << x;
	return 0;
}
int cnt_row(int a)						//????x,y???????
{
	int cnt=0;
	while(a != 0)
	{
		a=a/2;
		cnt++;
	}
	return cnt;
}
int main(int argc, char* argv[])
{
	int a,b;
	int c1=0,c2=0;
	scanf("%d%d",&a,&b);
	int t[10000],m[10000];
	int i,j;
	if(a==b)
	{
		printf("%d",a);
	}
	else if(a==1||b==1)
	{
		printf("1");
	}
	else 
	{
		t[1]=a;
	for(i=2;a!=1;i++)
	{
		a=a/2;
		t[i]=a;
		c1++;
	
		
	
	}
	m[1]=b;
	for(j=2;b!=1;j++)
	{
		b=b/2;
		m[j]=b;
		c2++;
	
	}
	for(i=1;i<=c1;i++)
	{
		for(j=1;j<=c2;j++)
		{
			if(t[i]==m[j])
				break;
		}
		if(t[i]==m[j])
			break;
	}
		
	
	printf("%d",t[i]);
	}





	return 0;
}
int main()
{
    int x,y;
    int p;
    int a[10];
    int b[10];
    int i=0,j=0,k,m;
    scanf("%d%d",&x,&y);
    do
    {
    if (x>y)
    {
        x=x/2;
    }
    else
    if (y>x)
    {
        y=y/2;
    }
    if(x==y)
        {
            printf("%d",x);
        }
    }
    while(x!=y);

    return 0;
}
int f(int x,int y){//????f(x)???????
	while(x!=y){
		if(x>y)x=x/2;
		else y=y/2;
	}
	return x;
}
int main(){
	int a,b;
	cin>>a>>b;//????????
	cout<<f(a,b)<<endl;//???????
	return 0;
}
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	int xp[12]={0},yp[12]={0};
	xp[0]=x; yp[0]=y;
	int xstp=0,ystp=0;
	int i;
	for(i=1;x>1;i++){
		x=x/2;
		xp[i]=x;
		xstp+=1;
	}
	for(i=1;y>1;i++){
		y=y/2;
		yp[i]=y;
		ystp+=1;
	}
	for(i=0;;i++){
		if(xp[0]==yp[0]){
			printf("%d",xp[0]);
			break;
		}
		if(xp[xstp-i-1]!=yp[ystp-i-1]&&xp[xstp-i]==yp[ystp-i]){
			printf("%d",xp[xstp-i]);
			break;
		}
	}
	return 0;
}
int main() {
	int x, y, i = 1, j = 1, xi;
	cin >> x >> y;
	int a[1001] = { 0 }, b[1001] = { 0 };
	a[1] = x;
	b[1] = y;
	while ( a[i] >= 1) {
		a[i + 1] = a[i] / 2;
		i ++;
	}
	while ( b[j] >= 1) {
		b[j + 1] = b[j] / 2;
		j ++;
	}
	while ( a[i] == b[j] && i >= 1 && j >= 1) {
		xi = a[i];
		i --;
		j --;
	}
	cout << xi << endl;
	return 0; 
}
int I=0;

int root(int *a,int n)
{
	*(a+I)=n;
	I++;
	if(n!=1){
		if(n%2==0)
			root( a,n/2 );
		else
			root( a,(n-1)/2 );
	}
	return I;
}

void main()
{
	int a0,b0,a[MAX],b[MAX],m,n,i,j,flag=0;
	scanf("%d%d",&a0,&b0);
	m=root(a,a0);
	I=0;
	n=root(b,b0);
	
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if( *(a+i)==*(b+j) ){
				printf("%d\n",*(a+i));
				flag=1;
				break;
			}
		}
		if(flag)
			break;
	}
}
f(int m,int n)
{
  if (m<n)
    return f(m,n/2);
  else if (m>n)
    return f(m/2,n);
  else 
  return m;
}
        
int main(int argc, char *argv[])
{
  int x,y;
  scanf("%d%d",&x,&y);
  printf("%d",f(x,y));
  return 0;
}
void main()
{int a,b,c=0,d=0;scanf("%d%d",&a,&b);
if(a==b)printf("%d",a);
else{
for(;a;)c=(c<<1)|(a&1),a>>=1;
for(;b;)d=(d<<1)|(b&1),b>>=1;
a=c^d,c=0;
for(;(a&1)==0;)c=(c<<1)|(d&1),a>>=1,d>>=1;
printf("%d",c);}}
int f(int a,int b)
{
	
	if(a==b)
		return a;
	else if(a>b)
		 return f(a/2,b);
	else if(a<b)
		 return f(a,b/2);

}



int main()
{
	int x,y;
	cin>>x>>y;
	f(x,y);
	
	cout<<f(x,y)<<endl;


	return 0;
}
int f(int a,int b)
{
	if(a==b) return a;
	else if(a>b) {a=a/2;return f(a,b);}
	else {b=b/2;return f(a,b);}
}
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<f(x,y)<<endl;
    return 0;
}
int main(int argc, char* argv[])
{

int a,b,c;
int i;
scanf("%d %d",&a,&b);


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

	return 0;
}
//**************************************************
//* ????1.cpp                                  *
//* ?  ?????                                 *
//* ?????2010?11?                           *
//* ????????                               *
//**************************************************
int t(int,int);
int x,y;
int main()
{	
	int i,j,m,n;
	cin>>x>>y;
	for(i=0;i<100;i++)
	{
		if(x>=pow(2.0,(i-1)*1.0)&&x<pow(2.0,i*1.0))
			break;
	}
	
	for(j=0;j<100;j++)
	{
		if(y>=pow(2.0,(j-1)*1.0)&&y<pow(2.0,j*1.0))
			break;
	}
	for(m=1;m<=i;m++)
	{
		for(n=1;n<=j;n++)
		{
			if(t(m,x)==t(n,y))
			break;
		}
		if(t(m,x)==t(n,y))
			break;
	}
	cout<<t(m,x)<<endl;
	
	return 0;	
}

int t(int n,int h)
{
	int f;

	if(n==1)
		f=h;
	else
	f=t(n-1,h)/2;
	return f;
}
void common(int a,int b);
void main()
{
    int x,y;
	scanf("%d %d",&x,&y);
	common(x,y);
}
void common(int a,int b)
{
	if(a==b) printf("%d",a);
    else if((a/2)==b) printf("%d",b);
    else if(a==(b/2)) printf("%d",a);
    else if(a/2>b) common(a/2,b);
	else if(b/2>a) common(a,b/2);
    else common(a/2,b/2);
}
int main()
{
int x,y,a[10000],b[10000],i,j,k,p;
scanf("%d %d",&x,&y);
if(x==y)
printf("%d",x);
else
{
a[1]=x;
b[1]=y;
for(i=2;;i++)
{
if(a[i-1]==1)
break;
else if(a[i-1]%2==0)
a[i]=(a[i-1]/2);
else a[i]=((a[i-1]-1)/2);
}
for(j=2;;j++)
{
if(b[j-1]==1)
break;
else if(b[j-1]%2==0)
b[j]=(b[j-1]/2);
else b[j]=((b[j-1]-1)/2);
}
for(k=i-1,p=j-1;;k--,p--)
if(a[k]!=b[p])
break;
printf("%d",a[k+1]);
}
}
int main()
{
	int x,y,l1=0,l2=0,i,j,k=0;
	scanf("%d%d",&x,&y);
	int s1[10]={0},s2[10]={0};
	int level(int a);
	l1=level(x);
	l2=level(y);
	s1[0]=x;
	s2[0]=y;
	for(i=1;i<l1;i++)
	{
		s1[i]=s1[i-1]/2;
	}
	for(i=1;i<l2;i++)
	{
		s2[i]=s2[i-1]/2;
	}
	for(i=0;i<l1;i++)
	{
		for(j=0;j<l2;j++)
			if(s1[i]==s2[j]&&s1[i]!=0&&s2[j]!=0) {k=s1[i];break;}
		if(k!=0) break;
	}
	printf("%d\n",k);
	return 0;
}
int level(int a)
{
	int k=0;
	if(a==1) k=1;
	if(a>1&&a<4) k=2;
	if(a>4&&a<8) k=3;
	if(a>8&&a<16) k=4;
	if(a>16&&a<32) k=5;
	if(a>32&&a<64) k=6;
	if(a>64&&a<128) k=7;
	if(a>128&&a<256) k=8;
	if(a>256&&a<512) k=9;
	else k=10;
	return(k);
}