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

Fixed submission:

N = int(input())
job = []
for i in range(N):
    a, b = map(int, input().split())
    job.append([a, b])
#print(job)
job.sort(key=lambda x: x[1])
#print(job)
for i in range(1, N):
    job[i][0] += job[i - 1][0]
for i in range(N):
    if job[i][0] > job[i][1]:
        print("No")
        break
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
job = [[0] * N for _ in range(N)]
for i in range(N):
    job[i] = list(map(int, input().split()))
#print(job)
job.sort(key=lambda x: x[1])
#print(job)
#for i in range(1, N):
#    job[i][1] += job[i - 1][1]
rest = 0
for i in range(N):
    if job[i][0] > job[i][1] + rest:
        print("No")
        break
    rest += rest + (job[i][1] - job[i][0])
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
job = [[0] * N for _ in range(N)]
for i in range(N):
    job[i] = list(map(int, input().split()))

job.sort(key = lambda x: x[1])
#print(job)
for i in range(1, N):
    job[i][0] += job[i - 1][0]
for i in range(N):
    if job[i][0] > job[i][1]:
        print("No")
        break
else:
    print("Yes")
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
cnt = 0
for i in range(1, N):
    if S[-i] == "C" and S[-i-1] == "A":
            cnt += 1
    dp[N-i] = cnt
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if r[q] < N:
        if S[r[q]] == "A" and S[r[q] + 1] == "C":
            ans -= 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
cnt = 0
for i in range(1, N):
    if S[-i] == "C" and S[-i-1] == "A":
            cnt += 1
    dp[N-i] = cnt
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
cnt = 0
for i in range(1, N):
    if S[-i] == "C" and S[-i-1] == "A":
            cnt += 1
    dp[N-i] = cnt
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
cnt = 0
for i in range(1, N):
    if S[-i] == "C" and S[-i-1] == "A":
            cnt += 1
    dp[N-i] = cnt
print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
for i in range(1, N + 1):
    dp[i] = S[i:].count("AC")
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
#CofAC= [-1] * (N + 1) #ACのC部分が何文字目か記録
#print([i for i, x in enumerate(l_dup) if x == 'a'])
# [0, 4]
#print([i for i, x in enumerate(S) if x == 'AC'])
dp = [0] * (N + 2) #i文字目から何個ACがあるか
for i in range(1, N + 1):
    dp[i] = S[i:].count("AC")
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)
Problem p03161 (python)

Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
dp = [0] * (N + 1)
dp[1] = 0
dp[2] = abs(H[2] - H[1])

for i in range(3, N+1):
    dp[i] = dp[i - 1] + abs(H[i] - H[i - 1])
    for j in range(1, K + 1):
        if i - j <= 0:
            break
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print(dp[N])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
dp = [0] * (N + 1)
dp[1] = 0
dp[2] = abs(H[2] - H[1])

for i in range(3, N+1):
    dp[i] = 1000000000
    for j in range(max(1, i - j), K + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print(dp[N])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2000)

N, M = map(int, input().split())
x = [0] * M
y = [0] * M
G = [[] for _ in range(N + 1)]
for i in range(M):
    X, Y = map(int, input().split())
    x[i] = X
    y[i] = Y
    G[X] += [Y]

dp = [-1] * (N + 1)


def f(n):
    if dp[n] != -1:
        return dp[n]
    res = 0
    for m in G[n]:
        res = max(res, f(m) + 1)
    dp[n] = res
    return res


