Problem p02975 (python)

Fixed submission:
import sys
from collections import Counter
n = int(input())
a = list(map(int, input().split()))


# 全て0ならYes
if all([x == 0 for x in a]):
    print("Yes")
    sys.exit()

    
# 全て0でない場合、nは必ず3の倍数になる
if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(a)

cli = list(c.keys())
cval = list(c.values())


# 排他的論理和は3つずつ循環するため、keyは3種類、または0を含む場合2種類になる
if len(cli) > 3 or len(cli) <2:
    print("No")
    sys.exit()

# keyが2種類の場合、0が全体の1/3ならOK
if len(cli) == 2 and 0 in cli:
    if c[0] == n // 3:
        print("Yes")
        sys.exit()
    else:
        print("No")
        sys.exit()

# keyが3種類の場合、全ての値が同数、かつ排他的論理和の関係であればOK
if not all([x == cval[0] for x in cval]):
    print("No")
    sys.exit()

ans_0 = cli[1] ^ cli[2] == cli[0]
ans_1 = cli[2] ^ cli[0] == cli[1]
ans_2 = cli[0] ^ cli[1] == cli[2]

print("Yes" if all([ans_0, ans_1, ans_2]) else "No")

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

n = int(input())
arr = list(map(int, input().split()))

# 全て0ならYes
if all([x == 0 for x in arr]):
    print("Yes")
    sys.exit()

# 3つずつ循環していなければNo
if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(arr)

# 2種類の場合
if len(c) == 2:
    if c[0] == n // 3:
        print("Yes")
        sys.exit()

# 3種類の場合
elif len(c) == 3:
    result = list(c.values())
    if result[0] == result[1] == result[2]:
        ans1 = True
    else:
        ans1 = False
else:
    print("No")
    sys.exit()

result = list(c.keys())
ans2 = result[0] == result[1] ^ result[2] and result[1] == result[0] ^ result[2] and result[2] == result[0] ^ result[1]

print("Yes" if ans1 and ans2 else "No")

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

n = int(input())
arr = list(map(int, input().split()))

# 全て0ならYes
if all([x == 0 for x in arr]):
    print("Yes")
    sys.exit()

# 3つずつ循環していなければNo
if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(arr)

# 2種類の場合
if len(c) == 2:
    if c[0] == n // 3:
        print("Yes")
        sys.exit()

# 3種類の場合
elif len(c) == 3:
    result = list(c.values())
    if result[0] == result[1] == result[2]:
        ans1 = True
    else:
        ans1 = False
else:
    ans1 = False

result = list(c.keys())
ans2 = result[0] == result[1] ^ result[2] and result[1] == result[0] ^ result[2] and result[2] == result[0] ^ result[1]

print("Yes" if ans1 and ans2 else "No")

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

if all([x == 0 for x in arr]):
    print("Yes")
    sys.exit()

if n % 3 != 0:
    print("No")
    sys.exit()

# 排他的論理和になっているか
ans1 = arr[0] == arr[1] ^ arr[2] and arr[1] == arr[0] ^ arr[2] and arr[2] == arr[0] ^ arr[1]

# 3つずつ循環しているか
ans2 = all([x == arr[0] for x in arr[0::3]]) and all([x == arr[1] for x in arr[1::3]]) and all([x == arr[2] for x in arr[2::3]])

print("Yes" if ans1 and ans2 else "No")

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

# 排他的論理和は3つずつ循環するため、満たすべき条件は以下
# nが3の倍数である, 数字が3種類で同数, 3種類が排他的論理和の関係になっている

if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(a)

if len(c.keys()) != 3:
    print("No")
    sys.exit()

if not all([x == cli[0] for x in cli]):
    print("No")
    sys.exit()

a = list(c.keys())
    
ans_0 = a[1] ^ a[2] == a[0]
ans_1 = a[2] ^ a[0] == a[1]
ans_2 = a[0] ^ a[1] == a[2]

print("Yes" if all([ans_0, ans_1, ans_2]) else "No")

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

# 排他的論理和は3つずつ循環するため、満たすべき条件は以下
# nが3の倍数である, 数字が3種類で同数, 3種類が排他的論理和の関係になっている

if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(a)

if len(c.keys()) != 3:
    print("No")
    sys.exit()

if not all([x == cli[0] for x in cli]):
    print("No")
    sys.exit()

ans_0 = a[1] ^ a[2] == a[0]
ans_1 = a[2] ^ a[0] == a[1]
ans_2 = a[0] ^ a[1] == a[2]

print("Yes" if all([ans_0, ans_1, ans_2]) else "No")