Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03393 (python)

Fixed submission:
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            while len(Q)>0 and ord(S[25 - i - 1])>min(Q):
                Q.remove(min(Q))
            if len(Q)>0:
                S.pop()
                S.pop()
                S.append(chr(min(Q)))
                flag = 1
                break
            else:
                Z = S[25-i]
                S.pop()
                S.pop()
                S.append(Z)
                flag = 1
                break
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))

Buggy submission (verdict: Runtime Error):
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            while len(Q)>0 and ord(S[25 - i - 1])>min(Q):
                Q.remove(min(Q))
            S.pop()
            S.pop()
            S.append(chr(min(Q)))
            flag = 1
            break
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))

Buggy submission (verdict: Runtime Error):
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            S.pop()
            S.append(chr(min(Q)))
            flag = 1
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))
Problem p03471 (python)

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


a = Y//10000
b = Y//5000

flag = False

for i in range(a+1):
    if flag == True:
        break
    for j in range(b+1):
        if N-i-j<0:
            break
        if i*10000+j*5000+(N-i-j)*1000 == Y:
            flag = True
            s = i
            t = j
            u = N-i-j
            break

if flag == True:
    print(s,t,u)
else:
    print(-1,-1,-1)

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


a = Y//10000
b = Y//5000

flag = False

for i in range(a+1):
    if flag == True:
        break
    for j in range(b+1):
        if N-i-j<0:
            break:
        if i*10000+j*5000+(N-i-j)*1000 == Y:
            flag = True
            s = i
            t = j
            u = N-i-j
            break

if flag == True:
    print(s,t,u)
else:
    print(-1,-1,-1)
Problem p03494 (python)

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

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

Z = A[0]

for i in range(N):
    Z = gcd(Z ,A[i])

flag = 0
i = 0

while flag == 0:
    if Z % pow(2,i) == 0:
        i += 1
    else :
        flag = 1

print(i-1)

Buggy submission (verdict: Runtime Error):
import functools
import math

N = int(input())
A = list(map(int, input().split()))

x = functools.reduce(math.gcd, A)

flag = 0
i = 0

while flag == 0:
    if x % pow(2,i) == 0:
        i += 1
    else :
        flag = 1

print(i-1)

Buggy submission (verdict: Runtime Error):
import functools
import math

N = int(input())
A = list(map(int, input().split()))

x = functools.reduce(math.gcd, A)

flag = 0
i = 0

while flag == 0:
    if x % pow(2,i) == 0:
        i += 1
    else :
        flag = 1

print(i-1)
Problem p02840 (python)

Fixed submission:
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,X,D) = (int(i) for i in input().split(" "))
mp = {}
if D == 0:
	if X == 0:
		ans = 1
	else:
		ans = N+1
