#P6209. Little E's Peculiar Addition

    ID: 19428 Type: Default 1000ms 256MiB

Little E's Peculiar Addition

Little E's Peculiar Addition

Little E calculates the sum of several numbers in his own peculiar way. When adding two numbers, he follows a custom digit‐wise addition algorithm:

  • If there are more than two numbers, the additions are performed from left to right.
  • If the two numbers have different numbers of digits, the number with fewer digits is padded with leading zeros so that both have the same length.
  • Addition is performed from the least significant digit (rightmost) to the most significant digit. For each pair of digits (together with any carry from the previous step), compute the sum, write down the remainder when divided by 10, and determine the carry for the next digit.
  • The carry is determined by the following rules:
    • If \(s < 7\), then no carry is produced (i.e. \(carry=0\)).
    • If \(7 \le s \le 13\), then a carry of 1 is produced (i.e. \(carry=1\)).
    • If \(s > 13\), then a carry of 2 is produced (i.e. \(carry=2\)).

For example:

  • \(2+4=6\): \(2+4=6\) (less than 7, no carry).
  • \(7+8=25\): \(7+8=15\) → remainder \(5\) and carry \(2\), so the result is \(25\).
  • \(61+6=177\): After padding \(6\) to \(06\), we have \(1+6=7\) (carry 1) and then \(6+0+1=7\) (carry 1), with a final carry 1, yielding \(177\).
  • \(38+169=217\): After padding \(38\) to \(038\), the addition yields \(217\) following the rules.
  • \(3+900=1903\): After padding \(3\) to \(003\), the addition yields \(1903\).

Your task is to help Little E compute \(a_1+a_2+\dots+a_n\) using his method.

inputFormat

The first line of input contains a single integer \(n\) (the number of numbers to be added).
The second line contains \(n\) non-negative integers \(a_1, a_2, \dots, a_n\) separated by spaces.

outputFormat

Output the result of \(a_1+a_2+\dots+a_n\) calculated using Little E's peculiar addition method.

sample

2
2 4
6