Problem:


Score : 300 points

Problem Statement

Snuke has N hats. The i-th hat has an integer a_i written on it.

There are N camels standing in a circle.
Snuke will put one of his hats on each of these camels.

If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.

The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.

What is XOR?

The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.

Sample Input 2

4
1 2 4 8

Sample Output 2

No

There is no such way to distribute the hats; the answer is No.



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    flg = False
    if len(set(A)) == 1 and 0 in set(A):
        flg = True
    else:
        if n % 2 == 0:
            D = Counter(A)
            if D[0] == n // 2 and len(D) == 2:
                flg = True
        if n % 3 == 0:
            D = Counter(A)
            if len(D) == 3:
                t = 0
                V = set()
                for k, v in D.items():
                    t ^= k
                    V.add(v)
                if len(V) == 1 and t == 0:
                    flg = True
    print("Yes" if flg else "No")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
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)

if len(c) == 2:
    if c[0] == n // 3:
        ans1 = True
    else:
        ans1 = False
elif len(c) == 3:
    ans1 = True
else:
    ans1 = False

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

# 3つずつ循環しているか
ans3 = 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 and ans3 else "No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(N):
    res ^= a[i]

if N == 3:
    print('Yes') if res==0 else print('No')
else:
    for i in range(N):
        if a[i]^a[(i+3)%N] != 0:
            print('No')
            exit()
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())

a = list(map(int,input().split()))
a.sort()
a = [a[-1]]+a+[a[0]]
        
Flag = True

for i in range(1,N+1):
    if a[i] != (a[i-1] ^ a[i+1]):
        Flag = False
        break
if Flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())

a = list(map(int,input().split()))
a = [a[-1]]+a+[a[0]]
        
Flag = True

for i in range(1,N+1):
    if a[i] != (a[i-1] ^ a[i+1]):
        Flag = False
        break
if Flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(N):
    res ^= a[i]
if res == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

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")

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(map(int, input().split()))
al.sort()
al_cnt_d = {}

if al[0] == 0 and al[n-1] == 0:
    print('Yes')

elif n == 3:
    if al[0] ^ al[1] ^al[2] == 0:
        print('Yes')
    else:
        print('No')

elif n%3 == 0:
    for a in al:
        al_cnt_d.setdefault(a,0)
        al_cnt_d[a] += 1

    if len(al_cnt_d) == 3:
        val = 0
        for k,v in al_cnt_d.items():
            val = val^k
            if v != n//3:
                print('No')
                exit()
        if val == 0: print('Yes')
        else: print('No')

else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
if N==3:
    if A[0]==A[1]^A[2]:
        print("Yes")
    else:
        print("No")
else:
    flag = 0
    for i in range(1,N):
        if A[i]!=A[0]:
            flag = 1
            break
    if flag==0:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(map(int, input().split()))
al.sort()
al_cnt_d = {}

if n == 3:
    if al[0] ^ al[1] ^al[2] == 0:
        print('Yes')
    else:
        print('No')

elif n%3 == 0:
    for a in al:
        al_cnt_d.setdefault(a,0)
        al_cnt_d[a] += 1

    if len(al_cnt_d) == 3:
        val = 0
        for k,v in al_cnt_d.items():
            val = val^k
            if v != n//3:
                print('No')
                exit()
        if val == 0: print('Yes')
        else: print('No')

else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

A = [int(i) for i in input().split()]
counts = Counter(A)
tmp = 0

for a in A:
    tmp ^= a
if tmp != 0:
    print("No")
    quit()

# case1: すべてが0の場合
if len(set(A)) == 1 and A[0] == 0:
    print("Yes")

# case2: nが3の倍数で、x^y^z == 0 となり、counts ==  x:n//3,y:n//3,z:n//3を満たす

