ZhenlongDai/ACPR huggingface dataset:
Problem: p02589
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys;input=sys.stdin.readline
N, = map(int, input().split())
MOD=998244353
S = []
for _ in range(N):
    s = input().strip()
    S.append(s)
S.sort(key=lambda x:len(x))
D = dict()
dd = set()
R = 0
for s in S:
    l = len(s)
    d = [0]*26
    for c in dd:
        d[c] += 1
    tmp=0
    for i in range(l-1, -1, -1):
        ee = ord(s[i]) - 97
        tmp = 100*tmp+ee
        R += d[ee]
        d[ee] = 0
        if tmp in D:
            for c in D[tmp]:
                d[c] += 1
        if i == 1:
            nn = tmp
    if l != 1:
        if nn not in D:
            D[nn] = set()
        D[nn].add(ee)
    else:
        dd.add(ee)
print(R)


Failing test case input:
3
cybxxa
cyw
baa

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import sys;input=sys.stdin.readline
N, = map(int, input().split())
MOD=67280421310721
S = []
for _ in range(N):
    s = input().strip()
    S.append(s)
S.sort(key=lambda x:len(x))
D = dict()
dd = set()
R = 0
for s in S:
    l = len(s)
    d = [0]*26
    for c in dd:
        d[c] += 1
    tmp=0
    for i in range(l-1, -1, -1):
        ee = ord(s[i]) - 97
        tmp = 100*tmp+(ee+1)
        tmp %= MOD
        R += d[ee]
        d[ee] = 0
        if tmp in D:
            for c in D[tmp]:
                d[c] += 1
        if i == 1:
            nn = tmp
    if l != 1:
        if nn not in D:
            D[nn] = set()
        D[nn].add(ee)
    else:
        dd.add(ee)
print(R)
Problem: p02404
Buggy submission (Python3, verdict: Wrong Answer):
def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a
 
def main():
    while True:
        a = numinput()
        if a[0] == 0 and a[1] == 0: break
        H = a[0];  W = a[1]
        for i in range(H):
            bar = ""
            for j in range(W):
                if i > 0 and i < H - 1 and j > 0 and j < W - 1: bar += "."
                else: bar += "*"
            if i < H - 1: print(bar)
            else: print(bar + '\n')
 
if __name__ == "__main__":
    main()


Failing test case input:
3 8
4 10
4 4
0 0

Expected output:
########
#......#
########

##########
#........#
#........#
##########

####
#..#
#..#
####



Actual output:
********
*......*
********

**********
*........*
*........*
**********

****
*..*
*..*
****



Fixed submission (verdict: Accepted):
def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a
  
def main():
    while True:
        a = numinput()
        if a[0] == 0 and a[1] == 0: break
        H = a[0];  W = a[1]
        for i in range(H):
            bar = ""
            for j in range(W):
                if i > 0 and i < H - 1 and j > 0 and j < W - 1: bar += "."
                else: bar += "
            if i < H - 1: print(bar)
            else: print(bar + '\n')
  
if __name__ == "__main__":
    main()
Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
for i in a:
    if x - i >= 0:
        x -= i
        ans += 1
    else:
        break
print(ans)

Failing test case input:
3 66
20 30 9

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
if sum(a) == x:
    ans = n
elif sum(a) < x:
    ans = n - 1
else:
    for i in range(n):
        if a[i] <= x:
            ans += 1
            x -= a[i]
print(ans)

Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
res = 0
for a in A:
    if a > X:
        break
    res += 1
    X -= a
if X > 0:
    res -= 1
print(max(res, 0))

Failing test case input:
2 9
20 1 10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
res = 0
for a in A:
    if a > X:
        break
    res += 1
    X -= a
else:
    if X > 0:
        res -= 1
print(max(res, 0))

Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x = map(int,input().split())
a = list(map(int,input().split()))

a.sort()

if x<a[0]:
    print(0)
    exit()

for i in range(N):
    x = x - a[i]
    if x <=0:
        print(i+1)
        exit()
print(N-1)
    

Failing test case input:
4 1101
1 2 110 1000

Expected output:
3


Actual output:
4


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

a.sort()


for i in range(N):
    if x<a[i]:
        print(i)
        exit()
    elif x == a[i]:
        print(i+1)
        exit()
    else:
        x = x - a[i]
    
print(N-1)

Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.sort()
count=0
for i in range(n):
  x-=a[i]
  if x>=0:
      count+=1
      
print(count)

Failing test case input:
3 70
20 39 3

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.sort()
count=0
for i in range(n):
  x-=a[i]
  if x>=0 and i<n-1:
      count+=1
  elif x==0 and i==n-1:
      count+=1
  
print(count)

Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int, input().split())
l=sorted(list(map(int, input().split())))
ans=0
if x==sum(l):
  print(n)
elif x>sum(l):
  print(n-1)
else:
  for i in range(n):
    if x-l[i]>=0:
      ans+=1
    else:
      print(ans)
      exit()
  print(ans-1)    
 

Failing test case input:
3 10
20 4 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n,x=map(int, input().split())
l=sorted(list(map(int, input().split())))
ans=0
if x==sum(l):
  print(n)
elif x>sum(l):
  print(n-1)
else:
  for i in range(n):
    if x>=l[i]:
      ans+=1
      x=x-l[i]
    else:
      print(ans)
      exit()
Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x=[int(i) for i in input().split()]
a = [int(x) for x in input().split()]
a.sort()
cnt=0
for k in range(N):
	if x-a[k] >= 0:
		x -= a[k]
		cnt += 1		
	else:
		break
if x>0:
	cnt -= 1
print(cnt)

Failing test case input:
3 70
29 39 3

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N,x=[int(i) for i in input().split()]
a = [int(x) for x in input().split()]
a.sort()
cnt=0
for k in a:
	x -= k
	if x < 0:
		break
	cnt +=1
if x >0:
	cnt -=1
print(cnt)

Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int,input().split())
li = list(map(int,input().split()))

