Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
water = np.array(list(map(int, input().split())))
A = np.zeros((N, N))
for i in range(N):
    if i == N-1:
        A[N-1][0] = 1
        A[N-1][N-1] = 1
    else:
        A[i][i] = 1
        A[i][i+1] = 1
D = np.linalg.solve(A, water)
d = [0]*N
for i in range(N):
    d[i] = int(D[i])
print(" ".join([str(2*n) for n in d]))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
rain = [0]
r0 = 0
for i in range(N):
    r0 += A[i] * (-1)**i
rain[0] = r0
for i in range(1, N):
    rain.append(2 * A[i-1] - rain[i-1])
print(" ".join([str(n) for n in rain]))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
water = np.array(list(map(int, input().split())))
A = np.zeros((N, N))
for i in range(N):
    if i == N-1:
        A[N-1][0] = 1
        A[N-1][N-1] = 1
    else:
        A[i][i] = 1
        A[i][i+1] = 1
D = np.linalg.solve(A, water)
d = [0]*N
for i in range(N):
    d[i] = int(D[i])
print(" ".join([str(2*n) for n in d]))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
rain = [0]
r0 = 0
for i in range(N):
    r0 += A[i] * (-1)**i
rain[0] = r0
for i in range(1, N):
    rain.append(2 * A[i-1] - rain[i-1])
print(" ".join([str(n) for n in rain]))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
INF = 10**9 + 7
def powmod(a, n, mod):
    p = 1
    while n > 0:
        if n % 2 == 0:
            a = a**2 % mod
            n /= 2
        else:
            p *= a
            p %= mod
            n -= 1
    return p

def invmod(a, mod):
    return powmod(a, mod-2, mod)

inv = []
for i in range(2002):
    inv.append(invmod(i, INF))

def combmod(n, k, mod):
    bunsi = 1
    bunbo = 1
    for i in range(1, n+1):
        bunsi *= i
    for i in range(1, k+1):
        bunbo *= inv[i]
    for i in range(1, n - k + 1):
        bunbo *= inv[i]
    return bunsi * bunbo % mod

for i in range(1, K+1):
    print((combmod(K-1, i-1, INF) * combmod(N-K+1, i, INF))%mod)

Fixed submission:
N, K = map(int, input().split())
INF = 10**9 + 7
def powmod(a, n, mod):
    p = 1
    while n > 0:
        if n % 2 == 0:
            a = a**2 % mod
            n /= 2
        else:
            p *= a
            p %= mod
            n -= 1
    return p

def invmod(a, mod):
    return powmod(a, mod-2, mod)

fac = [1] * 2002
inv = [1] * 2002
for i in range(2002):
    if i == 0:
        fac[i] = 1
        inv[i] = 1
    else:
        fac[i] = fac[i-1] * i % INF
        inv[i] = inv[i-1] * invmod(i, INF) % INF


def combmod(n, k, mod):
    if n < k : return 0
    else:
        bunsi = fac[n]
        bunbo = inv[k] * inv[n-k]
        return bunsi * bunbo % mod

for i in range(1, K+1):
    print((combmod(K-1, i-1, INF) * combmod(N-K+1, i, INF))%INF)
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
flag = 1 if x == W/2 and y == H/2 else 0
print(f"{W*H/2} {flag}")

Fixed submission:
W, H, x, y = map(int, input().split())
flag = 1 if x == W/2 and y == H/2 else 0
print("{0} {1}".format(W*H/2, flag))
Buggy python submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import bisect

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    W = NLI()
    cum = []
    cum.append(W[0])
    for i in range(1, len(W)):
        cum.append(cum[-1] + W[i])
    total = cum[-1]
    idx = bisect.bisect_left(cum, total/2)
    idx_r = bisect.bisect_right(cum, total / 2)
    print(min(abs(total-cum[idx]*2), abs(total-cum[idx_r+1]*2)))


if __name__ == "__main__":
    main()

Fixed submission:
import sys
import math
from collections import deque
import bisect

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    W = NLI()
    cum = []
    cum.append(W[0])
    for i in range(1, N):
        cum.append(cum[-1] + W[i])
    total = cum[-1]
    idx = 0
    for i in range(N):
        if cum[i] <= total / 2:
            idx = i
        else:
            idx_r = i
            break
    print(min(abs(total - cum[idx]*2) ,abs(total - cum[idx_r]*2)))




