Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())


# 約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = 5*10**4
acc = [0]*(N+1)
cnt = 0
for i in range(N+1):
    n1 = 2*i + 1
    n2 = i+1
    div1 = make_divisors(n1)
    div2 = make_divisors(n2)    
    if len(div1) == len(div2) == 2:
        cnt += 1
    acc[i] = cnt
# print(acc[:10])
for i in range(Q):
    l_,r_ = map(int, input().split())
    l = (l_-1)//2
    r = (r_-1)//2
    if l > 0:
        print(acc[r]-acc[l-1])
    else:
        print(acc[r])

Fixed submission:
Q = int(input())


# 約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = 5*10**4
acc = [0]*(N+1)
cnt = 0
for i in range(N+1):
    n1 = 2*i + 1
    n2 = i+1
    div1 = make_divisors(n1)
    div2 = make_divisors(n2)    
    if len(div1) == len(div2) == 2:
        cnt += 1
    acc[i] = cnt
# print(acc[:10])
for i in range(Q):
    l_,r_ = map(int, input().split())
    l = (l_-1)//2
    r = (r_-1)//2
    if l > 0:
        print(acc[r]-acc[l-1])
    else:
        print(acc[r])
Buggy python submission (verdict: Runtime Error):
"""
https://atcoder.jp/contests/abc080/tasks/abc080_d
400

同じチャンネル同士でかぶりが発生するとアウト
imos
"""

N,C  = map(int, input().split())
t_max = 10**5
# c_imos = [[0]*t_max for t in range(C)]
imos = [0] * t_max
for i in range(N):
    s,t,c = map(int, input().split())
    c -= 1
    # t -= 1
    s -= 1
    # c_imos[c][s] += 1
    # c_imos[c][t] -= 1
    imos[s] += 1
    imos[t] -= 1 

    # for c_ in c_imos:
    #     print(list(accumulate(c_)))
    
from itertools import accumulate
print(max(list(accumulate(imos))))

Fixed submission:
N,C  = map(int, input().split())
t_max = 2*10**5
c_imos = [[0]*t_max for t in range(C)]
# 前処理 : 同一チャンネルのときはくっつけられる
c_imos = [[0]*t_max for t in range(C)]

for i in range(N):
    s,t,c = map(int, input().split())
    c -= 1
    s -= 1
    # t -= 1
    c_imos[c][s] += 1
    c_imos[c][t] -= 1
    
ans = [0] * t_max
from itertools import accumulate
for c_ in c_imos:
    acc = list(accumulate(c_))
    ans = [a+min(1,b) for a,b in zip(ans,acc)]
print(max(ans))

Buggy python submission (verdict: Runtime Error):
N,C  = map(int, input().split())
t_max = 10**5
# c_imos = [[0]*t_max for t in range(C)]
imos = [0] * t_max
for i in range(N):
    s,t,c = map(int, input().split())
    c -= 1
    # t -= 1
    s -= 1
    # c_imos[c][s] += 1
    # c_imos[c][t] -= 1
    imos[s] += 1
    imos[t] -= 1 

    # for c_ in c_imos:
    #     print(list(accumulate(c_)))
    


Fixed submission:
N,C  = map(int, input().split())
t_max = 2*10**5
c_imos = [[0]*t_max for t in range(C)]
# 前処理 : 同一チャンネルのときはくっつけられる
c_imos = [[0]*t_max for t in range(C)]

for i in range(N):
    s,t,c = map(int, input().split())
    c -= 1
    s -= 1
    # t -= 1
    c_imos[c][s] += 1
    c_imos[c][t] -= 1
    
ans = [0] * t_max
from itertools import accumulate
for c_ in c_imos:
    acc = list(accumulate(c_))
    ans = [a+min(1,b) for a,b in zip(ans,acc)]
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
As = [list(map(int, input().split())) for _ in range(n)]

import copy
d = copy.deepcopy(As)
for i in range(n):
    for k in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
cnt = 0
routes = set()
for i in range(n):
    for j in range(i+1,n):
        routes.add(i*n+j)


