Harryxun/stf_run huggingface dataset:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=arr[i][0]+arr[i][1]
  for j in range(i+1,n-1):
    if ans<=arr[j][1]:
      ans=arr[j][0]+arr[j][1]
    else:
      if (ans-arr[j][1])%ans[j][2]==0:
        ans+=arr[j][0]
      else:
        ans+=arr[j][0]+arr[j][2]-ans%arr[j][2]
  print(ans)
print(0)

### FIXED CODE ###

n=int(input())
arr=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=arr[i][0]+arr[i][1]
  for j in range(i+1,n-1):
    if ans<=arr[j][1]:
      ans=arr[j][0]+arr[j][1]
    else:
      if (ans-arr[j][1])%arr[j][2]==0:
        ans+=arr[j][0]
      else:
        ans+=arr[j][0]+arr[j][2]-ans%arr[j][2]
  print(ans)
print(0)
import sys
input=sys.stdin.readline #文字列入力はするな！！
sys.setrecursionlimit(10**9) #再帰の上限をあげる
n=int(input())
a=list(map(int,input().split()))
z=[0]*(10**6+1)
ans=0
for i in a:
    z[i]+=1

x=[-1]*(10**6+1) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**6:
    if x[i]==-1:
        x[i]=i
        prime.append(i)
    for j in prime:
        if i*j>10**6 or j>x[i]:break
        x[j*i]=j
    i+=1

