semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
long times(int a ,int n)
{
	long sum =1;
	for (int i = 1;i<=n;i++)
	{
		sum*=a;
	}
	return sum;
}
long input(char n[1000],int a)
{
	int la;
	long out= 0;
	la = strlen(n);
	for (int i = la-1;i>=0;i--)
	{
		if (n[i]<=57)
		{
			int p;
			p = (int)n[i]-48;
			out+= ((long)p) *times(a,(la-i-1));
		}
		else
		{
			if (n[i]<=90)
			{
				int p;
				p = (int)n[i]-55;
				out+= ((long)p)*times(a,(la-i-1));
			}
			else
			{
				int p ;
				p = (int)n[i]-87;
				out+=((long)p)*times(a,(la-i-1));
			}
		}
	}
	return out;
}
int main()
{
	int a ,b;
	char n[1000];
	cin>>a>>n>>b;
	long out;
	out = input(n,a);
	char on[1000];
	int la;
	la = strlen(n);
	int l;
	for (l = 1; out/(long)b >= times(b,l-1);l++)
	{
	}
	for (int i = 0;i<l;i++)
	{
		int p;
		for (p = 0;out-times(b,(l-1-i))>=0;p++)
		{
			out-=times(b,(l-1-i));
		}
		if (p<=9)
		{
			on[i]=(char)(p+48);
		}
		else
		{
			on[i]=(char)(p+55);
		}
	}
	on[l]='\0';
	cout<<on;

}
int pow(int m,int n)
{
   int pi=1,i;
   for(i=1;i<=n;i++)
   {
      pi=pi*m ;             
                    } 
    return pi;
    }
    
void Get(int sum,int b)
{
  int t;
  if (!sum)
    return;
  Get(sum/b,b);       
  t=sum%b;
  if (t<10)
    printf("%1d",t);
  else
    printf("%1c",t-10+'A');
}    
int main()             
{
    int a,b,k=0,sum=0,i,j=0;//a???????,b???????,k???????,sum????????
    char num[10000];//???????? 
    char other[10000];//???????? 
    int another[10000];
          cin>>a;
          cin>>num;
          cin>>b;
      k=strlen(num);
    for(i=0;i<=k-1;i++)//?????? 
         { if(num[i]>=65&&num[i]<=90)
          {
              sum=sum+(num[i]-55)*pow(a,(k-i-1));                  
              }                     
          else if(num[i]>=97&&num[i]<=122)
             {
               sum=sum+(num[i]-87)*pow(a,(k-i-1));                     
                                     }
           else if(num[i]>=48&&num[i]<=57)
              {
                sum=sum+(num[i]-48)*pow(a,(k-i-1));                     
                                     }
          }
        
   /**   do//???b?? 
      {
        another[j]=sum%b;               
        sum=sum/b;               
        if(another[j]>=0&&another[j]<=9)
           {other[j]=another[j]+48;}            
        else               
            {other[j]=another[j]+55;}
            j=j+1;          
             }while(sum>0);
        for(i=j;i>=0;i--)     
       {      
              cout<<other[i];//??
                             }*/
  if (sum){
  Get(sum,b);                           
  cout<<endl;}
  else
    cout<<"0"<<endl;
    return 0;
    }
