semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main ()
{
    int m,n;
    int num,tot;
    int i,j,k1,k2;
    int a,b;
    char c;
    num=tot=0;
    m=n=0;
    a=b=0;
    char s[300];
    char s1[300];
    int s2[300];
    cin >>a;
    gets(s);
    k1=strlen(s);
    k2=k1;
    while (s[k1]!=' ') k1--;
    k1--;
    j=1;
    for (i=k1;i>=1;i--)
    {
        if (isdigit(s[i]))
        {
            num=(int)s[i];
            num=num-48;
            tot=tot+j*num;
        }
        if (islower(s[i]))
        {
            num=(int)s[i];
            num=num-97+10;
            tot=tot+j*num;
        }
        if (isupper(s[i]))
        {
            num=(int)s[i];
            num=num-65+10;
            tot=tot+j*num;
        }
        j=j*a;
   }
   j=1;

   for (i=k2-1;i>=k1+2;i--)
   {
      num=(int)s[i];
      num=num-48;
      b=b+j*num;
      j=j*10;

   }
   m=0;
   if (tot==0) cout <<0 <<endl;
   while (tot>0)
   {
        m++;
        s2[m]=tot%b;
        tot=tot/b;
   }
   if (b<=10)
   {
       for (i=1;i<=m;i++)
       cout <<s2[m-i+1];
   }
   else
   {
       for (i=1;i<=m;i++)
          if (s2[m-i+1]<=9) cout <<s2[m-i+1];
          else
          {
              n=s2[m-i+1]+65-10;
              cout <<(char)n;
          }

   }
   cout <<endl;

    return 0;
}
int huan(char k);
char huan2(int k);

int main()
{
	int a,b;
	char *ps,*result;
	int *tmp;
	ps = (char*) malloc (sizeof(long)*8);
	tmp = (int*) malloc (sizeof(long)*8);
	result = (char*) malloc (sizeof(long)*8);
	scanf("%d",&a);
	scanf("%s",ps);
	scanf("%d",&b);
	int k = strlen(ps);
	int i;
	long tmp2 = 0;
	for(i = 0;ps[i] != '\0';i++)
	{
		tmp[i] = huan(ps[i]);
		tmp2 += (long) (tmp[i] * pow(a,k-1-i));
        //printf("t%ld\n",(long) (tmp[i] * pow(a,k-1-i)));
	}
	//printf("t%ld\n",tmp2);
	int l = i - 1;
	int *tmp3 = (int*) malloc (sizeof(long)*8);
	for(l = 0 ; tmp2 != 0; l++)
	{
		tmp3[l] = tmp2 % b;
		//printf("t3 %d l%d\n",tmp3[l],l);
		tmp2 = tmp2 / b;
		//printf("l%d\n",l);
	}
	//printf("l%d\n",l);
	int m;
	l--;
	for (m = 0;l >= 0;l--,m++)
	{
		result[m] = huan2(tmp3[l]);
		//printf("r%c l%d\n",result[m],l);
	}
	result[m] = '\0';
	printf("%s",result);
	printf("\n");
         free(ps);
         free(tmp);
         free(result);
	return 0;
}

int huan(char k)
{
	if ( k <= 57)
	{
		return k-48;
	}
	else if ( k >=97 && k <= 122)
	{
		return k - 87;
	}
	else if ( k >= 65 && k <= 90)
	{
		return k - 55;
	}
	return 0;
}

char huan2(int k)
{
	if ( k <= 9 )
	{
		return k + 48;
	}
	if ( k >= 10 )
	{
		return k + 55;
	}
	return 0;
}
main()
{
	int a,b;
	char n[100];
	scanf("%d",&a);
	scanf("%s",n);
	scanf("%d",&b);
	long c=0,x;

	int i,j,k,l=strlen(n);
	for(i=0;i<l;i++)
	{
		if(n[i]>='A'&&n[i]<='Z')
			x=n[i]-'A'+10;
		else if(n[i]>='a'&&n[i]<='z')
			x=n[i]-'a'+10;
		else
			x=n[i]-'0';
		for(j=1;j<=l-i-1;j++)
			x=a*x;
		c+=x;
	}
	int m[100]={-1};
	for(j=0;;j++)
	{
		m[j]=c%b;
		c=c/b;
		if(c==0)
			break;
	}
	for(k=j;k>=0;k--)
	{
		if(m[k]>=10)
		{
			char y;
			y='A'+m[k]-10;
			printf("%c",y);
		}
		else
		     printf("%d",m[k]);
	}
	


}
void main()
{
	int a,b,i,t=1,w;
	char n[32],k[32]={0};
	long m=0;
	scanf("%d",&a);
	scanf("%s",n);
	scanf("%d",&b);
	for(i=strlen(n);i>=0;i--)
	{
		if((n[i]>='0')&&(n[i]<='9'))
		{
			m=m+(n[i]-'0')*t;
			t=t*a;
		}
		else if((n[i]>='a')&&(n[i]<='z'))
		{
			m=m+(n[i]-'a'+10)*t;
			t=t*a;
		}
		else if((n[i]>='A')&&(n[i]<='Z'))
		{
			m=m+(n[i]-'A'+10)*t;
			t=t*a;
		}
	}
	if(m==0)
		printf("0\n");
	else
	{
		if(b==10)
			printf("%ld",m);
		else
		{
			for(i=0;m!=0;i++)
			{
				w=m%b;
				if(w>=0&&w<=9)
					k[i]=w+'0';
				else if(w>9&&w<36)
					k[i]=w-10+'A';
				m=(m-w)/b;
			}
			k[i]='\0';
			for(i=strlen(k)-1;i>=0;i--)
				printf("%c",k[i]);
			printf("\n");
		}
	}
}
main()
{
int a,b,i,j,k,l,m,n;
long s=0;
int d[32]; 
char c[32],e[32];
scanf("%d %s %d",&a,c,&b);
if(c[0]=='0')
printf("%d\n",0);
else
{ 
n=strlen(c);
for(i=0;i<=n-1;i++)
{
if(c[i]<'A')
d[i]=c[i]-'0';
else if(c[i]>='A'&&c[i]<'a')
d[i]=c[i]-'A'+10;
else
d[i]=c[i]-'a'+10;
}                  
for(i=0;i<=n-1;i++)
{ 
k=d[i]; 
for(j=1;j<=n-1-i;j++)
k=k*a;
s=s+k;                   
}
for(i=0;s>0;i++)
{
l=s%b;
if(l<10)
e[i]=l+'0';
else
e[i]=l-10+'A';
s=s/b;         
}
for(m=i-1;m>0;m--) 
printf("%c",e[m]);
printf("%c\n",e[0]);
}
getchar();
getchar();  
getchar();        
}
//*****************************
//*??? :????           *
//*??   :???             *
//*??   :2011?11?         *
//*****************************
void zhuan(int, char [], int); 
int main ()
{
	int a, b;
	char n[101];
	cin >> a >> n >> b;
	zhuan(a, n, b);
	return 0;
}
void zhuan(int a, char n[], int b)
{
	int i, m[101], s, t;
	for (i = 0; ; i++)
	{
		if (n[i] =='\0') break;
		if (n[i] >= 'a' && n[i] <= 'z')
		{
			m[i] = n[i] - 'a' + 10;
			continue;
		}
		if (n[i] >= 'A' && n[i] <= 'Z')
			m[i] = n[i] - 'A' + 10;
		else m[i] = n[i] - '0';
	}
	t = i;
	s = m[0];
	if (s == 0) cout << 0;
	for (i = 0; i < t - 1; i++)
		s = s * a + m[i + 1];
	for (i = 0; ; i++)
	{
		if (s == 0) break;
		m[i] = s % b;
		s = s / b;
	}
	t = i - 1;
	for (i = t; i >= 0; i--)
	{
		if (m[i] < 10)
			cout << m[i];
		else cout << (char) (m[i] - 10 + 'A');
	}



}
int main()
{
   long a,b,i,j,k,l,z,length,sum10,zhi;
   i=0;
   j=0;
   k=1;
   l=0;
   z=0;
   length=0;
   sum10=0;
   zhi=0;
   char n[50],r[50];
   scanf("%d%s%d",&a,n,&b);
   long m[50][2],o[50][2],n2[50];
   length=strlen(n);
  
    
  for(i=0;i<length;i++)
   {
      if(n[i]<='9')
      n2[i]=n[i]-'0';
      else if(n[i]<'a'&&n[i]>'9')
      n2[i]=n[i]-'A'+10;             
      else 
      n2[i]=n[i]-'a'+10;
      
   } 
   
   
   for(i=0;i<length;i++)
   {
     m[i][0]=n2[i];
     m[i][1]=length-i-1;
     zhi=m[i][0];
     for(j=1;j<=m[i][1];j++)
     {
         zhi=zhi*a;
     }
     sum10=sum10+zhi;
     zhi=0;
    }
   
   if(sum10==0)
   printf("0");
   else
   {   
   k=sum10;
   
   while(k!=0)
   {
      o[l][0]=k%b;
      k=k/b;
      o[l][1]=l;
      l++;
   }
   
   length=l;
   
   for(i=0;i<length;i++)
   {
      if(o[l-i-1][0]<=9)
      r[i]=48+o[l-i-1][0];
      else
      r[i]=o[l-i-1][0]-10+65;             
   }
    r[length]='\0';
    //printf("%s",r);
    puts(r);
}  
    getchar();
    getchar();
    
}
//
//  main.cpp
//  hw
//
//  Created by ? ? on 12-12-16.
//  Copyright (c) 2012? ? ?. All rights reserved.
//

char *atob(int a,int b,char *str1)
{
    int len1=strlen(str1),Sum=0;
    static char str2[100]={0};
    for (int i=0; i<len1; i++) {//a????????
        int s;
        if (str1[i]<=57) {//?????????
            s=str1[i]-'0';
        }
        if(str1[i]>=65&&str1[i]<=90)
        {
            s=str1[i]-'A'+10;
        }
        if(str1[i]>90)
        {
            s=str1[i]-'a'+10;
        }
        Sum+=s*pow(a, len1-i-1);
    }
    for (int 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;
    }
    int len=strlen(str2);
    str2[len]=0;
    return str2;
}

int main(int argc, const char * argv[])
{
    int a,b;
    char str1[100]={0};
    cin>>a>>str1>>b;
    if (str1[0]=='0') {
        cout<<"0";
        return 0;
    }
    char *str2=atob(a,b,str1);
    int len=strlen(str2);
    for (int i=len-1; i>=0; i--) {
        cout<<*(str2+i);
    }
    return 0;
}
void main()
{
	int a=0,b=0,begin,end,i,j;long int e=0;char c[40]={0};int f(char x);char g(int x);
       gets(c);
		for(i=0;c[i]!=' ';i++)
			a=a*10+c[i]-'0';
		  begin=i+1;
		for(i=begin;c[i]!=' ';i++);
			end=i-1;
                        
		for(i=end+2;c[i+1]!=0;i++)
			b=b*10+c[i]-'0';
		for(i=begin;i<=end;i++)
			e=a*e+f(c[i]);
if(e==0)printf("0");
		for(j=0;e>0;j++)
		{
			c[j]=g(e%b);
			e=e/b;
		}
		for(i=0;i<j/2;i++)
		{
			c[39]=c[i];c[i]=c[j-i-1];c[j-i-1]=c[39];
		}
		c[j]=0;
		puts(c);
}
int f(char x)
{
	if('0'<=x&&x<='9')
		return(x-'0');
	else if('A'<=x&&x<='Z')
		return(x-'A'+10);
		else return(x-'a'+10);
}
char g(int x)
{
	if(0<=x&&x<=9)
		return(x+'0');
		else return(x+'A'-10);
}
int main()
{
    int a,b;
    char n[N];
    int i,j,t,l;
    int sum=0;

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


    l=strlen(n);
    for(i=0;i<=l/2-1;i++)
    {
        t=n[i];
        n[i]=n[l-i-1];
        n[l-i-1]=t;
    }

    //puts(n);

    for(i=0;i<l;i++)
    {
        if(n[i]>='0'&&n[i]<='9')
            t=n[i]-'0';
        else if(n[i]>='A'&&n[i]<='Z')
            t=n[i]-'A'+10;
        else if(n[i]>='a'&&n[i]<='z')
            t=n[i]-'a'+10;

        for(j=1;j<=i;j++)
        {
            t=t*a;
        }

        sum=sum+t;
    }
    for(i=0;i<N;i++)
        n[i]='\0';

    for(i=0;sum>=b;i++)
    {
        n[i]=sum%b;
        sum=(sum-sum%b)/b;

        if(n[i]<10)
        {
            n[i]=n[i]+'0';
        }
        else if(n[i]>=10)
        {
            n[i]=n[i]-10+'A';
        }
    }
    if(sum<10)
    {
        n[i]=sum+'0';
    }
    else if(sum>=10)
    {
        n[i]=sum-10+'A';
    }

    l=strlen(n);

    for(i=l-1;i>=0;i--)
        printf("%c",n[i]);

    return 0;
}
int main()
{
    char a[100000]={0},b[100000]={0};
    int i,n=0,ta,tb;
    scanf("%d ",&ta);
    scanf("%s",a);
    scanf("%d",&tb);
    
    for(i=0;i<strlen(a);i++)
        if(a[i]>=97&&a[i]<=122)
            a[i]-=32;
    
    for(i=0;i<strlen(a);i++)//?????????n?
    {
        if(a[i]>=65&&a[i]<=90)
            n=ta*n+(a[i]-55);
        else  n=ta*n+(a[i]-48);
    }
    //printf("%d\n",n);
    
    if(n==0) printf("0");
    else  for(i=0;n>0;i++)  //
    {
        if(n%tb<10)
           b[i]=n%tb+48;
        else b[i]=n%tb+55;
        n=n/tb;
    }
        
        for(i=strlen(b)-1;i>=0;i--)
            printf("%c",b[i]);
        return 0;
}
int main()
{
    int m,n,c[100],d[100],i,j,p,q,t=1,s=0;
    char a[100],b[100];
    scanf("%d %s %d",&m,a,&n);
    for(i=0;a[i]!='\0';i++)
    {
        if(a[i]>='0'&&a[i]<='9')
        c[i]=a[i]-'0';
        else if(a[i]>='a'&&a[i]<='z')
        c[i]=a[i]-'a'+10;
        else if(a[i]>='A'&&a[i]<='Z')
        c[i]=a[i]-'A'+10;
    }   
    p = i;
    for(i=p-1;i>=0;i--)
    {
         s=s+t*c[i];   
         t=t*m;
    }
    if(s==0)
    printf("0");
    else
    {
         for(i=0;s!=0;i++)
    {   
        d[i]=s%n;
        s=s/n;
    }
   q = i;
     for(i=0;i<q;i++) 
     {
        if(d[i]>=0&&d[i]<=9)
        b[i]=d[i]+'0';
        else
        b[i]=d[i]+'A'-10;
     }  
     for(i=q-1;i>=0;i--)
     printf("%c",b[i]);
     }
     printf("\n");
     getchar();
     getchar();
}
int main()                                                         
{                                                                 
	char n[100]=" ";                                                
	double a=0.0;                                                  
	int b=0,N=0,i=0,j=0,p=0,sum=0;                                  	  
	                                                                
	cin>>a>>n>>b;                                                 
	N=strlen(n);                                                    
	for(i=0;i<N;i++)                                               
	{
		if('A'<=n[i]&&n[i]<='Z')
			n[i]=n[i]-55;
		else if('a'<=n[i]&&n[i]<='z')
			n[i]=n[i]-87;
		else if('0'<=n[i]&&n[i]<='9')
			n[i]=n[i]-48;
	}                                                              
	for(i=0;i<N;i++)                                               
		sum=sum+n[i]*pow(a,N-i-1);                                 
	if(sum>0)                                                      
	{
		for(i=0;sum>0;i++)
		{
			n[i]=sum%b;
			sum=(sum-n[i])/b;
		}                                                                
		for(j=0;j<=i/2;j++)
		{
			p=n[j];
			n[j]=n[i-j];
			n[i-j]=p;
		}                                                          
		for(j=0;j<=i;j++)                                        
		{
			if(0<=n[j]&&n[j]<=9)
				n[j]=n[j]+48;
			else if(n[j]>9)
				n[j]=n[j]+55;
		}                                                          
		for(j=1;j<=i;j++)
			cout<<n[j];                                           
	}
	else if(sum==0)                                                
		cout<<"0"<<endl;
	return 0;
}
void main()
{
	int a,b,l,i,j,m,k;
	char c[100];
	int d[100];
	char e[100];
	int f[100];
	scanf("%d",&a);
	scanf("%s",c);
	scanf("%d",&b);
	l=strlen(c);
	for(i=0;i<l;i++)
	{
		if(c[i]>='A'&&c[i]<='Z')
			f[i]=10+c[i]-'A';
		if(c[i]>='a'&&c[i]<='z')
			f[i]=10+c[i]-'a';
		if(c[i]>='0'&&c[i]<='9')
			f[i]=c[i]-'0';
	}
	m=0;
	for(i=0;i<l;i++)
	{
		k=1;
		j=1;
		while(j<(l-i))
		{
			k=k*a;
			j++;
		}
		m=m+f[i]*k;
	}
	i=0;
	while(m>0)
	{
		if(m>=b)
		{
			d[i]=m%b;
			m=m/b;
			i++;
		}
		else
		{
			d[i]=m;
			m=0;
		}
	}
	l=i+1;
	for(i=0;i<l;i++)
	{
		if(d[i]<10)
			e[l-1-i]=d[i]+'0';
		else
			e[l-1-i]=d[i]-10+'A';
	}
	for(i=0;i<l;i++)
		printf("%c",e[i]);
}
long trans(int len,int a[],int b);
void main()
{
	int ori,fin,len0,i,len3,j;
	long ten;
	char num0[100],num3[100];
	int num1[100]={0},num2[100]={0};
	scanf("%d%s%d",&ori,num0,&fin);
	len0=strlen(num0);
	for(i=0;i<len0;i++)
	{
		if(num0[i]>='A'&&num0[i]<='Z')
			num1[i]=num0[i]-'A'+10;
		else if(num0[i]>='a'&&num0[i]<='z')
			num1[i]=num0[i]-'a'+10;
		else
			num1[i]=num0[i]-'0';
	}
	ten=trans(len0,num1,ori);
	if(ten==0)
		printf("0\n");
	else
	{
	for(i=0;ten;i++)
	{
		num2[i]=ten%fin;
		ten=ten/fin;
	}
	len3=i;
	for(j=0;j<=len3;j++,i--)
	{
		if(num2[i-1]<=9)
			num3[j]=num2[i-1]+'0';
		else
			num3[j]=num2[i-1]+'A'-10;
	}
	num3[len3]='\0';
	printf("%s\n",num3);
	}
}
long trans(int len,int a[],int b)
{
	long x;
	if(len==1)
		return(a[len-1]);
	else
		x=a[len-1]+b*trans(len-1,a,b);
	return(x);
}
int main()
{
	char s[100],u[100];
	int a,b,l,k=0,i,j,r,l1;
	cin>>a>>s>>b;
	l=strlen(s);
	int sum=1;
    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;
	}
	if(k==0)
		cout<<"0"<<endl;
	else
	{
    for(j=0;k!=0;j++)
	{
		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 main()          
{
	int sys2,oct=0,homo,i,j,t;    //??sys1?sys2????????????
	double sys1,length;  //?????????,??sys1?double
	char num[32];           //????????
	cin>>sys1>>num>>sys2;
	length=strlen(num);           //????????
	for(i=0;i<length;i++)          //?????????????????????
	    num[i]=(char)toupper(num[i]);
	for(i=0;i<length;i++)                //???????????
	{
		if(num[i]>=48&&num[i]<=57)
		    homo=num[i]-48;
		else 
			homo=num[i]-55;
		oct=oct+homo*pow(sys1,length-i-1);
	}
	int change[32]; 
	for(i=0;;i++)           //????????sys2???????sys2???
	{
		change[i]=oct%sys2;
		oct=oct/sys2;
		if(oct==0)
			break;
	}
	for(j=0;j<=i-j;j++)        //???????????????????
	{
		t=change[j];
		change[j]=change[i-j];
		change[i-j]=t;
	}
	char ans[32];
	for(j=0;j<=i;j++)          //??????ASCII?
	{
		if(change[j]>=10)
			ans[j]=change[j]+55;
		else
			ans[j]=change[j]+48;
		cout<<ans[j];           //??????
	}
	cout<<endl;
	return 0;
}
/*
 * ????.cpp
 *
 *  ??: 2010-11-12
 *      Author: ??
 */

int main(){
	int a,b,i=0,j=0,t=0;
	double p,l;
	char n[100],m[100];
	cin>>a>>n>>b;
	l=strlen(n);
	for(i=0;i<l;i++)
	{{if(n[i]>='A'&&n[i]<='Z')
		p=n[i]-55;
	else if(n[i]>='a'&&n[i]<='z')
		p=n[i]-87;
	else p=n[i]-48;}t+=p*pow((double)a,l-i-1.0);
	}
	while(t/b!=0)
		{m[j]=t%b;
		t=t/b;
		j++;
		}m[j]=t%b;

		while(j>=0){if(m[j]>9)(char)(m[j]+=55);
		else (char)(m[j]+=48);
			cout<<m[j];j--;}
	return 0;
}
int main()
{
	long int a,b,t=0,i,j,k,l,m,u,v,f[1000];
	char c[1000],d[1000]={'\0'};
	scanf("%d%s%d",&a,c,&b);
	u=strlen(c);
	for(i=0;i<u;i++)
	{
		f[i]=c[i];
	}
	for(i=u-1;i>=0;i--)
	{
		if(f[i]>=97)
			f[i]=f[i]-87;
		else if(f[i]>=65)
			f[i]=f[i]-55;
		else
			f[i]=f[i]-48;
	}
	for(j=0;j<u-1;j++)
	{
		for(k=0;k<u-1-j;k++)
			f[j]=f[j]*a;
	}
	for(l=0;l<u;l++)
		t=t+f[l];
	if(t==0)
	{
		printf("0");
	}
	else
	{
		for(m=0;t>0;m++)
	{
		if(t<b)
		d[m]=t;
		else d[m]=t%b;
		t=(t-d[m])/b;
		if(d[m]>9)
			d[m]=d[m]+55;
		else
			d[m]=d[m]+48;
	}
	}
	v=strlen(d);
	for(m=v-1;m>=0;m--)
	{
			printf("%c",d[m]);
	}
	return 0;
}
int main(int argc, char* argv[])
{
	int from,to,i,j;
	long sum=0;
	char in[255],out[255]="0";
	scanf ("%d%s%d",&from,in,&to);
	char s10[100],s[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (i='0';i<='9';i++)
		s10[i]=i-'0';
	for (i='a';i<='z';i++)
		s10[i]=i-'a'+10;
	for (i='A';i<='Z';i++)
		s10[i]=i-'A'+10;
	for (i=0;in[i]!='\0';i++)
		sum=sum*from+s10[in[i]];
	for (i=0;i<255;i++)
	{
		out[i]=s[sum%to];
		sum=sum/to;
		if (sum==0) break;
	}
	for (j=i;j>=0;j--)
		printf ("%c",out[j]);
	return 0;
}
//????
//2010?11?16?
//1000012753 ???
int main()
{
	char str1[200];
	char stdard[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 i, j, l1, l2, l3, r, str2[200];
	double a, b, medium = 0.0;
	cin >> a >> str1 >> b;
	l1 = strlen(str1);
	for (i = 0; i < l1; i++)
	{
		if (str1[i] >= 'a' && str1[i] <= 'z')
			str1[i] -= 'a' - 'A';
	}
	j = 0;
	for (i = l1 - 1; i >= 0; i--)
		str2[j++] = str1[i];
	for (i = 0; i < l1; i++)
	{
		for (j = 0; j < 36; j++)
		{
			if (str2[i] == stdard[j])
				medium += j * pow (a, i);
		}
	}
//	cout << medium;
	j = 0;
	while ((int)medium >= (int)b)
	{
		str2[j++] = (int)medium % (int)b;
		medium = (int)medium/(int)b;
	}
	str2[j] = (int)medium;
	for ( ; j >= 0; j--)
		cout << stdard[str2[j]];
	cout << endl;
			
//	itoa(medium, buf, (int)b);

/*	l2 = strlen(buf);
	r = 0;
	for (i = 0; i < l2; i++)
	{
		r = ((r * 10) + buf[i] - '0') % (int)b;
		for (j = 0; j < 36; j++)
		{
			if (j == r)
			{
				str2[i] = stdard[j];
				break;
			}
		}
	}
	str2[i] = '\0';
	l3 = strlen(str2);
	for (i = l3 - 1; i >= 0; i--)
		cout << str2[i];
	cout << endl;*/
	return 0;
}
int turn(char num)
{
	if(num>='0'&&num<='9') return num-48;
	if(num>='a'&&num<='z') return num-87;
	if(num>='A'&&num<='Z') return num-55;
}

char turn(int num)
{
	if(num>=0&&num<=9) return num+48;
	if(num>=10&&num<=36) return num+55;
}

int main()
{
	int a,b,i=-1,j=0,s;
	long temp=0,temp1=0;
	char num[8*sizeof(long)]={'\0'};
	int num1[8*sizeof(long)]={0};
	cin>>a;cin.get();
	do
	{
		i++;
		num[i]=cin.get();
	}while(num[i]!=' ');
	cin>>b;
	for(;j<i;j++)
		temp+=turn(num[j])*pow((double)a,i-j-1);
	temp1=temp;
	for(i=0;temp1>0;i++)
	{
		num1[i]=temp1%b;
		temp1=temp1/b;
	}
	for(j=i-1;j>0;j--)
		cout<<turn(num1[j]);
cout<<turn(num1[0]);

	return 0;
}
int main()
{
    char s[10000];
	int a,b,k,d,i,j,c,n;
	k=0;
	scanf("%d %s %d",&a,s,&b);
    for(i=strlen(s)-1;i>=0;i--)
	{
		if(s[i]>='a'&&s[i]<='z')
			d=10+(int)(s[i]-'a');
		if(s[i]>='A'&&s[i]<='Z')
			d=10+(int)(s[i]-'A');
        if(s[i]>='0'&&s[i]<='9')
			d=(int)(s[i]-'0');
		n=strlen(s)-1-i;
		c=1;
	    for(j=0;j<n;j++)
			c*=a;
		k=k+d*c;	
	}
	for(i=0;;i++)
	{
		if(k%b<=9)
		{
		   c=k%b+48;
		   s[i]=(char)(c);
		}
		if(k%b>9)
		{
			c=k%b+55;
			s[i]=(char)(c);
		}
		if(k/b==0)
		{
			break;
		}
        k=k/b;
	}
	d=i;
	for(i=d;i>=0;i--)
		printf("%c",s[i]);
	scanf("%d",1);
	return 0;
}
long decimal(char c[],long x)
{
	long d=0;
	for(int i=0;c[i]!='\0';i++)
	{
		if(c[i]>='0'&&c[i]<='9')
			d=d*x+c[i]-'0';
		if(c[i]>='A'&&c[i]<='Z')
			d=d*x+c[i]-'A'+10;
		if(c[i]>='a'&&c[i]<='z')
			d=d*x+c[i]-'a'+10;
	}
	return d;
}

int main()
{
	long a,b;
	int length;
	char n[65] = {0};
	cin>>a>>n>>b;
	long x = decimal(n,a);
	for(int i=0;x>=0;i++)
	{
		int remainder=x%b;
		n[i]=remainder<10?'0'+remainder:'A'+remainder-10;
		x=(x-remainder)/b;
		length=i;
		if(x==0)
			break;
	}
	for(int i=length;i>=0;i--)
		cout<<n[i];
	cout<<endl;
	return 0;
}
int main()
{
int s_n[128];
char n_s[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char in[255],out[255]="0";

int i,from,to,len=0;
long num=0;

for(i='0';i<='9';i++)
{s_n[i]=i-'0';}
for(i='A';i<='Z';i++)
{s_n[i]=i-'A'+10;}
for(i='a';i<'z';i++)
{s_n[i]=i-'a'+10;}

scanf("%d %s %d",&from,in,&to);
for(i=0;in[i]!='\0';i++)
{num=num*from+s_n[in[i]];}

len=(num==0)?1:0;
while(num>0)
{
out[len++]=n_s[num%to];
num=num/to;
}
for(i=len-1;i>=0;i--)
{
printf("%c",out[i]);
}
return 0;
}
main()
{
	char n[33],m[33];
	long c,x,y;
	int a,b,d,e,l,i;
	scanf("%d%s%d",&a,n,&b);
	l=strlen(n);
	for(i=0;i<l;i++)
	{if(n[i]>='a'&&n[i]<='z') n[i]=n[i]+10-'a';
	if(n[i]>='A'&&n[i]<='Z') n[i]=n[i]+10-'A';
	if(n[i]>='0'&&n[i]<='9') n[i]=n[i]-'0';}
	c=0;
	for(i=0;i<=l-1;i++)
	{
		c=c*a+n[i];
	}
	d=0;
	do
	{
		x=c/b;
		y=c%b;
		for(i=d-1;i>=0;i--) m[i+1]=m[i];
		m[0]=y;
		c=x;
		d++;
	} while(x!=0);
	m[d]='\0';
	for(i=0;i<d;i++)
	{
		if(m[i]>=0&&m[i]<=9) m[i]=m[i]+'0';
		else m[i]=m[i]+'A'-10;
	}
	printf("%s\n",m);
}
int main()
{
    int a,b;
    char num1[32];
    int num2[32]={0};
    long num;
    int i,lenth;
    scanf("%d %s %d",&a,num1,&b);
    for(lenth=0;num1[lenth]!='\0';lenth++)
        {
         if(num1[lenth]<='9')num1[lenth]-='0';
         else num1[lenth]-='A'-10;
         if(num1[lenth]>=35)num1[lenth]-=32;
         }
    for(i=1,num=num1[0];i<lenth;i++)
       num=num*a+num1[i];          
    for(i=31;num>=b;i--)
         {
          num2[i]=num%b+1;
          num/=b;
         }
    num2[i]=num+1;     
    for(i=0;i<32;i++)
       {
         if(num2[i]==0)continue;
         else if(num2[i]<10)printf("%d",num2[i]-1);      
         else printf("%c",num2[i]+'A'-11);
       }
    return 1;
}
//*************************
//*  ?  ??????     *
//*  ?  ??2010-10-27   *
//*  ?  ?????       *
//*************************
int main()
{
	char n[100];//???????
	int length,ten=0,i;//?????????????????????
	int a,b;
	scanf("%d",&a);scanf("%s",n);scanf("%d",&b);
	length=strlen(n);//????
	for(i=0;i<=length-1;i++)//?????????????
	{
		if(('A'<=n[i])&&(n[i]<='Z'))//???????????ASCII????????
			n[i]=n[i]-'A'+10;
		else if(('a'<=n[i])&&(n[i]<='z'))
			n[i]=n[i]-'a'+10;
		else if(('0'<=n[i])&&(n[i]<='9'))//?????????ASCII????????
			n[i]=n[i]-'0';
	}
	for(i=0;i<=length-1;i++)
	{
		ten=ten+(int)(n[i]*pow(a,length-i-1));//?a????????
	}
	if(ten==0)
		printf("%d",ten);//??0????
	if(ten!=0)
	{
		int yushu[100],j;//????
		for(i=0;ten!=0;i++)
		{
			yushu[i]=ten%b;//???????b???????
			ten=ten/b;
		}
		for(j=i-1;j>=0;j--)//??????b?????
		{
			if((0<=yushu[j])&&(yushu[j]<=9))
				printf("%d",yushu[j]);//???0-9?????
			else if(yushu[j]>=10)
			{
				yushu[j]=yushu[j]+'A'-10;
				printf("%c",yushu[j]);//???10????????????
			}
		}
	}
	printf("\n");
	return 0;
}
long C(long Z,long X)
{     long V;
      if (X==0)
      V=1;
      else
      {
      V=1;
      for(long B=1;B<=X;B++)
      V=V*Z;
      }
      return V;
      
}
main()
{
    char q;
  int d=0;
    long o,a,b,p,k,h,i,t;
    char n[20],l,g;
      scanf("%d %s %d",&a,n,&b);
      o=strlen(n);
      long m[o];
    for(k=0;k<=o-1;k++)
    {
    l=n[k];
    if(('9'-l>=0)&&('0'-l<=0))
    l=l-'0';
    else
    {
    if((l<=96)&&(l>=10))
    l=l-55;
    else 
    {
    if(l>=97)
    l=l-87;
    }
    }
    m[k]=l;
    }

    
    p=0;
    for(k=0;k<=o-1;k++)
    {long s=o-k-1;
    p=p+(m[k])*(C(a,s));
    }
    
    if(p==0)
    printf("0");
    
    if(b>=10)
{   
    for(int j=9;j>=0;j--)
    {
            
            t=p/(C(b,j));
            p=p-t*C(b,j);
            if(t!=0||d!=0)
        {
            if(t>=10&&t<=50)
            {
            g=t+55;
            printf("%c",g);
            }
            else
            printf("%d",t);
            d++;
        }
    }
}
    else
{  
    for(int j=20;j>=0;j--)
    {
            
            t=p/(C(b,j));
            p=p-t*C(b,j);
            if(t!=0||d!=0)
        {
            if(t>=10&&t<=50)
            {
            g=t+55;
            printf("%c",g);
            }
            else
            printf("%d",t);
            d++;
        }
    }
}
                   
    getchar();
    getchar();
}
int zheng (char x);
char fan(int x);

int main()
{
	int n,m,f,sum=0,wei=0,i;
	char zhuan[50];
	scanf("%d",&n);
	char x[10];
	scanf("%s",x);
	scanf("%d",&m);
	f=strlen(x);
    for(i=0;i<f;i++)
	{
			sum+=zheng(x[i])*pow(n,f-i-1);
	}
	for(i=49;i>=0;i--)
	{
		zhuan[i]=fan(sum%m);
		wei++;
		sum=sum/m;
		if(sum==0)
			break;
	}
	for(i=50-wei;i<50;i++)
	{
		printf("%c",zhuan[i]);
	}
	return 0;
}
    

    int zheng(char x)
	{
		int m;
		if(x>='a'&&x<='z')
			m=x-87;
		else if(x>='A'&&x<='Z')
			m=x-55;
		else
			m=x-48;
		return m;
	}


	char fan(int x)
	{
		char m;
		if(x>=0&&x<=9)
		    m=x+48;
		else if(x>=10&&x<=35)
			m=x+55;
		return m;
	}