semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int s(int x,int y);
int main(int argc)
{  int x,y;
    cin>>x>>y;
	cout<<s(x,y);          //??????
	return 0;

}
int s(int x,int y)
{
 if(x==y)
 {return x;}        //?????????????
 else if(x>y)
 {return s(x/2,y);}              //?????????????2????
 else
 {return s(x,y/2);}
};
int main()
{
	int x,y,a[20],b[20],i,j,p,q;
	scanf("%d%d",&x,&y);
	if(x==y)
		printf("%d",x);
	else
	{
		if((x==1)||(y==1))
			printf("1");

	    else
		{
	        a[0]=x;
			for(i=1;i<20;i++)
			{
		        if(a[i-1]%2==0)
		    		a[i]=a[i-1]/2;
	    		else
					a[i]=(a[i-1]-1)/2;
				if(a[i]==1)
				{
					p=i;
					break;
				}
			}
			b[0]=y;
			for(i=1;i<20;i++)
			{
				if(b[i-1]%2==0)
					b[i]=b[i-1]/2;
				else
					b[i]=(b[i-1]-1)/2;
				if(b[i]==1)
				{
					q=i;
					break;
				}
			}
			for(i=0;i<=p;i++)
			{
				for(j=0;j<=q;j++)
				{
					if(a[i]==b[j])
					{
						p=i;
						break;
					}
				}
			}
		printf("%d",a[p]);
		}
	}
	return 0;
}
int a1(int n)
{
	if (n/2==0)
	return 1;
	else
	return (1+a1(n/2));
}
void search(int a,int b)
{
	if (a1(a)==a1(b))
	{
		if (a/2==b/2&&a/2!=b/2)
		{
			cout<<a/2;
		}
		else if(a==b)
		{
			cout<<a;
		}
		else search(a/2,b/2);
	}
		if (a1(a)>a1(b))
		{
			search(a/2,b);
		}
		if (a1(a)<a1(b))
		{
			search(a,b/2);
		}
}




