Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a = list(map(int,[input() for i in range(5)]))

if max(a[-1]) - min(a[-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")


Fixed submission:
a = list(map(int,[input() for i in range(6)]))

if max(a[:-1]) - min(a[:-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")

Buggy python submission (verdict: Runtime Error):
a = list(map(int,[input() for i in range(4)]))

if max(a[-1]) - min(a[-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")


Fixed submission:
a = list(map(int,[input() for i in range(6)]))

if max(a[:-1]) - min(a[:-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")

Buggy python submission (verdict: Runtime Error):
a = list(map(int,i for i in input()))

if max(a[-1]) - min(a[-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")

Fixed submission:
a = list(map(int,[input() for i in range(6)]))

if max(a[:-1]) - min(a[:-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")
Buggy python submission (verdict: Runtime Error):
a = list(map(int,[input() for i in range(5)]))
b = []
c = []
d = False
for i in a:
	b.append(10-i % 10)
for i,j in zip(b,a):
	if max(b) != i:
		c.append(i+j)
	elif not d:
		c.append(j)
    else:
        c.append(i+j)
print(sum(c))


Fixed submission:
a = list(map(int,[input() for i in range(5)]))
b = 10
c = 0
for i in a:
	if i % 10 > 0:
		c += i + 10 - i % 10
		if b > i % 10:
			b = i % 10
	else:
		c += i
print(c-10+b)

Buggy python submission (verdict: Runtime Error):
b = []
c = []
for i in a:
	b.append(10-i % 10)
for i,j in zip(b,a):
	if max(b) != i:
		c.append(i+j)
	else:
		c.append(j)
print(sum(c))

Fixed submission:
a = list(map(int,[input() for i in range(5)]))
b = 10
c = 0
for i in a:
	if i % 10 > 0:
		c += i + 10 - i % 10
		if b > i % 10:
			b = i % 10
	else:
		c += i
print(c-10+b)

Buggy python submission (verdict: Runtime Error):
a = list(map(int,[input() for i in range(5)]))
b = []
c =[]
for i in a:
	b.append(10 - i % 10)
for i,j in zip(b,a):
	if max(b) != i:
		c.append(i+j)
    else:
        c.append(j)
print(sum(c))
	


Fixed submission:
a = list(map(int,[input() for i in range(5)]))
b = 10
c = 0
for i in a:
	if i % 10 > 0:
		c += i + 10 - i % 10
		if b > i % 10:
			b = i % 10
	else:
		c += i
print(c-10+b)

Buggy python submission (verdict: Runtime Error):
a = list(map(int,[input() for i in range(5)]))
b = []
c =[]
for i in a:
	b.append(10-i % 10)
for i,j in zip(b,a):
	if max[b] != i:
		c.append(i+j)
print(sum(c))
	


Fixed submission:
a = list(map(int,[input() for i in range(5)]))
b = 10
c = 0
for i in a:
	if i % 10 > 0:
		c += i + 10 - i % 10
		if b > i % 10:
			b = i % 10
	else:
		c += i
print(c-10+b)
Buggy python submission (verdict: Runtime Error):
a = str(input())
b = {"A":"T","G":"C"}
print(b[a])

Fixed submission:
a = str(input())
b = {"A":"T","G":"C","T":"A","C":"G"}
print(b[a])
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = input()
t = [0] * (n + 1)
for i in range(q):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r+1] - t[l-1])


Fixed submission:
n,q = map(int,input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = input()
t = [0] * (n + 1)
for i in range(q):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])


Fixed submission:
n,q = map(int,input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = str(input())
for _ in range(q):
  l,r = map(int,input().split())
  print(s[l-1:r].count("AC"))


Fixed submission:
n,q = map(int,input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = str(input())
for _ in range(q):
  l,r = map(int,input().split())
  print(s[l-1:r].count("AC")

Fixed submission:
n,q = map(int,input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
sum = 0
for _ in range(n):
  x,u = input().split()
  if str(u) = "BTC":
    sum += int(x) * 380000.0
  else:
    sum += int(x)
print(sum)

Fixed submission:
n = int(input())
sum = 0
for _ in range(n):
    x,u = input().split()
    if str(u) == "BTC":
        sum += float(x) * 380000.0
    else:
        sum += float(x)
print(sum)
Buggy python submission (verdict: Runtime Error):
A= [int(x) for x in input().split()]

sort(A)

if A == [5,5,7]:
  print("YES")
else:
  print("NO")

Fixed submission:
A= [int(x) for x in input().split()]
 
A.sort()

if A == [5,5,7]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))

count = 0
allpoint = sum(A)
X = allpoint // (4 * M)

for i in A:
    if i > X:
        count += 1

if  count >= M:
    print('Yes')
else:
    print('No')

Fixed submission:
x, y, z = map(int, input().split())

x, y = y, x
x, z = z, x

print(x, y ,z)

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

count = 0
allpoint = sum(A)

for i in A:
    if i > float(allpoint // (4 * M)):
        count += 1

if  count >= M:
    print('Yes')
else:
    print('No')

Fixed submission:
x, y, z = map(int, input().split())

x, y = y, x
x, z = z, x

print(x, y ,z)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

if K == 1:
    print(0)
else:
    while True:
        preN = N
        N = abs(N - K)
        if N >= preN :
            print(preN)
            break

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

amari = N % K
absplus = abs(amari - K)


if N <= (K // 2):
    print(N)
elif amari >= absplus:
    print(absplus)
else:
    print(amari)
Buggy python submission (verdict: Time Limit Exceeded):
k, n = map(int, input().split())
a = list(map(int, input().split()))

for i in range(1, n+1):
    if i == 1:
        distance = k - (a[0] + (k - a[-1]))
        mindistance = distance
        a.append(a[0])
        a.pop(0)
    else:
        distance = k - (a[0] - a[-1])
        if distance < mindistance:
            mindistance = distance
        a.append(a[0])
        a.pop(0)

print(mindistance)

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

a.append(a[0] + k)

distance = []

for i in range(len(a) - 1):
    distance.append(a[i+1] - a[i])

mindistance = 0
for j in distance:
    mindistance += j

print(mindistance - max(distance))

Buggy python submission (verdict: Time Limit Exceeded):
k, n = map(int, input().split())
a = list(map(int, input().split()))

mindistance = 10000000

for i in range(1, n+1):
    if i == 1:
        distance = k - (a[0] + (k - a[-1]))
        if distance < mindistance:
            mindistance = distance
        a.append(a[0])
        a.pop(0)
    else:
        distance = k - (a[0] - a[-1])
        if distance < mindistance:
            mindistance = distance
        a.append(a[0])
        a.pop(0)

print(mindistance)

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

a.append(a[0] + k)

distance = []

for i in range(len(a) - 1):
    distance.append(a[i+1] - a[i])

mindistance = 0
for j in distance:
    mindistance += j

print(mindistance - max(distance))
Buggy python submission (verdict: Runtime Error):
import fractions

n, k = map(int, input().split())
if (n > abs(n - k)):
    n = fractions.gcd(n, k)
while n > abs(n - k):
    n = abs(n - k)
if n == k:
    print('0')
else:
    print(n)

Fixed submission:
x, y, z = map(int, input().split())
print(z, x, y)
Buggy python submission (verdict: Runtime Error):
A, B, C, X = [int(input()) for i in range(4)]
res = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if a * 500 + b * 100 + c * 50 == X:
                res += 1
print(res)

Fixed submission:
N = int(input())
s = [input() for i in range(N)]
print(len(set(s)))

Buggy python submission (verdict: Runtime Error):
A, B, C, X = [int(input()) for i in range(4)]
res = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if a * 500 + b * 100 + c * 50 == X:
                res += 1
print(res)

Fixed submission:
N = int(input())
s = [input() for i in range(N)]
print(len(set(s)))
Buggy python submission (verdict: Runtime Error):
s = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'
while True:
    # 後ろから文字列検索
    # 合ったらその文字を削除
    D = hantei(s, d)
    if D > -1:
        s = s[:-len(d)]
        continue
    B = hantei(s, b)
    if B > -1:
        s = s[:-len(b)]
        continue
    C = hantei(s, c)
    if C > -1:
        s = s[:-len(c)]
        continue
    A = hantei(s, a)
    if A > -1:
        s = s[:-len(a)]
        continue
    if len(s) == 0:
        print('YES')
    else:
        print('NO')
    break


def hantei(s, h):
    try:
        slen = len(s)
        hlen = len(h)
        res = s.index(h, slen - hlen, slen + 1)
        return res
    except ValueError as e:
        return -1

Fixed submission:
def hantei(s, h):
    try:
        slen = len(s)
        hlen = len(h)
        res = s.index(h, slen - hlen, slen + 1)
        return res
    except ValueError as e:
        return -1


def resolve():
    s = input()
    a = 'dream'
    b = 'dreamer'
    c = 'erase'
    d = 'eraser'
    while True:
        # 後ろから文字列検索
        # 合ったらその文字を削除
        D = hantei(s, d)
        if D > -1:
            s = s[:-len(d)]
            continue
        B = hantei(s, b)
        if B > -1:
            s = s[:-len(b)]
            continue
        C = hantei(s, c)
        if C > -1:
            s = s[:-len(c)]
            continue
        A = hantei(s, a)
        if A > -1:
            s = s[:-len(a)]
            continue
        if len(s) == 0:
            print('YES')
        else:
            print('NO')
        break
        
resolve()

Buggy python submission (verdict: Runtime Error):
    s = input()
    a = 'dream'
    b = 'dreamer'
    c = 'erase'
    d = 'eraser'
    while True:
        # 後ろから文字列検索
        # 合ったらその文字を削除
        D = hantei(s, d)
        if D > -1:
            s = s[:-len(d)]
            continue
        B = hantei(s, b)
        if B > -1:
            s = s[:-len(b)]
            continue
        C = hantei(s, c)
        if C > -1:
            s = s[:-len(c)]
            continue
        A = hantei(s, a)
        if A > -1:
            s = s[:-len(a)]
            continue
        if len(s) == 0:
            print('YES')
        else:
            print('NO')
        break

Fixed submission:
def hantei(s, h):
    try:
        slen = len(s)
        hlen = len(h)
        res = s.index(h, slen - hlen, slen + 1)
        return res
    except ValueError as e:
        return -1


def resolve():
    s = input()
    a = 'dream'
    b = 'dreamer'
    c = 'erase'
    d = 'eraser'
    while True:
        # 後ろから文字列検索
        # 合ったらその文字を削除
        D = hantei(s, d)
        if D > -1:
            s = s[:-len(d)]
            continue
        B = hantei(s, b)
        if B > -1:
            s = s[:-len(b)]
            continue
        C = hantei(s, c)
        if C > -1:
            s = s[:-len(c)]
            continue
        A = hantei(s, a)
        if A > -1:
            s = s[:-len(a)]
            continue
        if len(s) == 0:
            print('YES')
        else:
            print('NO')
        break
        
resolve()
Buggy python submission (verdict: Runtime Error):
x,y,z = map(int, input().split())
x,y,z >= 1 && <= 100 
print(z,y,x)

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

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
x,y,z = map(int, input().split())
print(c,a,b)
print(z,y,x)

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

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().splite())
x,y,z = map(int,input().split())
print(c,a,b)
print(z,y,x)


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

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().splite())
print(c,a,b)


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

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
print(c,a,b)
x,y,z = map(int,input().split())
print(z,y,x)


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

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input(),split())
x,y,z = map(int,input(),split())
print(c,a,b)
print(z,y,x)

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

Buggy python submission (verdict: Runtime Error):
user_input = input(" ")
user_input = "a","b","c" && user_input = "x,y,z"
"a","b","c" = [1,2,3]
"x","y","z" = [1,2,3]
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))

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

Buggy python submission (verdict: Runtime Error):
"x,y,z" = map(int,input(),split())
print(z,y,x)

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

Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input(),split())
print(C,A,B)

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

Buggy python submission (verdict: Runtime Error):
x,y,z = = map(int, input(),split())
print(X,Z,Y)

Fixed submission:
a, b, c = map(int, input().split())
print(c, a, b)
Buggy python submission (verdict: Runtime Error):
ans = 1
    while True :
        if ans < 0 :
            print(abs(ans))
            break
        ans = N - K
        N = ans

Fixed submission:
n, k = map(int, input().split())
if n==0 or k==1:
    print(0)
    exit()
elif n<k:
    print(min(n, abs(n-k)))
    exit()
elif n % k == 0:
    print(0)
    exit()
else:
    mx = n%k
print(min(abs(mx-k), mx))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))

mod = 10**9 + 7

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % mod)
    inv.append(mod - inv[mod%i] * (mod//i) % mod)
    finv.append(finv[i-1] * inv[i] % mod)

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        if j == n-1:
            ans += inv[n-1-i] * (x[j] - x[i]) % mod * fac[n-1] % mod
        else:
            ans += (inv[j-i] - inv[j-i+1]) * (x[j] - x[i]) % mod * fac[n-1] % mod
        ans %= mod

print(ans)


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

mod = 10**9 + 7

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % mod)
    inv.append(mod - inv[mod%i] * (mod//i) % mod)
    finv.append(finv[i-1] * inv[i] % mod)

ans = 0
j_inv = []
num = 0
for j in range(1, n):
    num += inv[j]
    num %= mod
    j_inv.append(num)

for i in range(n-1):
    ans += j_inv[i] * (x[i+1] - x[i])
    ans %= mod

ans *=fac[n-1]
ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    g = gcd(a, b)
    g_a = a // g
    g_b = b // g
    return g_a * g_b * g

n, m = map(int, input().split())
a = list(map(int, input().split()))



b = []
for i in range(n):
    b.append(a[i]//2)

num = 1
for i in range(n):
    num = lcm(num, b[i])

for i in range(n):
    if (num // b[i]) % 2 == 0:
        print(0)
        exit()

if num > m:
    print(0)
    exit()

p = m // num
if p % 2 == 0:
    print(p//2)
else:
    print((p+1)//2)

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

def lcm(a, b):
    g = gcd(a, b)
    g_a = a // g
    g_b = b // g
    return g_a * g_b * g

n, m = map(int, input().split())
a = list(map(int, input().split()))



b = []
for i in range(n):
    b.append(a[i]//2)

num = 1
for i in range(n):
    num = lcm(num, b[i])
    if num > m:
        print(0)
        exit()

for i in range(n):
    if (num // b[i]) % 2 == 0:
        print(0)
        exit()


p = m // num
if p % 2 == 0:
    print(p//2)
else:
    print((p+1)//2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
c = list(map(int, input().split()))

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod)) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)


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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2+n, mod) * (n-i-1) + pow(2, n-i-1+n, mod)) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod)) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)


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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2+n, mod) * (n-i-1) + pow(2, n-i-1+n, mod)) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod) ) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2+n, mod) * (n-i-1) + pow(2, n-i-1+n, mod)) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod) ) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2+n, mod) * (n-i-1) + pow(2, n-i-1+n, mod)) % mod
    ans %= mod

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


mod = 10**9 + 7

ans = 0
for i in range(61):
    zero = 0
    one = 0
    for a_ in a:
        if (a_ >> i) & 1:
            one += 1
        else:
            zero += 1
    ans += one * zero * pow(2, i, mod) % mod
    ans %= mod

print(ans)

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


mod = 10**9 + 7

ans = 0
for i in range(61):
    zero = 0
    one = 0
    for a_ in a:
        if (a_ >> i) & 1:
            one += 1
        else:
            zero += 1
    ans += one * zero * pow(2, i, mod) % mod
    ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

INF = float('inf')
dp = [INF for j in range(2**n)]

dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = map(int, input().split())

    k = 0
    for ci in c:
        ci -= 1
        k |= (1 << ci)
    for j in range(2**n):
        l = k | j
        dp[l] = min(dp[l], dp[j] + a)

if dp[2**n-1] == INF:
    print(-1)
else:
    print(dp[2**n-1])


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

INF = float('inf')
dp = [INF for j in range(2**n)]

dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = map(int, input().split())

    k = 0
    for ci in c:
        ci -= 1
        k |= (1 << ci)
    for j in range(2**n):
        l = k | j
        dp[l] = min(dp[l], dp[j] + a)

if dp[2**n-1] == INF:
    print(-1)
