Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from collections import deque
# starting with start node and then looking for the kids
# and the solving the sub-problem with kids
def recursive_dfs(graph, start_node, map1):
  if start_node not in graph:
    map1[start_node] = 0
    return 0
  dist = 0
  for child in graph[start_node]:
    if child not in map1:
      dist = max(recursive_dfs(graph, child, map1), dist)
    else:
      dist = max(map1[child], dist)
  map1[start_node] = dist + 1
  #print(map1)
  return (dist + 1)

N,M = [int(i) for i in input().split()] # nodes, edges
graph = defaultdict(list)
for i in range(M):
  s,d = [i for i in input().split()]
  graph[s].append(d)
map1 = defaultdict(int)
ans = 0
for i in range(1, N+1):
  if i in map1:
    ans = max(ans, map1[str(i)])
  else:
    ans = max(recursive_dfs(graph, str(i), map1), ans)
print("%s" % ans)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(100000000)
from collections import defaultdict
from collections import deque
# starting with start node and then looking for the kids
# and the solving the sub-problem with kids
def recursive_dfs(graph, start_node, map1):
  if start_node not in graph:
    map1[start_node] = 0
    return 0
  dist = 0
  for child in graph[start_node]:
    if child not in map1:
      dist = max(recursive_dfs(graph, child, map1), dist)
    else:
      dist = max(map1[child], dist)
  map1[start_node] = dist + 1
  #print(map1)
  return (dist + 1)
 
N,M = [int(i) for i in input().split()] # nodes, edges
graph = defaultdict(list)
for i in range(M):
  s,d = [i for i in input().split()]
  graph[s].append(d)
map1 = defaultdict(int)
ans = 0
for i in range(1, N+1):
  if i in map1:
    ans = max(ans, map1[str(i)])
  else:
    ans = max(recursive_dfs(graph, str(i), map1), ans)
print("%s" % ans)
Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
N = int(input())
h = list(map(int, input().split()))

@lru_cache(None)
def dp(i):
    if i >= N: return 0
    if i + 1 == N - 1: return abs(h[i] - h[i+1])
    if i + 2 == N - 1: return abs(h[i] - h[i+2])
    return min(abs(h[i] - h[i+1]) + dp(i+1), abs(h[i] - h[i+2]) + dp(i+2))

print(dp(0))

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

dp = [0]*N
dp[N-1], dp[N-2] = 0, abs(h[N-1] - h[N-2])
for i in range(N-3,-1,-1):
    dp[i] = min(abs(h[i] - h[i+1]) + dp[i+1], abs(h[i] - h[i+2]) + dp[i+2])
print(dp[0])
Buggy python submission (verdict: Runtime Error):
def f(N,K,h):
    dp = [0]*N

    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-K), i)])
    print(dp[-1])


N, K = map(int, input().split())
h = list(map(int, input().split()))
f()

Fixed submission:
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N

for i in range(1,N):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-K), i)])
print(dp[-1])

Fixed submission:
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N

for i in range(1,N):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-K), i))
print(dp[-1])

Fixed submission:
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N

for i in range(1,N):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-K), i))
print(dp[-1])

Fixed submission:
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N

for i in range(1,N):
    dp[i] = min(dp[i-j] + abs(h[i] - h[i-j]) for j in range(1,K+1) if i-j >= 0)
print(dp[-1])

Fixed submission:
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')]*N
dp[0] = 0
for i in range(N):
    for j in range(i+1, min(N,i+K+1)):
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[-1])

Fixed submission:
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))
Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
def head_prob(N,p):
    @lru_cache(None)
    def f(i,k):
        if i <0 or k <0: return 0
        if i == 0 and k == 1:
            return p[0]
        if i == 0 and k == 0:
            return 1 - p[0]
        return p[i]*f(i-1,k-1) + (1-p[i])*f(i-1,k)

    probs = [(f(N-1,k),k) for k in range(1,N+1)]
    return sum(prob[0] for prob in probs if prob[1] > N/2)



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

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

dp = [0 for j in range(n + 1)]
dp[0] = 1
for i in range(n):
    pi = p[i]
    for j in range(i, -1, -1):
        dp[j + 1] = dp[j + 1] * pi + dp[j] * (1 - pi)
    dp[0] *= pi