void main()
{
	int i,j,k,n,m;
	long int t,p;
	char a[50],c[50];
	int b[50];
	scanf("%d %s %d",&n,a,&m);
	t=0;
	for(j=0;a[j]!='\0';j++)
	{
		if('a'<=a[j]&&a[j]<='z')
			b[j]=a[j]-87;
		else if('A'<=a[j]&&a[j]<='Z')
			b[j]=a[j]-55;
		else if('0'<=a[j]&&a[j]<='9')
			b[j]=a[j]-48;
	}
	for(i=0;i<=j-1;i++)
		t=pow(n,j-i-1)*b[i]+t;
    p=t;
	if(t==0)
		printf("0");
	else 
	{
	for(k=0;t!=0;k++)
		t=t/m;
	for(i=k-1;i>=0;i--)
	{
		if((p%m)>=10)
			c[i]=p%m+55;
		else 
			c[i]=p%m+48;
		p=(p-p%m)/m;
	}
	c[k]='\0';
	puts(c);
	}
}
int main()
{
	int a,b,num=0,i;
	char n[31],m[31];
	cin>>a>>n>>b;
	for(i=0;i<strlen(n);i++)
        {
		if(n[i]<58)n[i]-=48;
		else
		{
			if(n[i]>96)n[i]-=87;
			else n[i]-=55;
		}
		num=num*a+n[i];
        }
	for(i=0;num;i++)
	{
		if(num%b<10)m[i]=num%b+48;
		else m[i]=num%b+55;
		num=num/b;
	}
	if(i)for(;i>0;i--)cout<<m[i-1];
        else cout<<0;
	return 0;
}
//****************************************************** 
//* ? ? ?   ?? ? ? ?                           *
//* ? ?      ?? ? ?                              *
//* ? ? ? ??2010 ? 11 ? 24 ?                   * 
//* ? ?      ?1000010185                            *
//****************************************************** 
int main()
{
	int a, b, dec = 0, l, k = 1, j = 0;
	char n[32], nb[32];
	cin >> a >> n >> b;
	l = strlen(n);
	for (int i = l - 1; i >= 0; i --)
	{
		if (n[i] >= '0' && n[i] <= '9')
			dec += (n[i] - '0') * k;
		if (n[i] >= 'a' && n[i] <= 'z')
			dec += (n[i] - 'a' + 10) * k;
		if (n[i] >= 'A' && n[i] <= 'Z')
			dec += (n[i] - 'A' + 10) * k;
		k *= a;
	}
	do
	{
		if (dec % b <= 9)
			nb[j ++] = dec % b + '0';
		else
			nb[j ++] = dec % b - 10 + 'A';
		dec /= b;
	} while (dec != 0);
	for (int i = j - 1; i >= 0; i --)
		cout << nb[i];
	return 0;
}
int ppow(int a,int b){
    int i,j;
    j=1;
    for(i=1;i<=b;i++){
       j=j*a;
       }
       return j;
       }
int qq(char t){
 if(t<=57&&t>=48)
 return t-48;
 if(t<=90&&t>=65)
 return t-55;
 if(t<=122&&t>=97)
 return t-87;
}
char rr(int t){
if(t<=9&&t>=0)
return t+48;
if(t<=35&&t>=10)
return t+55;
}  
int main(){
    char n[10000];
    int a,b,m,i,j;
    cin>>a>>n>>b;
    if (n[0]=='0') 
    {
     cout<<'0';
     return 0;
    }
    m=0;
    j=0;
    while(n[m]!='\0')
      m++;
    for(i=0;i<=m-1;i++)
    { 
      j=j+qq(n[i])*ppow(a,m-i-1);     
      }
      m=(int)(log(j)/log(b))+1;
      for(i=0;i<=m-1;i++){
       cout<<rr(j/ppow(b,m-i-1));
       j=j-(j/ppow(b,m-i-1))*ppow(b,m-i-1);                
                        }    
                        
      return 0;
      }
int main(){
	char s[100];
	int a,b;
	scanf("%d %s %d",&a,s,&b);

	//?????????
	int l,k,i;
	l=strlen(s);
	int sz[100];
	
	for(i=0;i<l;i++){
		if(s[i]>='a'&&s[i]<='z')
			sz[i]=10+s[i]-'a';
		if(s[i]>='A'&&s[i]<='Z')
			sz[i]=10+s[i]-'A';
		if(s[i]>='0'&&s[i]<='9')
			sz[i]=0+s[i]-'0';
	}

	for(i=0;i<l;i++){
		//printf("sz[%d]=%d",i,sz[i]);
		k=l-i-1;
		while(k--){
			sz[i]=sz[i]*a;}
		//printf("sz[%d]=%d",i,sz[i]);
	}
	
	int num10=0;//shijinzhishu
	for(i=0;i<l;i++){
		num10+=sz[i];
		
	}
	//printf("%d",num10);

	//zhuanhuawei b jinzhi
	int shang,yushu;
	shang=num10/b;
	yushu=num10%b;
	int geweiyushu[100];
	if(shang==0){printf("%d",yushu);}
	else {for(i=0;shang!=0;i++){
		geweiyushu[i]=yushu;
		
		yushu=shang%b;
		shang=shang/b;
	}
	geweiyushu[i]=yushu;}

	int weishu;
	weishu=i+1;
	//printf("weishu=%d",weishu);

	


	//???string

	char s2[100];

	for(i=0;i<weishu;i++){
		if(geweiyushu[i]>=10){s2[i]=geweiyushu[i]-10+'A';}
		else s2[i]=geweiyushu[i]-0+'0';
	}
	int y=0; 
	for(i=0;i<l;i++){
		if(s[i]!='0')
			y++;
	}
	//printf("y=%d\n",y);
	if(y!=0){
	for(i=weishu-1;i>=0;i--){
		printf("%c",s2[i]);
	}}
	//else printf("0");


	return 0;	
}
void main()
{
long int n=0,m;
int a,b,i,j,k,l,t=0;
char s[20],d[20];
scanf("%d %s %d",&a,s,&b);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]>='0'&&s[i]<='9')
   k=s[i]-'0';
