Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
K,N=map(int,input().split())
A=list(map(int,input().split()))
x=[]
y=[]
for i in A:
  if i>10:
    a=20-i
    y.append(a)
  else:
    x.append(i)
if len(A)==1:
  if A[0]>=10:
    print(20-A[0])
  else:
    print(A[0])
else:
  ans=max(x)+max(y)
  print(ans)

Fixed submission:
K,N=map(int,input().split())
A=list(map(int,input().split()))
sa=[]
sa.append(int(K-A[-1]+A[0]))
for i in range(1,N):
  tmp=A[i]-A[i-1]
  sa.append(tmp)
ans=K-max(sa)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,A,B=map(int,input().split())
x=[]
for i in range(1,N+A+B):
  for j in range(A):
    x.append("a")
  for k in range(B):
    x.append("b")
   
x=x[:N]
print(x.count("a"))

Fixed submission:
N,A,B=map(int,input().split())
num=N//(A+B)
res=N-num*(A+B)
count=0
if res<=A:
  count=num*A+res
else:
  count=num*A+A
print(count)
Buggy python submission (verdict: Runtime Error):
a=[]
for i in range (2):
  for j in range(2):
    a.append(int(input()))
N=int(input())
for i in range(N):
  b[i]=int(input())
  
for i in range(2):
  for j in range(2):
    for k in range(N):
      if a[i][j]==b[k]:
        a[i][j]=1
      else:
        a[i][j]=0
        
if a[0][0]=1 and a[0][1]=1 and a[0][2]=1:
  print("Yes")
elif a[1][0]=1 and a[1][1]=1 and a[1][2]=1:
  print("Yes")
elif a[2][0]=1 and a[2][1]=1 and a[2][2]=1:
  print("Yes")
elif a[0][0]=1 and a[1][0]=1 and a[2][0]=1:
  print("Yes")
elif a[0][1]=1 and a[1][1]=1 and a[2][1]=1:
  print("Yes")
elif a[0][2]=1 and a[1][2]=1 and a[2][2]=1:
  print("Yes")
elif a[0][0]=1 and a[1][1]=1 and a[2][2]=1:
  print("Yes")
elif a[0][2]=1 and a[1][1]=1 and a[2][0]=1:
  print("Yes")
else:
  print("No")


Fixed submission:
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
B=list(int(input()) for i in range(N))
x=[]
for i in range(3):
  for j in range(3):
    if A[i][j] in B:
      x.append(A[i][j])
if A[0][0] in x and A[1][0] in x and A[2][0] in x:
  print("Yes")
elif A[0][1] in x and A[1][1] in x and A[2][1] in x:
  print("Yes")
elif A[0][2] in x and A[1][2] in x and A[2][2] in x:
  print("Yes")
elif A[0][0] in x and A[0][1] in x and A[0][2] in x:
  print("Yes")
elif A[1][0] in x and A[1][1] in x and A[1][2] in x:
  print("Yes")
elif A[2][0] in x and A[2][1] in x and A[2][2] in x:
  print("Yes")
elif A[0][0] in x and A[1][1] in x and A[2][2] in x:
  print("Yes")
elif A[0][2] in x and A[1][1] in x and A[2][0] in x:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]
begin=10**N-1
end=10**N
if N==1:
  print(SC[0][1])
for i in range(begin,end):
  i=str(i)
  for s,c in SC:
    if i[s-1]!=c:
      break
  else:
    print(i)
    exit()
print(-1)

Fixed submission:
N,M = map(int,input().split())
sc = [tuple(map(int,input().split())) for _ in range(M)]
sc = set(sc)
 
ans = -1
begin = 10**(N-1) - (1 if N == 1 else 0)
end = 10**N
for i in range(begin,end):
    num = str(i)
    for s,c in sc:
        if int(num[s-1]) != c:
            break
    else: ans = i
    if ans != -1:
        break
 
print(ans)
Buggy python submission (verdict: Runtime Error):
N,R=map(int,input().split())
ans=R+100*(10-K)
print(ans)

Fixed submission:
N,R=map(int,input().split())
if N>=10:
  print(R)
else:
  print(R+100*(10-N))
Buggy python submission (verdict: Runtime Error):
import collections
N=int(input())
S=list(input() for i in range(N))
S=collections.Counter(S)
S=S.most_common()
if S[0][1]>S[1][1]:
  print(S[0][0])