else:
    print(dp[2**n-1])

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

box = []
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    box.append([a, c])

box.sort(key=lambda x: x[0])

memo = [0] * n
tmp = []

ans = 0

for i in range(m):
    cost = box[i][0]
    target = box[i][1]

    for t in target:
        t -= 1
        memo[t] += 1
    ans += cost
    tmp.append(i)

    cost_max = 0
    bit_max = 0
    for bit in range(2**(i+1)):
        memo_sub = [0] * n
        cost_sub = 0
        for j in range(i+1):
            if (1 << j) & bit:
                co = box[j][0]
                ta = box[j][1]
                cost_sub += co
                for t in ta:
                    t -= 1
                    memo_sub[t] += 1
        flag = 1
        for k in range(n):
            if memo_sub[k] >= memo[k]:
                flag = 0
        if flag:
            if cost_sub > cost_max:
                cost_max = cost_sub
                bit_max = bit

    for j in range(i+1):
        if (1 << j) & bit_max:
            tmp.remove(j)
            for t in box[j][1]:
                t -= 1
                memo[t] -= 1
    ans -= cost_max

for mi in memo:
    if mi == 0:
        print(-1)
        exit()

print(ans)




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

INF = float('inf')
dp = [INF for j in range(2**n)]

dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = map(int, input().split())

    k = 0
    for ci in c:
        ci -= 1
        k |= (1 << ci)
    for j in range(2**n):
        l = k | j
        dp[l] = min(dp[l], dp[j] + a)