if(s[i]>='a'&&s[i]<='z')
   k=s[i]-'a'+10;
if(s[i]>='A'&&s[i]<='Z')
   k=s[i]-'A'+10;
m=k;
for(j=1;j<l-i;j++)
m=m*a;
n=n+m;
}
if(n==0)
printf("0");
for(i=0;n>0;i++)
{
if(n%b<10)
	d[i]=n%b+'0';
else 
	d[i]=n%b+'A'-10;
n=n/b;
}
for(j=i-1;j>=0;j--)
printf("%c",d[j]);
}
int main()
{
	long long int n=0,a,a0,b;
	int i=0,j;
	char change1(char),change2(char);
	char str[1000],put[1000];
	scanf("%lld ",&a0);
	do
	{
		scanf("%c",&str[i]);
		if(str[i]>96) str[i]=str[i]-32;
		i=i+1;
	}
	while(str[i-1]!=' ');
	i=i-1;
	scanf("%lld",&b);
	a=1;
	for(j=i-1;j>=0;j--)
	{
		n=n+a*change1(str[j]);
		a=a*a0;
	}
	j=0;
	while(n!=0)
	{
		put[j]=change2((char)(n%b));
		n=n/b;
		j=j+1;
	}
	if(j>0)
	{
		for(i=j-1;i>=0;i--)
	    printf("%c",put[i]);
	}
	if(j==0)
	printf("0");
	return 0;
}
char change1(char m)
{
	if(m<='9'&&m>='0') m=m-'0';
	if(m>'9') m=m-'A'+10;
	return(m);
}
char change2(char m)
{
	if(m>=10) m=m-10+'A';
	if(m<10)  m=m+'0';
	return(m);
}
int main()
{
    int a,b,l,decimal=0;
    char c[40];
    int i;
    scanf("%d %s %d",&a,c,&b);
    l=strlen(c);
    if(c[0]=='0') printf("0\n");
    else
    {
        for(i=0;i<l;i++)
        {
                        if(c[i]>='A'&&c[i]<='Z') c[i]=c[i]+'a'-'A';
        }
        int d[40];
        for(i=0;i<l;i++)
        {
                        if(c[i]>='a') c[i]=c[i]+10-'a';
                        else c[i]=c[i]-'0';
                        d[i]=1;
                        for(int j=0;j<l-i-1;j++)
                        {
                                          d[i]=d[i]*a;
                        }
        decimal=decimal+d[i]*c[i];    
        }
        char e[40];
        int k,y;
        for(k=0;decimal!=0;k++)
        {                  
                        e[k]=decimal%b;
                        decimal=decimal/b;                     
        }
        e[k]='\0';
        char f[40];
        for (y=0;y<k;y++)
        {
            if(e[y]<10)
            f[k-1-y]=e[y]+'0';
            else
            f[k-1-y]=e[y]-10+'A';
        }
        f[k]='\0';
        printf("%s",f);
        
    }
        getchar();
        getchar();
        getchar();
}
int main()
{
    int zhuan(char);
    int a,b,l,i,wei;
    char n[100];
    long shi;
    scanf("%d%s%d",&a,n,&b);
    l=strlen(n);
    for(i=0,shi=0;i<=l-1;i++)
    {
                       if(i<l-1)
                      shi=(shi+zhuan(n[i]))*a;
                       else
                       shi=shi+zhuan(n[i]);
    }
    
    for(i=0;;shi=shi/b,i++)
    {
                       wei=shi%b;
                       if(wei>=10)
                       n[i]=wei-10+'A';
                       else
                       n[i]=wei+'0';
                       
                       if(shi<b)
                       break;
    }
    for(i=i;i>=0;i--)
    printf("%c",n[i]);
                       
    
    return 0;
}
int zhuan(char b)
{
    int a;
    if(b>='0'&&b<='9')
    a=b-48;
    if(b>='a'&&b<='z')
    a=10+b-'a';
    if(b>='A'&&b<='Z')
    a=10+b-'A';
    return a;
}
int f(char a);
void k(int s,int n,int g[]);
int main()
{
	double m,n;
	char a[30];
	cin>>m;
	cin>>a;
	cin>>n;
	int i,l=strlen(a),s=0;
	for(i=0;i<=l-1;i++)
	{
		s=s+f(a[i])*(int)pow(m,l-i-1);
	}
	int b[50];
	k(s,n,b);
	
    
	return 0;

}