print(sum(dp[:n // 2 + 1]))
Buggy python submission (verdict: Runtime Error):
def dp_a_frog1(stones):
    if len(stones) == 0:
        return 0
    dp = [0] * len(stones)
    for i in range(1, len(stones)):
        cost_jump = dp[i-1] + abs(stones[i-1] - stones[i])
        if i > 1:
            cost_jump_2 = dp[i-2] + abs(stones[i-2] - stones[i])
            cost_jump = min(cost_jump, cost_jump_2)
        dp[i] = cost_jump
    return dp[len(stones) - 1]
 

if __name__ == '__main__':
	N = int(input())
	h = list(map(int, input().split()))
    print(dp_a_frog1(h))
    

Fixed submission:
def dp_a_frog1(stones):
    if len(stones) == 0:
        return 0
    dp = [0] * len(stones)
    for i in range(1, len(stones)):
        cost_jump = dp[i - 1] + abs(stones[i - 1] - stones[i])
        if i > 1:
            cost_jump_2 = dp[i - 2] + abs(stones[i - 2] - stones[i])
            cost_jump = min(cost_jump, cost_jump_2)
        dp[i] = cost_jump
    return dp[len(stones) - 1]


if __name__ == '__main__':
    N = int(input())
    h = list(map(int, input().split()))
    print(dp_a_frog1(h))

Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(a[0])]

result = []

max_weight = a[1]

def calc(i, queue):
    if len(b) <= i:
        return

    current = b[i]
    # print(queue)
    # print(i - 1)
    prev = queue[-1] if 0 < len(queue) else [0, 0] 
    
    if current[0] + prev[0] <= max_weight:
        result.append(prev[1] + current[1])
    
    next_queue = queue[:]
    next_queue.append([prev[0] + current[0], prev[1] + current[1]])
    # print(next_queue)
    # print(queue)
    calc(i + 1, next_queue)
    calc(i + 1, queue)

calc(0, [])

print(max(result))

Fixed submission:
number = int(input())
scaffolds = list(map(int, input().split()))
costs = [ 0 for i in range(number)]

for i in range(len(costs)):
    hight = scaffolds[i]

    i_1 = -1
    if 0 <= i - 1:
        min_v = costs[i - 1]
        hight_1 = scaffolds[i - 1]
        i_1 = min_v + abs(hight_1 - hight)

    i_2 = -1
    if 0 <= i - 2:
        min_v = costs[i - 2]
        hight_2 = scaffolds[i - 2]
        i_2 = min_v + abs(hight_2 - hight)
    if i_1 < 0 and i_2 < 0:
        costs[i] = 0
    elif i_1 < 0:   
        costs[i] = i_2
    elif i_2 < 0:
        costs[i] = i_1
    else:
        costs[i] = min(i_1, i_2)  
    
    
print(costs[number - 1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

def max_happiness(n, data, a, b, c):
  if n == 0:
    if a and b:
      return max(data[n][0], data[n][1])
    elif b and c:
      return max(data[n][1], data[n][2])
    elif c and a:
      return max(data[n][2], data[n][0])
  
  max_a = -1
  max_b = -1
  max_c = -1
  
  if a:
    max_a = data[n][0] + max_happiness(n-1, data, a=False, b=True, c=True)
  if b:
    max_b = data[n][1] + max_happiness(n-1, data, a=True, b=False, c=True)
  if c:
    max_c = data[n][2] + max_happiness(n-1, data, a=True, b=True, c=False)
    
  return max(max_a, max_b, max_c)

N = int(input())
data = []
for _ in range(N):
  data.append([int(num) for num in input().split()])

print(max_happiness(N-1, data, a=True, b=True, c=True))

Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)

def max_happiness(n, data, dp, a, b, c):
  string = str(n) + str(a) + str(b) + str(c)

  if dp[string] is not None:
    return dp[string]

  if n == 0:
    if a and b:
      dp[string] = max(data[n][0], data[n][1])
      return dp[string]
    elif b and c:
      dp[string] = max(data[n][1], data[n][2])
      return dp[string]
    elif c and a:
      dp[string] = max(data[n][2], data[n][0])
      return dp[string]

  max_a = -1
  max_b = -1
  max_c = -1

  if a:
    max_a = data[n][0] + max_happiness(n-1, data, dp, a=0, b=1, c=1)
  if b:
    max_b = data[n][1] + max_happiness(n-1, data, dp, a=1, b=0, c=1)
  if c:
    max_c = data[n][2] + max_happiness(n-1, data, dp, a=1, b=1, c=0)

  dp[string] = max(max_a, max_b, max_c)
  return dp[string]

N = int(input())
data = []
dp = defaultdict(lambda: None)

for _ in range(N):
  data.append([int(num) for num in input().split()])

print(max_happiness(N-1, data, dp, a=1, b=1, c=1))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000000)

n = int(raw_input())
h = list(map(int, raw_input().split()))
memo = {}

def get_cost(i, j):
    if j >= n:
        return 0
    return abs(h[i] - h[j])

def get_min_cost_from_postion(i):
    if i >= n-1:
        return 0
    if i in memo:
        return memo[i]
    k = min(2, (N-1)-i)
    ans = min(
        get_cost(i, i+x) + get_min_cost_from_postion(i+x) for x in range(1,k+1))

    memo[i] = ans
    return ans

ans = get_min_cost_from_postion(0)

print ans


Fixed submission:
import sys
sys.setrecursionlimit(100000000)

n = int(raw_input())
h = list(map(int, raw_input().split()))
memo = {}

def get_cost(i, j):
    if j >= n:
        return 0
    return abs(h[i] - h[j])

def get_min_cost_from_postion(i):
    if i >= n-1:
        return 0
    if i in memo:
        return memo[i]
    k = min(2, (n-1)-i)
    ans = min(
        get_cost(i, i+x) + get_min_cost_from_postion(i+x) for x in range(1,k+1))

    memo[i] = ans
    return ans

ans = get_min_cost_from_postion(0)

print ans

Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
h = list(map(int, raw_input().split()))
memo = {}

def get_cost(i, j):
    return abs(h[i] - h[j])

def get_min_cost_for_postion(i):
    if i >= n-1:
        return 0
    if i == n - 2:
        return get_cost(n-2, n-1)
    if i == n - 3:
        return min(get_cost(n-3, n-2), get_cost(n-3, n-1))

    if i in memo:
        return memo[i]

    ans = min(
        get_cost(i, i+1) + get_min_cost_for_postion(i+1),
        get_cost(i, i+2) + get_min_cost_for_postion(i+2))

    memo[i] = ans
    return ans

ans = get_min_cost_for_postion(0)

print ans


Fixed submission:
import sys
sys.setrecursionlimit(100000000)

n = int(raw_input())
h = list(map(int, raw_input().split()))
memo = {}

def get_cost(i, j):
    if j >= n:
        return 0
    return abs(h[i] - h[j])

def get_min_cost_from_postion(i):
    if i >= n-1:
        return 0
    if i in memo:
        return memo[i]
    k = min(2, (n-1)-i)
    ans = min(
        get_cost(i, i+x) + get_min_cost_from_postion(i+x) for x in range(1,k+1))

    memo[i] = ans
    return ans

ans = get_min_cost_from_postion(0)

print ans
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import random

import sys
sys.setrecursionlimit(100000000)

# N, W = 100, 20000
# W_V = [[random.randint(1,1000000), random.randint(1,1000)] for i in range(N)]
N = int(raw_input())
ADG_VERTICES= defaultdict(list)
panting_cache = {}
for i in range(N-1):
    u, v = map(int, raw_input().split())
    ADG_VERTICES[u].append(v)
    ADG_VERTICES[v].append(u)

BLACK_COLOR = 1
WHITE_COLOR = 0
MOD_VAL = int(1e9 + 7)
def get_ways_to_paint_vertices(parent_color, parent_vertex, vertex):
    if ADG_VERTICES[vertex] == [parent_vertex]:
        if parent_color == BLACK_COLOR:
            return 1
        else:
            return 2

    if (parent_color,  parent_vertex, vertex) in panting_cache:
        return panting_cache[parent_color,  parent_vertex, vertex]
    ans1 = 1
    ans2 = 0
    for adg_vertex in ADG_VERTICES[vertex]:
        if adg_vertex != parent_vertex:
            ans1 = (ans * get_ways_to_paint_vertices(WHITE_COLOR, vertex, adg_vertex)) % MOD_VAL
    if parent_color != BLACK_COLOR:
        ans2 = 1
        for adg_vertex in ADG_VERTICES[vertex]:
            if adg_vertex != parent_vertex:
                ans2 = (ans2 * get_ways_to_paint_vertices(BLACK_COLOR, vertex, adg_vertex)) % MOD_VAL

    ans = ans1 + ans2
    if ans >= MOD_VAL:
        ans -= MOD_VAL
    panting_cache[parent_color, parent_vertex, vertex] = ans

    return ans


print get_ways_to_paint_vertices(None, 0, 1)


Fixed submission:
from collections import defaultdict
import random

import sys
sys.setrecursionlimit(100000000)

# N, W = 100, 20000
# W_V = [[random.randint(1,1000000), random.randint(1,1000)] for i in range(N)]
N = int(raw_input())
ADG_VERTICES= defaultdict(list)
panting_cache = {}
for i in range(N-1):
    u, v = map(int, raw_input().split())
    ADG_VERTICES[u].append(v)
    ADG_VERTICES[v].append(u)

BLACK_COLOR = 1
WHITE_COLOR = 0
MOD_VAL = int(1e9 + 7)
def get_ways_to_paint_vertices(parent_color, parent_vertex, vertex):
    if ADG_VERTICES[vertex] == [parent_vertex]:
        if parent_color == BLACK_COLOR:
            return 1
        else:
            return 2

    if (parent_color,  parent_vertex, vertex) in panting_cache:
        return panting_cache[parent_color,  parent_vertex, vertex]
    ans1 = 1
    ans2 = 0
    for adg_vertex in ADG_VERTICES[vertex]:
        if adg_vertex != parent_vertex:
            ans1 = (ans1 * get_ways_to_paint_vertices(WHITE_COLOR, vertex, adg_vertex)) % MOD_VAL
    if parent_color != BLACK_COLOR:
        ans2 = 1
        for adg_vertex in ADG_VERTICES[vertex]:
            if adg_vertex != parent_vertex:
                ans2 = (ans2 * get_ways_to_paint_vertices(BLACK_COLOR, vertex, adg_vertex)) % MOD_VAL

    ans = ans1 + ans2
    if ans >= MOD_VAL:
        ans -= MOD_VAL
    panting_cache[parent_color, parent_vertex, vertex] = ans

    return ans


print get_ways_to_paint_vertices(None, 0, 1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
heigt = list(map(int, input().split()))

cost = [0] * n
cost[0] = 0
cost[1] = abs(heigt[1] - heigt[0])
cost[2] = abs(heigt[2] - heigt[0])

for i in range(3,n):
    cost[i] = min(cost[i-1] + abs(heigt[i] - heigt[i-1]),cost[i-2] + abs(heigt[i] - heigt[i-2]))

print(cost[n-1])

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

cost = [0] * n
cost[0] = 0
cost[1] = abs(heigt[1] - heigt[0])
if n == 2:
    print(cost[1])
else:
    cost[2] = abs(heigt[2] - heigt[0])
    if n == 3:
        print(cost[2])
    else:
        for i in range(3,n):
            cost[i] = min(cost[i-1] + abs(heigt[i] - heigt[i-1]),cost[i-2] + abs(heigt[i] - heigt[i-2]))

        print(cost[n-1])
Buggy python submission (verdict: Runtime Error):
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
for i in range(N-1)
    if a[i] + a[i+1] > x:
        answer += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(answer)


Fixed submission:
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
for i in range(N-1):
    if a[i] + a[i+1] > x:
        answer += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
while i < N-1:
    if a[i] + a[i+1] > x:
        answer = answer + a[i] + a[i+1] - x
        a[i+1] = x - a[i]
        i = i+1
print(answer)


Fixed submission:
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
for i in range(N-1):
    if a[i] + a[i+1] > x:
        answer += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
while i < N-1:
    if a[i] + a[i+1] > x:
        answer = answer + a[i] + a[i+1] - x
        a[i+1] = x - a[i]
        i = i+1
print(answer)


Fixed submission:
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
for i in range(N-1):
    if a[i] + a[i+1] > x:
        answer += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
n, x = map(int, input().split())
a_list = list(map(int, input().split()))
minimum = 10000000000
dist_list = []
for i,a in enumerate(a_list):
  minimum = min(abs(a - x), minimum)
  if i == 0:
    continue
  dist_list.append(abs(a_list[i-1] - a))

while minimum != 1:
  flag = 0
  for d in dist_list:
    if d % minimum != 0:
      flag = 1
  if flag == 0:
    break
  else:
    minimum -= 1

print(minimum)



Fixed submission:
import fractions
from functools import reduce

def gcd(a, b):
  while b:
    a, b = b, a % b
    return a

def gcds(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n, x = map(int, input().split())
a_list = list(map(int, input().split()))
minimum = 10000000000
dist_list = []
for i,a in enumerate(a_list):
  minimum = min(abs(a - x), minimum)
  if i == 0:
    continue
  dist_list.append(abs(a_list[i-1] - a))

dist_list.append(minimum)

print(gcd_list(dist_list))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
min_c = 9999999

w_cnt = s.count("W")
e_cnt = s.count("E")

if w_cnt > e_cnt:
   for i in range(int(n/2)+1):
      if i == 0:
         cnt = s.count("E")
         if s[0] == "E":
            cnt = cnt - 1
      elif i == n -1:
         cnt = s.count("W")
         if s[n-1] == "W":
            cnt -= 1
      else: 
         a = s[:i]
         b = s[i+1:]
         a_cnt = a.count("W")
         if a_cnt > min_c: continue
         b_cnt = b.count("E")
         if b_cnt > min_c: continue
         cnt = a_cnt + b_cnt
         if cnt > min_c: continue
      min_c = min(min_c, cnt)
else:
   for i in range(int(n/2)+2, n):
      if i == 0:
         cnt = s.count("E")
         if s[0] == "E":
            cnt = cnt - 1
      elif i == n -1:
         cnt = s.count("W")
         if s[n-1] == "W":
            cnt -= 1
      else: 
         a = s[:i]
         b = s[i+1:]
         a_cnt = a.count("W")
         if a_cnt > min_c: continue
         b_cnt = b.count("E")
         if b_cnt > min_c: continue
         cnt = a_cnt + b_cnt
         if cnt > min_c: continue
      min_c = min(min_c, cnt)

print(min_c)

Fixed submission:
def solve():
    n = int(input())
    s = input()

    cnt = [s[1:n].count("E")]

    for i in range(1, n):
        cnt.append(cnt[i-1] - int(s[i] is "E") + int(s[i-1] is "W"))

    print(min(cnt))

if __name__=='__main__':
   solve()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
min_c = 9999999

for i in range(n):
   if i == 0:
      cnt = s.count("E")
      if s[0] == "E":
         cnt = cnt - 1
   elif i == n -1:
      cnt = s.count("W")
      if s[n-1] == "W":
         cnt -= 1
   else: 
      a = s[:i]
      b = s[i+1:]
      a_cnt = a.count("W")
      if a_cnt > min_c: continue
      b_cnt = b.count("E")
      if b_cnt > min_c: continue
      cnt = a_cnt + b_cnt
      if cnt > min_c: continue
   min_c = min(min_c, cnt)

print(min_c)

Fixed submission:
def solve():
    n = int(input())
    s = input()

    cnt = [s[1:n].count("E")]

    for i in range(1, n):
        cnt.append(cnt[i-1] - int(s[i] is "E") + int(s[i-1] is "W"))

    print(min(cnt))

if __name__=='__main__':
   solve()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
min_c = 9999999

for i in range(n):
   if i == 0:
      cnt = s.count("E")
      if s[0] == "E":
         cnt = cnt - 1
   if i == n -1:
      cnt = s.count("W")
      if s[n-1] == "W":
         cnt -= 1
   else: 
      a = s[:i]
      b = s[i+1:]
      a_cnt = a.count("W")
      b_cnt = b.count("E")
      cnt = a_cnt + b_cnt
   min_c = min(min_c, cnt)

print(min_c)

Fixed submission:
def solve():
    n = int(input())
    s = input()

    cnt = [s[1:n].count("E")]

    for i in range(1, n):
        cnt.append(cnt[i-1] - int(s[i] is "E") + int(s[i-1] is "W"))

    print(min(cnt))

if __name__=='__main__':
   solve()
Buggy python submission (verdict: Runtime Error):
3 4a, b = map(int, input().split())
ans = 'Even' if (a * b) % 2 == 0 else 'Odd'
print(ans)

Fixed submission:
a, b = map(int, input().split())
ans = 'Even' if (a * b) % 2 == 0 else 'Odd'
print(ans)
Buggy python submission (verdict: Runtime Error):
dev solve():
  n, y = map(int, input().split())
  y //= 1000
  
  for nogu in range(n + 1):
    for higu in range(n + 1 - nogu):
      yuki = n - nogu - higu
      if nogu + higu * 5 + yuki * 10 == y:
        print(yuki, higu, nogu)
        return
  print("-1 -1 -1")
  
if __name__=='__main__':
  solve()

Fixed submission:
def solve():
    N, Y = map(int, input().split())

    for x in range(N + 1):
        for y in range(N + 1 - x):
            z = N - x - y
            if 10000 * x + 5000 * y + 1000 * z == Y:
                return " ".join([str(x), str(y), str(z)])

    return "-1 -1 -1"

if __name__=='__main__':
  print(solve())

Buggy python submission (verdict: Runtime Error):

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

    for x in range(N):
        for y in range(N):
            z = N - x - y
            if z < 0:
                break

            if 10000 * x + 5000 * y + 1000 * z == Y:
                return " ".join([str(x), str(y), str(z)])

    return "-1 -1 -1"

Fixed submission:
def solve():
    N, Y = map(int, input().split())

    for x in range(N + 1):
        for y in range(N + 1 - x):
            z = N - x - y
            if 10000 * x + 5000 * y + 1000 * z == Y:
                return " ".join([str(x), str(y), str(z)])

    return "-1 -1 -1"

if __name__=='__main__':
  print(solve())