else:
	for i in range(N+1):
		md = (i*X)%D
		if not md in mp:
			mp[md] = []
		k = i*(i-1)//2
		mp[md].append([k+(((i*X)-md)//D),0])
		k = (N*2-i-1)*i//2
		mp[md].append([k+(((i*X)-md)//D)+1,1])
	#print(mp)
	ans = 0
	for k in mp.keys():
		s = sorted(mp[k])
		#print(s)
		md = 0
		bef = 0
		for t in s:
			if md > 0:
				ans += t[0] - bef
			bef = t[0]
			if t[1] == 0:
				md += 1
			else:
				md -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,X,D) = (int(i) for i in input().split(" "))
mp = {}

for i in range(N+1):
	md = (i*X)%D
	if not md in mp:
		mp[md] = []
	k = 0
	for j in range(i):
		k += j
	mp[md].append([k+((i*X)-md)//D,0])
	k = 0
	for j in range(i):
		k += N-j-1
	mp[md].append([k+((i*X)-md)//D+1,1])
#print(mp)
ans = 0
for k in mp.keys():
	s = sorted(mp[k])
	#print(s)
	md = 0
	bef = 0
	for t in s:
		if md > 0:
			ans += t[0] - bef
		bef = t[0]
		if t[1] == 0:
			md += 1
		else:
			md -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,X,D) = (int(i) for i in input().split(" "))
mp = {}

for i in range(N+1):
	md = (i*X)%D
	if not md in mp:
		mp[md] = []
	k = 0
	for j in range(i):
		k += j
	mp[md].append([k+((i*X)-md)/D,0])
	k = 0
	for j in range(i):
		k += N-j-1
	mp[md].append([k+((i*X)-md)/D+1,1])
#print(mp)
ans = 0
for k in mp.keys():
	s = sorted(mp[k])
	#print(s)
	md = 0
	bef = 0
	for t in s:
		if md > 0:
			ans += t[0] - bef
		bef = t[0]
		if t[1] == 0:
			md += 1
		else:
			md -= 1
print(round(ans))
Problem p03000 (python)

Fixed submission:
(N,M) = (int(i) for i in input().split(" "))
A = [int(i) for i in input().split()]
A.append(100000)
for i in range(N):
	A[i+1] += A[i]
	if A[i+1] > M:
		print(i+2)
		break

Buggy submission (verdict: Runtime Error):

(N,M) = (int(i) for i in input().split(" "))
A = [int(i) for i in input().split()]
for i in range(N):
	A[i+1] += A[i]
	if A[i+1] > M:
		print(i+2)
		break
Problem p03006 (python)

Fixed submission:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
P = [[int(i) for i in input().split(" ")]for _ in range(N)]

min_point = 100
for i in range(N-1):
	for j in range(i+1, N):
		p = P[i]
		q = P[j]
		if p[0] <=  q[0]:
			x = q[0]-p[0]
			y = q[1]-p[1]
			point = 0
			mp = [False for _ in range(N)]
			count = N
			index = 0
			qu = queue.Queue()
			while count:
				if not mp[index]:
					point += 1
					qu.put(P[index])
					mp[index] = True
					count -= 1
					while not qu.empty():
						top = qu.get()
						for k in range(N):
							if not mp[k] and ((top[0]-x == P[k][0] and top[1]-y == P[k][1]) or (top[0]+x == P[k][0] and top[1]+y == P[k][1])):
								count -= 1
								qu.put(P[k])
								mp[k] = True
				index += 1
			if point < min_point:
				min_point = point
if N == 1:
	min_point = 1
print(min_point)

Buggy submission (verdict: Runtime Error):

N = int(input())
P = [[int(i) for i in input().split(" ")]for _ in range(N)]

min_point = 100
for i in range(N-1):
	for j in range(i+1, N):
		p = P[i]
		q = P[j]
		if p[0] <=  q[0] and p[1] <= q[1]:
			x = q[0]-p[0]
			y = q[1]-p[1]
			point = 0
			mp = [False for _ in range(N)]
			count = N
			index = 0
			qu = queue.Queue()
			while count:
				if not mp[index]:
					point += 1
					qu.put(P[index])
					mp[index] = True
					count -= 1
					while not qu.empty():
						top = qu.get()
						for k in range(N):
							if not mp[k] and ((top[0]-x == P[k][0] and top[1]-y == P[k][1]) or (top[0]+x == P[k][0] and top[1]+y == P[k][1])):
								count -= 1
								qu.put(P[k])
								mp[k] = True
				index += 1
			if point < min_point:
				min_point = point

print(min_point)
Problem p02787 (python)

Fixed submission:
H, n = map(int, input().split())
A = []
B = []
for i in range(n):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

dp = [0 for i in range(H+1)]

for i in range(1, H+1):
	dp[i] = min(dp[i - A[j]] + B[j]  if A[j] <= i  else  B[j]  for j in range(n))

print(dp[H])

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split())
A = []
B = []
for i in range(n):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

dp = [0 for i in range(H+1)]

for i in range(H+1):
	dp[i] = min(B[j]  if h < A[j]  else  dp[i - A[j]] + B[j]  for j in range(n))

print(dp[H])
Problem p02814 (python)

Fixed submission:
import fractions

n, m = map(int, input().split())
a = list(map(int, input().split()))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def lcm(x, y):
	return (x * y) // gcd(x, y)

now = a[0]
for i in range(1, n):
	now = lcm(now, a[i])
	if now > 2 * m:
		print(0)
		exit(0)

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

print(((m//(now//2))+1)//2)

Buggy submission (verdict: Runtime Error):
import fractions
 
n, m = map(int, input().split())
a = list(map(int, input().split()))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
 
def lcm(x, y):
	return (x * y) // gcd(x, y)
 
now = a[0]
for i in range(1, n):
	now = lcm(now, a[i])
    if now > m:
		print(0)
		exit(0)
 
for i in range(n):
	if (now//a[i])%2 == 0:
		print(0)
		exit(0)
 
print(((m//(now//2))+1)//2)

Buggy submission (verdict: Runtime Error):
import fractions

n, m = map(int, input().split())
a = list(map(int, input().split()))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def lcm(x, y):
	return (x * y) // gcd(x, y)

now = a[0]
for i in range(1, n):
	now = lcm(now, a[i])

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

print(((m//(now/2))+1)//2)

Buggy submission (verdict: Runtime Error):
import math

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

def lcm(x, y):
	return (x * y) // math.gcd(x, y)

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

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

print(((m//now)+1)//2)
Problem p02953 (python)

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

for i in range(1, N):
	if H[N-i-1] > H[N-i]:
		H[N-i-1] -= 1
	
for i in range(N-1):
	if H[i] > H[i+1]:
		print("No")
		exit(0)

print("Yes")

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

for i in range(1, N):
	if H[N-i-1] > H[N-i]:
		H[N-i-1] -= 1
	
for i in range(N-1):
	if H[i] > H[i+1]:
		print("No")
		exit(1)

print("Yes")

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

for i in range(N-1):
	if H[i] > H[i+1]:
		H[i] -= 1
	
for i in range(N-1):
	if H[i] > H[i+1]:
		print("No")
		exit(1)

print("Yes")
Problem p02995 (python)

Fixed submission:
import fractions
A, B, C, D = map(int, input().split())
CD = int((C*D)/fractions.gcd(C, D))

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))

Buggy submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())
CD = int((C*D)/math.gcd(C, D))

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))

Buggy submission (verdict: Runtime Error):
import fanctions
A, B, C, D = map(int, input().split())
CD = C*D/fanctions.gcd(C, D)

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))

Buggy submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())
CD = C*D/math.gcd(C, D)

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))
Problem p03061 (python)

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

left = []
left.append(a[0])
right = []
right.append(a[n-1])
for i in range(n-2):
	right.append(fractions.gcd(right[i], a[n-2-i]))

for i in range(n):
	if i == 0:
		ma = right[n-2]
	elif i == n-1:
		if ma < left[n-2]:
			ma = left[n-2]
	else:
		gc = fractions.gcd(left[i-1], right[n-2-i])
		if ma < gc:
			ma = gc
		left.append(fractions.gcd(left[i-1], a[i]))

print(ma)

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))

left = []
left.append(a[0])
right = []
right.append(a[n-1])
for i in range(n-2):
	right.append(fractions.gcd(right[i], a[n-2-i]))

for i in range(n):
	if i == 0:
		ma = right[n-2]
	elif i == n-1:
		if ma < left[n-2]:
			ma = left[n-2]
	elif ma < fractions.gcd(left[i-1], right[n-2-i]):
		ma = fractions.gcd(left[i-1], right[n-2-i])
		left.append(fractions.gcd(left[i-1], a[i]))

print(ma)

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))

left = []
left.append(a[0])
right = []
right.append(a[n-1])
for i in range(n-2):
	right.append(fractions.gcd(right[i], a[n-2-i]))

for i in range(n):
	if i == 0:
		ma = right[n-2]
	elif i == n-1:
		if ma < left[n-2]:
			ma = left[n-2]
	elif ma < math.gcd(left[i-1], right[n-2-i]):
		ma = fractions.gcd(left[i-1], right[n-2-i])
		left.append(fractions.gcd(left[i-1], a[i]))

print(ma)

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))

left = []
left.append(a[0])
right = []
right.append(a[n-1])
for i in range(n-2):
	right.append(fractions.gcd(right[i], a[n-2-i]))

for i in range(n-1):
	if i == 0:
		ma = right[n-2]
	elif ma < fractions.gcd(left[i-1], right[n-2-i]):
		ma = fractions.gcd(left[i-1], right[n-2-i])
		left.append(fractions.gcd(left[i-1], a[i]))

print(ma)

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))

left = []
left.append(a[0])
right = []
right.append(a[n-1])
for i in range(n-2):
	right.append(fractions.gcd(right[i], a[n-2-i]))

for i in range(n-1):
	if i == 0:
		ma = right[n-2]
	elif ma < fractions.gcd(left[i-1], right[n-2-i]):
		ma = fractions.gcd(left[i-1], right[n-2-i])
		left.append(fractions.gcd(left[i-1], a[i]))

print(ma)
Problem p03240 (python)

Fixed submission:
xyh = []
n = int(input())
for i in range(n):
	x, y, h = map(int, input().split())
	xyh.append([x, y, h])

for cx in range(101):
	for cy in range(101):
		h = 0
		judge = 1
		for k in range(n):
			if xyh[k][2] > 0:
				h = xyh[k][2] + abs(cx-xyh[k][0]) + abs(cy-xyh[k][1])
				break
		for k in range(n):
			if max(h - abs(cx-xyh[k][0]) - abs(cy-xyh[k][1]), 0) != xyh[k][2]:
				judge = 0
				break
		if judge:
			print(cx, cy, h)
			exit(0)

Buggy submission (verdict: Runtime Error):
xyh = []
n = int(input())
for i in range(n):
	x, y, h = map(int, input().split())
	if h != 0:
		xyh.append([x, y, h])

judge = 0
for i in range(101):
	cx = i
	for j in range(101):
		cy = j
		h = []
		for k in range(n):
			h.append(xyh[k][2] + abs(xyh[k][0]-cx) + abs(xyh[k][1]-cy))
		if len(h) == 1:
			lst = [cx, cy, h[k]]
			lst = [str(i) for i in lst]
			print(" ".join(lst))
			exit(0)
		for k in range(len(h)-1):
			if h[k] != h[k+1]:
				break
			if k == len(h)-2:
				lst = [cx, cy, h[k]]
				lst = [str(i) for i in lst]
				print(" ".join(lst))
				exit(0)
Problem p02730 (python)

Fixed submission:
S=input()
N=len(S)

a=S[0:(int((N-1)/2))]
b=S[(int((N+3)/2)-1):(N)]

if a==b:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=N
a=a*(N-1)/2
b=M*(M-1)/2



print(int(a+b))
Problem p02780 (python)

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


maxnum=0
index=0
num=0
for i in range(len(P)):
    num+=P[i]
    if maxnum<num:
        maxnum=num
        index=i




    if i>=K-1:
        num-=P[i-(K-1)]


List=[]
for i in range(K):
    x1=P[index-i]

    sumx1=(1+x1)/2
    List.append(sumx1)


print(sum(List))

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


maxnum=0
index=0
num=0
for i in range(len(P)):
    num+=P[i]
    if maxnum<num:
        maxnum=num
        index=i




    if i>=K-1:
        num-=P[i-(K-1)]


List=[]
for i in range(K):
    x1=P[index-i]
    sumx1=sum([j for j in range(1,x1+1)])


    sumx1=sumx1/x1
    List.append(sumx1)


print(sum(List))

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


maxnum=0
index=0
num=0
for i in range(len(P)-2):
    num+=P[i]



    if maxnum<num:
        maxnum=num
        index=i

    if i>=K:
        num-=P[i-(K-1)]
List=[]

for i in range(K):
    x1=P[index+i]
    sumx1=0
    for j in range(1,x1+1):
        sumx1+=j

    sumx1=sumx1/x1
    List.append(sumx1)


print(sum(List))
Problem p02802 (python)

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


ac = 0
wa = 0
aclist = {}
walist = {}

count_WA=0
for i in range(N):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]




print(ac,wa,sep=" ")

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


ac = 0
wa = 0
aclist = {}
walist = {}

count_WA=0
for i in range(n):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]




