semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int x,y,t,a,b,i=0,j=0,m;
	scanf("%d%d", &x, &y);
	if(x<y)
	{
		t=x;
		x=y;
		y=t;
	}
	a=x;
	b=y;
	while(a!=1)
	{
		a=a/2;
		i=i+1;
	}
	while(b!=1)
	{
		b=b/2;
		j=j+1;
	}
	m=i-j;
	while(m!=0)
	{
		x=x/2;
		m=m-1;
	}
	while(x!=y)
	{
		x=x/2;
		y=y/2;
	}
	printf("%d\n", x);
	return 0;
}
void main()
{
 int a,b,i=2,j=2,m[11]={0},n[11]={0};
 scanf("%d %d",&a,&b);
 m[1]=a;n[1]=b;
 m[0]=-1;n[0]=-2;
 while(a!=1) {m[i]=a/2;a=a/2;i++;}
 while(b!=1) {n[j]=b/2;b=b/2;j++;}
 i--;j--;
 while(m[i]==n[j]) {i--;j--;}
 printf("%d",m[i+1]);
}
/*
 * 1062.cpp
 *
 *  Created on: 2011-11-15
 *      Author: sony
 */

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


int main()
{
	int x,y;
	cin>>x>>y;
	cout<<route(x,y)<<endl;
	return 0;
}
void main()
{
	int a[12]={0},b[12]={0};
	int x,i,j;
	x=0;
    scanf("%d %d",&a[0],&b[0]);
	for(i=0;i<11;i++)
	{
		a[i+1]=a[i]/2;
		b[i+1]=b[i]/2;
	}
	for(i=0;i<12;i++)
		for(j=0;j<12;j++)
		{
			if(a[i]==b[j])
			{
				printf("%d",a[i]);
				x=1;
				break;
			}
			if(x==1)break;
		}
}
int main()
{
	int f(int x,int y);
	int x,y,i,j,k,l;
	scanf("%d%d",&x,&y);
	l=f(x,y);
	printf("%d",l);
	scanf("%d",&j);
	return 0;
}
int f(int x,int y)
{
	int a;
	if(x==1||y==1) a=1;
	else if(x%2==0&&y%2==1&&x+1==y) a=x/2;
	else if(x==y) a=x;
	else if(x>y) a=f(x/2,y);
	else a=f(x,y/2);
	return a;
}
void main()
{
	int i,j,k;
	int a,b,c;
	int t1,t2;
	int x[100],y[100],z;
	
	
	scanf("%d%d",&a,&b);

	i=0;
	do
	{
		x[i++]=a;
		a/=2;
	}
	while(a>1);
	x[i]=1;
	t1=i;

	
	
	j=0;
	do
	{
		y[j++]=b;
		b/=2;
	}
	while(b>1);
	y[j]=1;
	t2=j;


	for(i=0;i<=t1;i++)
	{
		for(j=0;j<=t2;j++)
		{
			if(x[i]==y[j])
			{
				printf("%d\n",x[i]);
				goto flag;
			}
		}
	}
flag:;
}
int main(){
	int x,y;
	cin>>x>>y;
	int a[11]={x},b[11]={y};	//???a,b??x,y???
	for(int i=1;a[i-1]!=1;i++){
		if(a[i-1]%2==0)
			a[i]=a[i-1]/2;
		else a[i]=(a[i-1]-1)/2;
		}	//??x???
	for(int i=1;b[i-1]!=1;i++){
		if(b[i-1]%2==0)
			b[i]=b[i-1]/2;
		else b[i]=(b[i-1]-1)/2;
		}   //??y???
	for(int j=0;a[j]!=0;j++)
		for(int k=0;b[k]!=0;k++)
			if(a[j]==b[k]){
				cout<<a[j];		//???????,??????xi,??
				a[j+1]=0;
				break;
			}
	return 0;
}
int shangyigejiedian(int);

int main()
{
	int m,n,a,b;
	cin>>a>>b;
	m=a;
	n=b;

	do
	{a=m;
	do
	{
		if (a==b) 
		{
			cout<<a<<endl;
			return 0;
		}
		else a=shangyigejiedian(a);

	}while(a>=1);

	b=shangyigejiedian(b);
	}while(b>=1);

	return 0;
}

