101431: [AtCoder]ABC143 B - TAKOYAKI FESTIVAL 2019

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

Problem Statement

It's now the season of TAKOYAKI FESTIVAL!

This year, $N$ takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the $i$-th takoyaki is $d_i$.

As is commonly known, when you eat two takoyaki of deliciousness $x$ and $y$ together, you restore $x \times y$ health points.

There are $\frac{N \times (N - 1)}{2}$ ways to choose two from the $N$ takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these $\frac{N \times (N - 1)}{2}$ values.

Constraints

  • All values in input are integers.
  • $2 \leq N \leq 50$
  • $0 \leq d_i \leq 100$

Input

Input is given from Standard Input in the following format:

$N$
$d_1$ $d_2$ $...$ $d_N$

Output

Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the $N$ takoyaki served.


Sample Input 1

3
3 1 2

Sample Output 1

11

There are three possible choices:

  • Eat the first and second takoyaki. You will restore $3$ health points.
  • Eat the second and third takoyaki. You will restore $2$ health points.
  • Eat the first and third takoyaki. You will restore $6$ health points.

The sum of these values is $11$.


Sample Input 2

7
5 0 7 8 3 3 2

Sample Output 2

312

Input

题意翻译

现在是章鱼烧烤的时间啦!!! 今年将有 $N$ 个章鱼烧(一种里面有章鱼的球状的食物)。第 $i$ 个章鱼烧的美味值是 $d_{i}$ 。 众所周知,当你在吃同时吃美味值为 $x$ 和 $y$ 的章鱼烧时,你将回复 $x\times y$ 的生命值。 在节日里,你有 $\frac{N\times (N-1)}{2} $ 种选法在 $N$ 个章鱼烧中选择两个不同的章鱼烧。 输出 $\frac{N\times (N-1)}{2} $ 种选法所能得到的健康值之和。 by [djh123456](https://www.luogu.com.cn/user/367575) 。

加入题单

上一题 下一题 算法标签: