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

Fixed submission:
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

first = [0] * (N + 1)
second = [0] * (N + 1)
roop1 = []
roop2 = []

now = 1
while True:
    if not first[now]:
        first[now] = 1
        roop1.append(now)
        now = A[now]
    elif not second[now]:
        second[now] = 1
        roop2.append(now)
        now = A[now]
    else:
        break


if K < len(roop1):
    print(roop1[K])
else:
    K -= len(roop1)
    m = K % len(roop2)
    print(roop2[m])

Buggy submission (verdict: Runtime Error):
D = 60
U = 2 * 10 ** 5 + 10
to = [[0] * D for _ in range(U)]

N, K = map(int, input().split())
for i, a in enumerate(map(int, input().split())):
    to[0][i] = a - 1
# 表の構築
for i in range(D - 1):
    for j in range(N):
        to[i + 1][j] = to[i][to[i][j]]

v = 0
for i in reversed(range(D)):
    x = 1 << i
    if x <= K:
        v = to[i][v]
        K -= x

print(v + 1)
Problem p02698 (python)

Fixed submission:
import bisect
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = tuple(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = map(int, input().split())
    edge[x].append(y)
    edge[y].append(x)

ans = [-1] * (N + 1)
inf = 10**18
LIS = [inf] * (N + 10)


def DFS(s, parent=0):
    a = A[s - 1]
    i = bisect.bisect_left(LIS, a)
    v = LIS[i]
    LIS[i] = a
    ans[s] = bisect.bisect_left(LIS, inf)
    for t in edge[s]:
        if t == parent:
            continue
        DFS(t, s)
    # 頂点sでの結果をもとに戻す
    LIS[i] = v
    return


DFS(1)
print(*ans[1:], sep="\n")

Buggy submission (verdict: Runtime Error):
import bisect
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = tuple(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = map(int, input().split())
    edge[x].append(y)
    edge[y].append(x)

ans = [-1] * (N + 1)
inf = 10**8
LIS = [inf] * (N + 10)


def DFS(s, parent=0):
    a = A[s - 1]
    i = bisect.bisect_left(LIS, a)
    v = LIS[i]
    LIS[i] = a
    ans[s] = bisect.bisect_left(LIS, inf)
    for t in edge[s]:
        if t == parent:
            continue
        DFS(t, s)
    # 頂点sでの結果をもとに戻す
    LIS[i] = v
    return


DFS(1)
print(*ans[1:], sep="\n")

Buggy submission (verdict: Runtime Error):
import bisect
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = tuple(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = map(int, input().split())
    edge[x].append(y)
    edge[y].append(x)

ans = [-1] * (N + 1)
inf = 10**8
LIS = [inf] * (N + 1)


def DFS(s, parent=0):
    a = A[s - 1]
    i = bisect.bisect_left(LIS, a)
    v = LIS[i]
    LIS[i] = a
    ans[s] = bisect.bisect_left(LIS, inf)
    for t in edge[s]:
        if t == parent:
            continue
        DFS(t, s)
    # 頂点sでの結果をもとに戻す
    LIS[i] = v
    return


DFS(1)
print(*ans[1:], sep="\n")
Problem p02761 (python)

Fixed submission:
from collections import defaultdict
d = defaultdict(list)

N, M = map(int, input().split())
for _ in range(M):
    s, c = map(int, input().split())
    d[s].append(c)

val = [-1] * N

# とりあえず桁を確定させる
for k, v in d.items():
    if len(set(v)) > 1:
        print(-1)
        exit()
    val[k - 1] = v[0]

if N == 1:
    ans = max(0, val.pop())
    print(ans)
    exit()
if N >= 2:
    if val[0] == 0:
        print(-1)
        exit()

    if val[0] == -1:
        val[0] = 1
    for i in range(N):
        val[i] = max(0, val[i])

    print(*val, sep="")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
d = defaultdict(list)

N, M = map(int, input().split())
for _ in range(M):
    s, c = map(int, input().split())
    d[s].append(c)

ans = [-1] * N

# とりあえず桁を確定させる
for k, v in d.items():
    if len(set(v)) > 1:
        print(-1)
        exit()
    ans[k - 1] = v[0]

if N == 1:
    val = ans.pop()
    val = max(0, val)
else:
    val = ""
    for i, a in enumerate(ans):
        if a != -1:
            val += str(a)
        else:
            if i == 0:
                val += "1"
            else:
                val += "0"

if val[0] == "0":
    print(-1)
    exit()

print(val)
Problem p02774 (python)

Fixed submission:
import numpy as np


def get_Negative(K, pos, neg):
    K = len(pos) * len(neg) - K + 1
    l = 0
    r = 10 ** 18 + 10
    while r - l > 1:
        m = (l + r) // 2
        target = m // pos
        x = np.searchsorted(neg, target, side="right").sum()
        if x >= K:
            r = m
        else:
            l = m
    return -r


def get_Positive(K, pos, neg):
    l = 0
    r = 10 ** 18 + 10
    tmp_pos = np.arange(len(pos))
    tmp_neg = np.arange(len(neg))
    while r - l > 1:
        m = (r + l) // 2
        cnt = 0
        if len(pos) > 1:
            t1 = m // pos
            x1 = np.searchsorted(pos, t1, side="right")
            x1 = np.maximum(0, x1 - tmp_pos - 1)
            cnt += x1.sum()
        if len(neg) > 0:
            t2 = m // neg
            x2 = np.searchsorted(neg, t2, side="right")
            x2 = np.maximum(0, x2 - tmp_neg - 1)
            cnt += x2.sum()
        if cnt >= K:
            r = m
        else:
            l = m
    return r


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)

    positive = A[A > 0]
    negative = -A[A < 0]
    positive.sort()
    negative.sort()

    Npos = len(positive)
    Nneg = len(negative)
    Nzero = N - Npos - Nneg

    P_neg = Npos * Nneg
    P_pos = 0
    if Npos:
        P_pos += Npos * (Npos - 1) // 2
    if Nneg:
        P_pos += Nneg * (Nneg - 1) // 2
    P_zero = N * (N - 1) // 2 - P_pos - P_neg

    if K <= P_neg:
        ans = get_Negative(K, positive, negative)
        return ans
    K -= P_neg
    if K <= P_zero:
        return 0
    K -= P_zero
    ans = get_Positive(K, positive, negative)
    return ans


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

Buggy submission (verdict: Runtime Error):
import bisect
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
A = np.sort(A)

Aneg = A[A < 0]
Azero = A[A == 0]
Apos = A[A > 0]

neg = len(Aneg)
zero = len(Azero)
pos = len(Apos)

Nneg = neg * pos
Npos = 0
if neg > 0:
    Npos += neg * (neg - 1) // 2
if pos > 0:
    Npos += pos * (pos - 1) // 2
Nzero = N * (N - 1) // 2 - Npos - Nneg
print(Nneg, Npos, Nzero)


def C(N, ar):
    if len(ar) <= 1:
        return 0
    tmp = np.arange(len(ar))+1
    n = np.searchsorted(ar, N / ar, side="left")
    return (len(ar)-np.maximum(n, tmp)).sum()


def C1(N, ar1, ar2):
    tmp = np.arange(len(ar1))+1
    n = np.searchsorted(ar1, N / ar2, side="left")
    return (len(ar1)-np.maximum(n, tmp)).sum()


def bs_Neg():
    l, r = -10 ** 20, 0
    while r - l > 1:
        m = (r - l) // 2
        num = C1(m, Apos, Aneg)
        if num < K:
            r = m
        else:
            l = m
    return l


def bs_Pos(K):
    l, r = 0, 10 ** 20
    while r - l > 1:
        m = (r - l) // 2
        num = C(m, Apos) + C(m, Aneg)
        if num < K:
            r = m
        else:
            l = m
    return l


if K <= Nneg:
    ans = bs_Neg()
elif K <= Nneg + Nzero:
    ans = 0
else:
    K = K-Nneg-Nzero
    ans = bs_Pos(K)

print(ans)
Problem p02812 (python)

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

ans = 0
for x, y, z in zip(s[:-2], s[1:-1], s[2:]):
    if x + y + z == "ABC":
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
def abc151_b():
    N, K, M = map(int, input().split())
    A = sum(list(map(int, input().split())))
    need = max(0, N * M - A)
    ans = need if need <= K else - 1
    print(ans)

abc151_b()
Problem p02814 (python)

Fixed submission:
def GCD(x, y):
    if y == 0:
        return x
    return GCD(y, x % y)


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

check = set()
for a in A:
    cnt = 0
    while a % 2 == 0:
        cnt += 1
        a //= 2
    check.add(cnt)

if len(check) > 1:
    print(0)
    exit()

LCM = 1
for a in A:
    gcd = GCD(LCM, a // 2)
    LCM = LCM * (a // 2) // gcd

ans = (M - LCM) // (2 * LCM) + 1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())
A = tuple(map(int, input().split()))


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


A = np.unique(A)
for i, a in enumerate(A):
    if i == 0:
        g = a
        lcm = a
    g = gcd(g, a)
    lcm *= a // g

ans = M / lcm + 0.5
ans = int(ans)
print(ans)
Problem p02821 (python)

Fixed submission:
import bisect

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = [0] * N
B[-1] = A[-1]
for i in range(N - 2, -1, -1):
    B[i] = B[i+1]+A[i]


def C(mid):
    tmp = 0
    for a in A:
        pos = bisect.bisect_right(A, mid - a)
        tmp += N-pos
    return tmp > M


lb = 0
rb = 10**6
while rb - lb > 1:
    happy = (lb + rb) // 2
    if C(happy):
        lb = happy
    else:
        rb = happy

ans = 0
cnt = 0
for a in A:
    pos = bisect.bisect_right(A, rb - a)
    if pos == N:
        continue
    ans += B[pos]+(N-pos)*a
    cnt += N - pos
ans += (M-cnt)*rb
print(ans)

Buggy submission (verdict: Runtime Error):
#handshake
from scipy.fft import rfft, irfft
import numpy as np
N, M = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

x = np.bincount(A)
fft_size = 1 << (2 * x.size + 10).bit_length()

fx = rfft(x, fft_size)
conv = irfft(fx * fx, fft_size)
conv = (conv + 0.5).astype(int)

tmp = np.arange(conv.size, dtype=int)
happy = tmp[np.nonzero(conv)].tolist()
cnt = conv[np.nonzero(conv)].tolist()


ans = 0
while M > 0:
    h = happy.pop()
    num = cnt.pop()
    num = min(M, num)

    M -= num
    ans += num * h

print(ans)

Buggy submission (verdict: Runtime Error):
#handshake
from scipy.fft import rfft, irfft
import numpy as np
N, M = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

x = np.bincount(A)
fft_size = 1 << (2 * x.size + 10).bit_length()

fx = rfft(x, fft_size)
conv = irfft(fx * fx, fft_size)
conv = (conv + 0.5).astype(int)

tmp = np.arange(conv.size, dtype=int)
happy = tmp[np.nonzero(conv)].tolist()
cnt = conv[np.nonzero(conv)].tolist()


ans = 0
while M > 0:
    h = happy.pop()
    num = cnt.pop()
    num = min(M, num)

M -= num
ans += num * h

print(ans)

Buggy submission (verdict: Runtime Error):
#handshake
from scipy.fft import rfft, irfft
import numpy as np
N, M = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

x = np.bincount(A)
fft_size = 1 << (2 * x.size + 10).bit_length()

fx = rfft(x, fft_size)
conv = irfft(fx * fx, fft_size)
conv = (conv + 0.5).astype(int)

tmp = np.arange(conv.size, dtype=int)
happy = tmp[np.nonzero(conv)].tolist()
cnt = conv[np.nonzero(conv)].tolist()


ans = 0
while M > 0:
h = happy.pop()
num = cnt.pop()
num = min(M, num)

M -= num
ans += num * h

print(ans)
Problem p02839 (python)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

H, W = map(int, input().split())
A = np.array([input().split() for _ in range(H)], dtype=int)
B = np.array([input().split() for _ in range(H)], dtype=int)
dif = np.abs(A - B).tolist()

U = (H + W) * 80
Um = U // 2

dp = [[[] for _ in range(W)] for _ in range(H)]
X = np.zeros(U + 1, dtype=bool)
X[Um + dif[0][0]] = True
X[Um - dif[0][0]] = True
dp[0][0] = X


for i in range(H):
    for j in range(W):
        if i == j == 0:
            continue
        d = dif[i][j]
        X = np.zeros(U + 1, dtype=bool)
        if d:
            if i > 0:
                X[d:] |= dp[i - 1][j][:-d]
                X[:-d] |= dp[i - 1][j][d:]
            if j > 0:
                X[d:] |= dp[i][j - 1][:-d]
                X[:-d] |= dp[i][j - 1][d:]
        else:
            if i > 0:
                X |= dp[i - 1][j]
            if j > 0:
                X |= dp[i][j - 1]
        dp[i][j] = X

tmp = np.arange(U+1)[dp[H-1][W-1]]
ans = np.abs(tmp - Um).min()
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

H, W = map(int, input().split())
A = np.array([input().split() for _ in range(H)], dtype=int)
B = np.array([input().split() for _ in range(H)], dtype=int)
dif = np.abs(A - B).tolist()

U = (H + W) * 80
Um = U // 2

dp = [[[] for _ in range(W)] for _ in range(H)]
X = np.zeros(U + 1, dtype=bool)
X[Um + dif[0][0]] = True
X[Um - dif[0][0]] = True
dp[0][0] = X


for i in range(H):
    for j in range(W):
        if i == j == 0:
            continue
        X = np.zeros(U + 1, dtype=bool)
        d = dif[i][j]
        if i > 0:
            X[d:] |= dp[i - 1][j][:-d]
            X[:-d] |= dp[i - 1][j][d:]
        if j > 0:
            X[d:] |= dp[i][j - 1][:-d]
            X[:-d] |= dp[i][j - 1][d:]
        dp[i][j] = X

tmp = np.arange(U+1)[dp[H-1][W-1]]
ans = np.abs(tmp - Um).min()
print(ans)
Problem p02845 (python)

Fixed submission:
import numpy as np


if __name__ == "__main__":
    n = int(input())
    a = np.array(list(map(int, input().split())))
    mod = 10**9+7

    memo = np.zeros(n+10, dtype=int)
    memo[0] = 3
    ans = 1
    for i in a:
        mae = memo[i]
        now = memo[i+1]
        ans *= mae-now
        ans %= mod

        memo[i+1] += 1

    print(ans)

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


def calc(mae, now):
    if mae == 3:
        if now == 0:
            return 3
        elif now == 1:
            return 2
        elif now == 2:
            return 1
    elif mae == 2:
        if now == 0:
            return 2
        elif now == 1:
            return 1
    elif mae == 1:
        if now == 0:
            return 1


if __name__ == "__main__":
    n = int(input())
    a = np.array(list(map(int, input().split())))
    mod = 10**9+7

    memo = np.zeros(n+1, dtype=int)
    memo[0] = 3
    ans = 1
    for i in a:
        mae = memo[i]
        now = memo[i+1]
        ans *= calc(mae, now)
        ans %= mod

        memo[i+1] += 1

    print(ans)
Problem p02850 (python)

Fixed submission:
from collections import deque
n = int(input())
tree = [[] for _ in range(n)]
edge = []

for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    edge.append((a, b))


# serch max number of color
for i in range(n):
    if i == 0:
        color = len(tree[i])
    else:
        color = max(color, len(tree[i])+1)

upper = [0 for _ in range(n)]

for i in range(n):
    if not tree[i]:
        continue

    top = upper[i]
    tmp = tree[i].copy()
    cnt = 1
    while tmp:
        if cnt == top:
            cnt += 1
        upper[tmp.pop()] = cnt
        cnt += 1

ans = []
for x, y in edge:
    ans.append(upper[y])
print(color)
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
tree = [[] for _ in range(n)]
edge = []

for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    edge.append((a, b))


# serch max number of color
for i in range(n):
    if i == 0:
        color = len(tree[i])
    else:
        color = max(color, len(tree[i])+1)

upper = [0 for _ in range(n)]

for i in range(n):
    if not tree[i]:
        continue

    top = upper[i]
    tmp = tree[i].copy()
    cnt = 1
    while tmp:
        if cnt == top:
            cnt += 1
        upper[tmp.pop()] = cnt
        cnt += 1

ans = []
for x, y in edge:
    ans.append(upper[y])
print(color)
print(*ans, sep="\n")
Problem p02852 (python)

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

dp = [-1] * (N + M + 1)
dp[N] = 0
pos = N

while pos > 0:
    dist = dp[pos]
    tmp = pos

    for i in range(1, M + 1):
        if pos - i < 0:
            break
        if S[pos - i] == "0":
            dp[pos - i] = dist + 1
            tmp = pos - i
    if pos == tmp:
        break
    pos = tmp

if dp[0] == -1:
    print(-1)
    exit()

ans = []
cnt = dp[0]
pos = 0
while cnt > 0:
    for i in range(1, M + 1):
        if dp[pos + i] + 1 == cnt:
            ans.append(i)
            pos += i
            cnt -= 1
            break

print(*ans, sep=" ")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()
S = S[::-1]

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

pos = 0
while pos < N:

    p = pos
    update = False

    for i in range(1, M + 1):
        if p + i > N:
            break
        if S[p + i] == "1":
            continue
        update = True
        pos = p + i
        dp[pos] = dp[p] + 1

    if not update:
        break

if dp[N] == -1:
    print(-1)
    exit()

dp = dp[::-1]
num = dp[0]
ans = []
pos = 0

while num > 0:
    for i in range(1, M + 1):
        if dp[pos + i] == num - 1:
            num -= 1
            pos += i
            ans.append(str(i))

ans = " ".join(ans)
print(ans)
Problem p02937 (python)

Fixed submission:
import collections
import bisect
S = input()
T = input()
N = len(S)

d = collections.defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)

ans = 0
end = 0
isOK = True
i = 0

for t in T:
    if len(d[t]) == 0:
        isOK = False
        break
    dic = d[t]
    idx = bisect.bisect_right(dic, i)
    if len(dic) == idx:
        i = dic[0]
        end += 1
    else:
        i = dic[idx]

if isOK:
    ans = N * end + i
else:
    ans = -1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import bisect

S = input()
T = input()

d = defaultdict(list)
for i, s in enumerate(S, start=1):
    d[s].append(i)

ans = 0
i = 0

for t in T:
    if not d[t]:
        print(-1)
        exit()

    if i > d[t][-1]:
        ans += len(S)
        i = 0
    pos = bisect.bisect_right(d[t], i)
    i = d[t][pos]

ans += i
print(ans)
Problem p02960 (python)

Fixed submission:
S = input()
mod = 10 ** 9 + 7

dp = [0]*13
dp[0] = 1

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)

Buggy submission (verdict: Runtime Error):
def main():
    S = input()[::-1]
    N = len(S)
    mod = 10 ** 9 + 7

    dp = [[0] * 13 for _ in range(N + 5)]
    dp[0][0] = 1

    digit = 1
    for i, s in enumerate(S):
        if s == "?":
            num = tuple(range(10))
        else:
            num = (int(s), )

        ni = i + 1
        for j in range(13):
            for k in num:
                nj = (j + k * digit) % 13
                dp[ni][nj] += dp[i][j]
                dp[ni][nj] %= mod

        digit *= 10
        digit %= 13

    return dp[N][5]


if __name__ == "__main__":
    print(main())pyp

Buggy submission (verdict: Runtime Error):
s=input()
mod=1000000007

#後ろから解くアルゴリズム
n=13
dp=[0 for _ in range(n)]
dp[0]=1

mul=1
for i in range(len(s)-1, -1, -1):
    nextDP=[0 for _ in range(n)]
    c=s[i]
    if c=='?':
        for k in range(10):
            for j in range(13):
                nextDP[(mul*k+j)%13] += dp[j]
                nextDP[(mul*k+j)%13] %= mod
    else:
        k=int(c)
        for j in range(n):
            nextDP[(mul*k+j)%13] += dp[j]
            nextDP[(mul*k+j)%13] %= mod
    
    mul*=10
    mul%=n
    dp=nextDP.copy()   

print(dp[5])
Problem p02973 (python)

Fixed submission:
import bisect
from collections import deque
N=int(input())
a=[int(input()) for _ in range(N)]
d=deque()

for i in range(N):
    p=bisect.bisect_left(d, a[i])
    #print(a[i], p, d)
    if p==0:
        d.appendleft(a[i])
    else:
        d[p-1]=a[i]
print(len(d))

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

lasts=[int(input())]
for _ in range(N-1):
    a=int(input())
    
    if a<=lasts[0]:
        lasts.insert(0, a)
    else:
        for i,val in enumerate(lasts[::-1]):
            if val<a:
                lasts[len(lasts)-1-i]=a
                break

print(len(lasts)
Problem p02975 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))


def xor_circle(N, A):
    if sum(A) == 0:
        return "Yes"
    if N % 3 != 0:
        return "No"

    B = Counter(A)
    if len(B) == 3:
        a, b, c = B.keys()
        Na, Nb, Nc = B.values()
        if a ^ b ^ c == 0 and Na == Nb == Nc:
            return "Yes"
        else:
            return "No"
    elif len(B) == 2:
        a, b = B.keys()
        Na, Nb = B.values()
        if a == 0 and 2*Na == Nb:
            return "Yes"
        elif b == 0 and Na == 2*Nb:
            return "Yes"
        else:
            return "No"
    else:
        return "No"


ans = xor_circle(N, A)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

if N % 3 != 0:
    ans = "Yes" if sum(A) == 0 else "No"
else:
    B = Counter(A)
    keys = tuple(B.keys())
    vals = tuple(B.values())
    if len(B) == 3:  # 3種類ならa^b^cかつNa==Nb==NCでおけ
        a, b, c = keys
        Na, Nb, Nc = vals
        if Na == Nb and Nb == Nc:
            a, b, c = keys
            ans = "No" if a ^ b ^ c else "Yes"
        else:
            ans = "No"
    elif len(B) == 2:  # 2種類なら、a^a==0かつb==0かつNa==2Nbでおけ
        a, b = keys
        Na, Nb = vals
        if a == 0:
            ans = "Yes" if Na == 2*Nb else "No"
        elif b == 0:
            ans = "Yes" if 2*Na == Nb else "No"
        else:
            ans = "No"
    elif len(B) == 1:
        a = keys[0]
        ans == "Yes" if a == 0 else "No"
    else:
        ans = "No"


print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

if N % 3 != 0:
    ans = "Yes" if sum(A) == 0 else "No"
else:
    B = Counter(A)
    keys = tuple(B.keys())
    vals = tuple(B.values())
    if len(B) == 3:  # 3種類ならa^b^cかつNa==Nb==NCでおけ
        a, b, c = keys
        Na, Nb, Nc = vals
        if Na == Nb and Nb == Nc:
            a, b, c = keys
            ans = "No" if a ^ b ^ c else "Yes"
        else:
            ans = "No"
    elif len(B) == 2:  # 2種類なら、a^a==0かつb==0かつNa==2Nbでおけ
        a, b = keys
        Na, Nb = vals
        if a == 0:
            ans = "Yes" if Na == 2*Nb else "No"
        elif b == 0:
            ans = "Yes" if 2*Na == Nb else "No"
        else:
            ans = "No"
    elif len(B) == 1:
        a = keys[0]
        ans == "Yes" if a == 0 else "No"


print(ans)
Problem p02995 (python)

Fixed submission:
def gcd(x,y):
    x,y=max(x,y),min(x,y)
    if y==0:
        return x
    return gcd(y, x%y)


a,b,c,d=map(int,input().split())
e=int(c*d/gcd(c,d))

rng=b-a+1
x=b//c-(a-1)//c
y=b//d-(a-1)//d
z=b//e-(a-1)//e
print(rng-x-y+z)

Buggy submission (verdict: Runtime Error):
from math import gcd
a,b,c,d=map(int,input().split())
e=int(c*d/gcd(c,d))

rng=b-a+1
x=b//c-(a-1)//c
y=b//d-(a-1)//d
z=b//e-(a-1)//e
print(rng-x-y+z)