int main()
{
	int x,y;
	cin>>x>>y;
	search(x,y);


}
int X, Y, TX, TY;
int A[256],B[256];
int main()
{
	cin >> X >> Y;
	A[TX = 1] = X;
	B[TY = 1] = Y;
	while (A[TX] > 1)
	{
		A[TX + 1] = A[TX] / 2;
		TX ++;
	}
	while (B[TY] > 1)
	{
		B[TY + 1] = B[TY] / 2;
		TY ++;
	}
	while ((A[TX] == B[TY]) && (TX > 0) && (TY > 0))
	{
		TX --;TY --;
	}
	cout << A[TX + 1] << endl;
}
int main()
{   
    int xunzhao(int x,int y);
	int x,y,q;
	scanf("%d %d",&x,&y);
	q=xunzhao(x,y);
	printf("%d",q);
	
}
int xunzhao(int x,int y)
{
	int q;
	if(x==y)
	q=x;
	if(x>y)
	return  xunzhao(x/2,y);
	if(x<y)
	return  xunzhao(x,y/2);	
	return q;
}
int main()
{
	int a,b,i,j,p,q,m[100],n[100];
	cin>>a>>b;
	m[0]=a,n[0]=b;
	if(a==1||b==1)cout<<'1'<<endl;//?????1?????????1
	else
	{
		for(i=1;;i++)
		{
			m[i]=a/2;
			a=a/2;//?????????????????
			if(a==1)break;//??????1???
		}
		for(j=1;;j++)
		{
			n[j]=b/2;
			b=b/2;
			if(b==1)break;
		}
		for(p=0;p<=i;p++)
		{
			for(q=0;q<=j;q++)
			{
				if(m[p]==n[q]){cout<<m[p]<<endl;return 0;};//?????????????
			}
		}
	}
	
}
int main()
{
	int m,n,i,j,a[12]={100},b[12]={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;

	}

   while(1)
	{if(a[i]!=b[j])
	break;
	   i--;j--;

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

int main(void)
{
	int x,y;
	cin>>x>>y;
	cout<<same(x,y)<<endl;
	return 0;
}
void gaoxiao(int m,int n)
{
	if(m>n)
		m=m/2;
	if(m<n)
		n=n/2;
	if(m==n)
		cout<<m<<endl;
	else
		gaoxiao(m,n);
}
int main()
{
	int m,n;
	cin>>m>>n;
	gaoxiao(m,n);
	char mm;
	cin>>mm;
	return 0;
}
int main()
{
    int x, y, i, a, b, m[20], n[20], j,f=0;
    scanf("%d%d",&x,&y);
    if(x==y)
    {
        printf("%d",x);
    }
    else
    {
    i=0;
    while(x>0)
    {
        m[i]=x;
        x=x/2;
        i++;
    }
    i=0;
    while(y>0)
    {
        n[i]=y;
        y=y/2;
        i++;
    }
    for(i=0;i<13;i++)
    {
        for(j=0;j<13;j++)
        {
            if(m[i]==n[j])
                if(f==0){printf("%d",m[i]);
                         f=1;}
        }
    }
    }
    return 0;
}
int c(int , int);
int main(void){
	int a,b;
	cin>>a>>b;
	cout<<c(a,b)<<endl;
	return 0;
}
int c(int x, int y){
	if(x%y==0) return y;
	if(x>y) return c(x/2,y);
	if(x<y) return c(x,y/2);
}
int main()
{
    int x,y,t,flag=0;
    scanf("%d%d", &x, &y);
    int a[10000]={0}, b[10000]={0},i=0,k=0,m,q,j;
    if(x==y)
    {
                    printf("%d", x);
    }
    else
    {
    if(x<y)
    {
           q=x;
           x=y;
           y=q;
    }
    while(x>0)
    {
              a[i]=x;
               x=x/2;
               
               i++;
    }
    while(y>0)
    {
               b[k]=y;
               y=y/2;
               
               k++;
    }
  
    int flg=0;
    for(t=0;t<i;t++)
    {
                     for(j=0;j<k;j++)
                     {
                                      if(a[t]==b[j])
                                      {
                                      printf("%d", a[t]);
                                      flg=1;
                                      break;
                                      }
                     }
                     if(flg==1)
                     break;
    }
    
    if(flg==0)
    printf("1");
}

    return 0;
}
int tree(int x,int *a)
{
	static int i=1;

	if(x!=1)
	{
		x=x/2;
		*a=x;
		a++;
		tree(x,a);
		i++;
	}
	else
		*a=1;
	return i;
}


int por(int *e,int *r)
{
	static int q;
	if(*e!=*r)
	{printf("%d\n",q);}
	else
	{
		q=*e;
		e--;
		r--;
//		printf("%d %d\n",*e,*r);
		por(e,r);
	}
	return q;
}

void main()
{
	int x,y,a[12],b[12],a1,b1;
	int *a2;
	int *b2;
	int *a3;
	int *b3;
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
	a2=&a[1];
	b2=&b[1];
	a1=tree(x,a2)+1;
	b1=tree(y,b2)-a1+3;
//	printf("%d %d ",a1,b1);
	a3=&a[a1-1];
	b3=&b[b1-1];
	por(a3,b3);
//	printf("%d",*a3);

}
void main()
{
	int a[11],b[11],i,j,p;
	scanf("%d%d",&a[0],&b[0]);
	for(i=1;i<=10;i++)
	{
		a[i]=a[i-1]/2;
		if(a[i]==1)
			break;
	}
	for(j=1;j<=10;j++)
	{
		b[j]=b[j-1]/2;
		if(b[j]==1)
			break;
	}
	for(i=0;i<=10;i++)
	{
		for(j=0;j<=10;j++)
		{
			if(a[i]==b[j])
			{
				printf("%d",a[i]);
                p=1;
				break;
			}
		}
		if(p==1)
			break;
	}
}
/****************************************************
 * dt03.cpp											*
 *													*
 *  Created on: 2010-11-22							*
 *      Author: Administrator						*
 ****************************************************/
int main()
{
	int a[10];
	int b[10];															//??????
	cin>>a[0]>>b[0];													//??????????
	int i=1,j=1;
	while(true)															//?????????????????????????
	{
		if(a[i-1]%2==0)
		{
			a[i]=a[i-1]/2;
		}
		else
		{
			a[i]=(a[i-1]-1)/2;
		}
		if(a[i]==1)
		{
			break;
		}
		else i++;
	}
	while(true)															//?????????????????????????
	{
		if(b[j-1]%2==0)
		{
			b[j]=b[j-1]/2;
		}
		else
		{
			b[j]=(b[j-1]-1)/2;
		}
		if(b[j]==1)
		{
			break;
		}
		else j++;
	}
	while(i>=0&&j>=0)													//?????????
	{
		if(a[i]==b[j])
		{
			i--;
			j--;
		}
		else
		{
			break;
		}
	}
	cout<<a[i+1];														//???????
	return 0;
}
int main(int argc, char* argv[])
{
    int a[100],b[100];
	int i=1,j=1,x,y,count=0,judge=0;
	scanf("%d%d",&x,&y);
	while(x!=0)
	{ 
		a[i]=x;
		x=x/2;
		i++;
	}
	while(y!=0)
	{
		b[j]=y;
		y=y/2;
        j++;
		count++;
	}
    for(i=1;i<100;i++)
	{
		for(j=1;j<=count;j++)
		{
			if(a[i]==b[j])
			{
				printf("%d\n",a[i]);
				judge=1;

				break;
			}
		}
		if(judge==1)
		{break;}


    }
	
	return 0;
}
int f(int a,int b)
{
	int r1,r2,a2,b2,c;
	r1=0;
	r2=0;

	a2=a;
	b2=b;
	for(;a2!=0;)
	{
		a2=a2/2;
		r1++;
	}
	for(;b2!=0;)
	{
		b2=b2/2;
		r2++;
	}                              
	if(r1>r2)
	{c=pow(2,r1-r2);
	a=a/c;}
	if(r1<r2)
	{c=pow(2,r2-r1);
	b=b/c;}               
	for(;;)
	{
		if(a==b)
		{                     
			printf("%d",a);
			break;
		}
		a=a/2;
		b=b/2;
	}

	return a;

}



int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	f(a,b);

	return 0;
}
int main()
{
	int s,m,n,i,j,t,m1,n1,q=0;
	int a[100];
	int b[100];
	scanf("%d %d",&m,&n);
	m1=m;
	n1=n;
	if(m==1||n==1){
		printf("1");
		return 0;
	}
	if(m==n){
		printf("%d",m);
		return 0;
	}
	a[0]=m;
	b[0]=n;
	for(i=1;;i++){
		if(m1/2==0){
			break;
		}
		m1=m1/2;
		a[i]=m1;
	}
	for(j=1;;j++){
		if(n1/2==0){
			break;
		}
		n1=n1/2;
		b[j]=n1;
	}
	if(m>n){
		s=i;
		t=j;
		for(i=0;i<s;i++){
			for(j=0;j<t;j++){
				if(a[i]==b[j]){
					printf("%d",a[i]);
					q=1;
					break;
				}
			}
			if(q==1)
				break;
		}
	}
	if(m<n){
		s=i;
		t=j;
		for(i=0;i<t;i++){
			for(j=0;j<s;j++){
				if(a[j]==b[i]){
					printf("%d",a[j]);
					q=1;
					break;
				}
			}
			if(q==1)
				break;
		}
	}
	return 0;
}
void main()
{
	int x,y,i,j,c=0,m,n;
	int a[50],b[50];
	scanf("%d %d",&x,&y);
	a[0]=x;
	b[0]=y;
	for(i=1;i<50;i++){
		if(x==1){
			m=i;
			break;
		}
		else{
			a[i]=x/2;
			x=x/2;
		}
	}
	for(i=1;i<50;i++){
		if(y==1){
			n=i;
			break;
		}
		else{
			b[i]=y/2;
			y=y/2;
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if(a[i]==b[j]){
				printf("%d",a[i]);
				c=1;
				break;
			}
		}
		if(c==1){
			break;
		}
	}
}
int main(int argc, char* argv[])
{

	int x,s,c,y,e=0,t,q,n=0,j,b[1000],i,a[1000],num;
	num=1;
	scanf ("%d %d",&x,&y); s=x; c=y;
	if(x==1 || y==1)
		printf ("1\n");
	else{
	do 
	{
		x=x/2;
		n++;
	}
	while (x!=1);
	
	do 
	{	
		e++;
		y=y/2;
	}
	while (y!=1);
	
	e++;
	n++;
	
	
	for (i=1;i<=n;i++)
	{
		a[i]=s;
		s=s/2;
	}
	
	for (j=1;j<=e;j++)
	{
		b[j]=c;
		c=c/2;
	}

	for (t=1;t<=n;t++)
	{	for (q=1;q<=e;q++)
		{
		if (a[t]==b[q]){
				printf ("%d\n",b[q]);
			num =0;
				break;
		}	
		}
		if(num==0)
			break;

       }
	}
		return 0;
}
int F(int a)
{
	if(a%2==0)
		a=a/2;
	else
		a=(a-1)/2;
	return a;
}

int main()
{
	int a,b;
	cin>>a>>b;
	while(a!=b)
	{
		if(a>b)
			a=F(a);
		if(a<b)
			b=F(b);
	}
	cout<<a;
	return 0;
}
int main()
{
  int m,n,i,j,flag=1;
  cin>>m>>n;
  for(i=m;i>0&&flag;i/=2)
   for(j=n;j>0&&flag;j/=2)
    if(i==j)
     {cout<<i;flag=0;}//???????????????????????
  return 0;
}
/**
 *???4.cpp
 *??????
 *??????
 *???11?26
 */
void route(int n,int a[],int c[])   //???????????????????????????
{
      c[0]=0;
      if(n==1)
	  {a[0]=1;}
      else
	  {route(n/2,a,c);
       c[0]++;
       a[c[0]]=n;}
}
int main()
{
    int x,y,x1;
    int a[12]={0},b[12]={0},c[2];
	cin>>x>>y;
    route(x,a,c);       //??x,y????????a,b?
    route(y,b,c);
    int n1,n2;
    for(n1=0;a[n1]!=0;n1++);  //???????????
    for(n2=0;b[n2]!=0;n2++);
    int j,k,flag=1;
    for(j=n1-1;j>=0;j--)
	{
         for(k=n2-1;k>=0;k--)
		 {
              if(a[j]==b[k])   //???????????????????????
			  {
                  x1=a[j];   //??????????x1
				  flag=0;
                  break;
			  }
		 }
		 if(flag==0)
		 {break;}
		 else
		 {continue;}
	}
	cout<<x1<<endl;   
	return 0;
}
int a(int,int);
main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	printf("%d",a(max(x,y),min(x,y)));
}
int a(int m,int n)
{
	while(m>n)
	{
		m/=2;
	}
	if(m==n)
		return m;
	else
		return a(n,m);
}
/*
 * 1000012712_322.cpp
 *Author:???
 * Created on: 2010-11-21
 * ????????
 */