for i in a:
    f=0
    u=i
    if z[u]>=2:
        f=1
    w=[]
    p=x[u]
    cnt=1
    while u>1:
        if p==x[u//p]:
            cnt+=1
        else:
            w.append([p,cnt])
            cnt=1
        u=u//p
    m=len(w)
    y=1
    def s(d,h,y):
        global m
        global i
        global f
        if d==m-1:
            p=y*(w[d][0]**h)
            if p!=i and z[p]>=1:
                f=1
        else:
            y*=w[d][0]**h
            for j in range(w[d+1][1]+1):
                s(d+1,j,y)
    if m==0:
        if z[1]>=2:
            f=1
    else:
        for j in range(w[0][1]+1):
            s(0,j,1)
        if f==0:
            ans+=1
print(ans)





### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
b=list(set(a))
m=len(b)

p=[0]*(10**6+1)
for i in b:
    if p[i]==0:
        j=2
        while i*j<=10**6:
            p[i*j]=1
            j+=1
a.append(-1)
a.insert(0,-1)
ans=0
for i in range(1,n+1):
    if a[i]!=a[i+1] and a[i]!=a[i-1] and p[a[i]]==0:
        ans+=1
print(ans)
for i in rang(1,10):
 for j in range(1,10):
  print "%dx%d=%d"%(i,j,i*j)

### FIXED CODE ###

for i in range(1,10):
    for j in range(1,10):
       print("{0}x{1}={2}".format(i,j,i*j))
from math import factorial
N, M, K = map(int, input().split())

MOD = 10**9+7

def comb(n, r):
    r = n-r if n-r < r else r
    if r == 0:
        return 1
    ndfact = 1
    for i in range(n, n-r, -1):
        ndfact *= i
    return ndfact // factorial(r)

p = comb(N*M-2, K-2) % MOD
ans = 0
for i in range(N):
    for j in range(M):
        if i == 0 and j == 0:
            continue
        d = i+j
        cnt = (N-i) * (M-j)
        if i != 0 and j != 0:
            cnt *= 2
        ans += d * cnt
        asn %= MOD

print((ans*p)%MOD)


### FIXED CODE ###

from math import factorial
N, M, K = map(int, input().split())

MOD = 10**9+7

fact = [1] * (N*M+1)
for i in range(2, N*M+1):
    fact[i] = fact[i-1] * i % MOD

def comb(n, r):
    r = n-r if n-r < r else r
    return fact[n] * pow(fact[r], MOD-2, MOD) * pow(fact[n-r], MOD-2, MOD) % MOD

p = comb(N*M-2, K-2)
ans = 0
for i in range(N):
    for j in range(M):
        if i == 0 and j == 0:
            continue
        d = i+j
        cnt = (N-i) * (M-j)
        if i != 0 and j != 0:
            cnt *= 2
        ans += d * cnt % MOD
ans = ans * p % MOD

print(ans)
import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


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

d_min = 0
d_max = d

while d_max - d_min >= 1:
    if check(d):
        d_max = d
    else:
        d_min = d
    d = (d_max + d_min) / 2
    # print(d, d_max, d_min)

if check(math.ceil(d_min)):
    print(math.ceil(d_min))
else:
    print(math.ceil(d_min)+1)


### FIXED CODE ###

import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


N, K = map(int, input().split())
leng = list(map(int, input().split()))

d_min = 0
d_max = max(leng)
d = math.ceil(d_max / 2)

while d_max - d_min > 1:
    if check(d):
        d_max = d
        d = math.ceil((d_max + d_min) / 2)
    else:
        d_min = d
        d = int((d_max + d_min) / 2)
    # print(d, d_max, d_min)

print(d_max)
n = input() #カードの枚数
taro = 0
hanako = 0
for i in range(n):
    x = map(str, raw_input().split())  #x[0]:太郎，x[1]:花子
    #print x[0]
    #print x[1]
    if(x[0] > x[1]):
        taro += 3
    elif(x[0] == x[1]):
        taro += 1
        hanako += 1
    else:
        hanako += 3
print '%d %d' %(taro, hanako)

### FIXED CODE ###

n = input()
taro = 0
hanako = 0
for i in range(n):
    x = map(str, raw_input().split())
    #print x[0]
    #print x[1]
    if(x[0] > x[1]):
        taro += 3
    elif(x[0] == x[1]):
        taro += 1
        hanako += 1
    else:
        hanako += 3
print '%d %d' %(taro, hanako)

exit(0)
n = int(input())
S = input()
a = list(S)
ans = 0

for i in range(n-2,-1,-1):

    if a[i] == "#" and a[i+1] == ".":
        bns += 1
        a[i] = "."

print(ans)

### FIXED CODE ###

n = int(input())
s = list(input())
b = [0] * n
w = [0] * n
x,y = 0,0
ans = 0
for i in range(n):
    if s[i] == '#':
        x += 1
    else:
        y += 1
    b[i] = x
    w[i] = y

ans = float('inf')
for i in range(n):
    ans = min(ans, b[i] + w[n-1] - w[i])
print(min(ans, b[n-1], w[n-1]))
print str(48 - int(raw_input))

### FIXED CODE ###

print str(48 - int(raw_input()))
a=int(input())
if a=>30:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a=int(input())
if a>=30:
  print('Yes')
else:
  print('No')
N = int(input())
if N ==1:
  print("Hello World")
else:
  A,B = [int(x) for x in input().split()]
  print(A+B)
  

### FIXED CODE ###

N = int(input())
if N ==1:
  print("Hello World")
else:
  A = int(input())
  B =int(input())
  print(A+B)
import itertools
n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

a = [i for i in range(10)]
combi = []
for i in range(10):
    combi.extend(list(itertools.combinations(a,i+ 1)))
#print(combi)

ans =  - float("inf")
for i in combi:
    #print(i)
    cnt = [0]*10
    for j in i:
        for k in range(n):
            cnt[k] += f[k][j]
    profit = sum([p[k][cnt[k]] for k in range(n)])
    ans = max(ans, profit)
print(ans)

### FIXED CODE ###

import itertools
n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

a = [i for i in range(10)]
combi = []
for i in range(10):
    combi.extend(list(itertools.combinations(a,i+ 1)))
#print(combi)

ans =  - float("inf")
for i in combi:
    #print(i)
    cnt = [0]*n
    for j in i:
        for k in range(n):
            cnt[k] += f[k][j]
    profit = sum([p[k][cnt[k]] for k in range(n)])
    ans = max(ans, profit)
print(ans)
N,A=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0 for i in range(50*50)] for j in range(N+1) ]for k in range(N+1)]
dp[0][0][0]=1
for i in range(1,N+1):
  for j in range(N+1):
    for k in range(50*50):
      dp[i][j][k]=dp[i-1][j][k]
      if x[i-1]<= k and j>0: dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,N+1):
  ans+=dp[N][j][j*A]
