Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
sum_A = 0

for i in range(N-1):
    sum_A += A[i]*sum(A[i+1:N]) 
    sum_A %= 10**9+7
print(sum_A)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 0
sum_A = [0]*N
for j in range(N-1, 0, -1):
    sum_A[j] = A[j]+sum_A[(j+1) % N]
for i in range(N-1):
    ans += A[i]*sum_A[i+1]
    ans %= 10**9+7
print(ans)

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

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

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 0
sum_A = [0]*N
for j in range(N-1, 0, -1):
    sum_A[j] = A[j]+sum_A[(j+1) % N]
for i in range(N-1):
    ans += A[i]*sum_A[i+1]
    ans %= 10**9+7
print(ans)
Buggy python submission (verdict: Runtime Error):
X, K, D = map(int, input().split())
absX = abs(X)
k = absX//D
if k < K:
    abs_pos = abs(absX-k*D)
    K -= k
    if K % 2 == 0:
        print(int(absX/X * abs_pos))
    else:
        print(int(absX/X * abs(abs_pos - D)))
else:
    print(int(absX/X * (absX-D*K)))

Fixed submission:
X, K, D = map(int, input().split())
absX = abs(X)
k = absX//D
if k < K:
    abs_pos = absX-k*D
    K -= k
    if K % 2 == 0:
        print(int(abs_pos))
    else:
        print(int(abs(abs_pos - D)))
else:
    print(int(abs(absX-D*K)))

Buggy python submission (verdict: Runtime Error):
X, K, D = map(int, input().split())
absX = abs(X)
k = absX//D
if k < K:
    abs_pos = absX-k*D
    K -= k
    if K % 2 == 0:
        print(int(absX/X * abs_pos))
    else:
        print(int(absX/X * abs(abs_pos - D)))
else:
    print(int(absX/X * (absX-D*K)))

Fixed submission:
X, K, D = map(int, input().split())
absX = abs(X)
k = absX//D
if k < K:
    abs_pos = absX-k*D
    K -= k
    if K % 2 == 0:
        print(int(abs_pos))
    else:
        print(int(abs(abs_pos - D)))
else:
    print(int(abs(absX-D*K)))

Buggy python submission (verdict: Runtime Error):
X, K, D = map(int, input().split())
absX = abs(X)
k = absX//D
if k <= K:
    abs_pos = absX-k*D
    K -= k
    if K % 2 == 0:
        print(int(absX/X * abs_pos))
    else:
        print(int(absX/X * abs(abs_pos - D)))
else:
    print(int(absX/X * (absX-D*K)))

Fixed submission:
X, K, D = map(int, input().split())
absX = abs(X)
k = absX//D
if k < K:
    abs_pos = absX-k*D
    K -= k
    if K % 2 == 0:
        print(int(abs_pos))
    else:
        print(int(abs(abs_pos - D)))
else:
    print(int(abs(absX-D*K)))
Buggy python submission (verdict: Time Limit Exceeded):
N,K= map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -1000000000