li.sort()
ans = 0

for i in range(n):
    x =  x-li[i]
    if x < 0:
        ans = i
        break
    ans = i+1
print(ans)


Failing test case input:
3 70
4 24 5

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n, x = map(int,input().split())
li = list(map(int,input().split()))

li.sort()
ans = 0

for i in range(n):
    x = x-li[i]
    if x < 0:
        ans = i
        break
    ans = i+1

if x > 0:
    ans -=1

print(ans)

Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x=[int(i) for i in input().split()]
a = [int(x) for x in input().split()]
a.sort()
cnt=0
for k in range(N):
	if x-a[k] >= 0:
		x -= a[k]
		cnt += 1
	else:
		break
print(cnt)

Failing test case input:
3 70
4 17 5

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N,x=[int(i) for i in input().split()]
a = [int(x) for x in input().split()]
a.sort()
cnt=0
for k in a:
	x -= k
	if x < 0:
		break
	cnt +=1
if x >0:
	cnt -=1
print(cnt)

Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, x = map(int, input().split())
alist = list(map(int, input().split()))

max = 0
for i in range(1, N + 1):
  if sum(sorted(alist)[:i]) <= x:
    max = i
print(max)

Failing test case input:
3 24
0 2 5

Expected output:
2


Actual output:
3


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

a.sort()
max = 0
for i in range(1, N + 1):
  if sum(a[:i]) <= x:
    max = i
if sum(a[:N + 1]) < x:
  print(N - 1)
else:
  print(max)
Problem: p03254
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
if __name__ == "__main__":
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    if sum(a) == x:
        print(n)
        exit()

    a.sort()

    ans = 0
    tmp = 0
    for aa in a:
        if tmp < x and aa <= x-tmp:
            tmp += aa
            ans += 1
        if tmp == x:
            print(ans)
            exit()
    if x-tmp > 0:
        ans -= 1

    print(ans)


Failing test case input:
2 10
29 20

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
if __name__ == "__main__":
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    if sum(a) == x:
        print(n)
        exit()

    a.sort()

    ans = 0
    for i in range(n):
        if sum(a[:i+1]) <= x:
            ans = i+1
        else:
            print(i)
            exit()

    if sum(a[:ans]) == x:
        print(ans)
    else:
        print(ans-1)
Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):
def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i += 1
            tmp = a[i]
            a[i] = a[j]
            a[j] = tmp
    tmp = a[i+1]
    a[i+1] = a[r]
    a[r] = tmp
    return i + 1, x


def print_list_split_whitespace(a, x):
    flag = False
    for y in a[:-1]:
        if x != y:
            print(y, end=" ")
        else:
            print("[" + str(y) + "]", end=" ")
            flag = True
    if flag:
        print(a[-1])
    else:
        print("[" + str(a[-1]) + "]", end=" ")


n = int(input())
a = [int(x) for x in input().split()]

q, x = partition(a, 0, n - 1)

print_list_split_whitespace(a, x)


Failing test case input:
12
40 19 9 1 12 8 8 6 21 0 10 1

Expected output:
1 0 [1] 40 12 8 8 6 21 19 10 9


Actual output:
[1] 0 [1] 40 12 8 8 6 21 19 10 9


Fixed submission (verdict: Accepted):
def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i += 1
            tmp = a[i]
            a[i] = a[j]
            a[j] = tmp
    tmp = a[i+1]
    a[i+1] = a[r]
    a[r] = tmp
    return i + 1, x


def print_list_split_whitespace(a, x):
    ind = 0
    for i, y in enumerate(a):
        if x == y:
            ind = i
    for i in range(len(a) - 1):
        if i == ind:
            print("[" + str(a[i]) + "]", end=" ")
        else:
            print(a[i], end=" ")
    if ind == len(a) - 1:
        print("[" + str(a[-1]) + "]")
    else:
        print(a[-1])


n = int(input())
a = [int(x) for x in input().split()]

q, x = partition(a, 0, n - 1)

print_list_split_whitespace(a, x)
Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):



def partition(target_list):
    x = target_list[-1]
    i = -1

    for j in range(len(target_list))[:-1]:
        if target_list[j] <= x:
            i = i+1
            tmp = target_list[i]
            target_list[i] = target_list[j]
            target_list[j] = tmp
    tmp = target_list[-1]
    target_list[-1] = target_list[i + 1]
    target_list[i + 1] = tmp
    
    return  i + 1

def convert(l):
    return " ".join([str(n) for n in l])

if __name__ == "__main__":
    n_list = int(input())
    target_list = [int(n) for n in input().split()]

    center_index = partition(target_list)
    print(convert(target_list[:center_index]) + " ["+ str(target_list[center_index]) + "] " + convert(target_list[center_index:]))

Failing test case input:
12
23 19 9 9 23 8 10 4 13 -1 10 22

Expected output:
19 9 9 8 10 4 13 -1 10 [22] 23 23


Actual output:
19 9 9 8 10 4 13 -1 10 [22] 22 23 23


Fixed submission (verdict: Accepted):



def partition(target_list):
    x = target_list[-1]
    i = -1

    for j in range(len(target_list))[:-1]:
        if target_list[j] <= x:
            i = i+1
            tmp = target_list[i]
            target_list[i] = target_list[j]
            target_list[j] = tmp
    tmp = target_list[-1]
    target_list[-1] = target_list[i + 1]
    target_list[i + 1] = tmp
    
    return  i + 1

def convert(l):
    return " ".join([str(n) for n in l])

if __name__ == "__main__":
    n_list = int(input())
    target_list = [int(n) for n in input().split()]

    center_index = partition(target_list)
    print(convert(target_list[:center_index]) + " ["+ str(target_list[center_index]) + "] " + convert(target_list[center_index + 1:]))

Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x :
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

b = partition(A, 0, n-1)
A[b] = '[{0}]'.format(b)
print(' '.join(map(str, A)))


Failing test case input:
12
40 19 9 1 12 8 8 6 21 0 10 22