print(ans)

### FIXED CODE ###

N,A=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0 for i in range(50*50+1)] for j in range(N+1) ]for k in range(N+1)]
dp[0][0][0]=1
for i in range(1,N+1):
  for j in range(N+1):
    for k in range(50*50+1):
      dp[i][j][k]=dp[i-1][j][k]
      if x[i-1]<= k and j>0: dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,N+1):
  ans+=dp[N][j][j*A]
print(ans)
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**10 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([1<<(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()

### FIXED CODE ###

n=int(input())
print(1-(n//2)/n)
n,a,b=map(int,input().split())
lis=""
ans=0
for i in range(n):
 for b in range(a):
  ans+=1
 for r in range(b+1):
print(ans)

### FIXED CODE ###

n,a,b=map(int,input().split())
ans=int(n/(a+b))*a
if n%(a+b)>=a:
    ans+=a
else:
    ans+=n%(a+b)
print(ans)
k,s=map(int,input().split())
x=0
for a in range(k+1):
  if a>s:
    break
  for b in range(k+1):
    if a+b>s:
      break
    for c in range(k+1):
      if a+b+c=s:
        x+=1
print(x)

### FIXED CODE ###

k,s=map(int,input().split())
x=0
m=min(s+1,k+1)
for a in range(m):
  for b in range(m):
    if a+b>s or a+b<s-k:
      continue
    x+=1
print(x)
valores = [int(input()), int(input()), int(input())]
del(valores[valores.index(max(valores))])
print(valores[0]+valores[1])


### FIXED CODE ###

p,q,r=map(int,input().split())
sum=min(p+q,q+r,p+r)
print(sum)
import numpypy as np
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]

def calc(s):
    res = []
    for v in s:
        v.append('-')
        tmp = []
        nc = ''
        nn = 0
        for c in v:
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp = tmp + [0 for _ in range(nn)]
                else:
                    tmp = tmp + [nn for _ in range(nn)]
                nc = c
                nn = 1
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        v = ['-']
        tmp = []
        nc = ''
        nn = 0
        for i in range(h+1):
            if i == h:
                c = '-'
            else:
                c = s[i][j]
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp = tmp + [0 for _ in range(nn)]
                else:
                    tmp = tmp + [nn for _ in range(nn)]
                nc = c
                nn = 1
        res.append(tmp)
    return res

tate = np.asarray(calc2(S)).T
yoko = np.asarray(calc(S))
print((tate + yoko).max() - 1)


### FIXED CODE ###

h, w = map(int, input().split())
S = [input() for _ in range(h)]

def calc(s):
    res = []
    for v in s:
        v = v + '-'
        tmp = []
        nc = v[0]
        nn = 0
        for c in v:
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        tmp = []
        nc = s[0][j]
        nn = 0
        for i in range(h):
            c = s[i][j]
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        if nc == '#':
            tmp.extend([0 for _ in range(nn)])
        else:
            tmp.extend( [nn for _ in range(nn)])
        res.append(tmp)
    return res

tate = calc2(S)
yoko = calc(S)

print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)
n = int(input())
a = list(map(int, input().split()))

count = 0
while all(i%2 == 0 for i in a):
    a = [i/2 for i in a]
    count += 1
print(count)


### FIXED CODE ###

i = input()
print(i.count("1"))
N = int(input())

A = lit(map(int, input().split()))

if 0 in A:
    print(0)
    return
    
limit = 10**18

result = 1
for value in A:
    result *= value
    if result > limit:
        result = -1
        break

print(result)

### FIXED CODE ###

N = int(input())

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

if 0 in A:
    print(0)
    exit()

limit = 10**18

result = 1
for value in A:
    result *= value
    if result > limit:
        result = -1
        break

print(result)
a=int(input())
b=int(input())
s=a*b
print(s)


### FIXED CODE ###

s = raw_input().split()
a = int(s[0])
b = int(s[1])
print("{0} {1}".format(a*b, 2*(a+b)))
from collections import deque, defaultdict

def main():
  n=int(input())
  edges=[tuple(map(int,input().split())) for _ in range(n-1)]
  d=defaultdict(list)
  for e in edges:
    d[e[0]].append(e[1])
    d[e[1]].append(e[0])
  def dist(m):
    dl=[-1]*(n+1)
    cv=deque([m])
    nv=deque([1])
    while nv:
      c+=1
      cv.extend(nv)
      nv.clear()
      for e in cv:
        dl[e]=c
        for x in d[e]:
          if dl[x]<0:
            nv.append(x)
      cv.clear()
    return dl[1:]
  fnc=dist(1)
  snk=dist(n)
  j=sum([(fnc[i]<=snk[i])-(fnc[i]>snk[i]) for i in range(n)])
  if j>0:
    print('Fennec')
  else:
    print('Snuke')

if __name__=='__main__':
    main()


### FIXED CODE ###

import sys
from collections import defaultdict
from collections import deque

n=int(input())
edges=[tuple(map(int,input().split())) for _ in range(n-1)]
d=defaultdict(list)
for e in edges:
  d[e[0]].append(e[1])
  d[e[1]].append(e[0])
fnc=[-1]*(n+1)
snk=[-1]*(n+1)
fnc[1]=0
snk[n]=0
cv=deque([1])
nv=deque([1])
c=-1
while nv:
  c+=1
  cv.extend(nv)
  nv.clear()
  for e in cv:
    fnc[e]=c
    for x in d[e]:
      if fnc[x]<0:
        nv.append(x)
  cv.clear()
cv.append(n)
nv=deque([1])
c=-1
while nv:
  c+=1
  cv.extend(nv)
  nv.clear()
  for e in cv:
    snk[e]=c
    for x in d[e]:
      if snk[x]<0:
        nv.append(x)
  cv.clear()

j=sum([(fnc[i]<=snk[i])-(fnc[i]>snk[i]) for i in range(1,n+1)])
if j>0:
  print('Fennec')
else:
  print('Snuke')
from decimal import *
A, B = map(float, input().split())
B = int(B * 100)
A = int(A)
ans = A * B
ans = // 10
ans = // 10
print(ans)

### FIXED CODE ###

from decimal import Decimal
A,B = map(str, input().split())
A = int(A)
B = Decimal(B)
print(int(A * B))
a=str(input())
l1 = [1,2,3]
for i in a:
  for j in l1:
  	if i == '7':
      print('Yes')
        break
    else if l1 == 3:
      print('No')

### FIXED CODE ###

a = str(input())
if '7' in a:
  print('Yes')
else:
  print('No')
n  = int(input())
w = []

w.append(input())

ans = 'Yes'
for i in range(1,n,1):
  w.append(input())
  l = len(w[j])
  if w[i][0:1] != w[j][l-1:l]: ans = 'No'
  for j in range(i):
    if w[i] == w[j]: ans = 'No'

print(ans)

### FIXED CODE ###

n  = int(input())
w = []

w.append(input())

ans = 'Yes'
for i in range(1,n,1):
  w.append(input())
  l = len(w[i-1])
  if w[i][0:1] != w[i-1][l-1:l]:
    ans = 'No'
    break
  for j in range(i):
    if w[i] == w[j]:
      ans = 'No'
      break

print(ans)
n,z,w=map(int,input().split())
a[] = map(int,input().split())
print(max(abs(a[-1]-w,a[-1]-a[-2]))

### FIXED CODE ###

n,z,w=map(int,input().split())
a = list(map(int,input().split()))
t = 0
if n>1 :t = abs(a[-1]-a[-2])
print(max(abs(a[-1]-w),t))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))

N = l1[0]
K = l1[1]
l2.sort(reverse=True)
for i in range(K):
  l2[i] = 0
print(sum(l2))

### FIXED CODE ###

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))