for i in range(N):
    S = []
    j = P[i]-1
    S.append(C[j])

    while i != j:
        j = P[j]-1
        S.append(S[-1] + C[j])

    if K <= len(S):
        score = max(S[:K])

    elif S[-1] <= 0:
        score = max(S)
    
    else:
        score1 = K//len(S) * S[-1]
        r = K%len(S)
        if r != 0:
            score1 += max(0, max(S[:r]))
        score2 = (K//len(S)-1)*S[-1] + max(S)
        score = max(score1, score2)
    ans = max(ans, score)
print(ans)

Fixed submission:
N,K= map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -1000000000

for i in range(N):
    S = []
    j = P[i]-1
    S.append(C[j])

    while i != j:
        j = P[j]-1
        S.append(S[-1] + C[j])

    if K <= len(S):
        score = max(S[:K])

    elif S[-1] <= 0:
        score = max(S)
    
    else:
        score1 = K//len(S) * S[-1]
        r = K%len(S)
        if r != 0:
            score1 += max(0, max(S[:r]))
        score2 = (K//len(S)-1)*S[-1] + max(S)
        score = max(score1, score2)
    ans = max(ans, score)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1

for a in A:
    ans *= a
if ans > 10 ** 18:
        print(str(-1))
else:
    print(ans)

Fixed submission:
import sys

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

if A[0] == 0:
    print(0)
    sys.exit()

for a in A:
    ans *= a
    if ans > 10 ** 18:
        print(str(-1))
        break
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
import math
A, B, H, M = map(int, input().split())
a = math.pi/360 * (H*60 + M)
b = math.pi/30 * M
# if abs(a - b) > math.pi:
#     theta = 2 * math.pi - abs(a-b)
# else:
theta = abs(a-b)
L = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
print(L)

Fixed submission:
N = int(input())
hon_list = ["pon","pon","hon","bon","hon","hon","pon","hon","pon","hon",]
hon_dict = {}
for i in range(10):
    hon_dict[i] = hon_list[i]

print(hon_dict[N % 10])
Buggy python submission (verdict: Runtime Error):
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [0]*n
 
for i in range(m):
    a =list(map(int, input().split()))
    if high[a[0]-1] > high[a[1]-1]:
        if ans[a[0]-1] == 0:
            ans[a[0]-1] = 1
        ans[a[1]-1] = -1
    elif high[a[0]]-1 < high[a[1]-1]:
        if ans[a[1]-1] == 0:
            ans[a[1]-1] = 1
        ans[a[0]-1] = -1
    else:
        ans[a[1]-1] = -1
        ans[a[0]-1] = -1
print(ans.count(0) + ans.count(1))

Fixed submission:
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [1]*n

for i in range(m):
    a, b = map(int, input().split())
    if high[a-1] > high[b-1]:
        ans[b-1] = 0
    elif high[a-1] < high[b-1]:
        ans[a-1] = 0
    else:
        ans[a-1] = 0
        ans[b-1] = 0
print(sum(ans))

Buggy python submission (verdict: Runtime Error):
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [0]*n

for i in range(m):
    a =list(map(int, input().split()))
    if high[a[0]]-1 > high[a[1]-1]:
        if ans[a[0]-1] == 0:
            ans[a[0]-1] = 1
        ans[a[1]-1] = -1
    elif high[a[0]]-1 < high[a[1]-1]:
        if ans[a[1]-1] == 0:
            ans[a[1]-1] = 1
        ans[a[0]-1] = -1
    else:
        ans[a[1]-1] = -1
        ans[a[0]-1] = -1
print(ans.count(0) + ans.count(1))

Fixed submission:
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [1]*n

for i in range(m):
    a, b = map(int, input().split())
    if high[a-1] > high[b-1]:
        ans[b-1] = 0
    elif high[a-1] < high[b-1]:
        ans[a-1] = 0
    else:
        ans[a-1] = 0
        ans[b-1] = 0
print(sum(ans))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque

def main():
    H, W = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())
    ch -= 1
    cw -= 1
    dh -= 1
    dw -= 1
    maze = [input() for _ in range(H)]

    INF = 10**12
    path = [[INF] * W for _ in range(H)] # 各マスへの移動コスト
    
    # walk:移動A, warp:移動B
    walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

    q = deque()
    path[ch][cw] = 0
    q.append((ch, cw, 0))

    while q:
        x, y, s = q.popleft()
        for dx, dy in walk: #移動A
            nx = x + dx
            ny = y + dy
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == "." and path[nx][ny] > s:
                path[nx][ny] = s
                q.appendleft((nx, ny, s)) # なぜleft?

        for dx, dy in warp: #移動B
            nx = x + dx
            ny = y + dy
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == "." and path[nx][ny] > s + 1:
                path[nx][ny] = s + 1
                q.append((nx, ny, s+1)) # なぜright?

    ans = path[dh][dw] if path[dh][dw] != INF else "-1"
    print(ans)

if __name__ == "__main__":
    main()




Fixed submission:
N, X, T = map(int, input().split())

if N % X == 0:
    times = N // X
else:
    times = N // X + 1

print(times * T)
Buggy python submission (verdict: Runtime Error):
ws = input()
ans = 0
i = 0
r = 0
while i < 3:
  if ws[i] == "R":
  	r += 1
    ans = max(ans, r)
  else
	r = 0
  i += 1

print(ans)



Fixed submission:
ws = input()

i, r, ans = 0, 0, 0

while i < 3:
    if ws[i] == "R":
        r += 1
        ans = max(ans, r)
    else:
        r = 0
    i += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

# loopに入ったらおしまい
record = deque([X,])
finished = False
while K > 0:
    if X > 0:
        X -= D
    else:
        X += D
    record.append(X)
    if len(record) > 3:
        record.popleft()
    if record[0] == record[-1]:
        if K % 2 == 0:
            print(abs(record[1]))
        else:
            print(abs(record[0]))
        finished = True
        break
    K -= 1     

if not finished:
    print(abs(X))


Fixed submission:
from collections import deque

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

# まずは何回目で符号が逆転するかを算出
num_reverse = abs(X) // D + 1
if num_reverse > K:
    print(abs(X) - (K * D))
else:
    K -= num_reverse
    ans = abs(X) - (num_reverse * D)
    if K % 2 == 0:
        print(abs(ans))
    else:
        print(abs(abs(ans) - D))
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())

