Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(inout())
if n == 1:
    print('Hello World')
else:
    a = int(inout())
    b = int(inout())
    print(a+b)

Fixed submission:
n = int(input())
if n == 1:
    print('Hello World')
else:
    a = int(input())
    b = int(input())
    print(a+b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[str(input()) for i in range(n)]
ans = 0
for i in range(n):
    if list(l[i])[-1] == list(l[i+1])[0] and l.count(l[i]) == 1:
        ans += 1
    else:
        ans += 0
print('Yes' if ans==n else'N0')

Fixed submission:
n=int(input())
l=[str(input()) for i in range(n)]
ans = 'Yes'
for i in range(1,n):
    if l[i][0] != l[i-1][-1]:
        ans = 'No'
        break
if len(set(l)) != n:
  ans = 'No'
print(ans)
Buggy python submission (verdict: Runtime Error):
x1,y1,x2,y2=map(int,input().split())
print(x2+y1-y2,y2+x2-x1,x3+y2-y3,y3+x3-x2)

Fixed submission:
x1,y1,x2,y2=map(int,input().split())
x3=x2+y1-y2
y3=y2+x2-x1
x4=x3+y2-y3
y4=y3+x3-x2
print(x3,y3,x4,y4)
Buggy python submission (verdict: Time Limit Exceeded):
S=list(str(input()))
k=int(input())
for i in range(len(S)):
    si=int(S[i])
    ti=si**(5*10**15)
    if k<=ti:
        print(S[i])
        break
    else:
        k-=ti

Fixed submission:
s = input()
k = int(input())
 
ans = '1'
for i in range(k):
  if s[i] != '1':
    ans = s[i]
    break
 
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
p = list(s)
i=1
f=0
while f==0:  
    if p[i-1]==p[i]:
        del p[i]
    else:
        i+=1
    if len(p)<=i:
        f=1

print(len(p))

Fixed submission:
n = int(input())
s = input()
p = list(s)
i=1
while len(p)>i:  
    if p[i-1]==p[i]:
        del p[i]
    else:
        i+=1

print(len(p))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
p = list(s)
i=1
f=0
while f==0:  
    if p[i-1]==p[i]:
        del p[i]
    else:
        i+=1
    if len(p)<=i:
        f=1

print(len(p))

Fixed submission:
n = int(input())
s = input()
p = list(s)
i=1
while len(p)>i:  
    if p[i-1]==p[i]:
        del p[i]
    else:
        i+=1

print(len(p))
Buggy python submission (verdict: Time Limit Exceeded):
m = list(map(int,input().split()))
a = list(map(int,input().split()))

for i in range(m[1]):
    a[a.index(max(a))] = a[a.index(max(a))]//2

print(sum(a))

Fixed submission:
import heapq

m = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(len(a)):
  a[i] = a[i]*-1

heapq.heapify(a)

for i in range(m[1]):
     k= heapq.heappop(a)
     heapq.heappush(a, -(-k//2))

print(sum(a)*-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int,input().split()))
c=0

if n == 1:
    print(b[0]*2+b[1])
elif n==2:
    print(b[-1]+min(b[0],b[1])*2)
else:    
    for i in range(n-2):
        c = c + min(b[i],b[i+1])
    print(c+b[-1])

Fixed submission:
n = int(input())
b = list(map(int,input().split()))
c=0

if n == 2:
    print(b[0]*2)
elif n==3:
    print(b[1]+min(b[0],b[1])*2)
else:
    co = [min(x , y) for (x, y) in zip(b[0:-1], b[1:])]
    print(sum(co)+b[-1]+b[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
out=0

out = [i for i in range(n)]
out = sum(out)

print(out)


Fixed submission:
n = int(input())
print(int((n-1)*n//2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
out=0
for i in range(n):
    out=out+i

print(out)

Fixed submission:
n = int(input())
print(int((n-1)*n//2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
out=0
for i in range(n):
    out=out+i

print(out)


Fixed submission:
n = int(input())
print(int((n-1)*n//2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

VC = 0
for i in range(N):
    if V[i]-C[i]>0:
        VC = VC + V[i]-C[i]
    else:

print(VC)

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

VC = 0
for i in range(N):
    if V[i]-C[i]>0:
        VC = VC + V[i]-C[i]
    else:
        VC = VC

print(VC)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int,input().split()))

NH = 1
for i in range(N-1):
    if H[i+1]=>max(H[0:i+1]):
        NH = NH + 1
    else:
        NH = NH

print(NH)

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

NH = 1
for i in range(N-1):
    if H[i+1] >= max(H[0:i+1]):
        NH = NH + 1
    else:
        NH = NH

print(NH)
Buggy python submission (verdict: Runtime Error):
m=[int(input()) for i in range(5)]
k = []
j=[]
for i in range(5):
    j.append(-(-m[i]//10)*10)
    t = m[i] - (m[i]//10)*10
    if t>0:
      k.append(t)
if min(k) == 0:
    print(sum(j))
else:
    print(sum(j)-(10-min(k)))

Fixed submission:
m=[int(input()) for i in range(5)]
k = []
j=[]
for i in range(5):
    j.append(-(-m[i]//10)*10)
    
    
    t=m[i] - (m[i]//10)*10
    if t>0:
        k.append(t)
if len(k)==0:
    print(sum(j))
else:
    print(sum(j)-(10-min(k)))

Buggy python submission (verdict: Runtime Error):
m=[int(input()) for i in range(5)]
k=[]
j=[]
for i in range(5):
    j.append(-(-m[i]//10)*10)
    t = m[i] - (m[i]//10)*10
    if t>0:
      k.append(t)
    
print(sum(j)-(10-min(k)))

Fixed submission:
m=[int(input()) for i in range(5)]
k = []
j=[]
for i in range(5):
    j.append(-(-m[i]//10)*10)
    
    
    t=m[i] - (m[i]//10)*10
    if t>0:
        k.append(t)
if len(k)==0:
    print(sum(j))
else:
    print(sum(j)-(10-min(k)))
Buggy python submission (verdict: Runtime Error):
n,m,c=map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
y=0
for i in range(n):
  x=0  
  for j in range(m):
    x+=a[i+1][j]*a[0][j]
  if x+c>0:
    y+=1
print(y)

Fixed submission:
n,m,c=map(int,input().split())
a=[]
for i in range(n+1):  
  a.append(list(map(int,input().split())) )
y=0
for i in range(n):
  x=0  
  for j in range(m):
    x+=a[i+1][j]*a[0][j]
  if x+c>0:
    y+=1
print(y)

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

Fixed submission:
n,m,c=map(int,input().split())
a=[]
for i in range(n+1):  
  a.append(list(map(int,input().split())) )
y=0
for i in range(n):
  x=0  
  for j in range(m):
    x+=a[i+1][j]*a[0][j]
  if x+c>0:
    y+=1
print(y)
Buggy python submission (verdict: Runtime Error):
m = list(map(int,input().split()))

s = [list(map(str,input().split())) for i in range(m[0])]
a=''
s.sort()
for i in range(m[1]):
  a=a+''.join(s[i]) 
print(a)

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

s = [list(map(str,input().split())) for i in range(m[0])]
a=''
s.sort()
for i in range(m[0]):
  a=a+''.join(s[i]) 
print(a)
Buggy python submission (verdict: Runtime Error):
input()
a=input()
if len(a)%2==0 and a[:len(a)/2]==a[len(a)/2:]:
	print("Yes")
else:
	pritn("No")

Fixed submission:
input()
a=input()
if len(a)%2==0 and a[:len(a)//2]==a[len(a)//2:]:
	print("Yes")
else:
	print("No")

Buggy python submission (verdict: Runtime Error):
input()
s=input()
if len(a)%2==0 and a[:len(a)/2]==a[len(a)/2:]:
	print("Yes")
else:
	pritn("No")

Fixed submission:
input()
a=input()
if len(a)%2==0 and a[:len(a)//2]==a[len(a)//2:]:
	print("Yes")
else:
	print("No")

Buggy python submission (verdict: Runtime Error):
len = int(input())
s = input()
s1 = s[:len / 2]
s2 = s[len/2:]
if s1 == s2:
  print('Yes')
else:
  print('No')

Fixed submission:
l = int(input())
s = input()
s1 = s[:l // 2]
s2 = s[l//2:]
if s1 == s2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    exit(0)
row = (x + y) // 3
mod = 10 ** 9 + 7
if x < row or x > row * 2:
    print(0)
    exit(0)
x = x - row

def pow_mod(a, x, mod):
    if x == 0:
        return 1 % mod
    if x == 1:
        return a % mod
    half = pow_mod(a, x // 2, mod)
    half = half * half % mod
    if x % 2 == 1:
        half = half * a % mod
    return half

def rev(i, mod):
    return pow_mod(i, mod - 2, mod)

def calc(n, m, mod):
    if n == m or m == 0:
        return 1
    if n - m < m:
        m = n - m
    ans = 1
    for i in range(1, m + 1):
        f1 = ans * (n-i+1) * rev(i, mod) % mod
        ans = f1
    return ans


print(calc(row, x, mod))


Fixed submission:
x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    exit(0)
row = (x + y) // 3
mod = 10 ** 9 + 7
if x < row or x > row * 2:
    print(0)
    exit(0)
x = x - row

def pow_mod(a, x, mod):
    if x == 0:
        return 1 % mod
    if x == 1:
        return a % mod
    half = pow_mod(a, x // 2, mod)
    half = half * half % mod
    if x % 2 == 1:
        half = half * a % mod
    return half

def rev(i, mod):
    return pow_mod(i, mod - 2, mod)

def calc(n, m, mod):
    if n == m or m == 0:
        return 1
    if n - m < m:
        m = n - m
    ans = 1
    for i in range(1, m + 1):
        f1 = ans * (n-i+1) * rev(i, mod) % mod
        ans = f1
    return ans


print(calc(row, x, mod))
Buggy python submission (verdict: Runtime Error):
from math import gcd

a, b = map(int, input().split())
g = gcd(a, b)
ans = set([1])
for i in range(2, 1000000):
    while g % i == 0:
        g = g // i
        ans.add(i)

print(len(ans))

Fixed submission:
def gcd(a : int, b: int):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

a, b = map(int, input().split())
g = gcd(a, b)
ans = set([1])
for i in range(2, 1000000):
    while g % i == 0:
        g = g // i
        ans.add(i)
if g > 1:
    ans.add(g)

print(len(ans))
Buggy python submission (verdict: Runtime Error):
import sys

lines = sys.stdin.readline()
a = lines[0]
b = lines[1].strip()

if a >= 3200:
    b = 'red'

print(b)

Fixed submission:
import sys

lines = sys.stdin.readlines()
a = int(lines[0])
s = lines[1].strip()

if a < 3200:
    s = 'red'

print(s)
print('\n')
Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
for i in range(1, n + 1):
    if len(str(i)) % 2 == 1:
		count += 1
print(count)

Fixed submission:
n = int(input())
count = 0
for i in range(1, n + 1):
    if len(str(i)) % 2 == 1:
    	count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
print(sum(range(1,N)))

Fixed submission:
N = int(input())
print(sum(range(1,N)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
w = list(map(int, input().split()))


LtoR = []

for i in range(len(w)):
    if i==0:
        LtoR.append(w[i])
    else:
        LtoR.append(w[i]+LtoR[-1])
        
RtoL = []
for i in range(len(w)):
    
    if i==0:
        RtoL.append(w[-i-1])
    else:
        RtoL.append(w[-i-1]+RtoL[-1])
RtoL.reverse()

i = 0
val = abs(LtoR[i]-RtoL[i+1])
while i<len(w):
#     print(val)
    next_val = abs(LtoR[i]-RtoL[i+1])
    if next_val > val:
        break
    else:
        val = next_val
        i+=1
        
print(val)

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


LtoR = []

for i in range(len(w)):
    if i==0:
        LtoR.append(w[i])
    else:
        LtoR.append(w[i]+LtoR[-1])
        
RtoL = []
for i in range(len(w)):
    
    if i==0:
        RtoL.append(w[-i-1])
    else:
        RtoL.append(w[-i-1]+RtoL[-1])
RtoL.reverse()

i = 0
val = abs(LtoR[i]-RtoL[i+1])
while i<len(w)-1:
#     print(val)
    next_val = abs(LtoR[i]-RtoL[i+1])
    if next_val > val:
        break
    else:
        val = next_val
        i+=1
        
print(val)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(15000)

*D, = open(0)
n = int(D[0])
 
v = [[] for _ in range(n+1)]
 
dist = {}
 
for i in range(1, n):
    a, b, d = map(int, D[i].split())
    v[a].append(b)
    v[b].append(a)
    dist[(a,b)]=d
    dist[(b,a)]=d
 
def visit(current, v, dist, color):
   
    for it in v[current]:
        if color[it] != None:
            continue
        if dist[(it, current)]%2 == 0:
            color[it] = color[current]
        else:
            color[it] = not color[current]
        visit(it, v, dist, color)
        
color = [None for _ in range(n+1)]
color[1]=True
visit(1, v, dist, color)
 
for i in range(1, n+1):
    if color[i]:
        print('0')
    else:
        print('1')

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
 
*D, = open(0)
n = int(D[0])
 
v = [[] for _ in range(n+1)]
 
dist = {}
 
for i in range(1, n):
    a, b, d = map(int, D[i].split())
    v[a].append(b)
    v[b].append(a)
    dist[(a,b)]=d
    dist[(b,a)]=d
 
def visit(current, v, dist, color):
   
    for it in v[current]:
        if color[it] != None:
            continue
        if dist[(it, current)]%2 == 0:
            color[it] = color[current]
        else:
            color[it] = not color[current]
        visit(it, v, dist, color)
        
color = [None for _ in range(n+1)]
color[1]=True
visit(1, v, dist, color)
 
for i in range(1, n+1):
    if color[i]:
        print('0')
    else:
        print('1')

Buggy python submission (verdict: Runtime Error):
*D, = open(0)
n = int(D[0])

v = [[] for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b, d = map(int, D[i].split())
    v[a].append(b)
    v[b].append(a)
    dist[(a,b)]=d
    dist[(b,a)]=d

def visit(current, v, dist, color):
   
    for it in v[current]:
        if color[it] != None:
            continue
        if dist[(it, current)]%2 == 0:
            color[it] = color[current]
        else:
            color[it] = not color[current]
        visit(it, v, dist, color)
        
color = [None for _ in range(n+1)]
color[1]=True
visit(1, v, dist, color)

for i in range(1, n+1):
    if color[i]:
        print('0')
    else:
        print('1')

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
 
*D, = open(0)
n = int(D[0])
 
v = [[] for _ in range(n+1)]
 
dist = {}
 
for i in range(1, n):
    a, b, d = map(int, D[i].split())
    v[a].append(b)
    v[b].append(a)
    dist[(a,b)]=d
    dist[(b,a)]=d
 
def visit(current, v, dist, color):
   
    for it in v[current]:
        if color[it] != None:
            continue
        if dist[(it, current)]%2 == 0:
            color[it] = color[current]
        else:
            color[it] = not color[current]
        visit(it, v, dist, color)
        
color = [None for _ in range(n+1)]
color[1]=True
visit(1, v, dist, color)
 
for i in range(1, n+1):
    if color[i]:
        print('0')
    else:
        print('1')
Buggy python submission (verdict: Runtime Error):
N = int(input())

import math
i=0
prime = []
while 2**i<math.sqrt(N):
    j = 0
    while 2**i*5**j < math.sqrt(N):
        prime.append(2**i*5**j)
        j += 1
    i += 1
prime = sorted(prime)

cnt = 0
ret = []
m = N//(prime[cnt])
while m>0:
    if N//m==N%m:
        ret.append(m)
#         print(m,N//m, N%m)
        cnt += 1
        if len(prime) > cnt:
            while N//(prime[cnt]) > m:
                cnt += 1
            m = N//(prime[cnt])-1
#             print(m)
        else:
            m = 0
    else:
        m-=1
        
sum(ret)

Fixed submission:
N = int(input())
val = []
max_len = [2,4]
def comb(val, max_len, depth=0):
    if depth==len(max_len):
        yield val
        return 

    for i in range(max_len[depth]+1):
        yield from comb(val+[i], max_len, depth+1)
# for it in comb(val, max_len):
# #     print('a')
#     print(it)


import math
def primeFactor(num):
    prime = {}
    x = 2
    MAX =  math.sqrt(num)+1
    while x <MAX:
        if num%x==0:
            if x in prime:
                prime[x] += 1
            else:
                prime[x]=1
            num //= x
        else:
            x += 1
    if num != 1:
        prime[num]=1
    return prime

divisor = primeFactor(N)


ans = 0
val = []
for it in comb(val, list(divisor.values())):
    total = 1
    for i, j in zip(list(divisor.keys()), it):
    #     print(i, j)
        total *= i**j
#     print(total)
    
    m = total - 1
    if m < 1:
        continue
    if N%m==N//m:
#         print('{0} mod {1} = {2}, {0}/{1} = {3}'.format(N, m, N%m, N//m))
        ans += m
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a =list(map(int, input().split()))

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

from functools import reduce
max_val = reduce(gcd, a[1:])
for i in range(1, N):
    tmp = a[i]
    a[i] = a[0]
    val = reduce(gcd, a)
    if max_val < val:
        max_val = val
        
    a[i] = tmp
print(max_val)

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

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

L = []
for i in range(len(a)):
    if i==0:
        L.append(None)
    elif i ==1:
        L.append(a[i-1])
    else:
        L.append(gcd(L[-1], a[i-1]))
        
R = []
for i in range(len(a)):
    if i==0:
        R.append(None)
    elif i ==1:
        R.append(a[-i])
    else:
        R.append(gcd(R[-1], a[-i]))
R = R[::-1]


max_val = 0
for r, l in zip(L,R):
    if r==None:
        val = l
    elif l==None:
        val = r
    else:
        val = gcd(r, l)
        
    if val > max_val:
        max_val = val
print(max_val)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a =list(map(int, input().split()))

ret = 0
for i in range(len(a)-1):
    if a[i] < 0:
        a[i] *= -1
        a[i+1] *= -1
    ret += a[i]
    print(a[i], ret)
ret += a[-1]

abs_list = list(map(abs, a))
test = sorted(enumerate(abs_list), key=lambda x:x[1])
print(max(solve(a), solve(a[::-1]), solve(a[::-1], test[0][0]), solve(a[::-1], test[1][0])))

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

cnt = 0
min_val = abs(a[0])
for it in a:
    if abs(it) < min_val:
        min_val = abs(it)
    
    if it < 0:
        cnt+=1
        
abs_list = list(map(abs, a))
if cnt%2 == 0:
    print(sum(abs_list))
else:
    print(sum(abs_list) - 2*min_val)
Buggy python submission (verdict: Runtime Error):
N = int(input())
b = list(map(int, input().split()))

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret = -1
        break

for it in ret[::-1]:
    print(it)

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

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret.append(-1)
        break

for it in ret[::-1]:
    print(it)

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

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret = -1
        break

for it in ret[::-1]:
    print(it)

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

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret.append(-1)
        break

for it in ret[::-1]:
    print(it)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
stone = []
for it in input().split():
    stone.append(int(it))
import sys
cost = [sys.maxsize]*len(stone)
cost[-1]=0
for i in range(len(stone)-1, 0, -1):
    h_now = stone[i]
    cost_now = cost[i]
    
    # one jump
    for jump in range(1,K+1):
        target = i - jump
        if target < 0:
            continue
        tmp_cost = abs(stone[i] - stone[target])+cost[i]
        if cost[target] > tmp_cost:
            cost[target] = tmp_cost

print(cost[0])

Fixed submission:
N,K = map(int, input().split())
stone = []
for it in input().split():
    stone.append(int(it))
import sys
cost = [sys.maxsize]*len(stone)
cost[-1]=0
for i in range(len(stone)-1, 0, -1):
    h_now = stone[i]
    cost_now = cost[i]
    
    # one jump
    for jump in range(1,K+1):
        target = i - jump
        if target < 0:
            continue
        tmp_cost = abs(stone[i] - stone[target])+cost[i]
        if cost[target] > tmp_cost:
            cost[target] = tmp_cost

print(cost[0])
Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    
MAX_WEIGHT = 1000000009
dp = [[MAX_WEIGHT for i in range(max_total+1)] for j in range(N+1)]
dp[0][0]=0
i = 0
for w, v in p:
    i += 1
    for target_val in range(0, max_total+1):
        
        if target_val-v >=0 and dp[i-1][target_val] > (dp[i-1][target_val-v]+w):
            dp[i][target_val] = dp[i-1][target_val-v]+w
        else:
            dp[i][target_val] = dp[i-1][target_val]
            
ret = 0
for v, w in enumerate(dp[N]):
    if w<=W and v>ret:
        ret = v
print(ret)

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

max_total = 0
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    max_total += p[-1][1]
    
    
MAX_WEIGHT = 1000000009
dp = [[MAX_WEIGHT for i in range(max_total+1)] for j in range(N+1)]
dp[0][0]=0
i = 0
for w, v in p:
    i += 1
    for target_val in range(0, max_total+1):
        
        if target_val-v >=0 and dp[i-1][target_val] > (dp[i-1][target_val-v]+w):
            dp[i][target_val] = dp[i-1][target_val-v]+w
        else:
            dp[i][target_val] = dp[i-1][target_val]
            
ret = 0
for v, w in enumerate(dp[N]):
    if w<=W and v>ret:
        ret = v
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    
dp = [[0 for i in range(W+1)] for j in range(N+1)]
i = 0
for w, v in p:
    i += 1
    for w_limit in range(1, W+1):
        if w_limit < w:
            dp[i][w_limit]=dp[i-1][w_limit]
            continue
        if (dp[i-1][w_limit-w] + v) > dp[i-1][w_limit]:
            dp[i][w_limit] = dp[i-1][w_limit-w] + v
        else:
            dp[i][w_limit]=dp[i-1][w_limit]
print(max(max(dp)))

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

max_total = 0
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    max_total += p[-1][1]
    
    
MAX_WEIGHT = 1000000009
dp = [[MAX_WEIGHT for i in range(max_total+1)] for j in range(N+1)]
dp[0][0]=0
i = 0
for w, v in p:
    i += 1
    for target_val in range(0, max_total+1):
        
        if target_val-v >=0 and dp[i-1][target_val] > (dp[i-1][target_val-v]+w):
            dp[i][target_val] = dp[i-1][target_val-v]+w
        else:
            dp[i][target_val] = dp[i-1][target_val]
            
ret = 0
for v, w in enumerate(dp[N]):
    if w<=W and v>ret:
        ret = v
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
*D, = open(0)
n, m = map(int, D[0].split())
edges = [list(map(int, it.split())) for it in D[1:]]
edges = sorted(edges, key=lambda x:x[1])

cnt = 0
while len(edges)>0:
    cnt += 1
    new_edges = []
    bridge = edges[0][1]
    for it in edges:
        if it[0]>=bridge:
            new_edges.append(it)
            
    edges = new_edges
print(cnt)

Fixed submission:
*D, = open(0)
n, m = map(int, D[0].split())
edges = [list(map(int, it.split())) for it in D[1:]]
edges = sorted(edges, key=lambda x:x[1])

cnt = 0
while len(edges)>0:
    cnt += 1
    new_edges = []
    bridge = edges[0][1]
    for it in edges:
        if it[0]>=bridge:
            new_edges.append(it)
            
    edges = new_edges
print(cnt)