int main(){
	int x[1000],a[1000],y[1000];
	cin>>x[1]>>y[1];//??????
	int i,j;
	a[0]=1;
	for(i=1;i<100;i++){
	    a[i]=a[i-1]*2;
	}//a[]?2?n???
	for(j=2;j<100;j++){
		if(x[1]==1){
			j=1;
			break;
		}
		for(i=0;i<100;i++){
		   if(x[j-1]<a[i])  break;
	    }
	    int t=a[i-1],m;//t?x[j]????????
	    m=(x[j-1]-t)/2;
	    x[j]=t/2+m;
	    if(x[j]==1)  break;
	}//???x???????
	int n=j;
	for(j=2;j<100;j++){
			for(i=0;i<100;i++){
			   if(y[j-1]<a[i])  break;
		    }
		    int t=a[i-1],m;//t?x[j]????????
		    m=(y[j-1]-t)/2;
		    y[j]=t/2+m;
		    if(y[j]==1)  break;
		}//???y???????
	int m=j;
	for(i=0;i<=100;i++){
		if(x[n-i]!=y[m-i])  break;
	}//???????????
	if((x[1]==1000)&&(y[1]==1000))  cout<<1000<<endl;
	else
		cout<<x[n-i+1]<<endl;//?????
	
	return 0;
}
int find(int a,int b[])
{
	int i,j[100],k,l=a;
	j[0]=1;
	for(i=1;i<100;i++)
		j[i]=2*j[i-1];
	for(i=0;;i++)
	{
		if(a>j[i])
			a=a-j[i];
		else break;
	}
	k=i+1;
	b[0]=l;	
	for(i=1;i<k;i++)
	{
		if(b[i-1]%2==0)
			b[i]=b[i-1]/2;
		else b[i]=(b[i-1]-1)/2;
	}	
	return k;
}

