Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
K,N=map(int,input().split())
if 500*K>=X:
    print('Yes')
else:
    print('No')

Fixed submission:
K,N=map(int,input().split())
if 500*K>=N:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import itertools

N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))


Ns=list(itertools.permutations(range(1,N+1)))
PO=Ns.index(P)
QO=Ns.index(Q)
print(abs(PO-QO))


Fixed submission:
import itertools

N=int(input())
p=list(map(str,input().split()))
q=list(map(str,input().split()))
P=''.join(p)
Q=''.join(q)

ns=list(itertools.permutations(range(1,N+1)))
Ns=[]
for i in range(len(ns)):
    temparr=[]
    for j in range(N):
        a=ns[i][j]
        temparr.append(str(a))
    b=''.join(temparr)
    Ns.append(b)

PO=Ns.index(P)
QO=Ns.index(Q)
print(abs(PO-QO))

Buggy python submission (verdict: Runtime Error):
import itertools

N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))


Ns=list(itertools.permutations(range(1,N+1)))
PO=Ns.index(P)
QO=Ns.index(Q)
print(abs(Po-QO))


Fixed submission:
import itertools

N=int(input())
p=list(map(str,input().split()))
q=list(map(str,input().split()))
P=''.join(p)
Q=''.join(q)

ns=list(itertools.permutations(range(1,N+1)))
Ns=[]
for i in range(len(ns)):
    temparr=[]
    for j in range(N):
        a=ns[i][j]
        temparr.append(str(a))
    b=''.join(temparr)
    Ns.append(b)

PO=Ns.index(P)
QO=Ns.index(Q)
print(abs(PO-QO))
Buggy python submission (verdict: Runtime Error):
import math
A,B=map(int,input().split())
print(math.gcd(A,B))

