semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
//*************************************************************************
//???????????????????????????????????  *
// ???????????????????????????????0?bug?
//????????????                                                *
//*************************************************************************
//*************************************************************************
const int size=500;
char inda[size],outda[size];
int indata[size],yu[2*size],ddd[size];
int main()               //?????
{
    int i,j,k;double inbase,outbase,la,dec=0;
    int map[300];char rmap[65];
    for(i='A';i<='Z';i++) {map[i]=i-'A'+10;rmap[i-'A'+10]=i;}//??????????????????

    for(i='a';i<='z';i++) {map[i]=i-'a'+10;rmap[i-'a'+36]=i;}
    for(i='0';i<='9';i++) {map[i]=i-'0';rmap[i-'0']=i;}
	cin>>inbase>>inda>>outbase;
	la=strlen(inda);           
	for(i=0;i<=la-1;i++){indata[i]=map[inda[i]];}
	for(i=0;i<=la-1;i++){dec=dec+indata[i]*pow(inbase,la-i-1);}
	ddd[0]=dec;i=0;    //??????????????
   while(true)
   {if(i>0&&ddd[i]==0) break;
	   ddd[i+1]=ddd[i]/outbase;
   yu[i]=ddd[i]%(int)outbase;i++; }    
   yu[i]=ddd[i]%(int)outbase;    //????
  for(j=0;j<=i;j++)              
  {outda[j]=rmap[yu[j]];}     
  for(k=i-1;k>=0;k--)
	  cout<<outda[k];         //??

  return 0;
}
void numchange(int x, int y, char c[100]);
int main()
{
	int a, b;
	char s[100]={0};
         int i;
	scanf("%d", &a);
	scanf("%s", s);
	scanf("%d", &b);
         for(i=0;i<strlen(s);i++)
         {if(s[i]>='a') s[i]=s[i]-'a'+'A';}
	numchange(a,b,s);
         return 0;
}
void numchange(int x, int y, char c[100])
{
	int i, l, k=0;
	long int s=0;
	char m[100]={0};
	l = strlen(c);
	for(i=0;i<=l-1;i++)
	{
		if((c[i]>='0')&&(c[i]<='9'))
			s=s*x+c[i]-'0';
		if((c[i]>='A')&&(c[i]<='Z'))
			s=s*x+c[i]-'A'+10;
	}
	for(i=0;;i++)
	{
		if(y<=10) m[i] = s%y+'0';
		else 
		{
			if(s%y<10) m[i] = s%y + '0';
			else m[i] = s%y - 10 + 'A';
		}
		s = (s-s%y)/y;
		k++;
		if(s==0) break;
	}
	for(i=k-1;i>=0;i--)
		printf("%c", m[i]);
}
int main()
{
      long k=0,a,b,i,h=0,c;
      unsigned int e[100];
      char n[100];
      long l[10000];
      long t[10000];
      scanf("%d %s %d",&a,n,&b);
      c = strlen(n);
      for(i=0;i<=c-1;i++)
      {
            if(n[i]>='0'&& n[i]<='9')
            n[i]=n[i]-('0'-0);
            if(n[i]<='Z' && n[i]>='A')
            n[i]=n[i]-('A'-10);
            if(n[i]>='a' && n[i]<='z')
            n[i]=n[i]-'a'+10;
            h=a*h+n[i];      
      }
      if(h==0)
      printf("0");
      for(i=0;h>0;i++)
      {
            e[i]=h%b;
            h=h-e[i];
            h=h/b;
            k=k+1;
      }
      for(i=0;i<=k-1;i++)
      {
            n[i]=e[k-1-i];
            if (n[i]>9)
            n[i]=n[i]+'A'-10;
            else
            n[i]=n[i]+'0';
      }
      n[k]='\0';
      printf("%s\n",n);
      getchar();
      getchar();
      getchar();
      getchar();
return 0;
}
int main()
{
    long int a,b,i,j,n,digit,sum,remain[1000];
    char num[1000],c;
    scanf("%d %s %d",&a,num,&b);
    n=strlen(num);
    sum = 0;
    for (i=0;(c=num[i])!='\0';i++)
    {
        if (isupper(c)!=0)
           digit = (int)(c-'A'+10);
        if (islower(c)!=0)
           digit = (int)(c-'a'+10);  
        if (isdigit(c)!=0)
           digit = (int)(c-'0');
        sum += (int)(digit*pow(a,n-i-1));
           }    
    if (sum==0) printf("%d",sum);
    else
    {
    for (i=0;sum!=0;i++)
       {
            remain[i] = sum%b;
            sum = sum/b;
        }
    for (j=i-1;j>=0;j--)
    {
        if (remain[j]<=9) printf("%d",remain[j]);
        if (remain[j]>9)
        { 
           remain[j] = remain[j]- 10 + (int)'A';
           printf("%c",remain[j]);
           }
        }
    printf("\n");
}
getchar();
getchar();
}
int main()
{
   char x[200],y[200];
   int a,b,i,j,num[200];
   long int n=0;
   cin>>a;
  cin>>x;
   cin>>b;
   int nlen1=strlen(x);
 
   for(i=0;i<=nlen1-1;i++)
   {
       if(x[i]>='0'&&x[i]<='9')
		   num[i]=x[i]-'0';
	   else if(x[i]>='a'&&x[i]<='z')
		   num[i]=x[i]-'a'+10;
	   else if(x[i]>='A'&&x[i]<='Z')
		   num[i]=x[i]-'A'+10;
	   n=n*a+num[i];	}
if(n!=0)
{
   for(i=0;n>=b;i++)
   {
       num[i]=n%b;
	   n=(n-num[i])/b;
   }
   if(n>0)num[i]=n;
   else i-=1;
   for(j=i;j>=0;j--)
   {
      if(num[j]>=0&&num[j]<=9)
		  cout<<num[j];
	  else
	  {y[j]=num[j]-10+'A';
	  cout<<y[j];}
   }
}
else cout<<0;

return 0;
	  
	   
}
int main()
{
	int a,b,x,n,i,j = 0,k,h,m,num1 = 0;
	char str[100],num[100];
	cin >> a >> str >> b;
	n = strlen(str);
	for(i = 0; i < n; i++)
	{
		int y = 1;
		for(m = 0; m < n - 1 - i;m++)
		{	
			y = y * a;
		}
		if(str[i] <= '9')
			num1 = num1 + (str[i] - '0') * y;
		if((str[i] >= 'A')&&(str[i] < 'a'))
			num1 = num1 + (str[i] - 'A' + 10) * y;
		if(str[i] >= 'a')
			num1 = num1 + (str[i] - 'a' + 10) * y;
	}
	x = num1;
	do
	{
		num1 = num1 / b;
		j++;                        
	}while(num1 > 0);
    for(k = 0 ; k < j; k++)
    {   
	    if(x % b < 10)
			num[j - 1 - k] = x % b + 48;
		if(x % b >= 10)
			num[j - 1 - k] = x % b + 55;
		x = x / b;
	}
	for(h = 0; h < j ; h++)
		cout << num[h];
	return 0;
}
int main()
{
	int a, b, num = 0 , e[100], f[100] = {0}, i, j, l;
	char c[100], d[100];
	cin >> a;cin.get();
	cin >> c;l = strlen(c);
	cin >> b;
	for(i = 0; i < l; i++)
	{
		if(c[i] >= '0' && c[i] <= '9') e[i] = c[i] - '0';
		else if(c[i] >= 'a' && c[i] <= 'z') e[i] = c[i] - 'a' + 10;
		else e[i] = c[i] - 'A' + 10;
		num = num * a + e[i];
	}
	if(num == 0) cout << "0" << endl;
	else 
	{i = 0;
	while(num!= 0)
	{
		f[i++] = num % b;
		num /= b;
	}
	for(j = i - 1;j >= 0; j--)
	{
		if(f[j] >= 0 && f[j] <= 9) d[j] = f[j] + '0';
		else d[j] = f[j] - 10 + 'A';
		cout << d[j] ;
	}
	cout << endl;
	}




	//cout << num << endl;
	return 0;
}
int main()
{
	char n[1000];
	int a,b,i,j=0,num=0,m[1000];
	cin>>a>>n>>b;
	int length=strlen(n);
	for(i=0;i<length;i++)
	{
		if(n[i]>64 && n[i]<91) n[i]+=32;
	}
	for(i=0;i<length;i++)
	{
		if(n[i]>96 && n[i]<123)
		{
			num+=(n[i]-'a'+10)* pow ( (double)a ,(double)(length-1-i) );
		}
		else num+=(n[i]-'0') * pow( (double)a , (double)(length-1-i) );
	}
	
	for(i=0;;i++)
	{
		m[i] = num % b;
		num = num/b;
		j++;
		if(num==0) break;
	}
	for(i=j-1;i>=0;i--)
	{
		if(m[i]>9) cout<<(char)(m[i]-10+'A');
		else cout<<m[i];
	}
	return 0;
}
void main()
{
	int l,x,y,i,j;
	long n;
	char a[100],b[100];
	n=0;
	scanf("%d %s %d",&x,a,&y);
	l=strlen(a);
	for(i=0;i<l;i++)
	{
		if(a[i]<58)
			n=x*n+a[i]-48;
		else if(a[i]>96)
			n=x*n+a[i]-87;
		else
			n=x*n+a[i]-55;
	}
	for(i=0;n!=0;i++)
	{
		if(n%y<10)
			b[i]=n%y+48;
		else
			b[i]=n%y+55;
		n=(n-n%y)/y;
	}
	if(i==0)
		printf("0");
	for(j=i-1;j>=0;j--)
		printf("%c",b[j]);
	printf("\n");
}
void main()
{
	int a,b,m=0,i,c[100],k=1,e=0,d=0;
	long sum=0;
	char n[100];
	scanf("%d%s%d",&a,n,&b);
	m=strlen(n);
	for(i=0;n[i]!='\0';i++)
	{
		if(n[i]>='a')
			c[i]=(int)(n[i])-87;
		else if(n[i]>='A')
			c[i]=(int)(n[i])-55;
		else
			c[i]=(int)(n[i])-48;
	}
	for(i=m-1;i>=0;i--)
	{
		sum+=c[i]*k;
		k*=a;
	}
	for(i=0,k=1;sum>0;i++)
	{
		c[i]=sum%b;
		sum=(sum-c[i])/b;
		k*=b;
		e++;
	}
	for(i=e-1;i>=0;i--)
	{
		if(c[i]<10)
			n[i]=(char)(c[i]+48);
		else
			n[i]=(char)(c[i]+55);
		printf("%c",n[i]);
		d=1;
	}
	if(d==0)
		printf("0");
}
struct stack  
{  
    char data[MAX];  
    int top;  
};  
  