for i in range(n):
    for k in range(n):
        for j in range(n):
            x = (i-j)*(j-k)*(k-i)
            # かぶりを消す
            if d[i][j] == d[i][k]+d[k][j] and x != 0:
                try:
                    routes.remove(i*n+j)
                except:
                    pass
cnt = 0
for r in routes:
    i,j = divmod(r,n)
    cnt += d[i][j]

if As != d:
    print(-1)
else:
    print(cnt)

Fixed submission:
n = int(input())
As = [list(map(int, input().split())) for _ in range(n)]

import copy
d = copy.deepcopy(As)
for i in range(n):
    for k in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
cnt = 0
routes = set()
for i in range(n):
    for j in range(i+1,n):
        routes.add(i*n+j)


for i in range(n):
    for k in range(n):
        for j in range(n):
            x = (i-j)*(j-k)*(k-i)
            # かぶりを消す
            if d[i][j] == d[i][k]+d[k][j] and x != 0:
                try:
                    routes.remove(i*n+j)
                except:
                    pass
cnt = 0
for r in routes:
    i,j = divmod(r,n)
    cnt += d[i][j]

if As != d:
    print(-1)
else:
    print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
n, m, r = map(int, input().split())
INF = 1 << 60

d = [[INF] * n for i in range(n)]
rs = list(map(int, input().split()))

for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c

