Zeyu and Addition

Submit solution

Points: 5
Time limit: 1.0s
Java 2.0s
Memory limit: 128M
PyPy 3 256M

Problem type

On Zeyu's first day at math class, the professor gives him a sequence of \(N\) integers \({a_i, a_2, …, a_N}\). The professor asks him for the sum of all pairs \((a_i, a_j)\), such that \(1 \le i,j \le N\). Since Zeyu is bad at math, he wants you to write a program which will solve the problem for him.

Input Specification

On the first line, Zeyu will tell you \(N\), the number of integers.

On the next line, Zeyu will give you \(N\) space separated integers; \(a_1, a_2, ... a_N\)

Output Specification

The sum of all pairs \((a_i, a_j)\) such that \(1 \le i,j \le N\). To prevent overflow, Java and C++ users are recommended to use the long or long long datatype, instead of int.


For all subtasks:

\(1 \le N \le 10^6\)

\(-10^5 \le {a_i} \le 10^5\)

Subtask 1 [40%]

\(1 \le N \le 10^3\)

Subtask 2 [60%]

No additional constraints.

Sample input

1 2 3 7

Sample Output



There are no comments at the moment.