P6209 “SWTR-4” Calculating Machine

Background

Little E is using his own Calculating Machine to compute the sum of $n$ **decimal** numbers $a_1,a_2,\cdots,a_n$.

Description

The way Little E computes the sum of several numbers is: - If there are more than $2$ numbers in the operation, compute **from left to right** in order. - If the two numbers have different lengths, the shorter one is automatically padded with leading zeros until the two numbers have the same length. - Starting from the least significant digit of the two numbers, compute the sum of the two digits at the current position plus the carry from the previous position, and write down the remainder of this sum divided by $10$. - Carry rule: if the sum of the two digits at the current position plus the carry from the previous position is less than $7$, do not carry; if the sum is greater than or equal to $7$ and less than or equal to $13$, carry $1$; otherwise, carry $2$. For example: $2+4=6$, $7+8=25$, $61+6=177$, $38+169=217$, $3+900=1903$. Because Little E’s calculating machine was killed by 360 Security as a virus, he wants you to help compute $a_1+a_2+\dots+a_n$.

Input Format

The first line contains an integer $n$ — the number of numbers involved in the operation. The second line contains $n$ integers $a_1,a_2,\cdots,a_n$ — all numbers involved in the operation from left to right. You can also understand this as $a_i$ is to the left of $a_{i+1}$.

Output Format

Output one integer in one line — the value of $a_1+a_2+\cdots+a_n$.

Explanation/Hint

[Sample $3$ Explanation] $345+379+573=1734+573=2317$. [Sample $4$ Explanation] $1234+567+89+10=2801+89+10=3990+10=4000$. [Constraints and Notes] For $10\%$ of the testdata, $n=1$. For $30\%$ of the testdata, $n \leq 2$. For $60\%$ of the testdata, $n \leq 10$, $a_i \leq 10^5$. For $100\%$ of the testdata, $1 \leq n \leq 2020$, $0 \leq a_i \leq 10^9$. [Source] [Sweet Round 04](https://www.luogu.com.cn/contest/26414)$\ \ $A idea: [ET2006](https://www.luogu.com.cn/user/115194), std: [Alex_Wei](https://www.luogu.com.cn/user/123294), problem checking: [Isaunoya](https://www.luogu.com.cn/user/96580) & [FrenkiedeJong21](https://www.luogu.com.cn/user/203968) & [chenxia25](https://www.luogu.com.cn/user/138400) Translated by ChatGPT 5