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: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] +=1
if len(d) == 1 and list(d.keys())==[0]:
    print('Yes')
elif len(d) == 2:
    for i in d:
        if i == 0 and d[i] * 3 != N or i != 0 and d[i] * 3 != 2 * N:
            print('No')
            exit()
    print('Yes')
elif len(d) == 3:
    s = 0
    for i in d:
        s ^= i
        if d[i] * 3 != N:
            print('No')
            exit()
    if s != 0:
        print('No')
    else:
        print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = list(map(int,input().split()))
    a_set = set(a)
    if len(a_set) > 3:
        return('No')

    if len(a_set) == 1:
        if sum(a_set) == 0:
            return('Yes')
        else:
            return('No')

    elif len(a_set) == 2:
        a_1,a_2 = sorted(a_set)
        if a_1 == 0 and a.count(a_1)*3 == N:
            return ('Yes')
        else:
            return('No')

    else:
        a_1,a_2,a_3 = a_set
        if a.count(a_1) == a.count(a_2) and a.count(a_1) == a.count(a_3) and a.count(a_3) == a.count(a_2):
            if a_1^a_2 == a_3:
                return ('Yes')
            else:
                return('No')
        else:
            return('No')

print(main())

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = {}
for i in range(n):
    b[a[i]] = b[a[i]]+1 if a[i] in b else 1
b = list(b.items())
if len(b) == 1:
    print("Yes") if b[0][0] == 0 else print("No")
elif len(b) == 2:
    b.sort()
    print("Yes") if b[0][0] == 0 and b[0][1]*2 == b[1][1] else print("No")
elif len(b) == 3:
    print("Yes") if b[0][0]^b[1][0]^b[2][0] == 0 and b[0][1] == b[1][1] and b[1][1] == b[2][1] else print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
*a,=map(int,input().split())

cnt=sorted(list(Counter(a).items()),key=lambda x:x[0])

if len(cnt)==1 and cnt[0][0]==0:
    print('Yes')
elif n%3==0 and len(cnt)==2 and cnt[0][0]==0 and cnt[0][1]==n//3:
    print('Yes')
elif n%3==0 and len(cnt)==3 and cnt[0][0]^cnt[1][0]^cnt[2][0]==0 and cnt[0][1]==n//3 and cnt[1][1]==n//3 and cnt[2][1]==n//3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
if len(set(a))>3:
    print("No")
    exit()
if a.count(0)==n:
    print("Yes")
    exit()
if n%3!=0:
    print("No")
    exit()
if len(set(a))==3:
    a.sort()
    if a.count(a[0])==n//3 and a.count(a[-1])==n//3:
        if a[0]^a[-1] in set(a):
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
elif len(set(a))==2:
    if a.count(0)==n//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
else:
    print("No")
    exit()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
if sum(A) ==0: #すべてゼロ
  print("Yes")
  exit()

if N%3 != 0:
  print("No")
else:
  dic = {}
  for x in A:
    if x in dic:
      dic[x] += 1
    else:
      dic[x] = 1
  V = list(dic.values())
  if len(V) == 2:
    K = list(dic.keys())
    if K[0] == 0 and dic[K[1]] == dic[0]*2:
      print("Yes")
    elif K[1] == 0 and dic[K[0]] == dic[0]*2:
      print("Yes")
    else:
      print("No")
    exit()  
  if len(V) != 3:
    print("No")
    exit()
  if V[0] == V[1] and V[1] == V[2]:
    K = list(dic.keys())
    if K[0]^K[1] == K[2] and K[1]^K[2] == K[0] and K[2]^K[0] == K[1]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
SA = set(A)
CA = Counter(A)

if len(SA) == 1 and list(SA)[0] == 0:
    print("Yes")
    exit()

if len(SA) == 2 and 0 in SA and CA[0] * 3 == N:
    print("Yes")
    exit()

for v in CA.values():
    if 3 * v != N:
        break
else:
    a, b, c = CA.keys()
    if a ^ b ^ c == 0:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
a = LI()

# a_i = a_(i+3) に注目

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

B = list(set(a))
b = len(B)
n = N//3
if b > 3:
    print('No')
elif b == 1:
    for i in range(N):
        if a[i] != 0:
            print('No')
            break
    else:
        print('Yes')
elif b == 2:
    x,y = B
    c = a.count(x)
    if x != 0 and y != 0:
        print('No')
    elif x == 0:
        if c == n:
            print('Yes')
        else:
            print('No')
    else:
        if c == 2*n:
            print('Yes')
        else:
            print('No')
else:
    x,y,z = B
    c = a.count(x)
    d = a.count(y)
    if not (c == d == n):
        print('No')
    else:
        if x ^ y == z:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def err():
    print('No')
    quit()
def ok():
    print('Yes')
    quit()

