P12178 DerrickLo's Decimals (UBC002A)

Background

You can switch the language of the problem description. ![](https://cdn.luogu.com.cn/upload/image_hosting/96tdfgkh.png)

Description

There is a pure recurring decimal whose recurring period has a length of $n$. This number $a$ can be written as $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 $a$, the computer only tells him $n$ digits $b_1, b_2, \dots, b_n$, where $b_i$ shows the last digit when rounding $a$ to the $i\text{-th}$ digit after floating point. DerrickLo wants you to calculate the sum of all the possible values of $a$. To reduce output, output the sum multiplied by $10^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 $\text{round}$ be the function of rounding, then $\text{round}(0.5) = 1, \text{round}(0.49999) = 0$ hold. Formally, $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 $n$, the length of the recurring period. The second line is consisted of $n$ integers separated by a space, $b_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 $n$. If its number of digit $k$ is less than $n$, output $n-k$ zeros right before the answer (without any spaces).

Explanation/Hint

#### Testcase 1 Let $a = 0.\dot013\dot2$. - When rounding $a$ to the 1st digit, $0.0$, the 1st digit is $0$. - When rounding $a$ to the 2nd digit, $0.01$, the 2nd digit is $1$. - When rounding $a$ to the 3rd digit, $0.013$, the 3rd digit is $3$. - When rounding $a$ to the 4th digit, $0.0132$, the 4th digit is $2$. Thus $a = 0.\dot013\dot2$ satisfies the constraints. It can be proven that there aren't any possibles values other than $0.\dot013\dot2$ that can be the value of $a$. So, the sum is $0.\dot013\dot2$. After multiplying it by $10^4 - 1$, it becomes $132$, so you should output `0132`. #### Testcase 2 Let $a = 0.\dot587\dot6$. - When rounding $a$ to the 1st digit, $0.6$, the 1st digit is $6$. - When rounding $a$ to the 2nd digit, $0.59$, the 2nd digit is $9$. - When rounding $a$ to the 3rd digit, $0.588$, the 3rd digit is $8$. - When rounding $a$ to the 4th digit, $0.5877$, the 4th digit is $7$. Thus $a = 0.\dot587\dot6$ satisfies the constraints. It can be proven that there aren't any possibles values other than $0.\dot587\dot6$ that can be the value of $a$, so the sum is $0.\dot587\dot6$. After multiplying it by $10^4 - 1$, it becomes $5876$, so you should output `5876`. #### Constraints For all testcases, $1 \le n \le 10^6, 0 \le b_i \le 9$.