def warshall_floyd(d):
    """
    input
        d : 初期全点対距離
    output
        d : 最適化後全点対距離
    """
    n = len(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

d_optimized = warshall_floyd(d)
# print(d_optimized)

ans = INF
for inds in permutations([r-1 for r in rs]):
    cnt = 0
    for i in range(r-1):
        prev = inds[i]
        nxt = inds[i+1]
        cnt += d_optimized[prev][nxt]
    ans = min(ans,cnt)
print(ans)

Fixed submission:
from itertools import permutations
n, m, r = map(int, input().split())
INF = 1 << 60

d = [[INF] * n for i in range(n)]
rs = list(map(int, input().split()))

for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c

def warshall_floyd(d):
    """
    input
        d : 初期全点対距離
    output
        d : 最適化後全点対距離
    """
    n = len(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

d_optimized = warshall_floyd(d)
# print(d_optimized)

ans = INF
for inds in permutations([r-1 for r in rs]):
    cnt = 0
    for i in range(r-1):
        prev = inds[i]
        nxt = inds[i+1]
        cnt += d_optimized[prev][nxt]
    ans = min(ans,cnt)
print(ans)
Buggy python submission (verdict: Runtime Error):
# 前から順番に後ろに向けてswap
n = int(input())
ps = list(map(int, input().split()))

cnt = 0
for i, p in enumerate(ps):
    if i + 1 == p:
        ps[i], ps[i+1] = ps[i+1], ps[i]
        cnt += 1
print(cnt)


Fixed submission:
N = int(input())
ps = list(map(int,input().split()))
# p_swap = [-1]*N
ans = 0
for i in range(N-1):
    if i+1 == ps[i]:
        p1,p2 = ps[i:i+2]
        ps[i] = p2
        ps[i+1] = p1
        ans += 1
if ps[N-1] == N:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s1 = input()
s2 = input()
mod = 10**9 + 7
ind = []
for i,(_s1,_s2) in enumerate(zip(s1,s2)):
    if _s1 == _s2:
        ind.append(i)
# print(ind)
cnt = 0
if ind[0] == 0:
    d = 3
    single = True
    cnt = 1
else:
    d = 6
    single = False
    cnt = 2
        
while cnt < n:
    if cnt in ind: # * -> 1
        if single: 
            d *= 2
        else:#2->1
            d *= 1
        cnt += 1
        single = True
    else: # * -> 2
        if single:
            d *= 2
        else:
            d *= 3
        cnt += 2
        single =False
    d %= mod
print(d)

Fixed submission:
n = int(input())
s1 = input()
s2 = input()
mod = 10**9 + 7
ind = []
for i,(_s1,_s2) in enumerate(zip(s1,s2)):
    if _s1 == _s2:
        ind.append(i)
# print(ind)
cnt = 0
if len(ind) == 0:
    d = 6
    cnt = 2
    single = False
elif ind[0] == 0:
    d = 3
    single = True
    cnt = 1
else:
    d = 6
    single = False
    cnt = 2
        
while cnt < n:
    if cnt in ind: # * -> 1
        if single: 
            d *= 2
        else:#2->1
            d *= 1
        cnt += 1
        single = True
    else: # * -> 2
        if single:
            d *= 2
        else:
            d *= 3
        cnt += 2
        single = False
    d %= mod
    
print(d)

"""
"""
Buggy python submission (verdict: Runtime Error):
n = int(input())
As = list(map(int, input().split()))

# four = sum([1 for a in As if a%4 == 0])
# odd = sum([1 for a in As if a%2 == 1])
# two = sum([1 for a in As if a%2 == 0 and a%4 != 0])
four = 0
odd = 0
two = 0
for a in As:
    if a % 2 == 1:
        odd += 1
    elif a % 4 == 0:
        four += 1
    else:
        two += 1


if four < two%2 + odd - 1:
    print("No")
else:
    print("Yes")


fields @timestamp, @message
| sort @timestamp desc
| filter 
| limit 20

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

four = sum([1 for a in As if a%4 == 0])
odd = sum([1 for a in As if a%2 == 1])
two = sum([1 for a in As if a%2 == 0 and a%4 != 0])
if four < two%2 + odd - 1:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
from collections import defaultdict
edges = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

first = edges[1]
# print(first)
for fr in first:
    if N in edges[fr]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")N,M = map(int, input().split())
from collections import defaultdict
edges = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

first = edges[1]
# print(first)
for fr in first:
    if N in edges[fr]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Fixed submission:
N,M = map(int, input().split())
from collections import defaultdict
edges = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

first = edges[1]
# print(first)
for fr in first:
    if N in edges[fr]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
K = int(input())
print(2)
print(N+K-2,2)

Fixed submission:
K = int(input())
N = 50

a = [i for i in range(N)]
a = [x + K // N for x in a]
for i in range(K % N):
    a = [x - 1 for x in a]
    a[i] += N + 1

print(N)
print(*a)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
from collections import defaultdict
edges = []
to = defaultdict(list) # 1から到達できるか
ot = defaultdict(list) # Nから到達できるか
N, M, P = map(int, input().split())
visited_toN = [False]*(N+1)
visited_fm1 = [False]*(N+1)    
for i in range(M):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((a,b,-c+P))
    to[a].append(b)
    ot[b].append(a)

def dfs(v):
    global visited_fm1
    if visited_fm1[v]:return
    visited_fm1[v] = True
    for nxt in to[v]:
        dfs(nxt)
    
def dfs_r(v):
    global visited_toN
    if visited_toN[v]:return
    visited_toN[v] = True
    for nxt in ot[v]:
        dfs_r(nxt)
        
dfs(0)
dfs_r(N-1)
is_ok = []

for s, t in zip(visited_fm1,visited_toN):
    is_ok.append(s and t)


# BellmanFord    
INF = 10 ** 18
def bellmanFord(n, edges, s, g):
    """
    input
        n : 頂点の数
        edges : (始点, 終点, コスト)のリスト
        s : 探索の始点
        g : 探索の終点
    output
        sから各点への最短距離
    """    
    d = [INF] * n
    d[s] = 0
    cnt = 0
    while True:
        update = False
        for a, b, c in edges:
            if not is_ok[a]:continue
            if not is_ok[b]:continue
            if d[a] != INF and d[b] > d[a] + c:
                d[b] = d[a] + c
                update = True
        if not update:
            break
        cnt += 1
        # 負閉路の存在をチェック
        if cnt > n:
            print(-1)
            exit()
        # print(d,cnt)
    return d[g]



ans = bellmanFord(N,edges,0,N-1)
print(max(0,-ans))


Fixed submission:
N = int(input())
As = list(map(int, input().split()))
from itertools import accumulate
acc = list(accumulate(As))
s = sum(As)
mn = 10**10
for i,x in enumerate(acc[:-1]):
    y = s - x
    if mn >= abs(x-y):
        mn = abs(x-y)
print(mn)
Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
f = 0
s = 0
from collections import deque
ps = [-1] * n
used = [False] * n
used[0] = True # 始めどこから行くか
q = deque([0])
while len(q) > 0:
    a = q.popleft()
    if a == n-1:
        break
    for u in edges[a]:
        if not used[u]:
            ps[u] = a
            q.append(u)
            used[u] = True
nx = n - 1
xs = [n-1]
while nx != 0:
    nx = ps[nx]
    xs.append(nx)
l = len(xs) - 2
f = (l + 1)//2
s = l - f

mid = len(xs)//2

# bfs 0側
used = [-1] * n
used[0] = 0 
q = deque([0])
cnt = 0
while len(q) > 0:
    a = q.popleft()
    for u in edges[a]:
        if used[u] == -1 and u != xs[mid+1]:
            q.append(u)
            used[u] = 0
            cnt += 1
# print("cnt",cnt)
f += cnt

# bfs n-1側
used = [-1] * n
used[n-1] = 0 
q = deque([n-1])
cnt = 0
while len(q) > 0:
    a = q.popleft()
    for u in edges[a]:
        if used[u] == -1 and u != xs[mid]:
            q.append(u)
            used[u] = 0
            cnt += 1
# print("cnt",cnt)
s += cnt

if f > s:
    print("Fennec")
else:
    print("Snuke")


Fixed submission:
n = int(input())
edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
f = 0
s = 0
from collections import deque
ps = [-1] * n
used = [False] * n
used[0] = True # 始めどこから行くか
q = deque([0])
while len(q) > 0:
    a = q.popleft()
    if a == n-1:
        break
    for u in edges[a]:
        if not used[u]:
            ps[u] = a
            q.append(u)
            used[u] = True

nx = n - 1
xs = [n-1]
while nx != 0:
    nx = ps[nx]
    xs.append(nx)

xs.reverse()
l = len(xs) - 2
f = (l+1)//2
s = l-f

if len(xs) == 2:
    z_lim = -1
    n_lim = 0
else:
    z_lim = (len(xs)+1)//2
    n_lim = z_lim - 1

# bfs 0側
used = [-1] * n
used[0] = 0 
q = deque([0])
cnt = 0
while len(q) > 0:
    a = q.popleft()
    for u in edges[a]:
        if used[u] == -1 and u != xs[z_lim]:
            q.append(u)
            used[u] = 0
            cnt += 1
# print("cnt",cnt)
f += cnt

# bfs n-1側
used = [-1] * n
used[n-1] = 0 
q = deque([n-1])
cnt = 0
while len(q) > 0:
    a = q.popleft()
    for u in edges[a]:
        if used[u] == -1 and u != xs[n_lim]:
            q.append(u)
            used[u] = 0
            cnt += 1

s += cnt
# print("z_lim",z_lim,"nlim",n_lim)
# print("f",f,"s",s)
if f > s:
    print("Fennec")
else:
    print("Snuke")
Buggy python submission (verdict: Runtime Error):
n = sum(Ss)
# INF = 10**10
dp = [False] * (n+1)
dp[0] = True
for i in range(N):
    x = Ss[i]
    for j in range(n+1):
        if j+x > n : continue 
        dp[j+x] = dp[j] or dp[j+x]

ans = 0
for i in range(n+1):
    if dp[i] and i%10 != 0:
        ans = i
print(ans)

Fixed submission:

N = int(input())
Ss = [int(input()) for _ in range(N)]
Ss.sort()
ans = sum(Ss)
if ans % 10 != 0:
    print(ans)
    exit()
cnt_10 = 0
for s in Ss:
    if s % 10 == 0:continue
    ans -= s
    if ans % 10 != 0:
        print(ans)
        exit()
print(0)
Buggy python submission (verdict: Runtime Error):
"""
rootを決めて、aから必ずrootを通ってbに到達するとする
aとbのlcaより上は、+2されることになるので、実質通っていないのと同値
どんな木であっても、自分自身が偶数回(0を含む)でてこないと
ノードの値は偶数にはなりえない
"""
n, m = map(int, input().split())
cnts = [0] * (n+1) 
for i in range(n):
    a,b = map(int, input().split())
    cnts[a] += 1
    cnts[b] += 1
if all([c%2 == 0 for c in cnts]):
    print("YES")
else:
    print("NO")

Fixed submission:
"""
rootを決めて、aから必ずrootを通ってbに到達するとする
aとbのlcaより上は、+2されることになるので、実質通っていないのと同値
どんな木であっても、自分自身が偶数回(0を含む)でてこないと
ノードの値は偶数にはなりえない
"""
n, m = map(int, input().split())
cnts = [0] * (n+1) 
for i in range(m):
    a,b = map(int, input().split())
    cnts[a] += 1
    cnts[b] += 1
if all([c%2 == 0 for c in cnts]):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int,input().split())
count = 0
start = max(S - 2*K, 0)
for X in range(start,K+1):
    for Y in range(X,K+1):
        for Z in range(Y,K+1):
            if X+Y+Z == S:
                if X == Y and X == Z:
                    count += 1
                elif X == Y and Y != Z:
                    count += 3
                elif Y == Z  and Z != X:
                    count += 3
                else:
                    count += 6

print(count)

Fixed submission:
K, S = map(int,input().split())
count = 0
start = max(S - 2*K, 0)

for X in range(start,K+1):
    for Y in range(start,K+1):
        Z = S - X - Y
        if Z >= 0 and Z <= K:
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
H,W = map(int, input().split())
fields = [list(input()) for i in range(H)]

for f in fields:
    cnt += f.count("#")
if cnt == H + W - 1: 
    print("Possible")
else:
    print("Impossible")

Fixed submission:
H,W = map(int, input().split())
fields = [list(input()) for i in range(H)]

mvs = [(0,1),(1,0)]

from collections import deque
q = deque()
q.append((0,0))

cnt = 0
for f in fields:
    cnt += f.count("#")
if cnt != H + W - 1: 
    print("Impossible")
    exit()
# ゴールまで連結しているか
while len(q) > 0:
    h,w = q.popleft()
    if h == H-1 and w == W-1:
        print("Possible")
        exit()
    for dh, dw in mvs:
        h_nx = h + dh
        w_nx = w + dw
        if h_nx >= H or w_nx >= W:continue
        if fields[h_nx][w_nx] == ".":continue
        q.append((h_nx,w_nx))
print("Impossible")
Buggy python submission (verdict: Runtime Error):
N = int(input())
return(N*(N+1)//2)

Fixed submission:
N = int(input())
print(int(N*(N+1)/2))
Buggy python submission (verdict: Runtime Error):
N,M  = map(int, input().split())
balls = [1]*N
reds = [False]*N
reds[0] = [True]
for i in range(M):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    balls[x] -= 1
    balls[y] += 1
    if reds[x]:
        reds[y] = True
    if balls[x] == 0:
        reds[x] = False

print(sum(reds))

Fixed submission:
N,M  = map(int, input().split())
balls = [1]*(N+1)
reds = [False]*(N+1)
reds[0] = True
for i in range(M):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    balls[x] -= 1
    balls[y] += 1
    if reds[x]:
        reds[y] = True
    if balls[x] == 0:
        reds[x] = False

print(sum(reds))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
c=0
for i in range(1,N+1):
  for j in range(1,N+1):
    if i*j<N:
      c+=1
    else:
      break
print(c)

Fixed submission:
N=int(input())
c=0
for i in range(1,N+1):
  d=(N-1)//i
  c+=d
  
print(c)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A2=0
for i in ragne(len(A)):
  A2+=A[i]**2
c=(sum(A))**2-A2
print(c//2)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
c=0
d=sum(A)
for i in range(0,N-1):
    d-=A[i]
    c+=A[i]*d
    if(c>10**9+7):
        c%=(10**9+7)
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
c=0
for i in range(len(A)):
  c+=A[i]*(sum(A)-A[i]%MOD)
print(c//2%MOD)



Fixed submission:
N = int(input())
A = list(map(int, input().split()))
c=0
d=sum(A)
for i in range(0,N-1):
    d-=A[i]
    c+=A[i]*d
    if(c>10**9+7):
        c%=(10**9+7)
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
c=0
for i in range(len(A)):
  c+=A[i]*(sum(A)-A[i])
print(c//2%MOD)



Fixed submission:
N = int(input())
A = list(map(int, input().split()))
c=0
d=sum(A)
for i in range(0,N-1):
    d-=A[i]
    c+=A[i]*d
    if(c>10**9+7):
        c%=(10**9+7)
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
MOD=1000000007
c=0
import itertools
a=list(itertools.combinations(A,2))
for i in range(len(a)):
  c+=(a[i][0]*a[i][1])
  c%=MOD
print(c)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
c=0
d=sum(A)
for i in range(0,N-1):
    d-=A[i]
    c+=A[i]*d
    if(c>10**9+7):
        c%=(10**9+7)
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
MOD=1000000007
c=0
import itertools
a=list(itertools.combinations(A,2))
for i in range(len(a)):
  c+=(a[i][0]*a[i][1])%MOD
e=c//MOD
print(c-e*MOD)
  
       

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
c=0
d=sum(A)
for i in range(0,N-1):
    d-=A[i]
    c+=A[i]*d
    if(c>10**9+7):
        c%=(10**9+7)
print(c)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
c=0
for i in range(len(A)):
  c+=A[i]*(pow(sum(A)-A[i],-1,MOD)
print(c//2%MOD)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
c=0
for i in range(N-1):
  j=i+1
  if A[j]<A[j-1]:
    gap=A[j-1]-A[j]
    c+=gap
    A[j]+=gap
    
print(c)
Buggy python submission (verdict: Runtime Error):
H,W,K=map(int,input().split())
c=[list(input()) for i in range(H)]
b=0
for i in range(H):
  b+=c[i].count('#')
if b==K:
  print(1)
  exit()
  
else:
  a=K-b
  count=0
  hc=[]
  wc=[]
  for i in range(2 ** H):
    h=['0']*H 
    for j in range(H):
        if ((i >> j) & 1):
            h[H- 1 - j] = '1'
    hc.append(h)
  for i in range(2 ** W):
    w=['0']*W
    for j in range(W):
        if ((i >> j) & 1):
            w[W- 1 - j] = '1'
    wc.append(w)
  
  for k in range(len(hc)):
    for l in range(len(wc)):
      c1=list(c)
      for m in range(H):
        if hc[k][m]=='0':
          c1[m]='.'
        for n in range(W):
          if wc[l][n]=='0' and c1[m][n]=='#':
                c1[m][n]=c1[m][n].replace('#','.')
      for i in range(H):
        b+=c1[i].count('#')
        print(c1)
      if b==a:
        count+=1
        
print(count)
    
            
  

Fixed submission:
import collections

N=int(input())
A=list(map(int, input().split()))
Q=int(input())
countA=collections.Counter(A)
ans=sum(A)

for i in range(Q):
    B,C=map(int, input().split())
    b=countA[B]
    ans=ans+(C-B)*b
    print(ans)
    countA[B]=0
    countA[C]+=b
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
H=list(map(int,input().split()))
c=[]
d=[]
e=[]
f=[]

for i in range(M):
  A,B=map(int,input().split())
  d.append(A)
  d.append(B)
  if H[A-1]>H[B-1]:
    c.append(A)
    e.append(B)
  elif H[B-1]>H[A-1]:
    c.append(B)
    e.append(A)

for k in range(1,N+1):
  if (k in c) and (k not in e):
    f.append(k)
    

for j in range(1,N+1):
  if j not in d:
    f.append(j)
    

    
print(len(f))




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

g = []
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] == H[b-1]:
        g += [a, b]
    if H[a-1] > H[b-1]:
        g += [b]
    else:
        g += [a]

g = set(g)
r = N - len(g)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[]
for i in range(N):
  s=input()
  if s not in S:
    S.append(s)
print(len(S))
  

Fixed submission:
N=int(input())
S=[]
for i in range(N):
  S.append(input())
print(len(set(S)))