Expected output:
19 9 1 12 8 8 6 21 0 10 [22] 40


Actual output:
19 9 1 12 8 8 6 21 0 10 [10] 40


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x :
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

b = partition(A, 0, n-1)
A[b] = '[{0}]'.format(A[b])
print(' '.join(map(str, A)))
Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
lst_n = list(map(int,input().split()))
x = lst_n[n-1]
left  = []
right = []
i = -1
for j in range(0,n-1):
    if lst_n[j] <= x:
        i += 1
        lst_n[i],lst_n[j] = lst_n[j],lst_n[i]
i += 1
lst_n[i],lst_n[n-1] = lst_n[n-1],lst_n[i]

ans = ['['+str(k)+']' if k == x else str(k) for k in lst_n]
print(' '.join(ans))


Failing test case input:
12
40 19 9 1 12 8 8 6 21 0 10 1

Expected output:
1 0 [1] 40 12 8 8 6 21 19 10 9


Actual output:
[1] 0 [1] 40 12 8 8 6 21 19 10 9


Fixed submission (verdict: Accepted):
n = int(input())
lst_n = list(map(int,input().split()))
x = lst_n[n-1]
left  = []
right = []
i = -1
for j in range(0,n-1):
    if lst_n[j] <= x:
        i += 1
        lst_n[i],lst_n[j] = lst_n[j],lst_n[i]
i += 1
lst_n[i],lst_n[n-1] = lst_n[n-1],lst_n[i]

ans = ['['+str(lst_n[k])+']' if k == i else str(lst_n[k])
        for k in range(len(lst_n))]
print(' '.join(ans))

Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

i = partition(A, 0, n-1)
print(' '.join(map(str, A[:i])) + ' [' + str(A[i]) + '] ' + ' '.join(map(str, A[i:])))

Failing test case input:
12
74 19 6 2 12 7 0 5 21 -1 10 22

Expected output:
19 6 2 12 7 0 5 21 -1 10 [22] 74


Actual output:
19 6 2 12 7 0 5 21 -1 10 [22] 22 74


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

i = partition(A, 0, n-1)
print(' '.join(map(str, A[:i])) + ' [' + str(A[i]) + '] ' + ' '.join(map(str, A[i+1:])))

Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):



def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i]
    return i + 1


def main():
    n = int(input())
    A = [int(e) for e in input().split()]
    p = 0
    r = len(A) - 1
    idx = partition(A, p, r)
    A = [str(e) for e in A]
    A[idx] = "[{}]".format(A[idx])
    return " ".join(A)


main()

Failing test case input:
12
13 19 9 5 12 8 7 4 21 2 10 11

Expected output:
9 5 8 7 4 2 10 [11] 21 13 19 12


Actual output:

Fixed submission (verdict: Accepted):



def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def main():
    n = int(input())
    A = [int(e) for e in input().split()]
    p = 0
    idx = partition(A, p, n - 1)
    A = [str(e) for e in A]
    A[idx] = "[{}]".format(A[idx])
    return " ".join(A)


print(main())
Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):
def partition(array, p, r):
    x = array[r]
    i = p-1
    for j in range(p, r):
        if array[j] <= x:
            i += 1
            array[i], array[j] = array[j], array[i]
    array[i+1], array[r] = array[r], array[i+1]
    a1 = array[:i+1]
    a2 = "[" + str(array[i+1]) +  "]"
    a3 = array[i+1:]
    array = a1[:]
    array.append(a2)
    array += a3
    print(*array)
    return i+1

n = int(input())
array = [int(a) for a in input().split()]
p = partition(array, 0, n-1)


Failing test case input:
12
63 19 22 2 12 11 0 5 21 -1 0 37

Expected output:
19 22 2 12 11 0 5 21 -1 0 [37] 63


Actual output:
19 22 2 12 11 0 5 21 -1 0 [37] 37 63


Fixed submission (verdict: Accepted):
def partition(array, p, r):
    x = array[r]
    i = p-1
    for j in range(p, r):
        if array[j] <= x:
            i += 1
            array[i], array[j] = array[j], array[i]
    array[i+1], array[r] = array[r], array[i+1]
    a1 = array[:i+1]
    a2 = "[" + str(array[i+1]) +  "]"
    a3 = array[i+2:]
    array = a1[:]
    array.append(a2)
    array += a3
    print(*array)
    return i+1

n = int(input())
array = [int(a) for a in input().split()]
p = partition(array, 0, n-1)

Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):



def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i]
    return i + 1


def main():
    n = int(input())
    A = [int(e) for e in input().split()]
    p = 0
    idx = partition(A, p, n - 1)
    A = [str(e) for e in A]
    A[idx] = "[{}]".format(A[idx])
    return " ".join(A)


print(main())

Failing test case input:
12
40 19 6 1 12 8 0 2 21 2 4 22

Expected output:
19 6 1 12 8 0 2 21 2 4 [22] 40


Actual output:
19 6 1 12 8 0 2 21 2 4 [22] 4


Fixed submission (verdict: Accepted):



def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def main():
    n = int(input())
    A = [int(e) for e in input().split()]
    p = 0
    idx = partition(A, p, n - 1)
    A = [str(e) for e in A]
    A[idx] = "[{}]".format(A[idx])
    return " ".join(A)


print(main())
Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):
def partition(A,p,r):
    x=A[r]
    i=p-1
    for j in range(p,r):
        if A[j]<x:
            i+=1
            A[i],A[j]=A[j],A[i]
    A[i+1],A[r]=A[r],A[i+1]
    return i+1

n=int(input())
A=list(map(int,input().split()))
k=partition(A,0,len(A)-1)
front=" ".join(map(str,A[:k]))
back=" ".join(map(str,A[k+1:]))
ans=front+" ["+str(A[k])+"] "+back
print(ans)


Failing test case input:
12
40 19 9 1 12 8 8 6 21 0 10 1

Expected output:
1 0 [1] 40 12 8 8 6 21 19 10 9


Actual output:
0 [1] 9 1 12 8 8 6 21 40 10 19


Fixed submission (verdict: Accepted):
def partition(A,p,r):
    x=A[r]
    i=p-1
    for j in range(p,r):
        if A[j]<=x:
            i+=1
            A[i],A[j]=A[j],A[i]
    A[i+1],A[r]=A[r],A[i+1]
    return i+1

n=int(input())
A=list(map(int,input().split()))
k=partition(A,0,len(A)-1)
front=" ".join(map(str,A[:k]))
back=" ".join(map(str,A[k+1:]))
ans=front+" ["+str(A[k])+"] "+back
print(ans)

Problem: p02276
Buggy submission (Python3, verdict: Wrong Answer):
def partition(array, p, r):
    x = array[r]
    i = p-1
    for j in range(p, r):
        if array[j] <= x:
            i += 1
            array[i], array[j] = array[j], array[i]
    array[i+1], array[r] = array[r], array[i+1]
    return i+1

n = int(input())
array = [int(a) for a in input().split()]
buff = array[:]
p = partition(array, 0, n-1)

for a in array:
    if a == buff[-1]:
        print("[{0}]".format(a), end=" ")
    elif a == array[-1]:
        print(a)
    else:
        print(a, end=" ")


Failing test case input:
12
23 19 9 9 23 8 7 4 13 -1 10 22

Expected output:
19 9 9 8 7 4 13 -1 10 [22] 23 23


Actual output:
19 9 9 8 7 4 13 -1 10 [22] 23
23


Fixed submission (verdict: Accepted):
def partition(array, p, r):
    x = array[r]
    i = p-1
    for j in range(p, r):
        if array[j] <= x:
            i += 1
            array[i], array[j] = array[j], array[i]
    array[i+1], array[r] = array[r], array[i+1]
    a1 = array[:i+1]
    a2 = "[" + str(array[i+1]) +  "]"
    a3 = array[i+2:]
    array = a1[:]
    array.append(a2)
    array += a3
    print(*array)
    return i+1

n = int(input())
array = [int(a) for a in input().split()]
p = partition(array, 0, n-1)
Problem: p02300
Buggy submission (Python3, verdict: Wrong Answer):

def clockwise(v0, v1, v2):
    a1 = v1[0] - v0[0]
    a2 = v1[1] - v0[1]
    b1 = v2[0] - v0[0]
    b2 = v2[1] - v0[1]
    return (a1*b2 - b1*a2) < 0


n = int(input())
vors = [[int(a) for a in input().split() ] for _ in range(n)]
vors.sort(key=lambda v: (v[1], v[0]))

over = [vors[0], vors[1]]

for v in vors[2:]:
    while len(over) > 1 and not clockwise(over[-2], over[-1], v):
        over.pop()
    over.append(v)
        
under = [vors[0], vors[1]]

for v in vors[2:]:
    while len(under) > 1 and clockwise(under[-2], under[-1], v):
        under.pop()
    under.append(v)

print(len(over) + len(under) - 2)
for v in under[:-1]:
    print(v[0], v[1])

for v in reversed(over[1:]):
    print(v[0], v[1])
          

Failing test case input:
4
0 0
2 3
1 2
0 1

Expected output:
4
0 0
2 3
1 2
0 1


Actual output:
3
0 0
2 3
0 1


Fixed submission (verdict: Accepted):

def sgined_area(v0, v1, v2):
    a1 = v1[0] - v0[0]
    a2 = v1[1] - v0[1]
    b1 = v2[0] - v0[0]
    b2 = v2[1] - v0[1]
    return a1*b2 - b1*a2


n = int(input())
vors = [[int(a) for a in input().split() ] for _ in range(n)]
vors.sort(key=lambda v: (v[1], v[0]))

over = [vors[0], vors[1]]

for v in vors[2:]:
    while len(over) > 1 and sgined_area(over[-2], over[-1], v) > 0:
        over.pop()
    over.append(v)
        
under = [vors[0], vors[1]]

for v in vors[2:]:
    while len(under) > 1 and sgined_area(under[-2], under[-1], v) < 0:
        under.pop()
    under.append(v)

print(len(over) + len(under) - 2)
for v in under[:-1]:
    print(v[0], v[1])

for v in reversed(over[1:]):
    print(v[0], v[1])
Problem: p02300
Buggy submission (Python3, verdict: Wrong Answer):
import heapq

def isCLKWISE(ph):
    a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
    b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
    crs = a[0]*b[1] - a[1]*b[0]
    if crs < 0 :
        return False
    else :
        return True
    
def ConvexHullScan(P):
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) :
                break
            else :
                del phU[-2]
                if len(phU) == 2 :
                    break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) :
                break
            else :
                del phL[-2]
                if len(phL) == 2 :
                    break
    ph = phU + phL[1:-1]
    return ph

n = int(input())
P = []
for i in range(n):
    heapq.heappush(P,[int(x) for x in input().split()])
    
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
for q in Q:
    idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
    R = Q[idx:] + Q[:idx]
for r in R:
    print(r[0],r[1])

Failing test case input:
7
2 1
0 0
1 0
2 0
4 2
1 3
3 3

Expected output:
6
0 0
1 0
2 0
4 2
3 3
1 3


Actual output:
7
0 0
2 0
4 2
3 3
1 3
1 0
2 0


Fixed submission (verdict: Accepted):
def isCLKWISE(ph):
    a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
    b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
    crs = a[0]*b[1] - a[1]*b[0]
    if crs < 0 :
        return False
    else :
        return True
     
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) :
                break
            else :
                del phU[-2]
                if len(phU) == 2 :
                    break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) :
                break
            else :
                del phL[-2]
                if len(phL) == 2 :
                    break
    ph = phU + phL[1:-1]
    return ph
 
n = int(input())
P = []
for i in range(n):
    P += [[int(x) for x in input().split()]]
     
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
    print(r[0],r[1])
Problem: p02300
Buggy submission (Python3, verdict: Wrong Answer):
from math import sqrt
from collections import deque

def sub(a, b):
    return [a[0] - b[0],a[1] - b[1]]

def cross(a, b):
    return  a[0] * b[1] - a[1] * b[0]

def ccw(a, b, c):
    x = sub(b, a)
    y = sub(c, a)
    return cross(x, y) > 0

n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
c.sort(key=lambda x: (x[0], x[1]))
U = deque(c[:2])

for i in range(2, n):
    j = len(U)
    while j >= 2 and ccw(U[-1],U[-2],c[i]):
        U.pop()
        j -= 1
    U.append(c[i])

c = c[::-1]
L = deque(c[:2])

for i in range(2, n):
    j = len(L)
    while j >= 2 and ccw(L[-1], L[-2], c[i]):
        L.pop()
        j -= 1
    L.append(c[i])

ans = U
for i in range(1,len(L)-1):
    x, y = L[i]
    ans.append([x,y])

i = ans.index(sorted(ans, key=lambda x: (x[1],x[0]))[0])
ans = list(ans)
for x,y in ans[:i] + ans[i:]:
    print(x, y)


Failing test case input:
7
4 1
0 1
1 4
3 0
4 2
1 3
3 3

Expected output:
6
3 0
4 1
4 2
3 3
1 4
0 1


Actual output:
0 1
3 0
4 1
4 2
3 3
1 4


Fixed submission (verdict: Accepted):
from math import sqrt
from collections import deque

def sub(a, b):
    return [a[0] - b[0],a[1] - b[1]]

def cross(a, b):
    return  a[0] * b[1] - a[1] * b[0]

def ccw(a, b, c):
    x = sub(b, a)
    y = sub(c, a)
    return cross(x, y) > 0

n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
c.sort(key=lambda x: (x[0], x[1]))
U = deque(c[:2])

for i in range(2, n):
    j = len(U)
    while j >= 2 and ccw(U[-1],U[-2],c[i]):
        U.pop()
        j -= 1
    U.append(c[i])

c = c[::-1]
L = deque(c[:2])

for i in range(2, n):
    j = len(L)
    while j >= 2 and ccw(L[-1], L[-2], c[i]):
        L.pop()
        j -= 1
    L.append(c[i])

ans = U
for i in range(1,len(L)-1):
    x, y = L[i]
    ans.append([x,y])

print(len(ans))
i = ans.index(sorted(ans, key=lambda x: (x[1],x[0]))[0])
ans = list(ans)
for x,y in ans[i:] + ans[:i]:
    print(x, y)
Problem: p03187
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from itertools import accumulate
L, N = map(int, input().split())
X = [int(input()) for _ in range(N)]
Y = [L - x for x in X][::-1]

sx = [0] + list(accumulate(X))
sy = [0] + list(accumulate(Y))

ans = 0
for i in range(N):
    j = N - i - 1
    mn = min(i, j)

    now = X[i]
    now += 2 * (sx[i] - sx[i - mn]) + 2 * (sy[j] - sy[j - mn - (i < j)])
    print(i - mn)
    ans = max(ans, now)

    now = Y[j]
    now += 2 * (sx[i] - sx[i - mn - (i > j)]) + 2 * (sy[j] - sy[j - mn])
    ans = max(ans, now)

print(ans)


Failing test case input:
67 3
0
22
29

Expected output:
121


Actual output:
0
0
2
121


Fixed submission (verdict: Accepted):

from itertools import accumulate
L, N = map(int, input().split())
X = [int(input()) for _ in range(N)]
Y = [L - x for x in X][::-1]

sx = [0] + list(accumulate(X))
sy = [0] + list(accumulate(Y))

ans = 0
for i in range(N):
    j = N - i - 1
    mn = min(i, j)

    now = X[i]
    now += 2 * (sx[i] - sx[i - mn]) + 2 * (sy[j] - sy[j - mn - (i < j)])
    ans = max(ans, now)

    now = Y[j]
    now += 2 * (sx[i] - sx[i - mn - (i > j)]) + 2 * (sy[j] - sy[j - mn])
    ans = max(ans, now)

print(ans)

Problem: p03187
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
L,N = list(map(int,input().split()))
X=[]
Y=[]
SX=[0]
SY=[0]
sx=0
sy=0
for i in range(N):
   x=int(input())
   X.append(x)
   sx+=x
   SX.append(sx)
   Y.append(L-x)
   sy+=L-x
   SY.append(sy)   

max_score=0   
for i in range(N):
    if i>N-i-1:
        max_score=max(2*(SX[i]-SX[2*i-N])+2*(SY[N]-SY[i+1])+Y[i],max_score)
    elif i<N-i-1:
        max_score=max(2*(SX[i]-SX[0])+2*(SY[2*i+2]-SY[i+1])+X[i],max_score)

        
    ind = min(i,N-i-1)
    max_score=max(2*(SX[i]-SX[i-ind])+2*(SY[i+ind]-SY[i+1])+X[i],max_score)
    max_score=max(2*(SX[i]-SX[i-ind])+2*(SY[i+ind]-SY[i+1])+Y[i],max_score)


print(max_score)

Failing test case input:
66 3
2
10
8

Expected output:
176


Actual output:
114


Fixed submission (verdict: Accepted):

L,N = list(map(int,input().split()))
X=[]
Y=[]
SX=[0]
SY=[0]
sx=0
sy=0
for i in range(N):
   x=int(input())
   X.append(x)
   sx+=x
   SX.append(sx)
   Y.append(L-x)
   sy+=L-x
   SY.append(sy)   

max_score=0   
for i in range(N):
    if i>N-i-1:
        max_score=max(2*(SX[i]-SX[2*i-N])+2*(SY[N]-SY[i+1])+Y[i],max_score)
    elif i<N-i-1:
        max_score=max(2*(SX[i]-SX[0])+2*(SY[2*i+2]-SY[i+1])+X[i],max_score)

        
    ind = min(i,N-i-1)
    max_score=max(2*(SX[i]-SX[i-ind])+2*(SY[i+ind+1]-SY[i+1])+X[i],max_score)
    max_score=max(2*(SX[i]-SX[i-ind])+2*(SY[i+ind+1]-SY[i+1])+Y[i],max_score)


