Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import itertools
n, m, r = map(int, input().split())
r = list(map(lambda x:int(x)-1, input().split()))
d = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
  a, b, t = map(int, input().split())
  a -= 1
  b -= 1
  d[a][b] = t
  d[b][a] = t
for i in range(n):
  d[i][i] = 0


def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j] = min(d[i][j],d[i][k] + d[k][j])
  return d  

d = warshall_floyd(d)

ans = float('inf')
for v in itertools.permutations(r):
  tmp = 0
  for i in range(len(v)-1):
    tmp += d[v[i]][v[i+1]]
  ans = min(ans, tmp)

print(ans)


Fixed submission:
import itertools
n, m, r = map(int, input().split())
d = [[float('inf')]*n for _ in range(n)]
rs = list(map(int, input().split()))
for _ in range(m):
  a, b, t = map(int, input().split())
  a -= 1
  b -= 1
  d[a][b] = t
  d[b][a] = t
for i in range(n):
  d[i][i] = 0

def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j] = min(d[i][j],d[i][k] + d[k][j])
  return d 

d = warshall_floyd(d)
ans = float('inf')
for p in itertools.permutations(rs):
  tmp = 0
  for i in range(len(p)-1):
    tmp += d[p[i]-1][p[i+1]-1]
  ans = min(ans, tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import itertools
n, m, r = map(int, input().split())
r = list(map(lambda x:int(x)-1, input().split()))
graph = [[] for _ in range(n)]
for _ in range(m):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1 
  graph[a] += [[b, c]]
  graph[b] += [[a, c]]

def dijkstra(s):
  dist = [float('inf')]*n
  dist[s] = 0
  q = [[0, s]]
  heapq.heapify(q)
  while q:
    c, u = heapq.heappop(q)
    if dist[u] < c:
      continue
    for v, weight in graph[u]:
      if dist[v] > dist[u] + weight:
        dist[v] = dist[u] + weight
        heapq.heappush(q, [dist[v], v])
  return dist

ans = float('inf')
for v in itertools.permutations(r):
  tmp = 0
  for i in range(len(v)-1):
    tmp += dijkstra(v[i])[v[i+1]]
  ans = min(ans, tmp)

print(ans)


Fixed submission:
import itertools
n, m, r = map(int, input().split())
d = [[float('inf')]*n for _ in range(n)]
rs = list(map(int, input().split()))
for _ in range(m):
  a, b, t = map(int, input().split())
  a -= 1
  b -= 1
  d[a][b] = t
  d[b][a] = t
for i in range(n):
  d[i][i] = 0

def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j] = min(d[i][j],d[i][k] + d[k][j])
  return d 

d = warshall_floyd(d)
ans = float('inf')
for p in itertools.permutations(rs):
  tmp = 0
  for i in range(len(p)-1):
    tmp += d[p[i]-1][p[i+1]-1]
  ans = min(ans, tmp)

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ca = Counter(A)
ca = sorted(ca.items(), key=lambda x:-x[0])
cnt = 0
m = []
for k, v in ca:
  if v >= 2:
    cnt += 1
    m += [k]
  if cnt >= 2:
    break

print(m[0]*m[1])


Fixed submission:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in a:
  d[i] += 1
l = [0, 0]
for k, v in d.items():
  if v >= 4 and k >= max(l):
    l = [k, k]
  elif v >= 2 and k >= min(l):
    l = sorted(l)
    l[0] = k
print(l[0]*l[1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]
dist = [float('inf')]*N

def dfs(u, pre, cnt):
  dist[u] = cnt
  for v in graph[u]:
    if v != pre and cnt+1 < dist[v]:
      dfs(v, u, cnt+1)

    
dfs(0, -1, 0)
if 0 < dist[N-1] <= 2:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Fixed submission:
from collections import defaultdict
n, m = map(int, input().split())
bridges = [list(map(int, input().split())) for _ in range(m)]
first_bridge = []
second_bridge = []
bri_dict = defaultdict(list)
for bridge in bridges:
  bri_dict[bridge[0]].append(bridge[1])
  bri_dict[bridge[1]].append(bridge[0])
for bridge in bridges:
  if bridge[1] == n:
    second_bridge.append(bridge[0])

flag = False
for island in second_bridge:
  if 1 in bri_dict[island]:
    flag = True
  
if flag:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]
dist = [float('inf')]*N

