semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
long f(int x[80],int p,int l)
{
 int i,sum=0;
 for(i=0;i<l;i++)
  sum=sum*p+x[i];
 return(sum);
}
void main()
{
 int a,b,y[80],i,len;
 long t;
 char x[80];
 scanf("%d%s%d",&a,x,&b);
 for(i=0;i<strlen(x);i++)
 {
  if(x[i]>='0'&&x[i]<='9')
   y[i]=x[i]-'0';
  else if(x[i]>='a'&&x[i]<='z')
   y[i]=x[i]-'a'+10;
  else if(x[i]>='A'&&x[i]<='Z')
   y[i]=x[i]-'A'+10;
 }
 t=f(y,a,strlen(x));
 if(t==0)
  printf("0");
 else
 {
  for(i=0;t!=0;i++)
  {
   y[i]=t%b;
   t=(t-y[i])/b;
  }
  len=i;
  for(i=0;i<len;i++)
  {
   if(y[i]>=0&&y[i]<=9)
    x[i]='0'+y[i];
   else if(y[i]>9)
    x[i]=y[i]-10+'A';
  }
  for(i=len-1;i>=0;i--)
   printf("%c",x[i]);
 }
}
int main()
{
  long int a,b,c,s,i,j,n,d[1000];
  char t[10000];
     scanf("%d%s%d",&a,&t,&b);
     s=0;c=1;
	 n=strlen(t);
	 for(i=n-1;i>=0;i--)
	 { if (t[i]>='a'&&t[i]<='z') s=s+c*(t[i]-87);
	 if (t[i]>='A'&&t[i]<='Z') s=s+c*(t[i]-55);
	 if (t[i]>='0'&&t[i]<='9') s=s+c*(t[i]-'0');
	 c=c*a;
	 }
	 i=0; 
	 	 if (s==0) printf("%d",s);
	 while(s!=0)
	 { if ((s%b)>9) d[i]=s%b+55;
	   else d[i]=s%b;
	 i++;
	 s=s/b;
	 }
	for (j=i-1;j>=0;j--)
	{ if (d[j]>=0&&d[j]<=9) printf("%d",d[j]);
	  if  (d[j]>=65&&d[j]<=90) printf("%c",d[j]);
	}
}
int turntonum (char c)
{
    if (c>='0'&&c<='9')
        return (c-'0');
    if (c>='a'&&c<='z')
        return (c-'a'+10);
    if (c>='A'&&c<='Z')
        return (c-'A'+10);
} 
int main ()
{
    int a,b,l;
    char c[100];
    long long num;
    cin >>a;getchar();
    cin.getline(c,80,' ');
    cin >>b;
    l=strlen(c);
    num=turntonum(c[0]);
    for (int i=1;i<l;i++)
    {
        int f;
        num=num*a+turntonum(c[i]);
    }
    if (num==0)
    {
        cout <<"0";
        return 0;
    }
    int d[100],l_;
    l_=log(num)/log(b)+1;
    for (int i=l_-1;i>=0;i--)
    {
        d[i]=num%b;
        num=num/b;
    }
    for (int i=0;i<l_;i++)
    {
        if (d[i]<10)
            cout <<d[i];
        else
            putchar('A'+d[i]-10);
    }
    return 0;
}
main()
{
      int a,b,i,c,d,x[2000],s=0,e,l,k;
      char s1[1000],s2[1000],y[2000];
      scanf("%d %s %d",&a,s1,&b);
      for(i=0;;i++)
       {
                   if(s1[i]=='\0')
                   {
                                  s2[i]='\0';
                                  break;
                   }
                   if(s1[i]>='a'&&s1[i]<='z')
                   {
                                  s1[i]=s1[i]-'a'+'A';
                   }
                   s2[i]=s1[i];
       }
      for(c=0;c<=i-1;c++)
      {
                   if(s2[c]>='A'&&s2[c]<='Z')
                   x[c]=s2[c]-55;
                   else
                   x[c]=s2[c]-48;    
      }
      for(d=i-1;d>=0;d--)
      {
                       e=i-1-d;
                       if(e!=0)
                       {do
                       {
                                     x[d]=x[d]*a;
                                     e--;
                       }
                       while(e>0);}
                       if(e==0)
                       x[d]=x[d];
                       s=s+x[d];
}
      if(s!=0)
      {
      for(l=0;s!=0;l++)
      {
                       if(s%b<=9)
                y[l]=s%b+'0'; 
                else
                y[l]=s%b+'7';
                  s=s/b;
      }
      for(k=l-1;k>=0;k--)
      printf("%c",y[k]);
      }
      else
      printf("0");
}
int main()
{
double a;int b;
char c[1000];
cin>>a;
cin>>c;
cin>>b;
int num=0,len,i;
int remain;
double x[1000];
len=strlen(c);
char m[1000];
int o[1000];

for(i=0;i<len;i++)
{
	if(c[i]>='a'&&c[i]<='z')
		x[i]=c[i]-'a'+10;
	if(c[i]<='Z'&&c[i]>='A')
		x[i]=c[i]-'A'+10;
	if(c[i]>='0'&&c[i]<='9')
		x[i]=c[i]-'0';
}
for(i=0;i<len;i++)                        
{	num+=x[i]*pow(a,len-1-i);}
remain=num;


int p=0;
do
{
	o[p]=remain%b;
	remain=(remain-o[p])/b;
	p++;
}
while(remain>0);

for(i=0;i<p;i++)
{
	if(o[i]>=10)
		m[i]=o[i]-10+'A';
	else
		m[i]=o[i]+'0';
}
for(i=p-1;i>=0;i--)
	cout<<m[i];
return 0;

}
//*****************
//??????? 
//?????
//???2011-11-16
//*****************
char function(int);         //????
int main()
{
	int a, b, k = 0, sum = 0, t, i = 0, count = 0;
	int sum1 = 1;
	char n[100000], c[100000];
	cin >> a >> n >> b;
	for(i = 0;n[i] != '\0';i++)          //??n????
		k++;
	for(i = k - 1;i >= 0;i--)
	{
		if(n[i] - '0' <= 9)           //????n???10???
			sum = sum + (n[i] - '0') * sum1;
		if(n[i] - '0' > 9 && n[i] - '0' <= 42)
			sum = sum +(n[i] - '0' - 7) * sum1;
		if(n[i] - '0' > 42 && n[i] - '0' <= 74)
			sum = sum + (n[i] - '0' - 39) * sum1;
		sum1 = sum1 * a;
	}
	for(i = 0;;i++)           
	{
		
		t = sum % b;             //???
		sum = sum / b;
		c[i] = function(t);
	    count++;              //?????????
		if(sum == 0)
			break;
	}
	for(i = count - 1;i >= 0;i--)
		cout << c[i];           //??????
	return 0;
}
char function(int t)               //??????????????
{
	char a[37] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return a[t];
}
void main()
{
    int i,j,k,t,l;
    long sum=0;
    int a,b;
    char c[100];

    scanf("%d%s%d",&a,c,&b);
    
    for(i=0;i<strlen(c);i++)
    {
                            if(c[i]>='0'&&c[i]<='9')
                            c[i]-=47;
                            else if(c[i]>='a'&&c[i]<='z')
                            c[i]=c[i]-'a'+11;
                            else if(c[i]>='A'&&c[i]<='Z')
                            c[i]=c[i]-'A'+11;
                            }
    for(k=0;k<strlen(c);k++)
    {
                            sum=sum*a+(c[k]-1);
//                            printf("%d",sum);
                            }
    for(j=0;sum>0;j++)
    {
                 c[j]=sum%b;
                 sum=sum/b;
                 }
    for(t=0;t<j;t++)
    {
                            if(c[t]>=0&&c[t]<=9)
                            c[t]+=48;
                            else if(c[t]>=10&&c[t]<=36)
                            c[t]=c[t]+'A'-10;
                    }
    if(j!=0)
	  for(l=j-1;l>=0;l--)
	  {
                       printf("%c",c[l]);
                       }
	  else
		  printf("0");
    printf("\n");
    }
