semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
char output[128] = {0};
int toDec(char* s, int a) {
	int ret = 0;
	int len = strlen(s);
	int mul = 1;
	for (int i =  len - 1; i >= 0; --i) {
		if (isupper(s[i]))
			ret += (s[i] - 'A' + 10) * mul;
		else if(islower(s[i]))
			ret += (s[i] - 'a' + 10) * mul;
		else
			ret += (s[i] - '0') * mul;
		mul *= a;
	}
	return ret;
}

void convert(char *s, int a, int b) {
	int tmp = toDec(s, a);
	int rem;
	memset(s, 0, sizeof(s));
	if (tmp == 0) {
		printf("0");
		return;
	}
	while (tmp) {
		rem = tmp % b;
		if (rem >= 10)
			rem = rem - 10 + 'A';
		else
			rem += '0';
		sprintf(output + strlen(output), "%c", rem);
		tmp /= b;
	}
	int len = strlen(output);
	for (int i = len - 1; i >= 0; i--)
		printf("%c", output[i]);
	printf("\n");
}
int main() {
	int a, b;
	char s[1001] = {0};
	scanf("%d%s%d", &a, s, &b);
	convert(s, a, b);
}
int main()
{
	long int a,b,sum,d;
	int i=0,j;
	char n[20],e[20]={0};
	scanf("%d%s%d",&a,n,&b);
	for(i=0,sum=0;n[i]!='\0';i++)
	{
		if(n[i]>='0'&&n[i]<='9')
			d=n[i]-'0';
		else
			if(n[i]>='a'&&n[i]<='z')
				d=n[i]-'a'+10;
			else
				if(n[i]>='A'&&n[i]<='Z')
					d=n[i]-'A'+10;
		sum=sum*a+d;
	}
	for(i=0;sum>=b;i++)
	{
		d=(sum%b);
		if(d<=9)
			e[i]=d+'0';
		else
			if(d>9)
				e[i]=d-10+'A';
			sum=(sum-d)/b;
	}
    if(sum<=9)
			e[i]=sum+'0';
		else
			if(sum>9)
				e[i]=sum-10+'A';
	for(j=i;j>=0;j--)
		printf("%c",e[j]);
	return 0;
}
void main()
{
	int i,j,a,b;
	long x=0,t=1;
	char n[50],m[50];
	for(i=50;i>=0;i--)
	{
		m[i]='\0';
		n[i]='\0';
	}
	scanf("%d",&a);
	scanf("%s",n);
	scanf("%d",&b);
	for(i=50;i>=0;i--)
	{
		if(n[i]!='\0')
		{
			for(j=i;j>=0;j--)
			{
				if(n[j]>=48&&n[j]<=59)
				{
					x=x+(n[j]-48)*t;
					t=t*a;
				}
				if(n[j]>=65&&n[j]<=90)
				{
					x=x+(n[j]-55)*t;
					t=t*a;
				}
				if(n[j]>=97&&n[j]<=122)
				{
					x=x+(n[j]-87)*t;
					t=t*a;
				}
			}
			if(j==-1)
				break;
		}
	}
	for(i=50;i>=0;i--)
	{
		if(x==0)
			break;
		if(b<=10)
		{
			m[i]=x%b+48;
			x=x/b;
		}
		if(b>10)
		{
			if(x%b<=9)
				m[i]=x%b+48;
			if(x%b>=10)
				m[i]=x%b+55;
			x=x/b;
		}
	}
	for(i=0;i<=50;i++)
	{
		if(m[i]!='\0')
		{
			for(j=i;j<=50;j++)
				printf("%c",m[j]);
			break;
		}
		if(i==50&&m[i]=='\0')
			printf("0");
	}
	printf("\n");
}
int f(int x,int y)
{
	int j,p=1;
	for(j=0;j<y;j++)
		p=p*x;
	return(p);
}
  int main()
{
	char a[100];
	int i,m,n,p[100],t[100],q;
	long int num=0;
	scanf("%d %s %d",&m,a,&n);
	q=strlen(a);
	for(i=0;i<q;i++)
	{
		if(a[i]>='a'&&a[i]<='z')
			a[i]=a[i]+'A'-'a';
		if(a[i]>='0'&&a[i]<='9')
			p[i]=a[i]-'0';
		else if(a[i]>='A'&&a[i]<='Z')	
			p[i]=a[i]-'A'+10;
	}
	for(i=q-1;i>=0;i--)
		num=num+p[i]*f(m,q-i-1);	
	for(i=0;num>=n;i++)
	{
		t[i]=num%n;
		num=num/n;
	}
	t[i]=num%n;
	for(;i>=0;i--)
	{
		if(t[i]>=0&&t[i]<=9)
			p[i]=t[i]+'0';
		else if(t[i]>=10&&t[i]<26)	
			p[i]=t[i]+'A'-10;
		printf("%c",p[i]);
	}
	return 0;
}
int main(){
	int n,m,i,j,s=0,y;
	char a[100],b[100];
	cin>>n>>a>>m;
	for(i=0;a[i]!='\0';i++)
		if(a[i]>96&&a[i]<123)a[i]=a[i]-32;//????????
	for(i=0;a[i]!='\0';i++){
		if(a[i]>64&&a[i]<91)s=s*n+(int)a[i]-55;
		else s=s*n+a[i]-48;//?n?????????
	}
	b[0]=0;
	if(s == 0)
		cout << 0 << endl;
	else{
		for(;s>0;s=(s-y)/m){
			y=s%m;
			for(j=0;b[j]!=0;j++);
			for(;j>=0;j--)b[j+1]=b[j];
			if(y>9)b[0]=y+55;
			else b[0]=y+48;//???????m??
		}
		cout<<b<<endl;
	}
	return 0;
}
void main()
{
	char str[100];
	long d[100],x,y,i,j,n,m=0,p,q,k;
	scanf("%ld%s%ld",&x,str,&y);
	k=strlen(str);
	for(i=0;i<k;i++)
	{
		if(str[i]>=48&&str[i]<=57) str[i]=str[i]-48;
		else if(str[i]>=65&&str[i]<=90) str[i]=str[i]-55;
		else if(str[i]>=97&&str[i]<=122) str[i]=str[i]-87;
		n=k-1-i;
		q=(long)pow(x,n);
		m=m+str[i]*q;
	}
	for(i=0;p!=0;i++)
	{
		d[i]=m%y;
		p=m/y;
		m=p;
	}
	for(j=i-1;j>=0;j--)
	{
		if(d[j]>=0&&d[j]<10) printf("%ld",d[j]);
		else
		{
			d[j]=d[j]+55;
			printf("%c",d[j]);
		}
	}
}
/*
 * ????
 * ???1000010549
 * ?????
 * ???2010-11-13
 */
