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

for i in range(N):
    b ^= A[i]

print("Yes" if b == 0 else "No")

Submission status: Accepted

Solution code:
_, *a = map(int, open(0).read().split());z = 0
for b in a:z ^= b
print("YNeos"[z>0::2])

Submission status: Accepted

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

print("Yes" if b == 0 else "No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
A = sorted(set(a))
if len(A) == 1 and A[0] == 0:
    print('Yes')
else:
    if n % 3 == 0:
        if len(A) == 2 and A[0] == 0 and a.count(A[0]) * 2 == a.count(A[1]):
            print('Yes')
        elif len(A) == 3 and bin(A[0]^A[1]) == bin(A[2]) and a.count(A[0]) == a.count(A[1]) == a.count(A[2]):
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

Solution code:
n = int(input())
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')
        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')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce
from operator import xor
n = int(input())
a = Counter(map(int , input().split()))

if n % 3 == 0:
    if len(a) == 3:
        if 0 == reduce(xor, a) and all(v == n // 3 for v in a.values()):
            print("Yes")
        else:
            print("No")
    elif len(a) == 2:
        if 0 in a and a[0] == n // 3:
            print("Yes")
        else:
            print("No")
    else:
        if 0 in a:
            print("Yes")
        else:
            print("No")
else:
    if len(a) == 1 and 0 in a:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = input()
a_list = [int(_c) for _c in input().split(" ")]

xor = 0
for a in a_list:
    xor = xor ^ a

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

Submission status: Accepted

Solution code:
def count(l):
    res = {}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res

n = float(input())
data = list(map(int, input().split()))
t = count(data)
if len(t) == 3:
    ks = list(t.keys())
    if 0 not in t and all(i == n/3 for i in t.values()) and ks[0]^ks[1] == ks[2]:
        print('Yes')
    else:
        print('No')

elif len(t) == 2:
    if 0 in t and t[0] == n/3:
        print('Yes')
    else:
        print('No')

elif len(t) == 1:
    if 0 in t:
        print('Yes')
    else:
        print('No')

else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
from collections import deque,defaultdict,Counter

def main():
    N = int(input())
    A = list(map(int,input().split()))
    if N%3 == 0:
        C = Counter(A)
        flag = True
        if len(C) > 3:
            flag = False
        elif len(C) == 3:
            a,b,c = tuple(C.keys())
            for _ in range(3):
                if a^b == c:
                    a,b,c = b,c,a
                else:
                    flag = False
                    break
            if not all(v*3 == N for v in C.values()):
                flag = False
        elif len(C) == 2:
            a,b = tuple(C.keys())
            if a*b == 0:
                if C[0]*3 == N:
                    pass
                else:
                    flag = False
            else:
                flag = False
        else:
            if 0 not in C:
                flag = False
        print('Yes' if flag else 'No')
    else:
        if set(A) == {0}:
            print('Yes')
        else:
            print('No')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
al = list(map(int,input().split()))
bit = [0]*35

for i in range(N):
  for j in range(35):
    if (al[i]>>j)&1 == 1:
      bit[j] += 1
      
for j in range(35):
  if bit[j] %2 == 1:
    print("No")
    exit()
    
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
for i in l:
    count^=i
flag=True
for j in l:
    if j!=j^count:
        flag=False
        break
if flag==True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict

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

if len(set(a)) == 1 and list(set(a))[0] == 0:
    print('Yes')
    exit()

if n % 3 == 0 and len(set(a)) == 3:
    x = list(set(a))
    e = x[0]
    b = x[1]
    c = x[2]
    if e ^ b != c:
        print('No')
        exit()
    if b ^ c != e:
        print('No')
        exit()
    if c ^ e != b:
        print('No')
        exit()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    if d[e] != d[b] or d[b] != d[c] or d[c] != d[e]:
        print('No')
        exit()
    print('Yes')
elif n % 3 == 0 and len(set(a)) == 2:
    x = list(set(a))
    x.sort()
    if x[0] == 0:
        t = 1
    else:
        print('No')
        exit()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    if d[x[0]]*2 == d[x[1]]:
        print('Yes')
        exit()
    print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = Counter(LI())
    ok = True
    if(N%3==0):
        B = []
        for a,c in A.items():
            if(c%(N//3)!=0):
                print("No")
                return 
                break
            for _ in range(c//(N//3)):
                B.append(a)
        if((B[0]^B[1]^B[2]) != 0):
            ok = False
    else:
        ok = len(A)==1
        
    if(ok):
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
s = set(a)
c = Counter(a)

if n%3 != 0:
  if s == {0}:
    print('Yes')
  else:
    print('No')
else:
  if len(c) > 3:
      print('No')
  elif len(c) == 3:
    a,b,q = list(s)
    if a^b == q and c[a] == n//3 and c[b] == c[q]:
      print('Yes')
    else:
      print('No')
  elif len(c) == 2:
    if not 0 in s:
      print('No')
    else:
      if c[0] == n//3:
        print('Yes')
      else:
        print('No')
  elif len(c) == 1:
    if s == {0}:
      print('Yes')
    else:
      print('No')

Submission status: Accepted

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

from functools import reduce
from operator import xor
ans = reduce(xor, A)

if ans == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

if 1:
    tmp=0
    for item in a:
        tmp=tmp^item
    if tmp==0:
        print("Yes")
    else:
        print("No")
else:
    tmp=0
    for item in a:
        tmp=tmp^item
    if tmp==2**len(str(bin(max(a))[2:]))-1:
        print(tmp)
        print("Yes")
    else:
        print("No")



#001 (1)
#010 (2)
#011 (3)
#001 (1)
#010 (2)
#011 (3)

#010 (2)
#011 (3)
#001 (1)

#011 (3)
#001 (1)
#010 (2)

Submission status: Accepted

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


As = set(A)

if len(As) == 3:
    k = 0
    x, y, z = As
    if x^y != z and x^z != y and y^z != x:
        print('No')
        k = 1
    n = N // 3
    if k == 0:
        for i in [x, y, z]:
            if A.count(i) != n and A.count(i) != n+1:
                k = 1
                print('No')
                break
        if k == 0:
            print('Yes')
elif len(As) == 2:
    k = 0
    if 0 in As:
        if A.count(0) == 2:
            pass
        elif A.count(0) == N//3 or A.count(0) == N//3 + 1:
            k = 1
            print('Yes')
    if k == 0:
        print('No')
elif len(As) == 1:
    if 0 in As:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
# n 枚の帽子を持っている。i番目の帽子には番号ai
# n 頭のラクダが輪っかになっててそこに帽子をかぶせる
# 3 ^ 5 = 011 ^ 101 = 110

n = int(input())
A = list(map(int, input().split()))
num = 0
for a in A:
    num = num ^ a

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
S = set(A)
if len(S) == 1:
    if 0 in S:
        print("Yes")
    else:
        print("No")
elif len(S) == 2:
    K = Counter(A)
    if 0 in K and K[0] == n//3:
        print("Yes")
    else:
        print("No")
elif len(S) == 3:
    K = Counter(A)
    ans = []
    for i,j in K.items():
        ans.append([i,j])
    if ans[0][1] == ans[1][1] and ans[1][1] == ans[2][1] and ans[0][0]^ans[1][0]^ans[2][0] == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
ans=a[0]
for i in range(1,n):
  ans^=a[i]
print('Yes' if ans==0 else 'No')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    A.sort()
    # First cond: all 0
    if A[-1] == 0:
        print('Yes')
        return
    # Second cond: N//3 -> 0, 2N//3 -> x
    if N % 3 == 0:
        if A[(2*N//3)-1] == 0 and A[-(N//3)] == A[-1]:
            print('Yes')
            return
    # Third cond: N//3 -> x, N//3 -> y, N//z -> 0 s.t. x^y^z=0
    if N % 3 == 0:
        if A[0] == A[(N//3)-1] and A[N//3] == A[(2*N//3)-1] and A[2*N//3] == A[N-1] \
                and A[0] ^ A[N//3] ^ A[2*N//3] == 0:
            print('Yes')
            return
    print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

def make_xor_sum(A):
    output = A[0]
    for i in range(1,len(A)):
        output = output ^ A[i]

    if output == 0:
        return True
    else:
        return False

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

    if make_xor_sum(a):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
if len(c) == 3:
    l = list(c.keys())
    v = list(c.values())
    if l[0]^l[1]^l[2] == 0 and v[0]==v[1]==v[2]:
        print("Yes")
    else:
        print("No")
elif len(c) == 1:
    if list(c.keys())[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(c) == 2:
    if (0 not in a):
        print("No")
    else:
        v = c[0]
        if len(a) == c[0]*3:
            print("Yes")
        else:
            print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
from itertools import permutations
N = int(input())
A = list(map(int, input().split()))

# 1 ^ 2 ^ 3 ^ 4 ^ 4 などが0になる順番は関係ない
# 各桁のビットが偶数になるかカウントする
D = [0] * 30
for a in A:
    bit = bin(a)[2:][::-1]
    for i in range(len(bit)):
        D[i] += int(bit[i])
# print('D', D)

ans = 'Yes' if all([d % 2 == 0 for d in D]) else 'No'
print(ans)

Submission status: Accepted

Solution code:
# A - XOR Circle

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

if a[N-1]==0:
    ans = 'Yes'
elif N%3!=0:
    ans = 'No'
elif a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[N-1] and a[0]^a[N//3]^a[2*N//3]==0:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

sa = set(a)
sa = list(sa)

if len(sa)>3:
    print('No')
    exit()

if len(sa)==3:
    aa = sa[0]
    bb = sa[1]
    cc = sa[2]
    if a.count(aa) != n/3 or a.count(bb) != n/3 or a.count(cc) != n/3:
        print('No')
        exit()
    if aa^bb^cc!=0:
        print('No')
        exit()

if len(sa)==2:
    aa = sa[0]
    bb = sa[1]
    if bb != 0 and aa != 0:
        print('No')
        exit()
    else:
        if aa==0:
            aa = bb
    if a.count(0) != n/3 or a.count(aa)!=n/3*2:
        print('No')
        exit()

if len(sa)==1:
    aa = sa[0]
    if aa != 0:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
from collections import deque,Counter

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

cnt = Counter(lisA)

if len(cnt)>3:
    print("No")
    exit()

if len(cnt) == 1:
    if lisA[0] == 0:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
elif len(cnt) == 2:
    if not 0 in cnt:
        print("No")
        exit()
    else:
        keys = sorted(list(cnt.keys()))
        another = keys[-1]
        if cnt[0]*2 == cnt[another]:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
else:
    keys = sorted(list(cnt.keys()))
    if keys[0]^keys[1]^keys[2] != 0:
        print("No")
        exit()
    else:
        if cnt[keys[0]]==cnt[keys[1]]==cnt[keys[2]]:
            print("Yes")
            exit()
        else:
            print("No")
            exit()

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

if len(c) > 3:
    print("No")
    exit()
elif len(c) == 3:
    if n % 3 != 0:
        print("No")
        exit()
    p = []
    for k , v in c.items():
        if v != n//3:
            print("No")
            exit()
        p.append(k)
    if (p[0] ^ p[1]) ^ p[2] != 0:
        print("No")
        exit()
elif len(c) == 2:
    if n % 3 != 0:
        print("No")
        exit()
    for k,v in c.items():
        if k == 0:
            if v != n//3:
                print("No")
                exit()
        else:
            if v != 2*n//3:
                print("No")
                exit()
elif len(c) == 1:
    for k in c.keys():
        if k != 0:
            print("No")
            exit()
            
print("Yes")

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    for i in range(N):
        if i==0:
            a = A[i]
        else:
            a = a^A[i]
    if a == 0:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()

Submission status: Accepted

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

count=A[0]
i=1
while i<N:
    count=count^A[i]
    i+=1

if count==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
alist = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans = ans ^ alist[i]
if ans == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
di = {}
for i in a:
    if i in di:
        di[i] += 1
    else:
        di[i] = 1
k = list(di.keys())
v = list(di.values())
if n%3!=0 and len(di)>1:
    print('No')
elif len(di)==3 and v[0]==v[1]==v[2] and k[0]^k[1]^k[2]==0:
    print('Yes')
elif len(di)==2 and ((v[0]<v[1] and v[0]==n//3 and k[0]==0) or (v[0]>v[1] and v[1]==n//3 and k[1]==0)):
    print('Yes')
elif len(di)==1 and k[0]==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
if not n % 3 == 0:
    if a[n - 1] == 0:
        print("Yes")
    else:
        print("No")
else:
    x, y, z = a.count(a[0]), a.count(a[n // 3]), a.count(a[2 * (n // 3)])
    if x == y == z == n // 3:
        if a[0] ^ a[n // 3] ^ a[2 * (n // 3)] == 0:
            print("Yes")
        else:
            print("No")
    elif a[0] == 0 and x == n // 3 and y == z == 2 * (n // 3):
        print("Yes")
    elif a[n - 1] == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

from collections import Counter

c = Counter(a)

if c[0] > 0:
    if len(c) == 1:
        bl = True
    else:
        if len(c) > 2:
            bl = False
        else:
            bl = (n == 3 * c[0])
else:
    se = set(c.keys())
    if len(se) != 3:
        bl = False
    else:
        bl = True
        xor = 0
        for key in se:
            xor ^= key
            if c[key] * 3 != n:
                bl = False
        if xor != 0:
            bl = False

print('Yes') if bl else print('No')

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
cnt = arr.count(0)
if cnt == N:
    print('Yes')
    exit()
if N % 3 != 0:
    print('No')
    exit()
if cnt == N//3 and len(set(arr)) == 2:
    print('Yes')
    exit()
from collections import defaultdict
d = defaultdict(int)
for i in arr:
    d[i] += 1
if len(d) != 3:
    print('No')
    exit()
check = []
for key in d.keys():
    check.append(key)
if d[check[0]] == d[check[1]] and d[check[1]] == d[check[2]] and d[check[2]] == d[check[0]] and check[0]^check[1]^check[2] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    # p1
    if sum(a) == 0:
        print("Yes")
        exit(0)

    # p2
    c = collections.Counter(a)
    if n % 3 == 0:
        if 0 in c.keys() and len(c) == 2:
            if n // 3 == c[0]:
                print("Yes")
                exit(0)

    # p3

    t_key=[]
    t_value=[]
    if len(c) == 3:
        for k,v in c.items():
            t_key.append(k)
            t_value.append(v)
    else:
        print("No")
        exit(0)


    if t_key[0] ^ t_key[1] ^ t_key[2] == 0 and t_value[0]==t_value[1]==t_value[2]==n//3:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = Counter(list(map(int, input().split())))
b = set(a.values())
if a[0] == N:
    print('Yes')
elif N % 3 == 0:
    if len(b) == 1:
        c = [x for x in a.keys()]
        if len(c) == 3:
            if c[0] ^ c[1] ^ c[2] == 0:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    elif len(b) == 2:
        if a[0] == N // 3:
            if (N*2) // 3 in b:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

check = set(a)
coll = Counter(a)

if check == {0}:
    print("Yes")
elif len(check) == 3:
    if list(check)[0] ^ list(check)[1] ^ list(check)[2] == 0:
        if coll[list(check)[0]] == coll[list(check)[1]] == coll[list(check)[2]]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(list(check)) == 2:
    if list(check)[0] == 0:
        if coll[list(check)[0]] * 3 == n:
            print("Yes")
        else:
            print("No")
    elif list(check)[1] == 0:
        if coll[list(check)[0]] * 3 == n:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
if sum(a)==0:
    print('Yes')
    exit()
x=[0]*3
x[0] = a.count(a[0])
x[1] = a.count(a[n//2])
x[2] = a.count(a[-1])
x.sort()

if a[0]^a[n//2] == a[-1] and x[0] == x[1] == x[2] == n//3:
    print('Yes')
elif a[0] == 0 and x[0] == n//3 and x[1] == x[2] == n*2//3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
def judge(vals):
    return vals[0] ^ vals[1] ^ vals[2] == 0
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = "No"
    c = Counter(A)
    con1 = len(c) == 2 and c[0] * 3 == N
    items = list(c.items())
    con2 = len(c) == 3 and items[0][1] * 3 == N and items[1][1] * 3 == N and judge(list(c.keys()))
    con3 = c[0] == N
    if con1 or con2 or con3:ans = "Yes"
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(_) for _ in input().split()]
    xor = 0
    for a in A:
        xor ^= a
    print('No' if xor else 'Yes')
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int,input().split()))
a.sort()
d = {}
for i in range(n):
    if(a[i] not in d):d[a[i]] = 1
    else:d[a[i]] += 1
if(len(d) == 1):
    if(a[0] == 0):
        print('Yes')
        exit()
elif(n%3 == 0):
    if(len(d) == 2):
        if(0 in d):
            if(d[0] == n // 3):
                print('Yes')
                exit()
    elif(len(d) == 3):
        k = list(d.keys())
        if(k[0]^k[1]^k[2] == 0):
            if(d[k[0]] == n // 3 and d[k[1]] == n // 3 and d[k[2]] == n // 3):
                print('Yes')
                exit()
print('No')

Submission status: Accepted

Solution code:
#AGC035-A XOR Circle
"""
問題：
円環状にリストの数値を配置した時、aのどの要素についても
ai == a(i-1)^a(i+1)
となるように配置できるか判定せよ
解法：
できるかどうかを判定すればよいので実際に組み立てる必要はない。
n<=10**5であることから、選び方を考えなくて良い解法が存在するはず
全てのXORの合計が0?
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))

ans = 0
for i in lst1:
    ans = ans^i

print("Yes" if ans == 0 else "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:
N = int(input())
A = list(map(int, input().split()))

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    if N%3 == 0:
        x,y,z = dic.keys()
        if li[0]== N//3 and li[1]==N//3 and x^y== z:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N//3 or li[1]==2*N//3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Submission status: Accepted

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    if N%3 == 0:
        x,y,z = dic.keys()
        if li[0]== N//3 and li[1]==N//3 and x^y^z == 0:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N//3 or li[1]==2*N//3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = Counter(a)
    if len(l)==1 and 0 in l:
        print('Yes')
        exit()
    if N%3==0 and len(l)==2 and 0 in l and l[0] == N//3:
        print('Yes')
        exit()
    if N%3==0 and len(l)==3:
        x,y,z = l.keys()
        if l[x] == l[y] == N//3 and x^y^z == 0:
            print('Yes')
            exit()
    print('No')

    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
import collections
a_frq_dict = collections.Counter(map(int, input().split(' ')))

n = len(a_frq_dict)

if n == 1:
    if a_frq_dict[0]:
        print('Yes')
        exit()

elif n == 2:
    if N % 3 == 0 and a_frq_dict[0] == (N//3):
        print('Yes')
        exit()

elif n == 3:
    if N % 3 == 0:
        if all([f == (N//3) for f in a_frq_dict.values()]):
            values = list(a_frq_dict.keys())
            v = values[0] ^ values[1] ^ values[2]
            if v == 0:
                print('Yes')
                exit()

print('No')

Submission status: Accepted

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

c = Counter(A)
n = len(c)
if ((n == 1 and c[0] > 0)
        or (n == 2 and c[0] == N//3)):
    print('Yes')
elif n == 3:
    x, y, z = c.keys()
    if x ^ y ^ z == 0 and all(n == N // 3 for n in c.values()):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = Counter(a)
    if len(l)==1 and 0 in l:
        print('Yes')
        exit()
    if N%3==0 and len(l)==2 and 0 in l and l[0] == N//3:
        print('Yes')
        exit()
    if N%3==0 and len(l)==3:
        x,y,z = l.keys()
        if l[x] == l[y] == N//3 and x^y^z == 0:
            print('Yes')
            exit()
    print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

A = list(map(int,input().split()))
from collections import Counter

for a in A:
  if a != 0:
    break
else:
  print('Yes')
  exit()

A = list(Counter(A).most_common())

if len(A) == 2 and A[1][0]==0 and A[1][1] == n//3:
  print('Yes')
  exit()

B = []
for a,c in A:
  if c != n//3:
    print('No')
    exit()
  B.append(a)
n = len(str(max(B)))
  
B = [[(1<<j&i)>>j for j in range(30)] for i in B]
for i in range(30):
  if B[0][i]^B[1][i]^B[2][i] != 0:
    print('No')
    break
else:
  print('Yes')

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'
if len(set(a))==2:
    c = a.count(a[-1])
    if c==n*2/3 and c0==n/3:
        ans = 'Yes'
if len(set(a))==3:
    s = 0
    f = True
    for i in set(a):
        s ^= i
        if a.count(i)!=n/3:
            f = False
    if f and s==0:ans='Yes'
print(ans)