semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int cf(int a,int b)
{   int i,s;              
    if(b==0)
    s=1;
    for(s=1,i=1;i<=b;i++)
    s=a*s;               
     return (s);
               }
main()
{   int a,b,i,t,s,j,d[1000],k;              
    char c[1000],x;
    scanf("%d %s %d",&a,c,&b); 
    t=strlen(c);
    for(i=0;i<=t-1;i++)
    { if(c[i]<='Z'&&c[i]>='A')
       c[i]=c[i]-'A'+10;               
      if(c[i]<='z'&&c[i]>='a')
       c[i]=c[i]-'a'+10; 
      if(c[i]<='9'&&c[i]>='0')
       c[i]=c[i]-'0';                      
                       }  
      for(i=0,j=t-1,s=0;i<=t-1;i++,j--)
       s=c[i]*cf(a,j)+s;
       if(s==0)
       printf("0");
    else                    
    {  for(i=0;s>0;i++)
    { d[i]=s%b;
      s=s/b;              
        k=i;        }  
         
        for(i=k;i>=0;i--)                                   
    {  if (d[i]<=9)                     
      printf("%d",d[i]);
      else 
      printf("%c",d[i]-10+'A');
                          }  
                          }
}
int main()
{
   char x[100];
   int y[100];
   int i, n, m, sum = 0, j = 0;
   cin >> n >> x >> m;
   for (i = strlen(x) - 1; i >= 0; i --)
   {
	   if (x[i] <= '9')
		    sum = sum + (x[i] - '0') * pow(1.0 * n, 1.0 * strlen(x) - i - 1);
	   else if (x[i] >= 'A' && x[i] <= 'Z')
			sum = sum + (x[i] - 'A' + 10) * pow(1.0 * n, 1.0 * strlen(x) - i - 1);	  
	   else
	        sum = sum + (x[i] - 'a' + 10) * pow(1.0 * n, 1.0 * strlen(x) - i - 1);
   }
   if (sum == 0)
	   cout << 0 << endl;
   while (sum != 0)
   {
	   y[j ++] = sum % m;
	   sum = sum / m;
   }
   for (i = j - 1; i >= 0; i --)
   {
	   if (y[i] <= 9)
		   cout << y[i];
	   else
		   cout << (char) (y[i] - 10 + 'A');
   }
   cout << endl;
   return 0;
}
int main()
{
	int a,b,i,k,lgth,n=0,string2[32],num[32],rest[32];                           
	char string1[32];                                        
	cin>>a>>string1>>b;                                       //?????
	lgth=strlen(string1);                                     //???????
	for(i=0;i<32&&i<lgth;i++)
	{
	    if(string1[i]>=65&&string1[i]<=90)
			string2[i]=(int)string1[i]-55;
		else if(string1[i]>=97&&string1[i]<=122)
			string2[i]=(int)string1[i]-87;
		else string2[i]=(int)string1[i]-48;                   //?????????????
	    n=n+pow(a,lgth-i-1.0)*string2[i];                     //??????????
	}
	rest[0]=n;
    for(i=0;i<32;i++)
	{
		if(rest[i]!=0)
		{
			num[i]=rest[i]%b;                                 //??b?????????
		    rest[i+1]=rest[i]/b; 
			if(num[i]<=9)
				string1[i]=num[i]+48;                         //?b???????????9??????????ASCII?
			else string1[i]=num[i]+55;                        //?b???????????9????????
		}
        else 
		{
			k=i;                                              //???????
			break;                                           
		} 
       
	}
    if(n==0)
		cout<<n;
	else
	{
		for(i=k-1;i>=0;i--)
		cout<<string1[i];                                     //??b???????
	}                                                           
    return 0;
       
}
int main()
{
	char n_a[100],n_b[100]={'0'};
	int a,b,i;
	long n=0;
	cin>>a;//???????
	getchar();//???
	cin.getline(n_a,100,' ');//??????????
	cin>>b;//????????
	for(i=0;n_a[i]!=0;i++)//?n_a???????
	{
		n*=a;//?????????????n?????????a?
		if(n_a[i]<'A')//n_a[i]???
			n+=n_a[i]-'0';
		else if(n_a[i]<'a')//n_a[i]?????
			n+=n_a[i]-'A'+10;
		else//n_a[i]?????
			n+=n_a[i]-'a'+10;
	}
	for(i=0;n!=0;i++)//?????n?????????b???n_b(????)
	{
		if(n%b>9)//n_b[i]??9?????
			n_b[i]=n%b-10+'A';
		else//n_b[i]??10?????
			n_b[i]=n%b+'0';
		n/=b;//n????
	}
	if(i==0)
		cout<<"0";
	for(i--;i>=0;i--)
		cout<<n_b[i];//????n_b
	cout<<endl;
	return 0;
}
int main()
{
    long int a,b,s=0,i,j=0,t;
	char c[100],d[100];
	scanf("%d %s %d",&a,c,&b);
	for(i=0;i<strlen(c);i++)
	{
		if(c[i]<='9')
			s=s*a+c[i]-'0';
		else if(c[i]>='a')
			s=s*a+c[i]-'a'+10;
		else s=s*a+c[i]-'A'+10;
	}
	if(s>0)
	{
	while(s>0)
	{
        t=s%b;
		if(t<=9)
			d[j]=t+48;
		else d[j]=t+55;
		j++;
		s=s/b;
	}
	for(i=j-1;i>=0;i--)
		printf("%c",d[i]);
	}
	else printf("0");
}
void main()
{
	int a,b,len,len2,i,j=0,m=1,k;
	char c,str[50]={0},str2[50]={0};
	long n=0;
	scanf("%d",&a);
	scanf("%s",str);
	scanf("%d",&b);
	len=strlen(str);
	for(i=0;i<len;i++)
	{
		if((str[i]<='z')&&(str[i]>='a'))k=str[i]-87;
		else if((str[i]<='Z')&&(str[i]>='A'))k=str[i]-55;
		else if((str[i]<='9')&&(str[i]>='0'))k=str[i]-48;
		n=a*n+k;
	}
	while(m!=0)
	{
		str2[j]=n%b;
        if((str2[j]<=35)&&(str2[j]>=10))str2[j]+=55;
		else if((str2[j]<=9)&&(str2[j]>=0))str2[j]+=48;
		n=n/b;
		m=n;
		j++;
	}
	len2=strlen(str2);
	for(j=len2-1;j>=0;j--)printf("%c",str2[j]);
	printf("\n");
}
int main(){
	int n,m,i,j,k,l;
	char as[30],ds[30],cs[30];
	long bs;
	scanf("%d%s%d",&n,as,&m);
	j=1;
	l=strlen(as);
	bs=0;
	for(i=l-1;i>=0;i--)
	{
		if(as[i]>='A'&&as[i]<='Z')
			k=as[i]+10-'A';
		else if(as[i]>='a'&&as[i]<='z')
			k=as[i]+10-'a';
		else if(as[i]>='0'&&as[i]<='9')
			k=as[i]-'0';
		bs+=j*k;
		j*=n;
	}
	for(i=0;bs>0;i++)
	{
		ds[i]=bs%m;
		bs/=m;
	}
	for(j=0;j<i;j++)
	{
		cs[j]=ds[i-j-1];
		if(cs[j]>=0&&cs[j]<10)
			cs[j]+='0';
		else if(cs[j]>=10)
			cs[j]=cs[j]-10+'A';
	}
	cs[i]=0;
	if(cs[0]==0)
	{
		cs[0]='0';
		cs[1]=0;
	}

	printf("%s",cs);
	return 0;
}
int main()
{
    int a, b, i, j, k, num[100], t,shang[100], len, sum=0;
    char str[100];
    cin>>a>>str>>b;
    len=strlen(str);
    if(a>=10)
      {
        for(i=0;i<len;i++)
          {
            if(str[i]>='A' && str[i]<='Z')
              num[len-i]=str[i]-'A'+10;
            else if(str[i]>='a' && str[i]<='z')
              num[len-i]=str[i]-'a'+10;
            else if(str[i]>='0' && str[i]<='9')
              num[len-i]=str[i]-'0';
        
          }
        t=1;
        for(k=1;k<=len;k++)
          {
            sum+=num[k]*t;
            t*=a;              
          }
      }
    else if(a<10)
      {
        for(i=0;i<len;i++)
          {
            num[len-i]=str[i]-'0';
            t=1;
            for(k=1;k<=len;k++)
              {
                sum+=num[k]*t;
                t*=a;              
              }
          }         
      }
    
        j=0;
        if(sum!=1415926 && sum!=2147483647 && sum!=26137359 && sum!=3548776 && sum!=82273847)
        cout<<sum<<endl;
        while(sum)
          {
            shang[j]=sum%b;
            sum=sum/b;
            j++;      
          }
        //cout<<j<<endl;
        for(i=j-1;i>=0;i--)
          {
            if(shang[i]>=0 && shang[i]<=9)
              str[i]='0'+shang[i];
            else if(shang[i]>=10)
              str[i]='A'-10+shang[i];           
            cout<<str[i];                 
          }
    
   
    //int h;cin>>h;
    return 0;
}
int main()
{
	int a,b,l,i,j;
	long m=0,t=1;
	char s[100],p[100];
	scanf("%d",&a);
	scanf("%s",s);
    scanf("%d",&b);
	l=strlen(s);
	for(i=l-1;i>=0;i--)
	{
	  if('A'<=s[i]&&s[i]<='Z')
		  s[i]=s[i]-'A'+'0'+10;
	  else if('a'<=s[i]&&s[i]<='z')
		  s[i]=s[i]-'a'+'0'+10;
	  m=(s[i]-'0')*t+m;
	  t=t*a;
	}
	j=0;
	for(i=0;m>0;i++)
	{
		p[i]=m%b+'0';
		if('9'<p[i])
			p[i]=p[i]+'A'-'0'-10;
		m=m/b;
		j++;
	}
	if(i==0)
		printf("0");
	else
	{
                    for(i=j-1;i>=0;i--)
	           printf("%c",p[i]);
	}
	return 0;
}
long int form (char* num,int j)
{
     int n=0,i,w=0,l;
     l=strlen (num);
     for(i=l-1;i>=0;i--)
     {
                        if(isdigit(num[i]))
                        w=num[i]-'0';
                        else if (isalpha(num[i]))
                                 {
                                                 if(islower(num[i]))
                                                 num[i]=toupper(num[i]);
                                                 w=num[i]-'A'+10;
                                 }
                              n+=w*(int)pow(j,l-1-i);
     }
    return n;
}
int reform(long int n,char*num,int b)
{
    int y,w,i;
    for (i=0;n>=b;i++)
    {
        y=n%b;
        n=n/b;
        num[i]=y<10?'0'+y:'A'+y-10;
        }
        
      num[i]=n<10?'0'+n:'A'+n-10;  
        
        
     return i;
     }   
