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

Fixed submission:
n = int(input())
aka = []
ao = []
for _ in range(n):
    ab = list(map(int, input().split()))
    aka.append(ab)
aka = sorted(aka, key=lambda x:x[1], reverse=True)
for _ in range(n):
    cd = list(map(int, input().split()))
    ao.append(cd)
ao = sorted(ao)
count = 0
for a, b in aka:
    for c, d in ao:
        if a<c and b<d:
            ao.remove([c,d])
            count+=1
            break
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
aka = []
ao = []
for _ in range(n):
    ab = sorted(list(map(int, input().split())), key=lambda x:x[1], reverse=True)
    aka.append(ab)
for _ in range(n):
    cd = sorted(list(map(int, input().split())))
    ao.append(cd)
count = 0
for a, b in aka:
    for c, d in ao:
        if a<c and b<d:
            ao.remove(c,d)
            count+=1
            break
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
aka = []
ao = []
for _ in range(n):
    ab = sorted(list(map(int, input().split())), key=lambda x:x[1], reverse=True)
    aka.append(ab)
for _ in range(n):
    cd = sorted(list(map(int, input().split())))
    ao.append(cd)
count = 0
for a, b in aka:
    for c, d in ao:
        if a<c and b<d:
            ao.remove(c,d)
            count+=1
print(count)
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
ab = a*b
if ab % 2 == 0:
    print('Even')
else:
    print('Odd')

Buggy submission (verdict: Runtime Error):
a, b = int(input()), int(input())
ab = a*b
if ab % 2 == 0:
    print('Even')
else:
    print('Odd')
Problem p03545 (python)

Fixed submission:
s = input()
l = len(s)

for i in range(2**(l-1)):
    f = ""
    for j in range(l-1):
        f += s[j]
        if i & (1 << j):
            f += "+"
        else:
            f += "-"
        if j == l-2:
             f += s[l-1]
    if eval(f)==7:
        print(f+"=7")
        break

Buggy submission (verdict: Runtime Error):
for i in range(2**(l-1)):
    f = ""
    for j in range(l-1):
        f += s[j]
        if i & (1 << j):
            f += "+"
        else:
            f += "-"
        if j == l-2:
             f += s[l-1]
    if eval(f)==7:
        print(f+"=7")
        break
Problem p03351 (python)

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

a = il[0]
b = il[1]
c = il[2]
d = il[3]

connectable = False
#print(abs(a-b))
#print(abs(b-c))
#print(abs(a-c))

if abs(a-b) <= d and abs(b-c) <= d:
    connectable = True
elif abs(a-c) <= d:
    connectable = True
else:
    pass


if connectable:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
X = int(input())
 
score =0
half_x = round(X/2)
 
answer = 0
 
if X < 3:
    print(1)
 
elif X <= 7:
    print(4)
 
else:
    while 1 < half_x:
        half_x -= 1
        
        for p in range(2, 10):
            
            score = pow(half_x,p)
            if score > X:
                continue
        
            if answer < score:
                answer = score
                
    print(answer)
Problem p03352 (python)

Fixed submission:
X = int(input())

score =0
half_x = round(X/2)

answer = 0

if X < 3:
    print(1)

elif X <= 8:
    print(2)

else:
    while 1 < half_x:
        half_x -= 1
        
        for p in range(2, 10):
            
            score = pow(half_x,p)
            if score > X:
                continue
        
            if answer < score:
                answer = score
                
    print(answer)

Buggy submission (verdict: Runtime Error):
from math import sqrt

x = int(input())
sqrt_x = int(sqrt(x))
ans = 1

for b in range(sqrt_x):
    for p in range(sqrt_x-1):
        exp = (b+1)**(p+2)
    if exp<=x and ans<=exp:
        ans = exp
        
print(ans)
Problem p03547 (python)

Fixed submission:
input_line = input().split()

first = int(input_line[0], 16)
second = int(input_line[1], 16)

if first < second:
    print('<')
elif first > second:
    print('>')
elif first == second:
    print('=')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
print((100*(N-M) + 1900*M)*pow(2,M))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
print((100*(N-M) + 1900*M)*pow(2,M))
Problem p03644 (python)

Fixed submission:
N = int(input())
score = 0
ans = 0
if N == 1:
    print(1)
else:
    for i in range(N,0,-1):
        s = i
        c=0
        while (i % 2 == 0) :
            i /= 2
            c += 1
        if score < c:
            score = c
            ans = s
        #カウントが更新されたらスコア配列に格納
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
score = 0

for i in range(N,0,-1):
    s = i
    c=0
    while (i % 2 == 0) :
        i /= 2
        c += 1
    if score < c:
        score = c
        ans = s
    #カウントが更新されたらスコア配列に格納
print(ans)
Problem p03657 (python)

Fixed submission:
a = input().split(' ')
b = list(map((int), a))
sum = sum(b)
A = b[0]
B = b[1]

if sum % 3 == 0 or A % 3 == 0 or B % 3 == 0:
    print('Possible')

else:
    print('Impossible')

Buggy submission (verdict: Runtime Error):
a = input()
card_list = list(map((int),input().split(' ')))

sum_card = sum(card_list)
score = []
sunuke = 0

for i in range(int(a)-1):
    
    sunuke += card_list[i]
    score.append(abs(sum_card-2*sunuke))

print(min(score))

Buggy submission (verdict: Runtime Error):
a = input().split(' ')
b = list(map((int), a))
sum = sum(b)
A = sum[0]
B = sum[1]

if sum % 3 == 0 || A % 3 == 0 || B % 3 == 0:
    print('Possible')

else:
    print('Impossible')
Problem p02657 (python)

Fixed submission:
A,B = map(int, input().split())
print(A*B)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
r=1
if 0 in A:
    r=0
for n in A:
    r=r*n
    if r>10**18:
        r=-1
        break
print(r)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
r=1
for n in A:
    r=r*n
    if r==0:
        print(0)
    elif r>10**18:
        print(-1)
    else:
        print(r)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
r=1
for n in A:
    r=r*n
print(-1 if r>10**18 else r)
Problem p02730 (python)

