Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

S = input()
T = input()
DP = [[""]*(len(T)+1) for i in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            DP[i+1][j+1] = DP[i][j] + S[i]
        else:
            if len(DP[i+1][j]) > len(DP[i][j+1]):
                DP[i+1][j+1] = DP[i+1][j]
            else:
                DP[i+1][j+1] = DP[i][j+1]
print(DP[-1][-1])


Fixed submission:
import sys
input=sys.stdin.readline

S = input().rstrip()
T = input().rstrip()
DP = [[0]*(len(T)+1) for i in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            DP[i+1][j+1] = DP[i][j]+1
        else:
            DP[i+1][j+1] = max(DP[i+1][j],DP[i][j+1])

m,n = len(S),len(T)
ans = ''
while m>0 and n>0:
    if DP[m][n] == DP[m][n-1]:
        n-=1
    elif DP[m][n] == DP[m-1][n]:
        m -= 1
    else:
        m,n = m-1,n-1
        ans = T[n]+ans
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()
DP = [[""]*(len(T)+1) for i in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            DP[i+1][j+1] = DP[i][j] + S[i]
        else:
            if len(DP[i+1][j]) > len(DP[i][j+1]):
                DP[i+1][j+1] = DP[i+1][j]
            else:
                DP[i+1][j+1] = DP[i][j+1]
print(DP[-1][-1])


Fixed submission:
import sys
input=sys.stdin.readline

S = input().rstrip()
T = input().rstrip()
DP = [[0]*(len(T)+1) for i in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            DP[i+1][j+1] = DP[i][j]+1
        else:
            DP[i+1][j+1] = max(DP[i+1][j],DP[i][j+1])

m,n = len(S),len(T)
ans = ''
while m>0 and n>0:
    if DP[m][n] == DP[m][n-1]:
        n-=1
    elif DP[m][n] == DP[m-1][n]:
        m -= 1
    else:
        m,n = m-1,n-1
        ans = T[n]+ans
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
PY = [[int(i) for i in input().split()]for i in range(M)]
l = [[] for i in range(N+1)]
for p,y in PY:
    l[p].append(y)
for i in range(N+1):
    l[i].sort()
for p,y in PY:
    print(str(p).zfill(6),end="")
    print(str(l[p].index(y)+1).zfill(6))

Fixed submission:
import heapq
N,M = map(int,input().split())
ans = [[0,0]for i in range(M)]
cityes = [[]for i in range(N)]
for i in range(M):
    p,y = map(int,input().split())
    heapq.heappush(cityes[p-1],[y,i])
for i in range(N):
    j = 0
    while cityes[i] != []:
        j += 1
        y,n = heapq.heappop(cityes[i])
        ans[n] = [i+1,j]
for a,b in ans:
    out = str(1000000+a)[1:] + str(1000000+b)[1:]
    print(out)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
PY = [[int(i) for i in input().split()]for i in range(M)]
l = [[] for i in range(N+1)]
for p,y in PY:
    l[p].append(y)
for i in range(N+1):
    l[i].sort()
for p,y in PY:
    print(str(p).zfill(6),end="")
    print(str(l[p].index(y)+1).zfill(6))

Fixed submission:
import heapq
N,M = map(int,input().split())
ans = [[0,0]for i in range(M)]
cityes = [[]for i in range(N)]
for i in range(M):
    p,y = map(int,input().split())
    heapq.heappush(cityes[p-1],[y,i])
for i in range(N):
    j = 0
    while cityes[i] != []:
        j += 1
        y,n = heapq.heappop(cityes[i])
        ans[n] = [i+1,j]
for a,b in ans:
    out = str(1000000+a)[1:] + str(1000000+b)[1:]
    print(out)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
PY = [[int(i) for i in input().split()]for i in range(M)]
l = [[] for i in range(N+1)]
for p,y in PY:
    l[p].append(y)
for i in range(N+1):
    l[i].sort()
for p,y in PY:
    print(str(p).zfill(6),end="")
    print(str(l[p].index(y)+1).zfill(6))

Fixed submission:
import heapq
N,M = map(int,input().split())
ans = [[0,0]for i in range(M)]
cityes = [[]for i in range(N)]
for i in range(M):
    p,y = map(int,input().split())
    heapq.heappush(cityes[p-1],[y,i])
for i in range(N):
    j = 0
    while cityes[i] != []:
        j += 1
        y,n = heapq.heappop(cityes[i])
        ans[n] = [i+1,j]
for a,b in ans:
    out = str(1000000+a)[1:] + str(1000000+b)[1:]
    print(out)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = []
for i in range(1,int(M**0.5)):
    if M%i == 0:
        if i <= N:
            a.append(i)
        else:
            a.append(int(M/i))
print(max(a))

Fixed submission:
N,M = map(int,input().split())
a = []
for i in range(1,int(M**0.5)+1):
    if M%i == 0:
        a.append(i)
        a.append(int(M/i))
a.sort(reverse = True)
for i in a:
    if i <= M/N:
        print(i)
        break

Buggy python submission (verdict: Time Limit Exceeded):
import math
N,M = map(int,input().split())
for i in range(math.floor(M/N),-1,-1):
    if M%i == 0:
        print(i)
        break

Fixed submission:
N,M = map(int,input().split())
a = []
for i in range(1,int(M**0.5)+1):
    if M%i == 0:
        a.append(i)
        a.append(int(M/i))
a.sort(reverse = True)
for i in a:
    if i <= M/N:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
N,M,Q = map(int,input().split())

station = [[0]*N for i in range(N)]

for i in range(M):
    L,R = map(int,input().split())
    station[L-1][R-1] += 1

DP = [[0]*(N) for i in range(N)]

for i in range(N):
    for j in range(N):
        for a in range(i,j+1):
            for b in range(i,j+1):
                DP[i][j] += station[a][b]

for i in range(Q):
    p,q = map(int,input().split())
    print(DP[p-1][q-1])

Fixed submission:
N,M,Q = map(int,input().split())

station = [[0]*(N+1) for i in range(N+1)]

for i in range(M):
    l,r = map(int,input().split())
    station[l][r] += 1

DP = [[0]*(N+1) for i in range(N+1)]

for i in range(N+1):
    for j in range(N):
        DP[i][j+1] = DP[i][j] + station[i][j+1]

for i in range(Q):
    p,q = map(int,input().split())
    ans = 0
    for i in range(p,q+1):
        ans += DP[i][q] - DP[i][p-1]
    print(ans)

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

station = [[0]*N for i in range(N)]

for i in range(M):
    L,R = map(int,input().split())
    station[L-1][R-1] += 1

DP = [[0]*(N) for i in range(N)]

for i in range(N):
    for j in range(N):
        for a in range(i,j+1):
            for b in range(i,j+1):
                DP[i][j] += station[a][b]

for i in range(Q):
    p,q = map(int,input().split())
    print(DP[p-1][q-1])

Fixed submission:
N,M,Q = map(int,input().split())

station = [[0]*(N+1) for i in range(N+1)]

for i in range(M):
    l,r = map(int,input().split())
    station[l][r] += 1

DP = [[0]*(N+1) for i in range(N+1)]

for i in range(N+1):
    for j in range(N):
        DP[i][j+1] = DP[i][j] + station[i][j+1]

for i in range(Q):
    p,q = map(int,input().split())
    ans = 0
    for i in range(p,q+1):
        ans += DP[i][q] - DP[i][p-1]
    print(ans)
Buggy python submission (verdict: Runtime Error):

S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpC = "abcdefghijklmnopqrstuvwxyzC"

ans = "AC"
if S[0] != "A":
    ans = "WA"
countC = 0
for i in S[2:-1]:
    if i == "C":
        countC += 1
    if not i in alpC:
        ans = "WA"
if countC != 1:
    ans = "WA"
if not S[1] in alp:
    ans = "WA"
if not S[-1] in alp:
    ans = "WA"
pirnt(ans)

Fixed submission:
S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpC = "abcdefghijklmnopqrstuvwxyzC"

ans = "AC"
if S[0] != "A":
    ans = "WA"
countC = 0
for i in S[2:-1]:
    if i == "C":
        countC += 1
    if not i in alpC:
        ans = "WA"
if countC != 1:
    ans = "WA"
if not S[1] in alp:
    ans = "WA"
if not S[-1] in alp:
    ans = "WA"
print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
alp = "abcdefghijklmnopqrstuvwxyzC"
ans = "AC"
if S[0] != "A":
    ans = "WA"
flag = 0
for C in S[2:-1]:
    if C == "C":
        flag+=1
    if not c in alp:
        ans = "WA"
if flag != 1:
    ans = "WA"
if not S[1] in alp[:-1]:
    ans = "WA"
if not S[-1] in alp[:-1]:
    ans = "WA"

print(ans)


Fixed submission:
S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpC = "abcdefghijklmnopqrstuvwxyzC"

ans = "AC"
if S[0] != "A":
    ans = "WA"
countC = 0
for i in S[2:-1]:
    if i == "C":
        countC += 1
    if not i in alpC:
        ans = "WA"
if countC != 1:
    ans = "WA"
if not S[1] in alp:
    ans = "WA"
if not S[-1] in alp:
    ans = "WA"
print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
alp = "abcdefghijklmnopqrstuvwxyzAC"
ans = "AC"
if S[0] != "A":
    ans = "WA"
flag = 0
for C in S[2:-1]:
    if C == "C":
        flag = 1
if flag == 0:
    ans = "WA"
for c in S:
    if alp.index(c) == -1:
        ans = "WA"
print(ans)


Fixed submission:
S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpC = "abcdefghijklmnopqrstuvwxyzC"

ans = "AC"
if S[0] != "A":
    ans = "WA"
countC = 0
for i in S[2:-1]:
    if i == "C":
        countC += 1
    if not i in alpC:
        ans = "WA"
if countC != 1:
    ans = "WA"
if not S[1] in alp:
    ans = "WA"
if not S[-1] in alp:
    ans = "WA"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input() for i in range(N))
ans = 0
for A in range(N):
    flag = 1
    for i in range(N):
        for j in range(N):
            if S[i][(j+A)%N] != S[j][(i+A)%N]:
                flag = 0
    ans += flag*N
print(ans)

Fixed submission:
N = int(input())
S = list(input() for i in range(N))
ans = 0
for A in range(N):
    flag = 1
    for i in range(N):
        for j in range(N):
            if S[i][(j+A)%N] != S[j][(i+A)%N]:
                flag = 0
    ans += flag*N
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,X = int(input().split())
if A < X and X < A+B:
    print("YES")
else:
    print("NO")

Fixed submission:
A,B,X = map(int,input().split())
if A <= X and X <= A+B:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
A,B,X = int(input())
if A < X and X < A+B:
    print("YES")
else:
    print("NO")

Fixed submission:
A,B,X = map(int,input().split())
if A <= X and X <= A+B:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int,input().split())
DP = [[0]*C for i in range(10**5+1)]
for i in range(N):
    s,t,c = map(int,input().split())
    DP[s][c-1] = t-s+1
ans = 0
for i in range(10**5):
    hoge = 0
    for j in range(C):
        DP[i+1][j] = max(DP[i][j]-1,DP[i+1][j])
        if DP[i][j]: hoge += 1
    ans = max(ans,hoge)

print(ans)


Fixed submission:
N,C = map(int,input().split())
DP = [[0]*C for i in range(10**5+1)]
for i in range(N):
    s,t,c = map(int,input().split())
    DP[s][c-1] = t-s+1
ans = 0
for i in range(10**5):
    hoge = 0
    for j in range(C):
        DP[i+1][j] = max(DP[i][j]-1,DP[i+1][j])
        if DP[i][j]: hoge += 1
    ans = max(ans,hoge)

print(ans)
Buggy python submission (verdict: Runtime Error):
X = list(map(int,input().split))
X.sort()
print(sum(X)-X[1]*2)

Fixed submission:
X = list(map(int,input().split()))
X.sort()
print(sum(X)-X[1]*2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = list(int(input().split())for i in range(N))
ans = sum(s)
if ans%10 == 0:
    for i in s:
        if i%10!=0:
            ans -= i
            break
print(ans)

Fixed submission:
N = int(input())
s = list(int(input()) for i in range(N))
ans = 0
sum_s = sum(s)
if sum_s%10 != 0:
    ans = sum_s
for i in s:
    if (sum_s - i)%10 != 0:
        ans = max(ans,sum_s - i)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
wv = list(list(map(int,input().split()))for i in range(N))
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(N):
    w,v = wv[i]
    for j in range(1,W+1):
        if w > j:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w]+v)
print(dp[-1][-1])

Fixed submission:
N,W = map(int,input().split())
w1,v = map(int,input().split())
wv = [[v],[],[],[]]
for i in range(N-1):
    w,v = map(int,input().split())
    wv[w-w1].append(v)
for i in range(4):
    wv[i]=[0] + sorted(wv[i],reverse=True)
# 累積和
for i in range(4):
    for j in range(1,len(wv[i])):
        wv[i][j] += wv[i][j-1]
ans = 0
hoge = [0,0,0,0]
for i in range(len(wv[0])):
    hoge[0] = wv[0][i]
    for j in range(len(wv[1])):
        hoge[1] = wv[1][j]
        for k in range(len(wv[2])):
            hoge[2] = wv[2][k]
            for l in range(len(wv[3])):
                hoge[3] = wv[3][l]
                if w1*(i+j+k+l)+j+2*k+3*l > W:
                    break
                else:
                    ans = max(ans,sum(hoge))
print(ans)

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
wv = list(list(map(int,input().split()))for i in range(N))
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(N):
    w,v = wv[i]
    for j in range(1,W+1):
        if w > j:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w]+v)