int main()
{
	int sx[1000],sy[1000];                         //????xi?yi
	int x,y,i,j,k,l,xi=0;
	scanf("%d %d",&x,&y);
	if(x==y)
		xi=x;
	else
	{
	i=find(x,sx);
	j=find(y,sy);
	
	for(k=i,l=j;;k--,l--)
	{
		 if(sx[k]!=sy[l])
			xi=sx[k+1];
		if(xi!=0) break;
	}
	}
	printf("%d\n",xi);
}
void main()
{
	int x,y,answerx[100]={0},answery[100]={0},i=1,j=1,p,q,temp,r=0;
	scanf("%d%d",&x,&y);
	answerx[0]=x;
	answery[0]=y;
	while(x!=1)
	{
		if(x%2==0)
		{
			answerx[i]=x/2;
			i++;
			x=x/2;
		}
		else
		{
			answerx[i]=(x-1)/2;
			i++;
			x=(x-1)/2;
		}
	}
	while(y!=1)
	{
		if(y%2==0)
		{
			answery[j]=y/2;
			j++;
			y=y/2;
		}
		else
		{
			answery[j]=(y-1)/2;
			j++;
			y=(y-1)/2;
		}
	}
	for(p=i-1;p>=0;p--)
	{
		for(q=j-1;q>=0;q--)
		{
			if(answerx[p]==answery[q])
			{
				temp=answerx[p];
				r=1;
				break;
			}
		}
	}
	if(r==1)
		printf("%d\n",temp);
	else
		printf("1\n");
}
int main()
{
	int back(int x,int y);
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d\n",back(x,y));
	
	return 0;
}