long int switchToTen(int a, char *s);  
  
int main()  
{  
    long int a, b, n;  
    char str[MAX];  
  
    while(scanf("%ld %s %ld", &a, str, &b) != EOF)  
    {  
        n = switchToTen(a, str);  
        if(n == 0)  
        {  
            printf("0");  
        }else  
        {  
            int temp;  
            struct stack *s = (struct stack *)malloc(sizeof(struct stack));  
            s->top = 0;  
  
            while(n)  
            {  
                temp = n % b;  
                if(temp >= 0 && temp <= 9)  
                {  
                    s->data[s->top ++] = temp + '0';  
                }else  
                {  
                    s->data[s->top ++] = temp - 10 + 'A';  
                }  
                n /= b;  
            }  
  
            while(s->top)  
            {  
                printf("%c", s->data[-- s->top]);  
            }  
        }  
        printf("\n");  
    }  
  
    return 0;  
}  
  
  
long int switchToTen(int a, char *s)  
{  
    int i, b;  
    long int n, c;  
  
    for(n = 0, c = 1, i = strlen(s) - 1; i >= 0; i --)  
    {  
        if(s[i] >= 'A' && s[i] <= 'Z')  
            b = s[i] - 55;  
        else if(s[i] >= 'a' && s[i] <= 'z')  
            b = s[i] - 87;  
        else  
            b = s[i] - '0';  
        n += b * c;  
        c *= a;  
    }     
  
    return n;  
}
int main()
{    int a,b,i,j=0,decimal,number=0;
  char n[20],m[20];
  cin>>a>>n>>b;
  for(i=0;n[i]!='\0';i++)
	  if (n[i]>='a'&&n[i]<='z') n[i]-=32;
  for(i=0;n[i]!='\0';i++)
  {   if(n[i]>='0'&&n[i]<='9') decimal=n[i]-'0';
  else decimal=n[i]-'A'+10;
  number=a*number+decimal;
  }
  while (number>=b)
  { if((number%b)>=10) 
	  m[j]=number%b-10+'A';
  else m[j]=number%b+'0';
     number=number/b;
	 j++;
  }
  if(number>=10) m[j]=number-10+'A';
  else m[j]=number+'0';
   for(i=j;i>=0;i--)
	   cout<<m[i];

  
  
	return 0;
}
void MyStrupr(char *p)
{
    int i = 0;
    for (i = 0; i < strlen(p); i++)
    {
        if ((p[i] >= 'a') && (p[i] <= 'z'))
        {
            p[i] -= 32;
        }
    }
}