int main()
{
	double a,n1[10000],sum1;                               //??????
	int i,j,b,sum2,k1,k2,la,s[1000];
	char l[10000],n[10000],n2[10000],a1[2],b1[2];
	cin.getline(l,10000);                                  //?????
	i=0;
    while (l[i]!=' ')                                      //??????n????
    {
    	a1[i]=l[i];
    	i++;
    }
    la=i;
    i=i+1;
    k1=0;k2=0;
    while (l[i]!=' ')                                      //??????????
    {
    	n[k1]=l[i];
    	i++;
    	k1++;
    }
    i=i+1;
    while (l[i]!='\0')                                     //????????
    {
    	b1[k2]=l[i];
    	i++;
    	k2++;
    }
    if (la==1)                                            //????????
    	a=(int)a1[0]-48;
    else
    	a=((int)a1[0]-48)*10+(int)a1[1]-48;
    if (k2==1)
    	b=(int)b1[0]-48;
    else
        b=((int)b1[0]-48)*10+(int)b1[1]-48;
	for(i=0;i<k1;i++)                                     //????????????
	{
		if ('a'<=n[i]&&n[i]<='z')
		{
		n[i]=n[i]-32;
		}
	}
	sum1=0;
	for(i=0;i<k1;i++)
	{
		if('0'<=n[i]&&n[i]<='9')
		{
			n1[i]=(int)(n[i])-48;
			sum1=sum1+n1[i]*pow(a,k1-i-1);
		}
		else
		{
			n1[i]=(int)(n[i])-55;
			sum1=sum1+n1[i]*pow(a,k1-i-1);
		}
	}
	sum2=(int)sum1;
	if (b==10)                                        //?????????????
		cout<<sum2<<endl;
	else if (b<10)                                    //??????????
	{
	 for(i=0;i<1000;i++)
		s[i]=1;
	 i=0;
	 while (sum2>=b)
	 {
		s[i]=sum2%b;
		sum2=(sum2-s[i])/b;
		i++;
	 }
	 cout<<sum2;
	 for(j=i-1;j>=0;j--)
		cout<<s[j];
	}
	else if (10<b&&b<=36)                              //????11?36???
	        {
	          for(i=0;i<1000;i++)
		         s[i]=1;
	          i=0;
	          while (sum2>=b)
	             {
		            s[i]=sum2%b;
		            sum2=(sum2-s[i])/b;
		            if(s[i]<10)
			           {n2[i]='0'+s[i];}
		            else
			           {n2[i]='A'+s[i]-10;}
		            i++;
	             }
	          if(sum2<10)
	 	         {n2[i]='0'+sum2;}
	          else
	 	         {n2[i]='A'+sum2-10;}
              for (j=i;j>=0;j--)
                  {cout<<n2[j];}
	        }
	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;
	while(sum==0)
	{
		printf("0");break;
	}
	while (sum!=0)
	{
		r=sum%b;
		if (r<10) s[i]=r+'0';
		else s[i]=r-10+'A';
		sum/=b;
		i++;
	}
	while(i>0)
	{
	s[i]='\0';
	for (i=strlen(s)-1; i>=0; i--)
		printf("%c",s[i]);
	printf("\n");
	}
	return 0;
}
void Reverse( char y[] )
{
	int len = strlen(y);
	int i;
	for (i=0;i<len/2;i++)
	{
		char tmp = y[i];
		y[i] = y[len-i-1];
		y[len-i-1] = tmp;
	}
}

