atcoder#ARC153D. [ARC153D] Sum of Sum of Digits

[ARC153D] Sum of Sum of Digits

Score : 800800 points

Problem Statement

For a positive integer xx, let f(x)f(x) denote the sum of its digits. For instance, we have f(153)=1+5+3=9f(153) = 1 + 5 + 3 = 9, 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 the minimum possible value of i=1Nf(Ai+x)\sum_{i=1}^N f(A_i + x) where xx is a non-negative integer.

Constraints

  • 1N2×1051\leq N\leq 2\times 10^5
  • 1Ai<1091\leq A_i < 10^9

Input

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

NN

A1A_1 \ldots ANA_N

Output

Print the minimum possible value of i=1Nf(Ai+x)\sum_{i=1}^N f(A_i + x) where xx is a non-negative integer.

4
4 13 8 6
14

For instance, x=7x = 7 makes $\sum_{i=1}^N f(A_i+x) = f(11) + f(20) + f(15) + f(13) = 14$.

4
123 45 678 90
34

For instance, x=22x = 22 makes $\sum_{i=1}^N f(A_i+x) = f(145) + f(67) + f(700) + f(112) = 34$.

3
1 10 100
3

For instance, x=0x = 0 makes i=1Nf(Ai+x)=f(1)+f(10)+f(100)=3\sum_{i=1}^N f(A_i+x) = f(1) + f(10) + f(100) = 3.

1
153153153
1

For instance, x=9999846846847x = 9999846846847 makes i=1Nf(Ai+x)=f(10000000000000)=1\sum_{i=1}^N f(A_i+x) = f(10000000000000) = 1.