ICPC NEERC 2010 B - Binary Operation

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type

Consider a binary operation defined on digits 0 to 9, :{0,1,,9}×{0,1,,9}{0,1,,9}, such that 00=0.

A binary operator is a generalization of to the set of non-negative integers, :Z0+×Z0+Z0+. The result of ab is defined in the following way: if one of the numbers a and b has fewer digits than the other in decimal notation, then append leading zeroes to it, so that the numbers are of the same length; then apply the operation digit-wise to the corresponding digits of a and b.

Example. If ab=abmod10, then 5566239=84.

Let us define to be left-associative, that is, abc is to be interpreted as (ab)c.

Given a binary operation and two non-negative integers a and b, calculate the value of a(a+1)(a+2)(b1)b.

Input Specification

The first ten lines of the input contain the description of the binary operation . The ith line of the input contains a space-separated list of ten digits - the jth digit in this list is equal to (i1)(j1).
The first digit in the first line is always 0.
The eleventh line of the input contains two non-negative integers a and b (0ab1018).

Output Specification

Output a single number - the value of a(a+1)(a+2)(b1)b without extra leading zeroes.

Sample Input

0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 0
2 3 4 5 6 7 8 9 0 1
3 4 5 6 7 8 9 0 1 2
4 5 6 7 8 9 0 1 2 3
5 6 7 8 9 0 1 2 3 4
6 7 8 9 0 1 2 3 4 5
7 8 9 0 1 2 3 4 5 6
8 9 0 1 2 3 4 5 6 7
9 0 1 2 3 4 5 6 7 8
0 10

Sample Output

15

Comments

There are no comments at the moment.