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



Sample input:
3
3 1 2


Sample output:
11

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import itertools

def main():
    n = int(input())
    D = list(map(int, input().split()))

    C = itertools.combinations(D, 2)
    ans = 0
    for c in C:
        ans += c[0]*c[1]

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(mi())
s=0
t=0
for i in l:
  s+=i
  t+=i**2
print(int((s**2-t)/2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - TAKOYAKI FESTIVAL 2019
def main():
    import itertools

    n = int(input())
    d = list(map(int, input().split()))
    sum = 0

    for v in itertools.combinations(ｄ, 2):
        sum += v[0] * v[1]
    print(sum)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve():
    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)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    D = il()
    ret = 0
    for x, y in itertools.combinations(D, 2):
        ret += x * y
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
d=list(map(int,input().split()))
x=0
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        else:
            x+=d[i]*d[j]
            
print(x//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    D = list(map(int, input().split()))

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
d = readints()
x = (list(itertools.combinations(d, 2)))
ans = 0
for i in range(len(x)):
    ans += x[i][0]*x[i][1]
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

print(a)

Submission status: Accepted

Solution code:
n = int(input())
num = list(map(int,input().split()))
a = 0
b = 0
for i in range(n):
    for j in range(n):
        a = a + num[i] * num[j]

for i in range(n):
    b = b + num[i] * num[i]

print((a - b) // 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = input().split()

sum = 0

for i in range(N-1):
  for j in range(i+1,N):
    #print(int(a[i])*int(a[j]))
    sum += int(a[i])*int(a[j])
  
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = 0

for i in range(n):
    j = i + 1
    while j < n:
        c = c + (a[i] * a[j])
        j += 1

print(c)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
n = int(input())
d = list(map(int, input().split()))
lst = list(itertools.combinations(d, 2))

ans = 0
for i, j in lst:
    ans += i * j
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
d = list(map(int, input().split()))
lst = list(itertools.combinations(d, 2))

ans = 0
for i in lst:
    a = i[0] * i[1]
    ans += a
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
d = [int(x) for x in input().split()]

total = 0
for i in list(combinations(d, 2)):
    total += i[0] * i[1]
print(total)

Submission status: Accepted

Solution code:
N = int(input())
D = [int(s) for s in input().split(' ')]
D_sum = sum(D)
ret = 0
for d in D:
    ret += d * (D_sum - d)

print(ret // 2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
D = [int(s) for s in input().split()]

life = 0

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

print(life)

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())
D = [int(n) for n in input().split()]

value = 0
for i in range(len(D) - 1):
    for j in range(i + 1, len(D)):
        value += D[i] * D[j]

print(value)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
d = list(map(int, input().split()))
ans = 0
sum = sum(d)
for i in range(N):
  ans += d[i]*(sum-d[i])
print(ans//2)

Submission status: Accepted

Solution code:
n = int(input())

d = [int(x) for x in input().split()]

result = 0

for i in range(len(d)):
    for h in range(i+1,len(d)):

        result += d[i] * d[h]

print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

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

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python

def main():
    N = int(input())
    D = list(map(int, input().split()))
    ans = 0
    for i in range(N-1):
        d1 = D[i]
        for d2 in D[i+1:]:
            ans += d1 * d2

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

dans = 0
for i in range(N):
    y = d[i] ** 2
    dans += y

fans = (ans - dans) // 2

print(fans)

Submission status: Accepted

Solution code:
n = int(input())
D = list(map(int, input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

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

total = 0
for i in itertools.combinations(d_list, 2):
    x, y = i
    total += x*y
    
print(total)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def k(n):
  return n**2
a=int(input())
L=list(map(int,input().split()))
c=sum(L)
c=c**2
L=list(map(k,L))
d=sum(L)
print((c-d)//2)

Submission status: Accepted

Solution code:
def main():
    N = int(input())

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

    sum = 0

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

    print(sum)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().strip().split()))
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
d = list(map(int, input().split()))
 
result = 0
# 最後尾はもう全部計算されてるから除外
for i in range(N - 1):
  # i=1個目の時2と3の2パターンをかける
    for j in range(i + 1, N):
        result += d[i] * d[j]
print(result)

# import itertools

# n = input()
# d_list = list(i.combinations(list(map(int,input().split())),2)

# ans = 0

# for i in d_list
   
#    a = i[0] * i[1]
#    ans += a
       
# print(ans)

Submission status: Accepted

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

result = 0
# 最後尾はもう全部計算されてるから除外
for i in range(N - 1):
  # i=1個目の時2と3の2パターンをかける
    for j in range(i + 1, N):
        result += d[i] * d[j]
print(result)

Submission status: Accepted

Solution code:
n=int(input())
d=list(map(int,input().split()))
sum1=sum(d)
sum2=0
for i in d:
    sum2+=i**2
print((sum1**2-sum2)//2)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))

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

Submission status: Accepted

Solution code:
n = int(input())
d = [int(x) for x in input().split()]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

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


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

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
hp = list(map(int, input().split()))
sum = 0

for i in range(n):
  for j in range(n):
    if i != j:
      sum += (hp[i]*hp[j])

sum = int(sum/2)
print(sum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - TAKOYAKI FESTIVAL 2019
https://atcoder.jp/contests/abc143/tasks/abc143_b

"""
import sys


from itertools import combinations

def solve(takoyaki):
    return sum(x * y for x, y in combinations(takoyaki, 2))


def main(args):
    _ = input()
    takoyaki = map(int, input().split())
    ans = solve(takoyaki)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
import itertools


def actual(n, D):
    """
    combinations でゴリ押し
    """
    comb = itertools.combinations(D, 2)

    # return sum([x * y for x, y in comb])

    """
    「順番を考慮しない2要素の選び方」を全探索する際のポイント
        内側のループ変数の始点を外側のループ変数 +1 から始めるとよい。
        これにより、内側のループで選ぶインデックスが必ず外側のループで選ぶインデックスより大きくなり、
        同じ選び方を 2 回見てしまうことを回避できます。
    """
    # s = 0
    # for i in range(len(D)):
    #     for j in range(i + 1, len(D)):
    #         s += D[i] * D[j]
    #
    # return s

    """
    O(N)で解くパターン
    
    ex: a, b, c, d
        a*b + a*c + a*d = a * (b + c +d)
              b*c + b*d = b * (    c +d)
                    c*d = c * (       d)
    """
    s = 0
    for i in range(len(D) - 1):
        s += D[i] * sum(D[i + 1:])

    return s


n = int(input())
D = list(map(int, input().split()))

print(actual(n, D))

Submission status: Accepted

Solution code:
import itertools


def actual(n, D):
    comb = itertools.combinations(D, 2)

    # return sum([x * y for x, y in comb])

    """
    「順番を考慮しない2要素の選び方」を全探索する際のポイント
        内側のループ変数の始点を外側のループ変数 +1 から始めるとよい。
        これにより、内側のループで選ぶインデックスが必ず外側のループで選ぶインデックスより大きくなり、
        同じ選び方を 2 回見てしまうことを回避できます。"""
    s = 0
    for i in range(len(D)):
        for j in range(i + 1, len(D)):
            s += D[i] * D[j]

    return s

n = int(input())
D = list(map(int, input().split()))

print(actual(n, D))

Submission status: Accepted

Solution code:
import itertools


def actual(n, D):
    comb = itertools.combinations(D, 2)

    return sum([x * y for x, y in comb])

n = int(input())
D = map(int, input().split())

print(actual(n, D))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    d = tuple(geta(int))

    print(((sum(d)**2 - sum([di**2 for di in d]))) // 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=0

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

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
d=list(map(int,input().split()))
c=list(combinations(d,2))
#print(c)
sum=0
for i,j in c:
  sum+=i*j
  
print(sum)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    pow = list(map(int, input().split()))
    ans = []
    for i in range(N):
        for j in range(N):
            if i != j:
                ans.append(pow[i]*pow[j])
    print((sum(ans))//2)
resolve()

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    pow = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        for j in range(N):
            if i != j:
                ans += pow[i]*pow[j]
    print(ans//2)
resolve()

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
l = []
for i in range(n):
  for j in range(n):
    if i != j:
      l.append(arr[i] * arr[j])
print(sum(l) // 2)

Submission status: Accepted

Solution code:
import itertools

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

P = 0
for i in itertools.permutations(D, 2):
    P += i[0]*i[1]

print(P // 2)

Submission status: Accepted

Solution code:
import sys
import itertools
input = lambda: sys.stdin.readline().rstrip()


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

    ruiseki = list(itertools.accumulate(d))
    ans = 0
    for i in range(N - 1):
        ans += d[i] * (ruiseki[N - 1] - ruiseki[i])

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
import itertools
input = lambda: sys.stdin.readline().rstrip()


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

    comb = list(itertools.combinations(range(N), 2))
    ans = 0
    for c in comb:
        i1, i2 = c
        ans += d[i1] * d[i2]

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i1, i2 in enumerate(l):
    for j in l[i1+1:]:
        ans += i2 * j
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
from sys import stdin

INF = float("inf")
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


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

Submission status: Accepted

Solution code:
N,*D = map(int,open(0).read().split())

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

Submission status: Accepted

Solution code:
N = int(input())
A=[int(x) for x in input().split(' ')]

heal = 0

for i in range(N-1):
  for j in range(i+1,N):
    heal += A[i]*A[j]

print(heal)

Submission status: Accepted

Solution code:
import itertools
n = int(input())

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

a = list(itertools.combinations(d, 2))

print(sum(i*j for i, j in a))

Submission status: Accepted

Solution code:
N = int(input())
d_lst= [int(x) for x in input().split(' ')]
sum = 0
for i in range(len(d_lst)):
    for j in range(1+i,len(d_lst)):
        sum = sum + d_lst[i]*d_lst[j]
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))

sum = 0

for i in range(n - 1):
  for j in range(i + 1, n):
    sum += l[i] * l[j]
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
dlist = list(map(int, input().split()))

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import decimal # 10進法に変換，正確な計算

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

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

Submission status: Accepted

Solution code:
import itertools

n = int(input())
d = list(map(int, input().split()))
sum = 0

for i in itertools.combinations(d, 2):
    sum += i[0] * i[1]

print(sum)

Submission status: Accepted

Solution code:
import itertools

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

print(sum([i * j for i, j in list(itertools.combinations(d, 2))]))

Submission status: Accepted

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

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

print(out)

Submission status: Accepted

Solution code:
N,*D = map(int,open(0).read().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
D = list(map(int, input().split()))
sum = 0
for i in range(n):
    for j in range(n):
        if i != j:
            sum += D[i] * D[j]
print(sum // 2)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_b
n=int(input())
item_list=list(map(int,input().split()))
c=int((n*(n-1))/2)
Answer=0
for i  in range(c):
    for k in range(i+1,n,1):
        Answer+=item_list[i]*item_list[k]

    
print(Answer)

Submission status: Accepted

Solution code:
n=int(input())
dlist=list(map(int,input().split()))

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

print(sum)

Submission status: Accepted

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

import itertools
e = itertools.combinations(list(range(n)),2)
ans = 0
for i,j in e:
  ans += d[i] * d[j]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
d = list(map(int, input().split()))
a = 0
for i in range(n):
    for j in range(i + 1,n):
        a += d[i] * d[j]
print(a)

Submission status: Accepted

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

import itertools

ans = 0
pairs = list(itertools.combinations(d, 2))

for pair in pairs:
    ans += pair[0] * pair[1]
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
tako=list(map(int,input().split()))
ans=0
for i in range(n-1):
    for j in range(1,n):
        if not j<=i:
            
          
            ans+=tako[i]*tako[j]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = list(map(int, input().split()))
# l = []
total = 0
for i,iv in enumerate(d):
    for j,jv in enumerate(d):
        if i < j:
            # l.append([iv,jv])
            total += iv * jv
# print(l)
print(total)

Submission status: Accepted

Solution code:
N,*D = map(int,open(0).read().split())
import itertools
print(sum(a * b for a,b in itertools.combinations(D,2)))

Submission status: Accepted

Solution code:
n = int(input())
oi = list(map(int,input().split()))

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

Submission status: Accepted

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

import itertools

D = list(range(1, len(d)+1))
p = itertools.permutations(d, 2)

ans = 0
for v in itertools.permutations(D, 2):
    ans = d[v[0]-1] *d[v[1]-1] + ans

print(int(ans/2))

Submission status: Accepted

Solution code:
# ABC 143 B

N = int(input())
D =[int(d) for d in input().split()]
from itertools import combinations
ans =0
for i in list(combinations(D,2)):
    ans+=i[0]* i[1]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as cmb
n = int(input())
D = list(map(int, input().split()))

ans = 0
for c in cmb(D, 2):
    ans += c[0]*c[1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
D = tuple(map(int, input().split()))
s = 0
for i in range(0, len(D)-1):
    for j in range(i+1, len(D)):
        s += D[i] * D[j]
print(s)

Submission status: Accepted

Solution code:
import itertools

def main():
    n = int(input())
    d = map(int, input().split())
    
    h = 0
    for d1, d2 in itertools.combinations(d, 2):
        h += d1 * d2
    print(h)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

combi = list(itertools.combinations(range(N), 2))
sumD = 0
for x in combi:
    sumD += d[x[0]] * d[x[1]]

print(sumD)

Submission status: Accepted

Solution code:
n = int(raw_input())
elems = map(int, raw_input().split(' '))
cumul = 0
res = 0
for j in range(len(elems)):
	res += elems[j] * cumul
	cumul += elems[j]
print res

Submission status: Accepted

Solution code:
import itertools

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

ans = 0
for a, b in list(itertools.combinations(range(N), 2)):
    ans += d[a] * d[b]

print(ans)

Submission status: Accepted

Solution code:
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)