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

Fixed submission:
N = int(input())
X, U = [], []
for i in range(N):
    x, u = input().split(" ")
    X.append(float(x))
    U.append(u)

ans = 0
for i in range(N):
    if U[i] == 'BTC':
        ans += X[i] * 380000
    else:
        ans += X[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
X, U = [], []
for i in range(N):
    x, u = input().split(" ")
    X.append(float(x))
    U.append(u)

ans = 0
for i in range(N):
    if u == 'BTC':
        ans += x * 380000
    else:
        ans += x
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
X, U = [], []
for i in range(N):
    x, u = map(int, input().split(" "))
    X.append(x)
    U.append(u)

ans = 0
for i in range(N):
    if u == 'BTC':
        ans += x * 380000
    else:
        ans += x
print(ans)
Problem p03200 (python)

Fixed submission:
S = input()
 
arr = [0 if s == "W" else 1 for s in S]
sorted_arr = sorted(arr)
  
state = sum([arr[i] * i for i in range(len(S))])
final_state = sum([sorted_arr[i] * i for i in range(len(S))])
 
print(final_state - state)

Buggy submission (verdict: Runtime Error):
S = input()
 
arr = [0 if s == "W" else 1 for s in S]
sorted_arr = sorted(arr)
 
state = [arr[i] * i for i in range(len(S))]
final_state = [sorted_arr[i] * i for i in range(len(S))]
 
print(final_state - state)
S = input()

arr = [0 if s == "W" else 1 for s in S]

state = sum([arr[i] * i for i in range(len(S))])
final_state = sum([sorted(arr)[i] * i for i in range(len(S))])

print(final_state - state)

Buggy submission (verdict: Runtime Error):
S = input()
 
arr = [0 if s == "W" else 1 for s in S]
 
state = [arr[i] * i for i in range(len(S))]
final_state = [sorted(arr)[i] * i for i in range(len(S))]
 
print(final_state - state)
S = input()

arr = [0 if s == "W" else 1 for s in S]

state = sum([arr[i] * i for i in range(len(S))])
final_state = sum([sorted(arr)[i] * i for i in range(len(S))])

print(final_state - state)

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

arr = [0 if s == "W" else 1 for s in S]

state = [arr[i] * i for i in range(len(S))]
final_state = [sorted(arr)[i] * i for i in range(len(S))]

print(final_state - state)
Problem p03206 (python)

Fixed submission:
D = int(input())
n_eve = 25 - D
text = "Christmas"
for _ in range(n_eve):
    text += " Eve"
print(text)

Buggy submission (verdict: Runtime Error):
D = int(input())
n_eve = 25 - D
text = "Christmas"
for _ in n_eve:
    text += " Eve"
print(text)
Problem p03231 (python)

Fixed submission:
import fractions
 
N, M = [int(i) for i in raw_input().split(" ")]
S = raw_input()
T = raw_input()
 
def solve():
    gcd = fractions.gcd(N, M)
    for i in range(1, gcd + 1):
        if S[-int(N / gcd) * i] != T[-int(M / gcd) * i]:
            return -1
    return int(N * M / gcd)
 
print(solve())

Buggy submission (verdict: Runtime Error):
import math
 
N, M = [int(i) for i in input().split(" ")]
S = input()
T = input()
 
def solve():
    gcd = math.gcd(N, M)
    for i in range(1, gcd + 1):
        if S[-int(N / gcd) * i] != T[-int(M / gcd) * i]:
            return -1
    return int(N * M / gcd)
 
print(solve())

Buggy submission (verdict: Runtime Error):
import math
 
N, M = [int(i) for i in input().split(" ")]
S = input()
T = input()
 
def solve():
    gcd = math.gcd(N, M)
    for i in range(1, gcd + 1):
        if S[-int(N / gcd) * i] != T[-int(M / gcd) * i]:
            return -1
    return int(N * M / gcd)
 
print(solve())

Buggy submission (verdict: Runtime Error):
import math

N, M = [int(i) for i in input().split(" ")]
S = input()
T = input()

def solve():
    gcd = math.gcd(N, M)
    for i in range(1, gcd + 1):
        if S[-int(N / gcd) * i] != T[-int(M / gcd) * i]:
            return -1
    return N * M / gcd

print(solve())

Buggy submission (verdict: Runtime Error):
import math

N, M = [int(i) for i in input().split(" ")]
S = input()
T = input()

print(-1 if S[0] != T[0] else int(N * M / math.gcd(N, M)))
Problem p02603 (python)

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

#hoge日めにhoge枚の株券持ち
dp = [-7 for _ in range(n+1)]

dp[0] = 1000

#　i日目の所持金
for i in range(1,n+1):
    dp[i] = dp[i-1]
    for j in range(i):
        buy = dp[j]//l[j]
        tmp = dp[j]%l[j] + buy*l[i-1]
        dp[i] = max(dp[i], tmp)

print(dp[n])

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

#hoge日めにhoge枚の株券持ち
dp = [[-10 for _ in range(2010)] for _ in range(n+1)]

dp[0][0] = 1000

#　i日目にj枚の株を持っているときに
for i in range(n):
    for j in range(2005):
        if dp[i][j] < 0:
            continue
        #print("i: %d, j: %d, dp: %d"%(i,j,dp[i][j]) )
        maxbuy = dp[i][j]//l[i]
        for k in range(maxbuy+1):
            dp[i+1][j+k] = max(dp[i+1][j+k], dp[i][j]-l[i]*k)
        for k in range(j+1):
            dp[i+1][j-k] = max(dp[i+1][j-k], dp[i][j]+l[i]*k)
print(dp[n][0])
Problem p03005 (python)

Fixed submission:
n,m=map(int,input().split())
if m==1:
    print(0)
else:
    print(n-m)

Buggy submission (verdict: Runtime Error):
n,m=map(int(input().split()))
if m=1:
    print(0)
else:
    print(n-m)

Buggy submission (verdict: Runtime Error):
n,m=map(int(input().split()))
if m=1:
    print(0)
else:
    print(m-n)
Problem p03061 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
s=[[0]for _ in range(n)]
#print(s)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

l.sort()
ans=1

b=l[1]
bl=make_divisors(b)
for i in bl:
    check=True
    for j in range(1,n):
        if l[j]%i!=0:
            check=False
            break
    if check:
        ans=max(ans,i)
        break
a=min(l)
al=make_divisors(a)
#print(al)
for i in al:
    cnt=0
    for j in range(n):
        if l[j]%i!=0:
            cnt+=1
        if cnt>1:
            break
    if cnt==0 or cnt==1:
        ans=max(ans,i)
        break
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
s=[[0]for _ in range(n)]
#print(s)

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
for i in range(n):
    if i==0:
        s[0]=l[1:]
    
    else:
        s[i]=l[:i]+l[i+1:]
ans=1
for i in s:
    ans=max(gcd_list(i),ans)
print(ans)
Problem p03152 (python)

Fixed submission:
n,m=map(int,input().split())
r=list(map(int,input().split()))
c=list(map(int,input().split()))
r.sort(reverse=True)
c.sort(reverse=True)
dict1={}
dict2={}
for i in range(n):
    dict1.setdefault(r[i],0)
    dict1[r[i]]+=1
for i in range(m):
    dict2.setdefault(c[i],0)
    dict2[c[i]]+=1
x,y=0,0
ans=1
mod=10**9+7
for i in range(n*m,0,-1):
    dy=dict1.get(i,0)
    dx=dict2.get(i,0)
    if dx*dy==1:
        x+=1
        y+=1
    elif dx==0 and dy==1:
        ans*=x
        y+=1
    elif dy==0 and dx==1:
        ans*=y
        x+=1
    else:
        ans*=(x*y-(n*m-i))
        ans%=mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import math

n,m=map(int,input().split())
r=list(map(int,input().split()))
c=list(map(int,input().split()))
r.sort(reverse=True)
c.sort(reverse=True)
a=min(min(r),min(c))
dict1={}
dict2={}
for i in range(n):
    dict1.setdefault(r[i],0)
    dict1[r[i]]+=1
for i in range(m):
    dict2.setdefault(c[i],0)
    dict2[c[i]]+=1
x,y=0,0
ans=1
if dict1.get(n*m)*dict2.get(n*m)>1:
    print(0)
    exit()
for i in range(n*m,a-1,-1):
    table=x*y
    ex=table-(n*m-i)
    dy=dict1.get(i,0)
    dx=dict2.get(i,0)
    x+=dx
    y+=dy
    if dx*dy==1:
        ans*=1
    elif dx==0 and dy==1:
        ans*=x
    elif dy==0 and dx==1:
        ans*=y
    else:
        ans*=(x*y-(n*m-i))
b=math.factorial(a-1)
mod=10**9+7
ans*=(b%mod)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
r=list(map(int,input().split()))
c=list(map(int,input().split()))
r.sort(reverse=True)
c.sort(reverse=True)
dict1={}
dict2={}
for i in range(n):
    dict1.setdefault(r[i],0)
    dict1[r[i]]+=1
for i in range(m):
    dict2.setdefault(c[i],0)
    dict2[c[i]]+=1
x,y=0,0
ans=1
if dict1.get(n*m)*dict2.get(n*m)>1:
    print(0)
    exit()
for i in range(n*m,0,-1):
    table=x*y
    ex=table-(n*m-i)
    dy=dict1.get(i,0)
    dx=dict2.get(i,0)
    x+=dx
    y+=dy
    if dx*dy==1:
        ans*=1
    elif dx==0 and dy==1:
        ans*=x
    elif dy==0 and dx==1:
        ans*=y
    else:
        ans*=(x*y-(n*m-i))
print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
r=list(map(int,input().split()))
c=list(map(int,input().split()))
r.sort(reverse=True)
c.sort(reverse=True)
dict1={}
dict2={}
for i in range(n):
    dict1.setdefault(r[i],0)
    dict1[r[i]]+=1
for i in range(m):
    dict2.setdefault(c[i],0)
    dict2[c[i]]+=1
x,y=0,0
ans=1
if dict1.get(n*m)*dict2.get(n*m)>1:
    print(0)
    exit()
for i in range(n*m,0,-1):
    table=x*y
    ex=table-(n*m-i)
    dy=dict1.get(i,0)
    dx=dict2.get(i,0)
    print(ans,x,y)
    x+=dx
    y+=dy
    if dx*dy==1:
        ans*=1
    elif dx==0 and dy==1:
        ans*=x
    elif dy==0 and dx==1:
        ans*=y
    else:
        ans*=(x*y-(n*m-i))
print(ans%(10**9+7))
Problem p03316 (python)

Fixed submission:
import sys
import string
input=sys.stdin.readline

n1=int(input())
n=n1
b=0
while n>0:
    a=n%10
    n=n//10
    b+=a
#print(b)
if n1%b==0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
import string
input=sys.stdin.readline

n=(input())
l=list(n)
n=int(n)
a=0
for i in range(len(l)):
    a+=int(l[i])
if n%a==0:
    print('Yes')
else:
    print('No')
Problem p03339 (python)

Fixed submission:
N=int(input())
S=input()
 
count=S[1:].count("E")
mincount=count
 
for i in range(1,N):
    if S[i]=="E":
        count-=1
    if S[i-1]=="W":
        count+=1
 
 
    mincount=min(count,mincount)
print(mincount)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import math

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[math.inf]
for i in range(n):
    if ls[i]==1:
        a-=1
        l.append(a)
    elif ls[i]==0:
        a+=1
        l.append(a-1)
print(min(l))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import math

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[math.inf]
for i in range(n):
    if ls[i]==1:
        a-=1
        l.append(a)
    elif ls[i]==0:
        a+=1
        l.append(a-1)
print(min(l))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import math

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[math.inf]
for i in range(n):
    if ls[i]==1:
        a-=1
        l.append(a)
    elif ls[i]==0:
        a+=1
        l.append(a-1)
print(min(l))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import math

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[math.inf]
for i in range(n):
    if ls[i]==1:
        a-=1
        l.append(a)
    elif ls[i]==0:
        a+=1
        l.append(a-1)
print(min(l))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import math

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[math.inf]
for i in range(n):
    if ls[i]==1:
        a-=1
        l.append(a)
    elif ls[i]==0:
        a+=1
        l.append(a-1)
print(min(l))
Problem p03387 (python)

Fixed submission:
import sys
input=sys.stdin.readline

l=list(map(int,input().split()))
a,b,c=sorted(l)
#print(a,b,c)
if a%2==b%2 and a%2==c%2:
    print((2*c-a-b)//2)
elif a%2==b%2:
    print((2*c-2-a-b)//2+1)
else:
    print((2*c+1-a-b)//2+1)

Buggy submission (verdict: Runtime Error):
mport sys
input=sys.stdin.readline

l=list(map(int,input().split()))
a,b,c=sorted(l)
#print(a,b,c)
if a%2==b%2 and a%2==c%2:
    print((2*c-a-b)//2)
elif a%2==b%2:
    print((2*c-2-a-b)//2+1)
else:
    print((2*c+1-a-b)//2+1)
Problem p03469 (python)

Fixed submission:
s=list(input())
s[3]='8'
for i in range(len(s)):
    print(s[i],end='')

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

n,y=map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            print(i,j,n-i-j)
            exit()
print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

n,y=map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            print(i,j,(n-i-j))
            exit()
print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split())
for i in range(n):
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            print(i,j,(n-i-j))
            exit()
print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split())
#print(n,y)
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split())
#print(n,y)
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            print(i,j,n-i-j)
            exit()
        else:
            print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split())
#print(n,y)
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            print(i,j,n-i-j)
            exit()
        else:
            print(-1,-1,-1)
Problem p03495 (python)

Fixed submission:
import collections
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
l=list(map(int,input().split()))
#print(l)
s=collections.Counter(l)
s=s.most_common()
#print(s)
a=0
for i in range(k,len(s)):
    a+=s[i][1]
print(a)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
#print(l)
s=collections.Counter(l)
s=s.most_common()
#print(s)
a=0
for i in range(k,len(s)):
    a+=s[i][1]
print(a)
Problem p03545 (python)

Fixed submission:
a,b,c,d=map(int,input())
s=[1,-1]
f=['+','-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+b*s[i]+c*s[j]+d*s[k]==7:
                    print(str(a)+f[i]+str(b)+f[j]+str(c)+f[k]+str(d)+'=7')
                    exit()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

a,b,c,d=map(int,input())
s=[1,-1]
f=['+','-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+b*s[i]+c*s[j]+d*s[k]==7:
                    print(str(a)+f[i]+str(b)+f[j]+str(c)+f[k]+str(d)+'=7')
                    exit()
Problem p03565 (python)

Fixed submission:
s=input()
t=input()
l=[]
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j]!=t[j] and s[i+j]!='?':
            break
    else:
        a=s[:i]+t+s[i+len(t):]
        l.append(a.replace('?', 'a'))
l.sort()
if l:
    print(l[0])
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
l=[]
for i in range(len(s)-len(t)+1):
    sl=copy.deepcopy(s)
    for j in range(len(t)):
        if sl[i+j]!=t[j] and sl[i+j]!='?':
            break
    else:
        s = s[:i] + t + s[i+len(t):]
        l.append(s.replace('?', 'a'))
l.sort()
if l:
    print(l[0])
else:
    print('UNRESTRABLE')
Problem p03607 (python)

Fixed submission:
import sys
import collections
input=sys.stdin.readline

n=int(input())
l=[int(input()) for i in range(n)]
ls=collections.Counter(l)
#print(ls)
a=0
for value in ls.values():
    if value%2==1:
        a+=1
print(a)

Buggy submission (verdict: Runtime Error):
mport sys
import collections
input=sys.stdin.readline

n=int(input())
l=[int(input()) for i in range(n)]
ls=collections.Counter(l)
#print(ls)
a=0
for value in ls.values():
    if value%2==1:
        a+=1
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[int(input()) for i in range(n)]
ls=collections.Counter(l)
#print(ls)
a=0
for value in ls.values():
    if value%2==1:
        a+=1
print(a)
Problem p03611 (python)

Fixed submission:
import collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=list(s.items())
s=sorted(s,key=lambda x:x[0])
#print(s)
f=[0]*len(s)
for i in range(len(s)):
    f[i]=s[i][1]
    if i>=1:
        if s[i-1][0]==s[i][0]-1:
            f[i]+=s[i-1][1]
    if i<=len(s)-2:
        if s[i+1][0]==s[i][0]+1:
            f[i]+=s[i+1][1]
print(max(f))

Buggy submission (verdict: Runtime Error):
iimport collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=list(s.items())
s=sorted(s,key=lambda x:x[0])
#print(s)
f=[0]*len(s)
for i in range(len(s)):
    f[i]=s[i][1]
    if i>=1:
        if s[i-1][0]==s[i][0]-1:
            f[i]+=s[i-1][1]
    if i<=len(s)-2:
        if s[i+1][0]==s[i][0]+1:
            f[i]+=s[i+1][1]
print(max(f))
Problem p03645 (python)

Fixed submission:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
#print(n,m,l)
def bin_search(a,li):
    max_len=len(li)-1
    min_len=0
    while max_len>=min_len:
        mid=(max_len+min_len)//2
        if li[mid]==a:
            return True
        elif li[mid]<a:
            min_len=mid+1
        else:
            max_len=mid-1
s=[]
g=[]
for i in l:
    if i[0]==1:
        s.append(i[1])
    if i[1]==n:
        g.append(i[0])
g.sort()
for i in s:
    if bin_search(i,g):
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
#print(n,m,l)
def bin_search(a,li):
    max_len=len(li)
    min_len=0
    while max_len>=min_len:
        mid=(max_len+min_len)//2
        if li[mid]==a:
            return True
        elif li[mid]<a:
            min_len=mid+1
        else:
            max_len=mid-1
s=[]
g=[]
for i in l:
    if i[0]==1:
        s.append(i[1])
    if i[1]==n:
        g.append(i[0])
g.sort()
for i in s:
    if bin_search(i,g):
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
#print(n,m,l)
def bin_search(a,li):
    max_len=len(li)
    min_len=0
    while max_len>min_len:
        mid=(max_len+min_len)//2
        if li[mid]==a:
            return True
        elif abs(min_len-max_len)==1 and li[min_len]!=a and li[max_len]!=a:
            break
        elif li[mid]<a:
            min_len=mid
        else:
            max_len=mid
s=[]
g=[]
for i in l:
    if i[0]==1:
        s.append(i[1])
    if i[1]==n:
        g.append(i[0])
g.sort
for i in s:
    if bin_search(i,g):
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
#print(n,m,l)
def bin_search(a,li):
    max_len=len(li)
    min_len=0
    while max_len>min_len:
        mid=(max_len+min_len)//2
        if li[mid]==a:
            return True
        elif abs(min_len-max_len)==1 and li[mid]!=a and li[mid+1]!=a and li[mid-1]!=a:
            break
        elif li[mid]<a:
            min_len=mid
        else:
            max_len=mid
s=[]
g=[]
for i in l:
    if i[0]==1:
        s.append(i[1])
    if i[1]==n:
        g.append(i[0])
g.sort
for i in s:
    if bin_search(i,g):
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')
Problem p03713 (python)

Fixed submission:
h,w=map(int,input().split())
s=float('inf')
for i in range(1,h):
    a1=min(i*w,w*((h-i)//2))
    b1=max(i*w,w*(h-i-(h-i)//2))
    d1=b1-a1
    a2=min(i*w,(h-i)*(w//2))
    b2=max(i*w,(h-i)*(w-w//2))
    d2=b2-a1
    s=min(s,d1,d2)
for j in range(1,w):
    a1=min(j*h,h*((w-j)//2))
    b1=max(j*h,h*(w-j-(w-j)//2))
    d1=b1-a1
    a2=min(j*h,(w-j)*(h//2))
    b2=max(j*h,(w-j)*(h-h//2))
    d2=b2-a2
    s=min(s,d1,d2)
print(s)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
s=[]
if h%3==0 or w%3==0:
    print(0)
else:
    for i in range(1,h):
        a=max(i*w,((h-i)*(w//2)),w*(h-i)//2)
        b=min(i*w,((h-i)*(w//2)),w*(h-i)//2)
        s.append((abs(a-b)))
    for j in range(1,w):
        a=max(h*j,(h//2)*(w-j),h*((w-j)//2))
        b=min(h*j,(h//2)*(w-j),h*((w-j)//2))
        s.append(abs(a-b))
print(min(s))
Problem p02615 (python)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
if n == 2:
  print(max(A))
else:
  A.sort(reverse=True)
  ans = A[0]
  for a in A[1:n//2]:
    ans += 2 * a
  if n % 2 == 1:
    ans += A[n//2]
  print(ans)

Buggy submission (verdict: Runtime Error):
4
2 2 1 3
Problem p02678 (python)

Fixed submission:
from collections import deque

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

graph = [[] for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  graph[a - 1].append(b - 1)
  graph[b - 1].append(a - 1)

ans = [-1] * (n - 1)

q = deque()
q.append(0)
used = {0}
while q:
  node = q.popleft()
  for next_node in graph[node]:
    if next_node in used:
      continue
    q.append(next_node)
    used.add(next_node)
    ans[next_node - 1] = node + 1

print('Yes')
print(*ans, sep='\n')

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

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

graph = [[] for _ in range(m)]
for _ in range(m):
  a, b = map(int, input().split())
  graph[a - 1].append(b - 1)
  graph[b - 1].append(a - 1)

ans = [-1] * (n - 1)

q = deque()
q.append(0)
used = {0}
while q:
    node = q.popleft()
    for next_node in graph[node]:
        if next_node in used:
          continue
        q.append(next_node)
        used.add(next_node)
        ans[next_node - 1] = node + 1

print('Yes')
print(*ans, sep='\n')
Problem p02683 (python)

Fixed submission:
from itertools import product

n, m, x = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(n)]

cost = -1
for cand in product((0, 1), repeat=n):
  tmp = 0
  scores = [0] * m
  for bought, ca in zip(cand, CA):
    if not bought:
      continue
    for i in range(1, m + 1):
      scores[i - 1] += ca[i]
    tmp +=  ca[0]
  if min(scores) >= x and (cost == -1 or tmp < cost):
    cost = tmp
print(cost)

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

n, m, x = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(n)]

cost = 10 ** 10
for cand in product((0, 1), repeat=n):
  tmp = 0
  scores = [0] * n
  for bought, ca in zip(cand, CA):
    if not bought:
      continue
    for i in range(1, m + 1):
      scores[i - 1] += ca[i]
    tmp +=  ca[0]
  if min(scores) >= x and tmp < cost:
    cost = tmp
print(cost)