P8772 [Lanqiao Cup 2022 NOI Qualifier A] Summation

Description

Given $n$ integers $a_{1}, a_{2}, \cdots, a_{n}$, find the sum of the products of every pair of them, that is, $$ S=a_{1} \cdot a_{2}+a_{1} \cdot a_{3}+\cdots+a_{1} \cdot a_{n}+a_{2} \cdot a_{3}+\cdots+a_{n-2} \cdot a_{n-1}+a_{n-2} \cdot a_{n}+a_{n-1} \cdot a_{n} $$

Input Format

The first line contains an integer $n$. The second line contains $n$ integers $a_{1}, a_{2}, \cdots a_{n}$.

Output Format

Output an integer $S$, representing the required sum. Please use an appropriate data type for the computation.

Explanation/Hint

For $30\%$ of the testdata, $1 \leq n \leq 1000, 1 \leq a_{i} \leq 100$. For all testdata, $1 \leq n \leq 2\times10^5, 1 \leq a_{i} \leq 1000$. Lanqiao Cup 2022 NOI Qualifier A Group, Problem C. Translated by ChatGPT 5