else:
  s=[i for i in S if i[1]==S[0][1]]
  s=dict(s)
  s=list(s.keys())
  s=sorted(s)
  for i in s:
    print(i)

Fixed submission:
import collections
N=int(input())
S=list(input() for i in range(N))
S=collections.Counter(S)
S=S.most_common()
if len(S)==1:
  print(S[0][0])
elif S[0][1]>S[1][1]:
  print(S[0][0])
else:
  s=[i for i in S if i[1]==S[0][1]]
  s=dict(s)
  s=list(s.keys())
  s=sorted(s)
  for i in s:
    print(i)
Buggy python submission (verdict: Runtime Error):
N=int(input())
P=list(map(int,input().split()))
cnt=1
x=[]
i=0
while True:
  max=P[0]
  if max==1:
    break
  if max>=P[i+1]:
    cnt+=1
    max=P[i+1]
  i+=1
print(cnt)
    

Fixed submission:
n = int(input())
p_n = list(map(int, input().split()))
ans = 1
p_i_1 = [p_n[0]]
m = p_n[0]
for i in range(1, n):
    if m > p_n[i]:
        ans += 1
    m = min(m, p_n[i])
    p_i_1.append(p_n[i])
    if m == 1:
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
P=list(map(int,input().split()))
cnt=1
x=[]
i=0
while True:
  max=P[0]
  if max>=P[i+1]:
    cnt+=1
    max=P[i+1]
  i+=1
  if max==1:
    break
print(cnt)
    

Fixed submission:
n = int(input())
p_n = list(map(int, input().split()))
ans = 1
p_i_1 = [p_n[0]]
m = p_n[0]
for i in range(1, n):
    if m > p_n[i]:
        ans += 1
    m = min(m, p_n[i])
    p_i_1.append(p_n[i])
    if m == 1:
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
P=list(map(int,input().split()))
cnt=0
x=[]
i=0
while True:
  max=P[0]
  if max>=P[i+1]:
    cnt+=1
    max=P[i+1]
  i+=1
  if i==N-1:
    break
print(cnt)
    

Fixed submission:
n = int(input())
p_n = list(map(int, input().split()))
ans = 1
p_i_1 = [p_n[0]]
m = p_n[0]
for i in range(1, n):
    if m > p_n[i]:
        ans += 1
    m = min(m, p_n[i])
    p_i_1.append(p_n[i])
    if m == 1:
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
PS=[list(input().split()) for i in range(M)]
AC=[0]*N
WA=[0]*N
for p,s in PS:
  p=int(p)
  if s=="AC" and AC[p]==0:
    AC[p]=1
  elif s=="WA":
    WA[p]+=1
wa=0
for i in WA:
  wa+=i
print(sum(AC),wa)
  

Fixed submission:
N,M=map(int,input().split())
AC=[0]*N
WA=[0]*N
wa=0
for i in range(M):
    p,s=input().split()
    p=int(p)-1
    if AC[p]==0 and s=="AC":
        AC[p]=1
        wa+=WA[p]
    WA[p]+=1
print(sum(AC),wa)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
x=[]
min=10000000
ans=0
for i in range(1,N+1//2):
  if N%i==0:
    j=int(N/i)
    a=[i,j]
    x.append(a)
for i,j in x:
  if i+j<=min:
    ans=i+j-2
    min=i+j
print(ans)

Fixed submission:
import math
N=int(input())
x=[]
min=10000000000000000
ans=0
sqN=math.ceil(math.sqrt(N))
for i in range(1,sqN+1):
  if N%i==0:
    j=int(N/i)
    a=[i,j]
    x.append(a)
for i,j in x:
  if i+j<=min:
    ans=i+j-2
    min=i+j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
x=[]
min=10000000
ans=0
for i in range(1,N+1):
  if N%i==0:
    j=int(N/i)
    a=[i,j]
    x.append(a)
for i,j in x:
  if i+j<=min:
    ans=i+j-2
    min=i+j
print(ans)


Fixed submission:
import math
N=int(input())
x=[]
min=10000000000000000
ans=0
sqN=math.ceil(math.sqrt(N))
for i in range(1,sqN+1):
  if N%i==0:
    j=int(N/i)
    a=[i,j]
    x.append(a)
for i,j in x:
  if i+j<=min:
    ans=i+j-2
    min=i+j
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
ans=[]
for i in range(N):
  mnum=A.index(B[i])
  ans.append(mnum+1)
for i in ans:
  print(i,end=" ")

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
Alist=[]
for i in range(N):
  Alist.append((A[i],i+1))
Alist=sorted(Alist,key=lambda x: x[0])
for i in range(N):
  print(Alist[i][1],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
ans=[]
for i in range(N):
  mnum=A.index(B[i])
  ans.append(mnum+1)
ans=map(str,ans)
ans=" ".join(ans)
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
Alist=[]
for i in range(N):
  Alist.append((A[i],i+1))
Alist=sorted(Alist,key=lambda x: x[0])
for i in range(N):
  print(Alist[i][1],end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q=map(int,input().split())
A=[int(input()) for i in range(Q)]
point=[K]*N
for i in A:
  i=int(i)
  point=list(map(lambda x: x-1,point))
  point[i-1]+=1
for i in point:
  if i>0:
    print("Yes")
  else:
    print("No")


Fixed submission:
N,K,Q=map(int,input().split())
A=[int(input()) for i in range(Q)]
point=[K-Q]*N
for i in A:
  i=int(i)
  point[i-1]+=1
for i in point:
  if i>0:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input().split()))
a=0
alist=[]
for i in range(N-1):
  if H[i]>=H[i+1]:
    if i!=N-2:
      a+=1
    else:
      a+=1
      alist.append(a)
  elif H[i]<H[i+1]:
    alist.append(a)
    a=0
print(max(alist))


Fixed submission:
N=int(input())
H=list(map(int,input().split()))
a=0
alist=[]
if N==1:
  print(0)
  exit()
for i in range(N-1):
  if H[i]>=H[i+1]:
    if i!=N-2:
      a+=1
    else:
      a+=1
      alist.append(a)
  elif H[i]<H[i+1]:
    alist.append(a)
    a=0
print(max(alist))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
a=[int(input()) for i in range(M)]
dp=[0]*(N+1)
dp[0]=1
anlist=[]
inf=10**9+7
if 1 not in a:
  dp[1]=1
else:
  dp[1]=0
for i in range(2,N+1):
  if i in a:
    continue
  else:
    dp[i]=dp[i-1]+dp[i-2]
ans=dp[N]%inf
print(ans)

  

Fixed submission:
N,M=map(int,input().split())
a=[int(input()) for i in range(M)]
a=set(a)
dp=[0]*(N+1)
dp[0]=1
anlist=[]
inf=10**9+7
if 1 not in a:
  dp[1]=1
else:
  dp[1]=0
for i in range(2,N+1):
  if i in a:
    continue
  else:
    dp[i]=dp[i-1]+dp[i-2]
ans=dp[N]%inf
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
a=[int(input()) for i in range(M)]
dp=[0]*(N+1)
dp[0]=1
anlist=[]
inf=10**9+7
if 1 not in a:
  dp[1]=1
else:
  dp[1]=0
for i in range(2,N+1):
  if i in a:
    continue
  else:
    dp[i]=dp[i-1]+dp[i-2]
for i in dp:
  i=i%inf
  anlist.append(i)
ans=anlist[N]%inf
print(ans)

  

Fixed submission:
N,M=map(int,input().split())
a=[int(input()) for i in range(M)]
a=set(a)
dp=[0]*(N+1)
dp[0]=1
anlist=[]
inf=10**9+7
if 1 not in a:
  dp[1]=1
else:
  dp[1]=0
for i in range(2,N+1):
  if i in a:
    continue
  else:
    dp[i]=dp[i-1]+dp[i-2]
ans=dp[N]%inf
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N,M=map(int,input().split())
L=[]
R=[]
for i in range(M):
  l,r=[int(i) for i in input().split()]
  L.append(l)
  R.append(r)
LR=[]
for i in range(M):
  for j in range(L[i],R[i]+1):
    LR.append(j)
LR=collections.Counter(LR)
LR=LR.most_common()
LR=dict(LR)
cnt=0
for i in list(LR.values()):
  if i==M:
    cnt+=1
print(cnt)

Fixed submission:
N,M=map(int,input().split())
L=[]
R=[]
for i in range(M):
  l,r=[int(i) for i in input().split()]
  L.append(l)
  R.append(r)
Lmax=max(L)
Rmin=min(R)
if Rmin-Lmax>=0:
  print(Rmin-Lmax+1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
S=input()
anlist=[]
check=["A","C","G","T"]
a=0
for i in S:
  if i in check:
    a+=1
  else:
    anlist.append(a)
    a=0
print(max(anlist))


Fixed submission:
S=input()
anlist=[]
check=["A","C","G","T"]
a=0
for i in S:
  if i in check:
    a+=1
  else:
    anlist.append(a)
    a=0
  anlist.append(a)
print(max(anlist))
Buggy python submission (verdict: Runtime Error):
a,b=map(int(),input().split())

if a*b%2==0:
  print("Even")
else:
  print("Odd")

Fixed submission:
a,b=map(int,input().split())
 
if a*b%2==0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
S=input()
S[3]=8
print(S)


Fixed submission:
S=input()
S=S.replace("2017","2018")
print(S)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
count=0
while all(a%2==0 for a in A):
  A=[a/2 for a in A]
  count+=1
print(count)

Fixed submission:
N=input()
print(N.count("1"))

Buggy python submission (verdict: Runtime Error):
N=int(input())
print(N.count("1"))

Fixed submission:
N=input()
print(N.count("1"))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().strip().split(" ")]

from collections import defaultdict

count = defaultdict(int)
for i in A:
    count[i] += 1

for i in A:
    count[i] -= 1
    tmp = 0
    for j in count.values():
        tmp += j * (j-1) // 2
    print(tmp)
    count[i] += 1


Fixed submission:
N = int(input())
A = [int(i) for i in input().strip().split(" ")]

from collections import defaultdict

count = defaultdict(int)
for i in A:
    count[i] += 1

diff = {}
total = 0
for i in count.keys():
    tmp = count[i] * (count[i]-1) // 2
    if tmp == 0:
        diff[i] = 0
    else:
        diff[i] = tmp - (count[i]-1) * (count[i]-2) // 2
    total += tmp

prnt = 0
for i in A:
    prnt = total
    prnt -= diff[i]
    print(prnt)
Buggy python submission (verdict: Runtime Error):
def flip_sq(sy, sx):
    gy = sy
    gx = sx
    while True:
        if sx == W - 1:
            if tiles[sy+1][sx] == "#":
                sy += 1
            else:
                break
        elif tiles[sy][sx+1] == "#":
            sx += 1
            if sy == H - 1:
                break
            if tiles[sy+1][sx] == "#":
                sy += 1
        else:
            break
    for y in range(gy, sy+1):
        for x in range(gx, sx+1):
            tiles[y][x] = flip[tiles[y][x]]

    print(tiles)

H, W = [int(i) for i in input().strip().split(" ")]
tiles = []
for i in range(H):
    tiles.append([i for i in input().strip()])

tile = {"#":1, ".":0}
flip = {"#":".", ".":"#"}
count = []
for i in range(H):
    count.append([])
    for j in range(W):
        count[i].append(0)

count[0][0] = tile[tiles[0][0]]
if tile[tiles[0][0]]:
    flip_sq(0, 0)

for y in range(H):
    for x in range(W):
        if y == 0:
            if x == 0:
                continue
            count[y][x] = count[y][x-1] + tile[tiles[y][x]]
        else:
            if x == 0:
                count[y][x] = count[y-1][x] + tile[tiles[y][x]]
            else:
                count[y][x] = min(count[y-1][x], count[y][x-1]) + tile[tiles[y][x]]
        if tile[tiles[y][x]]:
            flip_sq(y, x)

print(count[H-1][W-1])

Fixed submission:
H, W = map(int, input().split())
grid = [list(input().strip()) for _ in range(H)]

ans = [[0] * W for _ in range(H)]

if grid[0][0] == "#":
    ans[0][0] = 1

for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            continue

        r = H*W
        d = H*W
        if j > 0 and grid[i][j] != grid[i][j-1] and grid[i][j-1] == ".":
            r = 1 + ans[i][j-1]
        elif j > 0:
            r = ans[i][j-1]

        if i > 0 and grid[i][j] != grid[i-1][j] and grid[i-1][j] == ".":
            d = 1 + ans[i-1][j]
        elif i > 0:
            d = ans[i-1][j]
        ans[i][j] = min(r, d)

print(ans[H-1][W-1])
Buggy python submission (verdict: Runtime Error):
    K = int(input())
    n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(n[K-1])

Fixed submission:
K = int(input())
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(n[K-1])

Buggy python submission (verdict: Runtime Error):
K = int(input())
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(n[K])

Fixed submission:
K = int(input())
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(n[K-1])
Buggy python submission (verdict: Runtime Error):
S = [input()]
q = int(input().strip())

for i in range(q):
  query = input()
  if query[0] == "1":
    S.reverse()
  elif query[0] == "2":
    query = query.strip().split(" ")
    if query[1] == "1":
      S.insert(query[2])
    else:
      S.append(query[2])

print("".join(S))

Fixed submission:
from collections import deque

S = deque(input())
q = int(input().strip())


rev_count = 0
for i in range(q):
  query = input()
  if query[0] == "1":
    rev_count += 1
  elif query[0] == "2":
    query = query.strip().split(" ")
    if rev_count & 1 == 1:
      if query[1] == "1":
        S.append(query[2])
      else:
        S.appendleft(query[2])
    else:
      if query[1] == "1":
        S.appendleft(query[2])
      else:
        S.append(query[2])

if rev_count & 1 == 1:
  S.reverse()

print("".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
N, P = [int(i) for i in input().strip().split(" ")]
S = input()

ans = 0
for i in range(1, N+1):
    for j in range(N-i+1):
        s = int(S[j:j+i])
        if s % P == 0:
            ans += 1
print(ans)

Fixed submission:
N, P = [int(i) for i in input().strip().split(" ")]
S = [i for i in input()]

r = [int(i) % P for i in S]

ret = 0

if P == 2 or P == 5:
    for i in range(N):
        if int(S[i]) % P == 0:
            ret += (i+1)
else:
    from collections import defaultdict
    S.reverse()
    mp = defaultdict(int)
    mp[0] = 1
    cur = 0
    p10 = 1
    for c in S:
        cur = (cur + int(c) * p10) % P
        ret += mp[cur]
        mp[cur] += 1
        p10 *= 10
        p10 %= P

print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().strip().split(" "))
h = list(map(int, input().split(" ")))

dp = [0] * n
dp[1] = abs(h[0]-h[1])

for i in range(2, n):
    dp[i] = min([abs(h[i]-h[j])+dp[j] for j in range(max(0, i-k), i)])

print(dp[n-1])

Fixed submission:
n, k = map(int, input().strip().split(" "))
h = list(map(int, input().split(" ")))

dp = [0] * n
dp[1] = abs(h[0]-h[1])

for i in range(2, n):
    dp[i] = min([abs(h[i]-h[j])+dp[j] for j in range(max(0, i-k), i)])

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().strip().split(" "))
h = list(map(int, input().split(" ")))