void main()
{
	int a,b,i,t;
	long n=0;
	char s[100];
	scanf("%d%s%d",&a,s,&b);
	t=strlen(s)-1;
	for(i=0;i<=t;i++)
		if(s[i]>='0'&&s[i]<='9')
			s[i]=s[i]-'0';
		else if(s[i]>='A'&&s[i]<='Z')
			s[i]=s[i]-'A'+10;
		else if(s[i]>='a'&&s[i]<='z')
			s[i]=s[i]-'a'+10;
		for(i=0;i<=t;i++)
			n=n*a+s[i];
		i=0;
		do
		{
			if(n%b>=10)
				s[i]=n%b+'A'-10;
			else s[i]=n%b+'0';
			n=(n-n%b)/b;
			i++;
		}while(n>0);
		for(i--;i>=0;i--)
			printf("%c",s[i]);
}
unsigned long pow(unsigned long a,unsigned long b)
{
    unsigned long temp,sout=1;
    for(temp=1;temp<=b;temp++)
    sout=sout*a;
    return sout;
}
    
main()
{
      unsigned long ip,op,i,lenth,oplenth,cache,test=9999,mod;
      unsigned long dec=0;
      char num[100],wei;
      scanf("%d",&ip);
      scanf("%s",num);
      scanf("%d",&op);
      //printf("%d %s %d\n",ip,num,op);
      lenth=strlen(num);
      for(i=0;i<=lenth;i++)
      {
                          if(num[i]>='a'&&num[i]<='z')
                          num[i]=num[i]-'a'+'A';
      }
      //printf("%s\n",num);
      for(i=0;i<lenth;i++)
      {
                          if(num[i]>='0'&&num[i]<='9')
                          dec=dec+((unsigned long)num[i]-(unsigned long)'0')*pow(ip,lenth-i-1);
                          else
                          dec=dec+(10+(unsigned long)num[i]-(unsigned long)'A')*pow(ip,lenth-i-1);
      }
      for(oplenth=1;test>=op;oplenth++)
      test=dec/pow(op,oplenth-1);
      oplenth--;
      mod=dec;
      //printf("%d\n",dec);
      for(i=0;i<oplenth;i++)
      {
                             cache=mod/pow(op,oplenth-i-1);
                             mod=mod-cache*pow(op,oplenth-i-1);
                             //printf("     %d %d\n",cache,mod);
                             if(cache<=9)
                             printf("%d",cache);
                             else
                             {
                                 wei='A'+cache-10;
                                 printf("%c",wei);
                             }
      }
      getchar();
      getchar();
      return 0;
}
void main()
{
	int a,b,i,j=0,x=0,y,z=1;
	scanf("%d",&a);
	char a_shu[65],b_shu[65];
	while(1)
	{
		if((y=getchar())!=' ')
			a_shu[j++]=y;
		else
			if(j>0)
			{
				a_shu[j]='\0';
				break;
			}
	}
	for(i=0;a_shu[i]!='\0';i++)
	{
		if(a_shu[i]<='z'&&a_shu[i]>='a')
			a_shu[i]-='a'-10;
		else
			if(a_shu[i]<='Z'&&a_shu[i]>='A')
	    		a_shu[i]-='A'-10;
			else
				a_shu[i]-=48;
	}
	scanf("%d",&b);
	for(i--;i>=0;i--)
	{
		x+=a_shu[i]*z;
		z=z*a;
	}
	for(i=0;x>=b;i++)
	{
		b_shu[i]=x%b;
		x=x/b;
		if(b_shu[i]>=10)
			b_shu[i]+='A'-10;
	}
	if(x>=10)
	{
		x+='A'-10;
	    printf("%c",x);
	}
	else
		printf("%d",x);
	for(i--;i>=0;i--)
		if(b_shu[i]>=10)
			printf("%c",b_shu[i]);
		else
			printf("%d",b_shu[i]);
}
int change(char m);
char trans(int n);
int main()
{
	char f[10000];
	int g[10000];
	int a,b,i,len,s=0,t=0;
	scanf("%d %s %d",&a,f,&b);
	len=strlen(f);
	for(i=0;i<len;i++)
	{
		s=change(f[i])+s*a;
	}
	while(s/b)
	{
		g[t]=s%b;
		s/=b;
		t++;
	}
	g[t]=s%b;
	for(i=t;i>=0;i--)
	{
		printf("%c",trans(g[i]));
	}
	return 0;
}
int change(char m)
{
		int result;
		if((m-'0'>=0)&&(m-'0'<10))
		{
			result=m-'0';
		}
		else if((m-'a'>=0)&&(m-'a'<26))
		{
			result=m-'a'+10;
		}
		else if((m-'A'>=0)&&(m-'A'<26))
		{
			result=m-'A'+10;
		}
		return result;
}
char trans(int n)
{
	char last;
	if(n>=0||n<10)
	{
		last='0'+n;
	}
	if(n>9)
	{
		last='A'+n-10;
	}
	return last;
}
long int cifang(int x, int y)
{
	long int z;
	int i;
	z = 1;
	for(i=0; i<y; i++)
	{
		z = z*x;
	}
	return(z);
}