K = l1[1]
l2.sort(reverse=True)
print(sum(l2[K:]))
# keyence2019C - Exam and Wizard
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    dif = sorted(i - j for i, j in zip(A, B))
    ans, shortage = 0, 0
    for i in dif:
        if i < 0:
            ans += 1
            shortage += i
        else:
            break
    for i in dif[::-1]:
        if shortage >= 0:
            print(ans)
            return
        ans += 1
        shortage += i
    print(-1)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# AGC003B - Simplified mahjong
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, [input() for _ in range(N)]))
    ans = 0
    for i in range(N - 1):  # make pairs greedily
        ans += A[i] // 2  # pairs with same cards
        if A[i] % 2 and A[i + 1]:  # pairs with a neighbor
            ans += 1
            A[i + 1] -= 1
    ans += A[-1] // 2  # pairs with the same cards in the last one
    print(ans)


if __name__ == "__main__":
    main()
N = int(input())
aaa = map(int, input().split())
ans = 0
MOD = 1_000_000_007
for i in range(N-1):
    for j in range(i + 1, N):
        ans += aaa[i] ^ aaa[j]
        ans %= MOD
print(ans)


### FIXED CODE ###

N = int(input())
aaa = list(map(int, input().split()))
bbb = [format(a, '061b') for a in aaa]

zero = [0] * 61
one = [0] * 61
for i in range(61):
    s = ''.join(list(b[-(i+1)] for b in bbb))
    zero[i] = s.count('0')
    one[i] = s.count('1')
ans = 0
MOD = 1_000_000_007
for i, o, l in zip(range(61), zero, one):
    ans += 2**i * o * l
    ans %= MOD
print(ans)
x=input()
s=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
for i in s:
  if x.count(i)==0:
    print(i)
    exit()

### FIXED CODE ###

x=input()
s=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in s:
  if x.count(i)==0:
    print(i)
    exit()
print("None")
s = input()
l = len(s)
#後ろから見たら一意
import sys
i = l-1
try:
    while i>0:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dremer":
                i-=7
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
        	else:
            	print("NO")###
            	sys.exit()
    print("YES")
except:
    print("NO")


### FIXED CODE ###

s = input()
l = len(s)
#後ろから見たら一意
"""
tryブロックでsys.exit()を呼ぶと強制終了しない。
"""
import sys
i = l-1
try:
    while i>-1:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dreamer":
                i-=7
            else:
                print("NO")###
                sys.exit()
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
            else:
                print("NO")###
                sys.exit()
    print("YES")
except:
    pass
プ
 問題
 質問
 提出
 提出一覧
 順位表
 コードテスト
 解説
提出 #5696340

ソースコード 

Copy
Copy
# 入力
H,W=map(int,input().split())
 
l=[]
for i in range(H):
  x=input()
  # 白いマスのみからなる場合は追加しない
  if x!='.'*W:
    l.append(x)
 
rm=[]
for i in range(W):
  # フラグ
  f=True
  for j in range(len(l)):
    if l[j][i]=='#':
      f=False
 
  # 取り除く列の添字を保存しておく
  if f:
    rm.append(i)
 
a=[]
for x in l:
  for i in rm[::-1]:
    x=x[:i]+x[i+1:]
  a.append(''.join(x))
 
# 出力
for i in range(len(a)):
  print(''.join(a[i]))

### FIXED CODE ###

N, i = map(int, input().split())