int back(int x,int y)
{
	int a[100],b[100];
	int i=0,j;
	int n1,n2;
	while (x>0)
	{
		a[i]=x;
		x=x/2;
		i++;
	}
	n1=i;
	i=0;
	while (y>0)
	{
		b[i]=y;
		y=y/2;
		i++;
	}
	n2=i;
	for (i=0;i<n1;i++)
	{
		for (j=0;j<n2;j++)
		{
			if (a[i]==b[j])
			{
				return a[i];
				break;
			}
		}
	}
}
int point(int num)
{
	if(num==1)
	{
		return 1;
	}
	else
	{
		if(num%2==0)
		{
			return num/2;
		}
		else
		{
			return (num-1)/2;
		}
	}
}
int main()
{
	int point(int num);
	int x,y;
	scanf("%d %d",&x,&y);
	int X[11]={x},Y[11]={y},i,j;
	for(i=1;i<11;i++)
	{
		X[i]=point(X[i-1]);
		Y[i]=point(Y[i-1]);
	}
	for(i=0;i<11;i++)
	{
		int signal=0;
		for(j=0;j<11;j++)
		{
			if(X[i]==Y[j])
			{
				printf("%d\n",X[i]);
				signal=1;
				break;
			}
		}
		if(signal==1)
		{
			break;
		}
	}
	return 0;
}
int a[10],b[10];
int main()
{
	int x,y;
	cin>>x>>y;
	int i,j,m,n,l;
	i=1;
	j=1;
	l=1;
	a[i]=x;
	b[j]=y;
	while(a[i]!=1)
	{
		a[i+1]=a[i]/2;
		i=i+1;
	}
	m=i;
	while(b[j]!=1)
	{
		b[j+1]=b[j]/2;
			j=j+1;
	}
	n=j;
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(a[i]==b[j])
			{
				m=i;n=j;l=0;break;
			}
		}
		if(l==0)
		{
			break;}
	}
	cout<<a[m];
	return 0;
}
/*
 * 006.cpp
 *
 *  Created on: 2012-11-24
 *      Author: asus
 */
int common(int x, int y)//??common??
{
	if(x > y) return common(x / 2, y);//???????????2
	if(x < y) return common(x, y / 2);
	return x;//?????
}