dp = [10**5] * (n+k+1)
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        dp[i+j] = min(dp[i+j], abs(h[i]-h[i+j])+dp[i])

print(dp[n-1])

Fixed submission:
n, k = map(int, input().strip().split(" "))
h = list(map(int, input().split(" ")))

dp = [0] * n
dp[1] = abs(h[0]-h[1])

for i in range(2, n):
    dp[i] = min([abs(h[i]-h[j])+dp[j] for j in range(max(0, i-k), i)])

print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split(" "))
items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(1, W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])

Fixed submission:
N = int(input().strip())
h = [[0] * (N+1) for i in range(3)]
for i in range(1, N+1):
    a, b, c = map(int, input().split(" "))
    h[0][i] = max(h[1][i-1], h[2][i-1]) + a
    h[1][i] = max(h[0][i-1], h[2][i-1]) + b
    h[2][i] = max(h[0][i-1], h[1][i-1]) + c

print(max(h[0][N], h[1][N], h[2][N]))
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split(" "))
dp = [0]*(W+1)

for _ in range(N):
    w, v = map(int, input().split(" "))
    for i in range(W-w, -1, -1):
        dp[i+w] = max(dp[i] + v, dp[i+w])

print(dp[W])

Fixed submission:
N, W = map(int, input().split(" "))
#items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    w, v = map(int, input().split(" "))
    for j in range(1, W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split(" "))