if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, M = map(int, input().split())
*A, = map(int, input().split())
BC = [list(map(int, input().split())) for _ in range(M)]
hq = []
for i in range(N):
    heapq.heappush(hq, A[i])

for bc in BC:
    for i in range(bc[0]):
        tmp = heapq.heappop(hq)
        if tmp < bc[1]:
            heapq.heappush(hq, bc[1])
        else:
            heapq.heappush(hq, tmp)

print(sum(hq))

Fixed submission:
import heapq
N, M = map(int, input().split())
*A, = map(int, input().split())
BC = [list(map(int, input().split())) for _ in range(M)]
BC = list(reversed(sorted(BC, key=lambda x:x[1])))
#print(BC)
hq = []
for i in range(N):
    heapq.heappush(hq, A[i])

flag = False
for bc in BC:
    for i in range(bc[0]):
        tmp = heapq.heappop(hq)
        if tmp < bc[1]:
            heapq.heappush(hq, bc[1])
        else:
            heapq.heappush(hq, tmp)
            flag = True
            break
    if flag:
        break

print(sum(hq))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, M = map(int, input().split())
*A, = map(int, input().split())
BC = [list(map(int, input().split())) for _ in range(M)]
hq = []
for i in range(N):
    heapq.heappush(hq, A[i])

for bc in BC:
    for i in range(bc[0]):
        tmp = heapq.heappop(hq)
        if tmp < bc[1]:
            heapq.heappush(hq, bc[1])
        else:
            heapq.heappush(hq, tmp)

print(sum(hq))

Fixed submission:
import heapq
N, M = map(int, input().split())
*A, = map(int, input().split())
BC = [list(map(int, input().split())) for _ in range(M)]
BC = list(reversed(sorted(BC, key=lambda x:x[1])))
#print(BC)
hq = []
for i in range(N):
    heapq.heappush(hq, A[i])

flag = False
for bc in BC:
    for i in range(bc[0]):
        tmp = heapq.heappop(hq)
        if tmp < bc[1]:
            heapq.heappush(hq, bc[1])
        else:
            heapq.heappush(hq, tmp)
            flag = True
            break
    if flag:
        break

print(sum(hq))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N, M = map(int, input().split())
*A, = map(int, input().split())
BC = [list(map(int, input().split())) for _ in range(M)]

for bc in BC:
    A = sorted(A)
    border = bisect.bisect_left(A, bc[1])
    A = [bc[1]] * min(bc[0], border) + A[min(bc[0], border):]
    #print(A)

print(sum(A))

Fixed submission:
import heapq
N, M = map(int, input().split())
*A, = map(int, input().split())
BC = [list(map(int, input().split())) for _ in range(M)]
BC = list(reversed(sorted(BC, key=lambda x:x[1])))
#print(BC)
hq = []
for i in range(N):
    heapq.heappush(hq, A[i])

flag = False
for bc in BC:
    for i in range(bc[0]):
        tmp = heapq.heappop(hq)
        if tmp < bc[1]:
            heapq.heappush(hq, bc[1])
        else:
            heapq.heappush(hq, tmp)
            flag = True
            break
    if flag:
        break

print(sum(hq))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
S[K-1] = S[K-1].lower()
print(S)

Fixed submission:
N, K = map(int, input().split())
S = input()
print(S[0:K-1] + S[K-1].lower() + S[K:])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
S[K] = str.lower(S[k])
print(S)

Fixed submission:
N, K = map(int, input().split())
S = input()
print(S[0:K-1] + S[K-1].lower() + S[K:])
Buggy python submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    H, W = NMI()
    grid = [SI() for _ in range(H)]
    step = [[-1]*W for _ in range(H)]
    que = deque()
    for h in range(H):
        for w in range(W):
            p = grid[h][w]
            if p == "#":
                que.append((h, w))
                step[h][w] = 0
    DIR = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    while que:
        x, y = que.popleft()

        for dx, dy in DIR:
            if not(0 <= x+dx < H and 0 <= y+dy < W):
                continue
            if step[x+dx][y+dy] >= 0:
                continue
            que.append((x+dx, y+dy))
            step[x+dx][y+dy] = step[x][y] + 1

    print(max(map(max, *step)))