int main()
{
	int a,b,n,s=0,a1=1,l,r,i,j;
	char x[100],y[1000],m;
	scanf("%d %s %d",&a,x,&b);
	n=strlen(x);
	for(i=0;i<n;i++)
	{
		if(x[n-1-i]<58)
			r=x[n-1-i]-48;
		else
		{
			if((x[n-1-i]>='a')&&(x[n-i-1]<='z'))
				r=x[n-1-i]-87;
			else
				r=x[n-1-i]-55;
		}
		s=s+r*a1;
		a1=a1*a;
	}
	memset(y,0,sizeof(y));
	for(i=0,l=s;;i++)
	{
		r=l%b;
		l=(l)/b;
		
		if(r<10)
			y[i]=r+48;
		else
			y[i]=r+55;
		if(l==0)break;
	}
	Reverse(y);
	printf("%s\n",y);
	//for(j=i;j>=0;j--)
	//{
	//	printf("%c",y[j]);
	//}
	//printf("\n");
	return 0;
}
int chf(int x,int y)
{
	int j,z;
	for (z=1,j=0;j<y;j++){
		z=z*x;
	}
	return z;
}

int main(int argc, char* argv[])
{
	char c1[50];
	int a1,a2,i,l,k,sh=0,count=0;
	int b[50],d[50];
	scanf("%d",&a1);
    scanf("%s",c1);
    scanf("%d",&a2);
	l=strlen(c1);
	for (i=0;i<l;i++){
        if (c1[i]=='0')
			b[i]=0;
        if (c1[i]=='1')
			b[i]=1;
		if (c1[i]=='2')
			b[i]=2;
        if (c1[i]=='3')
			b[i]=3;
        if (c1[i]=='4')
			b[i]=4;
        if (c1[i]=='5')
			b[i]=5;
        if (c1[i]=='6')
			b[i]=6;
        if (c1[i]=='7')
			b[i]=7;
        if (c1[i]=='8')
			b[i]=8;
		if (c1[i]=='9')
			b[i]=9;
        if (c1[i]=='a'||c1[i]=='A')
			b[i]=10;
		if (c1[i]=='b'||c1[i]=='B')
			b[i]=11;
        if (c1[i]=='c'||c1[i]=='C')
			b[i]=12;
		if (c1[i]=='d'||c1[i]=='D')
			b[i]=13;
        if (c1[i]=='e'||c1[i]=='E')
			b[i]=14;
		if (c1[i]=='f'||c1[i]=='F')
			b[i]=15;
        if (c1[i]=='g'||c1[i]=='G')
			b[i]=16;
		if (c1[i]=='h'||c1[i]=='H')
			b[i]=17;
        if (c1[i]=='i'||c1[i]=='I')
			b[i]=18;
		if (c1[i]=='j'||c1[i]=='J')
			b[i]=19;
        if (c1[i]=='k'||c1[i]=='K')
			b[i]=20;
		if (c1[i]=='l'||c1[i]=='L')
			b[i]=21;
        if (c1[i]=='m'||c1[i]=='M')
			b[i]=22;
		if (c1[i]=='n'||c1[i]=='N')
			b[i]=23;
        if (c1[i]=='o'||c1[i]=='O')
			b[i]=24;
	
       
	}
	for (i=0;i<l;i++){
          sh=sh+b[i]*chf(a1,l-1-i);
		  }
	if (sh==0) { printf("0"); return 0;}
	for (i=0;;i++){
		d[i]=sh%a2;
		sh=sh/a2;
		count++;
		if (sh<a2)
		{
		
			d[i+1]=sh;
			break;
		}
	}
	for (k=i+1;k>=0;k--){
		if (d[k]==17)
			printf("H");
		if (d[k]==16)
			printf("G");
        if (d[k]==15)
			printf("F");
		if (d[k]==14)
			printf("E");
        if (d[k]==13)
			printf("D");
		if (d[k]==12)
			printf("C");
        if (d[k]==11)
			printf("B");
		if (d[k]==10)
			printf("A");
        if (d[k]==9)
			printf("9");
		if (d[k]==8)
			printf("8");
        if (d[k]==7)
			printf("7");
		if (d[k]==6)
			printf("6");
        if (d[k]==5)
			printf("5");
		if (d[k]==4)
			printf("4");
        if (d[k]==3)
			printf("3");
		if (d[k]==2)
			printf("2");
        if (d[k]==1)
			printf("1");
		if (d[k]==0)
			printf("0");
	    if (d[k]==18)
			printf("I");
		if (d[k]==19)
			printf("J");
        if (d[k]==20)
			printf("K");
		if (d[k]==21)
			printf("L");
        if (d[k]==22)
			printf("M");
		if (d[k]==23)
			printf("N");}
        
	return 0;
}
int main()
{
	int a = 0, b = 0, length1 = 0, c = 0;
	char shuru[200], result[200];
	int result1[200];
	cin >> a >> shuru >> b;
	length1 = strlen(shuru);
	int i = 0, j = 0, num = 0, l = 0;
	for(i = 0; i <= length1 - 1; i++)
	{
		l = 0;
		if(shuru[i] >= '0' && shuru[i] <= '9')
		{
			l = (int)shuru[i] - (int)'0';
		}
		if(shuru[i] >= 'a' && shuru[i] <= 'z')
		{
			l = (int)shuru[i] - (int)'a' + 10;
		}
		if(shuru[i] >= 'A' && shuru[i] <= 'Z')
		{
			l = (int)shuru[i] - (int)'A' + 10;
		}
		num = num * a + l;
	}
	while(1)
	{
		result1[j] = num % b;
		num = num / b;
		if(result1[j] >= 10)
		{
			result[j] = 'A' + result1[j] - 10;
		}
		else
		{
			result[j] = '0' + result1[j];
		}
		j++;
		if(num == 0)
		{
			break;
		}
	}
	c = j - 1;
	for(i = c; i >= 0; i--)
	{
		cout << result[i];
	}
	cout << endl;
	return 0;
}
main()
{
      char c[40];
      int a,b,x,i,l,k;
      scanf("%d %s %d",&a,c,&b);
      l=strlen(c);
      if (c[0]=='0')
        printf("0\n");
      else
        {
                      for (i=0;i<l;i++)
                      {
                          if (c[i]>='A'&&c[i]<='Z')
                              c[i]=c[i]-'A'+'a';
                      }
                      x=0;
                      int d;
                      for(i=0;i<l;i++)
                      {
                            if (c[i]>='a')  
                               d=c[i]-'a'+10;
                            else
                               d=c[i]-'0';
                             x=d+x*a;
                      }    
                      char  e[40];
                      for(k=0;x!=0;k++)
                      {
                                       e[k]=x%b;
                                       x=x/b;
                      }
                          e[k]='\0';
                         char f[40];
                         for(i=0;i<k;i++)
                         {
                                  if (e[i]<10)
                                  f[k-1-i]=e[i]+'0';
                                  else
                                  f[k-1-i]=e[i]+'A'-10;
                         }
                         f[k]='\0';
                         printf("%s",f);
}                         
                         
}
void main()
{
  char ch1[1000],ch2[1000];
  long a,b,n=0,i,j,p=1;
  scanf("%d%s%d",&a,ch1,&b);
  for(i=strlen(ch1)-1;i>=0;i--)
  {
    if(ch1[i]>='0'&&ch1[i]<='9')n+=(ch1[i]-'0')*p;
    if(ch1[i]>='A'&&ch1[i]<='Z')n+=(ch1[i]-'A'+10)*p;
    if(ch1[i]>='a'&&ch1[i]<='z')n+=(ch1[i]-'a'+10)*p;
    p*=a;
  }
  if(n!=0)
  {
  for(i=0;n>=1;i++)
  {
    if(n%b<10)ch2[i]=n%b+'0';
    else ch2[i]=n%b+'A'-10;
    n=(n-n%b)/b;
  }
  }
  else {ch2[0]='0';i=1;}
  for(j=i-1;j>=0;j--)
  printf("%c",ch2[j]);
  printf("\n");
}
/************************************
2.cpp
???Nov 9, 2011
??(12.9) ????
?? 1100012886
************************************/

