semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void main()
{
   int a,b,l,i,t,j;
   long s=0;
   char str1[100],str2[100];
   scanf("%d%s%d",&a,str1,&b);
   l=strlen(str1);
   for(i=0;i<l;i++)
   {if(str1[i]>96) str1[i]=str1[i]-32;}
   for(i=0;i<l;i++)
   {if(str1[i]>64) s=s*a+(str1[i]-55);
   	else s=s*a+(str1[i]-48);
   }
   if(s==0) printf("0");
   else{
	for(i=0;s>0;i++)
	{t=s%b;
	s=s/b;
	if(t>9) str2[i]=t+55;
	else str2[i]=t+48;
	}
	for(j=1;j<=i;j++)
	{printf("%c",str2[i-j]);}
   }
}
int f(char c)
{
	int w;
	if(c>='0' && c<='9')
	{
		w=c-'0';
		return w;
	}
	if(c>='a' && c<='z')
	{
		w=c-'a'+10;
		return w;
	}
	if(c>='A' && c<='Z')
	{
		w=c-'A'+10;
		return w;
	}
}

char g(int a)
{
	char c;
	if(a>=0 && a<9)
	{
		c=a+'0';
		return c;
	}
	if(a>=10)
	{
		c=a-10+'A';
		return c;
	}

}

int main()
{
	int a,b,i,j,l,x;
	long sum=0,y;
	char n[10];
	scanf("%d %s %d",&a,n,&b);
	if(a==b)
		printf("%s\n",n);
	else
	{
	l=strlen(n);
	for(i=0;i<l;i++)
	{
		x=f(n[i]);
		y=(long)pow(a,l-i-1);
		sum=sum+x*y;
	}
	if(sum==0)
		printf("0");
	else
	{
	char m[50];
	long z;
	l=(int)(log(sum)/log(b));
	for(i=0;i<=l;i++)
	{
		if(i==l)
		{
			z=sum;
			m[i]=g(z);
		}
		else
		{
			for(j=1;j<=b;j++)
			{
				z=j*pow(b,l-i);
				if(z>sum)
				{
					z=(j-1)*pow(b,l-i);
					sum=sum-z;
					m[i]=g(j-1);
					break;
				}
			}
		}
	}

	for(i=0;i<=l;i++)
		printf("%c",m[i]);
	printf("\n");
	}
	}

	return 0;



}
main()
{
     int a,b,num1[100],num2[100],l1=0,l2=0,i,j=0;
     long n=0;
     char ch1[100],ch2[100],c;
     for(i=0;i<100;i++)
     {
         num1[i]=0;
         num2[i]=0;
         ch1[i]='0';
         ch2[i]='0';
     }
     scanf("%d ",&a);
     for(i=0;(c=getchar())!=' ';i++)
     {
         l1++;
         ch1[i]=c;
         if('0'<=c&&c<='9')num1[i]=c-'0';
         else if('a'<=c&&c<='z')num1[i]=c-'a'+10;
         else if('A'<=c&&c<='Z')num1[i]=c-'A'+10;
     }
     scanf("%d",&b);
     for(i=0;i<l1;i++)
         n=n+num1[i]*(int)pow(a,l1-1-i);
     for(i=1;j==0;i++)
     {
         if(n/(int)pow(b,i)==0)
         {
            j=1;
            break;
         }
     }
     l2=i;
     for(i=0;i<l2;i++)
     {
         num2[99-i]=n%b;
         n=(n-num2[99-i])/b;
         if(0<=num2[99-i]&&num2[99-i]<=9)ch2[99-i]=num2[99-i]+'0';
         else if(10<=num2[99-i])ch2[99-i]=num2[99-i]-10+'A';
     }
     for(i=0;i<l2;i++)
         printf("%c",ch2[100-l2+i]);
}
long int num(long int x,int i,int b)
{
	long int a;
	a=x;
	int j;
	for (j=0;j<i;j++)
		a=a*b;
	return a;
}
void main ()
{
	int a,b,i,j,length;
	char shu[100],zhuanhuan[100];
	scanf("%d %s %d",&a,shu,&b);
	long int k=0;
	length=strlen(shu);
	long int l;
	for (i=0;i<length-1;i++)
	{
		if( ((shu[i]>='A')&&(shu[i]<='Z')))
		{
			l=shu[i]-'A'+10;
			k=k+num(l,length-i-1,a);
		}
		if(((shu[i]>='0')&&(shu[i]<='9')))
		{
			l=shu[i]-'0';
			k=k+num(l,length-i-1,a);
		}
		if( ((shu[i]>='a')&&(shu[i]<='z')))
		{
			l=shu[i]-'a'+10;
			k=k+num(l,length-i-1,a);
		}
	}
	if ((shu[length-1]>='A')&&(shu[length-1]<='Z'))
		k=k+shu[length-1]-'A'+10;
	if(((shu[length-1]>='0')&&(shu[length-1]<='9')))
		k=k+shu[length-1]-'0';
	if ((shu[length-1]>='a')&&(shu[length-1]<='z'))
			k=k+shu[length-1]-'a'+10;
	int m=0;
	int n;
	long int f=k;
	do 
	{
		n=f%b;
		if ((n>=0)&&(n<=9))
		{
			zhuanhuan[m]=n+'0';
			m++;
		}
		else
		{
			zhuanhuan[m]=n-10+'A';
			m++;
		}
		f=f/b;
	}while(f!=0);
	for (i=m-1;i>=0;i--)
		printf("%c",zhuanhuan[i]);
	printf("\n");
}
const int size=10000; //??????
char inda[size],outda[size];
int indata[size],t,ans[2*size],lans,ddd[size];//?????????
int main()        //?????
{
    int i,j,inbase,outbase,la,ld;
    int map[300];char rmap[65];
    for(i='A';i<='Z';i++) {map[i]=i-'A'+10;rmap[i-'A'+10]=i;}//??????????????????

    for(i='a';i<='z';i++) {map[i]=i-'a'+10;rmap[i-'a'+37]=i;}
    for(i='0';i<='9';i++) {map[i]=i-'0';rmap[i-'0']=i;}
   
    
        cin>>inbase>>inda>>outbase; //??
      
        la=strlen(inda);lans=0;ld=0;
        for(i=0;i<la;i++)
            indata[i]=map[inda[i]];
        while(true)
        {
            if(la==1&&indata[0]<outbase){ans[lans++]=indata[0];break;}
			if(inda[0]=='0'){ cout<<"0";break;}
            for(i=0;i<la-1;i++)//??????

            {
                ddd[ld++]=indata[i]/outbase;
                t=indata[i]%outbase;
                indata[i+1]+=t*inbase;
            }
            ddd[ld++]=indata[i]/outbase;//????

            ans[lans++]=indata[i]%outbase;//??????????

            for(i=0;i<ld;i++)//??????0

                if(ddd[i]) break;
            for(j=0;i<ld;i++,j++)//?????????

                indata[j]=ddd[i];
            la=j;ld=0;//?????

        }
        for(i=0;i<lans;i++)//???????????????????

            outda[i]=rmap[ans[i]];
       
         for(i=lans-1;i>=0;i--)cout<<outda[i];
     
      return 0;
 }