if len(counts.items()) == 3 and n % 3 == 0:
    tmp = 0
    for x, k in counts.items():
        if k == n // 3:
            tmp ^= x
        else:
            print("No")
            quit()
    if tmp == 0:
        print("Yes")
        quit()
    else:
        print("No")
        quit()

# case3: nが3の倍数で、counts == x: 2*n//3,0: n//3 を満たす

if len(counts.items()) == 2 and n % 3 == 0:
    if counts.most_common()[1][0] == 0 and counts.most_common()[1][1] == n // 3:
        print("Yes")
        quit()
    else:
        print("No")
        quit()

print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

A = [int(i) for i in input().split()]
counts = Counter(A)

# case3: nが3の倍数で、counts == x: 2*n//3,0: n//3 を満たす

if len(counts.items()) == 2 and n % 3 == 0:
    if counts.most_common()[1][0] == 0 and counts.most_common()[1][1] == n // 3:
        print("Yes")
        quit()
    else:
        print("No")
        quit()

tmp = 0
for a in A:
    tmp ^= a
if tmp == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

A = [int(i) for i in input().split()]
counts = Counter(A)

# case1: すべてが0の場合
if len(set(A)) == 1 and A[0] == 0:
    print("Yes")

# case2: nが3の倍数で、x^y^z == 0 となり、counts ==  x:n//3,y:n//3,z:n//3を満たす

if len(counts.items()) == 3 and n % 3 == 0:
    tmp = 0
    for x, k in counts.items():
        if k == n // 3:
            tmp ^= x
        else:
            print("No")
            quit()
    if tmp == 0:
        print("Yes")
        quit()
    else:
        print("No")
        quit()

# case3: nが3の倍数で、counts == x: 2*n//3,0: n//3 を満たす

if len(counts.items()) == 2 and n % 3 == 0:
    if counts.most_common()[1][0] == 0 and counts.most_common()[1][1] == n // 3:
        print("Yes")
        quit()
    else:
        print("No")
        quit()

print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

A = [int(i) for i in input().split()]
counts = Counter(A)

if len(set(A)) == 1 and A[0] == 0:
    print("Yes")
elif len(set(A)) == 2 and counts.most_common()[0][0] == 0 and counts.most_common()[0][1] == (n * 2) // 3:
    print("Yes")
elif len(set(A)) == 3 and counts.most_common()[0][1] == counts.most_common()[1][1] == counts.most_common()[2][1]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

A = [int(i) for i in input().split()]
counts = Counter(A)

if len(set(A)) == 1 and A[0] == 0:
    print("Yes")
elif len(set(A)) == 2 and counts.most_common()[0][0] == 0 and counts.most_common()[0][1] == n // 3:
    print("Yes")
elif len(set(A)) == 3 and counts.most_common()[0][1] == counts.most_common()[1][1] == counts.most_common()[2][1]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
bit = [0] * 32
tmp = 0
for a in A:
    for j in range(32):
        bit[j] += (a >> j) & 1
        bit[j] %= 2

for b in bit:
    if b % 2 == 1:
        print("No")
        quit()

print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
tmp = 0
for a in A:
    tmp ^= a
if tmp == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int()
A = [int(i) for i in input().split()]
tmp = 0
for a in A:
    tmp ^= a
if tmp == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
l = Counter(a)
all_xor = 0
if N % 3 != 0:
    if l[0] != N:
        print("No")
        exit()
    else:
        print("Yes")
        exit()
for _l in l.keys():
    if l[_l] == N // 3:
        continue
    if _l == 0:
        if l[0] == N:
            print("Yes")
            exit()
        if l[0] != N // 3 or len(l) != 2:
            print("No")
            exit()
    if l[_l] == (2 * N) // 3 and l[0] == N // 3:
        print("Yes")
        exit()
for i in range(N):
    all_xor = a[i] ^ all_xor
if all_xor == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
l = Counter(a)
all_xor = 0
if N % 3 != 0:
    if l[0] != N:
        print("No")
        exit()
    else:
        print("Yes")
        exit()
for _l in l.keys():
    if l[_l] == N // 3:
        continue
    if _l == 0:
        if l[0] != N // 3 or len(l) != 2:
            print("No")
            exit()
    if l[_l] == (2 * N) // 3 and l[0] == N // 3:
        print("Yes")
        exit()
for i in range(N):
    all_xor = a[i] ^ all_xor
if all_xor == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
l = Counter(a)
all_xor = 0
if N % 3 != 0:
    if l[0] != N:
        print("No")
        exit()
    else:
        print("Yes")
        exit()
for _l in l.values():
    if _l != N // 3:
        if _l != (2 * N) // 3:
            if l[0] != N // 3:
                print("No")
                exit()
for i in range(N):
    all_xor = a[i] ^ all_xor
if all_xor == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
l = Counter(a)
all_xor = 0
if N % 3 != 0:
    if l[0] != N:
        print("No")
        exit()
for _l in l.values():
    if _l != N // 3:
        if _l != (2 * N) // 3:
            if l[0] != N // 3:
                print("No")
                exit()
for i in range(N):
    all_xor = a[i] ^ all_xor
if all_xor == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
l = Counter(a)
all_xor = 0
if N % 3 != 0:
    if l[0] != N:
        print("No")
        exit()
for _l in l.values():
    if _l != N // 3:
        print("No")
        exit()
for i in range(N):
    all_xor = a[i] ^ all_xor
if all_xor == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for i in range(N):
    all_xor = a[i] ^ all_xor
    if i == 0:
        if a[N-1] == a[1]:
            if a[0] != 0:
                print("No")
                exit()
                break
        continue
    if i == N - 1:
        if a[N-2] == a[0]:
            if a[N-1] != 0:
                print("No")
                exit()
                break
        continue
    if a[i - 1] == a[i + 1]:
        if a[i] != 0:
            print("No")
            exit()


if all_xor == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for i in range(N):
    all_xor = a[i] ^ all_xor
    if i == 0:
        if a[N-1] == a[1]:
            if a[0] != 0:
                print("No")
                exit()
                break
        continue
    if i == N - 1:
        if a[N-2] == a[0]:
            if a[N-1] != 0:
                print("No")
                exit()
                break
        continue
    if a[i - 1] == a[i + 1]:
        if a[i] == 0:
            print("No")
            exit()


if all_xor == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for _a in a:
    all_xor = _a ^ all_xor
if all_xor == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import*
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
  ans^=i
flag=ans==0
a=dict(Counter(a))
ak=list(a.keys())
if n%3:flag=0
elif len(a)==1 and ak[0]!=0:flag=0
elif len(a)==2 and a.get(0)!=n//3:flag=0
elif len(a)==3 and not(a[ak[0]]==a[ak[1]]==a[ak[2]]==n//3):flag==0
print(['No','Yes'][flag])

Submission status: Wrong Answer

Solution code:
from collections import*
n=int(input())
a=dict(Counter(list(map(int,input().split()))))
flag=1
ak=list(a.keys())
if n%3:flag=0
elif len(a)==1 and ak[0]!=0:flag=0
elif len(a)==2 and a.get(0)!=n//3:flag=0
elif len(a)==3 and not(ak[0]==ak[1]==ak[2]==n//3):flag==0
print(['No','Yes'][flag])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
  ans^=i
print(['Yes','No'][ans!=0])

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))


l += [l[0], l[1], l[2]]
flag = True
for i in range(n):
    if l[i] != l[i + 3]:
        flag = False
        break