void main()
{
	int a, b, t, i, mod[50]={0};
	char n[10];
	long int ten;

	scanf("%ld", &a);
	scanf("%s", n);
	scanf("%ld", &b);

	//?a????????
	t = 0;
	ten = 0;
	for(i=0; n[i]!='\0'; i++)
	{
		t++;
	}
	for(i=0; i<t; i++)
	{
		if(n[i]>=48 && n[i]<=57)
		{
			ten = ten + (n[i]-48) * cifang(a, t-i-1);
		}
		else if(n[i]>=65 && n[i]<=90)
		{
			ten = ten + (n[i]-55) * cifang(a, t-i-1);
		}
		else if(n[i]>=97 && n[i]<=122)
		{
			ten = ten + (n[i]-87) * cifang(a, t-i-1);
		}
	}
	//???????b??
	t = 0;
	for(i=0; ; i++)
	{
		t++;
		mod[i] = ten%b;
		ten = (ten-mod[i])/b;
		if(ten==0)
			break;
		else
			continue;
	}

	//??
	for(i=t-1; i>=0; i--)
	{
		if(mod[i]<=9)
			printf("%d", mod[i]);
		else if(mod[i]>9)
			printf("%c", mod[i]+55);
	}
}
int main()
{
	int a,b;
	long  ans = 0;
	char x[20] = {0};
	scanf("%d %s %d",&a,x,&b);
	if(a == b) printf("%s\n",x);
	//printf("%d %s %d\n",a,x,b);
	else{
		long flag = 1;
		for(int i = strlen(x) - 1;i >= 0;i --){
			long temp;
			if(x[i] >= '0' && x[i] <= '9') temp = x[i] - '0';
			if(x[i] >= 'A' && x[i] <= 'Z') temp = x[i] - 'A' + 10;
			if(x[i] >= 'a' && x[i] <= 'z') temp = x[i] - 'a' + 10;
			ans += temp * flag;
		//	printf("%lld\n",ans);
			flag *= a;
		}
		if(ans == 0) printf("0\n");
		else{
		//	printf("%lld\n",ans);
			long final[100] = {0};
			flag = 0;
			while(ans > 0){
				flag ++;
				final[flag] = ans % b;
				ans /= b;
			}
			for(int i = flag;i >= 1;i --){
				if(final[i] >= 10){
					printf("%c",final[i] - 10 + 'A');
				}
				else printf("%ld",final[i]);
			}
			printf("\n");
		}
	}
	return 0;
}
// ????.cpp : Defines the entry point for the console application.
// ?????????
int main()
{
char a[100],b[100];
int p=0,q=0,m,n;
cin>>m>>a>>n;
for(int i=0;i<strlen(a);i++)
{
if(a[i]>='a')
a[i]=a[i]-'a'+10;
else if(a[i]>='A')
a[i]=a[i]-'A'+10;
else
a[i]=a[i]-'0';
p=p*m+a[i];
}
while(p>0)
{
b[q]=p%n;
if(b[q]>=10)
b[q]=b[q]-10+'A';
else
b[q]=b[q]+'0';
p=p/n;
q++;
}
for(int i=q-1;i>=0;i--)
cout<<b[i];
if (q==0) cout<<0;
cout<<endl;
return 0;
}
void main()
{long int num=0;
char s[50],t[50];
int a,b,i,x=0,j;
scanf("%d",&a);
scanf("%s",s);
scanf("%d",&b);
for(i=0;s[i]!='\0';i++)
{if(s[i]>='a'&&s[i]<='z')s[i]=s[i]-'a'+10;
else if(s[i]>='A'&&s[i]<='Z')s[i]=s[i]-'A'+10;
else if(s[i]>='0'&&s[i]<='9')s[i]=s[i]-'0';}
for(i=0;s[i]!='\0';i++)
num=num*a+s[i];
for(i=49;i>=0;i--)
{t[i]=num%b;
num=num/b;}
i=0;
while(x==0)
{if(t[i]==0)i++;
else x++;
if (i==50){printf("0");x++;}}
for(j=i;j<=49;j++)
{if(t[j]>=10&&t[j]<=35)
t[j]=t[j]+'A'-10;
else t[j]=t[j]+'0';
printf("%c",t[j]);}

}
void main()
{
	char n[35]={'0'},y[35]={'0'};
	unsigned long r,x1,x=1;
	int i,a,b,x2=0,y1,p,q,xm=0,k;
	scanf("%d%s%d",&a,n,&b);
    unsigned long m=0;
	p=strlen(n);
	r=pow(a,p-1);

	for(i=0;i<p;i++)
	{
	
		if(n[i]>47&&n[i]<58)
		{
			q=n[i]-48;
			m=m+q*r;
		
		}
		else
		{
			if(n[i]>64&&n[i]<91)
			{
				q=n[i]-55;
				m=m+q*r;
				
			}
			else if(n[i]>96&&n[i]<123)
				{
						q=n[i]-87;
				m=m+q*r;
			
				}
		}
		r=r/a;
	}

	while((m/b)>x)
	{
		x=b*x;
		xm=xm+1;
	}

	y1=0;

	for(i=xm;i>=0;i--)
	{
		
		k=m%b;
		if(k<10)
		y[i]=k+48;
		else y[i]=k+55;
		m=(m-k)/b;
	
	
	}
	printf("%s",y);
}
void main()
{int t=0;
char c[100],d[100];
 int a,b,i,j,k;
 scanf("%d",&a);
 scanf("%s",c);
 scanf("%d",&b);
 for(i=0;c[i]!='\0';i++)
  {if(c[i]>'9')
      {if(c[i]>='a'&&c[i]<='z')
        k=c[i]-'a'+10;
       else k=c[i]-'A'+10;
      }
    else k=c[i]-'0';
   t=a*t+k;}
 if(t==0) printf("0");
 else{
  for(i=0;t!=0;i++)
  {if(t%b>9)
    d[i]=t%b-10+'A';
   else
    d[i]=t%b+'0';
   t=t/b;
  }
 for(j=i-1;j>=0;j--)
	 printf("%c",d[j]);}
}
int f(int a,int n){
	if(n==0) return 1;
	else if(n==1) return a;
	else return(a*f(a,n-1));
}
	char n[100],m[100];