int main()//???
{
	int m = 0, n = 0;
	cin >> m >> n;
	cout << common(m, n) << endl;//????
	return 0;
}
int main()
{ 
	int x[20],y[20],i,h[20],j,s;
	for(i=0;i<20;i++){x[i]=0;y[i]=0;h[i]=0;}
    int a,b;
	scanf("%d %d",&a,&b);
	x[1]=a;y[1]=b;
	for(i=2;x[i-1]>1;i++)
		x[i]=x[i-1]/2;
	for(i=2;y[i-1]>1;i++)
		y[i]=y[i-1]/2;
	for(j=1;y[j]!=0;j++)
	for(i=1;x[i]!=0;i++)
		if(x[i]==y[j])h[i]=x[i];
	for(i=1;;i++)
		if(h[i]!=0){s=h[i];break;}
	printf("%d",s);
	return 0;
}
void main()
{
	int a,b;
	int ai[500],bi[500];
	scanf("%d%d",&a,&b);
	int i;
	ai[0]=a;
	bi[0]=b;
	int a_n=0,b_n=0;
	for(i=0;ai[i]!=0;i++)
	{
		ai[i+1]=ai[i]/2;
		a_n++;
	}
	for(i=0;bi[i]!=0;i++)
	{
		bi[i+1]=bi[i]/2;
		b_n++;
	}
	int eq=0;
	int j;
	for(i=0;i<a_n;i++)
	{
		for(j=0;j<b_n;j++)
		{
			if(ai[i]==bi[j])
			{
				eq=ai[i];
				break;
			}
		}
		if(eq!=0)
			break;
	}
	printf("%d\n",eq);
}
int tree (int,int);               // ??????
int power (int,int);              // ??????
int main ()
{
 int x,y;
 cin >> x >> y;
 cout << tree (x,y) << endl;
 return 0;
}
int tree (int a, int b)
{
 int i,c;
 for (i=0;i<11;i++)
 {
  c=a/power(2,i);
  if (b==c)
   return b;
 }
 for (i=0;i<11;i++)
 {
  c=b/power(2,i);
  if (a==c)
   return a;
 }
 if (a==1||b==1)
  return 1;
 return tree (a/2,b/2);
}
int power (int m,int n)
{
 int j,sum=1;
 for (j=0;j<n;j++)
  sum=sum*m;
 return sum;
}
main()
{
      int x,y,t,s=0;
      int a[11]={0},b[11]={0};
      int i,j;
      scanf("%d",&x);a[0]=x;
      scanf("%d",&y);b[0]=y;
      i=0;
      do
      {
          i+=1;
          a[i]=a[i-1]/2;
          b[i]=b[i-1]/2;
      }
      while((a[i]>1)||(b[i]>1));
      for(i=0;i<11;i++)
      {
          for(j=0;j<11;j++)
          {
              if(b[j]==a[i]) 
              {
                  t=b[j];
                  s=1;
                  break;
              }
          }
          if(s==1) break;
      }
      printf("%d",t);
}
int up(int x)                         //????????????????
{
	if(x%2==1)return (x-1)/2;
	else return x/2;
}
int main()
{
	int x,y;
	cin>>x>>y;
	while(x!=y)                  //?x???y????????
	{
		if(abs(x-y)==1)         //?????x?y??????????
		{
			y=up(y);   
			x=up(x);
		}
		else
		{
			if(y>x)y=up(y);  //????????????
			else x=up(x);
		}
	}
	cout<<x<<endl;   // ????????
	return 0;
}
int main()
{
	int m,n,i,j,k,l,p=0;
	int a[20]={0};
	int b[20]={0};
	scanf("%d%d",&m,&n);
	a[0]=m;
	b[0]=n;
	i=0;
	j=0;
	while(a[i]!=1)
	{
		a[i+1]=a[i]/2;
		i++;
	}
	while(b[j]!=1)
	{
		b[j+1]=b[j]/2;
		j++;
	}
	for(k=0;k<=i;k++)
	{
		if(p==1) break;
		else
		{
			for(l=0;l<=j;l++)
			{
				if(a[k]==b[l])
				{
					printf("%d\n",a[k]);
					p=1;
					break;		
				}
			}
		}
	}
	

return 0;
}
int func(int a);
int main()
{
	int x,y;//x,y???????
	int a[10],b[10];//a,b???????????
	int i,j,flag=1;
	scanf("%d%d",&x,&y);
	a[0]=x;
	b[0]=y;
	for(i=1;i<10;i++)
	{
		a[i]=func(x);
		x=a[i];
		if(x==1)
			break;
	}
	for(i=1;i<10;i++)
	{
		b[i]=func(y);
		y=b[i];
		if(y==1)
			break;
	}
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(a[i]==b[j])
			{
				printf("%d",a[i]);
				flag=0;
				break;
			}
		}
		if(flag==0)
			break;
	}
	return 0;
}

		
		
		
			