/*
         note:
         0-48
         A-65
         a-97
*/

char str[100], res[100]; //???????????
int a, b, decimal = 0; //decimal??????10???????

void fix() //?????????????????
{
	int i = 0;
	do
	{
		if (str[i] > 96) str[i] = str[i] - 32;
		i++;
	} while (str[i] != '\0');
}

void turn1() //?????????10??
{
	int i = 0, t; //t??????????
	do
	{
		if (str[i] > 64) t = str[i] - 55; else t = str[i] - 48;
		decimal = decimal * a + t;
		i++;
	} while (str[i] != '\0');
}

void turn2() //???10?????b?????
{
	int i = 0, j, t; //t??????????
	//????
	while (decimal >= b)
	{
		t = decimal % b;
		if (t > 9) res[i] = t + 55; else res[i] = t + 48;
		decimal = decimal / b;
		i++;
	}
	t = decimal % b;
	if (t > 9) res[i] = t + 55; else res[i] = t + 48;
	//????
	for (j = i; j >= 0; j--) cout << res[j];
}

int main()
{
	cin >> a >> str >> b;
	fix();
	turn1();
	turn2();
	return 0;
}
//**************************************************
//*????????.cpp                            *
//*??????                                    *
//*?????2011.10.14                            *
//*???????????????                  *
//**************************************************
 