int main(){
	int a,b,num=0;
	cin>>a>>n>>b; 
	for(int i = 0;i < (int)strlen(n);i ++){
		if(islower(n[i])) num+=((int)n[i]-87)*f(a,(int)strlen(n)-i-1);
		else if(isupper(n[i])) num+=((int)n[i]-55)*f(a,(int)strlen(n)-i-1);
		else if(isdigit(n[i])) num+=((int)n[i]-48)*f(a,(int)strlen(n)-i-1);
	}if (num == 0) {puts("0"); return 0;}
	int i=0;
	while(num>0){
		if(num%b>9) {
			m[i]=(char)(num%b+55);num=num/b;
		}
		else if(num%b==0) {
			m[i]='0';num=num/b;
		}
		else {
			m[i]=(char)(num%b+48);num=num/b;
		}
		i++;
	}
	for (int j = 1; j <= i; j++) cout <<m[i - j];
	return 0;
}
//551-????
int main()
{
	int a,b,i,j,t,m,n,s,temp=0;
	char p[20]="\0",q[20]="\0";//p[20]??????????q[20]?????????
	scanf("%d",&a);//???????
	getchar();//??????????????
	for(i=0;i<20;i++)//???????????????????????
	{
		scanf("%c",&p[i]);
		if(p[i]==' ')
			break;
	}
	scanf("%d",&b);//???????
	for(j=0;j<i;j++)
	{
		if(p[j]>=48&&p[j]<=57)
			t=p[j]-48;
		else if(p[j]>=65&&p[j]<=90)
			t=p[j]-55;
		else if(p[j]>=97&&p[j]<=122)
			t=p[j]-87;
		if(j==i-1)
			temp+=t;
		else
		{
			for(m=1;m<i-j;m++)
				t=t*a;
			temp+=t;
		}
	}
	s=0;
	if(temp>b)
	{
		for(s=0;s<20;s++)
		{
			n=temp%b;
			if(n<=9)
				q[s]=n+48;
			else
				q[s]=n+55;
			temp=temp/b;
			if(temp==0)
				break;
		}
		for(j=s;j>=0;j--)
			printf("%c",q[j]);
		printf("\n");
	}
	else
		printf("%d",temp);
	return 0;
}
int main(){
	int a,b,i,zhen,chu,result;
	long x=0;
	char n[32],m[32];
	scanf("%d%s%d",&a,n,&b);
	result=strlen(n);
	 
	for(i=0;i<result;i++){
		switch(n[i]){
		case '0':zhen=0;break;
		case '1':zhen=1;break;
		case '2':zhen=2;break;
        case '3':zhen=3;break;
		case '4':zhen=4;break;
		case '5':zhen=5;break;
		case '6':zhen=6;break;
		case '7':zhen=7;break;
		case '8':zhen=8;break;
		case '9':zhen=9;break;
		case 'a':
        case 'A':zhen=10;
		    break;
		case 'b':
		case 'B':zhen=11;
			break;
		case 'c':
		case 'C':zhen=12;
			break;
		case 'd':
		case 'D':zhen=13;
			break;
		case 'e':
		case 'E':zhen=14;
			break;
		case 'f':
        case 'F':zhen=15;
			break;
		case 'g':
		case 'G':zhen=16;
			break;
		case 'h':
		case 'H':zhen=17;
			break;
		case 'i':
		case 'I':zhen=18;
			break;
		case 'j':
		case 'J':zhen=19;
			break;
		case 'k':
		case 'K':zhen=20;
			break;
		case 'l':
		case 'L':zhen=21;
			break;
		case 'm':
		case 'M':zhen=22;
			break;
		case 'n':
		case 'N':zhen=23;
			break;
		case 'o':
		case 'O':zhen=24;
			break;
		case 'p':
		case 'P':zhen=25;
			break;
		case 'q':
		case 'Q':zhen=26;
			break;
		case 'r':
		case 'R':zhen=27;
			break;
		case 's':
		case 'S':zhen=28;
			break;
		case 't':
		case 'T':zhen=29;
			break;
		case 'u':
		case 'U':zhen=30;
			break;
		case 'v':
		case 'V':zhen=31;
			break;
		case 'w':
		case 'W':zhen=32;
			break;
		case 'x':
		case 'X':zhen=33;
			break;
		case 'y':
		case 'Y':zhen=34;
			break;
		case 'z':
		case 'Z':zhen=35;
			break;

		}
		x+=zhen*pow(a,result-1-i);
	}
	for(i=0;x>0;i++){
		chu=x%b;
		x=x/b;
		switch(chu){
        case 0:m[i]='0';break;
		case 1:m[i]='1';break;
        case 2:m[i]='2';break;
		case 3:m[i]='3';break;
        case 4:m[i]='4';break;
		case 5:m[i]='5';break;
		case 6:m[i]='6';break;
		case 7:m[i]='7';break;
		case 8:m[i]='8';break;
		case 9:m[i]='9';break;
		case 10:m[i]='A';break;
		case 11:m[i]='B';break;
		case 12:m[i]='C';break;
		case 13:m[i]='D';break;
		case 14:m[i]='E';break;
		case 15:m[i]='F';break;
		case 16:m[i]='G';break;
		case 17:m[i]='H';break;
		case 18:m[i]='I';break;
		case 19:m[i]='J';break;
		case 20:m[i]='K';break;
		case 21:m[i]='L';break;
		case 22:m[i]='M';break;
		case 23:m[i]='N';break;
		case 24:m[i]='O';break;
		case 25:m[i]='P';break;
		case 26:m[i]='Q';break;
		case 27:m[i]='R';break;
		case 28:m[i]='S';break;
		case 29:m[i]='T';break;
		case 30:m[i]='U';break;
		case 31:m[i]='V';break;
		case 32:m[i]='W';break;
		case 33:m[i]='X';break;
		case 34:m[i]='Y';break;
		case 35:m[i]='Z';break;
		}
	}
	i=i-1;
	for(;i>=0;i--){
		printf("%c",m[i]);
	}
	printf("\n");
	return 0;
}
int main()
{
    int a,b,s=0;
    int i,c,j,k,o;
    int number2[40];
    char number[40],number1[40],number3[40];
    scanf("%d",&a);
    scanf("%s",number);
    scanf("%d",&b);

    
     int q1,p1;
     p1=strlen(number);
     for(q1=0;number[q1]!='\0';q1++)
     number1[p1-q1-1]=number[q1];
     number1[p1]='\0';
     

    
    for(i=0;number1[i]!='\0';i++)
    {
       if(number1[i]>=97)
       c=number1[i]-87;
       else
       {
            if(number1[i]>=65)
            c=number1[i]-55;
            else
            c=number1[i]-48;
       }
       o=1;
       for(int l=1;l<=i;l++)
       {
       
       o=o*a;
       }
       s=o*c+s;
    }
    
    if(s==0)
    puts("0");
    else
    {
    
    for(j=0;s!=0;j++)
    {
                   
       number2[j]=s%b;
        s=s/b;    
        }

     int q2,p2;
     p2=j;
     for(q2=0;q2<p2;q2++)
     {
     if(number2[q2]>9)
     number2[q2]=number2[q2]+55;
     else
      number2[q2]=number2[q2]+48;
     number3[p2-q2-1]=number2[q2];
     }
     number3[p2]='\0';
     
    puts(number3);
    
     }
    
    getchar(); 
    getchar();
    getchar();
    getchar();
    return 0;
}
char x[N];
int Rtoten(int R,char shu[]){
    int i,s=0;
    int m=strlen(shu);
    for(i=0;i<m;i++){
        if(shu[i]>='A' && shu[i]<='Z' || shu[i]>='a'&&shu[i]<='z')
            (shu[i]|=0x20)-=0x57;

        if(shu[i]>='0'&&shu[i]<='9')
            shu[i]=shu[i]-'0';
    }
    for(i=0;i<m;i++){
        s=s*R+shu[i];
    }
    return s;
}
void shiR(int c,int R){
    int i,m,temp;
    for(i=0;c;i++){
        if((x[i]=c%R+'0')>'9') x[i]+=7;
        c=c/R;
    }
    x[i]='\0';

    m=strlen(x);
    for(i=0;i<m/2;i++){
        temp=x[i];
        x[i]=x[m-i-1];
        x[m-i-1]=temp;
    }
}
int main(void){
    int a,b,i,c;
    int count=0;
    char shu[N];
    cin>>a;
    cin>>shu;
    cin>>b;
    for (i=0;i<strlen(shu);i++)
    {
    	if (shu[i]=='0')
    		count++;
    }
    if (count==strlen(shu))
    	cout<<"0"<<endl;
    else{
    c=Rtoten(a,shu);
    shiR(c,b);
    int m=strlen(x);
    for(i=0;i<m;i++)
    { cout<<x[i];}

  cout<<endl;}

  return 0;
}
long toDex(int a,char n[]);
int toB(long Dn,int b,char answer[]);