void main()
{
    int a, b, s, i, j, k, m[100];
    long int x;
    char n[100], t[100];

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

    MyStrupr(n);
    s = strlen(n);
    x = 0;

    for(i = 0; i <= s-1; i++)
    {
        if((n[i] >= 'A') && (n[i]<='Z'))
        {
            m[i] = n[i] - 55;
        }
        else
        {
            m[i] = (int)(n[i]) - 48;
        }

        x = (long)(x + pow(a, (s-1-i)) * m[i]);
    }

    j = 0;
    while(x >= b)
    {
        m[j] = x%b;
        if(m[j] > 9)
        {
            t[j] = m[j] + 55;
        }
        else 
        {
            t[j] = m[j] + 48;
        }

        x = x/b;
        j++;
    }

    if(x > 9) 
    {
        t[j] = x + 55;
    }
    else 
    {
        t[j] = x+48;
    }

    for(i = 0; i <= j; i++)
    {
        printf("%c", t[j - i]);
    }
    printf("\n");

}
int main()
{
	char str[50],dest[50]={'\0'},trans[36];//??????????????
	                                        //trans[36]:???0~35???'0'~'9','A'~'Z'????
	int a,b,i,d,len;
	long num=0;                             //long??4???????????????31?
	for(i=0;i<10;i++)
		trans[i]='0'+i;
	for(i=10;i<36;i++)
		trans[i]='A'+i-10;
	cin>>a>>str>>b;
	for(i=0;str[i]!='\0';i++){                //?????a???????????
		if(str[i]>='0' && str[i]<='9')
			d=str[i]-'0';
		else if(str[i]>='a' && str[i]<='z')
			d=str[i]-'a'+10;
		else if(str[i]>='A' && str[i]<='Z')
			d=str[i]-'A'+10;
		num=num*a+d;                                  
	}                                         //????????????num
	i=0;
	do{                                       //???b?????????dest???
		dest[i++]=trans[num%b];               //???num==0???
		num=num/b;
	}while(num!=0);
	len=strlen(dest);                          //????????????dest????
	for(i=len-1;i>=0;i--)                      //????
		cout<<dest[i];
	return 0;
}
main()
{
  int i,j,d,b,s;
  int a[10000];
  char c[10000];
  scanf("%d %s %d",&d,c,&b);
  //d=15;
  //b=7;
  s=0;
  if(c[0]-'0'==0){printf("0");}
  else
  {for(i=0;c[i]!='\0';i++)
  {
      if(c[i]>='a'&&c[i]<='z'){c[i]=c[i]-32;}                   
      if(c[i]>=65&&c[i]<=90){a[i]=c[i]-55;}
      //if(c[i]>='A'&&c[i]<='Z'){a[i]=c[i]-'0'+10;printf("%d\n",a[i]);}
      else                   
      {a[i]=c[i]-'0';}
      //printf("%d\n",a[i]);                   
  }
  //printf("%d\n",i);
  for(j=0;j<i;j++)
  {
   s=d*s+a[j];               
                  
  }
  for(i=0;s!=0;i++)
  {
     a[i]=s%b;              
     s=s/b;
     
   // printf("%d\n",a[i]); 
     if(a[i]>=10)
     {
       c[i]='A'+a[i]-10;          
     }
     else
     {c[i]=a[i]+'0';}
     // printf("%c\n",c[i]);
       //printf("%d\n",i);            
  }
  
  for(j=i-1;j>=0;j--)   
  {
   printf("%c",c[j]);                   
  }
}    
getchar();
getchar();
 getchar();     
}
int main()
{
	int a,b,i=0,j=0,s=0,temp;                         //????a?b?????i?j?????temp
	char str1[32],str2[32];                           //?????str1,str2
	cin>>a>>str1>>b;                                  //?????a,str1,b
	do
	i++;
	while(str1[i]!='\0');                             //?????str1???
	for(int k=0;k<i;k++)
	{
		if(str1[k]>96)
			str1[k]-='a'-10;
		else if(str1[k]>64)
			str1[k]-='A'-10;
		else
			str1[k]-='0';                   //??????????????????
		s+=str1[k]*(int)pow((double)a,i-1-k);    //??str1?????
	}
	do
	j++;
	while(s>pow((double)b,j));                        //????????
	for(int l=0;l<j;l++)
	{
		temp=s/pow((double)b,j-l-1);
		if (temp<10)
			str2[l]=temp+'0';
		else
			str2[l]=temp-10+'A';
		s-=temp*pow((double)b,j-l-1);
	}                                                 //?????????????
	str2[j]='\0';                                     //?str2????????\0????????
	cout<<str2;                                       //????
	return 0;
}
const long maxL=100;

