#P8772. [蓝桥杯 2022 省 A] 求和

[蓝桥杯 2022 省 A] 求和

Problem Description

Given nn integers a1,a2,,ana_{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 nn.

The second line contains nn integers a1,a2,ana_{1}, a_{2}, \cdots a_{n}.

Output Format

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

4
1 3 6 9
117

Hint

For 30%30\% of the testdata, 1n1000,1ai1001 \leq n \leq 1000, 1 \leq a_{i} \leq 100.

For all testdata, 1n2×105,1ai10001 \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