A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

# dp[i][j] = Aをi冊、Bをj冊読んだ時のcost、costがkを超えない範囲で i + jの最大値を求める
# dp[0][0] = 0

# dp = [[0] * (M+1) for _ in range(N+1)]

# どうやって増やしていけばいいんだ ??
# recursionかな
ans = 0
def recur(i, j, cost):
    global ans
    if cost > K:
        return
    ans = max(ans, i + j)
    # dp[i][j] = cost

    if i + 1 < len(A):
        recur(i+1, j, cost+A[i+1])
    if j + 1 < len(B):
        recur(i, j+1, cost+B[j+1])
    return

recur(0, 0, 0)
print(ans)


Fixed submission:
# 再帰は深くなりすぎる
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
accum_A, accum_B = [0] * (len(A)+1), [0] * (len(B)+1)
for i in range(len(A)):
    accum_A[i+1] = accum_A[i] + A[i]
for i in range(len(B)):
    accum_B[i+1] = accum_B[i] + B[i]

ans = 0
i, j = len(A), 0
while i >= 0 and j <= len(B) :
    if accum_A[i] + accum_B[j] > K:
        i -= 1
    else:
        ans = max(ans, i+j)
        j += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())

A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

# dp[i][j] = Aをi冊、Bをj冊読んだ時のcost、costがkを超えない範囲で i + jの最大値を求める
# dp[0][0] = 0

dp = [[0] * (M+1) for _ in range(N+1)]

# どうやって増やしていけばいいんだ ??
# recursionかな
ans = 0
def recur(i, j, cost):
    global ans
    if cost > K:
        return
    ans = max(ans, i + j)
    dp[i][j] = cost

    if i + 1 < len(A):
        recur(i+1, j, dp[i][j]+A[i+1])
    if j + 1 < len(B):
        recur(i, j+1, dp[i][j]+B[j+1])
    return

recur(0, 0, 0)
print(ans)


Fixed submission:
# 再帰は深くなりすぎる
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
accum_A, accum_B = [0] * (len(A)+1), [0] * (len(B)+1)
for i in range(len(A)):
    accum_A[i+1] = accum_A[i] + A[i]
for i in range(len(B)):
    accum_B[i+1] = accum_B[i] + B[i]