Fixed submission:
import fractions
A,B=map(int,input().split())
print(A*B//fractions.gcd(A,B))
Buggy python submission (verdict: Runtime Error):
# N=1079
N=int(input())

a=str(N*100/108)
b=str((N+1)*100/108)

if a+1 <=b:
    print(round(a+0.5))
else:
    print(":(")


Fixed submission:
# N=1079
N=int(input())

a=int(N*100/110)-1

flg=False

for i in range (N-a+1):
    if ((a+i)*1.08)//1==N:
        print(a+i)
        exit()
    else:
        pass
print(':(')

Buggy python submission (verdict: Runtime Error):
# N=1079
N=int(input())

a=str(N*100/108)
b=str((N+1)*100/108)

print(a,b)

if a+1 <=b:
    print(round(a+0.5))
else:
    print(":(")


Fixed submission:
# N=1079
N=int(input())

a=int(N*100/110)-1

flg=False

for i in range (N-a+1):
    if ((a+i)*1.08)//1==N:
        print(a+i)
        exit()
    else:
        pass
print(':(')
Buggy python submission (verdict: Runtime Error):
S=input()
D=[SUN,MON,TUE,WED,THU,FRI,SAT]
Today=D.index(S)
print(7-Today)

Fixed submission:
S=input()
D=['SUN','MON','TUE','WED','THU','FRI','SAT']
Today=D.index(S)
print(7-Today)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()

a=['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','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']
anslist=[]

for i in range(len(S)):
    b=a.index(S[i])
    ans.append(a[b+N])

ans="".join(anslist)


Fixed submission:
N=int(input())
S=input()

a=['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','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']
anslist=[]

for i in range(len(S)):
    b=a.index(S[i])
    anslist.append(a[b+N])

ans="".join(anslist)
print(ans)
Buggy python submission (verdict: Runtime Error):

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


N=int(input())

a=1
b=N//a
dis=abs(b-a)

for i in range(1,int(N**0.5)+1):
    if N%i==0:
        _a=i
        _b=N//i
        _dis=abs(_b-_a)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis

print(a-1+b-1)

Fixed submission:
A,B=map(int,input().split())
if A>9 or B>9:
  print(-1)
  exit()
print(A*B)
Buggy python submission (verdict: Runtime Error):
from itertools import combinations

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

c=combinations(d,2)
print(d)

Fixed submission:
from itertools import combinations

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

c=list(combinations(d,2))

ans=0

for i in range(len(c)):
    a=c[i][0]*c[i][1]
    ans+=a

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# D - Triangles
from itertools import combinations

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

ans=0

l=list(combinations(Li,3))
for i in range(len(l)):
    a,b,c=l[i]
    if a<b+c and b<c+a and c<a+b:
        ans+=1

print(ans)


Fixed submission:
# D - Triangles
import bisect

N=int(input())
Li=list(map(int,input().split()))
Li.sort()

ans=0

for i in range(N):
    for j in range (i+1,N):
        a=Li[i]+Li[j]
        t=bisect.bisect_left(Li,a)
        ans+=t-(j+1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Triangles
from itertools import combinations

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

ans=0

l=list(combinations(Li,3))
for i in range(len(l)):
    a,b,c=l[i]
    if a<b+c and b<c+a and c<a+b:
        ans+=1

print(ans)


Fixed submission:
# D - Triangles
import bisect

N=int(input())
Li=list(map(int,input().split()))
Li.sort()

ans=0

for i in range(N):
    for j in range (i+1,N):
        a=Li[i]+Li[j]
        t=bisect.bisect_left(Li,a)
        ans+=t-(j+1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Triangles
import itertools


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

ans=0

l=list(itertools.combinations(Li,3))
for i in range(len(l)):
    a,b,c=l[i]
    if a<b+c and b<c+a and c<a+b:
        ans+=1
    else:
        pass

print(ans)


Fixed submission:
# D - Triangles
import bisect

N=int(input())
Li=list(map(int,input().split()))
Li.sort()

ans=0

for i in range(N):
    for j in range (i+1,N):
        a=Li[i]+Li[j]
        t=bisect.bisect_left(Li,a)
        ans+=t-(j+1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Triangles
import itertools


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

ans=0

l=list(itertools.combinations(Li,3))
for i in range(len(l)):
    a=l[i][0]
    b=l[i][1]
    c=l[i][2]
    if a<b+c and b<c+a and c<a+b:
        ans+=1
    else:
        pass

print(ans)


Fixed submission:
# D - Triangles
import bisect

N=int(input())
Li=list(map(int,input().split()))
Li.sort()

ans=0

for i in range(N):
    for j in range (i+1,N):
        a=Li[i]+Li[j]
        t=bisect.bisect_left(Li,a)
        ans+=t-(j+1)

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N,K=map(int,input().split())
h=list(map(int,input().split()))
# N,K=4,150
# h=[150, 140, 100, 200]

harry=np.array(h)
ans=np.where(harry>=K)

print(ans[0][1])


# import sys
# print(sys.version_info)

Fixed submission:
import numpy as np

N,K=map(int,input().split())
h=list(map(int,input().split()))
# N,K=4,150
# h=[150, 140, 100, 200]

harry=np.array(h)
ans=np.count_nonzero(harry>=K)

print(ans)


# import sys
# print(sys.version_info)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N,K=map(int,input().split())
h=list(map(int,input().split()))
# N,K=4,150
# h=[150, 140, 100, 200]

harry=np.array(h)
ans=np.where(harry>=K)


print(harry)
print(ans[0][1])
print(type(ans))


Fixed submission:
import numpy as np

N,K=map(int,input().split())
h=list(map(int,input().split()))
# N,K=4,150
# h=[150, 140, 100, 200]

harry=np.array(h)
ans=np.count_nonzero(harry>=K)

print(ans)


# import sys
# print(sys.version_info)
Buggy python submission (verdict: Runtime Error):
N=int(input())
Ai=list(map(int,input().split()))

# ans=[]
ans=[]*N

# for i in range(1,N+1):
    # a=Ai.index(i)+1
    # ans.append(str(a))
for i in range (N):
    ans[Ai[i]-1]=str(i+1)

print(' '.join(ans))


Fixed submission:
N=int(input())
Ai=list(map(int,input().split()))

# ans=[]
ans=[0]*N

# for i in range(1,N+1):
    # a=Ai.index(i)+1
    # ans.append(str(a))
for i in range (N):
    ans[Ai[i]-1]=str(i+1)

print(' '.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Ai=list(map(int,input().split()))

dic={}

for i in range(1,N+1):
    a=Ai.index(i)+1
    dic[i]=a

ans=''
for i in range(1,N+1):
    ans+=str(dic[i])+' '
print(ans)

Fixed submission:
N=int(input())
Ai=list(map(int,input().split()))

# ans=[]
ans=[0]*N

# for i in range(1,N+1):
    # a=Ai.index(i)+1
    # ans.append(str(a))
for i in range (N):
    ans[Ai[i]-1]=str(i+1)

print(' '.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Ai=list(map(int,input().split()))

ans=''

for i in range(1,N+1):
    a=Ai.index(i)+1
    ans+=(str(a)+' ')

print(ans)

Fixed submission:
N=int(input())
Ai=list(map(int,input().split()))

# ans=[]
ans=[0]*N

# for i in range(1,N+1):
    # a=Ai.index(i)+1
    # ans.append(str(a))
for i in range (N):
    ans[Ai[i]-1]=str(i+1)

print(' '.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Ai=list(map(int,input().split()))

ans=''

for i in range(1,N+1):
    a=Ai.index(i)+1
    ans+=(str(a)+' ')

print(ans)

Fixed submission:
N=int(input())
Ai=list(map(int,input().split()))

# ans=[]
ans=[0]*N

# for i in range(1,N+1):
    # a=Ai.index(i)+1
    # ans.append(str(a))
for i in range (N):
    ans[Ai[i]-1]=str(i+1)

print(' '.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Ai=list(map(int,input().split()))

ans=[]

for i in range(1,N+1):
    a=Ai.index(i)+1
    ans.append(str(a))

print(' '.join(ans))

Fixed submission:
N=int(input())
Ai=list(map(int,input().split()))

# ans=[]
ans=[0]*N

# for i in range(1,N+1):
    # a=Ai.index(i)+1
    # ans.append(str(a))
for i in range (N):
    ans[Ai[i]-1]=str(i+1)

print(' '.join(ans))
Buggy python submission (verdict: Runtime Error):
s=input()
w=(Sunny,Cloudy,Rainy,Sunny)
n=w.index(s)
print(w[n+1])

Fixed submission:
s=input()
w=('Sunny','Cloudy','Rainy','Sunny')
n=w.index(s)
print(w[n+1])
Buggy python submission (verdict: Runtime Error):
S=input()
T=input()

ans=0

for in in range(3):
    if S[i]==T[i]:
        ans+=1

print(ans)

Fixed submission:
S=input()
T=input()

ans=0

for i in range(3):
    if S[i]==T[i]:
        ans+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
Hi=list(map(int,input().split()))

ans=[0]*N

for i in range (N):
    a=0
    # if Hi[i]<Hi[i-1]:
    #     continue
    for j in range(N-i-1):
        if Hi[i+j]>=Hi[i+j+1]:
            a+=1
        else:
            break
    ans[i]=a
    i=i+j

print(max(ans))

Fixed submission:
N=int(input())
Hi=list(map(int,input().split()))

# ans=[0]*N

# for i in range (N):
#     a=0
#     # if Hi[i]<Hi[i-1]:
#     #     continue
#     for j in range(N-i-1):
#         if Hi[i+j]>=Hi[i+j+1]:
#             a+=1
#         else:
#             break
#     ans[i]=a

# print(max(ans))

ans=0
temp=0

for i in range(1,N):
    if Hi[i]<=Hi[i-1]:
        temp+=1
    else:
        if temp>ans:
            ans=temp
        else:
            pass
        temp=0
else:
    if temp>ans:
        ans=temp

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Hi=list(map(int,input().split()))

ans=[0]*N

for i in range (N):
    a=0
    if Hi[i]<Hi[i-1]:
        continue

    for j in range(N-i-1):
        if Hi[i+j]>=Hi[i+j+1]:
            a+=1
        else:
            break
    ans[i]=a

print(max(ans))

Fixed submission:
N=int(input())
Hi=list(map(int,input().split()))

# ans=[0]*N

# for i in range (N):
#     a=0
#     # if Hi[i]<Hi[i-1]:
#     #     continue
#     for j in range(N-i-1):
#         if Hi[i+j]>=Hi[i+j+1]:
#             a+=1
#         else:
#             break
#     ans[i]=a

# print(max(ans))

ans=0
temp=0

for i in range(1,N):
    if Hi[i]<=Hi[i-1]:
        temp+=1
    else:
        if temp>ans:
            ans=temp
        else:
            pass
        temp=0
else:
    if temp>ans:
        ans=temp

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Hi=list(map(int,input().split()))

ans=[0]*N

for i in range (N):
    a=0
    for j in range(N-i-1):
        if Hi[i+j]>=Hi[i+j+1]:
            a+=1
        else:
            break
    ans[i]=a

print(max(ans))

Fixed submission:
N=int(input())
Hi=list(map(int,input().split()))

# ans=[0]*N

# for i in range (N):
#     a=0
#     # if Hi[i]<Hi[i-1]:
#     #     continue
#     for j in range(N-i-1):
#         if Hi[i+j]>=Hi[i+j+1]:
#             a+=1
#         else:
#             break
#     ans[i]=a

# print(max(ans))

ans=0
temp=0

for i in range(1,N):
    if Hi[i]<=Hi[i-1]:
        temp+=1
    else:
        if temp>ans:
            ans=temp
        else:
            pass
        temp=0
else:
    if temp>ans:
        ans=temp

print(ans)
Buggy python submission (verdict: Runtime Error):
print(((N-1)*N)/2)


Fixed submission:
N=int(input())
print(((N-1)*N)//2)

Buggy python submission (verdict: Runtime Error):
N=int(input())
n=list(range(N-1))
print(sum(n))

Fixed submission:
N=int(input())
print(((N-1)*N)//2)
Buggy python submission (verdict: Runtime Error):
a,b=int(input().split())
print(max(a+b,a-b,a*b))

Fixed submission:
a,b=map(int,input().split())
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Beginner Contest 131
# C - Anti-Division

A,B,C,D=map(int,input().split())
if C==1 or D==1:
    print(0)
    exit()

S=set()
sC=A//C -1
eC=B//C +1

sD=A//D -1
eD=B//D +1

for i in range (sC,eC):
    tC=C*i
    if A<=tC and tC<=B:
        S.add(tC)
    if tC>B:
        break


for i in range (sD,eD):
    tD=D*i
    if A<=tD and tD<=B:
        S.add(tD)
    if tD>B:
        break

print(B-A-len(S)+1)


Fixed submission:
# AtCoder Beginner Contest 131
# C - Anti-Division
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D=map(int,input().split())
bc=B//C
ac=(A-1)//C
cnum=bc-ac

bd=B//D
ad=(A-1)//D
dnum=bd-ad


lcmcd=lcm(C,D)
blcmcd=B//lcmcd
alcmcd=(A-1)//lcmcd
lcmcdnum=blcmcd-alcmcd


print(B-A-cnum-dnum+lcmcdnum+1)
Buggy python submission (verdict: Runtime Error):
N,A,B,C,D=map(int,input().split())
S=input()

c1=S[B-2:C].count('...')
c2=S[A-1:D].count('##')

if c2>=1:
    print('No')
    exit()
else:
    pass

if C>D:
    if c1==0:
    print('No')
    exit()
    else:
        print('Yes')
        exit()

Fixed submission:
N,A,B,C,D=map(int,input().split())
S=input()

c1=S[B-2:D+1].count('...')
c2=S[A-1:D].count('##')

if c2>=1:
    print('No')
    exit()
else:
    pass

if C>D and c1==0:
    print('No')
    exit()
else:
    pass


print('Yes')
Buggy python submission (verdict: Runtime Error):
N=input()
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)<sum(b):
    print(-1)
    exit()

count=0

d=[]
for i in range (N):
    _d=a[i]-b[i]
    d.append(_d,i)
print(d)


Fixed submission:
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)<sum(b):
    print(-1)
    exit()

p=0

ori_d=[]
for i in range (N):
    _d=a[i]-b[i]
    ori_d.append([i,_d])

d=sorted(ori_d,key=lambda x: x[1])
d2=[0]*N
for j in range (N):
    if d[j][1]>=0:
        break
    else:
        p+=abs(d[j][1])
        d2[j]+=1

for k in range (N-1,0,-1):
    if p==0:
        break
    elif d[k][1]<p:
        p-=d[k][1]
        d[k][1]=0
        d2[k]+=1
    else:
        d[k][1]-=p
        p=0
        d2[k]+=1

print(sum(d2))
Buggy python submission (verdict: Runtime Error):
N=int(input())
Ws=[]
for n in range(N):
    W=input()
    Ws.append(W)

for w in range(len(Ws)):
    if Ws.count(w)>=2:
        print('No')
        exit()

for x in range (1,N+1):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()
print("Yes")


Fixed submission:
N=int(input())
Ws=[]
for n in range(N):
    W=input()
    Ws.append(W)

for w in range(len(Ws)):
    if Ws.count(Ws[w])>=2:
        print("No")
        exit()
        
for x in range (1,len(Ws)):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Beginner Contest 100
# C - *3 or /2

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

count=0

A=[ a for a in A if a%2==0 ]

while len(A)>0:
    _A=[]
    for a in A:
        if a==max(A):
            _a=a//2
            if _a%2==0:
                _A.append(_a)
            else:
                pass
        else:
            if a%2==0:
                _a=a*3
                _A.append(_a)
            else :
                pass
    count+=1
    A=_A
    # print(A)
    # print(_A)

print(count)


Fixed submission:
# AtCoder Beginner Contest 100
# C - *3 or /2
def f(N,c):
    if N%2==0:
        n=N//2
        c+=1
        return f(n,c)
    else:
        return c



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

count=0

for a in A:
    count+= f(a,0)

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Beginner Contest 100
# C - *3 or /2

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

count=0

A=[ a for a in A if a%2==0 ]

while len(A)>0:

    _A=[]
    for a in A:
        if a==max(A):
            _a=a//2
            _A.append(_a)
        else:
            _a=a*3
            _A.append(_a)
    count+=1
    A=[ _a for _a in _A if _a%2==0 ]
    # print(A)
    # print(_A)


print(count)


Fixed submission:
# AtCoder Beginner Contest 100
# C - *3 or /2
def f(N,c):
    if N%2==0:
        n=N//2
        c+=1
        return f(n,c)
    else:
        return c



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

count=0

for a in A:
    count+= f(a,0)

print(count)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input

ans=1

for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    setX=set(X)
    setY=set(Y)
    intersectionXY=setX & setY
    _temp=len(intersectionXY)
    if _temp>ans:
        ans=_temp
    else:
        pass
print(ans)

Fixed submission:
N=int(input())
S=input()



ans=0

for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    setX=set(X)
    setY=set(Y)
    intersectionXY=setX & setY
    _temp=len(intersectionXY)
    if _temp>ans:
        ans=_temp
    else:
        pass
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# ABC0555 - B - Training Camp

N=int(input())

ans=1

for i in range(1,N+1):
    ans*=i

if ans>=10**9+7:
    ans=ans%(10**9+7)

print(ans)


Fixed submission:
# ABC0555 - B - Training Camp

N=int(input())

ans=1

for i in range(1,N+1):
    ans*=i
    ans%=(10**9+7)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC0555 - B - Training Camp

N=int(input())

ans=1

for i in range(1,N+1):
    ans*=i

if ans>=10**9+7:
    ans=ans%(10**9+7)

print(ans)


Fixed submission:
# ABC0555 - B - Training Camp

N=int(input())

ans=1

for i in range(1,N+1):
    ans*=i
    ans%=(10**9+7)

print(ans)
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input(),())
S=input()

nowA=0
nowB=0

for s in S:
    if s=='c':
        print('No')
    elif s=='a':
        if nowA+nowB<=A+B:
            nowA+=1
            print('Yes')
        else:
            print('No')
    else:
        if nowA+nowB<=A+B and nowB<=B:
            nowB+=1
            print('Yes')
            nowB+=1
        else:
            print('No')


Fixed submission:
N,A,B=map(int,input().split())
S=input()

nowA=0
nowB=0

for s in S:
    if s=='c':
        print('No')
    elif s=='a':
        if nowA+nowB<A+B:
            print('Yes')
            nowA+=1
        else:
            print('No')
    else:
        if nowA+nowB<A+B and nowB<B:
            print('Yes')
            nowB+=1
        else:
            print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))

s = [0]*n

for i in range(n):
    s[i] = sum(A[i+1:])


tot = 0
for i in range(n-1):
    tot += A[i]*s[i]
    
print(tot%(10**9+7))

Fixed submission:
n = int(input())
A = list(map(int,input().split()))

a = A[::-1]
s = [0]*(n+1)

for i in range(n):
    s[i+1] = s[i] + a[i]

s = s[:n]
s = s[::-1]

tot = 0
for i in range(n-1):
    tot += A[i]*s[i]
    
print(tot%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))

s = [0]*n

for i in range(n):
    s[i] = sum(A[i+1:])


tot = 0
for i in range(n-1):
    tot += A[i]*s[i]
    
print(tot%(10**9+7))

Fixed submission:
n = int(input())
A = list(map(int,input().split()))

a = A[::-1]
s = [0]*(n+1)

for i in range(n):
    s[i+1] = s[i] + a[i]

s = s[:n]
s = s[::-1]

tot = 0
for i in range(n-1):
    tot += A[i]*s[i]
    
print(tot%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())

ch,cw,dh,dw = ch-1,cw-1,dh-1,dw-1
S = [[""]*w for i in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        S[i][j] = s[j]
        
visited = [[-1]*w for _ in range(h)]

visited[ch][cw] = 0

INF = 10**9
dist = [[INF]*w for _ in range(h)]
Q = deque([])
Q.append([ch,cw])
dist[ch][cw] = 0

while Q:
    y,x = Q.popleft()
    d = dist[y][x]
    
    for i, j in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
      nx = x + i
      ny = y + j
      if (nx < 0 or nx >= w or ny < 0 or ny >= h): 
          continue
      if S[ny][nx] == "#":
          continue
      if dist[ny][nx] <= d:
          continue
      dist[ny][nx] = d
      Q.appendleft([ny,nx])
      
    
    for ey in range(-2,3):
        for ex in range(-2,3):
            nx = x + ex
            ny = y + ey
            if (nx < 0 or nx >= w or ny < 0 or ny >= h): 
              continue
            if S[ny][nx] == "#":
              continue
            if dist[ny][nx] <= d+1:     
              continue
            dist[ny][nx] = d+1
            Q.append([ny,nx])
      
ans = dist[dh][dw]

if ans == INF:
    print(-1)
else:
    print(ans)

Fixed submission:
from collections import deque

h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())

ch,cw,dh,dw = ch-1,cw-1,dh-1,dw-1
S = [[""]*w for i in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        S[i][j] = s[j]
        
visited = [[-1]*w for _ in range(h)]

visited[ch][cw] = 0

INF = 10**9
dist = [[INF]*w for _ in range(h)]
Q = deque([])
Q.append([ch,cw])
dist[ch][cw] = 0

while Q:
    y,x = Q.popleft()
    d = dist[y][x]
    
    for i, j in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
      nx = x + i
      ny = y + j
      if (nx < 0 or nx >= w or ny < 0 or ny >= h): 
          continue
      if S[ny][nx] == "#":
          continue
      if dist[ny][nx] <= d:
          continue
      dist[ny][nx] = d
      Q.appendleft([ny,nx])
      
    
    for ey in range(-2,3):
        for ex in range(-2,3):
            nx = x + ex
            ny = y + ey
            if (nx < 0 or nx >= w or ny < 0 or ny >= h): 
              continue
            if S[ny][nx] == "#":
              continue
            if dist[ny][nx] <= d+1:     
              continue
            dist[ny][nx] = d+1
            Q.append([ny,nx])
      
ans = dist[dh][dw]

if ans == INF:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
x,n = map(int,input().split())

p = [int(input()) for i in range(n)]
s = 1000000000

for i in range(1,101):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

if not x-s in p:
    print(x - s)
else:
    print(x + s)

Fixed submission:
x,n = map(int,input().split())

if n != 0:
    p = list(map(int,input().split()))
else:
    print(x)
    exit()

s = 1000000000

for i in range(-100,102):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

if not x-s in p:
    print(x - s)
else:
    print(x + s)
Buggy python submission (verdict: Runtime Error):
s=input()

a=[""]*(len(s)+1)

for i in range(len(s)):
    a[i+1]=a[i]+s[i]

a.pop(0)
ans=0
for i in range(len(s)):
    for j in a:
        if j[i:]!="":
            b=int(j[i:])
            if b%2019==0:
                ans+=1
                
print(ans)   

Fixed submission:
s=input()
s=s[::-1]

t=0

x=1
cnt=[0]*2019
cnt[0]=1


for i in s:
    t += int(i)*x
    t %= 2019
    x *= 10
    x %= 2019
    cnt[t]+=1

ans=0
for i in cnt:
    ans +=i*(i-1)//2

print(ans)