def dfs(u, pre, cnt):
  dist[u] = cnt
  for v in graph[u]:
    if v != pre and cnt+1 < dist[v]:
      dfs(v, u, cnt+1)

    
dfs(0, -1, 0)
if 0 < dist[N-1] <= 2:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Fixed submission:
from collections import defaultdict
n, m = map(int, input().split())
bridges = [list(map(int, input().split())) for _ in range(m)]
first_bridge = []
second_bridge = []
bri_dict = defaultdict(list)
for bridge in bridges:
  bri_dict[bridge[0]].append(bridge[1])
  bri_dict[bridge[1]].append(bridge[0])
for bridge in bridges:
  if bridge[1] == n:
    second_bridge.append(bridge[0])

flag = False
for island in second_bridge:
  if 1 in bri_dict[island]:
    flag = True
  
if flag:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]
dist = [float('inf')]*N

def dfs(u, pre, cnt):
  dist[u] = cnt
  for v in graph[u]:
    if v != pre and cnt+1 < dist[v]:
      dfs(v, u, cnt+1)

    
dfs(0, -1, 0)
if 0 < dist[N-1] <= 2:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Fixed submission:
from collections import defaultdict
n, m = map(int, input().split())
bridges = [list(map(int, input().split())) for _ in range(m)]
first_bridge = []
second_bridge = []
bri_dict = defaultdict(list)
for bridge in bridges:
  bri_dict[bridge[0]].append(bridge[1])
  bri_dict[bridge[1]].append(bridge[0])
for bridge in bridges:
  if bridge[1] == n:
    second_bridge.append(bridge[0])

flag = False
for island in second_bridge:
  if 1 in bri_dict[island]:
    flag = True
  
if flag:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

b = []
for i in a:
  b.append(i)
  b.reverse()

print(*b)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
count = 0
i = 0
j = -1
k = -1

for _ in range(n):
  if count % 2 == 0:
    b[i] = a[k]
    i += 1
    k -= 1
  else:
    b[j] = a[k]
    j -= 1
    k -= 1
  count += 1

print(*b)
Buggy python submission (verdict: Runtime Error):
import math
n, m = map(int, input().split())
MOD = 1000000007
a, b = n, m
count_n = n
count_m =m
count = 0
if abs(n-m) == 1:
  count_n = math.factorial(n) / MOD
  count_m = math.factorial(m) / MOD
  count = count_m * count_n % MOD
elif abs(n-m) == 0:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = 2 * count_m * count_n % MOD
else:
  count = 0

print(count % MOD)

Fixed submission:
import math
n, m = map(int, input().split())
MOD = 1000000007
count_n = 0
count_m = 0
count = 0
if abs(n-m) == 1:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = count_m * count_n % MOD
elif abs(n-m) == 0:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = 2 * count_m * count_n % MOD
else:
  count = 0