ans = 0
i, j = len(A), 0
while i >= 0 and j <= len(B) :
    if accum_A[i] + accum_B[j] > K:
        i -= 1
    else:
        ans = max(ans, i+j)
        j += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    A = [0] + A

    seen = {}
    cnt = 0
    dst = 1
    while K:
        if dst in seen:
            cycle = cnt - seen[dst]
            K %= cycle
            seen = {}
        else:
            seen[dst] = cnt

        dst = A[dst]
        cnt += 1
        K -= 1

    print(dst)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    A = [0] + A

    seen = {}
    find_cnt = {}
    cnt = 0
    dst = 1
    while K:
        if dst in seen:
            cycle = cnt - seen[dst]
            K %= cycle
            print(find_cnt[seen[dst]+K])
            return

        else:
            seen[dst] = cnt
            find_cnt[cnt] = dst

        dst = A[dst]
        cnt += 1
        K -= 1

    print(dst)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):

mod = 998244353

class COM:
    def __init__(self, n, MOD):
        self.n = n
        self.MOD = MOD
        self.fac = [0] * (n+1)
        self.finv = [0] * (n+1)
        self.inv = [0] * (n+1)
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, n+1):
            self.fac[i] = self.fac[i-1] * i % MOD
            self.inv[i] = MOD - self.inv[MOD % i] * (MOD // i) % MOD
            self.finv[i] = self.finv[i-1] * self.inv[i] % MOD

    def calc(self, k):
        if k < 0:
            return 0
        return self.fac[self.n] * (self.finv[k] * self.finv[self.n-k] % self.MOD) % self.MOD

def main():
    N, M, K = map(int,input().split())

    # 隣り合う組がK以下のパターンを総当たりして解く
    cmb = COM(N-1, mod)
    res = 0
    for i in range(K+1):
        res += M * cmb.calc(i) % mod * pow(M-1, N-i-1, mod)

    print(res % mod) 


if __name__ == "__main__":
    main()


Fixed submission:
# https://kmjp.hatenablog.jp/entry/2020/05/10/0900
# 数学的な問題


mod = 998244353

class COM:
    def __init__(self, n, MOD):
        self.n = n
        self.MOD = MOD
        self.fac = [0] * (n+1)
        self.finv = [0] * (n+1)
        self.inv = [0] * (n+1)
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, n+1):
            self.fac[i] = self.fac[i-1] * i % MOD
            self.inv[i] = MOD - self.inv[MOD % i] * (MOD // i) % MOD
            self.finv[i] = self.finv[i-1] * self.inv[i] % MOD

    def calc(self, k):
        if k < 0:
            return 0
        return self.fac[self.n] * (self.finv[k] * self.finv[self.n-k] % self.MOD) % self.MOD

def main():
    N, M, K = map(int,input().split())

    # 隣り合う組がK以下のパターンを総当たりして解く
    if N > 1:
        cmbclass = COM(N-1, mod)
        cmb = cmbclass.calc
    else:
        cmb = lambda x:1
    res = 0
    for i in range(K+1):
        res += M * cmb(i) % mod * pow(M-1, N-i-1, mod)


    print(res % mod) 


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):

H, W = list(map(int, input().split()))

maze = []
for _ in range(H):
    maze.append(list(input()))

def dfs(i, j, path):
    global ans
    if i == end[0] and j == end[1]:
        # print(path)
        ans = min(ans, path)
        return 

    for dx, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        x = i + dx
        y = j + dj
        if 0 <= x < H and 0 <= y < W and maze[x][y] == "." :
            if (x, y) not in seen:
                seen.add((x, y))
                dfs(x, y, path+1)
                seen.discard((x, y))   
    return

res = []
for i in range(H):
    for j in range(W):
        for k in range(H):
            for l in range(W):
                if maze[i][j] == "." and maze[k][j] == ".":
                    ans = float("inf")
                    seen = set()
                    seen.add((i, j))
                    end = (k, l)
                    dfs(i, j, 0)
                    if ans != float("inf"):
                        res.append(ans)
                    # res = max(res, ans if ans != float("inf") else 0)

print(max(res))


Fixed submission:
from collections import deque