int shangyigejiedian(int i)
{
	int shangyigejiedian;
	if(i==1) return 0;
	else
	{
		if(i%2==0) return i/2;
		else return(i-1)/2;
	}
}
/* Note:Your choice is C IDE */
void main()
{int i=0,j=0,flag=0,s1,s2,n,p,a[12],b[12];
	scanf("%d%d",&n,&p);
	while(n>0)
	{a[i]=n;
		n/=2;
		i++;}
    	while(p>0)
	{b[j]=p;
		p/=2;
		j++;}
	for(s1=0;s1<i&&flag!=1;s1++)
	{for(s2=0;s2<j&&flag!=1;s2++)
	{if(a[s1]==b[s2])flag=1;}
	}
	printf("%d",a[s1-1]);
}
int main()
{
	int searchjoint(int x,int y);
	int x,y,flag;
	scanf("%d%d",&x,&y);
	if(x==y)
		flag=x;
	else if(x>y)
		flag=searchjoint(y,x);
	else 
		flag=searchjoint(x,y);
	printf("%d",flag);
	return 0;
}
int searchjoint(int x,int y)
{
	int i,j,t,flag=1;
	for(i=0;i<10 && x>=1;i++)
	{
		for(j=0,t=y;j<10 && t>=1;j++)
		{
			t=t/2;
			if(x==t)
			{
				flag=x;
				break;
			}
		}
		if(flag!=1)
			break;
		x=x/2;
	}
	return flag;
}
void main()
{
	int road_1[10]={0},road_2[10]={0};
	int n,x,y,m,i,j;
	scanf("%d %d",&x,&y);
	
	//?????????
	road_1[0]=x;//?x????
	for(n=1;x!=1;n++)
	{
		if(x%2==0)
		{
			road_1[n]=x/2;
			x=x/2;
		}
		else
		{
			road_1[n]=(x-1)/2;
			x=(x-1)/2;
		}
	}
	
	road_2[0]=y;//?y????
	for(m=1;y!=1;m++)
	{
		if(y%2==0)
		{
			road_2[m]=y/2;
			y=y/2;
		}
		else
		{
			road_2[m]=(y-1)/2;
			y=(y-1)/2;
		}
	}

	//????
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
		{
			if(road_1[i]==road_2[j])
			{
				printf("%d",road_1[i]);
				goto lable;
			}
		}
lable:;
}
//???
int main( )
{
	int fa(int x,int y);
	int x,y;
	cin>>x>>y;
	cout<<fa(x,y);
	return 0;
}
int fa(int x,int y)
{
	int a[10],b[10];
	int i,m,n,p;
	a[0]=x;
	b[0]=y;
	if(x==1||y==1)
		return 1;
	for(i=1;i<=10;i++)
	{
		a[i]=a[i-1]/2;
		m=i;
		if(a[i]==1)
			break;
	}
	for(i=1;i<=10;i++)
	{
		b[i]=b[i-1]/2;
		n=i;
		if(b[i]==1)
			break;
	}
	if(m>n)
		p=n;
	else p=m;
	for(i=0;i<=p;i++)
	{
		if(a[m-i]!=b[n-i])
		{
			break;
		}
	}
	return a[m-i+1];
}
int main()
{
    int xpath[100]={0},ypath[100]={0};
    int xi=0,yi=0;
    cin>>xpath[0]>>ypath[0];
    while(xpath[xi]!=1)
	{
	      xpath[xi+1]=xpath[xi]/2;
	      xi++;
	}
    while(ypath[yi]!=1)
	{
	      ypath[yi+1]=ypath[yi]/2;
	      yi++;
}
while(xi>=0 && yi>=0)
{
	if(xpath[xi]!=ypath[yi])
	{
		cout<<xpath[xi+1]<<endl;
		return 0;
	}
	xi--;
	yi--;
}
cout<<(xi<0?xpath[0]:ypath[0])<<endl;
return 0;
}
int main()
{
	int x[1000], y[1000], i, j, temp;
	scanf("%d%d", &x[0], &y[0]);
	if(x[0]>y[0])
	{
		temp=x[0];
		x[0]=y[0];
		y[0]=temp;
	}
	i=0;
	while(x[i]!=1)
	{
		i++;
		x[i]=x[i-1]/2;
	}
	i=0; j=0;
	while(y[j]!=x[i])
	{
       j++;
	   y[j]=y[j-1]/2;
	   if(y[j]<x[i]) i++;
	}
	printf("%d\n", x[i]);
	return 0;
}
void father(int x,int y)
{
     int r1=0,r2=0;
     for (int i=1;i<12;i++)
     {
           if (x-pow(2,i-1) < pow(2,i-1) && x-pow(2,i-1)>=0)
           r1=i;
           if ((y-pow(2,i-1)) < pow(2,i-1) && (y-pow(2,i-1))>=0)
           r2=i;
           if (r1!=0 && r2!=0)
               break;
      }
      if (r1>r2)
            x=x/pow(2,r1-r2);
      else if (r1<r2)
            y=y/pow(2,(r2-r1));
      if (x==y)
             cout <<x<<endl;
      else
            father(x/2,y/2);
}
int main()
{
     int m,n;
     cin >>m>>n;
     father(m,n);
     return 0;
}
int erchashu(int a,int b)
{
	if(a==b) return(a);
	if(a>b) return(erchashu(a/2,b));
	if(a<b) return(erchashu(a,b/2));
}
void main()
{
	int a,b,c;
	scanf("%d%d",&a,&b);
	c=erchashu(a,b);
	printf("%d",c);
}
int main()
{
	int m,n,x[12],y[12],i,j,l1,l2,t=0;
	scanf("%d%d",&m,&n);
	x[0]=m;y[0]=n;
	for(i=1;x[i-1];i++)
		x[i]=x[i-1]/2;
	l1=i-1;
	for(i=1;y[i-1];i++)
		y[i]=y[i-1]/2;
	l2=i-1;
    for(i=0;i<l1;i++){
		for(j=0;j<l2;j++){
			if(x[i]==y[j]){
				printf("%d",x[i]);
				t=1;
				break;
			}
		}
		if(t) break;
	}
    return 0;
}
void main()
{
	int a,b,i,j,e,f;
	int c[99],d[99];
	scanf("%d %d",&a,&b);
	c[0]=a;
	d[0]=b;
	for (i=0;i<=100;i++)
	{
		if (c[i]%2==0)
			c[i+1]=c[i]/2;
		else c[i+1]=(c[i]-1)/2;
		if (c[i]==1)
			break;
	}
	for (j=0;j<=100;j++)
	{
		if (d[j]%2==0)
			d[j+1]=d[j]/2;
		else d[j+1]=(d[j]-1)/2;
		if (d[j]==1)
			break;
	}
	int g=0;
	for (e=0;e<=i;e++)
	{
		for (f=0;f<=j;f++)
		{
			if (c[e]==d[f])
			{	
				printf("%d\n",c[e]);
				g=1;
			}
		}
		if (g==1)
			break;
	}

   
}
int main()
{
	int a[15],b[15],i,j,t;
	cin>>a[0]>>b[0];
	
	//????a???
	for(i=0;a[i]>0;i++)
		a[i+1]=a[i]/2;
	for(j=0;j<=i/2-1;j++)       //"<="!!!!!!!!
	{
		t=a[j];a[j]=a[i-1-j];a[i-1-j]=t;
	}
	a[i]=-1;

	
	//????b???
	for(i=0;b[i]>0;i++)
		b[i+1]=b[i]/2;
	for(j=0;j<=i/2-1;j++)
	{
		t=b[j];b[j]=b[i-1-j];b[i-1-j]=t;
	}
	b[i]=-1;

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

int f(int x,int y)
{
	int z;
	if(x==y) {z=x;return z;}
	else if(x/2*2==x&&y/2*2==y)
	{
		x=x/2;
		y=y/2;
		z=f(x,y);
	}
	else if(x/2*2!=x&&y/2*2!=y)
	{
		x=(x-1)/2;
		y=(y-1)/2;
		z=f(x,y);
	}
	else if(x/2*2!=x&&y/2*2==y)
	{
		x=(x-1)/2;
		y=y/2;
		z=f(x,y);
	}
	else if(x/2*2==x&&y/2*2!=y)
	{
		x=x/2;
		y=(y-1)/2;
		z=f(x,y);
	}
}
void main()
{
    int x,y,a,b,flag=1;
    scanf("%d %d",&x,&y);
    for(b=y;b>=1;b=b/2)
    {
    	for(a=x;a>=1;a=a/2)
        {
        	if(a==b) 
        	{
        		if(flag==1)
        		{
        			printf("%d",a);
        			flag=0;
        		}
        	}
        }
    }
    
}
int main()
{
	int x[1000]={0},y[1000]={0};
	cin>>x[0]>>y[0];
	for(int i=0;x[i]!=1;i++)
	{
		if(x[i]%2==1)
			x[i+1]=(x[i]-1)/2;
		else
			x[i+1]=x[i]/2;
	}
	for(int i=0;y[i]!=1;i++)
	{
		if(y[i]%2==1)
			y[i+1]=(y[i]-1)/2;
		else
			y[i+1]=y[i]/2;
	}
	for(int i=0;i<1000;i++)
	{
		for(int j=0;j<1000;j++)
		{
			if(x[i]==y[j])
			{
				cout<<x[i]<<endl;
				j=1000;
				i=1000;
			}
		}
	}
	return 0;
}
int main()
{
	int t,n,m;
	cin>>n>>m;
	while(1)
	{
		if(n<m)
		{
			t=n;n=m;m=t;
		}
		if(n==m)
		{
			cout<<n;
			return 0;
		}
		if(n-1==m&&n%2==1)
		{
			cout<<n/2;
			return 0;
		}
		n/=2;
		if(m==1)
		{
			cout<<"1";
			return 0;
		}
	}
}
void tree(int a,int b)
{
	if(a==b) printf("%d",a);
	else
	if(a>b)
	{
		if(a>=2*b)
			tree(a/2,b);
		else
			tree(a/2,b/2);
	}
	else
		tree(b,a);
}

int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	tree(x,y);
	return 0;
}
void main()
{
	int x[11]={0},y[11]={0},i,j,flag=1;
	scanf("%d%d",&x[0],&y[0]);
	for(i=0;i<10;i++)
	{
		x[i+1]=x[i]/2;
		if(x[i]==1)
		{
			break;
		}
	}
	for(j=0;j<10;j++)
	{
		y[j+1]=y[j]/2;
		if(y[j]==1)
		{
			break;
		}
	}
	for(i=0;i<11;i++)
	{
		if(x[i]==1)
		{
			printf("1\n");
			break;
		}
		for(j=0;j<11;j++)
		{
			if(x[i]==y[j])
			{
				printf("%d\n",x[i]);
				
				if(x[i+1]==y[j+1])
				{
					flag=0;
				}
				break;
			}
		}
		if(flag==0)
		{
			break;
		}
	}
}
int min (int m,int n)
{
	if (m<n) return m;
	else return n;
}
int main()
{
	int x,y,a[100],b[100],i,j,k,p,m,n,x0,y0;
	cin>>x>>y;
	x0=x;
	y0=y;
	for(i=0;x>=1;i++)
	{
		a[i]=x;
		x=x/2;
	}	
	m=i;																				//m??????????????a[m-1];
	for(i=0;y>=1;i++)
	{
		b[i]=y;
		y=y/2;
	}	
	n=i;
	int flag=0;
	for(i=0;i<min(m,n);i++)
	{
		if(a[m-1-i]!=b[n-1-i])
		{
			flag=a[m-i];
			break;
		}
	}
	if(flag!=0) cout <<flag;
	else cout <<min(x0,y0);
	return 0;
}
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	int i,j;int j2=1;int a1,b1;b1=b;
	for(i=1;;i++)
	{
		int i1=1,j1=1;
		a1=a;
		for(j=1;;j++)
		{
			if(a1!=b1)
			{
				a1/=2;j1++;j2=j1;
				if(a1==0)
					break;
			}
			else 
			{i1=0;break;}
		}
		if(i1==0)
			break;
		else
			b1/=2;
	}
	if(a==1)
		printf("1");
	
	else if(j2==1)
		printf("%d",a);
	else
	{
		for(i=1;i<j2;i++)
		{
			a/=2;
		}
		printf("%d",a);
	}
	