print(count % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
MOD = 1000000007
a, b = n, m
count_n = n
count_m =m
count = 0
if abs(n-m) == 1:
  for _ in range(n-1):
    n -= 1
    count_n *= (n % MOD)
  for _ in range(m-1):
    m -= 1
    count_m *= (m % MOD)
  count = (count_m % MOD) * (count_n % MOD)
elif abs(n-m) == 0:
  for _ in range(n-1):
    n -= 1
    count_n *= (n % MOD)
  for _ in range(m-1):
    m -= 1
    count_m *= (m % MOD)
  count = 2 * (count_m % MOD) * (count_n % MOD)
  count %= MOD
else:
  count = 0

print(count)

Fixed submission:
import math
n, m = map(int, input().split())
MOD = 1000000007
count_n = 0
count_m = 0
count = 0
if abs(n-m) == 1:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = count_m * count_n % MOD
elif abs(n-m) == 0:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = 2 * count_m * count_n % MOD
else:
  count = 0

print(count % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n = int(input())
a = list(map(int, input().split()))

ans = -float('inf')
for i in range(n+1):
  fh = list(map(lambda x:x, a[:n+i]))
  sh = a[n+i:]
  heapq.heapify(fh)
  heapq.heapify(sh)
  ans = max(ans, sum(heapq.nlargest(n, fh))-sum(heapq.nsmallest(n, sh)))

print(ans)

Fixed submission:
from heapq import heappush, heappop, heapify
N = int(input())
a = list(map(int, input().split()))
ans_list = []
def red_sum():
  red = sum(a[:N])
  pqr = a[:N]
  heapify(pqr)
  ans_list.append(red)
  for i in range(N, 2*N):
    heappush(pqr, a[i])
    red += a[i]-heappop(pqr)
    ans_list.append(red)

def blue_sum():
  blue = sum(a[2*N:])
  pqb = [-a[i] for i in range(2*N, 3*N)]
  heapify(pqb)
  ans_list[N] -= blue
  for i in range(2*N-1, N-1, -1):
    heappush(pqb, -a[i])
    tmp = heappop(pqb)
    blue += a[i]+tmp
    ans_list[i-N] -= blue

red_sum()
blue_sum()
print(max(ans_list))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
s, t = len(S), len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
while True:
  flg = True
  for i in range(t, -1, -1):
    if S[i:t] in words:
      t = i 
      flg = False
  if flg:
    print('NO')
    break
  if t == 0:
    print('YES')
    break

Fixed submission:
S = input()
t = len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
while True:
  flg = True
  for i in range(t, -1, -1):
    if S[i:t] in words:
      t = i 
      flg = False
  if flg:
    print('NO')
    break
  if t == 0:
    print('YES')
    break
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
b = input()
b = list(map(int, b.split()))
c = 1
for d in range(a):
  c = c * b[d]
if c <= 1000000000000000000:
  print(c)
else:
  print(-1)

Fixed submission:
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = 1
e = 0
for d in range(a):
  c = c * b[0]
  b.pop(0)
  if c > 1000000000000000000:
    print(-1)
    e = 1
    break
if e == 0:
  print(c)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
b = input()
b = b.split()
c = 1
for d in range(a):
  c = c * int(b[0])
  b.pop(0)
if c <= 1000000000000000000:
  print(c)
else:
  print(-1)

Fixed submission:
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = 1
e = 0
for d in range(a):
  c = c * b[0]
  b.pop(0)
  if c > 1000000000000000000:
    print(-1)
    e = 1
    break
if e == 0:
  print(c)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
n = str(N)
a = list(n)

count = 0

for i in range(len(a)):
  count = count + int(a[i]) % (10**(i+1))

if count % 9 == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
n = str(N)
a = list(n)

count = 0

for i in range(len(a)):
  count = count + int(a[i])

if count % 9 == 0:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
#N = int(input()).split()
n = 12141.split()
print(n[0])

Fixed submission:
N = int(input())
n = str(N)
a = list(n)

count = 0

for i in range(len(a)):
  count = count + int(a[i])

if count % 9 == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
A = []
for i in range(3):
  a = input().split()
  a = [int(num) for num in a]
  A.append(a)

N = int(input())
b = [int(input()) for i in range(N)]

for i in range(3):
  for j in range(3):
    if b.count(A[i][j]) != 0:
      A[i][j] = 0
    else:
      continue

if A[1][1] == 0:
  if A[0][0]==A[2][2]==0 or A[0][2]==A[2][0]==0:
    print("Yes")
  else:
    print("No")
elif A[1][1] != 0:
  if sum(A[0])==0 or sum(A[2])==0 or sum(A[:][0])==0 or sum(A[:][2]==0):
    print("Yes")
  else:
    print("No")

Fixed submission:
A = []
for i in range(3):
  a = input().split()
  a = [int(num) for num in a]
  A.append(a)

N = int(input())
b = [int(input()) for i in range(N)]

for i in range(3):
  for j in range(3):
    if b.count(A[i][j]) != 0:
      A[i][j] = 0
    else:
      continue

def Agetraw(j):
    Ans = [int(A[i][j]) for i in range(3)]
    return(Ans)

if (sum(A[0])==0 or sum(A[1])==0 or sum(A[2])==0 
    or sum(Agetraw(0))==0 or sum(Agetraw(1))==0 or sum(Agetraw(2))==0 
    or A[0][0]+A[1][1]+A[2][2]==0 or A[0][2]+A[1][1]+A[2][0]==0):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
A = []
for i in range(3):
  a = input().split()
  a = [int(num) for num in a]
  A.append(a)
print(A)

N = int(input())
b = [int(input()) for i in range(N)]
print(b)

for i in range(3):
  for j in range(3):
    if b.count(A[i][j]) != 0:
      A[i][j] = 0
    else:
      continue

if A[1][1] == 0:
  if A[0][0]==A[2][2]==0 or A[0][2]==A[2][0]==0:
    print("Yes")
  else:
    print("No")
elif A[1][1] != 0:
  if sum(A[0])==0 or sum(A[2])==0 or sum(A[:][0])==0 or sum(A[:][2]==0):
    print("Yes")
  else:
    print("No")

Fixed submission:
A = []
for i in range(3):
  a = input().split()
  a = [int(num) for num in a]
  A.append(a)

N = int(input())
b = [int(input()) for i in range(N)]

for i in range(3):
  for j in range(3):
    if b.count(A[i][j]) != 0:
      A[i][j] = 0
    else:
      continue

def Agetraw(j):
    Ans = [int(A[i][j]) for i in range(3)]
    return(Ans)

if (sum(A[0])==0 or sum(A[1])==0 or sum(A[2])==0 
    or sum(Agetraw(0))==0 or sum(Agetraw(1))==0 or sum(Agetraw(2))==0 
    or A[0][0]+A[1][1]+A[2][2]==0 or A[0][2]+A[1][1]+A[2][0]==0):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
x = input().split()
A, B, K = [int(i) for i in x]
for i in range(K):
  if A >= 1:
    A -= 1
  elif B >= 1:
    B -= 1
print(str(A)+" "+str(B))

Fixed submission:
x = input().split()
A, B, K = [int(i) for i in x]
if A - K > 0:
  print(str(A-K) + " " + str(B))
elif A+B-K > 0:
  print("0" + " " + str(A+B-K))
else:
  print("0 0")
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
new_S = []
for i in range(len(S)):
  s = alphabet.index(S[i])+N
  new_S.append(alphabet[s])
print("".join(new_S))

Fixed submission:
N = int(input())
S = list(input())
alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
new_S = []
for i in range(len(S)):
  s = alphabet.index(S[i])+N
  if s >= 26 :
    s -= 26
  new_S.append(alphabet[s])
print("".join(new_S))
Buggy python submission (verdict: Runtime Error):
x = input().split()
A, B = x[0], x[1]
n = 1
t = 0
while n <= B:
  n += A - 1
  t += 1
print(t)

Fixed submission:
x = input().split()
A, B = int(x[0]), int(x[1])
n = 1
t = 0
while n < B:
  n += A - 1
  t += 1
print(t)
Buggy python submission (verdict: Runtime Error):
x = input().split()
A, B = [int(num) for num in x]
K = (A+B)/2
if int(K) = K:
  print(K)
else:
  print("IMPOSSIBLE")

Fixed submission:
x = input().split()
A, B = [int(num) for num in x]
K = (A+B)/2
if int(K) == K:
  print(int(K))
else:
  print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
l = input().split()
N, A, B = [int(num) for i in l]
NA = N * A
print(min(NA,B))

Fixed submission:
l = input().split()
N, A, B = [int(i) for i in l]
train = N * A
m = min(train, B)
print(m)
Buggy python submission (verdict: Runtime Error):
S = list(input())
A = sorted(S)
if A[0] == A[1] ! A[2] == A[3]:
  print("Yes")
else:
  print("No")

Fixed submission:
S = list(input())
A = sorted(S)
if A[0] == A[1] != A[2] == A[3]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
lst = [input() for i in range(5)]
d = [int(num) for num in lst]
lst_one = [int(list(i)[-1]) for i in lst]

if lst_one.count(0) == 0:
  idx = lst_one.index(min(lst_one))
else:
  no_zero = [i for i in lst_one if i != 0]
  m = min(no_zero)
  idx = lst_one.index(m)

x = d[idx]
del d[idx]

for i in range(len(d)):
  if d[i] % 10 != 0:
    d[i] = 10*(int((d[i]/10))+1)
  else:
    continue
print(sum(d) + x)
  

Fixed submission:
lst = [input() for i in range(5)]
d = [int(num) for num in lst]
lst_one = [int(list(i)[-1]) for i in lst]
if lst_one.count(0) == len(lst_one):
  print(sum(d))
else:
  if lst_one.count(0) == 0:
    idx = lst_one.index(min(lst_one))
  else:
    no_zero = [i for i in lst_one if i != 0]
    m = min(no_zero)
    idx = lst_one.index(m)

  x = d[idx]
  del d[idx]

  for i in range(len(d)):
    if d[i] % 10 != 0:
      d[i] = 10*(int((d[i]/10))+1)
    else:
      continue
  print(sum(d) + x)

Buggy python submission (verdict: Runtime Error):
d = [input() for i in range(5)]
p = [int(list(i)[-1]) for i in d]
if p.count(0) == 0:
  n = p.index(min(p))
else:
  q = sorted(p)
  while q.count(0) != 0:
    q.remove(0)
  m = q[0]
  n = p.index(m)
  
x = int(d[n])
del d[n]

for i in range(len(d)):
  if list(d[i])[-1] == "0":
    continue
  else:
    d[i] = int(d[i])
    d[i] = (int(d[i]/10)+1)*10
    
d = [int(num) for num in d]

print(sum(d)+x)

Fixed submission:
lst = [input() for i in range(5)]
d = [int(num) for num in lst]
lst_one = [int(list(i)[-1]) for i in lst]
if lst_one.count(0) == len(lst_one):
  print(sum(d))
else:
  if lst_one.count(0) == 0:
    idx = lst_one.index(min(lst_one))
  else:
    no_zero = [i for i in lst_one if i != 0]
    m = min(no_zero)
    idx = lst_one.index(m)

  x = d[idx]
  del d[idx]

  for i in range(len(d)):
    if d[i] % 10 != 0:
      d[i] = 10*(int((d[i]/10))+1)
    else:
      continue
  print(sum(d) + x)
Buggy python submission (verdict: Runtime Error):
S = list(input())
length = []
t = 0
for i in range(len(S)):
  if S[i]=="A" or S[i]=="C" or S[i]=="G" or S[i]=="T":
    t += 1
  else:
    length.append(t)
    t = 0
print(max(length))
    

Fixed submission:
S = list(input())
length = []
t = 0
for i in range(len(S)):
  if S[i] == "A" or S[i]=="C" or S[i]=="G" or S[i]=="T":
    t += 1
  else:
    length.append(t)
    t = 0
length.append(t)
print(max(length))
Buggy python submission (verdict: Runtime Error):
N = int(input())
t = 0
if N % 4 == 0 or N % 7 == 0:
  ans = "Yes"
elif N < 4:
  ans = "No"
else:
  for i in range(1, (N//7)+1):
    x = (N - 7*i) / 4
    if int(x) == x:
      ans = "Yes"
    else:
      ans = "No"
print(ans)

Fixed submission:
N = int(input())
t = 0
if N % 4 == 0 or N % 7 == 0:
  ans = "Yes"
else:
  t = 0
  for i in range(1,(N//7)+1):
    x = (N-7*i)/4
    if x == int(x):
      t += 1
    else:
      continue
  if t > 0:
    ans = "Yes"
  else:
    ans = "No"
print(ans)
Buggy python submission (verdict: Runtime Error):
n=str(input())
if n[1]==n[2]==n[3] or n[2]==n[3]==n[4]:
  print('Yes')
else:
  print('No')

Fixed submission:
n=str(input())
if n[0]==n[1]==n[2] or n[1]==n[2]==n[3]:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
n=str(input())
if n[1]==n[2]==n[3] or n[2]==n[3]==n[4]:
  print('Yes')
else:
  print('N')


Fixed submission:
n=str(input())
if n[0]==n[1]==n[2] or n[1]==n[2]==n[3]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def knapsack(N,W,w,v):
    dp = [[0]*(W+1) for _ in range(N)]
    
    for i in range(N):
        for j in range(W+1):
            if j-w[i]>=0:
                dp[i][j] = max(dp[i-1][j],v[i]+ dp[i-1][j-w[i]])
            else:
                dp[i][j] = dp[i-1][j]
    
    return dp[N-1][W]

N,W = map(int,input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split())

print(knapsack(N,W,w,v))

Fixed submission:
def knapsack(N,W,w,v):
    dp = [[0]*(W+1) for _ in range(N)]
    
    for i in range(N):
        for j in range(W+1):
            if j-w[i]>=0:
                dp[i][j] = max(dp[i-1][j],v[i]+ dp[i-1][j-w[i]])
            else:
                dp[i][j] = dp[i-1][j]
    
    return dp[N-1][W]

N,W = map(int,input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split())

print(knapsack(N,W,w,v))
Buggy python submission (verdict: Time Limit Exceeded):
def lcs(s,t):
    m = len(s)
    n = len(t)

    dp = [[0]*(n+1) for _ in range(m+1)]

    for i in range(1,m+1):
        for j in range(1,n+1):
            if s[i-1] == t[j-1]:
                dp[i][j] = 1+ dp[i-1][j-1]
            else:
                dp[i][j] = max(dp[i-1][j],dp[i][j-1])
    
    
    substr = ""
    i,j = m,n
    while i>0 and j>0:
        if s[i-1] == t[j-1]:
            substr+=s[i-1]
            i-=1
            j-=1
        elif dp[i][j-1]>dp[i-1][j]:
            j-=1
        else:
            i-=1
    return substr[::-1]
    
    

# s = "abracadabra"
# t = "avadakedavra"
# s = "axyb"
# t = "abyxb"
s = input()
t = input()
print(lcs(s,t))

Fixed submission:
def lcs(s,t):
    m = len(s)
    n = len(t)

    dp = [[0]*(n+1) for _ in range(m+1)]

    for i in range(1,m+1):
        for j in range(1,n+1):
            if s[i-1] == t[j-1]:
                dp[i][j] = 1+ dp[i-1][j-1]
            else:
                dp[i][j] = max(dp[i-1][j],dp[i][j-1])
    
    
    substr = ""
    i,j = m,n
    while i>0 and j>0:
        if s[i-1] == t[j-1]:
            substr+=s[i-1]
            i-=1
            j-=1
        elif dp[i][j-1]>dp[i-1][j]:
            j-=1
        else:
            i-=1
    return substr[::-1]
    
    

# s = "abracadabra"
# t = "avadakedavra"
# s = "axyb"
# t = "abyxb"
s = input()
t = input()
print(lcs(s,t))

Buggy python submission (verdict: Runtime Error):
def lcs(s,t):
    m = len(s)
    n = len(t)

    dp = [[0]*(n+1) for _ in range(m+1)]

    for i in range(1,m+1):
        for j in range(1,n+1):
            if s[i-1] == t[j-1]:
                dp[i][j] = 1+ dp[i-1][j-1]
            else:
                dp[i][j] = max(dp[i-1][j],dp[i][j-1])
    
    
    substr = ""
    i,j = m,n
    while i!=0 or j!=0:
        if s[i-1] == t[j-1]:
            substr+=s[i-1]
            i-=1
            j-=1
        elif dp[i][j-1]>dp[i-1][j]:
            j-=1
        else:
            i-=1
    return substr[::-1]
    
    

# s = "abracadabra"
# t = "avadakedavra"
# s = "axyb"
# t = "abyxb"
s = input()
t = input()
print(lcs(s,t))

Fixed submission:
def lcs(s,t):
    m = len(s)
    n = len(t)

    dp = [[0]*(n+1) for _ in range(m+1)]

    for i in range(1,m+1):
        for j in range(1,n+1):
            if s[i-1] == t[j-1]:
                dp[i][j] = 1+ dp[i-1][j-1]
            else:
                dp[i][j] = max(dp[i-1][j],dp[i][j-1])
    
    
    substr = ""
    i,j = m,n
    while i>0 and j>0:
        if s[i-1] == t[j-1]:
            substr+=s[i-1]
            i-=1
            j-=1
        elif dp[i][j-1]>dp[i-1][j]:
            j-=1
        else:
            i-=1
    return substr[::-1]
    
    

# s = "abracadabra"
# t = "avadakedavra"
# s = "axyb"
# t = "abyxb"
s = input()
t = input()
print(lcs(s,t))