Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# 整数の入力
list = list(str(input())

flag = 0

for i in list:
    if i == "7":
        print("Yes")
        flag = 1
        break

if flag == 0:
    print("No")

Fixed submission:
list = list(str(input()))

YN_flag = 0

for i in list:
    if i == "7":
        print("Yes")
        YN_flag = 1
        break

if YN_flag == 0:
    print("No")
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
# コンテナの座標（西→東）
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

# 電波が届く最大の距離
k = int(input())

# 最大の距離(=e-e)
int max_dis = e -a
        
# 出力
if max_dis < k:
  print('Yay!')
else:
    print(':(')


Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
# コンテナの座標（西→東）
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

# 電波が届く最大の距離
k = int(input())

# 最大の距離(=e-a)
max_dis = e -a
        
# 出力
if max_dis <= k:
  print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
 
N, u, v = map(int, input().split())
 
u -= 1
v -= 1
 
graph = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
 
lst = []
def calcDist(cur, par, dst):
    global lst
    lst[cur] = dst
    for neighbour in graph[cur]:
        if neighbour == par: continue
        calcDist(neighbour, cur, dst + 1)
        
uDist = [None for i in range(N)]
vDist = [None for i in range(N)]
lst = uDist
calcDist(u, -1, 0)
lst = vDist
calcDist(v, -1, 0)
 
best = 0
 
for node in range(N):
    if uDist[node] < vDist[node]: best = max(best, vDist[node] - 1)
print(best)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
 
N, u, v = map(int, input().split())
 
u -= 1
v -= 1
 
graph = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
 
lst = []
def calcDist(cur, par, dst):
    global lst
    lst[cur] = dst
    for neighbour in graph[cur]:
        if neighbour == par: continue
        calcDist(neighbour, cur, dst + 1)
        
uDist = [None for i in range(N)]
vDist = [None for i in range(N)]
lst = uDist
calcDist(u, -1, 0)
lst = vDist
calcDist(v, -1, 0)
 
best = 0
 
for node in range(N):
    if uDist[node] < vDist[node]: best = max(best, vDist[node] - 1)
print(best)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
 
N, u, v = map(int, input().split())
 
u -= 1
v -= 1
 
graph = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
 
lst = []
def calcDist(cur, par, dst):
    global lst
    lst[cur] = dst
    for neighbour in graph[cur]:
        if neighbour == par: continue
        calcDist(neighbour, cur, dst + 1)
        
uDist = [None for i in range(N)]
vDist = [None for i in range(N)]
lst = uDist
calcDist(u, -1, 0)
lst = vDist
calcDist(v, -1, 0)
 
best = 0

for node in range(N):
    if uDist[node] < vDist[node]: best = max(best, vDist[node] - 1)
print(best)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
 
N, u, v = map(int, input().split())
 
u -= 1
v -= 1
 
graph = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
 
lst = []
def calcDist(cur, par, dst):
    global lst
    lst[cur] = dst
    for neighbour in graph[cur]:
        if neighbour == par: continue
        calcDist(neighbour, cur, dst + 1)
        
uDist = [None for i in range(N)]
vDist = [None for i in range(N)]
lst = uDist
calcDist(u, -1, 0)
lst = vDist
calcDist(v, -1, 0)
 
best = 0
 
for node in range(N):
    if uDist[node] < vDist[node]: best = max(best, vDist[node] - 1)
print(best)
Buggy python submission (verdict: Runtime Error):
N = int(input())
edges = [[] for i in range(N+1)]
alledges = []
for i in range(N-1):
    a, b = map(int, input().split())
    alledges.append((a, b))
    edges[a].append(b)
    edges[b].append(a)

def dfs(node, parent):
    used = {col[(node, parent)]}
    curcol = 1
    for n in edges[node]:
        if n == parent: continue

        while curcol in used: curcol += 1

        col[(node, n)] = curcol
        col[(n, node)] = curcol

        dfs(n, node)

        used.add(curcol)
        
col = {}
start = max(range(1, N+1), key = lambda x : len(edges[x]))

for i, n in enumerate(edges[start]):
    col[(start, n)] = i + 1
    col[(n, start)] = i + 1
    dfs(n, start)



done = set()
print(len(edges[start]))
for e in alledges:
    print(col[e])


Fixed submission:
import sys
sys.setrecursionlimit(10000000)

N = int(input())
edges = [[] for i in range(N+1)]
alledges = []
for i in range(N-1):
    a, b = map(int, input().split())
    alledges.append((a, b))
    edges[a].append(b)
    edges[b].append(a)

def dfs(node, parent):
    used = {col[(node, parent)]}
    curcol = 1
    for n in edges[node]:
        if n == parent: continue

        while curcol in used: curcol += 1

        col[(node, n)] = curcol
        col[(n, node)] = curcol

        dfs(n, node)

        used.add(curcol)
        
col = {}
start = max(range(1, N+1), key = lambda x : len(edges[x]))

for i, n in enumerate(edges[start]):
    col[(start, n)] = i + 1
    col[(n, start)] = i + 1
    dfs(n, start)



done = set()
print(len(edges[start]))
for e in alledges:
    print(col[e])
Buggy python submission (verdict: Runtime Error):
W, H, X = map(int, input().split())
X /= W
import math
angle = 90 - math.atan(2*X/pow(H,2)) * 180/math.pi
if angle >= 45:
    print(angle)
else:
    angle = 90 - math.atan(W*W/(2*(W*H-X))) * 180/math.pi
    print(angle)


Fixed submission:
W, H, X = map(int, input().split())
X /= W
if W*H==X:
    print(0)
    quit()
import math
if H*2*X/pow(H,2)<=W:
    print(90 - math.atan(2*X/pow(H,2)) * 180/math.pi)
else:
    angle = 90 - math.atan(W*W/(2*(W*H-X))) * 180/math.pi
    print(angle)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
AS = list(map(int, input().split()))
FS = list(map(int, input().split()))
AS.sort(); FS.sort(reverse=True)

def isValid(x):
    trains = 0
    for i in range(N):
        num = AS[i] * FS[i]
        while num > x:
            trains += 1
            num -= FS[i]
    return trains <= K

def binarySearch(lo, hi):
    if lo >= hi:
        return lo
    mid = lo + (hi - lo) // 2
    if isValid(mid):
        return binarySearch(lo, mid)
    else:
        return binarySearch(mid + 1, hi)
            
print(binarySearch(0, max(AS[i] * FS[i] for i in range(N))))


Fixed submission:
N, K = map(int, input().split())
AS = list(map(int, input().split()))
FS = list(map(int, input().split()))
AS.sort(); FS.sort(reverse=True)

def isValid(x):
    import math
    trains = 0
    for i in range(N):
        num = AS[i] * FS[i]
        if num <= x: continue
        trains += math.ceil((num - x) / FS[i])
    return trains <= K

def binarySearch(lo, hi):
    if lo >= hi:
        return lo
    mid = lo + (hi - lo) // 2
    if isValid(mid):
        return binarySearch(lo, mid)
    else:
        return binarySearch(mid + 1, hi)
            
print(binarySearch(0, max(AS[i] * FS[i] for i in range(N))))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
types = {}
for i in A: types[i] = types.get(i, 0) + 1
A = sorted([types[k] for k in types], reverse=True)
L = len(A)
cumsum = [0 for i in range(L+1)]
for i in range(L-1, -1, -1):
    cumsum[i] = A[i] + cumsum[i+1]

# Highest K for given O
def calc(O):
    def getMidPoint(lo, hi):
        if lo >= hi: return lo
        mid = lo + (hi - lo+1) // 2
        if A[mid] > O:
            return getMidPoint(mid, hi)
        else:
            return getMidPoint(lo, mid-1)

    mid = getMidPoint(0, L-1)
    if A[mid] < O: mid = - 1
    return (mid+1) + cumsum[mid+1] // O

for K in range(1, N+1):
    def getO(lo, hi):
        if lo >= hi: return lo
        mid = lo + (hi - lo+1) // 2
        if calc(mid) < K:
            return getO(lo, mid - 1)
        else:
            return getO(mid, hi)
        
    print(getO(0, N))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
types = {}
for i in A: types[i] = types.get(i, 0) + 1
A = sorted([types[k] for k in types], reverse=True)
L = len(A)
cumsum = [0 for i in range(L+1)]
for i in range(L-1, -1, -1):
    cumsum[i] = A[i] + cumsum[i+1]



def getMidPoint(lo, hi, O):
    if lo >= hi: return lo
    mid = lo + (hi - lo+1) // 2
    if A[mid] > O:
        return getMidPoint(mid, hi, O)
    else:
        return getMidPoint(lo, mid-1, O)

getMid = [getMidPoint(0, L - 1, o) for o in range(N+1)]

# Highest K for given O
def calc(O):
    

    mid = getMid[O]
    if A[mid] < O: mid = - 1
    return (mid+1) + cumsum[mid+1] // O

for K in range(1, N+1):
    def getO(lo, hi):
        if lo >= hi: return lo
        mid = lo + (hi - lo+1) // 2
        if calc(mid) < K:
            return getO(lo, mid - 1)
        else:
            return getO(mid, hi)
        
    print(getO(0, N))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

costs = [None for i in range(M)]
opens = [None for i in range(M)]

for i in range(M):
    costs[i] = list(map(int,input().split()))[0]
    opens[i] = list(map(int, input().split()))

dp = {}
dp[tuple(0 for i in range(N))] = 0

def recurse(required):
    if required in dp:
        return dp[required]

    totalCost = float('inf')
    for i in range(M):
        c = list(required)
        for item in opens[i]:
            c[item-1] = 0
        if tuple(c) == required:continue
        totalCost = min(totalCost, costs[i] + recurse(tuple(c)))

    dp[required] = totalCost
    return totalCost


val = recurse(tuple(1 for i in range(N)))
if val == float('inf'):
    print(-1)
else:
    print(val)


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

costs = [None for i in range(M)]
opens = [None for i in range(M)]

for i in range(M):
    costs[i] = list(map(int,input().split()))[0]
    o = list(map(int, input().split()))
    x = pow(2, 12)-1
    for item in o:
        x &= ~(1 << (item-1))
    opens[i] = x

dp = [-1 for i in range(pow(2, 12))]
dp[0] = 0

def recurse(required):
    if dp[required] != -1:
        return dp[required]

    totalCost = float('inf')
    for i in range(M):
        c = required & opens[i]
        if c == required:continue
        
        totalCost = min(totalCost, costs[i] + recurse(c))

    dp[required] = totalCost
    return totalCost


val = recurse(pow(2, N)-1)
if val == float('inf'):
    print(-1)
else:
    print(val)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
AS = list(map(int, input().split()))
for i in range(M):
    hi = max(range(N), key = lambda n : AS[n])
    AS[hi]//=2
print(sum(AS))


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

import math

buckets = [[] for i in range(31)]
count = [0 for i in range(31)]
for num in AS:
    buckets[math.floor(math.log(num)/math.log(2))].append(num)
    
for lst in buckets: lst.sort(reverse=True)

hi = 30
while buckets[hi-1] == []: hi -= 1
found = 0
while True:
    try:
        if M > found:
            for i in range(hi, 31):
                count[i] += 1
            hi -= 1
            M -= found
            found += len(buckets[hi])
        else:
            total = 0
            for i in range(hi):
                total += sum(buckets[i])
                
            lst = []
            for i in range(hi, 30):
                for item in buckets[i]:
                    lst.append(item // pow(2, count[i]))
             
            lst.sort(reverse=True)
            
            for i in range(M):
                lst[i] //= 2

            total += sum(lst)

            print(total)
            break
    except:
        print(0)
        break
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]
def dfs(root, curCount):
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        dfs(neighbour, curCount)

dfs(1, 0)

print(*count[1:])


Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]

