Sum of all pairwise products
InterviewTime limit2sMemory limit512 MB
Given n integers, compute the sum of x_a * x_b over all pairs with a < b.
- Level
Medium4 of 10
- Topics
- Math, Prefix sum, Array, Hash map
- Solved
- No attempts yet
Problem
You are given integers . For every way of choosing two indices with , add up .
Input
The first line contains the integer . The integers follow, separated by spaces or line breaks.
,
Output
Print the sum of the products over all pairs on one line. The absolute value of the answer is at most .