print(max_score)
Problem: p03880
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]

A.sort(reverse=True, key=lambda a: (a & -a))

xor = 0
for a in A:
    xor ^= a

left = 0
ans = 0

for digit in range(1, xor.bit_length() + 1)[:: -1]:
    if (xor & (1 << digit)) > 0:
        while left < N and (A[left] & -A[left]).bit_length() > digit:
            left += 1

        if left >= N or (A[left] & -A[left]).bit_length() != digit:
            print(-1)
            exit()

        ans += 1
        xor ^= ((1 << (digit + 1)) - 1)

if xor:
    for a in A:
        if a % 2 == 1:
            ans += 1
            break
    else:
        print(-1)
        exit()

print(ans)

Failing test case input:
3
001
110
100

Expected output:
-1


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]

A.sort(reverse=True, key=lambda a: (a & -a))

xor = 0
for a in A:
    xor ^= a

left = 0
ans = 0

for digit in range(xor.bit_length() + 1)[:: -1]:
    if (xor & (1 << digit)) > 0:
        while left < N and ((A[left] & -A[left]).bit_length() - 1) > digit:
            left += 1

        if left >= N or ((A[left] & -A[left]).bit_length() - 1) != digit:
            print(-1)
            exit()

        ans += 1
        xor ^= ((1 << (digit + 1)) - 1)

print(ans)

Problem: p03880
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
A = [int(input()) for _ in range(n)]
m = 30
C = [False]*m
x = 0
for a in A:
  x ^= a
  for i in range(m):
    if a>>i & 1:
      C[i] = True
total = 0
ans = 0
for i in range(m):
  if (x>>i & 1) ^ total:
    if C[i]:
      ans += 1
      total ^= 1
    else:
      print(-1)
      break
else:
  print(ans)

Failing test case input:
3
2
5
6

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(input()) for _ in range(n)]
m = 30
C = [False]*m
x = 0
for a in A:
  x ^= a
  for i in range(m):
    if a>>i & 1:
      C[i] = True
      break
total = 0
ans = 0
for i in range(m-1, -1, -1):
  if (x>>i & 1) ^ total:
    if C[i]:
      ans += 1
      total ^= 1
    else:
      print(-1)
      break
else:
  print(ans)
Problem: p03880
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]

A.sort(reverse=True, key=lambda a: (a & -a))

xor = 0
for a in A:
    xor ^= a

left = 0
ans = 0

for digit in range(1, xor.bit_length() + 1)[:: -1]:
    if (xor & (1 << digit)) > 0:
        while left < N and (A[left] & -A[left]).bit_length() > digit:
            left += 1

        if left >= N:
            print(-1)
            exit()

        ans += 1
        xor ^= ((1 << (digit + 1)) - 1)

if xor:
    for a in A:
        if a % 2 == 1:
            ans += 1
            break
    else:
        print(-1)
        exit()

print(ans)

Failing test case input:
3
111
100
111

Expected output:
-1


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]

A.sort(reverse=True, key=lambda a: (a & -a))

xor = 0
for a in A:
    xor ^= a

left = 0
ans = 0

for digit in range(xor.bit_length() + 1)[:: -1]:
    if (xor & (1 << digit)) > 0:
        while left < N and ((A[left] & -A[left]).bit_length() - 1) > digit:
            left += 1

        if left >= N or ((A[left] & -A[left]).bit_length() - 1) != digit:
            print(-1)
            exit()

        ans += 1
        xor ^= ((1 << (digit + 1)) - 1)

print(ans)

Problem: p03880
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]

A.sort(reverse=True, key=lambda a: (a & -a))
D = A[0].bit_length()

xor = 0
for a in A:
    xor ^= a

left = 0
ans = 0

for digit in range(1, xor.bit_length() + 1)[:: -1]:
    if (xor & (1 << digit)) > 0:
        mask = ((1 << (D + 1)) - 1) ^ ((1 << digit) - 1)
        while left < N and (A[left] & mask) != A[left]:
            left += 1

        if left >= N:
            print(-1)
            exit()

        ans += 1
        xor ^= ((1 << (digit + 1)) - 1)

if xor:
    for a in A:
        if a % 2 == 1:
            ans += 1
            break
    else:
        print(-1)
        exit()

print(ans)

Failing test case input:
3
8
1
2

Expected output:
-1


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]

A.sort(reverse=True, key=lambda a: (a & -a))

xor = 0
for a in A:
    xor ^= a

left = 0
ans = 0

for digit in range(xor.bit_length() + 1)[:: -1]:
    if (xor & (1 << digit)) > 0:
        while left < N and ((A[left] & -A[left]).bit_length() - 1) > digit:
            left += 1

        if left >= N or ((A[left] & -A[left]).bit_length() - 1) != digit:
            print(-1)
            exit()

        ans += 1
        xor ^= ((1 << (digit + 1)) - 1)

print(ans)
Problem: p03880
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
A = [int(input()) for _ in range(n)]
m = 32
C = [False]*m
x = 0
for a in A:
  x ^= a
  for i in range(m):
    if a>>i & 1:
      C[i] = True
total = 0
ans = 0
for i in range(m-1, -1, -1):
  if (x>>i & 1) ^ total:
    if C[i]:
      ans += 1
      total ^= 1
    else:
      print(-1)
      break
else:
  print(ans)

Failing test case input:
3
2
5
1

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(input()) for _ in range(n)]
m = 30
C = [False]*m
x = 0
for a in A:
  x ^= a
  for i in range(m):
    if a>>i & 1:
      C[i] = True
      break
total = 0
ans = 0
for i in range(m-1, -1, -1):
  if (x>>i & 1) ^ total:
    if C[i]:
      ans += 1
      total ^= 1
    else:
      print(-1)
      break