int f(char a)
{
	if(a=='0')return 0;
	if(a=='1')return 1;
	if(a=='2')return 2;
	if(a=='3')return 3;
	if(a=='4')return 4;
	if(a=='5')return 5;
	if(a=='6')return 6;
	if(a=='7')return 7;
	if(a=='8')return 8;
	if(a=='9')return 9;
	if(a=='a'||a=='A')return 10;

if(a=='b'||a=='B')return 12-1;
if(a=='c'||a=='C')return 13-1;
if(a=='d'||a=='D')return 14-1;
if(a=='e'||a=='E')return 15-1;
if(a=='f'||a=='F')return 16-1;
if(a=='g'||a=='G')return 17-1;
if(a=='h'||a=='H')return 18-1;
if(a=='i'||a=='I')return 19-1;
if(a=='j'||a=='J')return 20-1;
if(a=='k'||a=='K')return 21-1;
if(a=='l'||a=='L')return 22-1;
if(a=='m'||a=='M')return 23-1;
if(a=='n'||a=='N')return 24-1;
if(a=='o'||a=='O')return 25-1;
if(a=='p'||a=='P')return 26-1;
if(a=='q'||a=='Q')return 27-1;
if(a=='r'||a=='R')return 28-1;
if(a=='s'||a=='S')return 29-1;
if(a=='t'||a=='T')return 30-1;
if(a=='u'||a=='U')return 31-1;
if(a=='v'||a=='V')return 32-1;
if(a=='w'||a=='W')return 33-1;
if(a=='x'||a=='X')return 34-1;
if(a=='y'||a=='Y')return 35-1;
if(a=='z'||a=='Z')return 36-1;
}

void k(int s,int n,	int g[])
{

	int i=0;
	do
	{
		g[i]=s%n;
		s=(s-g[i])/n;
		i++;
	}while(s!=0);
	int j;

	for(j=i-1;j>=0;j--)
	{
		if(g[j]>=10)
			cout<<(char)('A'+g[j]-10);
	   else
		   cout<<g[j];
	}
}
int main(int argc, char* argv[])
{
	int i,j=0,k,l,n,m,a,b,put[100];
	long num=0;
	char str[100];
	scanf("%d%s%d",&a,str,&b);
    m=strlen(str);
	if(str[0]=='0')
	{
		printf("0");
		return 0;
	}
	else
	{for(i=0;i<m;i++)
	{
		if(str[i]>='0'&&str[i]<='9')
			n=str[i]-'0';
		else if(str[i]>='a'&&str[i]<='z')
			n=str[i]-'a'+10;
		else 
			n=str[i]-'A'+10;
		num+=n*pow(a,m-i-1);
	}                                                   //num????????
	while(num>0)
	{
		put[j]=num%b;
		j++;
		num=num/b;
	}
	for(k=j-1;k>=0;k--)                                 //???????
	{
		if(put[k]>=0&&put[k]<=9)
			printf("%d",put[k]);
		else 
			printf("%c",((char)(put[k]-10))+'A');
	}
	}
	return 0;
}
/**
?originBase?number???10?? 
*/
int change2Dec(char * number, int len_number, int originBase) {
  
  int result = 0;
  //for?? 
  for (int i=0; i<len_number; i++) {
    //???????10????????
    int numberBit = 0;
    if (number[i]>='0' && number[i]<='9') {
      numberBit = number[i]-'0';
    }
    else if (number[i]>='a' && number[i]<='z') {
      numberBit = number[i]-'a'+10;
    }
    else {
      numberBit = number[i]-'A'+10;
    }
    
    //???????????
    int position = len_number-i;
    
    //???????????? 
    int currentBitValue = numberBit;
    for (int i=1; i<position; i++) {
      currentBitValue *= originBase;
    }
    result += currentBitValue;
  }
  return result;       
} 