scanf("%d",&i);
	return 0;
}
int common(int a,int b);
void main()
{
    int x,y;
	scanf("%d %d",&x,&y);
	printf("%d",common(x,y));
}
int common(int a,int b)
{
	if(a==b) return a;
	if(a>b) return common(a/2,b);
	return common(a,b/2);
}
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++)
                {
              l1:
{if(y==k)
break;	}		
                   y/=2;
                    if(y==k)
                    {
                       printf("%d",y);
                       break;
                    }
                    else
                     for(j=0;k>1;j++) 
                        {
                        k/=2;
                          if(y==k)
						  {printf("%d",y);
						  goto l1;}
		       }			    
                      if(k==1)
                          k=n;
                       
                }
}
}
void main()
{
	int x,y,i,countx,county,c,p,q;
	int a[11]={0},b[11]={0};
	scanf("%d %d",&x,&y);
	countx=1;
	county=1;
	c=0;
	p=x;
	q=y;
	while (p!=1)
	{
		countx++;
		p=p/2;
	}
		while (q!=1)
	{
		county++;
		q=q/2;
	}
		for(i=countx;i>=1;i--)
		{
			a[i]=x;
			x=x/2;
		}
		for(i=county;i>=1;i--)
		{
			b[i]=y;
			y=y/2;
		}
		for (i=1;i<=10;i++)
		{
			if(a[i]==b[i]&&a[i]!=0&&b[i]!=0) c=a[i];
			else break;
		}
	printf("%d",c);
}
/*int days(int month,int day)
{
	int z=0;
	int k;
	if (month==1) z=day;
	else
	{
		for(k=1;k<month;k++)
		{
			if(k==1||k==3||k==5||k==7||k==8||k==10||k==12) z+=31;
			else if (k==2) z+=28;
			else z+=30;
		}
		z+=day;
	}
	return z;
}*/
/*
 *???? ???
 *????: 2012-11-21
*/
void tree(int x,int y){//?????????
	if(x==y)
		cout << x;
	else if(x<y)
		tree(x,y/2);
	else if(x>y)
		tree(x/2,y);
}
int main (){
	int x,y;
	cin >> x >> y;//?????
	tree(x,y);//??x1
	return 0;
}
void main()
{
	int x,y,a[1000],b[1000],i,j,mx,my,flag=0;
	scanf("%d %d",&x,&y);
	*a=x;
	for(mx=1;mx<1000;mx++)
	{
		*(a+mx)=*(a+mx-1)/2;
        if(*(a+mx)==0) break;
	}
	*b=y;
	for(my=1;my<1000;my++)
	{
		*(b+my)=*(b+my-1)/2;
        if(*(b+my)==0) break;
	}
	for(i=0;i<=mx;i++)
	{
		for(j=0;j<=my;j++)
		{
			if(*(a+i)==*(b+j))
			{
				flag=1;
				break;
			}
		}
		if(flag==1) break;
	}
	printf("%d",*(a+i));
}
int main(){
	int x,y,an[15]={0},bn[15]={0};
	scanf("%d%d",&x,&y);
	int i=0,j=0,t=1;
	while(x!=0){
		an[i]=x;
		x=x/2;
		i++;
	}
	while(y!=0){
		bn[j]=y;
		y=y/2;
		j++;
	}
	while(1){
		if(an[i-t]!=bn[j-t]||i-t<0||j-t<0)break;
		t++;
	}
	printf("%d",an[i-t+1]);
	return 0;
}
//**************************************************
//* ????1.cpp                                  *
//* ?  ?????                                 *
//* ?????2010?11?                           *
//* ????????                               *
//**************************************************
int t(int,int);                                               //????t??n????x
int x,y;                                                      //??????x,y
int main()
{	
	int i,j,m,n;
	cin>>x>>y;
	for(i=0;i<100;i++)                                        //?????x??1?????     
	{
		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))           //?????y??1?????
			break;
	}
	int flag=0;                                              //????flag=0
	for(m=1;m<=i;m++)
	{
		for(n=1;n<=j;n++)
		{
			if(t(m,x)==t(n,y))
			{cout<<t(m,x)<<endl;flag=1;break;}               //??x??y??????????????flag??1
		}
		if(flag)              
			break;                                           //??????                               
	}
	
	return 0;	
}

