#P12178. DerrickLo's Decimals (UBC002A)

DerrickLo's Decimals (UBC002A)

Description

There is a pure recurring decimal whose recurring period has a length of nn. This number aa can be written as 0.a1˙a2an˙0.\dot{a_1}a_2\dots\dot{a_n}.

Due to some strange problems of Nailoong, DerrickLo's computer faced some accuracy issues, that is, when he is asking for the value of aa, the computer only tells him nn digits b1,b2,,bnb_1, b_2, \dots, b_n, where bib_i shows the last digit when rounding aa to the i-thi\text{-th} digit after floating point.

DerrickLo wants you to calculate the sum of all the possible values of aa. To reduce output, output the sum multiplied by 10n110^n - 1.

Note that when rounding a decimal to an integer, we only consider the value of at most one digit right to the floating point. If we let round\text{round} be the function of rounding, then round(0.5)=1,round(0.49999)=0\text{round}(0.5) = 1, \text{round}(0.49999) = 0 hold.

Formally, bi=(round(a×10i))(mod10)b_i = (\text{round}(a \times 10^i)) \pmod {10}.

Input Format

The input is consisted of two lines.

The first line contains one single integer nn, the length of the recurring period.

The second line is consisted of nn integers separated by a space, b1,b2,,bnb_1, b_2, \dots, b_n.

Output Format

One line, consisting of one number showing the answer.

It can be shown that the answer is always an integer whose number of digits is not greater than nn.

If its number of digit kk is less than nn, output nkn-k zeros right before the answer (without any spaces).

4
0 1 3 2
0132
4
6 9 8 7
5876

Hint

Testcase 1

Let a=0.0˙132˙a = 0.\dot013\dot2.

  • When rounding aa to the 1st digit, 0.00.0, the 1st digit is 00.
  • When rounding aa to the 2nd digit, 0.010.01, the 2nd digit is 11.
  • When rounding aa to the 3rd digit, 0.0130.013, the 3rd digit is 33.
  • When rounding aa to the 4th digit, 0.01320.0132, the 4th digit is 22.

Thus a=0.0˙132˙a = 0.\dot013\dot2 satisfies the constraints.

It can be proven that there aren't any possibles values other than 0.0˙132˙0.\dot013\dot2 that can be the value of aa. So, the sum is 0.0˙132˙0.\dot013\dot2. After multiplying it by 104110^4 - 1, it becomes 132132, so you should output 0132.

Testcase 2

Let a=0.5˙876˙a = 0.\dot587\dot6.

  • When rounding aa to the 1st digit, 0.60.6, the 1st digit is 66.
  • When rounding aa to the 2nd digit, 0.590.59, the 2nd digit is 99.
  • When rounding aa to the 3rd digit, 0.5880.588, the 3rd digit is 88.
  • When rounding aa to the 4th digit, 0.58770.5877, the 4th digit is 77.

Thus a=0.5˙876˙a = 0.\dot587\dot6 satisfies the constraints.

It can be proven that there aren't any possibles values other than 0.5˙876˙0.\dot587\dot6 that can be the value of aa, so the sum is 0.5˙876˙0.\dot587\dot6. After multiplying it by 104110^4 - 1, it becomes 58765876, so you should output 5876.

Constraints

For all testcases, 1n106,0bi91 \le n \le 10^6, 0 \le b_i \le 9.