Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int,input().split())
sh, sw = map(int,input().split())
gh, gw = map(int,input().split())
sh, sw, gh, gw = sh-1, sw-1, gh-1, gw-1
S = [input() for _ in range(H)]

INF = 10**9
ans = [[INF] * W for _ in range(H)]
ans[sh][sw] = 0

Q = deque([[sh,sw]])

while len(Q) > 0:
    h, w = Q.popleft()
    
    for nh, nw in [[h,w+1],[h,w-1],[h+1,w],[h-1,w]]:
        if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w]:
            ans[nh][nw] = ans[h][w]
            Q.append([nh, nw])

    for nh in range(h-2,h+3):
        for nw in range(w-2,w+3):
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w] + 1:
                ans[nh][nw] = ans[h][w] + 1
                Q.append([nh,nw])

if ans[gh][gw] == INF:
    print(-1)
else:
    print(ans[gh][gw])

Fixed submission:
from collections import deque

H, W = map(int,input().split())
sh, sw = map(int,input().split())
gh, gw = map(int,input().split())
sh, sw, gh, gw = sh-1, sw-1, gh-1, gw-1
S = [input() for _ in range(H)]

INF = 10**9
ans = [[INF] * W for _ in range(H)]
ans[sh][sw] = 0

Q = deque([[sh,sw]])
while Q:
    h, w = Q.popleft()

    for nh, nw in [[h,w+1],[h,w-1],[h+1,w],[h-1,w]]:
        if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w]:
            ans[nh][nw] = ans[h][w]
            Q.appendleft([nh, nw])

    for nh in range(h-2,h+3):
        for nw in range(w-2,w+3):
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w] + 1:
                ans[nh][nw] = ans[h][w] + 1
                Q.append([nh,nw])

if ans[gh][gw] == INF:
    print(-1)
else:
    print(ans[gh][gw])
Buggy python submission (verdict: Runtime Error):
import bisect

H, W, M = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(M)]
hw.sort()

rows, columns = [0]*H, [0]*W
for h, w in hw:
    rows[h-1] += 1
    columns[w-1] += 1
max_r, max_c = max(rows), max(columns)

argmax_r, argmax_c = [], []
for i in range(H):
    if max_r == rows[i]:
        argmax_r.append(i)

for i in range(W):
    if max_c == columns[i]:
        argmax_c.append(i)

for r in argmax_r:
    for c in argmax_c:
        idx = bisect.bisect_left(hw, [r+1, c+1])
        if hw[idx] != [r+1,c+1]:
            print(max_r + max_c)
            exit()

print(max_r + max_c - 1)

Fixed submission:
import bisect

H, W, M = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(M)]
hw.sort()

rows, columns = [0]*H, [0]*W
for h, w in hw:
    rows[h-1] += 1
    columns[w-1] += 1
max_r, max_c = max(rows), max(columns)

argmax_r, argmax_c = [], []
for i in range(H):
    if max_r == rows[i]:
        argmax_r.append(i)

for i in range(W):
    if max_c == columns[i]:
        argmax_c.append(i)

for r in argmax_r:
    for c in argmax_c:
        idx = bisect.bisect_left(hw, [r+1, c+1])
        if idx == M or hw[idx] != [r+1,c+1]:
            print(max_r + max_c)
            exit()

print(max_r + max_c - 1)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(M)]

rows, columns = [0]*H, [0]*W
for h, w in hw:
    rows[h-1] += 1
    columns[w-1] += 1
max_r, max_c = max(rows), max(columns)

argmax_r, argmax_c = [], []
for i in range(H):
    if max_r == rows[i]:
        argmax_r.append(i)
for i in range(W):
    if max_c == columns[i]:
        argmax_c.append(i)

for r in argmax_r:
    for c in argmax_c:
        if [r+1,c+1] not in hw:
            print(max_r + max_c)
            exit()

print(max_r + max_c - 1)
    


