Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
N, K = map(int,input().split())

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

if N == K:
    print(1)
else:
    for i in range(K):
        if N-K < i-1:
            break
        print(comb(N-K+1, i+1)*comb(K-1, i) % 1000000007)

Fixed submission:
import math
N, K = map(int,input().split())

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))


for i in range(K):
    if N-K < i:
        print(0)
    else:
        print(comb(N-K+1, i+1)*comb(K-1, i) % 1000000007)

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

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

if N == K:
    print(1)
else:
    for i in range(K):
        print(comb(N-K+1, i+1)*comb(K-1, i) % 1000000007)

Fixed submission:
import math
N, K = map(int,input().split())

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))


for i in range(K):
    if N-K < i:
        print(0)
    else:
        print(comb(N-K+1, i+1)*comb(K-1, i) % 1000000007)

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

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

for i in range(K):
    print(comb(N-K+1, i+1)*comb(K-1, i) % 1000000007)

Fixed submission:
import math
N, K = map(int,input().split())

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))


for i in range(K):
    if N-K < i:
        print(0)
    else:
        print(comb(N-K+1, i+1)*comb(K-1, i) % 1000000007)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

def inverse(b, w, index, first):
    count = 0
    if first == '#':
        count = b[index//2 + 1] + w[-1] - w[(index + 1)//2]
    else:
        count = b[(index+1)//2] + w[-1] - w[index//2 + 1]
    return count

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

b = [0]
w = [0]
offset = 0
bsum = 0
wsum = 0
if first == '*':
    offset = 1
for i in range(len(num)):
    if i % 2 == offset:
        bsum += num[i]
        b.append(bsum)

offset = abs(offset -1)
for i in range(len(num)):
    if i % 2 == offset:
        wsum += num[i]
        w.append(wsum)

if len(num) == 1:
    print(0)
else:
    minlist = []
    minlist.append(sum(num[::2]))
    minlist.append(sum(num[1::2]))
    for i in range(len(num)):
        minlist.append(inverse(b, w, i, first))
    print(min(minlist))

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

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

if len(num) == 1:
    print(0)
else:
    b = 0
    w = n
    offset = 0
    if first == '#':
        offset = 1
    w = sum(num[offset::2])
    minlist = [b + w]
    for i in range(len(num)):
        if i % 2 == offset:
            w -= num[i]
        else:
            b += num[i]
        minlist.append(b + w)
    print(min(minlist))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

def inverse(b, w, index, first):
    if first == '#':
        count = b[index//2 + 1] + w[-1] - w[(index + 1)//2]
    else:
        count = b[(index+1)//2] + w[-1] - w[index//2 + 1]
    return count

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

b = [0]
w = [0]
offset = 0
bsum = 0
wsum = 0
if first == '*':
    offset = 1
for i in range(len(num)):
    if i % 2 == offset:
        bsum += num[i]
        b.append(bsum)

offset = abs(offset -1)
for i in range(len(num)):
    if i % 2 == offset:
        wsum += num[i]
        w.append(wsum)

if len(num) == 1:
    print(0)
else:
    minlist = []
    minlist.append(sum(num[::2]))
    minlist.append(sum(num[1::2]))
    for i in range(len(num)):
        minlist.append(inverse(b, w, i, first))
    print(min(minlist))



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

num = []
first = s[0]
end = s[-1]
pre = first
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        num.append(count)
        count = 1
        pre = c
num.append(count)

if len(num) == 1:
    print(0)
else:
    b = 0
    w = n
    offset = 0
    if first == '#':
        offset = 1
    w = sum(num[offset::2])
    minlist = [b + w]
    for i in range(len(num)):
        if i % 2 == offset:
            w -= num[i]
        else:
            b += num[i]
        minlist.append(b + w)
    print(min(minlist))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

first = s[0]
end = s[-1]
len_list = []

count = 0
pre = first
for i in range(n):
    if s[i] == pre:
        count += 1
    else:
        len_list.append(count)
        pre = s[i]
        count = 1
len_list.append(count)

size = len(len_list)

if size < 2*k + 1:
    print(n)
else:
    ans = 0
    index = 0
    if first == '0':
        index = 1
        ans = sum(len_list[:2*k])
    if end == '0':
        ans = max(sum(len_list[size-2*k:]), ans)

    while index + 2 * k < size:
        ans = max(ans, sum(len_list[index: index+2*k+1]))
        index += 2

    print(ans)

Fixed submission:
n, k = map(int, input().split())
s = input()

first = s[0]
end = s[-1]
len_list = []

count = 0
pre = first
for i in range(n):
    if s[i] == pre:
        count += 1
    else:
        len_list.append(count)
        pre = s[i]
        count = 1
len_list.append(count)
sum_list = [0]
sum_tmp = 0
for i in len_list:
    sum_tmp += i
    sum_list.append(sum_tmp)

size = len(len_list)

if size < 2*k + 1:
    print(n)
else:
    ans = 0
    index = 0
    if first == '0':
        index = 1
        ans = sum_list[2*k] - sum_list[0]
    if end == '0':
        ans = max((sum_list[size] - sum_list[size-2*k]), ans)

    while index + 2 * k < size:
        ans = max(ans, (sum_list[index+2*k+1] - sum_list[index]))
        index += 2

    print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
s2 = ''
for c in s:
    if c in ('A','T','C','G'):
        s2 += '1'
    else:
        s2 += '0'

print(s,s2)

tmp = 0
ret = 0
    if c == '1':
        tmp += 1
    else:
        ret = max(ret, tmp)
        tmp = 0
ret = max(ret, tmp)
print(ret)


Fixed submission:
s = input()
s2 = ''
for c in s:
    if c in ('A','T','C','G'):
        s2 += '1'
    else:
        s2 += '0'


tmp = 0
ret = 0
for c in s2:
    if c == '1':
        tmp += 1
    else:
        ret = max(ret, tmp)
        tmp = 0
ret = max(ret, tmp)
print(ret)
Buggy python submission (verdict: Runtime Error):
import bisect
N, Q = map(int, input().split())
s = input()
AC = []
for i in range(len(s)):
    if s[i] == 'A':
        if s[i+1] == 'C':
            AC.append(i)

for _ in range(Q):
    l, r = map(int, input().split())
    a = bisect.bisect_left(AC, l-1)
    b = bisect.bisect_right(AC, r-2)
    print(b-a)

Fixed submission:
import bisect
N, Q = map(int, input().split())
s = input()
AC = []
length = len(s)
for i in range(length):
    if s[i] == 'A':
        if i != length-1 and s[i+1] == 'C':
            AC.append(i)

for _ in range(Q):
    l, r = map(int, input().split())
    a = bisect.bisect_left(AC, l-1)
    b = bisect.bisect_right(AC, r-2)
    print(b-a)
Buggy python submission (verdict: Runtime Error):
import numpy as np
A, B = map(int, input().split())

pre = A
for b in np.arange(A+1, B+1):
    pre = pre ^ b
print(pre)

Fixed submission:
import numpy as np

def f(x):
    fm = x - (x % 4) - 1 
    ans = 0
    while fm < x:
        fm += 1
        ans ^= fm
    return ans

A,B = map(int, input().split())
print(f(A-1) ^ f(B))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

if K % 2 == 0:
	ans1 = N // K
	if (N % K) >= (K // 2):
		ans2 = ans1 + 1
	else:
		ans2 = ans1s
	ans = (ans1 ** 3) + (ans2 ** 3)
else:
	ans = (N // K)**3

print(ans)

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

if K % 2 == 0:
	ans1 = N // K
	if (N % K) >= (K // 2):
		ans2 = ans1 + 1
	else:
		ans2 = ans1
	ans = (ans1 ** 3) + (ans2 ** 3)
else:
	ans = (N // K)**3

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())

a = np.zeros((M,2))

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

a = a[np.argsort(a[:,1])[::-1]]

prev = 0

a_max = 0
index = M
del_list = []
for i tmp in enumerate(a):
	if tmp[1] == prev:
		if tmp[0] > a_max:
			del_list.append(index)
			index = i
			a_max = tmp[0]
		else:
			del_list.append(i)
	else:
		prev = tmp[1]
		if tmp[0] > a_max:
			del_list.append(index)
			index = i
			a_max = tmp[0]
		elif a_max >= tmp[1]:
			a_max = tmp[0]
		else:
			del_list.append(i)
del del_list[0]
a = np.delete(a, del_list, 0)

prev = 0
b_min = N+1
index = M
del_list = []
for i, tmp in enumerate(a):
	if tmp[0] == prev:
		if tmp[1] < b_min:
			del_list.append(index)
			index = i
			b_min = tmp[1]
		else:
			del_list.append(i)
	else:
		prev = tmp[0]
		if tmp[1] < b_min:
			del_list.append(index)
			index = i
			b_min = tmp[1]
		elif b_min <= tmp[0]:
			b_min = tmp[1]
		else:
			del_list.append(i)
del del_list[0]
a = np.delete(a, del_list, 0)


a = a[np.argsort(a[:,0])]

prev = 0
b_min = N+1
index = M
del_list = []
for i, tmp in enumerate(a):
	if tmp[0] == prev:
		if tmp[1] < b_min:
			del_list.append(index)
			index = i
			b_min = tmp[1]
		else:
			del_list.append(i)
	else:
		prev = tmp[0]
		if tmp[1] < b_min:
			del_list.append(index)
			index = i
			b_min = tmp[1]
		elif b_min <= tmp[0]:
			b_min = tmp[1]
		else:
			del_list.append(i)
del del_list[0]
a = np.delete(a, del_list, 0)



ans = 0
flg = True
for i in range(len(a[:,0])-1):
	if a[i,1] > a[i+1, 0]:
		ans += 1
		flg = False
	elif flg:
		ans += 1
		flg = True
	else:
		flg = True
if flg:
	ans += 1
print(ans)


Fixed submission:
import numpy as np
N, M = map(int, input().split())

a = np.zeros((M,2))

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

a = a[np.argsort(a[:,1])]

index = 0
ans = 0
for tmp in a:
	if tmp[0] <= index:
		continue
	else:
		ans += 1
		index = tmp[1] - 1

print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a > 8 or b > 8:
	print(':(')
else:
	print('Yey!')

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

if a > 8 or b > 8:
	print(':(')
else:
	print('Yay!')

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a > 8 or b > 8:
	print(':(')
else:
	print('Yey!')

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

if a > 8 or b > 8:
	print(':(')
else:
	print('Yay!')

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a > 8 or b > 8:
	print(':(')
else:
	print('Yey!')

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

if a > 8 or b > 8:
	print(':(')
else:
	print('Yay!')

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a > 8 or b > 8:
		print(':(')
else:
		print('Yey!')

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

if a > 8 or b > 8:
	print(':(')
else:
	print('Yay!')

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a > 8 or b > 8:
		print(':(')
else:
		print('Yey!')

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

if a > 8 or b > 8:
	print(':(')
else:
	print('Yay!')

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a > 8 or b > 8:
		print(':(')
else:
		print('Yey!')

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

if a > 8 or b > 8:
	print(':(')
else:
	print('Yay!')
Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())

se = set()
for i in range(1,min(len(s)+1, K)):
	for j in range(len(s)-i+1):
		se.add(s[j:j+i])
print(sorted(list(se))[K-1])

Fixed submission:
a,b,c,d = map(int, input().split())

if abs(a-c) <= d:
	print('Yes')
elif abs(a-b) <= d and abs(b-c) < d:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

se = set()
for i in range(1,len(s)+1):
	for j in range(len(s)-i+1):
		se.add(s[j:j+i])
print(sorted(list(se))[K-1])

Fixed submission:
s = input()
K = int(input())

se = set()
for i in range(1,min(len(s)+1,K+1)):
	for j in range(len(s)-i+1):
		se.add(s[j:j+i])
print(sorted(list(se))[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
#python 3.5.2

N, M = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
choiced = [bc[1] for bc in [[int(j) for j in input().split()] for i in range(M)] for i in range(bc[0])]
choiced = choiced + As
choiced = sorted(choiced, reverse=True)
print(sum(choiced[:N]))

Fixed submission:
#python 3.5.2

N, M = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
BCs = [[int(j) for j in input().split()] for i in range(M)]
BCs += [[1, a] for a in As]
BCs = sorted(BCs, key=lambda x: x[1], reverse=True)
cnt = 0
sum = 0
for b, c in BCs:
    if N < cnt + b:
        sum += (N - cnt)*c
        break
    else:
        sum += b*c
        cnt += b
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
#python 3.5.2

N, M = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
BCs = [[int(j) for j in input().split()] for i in range(M)]

#LRs = list(map(list, zip(*LRs)))  # 転置

choiced = [bc[1] for bc in BCs for i in range(bc[0])]
choiced = choiced + As
choiced = sorted(choiced)[::-1]
print(sum(choiced[:N]))

Fixed submission:
#python 3.5.2

N, M = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
BCs = [[int(j) for j in input().split()] for i in range(M)]
BCs += [[1, a] for a in As]
BCs = sorted(BCs, key=lambda x: x[1], reverse=True)
cnt = 0
sum = 0
for b, c in BCs:
    if N < cnt + b:
        sum += (N - cnt)*c
        break
    else:
        sum += b*c
        cnt += b
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *

def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    n, m = read_int_array()
    nums = read_int_array()

    heapify(nums)
    for _ in range(m):
        b, c = read_int_array()
        while b and nums[0] < c:
            heapreplace(nums, c)
            b -= 1
    write(sum(nums))

main()


Fixed submission:
from heapq import *

def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    n, m = read_int_array()
    nums = read_int_array()

    heapify(nums)
    ops = [None]*m
    for i in range(m):
        b, c = read_int_array()
        ops[i] = (c, b)
    ops.sort(reverse=True)

    done = []
    for c, b in ops:
        while b and nums and nums[0] < c:
            heappop(nums)
            done.append(c)
            b -= 1
        if not nums or nums[0] >= c:
            break
    write(sum(nums) + sum(done))

main()
Buggy python submission (verdict: Runtime Error):
n=input()
l=[map(int,input().strip().split())]
ans=0
for i in range(1,len(l)-2):
  gc=0;
  lc=0;
  if(l[i] >l[i-1] or l[i]>l[i+1]):
    gc=1
  if(l[i] <l[i-1] or l[i]<l[i+1]):
    lc=1
   ans+=gc & lc

Fixed submission:
n=input()
l=list(map(int,input().strip().split()))
ans=0
for i in range(1,len(l)-1):
  gc=0;
  lc=0;
  if(l[i] >l[i-1] or l[i]>l[i+1]):
    gc=1
  if(l[i] <l[i-1] or l[i]<l[i+1]):
    lc=1
  ans+=(gc & lc)
  #print(gc,lc,l[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
  if(y==0):
  	return x
  if(x<y):
    x,y=y,x
  return gcd(y,x % y)
def lllen(a,b,c):
  at=a//c
  at=at*c
  b=b//c *c
  ansc=0
  while(at<a):
    at+=c
  ansc=b-at
  if ansc<0 :
  	ansc=0
  else:
  	ansc=ansc//c + 1
  	return ansc

a,b,c,d=map(int , input().strip().split() )
tl=b-a+1

ansc=lllen(a,b,c)
ansd=lllen(a,b,d)
ansl=lllen(a,b,(c*d)//gcd(c,d))
#print(ansc,ansl,ansd)
print(b-a+1 -ansc -ansd + ansl)


  

Fixed submission:
def gcd(x,y):
  if(y==0):
  	return x
  if(x<y):
    x,y=y,x
  return gcd(y,x % y)
def lllen(a,b,c):
  at=a//c
  at=at*c
  b=b//c *c
  ansc=0
  while(at<a):
    at+=c
  ansc=b-at
  if ansc<0 :
  	ansc=0
  else:
  	ansc=ansc//c + 1
  return ansc

a,b,c,d=map(int , input().strip().split() )
tl=b-a+1

ansc=lllen(a,b,c)
ansd=lllen(a,b,d)
ansl=lllen(a,b,(c*d)//gcd(c,d))
#print(ansc,ansl,ansd)
print(b-a+1 -ansc -ansd + ansl)

Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
  if(y==0):
  	return x
  if(x<y):
    x,y=y,x
  return gcd(y,x % y)
def lllen(a,b,c):
  at=a//c
  at=at*c
  b=b//c *c
  ansc=0
  while(at<a):
    at+=c
  ansc=b-at
  if ansc<0 :
  	ansc=0
  else:
  	ansc=ansc//c + 1
  	return ansc

a,b,c,d=map(int , input().strip().split() )
tl=b-a+1

ansc=lllen(a,b,c)
ansd=lllen(a,b,d)
ansl=lllen(a,b,(c*d)//gcd(c,d))
print(ansc,ansl,ansd)
print(b-a+1 -ansc -ansd + ansl)


  

Fixed submission:
def gcd(x,y):
  if(y==0):
  	return x
  if(x<y):
    x,y=y,x
  return gcd(y,x % y)
def lllen(a,b,c):
  at=a//c
  at=at*c
  b=b//c *c
  ansc=0
  while(at<a):
    at+=c
  ansc=b-at
  if ansc<0 :
  	ansc=0
  else:
  	ansc=ansc//c + 1
  return ansc

a,b,c,d=map(int , input().strip().split() )
tl=b-a+1

ansc=lllen(a,b,c)
ansd=lllen(a,b,d)
ansl=lllen(a,b,(c*d)//gcd(c,d))
#print(ansc,ansl,ansd)
print(b-a+1 -ansc -ansd + ansl)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=1000000009;
for t in range(1,n+1):
  ans=min(ans,abs(sum(l[:t]) - sum(l[t:]))
print(ans)

Fixed submission:
n=int(input().strip())
l=list(map(int,input().strip().split()))
ans=1000000009;
for t in range(1,n):
  ans=min(ans,abs(sum(l[:t]) - sum(l[t:])))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N = 1:
    print('Hello World')

else:
    A = int(input())
    B = int(input())

    print(A+B)

Fixed submission:
N=int(input())

if N == 1:
    print('Hello World')

if N == 2:
    A=int(input())
    B=int(input())

    print(A+B)

Buggy python submission (verdict: Runtime Error):
age=input()
if age==1:
  print('Hello World')
 
else:
  A=int(input())
  B=int(input())
  print(A+B)

Fixed submission:
N=int(input())

if N == 1:
    print('Hello World')

if N == 2:
    A=int(input())
    B=int(input())

    print(A+B)
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
array = [[0] * (W+1) for i in range((N+1))]
for i in range(N):
  wei,V = map(int,input().split())
  for j in range(W):
    if(wei<=j+1):
      if(array[i][j] < array[i][j-wei+1]+V):
        array[i+1][j+1]=array[i][j-wei+1]+V
      else:
        array[i+1][j+1]=array[i][j+1]
    else:
      array[i+1][j+1]=array[i][j+1]
print(array[N][W])

Fixed submission:
N,W = map(int,input().split())
array = [[0] * (W+1) for i in range((N+1))]
for i in range(N):
  wei,V = map(int,input().split())
  for j in range(W):
    if(wei<=j+1):
      if(array[i][j] < array[i][j-wei+1]+V):
        array[i+1][j+1]=array[i][j-wei+1]+V
      else:
        array[i+1][j+1]=array[i][j+1]
    else:
      array[i+1][j+1]=array[i][j+1]
print(array[N][W])

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
array = [[0] * (W+1) for i in range((N+1))]
for i in range(N):
  wei,V = map(int,input().split())
  for j in range(W,wei-1,-1):
    if(wei<=j+1):
      if(array[i][j] < array[i][j-wei+1]+V):
        array[i+1][j+1]=array[i][j-wei+1]+V
      else:
        array[i+1][j+1]=array[i][j+1]
    else:
      array[i+1][j+1]=array[i][j+1]
print(array[N][W])

Fixed submission:
N,W = map(int,input().split())
array = [[0] * (W+1) for i in range((N+1))]
for i in range(N):
  wei,V = map(int,input().split())
  for j in range(W):
    if(wei<=j+1):
      if(array[i][j] < array[i][j-wei+1]+V):
        array[i+1][j+1]=array[i][j-wei+1]+V
      else:
        array[i+1][j+1]=array[i][j+1]
    else:
      array[i+1][j+1]=array[i][j+1]
print(array[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
array = [[0] * (W+1) for i in range((N+1))]
for i in range(N):
  wei,V = map(int,input().split())
  for j in range(W):
    if(wei<=j+1):
      if(array[i][j] < array[i][j-wei+1]+V):
        array[i+1][j+1]=array[i][j-wei+1]+V
      else:
        array[i+1][j+1]=array[i][j+1]
    else:
      array[i+1][j+1]=array[i][j+1]
print(array[N][W])

Fixed submission:
N,W = map(int,input().split())
array = [[0] * (W+1) for i in range((N+1))]
for i in range(N):
  wei,V = map(int,input().split())
  for j in range(W):
    if(wei<=j+1):
      if(array[i][j] < array[i][j-wei+1]+V):
        array[i+1][j+1]=array[i][j-wei+1]+V
      else:
        array[i+1][j+1]=array[i][j+1]
    else:
      array[i+1][j+1]=array[i][j+1]
print(array[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
def enter_card(card, L, R):
    for k in range(L-1,R):
        card[k] += 1
    return card

def open_list(a, M):
    b = []
    for (index, i) in enumerate(a):
        if i == M:
            b.append(index)
    return b

N, M = map(int, input().split(' '))
idcard = [0 for i in range(N)]
for i in range(M):
    L,  R = map(int, input().split(' '))
    idcard = enter_card(idcard, L, R)
a = open_list(idcard, M)
print(len(a))

Fixed submission:
def enter_card(L, R, f_point, e_point):
    if f_point < L:
        f_point = L
    if e_point > R:
        e_point = R
    return f_point, e_point

def open_list(L, R):
    if L > R:
        return 0
    else:
        return R - L + 1
   

N, M = map(int, input().split(' '))
f_point = 1
e_point = N
for i in range(M):
    L,  R = map(int, input().split(' '))
    f_point, e_point = enter_card(L, R, f_point, e_point)
a = open_list(f_point, e_point)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))
A = []
for i in range(N):
    a, b = map(int, input().split(' '))
    A.append([a]*b)
A.sort()
A = [i for v in A for i in v]
print(A[M-1])


Fixed submission:
N, M = map(int, input().split(' '))
A = []
for i in range(N):
    a, b = map(int, input().split(' '))
    A.append([a, b])
A.sort()
i = -1
count=0
while(True):
    i += 1
    count += A[i][1]
    if count >= M:
        print(A[i][0])
        break
Buggy python submission (verdict: Runtime Error):
N=int(input())
d=[int(input().sprit())]
d.sort()
print(d[N]-d[N-1])

Fixed submission:
N=int(input())
x=int(N/2)
d=[int(x) for x in (input().split())]
d.sort()
print(d[x]-d[x-1])