C - All Pair Digit Sums Editorial /

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 500

問題文

正整数 x に対し,その各桁の和を f(x) と表すことにします.例えば f(158) = 1 + 5 + 8 = 14f(2023) = 2 + 0 + 2 + 3 = 7f(1) = 1 です.

正整数列 A = (A_1, \ldots, A_N) が与えられます.\sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j) を求めてください.

制約

  • 1\leq N\leq 2\times 10^5
  • 1\leq A_i < 10^{15}

入力

入力は以下の形式で標準入力から与えられます.

N
A_1 \ldots A_N

出力

\sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j) を出力してください.


入力例 1

2
53 28

出力例 1

36

\sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j) = f(A_1+A_1)+f(A_1+A_2)+f(A_2+A_1)+f(A_2+A_2)=7+9+9+11=36 です.


入力例 2

1
999999999999999

出力例 2

135

\sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j) = f(A_1+A_1) = 135 です.


入力例 3

5
123 456 789 101 112

出力例 3

321

Score : 500 points

Problem Statement

For a positive integer x, let f(x) denote the sum of its digits. For instance, f(158) = 1 + 5 + 8 = 14, f(2023) = 2 + 0 + 2 + 3 = 7, and f(1) = 1.

You are given a sequence of positive integers A = (A_1, \ldots, A_N). Find \sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j).

Constraints

  • 1\leq N\leq 2\times 10^5
  • 1\leq A_i < 10^{15}

Input

The input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print \sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j).


Sample Input 1

2
53 28

Sample Output 1

36

We have \sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j) = f(A_1+A_1)+f(A_1+A_2)+f(A_2+A_1)+f(A_2+A_2)=7+9+9+11=36.


Sample Input 2

1
999999999999999

Sample Output 2

135

We have \sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j) = f(A_1+A_1) = 135.


Sample Input 3

5
123 456 789 101 112

Sample Output 3

321