H, W = list(map(int, input().split()))

maze = []
for _ in range(H):
    maze.append(list(input()))

#bfsならうまく解ける!!
def bfs(i, j):
    q = deque([(i, j, 0)])
    seen = set([(i, j)])
    ans = 0
    while q:
        i, j, d = q.popleft()
        ans = max(ans ,d)
        for dx, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            x = i + dx
            y = j + dj
            if 0 <= x < H and 0 <= y < W and maze[x][y] == "." :
                if (x, y) not in seen:
                    seen.add((x, y))
                    q.append((x, y, d + 1))           
    return ans


res = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            res = max(res, bfs(i, j))
print(res)
Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict

def main():
    #bfならどう解く？
    #O(n2)で解ける
    N = int(input())
    S = input()
    
    length = 1
    ans = 0
    while length<= N//2:
        seen = defaultdict(int)
        for start in range(length):
            for idx in range(start, N-length+1, length):
                sub = S[idx:idx+length]
                if sub in seen:
                    prev_idx = seen[sub]
                    if prev_idx + length <= idx:
                        ans = length
                        break
                else:
                    seen[sub] = idx
        length += 1
    
    print(ans)

if __name__ == "__main__":
    main()

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

    ans = 0
    dp = [[0] * (N+1) for _ in range(N+1)]
    for i in range(N-1, -1, -1):
        for j in range(N-1, i, -1):
            if S[i] == S[j]:
                dp[i][j] = dp[i+1][j+1] + 1
                tmp = min(dp[i][j], j-i)
                ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict

def main():
    #bfならどう解く？
    #O(n2)で解ける
    N = int(input())
    S = input()
    
    length = 1
    ans = 0
    while length<= N//2:
        seen = defaultdict(set)
        for start in range(length):
            for idx in range(start, N-length+1, length):
                sub = S[idx:idx+length]
                if sub in seen:
                    for prev_idx in seen[sub]:
                        if prev_idx + length <= idx:
                            ans = length
                            break
                seen[sub].add(idx)
        length += 1
    
    print(ans)

if __name__ == "__main__":
    main()


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

    ans = 0
    dp = [[0] * (N+1) for _ in range(N+1)]
    for i in range(N-1, -1, -1):
        for j in range(N-1, i, -1):
            if S[i] == S[j]:
                dp[i][j] = dp[i+1][j+1] + 1
                tmp = min(dp[i][j], j-i)
                ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
count = 0
for i in range(1,n):
	a = i
	b = 1
	while a*b < n:
		count+=1
		b+=1
print(count)

Fixed submission:
n = int(input())
count = 0
same = 0
for i in range(1,n):
	a = i
	b = i
	if a*b >= n:
		break
	same += 1
	while a*b < n:
		count+=1
		b+=1
print(count*2-same)
Buggy python submission (verdict: Time Limit Exceeded):
n,x,m = map(int,input().split())
#listを2つ使って初項からループ手前までのセット、そして二回目のループのセット。
k_1 = list()
k_2 = list()
#len(k_2)でも良かった
#loop_sumはk_2によって表されるループの和
loop_number = 0
loop_sum = 0
while x not in k_1:
	k_1.append(x)
	x = x*x%m
while x not in k_2:
	k_2.append(x)
	loop_number+=1
	loop_sum+=x 
	x = x*x%m
ans = 0
for i in range(len(k_1)):
	ans +=  k_1[i]