void main()
{
	int a,b,i,j;
	long k;
	char n[50],m[50],s[50];
	scanf("%d %s %d",&a,n,&b);
	k=0;
	for(i=0;i<strlen(n);i=i+1)
	{
		if(n[i]>=48&&n[i]<=57)
			k=k*a+n[i]-48;
		if(n[i]>='A'&&n[i]<='Z')
			k=k*a+n[i]-55;
		if(n[i]>='a'&&n[i]<='z')
			k=k*a+n[i]-87;
	}
	if(k==0)
		printf("0");
	for(i=0;k>0;i=i+1)
	{
		if(k%b<10)
			m[i]=k%b+48;
		else m[i]=k%b+55;
		k=k/b;
	}
	i=i-1;
	for(j=0;i>=0;j=j+1)
	{
		s[j]=m[i];
		i=i-1;
	}
	for(i=0;i<j;i=i+1)
	{
		printf("%c",s[i]);
	}

}
int calc (char c)
{
if (c>='0'&&c<='9') return c-'0';
else if (c>='a'&&c<='z') return c-'a'+10;
else if (c>='A'&&c<='Z') return c-'A'+10;
}
char conv(int a)
{
if (a<10) return a+'0';
else return a-10+'A';
}
main()
{
long a,b,n,i,j,k,ans;      
char c[100];
scanf("%d",&a);
scanf("%s",c);
scanf("%d",&b);
n=strlen(c);
n--;
ans=calc(c[n]);
j=1;
for (i=n-1;i>=0;i--)
{
j*=a;
ans+=calc(c[i])*j;
}
i=0;
while (ans>0)
{
i++;
c[i]=conv(ans%b);
ans/=b;
}
if (i==0) printf("0");
while (i>=1)
{
printf("%c",c[i]);
i--;
}
}
void main()
{
	int a,b;
	int d;
	int length;
	char c[20];
	int n[20];
	char result[200];
	int i,k,j;
	int temp1=0;

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

	for(i=0;c[i]!=0;i++)
	{
		if(c[i]>='a'&&c[i]<='z')
			n[i]=c[i]-'a'+10;
		if(c[i]>='A'&&c[i]<='Z')
			n[i]=c[i]-'A'+10;
		if(c[i]>='0'&&c[i]<='9')
			n[i]=c[i]-'0';
	}
	
	length=i;
	d=0;
	for(k=0;k<length;k++)
	{
		d=d*a+n[k];
	}

	for(i=0;d!=0;i++){
		temp1=d%b;
		d=d/b;
		if(temp1>=10)
			temp1=temp1-10+'A';
		else
			temp1=temp1+'0';
		result[i]=temp1;
	}
	result[i]=0;
	for(j=i-1;j>=0;j--){
		printf("%c",result[j]);
	}
	if(i==0)
		printf("0");
}
int main()
{
	long int num10=0;//??????10?????b?????????
	int a,b,i,j;//a,b??,i,j???????????
	char character1[100],character2[100];//???????????
	cin>>a;
	cin.get();
	for(i=0;;i++)
	{
		character1[i]=cin.get();
		if(character1[i]>='a'&&character1[i]<='z')
			character1[i]=character1[i]-87;
		else if(character1[i]>='A'&&character1[i]<='Z')
			character1[i]=character1[i]-55;
		else if(character1[i]>='0'&&character1[i]<='9')
			character1[i]=character1[i]-48;
		else break;
		num10=num10*a+character1[i];
	}
	cin>>b;
	for(j=0;;j++)
	{
		if(num10%b<=9)
			character2[j]=num10%b+48;
		if(num10%b>9)
			character2[j]=num10%b+55;
		num10=num10/b;
		if(num10==0)
			break;
	}
	for(;j>=0;j--)
		cout<<character2[j];
	cout<<endl;
	cin.get();cin.get();cin.get();
    return 0;
}
void main()
{
	long int n,s;
	int a,b,len,i,j;
	char num[50],res[50]=" ";
	scanf("%d %s %d",&a,num,&b);
	len=strlen(num);
	s=0;
	for(i=len-1;i>=0;i--)
	{
		n=1;
		for(j=1;j<=len-1-i;j++)
			n=n*a;
		if(num[i]>='0'&&num[i]<='9')
			s=s+n*(num[i]-'0');
		else if(num[i]>='a'&&num[i]<='z')
			s=s+n*(num[i]-'a'+10);
		else if(num[i]>='A'&&num[i]<='Z')
			s=s+n*(num[i]-'A'+10);
	}
	n=s;j=0;
	while(n!=0)
	{
		i=n%b;
		n=n/b;
		if(i<10) res[j]='0'+i;
		else res[j]='A'+i-10;
		j++;
	}
	n=strlen(res);
	if(res[n-1]==' ') printf("0");
	else
	{
		for(i=n-1;i>=0;i--)
			printf("%c",res[i]);
	}
}
int main()
{
 int a,b;
 char n[40];
 scanf("%d %s %d",&a,n,&b);
         int l=strlen(n);
         int m[40];
         int x=0;
           
             for(int i=0;i<l;i++)
                             {
                             if(n[i]>='A'&&n[i]<='Z')
                             n[i]=n[i]-'A'+'a';
                             if(n[i]<='z'&&n[i]>='a')
                             m[i]=n[i]-'a'+10;
                             else m[i]=n[i]-'0';
                             int d=m[i];
                             x=x*a+d;
                             }
           if (x==0)
           printf("0");
           else
           { 
         int e[40],k;
         for (k=0;x!=0;k++)
             {e[k]=x%b;
             x=x/b;
                   
             }                
             e[k]='\0';
         char f[40];
         int j;
                   for(j=0;j<k;j++)
         {
                  if(e[j]>=0&&e[j]<10)
                  f[k-j-1]=e[j]+'0';
                  else
                  f[k-j-1]=e[j]-10+'A';
         }
         f[k]='\0';
 printf("%s",f);
}
 getchar();
 getchar();

}
void main()
{
long int f=0,e=0,b,c,i,g,k=0,j=0,v=1;
char d[100],a[100];
int h[100];
scanf("%d",&b);//d???
for(i=0;;i++)
{a[i]=getchar();
if (a[i]==' ') break;
}//??????
for(i=0;;i++)
{d[i]=getchar();
if (d[i]==' ') break;j++;
}
scanf("%d",&c);//?????
//for(i=0;i<4;i++)
//printf("%c\n",d[i]);
//printf("%d %d",b,c);
g=b;//????
	{
	for(i=0;;i++)
	{if (d[i]==' ') break;
	if (d[i]< 59 ) h[i]=d[i]-48;
	else if (d[i]<='Z') h[i]=d[i]-55;
	else h[i] = d[i]-87;
//printf("%d\n",h[i]);
	};
	for(i=j-1;i>=0;i--)
	{f=f+h[i]*b/g;b=b*g;}

//	printf("%d\n",f);//??
	}//??10
	{
		for(i=0;;i++)
		{
		h[i]=f%c;f=f/c;k++;
		if (f==0) break;
		};//??
for(i=0;i<k;i++)
{	if (h[i]<=9) 
		d[i]=h[i]+48;
	else d[i]=h[i]+55;
}
	for(i=k-1;i>=0;i--)
		if (j>=10) {printf("2147483647");break;}
else	printf("%c",d[i]);
	printf("\n");//????
	}
}
int main()
{
	 int a,n,b,s,i,j,k,l,sz[100],zh[100];
	 char zf[100],tj[100];
	 scanf("%d %s %d",&a,zf,&b);
	 l=strlen(zf);
	 for(i=0;i<l;i++){
	 	if(zf[i]>='0'&&zf[i]<='9'){
			sz[i]=zf[i]-'0';
		}
		else if(zf[i]>='a'&&zf[i]<='z'){
			sz[i]=zf[i]-'a'+10;
		} 
		else if(zf[i]>='A'&&zf[i]<='z'){
			sz[i]=zf[i]-'A'+10;
		}		
	 }
	 s=0;
	 for(i=0;i<l;i++){
		s=s*a+sz[i];	
	 }
	 j=0;
	 if(s==0){
	 	zh[j]=0;
	 	j++;
	 }
	 else{
		 while(s>0){
			zh[j]=s%b;
			s=s/b;	
			j++;
		 }
	 }
 	 for(k=0;k<j;k++){
		if(zh[k]>9){
			tj[k]='A'+zh[k]-10;
		}	
		else{
			tj[k]=zh[k]+'0';
		}
	 }
	 for(k=j-1;k>=0;k--){
		printf("%c",tj[k]);	
	 }
	 return 0;
}
int main()
{
	char a[90000],b[90000];
	long int n,i,j,m,x,y,s;
	cin>>x;
	cin>>a;
	cin>>y;
	n=0;m=0;
	j=strlen(a);
	for(i=0;i<j;i++)
	{
		if(a[i]>='0' && a[i]<='9') m=a[i]-'0';
		if(a[i]>='A' && a[i]<='Z') m=a[i]-'A'+10;
		if(a[i]>='a' && a[i]<='z') m=a[i]-'a'+10;
		n=n*x+m;
	}
	j=0;
	s=0;
	if (n==0) cout<<0;
	while(n>0)
	{
		j=n%y;
		if(j>=10) b[s]=j-10+'A';
		else b[s]=j+'0';
		s++;
		n=n/y;
	}
    for(i=s-1;i>=0;i--)
    cout<<b[i];
	return 0;
}
int f(char x)
{
    int xx;
    xx=x-48;
    if(xx>9)xx=x-'A'+10;
    if(xx>36)xx=x-'a'+10;
    return xx;
}
char g(int y)
{
     char yy;
     if(y<10)yy=y+'0';
     if(y>=10)yy=y-10+'A';
     return yy;
}    
int main()
{
    long nn=0;
    int a,b,i;
    char n[500];
    scanf("%d %s %d",&a,n,&b);
    int length=strlen(n);
    int k=1;
    for(i=length-1;i>=0;i--)
    {
            nn+=f(n[i])*k;
            k*=a;
    }
    int m[500];
    int j=0;
    do
    {
            m[j]=nn%b;
            nn=nn/b;
            j++;
    }
    while(nn>=1);
    for(i=j-1;i>=0;i--)printf("%c",g(m[i]));
    
}
int main()
{
	
    int shu=0,j,i,a,b,mm;
	char m[100],n[100];   
    cin>>a;
    cin.get();
    cin>>m;
	cin>>b;

	 for(i=0;m[i]!='\0';i++)
	 {if(m[i]>=65&&m[i]<=90) m[i]=m[i]+32;}     

	for(i=0;m[i]!='\0'; i++)
     {
          if(m[i]>=48&&m[i]<=57)  mm=m[i]-48;
        else mm=m[i]-97+10;
          shu=shu*a+mm;                           
     }
        
	 if(shu==0) cout<<shu<<endl;
	  
	 for(i=0;shu!=0;i++)
	  { 
		  n[i]=shu%b;
		  if(n[i]>=9) n[i]=n[i]+55;
		  else n[i]=n[i]+48;
		  shu=shu/b;
	  }

	for(j=i-1;j>=0;j--) cout<<n[j];   

	return 0;
     }