if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
tmp1 = list(A.items())
tmp1.sort()
if len(tmp1) == 1 and tmp1[0][0] == 0 or len(tmp1) == 2 and tmp1[0][0] == 0 and tmp1[0][1] == N // 3 * 2 and tmp1[1][1] == N // 3 or len(tmp1) == 3 and (tmp1[0][0] ^ tmp1[1][0] ^ tmp1[2][0]) == 0 and tmp1[0][1] == tmp1[1][1] == tmp1[2][1] == N // 3:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
tmp = list(A.keys())
tmp.sort()
if len(tmp) == 1 and tmp[0] == 0 or len(tmp) == 2 and tmp[0] == 0 and list(A.values())[0] == N // 3 * 2 and list(A.values())[1] == N // 3 or len(tmp) == 3 and (tmp[0] ^ tmp[1] ^ tmp[2]) == 0 and list(A.values())[0] == list(A.values())[1] == list(A.values())[2] == N // 3:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if a[-1] != a[0] ^ a[-2]:
    print("No")
    exit()
for i in range(n-1):
    if a[i] != a[i-1] ^ a[i+1]:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    if A[i] not in C:
        C[A[i]] = 0
    C[A[i]] += 1
if len(C)>3:
    print("No")
else:
    if N%3==0:
        if 0 in C:
            if len(C)==1:
                print("Yes")
            elif len(C)==2:
                if C[0]==N//3:
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
        else:
            if len(C)!=3:
                print("No")
            else:
                flag = 0
                for a in C:
                    if C[a]!=N//3:
                        flag = 1
                        break
                if flag==0:
                    print("Yes")
                else:
                    print("No")
    else:
        if len(C)==1 and 0 in C:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    if A[i] not in C:
        C[A[i]] = 0
    C[A[i]] += 1
if len(C)>3:
    print("No")
else:
    if N%3==0:
        if 0 in C:
            if len(C)==1:
                print("Yes")
            elif len(C)==2:
                if C[0]==N//3:
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
        else:
            if len(C)!=3:
                print("No")
            else:
                flag = 0
                for a in C:
                    if C[a]!=N//3:
                        flag = 1
                        break
                if flag==0:
                    print("Yes")
                else:
                    print("No")
    else:
        if A[0]==A[1]==0:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [A[0],A[1],A[0]^A[1]]
flag = 0
for i in range(2,N):
    if A[i] not in B:
        flag = 1
        break
if flag==1:
    print("No")
else:
    if N%3==0:
        if A[0]==A[1]==0:
            print("Yes")
        elif A[0]==0 or A[1]==0:
            cnt = 0
            for i in range(N):
                if A[i]==0:
                    cnt += 1
            if cnt==N//3:
                print("Yes")
            else:
                print("No")
        else:
            C = {A[0]:0,A[1]:0,A[0]^A[1]:0}
            for i in range(N):
                C[A[i]] += 1
            if C[A[0]]==C[A[1]]==C[A[0]^A[1]]:
                print("Yes")
            else:
                print("No")
    else:
        if A[0]==A[1]==0:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
from functools import reduce


N, *A = map(int, open(0).read().split())
xor_A = reduce(lambda x, y: x ^ y, A)
if N % 2:
    print("Yes") if xor_A == 0 else print("No")
else:
    print("Yes") if xor_A in A else print("No")

Submission status: Wrong Answer

Solution code:
# from random import randint, shuffle, sample, choice

# def randil(a,b,n): return [ randint(a,b) for _ in range(n) ]  # list of N elements (a <= n <= b)
from itertools import permutations


# # n = int(input())
# n = 4

# for i in range(100):
#     al = randil(1,10,6)
    # ll = list(range(0,n))  # list of elements
    # perml = list(permutations(ll, n))
    # for perm in perml:
    #     for i in range(n):
    #         prev = al[perm[i-2]]
    #         curr = al[perm[i-1]]
    #         nextv = al[perm[i]]
    #         if prev^nextv != curr:
    #             break
    #     else:
    #         ans = []
    #         for i in range(n): 
    #             ans.append(al[perm[i]])
    #         print(ans)


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

if n >3:
    print('No')
