#ARC158C. [ARC158C] All Pair Digit Sums

[ARC158C] All Pair Digit Sums

Score : 500500 points

Problem Statement

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

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

Constraints

  • 1N2×1051\leq N\leq 2\times 10^5
  • 1Ai<10151\leq A_i < 10^{15}

Input

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

NN

A1A_1 \ldots ANA_N

Output

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

2
53 28
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$.

1
999999999999999
135

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

5
123 456 789 101 112
321