long a,b;
char str[maxL+1];

long ans[maxL+1];

main(){
    long i,l,x;
    scanf("%ld%s%ld",&a,str,&b);
    l=strlen(str);
    x=0;
    for(i=0;i<l;i++){
	x*=a;
	if(str[i]>='0' && str[i]<='9')
	    x+=str[i]-'0';
	else if(str[i]>='a' && str[i]<='z')
	    x+=str[i]-'a'+10;
	else
	    x+=str[i]-'A'+10;
    }
    l=0;
    while(x>0){
	ans[l]=x%b;
	x/=b;
	l++;
    }
    if(l==0)ans[++l]=0;
    for(i=l-1;i>=0;i--){
	if(ans[i]<10)printf("%ld",ans[i]);
	else printf("%c",ans[i]-10+'A');
    }
    return 0;
}
int main()
{
	char a[100],b[100];   //?a???????b??????
	int i,j;
	for(i=0;i<100;i++)
		b[i]=0;
	int n1,n2,m=0;
	
	double dn1; 


	cin>>n1>>a>>n2;
	int lena=strlen(a);
	for(i=0;i<lena;i++)
	{
		if(a[i]>='a' && a[i]<='z')     //?????????????
		{a[i]=a[i]-'a'+10;}
		else if(a[i]>='A' && a[i]<='Z')
		{a[i]=a[i]-'A'+10;}
		else 
		{a[i]=a[i]-'0';}      //????ASCII?????
	}
	for(i=0;i<lena;i++)
	{
		dn1=n1;
		m=m+a[i]*pow(dn1,lena-i-1); //???????10???
	}

	i=1;
	do
	{
		b[i]=m%n2;          //?10??????n2???
		m=m/n2;
		i++;
	}
	while(m!=0);
	int t=i-1;
	for(j=t;j>0;j--)
	{
		if(b[j]>=0 && b[j]<=9)  //?b???????????ASCII????
		{b[j]=b[j]+'0';}
		else if(b[j]>=10)
		{b[j]=b[j]-10+'A';}
		cout<<b[j];
	}
	cout<<endl;
	return 0;
}
long change1(char a[],int n1)
{
	int s=0,temp;
	int len,i;
	len=strlen(a);
	
	for(i=0;i<len;i++)
	{
		if(a[i]>='0'&&a[i]<='9')
			temp=a[i]-'0';
		if(a[i]>='a'&&a[i]<='z')
			temp=a[i]-'a'+10;
		if(a[i]>='A'&&a[i]<='Z')
			temp=a[i]-'A'+10;
		
		s=s*n1+temp;
	
	}
	
	return s;
}