/**
?10??decNumber???newBase??????newNumber???????????? 
*/
int changeDec2NewBase(int decNumber, int newBase, char* newNumber) {
    int bitValue[100];                   //??????????????????? 
    int length=0;                          //??????? 
    while (decNumber/newBase > 0) {
        bitValue[length++] = decNumber%newBase;         //??
        decNumber /= newBase;
    }
    bitValue[length++] = decNumber;                     //??????
    
    for (int i=length-1,j=0; i>=0; i--,j++) {
        int currentBit = bitValue[i];
        if (currentBit < 10)
            newNumber[j]=currentBit+'0';
        else
            newNumber[j]=currentBit+'A'-10;
    }
    return length;
}

int main()
{
    int originBase;         //????
    int newBase;            //???
    char number[100];       //????????
    char newNumber[100];    //?????? 
    cin >> originBase >> number >> newBase;
    int len_number;             //????????
    int len_newNumber;          //????????
     
    for (int i=0; i<100; i++)
        if (number[i]==0) {
           len_number = i;
           break;
        }
    int decNumber = change2Dec(number, len_number, originBase);
    len_newNumber = changeDec2NewBase(decNumber, newBase, newNumber);
    newNumber[len_newNumber]=0;
    cout << newNumber << endl;
    
}
void main()
{
long int f=0,e,b,c,i,g,k=0,j=0,v=1;
char d[100],a[100];
int h[100];
e=0;
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");//????
	}
}
/* Note:Your choice is C IDE */
main()
{
    int f(int a,int b);
    int a,b,i,n,sum=0;
    char s[999];
    scanf("%d %s %d",&a,s,&b);
    n=strlen(s);
    for(i=0;i<n;i++)
    {if(s[i]>=97&&s[i]<=122)
    s[i]-=87;
    else if(s[i]>=65&&s[i]<=90)
    s[i]-=55;
    if(s[i]>=48&&s[i]<=57)
    s[i]-=48;}
    for(i=0;i<n;i++)
    sum+=s[i]*f(a,n-i-1);
    for(i=0;;i++)
    {
    	s[i]=sum%b;
    	sum=(sum-s[i])/b;
    	if(s[i]>9)
    	s[i]+=55;
    	if(sum==0)
    	break;
    }
    for(i=i;i>=0;i--)
    {
    	if(s[i]>9)
    	printf("%c",s[i]);
    	else printf("%d",s[i]);
    }
}
int f(int a,int b)
{
	int i,n=1;
	for(i=0;i<b;i++)
	n*=a;
	return n;
}
void main()
{
	char a[32]={0},b[32]={0};
	long int n=0;
	int i,k,j1,j2;
	scanf("%d%s%d",&j1,a,&j2);
	for (i=0;a[i]!=0;i++)
		if (a[i]>='0'&&a[i]<='9')
			n=n*j1+a[i]-'0';
		else if (a[i]>='A'&&a[i]<='Z')
			n=n*j1+a[i]-'A'+10;
		else if (a[i]>='a'&&a[i]<='z')
			n=n*j1+a[i]-'a'+10;
	if (n==0)
		printf("0\n");
	else
	{
		for (i=0;i<=31,n>0;i++)
		{
		    k=n%j2;
		    if (k<10)
			    b[i]=k+'0';
		    else b[i]=k-10+'A';
		    n=n/j2;
		}
	    i=31;
	    while (b[i]==0)
		    i--;
	    for (;i>=0;i--)
		    printf("%c",b[i]);
	    printf("\n");
	}
}
//************************************************************
//*? ? ?:????                                         *
//*?    ?: ???                                          *
//*????:2010-10-25                                       *
//*????:?2--35???????????????            *
//************************************************************
int main()
{
	int i,b,c=0,d,j,count=0;
	double a,e;
	char char_a[32],char_b[32];//????????????????32?????????32?
	cin>>a;
	cin>>char_a;//?????char_a
	cin>>b;
	for(i=0;i<strlen(char_a);i++)//??????????10???????
	{
		if (char_a[i]>=48&&char_a[i]<=57)
			char_a[i]=char_a[i]-48;
		else if(char_a[i]>=97&&char_a[i]<=122)
			char_a[i]=char_a[i]-87;
		else if(char_a[i]>=65&&char_a[i]<=90)
			char_a[i]=char_a[i]-55;
		else break;
	}
	for(i=0;i<strlen(char_a);i++)//??????????10???????
	{
		e=strlen(char_a)-i-1;
		c=c+char_a[i]*pow(a,e);
	}
	j=0;
    if(c<b)
	{
		cout<<c<<endl;
		return 0;
	}
	while(c>=b)//?10??????????
	{
		d=c%b;
		c=c/b;
		if (d<10)
			char_b[j]=d+48;
		else if (d>=10&&b<=35)
			char_b[j]=d+55;
		count=count++;
		++j;
		if (c<b&&c<10)
			char_b[j]=c+48;
		if (c<b&&c>10)
			char_b[j]=c+55;
	}
for(j=count;j>=0;j--)//????
{
	cout<<char_b[j];
}
cout<<endl;
return 0;
}//?????
int main()
{
int temp,b[500];
int n,m,i,j;
long lala=0;
cin>>n;
scanf(" %1c",&i);
while((i>=48&&i<=57)||(i>=65&&i<=90)||(i>=97&&i<=122))
{
    if (i>=48&&i<=57) temp=i-48;
    if (i>=65&&i<=90) temp=i-55;
    if (i>=97&&i<=122) temp=i-87;
    lala=lala*n+temp;
    scanf("%1c",&i);
}

cin>>m;
int c=0;
while(lala>=m)
{
             b[c]=lala%m;
             lala=lala/m;
             c++;
}
b[c]=lala;
for(i=c;i>=0;i--) if (b[i]<10) cout<<b[i]; else printf("%c",b[i]+55);

}
int main()
{
	char a[100],b[100];
	char h;
	long s=0,p;
	int i,t,m,n,j,q;
	scanf("%d%s%d",&m,a,&n);
    t=strlen(a);
    for(i=0;i<t;i++)
	{
		if(a[i]>='A'&&a[i]<='Z')
		{
			s=s*m+a[i]-55;
		}
		else if(a[i]>='0'&&a[i]<='9')
			s=s*m+a[i]-48;
		else
			s=s*m+a[i]-87;
	}
	p=s;
	for(i=0;;i++)
	{
		q=p%n;
		if(q>=10)
			b[i]=55+q;
		else
			b[i]=48+q;
		for(j=i;j>0;j--)
		{
            h=b[j];
			b[j]=b[j-1];
			b[j-1]=h;
		}
		p=p/n;
		if(p==0)
			break;
	}
	b[i+1]='\0';
	printf("%s",b);
	return 0;
}
long int shijinzhi(int a,char n[100])
{
	int i;
	long int z=0;
	for(i=0;i<strlen(n);i++)
	{
		if(n[i]>='0'&&n[i]<='9')
		{
		z+=pow(a,strlen(n)-1-i)*(n[i]-'0');
		}
		else if(n[i]>='a'&&n[i]<='z')
		{
		z+=pow(a,strlen(n)-1-i)*(n[i]-'a'+10);
		}
		else if(n[i]>='A'&&n[i]<='Z')
		{
		z+=pow(a,strlen(n)-1-i)*(n[i]-'A'+10);
		}
	}
	return z;
}
void zhuanhuan(long int x,char a[1000],int b)
{
	int yushu,l,j;
		int i=0;
		char n[1000]={0};
	if(b<=10)
	{
		do
		{
		yushu=x%b;
		x=x/b;
		n[i]=yushu+'0';
		i++;
		}while(x>=b);
		n[i]=x+'0';
	}
	else if(b>10)
	{
		do
		{
		yushu=x%b;
		x=x/b;
		if(yushu<=9)
		n[i]=yushu+'0';
		else if(yushu>9)
		n[i]=yushu-10+'A';
		i++;
		}while(x>=b);
		if(x<=9)
		n[i]=x+'0';
		else if(x>9)
		n[i]=x-10+'A';
	}
	for(l=i,j=0;l>=0;l--,j++)
	{
		a[j]=n[l];
	}
}
void main()
{
	int a,b,i,p;
	long int x;
		char n[1000]={0};
	scanf("%d %s %d",&a,&n,&b);
	x=shijinzhi(a,n);
	p=strlen(n);
	for(i=0;i<=p;i++)
	{n[i]=0;}
	zhuanhuan(x,n,b);
	if(n[0]!='0') printf("%s",n);
	else printf("0");
}
int main()
{
    int a,b,i,j,l,s;
    int c[1000]; 
    char str1[1000],str2[1000];
    scanf("%d%s%d",&a,str1,&b);
    l=strlen(str1);
    s=0;
    for(i=0;i<l;i++)
    {
    if(str1[i]>='A'&&str1[i]<='Z')
    str1[i]=str1[i]-'A'+10;
    else if(str1[i]>='a'&&str1[i]<='z')
    str1[i]=str1[i]-'a'+10;
    else
    str1[i]=str1[i]-'0';
    s=str1[i]+(s*a);
    }
    if(s==0)
    printf("0");
    for(i=0;s!=0;i++)
    {
    c[i]=s%b;
    s=s/b;
    }
    for(j=0;j<i;j++)
    {
    if(c[j]<=9)
    str2[i-j-1]=c[j]+'0';
    else 
    str2[i-j-1]=c[j]+'A'-10;
    }
    printf("%s\n",str2);
    getchar();
    getchar();
}
long long a,b,i,len,j,h[130],t[100],m;
	char s[1000],r[36]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	
