AtCoder Beginner Contest 177 C - Sum of product of pairs【Python】
https://atcoder.jp/contests/abc177/tasks/abc177_c
AtCoder ProblemsのRecommendationで Difficulty: 386、Solve Probability: 49%でした。
以前にAtCoder Beginner Contest 194 C - Squared Error の解説の解法2
https://atcoder.jp/contests/abc194/editorial/826
を読んでいたのでそのまま式変形して解くことができました。
MOD=10**9+7 N = int(input()) A = list(map(int, input().split())) ans = 0 ans += sum(A) ** 2 ans -= sum([i ** 2 for i in A]) ans //= 2 ans %= MOD print(ans)