void change2(long s,int n2,char b[])
{
	int i=0,j;
	int temp,add;
	while(s>0)
	{
		add=s%n2;
		
		if(add>=10)
		{
			b[i]=add-10+'A';
		}
		else
			b[i]=add+'0';
       
        
		i++;
		s=s/n2;
	
	}
		for(j=0;j<=i/2-1;j++)
		{
			temp=b[j];
			b[j]=b[i-1-j];
			b[i-1-j]=temp;
		}
}
	
	

void main()
{
	char a[50]={0},b[50]={0};
	int n1,n2,len,i;
	long s;
	scanf("%d%s%d",&n1,a,&n2);
	
	s=change1(a,n1);
	
	change2(s,n2,b);
    len=strlen(b);
	if(len>0)
	{
	for(i=0;i<len;i++)
	   printf("%c",b[i]);
	printf("\n");
	}
	if(len==0)
		printf("0\n");
}
int main()
{
	char input[100], output[100];
	int in, out, num = 0, tmp, tmp1;
	cin >> in >> input >> out;
	for (int i = 0; input[i] != '\0'; i++)
	{
		if (input[i] > 47 && input[i] < 58)
			tmp = input[i] - 48;
		else if (input[i] > 64 && input[i] < 91)
			tmp = input[i] - 55;
		else
			tmp = input[i] - 87;
		num = num * in + tmp;
	}
	int i = 0;
	for (;num != 0; i++)
	{
		tmp1 = num % out;
		if (tmp1 < 10)
			output[i] = tmp1 + 48;
		else
			output[i] = tmp1 + 55;
		num /= out;
	}
	if (i == 0)
	{
		output[i] = 48;
		i++;
	}
	for (int j = i - 1; j >= 0; j--)
	{
		cout << output[j];
	}
	cout << endl;

	return 0;
}
int main()
{
	double a,b,d;
	int e[1000];
	char c[1000];
	cin>>a>>c>>b;
	d=strlen(c);
	for(int i=0;i<d;i++)
	{
		if(c[i]>='0'&&c[i]<='9')
		{
			e[i]=c[i]-48;
		}
		else if(c[i]>='A'&&c[i]<='Z')
		{
			e[i]=c[i]-55;
		}
		else if(c[i]>='a'&&c[i]<='z')
		{
			e[i]=c[i]-87;
		}
	}
	long long num=0;
	for(int i=0;i<d;i++)
	{
		num=num+e[i]*pow(a,(d-i-1));
	}
	long long k[1000];
	long long sum;
	sum=num;
	int t=-1;
	int m;
	m=b/1;
	for(int i=0;i<1000;i++)
	{
		k[i]=sum%m;
		sum=sum/m;
		t=t+1;
		if(sum<1)break;
	}
	char l[1000];
	for(int i=0;i<=t;i++)
	{
		if(k[t-i]>=0&&k[t-i]<=9)
		{
			l[i]=k[t-i]+48;
		}
		else if(k[t-i]>=10&&k[t-i]<=35)
		{
			l[i]=k[t-i]+55;
		}
	}
	for(int i=0;i<=t;i++)
	{
		cout<<l[i];
	}
	cout<<endl;
	
	return 0;
}
int zhuan(int a,char n[])
{
    long int d=0;
    int c,i,j;
    for(i=0;n[i]!='\0';i++)
      {
         if(n[i]>=48&&n[i]<=57)
            c=n[i]-48;
         else if(n[i]<=90&&n[i]>=65)
            c=n[i]-55;
         else if(n[i]>=97&&n[i]<=122)
               c=n[i]-87;
         for(j=i+1;n[j]!='\0';j++) 
             c=c*a;
         d=d+c;
      }
    return d;
}
void huan(int b,long int c)
{
   int d,i,j;
   char n[100];
   if(c==0)
      printf("0\n");
   for(i=0;c!=0;i++)
     {
         d=c%b;
         c=c/b;
         if(d<=9&&d>=0)
            n[i]=d+48;
         else if(d>=10&&d<=35)
            n[i]=d+55;
     }
     for(j=i-1;j>0;j--)
       printf("%c",n[j]);
     printf("%c\n",n[0]);
}
int main()
{   
    int a,b;
    long int c;
    char n[100];
    scanf("%d %s %d",&a,n,&b);
    c=zhuan(a,n);
    huan(b,c);
    return 0;
}
int ten(int m)
    { int z;
      if(48<=m&&m<=57)
         z=m-48;   
      else if(65<=m&&m<=90)
         z=m-55;
      else if(97<=m&&m<=122)
         z=m-87;
      return (z);
      }
    char letter(int p)
    {  int k;
       if(0<=p&&p<=9)
       k=p+48;
       else if(10<=p&&p<=26)
       k=p+55;
       return (k);
       }