for i in range(1, N + 1):
    f(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
x = [0] * M
y = [0] * M
G = [[] for _ in range(N + 1)]
for i in range(M):
    X, Y = map(int, input().split())
    x[i] = X
    y[i] = Y
    G[X] += [Y]

dp = [-1] * (N + 1)


def f(n):
    if dp[n] != -1:
        return dp[n]
    res = 0
    for m in G[n]:
        res = max(res, f(m) + 1)
    dp[n] = res
    return res


for i in range(1, N + 1):
    f(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):

N, M = map(int, input().split())
x = [0] * (M)
y = [0] * (M)
G = [[] for _ in range(N + 1)]
for i in range(M):
    X, Y = map(int, input().split())
    x[i] = X
    y[i] = Y
    G[X] += [Y]

dp = [-1] * (N + 1)



def f(n):
    if dp[n] != -1:
        return dp[n]
    res = 0
    for m in G[n]:
        res = max(res, f(m) + 1)
    dp[n] = res
    return res


for i in range(1, N + 1):
    f(i)
print(max(dp))
Problem p02684 (python)

Fixed submission:
'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date: 7th May 2020
'''

n,k=map(int,input().split())
a=list(map(int,input().split()))
a=[0]+a
vis=[-1]*(n+5)


turn=k
now=1
c=0
while vis[now]==-1:

    if turn<=0:
        print(now)
        exit()
    vis[now]=c
    c+=1
    now=a[now]
    turn=turn-1

diff =c-vis[now]

lo=1
hi=10**25
cost=vis[now]
while lo<=hi:

    mid=(lo+hi)//2
    t=mid*diff
    if t+cost<=k:
       lo=mid+1
    else:
        hi=mid-1

t=hi*diff+cost


rem=k-t

while rem>0:
    now=a[now]
    rem-=1

print(now)

Buggy submission (verdict: Runtime Error):
'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date: 7th May 2020
'''


n,k=[int(x) for x in input().split()]
vis=[-1 for i in range(n+4)]
node=0
a=[int(x) for x in input().split()]
a=[0]+a
#print(a)

def dfs(u,l,turn):
    if turn<=0:
        print(u)
        return -1
    if vis[u]!=-1:
        global node
        node=u
        #print("node "+str(node))
        return l-vis[node]
    vis[u]=l
    return dfs(a[u],l+1,turn-1)

diff=dfs(1,0,k)
if diff==-1:
    exit()
else:

    lo=1
    hi=10**25
    cost=vis[node]

    while lo<=hi:
        mid=(lo+hi)//2
        temp=mid*diff
        #print(lo,hi)
        if cost+temp<=k:
            lo=mid+1
        else:
            hi=mid-1


    t=hi*diff+cost
    #print("Node "+str(node))
    def dfs2(u,turn):
        if turn<=0:
            print(u)
            return
        
        dfs2(a[u],turn-1)

    dfs2(node,k-t)

Buggy submission (verdict: Runtime Error):
'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date: 7th May 2020
'''


n,k=[int(x) for x in input().split()]
vis=[-1 for i in range(n+4)]
node=0
a=[int(x) for x in input().split()]
a=[0]+a
#print(a)

def dfs(u,l,turn):
    if turn<=0:
        print(u)
        return -1
    if vis[u]!=-1:
        global node
        node=u
        #print("node "+str(node))
        return l-vis[node]
    vis[u]=l
    return dfs(a[u],l+1,turn-1)

diff=dfs(1,0,k)
if diff==-1:
    exit()
lo=1
hi=10**25
cost=vis[node]

while lo<=hi:
    mid=(lo+hi)//2
    temp=mid*diff
    #print(lo,hi)
    if cost+temp<=k:
        lo=mid+1
    else:
        hi=mid-1


t=hi*diff+cost

#print(k-t)

def dfs2(u,turn):
    if turn<=0:
        print(u)
        return
    
    dfs2(a[u],turn-1)

dfs2(node,k-t)

Buggy submission (verdict: Runtime Error):
'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date: 7th May 2020
'''


n,k=[int(x) for x in input().split()]
vis=[-1 for i in range(n+4)]
node=0
a=[int(x) for x in input().split()]
a=[0]+a
#print(a)

def dfs(u,l,turn):
    if turn<=0:
        print(u)
        return -1
    if vis[u]!=-1:
        global node
        node=u
        #print("node "+str(node))
        return l-vis[node]
    vis[u]=l
    return dfs(a[u],l+1,turn-1)

diff=dfs(1,0,k)
lo=1
hi=10**24
cost=vis[node]

while lo<=hi:
    mid=(lo+hi)//2
    temp=mid*diff
    #print(lo,hi)
    if cost+temp<=k:
        lo=mid+1
    else:
        hi=mid-1


t=hi*diff+cost

#print(k-t)

def dfs2(u,turn):
    if turn<=0:
        print(u)
        return
    
    dfs2(a[u],turn-1)

dfs2(node,k-t)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
N = int(input())
s = list(map(int,input().split()))
 
t = 1
for i in range(N):
    t = t * s[i]
 
if( t > 10**18):
    print(-1)
else:
    print(t)
Problem p02675 (python)

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

m = N % 10

if (m == 3):
    print("bon")
elif (m == 0 or m == 1 or m == 6 or m == 8):
    print("pon")
else:
    print("hon")

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

if (len(S) <= K):
    print(S)
else:
    print(S[:K] + "...")

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

if (len(S) <= K):
    print(S)
else:
    print(S[0:K] + "...")

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

m = N % 10

if (m == 3):
    print(bon)
elif (m == 0 or m == 1 or m == 6 or m == 8):
    print(pon)
else:
    print(hon)

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

m = N % 10

if (n == 3):
    print(bon)
elif (n == 0 or n == 1 or n == 6 or n == 8):
    print(pon)
else:
    print(hon)
Problem p02641 (python)

Fixed submission:
x, n, *P = map(int, open(0).read().split())
A = list(range(102))
P = set(P)
B = []
m = 10**4
for a in A:
    if a not in P:
        if abs(x-a) < m:
            m = abs(x-a)
            B.append((m, a))
B.sort()
print(min([k for v, k in B if v == B[0][0]]))

Buggy submission (verdict: Runtime Error):
x, n, *P = map(int, open(0).read().split())
P = set(P)
for i in range(51):
    Q = {x-i, x+i} - P
	if Q:
		print(min(Q))
		break
Problem p02660 (python)

Fixed submission:
from math import sqrt
def factorint(n):
    d = {}
    for i in range(2, int(sqrt(n))+1):
        c = 0
        q, r = divmod(n, i)
        while not r:
            c += 1
            n = q
            q, r = divmod(n, i)
        if c:
            d[i] = c
    if n != 1:
        d[n] = 1
    return d

n = int(input())
if n == 1:
    print(0)
else:
    d = factorint(n)
    s = 0
    for v in d.values():
        s += int((sqrt(8*v+1)-1)/2)
    print(s)

Buggy submission (verdict: Runtime Error):
from numba import njit
@njit
def factorint(n):
    d = {}
    for i in range(2, int(sqrt(n))+1):
        c = 0
        q, r = divmod(n, i)
        while not r:
            c += 1
            n = q
            q, r = divmod(n, i)
        if c:
            d[i] = c
    if n != 1:
        d[n] = 1
    return d

n = int(input())
if n == 1:
    print(0)
else:
    d = factorint(n)
    s = 0
    for v in d.values():
        s += int((sqrt(8*v+1)-1)/2)
    print(s)
Problem p02678 (python)

Fixed submission:
from collections import deque
n, m, *AB = map(int, open(0).read().split())
graph = [[] for _ in range(n)]
for a, b in zip(AB[::2], AB[1::2]):
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

d = [0] * n
queue = deque([0])
while queue:
    current_node = queue.popleft()
    for next_node in graph[current_node]:
        if d[next_node] == 0:
            d[next_node] = current_node+1
            queue.append(next_node)
print('Yes')
print(*d[1:], sep='\n')

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, shortest_path
n, m, *AB = map(int, open(0).read().split())
graph = [[10**9]*n for _ in range(n)]
for a, b in zip(AB[::2], AB[1::2]):
    graph[a-1][b-1] = 1
    graph[b-1][a-1] = 1
G = csgraph_from_dense(graph)
d, p = shortest_path(G, indices=0, method='D', return_predecessors=1)
if np.any(d > 10**9-1):
    print('No')
else:
    print('Yes')
    print(*map(lambda x: int(x)+1, p[1:]), sep='\n')
Problem p02690 (python)

Fixed submission:
d = {}
for i in range(1, 1000):
    if i ** 5 - (i-1) ** 5 > 10 ** 9:
        break
    for j in range(i-1, -i-1, -1):
        if i ** 5 - j ** 5 > 10 ** 9:
            break
        d[i ** 5 - j ** 5] = (i, j)
print(*d[int(input())])

Buggy submission (verdict: Runtime Error):
d = {}
for i in range(1, 100):
    for j in range(i-1, -i-1, -1):
        if i ** 5 - j ** 5 > 10 ** 9:
            print(*d[int(input())])
            exit()
        d[i ** 5 - j ** 5] = (i, j)
    else:
        continue
Problem p02691 (python)

Fixed submission:
from collections import Counter
inputs = open(0).readlines()
n = int(inputs[0])
*A, = (map(int, inputs[1].split()))
B = Counter([a+i for i, a in enumerate(A, 1)])
C = Counter([i-a for i, a in enumerate(A, 1)])
ans = 0
for k, v in B.items():
    if k in C:
        ans += C[k]*v
print(ans)

Buggy submission (verdict: Runtime Error):
n, *A = map(int, open(0).read().split())
ans = 0
for i, a in enumerate(A, 1):
    x, y = i+a, i-a
    d[x] = d.get(x, 0)+1
    ans += d.get(y, 0)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(inputs[0])
*A, = (map(int, inputs[1].split()))
B = Counter([a+i for i, a in enumerate(A, 1)])
C = Counter([i-a for i, a in enumerate(A, 1)])
ans = 0
for k, v in B.items():
    if k in C:
        ans += C[k]*v
print(ans)
Problem p02838 (python)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 10 ** 9 + 7

bit = len(format(max(A), 'b'))
ans = 0
for i in range(bit):
    nb_1 = sum(((a >> i) & 1 for a in A))
    ans += (nb_1 * (n - nb_1)) << i
    ans %= MOD
    
print(ans)

Buggy submission (verdict: Runtime Error):
n, *A = map(int, open(0).read().split())
A = [a%mod for a in A]
mod = 10**9 + 7
ans = 0
d = 1
while any(A):
  c = 0
  for i in range(n):
    q, r = divmod(A[i], 2)
    A[i] = q
    c += r
  ans += c*(n-c) * d
  ans %= mod
  d *= 2
print(ans % mod)
Problem p02845 (python)

Fixed submission:
import sys
inputs = sys.stdin.readlines()
from functools import reduce
from operator import mul

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
B = {0:0, 1:0, 2:0}
C = []
mod = 1000000007
for i in range(n):
    matches = [int(nb == A[i]) for nb in B.values()]
    if sum(matches) == 1:
        B[matches.index(1)] += 1
    elif sum(matches) == 2:
        B[matches.index(1)] += 1
        C.append(2)
    elif sum(matches) == 3:
        B[matches.index(1)] += 1
        C.append(3)
    else:
        print(0)
        break
else:
    print(reduce(mul, C) % mod)

Buggy submission (verdict: Runtime Error):
import sys
inputs = sys.stdin.readlines()
from functools import reduce
from operator import mul

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
B = []
C = []
mod = 1000000007
for i in range(n):
    nb_rgb = [
        len([x for x in B if x == 0]),
        len([x for x in B if x == 1]),
        len([x for x in B if x == 2])
    ]
    tmp = [int(nb == A[i]) for nb in nb_rgb]
    if sum(tmp) == 1:
        B.append(tmp.index(1))
    elif sum(tmp) == 2:
        B.append(tmp.index(1))
        C.append(2)
    elif sum(tmp) == 3:
        B.append(tmp.index(1))
        C.append(3)

print(reduce(mul, C) % mod)
Problem p02888 (python)

Fixed submission:
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
L = list(map(int, inputs[1].split()))
A = sorted(L)
 
ans = 0
for i in range(n-1, 0, -1):
    l, r = 0, i-1
    while l < r:
        if A[i] < A[l] + A[r]:
            ans += r-l
            r -= 1
        else:
            l += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
L = list(map(int, inputs[1].split())
A = sorted(L)

ans = 0
for i in range(n-1, 0, -1):
    l, r = 0, i-1
    while l < r:
        if A[i] < A[l] + A[r]:
            ans += r-l
            r -= 1
        else:
            l += 1

print(ans)
Problem p02900 (python)

Fixed submission:
def is_prime(n):
    assert n >= 1,  'Argument Error! n is "1 <= n".'
    for i in range(2, n + 1):
        if i ** 2 > n:
            break
        if n % i == 0:
            return False
    return n != 1

def 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()
    return divisors

a, b = sorted(list(map(int, input().split())))
divisors_ = set(divisors(a)) & set(divisors(b))

prime_divisors = [x for x in divisors_ if is_prime(x)]
print(len(prime_divisors) + 1)

Buggy submission (verdict: Runtime Error):
def is_prime(n):
    assert n >= 1,  'Argument Error! n is "1 <= n".'
    for i in range(2, n + 1):
        if i ** 2 > n:
            break
        if n % i == 0:
            return False
    return n != 1

def 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()
    return divisors

a, b = sorted(list(map(int, inputs[0].split())))
divisors_ = set(divisors(a)) & set(divisors(b))

prime_divisors = [x for x in divisors_ if is_prime(x)]
print(len(prime_divisors) + 1)

Buggy submission (verdict: Runtime Error):
def 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()
    return divisors

a, b = sorted(list(map(int, input().split())))
divisors_ = set(divisors(a)) & set(divisors(b))

prime_divisors = [x for x in divisors_ if is_prime(x)]
print(len(prime_divisors) + 1)
Problem p02927 (python)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

M, D = map(int, inputs[0].split())

good_dates = []
for date in range(D):
    d10 = (date+1) // 10
    d1 = (date+1) % 10
    if d1 >= 2 and d10 >= 2:
        if d1*d10 <= M:
            good_dates.append((d1*d10, date))
print(len(good_dates))

Buggy submission (verdict: Runtime Error):
M, D = map(int, inputs[0].split())
good_dates = []
for date in range(D):
    d10 = (date+1) // 10
    d1 = (date+1) % 10
    if d1 >= 2 and d10 >= 2:
        if d1*d10 <= M:
            good_dates.append((d1*d10, date))
print(len(good_dates))

Buggy submission (verdict: Runtime Error):
import sys
inputs = sys.stdin.readlines()

M, D = map(int, inputs[0].split())

good_dates = []
for date in range(D):
	d10 = (date+1) // 10
    d1 = (date+1) % 10
    if d1 >= 2 and d10 >= 2:
        if d1*d10 <= M:
            good_dates.append((d1*d10, date))
print(len(good_dates))

d10 = (date+1) // 10
    d1 = (date+1) % 10
Problem p02953 (python)

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

H[0] -= 1
for i in range(1, n):
    if H[i-1] < H[i]:
        H[i] -= 1

if all(H[i-1] <= H[i] for i in range(1, n)):
    print('Yes')
else:
    print('No')

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

H[0] -= 1
for i in range(1, n):
    if H[i] < H[i-1]:
        H[i] -= 1
print('Yes' if reduce(lambda x, y: x <= y, H) else 'No')
Problem p02975 (python)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

from collections import Counter

def all_zeros(a_list):
    return sum(a_list) == 0

def check(N, a_list):
    if all_zeros(a_list):
        print('Yes')
        return
    elif N % 3 == 0:
        x = N // 3
        if not all([v % x == 0 for v in Counter(a_list).values()]):
            print('No')
            return
        while not all_zeros(a_list):
            counter = Counter([a & 1 for a in a_list])
            if counter[0] == x or counter[0] == N:
                a_list = [a >> 1 for a in a_list]
            else:
                print('No')
                return
        print('Yes')
    else:
        print('No')

check(N, a_list)

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

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

def check(N, a_list):
    mc = Counter(a_list).most_common()
    n = len(mc)
    if n == 1:
        if mc[0][0] == 0:
            print('Yes')
            return
    elif n == 2:
        if mc[0][1] == 2*N // 3 and mc[1][0] == 0:
            print('Yes')
            return
    elif n == 3:
        if mc[0][1] == mc[1][1] == mc[2][1] and mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0:
            print('Yes')
            return
    print('No')

check(N, a_list)

Buggy submission (verdict: Runtime Error):
import sys
inputs = sys.stdin.readlines()

from collections import Counter

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

def check(N, a_list):
    mc = Counter(a_list).most_common()
    n = len(mc)
    if n == 1:
        if mc[0][0] == 0:
            print('Yes')
            return
    elif n == 2:
        if mc[0][1] == 2*N // 3 and most_common[1][0] == 0:
            print('Yes')
            return
    elif n == 3:
        if mc[0][1] == mc[1][1] == mc[2][1] and mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0:
            print('Yes')
            return
    print('No')

check(N, a_list)
Problem p02981 (python)

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

if N*A <= B:
    print(N*A)
else:
    print(B)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
from itertools import combinations

mod = 2019
l, r = L % mod, R % mod
if l > r:
    l, r = r, l

mini = l*r % mod
for i, j in combinations(range(l, r+1), 2):
    mini = min(mini, i*j % mod)
    if mini == 0:
        break
print(mini)