#items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    w, v = map(int, input().split(" "))
    for j in range(1, W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split(" "))
#items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    w, v = map(int, input().split(" "))
    for j in range(1, W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split(" "))
items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(1, W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split(" "))
#items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    w, v = map(int, input().split(" "))
    for j in range(1, W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int,input().strip().split(" "))
Vmax = 10**5
dp = [10**9+1] * (Vmax+1)
dp[0] = 0
Vtotal = 0

for _ in range(N):
    w, v = map(int, input().strip().split(" "))
    Vtotal += v
    for i in range(Vtotal-v, -1, -1):
        dp[i+v] = min(dp[i+v], dp[i]+w)

for v in range(Vtotal, -1, -1):
    if dp[v] <= W:
        print(v)
        break


Fixed submission:
N, W = map(int,input().strip().split(" "))
Vmax = 10**5
dp = [10**9+1] * (Vmax+1)
dp[0] = 0
Vtotal = 0

for _ in range(N):
    w, v = map(int, input().strip().split(" "))
    Vtotal += v
    for i in range(Vtotal-v, -1, -1):
        dp[i+v] = min(dp[i+v], dp[i]+w)

for v in range(Vtotal, -1, -1):
    if dp[v] <= W:
        print(v)
        break
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
dp = [[0] * (len(t)+1) for _ in range(len(s)+1)]