Fixed submission:
import bisect

H, W, M = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(M)]
hw.sort()

rows, columns = [0]*H, [0]*W
for h, w in hw:
    rows[h-1] += 1
    columns[w-1] += 1
max_r, max_c = max(rows), max(columns)

argmax_r, argmax_c = [], []
for i in range(H):
    if max_r == rows[i]:
        argmax_r.append(i)

for i in range(W):
    if max_c == columns[i]:
        argmax_c.append(i)

for r in argmax_r:
    for c in argmax_c:
        idx = bisect.bisect_left(hw, [r+1, c+1])
        if idx == M or hw[idx] != [r+1,c+1]:
            print(max_r + max_c)
            exit()

print(max_r + max_c - 1)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

monsters = []
for i in range(N):
    X, H =map(int,input().split())
    monsters.append([X,H])

monsters = sorted(monsters)

id = 0
ans = 0

damage = [0 for i in range(N)]

while id < N:
    if id > 0: damage[id] += damage[id-1]
    nowX, nowH = monsters[id][0], monsters[id][1]
    nowH -= damage[id]

    if nowH > 0:
        damage[id] += A * ((nowH + A - 1) // A)

        right = bisect.bisect_left(monsters, [nowX+2*D+1,0])
        if right < N:
            damage[right] -= A * ((nowH + A - 1) // A)

        ans += (nowH + A -1) // A

    id += 1

print(ans)

Fixed submission:
import bisect

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

monsters = []
for i in range(N):
    X, H =map(int,input().split())
    monsters.append([X,H])

monsters = sorted(monsters)

id = 0
ans = 0

damage = [0 for i in range(N)]

while id < N:
    if id > 0: damage[id] += damage[id-1]
    nowX, nowH = monsters[id][0], monsters[id][1]
    nowH -= damage[id]

    if nowH > 0:
        damage[id] += A * ((nowH + A - 1) // A)

        right = bisect.bisect_left(monsters, [nowX+2*D+1,0])
        if right < N:
            damage[right] -= A * ((nowH + A - 1) // A)

        ans += (nowH + A -1) // A

    id += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
class Combination:
    def __init__(self, mod, max_n):
        self.MOD = mod
        self.MAX_N = max_n

        self.f = self.factorial(self.MAX_N)
        self.f_inv = [self.inv(x) for x in self.f]

    def inv(self,x):
        return pow(x, self.MOD-2, self.MOD)
    
    def factorial(self, n):
        res = [1]
        for i in range(1,n+1):
            res.append(res[-1] * i % self.MOD)
        return res
    
    def comb(self, n, r):
        return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD


X, Y = map(int,input().split())

if (X + Y) % 3 != 0:
    print(0)
    exit()

k, l = (2*Y-X)//3, (2*X-Y)//3
CB = Combination(10**9+7, k+l)
print(CB.comb(k+l,k))


Fixed submission:
class Combination:
    def __init__(self, mod, max_n):
        self.MOD = mod
        self.MAX_N = max_n

        self.f = self.factorial(self.MAX_N)
        self.f_inv = [self.inv(x) for x in self.f]

    def inv(self,x):
        return pow(x, self.MOD-2, self.MOD)
    
    def factorial(self, n):
        res = [1]
        for i in range(1,n+1):
            res.append(res[-1] * i % self.MOD)
        return res
    
    def comb(self, n, r):
        return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD


X, Y = map(int,input().split())
k, l = (2*Y-X)//3, (2*X-Y)//3

if (X + Y) % 3 != 0 or k < 0 or l < 0:
    print(0)
    exit()

CB = Combination(10**9+7, k+l)
print(CB.comb(k+l,k))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

N, Q = map(int,input().split())
G = [[] for _ in range(N)]
counter = [0] * N

for _ in range(N-1):
    a, b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

for _ in range(Q):
    p, x = map(int,input().split())
    counter[p-1] += x

seen = [False]*N

def dfs(v, seen, G, counter):
    seen[v] = True
    for u in G[v]:
        if not seen[u]:
            counter[u] += counter[v]
            dfs(u, seen, G, counter)

dfs(0, seen, G, counter)

for c in counter:
    print(c, end = " ")
print("")

Fixed submission:
import sys
sys.setrecursionlimit(10**5)

N, Q = map(int,input().split())
G = [[] for _ in range(N)]
counter = [0] * N

for _ in range(N-1):
    a, b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

for _ in range(Q):
    p, x = map(int,input().split())
    counter[p-1] += x

stack, seen = [0], [False]*N
while stack:
    v = stack.pop()
    seen[v] = True

    for u in G[v]:
        if not seen[u]:
            stack.append(u)
            counter[u] += counter[v]

for c in counter:
    print(c, end = " ")
print("")
Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7
N, K = map(int,input().split())

G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a, b = a-1, b-1

    G[a].append(b)
    G[b].append(a)

# 頂点nowを根とする部分木の色の塗り方 (parが親の時)
#   ただしnowはすでに塗られているとする
def dfs(now, par):
    if K < len(G[now]): return 0

    res = 1

    if par == -1:
        colors = K-1
        for i in range(len(G[now])):
            res *= colors-i
            res %= MOD
    else:
        colors = K-2
        for i in range(len(G[now])-1):
            res *= colors-i
            res %= MOD

    for c in G[now]:
        if c == par: continue
        
        res *= dfs(c, now)
        res %= MOD
    
    return res

print(K * dfs(0,-1) % MOD)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

MOD = 10**9 + 7
N, K = map(int,input().split())

G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a, b = a-1, b-1

    G[a].append(b)
    G[b].append(a)

# 頂点nowを根とする部分木の色の塗り方 (parが親の時)
#   ただしnowはすでに塗られているとする
def dfs(now, par):
    if K < len(G[now]): return 0

    res = 1

    if par == -1:
        colors = K-1
        for i in range(len(G[now])):
            res *= colors-i
            res %= MOD
    else:
        colors = K-2
        for i in range(len(G[now])-1):
            res *= colors-i
            res %= MOD

    for c in G[now]:
        if c == par: continue
        
        res *= dfs(c, now)
        res %= MOD
    
    return res

print(K * dfs(0,-1) % MOD)

Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7
N, K = map(int,input().split())

G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a, b = a-1, b-1

    G[a].append(b)
    G[b].append(a)

# 頂点nowを根とする部分木の色の塗り方 (parが親の時)
#   ただしnowはすでに塗られているとする
def dfs(now, par):
    if K < len(G[now]): return 0

    res = 1

    if par == -1:
        colors = K-1
        for i in range(len(G[now])):
            res *= colors-i
            res %= MOD
    else:
        colors = K-2
        for i in range(len(G[now])-1):
            res *= colors-i
            res %= MOD

    for c in G[now]:
        if c == par: continue
        
        res *= dfs(c, now)
        res %= MOD
    
    return res

print(K * dfs(0,-1) % MOD)


Fixed submission:
import sys
sys.setrecursionlimit(100000)

MOD = 10**9 + 7
N, K = map(int,input().split())

G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a, b = a-1, b-1

    G[a].append(b)
    G[b].append(a)

# 頂点nowを根とする部分木の色の塗り方 (parが親の時)
#   ただしnowはすでに塗られているとする
def dfs(now, par):
    if K < len(G[now]): return 0

    res = 1

    if par == -1:
        colors = K-1
        for i in range(len(G[now])):
            res *= colors-i
            res %= MOD
    else:
        colors = K-2
        for i in range(len(G[now])-1):
            res *= colors-i
            res %= MOD

    for c in G[now]:
        if c == par: continue
        
        res *= dfs(c, now)
        res %= MOD
    
    return res

print(K * dfs(0,-1) % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
MOD = 10**9 + 7

state= [] # 同じ状態とみなしてよいものの個数の配列
i = 1
while i <= N:
    if i*i <= N:
        state.append(1)
        i += 1
    else:
        j = N // i # iの後における最大の数
        state.append(N//j-i+1) 
        i = N//j + 1

L = len(state)
#print(state)

# dp[k][x] : 最後が状態xであるようなk個の整数を並べる場合の数
dp = [[0]*L for _ in range(K+1)]
dp[0][0] = 1

#dp[k+1][x] = sum_{y: xを後ろにおける状態} dp[k][y]
for k in range(K):
    cum_sum = [0] * (L+1)
    for y in range(L): 
        cum_sum[y+1] = (cum_sum[y] + dp[k][y]) % MOD

    for x in range(L):
        # xを後ろにおけるような最大の状態はL-x-1
        dp[k+1][x] += cum_sum[L-x]
        dp[k+1][x] *= state[x]
        dp[k+1][x] %= MOD

#print(dp)
print(sum(dp[K]) % MOD)

Fixed submission:
N, K = map(int,input().split())
MOD = 10**9 + 7

state= [] # 同じ状態とみなしてよいものの個数の配列
i = 1
while i <= N:
    if i*i <= N:
        state.append(1)
        i += 1
    else:
        j = N // i # iの後における最大の数
        state.append(N//j-i+1) 
        i = N//j + 1

L = len(state)
#print(state)

# dp[k][x] : 最後が状態xであるようなk個の整数を並べる場合の数
dp = [[0]*L for _ in range(K+1)]
dp[0][0] = 1

#dp[k+1][x] = sum_{y: xを後ろにおける状態} dp[k][y]
for k in range(K):
    cum_sum = [0] * (L+1)
    for y in range(L): 
        cum_sum[y+1] = (cum_sum[y] + dp[k][y]) % MOD

    for x in range(L):
        # xを後ろにおけるような最大の状態はL-x-1
        dp[k+1][x] += cum_sum[L-x]
        dp[k+1][x] *= state[x]
        dp[k+1][x] %= MOD

#print(dp)
print(sum(dp[K]) % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

MOD = 10**9 + 7

# dp[i+1][j+1] : S_iまで，T_jまでで作ることのできる共通部分列の数
dp = [[0] * 2010 for _ in range(2010)]
dp[0][0] = 1

for i in range(N+1):
    for j in range(M+1):
        if i > 0: dp[i][j] += dp[i-1][j]
        if j > 0: dp[i][j] += dp[i][j-1]
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1]
            if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
        dp[i][j] = (dp[i][j] + MOD) % MOD

print(dp[N][M])

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

MOD = 10**9 + 7

# dp[i+1][j+1] : S_iまで，T_jまでで作ることのできる共通部分列の数
dp = [[0] * 2010 for _ in range(2010)]
dp[0][0] = 1

for i in range(N+1):
    for j in range(M+1):
        if i > 0: dp[i][j] += dp[i-1][j]
        if j > 0: dp[i][j] += dp[i][j-1]
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1]
            if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
        dp[i][j] = (dp[i][j] + MOD) % MOD

print(dp[N][M])
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7

N, M = map(int,input().split())
A = []
for _ in range(M):
    a = int(input())
    A.append(a)

dp = [1] * (N+1)

if 1 in A: dp[1] = 0

for i in range(N-1):
    if i+2 in A:
        dp[i+2] = 0
    else:
        dp[i+2] = (dp[i] + dp[i+1]) % MOD
    
print(dp[N])

Fixed submission:
MOD = 10**9 + 7

N, M = map(int,input().split())
A = set()
for _ in range(M):
    A.add(int(input()))

dp = [1] * (N+1)

if 1 in A:
    dp[1] = 0

for i in range(N-1):
    if i+2 in A:
        dp[i+2] = 0
    else:
        dp[i+2] = (dp[i] + dp[i+1]) % MOD
    
print(dp[N])
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y: self.p[x] = y
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))

N, M = map(int,input().split())

UF = UnionFind(N)

for _ in range(M):
    X, Y, Z = map(int,input().split())
    X, Y = X-1, Y-1
    UF.unite(X,Y)

S = set()
for i in range(N):
    S.add(UF.root(i))

print(len(S))

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))
N, M = map(int,input().split())

UF = UnionFind(N)

for _ in range(M):
    X, Y, Z = map(int,input().split())
    X, Y = X-1, Y-1
    UF.unite(X,Y)

print(UF.components)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

U = 10**18
ret = 1

for x in A:
  ret *= x
  if ret > U:
    ret += 1
    
if ret > U:
  ret = -1

print(ret)

Fixed submission:
import sys

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

U = 10**18
ret = 1

for x in A:
  ret *= x
  if ret > U:
    ret = U+1
    
if ret > U:
  ret = -1

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

U = 1e18
ret = 1
for x in A:
  ret *= x
  if ret > U:
    ret += 1
if ret > U:
  ret = -1

print(ret)

Fixed submission:
import sys

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

U = 10**18
ret = 1

for x in A:
  ret *= x
  if ret > U:
    ret = U+1
    
if ret > U:
  ret = -1

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

def solve():
  ret = 1
  for x in A:
    ret *= x
    if ret > 1e18:
      ret += 1
  if ret > 1e18:
    ret = -1
  return ret

print(solve())

Fixed submission:
import sys

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

U = 10**18
ret = 1

for x in A:
  ret *= x
  if ret > U:
    ret = U+1
    
if ret > U:
  ret = -1

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

def solve():
  ret = 1
  for x in A:
    ret *= x
  if ret > 1e18:
      ret += 1
  if ret > 1e18:
    ret = -1
  return ret

print(solve())

Fixed submission:
import sys

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

U = 10**18
ret = 1

for x in A:
  ret *= x
  if ret > U:
    ret = U+1
    
if ret > U:
  ret = -1

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

def solve():
  ret = 1
  for i in range(N):
    ret *= A[i]
  if ret > 1e18:
      ret = -1
  return ret

print(solve())

Fixed submission:
import sys

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

U = 10**18
ret = 1

for x in A:
  ret *= x
  if ret > U:
    ret = U+1
    
if ret > U:
  ret = -1

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

def solve():
  ret = 1
  for i in range(N):
    ret *= A[i]
  if ret > 1e18:
      ret = -1
  return ret

print(solve())

Fixed submission:
import sys

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

U = 10**18
ret = 1

for x in A:
  ret *= x
  if ret > U:
    ret = U+1
    
if ret > U:
  ret = -1

print(ret)
Buggy python submission (verdict: Runtime Error):
N=input()
if N%9 == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
N=int(input())
if N%9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k,q = map(int,input().split())
num_array = np.ones(n) * k
for i in range(q):
    num_array -= 1
    num_array[int(input())-1] +=1
for i in num_array:
    if i > 0:
        print('Yes')
    else:
        print('No')

Fixed submission:
n,k,q = map(int,input().split())
count_dict = {s: 0 for s in range(1,n+1)}
for i in range(q):
    seikaisha = int(input())
    if seikaisha in count_dict:
        count_dict[seikaisha] +=1
    else:
        count_dict[seikaisha] = 0
count_dict_sorted = sorted(count_dict.items(), key=lambda x:x[0])
# print(type(count_dict_sorted))
# print(count_dict_sorted)
for i, j in count_dict_sorted:
    if k + j-q >0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
count_dict = {}
s = [''.join(sorted(input())) for i in range(N)]
for word in s:
    if word in list(count_dict.keys()):
        count_dict[word] +=1
    else:
        count_dict[word] = 1
result = sum([i *(i-1)/2 for i in count_dict.values()])
print(int(result))

Fixed submission:
N = int(input())
d = dict()
for i in range(N):
    S = input()
    S = ''.join(sorted(list(S)))
    if S in d.keys():
        d[S] += 1
    else:
        d[S] = 1

ans = 0
for n in d.values():
    ans += n*(n-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
for n in range(1,N+1):
    if len(str(n)) % 2 == 1:
    ans += 1
print(ans)

Fixed submission:
N = int(input())
ans = 0
for n in range(1,N+1):
    if len(str(n)) % 2 == 1:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]
for j in range(N):
    B = A[:j] + A[j+1:]
    print(max(B))

Fixed submission:
N=int(input())
A=[int(input()) for _ in range(N)]
B=sorted(A)[:N-1]
m=max(A)
n=A.index(max(A))
for i in range(N):
    if  i!=n:
        print(m)
    else:
        print(max(B))
Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
result = 2020
R = min(R,L+4038)
for i in range(L,R):
    for j in range(L+1,R+1):
        result = min(result,i*j%2019)
print(result)

Fixed submission:
L,R = map(int,input().split())
result = 2018
if R - L >= 2019:
    result = 0
else:
    for i in range(L,R):
        for j in range(L+1,R+1):
            result = min(result,i*j%2019)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
result = 1e9
R = min(R,L+4038)
for i in range(L,R):
    for j in range(L+1,R+1):
        result = min(result,i*j%2019)
print(result)

Fixed submission:
L,R = map(int,input().split())
result = 2018
if R - L >= 2019:
    result = 0
else:
    for i in range(L,R):
        for j in range(L+1,R+1):
            result = min(result,i*j%2019)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
result = 1e9
for i in range(L,R):
    for j in range(L+1,R+1):
        result = min(result,i*j%2019)
print(result)

Fixed submission:
L,R = map(int,input().split())
result = 2018
if R - L >= 2019:
    result = 0
else:
    for i in range(L,R):
        for j in range(L+1,R+1):
            result = min(result,i*j%2019)
print(result)
Buggy python submission (verdict: Runtime Error):
import pandas as pd
import numpy as np
N = int(input())
df = pd.DataFrame(index = range(1,N+1),columns =['name','score'])
for i in range(N):
    name,score = input().split()
    df['name'].iloc[i] = name
    df['score'].iloc[i] = score
for i in df.sort_values(['name','score'],ascending = [True,False]).index:
    print(i)

Fixed submission:
N = int(input())
 
city = []
for i in range(N):
    s, p = input().split()
    city.append([s, int(p), i+1])
city.sort(key=lambda city: (city[0], -city[1]))
 
for i in city:
    print(i[2])
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
result = 0
for i in range(1,N+1):
    prob = 1
    count = i 
    while count < K:
        prob *= 0.5
        count *= 2
    result += prob /N
print(result)

Fixed submission:
N,K = map(int,input().split())
result = 0
for i in range(1,N+1):
    prob = 1
    count = i 
    while count < K:
        prob *= 0.5
        count *= 2
    result += prob /N
print(result)
Buggy python submission (verdict: Runtime Error):
X,A,B = map(int,input().split())
print((X - A)%B)

Fixed submission:
x = int(input())
a = int(input())
b = int(input())
print((x-a)%b)

Buggy python submission (verdict: Runtime Error):
X,A,B = map(int,input().split())
print((X - A)%B)

Fixed submission:
x = int(input())
a = int(input())
b = int(input())
print((x-a)%b)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
count =1
for i in range(1,N+1):
    count *=i
print(count%(10**9+7))

Fixed submission:
n = int(input())
mod = 10**9+7
ans = 1
for i in range(1, n+1):
  ans *= i
  ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int,input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k ==S:
                count +=1
print(count)

Fixed submission:
K, S = map(int,input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        k = S - i - j
        if k >= 0 and k <=K:
                count +=1
print(count)