int main()
{
    long int a1,b1,a[1001],b[1001],tensum=0,n,i;
    long a1_;
    cin>>a1;
    a1_=a1;
    getchar();
    for(i=1;i<=1000;i++)
    {
    a[i]=getchar();
    if(a[i]==32)
    break;
    }
    n=i-1;
    cin >>b1;
    tensum=ten(a[n]);
    for(i=n-1;i>0;i--)
    {tensum=a1_*ten(a[i])+tensum;
    a1_=a1_*a1;
    }
    i=1;
    do
    {
    b[i]=tensum%b1;
    tensum=tensum/b1;
    i++;}
    while(tensum>0);
    for(i=i-1;i>0;i--)
    putchar(letter(b[i]));
    return 0;
}
long int f(int ia[],int m,int la);
void main()
{
	char a[200],b[200];
	int m,n,la,i,j,ia[200],ib[200],t;
	long int sum;
	scanf("%d",&m);
	scanf("%s",a);
	scanf("%d",&n);
	la=strlen(a);
	for(i=0;i<la;i++)
	{
		if(a[i]>='0'&&a[i]<='9')
			t=a[i]-'0';
		else if(a[i]>='a'&&a[i]<='z')
			t=a[i]-'a'+10;
		else if(a[i]>='A'&&a[i]<='Z')
			t=a[i]-'A'+10;
		ia[la-i-1]=t;
	}
	sum=f(ia,m,la);
	if(sum==0)
		printf("%d",sum);
	for(i=0;sum!=0;i++)
	{
		ib[i]=sum%n;
		sum=sum/n;
	}
	
	for(j=0;j<i;j++)
	{
		if(ib[j]<10)
			b[i-1-j]=ib[j]+'0';
		else if(ib[j]>9)
			b[i-1-j]=ib[j]-10+'A';
	}
	for(j=0;j<i;j++)
		printf("%c",b[j]);


}
long int f(int ia[],int m,int la)
{
	int i,j;
	long int sum=0,num;
	for(i=0;i<la;i++)
	{
		num=1;
		for(j=0;j<i;j++)
			num=num*m;
		sum=sum+num*ia[i];
	}
	return(sum);
}
/*???????
  ??????
  ???1100012802*/