print(dp[-1][-1])

Fixed submission:
N,W = map(int,input().split())
w1,v = map(int,input().split())
wv = [[v],[],[],[]]
for i in range(N-1):
    w,v = map(int,input().split())
    wv[w-w1].append(v)
for i in range(4):
    wv[i]=[0] + sorted(wv[i],reverse=True)
# 累積和
for i in range(4):
    for j in range(1,len(wv[i])):
        wv[i][j] += wv[i][j-1]
ans = 0
hoge = [0,0,0,0]
for i in range(len(wv[0])):
    hoge[0] = wv[0][i]
    for j in range(len(wv[1])):
        hoge[1] = wv[1][j]
        for k in range(len(wv[2])):
            hoge[2] = wv[2][k]
            for l in range(len(wv[3])):
                hoge[3] = wv[3][l]
                if w1*(i+j+k+l)+j+2*k+3*l > W:
                    break
                else:
                    ans = max(ans,sum(hoge))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Ma,Mb=map(int,input().split())
abc = list(list(map(int,input().split()))for i in range(N))
DP = [[[10**9]*(10*N+1) for i in range(10*N+1)]for i in range(N+1)]
DP[0][0][0] = 0
for i in range(N):
    for j in range(10*N+1):
        for k in range(10*N+1):
            if j >= abc[i][0] and k >= abc[i][1]:
                DP[i+1][j][k] = min(DP[i][j][k],DP[i][j-abc[i][0]][k-abc[i][1]]+abc[i][2])
            else:
                DP[i+1][j][k] = DP[i][j][k]