int main()
{
	cin>>a;
	cin>>s;
	cin>>b;
	for(i='0';i<='9';i++)
	h[i]=i-48;
	for(i='a';i<='z';i++)
	h[i]=i-87;
	for(i='A';i<='Z';i++)
	h[i]=i-55;
	len=strlen(s);

	m=0;j=1;
	for (i=len-1;i>=0;i--)
		{m=m+h[s[i]]*j;j=j*a;}
i=0;
	while(m>0)
	{
			i++;
			t[i]=m%b;
			m=m/b;
	}
          if (i==0) cout << 0 << endl;
	for(j=i;j>0;j--) cout<<r[t[j]];
	//cin>>i;
          //if(a!=20&&a!=10&&a!=35&&a!=17)cout << "sb" << endl;
	return 0;
}
int main()
{
    int jinzhi1,jinzhi2,length,i,j,m=0,n,sum=0,k;//jinzhi1?????????jinzhi2???????,length???????i?j?m?n?k?????sum?????? 
    int shu[40],shu2[40];//?????????????????? 
    char input[40],output[40];//input?????output??????
    cin>>jinzhi1>>input>>jinzhi2;
    length=strlen(input);//??????? 
    for(i=0;i<length;i++)
    {
                     shu[i]=input[i];//??????????????ASCII? 
                     if(shu[i]<65) shu[i]=shu[i]-48;//????? 
                     else if (shu[i]<97) shu[i]=shu[i]-55;//???? 
                     else shu[i]=shu[i]-87;//???? 
                     for(j=length-i-1;j>0;j--) shu[i]=shu[i]*jinzhi1; 
                     sum=sum+shu[i];//??????                         
    }
    if (sum==0) cout<<sum;
    else
    {
        for(k=0;sum>0;k++) 
        {
             shu2[k]=sum%jinzhi2;//?????? 
             sum=sum/jinzhi2;
             if (shu2[k]<10) shu2[k]=shu2[k]+48;//????ASCII?????? 
             else shu2[k]=shu2[k]+55;
             output[k]=shu2[k];
             m++;
        }
    for(n=m-1;n>=0;n--) cout<<output[n];//???????????????????
    } 
    cin.get();
    cin.get(); cin.get(); cin.get(); cin.get(); cin.get();
    return 0;
}
long f(long a,char str[20],int l);
long F(long n,long b);
int main()
{
	long a,b,n;int i,l;char str[20];
	cin >> a >> str >> b;
	l=strlen(str);
	for(i=0;i<l;i++)
	{
		if(str[i]>96&&str[i]<123)
			str[i]=str[i]-32;
	}
	n=f(a,str,l);
	F(n,b);
	return 0;
}
long f(long a,char str[20] ,int l)
{
	long sum=0;int i,t,num=1;
	for(i=l-1;i>=0;i--)
	{
		if(str[i]>64&&str[i]<91)
		{
			t=str[i]-'A'+10;
		}
		else
			t=str[i]-'0';
		sum=sum+t*num;
		num=num*a;
	}
	return sum;
}
long F(long n,long b)
{
	int i=0,str[200];char a;
	if(n==0)
		cout << "0" << endl;
	while(n>0)
	{
		str[i]=n%b;
		n=n/b;
		i++;
	}
	for(i=i-1;i>=0;i--)
	{
		if(str[i]>=0&&str[i]<=9)
			cout << str[i];
		else
		{
			a='A'+str[i]-10;
			cout << a;
		}
	}
	cout << endl;
	return 0;
}
/*
 * pp5.cpp
 *
 *  Created on: 2010-11-13
 *      Author: d
 */
