Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
numlist=[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
timeslis2=[0,]*(100000)
timeslis2[1]=1
numlist2=numlist[::-1]
def times2(N):
    if N!=0:
        if timeslis2[N]==0:
            mini2=[]
            i=0
            while i<=11 and len(mini2)<=2:
                if N-numlist2[i]>=0:
                    mini2.append(times2(N-numlist2[i]))
                #print(mini2,numlist2[i],i)
                i+=1
            mini2.sort()
            timeslis2[N]=mini2[0]+1
            return mini2[0]+1
        else:
            return timeslis2[N]
    return 0
print(times2(N))

Fixed submission:
N=int(input())
numlist=[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
timeslis2=[0,]*(100001)
timeslis2[1]=1
numlist2=numlist[::-1]
def times2(N):
    if N!=0:
        if timeslis2[N]==0:
            mini2=[]
            i=0
            while i<=11 and len(mini2)<=2:
                if N-numlist2[i]>=0:
                    mini2.append(times2(N-numlist2[i]))
                #print(mini2,numlist2[i],i)
                i+=1
            mini2.sort()
            timeslis2[N]=mini2[0]+1
            return mini2[0]+1
        else:
            return timeslis2[N]
    return 0
print(times2(N))

Buggy python submission (verdict: Runtime Error):
N=int(input())
timeslis2=[0,]*(100000)
timeslis2[1]=1
numlist2=numlist[::-1]
def times2(N):
    if N!=0:
        if timeslis2[N]==0:
            mini2=[]
            i=0
            while i<=11 and len(mini2)<=2:
                if N-numlist2[i]>=0:
                    mini2.append(times2(N-numlist2[i]))
                #print(mini2,numlist2[i],i)
                i+=1
            mini2.sort()
            timeslis2[N]=mini2[0]+1
            return mini2[0]+1
        else:
            return timeslis2[N]
    return 0
print(times2(N))

Fixed submission:
N=int(input())
numlist=[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
timeslis2=[0,]*(100001)
timeslis2[1]=1
numlist2=numlist[::-1]
def times2(N):
    if N!=0:
        if timeslis2[N]==0:
            mini2=[]
            i=0
            while i<=11 and len(mini2)<=2:
                if N-numlist2[i]>=0:
                    mini2.append(times2(N-numlist2[i]))
                #print(mini2,numlist2[i],i)
                i+=1
            mini2.sort()
            timeslis2[N]=mini2[0]+1
            return mini2[0]+1
        else:
            return timeslis2[N]
    return 0
print(times2(N))
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
                
    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]

    
f=lambda:map(int,input().split())
N,M=f()
uf=UnionFind(N+1)

p=list(f())
for _ in [0]*M:
    uf.unite(*f())

index_list=[[] for _ in [0]*(N+1)]
group_list=[[] for _ in [0]*(N+1)]
for i in range(1,N+1):
    index_list[uf.find_root(i)].append(p.index(i)+1)
    group_list[uf.find_root(i)].append(i)
    
res=0
for i in range(1,N+1):
    if i==uf.find_root(i):
        res+=len(set(index_list[i]) & set(group_list[i]))

print(res)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
                
    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]

    
f=lambda:map(int,input().split())
N,M=f()
uf=UnionFind(N+1)

p=list(f())
p_index=[[] for _ in [0]*(N+1)]
for i in range(1,N+1):
    p_index[p[i-1]]=i
for _ in [0]*M:
    uf.unite(*f())


index_list=[[] for _ in [0]*(N+1)]
group_list=[[] for _ in [0]*(N+1)]

for i in range(1,N+1):
    index_list[uf.find_root(i)].append(p_index[i])
    group_list[uf.find_root(i)].append(i)
    
res=0
for i in range(1,N+1):
    if i==uf.find_root(i):
        res+=len(set(index_list[i]) & set(group_list[i]))

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq 
# よく使うメソッドは以下
# q=heapq.heapify(List)：リスト→プライオリティキュー
# heapq.heappop(q)：プライオリティキュー q から最小要素を取り出す(O(log n))
# heapq.heappop(q,a)：プライオリティキュー q に要素を追加 O(log n))

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

A1,A2,A3=A[:N],A[N:2*N],A[2*N:]

res=[]
for k in range(N+1):
    qA=A1+A2[:k]
    heapq.heapify(qA)
    sumA=sum(qA)

    qB=A2[k:]+A3
    heapq.heapify(qB)
    sumB=0
    
    for n in range(N):
        sumB+=heapq.heappop(qB)
    for n in range(k):
        sumA-=heapq.heappop(qA)
    res.append(sumA-sumB)
print(max(res))

Fixed submission:
import heapq 

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

A1,A2,A3=A[:N],A[N:2*N],A[2*N:]

res=[]
qA=A1
heapq.heapify(qA)
sumA=sum(qA)

qB=[-b for b in A3]
heapq.heapify(qB)
sumB=sum(qB)


resA,resB=[sumA],[sumB]
for k in range(N):
    heapq.heappush(qA,A2[k])
    a=heapq.heappop(qA)
    sumA+=A2[k]-a
    
    heapq.heappush(qB,-A2[N-(k+1)])
    b=heapq.heappop(qB)
    sumB+=-A2[N-(k+1)]-b
    resA.append(sumA)
    resB.append(sumB)

res=[resA[i]+resB[N-i] for i in range(N+1)]
print(max(res))
Buggy python submission (verdict: Runtime Error):
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]>0:
            if 2*T-(X[j]-X[0])>=0:
                col+=1+(2*T-(X[j]-X[0]))//L
            else:
                col+=0
        else:
            col-=max((2*T-X[j]+X[0])//L,0)
col=col%N
X2=[(X[i]+(3-2*W[i])*(T-0.01)) % L for i in range(N)]

ant0=(X2[0],col)

X2.sort()

x=X2.index(ant0[0])


for i in range(x-col-N,x-col):
    print(round(X2[i]))

Fixed submission:
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]==1:
            if 2*T-(X[j]-X[0])>=0:
                col+=(1+(2*T-(X[j]-X[0]))//L)
        else:
            if 2*T-(X[0]-X[j])>=0:
                col-=(1+(2*T-(X[0]-X[j]))//L)

col=col%N
X2=[(X[i]+(3-2*W[i])*T) % L for i in range(N)]
X2_0=X2[0]

X2.sort()

index=[i for i,x in enumerate(X2) if x==X2_0]

if len(index)==1:
    index=index[0]
else:
    if W[0]==1:
        index=index[1]
    else:
        index=index[0]

i=(index-col)%N

X2=X2[i:]+X2[:i]
print(*X2,sep='\n')
Buggy python submission (verdict: Runtime Error):
i,p=input,print;H,W=map(int,i().split());for j in range(H):k=i();p(k);p(k)

Fixed submission:
i,p=input,print;H,W=map(int,i().split());C=[i() for x in range(H)]
for j in range(H):
    p(C[j]);p(C[j])
Buggy python submission (verdict: Runtime Error):
S=input()[::-1]
def a(s):
    if s:
        if s[:5]=='maerd':
            return a(s[5:])
        elif s[:5]=='esare':
            return a(s[5:])
        elif s[:6]=='resare':
            return a(s[6:])
        elif s[:7]=='remaerd':
            return a(s[7:])
        else:
            return False
    else:
        return True
print(a(S))

Fixed submission:
s,f=input()[::-1],-1
while f<0:
    if s:
        if s[:5]=='maerd':
            s=s[5:]
        elif s[:5]=='esare':
            s=s[5:]
        elif s[:6]=='resare':
            s=s[6:]
        elif s[:7]=='remaerd':
            s=s[7:]
        else:
            f=0
    else:
        f=1
print(['NO','YES'][f])
Buggy python submission (verdict: Runtime Error):
import bisect

N,A=map(int,input().split())
x=[i-A for i in map(int,input().split())]


dp=[[0]*(2*N*A+1) for _ in [0]*(N+1)]
dp[0][N*A]=1
# dp[n][k]:n番目までの整数でkが作れる場合の数
    
for n in range(1,N+1):
    for k in range(-N*A,N*A+1):
        dp[n][k]+=dp[n-1][k-x[n-1]]+dp[n-1][k]

print(dp[N][N*A]-1)

Fixed submission:
import bisect

N,A=map(int,input().split())
x=[i-A for i in map(int,input().split())]

B=max(max(x),abs(min(x)))

dp=[[0]*(2*N*B+1) for _ in [0]*(N+1)]
dp[0][N*B]=1
# dp[n][k]:n番目までの整数でkが作れる場合の数
    
for n in range(1,N+1):
    for k in range(-N*B,N*B+1):
        dp[n][k]+=dp[n-1][k-x[n-1]]+dp[n-1][k]

print(dp[N][N*B]-1)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

evens = Counter(A[::2])
odds = Counter(A[1::2])
evens[0] = 0 # 番兵
odds[0] = 0

e1, e2 = evens.most_common(2)
o1, o2 = odds.most_common(2)

if e1[0] != o1[0]:
  print(N - (e1[1] + o1[1]))
else:
  print(N - max(e1[1] + o2[1], e2[1] + o1[1]))

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

evens = Counter(A[::2])
odds = Counter(A[1::2])
evens[0] = 0 # 番兵
odds[0] = 0

e1, e2 = evens.most_common(2)
o1, o2 = odds.most_common(2)

if e1[0] != o1[0]:
  print(N - (e1[1] + o1[1]))
else:
  print(N - max(e1[1] + o2[1], e2[1] + o1[1]))
Buggy python submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]

*p, = range(n)
rank = [1]*n
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    rx = rank[px]; ry = rank[py]
    if ry < rx:
        p[py] = px
    elif rx < ry:
        p[px] = py
    else:
        p[py] = px
        rank[px] += 1
    return 1
 
for a,b in ab:
    unite(a,b)

print( len(set(p)) - 1 )


Fixed submission:
n,m = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(n)
 
for a,b in ab:
    uf.union(a-1,b-1)

print( uf.group_count() - 1 )
Buggy python submission (verdict: Runtime Error):
n = int(input())
c = input()
rl = [ i for i,_ in enumerate(c) if _ == 'R' ]

cnt = 0
loc = 0
rid = -1
while True:
	if c[loc] == 'W':
		rloc = rl[rid]
		rid -= 1
		if rloc < loc:
			break
		else:
			cnt += 1
	loc += 1
	if loc == n:
		break
	#print(c,cnt)
print(cnt)

Fixed submission:
n = int(input())
c = input()
rl = [ i for i,_ in enumerate(c) if _ == 'R' ]

cnt = 0
loc = 0
rid = -1
while True:
	try:
		if c[loc] == 'W':
			rloc = rl[rid]
			rid -= 1
			if rloc < loc:
				break
			else:
				cnt += 1
		loc += 1
		if loc == n:
			break
		#print(c,cnt)
	except:
		break
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
#from collections import Counter
#print(min([i for i in Counter(list(c)).values()]))

cnt = 0
loc = 0
while True:
	if c[loc] == 'W':
		rloc = c.rfind('R')
		if rloc < loc:
			break
		else:
			cnt += 1
			lc = list(c)
			lc[rloc] = 'W'
			c = ''.join(lc)
	loc += 1
	if loc == n:
		break
	#print(c,cnt)
print(cnt)

Fixed submission:
n = int(input())
c = input()
rl = [ i for i,_ in enumerate(c) if _ == 'R' ]

cnt = 0
loc = 0
rid = -1
while True:
	try:
		if c[loc] == 'W':
			rloc = rl[rid]
			rid -= 1
			if rloc < loc:
				break
			else:
				cnt += 1
		loc += 1
		if loc == n:
			break
		#print(c,cnt)
	except:
		break
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
    
def f(x, result):
    if x == 1:
        return 1
    while True:
        if x % 2 == 0:
            qcnt = 0
            while True:
                x = x // 2
                qcnt += 1
                if x % 2 != 0:
                    break
            return result[x] * (qcnt + 1)
        else:
            break
    
    while True:
        if x == 1:
            break
        else:
            p = 3
            while True:
                if x % p == 0:
                    pcnt = 0
                    while True:
                        x = x // p
                        pcnt += 1
                        if x % p != 0:
                            break
                    return result[x] * (pcnt + 1)
                else:
                    p += 2
    y = 1
    for i in yakusu.values():
        y *= (i+1)
    return y
    

s = 0
result = {1:1}
for i in range(1,n+1):
    result[i] = f(i, result)
    s += i * f(i,result)
    

print(s)

Fixed submission:

n = int(input())
s = 0
for i in range(1,n+1):
    s +=  i * ( (n // i) * (n // i + 1) // 2 )


print(s)
Buggy python submission (verdict: Time Limit Exceeded):
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table
  
n = int(input())
ans = 0


for c in range(1,n):
    ab = n - c
    ans += num_divisors_table(ab)[-1]
print(ans)


Fixed submission:
import math
n = int(input())
ans = 0

for a in range(1, n):
    ans += math.floor((n-1)/a)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table
  
n = int(input())
ans = 0


for c in range(1,n):
    ab = n - c
    ans += num_divisors_table(ab)[-1]
print(ans)


Fixed submission:
import math
n = int(input())
ans = 0

for a in range(1, n):
    ans += math.floor((n-1)/a)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
ans = 0

for c in range(1,n):
    ab = n - c
    for i in range(1, int(math.sqrt(ab)) + 1):
        if ab % i == 0:
            ans += 1
            if ab != i**2:
                ans += 1

print(ans)


Fixed submission:
import math
n = int(input())
ans = 0

for a in range(1, n):
    ans += math.floor((n-1)/a)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
import sympy
n = int(input())
ans = 0

for c in range(1,n):
    ab = n - c
    ans += sympy.divisor_count(ab)
        
print(ans)


Fixed submission:
import math
n = int(input())
ans = 0

for a in range(1, n):
    ans += math.floor((n-1)/a)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n-1):
    ans += (sum(a[0:i+1])%1000000007)*(a[i+1]%1000000007)

print(ans%1000000007)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
a_sum = [a[0]]

for i in range(n-1):
    a_sum.append((a_sum[i]+a[i+1])%1000000007)

    ans += a_sum[i]*(a[i+1]%1000000007)

print(ans%1000000007)
Buggy python submission (verdict: Runtime Error):
n = int(input())
num = [0]*1000

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x - 1
            if a <= 1001:
                num[a] += 1

num = num[:n]

for i in num:
    print(i)


Fixed submission:
n = int(input())
num = [0]*10000

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x - 1
            if a <= 9999:
                num[a] += 1

num = num[:n]

for i in num:
    print(i)

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

for i in range(1, n+1):
    cnt = 0
    j = int(i**0.5)

    for x in reversed(range(1, j)):
        for y in reversed(range(1, x+1)):
            for z in reversed(range(1, y+1)):
                if i == x**2 + y**2 + z**2 + x*y + y*z + z*x:
                    if x==y==z:
                        cnt += 1
                    elif x==y or y==z or z==x:
                        cnt += 3
                    else:
                        cnt += 6
                    break

    print(cnt)


Fixed submission:
n = int(input())
num = [0]*10000

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x - 1
            if a <= 9999:
                num[a] += 1

num = num[:n]

for i in num:
    print(i)

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

for i in range(1, n+1):
    cnt = 0
    j = int(i**0.5)

    for x in reversed(range(1, j+1)):
        for y in reversed(range(1, x+1)):
            for z in reversed(range(1, y+1)):
                if i == x**2 + y**2 + z**2 + x*y + y*z + z*x:
                    if x==y==z:
                        cnt += 1
                    elif x==y or y==z or z==x:
                        cnt += 3
                    else:
                        cnt += 6

    print(cnt)


Fixed submission:
n = int(input())
num = [0]*10000

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x - 1
            if a <= 9999:
                num[a] += 1

num = num[:n]

for i in num:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = list(map(int, input().split()))
list_a.sort()

for i in range(n):
    under = list_a.count(i+1)
    print(under)
    del list_a[:under]


Fixed submission:
n = int(input())
list_a = list(map(int, input().split()))
from collections import Counter
under = Counter(list_a)

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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = list(map(int, input().split()))
for i in range(n):
    print(list_a.count(i+1))


Fixed submission:
n = int(input())
list_a = list(map(int, input().split()))
from collections import Counter
under = Counter(list_a)

for i in range(1,n+1):
    print(under[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math
k =  int(input())
ans = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += math.gcd((math.gcd(a, b)), c)

print(ans)


Fixed submission:
import math
k =  int(input())
ans = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        if math.gcd(a, b) == 1:
            ans += k
        else:
            for c in range(1, k+1):
                ans += math.gcd((math.gcd(a, b)), c)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N_1 = map(int, input().split())
cnt = 0

for r in range(N_1//R + 1):
    N_2 = N_1
    N_2 -= r*R
    for g in range(N_2//G + 1):
        N_3 = N_2
        N_3 -= g*G
        for b in range(N_3//B + 1):
            if N_3 == b*B:
                cnt += 1

print(cnt)


Fixed submission:
R, G, B, N_1 = map(int, input().split())
cnt = 0

for r in range(N_1//R + 1):
    N_2 = N_1
    N_2 -= r*R
    for g in range(N_2//G + 1):
        N_3 = N_2
        N_3 -= g*G

        if N_3%B == 0:
            cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
from sys import exit
N = int(input())
 
cnt = 0
for i in range(N):
    x,y = map(int,input().split())
    if cnt == 3:
        print("Yes")
        exit(0)
    if x == y:
        cnt += 1
    else:
        cnt = 0

if cnt == 3:
    print("Yes"
    
print("No")

Fixed submission:
from sys import exit
N = int(input())
 
cnt = 0
for i in range(N):
    x,y = map(int,input().split())
    if cnt == 3:
        print("Yes")
        exit(0)
    if x == y:
        cnt += 1
    else:
        cnt = 0

if cnt == 3:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

_sum = 0

for i in range(N-1):
    for j in range(i+1,N):
        _sum += A[i]*A[j]
        _sum %= (10**9 + 7)

print(_sum)

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

S = [A[0]]

for i in range(1,N):
    S.append(A[i]+S[i-1])

_sum = 0
for i in range(N):
    _sum += A[i]*(S[N-1]-S[i])
    _sum %= 10**9+7

print(_sum)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
from sys import exit

def maxindexes(L,Lmax):
    ret = []
    for i in range(len(L)):
        if L[i] == Lmax:
            ret.append(i)
    
    return ret


H,W,M = map(int,input().split())
row = [0]*H
col = [0]*W
bomb = []

for _ in range(M):
    a,b = (int(x)-1 for x in input().split())
    row[a] += 1
    col[b] += 1
    bomb.append((a,b))

rmax = max(row)
cmax = max(col)

rmaxind= maxindexes(row,rmax)
cmaxind = maxindexes(col,cmax)

for p in product(rmaxind,cmaxind):
    if p not in bomb:
        print(rmax+cmax)
        exit(0)

print(rmax+cmax-1)

Fixed submission:
from itertools import product
from sys import exit

def maxindexes(L,Lmax):
    ret = []
    for i in range(len(L)):
        if L[i] == Lmax:
            ret.append(i)
    
    return ret


H,W,M = map(int,input().split())
row = [0]*H
col = [0]*W
bomb = set([])

for _ in range(M):
    a,b = (int(x)-1 for x in input().split())
    row[a] += 1
    col[b] += 1
    bomb.add((a,b))

rmax = max(row)
cmax = max(col)

rmaxind= maxindexes(row,rmax)
cmaxind = maxindexes(col,cmax)
prod = product(rmaxind,cmaxind)

for p in prod:
    if p not in bomb:
        print(rmax+cmax)
        exit(0)

print(rmax+cmax-1)
Buggy python submission (verdict: Time Limit Exceeded):
X,K,D = map(int,input().split())

if X < 0:
    X = -X

cnt = 0
for i in range(K):
    X -= D
    cnt += 1
    if X <= 0:
        break
    else:
        continue
    
remain = K-cnt
    
if remain == 0:
    print(abs(X))
else:
    if remain % 2 == 0:
        print(abs(X))
    else:
        print(abs(X+D))

Fixed submission:
X,K,D = map(int,input().split())

if X < 0:
    X = -X

cnt = 0
Q = X//D
R = X%D

if K < Q:
    print(X-K*D)
else:
    if (K - Q)%2 == 0:
        print(abs(R))
    else:
        print(abs(R-D))