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

Fixed submission:
n, m = map(int, input().split())
a=sorted(list(map(int, input().split())), reverse = True)
bc = sorted([list(map(int, input().split())) for _ in range(m)], key = lambda x:x[1], reverse = True)
i=0
j=0
cnt=0
ans=0
while True:
    if j<m and a[i]<bc[j][1]:
        ans+=min(n-cnt, bc[j][0])*bc[j][1]
        cnt+=min(n-cnt, bc[j][0])
        j+=1
    else:
        ans+=a[i]
        i+=1
        cnt+=1
    if cnt==n:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a=sorted(list(map(int, input().split())), reverse = True)
bc = sorted([list(map(int, input().split())) for _ in range(m)], key = lambda x:x[1], reverse = True)
i=0
j=0
cnt=0
ans=0
while True:
    if a[i]<bc[j][1]:
        ans+=min(n-cnt, bc[j][0])*bc[j][1]
        cnt+=min(n-cnt, bc[j][0])
        j+=1
    else:
        ans+=a[i]
        i+=1
        cnt+=1
    if cnt==n:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a=sorted(list(map(int, input().split())))
bc = sorted([list(map(int, input().split())) for _ in range(m)], key = lambda x:x[1], reverse = True)
tmp=0
cnt=0
ans=0
for i in range(n):
    if cnt>=bc[tmp][0]:
        ans+=bc[tmp][1]*bc[tmp][0]
        cnt-=bc[tmp][0]
        tmp+=1
    if tmp==m:
        k=n
        break
    if a[i]>bc[tmp][1]:
        k=i
        ans+=bc[tmp][1]*(cnt)
        break
    cnt+=1
print(sum(a[k:])+ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a=sorted(list(map(int, input().split())))
bc = sorted([list(map(int, input().split())) for _ in range(m)], key = lambda x:x[1], reverse = True)
tmp=0
cnt=0
ans=0
print(a, bc)
for i in range(n):
    if cnt>=bc[tmp][0]:
        ans+=bc[tmp][1]*bc[tmp][0]
        cnt-=bc[tmp][0]
        tmp+=1
    if a[i]>bc[tmp][1]:
        k=i
        ans+=bc[tmp][1]*(cnt)
        break
    cnt+=1
print(sum(a[k:])+ans)
Problem p03041 (python)

Fixed submission:
n, k = map(int, input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print(''.join(s))

Buggy submission (verdict: Runtime Error):

class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
 
 
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
 
 
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
 
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
n, m = map(int, input().split())
U=UnionFind(n)
for i in range(m):
    x, y, z = map(int, input().split())
    U.unite(x-1, y-1)
cnt=0
for i in range(n):
    if U.find(i)==i:
        cnt+=1
print(cnt)
Problem p03055 (python)

Fixed submission:
from collections import deque
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

def bfs(v0):
    dist = [-1]*N
    que = deque([v0])
    dist[v0] = 0
    while que:
        v = que.pop()
        d = dist[v]
        for nv in edges[v]:
            if dist[nv] < 0:
                que.append(nv)
                dist[nv] = d+1
    m = max(dist)
    v = dist.index(m)
    return v, m
u, _ = bfs(0)
_, dia = bfs(u)
if N == 1:
    print('First')
elif (dia+1-2)%3 == 0:
    print('Second')
else:
    print('First')

Buggy submission (verdict: Runtime Error):
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

def bfs(v0):
    dist = [-1]*N
    que = deque([v0])
    dist[v0] = 0
    while que:
        v = que.pop()
        d = dist[v]
        for nv in edges[v]:
            if dist[nv] < 0:
                que.append(nv)
                dist[nv] = d+1
    m = max(dist)
    v = dist.index(d)
    return v, m
u, _ = bfs(0)
_, dia = bfs(u)
if (dia+1-2)%3 == 0:
    print('Second')
else:
    print('First')
Problem p03291 (python)

Fixed submission:
mod=10**9+7
s=input()
n=len(s)
Sum_A=[0]*(n+1)
Sum_B=[0]*(n+1)
Sum_C=[0]*(n+1)
Sum_q=[0]*(n+1)
for i in range(1, n+1):
    Sum_A[i]=Sum_A[i-1]
    Sum_C[i]=Sum_C[i-1]
    Sum_q[i]=Sum_q[i-1]
    if s[i-1]=='A':
        Sum_A[i]+=1
    elif s[i-1]=='C':
        Sum_C[i]+=1
    elif s[i-1]=='?':
        Sum_q[i]+=1
ans=0
def count(x, q):
    return int(x*pow(3, q, mod)+q*pow(3, (q-1), mod)) if q>0 else int(x*pow(3, q, mod))
for i in range(n):
    if s[i]=='B' or s[i]=='?':
        ans+=count(Sum_A[i], Sum_q[i])*count(Sum_C[n]-Sum_C[i+1], Sum_q[n]-Sum_q[i+1])
        ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
s=input()
n=len(s)
Sum_A=[0]*(n+1)
Sum_B=[0]*(n+1)
Sum_C=[0]*(n+1)
Sum_q=[0]*(n+1)
for i in range(1, n+1):
    Sum_A[i]=Sum_A[i-1]
    Sum_C[i]=Sum_C[i-1]
    Sum_q[i]=Sum_q[i-1]
    if s[i-1]=='A':
        Sum_A[i]+=1
    elif s[i-1]=='C':
        Sum_C[i]+=1
    elif s[i-1]=='?':
        Sum_q[i]+=1
ans=0
def count(x, q):
    return int(x*pow(3, q, mod)+q*pow(3, (q-1), mod))
for i in range(n):
    if s[i]=='B' or s[i]=='?':
        ans+=count(Sum_A[i], Sum_q[i])*count(Sum_C[n]-Sum_C[i+1], Sum_q[n]-Sum_q[i+1])
        ans%=mod
print(ans)
Problem p03332 (python)

Fixed submission:
mod = 998244353
N, A, B, K = map(int, input().split())
def make_fact(n):#0~nの階乗を求める
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i%mod
    return fact
fact = make_fact(N) #＠
def make_fact_inv(n):#0~nの階乗のmodに関する逆元を求める
    fact_inv = [1]*(n+1)
    fact_inv[n] = pow(fact[n], mod-2, mod)#フェルマーの小定理
    for i in range(n, 0, -1):
        fact_inv[i-1] = fact_inv[i]*i%mod
    return fact_inv
fact_inv = make_fact_inv(N)#＠
def comb(n, k):#nCk
    return fact[n]*fact_inv[k]*fact_inv[n-k]%mod
ans = 0
for k in range(N+1):
    r = K-k*A
    if r<0 or r%B != 0 or r//B>N:
        continue
    l = r//B
    ans+=comb(N, k)*comb(N, l)
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 998244353
N, A, B, K = map(int, input().split())
def make_fact(n):#0~nの階乗を求める
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i%mod
    return fact
fact = make_fact(N) #＠
def make_fact_inv(n):#0~nの階乗のmodに関する逆元を求める
    fact_inv = [1]*(n+1)
    fact_inv[n] = pow(fact[n], mod-2, mod)#フェルマーの小定理
    for i in range(n, 0, -1):
        fact_inv[i-1] = fact_inv[i]*i%mod
    return fact_inv
fact_inv = make_fact_inv(N)#＠
def comb(n, k):#nCk
    return fact[n]*fact_inv[k]*fact_inv[n-k]%mod
ans = 0
for k in range(N+1):
    r = K-k*A
    if r%B != 0 or r//B>N:
        continue
    l = r//B
    ans+=comb(N, k)*comb(N, l)
    ans%=mod
print(ans)
Problem p03634 (python)

Fixed submission:
N = int(input())
List = [[] for _ in range(N)]
ans = [-1]*N
for i in range(N-1):
    a, b, c = map(int, input().split())
    List[a-1].append((b-1, c))
    List[b-1].append((a-1, c))
Q, K = map(int, input().split())
queue = [K-1]
ans[K-1] = 0
while queue:
    edge = queue.pop()
    for node in List[edge]:
        index, cost = node
        if ans[index]>0:
            continue
        ans[index] = ans[edge]+cost
        queue.append(index)
for i in range(Q):
    x, y = map(int, input().split())
    print(ans[x-1]+ans[y-1])

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import shortest_path
n = int(input())
mat=[[0]*n for i in range(n)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    mat[a-1][b-1]=c
    mat[b-1][a-1]=c
q, k  = map(int, input().split())
distance = shortest_path(mat, directed = False, indices = [k-1], method = 'D')
for i in range(q):
    x, y = map(int, input().split())
    print(int(distance[0][x-1]+distance[0][y-1]))
Problem p03724 (python)

Fixed submission:
from collections import Counter
N, M = map(int, input().split())
c = []
for i in range(M):
    a, b = map(int, input().split())
    c.append(a)
    c.append(b)
c = Counter(c)
if all(cnt%2==0 for cnt in c.values()):
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
from collections import Counter
N, M = map(int, input().split())
c = []
for i in range(N):
    a, b = map(int, input().split())
    c.append(a)
    c.append(b)
c = Counter(c)
if all(cnt%2==0 for cnt in c.values()):
    print('YES')
else:
    print('NO')
Problem p02862 (python)

Fixed submission:
mod = int(1e9 + 7)
def powmod(a, b):
    ans = 1
    while(b):
        if(b&1): ans = ans*a%mod
        a = a*a%mod
        b >>= 1
    return ans
x, y = map(int,input().split())
if(2*x < y or 2*y < x or (2*x-y)%3 or (2*y-x)%3): print(0)
else:
    x, y = (2*x-y)//3, (2*y-x)//3
    #print(x,y)
    fac = [0 for i in range(x+y+1)]
    inv = [0 for i in range(x+y+1)]
    fac[0] = 1
    for i in range(1,x+y+1):
        fac[i] = fac[i-1]*i%mod
    inv[x+y] = powmod(fac[x+y],mod-2)
    for i in range(x+y-1,-1,-1):
        inv[i] = inv[i+1]*(i+1)%mod
    ans = fac[x+y]*inv[x]*inv[y]%mod
    print(ans)

Buggy submission (verdict: Runtime Error):
mod = int(1e9 + 7)
def powmod(a, b):
    ans = 1
    while(b):
        if(b&1): ans = ans*a%mod
        a = a*a%mod
        b >>= 1
    return ans
x, y = map(int,input().split())
if((2*x-y)%3 or (2*y-x)%3): print(0)
else:
    x, y = (2*x-y)//3, (2*y-x)//3
    #print(x,y)
    fac = [0 for i in range(x+y+1)]
    inv = [0 for i in range(x+y+1)]
    fac[0] = 1
    for i in range(1,x+y+1):
        fac[i] = fac[i-1]*i%mod
    inv[x+y] = powmod(fac[x+y],mod-2)
    for i in range(x+y-1,-1,-1):
        inv[i] = inv[i+1]*(i+1)%mod
    ans = fac[x+y]*inv[x]*inv[y]%mod
    print(ans)
Problem p02793 (python)

Fixed submission:
def gcd(a, b):
  while(b > 0):
    a %= b
    a, b = b, a
  return a
def lcm(a, b):
  return a * b // gcd(a,b)
n = int(input())
md = int(1e9 + 7)
a = [int(e) for e in input().split()]
x = 1
for j in range(n):
  x = lcm(x, a[j])
ans = 0
for i in range(n):
  ans += x // a[i]
ans %= md
print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
  while(b > 0):
    a %= b
    swap(a, b)
  return a
def lcm(a, b):
  return a * b // gcd(a,b)
n = int(input())
md = int(1e9 + 7)
a = [int(e) for e in input().split()]
x = 1
for j in range(n):
  x = lcm(x, a[j])
ans = 0
for i in range(n):
  ans += lcm // a[i]
ans %= md
print(ans)
Problem p02790 (python)

Fixed submission:
u = input()

a = u[0];
b = u[2];
at = int(a)
bt = int(b)

x = b*at
y = a*bt

if x <= y:
  print(x)

else:
 print(y)

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

a = u[0];
b = u[2];
at = int(a)
bt = int(b)

x = at*b
y = bt*a

if(x < y)
{
  print(x)
}
else
{
 print(y)
}
Problem p02763 (python)

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

seg = [0]*(2*N-1)

def update(k, x):
    k += N-1
    seg[k] = 2**x
    while k:
        k = (k-1)//2
        seg[k] = seg[2*k+1] | seg[2*k+2]
        
def query(p, q):
    p += N-1
    q += N-2
    res = 0
    while q-p > 1:
        if p&1 == 0:
            res = res | seg[p]
        if q&1 == 1:
            res = res | seg[q]
            q -= 1
        p //= 2
        q = (q-1)//2
    if p == q:
        res |= seg[q]
    else:
        res |= seg[p] | seg[q]
    return bin(res).count("1")

def f(s):
    return ord(s) - ord("a") + 1

for i in range(N):
    update(i, f(S[i]))
    
Q = int(input())
for _ in range(Q):
    a,b,c = map(str, input().split())
    if a == "1":
        update(int(b)-1, f(c))
    else:
        print(query(int(b)-1, int(c)))

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
S = input()

dic = {}
for i in range(N):
    if S[i] in dic:
        dic[S[i]].append(i+1)
    else:
        dic[S[i]] = [i+1]

Q = int(input())
for _ in range(Q):
    a,b,c = map(str, input().split())
    if a == "1":
        b = int(b)
        dic[S[b-1]].remove(b)
        if c in dic:
            idx = bisect.bisect_left(dic[c], b)
            dic[c].insert(idx, b)
        else:
            dic[c] = [b]
    else:
        l = int(b)
        r = int(c)
        cnt = 0
        for key in dic:
            if len(dic[key]) == 0:
                continue
            elif len(dic[key]) == 1:
                if l <= dic[key][0] <= r:
                    cnt += 1
                continue
            elif bisect.bisect_left(dic[key], r)-bisect.bisect_left(dic[key], l) > 0:
                cnt += 1
        print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
import bisect
N = int(input())
S = input()

dic = {}
for i in range(N):
    if S[i] in dic:
        dic[S[i]].append(i+1)
    else:
        dic[S[i]] = [i+1]

Q = int(input())
for _ in range(Q):
    a,b,c = map(str, input().split())
    if a == "1":
        b = int(b)
        dic[S[b-1]].remove(b)
        if c in dic:
            idx = bisect.bisect_left(dic[c], b)
            dic[c].insert(idx, b)
        else:
            dic[c] = [b]
    else:
        l = int(b)
        r = int(c)
        cnt = 0
        for key in dic:
            if len(dic[key]) == 0:
                continue
            elif len(dic[key]) == 1:
                if l <= dic[key][0] <= r:
                    cnt += 1
                continue
            elif bisect.bisect_left(dic[key], r)-bisect.bisect_left(dic[key], l) > 0:
                cnt += 1
        print(cnt)
Problem p02880 (python)

Fixed submission:
N = int(input())

for i in range(2, N+1):
    if N%i == 0:
        a = i
        b = N//i
        if a <= 9 and b <= 9:
            break

if N <= 2:
    print("Yes")
elif a <= 9 and b <= 9:
    print("Yes")
else:
    print("No")

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

for i in range(2, N):
    if N%i == 0:
        a = i
        b = N//i
        if a <= 9 and b <= 9:
            break

if N <= 2:
    print("Yes")
elif a <= 9 and b <= 9:
    print("Yes")
else:
    print("No")

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

for i in range(2, N):
    if N%i == 0:
        a = i
        b = N//i
        if a <= 9 and b <= 9:
            break

if N == 1:
    print("Yes")
elif a <= 9 and b <= 9:
    print("Yes")
else:
    print("No")
Problem p02891 (python)

Fixed submission:
S = input()
K = int(input())

L = []
temp = S[0]
c = 1
for i in range(1, len(S)):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
    if i == len(S)-1:
        L.append(c)
        
ans = 0

if S[0] != S[-1]:
    for i in range(len(L)):
        ans += (L[i]//2)
    ans *= K
else:
    if len(L) == 1:
        ans += K*L[0]//2
    elif len(L) == 0:
        ans += K//2
    else:
        for i in range(1, len(L)-1):
            ans += (L[i]//2)
        ans *= K
        ans += L[0]//2
        ans += L[-1]//2
        ans += (L[0]+L[-1])//2*(K-1)
        
print(ans)

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

L = []
temp = S[0]
c = 1
for i in range(1, len(S)):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
    if i == len(S)-1:
        L.append(c)
        
ans = 0
if S[0] != S[-1]:
    for i in range(len(L)):
        ans += (L[i]//2)
    ans *= K
else:
    if len(L) == 1:
        ans = K*L[0]//2
    else:
        for i in range(1, len(L)-1):
            ans += (L[i]//2)
        ans *= K
        ans += (L[0]+L[-1])//2*K
        
print(ans)
Problem p02892 (python)

Fixed submission:
N = int(input())
S = []
for i in range(N):
    S.append(input())
    

#二部グラフ判定
L = [0 for i in range(N)]
L[0] = 1
q = [0]
res = 0

while len(q) > 0:
    idx = q.pop(-1)
    c = L[idx]*(-1)
    for i in range(N):
        if S[idx][i] == "1":
            if L[i] == 0:
                L[i] = c
                q.append(i)
            elif L[i] == c*(-1):
                res = 1
                q = []
                break
            

if res == 1:
    print(-1)
else:
    # Warshall-Floyd法で直径を求める
    d = [[10**4 for j in range(N)] for i in range(N)]
    # initialize
    for i in range(N):
        for j in range(N):
            if S[i][j] == "1":
                d[i][j] = 1
    
    # DP
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if i != j:
                    d[i][j] = min(d[i][j], d[i][k]+d[k][j])

                
    ans = 0
    for i in range(N):
        for j in range(N):
            if d[i][j] < 10**4:
                ans = max(ans, d[i][j])
                
    print(ans+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = []
for i in range(N):
    S.append(input())
    

#二部グラフ判定
L = [0 for i in range(N)]
L[0] = 1
q = [0]
res = 0

while len(q) > 0:
    idx = q.pop(-1)
    c = L[idx]*(-1)
    for i in range(N):
        if S[idx][i] == "1":
            if L[i] == 0:
                L[i] = c
                q.append(i)
            elif L[i] == c*(-1):
                res = 1
                q.clear()
                break
            

if res == 1:
    print(-1)
else:
    # Warshall-Floyd法で直径を求める
    d = [[10**4 for j in range(N)] for i in range(N)]
    # initialize
    for i in range(N):
        for j in range(N):
            if S[i][j] == "1":
                d[i][j] = 1
    
    # DP
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if i != j:
                    d[i][j] = min(d[i][j], d[i][k]+d[k][j])

                
    ans = 0
    for i in range(N):
        for j in range(N):
            if d[i][j] < 10**4:
                ans = max(ans, d[i][j])
                
    print(ans+1)
Problem p02912 (python)

Fixed submission:
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

import heapq

h = []
for i in range(N):
    heapq.heappush(h, A[i]*(-1))
    
for i in range(M):
    temp = heapq.heappop(h)
    temp *= (-1)
    temp //= 2
    temp *= (-1)
    heapq.heappush(h, temp)
    
print(sum(h)*(-1))

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

A.sort(reverse=True)
List = [[] for i in range(100)]
for i in range(N):
    temp = bin(A[i])
    List[len(temp)-3].append(A[i])

List.reverse()
List = [i for i in List if i != []]
for i in range(len(List)):
    List[i].sort(reverse=True)
c = 0
cnt = 0
while cnt < M:
    for i in range(cnt+1):
        for j in range(len(List[i])):
            List[i][j] = List[i][j]//2
            c += 1
            if c == M:
                cnt = M+1
                c = M+1
                break
        if c > M:
            break
    cnt += 1
            
ans = 0
for i in range(len(List)):
    ans += sum(List[i])
            
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

A.sort(reverse=True)
List = [[] for i in range(100)]
for i in range(M):
    temp = bin(A[i])
    List[len(temp)-3].append(A[i])

List.reverse()
List = [i for i in List if i != []]
for i in range(len(List)):
    List[i].sort(reverse=True)
c = 0
cnt = 0
while cnt < M:
    for i in range(cnt+1):
        for j in range(len(List[i])):
            List[i][j] = List[i][j]//2
            c += 1
            if c == M:
                c = M+1
                break
        if c > M:
            break
    cnt += 1
            
ans = 0
for i in range(len(List)):
    ans += sum(List[i])
            
print(ans)
Problem p03033 (python)

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x)
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)
Problem p03652 (python)

Fixed submission:
N,M = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(N)]

L = [0]*(M+1) #L[i]:0ならスポーツiを含める、1なら含めない
I = [0]*N #A[i][I[i]]:人iが参加するスポーツ
ans = N
flag = True
while flag:
    cnt = [0]*(M+1)
    for i in range(N):
        while I[i] < N and L[A[i][I[i]]] == 1:
            I[i] += 1
        if I[i] == N:
            flag = False
            break
        cnt[A[i][I[i]]] += 1
    if flag:
        num = max(cnt)
        ans = min(ans, num)
        for i in range(1, M+1):
            if cnt[i] == num:
                L[i] = 1
    if sum(L) == M:
        flag = False

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(N)]

L = [0]*(M+1)
I = [0]*N
ans = N
flag = True
while flag:
    cnt = [0]*(M+1)
    for i in range(N):
        while I[i] < N and L[A[i][I[i]]] == 1:
            I[i] += 1
        if I[i] == N:
            flag = False
            break
        cnt[A[i][I[i]]] += 1
        I[i] += 1
    num = max(cnt)
    ans = min(ans, num)
    for i in range(1, M+1):
        if cnt[i] == num:
            L[i] = 1
    if sum(L) == M:
        flag = False

print(ans)
Problem p02695 (python)

Fixed submission:
import itertools

N, M, Q = map(int, input().split())

Q_list = []
for _ in range(Q):
    a, b, c, d = list(map(int, input().split()))
    Q_list.append((a, b, c, d))

A_list = []
for a in itertools.combinations_with_replacement(range(1, M+1), N):
    A_list.append(a)

answer = 0
score_list = []
for A in A_list:
    score = 0
    for i in range(Q):
        a, b, c, d = Q_list[i]
        a -=1
        b -=1
        if A[b] - A[a] == c:
            score += d
    answer = max(answer, score)

print(answer)

Buggy submission (verdict: Runtime Error):
import itertools

N, M, Q = map(int, input().split())

Q_list = []
for _ in range(Q):
    q = list(map(int, input().split()))
    Q_list.append(q)

A_list = []
for a in itertools.combinations_with_replacement(range(1, M+1), N):
    if a[0]<= a[1] and a[1] <= a[2]:
        A_list.append(a)

score_list = []
for A in A_list:
    score = 0
    for i in range(Q):
        a, b, c, d = Q_list[i][0], Q_list[i][1], Q_list[i][2], Q_list[i][3]
        a -=1
        b -=1
        if A[b] - A[a] == c:
            score += d
    score_list.append(score)

print(max(score_list))
Problem p03286 (python)

Fixed submission:
a=int(input())
b=[]
if a==0:
	print(0)
while a:
	b.append(a&1)
	a-=a&1
	a=int(a/-2)

print(''.join(map(str,b[::-1])))

Buggy submission (verdict: Runtime Error):
a=int(input())
b=''
while a:
  s=str(a&1)+s
  n=-(n//2)
print(b if b else 0)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=[]
if a==0:
  print(0)
else:
  while a:
	b.append(a&1)
	a=int((a-(a&1))/(-2))
  print(''.join(map(str,b)))

Buggy submission (verdict: Runtime Error):
a=int(input())
b=[]
if(a==0)print(0)
else:
  while a:
	b.append(a&1)
	a=int((a-(a&1))/(-2))
  print(''.join(map(str,b)))

Buggy submission (verdict: Runtime Error):
a=int(input())
b=[]
if(a==0)print(0)
while a:
	b.append(a&1)
	a=int((a-(a&1))/(-2))
print(''.join(map(str,b)))