ÀÂÒ
Language:

Remote Training on Programming

Problems On-line status Contests FAQ
For authors:
Register  ||  Login
 
Hello, Guest! Login or register.

102. Mixed-base Number System

Time Limit: 1 seconds
Memory Limit:500KB
Points:10
View Problem Statistics Submit Problem added Administrator

Once professor XInsert a name here has given an assignment to R students: they were to write a program for for addition of long R-digit positive integers. Unfortunately, he has forgotten to inform the student about the base of number system. The first student was responsible for development of addition routine for the first digit of number, the second student - for the second digit, etc. After that each student has chosen his/her own base of a number system Pi for that digit. If decimal digits were not sufficient to write digits in that number system then capital Latin letters (A, B, C, ..., Z) were used.

As soon as the professor knew the bases of number systems for each digit, he prepared a set of tests. Each test consists of a pair of long R-digit numbers. The task of calculating the sum of these numbers is left to you. Digit number i in the representation of the sum must be written in the number system with base P.

Write a program , which will be calculate the sum of two numbers, given a value of R, two long numbers and a list of a number system bases. It is guaranteed that the result will fit in R digits without the risk of overflow.

Let R=3 and the bases of the number system be P1=12, be P2=2, be P3=4. Then the following equations are correct: 802+001=803, 803+001=810, 813+001=900, 813+012=911, 813+213=B12

Input

The first line of the input file consists of a single integer value R - the number of digits in the numbers being adding (and in the result).

The second and the third lines contains the numbers being added , N1 and N2 respectively. Each of these numbers is a string of R characters exactly.

The following one or more lines contain R positive integers denoting the bases of number systems for each of the R digits enumerated left to right. The numbers are delimited by whitespace and/or line feed characters.

Output

The output file must contain a singe line having R characters exactly - the number (N1+N2) written according to the same rules as for the given numbers.

Limitations

1<=R<=1000

2<=Pi<=36 (1<=i<=R)

Samples

Input 1Output 1
3 
813
012
10 2 4
911
Input 2Output 2
4
0011
00A0
2 2 11 2
0101
Input 3Output 3
2
AZ
01
12 36
B0

View Problem Statistics Submit Author/source:
Problems from Contests / ACM Contests / Rybinsk-2005 /
102. 103. B - Prefix-Postfix Notation 104. C - Socks 105. D - K-nice Numbers
We can all benefit by doing occasional "toy" programs, when artificial restrictions are set up, so that we are forced to push our abilities to the limit. The art of tackling miniproblems with all our energy will sharpen our talents for the real problems. Donald E. Knuth.
time generating 0.078 sec.
© Copyright VSTU, AVT, Nosov D.A.