int t(int n,int h)                                           //?????x????n???????x(n)
{
	int f;

	if(n==1)                                                 //???????x(??y)
		f=h;
	else
	f=t(n-1,h)/2;                                            //????
	return f;
}
int kuso(int x)
{
	int i;
	for(i=0;;i++)
	if(x>=pow(2,i-1)&&x<pow(2,i))
		break;
	return(i);
}
void main()
{
	int a,b,a1,b1,a2[100],b2[100],b3,a3,i,j,x,y;
	scanf("%d %d",&a,&b);
	a1=kuso(a);
	b1=kuso(b);
	x=a1;
	y=b1;
	while(a1!=0)
	{	
		a2[a1]=a;
		a3=(a-pow(2,a1-1))/2+pow(2,a1-2);
		a=a3;
		a1--;
	}
	while(b1!=0)
	{	
		b2[b1]=b;
		b3=(b-pow(2,b1-1))/2+pow(2,b1-2);		
		b=b3;
		b1--;
	}

	for(i=x;i>0;i--)
		for(j=y;j>0;j--)
			if(a2[i]==b2[j])
			{
				printf("%d",a2[i]);
				goto loop;
			}
loop:printf("\n");
}
int main(int argc, char* argv[])
{
	int iaX[11], iaY[11];
	int x,y, i, j, ilenx=0, ileny=0;
	int itemp;
	int imin;
	scanf("%d%d", &x, &y);
	for (i=0; i<11; i++)
	{
		iaX[i]=-1;
		iaY[i]=-1;
	}

	i=0;
	while(x>0)
	{
		iaX[i++]=x;
		x/=2;
		ilenx++;
	}
	i=0; j=ilenx-1;
	while(i<j)
	{
		itemp=iaX[i];
		iaX[i]=iaX[j];
		iaX[j]=itemp;
		i++; j--;
	}

	i=0;
	while(y>0)
	{
		iaY[i++]=y;
		y/=2;
		ileny++;
	}
	i=0; j=ileny-1;
	while(i<j)
	{
		itemp=iaY[i];
		iaY[i]=iaY[j];
		iaY[j]=itemp;
		i++; j--;
	}

	imin=ilenx>ileny? ileny:ilenx;
	for (i=0;i<imin; i++)
	{
		if (iaX[i]!=iaY[i])
		{
			break;
		}
	}
	printf("%d", iaX[--i]);

	return 0;
}
int main()
{
  int m,n,a[13]={0},b[13]={0},i1,i2,e,f,i3,c[13]={0},d[13]={0},i4=0;
  scanf("%d %d",&m,&n);
  a[0]=m;
  b[0]=n;
  for(i1=1;m>0;i1++)
  {
   a[i1]=m/2;
   m=m/2;
  }
  for(i2=1;n>0;i2++)
  {
   b[i2]=n/2;
   n=n/2;
  }
  for(i3=12;i3>=0;i3--)
  {
   if(a[i3]!=0) {c[i4]=a[i3];i4++;}
  }
  i4=0;
  for(i3=12;i3>=0;i3--)
  {
   if(b[i3]!=0) {d[i4]=b[i3];i4++;}
  }
  for(i3=0;i3<13;i3++)
  {
    if(c[i3]!=d[i3]||(c[i3]==0&&d[i3]==0))
    {
    printf("%d",c[i3-1]);
    break;
   }
  }
 return 0;
}
int main()
{
	int a[12]={100,100,100,100,100,100,100,100,100,100,100,100},b[12]={99,99,99,99,99,99,99,99,99,99,99,99},i,c,d,e;
	void x(int o[],int q);
	void y(int p[],int w);
	scanf("%d%d",&d,&e);
	x(a,d);
	y(b,e);
	for(i=1;i<11;i++)
	{
       c=a[i];
	   if(a[i+1]!=b[i+1])
		   break;
	}
	printf("%d\n",a[i]);
	return 0;
}
void x(int o[],int q)
{
	int m,u;
	if(q==1)
		m=1;
	else if(q<4)
		m=2,u=2;
	else if(q<8)
		m=3,u=4;
	else if(q<16)
		m=4,u=8;
	else if(q<32)
		m=5,u=16;
	else if(q<64)
	    m=6,u=32;
	else if(q<128)
		m=7,u=64;
	else if(q<256)
		m=8,u=128;
	else if(q<512)
		m=9,u=256;
	else
		m=10,u=512;
	o[m]=q;
	o[m-1]=u/2+(q-u)/2;
	if(m>2)
	x(o,o[m-1]);
}
void y(int p[],int w)
{
	int n,v;
	if(w==1)
		n=1;
	else if(w<4)
		n=2,v=2;
	else if(w<8)
		n=3,v=4;
	else if(w<16)
		n=4,v=8;
	else if(w<32)
		n=5,v=16;
	else if(w<64)
	    n=6,v=32;
	else if(w<128)
		n=7,v=64;
	else if(w<256)
		n=8,v=128;
	else if(w<512)
		n=9,v=256;
	else
		n=10,v=512;
	p[n]=w;
	p[n-1]=v/2+(w-v)/2;
	if(n>2)
	x(p,p[n-1]);
}
int main(int a,int b){scanf("%d%d",&a,&b);while(a!=b){while(a>b)a/=2;while(a<b)b/=2;}printf("%d\n",a);}
int main()
{
	int m, n;
	scanf("%d %d", &m, &n);
	int x[10000], y[10000];
	x[0]=m;y[0]=n;
	int i=0, j=0, num1, num2;
	if(m==1 || n==1) {int k=1; printf("%d\n", k);}
	else
	{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;
		num1=i+1;
	}
	while(y[j]>1)
	{
		if(y[j]%2==0) y[j+1]=y[j]/2;
		else y[j+1]=(y[j]-1)/2;
		j=j+1;
		num2=j+1;
	}
	int judge;
	for(i=num1, j=num2;i>=0;i--)
	{
		if(x[i]==y[j]){j=j-1; judge=x[i];}
	}
	printf("%d\n", judge);
	}
	return 0;
}
void count (int ,int );
int flag;
int main()
{  int m,n,temp;
  cin>>m>>n;
  if( m > n )
  {
	  temp = n;
	  n = m;
	  m = temp;
  }	
  flag = 0;
  for(int i=m;i>=1 && flag  == 0;i = i/2 )
  {
	count (n,i);
  }
  return 0;
}
 void count (int n,int i)
 {   
	 if( n < 1 || n < i )
	 {
		 return ;
	 }
	 else
	 {
		 if(i == n)
		 {
	    	cout<<i<<endl;
			flag = 1;
			return ;
		 }
		 else
		 {
			count(n/2,i);
		 }
	 }
	 return ;
 }