if __name__ == "__main__":
    main()

Fixed submission:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    H, W = NMI()
    grid = [SI() for _ in range(H)]
    step = [[-1]*W for _ in range(H)]
    que = deque()
    for h in range(H):
        for w in range(W):
            p = grid[h][w]
            if p == "#":
                que.append((h, w))
                step[h][w] = 0
    DIR = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    while que:
        x, y = que.popleft()

        for dx, dy in DIR:
            if not(0 <= x+dx < H and 0 <= y+dy < W):
                continue
            if step[x+dx][y+dy] >= 0:
                continue
            que.append((x+dx, y+dy))
            step[x+dx][y+dy] = step[x][y] + 1

    print(max([max(s) for s in step]))



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N+1):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

for l, r in LR:
    print(dp[r-1] - dp[l-1])


Fixed submission:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

for l, r in LR:
    print(dp[r-1] - dp[l-1])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N+1):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

for l, r in LR:
    print(dp[r-1] - dp[l-1])

Fixed submission:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

for l, r in LR:
    print(dp[r-1] - dp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
cum = []
for i in range(N+1):
    cum.append(S[:i].count('AC'))
for l, r in LR:
    print(cum[r] - cum[l])

Fixed submission:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

for l, r in LR:
    print(dp[r-1] - dp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
cum = []
for i in range(N+1):
    cum.append(S[:i].count('AC'))
for l, r in LR:
    print(cum[r] - cum[l])

Fixed submission:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

for l, r in LR:
    print(dp[r-1] - dp[l-1])
Buggy python submission (verdict: Runtime Error):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, M = NMI()
    A = NLI()

    match_dict = {i+1: m for i, m in enumerate([2,5,5,4,5,6,3,7,6])}
    usable_list = [[a, match_dict[a]] for a in A]
    usable_list.sort(key=lambda x: (x[1], -x[0]))

    ans = []
    def dfs(now_num, n):
        if n == 0:
            now = list(str(now_num))
            now.sort(reverse=True)
            ans.append(int("".join(now)))

        for num, m in usable_list:
            if n < m:
                break
            dfs(now_num*10+num, n-m)
            if n > 20:
                break

    dfs(0, N)
    print(max(ans))


if __name__ == "__main__":
    main()

Fixed submission:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, M = NMI()
    A = NLI()

    match_dict = {i+1: m for i, m in enumerate([2,5,5,4,5,6,3,7,6])}
    usable_list = [[a, match_dict[a]] for a in A]
    usable_list.sort(key=lambda x: (x[1], -x[0]))

    # dp[i] はi本使った時の最大数
    dp = [-1]*(N+10)
    dp[0] = 0

    for i in range(N+1):
        for num, m in usable_list:
            dp[i+m] = max(dp[i+m], dp[i]*10+num)
    print(dp[N])



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [input() for _ in range(H)]
seen = [[0]*W for _ in range(H)]


def rec(h,w,seen):
	if S[h][w] == '.':
		res = [1, 0]
	else:
		res = [0, 1]
	dh = [-1, 1, 0, 0]
	dw = [0, 0, -1, 1] 
	seen[h][w] = 1
	for i in range(4):
		nh = h+dh[i]
		nw = w+dw[i]
		if 0 <= nh <= H-1 and 0 <= nw <= W-1:
			if seen[nh][nw] == 0 and S[nh][nw] != S[h][w]:
				r0, r1 = rec(nh, nw, seen)
				res[0] += r0
				res[1] += r1
					
	return res

ans = 0
for h in range(H):
	for w in range(W):
		if seen[h][w] != 1:
			t0, t1 = rec(h, w, seen)
			ans += t0 * t1
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
H, W = map(int, input().split())
S = [input() for _ in range(H)]
seen = [[0]*W for _ in range(H)]


def rec(h,w,seen):
	if S[h][w] == '.':
		res = [1, 0]
	else:
		res = [0, 1]
	dh = [-1, 1, 0, 0]
	dw = [0, 0, -1, 1] 
	seen[h][w] = 1
	for i in range(4):
		nh = h+dh[i]
		nw = w+dw[i]
		if 0 <= nh <= H-1 and 0 <= nw <= W-1:
			if seen[nh][nw] == 0 and S[nh][nw] != S[h][w]:
				r0, r1 = rec(nh, nw, seen)
				res[0] += r0
				res[1] += r1
					
	return res

ans = 0
for h in range(H):
	for w in range(W):
		if seen[h][w] != 1:
			t0, t1 = rec(h, w, seen)
			ans += t0 * t1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))