else:
    ll = list(range(0,n))  # list of elements
    perml = list(permutations(ll, n))
    for perm in perml:
        for i in range(n):
            prev = al[perm[i-2]]
            curr = al[perm[i-1]]
            nextv = al[perm[i]]
            if prev^nextv != curr:
                break
        else:
            print('Yes')
            exit()
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
C = Counter(a)
if C[0] == N:
    print("Yes")
elif len(C) != 3 or N%3 != 0:
    print("No")
else:
    for e in C:
        if C[e] != N//3:
            print("No")
            exit(0)
    C = list(set(C))
    if C[0]^C[1] == C[2] or C[1]^C[2] == C[0] or C[2]^C[0] == C[1]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
C = Counter(a)
if C[0] == N:
    print("Yes")
elif len(C) != 3 or N%3 != 0:
    print("No")
else:
    for e in C:
        if C[e] != N//3:
            print("No")
            exit(0)
    print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
C = Counter(a)
if len(C) != 3 or N%3 != 0:
    print("No")
else:
    for e in C:
        if C[e] != N//3:
            print("No")
            exit(0)
    print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
C = [A[0],A[1],A[0]^A[1]]
flag = 0
for i in range(2,N):
    if A[i] not in C:
        flag = 1
        break
if flag==1:
    print("No")