Fixed submission:
S = input()
L=len(S)
ans=0
S1=S[:(L-1)//2]
S2=S[((L+3)//2)-1:]
if (S==S[::-1]) & (S1==S1[::-1]) & (S2==S2[::-1]):
    ans='Yes'
else:
    ans='No'
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L=len(S)
ans='No'
    if S[:(L-1)/2]==S[(L-1)/2-1::-1] and S[L+3/2-1:]==S[:(L+3/2)-2:-1]:
    ans='Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L=len(S)
ans='No'
    if S[:(L-1)/2+1]==S[(L-1)/2-1::-1] and S[L+3/2:]==S[:(L+3/2)-2:-1]:
    ans='Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L=len(S)
ans='No'
for i in S:
    if S[:(L-1)/2+1]==S[(L-1)/2+1::-1] and S[L+3/2:]==S[:(L+3/2)-1:-1]:
    ans='Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L=len(S)
ans='No'
for i in S:
    if S==S[::-1] and S[:(L-1)/2+1]==S[(L-1)/2+1::-1] and S[L+3/2:]==S[:(L+3/2)-1:-1]:
    ans='Yes'
print(ans)
Problem p02817 (python)

Fixed submission:
S,T = input().split()
print(T+S)

Buggy submission (verdict: Runtime Error):
S = input() 
T = input() 
print(S+T)
Problem p02887 (python)

Fixed submission:
N = int(input())
S = input()
ans=0
for i in range(1,N):
    if S[i]!=S[i-1]:
        ans+=1
print(ans+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
ans=0
for i in range(1,N):
    if S[i]!=S[i-1]
        ans+=1
print(ans+1)
Problem p02993 (python)

Fixed submission:
a,b,c,d = input()
print("Bad" if a==b or b==c or c==d else "Good")

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())
print("Bad" if a==b or b==c or c==d else "Good")
Problem p02681 (python)

Fixed submission:
a=input()
b=input()
b = b[:-1]

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

Buggy submission (verdict: Runtime Error):
a,b=input().split()
b = b[:-1]

if a ==b:
    print('Yes')
else:
    print('No')
Problem p02719 (python)

Fixed submission:
n, m = (int(x) for x in input().split())

a = n % m
b = n / m
if abs(a-m) > a:
    print(a)
else:
    print(abs(a-m))

Buggy submission (verdict: Runtime Error):
n, m = (int(x) for x in input().split())
num_point = [int(x) for x in input().split()]
count = 0

for n in num_point:
    if n > (sum(num_point) / (4 * m)):
        count += 1

if count < m:
    print("No")
else:
    print("Yes")
Problem p02613 (python)

Fixed submission:
N = int(input())
s = [input() for i in range(N)]
for v in ['AC', 'WA', 'TLE', 'RE']:
    print('{} x {}'.format(v, s.count(v)))

Buggy submission (verdict: Runtime Error):
n = int(input())
c0 = c1 = c2 = c3 = 0
for _ in range(n):
  s = input()
  if s == "AC":
    c0 += 1
  elif s == "WA":
    c1 += 1
  elif s == "TLE":
    c2 += 1
  else
  	c3 += 1

print("AC x", c0, sep = " ")
print("WA x", c1, sep = " ")
print("TLE x", c2, sep = " ")
print("RE x", c3, sep = " ")

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

dct = dict(Counter(a))
for v, num in dct.items():
  print(v + " x " + num)

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

dct = dict(Counter(a))
for v, num in dct.items():
  print(f"{v} x {num})
Problem p02621 (python)

Fixed submission:
a = int(input())

print(a+a**2+a**3)

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

print(a+a**2+(a*(a**2)))
Problem p02628 (python)

Fixed submission:
n, k = map(int, input().split())
pr = list(map(int, input().split()))
 
pr.sort()
 
print(sum(pr[0:k]))

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

pr.sort()

print(sum(pr[0:k])
Problem p03892 (python)

Fixed submission:
import fractions

def main():
    a,b,c,d = map(int,input().split())
    a,c = min(a,c),max(a,c)
    b,d = min(b,d),max(b,d)

    c -= a
    a = 0
    d -= b
    b = 0

    if a==c or b==d:
        return 0

    g = fractions.gcd(c,d)
    c//=g
    d//=g
    ct = c+d-1
    return g*ct

if __name__ == '__main__':
    print(main())

Buggy submission (verdict: Runtime Error):
import math

def main():
    a,b,c,d = map(int,input().split())
    a,c = min(a,c),max(a,c)
    b,d = min(b,d),max(b,d)

    c -= a
    a = 0
    d -= b
    b = 0

    if a==c or b==d:
        return 0

    g = math.gcd(c,d)
    c//=g
    d//=g
    ct = c+d-1
    return g*ct

if __name__ == '__main__':
    print(main())
Problem p02705 (python)

Fixed submission:
R=float(input())
print(2*R*3.141592)

Buggy submission (verdict: Runtime Error):
R=input()
print(R*3.141592)

Buggy submission (verdict: Runtime Error):
import math
R=input()
print(R*math.pi)
Problem p02641 (python)

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

for i in range(101):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Buggy submission (verdict: Runtime Error):
import copy
x,n = list(map(int, input("").split()))
p = list(map(int, input("").split()))

mina =101
y = []
minc = []

if x not in p:
    print(x)
    exit()

for i in range(1,101):
    y.append(i)

if n == 0:
    print(x)
else:
    for j in range(n):
        y.remove(p[j])

    z = copy.copy(y)

    for k in range(len(y)):
        if abs(x - y[k]) < mina:
            mina = abs(x - y[k])
            minb = y[k]
            z.remove(minb)

    minc.append(minb)
    mina = 101

    for m in range(len(z)):
        if abs(x - z[m]) < mina:
            mina = abs(x - z[m])
            minb = z[m]

    minc.append(minb)

    print(min(minc))

Buggy submission (verdict: Runtime Error):
import copy
x,n = list(map(int, input("").split()))
p = list(map(int, input("").split()))

mina =101
y = []
minc = []

for x not in p:
    print(x)
    exit()

for i in range(1,101):
    y.append(i)

if n == 0:
    print(x)
else:
    for j in range(n):
        y.remove(p[j])

    z = copy.copy(y)

    for k in range(len(y)):
        if abs(x - y[k]) < mina:
            mina = abs(x - y[k])
            minb = y[k]
            z.remove(minb)

    minc.append(minb)
    mina = 101

    for m in range(len(z)):
        if abs(x - z[m]) < mina:
            mina = abs(x - z[m])
            minb = z[m]

    minc.append(minb)

    print(min(minc))

Buggy submission (verdict: Runtime Error):
import copy
x,n = list(map(int, input("").split()))
p = list(map(int, input("").split()))

mina =101
y = []
minc = []


for i in range(1,101):
    y.append(i)

if n == 0:
    print(x)
else:
    for j in range(n):
        y.remove(p[j])

    z = copy.copy(y)

    for k in range(len(y)):
        if abs(x - y[k]) < mina:
            mina = abs(x - y[k])
            minb = y[k]
            z.remove(minb)

    minc.append(minb)
    mina = 101

    for m in range(len(z)):
        if abs(x - z[m]) < mina:
            mina = abs(x - z[m])
            minb = z[m]

    minc.append(minb)

    print(min(minc))
Problem p02646 (python)

Fixed submission:
a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(input())

l  = abs(a-b)

if (v - w) * t >= l:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a, v = list(map(int, input("").split()))
b, w = list(map(int, input("").split()))
t = int(input(""))

l  = abs(a-b)

if (v - w) * t >= l:
    Print("YES")
else:
    Print("NO")

Buggy submission (verdict: Runtime Error):
a, v = list(map(long, input("").split()))
b, w = list(map(long, input("").split()))
t = long(input(""))

if b > a:
    if a + v * t >= b + w * t:
        print("YES")
    else:
        print("NO")
else:
    if v > w:
        print("NO")
    else:
        if b + w * t >= a + v * t:
            print("YES")
        else:
            print("No")
Problem p02886 (python)

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

kaihuku = 0

for i in range(n-1):
    for j in range(i+1,n):
        kaihuku += d[i] * d[j]

print(kaihuku)

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

kaihuku = 0

for i in range(n-1):
    for j in range(i+1,n):
        kaihuku += d(i) * d(j)

print(kaihuku)
Problem p03796 (python)

Fixed submission:
n = int(input())
power = 1
for i in range(1,n+1):
    power *= i
    power = power % (10 ** 9 + 7)

print(power % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
n = int(input())
power = 1
for i in range(1,n+1):
    power *= i
    power = power % (10 ** 9 + 7))

print(power % (10 ** 9 + 7))
Problem p03076 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
inputs = []
inputs.append(int(input()))
inputs.append(int(input()))
inputs.append(int(input()))
inputs.append(int(input()))
inputs.append(int(input()))
amari_list = []
time = 0
for input in inputs:
  amari = input % 10
  if amari == 0:
    time += input
  else:
    time += (input // 10) * 10
    amari_list.append(amari)
if len(amari_list) > 0:
  time += (len(amari_list) - 1)*10
  time += min(amari_list)
# 出力
print(time)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
inputs = []
inputs.append(int(input()))
inputs.append(int(input()))
inputs.append(int(input()))
inputs.append(int(input()))
inputs.append(int(input()))
amari_list = []
time = 0
for input in inputs:
  amari = input % 10
  if amari == 0:
    time += input
  else:
    time += (input // 10) * 10
    amari_list.append(amari)
time += (len(amari_list) - 1)*10
time += min(amari_list)
# 出力
print(time)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(a*b)
Problem p02641 (python)

Fixed submission:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

def bin(arr, val):
    l,r = 0, len(arr)-1
    while l <= r:
        mid = (l + r)//2
        if arr[mid] == val: return 1
        elif arr[mid] <= val: l = mid + 1
        elif arr[mid] >= val: r = mid - 1
    return 0

x,n = imap()
p = sorted(iarr())

for i in range(n+1):
    a,b = x-i,x+i
    if not bin(p,a): ans = a; break
    if not bin(p,b): ans = b; break

if n==0: ans = x
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

def bin(arr, val):
    l,r = 0, len(arr)-1
    while l <= r:
        mid = (l + r)//2
        if arr[mid] == val: return 1
        elif arr[mid] <= val: l = mid + 1
        elif arr[mid] >= val: r = mid - 1
    return 0

x,n = imap()
p = sorted(iarr())

for i in range(n):
    a,b = x-i,x+i
    if not bin(p,a): ans = a; break
    if not bin(p,b): ans = b; break

if n==0: ans = x
print(ans)
Problem p02642 (python)

Fixed submission:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

n = iinput()
a = iarr()
amax = max(a)
#amax = 10**6

cnt = [0 for i in range(amax+1)]
for num in a:
    for i in range(1,amax//num + 1):
        tmp = num * i
        cnt[tmp] += 1

ans = 0
for num in a:
    if cnt[num]==1: ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

n = iinput()
a = iarr()
amax = 10**6 + 1

dp = [1 for i in range(amax)]
for num in a:
    for i in range(2, amax//num + 1): dp[num * i] = 0

cnt = col.Counter(a)

ans = 0
for num in a:
    if dp[num] and cnt[num]==1: ans += 1

print(ans)
Problem p02665 (python)

Fixed submission:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n = iinput()
a = iarr()

cum = []; sum = 0
for num in a: sum += num; cum.append(sum)

ans = 1
now = 1
for i in range(n+1):
    next = min(2*(now - a[i]), cum[n]-cum[i])
    now = next
    if n==i and next<0 : ans = -1; break
    if n!=i and next<=0 : ans = -1; break
    ans += next

if a[n] > 2**n: ans = -1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n = iinput()
a = iarr()

cum = []; sum = 0
for num in a: sum += num; cum.append(sum)

ans = 1
now = 1
for i in range(n):
    next = min(2*(now - a[i]), cum[n]-cum[i])
    now = next
    if n==i and next<0 : ans = -1; break
    if n!=i and next<=0 : ans = -1; break
    ans += next

if a[n] > 2**n: ans = -1
if a[1] < 2: ans = -1
print(ans)
Problem p02683 (python)

Fixed submission:
import numpy as np
n,m,x = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]

ans = np.inf
flag = 0
for i in range(2**n):
    r = np.array([0]*(m+1))
    for j in range(n):
        if (i>>j)&1:
            for k in range(m+1): r[k] += a[j][k]
    if np.all(r[1:]>=x):
        if ans > r[0]: ans = r[0]
        flag = 1
    else: flag = 0

if flag: print(ans)
else: print("-1")

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

n,m,x = map(int,input().split())
arr = np.array([list(map(int,input().split())) for i in range(n)])
c = arr.T[0] # c[n-1]まで
a = arr.T[1:].T # a[n-1][m-1]まで

ans = np.inf
for i in range(2**n):
    ability = np.zeros(m, np.int64)
    cost = 0
    # 二進数の右から0番目〜n-1番目をみていき、使用or不使用を判断
    for j in range(n):
    # 使用する場合にability/costを更新
        if (i>>j)&1: ability += a[j] ; cost += c[j]
    # 条件クリアしている場合にansを更新
    if np.all(ability>=x): ans = min(ans,cost)

# ansが無限なら、未更新＝条件クリアしてないので-1を出力
ans = -1 if ans==np.inf else ans
print(ans)

Buggy submission (verdict: Runtime Error):


import numpy as np
N,M,X = map(int,input().split())
arr = np.array([list(map(int,input().split())) for i in range(n)])
C = arr.T[0]
A = arr.T[1:].T


cost = np.zeros(1<<N, np.int64)
ability = np.zeros((1<<N, M), np.int64)
for i in range(N):
    cost[1<<i:1<<(i+1)] = cost[:1<<i] + C[i]
    ability[1<<i:1<<(i+1)] = ability[:1<<i] + A[i]

ok = np.all(ability >= X, axis=1)

x = cost[ok]
answer = -1 if len(x) == 0 else x.min()
print(answer)