stack = [(1, 0)]
while stack:
    root, curCount = stack.pop()
    
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        stack.append((neighbour, curCount))

print(*count[1:])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]
def dfs(root, curCount):
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        dfs(neighbour, curCount)

dfs(1, 0)

print(*count[1:])


Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]

stack = [(1, 0)]
while stack:
    root, curCount = stack.pop()
    
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        stack.append((neighbour, curCount))

print(*count[1:])
Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(lambda x : ord(x)-ord('a'), input().strip()))
T = list(map(lambda x : ord(x)-ord('a'), input().strip()))

L = len(S)

occ = [[] for i in range(26)]
for i, c in enumerate(S):
    occ[c].append(i)

for c in T:
    if occ[c] == []:
        print(-1)
        quit()

total = 0
cur = -1

def getLowest(bound, lo, hi, lst):
    # Return index of lowest element in list greater than bound
    if lo >= hi:
        if lst[lo] > bound:
            return lo
        else:
            return 0
        
    mid = lo + (hi - lo) // 2
    if lst[mid] > bound:
        return getLowest(bound, lo, mid, lst)
    else:
        return getLowest(bound, mid+1, hi, lst)

for i, char in enumerate(T):
    newpos = occ[char][getLowest(cur, 0, len(occ[char])-1, occ[char])]
    if cur == newpos:
        total += L
    elif newpos < cur:
        total += L - cur + newpos
    else:
        total += newpos - cur
    cur = newpos