print(ac,wa,sep=" ")
Problem p03068 (python)

Fixed submission:
N=int(input())
S=input()
K=int(input())
s=S[K-1]

X=[]*N

for i in S:

    if i==s:
        X.append(i)
    else:
        X.append("*")

Y="".join(X)
print(Y)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
K=int(input())
s=S[K]

X=[]*N

for i in S:

    if i==s:
        X.append(i)
    else:
        X.append("*")

Y="".join(X)
print(Y)
Problem p03103 (python)

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

C=[input().split() for i in range(N)]
B=[]
for i in C:
    B.append(list(map(int,i)))

B.sort()

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数
for a,b in B:
    if(M<=0):
        break
    if(b<=M):
        money+=a*b
    else:
        money+=M*a
    M-=b
print(money)

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

C=[input().split() for i in range(N)]
B=[]
for i in C:
    B.append(list(map(int,i)))

B.sort()

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    money+=B[0][0]*B[0][1]
    X+=B[0][1]
    if M<X:
        money-=B[0][0]*B[0][1]
        X-=B[0][1]
        for x in range(B[0][1]):
            m+=1
            if M=X+m:
                money+=B[0][0]*m
                print(money)
                break

    B.pop(l)#取り出す

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

C=[input().split() for i in range(N)]

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    Min=int(C[0][0])
    for i in C:#どの店で買うか
        if Min>=int(i[0]):
            Min=int(i[0])
            l=k
        k+=1
    money+=int(C[l][1])*Min
    X+=m
    if X>M:
        money-=int(C[l][1])*Min
        X-=m
        for x in range(int(C[l][1])):#何個かえるか
            m+=1
            if M==X+m:#max
                money+=m*Min
                print(money)
                break


    C.pop(l)#取り出す
    #リセット
    k=0
    l=0
    m=0#その店で買う数

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