n = inp()
a = inpl()
a.sort()
c = Counter(a)
now = a[0]
for i in range(1,n):
    now ^= a[i]
if now: err()
if a[0] == a[-1] == 0: ok()
if n == 3:
    x,y,z = a
    if x == 0 and y == z: ok()
if n%3: err()
if len(c.keys()) == 3:
    for x in c.values():
        if x != n//3:
            err()
    x,y,z = c.keys()
    if x^y != z:
        err()
elif len(c.keys()) == 2:
    x,y = sorted(list(c.values()))
    if x != n//3 or y != n//3*2:
        err()
    x,y = sorted(list(c.keys()))
    if x != 0: err()
else: err()
ok()

Submission status: Accepted

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline

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

c = Counter(a)

if c[0] == n:
    print("Yes")
elif len(c) == 2 and c[0]*3 == n:
    print("Yes")
elif len(c) == 3 and len(set(c.values())) == 1:
    a, b, c = c.keys()
    if (a ^ b ^ c) == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a = list(map(int, input().split()))

if len(set(a)) == 1 and a[0] == 0:
    print('Yes')
elif N % 3 == 0:
    l = [*Counter(a).values()]
    res = 0
    for s in set(a):
        res ^= s
    if len(l) == 3 and res == 0 and len(set(l)) == 1:
        print('Yes')
    elif len(l) == 2 and a.count(0) == N//3:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

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')
    elif len(al_cnt_d) == 2:
        if 0 not in al_cnt_d or al_cnt_d[0] != n//3:
            print('No')
            exit()            
        else:
            print('Yes')
    else:
        print('No')


else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
if b.count(0)==n:
    print("Yes")
elif n%3==0:
    if b.count(0)==n//3 and b.count(b[n-1])==n-(n//3):
        print("Yes")
    elif b[0]^b[n//3]^b[n-1]==0 and b.count(b[0])==n//3 and b.count(b[n//3])==n//3 and b.count(b[n-1])==n//3:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

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 % 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
            elif len(D) == 2 and D.get(0, -1) != -1:
                v = D[0]
                if n - v == n * 2 // 3:
                    flg = True
    print("Yes" if flg else "No")


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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)

# 2種類の場合
if len(c) == 2:
    if c[0] == n // 3:
        print("Yes")
        sys.exit()
    else:
        print("No")
        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")

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
a = LI()

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

B = list(set(a))
b = len(B)
n = N//3
if b > 3:
    print('No')
elif b == 1:
    for i in range(N):
        if a[i] != 0:
            print('No')
            break
    else:
        print('Yes')
elif b == 2:
    x,y = B
    c = a.count(x)
    d = a.count(y)
    if x != 0 and y != 0:
        print('No')
    elif x == 0:
        if c == n:
            print('Yes')
        else:
            print('No')
    else:
        if d == n:
            print('Yes')
        else:
            print('No')
else:
    x,y,z = B
    c = a.count(x)
    d = a.count(y)
    if not (c == d == n):
        print('No')
    else:
        if x ^ y == z:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())

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


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

# 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: Accepted

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()
    else:
        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: Accepted

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

Submission status: Accepted

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[1][1] == N // 3 * 2 and tmp1[0][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: Accepted

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

if lis.count(0) == n:
    print('Yes')
elif n % 3 != 0:
    print('No')
elif len(set(lis)) == 2:
    if 0 in set(lis):
        if lis.count(0) == n/3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(set(lis)) == 3:
    xor = 0
    for  a in set(lis):
        if lis.count(a) == n/3:
            xor ^= a
        else:
            print('No')
            exit()
    if xor == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
d = Counter(list(map(int, input().split())))
if len(d) == 1:
    if d[0] == n:
        print("Yes")
        exit()
elif len(d) == 2:
    if n%3 == 0 and d[0] == n//3:
        print("Yes")
        exit()
elif len(d) == 3:
    k = list(d.keys())
    if n%3 == 0 and k[0] ^ k[1] ^ k[2] == 0 and d[k[0]] == d[k[1]] == d[k[2]]:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())
A_set = set(A)

if len(A_set) == 1:
    print("Yes") if sum(A) == 0 else print("No")
elif len(A_set) == 2:
    a1, a2 = sorted(A_set)
    print("Yes") if a1 == 0 and A.count(a1) * 3 == N else print("No")
elif len(A_set) == 3:
    a1, a2, a3 = list(A_set)
    if a1 ^ a2 ^ a3 == 0 and A.count(a1) == A.count(a2) == A.count(a3):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

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:
                    C = list(C.keys())
                    if C[0]^C[1]==C[2]:
                        print("Yes")
                    else:
                        print("No")
                else:
                    print("No")
    else:
        if len(C)==1 and 0 in C:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
li = list(map(int,input().split()))
se = set(li)
if len(se) == 1:
    if sum(se) == 0:
        print('Yes')
    else:
        print('No')
