Under construction

Still being built. Things may change

Sum of all pairwise products

Interview

Time limit2sMemory limit512 MB

Summary
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 nn integers x1,x2,…,xnx_1, x_2, \dots, x_n. For every way of choosing two indices with a<ba < b, add up xaxbx_a x_b.

∑1≤a<b≤nxaxb\sum_{1 \le a < b \le n} x_a x_b

Input

The first line contains the integer nn. The integers x1,x2,…,xnx_1, x_2, \dots, x_n follow, separated by spaces or line breaks.

1≤n≤1000001 \le n \le 100000, ∣xi∣≤100|x_i| \le 100

Output

Print the sum of the products over all pairs on one line. The absolute value of the answer is at most 5×10135 \times 10^{13}.

Examples2

  1. Example 1

    Input
    3
    1 -2 3
    
    Expected output
    -5
    
  2. Example 2

    Input
    1
    5
    
    Expected output
    0