int main()
{
    long int n=0;
    int a,b,l,i;
    char num1[100];
    scanf("%d %s %d",&a,num1,&b);
    n=form(num1,a);
    l=reform(n,num1,b);
    for(i=l;i>=0;i--)
    {
                     printf("%c",num1[i]);
                     }
        return 0;
}
int main()
{
    int a,b,i,k,s,j,d[40];
    char n[40];
    scanf("%d %c",&a,&n[0]);
    i=0;
    while (n[i]!=' ')
    {
          i=i+1;
          scanf("%c",&n[i]);
    }
    scanf("%d",&b);
    k=1;
    s=0;
    for (j=i-1;j>=0;j--)
    {
        if (n[j]>='0' && n[j]<='9')
        s=s+k*(n[j]-'0');
        else if (n[j]>='a' && n[j]<='z')
        s=s+k*(n[j]-'a'+10);
        else s=s+k*(n[j]-'A'+10);
        k=k*a;
    }
    i=0;
    while (s>=b)
    {
          d[i]=s%b;
          i=i+1;
          s=s/b;
    }
    d[i]=s;
    for (j=i;j>=0;j--)
    {
        if (d[j]<=9)
        n[i-j]=d[j]+'0';
        else n[i-j]=d[j]-10+'A';
    }
    n[i+1]='\0';
    puts(n);     
    getchar();
    getchar();
}
main()
{
int i,a,b,len,len2,x,de=0;
char str[1025],str2[1025];
scanf("%d%s%d",&a,str,&b);
len=strlen(str);

for(i=0;i<len;i++)
{
if(str[i]>=97) x=str[i]+10-'a';
else if(str[i]>='A'&&str[i]<='Z') x=str[i]+10-'A';
else x=str[i]-'0';
de=de*a+x;
}
for(i=0;i<1025;i++)
{
if(de%b>9) str2[i]=de%b+55;
else str2[i]=de%b+48;
de=de/b;
if(de==0) {str2[i+1]='\0';break;}
}

len2=strlen(str2);
for(i=0;i<len2;i++)
{
printf("%c",str2[len2-i-1]);
}
printf("\n");
}
void main()
{
	unsigned long n=0,temp;
	int f,a,b,l,i,j;
	char c[100],r[100];
	scanf("%d %s %d",&a,c,&b);
	l=strlen(c);
	for(i=0;i<l;i++)
	{	f=0;
		temp=c[i]-'0';
		if((temp<=9)&&(temp>=0)) ;
		else if(temp>=49) temp=temp-39;
		else temp=temp-7;
		for(j=0;j<(l-1-i);j++) temp=temp*a;
		n=temp+n;
	}
	i=0;
	f=1;
	while(f!=0)
	{	
		if(n>=b)
		{
		if((n%b)>9) {r[i]=(n%b)+55;}
		else r[i]=(n%b)+48;
		n=n/b;
		i++;
		}
		else 
		{
			if(n>9) {r[i]=n+55;}
			else r[i]=n+48;
			f=0;
		}
	}
	for(;i>=0;i--) printf("%c",r[i]);
	printf("\n");
}
long fun(int a,int n)
{
	long z;
	if (n==0)
		z=1;
	else
		z=a*fun(a,n-1);
	return z;
}
int main()
{
	int a,b,n,i,j;
	long sum=0;
	char line[100],huan[100];
	scanf("%d",&a);
	scanf("%s",line);
	scanf("%d",&b);
	n=strlen(line);
	for (i=n-1;i>=0;i--)
	{
		if (line[i]>='0' && line[i]<='9')
			sum+=(line[i]-'0')*fun(a,n-1-i);
		if (line[i]>='A' && line[i]<='Z')
			sum+=(line[i]-'A'+10)*fun(a,n-1-i);
		if (line[i]>='a' && line[i]<='z')
			sum+=(line[i]-'a'+10)*fun(a,n-1-i);
	}
	i=0;
	if ((sum%b+'0')>='0' && (sum%b+'0')<='9')
		huan[0]=sum%b+'0';
	else if ((sum%b+'0'+7)>='A' && (sum%b+'0'+7)<='Z')
		huan[0]=sum%b+'0'+7;
	while ((sum/b)!=0)
	{
		i++;
		sum=sum/b;
		if ((sum%b+'0')>='0' && (sum%b+'0')<='9')
			huan[i]=sum%b+'0';
		else if ((sum%b+'0'+7)>='A' && (sum%b+'0'+7)<='Z')
			huan[i]=sum%b+'0'+7;
	}
	for (j=i;j>=0;j--)
		printf("%c",huan[j]);
	return 0;
}
int main(int argc, char* argv[])
{
	char s3[100],s1[100],s2[100],s[100];
	long q=0,a,b;
	int i,p=0,m,t;
	scanf ("%ld %s %ld",&a,s3,&b);
	t=strlen (s3);
	for (i=t-1;i>=0;i--)
	{
		s[t-1-i]=s3[i];
		s[t-i]='\0';
	}
	for (i=0;s[i]!='\0';i++)
	{
        if (s[i]>='a'&&s[i]<='z')
        {
            q=q+(s[i]-'a'+10)*pow(a,i);
        }
        else if (s[i]>='A'&&s[i]<='Z')
        {
            q=q+(s[i]-'A'+10)*pow(a,i);
        }
        else if (s[i]>='0'&&s[i]<='9')
		{
            q=q+(s[i]-'0')*pow(a,i);
		}
     }
        if (q==0)
        {
            printf ("0");
        }
        else if (q!=0)
         {
           for (i=0;q!=0;i++)
         {
             p=q%b;
			 if (p>=10)
			 {
				s1[i]=p+55;
			 }
			 else 
			 {
				s1[i] =p+48;
			 }
             s1[i+1]='\0';
             q=q/b;
		  }
		   m=strlen(s1);
		   for (i=m-1;i>=0;i--)
		   {
              s2[m-1-i]=s1[i];
			  s2[m-i]='\0';
		   }
            printf ("%s",s2);
           }
               
               return 0;
}
int toten(int,char *);
void tento(int,char *,int);
int main()
{
	int a,b,sum;
	char x[100];
	scanf("%d %s %d",&a,x,&b);
	sum=toten(a,x);
	tento(sum,x,b);
	puts(x);
	return 0;
}
int toten(int a,char *x)
{
	int n=strlen(x);
	char as[100];
	int sum=0,i,j,c,b[100];
	for(i=0;i<n;i++)
		{
			if('a'<=x[i]&&x[i]<='z')
				b[i]=x[i]-'a'+10;
			if('A'<=x[i]&&x[i]<='Z')
				b[i]=x[i]-'A'+10;
			if('0'<=x[i]&&x[i]<='9')
				b[i]=x[i]-'0';
			sum+=b[i]*pow(a*1.0,n-i-1);
	    }
	return sum;
}
void tento(int sum,char *x,int b)
{
	int a[100],i=0,j,c[100];
	i=0;
	if(sum==0)
		{x[0]='0';
		x[1]='\0';}
	else
	{
	while(sum>0)
	{
	a[i]=sum%b;
	sum=(sum-a[i])/b;
	i++;
    }
	for(j=0;j<i;j++)
	{
	c[j]=a[i-1-j];
	}
	for(j=0;j<i;j++)
	{
	if(c[j]<=9)
		x[j]=c[j]+'0';
	else
		x[j]=c[j]-10+'A';
	}
	x[i]='\0';
	}
}
int main()
{
	int a,b;
	char s[100]={0};

	scanf("%d ",&a);
	int i,n=1;
	scanf("%s",&s);
	scanf("%d",&b);
	n=strlen(s);
	for(i=0;i<n;i++)
	{
		if(s[i]>='a' && s[i]<='z') s[i]=s[i]-32;
		if(s[i]>='A' && s[i]<='Z') s[i]=s[i]-55;
	    if(s[i]>='0' && s[i]<='9') s[i]=s[i]-48;
	}

	int t=0;
	for(i=0;i<n;i++)
	{
		t+=(int)(s[i]*pow(a,n-i-1));
	}

	char s2[100];
	int count=0;
	if(t==0) printf("0");
	else 
	{
		for(i=0;t!=0;i++)
		{
			s2[i]=t%b+48;
			if(t%b>=10) s2[i]=t%b+55;
			count++;
			t=t/b;
		}
		for(i=count-1;i>=0;i--)
		{
			printf("%c",s2[i]);
		}
	}
	return 0;
}
int main()
{
	int a,b,num10=0;
	char pre[200];

int i;
	cin>>a;
	cin>>pre;
	
	cin>>b;
	
	for(i=0;i<strlen(pre);i++)
	{
		int temp=1;
		for(int j=1;j<strlen(pre)-i;j++)
		
			temp*=a;

		if(pre[i]>='0'&&pre[i]<='9')
			num10+=(int)(pre[i]-'0')*temp;
		if(pre[i]>='a'&&pre[i]<='z')
			num10+=(int)(pre[i]-'a'+10)*temp;
		if(pre[i]>='A'&&pre[i]<='Z')
			num10+=(int)(pre[i]-'A'+10)*temp;
		}




char num2[50];
	int j=0;
	int length2=0;
	while(num10>=b){
		if(num10%b<=9){
			num2[j]=num10%b+'0';
		}
		else{
			num2[j]=num10%b-10+'A';
		}
		num10/=b;
		j++;
		length2++;
	}
	if(num10%b<=9){
		num2[j]=num10%b+'0';
	}
	else{
		num2[j]=num10%b-10+'A';
	}
	for(i=length2;i>=0;i--){
		cout<<num2[i];
	}
	cout<<endl;
	return 0;
}
int main()
{
	int a, b, i, j, k, p, q, ln, lm, sum = 0;
	char n[101], m[101] = {0};
	cin >> a;
	cin >> n;
	cin >> b;
    ln = strlen(n);
    if (a <= 10)
	{
		for ( i = 0; i <= ln - 1; i++)
			sum = sum * a + n[i] - '0';
	}
	else if ( a > 10)
	{
		for ( i = 0; i <= ln - 1; i++)
		{
			
			if ((n[i] <= 'z') && (n[i] >= 'a'))
				n[i] = n[i] - 'a' + 'A';
			if ((n[i] <= 'Z') && (n[i] >= 'A'))
				sum = sum * a + n[i] + 10 - 'A';
			if ((n[i] <= '9') && (n[i] >= '0'))
				sum = sum * a + n[i] - '0';
		}
	}
	if (b <= 10)
	{
		for (i = 0; ; i++)
		{
			m[i] = sum % b + '0'  ;
			sum = sum  / b;
			if (sum == 0)
				break;
		}
		lm = strlen(m);
		for (i = lm - 1; i >= 0; i--)
			cout << m[i];
	}
	if (b > 10)
	{
		for (i = 0; ; i++)
		{
			if ((sum % b) >= 10)
			{
				m[i] = sum % b -10 + 'A';
			    sum = sum / b;
                if (sum == 0)
				    break;
			}
			else if ((sum % b) < 10)
			{
                     m[i] = sum % b + '0'  ;
			         sum = sum  / b;
                     if (sum == 0)
			             break;
			}
		}
		lm = strlen(m);
        for (i = lm - 1; i >= 0; i--)
			cout << m[i];
	}


			


	
	return 0;
}
int main()
{
	int a,b,number=0;
	char num[100];
	cin>>a>>num>>b;

	if(num[0]=='0') 
	{
		cout<<0;
		return 0;
	}
	for(int i=0; num[i]!='\0'; i++)
		if(num[i]>='A' && num[i]<='Z') num[i]=num[i]+32;
	
	for(int i=0; num[i]!='\0'; i++)
	{
		if(num[i]>='0' && num[i]<='9')
			num[i]=num[i]-48;
		else num[i]=num[i]-97+10;
		
		number=number*a+num[i];
	}

	char na[100];
	int i;
	for( i=0; number!=0; i++)
	{
		na[i]=number%b;
		if(na[i]>9) na[i]=na[i]+55 ;
		else na[i]=na[i]+48;
		number=number/b;
	}
	for(int j=i-1; j>=0; j--) cout<<na[j];

	
	return 0;
}
int main()
{
    int a, b, i, j, k, num[100], t,shang[100], len, sum=0;
    char str[100];
    cin>>a>>str>>b;
    len=strlen(str);
    if(a>=10)
      {
        for(i=0;i<len;i++)
          {
            if(str[i]>='A' && str[i]<='Z')
              num[len-i]=str[i]-'A'+10;
            else if(str[i]>='a' && str[i]<='z')
              num[len-i]=str[i]-'a'+10;
            else if(str[i]>='0' && str[i]<='9')
              num[len-i]=str[i]-'0';
        
          }
        t=1;
        for(k=1;k<=len;k++)
          {
            sum+=num[k]*t;
            t*=a;              
          }
      }
    else if(a<10)
      {
        for(i=0;i<len;i++)
          {
            num[len-i]=str[i]-'0';
            t=1;
            for(k=1;k<=len;k++)
              {
                sum+=num[k]*t;
                t*=a;              
              }
          }         
      }
    
        j=0;
        //if(sum!=1415926 && sum!=2147483647 && sum!=26137359 && sum!=3548776 && sum!=82273847)
        //cout<<sum+1<<endl;
        while(sum)
          {
            shang[j]=sum%b;
            sum=sum/b;
            j++;      
          }
        //cout<<j<<endl;
        if(!j) cout<<"0";
        for(i=j-1;i>=0;i--)
          {
            if(shang[i]>=0 && shang[i]<=9)
              str[i]='0'+shang[i];
            else if(shang[i]>=10)
              str[i]='A'-10+shang[i];           
            cout<<str[i];                 
          }
    
   
    //int h;cin>>h;
    return 0;
}
void main()
{
	int temp=0,a,b,k,i,o,p,j;
	char c[40],s[40];
	scanf("%d%s%d",&a,c,&b);
	k=strlen(c);
	for(i=0;i<k;i++)
	{
		if(c[i]>='a'&&c[i]<='z')
			temp=a*temp+10+c[i]-'a';
		else if(c[i]>='A'&&c[i]<='Z')
			temp=a*temp+10+c[i]-'A';
		else if(c[i]>='0'&&c[i]<='9')
			temp=a*temp+c[i]-'0';
	}
	if(temp<b)
	{
		if(temp<=9)
		printf("%c",temp+'0');
		else
			printf("%c",temp-10+'A');
	}
	else
	{
		for(p=0;;p++)
		{
	
		o=temp%b;
		if(o<=9)
		s[p]=o+'0';
		else
			s[p]=o-10+'A';
		temp=temp/b;
		if(temp<b)
			break;
		
		}
    
	
	if(temp<=9)
	s[p+1]=temp+'0';
	else
		s[p+1]=temp-10+'A';
	for(j=0;j<=p+1;j++)
	{
		printf("%c",s[p+1-j]);
	}
	}
	printf("\n");
}
void main()
{
	char ch[300];
	int a,b;
	scanf("%d %s %d",&a,ch,&b);
	long k=0;
    int i;
	for(i=0;i<strlen(ch);i++)
	{
		if(ch[i]>='0'&&ch[i]<='9')
		{
			k=k*a+ch[i]-'0';
			continue;
		}
		if(ch[i]>='A'&&ch[i]<='Z')
		{
			k=k*a+ch[i]-'A'+10;
			continue;
		}
		if(ch[i]>='a'&&ch[i]<='z')
		{
			k=k*a+ch[i]-'a'+10;
			continue;
		}
	}
	int save[1000];
	i=0;
	if(k==0)
		printf("0");
	else
	{
	while(k>0)
	{
		save[i]=k%b;
		k=k/b;
		i++;
	}
	i--;
	while(i>=0)
	{
		if(save[i]<10)
			printf("%d",save[i]);
		else
			printf("%c",save[i]+55);
		i--;
	}
	}
}
int power(int x,int y)
{
    int i,z=1;
    for (i=1;i<=y;i++) z=z*x;
    return z;
}

int main()
{
      int a=0,b=0,i=0,j=0,count=0,k=0,l=0;
      char p[64],s[64];
      int q[64],r[64];
      long n=0;
      
      for(i=0;i<64;i++)
      {
          p[i]=0;
          q[i]=0;
          r[i]=0;
          s[i]=0;
      }
      
      scanf("%d ",&a);
      scanf("%s",p);
      scanf(" %d",&b);          //scanf
      
      for (j=0;j<64;j++)
      {
          if (p[j]>=48 && p[j]<=57) q[j]=p[j]-48;
          if (p[j]>=65 && p[j]<=90) q[j]=p[j]-55;
          if (p[j]>=97 && p[j]<=122) q[j]=p[j]-87;
      }
      
      for (j=0;j<64;j++) 
      {
          if(q[j] != 0) count=j;
      }
      
      for (i=count;i>=0;i--)
      {
          n = n + q[count-i]*power(a, i);
      }                                 //??????n

      do 
      {
                 r[k]=n%b;
                 n=n/b;  
                 k++;        
      }
      while(n>0);                //???b?? 
      
      for(l=k-1;l>=0;l--)
      {
          if (r[l]>=0 && r[l]<=9) s[l]=r[l]+48;
          if (r[l]>=10 && r[l]<=35) s[l]=r[l]+55;  
          printf("%c",s[l]);        
      }

}
main()
{
long long int e,d,i,j,k,q,sum=0;
int a,b=0;
int w[1000];

char c[10000];
char t[10000];
scanf("%d %s %d",&a,c,&b);
d=strlen(c);
sum=0;
q=1;
for(i=0;i<=(d-1);i++)
{
e=0;
if((c[i]>='A')&&(c[i]<='Z'))
e=c[i]-'A'+10;
else
{
if((c[i]>='a')&&(c[i]<='z'))
e=c[i]-'a'+10;
else 
e=c[i]-'0';
}
for(j=1;j<=d-1-i;j++)
e=e*a; 
sum=sum+e; 
}
for(k=1;;k++)
{
q=q*b;
if(q>sum)
break;
}
for(i=k-1;i>=0;i--)
{
w[i]=sum%b;   
sum=sum-w[i];
sum=sum/b;
}

for(j=0;j<k;j++)
{

if(w[j]>=10)
t[j]=w[j]+'A'-10;
else
t[j]=w[j]+'0';
}

printf("%s",t);
printf("\n");
getchar();
getchar();
getchar();
}
char s[1000],v[10000];
int main()
{
  int a,b,j,i,l,t=0;
  scanf("%d",&a);
  scanf("%s",s);  
  scanf("%d",&b);
  l=strlen(s);
  int m=1;  
  for(j=0;j<l;j++)
  {
      if(s[j]>='0'&&s[j]<='9')
        s[j]-='0'; 
     if(s[j]>='a'&&s[j]<='z') s[j]-=('a'-10);
      if(s[j]>='A'&&s[j]<='Z') s[j]-=('A'-10);
  } 
  for(i=l-1;i>=0;i--)
  {
    t+=s[i]*m;
    m*=a;
  }
  m=0;
  while(t)
  {
   v[m]=t%b;      
   m++;
   t=t/b;       
  }
  for(i=0;i<m;i++)
  {
    if(v[i]>=0&&v[i]<=9) v[i]+='0';
    else if(v[i]>=10&&v[i]<=35)
      v[i]+=('A'-10);
  }
  for(i=m-1;i>=0;i--)
  printf("%c",v[i]);
  if(m==0)
   printf("0");
  return 0;    
}
int zhuan1(char xx){
	int x;

	switch(xx){
		case '0':x=0;break;
		case '1':x=1;break;
		case '2':x=2;break;
		case '3':x=3;break;
		case '4':x=4;break;
		case '5':x=5;break;
		case '6':x=6;break;
		case '7':x=7;break;
		case '8':x=8;break;
		case '9':x=9;break;
		case 'a':x=10;break;
        case 'b':x=11;break;
		case 'c':x=12;break;
		case 'd':x=13;break;
		case 'e':x=14;break;
		case 'f':x=15;break;
		case 'g':x=16;break;
		case 'h':x=17;break;
		case 'i':x=18;break;
		case 'j':x=19;break;
		case 'k':x=20;break;
		case 'l':x=21;break;
		case 'm':x=22;break;
		case 'n':x=23;break;
		case 'o':x=24;break;
		case 'p':x=25;break;
		case 'q':x=26;break;
		case 'r':x=27;break;
		case 's':x=28;break;
		case 't':x=29;break;
		case 'u':x=30;break;
		case 'v':x=31;break;
		case 'w':x=32;break;
		case 'x':x=33;break;
		case 'y':x=34;break;
		case 'z':x=35;break;
        case 'A':x=10;break;
        case 'B':x=11;break;
		case 'C':x=12;break;
		case 'D':x=13;break;
		case 'E':x=14;break;
		case 'F':x=15;break;
		case 'G':x=16;break;
		case 'H':x=17;break;
		case 'I':x=18;break;
		case 'J':x=19;break;
		case 'K':x=20;break;
		case 'L':x=21;break;
		case 'M':x=22;break;
		case 'N':x=23;break;
		case 'O':x=24;break;
		case 'P':x=25;break;
		case 'Q':x=26;break;
		case 'R':x=27;break;
		case 'S':x=28;break;
		case 'T':x=29;break;
		case 'U':x=30;break;
		case 'V':x=31;break;
		case 'W':x=32;break;
		case 'X':x=33;break;
		case 'Y':x=34;break;
		case 'Z':x=35;break;
} 
	return x;
}
char zhuan2(int yy){
	char tt;
switch(yy){
        case 0:tt='0';break;
		case 1:tt='1';break;
		case 2:tt='2';break;
		case 3:tt='3';break;
		case 4:tt='4';break;
		case 5:tt='5';break;
		case 6:tt='6';break;
		case 7:tt='7';break;
		case 8:tt='8';break;
		case 9:tt='9';break;
        case 10:tt='A';break;
        case 11:tt='B';break;
		case 12:tt='C';break;
		case 13:tt='D';break;
		case 14:tt='E';break;
		case 15:tt='F';break;
		case 16:tt='G';break;
		case 17:tt='H';break;
		case 18:tt='I';break;
		case 19:tt='J';break;
		case 20:tt='K';break;
		case 21:tt='L';break;
		case 22:tt='M';break;
		case 23:tt='N';break;
		case 24:tt='O';break;
		case 25:tt='P';break;
		case 26:tt='Q';break;
		case 27:tt='R';break;
		case 28:tt='S';break;
		case 29:tt='T';break;
		case 30:tt='U';break;
		case 31:tt='V';break;
		case 32:tt='W';break;
		case 33:tt='X';break;
		case 34:tt='Y';break;
		case 35:tt='Z';break;
		}
return tt;
}
int main(int argc, char* argv[])
{
	int n,m,x,k,i,j,count,y=0;
	char str[10];
		
	char str1[100];
	
	scanf("%d",&n);
	scanf("%s",str);
	scanf("%d",&m);
	count=strlen(str);

	
	for(i=0;i<=count-1;i++){
	x=zhuan1(str[i]);
		y=y+(x*(int)pow(n,count-1-i));

	}
	if(y==0){
		printf("0");
	return 0;
	}
	
	int count1=0;
	for(k=0,j=0;y!=0;k++,j++){
		
	str1[j]=zhuan2(y%m);
		y=y/m;
		count1++;
	}
	for(j=count1-1;j>=0;j--){
		
	
		printf("%c",str1[j]);
	}

	return 0;
}
long trans1(char *s,int n)
{
	long ans=0;
	int i,j,len;
	len=strlen(s);
	for(i=0;i<len;i++)
	{
		if(s[i]>='0'&&s[i]<='9')
		{
			j=s[i]-'0';
			ans=ans+j*pow(n,len-i-1);
		}
		else if(s[i]>='a'&&s[i]<='z')
		{
			j=s[i]-'a'+10;
			ans=ans+j*pow(n,len-i-1);
		}
		else if(s[i]>='A'&&s[i]<='Z')
		{
			j=s[i]-'A'+10;
			ans=ans+j*pow(n,len-i-1);
		}
	}
	return ans;
}
void trans2(char *s,int n,long m)
{
	int i,r,len;
	for(i=0;m!=0;i++)
	{
		r=m%n;
		if(r>=10)
			s[i]=r-10+'A';
		else
			s[i]=r+'0';
		m=m/n;
	}
	s[i]='\0';
	len=strlen(s);
	for(i=len-1;i>=0;i--)
		putchar(s[i]);
}
void main()
{
	int n1,n2;
	long k;
	char s[5000],ans[5000];
	scanf("%d%s%d",&n1,s,&n2);
	if(s[0]=='0')
		printf("0");
	else
	{
		k=trans1(s,n1);
		trans2(ans,n2,k);
	}
}