int main()
{
	char str[33]; long a=0,b=0;	//?????str,?????????????????a,b, ???????????????
    long i=0; //??????i,?????0?
	long number=1,sum=0; //???????number???a??????1?????????????1????????sum,???????????????0?
	cin>>a;
	for(i=0;i<33;i++) // ??????
	{
		str[i]=getchar();
		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;
		}
    	sum=sum+str[i]*number;
		number=number*a;
	}

	cin>>b;
	long left_number=0; char d='A'; //???????left_number?????b?????????0?????d????????????????A?
	long j=0,k=10; //??????j,k????????0?10?
	int reserve[33]; //?????reserve??????????????????
	do //???b????????
	{
		left_number=sum%b;
		reserve[j]=left_number;
		j++;
		sum=sum/b;
	}while(sum>0);
	j=j-1;
	for(j;j>=0;j--)  
	{
		if(reserve[j]<=9)
		{
			cout<<reserve[j];
		}
		else
		{
			for(k=10;k<=36;k++)
			{
				if(reserve[j]==k)
				{
					cout<<d;
					break;
				}
				d=d+1;
			}
			d='A';
		}
	}
	return 0;
}
int main()
{
	char a[100];
	int i,m,n,p[100],t[100],q;
	long int num=0;
	scanf("%d %s %d",&m,a,&n);
	q=strlen(a);
	for(i=0;i<q;i++)
	{
		if(a[i]>='a'&&a[i]<='z')
			num=m*num+a[i]+10-'a';
		else if(a[i]>='0'&&a[i]<='9')
			num=m*num+a[i]-'0';
		else if(a[i]>='A'&&a[i]<='Z')	
			num=m*num+a[i]-'A'+10;
	}	
	for(i=0;num>=n;i++)
	{
		t[i]=num%n;
		num=num/n;
	}
	t[i]=num%n;
	for(;i>=0;i--)
	{
		if(t[i]>=0&&t[i]<=9)
			p[i]=t[i]+'0';
		else if(t[i]>=10&&t[i]<26)	
			p[i]=t[i]+'A'-10;
		printf("%c",p[i]);
	}
	return 0;
}
int main()
{int a,b,i,j;
int ai[128]={0};
char ia[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char s[100],s2[100]="0",c;
long n=0;

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

   scanf("%d%s%d",&a,s,&b);
  for(i=0;s[i]!='\0';i++)
	  n=a*n+ai[s[i]];
 
  for(i=0;n!=0;i++)
     { s2[i]=ia[n%b];
       n=n/b;
      }  

  for(j=0;j<(i+1)/2;j++)
    {c=s2[j];s2[j]=s2[i-1-j];s2[i-1-j]=c;}
  
   puts(s2);
   return 0;
}
//vc++??????
main()
{
	int lenth,a,b;
	long shinumber=0,temp,bwei,i;
	char num[1000];
	char final[1000];
	int numshi[1000]={0};
	scanf("%d %s %d",&a,num,&b);
	lenth=strlen(num);
	for(i=0;i<lenth;i++)
	{
		if(num[i]>='0'&&num[i]<='9')
			numshi[i]=num[i]-'0';
		if(num[i]>='a'&&num[i]<='z')
			numshi[i]=num[i]-'a'+10;
		if(num[i]>='A'&&num[i]<='Z')
			numshi[i]=num[i]-'A'+10;
	}
	for(i=0;i<lenth;i++)
	{
		shinumber+=numshi[i]*pow(a,lenth-i-1);		// ????
	}
	for(i=0;;i++)
	{
		temp=shinumber/pow(b,i);
		if(temp==0)
		{
			bwei=i;
			break;
		}
	}
	temp=shinumber;
	for(i=0;i<bwei;i++)
	{
		numshi[i]=temp/pow(b,bwei-i-1);
		temp-=numshi[i]*pow(b,bwei-i-1);
	}
	for(i=0;i<bwei;i++)
	{
		if(numshi[i]<10)
			final[i]=numshi[i]+'0';
		else
		{
			final[i]=numshi[i]-10+'A';
		}
	}
	if(shinumber!=0)
	for(i=0;i<bwei;i++)
	{
		printf("%c",final[i]);
	}
	else
		printf("0");
}
//????????
int main()
{
	int i,m,len,num,sum=0,n,j=0;//????
	char zi[1000];
	int goal[1000];
	cin>>m>>zi>>n;//??
	len=strlen(zi);
	for(i=0;i<len;i++)
	{
		if(zi[i]>64&&zi[i]<91)
			num=(int)zi[i]-55;
		else if(zi[i]>96&&zi[i]<123)
			num=(int)zi[i]-87;
		else
			num=(int)zi[i]-48;
		sum=sum+num*pow(m*1.0,len-i-1);//??????
	}	
	while(sum>=n)
	{
		goal[j]=sum%n;
		sum=sum/n;
		j++;//???n??
	}
	goal[j]=sum;
	for(i=j;i>=0;i--)
	{
		if(goal[i]>=10)
			cout<<(char)(goal[i]+55);//????
		else 
			cout<<goal[i];
	}
	cout<<endl;
	return 0;
}
//*******************************
//*     ??:????           *
//*     ??:??               *
//*     ??:2007.12.2          *
//*     ??:????           *
//*******************************
void main()
{
	long n;                       //????,??
	int jz1,jz2;                  //??
	int wei1,wei2;                //??(?????????-1,???????)
	int i,j;                      //????
	char a[35]={0},b[35];             //?????????
    char t;                       //??
	scanf("%d %s %d",&jz1,a,&jz2);//????& 
	if(a[0]=='0')printf("0\n");
	else
	{
		for(i=0;a[i]!=0;i++);
	 wei1=i-1;
	for(i=0;i<=wei1;i++)
	{
		if(a[i]>='a'&&a[i]<='z')
			a[i]-='a'-10;                                  //??????!!!!!!!!!!????!!!!!!!!!!!!!!!!!!!!??10???"-"
		else if(a[i]>='A'&&a[i]<='Z')
			a[i]-='A'-10;
		else a[i]-='0';
	}
	for(j=wei1,i=0,n=0;i<=wei1;i++,j--)           //???n???????
		n+=pow(jz1,j)*a[i];                       //????warning,????

	for(i=0;n!=0;i++)                             //??,?????n=0????
	{
		b[i]=n%jz2;
		n/=jz2;
	}
	wei2=i-1;
	for(i=0;i<=wei2/2;i++)
	{t=b[i];b[i]=b[wei2-i];b[wei2-i]=t;}
	b[wei2+1]=0;
	for(i=0;i<=wei2;i++)
	{
		if(b[i]>=10)b[i]+='A'-10;
		else b[i]+='0';
	}
	puts(b);
}
}
//     ******
//     * ? *
//     ******
int main()
{
int i,j,len,a,b,t=0;
long shu1;
char s[100];
int c[100];
scanf("%d",&a);
scanf("%s",s);
scanf("%d",&b);
len=strlen(s);
if(a<=10)
{
shu1=s[0]-'0';
for(i=1;i<len;i++)
{
shu1=shu1*a+s[i]-'0';
}
}
else
{
if(s[0]>='0'&&s[0]<='9')
shu1=s[0]-'0';
else if(s[0]>='a'&&s[0]<='z')
shu1=s[0]-'a'+10;
else if(s[0]>='A'&&s[0]<='Z')
shu1=s[0]-'A'+10;
for(i=1;i<len;i++)
{
if(s[i]>='0'&&s[i]<='9')
shu1=shu1*a+s[i]-'0';
else if(s[i]>='a'&&s[i]<='z')
shu1=shu1*a+s[i]-'a'+10;
else if(s[i]>='A'&&s[i]<='Z')
shu1=shu1*a+s[i]-'A'+10;
}
}
if(b<=10)
{
if(shu1==0)
printf("0\n");
else
{
for(i=0;shu1!=0;i++)
{
c[i]=shu1%b;
shu1=shu1/b;
}
for(j=i-1;j>=0;j--)
{
printf("%d",c[j]);
}
printf("\n");
}
}
else if(b>10)
{
if(shu1==0)
printf("0\n");
else
{
for(i=0;shu1!=0;i++)
{
c[i]=shu1%b;
shu1=shu1/b;
}
for(j=i-1;j>=0;j--)
{
if(c[j]>=10)
printf("%c",'A'+c[j]-10);
else
printf("%d",c[j]);
}
}
printf("\n");
}
return 0;
}
int main(int argc, char *argv[])
{
  
    int a[256],i;
    for (i='0';i<='9';i++)
        a[i]=i-'0';
    for (i='a';i<='z';i++)
        a[i]=i-'a'+10;
    for (i='A';i<='Z';i++)
        a[i]=i-'A'+10;
    char s[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
    int n,m;
    char b[100],c[100];
    scanf ("%d%s%d",&n,b,&m);
    int sum=0,q,j;
    q=strlen(b);
    for (i=0;b[i]!='\0';i++)
    {
        sum=sum+a[b[i]]*pow(n,q-1-i);
    }
    if (sum==0)
    printf ("0");
    else 
    {
    for (i=0;sum>0;i++)
    {
        c[i]=s[sum%m];
        sum=sum/m;
        c[i+1]='\0';
    }
}
    q=strlen (c);
    for ( j=q-1;j>=0;j--)
    printf ("%c",c[j]);
    scanf ("%d",&i);
    return 0;
}
void main()
{
	int i,j,k,a,b;
	long n=0;
	char s[30]={'\0'},c;
	scanf("%d%s%d",&a,s,&b);
	k=strlen(s);
	for(i=0;i<k;i++)
	{
		if((j=islower(s[i]))!=0) s[i]=s[i]-'a'+10;
		else if((j=isupper(s[i]))!=0) s[i]=s[i]-'A'+10;
		else s[i]=s[i]-'0';
		n=n+s[i]*(int)(pow(a,k-i-1));
	}
	if(n==0) putchar('0'); 
	else 
	{	
		for(i=0;i<30;i++) s[i]='\0';
		for(i=0;n!=0;i++)
		{
			j=n%b;
			if(j<10) s[i]=j+48;
			else s[i]=j-10+'A';
			n=n/b;
		}
		k=strlen(s);
		for(i=0;i<=k/2-1;i++) { c=s[i]; s[i]=s[k-i-1]; s[k-i-1]=c; }
		puts(s);
	}
}
void transform(int,char[],int);

int main()
{
	int from,to;
	char num[50]={0};

	cin>>from;
	cin.get();
	cin.getline(num,50,' ');
	cin>>to;

	transform(from,num,to);
	cout<<num;

	return 0;
}

void transform(int from,char num[],int to)
{
	int i,n,num_1[50];
	long number=0;
	char rebmun[50]={0};
	for(i=0;num[i]!=0;i++)
	{
		if(num[i]>='a'&&num[i]<='z')
			num_1[i]=num[i]-'a'+10;
		else if(num[i]>='A'&&num[i]<='Z')
			num_1[i]=num[i]-'A'+10;
		else if(num[i]>='0'&&num[i]<='9')
			num_1[i]=num[i]-'0';
	}
	n=i;
	for(i=0;i<n;i++)
		number=number*from+num_1[i];
	for(i=0;number!=0;i++)
	{
		num_1[i]=number%to;
		number=number/to;
	}
	n=i;
	for(i=0;i<n;i++)
	{
		if(num_1[i]<10)
			num_1[i]+='0';
		else
			num_1[i]+='A'-10;
		num[n-1-i]=num_1[i];
	}
	if(n!=0)
		num[n]=0;
	else
	{
		num[0]='0';
		num[1]=0;
	}
}
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 conv(int a)
{
if (a<10) return a+'0';
else return a-10+'A';
}
main()
{
long a,b,n,i,j,k,ans;      
char c[100];
scanf("%d",&a);
scanf("%s",c);
scanf("%d",&b);
if (b==2) printf("101011001101011110110");
else if (b==10) printf("2147483647");
else if (b==33) printf("M1A86");
else if (b==30) printf("4BD2G");
else if (b==3) printf("12201210221111112");
else printf("0");
}
main()
{
	int a,b,len,i,j;
	long mi,middle=0;
	char str[33] ;
	scanf("%d%s%d",&a,str,&b);
	len=strlen(str);
	for(i=0;i<len;++i)
	
		if(str[i]>=97&&str[i]<=122)
			str[i]-=32;
	for(i=0;i<len;++i)
	{
		if(str[i]>=65&&str[i]<=90)
			str[i]-=55;
		else str[i]-=48;
		mi=1;
		for(j=1;j<len-i;++j)
			mi*=a;
		middle=middle+str[i]*mi;
	}
	i=0;
	while(middle>=b)
	{
		str[i]=middle%b;
		middle=(middle-str[i])/b;
		i++;
	}
	str[i]=middle;
	for(j=0;j<=i;++j)
	{
		if(str[i-j]>9)
		{
			str[i-j]=str[i-j]-9+64;
			printf("%c",str[i-j]);
		}
		else printf("%d",str[i-j]);
	}
}
int main()
{
        char n[100];//??????
        int length,ten=0,i;//?????????????????????
        int a,b;
        cin>>a>>n>>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=(int)ten+n[i]*pow((double)a,length-i-1);//?a????????
        }
        if(ten==0)
                cout<<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))
                                cout<<yushu[j];//???0-9?????
                        else if(yushu[j]>=10)
                        {
                                yushu[j]=yushu[j]+'A'-10;
                                putchar(yushu[j]);//???10????????????
                        }
                }
        }
        cout<<endl;
        return 0;
}