ans = ans + loop_sum * ((n-len(k_1))//loop_number)
for i in range((n-len(k_1))%loop_number):
	ans += k_2[i]
print(ans)

Fixed submission:
n,x,m = map(int,input().split())
k_1 = set()
k_2 = set()
tmp = list()
loop_number = 0
loop_sum = 0
while x not in k_1:
	k_1.add(x)
	x = x*x%m
while x not in k_2:
	k_2.add(x)
	tmp.append(x)
	loop_number+=1
	loop_sum+=x 
	x = x*x%m
ans = 0
k_1 = list(k_1)
for i in range(len(k_1)):
	ans +=  k_1[i]
ans = ans + loop_sum * ((n-len(k_1))//loop_number)
for i in range((n-len(k_1))%loop_number):
	ans += tmp[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
O = input()
E = input()
for i in range(len(O)):
	print(O[i],E[i],sep="",end="")
    

Fixed submission:
O = input()
E = input()
for i in range(min(len(O),len(E))):
	print(O[i],E[i],sep="",end="")
if len(O) > len(E):
	print(O[-1])
Buggy python submission (verdict: Runtime Error):
import math
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N = I()
L = LI()
count =0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      flag = 0
      l1 = [L[i],L[j],L[k]]
      l = sorted(l1)
      for n in range(3):
        if(l.count(l[i])>1):
          flag = 1
      if(flag == 0):
        if(l[1]-l[0] < l[2] and l[1]+l[0] > l[2]):
          count += 1
print(count)

Fixed submission:
import math
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N = I()
L = LI()
count =0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      flag = 0
      l1 = [L[i],L[j],L[k]]
      l = sorted(l1)
      for n in range(3):
        if(l.count(l[n])>1):
          flag = 1
      if(flag == 0):
        if(l[1]-l[0] < l[2] and l[1]+l[0] > l[2]):
          count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))

if(N%2 == 0):
  N = (N/2)
else:
  N = int(N/2)+1
count = 0
for i in range(1,N+1):
  if(a[(2*i-1)-1]%2 == 1):
    count += 1
print(count)

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

if(N%2 == 0):
  N = int(N/2)
else:
  N = int(N/2)+1
count = 0
for i in range(1,N+1):
  if(a[(2*i-1)-1]%2 == 1):
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
N = input()

s = int(N[len(N)-3])*100+int(N[len(N)-2])*10+int(N[len(N)-1])
if(s==0):
  print(0)
else: 
  print(1000-s)

Fixed submission:
N = input()
if(int(N)>=100):
  s = int(N[len(N)-3])*100+int(N[len(N)-2])*10+int(N[len(N)-1])
else:
  s = int(N)
if(s==0):
  print(0)
else: 
  print(1000-s)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

A = sorted(A, reverse=True)
sum = A[0]
temp=[]
temp.append(A[0])
temp.append(A[2])
for i in range(2,len(A)):
  temp.append(A[i])
  sum += temp[len(temp)-2]
print(sum)

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

A = sorted(A)
ans =0
for i in range(1,len(A)):
  ans += A[len(A) - 1 - i//2]
           
print(ans)
Buggy python submission (verdict: Runtime Error):
D=int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]

for i in range(D):
  print(i%26+1):

Fixed submission:
D=int(input())
#c = list(map(int,input().split()))
#s = [list(map(int,input().split())) for _ in range(D)]

for i in range(D):
  print(i%26+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
A.sort()
Q = int(input())


for _ in range(Q):
  b,c=map(int,input().split())
  time = A.count(b)
  if(time != 0):
    place = A.index(b)
    for i in range(time):
      A[place + i] = c
    A.sort()
  print(sum(A))

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

num = [0]*(10**5+1)

sum = sum(A)
for i in range(N):
  num[A[i]-1] += 1

for _ in range(Q):
  b,c=map(int,input().split())
  sum += (c-b)*num[b-1]
  num[c-1] += num[b-1]
  num[b-1] = 0
  
  print(sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A.sort()
Q = int(input())


for _ in range(Q):
  b,c=map(int,input().split())
  time = A.count(b)
  if(b != 0):
    place = A.index(b)
    for i in range(time):
      A[place + i] = c
    A.sort()
  print(sum(A))

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

num = [0]*(10**5+1)

sum = sum(A)
for i in range(N):
  num[A[i]-1] += 1

for _ in range(Q):
  b,c=map(int,input().split())
  sum += (c-b)*num[b-1]
  num[c-1] += num[b-1]
  num[b-1] = 0
  
  print(sum)