int main()
{
	long int a,b,i=0,sum=0,count=0,sum1;
	long int k[100],p[100];
	char temp;
	char n[100],m[100];
	cin>>a>>n>>b;   //??
	while(n[i]!='\0')    //????????
	{
		if(n[i]>=65&&n[i]<=90)
			p[i]=n[i]-55;
		 if(n[i]>=97&&n[i]<=122)
			p[i]=n[i]-87;
		if(n[i]>=48&&n[i]<=57)
			p[i]=n[i]-48;
		i++;
	}
	for(i=0;i<strlen(n);i++)   //??????
	sum=sum+pow((double)a,(double)i)*p[strlen(n)-i-1];
	sum1=sum;
	if(sum1==0) cout<<"0"; else
	while(sum1!=0)
	{    sum1/=b;
	     count++;
	}

		  for(i=0;i<count;i++)
		   k[i]=(sum/(int)pow((double)b,(double)i))%b;
		  for(i=0;i<count;i++)    //????????
		  {
		if(k[i]>9)
		m[i]=k[i]+55;
		else m[i]=k[i]+48;
		  }
		  for(i=0;i<(int)(count/2);i++)
		  {temp=m[i];m[i]=m[count-1-i];m[count-1-i]=temp;}
		  for(i=0;i<count;i++)
			  cout<<m[i];
		  cout<<endl;

	return 0;
}
void main()
{
   long m,n,len,i,total=0,t=0;
   char a[100],b[100];
   scanf("%d%s%d",&m,&a,&n);
   len=strlen(a);
   for(i=0;i<len;i++)
   {
       if(a[i]<='9'&&a[i]>='0')
	   {
	      total=total+(a[i]-'0')*pow(m,len-1-i);
	   }
	   else
	   {
	      if(a[i]<='z'&&a[i]>='a')
		  {
	           total=total+(a[i]-'a'+10)*pow(m,len-1-i);
		  }
		  else
		  {
		       total=total+(a[i]-'A'+10)*pow(m,len-1-i);
		  }
	   }
   }
   if(total==0)printf("0\n");
   else
   {
	   for(i=0;total!=0;i++)
   {
       b[i]=total%n;
	   total=total/n;
	   t++;
	   if(b[i]<=9)b[i]=b[i]+'0';
	   else b[i]=b[i]+'A'-10;
   }
   for(i=t-1;i>=0;i--)
   {
      printf("%c",b[i]);
   }
   printf("\n");
   }
}
char str[100];  
int a,b;  
int num,tmp,i;  
int main() {  
    while(scanf("%d%s %d", &a, str, &b) != EOF){  
        num = 0;  
        for(i=0; str[i]; i++){  
            if(str[i] >= 'a') str[i] -= 32;  
            tmp = (str[i] >= 'A' ? str[i]-'A'+10:str[i]-'0');  
            //tmp = str[i]  
            num = num * a + tmp;  
        }  
        int cnt=0;  
        if(num == 0)  
        {puts("0"); continue;}  
        while(num){  
            if(num%b <=9)  
                str[cnt++] = num%b+'0';  
            else  
                str[cnt++] = num%b-10+'A';  
            num = num/b;  
        }  
        for(i=cnt-1; i>=0; i--)  
            printf("%c",str[i]);  
        puts("");  
    }  
    return 0;  
}