Problem:
 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

Solution (Python):










import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    arr = get_array()
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += arr[i] * arr[j]
    print(ans)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array():
    return list(map(int, sys.stdin.readline().split()))


def get_ints():
    return map(int, sys.stdin.readline().split())


def input():
    return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Solution (Python):
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    d = list(map(int, input().rstrip('\n').split()))
    t = 0
    for v in itertools.combinations(d, 2):
        t += (v[0] * v[1])
    print(t)


if __name__ == '__main__':
    slove()

Solution (Python):

N = int(input())
d = list(map(int,input().split()))

ans = 0

for i in range(N):
    for j in range(i+1,N):
        ans += d[i] * d[j]
print(ans)

Solution (Python):










n = int(input())
d = tuple(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += d[i] * d[j]
print(ans)

Solution (Python):
N = int(input())
d = list(map(int,input().split()))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += d[i]*d[j]
print(ans)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
D = list(map(int, sys.stdin.readline().split()))

ans = 0
for i, j in itertools.product(range(N), range(N)):
    if i < j:
        ans += D[i] * D[j]
print(ans)

Solution (Python):
n  = int(input())
arr = [int(i) for i in input().split()]

total = 0

for i in range(n):
    for j in range(i):
        total += arr[i]*arr[j]

print(total)

Solution (Python):
n=int(input())
d=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=d[i]*d[j]
print(ans)

Solution (Python):
N = int(input())
d = list(map(int,input().split()))
ans = 0
for k in range(N-1):
    for l in range(k+1,N):
        ans += d[k]*d[l]
print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans +=A[i]*A[j]

print(ans)

Solution (Python):
n=int(input())
d = list(map(int, input().split()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=d[i]*d[j]
print(ans)

Solution (Python):
n=int(input())
d = list(map(int,input().split()))	
S=0
for i in range(n-1):
    for j in range(n-i-1):
        j+=i+1
        S+=d[i]*d[j]
print(S)

Solution (Python):

N = int(input())

d = list(map(int,input().split()))

ans = 0
for i in range(N):

    for j in range(i):

        ans += d[i] * d[j]

print (ans)

Solution (Python):
n = int(input())
d = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += d[i]*d[j]
print(ans)

Solution (Python):
N = int(input())
d = [int(i) for i in input().split()]

ret = 0
for i in range(N) :
    for j in range(i + 1, N) :
        ret += d[i] * d[j]
print(ret)

Solution (Python):
N=int(input())
D=list(map(int,input().split()))
r=0
for i in range(N-1):
    for j in range(i+1,N):
        r+=D[i]*D[j]
print(r)

Solution (Python):
n = int(input())
d = list(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += d[i] * d[j]

print(ans)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
print((sum(A)**2 - sum([a**2 for a in A]))//2)

Solution (Python):
N = int(input())
D = list(map(int,input().split()))

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans += D[i] * D[j]
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
S = sum(L)

ans = 0
for l in L:
    ans += l*(S-l)
    S -= l
print(ans)

Solution (Python):
N = int(input())
d = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans+=d[i]*d[j]
print(ans)

Solution (Python):
from itertools import combinations

N = int(input())
*D, = map(int, input().split())
ans = 0
for x, y in combinations(D, 2):
    ans += x*y
print(ans)

Solution (Python):
N=int(input())
d=[int(i) for i in input().split()]
X=sum([i*i for i in d])
print((sum(d)**2-X)//2)

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))

ans = 0

for i in range(N):
    for j in range(i+1, N):
        if i == j:
            continue
        else:
            ans += a_list[i] * a_list[j]
print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
dd = inpl()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += dd[i]*dd[j]
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    ans+=a[i]*a[j]
print(ans)

Solution (Python):
n = int(input())
d = list(map(int, input().split()))
ans = 0

for i in range(n):
    for j in range(n):
        if i == j :
            continue
        ans += d[i]*d[j]
print(ans//2)

Solution (Python):
n=int(input())
d=list(map(int,input().split()))
a=0
for i in range(n-1):
  for j in range(i+1,n):
    a+=d[i]*d[j]
print(a)

Solution (Python):
n = int(input())
d = list(map(int, input().split()))
s = 0
for i in range(n-1):
  for j in range(i+1,n):
    s += d[i]*d[j]
print(s)

Solution (Python):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    D = list(map(int, input().split()))

    ans = 0
    for d1 in D:
        for d2 in D:
            ans += d1 * d2

    for d in D:
        ans -= d * d

    print(ans // 2)


sol()

Solution (Python):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
    n = ni()
    d = na()

    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            ans += d[i] * d[j]
    
    print(ans)

main()

Solution (Python):
from collections import defaultdict, deque, Counter
import sys
import heapq
import math



sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    d = [int(a) for a in input().split()]
    
    
    
    
    
    s = 0
    for i in range(len(d)):
        for j in range(i + 1, len(d)):
            s += d[i] * d[j]
    print(s)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
d = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    ans += d[i] * d[j]
print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
ans=0
for i in l:
    ans+=(s-i)*i
print(ans//2)

Solution (Python):
def main():
    N = int(input())
    d = [int(i) for i in input().split()]

    ans = 0
    for i in range(N-1):
        for j in range(i+1,N):
            ans += d[i] * d[j]
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, d: "List[int]"):

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            ans += d[i]*d[j]
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    d = [int(next(tokens)) for _ in range(N)]  
    solve(N, d)


if __name__ == '__main__':
    main()

Solution (Python):

n=int(input())
da=list(map(int,input().split()))
ans=0
for i in range(n):
    ans+=da[i]
ans*=ans
for i in range(n):
    ans-=da[i]**2
print(ans//2)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



N = I()
d = III()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += d[i]*d[j]

print(ans)

Solution (Python):
n=int(input())
d=list(map(int,input().split()))
ans=0
for i in range(n):
	for j in range(n):
		if i<j:
			ans+=d[i]*d[j]
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)

def main():
    n=int(input())
    dd=list(map(int, input().split()))
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            ans+=dd[i]*dd[j]
    print(ans)

main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7

def resolve():
    n=int(input())
    D=list(map(int,input().split()))
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            ans+=D[i]*D[j]
    print(ans)
resolve()

Solution (Python):
N = int(input())
d = list(map(int, input().split()))

ans = 0;
for i in range(N):
    for j in range(i+1, N):
        ans += d[i]*d[j]

print(ans)

Solution (Python):
N = int(input())
*D, = map(int,input().split())

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += D[i]*D[j]
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

res = 0
for i in range(n):
    for j in range(i + 1, n):
        res += a[i] * a[j]
print(res)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    d = LI()
    ans = 0
    for i in range(n):
        for j in range(i):
            ans += d[i]*d[j]
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
N=int(input())
d=list(map(int,input().split()))

ANS=0
for i in range(N-1):
    for j in range(i+1,N):
        ANS+=d[i]*d[j]

print(ANS)

Solution (Python):


from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
d = map(int, raw_input().split())
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += d[i] * d[j]
print ans