semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void main()
{
	int a,b,n,l,t=1,i,j,g,re[100],k=0;
	long int sum=0;
	char num[100],c[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'};
	scanf("%d %s %d",&a,num,&b);
	l=strlen(num);
	for(i=0;i<l;i++)
		if(num[i]>='a'&&num[i]<='z')
			num[i]=num[i]-32;
	for(i=l-1;i>=0;i--)
		for(j=0;j<a;j++)
		if(c[j]==num[i])
			{
				sum=sum+t*j;
				t=t*a;
			}
			while(sum>=b)
			{
				g=sum%b;
				re[k++]=c[g];
				sum=sum/b;
			}
			re[k]=c[sum];
		
		for(i=k;i>=0;i--)
			printf("%c",re[i]);
		printf("\n");
}
int main()
{
   int n,m,i,t=0,j,c=0;
   char s[80],a[80];
   char  b[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   scanf("%d %s %d",&n,s,&m);
   for(i=0;s[i]!='\0';i++)
   {
         for(j=0;j<37;j++)
         {
               if(s[i]==b[j]||(s[i]==b[j]+32&&s[i]>='a'&&s[i]<='z'))
              {
                  t=t*n+j;
              }
          }
    }
   for(i=79;i>0;i--)
   {
          a[i]=b[t%m];
          c++;
          t=t/m;
          if(t==0)
          {
             break;
          }
   }
   for(i=80-c;i<80;i++)
  {
       printf("%c",a[i]);
  }
      return 0;
}
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];
        }
	i=0;
	do
	{
		if(num%b<10)m[i]=num%b+48;
		else m[i]=num%b+55;
		num=num/b;
		i++;
	}while(num);
	for(;i>0;i--)cout<<m[i-1];
	return 0;
}
int main()
{   int m,n,k,i,t=0,j=1,t1;
    char a[20],b[20],c[20];
    scanf("%d",&m);
    scanf("%s",a);
    scanf("%d",&n);
    k=strlen(a);
    for(i=k-1;i>=0;i--)
       {  if(a[i]>=48&&a[i]<=57) t=t+(a[i]-48)*j;
          else if(a[i]>=65&&a[i]<=90) t=t+(a[i]-55)*j;
          else if(a[i]>=97&&a[i]<=122) t=t+(a[i]-87)*j;
          j=j*m;
       }
    if(t==0) printf("%d",t);
    else {i=0;
    while(t>0)
       {  t1=t%n;
          t=t/n;
          if(t1<=9) b[i]=t1+48;
          else b[i]=t1+55;
          i++;
       }
    for(j=0;j<i;j++)
       {  c[j]=b[i-1-j];
          printf("%c",c[j]);}}
    printf("\n");  
    scanf("%d",&m);
}
//******************************************
//*???????.cpp                     **
//*??: ??     1100012808              **
//*???2011.11.13                       **
//******************************************
int shi(int a, char b[]) //???????????????????
{
    int sum = 0, i = 0, f;  
    double t;   
    f = strlen(b);  //f?usigned int?????int
    t = a;//t??a?????????????
    for (i = 0; i < strlen(b); i++)
    {
	if (b[i] < 'A')   //????????????????
            sum +=(int) (b[i] - '0') * pow(t, f - 1 - i);
	else if (b[i] < 'a')
	    sum +=(int) (b[i] - 'A' + 10) * pow(t, f - 1 - i);
	else
	    sum +=(int) (b[i] - 'a' + 10) * pow(t, f - 1 - i);
    }
    return sum;
}
void zhuanhua(int x, int y)  //????????????????????
{
    int i = 0, yu[300] = {0}, j = 0;   
    if (x != 0)     //??????????0
    {
  	for (i = 0; x != 0; i++)  //???????x??0
	{
            yu[i] = x % y;   //?????????????
	    x = x / y;   //?????????
	}
    }
    else
 	cout << "0" << endl;  //??0???????0??
    for (j = i - 1; j >= 0; j--)  
    {
	if (yu[j] > 9)  //????????9
	{
            cout << (char)(yu[j] - 10 + 'A');//???????????
	}
	else
	{
	    cout << yu[j]; //????????????
	}
    }
    return;
}
int main()  //???
{        //?????
	int a, b;
	char n[300];  //??????????
	cin >> a >> n >> b;
	zhuanhua(shi(a, n), b); //???????
	return 0;
} //?????
void main()
{
	int length,original,then,change[100],i,j,k,s=0,m,length2;
	char input[100],output[100];
	scanf("%d %s %d",&original,input,&then);
	length=strlen(input);
	for(i=0;i<length;i++)
	{
		if(input[i]<='9') change[i]=input[i]-48;
		else if(input[i]>='a') change[i]=input[i]-87;
		else change[i]=input[i]-55;
	}
	for(i=0;i<length;i++)
	{
		s=s+pow(original,length-i-1)*change[i];
	}
	for(j=0;;j++)
	{
		m=s%then;s=s/then;
		{
			if(s==0) 
			{
				if((m<=9)&&(m>=0)) {output[j]=m+48;break;}
				else if((m>9)&&(m<=35)) {output[j]=m+55;break;}
			}
			else
			{
				if((m<=9)&&(m>=0)) output[j]=m+48;
		     	else if((m>9)&&(m<=35)) output[j]=m+55;
			}
		}
	}
	for(k=0;k<j+1;k++)
		printf("%c",output[j-k]);
	printf("\n");
}
int convert_1(char a){
   if (a >= '0' && a<= '9') return a - '0';
   if (a >= 'a' && a<= 'z') return a - 'a' + 10;
   if (a >= 'A' && a<= 'Z') return a - 'A' + 10;
}
char convert_2(int a){
    if (a < 10) return a + '0';
     else return a - 10 +'A';
}
void convert(int a,int n){
    if (a >= n) convert(a / n,n);
    printf("%c",convert_2(a % n));
}
int main(){
    int a,n = 0,b,k = 1,i;
    char str[500];
    scanf("%d %s %d",&a,str,&b);
    for(i = strlen(str) - 1;i >= 0;i --){
        n += convert_1(str[i]) * k;
        k *= a;
    }
    convert(n,b);
    printf("\n");
    return 0;
}
main()
{
      int a,b,i,x,j,l,y;
      char c[1000];
      char f[1000];
      int e[1000];
      scanf("%d %s %d",&a,c,&b);
      l=strlen(c);
      x=0;
      int d[l];
          for(i=0;i<l;i++)
          {
              if(c[i]<='Z'&&c[i]>='A')
              d[i]=c[i]-'A'+10;
             else if(c[i]<='z'&&c[i]>='a')
              d[i]=c[i]-'a'+10;
              else
              d[i]=c[i]-'0';
              x=d[i]+x*a;
              }
              if(x==0)
    printf("%d",0);
          for(j=0;x!=0;j++)
          {
              e[j]=x%b;
              x=x/b;
          }
  e[j]=0;
          for(y=0;y<j;y++)
          {
              if(e[y]<=9)
              f[j-1-y]='0'+e[y];
              else
              f[j-1-y]=e[y]-10+'A';
          f[j]='\0';
          }
          
      printf("%s",f);
      printf("\n");

      getchar();
      getchar();
}
main()
{
	int i,a,b,n=0,l,l1=0,p;
	char s[33],t[33];
	scanf("%d%s%d",&a,s,&b);
	l=strlen(s);
	for(i=0;i<l;++i)
	{
		if((s[i]>='0')&&(s[i]<='9'))
			p=s[i]-'0';
		else if((s[i]>='a')&&(s[i]<='z'))
			p=s[i]-'a'+10;
		else
			p=s[i]-'A'+10;
		n=n*a+p;
	}
	for(;n;n/=b)
	{
		p=n%b;
		if(p<10)
			t[l1++]='0'+p;
		else
			t[l1++]='A'+p-10;
	}
	if(!l1)
		printf("0");
	else
		for(i=l1-1;i>=0;--i)
			printf("%c",t[i]);
	printf("\n");
}
main()
{
	char a[100],b[100];
	int i,j,n,k,l=0;
	long c=0;
	scanf("%d %s %d",&i,a,&j);
	n=strlen(a);
	for(k=0;k<n;k++)
	{
		if(a[k]>='A'&&a[k]<='Z')
			a[k]=a[k]-'A'+10;
		else if(a[k]>='a'&&a[k]<='z')
			a[k]=a[k]-'a'+10;
		else
			a[k]=a[k]-'1'+1;
	}
	for(k=0;k<n;k++)
		c=c*i+a[k];
	for(k=0;;k++)
	{
		b[k]=c%j;
		if(b[k]>=10)
			b[k]=b[k]-10+'A';
		else
			b[k]=b[k]+'1'-1;
		c=c/j;
		l=l++;
		if(c==0)
			break;
		
	}
	for(k=0;k<l;k++)
		printf("%c",b[l-k-1]);
}
int main()
{
	char str[100], ch[100];
	int i, l, j, k, jin1, jin2, r, sh;
	int sum;
	cin >> jin1;
	cin >> str;
	cin >> jin2;
	sum = 0;
	l = 0;
	for(i = 0; i < 100; i++)
	{
		if(str[i] == '\0') break;
	    else l++;
	}
	for(i = 0; i < l; i++)
	{
		if(str[i] >= 'a' && str[i] <= 'z') 
		{
			sum = sum * jin1 + (str[i] - 'a' + 10);
		}
		if(str[i] >= 'A' && str[i] <= 'Z')
		{
			sum = sum * jin1 + (str[i] - 'A' + 10);
		}
		if(str[i] >= '0' && str[i] <= '9')
		{
			sum = sum * jin1 + (str[i] - '0');
		}
	}
	sh = sum;
	k = 0;
	if(sum == 0)
	{
		cout << '0' << endl;
	}
	for(i = 0; sh != 0; i++)
	{
		r = sh % jin2;
		sh = sh / jin2;
		if(r < 10)
		{
			ch[i] = r + '0';
		}
		else
		{
			ch[i] = r + 'A' - 10;
		}
		k++;
	}
	for(j = k - 1; j >= 0; j--)
	{
		cout << ch[j];
	}
	cout << endl;
         return 0;
}
int main(){
	long int a,b,sum,c=0;
	char str[100],str1[100];
	cin>>a>>str>>b;
	for(int i=0;str[i]!='\0';i++)
		if((str[i]>='a')&&(str[i]<='z'))
			str[i]-=32;
	sum=strlen(str);
	for(int i=0;i<sum;i++){
		if(str[i]>='0'&&str[i]<='9')
			c+=(int)pow((double)a,(double)(sum-1-i))*(str[i]-48);
		if(str[i]>='A'&&str[i]<='Z')
			c+=(int)pow((double)a,(double)(sum-1-i))*(str[i]-55);
	}
	int Len=0; 
	if(c==0)
		cout<<"0";
	else{
		while(c>0){
			int t=c%b;
			if (t>=10) str1[Len]='A'+t-10;
				else str1[Len]='0'+t;
			c/=b;Len++;
		}
		for(int j=Len-1;j>=0;j--) 
			cout<<str1[j];
	}
	return 0; 
}
int main()
{
    int n,m,i,j,t=0,b=0;
    char s[80],s0[80];
    char s1[80]={"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    scanf("%d %s %d",&n,s,&m);
    for(i=0;s[i]!='\0';i++)
    {
           if(s[i]>='a'&&s[i]<='z')
           {
               s[i]=s[i]-32;
           }
         for(j=0;j<36;j++)
        {
             if(s1[j]==s[i])
         {
           t=n*t+j;
          }
         }
    }
   for(i=0;;i++)
   {
        s0[i]=s1[t%m];
        b++;
        t=t/m;
        if(t==0)
        {
            break;
        }
   }
   for(i=b-1;i>=0;i--)
   {
       printf("%c",s0[i]);
   }
    printf("\0");
    return 0;
}
int main()
{
	int a,b,sum=0,len,i,t,r;
	char s[100];
	scanf("%d %s %d", &a, s ,&b);
	len=strlen(s);
	for (i=0; i<len; i++)
	{
		if ( s[i]>='0' && s[i]<='9' ) t=s[i]-'0';
		else if ( s[i]>='a' && s[i]<='z') t=s[i]-'a'+10;
		else t=s[i]-'A'+10;
		sum = sum*a+t;
	}
	i=0;
	if (sum==0) printf("0\n");
	else
	{
		while (sum!=0)
		{
			r=sum%b;
			if (r<10) s[i]=r+'0';
			else s[i]=r-10+'A';
			sum/=b;
			i++;
		}
		s[i]='\0';
		i=strlen(s)-1;
		while (s[i]=='0') i--;
		for (; i>=0; i--)
			printf("%c",s[i]);
		printf("\n");
	}

	return 0;
}
void fun(char[][10],int*,int*,int);
void main()
{
	long i,l,a,b,t=0,r;
	char n[20],m[20]={'\0'};
	scanf("%ld %s %ld",&a,n,&b);
	l=strlen(n);
	for(i=0;i<l;i++)
	{
		if(n[i]>='0'&&n[i]<='9')
			t+=(n[i]-'0')*pow(a,l-i-1);
		else if(n[i]>='a'&&n[i]<='z')
			t+=(n[i]-'a'+10)*pow(a,l-i-1);
		else 
			t+=(n[i]-'A'+10)*pow(a,l-i-1);
	}
	if(t==0)
		printf("0");
	else
	{
    	for(i=0;t>0;i++)
		{
    		r=t%b;
    		if(r<10)
	    		m[i]='0'+r;
	    	else
		    	m[i]='A'+(r-10);
	    	t/=b;
		}
		for(i=i-1;i>=0;i--)
			printf("%c",*(m+i));
	}
}
int calc(char c)
{
if (c>='0' && c<='9') return c-'0';
else if (c>='a' && c<='z') return c-'a'+10;
else if (c>='A' && c<='Z') return c-'A'+10;
}
char form(int n)
{
if (n>=0 && n<=9) return '0'+n;
else return 'A'+n-10;
}
main()
{
int a,b,n,len,bs1;
char s[200];
char *p;
scanf("%d",&a);
scanf("%s",&s);
scanf("%d",&b);
len=strlen(s)-1;
bs1=1;
n=0;
int i;
for (i=len;i>=0;i--)
{
n+=bs1*(calc(s[i]));
bs1*=a;
}
if (n==0) printf("0");
for (i=0;n>0;i++)
{
s[i]=form(n%b);
n/=b;
}
for (int j=--i;j>=0;j--)
putchar(s[j]);
printf("\n");
}
void main()
{
    char s1[1000],s2[1000];
    int m[1000],n[1000],t,s,a,b,i,j,l1;
    scanf("%d%s%d",&a,s1,&b);
    l1=strlen(s1);
     for(i=0;i<l1;i++)
     {
     	if(s1[l1-1-i]>='0'&&s1[l1-1-i]<='9') m[i]=s1[l1-i-1]-'0';
     	else if(s1[l1-1-i]>='a'&&s1[l1-1-i]<='z') m[i]=s1[l1-i-1]-'a'+10;
     	else if(s1[l1-1-i]>='A'&&s1[l1-1-i]<='Z') m[i]=s1[l1-i-1]-'A'+10;
     }
     t=1;s=0;
        for(i=0;i<l1;i++)
       {s+=m[i]*t;
        t*=a;}//??????
       i=0;
       if(s)
       {
       while(s!=0)
      {
      	n[i]=s%b;
      	s=s/b;
      	i++;
      }
      i--;}
      for(j=i;j>=0;j--)
      {
      	if(n[j]<10) {s2[j]=n[j]+'0';printf("%c",s2[j]);}
      	else {s2[j]=n[j]+'A'-10;printf("%c",s2[j]);}
      	}
       
}
char uup(char c)
{
  if (c>=97) c-=32; return(c);
}
void main()
{
  char arr[40]={0},brr[40]={0};
  int n,m,i,j,k;
  int a[40]={0},b[40]={0};
  scanf("%d%s%d",&n,arr,&m);
  i=strlen(arr);
  for (k=0;k<i;k++)
    {if(uup(arr[k])>58) a[i-k-1]=uup(arr[k])-'A'+10; else a[i-k-1]=arr[k]-'0';}
//if (n>30)printf("%d%d%d%d%d",a[0],a[1],a[2],a[3],a[4]);
  for (k=0;k<40;k++)
  {
    for (j=39;j>=1;j--)
    {
      a[j-1]=a[j-1]+a[j]%m*n;
      a[j]=a[j]/m;
    }
    b[k]=a[0]%m; a[0]=a[0]/m;
  }
  k=39; while((b[k]==0)&&(k>=1))k--;
  for (;k>=0;k--)
  {
    if(b[k]>9)printf("%c",b[k]+'A'-10);
    else printf("%d",b[k]);
  }
  printf("\n");
}
int main ()
{
    int a,b,k=0;
    char c1[100];
    int d1[100],d2[100],c2[100];
    cin >>a;
    scanf("%s",c1);
    cin >>b;
    k=strlen(c1);
    int i;
    for(i=0;i<=k-1;i++)
    {
        if (48<=c1[i]&&c1[i]<=57)
           d1[i]=c1[i]-48;
        else if (65<=c1[i]&&c1[i]<=90)
           d1[i]=c1[i]-55;
        else d1[i]=c1[i]-87;
    }
    int s=0;
    int fc=1;
    for (i=k-1;i>=0;i--)
    {
        s=s+fc*d1[i];
        fc=fc*a;
    }
    i=0;
if (s==0)
      cout <<0 <<endl;
    while (s>0)
    {
        d2[i]=s%b;
        s=s/b;
        i++;
    }
    

    int g;
    for (g=0;g<=i-1;g++)
       if (d2[g]<=9)
          c2[g]=d2[g]+48;
        else c2[g]=d2[g]+55;
    for (g=i-1;g>=0;g--)
    cout <<(char)c2[g];
    return 0;


}
void main()
{
	int a,b,i,m,e,f,d=1,c=0;
	char n[1000]={0},k[1000]={0};
	scanf("%d",&a);
	scanf("%s",n);
	scanf("%d",&b);
	m=strlen(n);
    for(i=0;i<m;++i)
	{
		if(n[i]>=65&&n[i]<=90)
			n[i]=n[i]-55;
		if(n[i]>=97&&n[i]<=122)
			n[i]=n[i]-87;
		if(n[i]>=48&&n[i]<=57)
			n[i]=n[i]-48;
		c=c*a+n[i];
			}
         if(c==0) printf("0\n");
	for(i=0;c>0;++i)
	{
		e=c%b;
		if(e>=10&&e<=35) 
       e=e+55;
       if(e>=0&&e<=9) 
       e=e+48;
	  c=(c-c%b)/b;
	    k[i]=e;
	}
	 f=strlen(k);
	 for(i=0;i<f;++i)
	 
     { if(k[i]!='\0')
       printf("%c",k[f-1-i]);}
           
}
int main(){
	char str[10001];
	char* array[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"};
	long int a,b,n,m[10001],lstr,i,lb,a1;
	cin>>a;
	cin.get();
	cin>>str;
	cin>>b;
	lstr=strlen(str);
	n=0;lb=0;
	for(i=0;i<lstr;i++){
		if(str[i]>=65&&str[i]<=90)
		    m[i]=str[i]-'A'+10;
		else if(str[i]>=97&&str[i]<=122)
			m[i]=str[i]-'a'+10;
		else
			m[i]=str[i]-'0';
	}
	a1=a;
	n+=m[lstr-1];
	for(i=lstr-2;i>=0;i--){
		n=n+m[i]*a;
		a=a*a1;
	}
	for(i=1;i<10000;i++){
		if(n<b){
			cout<<array[n];
			break;
		}
		else{
			m[i]=n%b;
		    n-=m[i];
		    n=n/b;
			lb++;
		}
	}
	for(i=lb;i>=1;i--)
		cout<<array[m[i]];
return 0;
}
int main() {
        int a;
        char n[200];
        int b;
        cin >> a >> n >> b;
        int v = 0;
        int i = 0;
        for (i = 0; n[i]; i ++) {
                v *= a;
                n[i] = tolower(n[i]);
                if (n[i] >= '0' && n[i] <= '9') {
                        v += n[i] - '0';
                }
                else if (n[i] >= 'A' && n[i] <= 'Z') {
                        v += 10 + n[i] - 'A';
                }
                else if (n[i] >= 'a' && n[i] <= 'z') {
                        v += 10 + n[i] - 'a';
                }
        }
        if (v == 0)
                cout << 0 << endl;
        else {
                char r[200];
                i = 0;
                while (v != 0) {
                        if (v % b < 10)
                                r[i ++] = v % b + '0';
                        else
                                r[i ++] = v % b + 'A' - 10;
                        v /= b;
                }
                while (i > 0) {
                        cout << r[-- i];
                }
                cout << endl;
        }

        return 0;


}
int main()
{
	unsigned int decn=0;
    int a,b,i,k;                          //????????????????????????????????????????????????????????
	char n[100],r[100];                            //?????????????????????????????
	cin>>a>>n>>b;
    for(i=0;i<100;i++)
	{
		if(n[i]==0)
		{
			k=i;
			break;
		}
	}
	for(i=0;i<k;i++)
	{
		if(n[i]<=57)
		{
			decn=decn+(n[i]-48)*pow((double)a,(int)k-i-1);
		}
		else if(n[i]<=90)
		{
			decn=decn+(n[i]-55)*pow((double)a,(int)k-i-1);
		}
		     else
		     {
                 decn=decn+(n[i]-87)*pow((double)a,(int)k-i-1);
             }
	}                                           //?????????
	i=0;
	do{
		r[i]=decn%b;                      //???????????????????????
		if(r[i]<10)
		{
			r[i]=r[i]+48;
		}
		else
		{
			r[i]=r[i]+55;
		}                                //??????????
		decn=decn/b;                     //????????
		i++;
	}while(decn!=0);
	i=i-1;
	for(;i>=0;i--)
	{
		cout<<r[i];                      //???????
	}
    return 0;
}
//*********************************************
//*???????                            **
//*?????? 1100012914                   **
//*???2011.11.14                          **
//*********************************************


char num1[1000000], num2[100000];
int a, b, c, x = 0, i, len1, len2;
void change(int);
int main()
{
	cin >> a;
	cin >> num1;
	cin >> b;
	len1 = strlen(num1);
	int t, j;

	for (j = 0; j < len1; j++)
	{
		if (num1[j] >= 'a' && num1[i] <= 'z')
		{
			t = num1[j] - 'a' + 10;
			x = x * a + t;
		}
		else
			if(num1[j] >= 'A' && num1[j] <= 'Z')
			{
				t = num1[j] - 'A' + 10;
				x = x * a + t;
			}
			else
			{
				t = num1[j] - '0';
				x = x * a + t;
			}
	}
	
	change(x);
	
	len2 = strlen(num2);
	for (i = len2 - 1; i >= 0; i--)
	{
		cout << num2[i];
	}
	cin >> i;
	return 0;
}
void change(int x)
{
	int z, h = 0;
	char ch;
	if (x == 0)
		cout << 0 << endl;
	else
	{
		while (x != 0)
	{
		z = x % b;
		x = x / b;
		if (z >= 0 && z <= 9)
		{
			ch = z + '0';
			num2[h] = ch;
			h++;
		}
		else
		{
			z = z - 10;
			ch = z + 'A';
			num2[h] = ch;
			h++;
		}
	}
	}
}
int char_to_num(char c)
{
	if ('0'<=c && c<='9')
		return c-'0';
	if ('a'<=c && c<='z')
		return 10+(c-'a');
	if ('A'<=c && c<='Z')
		return 10+(c-'A');
}

char num_to_char(int n)
{
	if (n<10)
		return n+'0';
	else
		return n-10+'A';
}

int main()
{
	int a, b, i, length;
	char n[100];
	long num, pow;
	scanf("%d %s %d", &a, n, &b);
	length = strlen(n);
	pow = 1;
	num = 0;
	// get the number
	for (i=length-1; i>=0; i--)
	{
		num = num + char_to_num(n[i])*pow;
		pow = pow * a;
	}

	for (i=0; i<100; i++)
	{
		n[i] = num_to_char(num%b);
		num = num / b;
		if (num == 0)
			break;
	}
	for ( ; i>=0; i--)
		printf("%c", n[i]);
	printf("\n");
	
	return 0;
}
long pow(int m,int a)
{
     long p=1;
     for(int i=0;i<m;i++)p*=a;
     return p;
}
     


int main()
{
char s1[200],s2[200];
int a,b;
cin>>a>>s1>>b;
long n=0;
int lt=strlen(s1);
int i,j;
for(i=0;i<lt;i++)
{
                 if(s1[i]>='a' && s1[i]<='z')s1[i]=s1[i]-'a'+10;
                 else if(s1[i]>='A' && s1[i]<='Z')s1[i]=s1[i]-'A'+10;
                 else s1[i]-='0';
}
for(i=0;i<lt;i++)
n+=s1[i]*pow(lt-i-1,a);
j=0;
while(n>0)
{
        s2[j]=n%b;
        n/=b;
        j++;
}

for(i=0;i<j;i++)
{
                if(s2[i]<10)s2[i]+='0';
                else s2[i]+='A'-10;
}
for(i=0;i<j;i++)cout<<s2[j-1-i];
if(!j)cout<<'0';
cout<<endl;

  


          
          return 0;
}
int main()
{
  char s[100],v[100];
  int a,b,j,i,l,t=0;
  cin>>a;
  cin>>s;  
  cin>>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]+=('A'-10);
  }
  for(i=m-1;i>=0;i--)
  cout<<v[i];
  if(m==0)
	  cout<<0; 
}
int main()
{
    int i,k,r,l,x,t[40],s,a,b;
    char c[40],d[40];
    scanf("%d %s %d",&a,c,&b);
    l=strlen(c);x=0;
    for(i=0;i<l;i++)
    {
       if(c[i]>='A'&&c[i]<='Z')
          s=c[i]-'A'+10;
       else
        {
         if(c[i]>='a'&&c[i]<='z')
          s=c[i]-'a'+10;
         else
          s=c[i]-'0';
        }
        x=s+x*a;
    }
     k=0;
     r=x;
     for(i=0;i<40;i++)
     {
       t[i]=r%b;
       r=r/b;
       k++;
       if(r==0)
       break;
     }
     for(i=0;i<k;i++)
     {
       if(t[k-1-i]>=0&&t[k-1-i]<=9)
         d[i]=t[k-1-i]+'0';
       else
           if(t[k-1-i]>=10&&t[k-1-i]<=35)
         d[i]=t[k-1-i]-10+'A';  
     }
     for(i=0;i<k;i++)
     printf("%c",d[i]);
     getchar();
     getchar();
}
int main(){
int a,b,i=0,j=0,t=0;
double k,x;
char n[100],m[100];
cin>>a>>n>>b;
x=strlen(n);
for(i=0;i<x;i++)
{{if(n[i]>='A'&&n[i]<='Z')
k=n[i]-55;
else if(n[i]>='a'&&n[i]<='z')
k=n[i]-87;
else k=n[i]-48;}t=t+k*pow((double)a,x-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()
{
	int a = 0, i = 0;
	int b, j, num[100] = {0}, sum  = 0, flag1 = 0, flag2 = 0, l;
	char str1[100];
	cin >> a >> str1 >> b;
	l = strlen(str1);
	for (i = 0; i <= l - 1; i++)
	{
		if(str1[i] > 96)
			str1[i] = str1[i] - 87;
		else if (str1[i] > 64)
			str1[i] = str1[i] - 55; 
		else
			str1[i] = str1[i] - '0';
		sum = sum * a + str1[i];
	}
	for(j = 0; sum > 0; j++)
	{
		num[j] = sum % b;
		sum = sum / b;
	}
	j--;
	for(; j >= 0; j--)
	{
		if((num[j] != 0) && (flag1 == 0))
		{
			if(num[j] > 9)
			{
				num[j] = num[j] + 55;
				cout << (char)num[j];
			}
			else 
				cout << num[j];
			flag1 = 1;
			flag2 = 1;
			j--;
		}
		if(flag1 == 1)
		{
			if(num[j] > 9)
			{
				num[j] = num[j] + 55;
				cout << (char)num[j];
			}
			else 
				cout << num[j];
				flag2 = 1;
		}
	}
	if(flag2 == 0)
		cout << "0";
	return 0;
}
int mpow(int a,int b)
{
    int i,c=1;
    for(i=0;i<b;i++)c*=a;
    return c;
}


main()
{ 
	char a[10],d[10],c;
	int aa[10],b[10];
	int m=0,n=0,i=0,t=0,l=0,j=0,h=0;
	int s=0;
	
        scanf("%d%s%d",&m,a,&n);
	i=strlen(a);
	
        for(t=0;t<i;t++)
	{
		if(a[t]>=65 && a[t]<=90)
			aa[t]=a[t]-55;
	}
	
        for(t=0;t<i;t++)
	{
		if(a[t]>=97 && a[t]<=122)
			aa[t]=a[t]-87;
	}
	
        for(t=0;t<i;t++)
	{
		if(a[t]>=48 && a[t]<=57)
			aa[t]=a[t]-48;
	}
	


        for(h=0;h<i;h++)
	{
		t=aa[h]*mpow(m,i-h-1);
		s=s+t;
	}
	
	j=0;

	if (s==0)
		printf("0");

	while(s>=1)
	{
                b[j]=s%n; 
		j++;
		s=s/n;
	}
	
        j--;
	
        for(l=j;l>=0;l--)
	{
		if (b[l]>9) d[l]=b[l]+'A'-10;
		else d[l]=b[l]+'0';
	}
	
	for(l=j;l>=0;l--)
		printf("%c",d[l]);
	    printf("\n");
	
	
}
main()
{
 int i,j,a,b,x,n;
 long temp;
 char s[10];
 char p[10];
 scanf("%d %s %d",&a,s,&b);
 n=strlen(s);
 temp=0;
 for(i=0;i<n;i++)
 {
  if(s[i]>='a'&&s[i]<='z')
   temp=temp*a+s[i]-'a'+10;
  if(s[i]>='A'&&s[i]<='Z')
   temp=temp*a+s[i]-'A'+10;
  if(s[i]>='0'&&s[i]<='9')
   temp=temp*a+s[i]-'0';
 }
 for(x=0,i=0;;i++)
 {
  if(temp%b>=10) p[x]=temp%b-10+'A';
   else p[x]=temp%b+'0';
  x++;
  temp=temp/b;
  if (temp==0) break;
 }
 for(i=x-1;i>=0;i--)
  printf("%c",p[i]);
}
void main()
{
	int a,b,x[100],y[100],i,j,k,q;
	long n=0;
	scanf("%d",&a);
	q=getchar();
	for(i=0;;i++)
	{x[i]=getchar();
	if(x[i]==' ')break;
	}
	scanf("%d",&b);
	for(j=0;j<i;j++)
	{if(x[j]>=48&&x[j]<=57)
	    x[j]=x[j]-48;
	 if(x[j]>=65&&x[j]<=90)
		x[j]=x[j]-55;
     if(x[j]>=97&&x[j]<=122)
		x[j]=x[j]-87;
	}
	for(j=0;j<i;j++)
		n=a*n+x[j];
	if(n==0)printf("0");
	for(j=0;n!=0;j++)
	{y[j]=n%b;
	n=n/b;
	if(y[j]>=10)y[j]=y[j]+55;
	else
		y[j]=y[j]+48;
	}
	for(k=j-1;k>=0;k--)
		putchar(y[k]);
	printf("\n");
}
//*???????
//*??????????????????????2???36?????????long?????????
int main( )      //?????
{      //?????
	double a,b;      //????
	int i,L1,L2;
	char n[32],m[32];      //???????
	int p[32],q[32];
	cin >>a >>n >>b;
	L1=strlen(n);      //??n???
	for(i=0;i<L1;i++)
	{
		p[i]=n[i];
		if(p[i]>=97) p[i]=p[i]-87;
		else if(p[i]>=65) p[i]=p[i]-55;
		else p[i]=p[i]-48;
	}
	int dec=0;
	for(i=0;i<L1;i++)      //?n???10???
		dec=dec+p[i]*pow(a,L1-1-i);
	if(dec==0) cout <<"0";
	else
	{
		for(i=0;i<32;i++)
		if(pow(b,i)>dec) 
		{
			L2=i;
			break;
		}
		for(i=0;i<L2;i++)      //?10??????b???
		{
			q[i]=dec/(int)(pow(b,L2-1-i));
			dec=dec-q[i]*pow(b,L2-1-i);
		}
		for(i=0;i<L2;i++)
		{
			if(q[i]<10) m[i]=q[i]+48;
			else m[i]=q[i]+55;
		}
		m[L2]='\0';
		cout <<m;      //??b???
	}
return 0;      //???????????????????
}      //????