void trans(int num,int b)
{
	int m;
	char l;
	if(num != 0)
	{
		m = num % b;
		if(m >= 10)
			l = 'A' + m - 10;
		else
			l = m + '0';
		num = num / b;
		trans(num,b);
		cout << l;
	}
}

void shuzhi(char m[],int a,int b)
{
	int i = 0,temp,num = 0;//i?????
	while(m[i] != ' ')
	{
		if(m[i] >= 'a' && m[i] <= 'z')
			temp = m[i] - 'a' + 10;
		else if(m[i] >= 'A' && m[i] <= 'Z')
			temp = m[i] - 'A' + 10;
		else
			temp = m[i] - '0';
		num = num * a + temp;
		i++;
	}
	if(num == 0)
		cout << 0;
	else
		trans(num,b);
}

int main()
{
	char a[20];
	int z1,z2,i = -1;
	cin >> z1;
	cin.get();
	do
	{
		i++;
		a[i] = cin.get();
	}while(a[i] != ' ');
	cin >> z2;
	shuzhi(a,z1,z2);
	return 0;
}
int main()
{
    int a,b,i;
    char num[100];
    long sum=0;
    int temp;
    char ans[100];
    scanf("%d %s %d",&a,num,&b);
    int len;
    len=strlen(num);
    for(i=0;i<len;i++)
    {
        if((num[i]>='0')&&(num[i]<='9')){sum*=a;sum+=num[i]-'0';}
        if((num[i]>='A')&&(num[i]<='Z')){sum*=a;sum+=num[i]-'A'+10;}
        if((num[i]>='a')&&(num[i]<='z')){sum*=a;sum+=num[i]-'a'+10;}
    }
    for(i=0;;i++)
    {
        temp=sum%b;
        sum=sum/b;
        if(temp<10)ans[i]=temp+'0';
        else ans[i]=temp-10+'A';
        if(sum==0)break;
    }
    for(int j=i;j>=0;j--)
    {
        printf("%c",ans[j]);
    }


        
        





    return 0;
}
int main()
{
	char str[50]; long a=0,b=0;	//?????str[50],?????????????????????a,b, ??????????????
    long i=0; //??????i?
	long n=1,s=0; //n??a??????1????????s???????????
	cin>>a;
	for(i=0;i<50;i++)
	{
		str[i]=getchar();  //????????????????????str[i]?
		if((str[i]==' ')&&(i>0))
			break;
	}
	i=i-1;
	for(i;i>0;i--)   //?a???????????
	{
		if((str[i]<58)&&(str[i]>47))
		{
			str[i]=str[i]-48;
		}
        else if((str[i]>64)&&(str[i]<91))
		{
			str[i]=str[i]-55;
		}
		else if(str[i]>96)
		{
			str[i]=str[i]-87;
		}
    	s=s+str[i]*n;
		n=n*a;
	}

	cin>>b;
	char c='A',d='A'; //????c?d??????????????????A?
	long j=0,k=10,q=10; //??????j,k,q????????0?10,10?
	int r[50]; //?????r[50]???????????
	while(s>=b)  //?s???b????????
	{
		r[j]=s%b;
		s=s/b;
		j++;
	}
	j=j-1;
	if(s<=9)
	{
		cout<<s;
	}
	else
	{
		for(q=10;q<36;q++)
			{
				if(s==q)
				{
					cout<<d;
					break;
				}
				d=d+1;
			}
			d='A';
	}
	for(j;j>=0;j--)  
	{
		if(r[j]<=9)
		{
			cout<<r[j];
		}
		else
		{
			for(k=10;k<36;k++)
			{
				if(r[j]==k)
				{
					cout<<c;
					break;
				}
				c=c+1;
			}
			c='A';
		}
	}
	cin.get();cin.get();
	return 0;
}
void main()
{
int m,n;
char a[100];
scanf("%d %s %d",&m,a,&n);
int x,i;
long int t=0;
x=strlen(a);
for(i=0;i<=x-1;i++)
	{if(a[i]>='0'&&a[i]<='9')t=t*m+a[i]-48;
	else if(a[i]>='a'&&a[i]<='z')t=t*m+a[i]-87;
	else if(a[i]>='A'&&a[i]<='Z')t=t*m+a[i]-55;}

char b[100];
for(i=0;i<=99;i++) b[i]='\0';
for(i=99;t!=0;i--)
	{if(t%n>=0&&t%n<=9) {b[i]=t%n+48;t=t/n;}
	else if(t%n>=10) {b[i]=t%n+55;t=t/n;}
	}
for(i=0;b[i]=='\0'&&i<=99;i++){}
if(i==100) printf("0");
for(i;i<=99;i++) {putchar(b[i]);}

printf("\n");
}
int main()
{
double a;int b;
char c[1000];
cin>>a;
cin>>c;
cin>>b;
double num=0;
int 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]-87;
	if(c[i]<='Z'&&c[i]>='A')
		x[i]=c[i]-55;
	if(c[i]>='0'&&c[i]<='9')
		x[i]=c[i]-48;
}
for(i=0;i<len;i++)                        //
{	num+=x[i]*pow(a,len-1-i);}
remain=num;

