Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
Al = list(set(A))
Al.sort(reverse = True)
HW = []
for i in Al:
  n = A.count(i)
  for j in range(min(n//2,2)):
    HW.append(i)
  if len(HW)>=2:
    break
HW = HW + [0,0]
print(HW[0]*HW[1])

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse = True)
HW = []
i = 1
while i<N:
  if A[i]==A[i-1]:
    n = A.count(A[i])
    HW += [A[i]]*(min(n//2,2))
    i = i + n -1
  else:
    i = i + 1
  if len(HW)>=2:
    break
if len(HW)<2:
  print(0)
else:
  print(HW[0]*HW[1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
Al=list(set(A))
Al.sort(reverse = True)
HW = []
for i in Al:
  n = A.count(i)
  for j in range(min(n//2,2)):
    HW.append(i)
  if len(HW)>=2:
    break
HW = HW + [0,0]
print(HW[0]*HW[1])

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse = True)
HW = []
i = 1
while i<N:
  if A[i]==A[i-1]:
    n = A.count(A[i])
    HW += [A[i]]*(min(n//2,2))
    i = i + n -1
  else:
    i = i + 1
  if len(HW)>=2:
    break
if len(HW)<2:
  print(0)
else:
  print(HW[0]*HW[1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
#A.sort(reverse = True)
Al=list(set(A))
Al.sort(reverse = True)
HW = []
for i in Al:
  n = A.count(i)
  for j in range(min(n//2,2)):
    HW.append(i)
  if len(HW)>=2:
    break
HW = HW + [0,0]
print(HW[0]*HW[1])

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse = True)
HW = []
i = 1
while i<N:
  if A[i]==A[i-1]:
    n = A.count(A[i])
    HW += [A[i]]*(min(n//2,2))
    i = i + n -1
  else:
    i = i + 1
  if len(HW)>=2:
    break
if len(HW)<2:
  print(0)
else:
  print(HW[0]*HW[1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = A.count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = (A[d:d+4]).count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
Ans = []
d = 0
while len(Ans) < 2:
  c = A.count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
print(Ans[0]*Ans[1])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = (A[d:d+4]).count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(set(A))
B.sort()
B.reverse()
C = []
for i in range(len(B)):
  c = A.count(B[i])
  if c//2!=0:
    for j in range(c//2):
      C.append(B[i])
  if len(C)==2:
    break
if len(C)==0:
  print(0)
else:
  print(C[0]*C[1])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = (A[d:d+4]).count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(set(A))
B.sort()
B.reverse()
C = []
for i in range(len(B)):
  c = A.count(B[i])
  if c//2!=0:
    for j in range(c//2):
      C.append(B[i])
  if len(C)==2:
    break
if len(C)==0:
  print(0)
else:
  print(C[0]*C[1])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = (A[d:d+4]).count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])
Buggy python submission (verdict: Runtime Error):
from math import gcd
from math import reduce
from fractions import gcd
from functools import reduce
def Gcd(list):
    gcd = 1
    G = reduce(gcd, list)
    return G

A = [2,6,8]
print(Gcd(A))


Fixed submission:
#####################
#複数の最小公倍数lcm
#####################
from fractions import gcd
def Lcm(list):
  L = 1
  for a in list:
    L = (a // gcd(a, L))*L
  return L
n= int(input())
A = [int(input()) for i in range(n)]
print(Lcm(A))

Buggy python submission (verdict: Runtime Error):
#####################
#複数の最小公倍数lcm
#####################
from fractions import gcd
def Lcm(list):
  for a in list:
    L = (a // gcd(a, L))*L
  return L
n= int(input())
A = [int(input()) for i in range(n)]
# A = [2,6,8]
print(Lcm(A))



Fixed submission:
#####################
#複数の最小公倍数lcm
#####################
from fractions import gcd
def Lcm(list):
  L = 1
  for a in list:
    L = (a // gcd(a, L))*L
  return L
n= int(input())
A = [int(input()) for i in range(n)]
print(Lcm(A))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, input().split())
TO = set([])
FM = set([])
ans = 'IMPOSSIBLE'
for i in range(M):
    f,t = map(int, input().split())
    if f == 1:
        TO.add(t)
    elif t == N:
        FM.add(f)
#    print(TO,FM,TO & FM)
    if len(TO & FM)>0:
      ans = 'POSSIBLE'
print(ans)

Fixed submission:
N,M=map(int, input().split())
TO = set([])
FM = set([])
for i in range(M):
    f,t = map(int, input().split())
    if f == 1:
        TO.add(t)
    elif t == N:
        FM.add(f)
if len(TO & FM)>0:
    ans = 'POSSIBLE'
else:
    ans = 'IMPOSSIBLE'
print(ans)
Buggy python submission (verdict: Runtime Error):
a = map(int,input(),split())
print((sorted(a))[0:2])

Fixed submission:
a = map(int,input().split())
print(sum((sorted(a))[0:2]))

Buggy python submission (verdict: Runtime Error):
a = map(int,input(),split())
print((a.sort())[0:2])

Fixed submission:
a = map(int,input().split())
print(sum((sorted(a))[0:2]))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
item = [int(input()) for i in range(N)]
ans=0
for i in range(2 ** N):
    out = 0
    for j in range(N):  # このループが一番のポイント
        if (i >> j) & 1:  # 順に右にシフトさせ最下位bitのチェックを行う
            out+=item[j]  # フラグが立っていたら 加算する
    if str(out)[-1]=='0':
        out = 0
    ans=max(ans,out)
print(ans)

Fixed submission:
N=int(input())
items = [int(input()) for i in range(N)]
tot=sum(items)
ans=0
if tot%10!=0:
  ans=tot
else:
  items.sort()
  for i in range(N):
    if items[i]%10!=0:
      ans=tot-items[i]
      break
print(ans)
Buggy python submission (verdict: Runtime Error):
o = int(input())
e = int(input())
if len(o)-len(e)==1:
  x = o[-1]
else:
  x = ''
ans = ''
for i in range(len(e)):
  ans += o[i] + e[i]
ans += x
print(ans)

Fixed submission:
o = input()
e = input()
if len(o)-len(e)==1:
  x = o[-1]
else:
  x = ''
ans = ''
for i in range(len(e)):
  ans += o[i] + e[i]
ans += x
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
if a = "H":
  print(b)
elif b = "H":
  print("D")
else:
  print("H")

Fixed submission:
a,b = input().split()
if a == "H":
  print(b)
elif b == "H":
  print("D")
else:
  print("H")
Buggy python submission (verdict: Runtime Error):
X=int(input())
import numpy as np
dp = np.zeros(X+1, dtype = int) #xに到達できる判定
dp[0] = 1
for t in range(1,X+1):
    if dp[X-t]==1:
        print(t)
        break
    else:
        dp[t:] = dp[:X+1-t]

Fixed submission:
X=int(input())
s=0
for t in range(X+1):
  s+=t
  if s>=X:
    print(t)
    break

Buggy python submission (verdict: Runtime Error):
X=int(input())
import numpy as np
dp = np.zeros(X+1, dtype = int) #xに到達できる判定
dp[0] = 1
for t in range(1,X+1):
    if dp[X-t]==1:
        print(t)
        break
    else:
        dp[t:] = dp[:X+1-t]
    print(dp)

Fixed submission:
X=int(input())
s=0
for t in range(X+1):
  s+=t
  if s>=X:
    print(t)
    break

Buggy python submission (verdict: Runtime Error):
X=int(input())
import numpy as np
dp=[[False]*(X+1) for _ in range(X+1)]
dp[0][0]=True
for t in range(1,X+1):
  if dp[t-1][X-t]==True:
    ans = t
    break
  for x in range(0,X+1):
    if x>=t:
      dp[t][x]=dp[t-1][x-t]
    else:
      dp[t][x]=dp[t-1][x]
print(ans)

Fixed submission:
X=int(input())
s=0
for t in range(X+1):
  s+=t
  if s>=X:
    print(t)
    break

Buggy python submission (verdict: Time Limit Exceeded):
X=int(input())
#幅
from collections import deque
def dfs_2(start,goal):
  q = deque([])   # スタック
  q.append([start])
  flg = 0
  while flg==0:
    p = q.popleft()         # スタック取りだし（先頭）
    jp = len(p)
#    if p[-1]-jp == goal or p[-1]+jp == goal:
    if p[-1]+jp == goal:
      return jp
    else:
      p0 = [p[-1]]
      pp = [p[-1]+jp]
#      pm = [p[-1]-jp]
      q.append(p+pp)# スタック追加
#      q.append(p+pm)
      q.append(p+p0)

print(dfs_2(0,X))

Fixed submission:
X=int(input())
s=0
for t in range(X+1):
  s+=t
  if s>=X:
    print(t)
    break

Buggy python submission (verdict: Time Limit Exceeded):
X=int(input())
#幅
from collections import deque
def dfs_2(start,goal):
  q = deque([])   # スタック
  q.append([start])
  flg = 0
  while flg==0:
    p = q.popleft()         # スタック取りだし（先頭）
    jp = len(p)
    if p[-1]-jp == goal or p[-1]+jp == goal:
      return jp
    else:
      p0 = [p[-1]]
      pp = [p[-1]+jp]
      pm = [p[-1]-jp]
      q.append(p+pp)# スタック追加
      q.append(p+pm)
      q.append(p+p0)

print(dfs_2(0,X))

Fixed submission:
X=int(input())
s=0
for t in range(X+1):
  s+=t
  if s>=X:
    print(t)
    break
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    ret = 0
#    print(Ti)
    while len(Ti)>0:
        Tto = K + Ti[0]
        Ti = Ti[min(C,bisect_right(Ti[:min(C,len(Ti))], Tto)):]
        ret += 1
#        print(Ti)
    print(ret)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    i = 0
    ret = 0
    while i<N:
        ret += 1
        s = i
        Ts = Ti[i]
        while i<N and Ti[i]<=(Ts+K) and (i-s)<C:
            i += 1

    print(ret)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    ret = 0
#    print(Ti)
    while len(Ti)>0:
        Tto = K + Ti[0]
        Ti = Ti[min(C,bisect_right(Ti, Tto)):]
        ret += 1
#        print(Ti)
    print(ret)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    i = 0
    ret = 0
    while i<N:
        ret += 1
        s = i
        Ts = Ti[i]
        while i<N and Ti[i]<=(Ts+K) and (i-s)<C:
            i += 1

    print(ret)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    ret = 0
#    print(Ti)
    while len(Ti)>0:
        Tto = K + Ti[0]
        Ti = Ti[min(C,bisect_right(Ti, Tto)):]
        ret += 1
#        print(Ti)
    print(ret)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    i = 0
    ret = 0
    while i<N:
        ret += 1
        s = i
        Ts = Ti[i]
        while i<N and Ti[i]<=(Ts+K) and (i-s)<C:
            i += 1

    print(ret)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
s=input()
st=s.index('A')
t=s
t.reverse()
en=t.index('Z')
print(len(s)-st-en)

Fixed submission:
s=input()
st=s.index('A')
t=s[::-1]
en=t.index('Z')
print(len(s)-st-en)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
nw = 0
ans = 0
for i in s:
  if i='I':
    nw+=1
  else:
    nw-=1
  ans = max(ans,nw)
print(ans)
  

Fixed submission:
n=int(input())
s=list(input())
nw = 0
ans = 0
for i in s:
  if i=='I':
    nw+=1
  else:
    nw-=1
  ans = max(ans,nw)
print(ans)
Buggy python submission (verdict: Runtime Error):
print(input().replace(',',' ')

Fixed submission:
print(input().replace(',',' '))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    K, S = map(int, input().split())
    ret = 0
    for z in range(K+1):
        for y in range(K+1):
            if S-z-y in range(K+1):
                ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
  if x<=s:
    for y in range(k+1):
      z=s-(x+y)
      if 0<=z<=k:
        cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N=int(input())
T=list(map(int,input().split())
M=int(input())
Ans=sum(T)
for i in range(M):
  p,x=map(int,input().split())
  xx=Ans+x-T[p-1]
  print(x)


Fixed submission:
N=int(input())
T=list(map(int,input().split()))
M=int(input())
Ans=sum(T)
for i in range(M):
  p,x=map(int,input().split())
  xx=Ans+x-T[p-1]
  print(xx)

Buggy python submission (verdict: Runtime Error):
N=int(input())
T=list(map(int,input().split())
M=int(input())
Ans=sum(T)
for i in range(M):
  p,x=map(int,input().split()))
  xx=Ans+x-T[p-1]
  print(x)


Fixed submission:
N=int(input())
T=list(map(int,input().split()))
M=int(input())
Ans=sum(T)
for i in range(M):
  p,x=map(int,input().split())
  xx=Ans+x-T[p-1]
  print(xx)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
if abs(n-x)<=1 :
  print('Yes')
else:
  print('No')
  exit()
if n == x:
  for i in range(2*(n-1)):
    print(i+1)
elif x == n-1:
  print(n)
  for i in range(2*(n-1)):
    if i != n:
      print(i)
else x == n-1:
  for i in range(2*(n-1)):
    if i != n:
      print(i)
  print(n)

Fixed submission:
n, x = map(int, input().split())
if 2<=x<=2*(n-1):
  print('Yes')
else:
  print('No')
  exit()
  
if x == n:
  for i in range(1, 2*n):
    print(i)
elif x < n:
  for i in range(n, x, -1):
    print(i)
  for i in range(1, x+1):
    print(i)
  for i in range(n+1, 2*n):
    print(i)
else:
  for i in range(1, n):
    print(i)
  for i in range(x, 2*n):
    print(i)
  for i in range(x-1, n-1, -1):
    print(i)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
def pt(n,k):
  if n==1:
    return k
  else:
    return pt(n-1,k)*(k-1)
print(pt(n,k))

Fixed submission:
n,k=map(int,input().split())
def pt(n,k):
  if n==1:
    return k
  else:
    return pt(n-1,k)*(k-1)
print(k*((k-1)**(n-1)))
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
cab,cb=0,0
for i in range(n):
  s=input()
  if s=='c':
    print('No')
  if s=='a':
    if cab<a+b:
      print('Yes')
      cab+=1
    else:
      print('No')
  if s=='b':
    if cab<a+b and cb<b:
      print('Yes')
      cab+=1
      cb+=1
    else:
      print('No')

Fixed submission:
n,a,b=map(int,input().split())
cab,cb=0,0
S=input()
for i in range(n):
  s=S[i]
  if s=='c':
    print('No')
  if s=='a':
    if cab<a+b:
      print('Yes')
      cab+=1
    else:
      print('No')
  if s=='b':
    if cab<a+b and cb<b:
      print('Yes')
      cab+=1
      cb+=1
    else:
      print('No')
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
a=min(1,a)
b=min(1,b)
z=aa.count(0)
if b==1 and a<=0:
  print('Zero')
elif b==0:
  print('Zero')
elif (b-a)%2==0 and b<0:
  print("Negative")
else:
  print("Positive")

Fixed submission:
a,b=map(int,input().split())
a=min(1,a)
b=min(1,b)
if b==1 and a<=0:
  print('Zero')
elif b==0:
  print('Zero')
elif (b-a)%2==0 and b<0:
  print("Negative")
else:
  print("Positive")

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
aa=[a,b]
if a<b:
  aa+=list(range(a+1,b))
z=aa.count(0)
n=sum([1 for i in aa if i<0])%2
if z>0:
  print('Zero')
elif n==0:
  print("Positive")
else:
  print("Negative")

Fixed submission:
a,b=map(int,input().split())
a=min(1,a)
b=min(1,b)
if b==1 and a<=0:
  print('Zero')
elif b==0:
  print('Zero')
elif (b-a)%2==0 and b<0:
  print("Negative")
else:
  print("Positive")

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
aa=[a,b]
for i in range(a,b):
  if not i in aa:
    aa.append(i)
z=aa.count(0)
n=sum([1 for i in aa if i<0])%2
if z>0:
  print('Zero')
elif n==0:
  print("Positive")
else:
  print("Negative")

Fixed submission:
a,b=map(int,input().split())
a=min(1,a)
b=min(1,b)
if b==1 and a<=0:
  print('Zero')
elif b==0:
  print('Zero')
elif (b-a)%2==0 and b<0:
  print("Negative")
else:
  print("Positive")

Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
aa=list(range(a[0],a[1]+1))
z=aa.count(0)
n=sum([1 for i in aa if i<0])%2
if z>0:
  print('Zero')
elif n==0:
  print("Positive")
else:
  print("Negative")

Fixed submission:
a,b=map(int,input().split())
a=min(1,a)
b=min(1,b)
if b==1 and a<=0:
  print('Zero')
elif b==0:
  print('Zero')
elif (b-a)%2==0 and b<0:
  print("Negative")
else:
  print("Positive")
Buggy python submission (verdict: Runtime Error):
X=map(int,input().split())
X.sort()
if X==[5,5,7]:
  print('YES')
else:
  print('NO')

Fixed submission:
X=list(map(int,input().split()))
X.sort()
if X==[5,5,7]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    MOD = 998244353
    cand = set()
    for _ in range(K):
        L, R = map(int, input().split())
        A = set(range(L,R+1))
        cand |= A

    dp = [0] * (N + 5)
    dp[0] = 1
    for i in range(N):
        for j in cand:
            if i + j <= N:
                dp[i+j] += dp[i]
                dp[i+j] %= MOD

    print(dp[N-1])
    




if __name__ == "__main__":
    main()

Fixed submission:

def main():
    N, K = map(int, input().split())
    MOD = 998244353
    L = [0] * K
    R = [0] * K
    for i in range(K):
        L[i], R[i] = map(int, input().split())

    
    dp = [0] * (N + 1)
    dpsum = [0] * (N + 1)
    dp[1] = 1
    dpsum[1] = 1
    for i in range(2,N+1):
        for j in range(K):
            l = i - R[j]
            r = i - L[j]
            if r <= 0:
                continue
            l = max(1,l)
            dp[i] += dpsum[r] - dpsum[l-1]
            dp[i] %= MOD
        dpsum[i] = dpsum[i-1] + dp[i]
        dpsum[i] %= MOD

    print(dp[N])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            ans += A[i] * A[j]
            ans %= MOD

    print(ans % MOD)




if __name__ == "__main__":
    main()

Fixed submission:
from itertools import accumulate

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] + list(accumulate(A))
    MOD = 10 ** 9 + 7
    ans = 0
    for i in range(N):
        ans += A[i] * (B[N] - B[i+1])
        ans %= MOD

    print(ans)




if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
import sys
sys.setrecursionlimit(1000000)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = gcd(A[0],A[1])
    set_A = set(A)
    for i in range(2,N):
        tmp = gcd(tmp, A[i])

    if tmp != 1:
        print('not coprime')
        exit()
    max_A = max(A)
    ans = [0] * (max_A + 1)
    ans = [set() for _ in range(max_A + 1)]
    flag = True
    for i in range(2,int(max_A ** 0.5) +1):
        tmp = 1
        b = 0
        c = set()
        while b <= max_A:
            b = i * tmp
            if {b} & set_A:
                c.add(b)
            if len(c) >= 2:
                flag = False
                break
            if b > max_A:
                break
            ans[b].add(i)
            tmp += 1
    if flag:
        print('pairwise coprime')
    else:
        print('setwise coprime')
    






if __name__ == "__main__":
    main()

Fixed submission:
from math import gcd
import sys
sys.setrecursionlimit(1000000)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = gcd(A[0],A[1])
    set_A = set(A)
    for i in range(2,N):
        tmp = gcd(tmp, A[i])

    if tmp != 1:
        print('not coprime')
        exit()
    max_A = max(A)
    ans = [False] * (max_A + 1)
    flag = True
    def divisor(n):
        ass = []
        for i in range(1,int(n**0.5)+1):
            if n%i == 0:
                ass.append(i)
                if ans[i]:
                    return False
                if i != 1:
                    ans[i] = True
                if i**2 == n:
                    continue
                if ans[n//i]:
                    return False
                ans[n//i] = True
                ass.append(n//i)
        if n != 1:
            ans[n] = True
        return True #sortされていない
    for a in A:
        if not divisor(a):
            flag = False
            break

    if flag:
        print('pairwise coprime')
    else:
        print('setwise coprime')
    






if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys

input = sys.stdin.readline

def main():
    H, W, M = map(int, input().split())
    d = defaultdict(int)
    e = defaultdict(int)
    X = []
    for _ in range(M):
        h, w = map(int, input().split())
        d[h] += 1
        e[w] += 1
        X.append((h,w))
    
    a = max(d.values())
    b = max(e.values())
    cand_d = []
    cand_e = []
    for i, j in d.items():
        if j == a:
            cand_d.append(i)

    for i, j in e.items():
        if j == b:
            cand_e.append(i)

    for i in cand_d:
        for j in cand_e:
            if not (i,j) in X:
                ans = a + b
                print(ans)
                exit()

    print(a + b - 1)


if __name__ == "__main__":
    main()

Fixed submission:
from collections import defaultdict
import sys

input = sys.stdin.readline

def main():
    H, W, M = map(int, input().split())
    d = defaultdict(int)
    e = defaultdict(int)
    x = defaultdict(set)
    y = defaultdict(set)
    X = []
    for _ in range(M):
        h, w = map(int, input().split())
        d[h] += 1
        e[w] += 1
        x[h].add(w)
        y[w].add(h)
        
    a = max(d.values())
    b = max(e.values())
    cand_d = set()
    cand_e = set()
    for i, j in d.items():
        if j == a:
            cand_d.add(i)

    for i, j in e.items():
        if j == b:
            cand_e.add(i)

    for i in cand_d:
        if (cand_e - x[i]) != set():
            ans = a + b
            print(ans)
            exit()

    for i in cand_e:
        if (cand_d - y[i]) != set():
            ans = a + b
            print(ans)
            exit()

    print(a + b - 1)


if __name__ == "__main__":
    main()