C=[input().split() for i in range(N)]

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    Min=int(C[0][0])
    for i in C:#どの店で買うか
        if Min>=int(i[0]):
            Min=int(i[0])
            l=k
        k+=1
    money+=int(C[l][1])*Min
    X+=m
    if X>M:
        for x in range(int(C[l][1])):#何個かえるか
            m+=1
            if M==X+m:#max
                money+=m*Min
                print(money)
                break


    C.pop(l)#取り出す
    #リセット
    k=0
    l=0
    m=0#その店で買う数
Problem p03031 (python)

Fixed submission:
import numpy as np
from itertools import product

N, M = map(int, input().split())
S = np.zeros((M, N))  # (M, N), switch

for i in range(M):
    k, *s = map(int, input().split())
    s = [x - 1 for x in s]
    S[i, s] = 1
p = np.array(list(map(int, input().split())), dtype=np.int)

cnt = 0
for i in product([0, 1], repeat=N):
    a = np.array(i, dtype=np.int)  # N,
    b = (np.dot(S, a) % 2).astype(np.int)
    if np.all(b == p):
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
import numpy as np
from itertools import product

N, M = map(int, input().split())
S = np.zeros((M, N))  # (M, N), switch

for i in range(M):
    k, *s = map(int, input().split())
    s = [x - 1 for x in s]
    S[i, s] = 1