dp = [0 for i in range(N+1)]

for i in range(2, N+1):
    kouho = []
    for k in range(1, min(i-1, K)+1):
        heapq.heappush(kouho, dp[i-k] + abs(h[i]-h[i-k]))
    dp[i] = heapq.heappop(kouho)
print(dp[N])

Fixed submission:
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))
dp = [0 for i in range(N+1)]

for i in range(2, N+1):
    kouho = []
    for k in range(1, min(i-1, K)+1):
        kouho.append(dp[i-k] + abs(h[i]-h[i-k]))
    dp[i] = min(kouho)
print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))
dp = [0 for i in range(N+1)]

for i in range(2, N+1):
    kouho = []
    for k in range(1, min(i-1, K)+1):
        kouho.append(dp[i-k] + abs(h[i]-h[i-k]))
    dp[i] = min(kouho)
print(dp[N])

Fixed submission:
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))
dp = [0 for i in range(N+1)]

for i in range(2, N+1):
    kouho = []
    for k in range(1, min(i-1, K)+1):
        kouho.append(dp[i-k] + abs(h[i]-h[i-k]))
    dp[i] = min(kouho)
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
goods = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0 for i in range(W+1)] for j in range(N+1)]
for i, item in enumerate(goods):
    i += 1
    for w in range(1, W+1):
        if w < item[0]:
            dp[i][w] = dp[i-1][w]
        else:
            dp[i][w] = max(dp[i-1][w], dp[i-1][w-item[0]] + item[1])

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
goods = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0 for i in range(W+1)] for j in range(N+1)]
for i, item in enumerate(goods):
    i += 1
    for w in range(1, W+1):
        if w < item[0]:
            dp[i][w] = dp[i-1][w]
        else:
            dp[i][w] = max(dp[i-1][w], dp[i-1][w-item[0]] + item[1])

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
goods = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0 for i in range(W+1)] for j in range(N+1)]
for i, item in enumerate(goods):
    i += 1
    for w in range(1, W+1):
        if w < item[0]:
            dp[i][w] = dp[i-1][w]
        else:
            dp[i][w] = max(dp[i-1][w], dp[i-1][w-item[0]] + item[1])

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
INF = 10**12
goods = [tuple(map(int, input().split())) for _ in range(N)]
total_val = 0
for item in goods:
    total_val += item[1]
dp = [[INF for i in range(total_val+1)] for j in range(N+1)]
dp[0][0] = 0
for i, item in enumerate(goods):
    i += 1
    for v in range(total_val+1):
        if v < item[1]:
            dp[i][v] = dp[i-1][v]
        else:
            dp[i][v] = min(dp[i-1][v], dp[i-1][v-item[1]] + item[0])

for i in range(total_val+1):
    if dp[N][i] <= W:
        ans = i
print(ans)
Buggy python submission (verdict: Runtime Error):
node_num, path_num = map(int, input().split())
graph = [[] for _ in range(node_num)]

for i in range(path_num):
    from_node, to_node = map(int, input().split())
    graph[from_node - 1].append(to_node - 1)
#print(graph)

#dp[i]はiを始点としたときの経路長の最大値
dp = [-1] * node_num

def rec(v):
    #print(v)
    #print(dp)
    if dp[v] > -1:
        return dp[v]
    else:
        dp[v] = 0
        for nv in graph[v]:
            dp[v] = max(dp[v], rec(nv) + 1)
        return dp[v]

