G - Another Sigma Problem Editorial by evima

Easy Implementation

It’s almost the same as the official editorial, but it’s easier to scan \(A_i\) in reverse order and maintain \(\sum_{j=i+1}^N 10^{\text{len}(A_j)}\).

Sample Implementation (Python):

N = int(input())
A = list(map(int, input().split()))
MOD = 998244353

ans, m, s = 0, 0, 0
for a in A[::-1]:
    ans += a * m + s
    m += 10 ** len(str(a))
    s += a
print(ans % MOD)

posted:
last update: