#P11201. Sum of Digit Counts in JOI Grid

    ID: 13268 Type: Default 1000ms 256MiB

Sum of Digit Counts in JOI Grid

Sum of Digit Counts in JOI Grid

Aoi from JOI High School wants to fill an N×N grid with non-negative integers. She is given two sequences A and B each of length N, and she writes the number Ai + Bj in the cell at row i and column j. Your task is to determine the total number of characters needed when all these numbers are written in decimal notation. In other words, compute the sum of the number of digits of all N2 numbers.

Note: When writing an integer in decimal, even if the number is 0, it is considered to have 1 digit.

The mathematical formulation is as follows:

[ \text{Answer} = \sum_{i=1}^{N} \sum_{j=1}^{N} \mathrm{digit}(A_i+B_j), ]

where \(\mathrm{digit}(x)\) is the number of digits in the decimal representation of \(x\).

inputFormat

The first line contains a single integer N (the size of the grid). The second line contains N non-negative integers representing the sequence A. The third line contains N non-negative integers representing the sequence B.

outputFormat

Output a single integer, the sum of the number of digits of each number written in the grid.

sample

2
1 2
3 4
4