int func(int a)
{
	if(a%2==0)
		a=a/2;
	else
		a=(a-1)/2;
	return(a);
}
int main()
{
	void Hanshu(int a,int b);
	int a,b,k;
	scanf("%d %d",&a,&b);
	Hanshu(a,b);
	return 0;
}

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

		}
	return 0;
}
/*
 * 111.cpp
 *
 *  Created on: 2010-11-13
 *      Author: dell
 *      ??????
 */


int main(){
    int x,i,n[100],m[100],j,k;
    cin>>n[1];
    cin>>m[1];
    if(m[1]!=n[1]){
    for(i=1;i<=100;i++){
    	if(n[i]%2==0)n[i+1]=n[i]/2;
    	else if(n[i]%2!=0&&n[i]!=1)n[i+1]=(n[i]-1)/2;
    	else if(n[i]%2!=0&&n[i]==1)break;}
    for(j=1;j<=100;j++){
    	if(m[j]%2==0)m[j+1]=m[j]/2;
    	else if(m[j]%2!=0&&m[j]!=1)m[j+1]=(m[j]-1)/2;
    	else if(m[j]%2!=0&&m[j]==1){
    		k=j;
    		break;}
    	}
    for(i=1;i<=100;i++){
    	for(j=1;j<=k;j++){
    	if(m[j]==n[i])
    		break;}
    	if(m[j]==n[i])
    	    break;
    }


    x=m[j];
    cout<<x<<endl;
    }
    else cout<<m[1]<<endl;

	return 0;//????
}
/*??


??????????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??
????
??????????????x?y???????????1000?
????
?????????xi?*/
int main()
{
	int Er(int , int );
    int x,y;
    cin>>x>>y;
    cout<<Er(x,y);
    return 0;
}
int Er( int x, int y )
{
	if (x==y)return x;
	else if ( x<y )return Er( y,x );
	else if ( x/2<y )return Er(x/2,y/2);
	else return Er(x/2,y);
}
int f(int ,int);
int main()
{
    int x,y,i,j,k=0;
    cin>>x>>y;
    for(i=1;i<=500;i++)
      { for(j=1;j<=500;j++)
       {   if(f(x,i)==f(y,j)) {cout<<f(y,j)<<endl;k=1;break;}
           else continue;}
           if(k==1) break;}
           return 0;
           }
int f(int a,int b)
{
    int m;
    if(b==1) m=a;
   else if(b==2) m=a/2;
    else m=f(a,b-1)/2;
    return m;
}
int common(int,int);