print(total)
    


Fixed submission:
S = list(map(lambda x : ord(x)-ord('a'), input().strip()))
T = list(map(lambda x : ord(x)-ord('a'), input().strip()))

L = len(S)

occ = [[] for i in range(26)]
for i, c in enumerate(S):
    occ[c].append(i)

for c in T:
    if occ[c] == []:
        print(-1)
        quit()

total = 0
cur = -1

def getLowest(bound, lo, hi, lst):
    # Return lowest element in list greater than bound
    while lo < hi:
        mid = lo + (hi - lo) // 2
        if lst[mid] > bound:
            hi = mid
        else:
            lo = mid + 1
    if lst[lo] > bound:
        return lst[lo]
    return lst[0]
        
    

for i, char in enumerate(T):
    newpos = getLowest(cur, 0, len(occ[char])-1, occ[char])
    if cur == newpos:
        total += L
    elif newpos < cur:
        total += L - cur + newpos
    else:
        total += newpos - cur
    cur = newpos
print(total)
Buggy python submission (verdict: Runtime Error):
N = int(input())

vals = [[0, 0, 0] for i in range(N)]

for i in range(N):
    v1, v2, v3 = map(int, input().split())
    vals[i][0] = v1
    vals[i][1] = v2
    vals[i][2] = v3