for s_i in range(len(s)):
    for t_i in range(len(t)):
        if s[s_i] == t[t_i]:
            dp[s_i+1][t_i+1] = dp[s_i][t_i] + 1
        else:
            dp[s_i+1][t_i+1] = max(dp[s_i][t_i+1], dp[s_i+1][t_i])

ans = []
s_i = len(s)
t_i = len(t)
while s_i > 0 and t_i > 0:
    if dp[s_i][t_i] == dp[s_i][t_i-1] and dp[s_i-1][t_i-1] == dp[s_i][t_i]:
        s_i -= 1
        t_i -= 1
    elif dp[s_i][t_i] - dp[s_i-1][t_i-1] == 1:
        s_i -= 1
        t_i -= 1
        if s_i >= 0:
            ans.append(s[s_i])
    else: #dp[s_i][t_i] - dp[s_i-1][t_i] == 1:
        t_i -= 1
        if t_i >= 0:
            ans.append(t[t_i])

print("".join(ans[::-1]))

Fixed submission:
s = input()
t = input()
dp = [[0] * (len(t)+1) for _ in range(len(s)+1)]

for s_i in range(len(s)):
    for t_i in range(len(t)):
        if s[s_i] == t[t_i]:
            dp[s_i+1][t_i+1] = dp[s_i][t_i] + 1
        else:
            dp[s_i+1][t_i+1] = max(dp[s_i][t_i+1], dp[s_i+1][t_i])

ans = []
s_i = len(s)
t_i = len(t)
while s_i > 0 and t_i > 0:
    if dp[s_i][t_i] == dp[s_i][t_i-1]:
        t_i -= 1
    elif dp[s_i][t_i] == dp[s_i-1][t_i]:
        s_i -= 1
    else: #dp[s_i][t_i]  dp[s_i-1][t_i] == 1:
        s_i -= 1
        t_i -= 1
        if t_i >= 0:
            ans.append(t[t_i])


print("".join(ans[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
dp = [[""] * (len(t)+1) for _ in range(len(s)+1)]

for s_i in range(len(s)):
    for t_i in range(len(t)):
        if s[s_i] == t[t_i]:
            dp[s_i+1][t_i+1] = max(dp[s_i][t_i], dp[s_i+1][t_i], key=len) + s[s_i]
        else:
            dp[s_i+1][t_i+1] = max(dp[s_i][t_i], dp[s_i+1][t_i], key=len)

print(dp[len(s)][len(t)])


Fixed submission:
s = input()
t = input()
dp = [[0] * (len(t)+1) for _ in range(len(s)+1)]

for s_i in range(len(s)):
    for t_i in range(len(t)):
        if s[s_i] == t[t_i]:
            dp[s_i+1][t_i+1] = dp[s_i][t_i] + 1
        else:
            dp[s_i+1][t_i+1] = max(dp[s_i][t_i+1], dp[s_i+1][t_i])

ans = []
s_i = len(s)
t_i = len(t)
while s_i > 0 and t_i > 0:
    if dp[s_i][t_i] == dp[s_i][t_i-1]:
        t_i -= 1
    elif dp[s_i][t_i] == dp[s_i-1][t_i]:
        s_i -= 1
    else: #dp[s_i][t_i]  dp[s_i-1][t_i] == 1:
        s_i -= 1
        t_i -= 1
        if t_i >= 0:
            ans.append(t[t_i])


print("".join(ans[::-1]))