else:
  print(ans)

Problem: p03880
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
A = [int(input()) for _ in range(n)]
m = 30
C = [False]*m
x = 0
for a in A:
  x ^= a
  for i in range(m):
    if a>>i & 1:
      C[i] = True
total = 0
ans = 0
for i in range(m-1, -1, -1):
  if (x>>i & 1) ^ total:
    if C[i]:
      ans += 1
      total ^= 1
    else:
      print(-1)
      break
else:
  print(ans)

Failing test case input:
3
3
3
4

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(input()) for _ in range(n)]
m = 30
C = [False]*m
x = 0
for a in A:
  x ^= a
  for i in range(m):
    if a>>i & 1:
      C[i] = True
      break
total = 0
ans = 0
for i in range(m-1, -1, -1):
  if (x>>i & 1) ^ total:
    if C[i]:
      ans += 1
      total ^= 1
    else:
      print(-1)
      break
else:
  print(ans)

Problem: p03880
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
xor = 0
rank = [0] * 35 
for i in range(n):
    a = int(input())
    LSB = (a & -a).bit_length()
    rank[LSB] += 1
    xor ^= a 

prev = False 
ans = 0
for i in range(33, -1, -1):
    bit = xor & (1 << i)
    if bit ^ prev:
        if rank[i+1] == 0:
            print(-1)
            exit()
        else:
            ans += 1
    prev = bit
print(ans)

Failing test case input:
3
3
5
8

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
xor = 0
rank = [0] * 35 
for i in range(n):
    a = int(input())
    LSB = (a & -a).bit_length()
    rank[LSB] += 1
    xor ^= a 

prev = False 
ans = 0
for i in range(33, -1, -1):
    bit = xor & (1 << i)
    if (bit > 0 and prev == 0) or (bit == 0 and prev > 0):
        if rank[i+1] == 0:
            print(-1)
            exit()
        else:
            ans += 1
    prev = bit
print(ans)
Problem: p03880
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]
gr = 0
for x in a:
	gr ^= x
exist = set()
for i in range(n):
	cnt = 0
	while (a[i]>>cnt)&1 == 0:
		cnt += 1
	exist.add(cnt)
ok = True
ans = 0
for i in range(35, -1, -1):
	if (gr>>i)&1:
		if i not in exist:
			ok = False
		else:
			gr %= (1<<(i+1))
			gr = (1<<(i+1)) - gr
			ans += 1
	else:
		gr %= (1<<(i+1))
if ok:
	print(ans)
else:
	print(-1)

Failing test case input:
3
2
3
3

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
gr = 0
for x in a:
	gr ^= x
exist = set()
for i in range(n):
	cnt = 0
	while (a[i]>>cnt)&1 == 0:
		cnt += 1
	exist.add(cnt)
ok = True
ans = 0
for i in range(35, -1, -1):
	if (gr>>i)&1:
		if i not in exist:
			ok = False
		else:
			gr %= (1<<(i+1))
			gr = (1<<(i+1)) - gr - 1
			ans += 1
	else:
		gr %= (1<<(i+1))
if ok:
	print(ans)
else:
	print(-1)

Problem: p03880
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n = int(input())
    a = [int(input()) for _ in [0]*n]
    m = max(a)
    xor = 0
    for i in a:
        xor ^= i
    i = 1
    cnt = 0
    while True:
        if xor >= i:
            i *= 2
            cnt += 1
        else:
            break
    ans = 0
    for i in range(cnt-1, -1, -1):
        j = (xor & 2**i) 
        if j == 1:
            for k in a:
                if k % (2**i) == 0:
                    xor ^= k
                    xor ^= k-1
                    ans += 1
                    a.remove(k)
                    break
            else:
                print(-1)
                return 0
    print(ans)


main()

Failing test case input:
3
3
3
3

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    a = [int(input()) for _ in [0]*n]
    xor = 0
    for i in a:
        xor ^= i
    i = 1
    cnt = 0
    while True:
        if xor >= i:
            i *= 2
            cnt += 1
        else:
            break
    ans = 0
    for i in range(cnt-1, -1, -1):
        j = (xor & 2**i) 
        if j == 1:
            for k in a:
                if (k & 2**i) 
                    xor ^= k
                    xor ^= k-1
                    ans += 1
                    a.remove(k)
                    break
            else:
                print(-1)
                return 0
    print(ans)


main()

Problem: p03880
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,*a=map(int,open(0))
x=0
c=[0]*30
for i in a:
  x^=i
  c[bin(i^i-1)[::-1].rfind('1')]=1
a=0
for i in range(29,-1,-1):
  if x&2**i:
    if c[i]:
      a+=1
      x^=2**i-1
  else:
    print(-1)
    break
else:
  print(a)

Failing test case input:
3
3
8
4

Expected output:
1


Actual output:
-1


Fixed submission (verdict: Accepted):
n,*a=map(int,open(0))
x=0
c=[0]*30
for i in a:
  x^=i
  c[bin(i^i-1)[::-1].rfind('1')]=1
a=0
for i in range(29,-1,-1):
  if x&2**i:
    if c[i]:
      a+=1
      x^=2**i-1
    else:
      print(-1)
      break
else:
  print(a)
Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

V = sum(v)
dp = [[float("inf")] * (V + 1) for _ in range(N + 1)]

dp[0][0] = 0

for i in range(N):
	for j in range(V + 1):
		
		if j - v[i] >= 0:
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
		
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])




ans = 0
for j in range(V):
	if dp[N][j] <= W:
		ans = j

print(ans)


Failing test case input:
5 31
4 0
0 11
9 6
16 20
4 9
0 4

Expected output:
46


Actual output:
40


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

V = sum(v)
dp = [[float("inf")] * (V + 1) for _ in range(N + 1)]

dp[0][0] = 0

for i in range(N):
	for j in range(V + 1):
		
		if j - v[i] >= 0:
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
		
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])