ans = 10**9
for i in range(1,10*N//max(Ma,Mb)+1):
    ans = min(DP[-1][i*Ma][i*Mb],ans)
if ans >= 10**8:
    print(-1)
else:
    print(ans)

Fixed submission:
N,Ma,Mb=map(int,input().split())
abc = list(list(map(int,input().split()))for i in range(N))
DP = [[[10**9]*(10*N+1) for i in range(10*N+1)]for i in range(N+1)]
DP[0][0][0] = 0
for i in range(N):
    for j in range(10*N+1):
        for k in range(10*N+1):
            if j >= abc[i][0] and k >= abc[i][1]:
                DP[i+1][j][k] = min(DP[i][j][k],DP[i][j-abc[i][0]][k-abc[i][1]]+abc[i][2])
            else:
                DP[i+1][j][k] = DP[i][j][k]
ans = 10**9
for i in range(1,10*N//max(Ma,Mb)+1):
    ans = min(DP[-1][i*Ma][i*Mb],ans)
if ans >= 10**8:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    l = 1
    for j in range(i-1,-1,-1):
        if A[i] <= A[j]:
            l += 1
        else:
            break
    r = 1
    for j in range(i+1,N):
        if A[i] <= A[j]:
            r += 1
        else:
            break
    ans += l*r*A[i]
print(ans)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
l = [i for i in range(N)]
r = [i for i in range(N)]

b = [0] * N
for i in range(N):
    b[a[i]-1] = i

ans = 0
for i in range(N-1,-1,-1):
    m = b[i]
    x,y = l[m],r[m]
    ans += (i+1)*(m-x+1)*(y-m+1)
    l[min(y+1,N-1)] = x
    r[max(x-1,0)] = y
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = list(map(int,input().split()))
A = np.array(A)
ans = 0
for i in range(N):
    for j in range(i,N):
        ans += np.min(A[i:j+1])

print(ans)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
l = [i for i in range(N)]
r = [i for i in range(N)]

b = [0] * N
for i in range(N):
    b[a[i]-1] = i

ans = 0
for i in range(N-1,-1,-1):
    m = b[i]
    x,y = l[m],r[m]
    ans += (i+1)*(m-x+1)*(y-m+1)
    l[min(y+1,N-1)] = x
    r[max(x-1,0)] = y
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import heapq
H,W,N = map(int,input().split())
P = list(list(map(int,input().split()))for i in range(N))
P.sort()

def index(a,x):
    i = bisect.bisect_left(a,x)
    if i != len(a) and a[i] == x:
        return 0
    return -1

def around(a,b):
    out = []
    for i in [-1,0,1]:
        if not 1 < a+i < H:
            continue
        for j in [-1,0,1]:
            if not 1 < b+j < W:
                continue
            out.append([a+i,b+j])
    return out



def search(a,b):
    hoge = 0
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            x,y = a+i,b+j
            if index(P,[x,y]) != -1:
                hoge += 1
    return hoge

A = []
for a,b in P:
    for x,y in around(a,b):
        heapq.heappush(A,[search(x,y),x,y])
a,b = 0,0
ans = [0]*10

while A:
    a = heapq.heappop(A)
    if a != b:
        ans[a[0]] += 1
    b = a[:]

ans[0] = (H-2)*(W-2)-sum(ans[1:])

for i in ans:
    print(i)

Fixed submission:
import sys
input = sys.stdin.readline

H,W,N = map(int,input().split())
A = []
for i in range(N):
    a,b = map(int,input().split())
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if (1< a+i <H) and (1 < b+j < W):
                A.append([a+i,b+j])
A.sort()
ans = [0]*10
hoge = 0
for i in range(len(A)):
    if A[i] == A[i-1]:
        hoge += 1
    else:
        ans[hoge]+= 1
        hoge = 1
ans[hoge]+= 1


ans[0] = (W-2)*(H-2)-sum(ans[1:])

for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import heapq
H,W,N = map(int,input().split())
P = list(list(map(int,input().split()))for i in range(N))
P.sort()

def index(a,x):
    i = bisect.bisect_left(a,x)
    if i != len(a) and a[i] == x:
        return 0
    return -1

def around(a,b):
    out = []
    for i in [-1,0,1]:
        if not 1 < a+i < H:
            continue
        for j in [-1,0,1]:
            if not 1 < b+j < W:
                continue
            out.append([a+i,b+j])
    return out



def search(a,b):
    hoge = 0
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            x,y = a+i,b+j
            if index(P,[x,y]) != -1:
                hoge += 1
    return hoge

A = []
for a,b in P:
    for x,y in around(a,b):
        heapq.heappush(A,[search(x,y),x,y])
a,b = 0,0
ans = [0]*10

while A:
    a = heapq.heappop(A)
    if a != b:
        ans[a[0]] += 1
    b = a[:]

ans[0] = (H-2)*(W-2)-sum(ans[1:])

for i in ans:
    print(i)

Fixed submission:
import sys
input = sys.stdin.readline

H,W,N = map(int,input().split())
A = []
for i in range(N):
    a,b = map(int,input().split())
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if (1< a+i <H) and (1 < b+j < W):
                A.append([a+i,b+j])
A.sort()
ans = [0]*10
hoge = 0
for i in range(len(A)):
    if A[i] == A[i-1]:
        hoge += 1
    else:
        ans[hoge]+= 1
        hoge = 1
ans[hoge]+= 1


ans[0] = (W-2)*(H-2)-sum(ans[1:])

for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N,x = map(int,input().split())
DP = [list(map(int,input().split()))]+[[float('inf')]*(N) for i in range(N-1)]
for i in range(N-1):
    for j in range(N):
        DP[i+1][j] = min(DP[i][j-1],DP[i][j])
ans = float('inf')
for i in range(N):
    ans = min(ans,sum(DP[i])+i*x)
print(ans)

Fixed submission:
N,x = map(int,input().split())
DP = [list(map(int,input().split()))]+[[float('inf')]*(N) for i in range(N-1)]
for i in range(N-1):
    for j in range(N):
        DP[i+1][j] = min(DP[i][j-1],DP[i][j])
ans = float('inf')
for i in range(N):
    ans = min(ans,sum(DP[i])+i*x)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

ans = 0
for i in range(n):
    ans += nums[i] * sum(nums[i+1:])

print(ans % (10**9+7))

Fixed submission:
n = int(input())

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

ans = 0
s = sum(nums)
for i in range(n):
    s -= nums[i]
    ans += nums[i] * s

print(ans % (10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

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

print(ans % (10**9+7))

Fixed submission:
n = int(input())

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

ans = 0
s = sum(nums)
for i in range(n):
    s -= nums[i]
    ans += nums[i] * s

print(ans % (10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

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

print(ans % (10**9+7))

Fixed submission:
n = int(input())

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

ans = 0
s = sum(nums)
for i in range(n):
    s -= nums[i]
    ans += nums[i] * s

print(ans % (10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations_with_replacement

n = int(input())

for i in range(1, n+1):
    ans = 0
    for v in combinations_with_replacement(range(1, 40), 3):        
        x, y, z = v

        if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
            if x == y == z:
                ans = 1
            else:
                ans = 3
            break

    print(ans)

Fixed submission:
n = int(input())
ans = [0] * (n+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            s = x*x + y*y + z*z
            s += x*y + y*z + z*x
            if (s > n):
                continue
            else:
                ans[s] += 1

for i in range(1, n+1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations_with_replacement

n = int(input())

for i in range(1, n+1):
    ans = 0
    for v in combinations_with_replacement(range(1, 60), 3):        
        x, y, z = v

        if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
            if x == y == z:
                ans = 1
            else:
                ans = 3
            break
            
    print(ans)

Fixed submission:
n = int(input())
ans = [0] * (n+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            s = x*x + y*y + z*z
            s += x*y + y*z + z*x
            if (s > n):
                continue
            else:
                ans[s] += 1

for i in range(1, n+1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations_with_replacement

n = int(input())

for i in range(1, n+1):
    ans = 0
    for v in combinations_with_replacement(range(1, 60), 3):        
        x, y, z = v
        if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
            if x == y == z:
                ans = 1
            else:
                ans = 3
    print(ans)

Fixed submission:
n = int(input())
ans = [0] * (n+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            s = x*x + y*y + z*z
            s += x*y + y*z + z*x
            if (s > n):
                continue
            else:
                ans[s] += 1

for i in range(1, n+1):
    print(ans[i])