elif len(se) == 2:
    a,b = sorted(se)
    if a == 0:
        if li.count(a) * 3 == n:
            print('Yes') # 0 count is equal 1
        else:
            print('No')
    else:
        print('No')
elif len(se) == 3:
    a,b,c = se
    if li.count(a) == li.count(b) == li.count(c):
        if a^b == c:
            print('Yes')
        else:
            print('No') # a xor b xor c = 0 is ok
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
c0 = a.count(0)

ans = "No"
if c0==n: ans = "Yes"
elif len(set(a)) == 2:
    c = a.count(a[-1])
    if c == (2*n)//3 and c0 == n//3: ans = "Yes"
elif len(set(a)) == 3:
    x,y,z = list(set(a))
    if a.count(x) == a.count(y) == a.count(z):
        if int(bin(x ^ y ^ z),2) == 0: ans = "Yes"
print(ans)

Submission status: Accepted

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: Accepted

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 (len(d) == 1 and 0 in d) or (2 <= len(d) <= 3 and all(v%(N//3) == 0 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: Accepted

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):
        if vals[0] == 0 and  2*cnts[0] == cnts[1]:
            print("Yes")
        elif vals[1] == 0 and cnts[0] == 2*cnts[1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

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

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==0)

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

M=max(T,key=lambda x:T[x])
if 3*T[M]==N:
    x,y,z=list(T.keys())
elif 3*T[M]==2*N:
    x=y=M
    del T[M]
    z=tuple(T.keys())[0]
else:
    x=y=z=M

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
if N % 3 != 0:
    if any(a):
        print('No')
    else:
        print('Yes')
else:
    a.sort()
    a1 = set(a[:N//3])
    a2 = set(a[N//3:2*N//3])
    a3 = set(a[2*N//3:])
    if len(a1) == 1 and len(a2) == 1 and len(a3) == 1:
        if a1.pop()^a2.pop()^a3.pop() == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

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

a.sort()

if n % 3 != 0:
    if all((a[i] == 0 for i in range(n))):
        print('Yes')
    else:
        print('No')
else:
    a1 = a[:n//3]
    a2 = a[n//3:n*2//3]
    a3 = a[n*2//3:]
    if all((a1[i] == 0 for i in range(n//3))) and all((a2[i] == a2[0] for i in range(n//3))) and all((a3[i] == a3[0] for i in range(n//3))):
        print('Yes')
    elif all((a1[i] == a1[0] for i in range(n//3))) and all((a2[i] == a2[0] for i in range(n//3))) and all((a3[i] == a3[0] for i in range(n//3))) and a1[0] ^ a2[0] ^ a3[0] == 0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
# from numba import njit

# input = stdin.readline

# @njit
def solve(n,a):
  d = Counter(a)

  if d[0] == n:
    return True
  if n % 3 != 0:
    return False
  if len(d) == 2 and d[0] == n // 3:
    return True
  if len(d) == 3:
    if not all(v == n//3 for v in d.values()):
      return False
    x,y,z = d.keys()
    if x ^ y ^ z == 0:
      return True
  return False





def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print("Yes" if solve(N,a) else "No")
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=0
for i in a:
  b^=i
c=collections.Counter(a)
if len(c)>3:
  print('No')
elif len(c)==1:
  if a[0]==0:
    print('Yes')
  else:
    print('No')
elif b==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
if a.count(0) == n:
    print("Yes")
    exit()

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

c = Counter(a)
if len(c) == 2:
    if 0 not in c.keys():
        print("No")
        exit()
    if c[0] != n//3:
        print("No")
    else:
        print("Yes")
elif len(c) == 3:
    x = 0
    for i,j in c.items():
        if j != n//3:
            print("No")
            exit()
        x ^= i
    if x:
        print("No")
    else:
        print("Yes")

else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = list(set(a))
n = len(l)
if n == 3:
    if l[0] ^ l[1] ^ l[2] == 0:
        x = a.count(l[0])
        y = a.count(l[1])
        z = a.count(l[2])
        if x == y == z:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif n == 2:
    z = -1
    if l[0] == 0:
        x = 1
        z = 0
    if l[1] == 0:
        x = 0
        z = 1
    if z != -1:
        x = a.count(l[x])
        z = a.count(l[z])
        if x == z + z:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif n == 1:
    if l[0] == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = Counter(A)

try:
    if cnt[0] == N:
        print("Yes")
    else:
        if N % 3 != 0:
            print("No")
        else:
            if cnt.most_common(1)[0][1] == N*2//3 and cnt[0] == N//3:
                print("Yes")
            else:
                x = cnt.most_common(3)
                if x[0][1] == x[1][1] == x[2][1] == N//3:
                    if x[0][0]^x[1][0]^x[2][0] == 0:
                        print("Yes")
                    else:
                        print("No")
                else:
                    print("No")
except:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
def check():
  N = int(input())
  A = list(map(int, input().split()))
  if N%3 in [1,2]:
    if A!=[0]*N:
      return 'No'
    return 'Yes'
  c = Counter(A)
  if len(c)==1:
    if c[0]==0:
      return 'No'
    return 'Yes'
  if len(c)==2:
    if c[0]!=N//3:
      return 'No'
    return 'Yes'
  if len(c)==3:
    lis = []
    for k,v in c.items():
      if v!=N//3:
        return 'No'
      lis.append(k)
    if lis[0]^lis[1]==lis[2]:
      return 'Yes'
  return 'No'
print(check())

Submission status: Accepted

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

if a.count(0) == n:
    print('Yes')
elif n%3 != 0:
    print('No')
elif a.count(max(a)) == 2*n//3 and a.count(0) == n//3:
    print('Yes')
elif len(b) == 3 and b[0]^b[1]^b[2] == 0 and a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a_counter = Counter(a)
k = list(a_counter.keys())
v = list(a_counter.values())

if len(a_counter) == 3 and k[0]^k[1]^k[2] == 0 and v[0] == v[1] == v[2]:
    print("Yes")
elif len(a_counter) == 2 and 0 in k and (v[0] == v[1]*2 or v[1] == v[0]*2):
    print("Yes")
elif len(a_counter) == 1 and 0 in k:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a_counter = Counter(a)
a_counter_li = list(a_counter)
if sum(a) == 0:
    print("Yes")
elif len(a)%3 != 0:
    print("No")
elif len(a_counter) > 3 or len(a_counter) <= 1:
    print("No")
elif len(a_counter) == 3:
    if a_counter[a_counter_li[0]] == n // 3 and a_counter[a_counter_li[1]] == n // 3 and a_counter[a_counter_li[2]] == n // 3:
        if a_counter_li[0]^a_counter_li[1]^a_counter_li[2] == 0:
            print("Yes")
        else:
            print('No')
    else:
        print("No")
else:
    a_counter_li.sort()
    if a_counter_li[0] == 0 and a_counter[a_counter_li[0]] == n // 3:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import collections

N = int(input())
a = list(map(int, input().split()))

B = collections.Counter(a)
k = list(B.keys())
v = list(B.values())

if len(B) == 3 and k[0]^k[1]^k[2] == 0 and v[0] == v[1] == v[2]:
    print("Yes")
elif len(B) == 2 and 0 in k and (v[0] == 2*v[1] or v[1] == 2*v[0]):
    print("Yes")
elif len(B) == 1 and 0 in k:
    print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
max_a = max(a)
if max_a == 0:
    print('Yes')
    exit()

if N % 3 != 0:
    print('No')
    exit()

if a.count(max_a) == 2 * N // 3 and a.count(0) == N // 3:
    print('Yes')
    exit()

set_a = list(set(a))
if len(set_a) == 3 and set_a[0] ^ set_a[1] ^ set_a[2] == 0:
    if a.count(set_a[0]) == a.count(set_a[1]) == a.count(set_a[2]):
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(map(int,input().split()))
B = collections.Counter(a)
k = list(B.keys())
v = list(B.values())

if len(B) == 3 and k[0]^k[1]^k[2] == 0 and v[0] == v[1] == v[2]:
    print("Yes")
elif len(B) == 2 and 0 in k and (v[0] == 2*v[1] or v[1] == 2*v[0]):
    print("Yes")
elif len(B) == 1 and 0 in k:
    print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1 and a[0] == 0:
    print("Yes")
    exit()
if N%3 != 0:
    print("No")
    exit()

import collections
sa = list(set(a))
sa.sort()
B = collections.Counter(a)

if len(sa) == 2 and 0 in sa:
    if B[0] == N//3 and B[sa[1]] == N*2//3:
        print("Yes")
    else: print("No")
    exit()
if len(sa) != 3:
    print("No")
    exit()

if B[sa[0]] == B[sa[1]] == B[sa[2]]:
    print("Yes" if sa[0] ^ sa[1] == sa[2] else "No")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

d = dict()
for i in range(N):
    d[A[i]] = d.get(A[i], 0) + 1

if len(d) > 3:
    print('No')

else:
    k = list(d.keys())
    v = list(d.values())
    
    # a1 ^ a2 ^ a3 = 0 and an: N/3
    if len(d) == 3 and k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2]:
        print('Yes')
    
    # a1: 2N/3, 0: N/3
    elif len(d) == 2 and ((k[0] == 0 and v[1] == 2*v[0]) or (k[1] == 0 and v[0] == 2*v[1])):
        print('Yes')
    
    # 0: N
    elif len(d) == 1 and k[0] == 0:
        print('Yes')
    
    else:
        print('No')