int main()
{
	int x,y;
	cin>>x>>y;
	common(x,y);
	return 0;
}
void tree(int x)
{
	int a[100],i;
	for(i=0;i<100;i++)
		a[i]=1;
	a[0]=x;
	if(x>1)
		for(i=1;x>1;i++)
		{
			if(x%2!=0)
				{
					a[i]=(x-1)/2;
					x=a[i];
			}
			else
			{
				a[i]=x/2;
				x=a[i];
			}
		}
}
int common(int x,int y)
{
	int i,j,t,a[100],b[100];
	for(i=0;i<100;i++)
		{
			a[i]=1;
			b[i]=1;
	}
	a[0]=x;b[0]=y;
	if(x>1)
		for(i=1;x>1;i++)
		{
			if(x%2!=0)
				{
					a[i]=(x-1)/2;
					x=a[i];
			}
			else
			{
				a[i]=x/2;
				x=a[i];
			}
		}
	if(y>1)
		for(i=1;y>1;i++)
		{
			if(y%2!=0)
				{
					b[i]=(y-1)/2;
					y=b[i];
			}
			else
			{
				b[i]=y/2;
				y=b[i];
			}
		}
	if(x>=y)
	{
	    
	    for(i=0;i<100;i++)
			{
				for(j=0;j<100;j++)
					{
						if(b[j]==a[i])
					    {
						   cout<<b[j]<<endl;
						   return 0;
					    } 
				}
		}
	}
	else
	{
		
	    for(i=0;i<100;i++)
			{
				for(j=0;j<100;j++)
				   {
					   if(a[j]==b[i])
					   {
						   cout<<b[i]<<endl;
						   return 0;
				       }
				}
		}
	}

}
int main()
{
	int a1[20],a2[20],A1,A2,i,j,k,l;
	scanf("%d %d",&A1,&A2);
	if(A1==A2) 
	{
		printf("%d",A2);
		return 0;
	}
	for(i=0;A1!=0;i++)
	{
		a1[i]=A1;
		A1=A1/2;
	}
	for(j=0;A2!=0;j++)
	{
		a2[j]=A2;
		A2=A2/2;
	}
	for(k=0,l=0;k<i&&l<j;)
	{
		if(a1[k]==a2[l])
		{
			printf("%d",a1[k]);
			break;
		}
		else if(a1[k]>a2[l]) k++;
		else l++;
	}
	return 0;
}
int a(int x,int i)                          //?x?????i??
{
	if(i==1)
		return x;
	else return a(x,i-1)/2;
}
int main()
{
	int x,y;                                //??x?y           
	cin>>x>>y;
	int xline[100],yline[100];              //??x?y???
	int i=1;                                //??x?y???
	do{
		xline[i]=a(x,i);
		i++;
	}while(a(x,i));
	int j=1;
	do{
		yline[j]=a(y,j);
		j++;
	}while(a(y,j));
	for(j--,i--;yline[j]==xline[i]&&j>=1&&i>=1;j--,i--);//??????????????
	cout<<xline[++i];
	return 0;
}
//============================================================================
// Name        : 7.6.cpp
// Author      : Zhang Yu
// Version     :
// Copyright   : Your copyright notice
// Description : ???
//============================================================================

int findknot(float,float);
int findknot(float x,float y)
{
	if (x==y)//??x,y???????
		return (int)x;//x????
	if (ceil(log((double)x)/log(2))==ceil(log((double)y)/log(2)))//??x,y????
		return findknot(floor(x/2),floor(y/2));//?????
	else//??x,y?????
	{
		float tempmax=max(x,y);
		float tempmin=min(x,y);
		x=tempmax;
		y=tempmin;
		//??????x???????
		return findknot(floor(x/2),y);//x??????y??
	}
}
int main() {
	int inputx,inputy;
	cin >>inputx>>inputy;
	cout <<findknot((float)inputx,(float)inputy);
	return 0;
}
void main()
{
	int a[500]={0},b[500]={0},m,n,x=0,y=0,i;
	scanf("%d %d",&m,&n);
	if (m==n)
	{	printf("%d\n",m);}
	else
	{
		a[0]=m;
		b[0]=n;
	    for (i=1;m!=1;i++)
		{
		    if (m%2==0)
			{	m=m/2;}
		    else
			{   m=(m-1)/2;}
		    a[i]=m;
		}
        for (i=1;n!=1;i++)
		{
		    if (n%2==0)
			{	n=n/2;}
		    else
			{   n=(n-1)/2;}
		    b[i]=n;
		}
	    for (i=0;a[i]!=0;i++)
		{	x=x+1;}
        for (i=0;b[i]!=0;i++)
		{	y=y+1;}
	    if (a[0]==1 || b[0]==1)
		{	printf("1\n");}
	    else
		{
	        for (i=1;x-1-i>=0 && y-1-i>=0;i++)
			{ 	if (a[x-1-i]!=b[y-1-i])
			     {break;}
			}
	        printf("%d\n",a[x-i]);
		}
	}
}
int last(int k)
{
	if (k%2==0)
	{
		return (k/2);
	}
	else
	{
		return ((k-1)/2);
	}
}

int main()
{
	int x,y;
	cin>>x>>y;
	while (x!=y)
	{
		if (x>y)
		{
			x = last(x);
		}
		else
		{
			y = last(y);

		}
	}
	cout<<x;
}