p = np.array(list(map(int, input().split())), dtype=np.int)

cnt = 0
for i in product([0, 1], repeat=N):
    a = np.array(i, dtype=np.int)  # N,
    b = (np.dot(S, a) % 2).astype(np.int)
    if np.all(b == p):
        cnt += 1
print(cnt)
Problem p03069 (python)

Fixed submission:
N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        L[i] = 1
    else:
        L[i] = 0

leftblack = 0
rightwhite = len([x for x in L if x == 0])
ans = leftblack + rightwhite

for i in range(N):
    if S[i] == "#":
        leftblack += 1
    else:
        rightwhite -=1
    ans = min(ans, leftblack + rightwhite)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        # white
        L[i] = 1
    else:
        L[i] = 0
# L = np.array(L, dtype=np.int8)
L2 = np.zeros(N, dtype=np.int16)
# ans = np.abs((L - L2)).sum()
# for i in range(N):
#     L2[N-1-i] = 1
#     ans_tmp = np.abs((L - L2)).sum()
#     ans = min(ans, ans_tmp)
# print(ans)
all_whitedist = np.abs((L - L2)).sum()
dist = np.zeros(N, dtype=np.int16)
dist[0:] = all_whitedist
dist[0] = all_whitedist
for i in range(N):
    if L[N-1-i] == 1:
        dist[i:] -= 1
    else:
        dist[:i] -= 1
indx = np.where(dist == dist.min())[0][0]
L3 = np.zeros(N, dtype=np.int16)
L3[indx:] = 1
ans_tmp = np.abs((L - L3)).sum()
print(min(all_whitedist, ans_tmp))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        # white
        L[i] = 1
    else:
        L[i] = 0
L = np.array(L, dtype=np.int8)
L2 = np.zeros(N, dtype=np.int8)
ans = np.abs((L - L2)).sum()
for i in range(N):
    L2[N-1-i] = 1
    ans_tmp = np.abs((L - L2)).sum()
    ans = min(ans, ans_tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        # white
        L[i] = 1
    else:
        L[i] = 0
L = np.array(L, dtype=np.int8)
a = np.zeros((N+1, N), dtype=np.int8)
for i in range(N):
    a[i, :i] = 1
a[N] = 1

ans = (a - L)**2
ans = ans.sum(axis=1).min()
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
S = input()

a = np.zeros((N+1, N))

for i in range(N):
    a[i, :i] = 1
a[N] = 1
L = [0] * N
for i in range(N):
    if S[i] == ".":
        # white
        L[i] = 0
    else:
        L[i] = 1
L = np.array(L)
ans = (a - L)**2
ans = ans.sum(axis=1).min()
print(int(ans))