int p=0;
while(remain>0)
{
	o[p]=remain%b;
	remain=(remain-o[p])/b;
	p++;
}
for(i=0;i<p;i++)
{
	if(o[i]>=10)
		m[i]=o[i]+55;
	else
		m[i]=o[i]+48;
}
for(i=p-1;i>=0;i--)
	cout<<m[i];
if(p==0)
    cout<<0<<endl;
return 0;

}
char n[10000000], result[10000000];
long int exchange = 0;

void change(int a, char t[], int b)
{
	int len, i, j, k, temp, temp2, pow = 1;
	len = strlen(t);
	i = len - 1;
	j = 0;
	while (i >= 0)
	{
		if (t[i] >= 'A' && t[i] <= 'Z')
			temp = 10 + t[i] - 'A';
		else
		{
			if (t[i] >= 'a' && t[i] <= 'z')
			temp = 10 + t[i] - 'a';
			else
				temp = t[i] - '0';
		}
		exchange = exchange + temp * pow;
		pow = a * pow;
		i--;
		j++;
	}
	if (exchange == 0)
		cout << 0;
	else
	{
		j = 9999999;
		while (exchange != 0)
		{
			temp2 = exchange % b;
			if (temp2 >= 0 && temp2 <= 9)
				result[j] = temp2 + 48;
			else
				result[j] = temp2 + 55;
			exchange = exchange / b;
			j--;
		}
		for (k = j + 1; k < 10000000; k++)
			cout << result[k];
	}
}

int main()
{
	int a, b;
	cin >> a;
	cin >> n;
	cin >> b;
	change(a, n, b);
	return 0;
}
int main()
{
    int a,b,i,l,t=0,x;
	long m=0;
	char n[2][100];
	scanf("%d %s %d",&a,n[0],&b);
	l=strlen(n[0]);
	if (a<=10)
	{
		for(i=0;i<l;i++)
		{
			m=m*a+n[0][i]-'0';
		}
	}
	else
	{
        for(i=0;i<l;i++)
		{
			if((n[0][i]>='0')&&(n[0][i]<='9'))
				m=m*a+n[0][i]-'0';
		    if((n[0][i]>='A')&&(n[0][i]<='Z'))
                m=m*a+n[0][i]-'A'+10;
            if((n[0][i]>='a')&&(n[0][i]<='z'))
                m=m*a+n[0][i]-'a'+10;
		}
	}
	x=m;
	while(x>=b)
	{
		x=x/b;
		t++;
	}
	for(i=t;i>=0;i--)
	{
		if(m%b>=0&&m%b<10)
		{
		    n[1][i]=m%b+'0';
           	m=(m-n[1][i]+'0')/b;
		}
		else if(m%b>=10&&m%b<36)
		{
            n[1][i]=m%b-10+'A';
	       	m=(m-n[1][i]-10+'A')/b;
		}
	}
    for(i=0;i<=t;i++)
	    printf("%c",n[1][i]);
	return 0;
}