/*
 * erchashudigui.cpp
 *
 *  Created on: 2010-11-26
 *      Author: 378073652
 */

int s=0;

int common(int x ,int y,int s){
	if(x==y) return x;
	if(x>y)  {s++;   return common(x/2,y,s);}
	if(x<y)   {      s++;   return common(x,y/2,s);}
}
int main(){
	int a,b;

	cin>>a>>b;
	cout<<common(a,b,s)<<endl;

 }
/*
 * 1.cpp
 *
 *  Created on: 2011-11-15
 *      Author: 1100012870
 */
int main()
{
	int p[1001],f[1001],i,x,y;
	f[1]=1;
	for(i=2;i<=1000;i++){
		f[i]=i/2;
	}
	cin>>x>>y;
	memset(p,0,sizeof(p));
	p[1]=1;
	while(x!=1){           //?x?????????
		p[x]=1;            //??x?????
		x=f[x];
	}
	while(p[y]!=1) y=f[y];     //??y?????????x????????
	cout<<y<<endl;
	return 0;
}
int main()
{
	int common(int,int);
	int x=0,y=0;
	cin>>x>>y;
	cout<<common(x,y)<<endl;
	return 0;
}
int common(int x,int y)
{
	if(x==y)
		return x;
	if(x>y)
		return common(x/2,y);
	else
		return common(x,y/2);
}
int x(int a,int b);
main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",x(a,b));
}
int x(int a,int b)
{
	if(a>b)
	{a=a/2;
	return x(a,b);}
    if(a<b)
	{b=b/2;
	return x(a,b);}
	if(a=b)
	return a;
}
void main()
{
	int m,n,i,j,k,a[100],b[100],c[100];
	scanf("%d %d",&m,&n);
		a[0]=m;
		for(i=0;a[i]>=1;i++)
		{
			if(a[i]%2==0)
			a[i+1]=a[i]/2;
			if(a[i]%2==1)
				a[i+1]=(a[i]-1)/2;
		}
		b[0]=n;
		for(j=0;b[j]>=1;j++)
				{
					if(b[j]%2==0)
					b[j+1]=b[j]/2;
					if(b[j]%2==1)
						b[j+1]=(b[j]-1)/2;
				}
		for(i=0;a[i]>=1;i++)
		{
			for(j=0;b[j]>=1;j++)
			{
				if(b[j]==a[i])
				{
					k=a[i];
					break;
				}
			}
			if(k==a[i])
			break;
			
		}
		printf("%d",k);
}
/*
 * T.cpp
 *
 *  Created on: 2011-11-5
 *      Author: dell
 */
