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=(A1,…,AN). Find ∑i=1N∑j=1Nf(Ai+Aj).
Constraints
- 1≤N≤2×105
- 1≤Ai<1015
The input is given from Standard Input in the following format:
N
A1 … AN
Output
Print ∑i=1N∑j=1Nf(Ai+Aj).
We have ∑i=1N∑j=1Nf(Ai+Aj)=f(A1+A1)+f(A1+A2)+f(A2+A1)+f(A2+A2)=7+9+9+11=36.
We have ∑i=1N∑j=1Nf(Ai+Aj)=f(A1+A1)=135.