main()
{
	int a,b,len,i;
	char n[50]={"0"},answer[50]={"0"};	
	long Dn;				

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

	for (i=0;i<=strlen(n)-1;i++)		
		n[i]=toupper(n[i]);		
	Dn=toDex(a,n);				
	len=toB(Dn,b,answer);			

	for (i=len-1;i>=0;i--)
		printf("%c",answer[i]);	
	
}

long toDex(int a,char n[])
{
	int i,j;
	long Dn=0,sqr;	

	for (i=0;i<strlen(n);i++)
	{
		sqr=1;			
		for (j=0;j<strlen(n)-i-1;j++)
			sqr*=a;			
		if ((int)(n[i])>=65) Dn+=sqr*((int)(n[i])-55);
		else Dn+=sqr*((int)(n[i])-48);			
	}

	return Dn;
}

int toB(long Dn,int b,char answer[])
{
	long shang=Dn;						
	int i=0,yu;			

	do										
	{	
		yu=shang%b;							
		(yu>=10)?(answer[i]=(char)(yu)+55):(answer[i]=(char)(yu)+48);	
		i++;								
		shang=shang/b;							
	}while (shang!=0);							

	return i;
}
main ()
{
     int i,j,x,y=0,z,a,b,q;
     char c[40];
     scanf ("%d %s %d",&a,c,&b);
     i=strlen (c);
     if (c[0]=='0')
     printf ("0\n");
     else 
     {
          for (j=0;j<i;j++)
                  {
                     if (c[j]>='A'&&c[j]<='Z')
                         x=c[j]-'A'+10;
                     else 
                      {
                       if (c[j]>='a'&&c[j]<='z')
                          x=c[j]-'a'+10;
                       else 
                          x=c[j]-'0';
                       }
                           y=y*a+x;
                  }
             
          char k[40];
          for (i=0,q=y;q!=0;i++)
          {
              k[i]=q%b;
              q=q/b;
          }
             k[i]='0';
             char h[i];
             for (j=0;j<i;j++)
                {
                    if (k[j]>9)
                         h[i-j-1]=k[j]+'A'-10;
                    else 
                         h[i-j-1]=k[j]+'0';
                    }
              for (j=0;j<i;j++)
              printf ("%c",h[j]);       
              
}
    getchar ();
    getchar ();         
}
int main()
{	
	char n[100],t[100];
	int a,b,s[100],i,j,m;
	long num=0;
	scanf("%d%s%d",&a,n,&b);
	m=strlen(n);
	for(i=0;i<m;i++)
		if(n[i]>='0'&&n[i]<='9')
			num=num*a+n[i]-'0';
		else if(n[i]>='a'&&n[i]<='z')
			num=num*a+n[i]-'a'+10;
		else if(n[i]>='A'&&n[i]<='Z')
			num=num*a+n[i]-'A'+10;
	for(i=0;num>=b;i++)
	{
		s[i]=num%b;
		num=num/b;
	}s[i]=num%b;
	j=i;
	for(i=0;i<=j;i++)
	{
		if(s[i]>=10)
			t[i]=s[i]-10+'A';
		else 
			t[i]=s[i]+'0';
	}
	for(i=j;i>=0;i--)
	printf("%c",t[i]);
	printf("\n");


	return 0;
}
int main(int argc, const char *argv[]) {
	int a, b, i, s2[100] =  {
		0
	}
	, s1[100] =  {
		0
	}
	, Sum = 0;
	char str1[100], str2[100];
	cin >> a >> str1 >> b;
	int len1 = strlen(str1);
	for (i = 0; i < len1; i++) {
		//a????????
		if (str1[i] <= 57) {
			//?????????
			s1[i] = str1[i] - '0';
		}
		if (str1[i] >= 65 && str1[i] <= 90) {
			s1[i] = str1[i] - 'A' + 10;
		}
		if (str1[i] > 90) {
			s1[i] = str1[i] - 'a' + 10;
		}
		s2[i] = s1[i] *pow((double)a, len1 - i - 1);
		Sum += s2[i];
	}
	if(Sum == 0) {
		cout << '0';
		return 0;
	}
	for (i = 0; Sum > 0; i++) {
		//??????b??
		if (Sum % b < 10) {
			str2[i] = Sum % b + '0';
		} else {
			str2[i] = Sum % b - 10+'A';
		}
		Sum -= Sum % b;
		Sum /= b;
	}
	str2[i] = '\0';
	int len2 = strlen(str2);
	for (i = len2 - 1; i >= 0; i--) {
		cout << str2[i];
	}
	return 0;
}
int main()//?????
{
	char n[32],t[32];
	double a,b;
	int i,m[32],c[32],d[32],size,k;
	long n10=0;//????
	cin>>a>>n>>b;//??a,n,b
	size=strlen(n);//??n???
	for(i=0;i<size;i++)
		if(toascii(n[i])>=48&&toascii(n[i])<=57)
			m[i]=toascii(n[i])-48;
		else if(toascii(n[i])>=65&&toascii(n[i])<=90)
			m[i]=toascii(n[i])-55;
		else if(toascii(n[i])>=97&&toascii(n[i])<=122)
			m[i]=toascii(n[i])-87;//?n10??????????
		for(i=0;i<size;i++)
		n10=n10+m[i]*pow(a,size-i-1);//??n10????long???
		if(n10==0)
			cout<<"0";//?n10=0?????0
		else
			 {
				 for(i=0;i<32;i++)
		       if(pow(b,i)>n10)
		         {
			       k=i;
		 	       break;
		         }//??n10?b?????k?
		    c[0]=n10/pow(b,k-1);//???????1?c[0]
			for(i=1;i<k;i++)
				{
					n10=n10-c[i-1]*pow(b,k-i);
			        c[i]=n10/(pow(b,k-1-i));
			    }//???????2??k?c[1]?c[k-1]
			for(i=0;i<k;i++)
					if(c[i]<10) d[i]=c[i]+48;
					else if (c[i]>=10) d[i]=c[i]+55;//?c[i]????????ascii?
					for(i=0;i<k;i++)
						t[i]=d[i];//t[i]?????
					t[k]='\0';//t[k]???
					cout<<t;//??b???t
		}
	return 0;
}//?????
void main()
{
	int a,b,l1,i,j=0,t,m=0,n;
	char str1[100],str2[100];
	scanf("%d%s%d",&a,str1,&b);
	l1=strlen(str1);
	if(str1[0]=='0')
		printf("0");
    for(i=0;i<l1;i++)
	{if(str1[i]<='z'&&str1[i]>='a')
	t=str1[i]-'a'+10;
	else if(str1[i]<='Z'&&str1[i]>='A')
		t=str1[i]-'A'+10;
	else
		t=str1[i]-'0';
	m=m*a+t;
	}
	while(m!=0)
	{
		n=m%b;
		m=m/b;
		if(n>=10)
			str2[j]=n-10+'A';
			else str2[j]=n+'0';
		j++;
	}
	for(i=0;i<j;i++)
		str1[i]=str2[j-i-1];
	str1[j]='\0';
	printf("%s",str1);

}