int main()
{
	int x,y,i,j,flag=1;
	cin>>x>>y;
	int a[x],b[y];
	a[0]=x;b[0]=y;
	for(i=1;i<=x;i++)
		a[i]=0;
	for(i=1;i<=y;i++)
			b[i]=0;
	for(i=0;i<=x;i++)
		a[i+1]=a[i]/2;
	for(j=0;j<=y;j++)
		b[j+1]=b[j]/2;
	for(i=0;i<=x;i++)
	{
		for(j=0;j<=y;j++)
			if(a[i]==b[j])
			{
				cout<<a[i]<<endl;
				flag=0;
				break;
			}
		if(flag==0)
			break;
	}
	return 0;
}
int count(int b,int c)
{
	if (c==1) return 1;
	long k,i,sum=0;
	double t=c;
	for (i=b;i<=c;i++)
       if (c%i==0)
		   sum+=(count(i,c/i));
    return sum;
}

void main()
{ 
	int n,m,p[2000]={0},sum=0,tmp;
	scanf("%d%d",&n,&m);
	if (n>m)
	{
		tmp=n;
		n=m;
		m=tmp;
	}
	do
	{
		p[n]=1;
		n=n/2;
	} while (n>0);
	do
	{
		if (p[m]) 
		{
			printf("%d",m);
			return;
		}
		m=m/2;
	} while (m>0);
}
int x,y;
int *p1=&x;
int *p2=&y;
void Read()
{
	scanf("%d%d",p1,p2);
}
/*int array for Pathway a[11],b[11]*/
int a[11]={0},b[11]={0};
/*int Function return Answer (x>=2^(Answer-1)&&x<(2^Answer))   as  FuncofA  */
int FuncofA(int X)
{
	int i;
	for(i=1;;i++)
	{
		if((pow(2.0,i-1)<=X)&&pow(2.0,i)>X)
		{
			return i;
		}
		else
		{}
	}
}
/*Function for binary tree  as  FuncofB*/
void FuncofB()
{
	int i;
	for(i=(FuncofA(x));i>=1;i--)
	{
		a[i-1]=x;
		x/=2;
	}
	for(i=(FuncofA(y));i>=1;i--)
	{
		b[i-1]=y;
		y/=2;
	}
}
void main()
{
	Read();
	if(x==y)
	{
		goto equal;
	}
	else
	{
		goto unequal;
	}
equal:
	printf("%d",x);
	goto End;
unequal:
	FuncofB();
	int i;
	for(i=1;;i++)
	{
		if(a[i-1]==b[i-1])
		{}
		else
		{
			printf("%d",a[i-2]);
			break;
		}
	}
End:
	;
}
void main()
{
	int a[10000],b[10000];
	int x,y,i,k,j;
	scanf("%d %d",&x,&y);
	if(x==y)printf("%d\n",x);
	else if(x*y==x||x*y==y)printf("1");
	else
	{
	for(i=2;;i++)
	{
		a[0]=0;
		a[1]=x;

	

		if(x%2==1)
		{
			x=(x-1)/2;
			a[i]=x;
		}
		else
		{
			x=x/2;
			a[i]=x;
		}
	if(x==1)break;
	}

	b[1]=y;
	b[0]=1;
	for(j=2;;j++)

	{
	
		

		if(y%2==1)
		{
			y=(y-1)/2;
			b[j]=y;
		}
		else
		{
			y=y/2;
			b[j]=y;
		}
       if(y==1)break;

	}
	for(k=0;;k++)
	{
		if(a[i-k]!=b[j-k])
			break;
	}
	printf("%d\n",a[i-k+1]);
	}
}
void main()
{
	int c[15],d[15],p,q,i,x,j,m,n;
	scanf("%d%d",&n,&m);
	i=0;
	do
	{
		c[i]=n;
		n=n/2;
		i=i+1;
	}while(n>0);
	p=i;
	i=0;
	do
	{
		d[i]=m;
		m=m/2;
		i=i+1;
	}while(m>0);
	q=i;x=0;
	for(i=0;i<p;i++)
	{
		if(x==1) break;
	 else for(j=0;j<q;j++)
			if(c[i]==d[j])
			{
				printf("%d",c[i]);
				x=1;
				break;
			}
	}
}
/*
 * 1000012739_32_2.cpp
 *
 *  Created on: 2010-11-22
 *      Author: ???
 *		Title: 1062 ???
 */