else:
    if N%3==0:
        print("Yes")
    else:
        if A[0]==A[1]==0:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    
    c = Counter(A).most_common()

    if c[0][0] == "0" and c[0][1] == N:
        print("Yes")
    elif len(c) == 2 and c[0][1] == 2*N//3 and c[1][0] == "0" and c[1][1] == N//3:
        print("Yes")
    elif len(c) == 3 and int(c[0][0])^int(c[1][0]) == int(c[2][0]) and c[0][1] == c[1][1] and c[1][1] == c[2][1]:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    
    c = Counter(A)
    values = list(c.values())
    keys = list(map(int, c.keys()))

    if len(keys) == 3 and keys[0] ^ keys[1] == keys[2] and values[0] == values[1] and values[1] == values[2]:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    s = 0
    for i in range(N):
        s ^= a[i]

    if s != 0:
        print('No')
        return

    if N%3 == 0:
        d = {}
        for i in range(N):
            if not a[i] in d:
                d[a[i]] = 0
            d[a[i]] += 1

        if all(v == N//3 for v in d.values()) or all(a[i] == 0 for i in range(N)):
            print('Yes')
        else:
            print('No')

    else:
        if all(a[i] == 0 for i in range(N)):
            print('Yes')
        else:
            print('No')



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    s = 0
    for i in range(N):
        s ^= a[i]

    if s != 0:
        print('No')
        return

    if N%3 == 0:
        d = {}
        for i in range(N):
            if not a[i] in d:
                d[a[i]] = 0
            d[a[i]] += 1

        if all(v == N//3 for v in d.values()):
            print('Yes')
        else:
            print('No')

    else:
        if all(a[i] == 0 for i in range(N)):
            print('Yes')
        else:
            print('No')



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

if n == 3:
    if a[0] == a[1]^a[2]:
        print("Yes")
    else:
        print("No")
elif sum(a) == 0:
    print("Yes")
else:
    vals = []
    cnts = []

    for i in range(n):
        if a[i] in vals:
            cnts[vals.index(a[i])] += 1
        else:
            if len(vals) == 3:
                print("No")
                exit()

            vals.append(a[i])
            cnts.append(1)

    if len(vals) == 3 and (vals[0] == vals[1]^vals[2]) and (cnts[0] == cnts[1] and cnts[1] == cnts[2]):
        print("Yes")
    elif len(vals) == 2 and (vals[0] == 0 or vals[1] == 0) and cnts[0] == cnts[1]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

if n == 3:
    if a[0] == a[1]^a[2]:
        print("Yes")
    else:
        print("No")
elif sum(a) == 0:
    print("Yes")
else:
    vals = []
    cnts = []

    for i in range(n):
        if a[i] in vals:
            cnts[vals.index(a[i])] += 1
        else:
            if len(vals) == 3:
                print("No")
                exit()

            vals.append(a[i])
            cnts.append(1)

    if len(vals) == 3 and (vals[0] == vals[1]^vals[2]) and (cnts[0] == cnts[1] and cnts[1] == cnts[2]):
        print("Yes")
    elif len(vals) == 2 and (vals[0] == 0 or vals[1] == 0):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

if n == 3:
    if a[0] == a[1]^a[2]:
        print("Yes")
    else:
        print("No")
elif sum(a) == 0:
    print("Yes")
else:
    vals = []
    cnts = []

    for i in range(n):
        if a[i] in vals:
            cnts[vals.index(a[i])] += 1
        else:
            if len(vals) == 3:
                print("No")
                break

            vals.append(a[i])
            cnts.append(1)

    if len(vals) == 3 and (vals[0] == vals[1]^vals[2]) and (cnts[0] == cnts[1] and cnts[1] == cnts[2]):
        print("Yes")
    elif len(vals) == 2 and (vals[0] == 0 or vals[1] == 0):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

if n == 3:
    if a[0] == a[1]^a[2]:
        print("Yes")
    else:
        print("No")
elif sum(a) == 0:
    print("Yes")
else:
    vals = []
    cnts = []

    for i in range(n):
        if a[i] in vals:
            cnts[vals.index(a[i])] += 1
        else:
            if len(vals) == 3:
                print("No")
                exit()

            vals.append(a[i])
            cnts.append(1)

    if len(vals) == 3 and (vals[0] == vals[1]^vals[2]) and (cnts[0] == cnts[1] and cnts[1] == cnts[2]):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

if n == 3:
    if a[0] == a[1]^a[2]:
        print("Yes")
    else:
        print("No")
elif sum(a) == 0:
    print("Yes")
else:
    vals = []
    cnts = []

    for i in range(n):
        if a[i] in vals:
            cnts[vals.index(a[i])] += 1
        else:
            if len(vals) == 3:
                print("No")
                exit()

            vals.append(a[i])
            cnts.append(1)

    if len(vals) == 3 and cnts[0] == cnts[1] and cnts[1] == cnts[2]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

if n == 3:
    if a[0] == a[1]^a[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))

if A==[0]*N:
    print("Yes")
    exit()

T={}
for a in A:
    if a in T:
        T[a]+=1
    else:
        T[a]=1

F=True
for x in T:
    F&=(3*T[x]==N)

if not F:
    print("No")
    exit()

x,y,z=list(T.keys())

if x^y==z:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
x = 0
for i in range(N):
    x ^=  a[i]
if x:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    xor_all = 0
    zero_cnt = 0
    for a in A:
        xor_all = xor_all ^ a
        zero_cnt += 1 if a == 0 else 0

    if xor_all == 0:
        if zero_cnt > 0:
            if zero_cnt * 2 == N - zero_cnt:
                ans = "Yes"
            else:
                ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    xor_all = 0
    zero_cnt = 0
    for a in A:
        xor_all = xor_all ^ a
        zero_cnt += 1 if a == 0 else 0

    if xor_all == 0:
        if zero_cnt > 0:
            n_types = len(set(A))
            if n_types == 1:
                ans = "Yes"
            elif n_types == 2 and zero_cnt * 2 == N - zero_cnt:
                ans = "Yes"
            else:
                ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    xor_all = 0
    zero_cnt = 0
    for a in A:
        xor_all = xor_all ^ a
        zero_cnt += 1 if a == 0 else 0

    if xor_all == 0:
        if zero_cnt > 0:
            n_types = len(set(A))
            if n_types == 2 and zero_cnt * 2 == N - zero_cnt:
                ans = "Yes"
            else:
                ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()