dp = [[0 for i in range(N)] for j in range(3)]

dp[0][0] = vals[0][0]
dp[0][1] = vals[0][1]
dp[0][2] = vals[0][2]

for i in range(1, N):
    for activity in range(3):
        for pastActivity in range(3):
            if activity == pastActivity: continue
            
            dp[i][activity] = max(dp[i][activity],
                                  dp[i-1][pastActivity] + vals[i][activity])

print(max(dp[-1]))


Fixed submission:
N = int(input())

vals = [[0, 0, 0] for i in range(N)]

for i in range(N):
    v1, v2, v3 = map(int, input().split())
    vals[i][0] = v1
    vals[i][1] = v2
    vals[i][2] = v3

dp = [[0 for i in range(3)] for j in range(N)]

dp[0][0] = vals[0][0]
dp[0][1] = vals[0][1]
dp[0][2] = vals[0][2]

for i in range(1, N):
    for activity in range(3):
        for pastActivity in range(3):
            if activity == pastActivity: continue
            
            dp[i][activity] = max(dp[i][activity],
                                  dp[i-1][pastActivity] + vals[i][activity])

print(max(dp[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

weights = [None for i in range(N)]
values = [None for i in range(N)]

# dp[i][j] = maximum value using at most i weight and using elements 1,...,j

dp = [[0 for i in range(N+1)] for j in range(W+1)]

for i in range(N):
    w, v = map(int, input().split())
    weights[i] = w
    values[i] = v
    
for weight in range(W+1):
    for item in range(1,N+1):
        if weights[item-1] > weight: continue

        dp[weight][item] = max([dp[weight][item]] + 
                               [values[item-1] + dp[weight - weights[item-1]][j] for j in range(item)])

        dp[weight][item] = max(dp[weight-1][item], dp[weight][item])
    
print(max(dp[-1]))


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

weights = [None for i in range(N)]
values = [None for i in range(N)]

# dp[i][j] = maximum value using at most i weight and using elements 1,...,j

dp = [[0 for i in range(N+1)] for j in range(W+1)]

for i in range(N):
    w, v = map(int, input().split())
    weights[i] = w
    values[i] = v
    
for weight in range(W+1):
    for item in range(1,N+1):

        # Case: dont include item
        dp[weight][item] = max(dp[weight][item],
                               dp[weight][item-1])

        # Case: include item
        dp[weight][item] = max(dp[weight][item],
                               dp[weight-1][item])
        
        if weights[item-1] > weight: continue
 
        # Case: include item
        dp[weight][item] = max(dp[weight][item],
                               values[item-1] + dp[weight - weights[item-1]][item - 1])
    
print(max(dp[-1]))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

maxDist = [0 for i in range(N+1)]
in_degree = [0 for i in range(N+1)]
adj_list = [[] for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    adj_list[x].append(y)
    in_degree[y] += 1

for node in range(1, N+1):
    adj_list[0].append(node)
    in_degree[node] += 1

# dp[i] = maximum length of path ending at i
flattenedNodes = []
def dfs(node):
    for child in adj_list[node]:
        maxDist[child] = max(maxDist[child], 1 + maxDist[node])
        in_degree[child] -= 1
        if in_degree[child] == 0:
            dfs(child)
            
dfs(0)
print(max(maxDist) - 1)


Fixed submission:
import sys
sys.setrecursionlimit(100000 + 1)

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

maxDist = [0 for i in range(N+1)]
in_degree = [0 for i in range(N+1)]
adj_list = [[] for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    adj_list[x].append(y)
    in_degree[y] += 1

for node in range(1, N+1):
    adj_list[0].append(node)
    in_degree[node] += 1

# dp[i] = maximum length of path ending at i
flattenedNodes = []
def dfs(node):
    for child in adj_list[node]:
        maxDist[child] = max(maxDist[child], 1 + maxDist[node])
        in_degree[child] -= 1
        if in_degree[child] == 0:
            dfs(child)
            
dfs(0)
print(max(maxDist) - 1)

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

maxDist = [0 for i in range(N)]
in_degree = [1 for i in range(N)]
adj_list_f = [[] for i in range(N)]
adj_list_b = [[] for i in range(N)]

for i in range(M):
    x, y = map(lambda x:int(x)-1, input().split())
    adj_list_f[x].append(y)
    adj_list_b[y].append(x)
    in_degree[y] += 1

# dp[i] = maximum length of path ending at i
def dfs(node):
    children = adj_list_f[node] if node != -1 else [i for i in range(N)]
    for child in children:
        if node == -1:
            maxDist[child] = max(maxDist[child], 1)
        else:
            maxDist[child] = max(maxDist[child], 1 + maxDist[node])
        in_degree[child] -= 1
        if in_degree[child] == 0:
            dfs(child)
            
dfs(-1)
print(max(maxDist) - 1)


Fixed submission:
import sys
sys.setrecursionlimit(100000 + 1)

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

maxDist = [0 for i in range(N+1)]
in_degree = [0 for i in range(N+1)]
adj_list = [[] for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    adj_list[x].append(y)
    in_degree[y] += 1

for node in range(1, N+1):
    adj_list[0].append(node)
    in_degree[node] += 1

# dp[i] = maximum length of path ending at i
flattenedNodes = []
def dfs(node):
    for child in adj_list[node]:
        maxDist[child] = max(maxDist[child], 1 + maxDist[node])
        in_degree[child] -= 1
        if in_degree[child] == 0:
            dfs(child)
            
dfs(0)
print(max(maxDist) - 1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

coins = list(map(float, input().split()))

dp = [[0 for i in range(N+1)] for j in range(N)]

dp[0][0] = 1 - coins[0]
dp[0][1] = coins[0]

for j in range(1, N):
    for h in range(j+2):
        if h == 0:
            dp[j][h] = (1 - coins[j]) * dp[j-1][0]
        else:
            dp[j][h] = (1 - coins[j]) * dp[j-1][h] + coins[j] * dp[j-1][h-1]
     
print(sum(dp[-1][head] for head in range(N//2 + 1, N+1)))


Fixed submission:
N = int(input())

coins = list(map(float, input().split()))

dp = [[0 for i in range(N+1)] for j in range(N)]

dp[0][0] = 1 - coins[0]
dp[0][1] = coins[0]

for j in range(1, N):
    for h in range(j+2):
        if h == 0:
            dp[j][h] = (1 - coins[j]) * dp[j-1][0]
        else:
            dp[j][h] = (1 - coins[j]) * dp[j-1][h] + coins[j] * dp[j-1][h-1]
     
print(sum(dp[-1][head] for head in range(N//2 + 1, N+1)))

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

coins = list(map(float, input().split()))

dp = [[0 for i in range(N+1)] for j in range(N)]

dp[0][0] = 1 - coins[0]
dp[0][1] = coins[0]

for j in range(1, N):
    for h in range(N+1):
        if h == 0:
            dp[j][h] = (1 - coins[j]) * dp[j-1][0]
        else:
            dp[j][h] = (1 - coins[j]) * dp[j-1][h] + coins[j] * dp[j-1][h-1]

print(sum(dp[-1][head] for head in range(N//2 + 1, N+1)))


Fixed submission:
N = int(input())

coins = list(map(float, input().split()))

dp = [[0 for i in range(N+1)] for j in range(N)]

dp[0][0] = 1 - coins[0]
dp[0][1] = coins[0]

for j in range(1, N):
    for h in range(j+2):
        if h == 0:
            dp[j][h] = (1 - coins[j]) * dp[j-1][0]
        else:
            dp[j][h] = (1 - coins[j]) * dp[j-1][h] + coins[j] * dp[j-1][h-1]
     
print(sum(dp[-1][head] for head in range(N//2 + 1, N+1)))