int main()
{
	int x,y,m;		//?????m??????x
	cin>>x>>y;		//????x?y
	while (y!=1)
	{
		m=x;		//m????x
		while (m!=1)
		{
			if (m==y)		//?????
			{
				cout<<m;	//?????
				return 0;	//????
			}
			m/=2;			//x???????
		}
		y/=2;		//y???????
	}
	cout<<1;		//?y=1????1
	return 0;		//????
}
void main()
{
	int findout(int x,int y);
	int m,n,num;
	scanf("%d%d",&m,&n);
	num=findout(m,n);
	printf("%d\n",num);
}

int findout(int x,int y)
{
	int a[500],b[500],i,j,k=0,l=0,t,c;
	a[0]=x;
	for(i=1;x!=1;i++)
	{
		if(x%2==1)
		{
			x=(x-1)/2;
			a[i]=x;
		}
		else if(x%2==0)
		{
			x=x/2;
			a[i]=x;
		}
	}
	k=i;
	for(i=0;i<=(k-1)/2;i++)
	{
		t=a[i];
		a[i]=a[k-1-i];
		a[k-1-i]=t;
	}

	b[0]=y;
	for(j=1;y!=1;j++)
	{
		if(y%2==1)
		{
			y=(y-1)/2;
			b[j]=y;
		}
		else if(y%2==0)
		{
			y=y/2;
			b[j]=y;
		}
	}
	l=j;
	for(j=0;j<=(l-1)/2;j++)
	{
		t=b[j];
		b[j]=b[l-1-j];
		b[l-1-j]=t;
	}

	for(i=0;i<k;i++)
	{
		if(a[i]==b[i]&&a[i+1]!=b[i+1]) break;
	}

	if(a[k-1]==1||b[l-1]==1) c=1;
	else c=a[i];
	
	return(c);
}
int main()
{
 int x,y,m[11],n[11],i,j,k;
 scanf("%d%d",&x,&y);
 m[0]=x;
 n[0]=y;
 for(i=1;i<11;i++)
  {m[i]=m[i-1]/2;
   n[i]=n[i-1]/2;}
 for(i=0;i<11;i++)
  for(j=0;j<11;j++)
   if(m[i]==n[j]) 
   {printf("%d",n[j]);
    j=11;
    i=11;}
}
int kuai(int x,int y);
int main()
{
    int a,b;
    cin>>a>>b;
    kuai(a,b);
    return 0;
}

int kuai(int x,int y)
{
    if(x==y)
    cout<<x<<endl;
    if(x<y)
    kuai(x,y/2);
    if(x>y)
    kuai(x/2,y);
    return x;
}
void main()
{
	int a[20],b[20]={0},x,y,i,j,a0,b0,ia,jb,word=0;
	scanf("%d%d",&x,&y);
	a[0]=x,b[0]=y;
	for(i=1;a0!=1;i++)
	{
		if(a[i-1]%2==0)a[i]=a[i-1]/2;
		else a[i]=(a[i-1]-1)/2;
		a0=a[i];
	}
	ia=i;
	for(j=1;b0!=1;j++)
	{
		if(b[j-1]%2==0)b[j]=b[j-1]/2;
		else b[j]=(b[j-1]-1)/2;
		b0=b[j];
	}
	jb=j;
	for(i=0;i<ia;i++)
	{
		for(j=0;j<jb;j++)
			if(b[j]==a[i])/*word=1,printf("%d\n",a[i])*/break;
		if(/*word==1*/b[j]==a[i])break;
	}
	printf("%d\n",a[i]);
}