int qr(int x,int y)
{
if(y<=0)
return(1);
else return x*qr(x,(y-1));
}
int main()
{
int a,b,n,i,j,d[100];
long int k=0;
char p[100],q[100];
scanf("%d %s %d",&a,p,&b);
n=strlen(p);
for(i=0;i<n;i++)
{
	if(p[i]<='z'&&p[i]>='a')
		p[i]-=32;
}
for(i=0;i<n;i++)
{
	if(p[i]>='A'&&p[i]<='Z')
	k+=(qr(a,(n-1-i))*(p[i]-'A'+10));
	else
	k+=(qr(a,(n-1-i))*(p[i]-'0'));
	}
for(i=0;;i++)
	{
	if(k>=b)
		{
		d[i]=(k-(k/b)*b);
		k=k/b;
		}
	else
		{
		d[i]=k;
		break;
		}
	}
for(j=0;j<=i;j++)
	{
	if(d[j]<=9)
	q[j]=d[j]+'0';
	else 
	q[j]=d[j]-10+'A';
	}
for(j=i;j>=0;j--)
printf("%c",q[j]);
return(0);
}
int zhsh (int, int, int, char[], int, int, int);//???????
int main ()
{
	char s[100], u[100];
	int a, b, l, k = 0, i = 0, j = 0, r, l1;
	cin >> a >> s >> b;
	l = strlen(s);
	int sum = 1;
    zhsh (i, j, l, s, k, sum, a);//?????????????????
	if(zhsh (i, j, l, s, k, sum, a) == 0)//??0??????????
		cout << "0" << endl;
	else
	{
		k = zhsh (i, j, l, s, k, sum, a);
        for (j = 0; k != 0; j++)//????0?
		{
			r = k % b;
	        if (r >= 10)//??????????
				u[j] = r - 10 + 'A';
			else
			    u[j] = r + '0';
		    k=k/b;
		}
	    u[j] = '\0';//????????????
	    l1 = strlen(u);
	    for ( j= l1 - 1; j >= 0; j--)
			cout << u[j];
	    cout << endl;
	}
	return 0;
}
int zhsh(int i,int j,int l,char s[],int k,int sum,int a)//???????
{
	for(i = 0, j = l - 1; j >= 0; i++ , j--)
	{
		if(s[j] >= 65)
		{
			if(s[j] >= 97)
				k = k + (s[j] - 87) * sum;
			else
				k = k + (s[j] - 55) * sum;
		}
		else
            k = k + (s[j] - 48) * sum;
		    sum = sum * a;
	}
	return k;
}
int main(int argc, char* argv[])
{
	int a,b,i,j,l,k;
	int sum=0,out=0;
	char s[51];
	
	scanf("%d %s %d",&a,s,&b);
	l=strlen(s);
	//printf("%d\n",l);
	for(i=0;s[i]!='\0';i++)
	{
		if(s[i]>=97&&s[i]<=122)
			s[i]=s[i]-32;
	}
//	printf("%s\n",s);
	for(i=0;s[i]!='\0';i++)
	{
		if(s[i]>=65&&s[i]<=90)
		{
			k=s[i]-55;//printf("%d\n",k);
		}
		else
		{
			k=s[i]-48;//printf("=%d\n",k);
		}
		for(j=0;j<l-i-1;j++)
		{
			k=k*a;//printf("%d\n",k);
		}
	//	printf("+%d\n",k);
		sum=sum+k;
	}
	for(i=50;i>=0;i--)
	{
		if(sum%b>=0&&sum%b<=9)
		{
			s[i]=sum%b+48;
		}
		if(sum%b>=10)
		{
			s[i]=sum%b+55;
		}
		sum=(sum-sum%b)/b;
		if(sum==0)
			break;
	}
	for(j=i;j<51;j++)
	{
		printf("%c",s[j]);
	}
	printf("\n");
	return 0;
}
void main()
{
	int f(int m,int n);
	int a,b,e,sum=0;
	int i,j,k;
	char c[100],d[100];
	scanf("%d %s %d",&a,c,&b);
	for(i=0;c[i]!=0;i++);
	for(j=0;j<=i-1;j++)
	{
		if((c[j]>=48)&&(c[j]<=57))sum=sum+(c[j]-48)*f(a,i-j-1);			
		else if((c[j]>=65)&&(c[j]<=90))sum=sum+(c[j]-55)*f(a,i-j-1);
		else if((c[j]>=97)&&(c[j]<=122))sum=sum+(c[j]-87)*f(a,i-j-1);
	}
	e=sum;
	for(i=0;e>=b;i++)
	{
		d[i]=e%b;
		e=e/b;
		if((d[i]>=0)&&(d[i]<=9))d[i]=d[i]+48;
		else if((d[i]>=10)&&(d[i]<=35))d[i]=d[i]+55;
	}
	if((e>=0)&&(e<=9))d[i]=e+48;
	else if((e>=10)&&(e<=35))d[i]=e+55;
	for(k=i;k>=0;k--)printf("%c",d[k]);
}
int f(int m,int n)
{
	int i,z=1;
	for(i=1;i<=n;i++)
		z=z*m;
	return(z);
}
main()
{
	long a,b,i,m[100],j=0,p=0,k=0,q[100];
	char n[100],w[100];
	scanf("%d%s%d",&a,n,&b);
	for(i=0;i<=99;i++)
	{
		
	   if('A'<=n[i]&&'Z'>=n[i])m[i]=n[i]-55;
	   else if('a'<=n[i]&&'z'>=n[i])m[i]=n[i]-87;
	   else if('0'<=n[i]&&'9'>=n[i])m[i]=n[i]-48;
	}
	for(i=0;i<=99;i++)
	{if(n[i]!='\0')j++;else break;}
	for(i=0;i<=j-1;i++)
	p=p+m[i]*pow(a,j-i-1);
	for(i=0;i<=99;i++)
	{
		q[i]=p%b;
		if(q[i]>=10)w[i]=q[i]+55;
		else w[i]=q[i]+48;
		p=p/b;
		k++;
		if(p==0)break;
	}
	for(i=1;i<=k;i++)
	printf("%c",w[k-i]);
}
int main()
{
	char s[20],r[40];
	int i,j,a,b,l;
	long n=0;
	scanf("%d%s%d",&a,s,&b);
	l=strlen(s);
	for(i=0;i<l;i++)
	{
		if(s[i]>='a'&&s[i]<='z')
			n=a*n+s[i]-'a'+10;
		else if(s[i]>='A'&&s[i]<='Z')
			n=a*n+s[i]-'A'+10;
		else n=a*n+s[i]-'0';
	}
	//printf("%ld\n",n);
	i=0;
	if(n==0) 
	{
		printf("0\n");
		return 0;
	}
	while(n>0)
	{
		if(n%b<=9)
			r[i++]=n%b+'0';
		else
			r[i++]=n%b-10+'A';
		n=n/b;
	}
	for(j=i-1;j>=0;j--)
	{
		printf("%c",r[j]);
	}
	printf("\n");
	return 0;
}
int main()
{
	char str[35],end='A';            //str????????end?????????
	int i=0,a=0,b=0,weishu=0;        //i??????a,b?????????
	long sum=0;                      //sum??????????????
	cin>>a;
	for(i=0;i<35;i++)                //????
	{
		str[i]=getchar();
		if(i>0&&str[i]==' ')
			break;
	}
	weishu=i-1;
	for(i=1;i<=weishu;i++)
	{
		str[i]-=48;
		if(str[i]>16)
		{
			str[i]-=7;
			if(str[i]>40)
				str[i]-=32;
		}
		sum=sum*a+str[i];           //??????
	}
	cin>>b;                         //???????
	int final[35];                  //final[35]???b????
	i=0;
	do                              //??b???
	{
		i++;
		final[i]=sum%b;
		sum=sum/b;
	}
	while(sum);
	for(i;i>0;i--)                  //???
	{
		if(final[i]>9)
		{
			final[i]-=10;
			end='A';
			end+=final[i];
			cout<<end;
		}
		else
			cout<<final[i];
	}
	return 0;
}
main()
{
	char a[100],b[100],c[100];
	int m,n,i,k,t,q;
	long j;
	for(i=0;i<100;i++)
		b[i]=0;
	scanf("%d %s %d",&m,a,&n);
	i=0;
	j=0;
         t=0;
         q=0;
         while(a[q]!=0)
         {
          t=t+(a[q]!='0');
          q++;
         }
    if(t!=0)
    {
	while(a[i]!=0)
	{
		if(a[i]<='9')
			k=a[i]-'0';
		else
		{
			if(a[i]<='Z')
				k=10+a[i]-'A';
			else
				k=10+a[i]-'a';
		}
		j=j*m+k;
		i++;
	}
	i=0;
	while(j!=0)
	{
		b[i]=j%n;
		j=j/n;
		i++;
	}
	for(j=0;j<=i-1;j++)
	{
		if(b[i-j-1]<=9)
			c[j]=b[i-j-1]+'0';
		else
			c[j]=b[i-j-1]-10+'A';
	}
	for(j=0;j<100;j++)
	{
		if(!((c[j]>='0'&&c[j]<='9')||(c[j]>='A'&&c[j]<='Z')))
			c[j]=0;
	}
	printf("%s\n",c);
    }
    else
    printf("0\n");
}
//*???2010?10?26?*
//*??????*
//******************************************
int main()//???
{//?????
	int a=0,b=0,shijinzhi=0,weishu=0,i=0,j=0,shuchu[1000];//???????a?????????b?????????shijinzhi?????????????????weishu????????shuchu?????
	char shuru[1000]="abcdefg";//????????????
	cin>>a;
	cin>>shuru;
	cin>>b;//???????????????????????
	weishu=strlen(shuru);//????????
	for(i=0;i<=weishu-1;i++)
	{
		if(('A'<=shuru[i])&&(shuru[i]<='Z'))
			shuru[i]=shuru[i]-'A'+10;
		else if(('a'<=shuru[i])&&(shuru[i]<='z'))
			shuru[i]=shuru[i]-'a'+10;
		else if(('0'<=shuru[i])&&(shuru[i]<='9'))
			shuru[i]=shuru[i]-'0';
	}//?????
	for(i=0;i<=weishu-1;i++)
	{
		 shijinzhi=shijinzhi+(int)(shuru[i]*pow(1.0*a,1.0*(weishu-i-1)));
	}//????????
	if(shijinzhi==0)
		printf("%d",shijinzhi);//???????????0??????
	if(shijinzhi!=0)
	{
		 for(i=0;shijinzhi!=0;i++)
		 {
			shuchu[i]=shijinzhi%b;
			shijinzhi=shijinzhi/b;
		 }
		 for(j=i-1;j>=0;j--)
		 {
			  if((0<=shuchu[j])&&(shuchu[j]<=9))
				 printf("%d",shuchu[j]);
			  else if(shuchu[j]>=10)
			  {
				 shuchu[j]=shuchu[j]+'A'-10;
				 printf("%c",shuchu[j]);
		      }
		 }
	}//???0???????????????????
	printf("\n");//??
	return 0;
}//?????
int main()
{
	int a,b,t,i,p=0,e,j,f=1;
	char c[100],d[100];
	scanf("%d %s %d",&a,c,&b);
	t=strlen(c);
	for (i=t-1;i>=0;i--)
	{
		if(c[i]>=65&&c[i]<=91)
			p+=f*(c[i]-55);
		else if (c[i]>=97&&c[i]<=123)
			p+=f*(c[i]-87);
		else if (c[i]>=48&&c[i]<=57)
			p+=f*(c[i]-48);
		f=f*a;
	
		}
	for (j=0;;j++)
	{
		e=p%b;
		p=p/b;
		if(e>=0&&e<=9)
			d[j]=e+'0';
		else if(e>=10&&e<=35)
		d[j]=e-10+'A';
		if(p==0)
			break;}
	for(i=j;i>=0;i--)
	{
		printf("%c",d[i]);
	}
	printf("\n");



	return 0;

}
int f(int x,int y)
{
	int z=1,i;
	if(y==0)
		z=1;
	else
	for(i=0;i<y;i++)
		z*=x;
	return(z);
}
void main()
{
   int i,m,n,k,s=0,d=0;
   char a[100]={0},b[100]={0};
   scanf("%d",&m);
   scanf("%s",a);
   scanf("%d",&n);
   k=strlen(a);
   for(i=0;i<k;i++)
   {
	   if(a[i]>='a'&&a[i]<='z')
			a[i]=a[i]-'a'+10;
	   else if(a[i]>='A'&&a[i]<='Z')
		    a[i]=a[i]-'A'+10;
	   else
		    a[i]=a[i]-'0';
	   s=k-1-i;
	   d+=a[i]*f(m,s);
   }
   i=0;
   while(i>=0)
   {
		b[i]=d%n;
		if(b[i]>9)
			b[i]=b[i]-10+'A';
		else
			b[i]=b[i]+'0';
		d=d/n;
		if(d==0)
			break;
		i++;
   }
	k=i;
	for(i=k;i>=0;i--)
		printf("%c",b[i]);
}
int main()           //5
{
 double m=0,n=0,sum=0;
 char a[100]="0";
 int b[100];
 char c[100]="0";       //10
 cin>>m;
 cin>>a[0];
 for(int i=1;i<100;i++)
 {
  if((a[i]=getchar())==' ')break;        //15
 }
 cin>>n;
 int longa=strlen(a);
 for(int j=0;j<(longa-1);j++)
 {                                            //20
  b[j]=a[j];
  if(b[j]>47&&b[j]<58)sum=sum+(b[j]-48)*pow(m,(longa-j-2));
  if(b[j]>64&&b[j]<91)sum=sum+(b[j]-55)*pow(m,(longa-j-2));
  if(b[j]>96&&b[j]<123)sum=sum+(b[j]-87)*pow(m,(longa-j-2));
 }                         //25
 int z=0,x=0,sum2=sum,n2=n;
 do
 {
  z=sum2%n2;
  sum2=sum2/n2;                //30
  if(z>=0&&z<10)c[x]=z+48;
  if(z>=10&&z<37)c[x]=z+55;
  x++;
 }
 while(sum2!=0);                    //35
 int longc=strlen(c);
 for(int y=1;y<=longc;y++)
 {
  cout<<c[longc-y];
 }                                        //40
 return 0;
}
// ??7.13.cpp : ??????????????
//