if dp[2**n-1] == INF:
    print(-1)
else:
    print(dp[2**n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
a = [int(input()) for _ in range(n)]


b = []

for ai in a:
    if len(b) == 0:
        b.append(ai)
    else:
        if ai <= b[0]:
            b = [ai] + b
        else:
            index = bisect.bisect_left(b, ai)
            b[index-1] = ai

print(len(b))


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]


b = []

for ai in a:
    if len(b) == 0:
        b.append(ai)
    else:
        if ai <= b[-1]:
            b.append(ai)
        else:
            l = -1
            r = len(b)
            mid = (l + r) // 2
            while (r - l > 1):
                mid = (l + r) // 2
                if b[mid] >= ai:
                    l = mid
                else:
                    r = mid
            b[r] = ai

print(len(b))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
a = [int(input()) for _ in range(n)]


b = []

for ai in a:
    if len(b) == 0:
        b.append(ai)
    else:
        if ai <= b[0]:
            b = [ai] + b
        else:
            index = bisect.bisect_left(b, ai)
            b[index-1] = ai

print(len(b))


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]


b = []

for ai in a:
    if len(b) == 0:
        b.append(ai)
    else:
        if ai <= b[-1]:
            b.append(ai)
        else:
            l = -1
            r = len(b)
            mid = (l + r) // 2
            while (r - l > 1):
                mid = (l + r) // 2
                if b[mid] >= ai:
                    l = mid
                else:
                    r = mid
            b[r] = ai

print(len(b))