print(N-i +1)
def BubbleSort(A,n):
    count = 0
    for i in range(n):
        for j in range(n-1,i,-1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                print (A[j], A[j-1])
                count += 1
    return A, count


n = int(input())
A = [int(input()) for i in range(n)]
count = 0
ans = 0
ans, count =  (BubbleSort(A,n))
ans = list(map(str,ans))

print (" ".join(ans))
print (count)

### FIXED CODE ###

n = int(input())
 
numbers = list(map(int, input().split(" ")))
 
cnt = 0
 
for i in range(n):
    for j in range(n - 1, i, -1):
        if numbers[j] < numbers[j - 1]:
            numbers[j],numbers[j - 1] = numbers[j - 1], numbers[j]
            cnt += 1
 
numbers = map(str, numbers)
print(" ".join(numbers))
 
print(cnt)
s = input()
if s[3] == s[4] and s[5] == s[6]:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

s = input()
if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')
import numpy as np
H,W = map(int,input().split())
h = [0]*H
w = [0]*W
l = [list(input()) for i in range(H)]
for i in range(H):
    if all([i=='.' for i in l[i][:]]):
        h[i]=1
for j in range(W):
    if all([j=='.' for j in np.array(l).T[j][:]]):
        w[j]=1
for i in range(H):
    for j in range(W):
        if h[i]==0 and w[j]==0:
            print(l[i][j],end='')
    if h[i]==0:
        print()

### FIXED CODE ###

H,W = map(int,input().split())
h = [0]*H
w = [0]*W
l = [list(input()) for i in range(H)]
for i in range(H):
    if all([i=='.' for i in l[i][:]]):
        h[i]=1
lt = list(zip(*l))
for j in range(W):
    if all([j=='.' for j in lt[j][:]]):
        w[j]=1
for i in range(H):
    for j in range(W):
        if h[i]==0 and w[j]==0:
            print(l[i][j],end='')
    if h[i]==0:
        print()
N, x = map(int, input().split())
A = [int(i) for i in input().split()]

A.sort()
ans = []
for i in A:
	if x < i:
		break
	ans += 1
	x -= i
	else:
		break

if x > 0:
		ans -= 1
print(ans)


### FIXED CODE ###

n, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
for a in A:
    x -= a
    if x >= 0:
        ans += 1
    else:
        break
if x > 0:
    ans -= 1
print(ans)
n = int(input())
a = [input() for i in range(n)]


print(min(a), max(a), sum(a))





### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
 
 
print(min(a), max(a), sum(a))
inpl = lambda: list(map(int, input().split()))
H, W = inpl()
def next_sq(sq):
  h, w = sq
  if h % 2 == 0:
    if w == h-1:
      return h+1, w
    else:
      return h, w+1
  else:
    if w == 0:
      return h+1, w
    else:
      return h, w-1
a = [inpl() for _ in range(H)]
n = sum(sum(a[h][w] % 2 for w in range(W)) for h in range(H))
if n < 2:
  print(0)
  exit()
sq = (0, 0)
prev = None
for _ in range(H*W):
  h, w = sq
  if prev is not None:
    print(prev[0], prev[1], h, w)
    if a[h][w] % 2:
      n -= 1
      if n < 2:
        break
      prev = None
    else:
      prev = sq
  elif a[h][w] % 2:
	n -= 1
    prev = sq
  sq = next_sq(sq)

### FIXED CODE ###

inpl = lambda: list(map(int,input().split()))

H, W = inpl()
A = []
for _ in range(H):
    A.append(inpl())

def pos(n):
    q, m = divmod(n, W)
    if q % 2:
        m = (W-1) - m
    return q, m

ans = []
f = 0
hn, wn = 0, 0
for n in range(H*W-1):
    h, w = hn, wn
    hn, wn = pos(n+1)
    if (f+A[h][w]) % 2:
        ans.append([h+1,w+1,hn+1,wn+1])
        f = 1
    else:
        f = 0

print(len(ans))
for rec in ans:
    print(rec[0],rec[1],rec[2],rec[3])
import math
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
b = [-1]
b.extend(a)
b.extend([N+1])
ans = 1
def fibo(t):
    if t < 1:
        return 0
    else:
        fi = (int(1/math.sqrt(5)*(((1+math.sqrt(5))/2)**dan-((1-math.sqrt(5))/2)**dan)+0.0000001))%1000000007
        return fi
for i in range(M+1):
    dan = b[i+1]-1 - b[i]
    ans = ans*fibo(dan)%1000000007
print(ans)

### FIXED CODE ###

import math
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
b = [-1]+ a+ [N+1]
fib = [0,1]
for i in range(10**5):
    fib.append((fib[-1]+fib[-2])%1000000007)
ans = 1
for i in range(len(b)-1):
    ans= (ans*fib[b[i+1]-b[i]-1])%1000000007
print(ans)
del = [int(d) for d in input().split()]
n = len(del)
sum = 0
i = 0

while i < n - 1:
  k = i
  while k < n - 1:
    k += 1
    sum += del[i] * del[k]
  i += 1
  
print(sum)



### FIXED CODE ###

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

while i < n - 1:
  k = i
  while k < n - 1:
    k += 1
    sum += deliciousness[i] * deliciousness[k]
  i += 1
  
print(sum)