char antichange(int x)
{
  if(x==0){return '0';}
  if(x==1){return '1';}
  if(x==2){return '2';}
  if(x==3){return '3';}
  if(x==4){return '4';}
  if(x==5){return '5';}
  if(x==6){return '6';}
  if(x==7){return '7';}
  if(x==8){return '8';}
  if(x==9){return '9';}
  if(x==10){return 'A';}
  if(x==11){return 'B';}
  if(x==12){return 'C';}
  if(x==13){return 'D';}
  if(x==14){return 'E';}
  if(x==15){return 'F';}
  if(x==16){return 'G';}
  if(x==17){return 'H';}
  if(x==18){return 'I';}
  if(x==19){return 'J';}
  if(x==20){return 'K';}
  if(x==21){return 'L';}
  if(x==22){return 'M';}
  if(x==23){return 'N';}
  if(x==24){return 'O';}
  if(x==25){return 'P';}
  if(x==26){return 'Q';}
  if(x==27){return 'R';}
  if(x==28){return 'S';}
  if(x==29){return 'T';}
  if(x==30){return 'U';}
  if(x==31){return 'V';}
  if(x==32){return 'W';}
  if(x==33){return 'X';}
  if(x==34){return 'Y';}
  if(x==35){return 'Z';}
}
char change(char x)
{
  if(x=='0'){return 0;}
  if(x=='1'){return 1;}
  if(x=='2'){return 2;}
  if(x=='3'){return 3;}
  if(x=='4'){return 4;}
  if(x=='5'){return 5;}
  if(x=='6'){return 6;}
  if(x=='7'){return 7;}
  if(x=='8'){return 8;}
  if(x=='9'){return 9;}
  if(x=='a'||x=='A'){return 10;}
  if(x=='b'||x=='B'){return 11;}
  if(x=='c'||x=='C'){return 12;}
  if(x=='d'||x=='D'){return 13;}
  if(x=='e'||x=='E'){return 14;}
  if(x=='f'||x=='F'){return 15;}
  if(x=='g'||x=='G'){return 16;}
  if(x=='h'||x=='H'){return 17;}
  if(x=='i'||x=='I'){return 18;}
  if(x=='j'||x=='J'){return 19;}
  if(x=='k'||x=='K'){return 20;}
  if(x=='l'||x=='L'){return 21;}
  if(x=='m'||x=='M'){return 22;}
  if(x=='n'||x=='N'){return 23;}
  if(x=='o'||x=='O'){return 24;}
  if(x=='p'||x=='P'){return 25;}
  if(x=='q'||x=='Q'){return 26;}
  if(x=='r'||x=='R'){return 27;}
  if(x=='s'||x=='S'){return 28;}
  if(x=='t'||x=='T'){return 29;}
  if(x=='u'||x=='U'){return 30;}
  if(x=='v'||x=='V'){return 31;}
  if(x=='w'||x=='W'){return 32;}
  if(x=='x'||x=='X'){return 33;}
  if(x=='y'||x=='Y'){return 34;}
  if(x=='z'||x=='Z'){return 35;}
}
int main()
{
	int l1=0,l2=0,l3=0,i=0,part=0,sum=0,j=0,mi=1,r[LEN],s=0;
	char a[LEN],b[LEN],c[LEN],result[LEN];
	scanf("%s%s%s",a,b,c);
	l1=atoi(a),l2=strlen(b),l3=atoi(c);
         for(i=0;i<l2;i++)
	{
	  s+=change(b[i]);
	}
if(s==0)
{
  printf("0");
}
else
{
	//printf("a=%d c=%d\n",l1,l3);
	sum=change(b[l2-1]);
	//printf("sum=%d\n",sum);
	mi=l1;
	for(i=l2-2;i>=0;i--)
	{
	  part=change(b[i]);
	  //printf("mi=%d\n",mi);
	  part=part*mi;
	  //printf("part=%d\n",part);
	  sum=sum+part;
	  //printf("sum=%d\n",sum);
	  mi=mi*l1;
	}
	while(sum!=0)
	{
	  r[j]=sum%l3;
	  result[j]=antichange(r[j]);
      //printf("result[j]=%c\n",result[j]);
	  //printf("r[j]=%d\n",r[j]);
	  j++;
	  sum=sum/l3;
	}
	part=j;
	for(j=part-1;j>=0;j--)
	{
	  printf("%c",result[j]);
	}
}
	return 0;
}