ans = 0
for j in range(V + 1):
	if dp[N][j] <= W:
		ans = j

print(ans)

Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,W = map(int,input().split())
w = []
v = []
for _ in range(n):
    weight,value = map(int,input().split())
    w.append(weight)
    v.append(value)
INF =float("inf")
order = 150
dp = [[INF] * order for _ in range(n+1)] 
dp[0] =[-INF] * order
dp[0][0]=0
for i in range(n):
    for value in range(order):
        if value - v[i] >= 0:
            dp[i+1][value] = min(dp[i+1][value], dp[i][value-v[i]] + w[i])
        if dp[i][value] != -INF:
            dp[i+1][value] = min(dp[i+1][value],dp[i][value])
ans = 0
for value in range(order):
    if 0<=dp[n][value]<= W:
        ans = max(ans,value)

print(ans)


Failing test case input:
3 1
0 0
-1 42
1 180

Expected output:
222


Actual output:
0


Fixed submission (verdict: Accepted):
n,W = map(int,input().split())
w = []
v = []
for _ in range(n):
    weight,value = map(int,input().split())
    w.append(weight)
    v.append(value)

INF = float("inf")
order = 10**5  + 1 
dp = [[INF] * order for _ in range(n+1)] 
dp[0][0] = 0

for i in  range(n):
    for value in range(order):
        if value-v[i]>= 0:
            dp[i+1][value] = min(dp[i+1][value],dp[i][value-v[i]] + w[i])
        dp[i+1][value] = min(dp[i+1][value],dp[i][value])

ans = 0
for value in range(order):
    if dp[n][value] <= W:
        ans = max(ans,value)
print(ans)
Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,W = map(int,input().split())
weight = []
value = []
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
maxValue = N*1000
dp = [[0 for i in range(maxValue+1)] for j in range(N+1)]
for i in range(maxValue+1):
    dp[0][i] = float("inf")
dp[0][0] = 0
dp[0][value[0]] = weight[0]
for i in range(1,N+1):
    op2 = float("inf")
    for v in range(maxValue+1):
        dp[i][v] = dp[i-1][v]
        if value[i-1] > v: continue;
        dp[i][v] = min(dp[i][v],weight[i-1] + dp[i-1][v-value[i-1]])
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

Failing test case input:
3 23
2 9
1 46
1 145

Expected output:
200


Actual output:
209


Fixed submission (verdict: Accepted):
N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
    
maxValue = sum(value)
INF = 10**10
dp = [[INF for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
for i in range(1,N+1):
    for v in range(1,maxValue+1):
        if value[i] <= v:
            dp[i][v] = min(dp[i-1][v],weight[i] + dp[i-1][v-value[i]])
        else:
            dp[i][v] = dp[i-1][v]
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict

MAX_VAL = 100000
N, W = map(int, input().split())

dp = defaultdict(lambda: 1e9)
dp[0] = 1
ans = 0
for _ in range(N):
    w, v = map(int, input().split())
    for k in range(MAX_VAL, -1, -1):
        dp[k + v] = min(dp[k+v], dp[k] + w)
        if dp[k + v] <= W:
            ans = max(ans, k + v)


print(ans)


Failing test case input:
2 0
5 6
0 29
8 191

Expected output:
29


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import defaultdict

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

dp = defaultdict(lambda: 1e9)
dp[0] = 0
ans = 0
for _ in range(N):
    w, v = map(int, input().split())
    keys = sorted(dp.keys(), reverse=True)
    for k in keys:
        dp[k + v] = min(dp[k + v], dp[k] + w)
        if dp[k + v] <= W:
            ans = max(ans, k + v)


print(ans)
Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, W = map(int, input().split())
w = [0]
v = [0]
for _ in range(N):
    x, y = map(int, input().split())
    w.append(x)
    v.append(y)
dp = [[0 for _ in range(10**5 + 1)] for _ in range(N+1)]
for i in range(1, 10**5 + 1):
    dp[0][i] = float('inf')

for i in range(1, N+1):
    for j in range(10**5 + 1):
        dp[i][j] = dp[i-1][j]
        if j - v[i-1] >= 0:
            dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i])

ans = 0
for k in range(10**5 + 1):
    if dp[N][k] <= W:
        ans = max(ans, k)


print(ans)

Failing test case input:
6 7
6 5
5 6
3 3
6 6
3 5
7 2

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
N, W = map(int, input().split())
w = [0]
v = [0]
for _ in range(N):
    x, y = map(int, input().split())
    w.append(x)
    v.append(y)

dp = [[0 for _ in range(10**5 + 1)] for _ in range(N+1)]
for i in range(1, 10**5 + 1):
    dp[0][i] = float('inf')

for i in range(1, N+1):
    for j in range(10**5 + 1):
        dp[i][j] = dp[i-1][j]
        if j - v[i] >= 0:
            dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i])

ans = 0
for k in range(10**5 + 1):
    if dp[N][k] <= W:
        ans = max(ans, k)

print(ans)

Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, W = map(int, input().split())
wv = []

for i in range(N):
    w, v = map(int, input().split())
    wv.append([w, v])
MAX_V = 10**5+100
INF = 10**9
dp = [[INF]*MAX_V for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(MAX_V):
        if j - wv[i][1] >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i][j-wv[i][1]]+wv[i][0])
        else:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
ans = 0
for i in range(MAX_V):
    if dp[N][i] <= W:
        ans = i
print(ans)

Failing test case input:
1 1000000000
0000000000 10

Expected output:
10


Actual output:
100099


Fixed submission (verdict: Accepted):
N, W = map(int, input().split())
wv = []

for i in range(N):
    w, v = map(int, input().split())
    wv.append([w, v])
MAX_V = 10**5+100
INF = 10**10
dp = [[INF]*MAX_V for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(MAX_V):
        if j - wv[i][1] >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i][j-wv[i][1]]+wv[i][0])
        else:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
ans = 0
for i in range(MAX_V):
    if dp[N][i] <= W:
        ans = i
print(ans)