ans = 0
for node in range(node_num):
    ans = max(ans, rec(node))
print(ans)

Fixed submission:
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = sys.stdin.readline

node_num, path_num = map(int, input().split())
graph = [[] for _ in range(node_num)]

for i in range(path_num):
    from_node, to_node = map(int, input().split())
    graph[from_node - 1].append(to_node - 1)
#print(graph)

#dp[i]はiを始点としたときの経路長の最大値
dp = [-1] * node_num

def rec(v):
    #print(v)
    #print(dp)
    if dp[v] > -1:
        return dp[v]
    else:
        dp[v] = 0
        for nv in graph[v]:
            dp[v] = max(dp[v], rec(nv) + 1)
        return dp[v]

ans = 0
for node in range(node_num):
    ans = max(ans, rec(node))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
p = list(map(float, input().split()))

#dp[i][j]は最初のi枚まで投げてj枚表になる確率
#初期化
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
#初期条件 0枚投げたとき0枚表→1
dp[0][0] = 1

for i in range(N):
    for j in range(N):
        dp[i+1][j] += dp[i][j] * (1 - p[i])
        dp[i+1][j+1] += dp[i][j] * p[i]

#i == N で j >= (N+1)/2 のものを足し合わせる
ans = 0
for j in range((N+1)//2, N+1):
    ans += dp[N][j]
print(ans)

Fixed submission:
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
p = list(map(float, input().split()))

#dp[i][j]は最初のi枚まで投げてj枚表になる確率
#初期化
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
#初期条件 0枚投げたとき0枚表→1
dp[0][0] = 1

for i in range(N):
    for j in range(N):
        dp[i+1][j] += dp[i][j] * (1 - p[i])
        dp[i+1][j+1] += dp[i][j] * p[i]

#i == N で j >= (N+1)/2 のものを足し合わせる
ans = 0
for j in range((N+1)//2, N+1):
    ans += dp[N][j]
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# Nの素因数分解を辞書で返す
def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def combination_mod_initialize(n, MOD=10**9+7):
    fac = [1]*(n+1)
    inv = [1]*(n+1)
    for i in range(1, n+1):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = inv[i-1] * pow(i, -1, MOD) % MOD
    return fac, inv

# 二項係数　高速
def combination_mod(n, r, fac, inv, mod=10**9+7):
    return fac[n] * inv[r] * inv[n-r]


def main():
    N, M = NMI()
    PD = prime_fact(M)
    ans = 1
    fac, inv = combination_mod_initialize(10**6, MOD)

    for x in list(PD.values()):
        ans = ans * combination_mod(N+x-1, N-1, fac, inv) % MOD

    print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# Nの素因数分解を辞書で返す
def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def combination_mod_initialize(n, MOD=10**9+7):
    fac = [1]*(n+1)
    inv = [1]*(n+1)
    for i in range(1, n+1):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = inv[i-1] * pow(i, -1, MOD) % MOD
    return fac, inv

# 二項係数　高速
def combination_mod(n, r, fac, inv, mod=10**9+7):
    return fac[n] * inv[r] * inv[n-r]


def main():
    N, M = NMI()
    PD = prime_fact(M)
    ans = 1
    fac, inv = combination_mod_initialize(10**6, MOD)

    for x in list(PD.values()):
        ans = ans * combination_mod(N+x-1, N-1, fac, inv) % MOD

    print(ans)



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
x1 = int(input())
y1 = int(input())
x2 = int(input())
y2 = int(input())
v1x = x2 - x1
v1y = y2 - y1

v2x = -v1y
v2y = v1x
v3x = -v2y
v3y = v2x
x3 = x2 + v2x
y3 = y2 + v2y
x4 = x3 + v3x
y4 = y3 + v3y
print(x3, " ", y3, " ", x4, " ", y4)

Fixed submission:
x1, y1, x2, y2 = map(int, input().split())
v1x = x2 - x1
v1y = y2 - y1

v2x = -v1y
v2y = v1x
v3x = -v2y
v3y = v2x
x3 = x2 + v2x
y3 = y2 + v2y
x4 = x3 + v3x
y4 = y3 + v3y
print(x3, y3, x4, y4)