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:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n=int(input())
    a = list(map(int,input().split())) 
    if a==[0 for _ in range(n)]:
        print("Yes")
        exit()
    if n%3!=0:
        print("No")
        exit()
    else:
        a.sort()
        x=a[0]
        z=a[n-1]
        if n%2==0:
            y=a[n//2]
        else:
            y=a[((n+1)//2)-1]
        x0=y0=z0=0
        for i in range(n):
            if a[i]==x:
                x0+=1
            if a[i]==y:
                y0+=1
            if a[i]==z:
                z0+=1
        if x==0 and x0==n//3 and y==z:
            print("Yes")
            exit()
        if x0!=n//3 or y0!=n//3 or z0!=n//3:
            print("No")
            exit()
        cnt={}
        index=0
        while x != 0:
            if x//2>0:
                if x%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                x=x//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                x=0
        index=0
        while y != 0:
            if y//2>0:
                if y%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                y=y//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                y=0
        index=0
        while z != 0:
            if z//2>0:
                if z%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                z=z//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                z=0
        for i in cnt:
            if cnt[i]%2==1:
                print("No")
                exit()
        print("Yes")

main()

Submission status: Accepted

Solution code:
from collections import Counter

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

ak = list(a.keys())
av = list(a.values())

if N % 3 != 0:
    if a[0] == N:
        print('Yes')
    else:
        print('No')
elif len(ak) == 3:
    if ak[0] ^ ak[1] ^ ak[2] == 0 and av[0] == av[1] == av[2]:
        print('Yes')
    else:
        print('No')
elif len(ak) == 2:
    if 0 in ak:
        if a[0] == N // 3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(ak) == 1:
    if 0 in ak:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

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

if len(A)==1:
  if 0 in A:
    print("Yes")
  else:
    print("No")
elif len(A)==2:
  if A[0]==N/3:
    print("Yes")
  else:
    print("No")
elif len(A)==3:
  if list(A.values())==[N/3]*3 and list(A.keys())[0]^list(A.keys())[1]^list(A.keys())[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Accepted

Solution code:
cnt = [0 for i in range(31)]

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

for num in lis:
  s = format(num,'b').zfill(31)
  for i in range(31):
    cnt[i] += int(s[i])

if n % 3 == 0:
  for nu in cnt:
    if nu != 0 and nu * 3 != n * 2:
      print("No")
      exit()
  print("Yes")
else:
  for nu in cnt:
    if nu != 0:
      print("No")
      exit()
  print("Yes")

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

s = 0

for i in range(n):
    s ^= a[i]
if s == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input().split()[0])
a_list = list(map(int, input().split()))

counter = collections.Counter(a_list)

# 4種類以上だと、どうしようもない
is_ok = True
if len(counter) > 4:
    is_ok = False
elif len(counter) == 3:
    v_list = list(counter.values())
    if len(set(v_list)) != 1:
        # 全部同じ数ではない
        is_ok = False

    if is_ok:
        k_list = list(counter.keys())
        if k_list[0] ^ k_list[1] != k_list[2]:
            is_ok = False
elif len(counter) == 2:
    v_list = list(counter.values())
    if min(v_list) * 2 == max(v_list):
        a = [k for k, v in counter.items() if v == max(v_list)][0]
        b = [k for k, v in counter.items() if v == min(v_list)][0]
        if a ^ a != b:
            is_ok = False
    else:
        is_ok = False
else:
    for k in counter.keys():
        if k != 0:
            is_ok = False
            break

ans = "Yes" if is_ok else "No"

print(ans)

Submission status: Accepted

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

a.sort()

if a[-1]==0:
    f=True
elif N%3!=0:
    f=False
elif a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[-1] and a[0]^a[N//3]==a[-1]:
    f=True
else:
    f=False

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

Submission status: Accepted

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

def a():
    if n%3 > 0:
        if len(list(set(A))) == 1:
            return "Yes"
    else:
        B = list(set(A))
        if len(B) <= 3:
            c = 0
            t = 0
            for i in B:
                cou = A.count(i)
                # print("cou",cou)
                if cou % (n//3) == 0:
                    c += 1
                    for j in range(cou // (n//3)):
                        # print(t,i)
                        t ^= i
                # print(t)
            if c == len(B) and t == 0:
                return "Yes"
    return "No"

print(a())

Submission status: Accepted

Solution code:
from collections import Counter

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

A = Counter(A)
V = Counter(A.values())

if list(A.keys())==[0]:
    print('Yes')

elif len(A)==2:
    p,q = A.keys()
    if min(p,q)==0 and A[0]*2==A[max(p,q)]:
        print('Yes')
    else:
        print('No')

elif len(A)==3 and len(V)==1:
    p,q,r = A.keys()
    if p^q^r == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

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

c = list(set(a))
c.sort()
if len(c) > 3:
    print('No')
    exit()

if len(c) == 1:
    if c[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(c) == 2:
    if c[0] == 0 and a.count(0) * 2 == a.count(c[1]):
        print('Yes')
    else:
        print('No')
else:
    if c[0] ^ c[1] == c[2] and a.count(c[0]) == a.count(c[1]) and a.count(c[1]) == a.count(c[2]):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
from collections import Counter


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

    cnt_a = Counter(lst_a)

    if len(cnt_a) > 3:
        print("No")
        exit()
    
    if len(cnt_a) == 1:
        print("Yes" if lst_a[0] == 0 else "No")
        exit()
    
    if N % 3:
        print("No")
        exit()
    
    if len(cnt_a) == 2:
        if cnt_a[0] != N//3:
            print("No")
        else:
            print("Yes")
    else:
        if any(v != N//3 for v in cnt_a.values()):
            print("No")
        else:
            x, y, z = list(cnt_a)
            print("Yes" if x ^ y ^ z == 0 else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
p=[]
cnt=[]
zero=0
for i in range(n):
	if len(p)>=4:
		print("No")
		exit()
	if a[i]==0:
		zero+=1
	elif a[i] not in p:
		p.append(a[i])
		cnt.append(1)
	else:
		for j in range(len(p)):
			if a[i]==p[j]:
				cnt[j]+=1
if n%3!=0 and zero!=n:
	print("No")
	exit()
if len(p)>=4:
	print("No")
	exit()
if len(p)==3:
	if cnt[0]==cnt[1]==cnt[2]==n/3:
		if p[0]^p[1]^p[2]==0:
			print("Yes")
			exit()
	else:
		print("No")
		exit()
elif len(p)==1:
	if cnt[0]==n/3*2:
		print("Yes")
		exit()
elif len(p)==0:
	if sum(a)==0:
		print("Yes")
		exit()
print("No")

Submission status: Accepted

Solution code:
import collections
import itertools

n = int(input())
ls = list(map(int, input().split()))
counter = collections.Counter()
for x in ls:
    counter[x] += 1
if len(counter.keys()) > 3:
    print('No')
else:
    for a, b in itertools.combinations_with_replacement(counter.keys(), 2):
        if a == b and counter[a] == 1:
            continue
        counter2 = collections.Counter()
        x = a
        counter2[a] += 1
        counter2[b] += 1
        for _ in range(n - 2):
            a, b = b, a ^ b
            counter2[b] += 1
            if counter2[b] > counter[b]:
                break
        else:
            if a ^ b != x:
                continue
            else:
                print('Yes')
                break
    else:
        print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
b = list(set(a))
flag = False
if len(b) == 3:
    if b[0]^b[1] == b[2] and N % 3 == 0 and a.count(b[0]) == a.count(b[1]) and a.count(b[1]) == a.count(b[2]):
        flag = True
elif len(b) == 2:
    if b[0]^b[0] == b[1]:
        if N % 3 == 0 and a.count(b[0]) == a.count(b[1]) * 2:
            flag = True
    if b[1]^b[1] == b[0]:
        if N % 3 == 0 and a.count(b[1]) == a.count(b[0]) * 2:
            flag = True
elif len(b) == 1:
    if b[0] == 0:
        flag = True
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

mc = Counter(a).most_common()
ln = len(mc)

def detect():
    if ln == 1 and mc[0][0] == 0:
        return True
    elif ln == 2 and mc[1][0] == 0 and mc[1][1] == n // 3:
        return True
    elif ln == 3 and mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0 and mc[0][1] == mc[1][1] == mc[2][1]:
        return True
    return False

print("Yes" if detect() else "No")

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
n = int(input())
a = [int(i) for i in input().split()]
if sum(a):
    if n%3: f = 0
    else:
        d,x = dd(int),[]
        for i in a: d[i]+=1
        for i in d.keys(): x.append(i)
        if len(d)==2 and d[0]==n//3: f = 1
        elif len(d)==3 and x[0]^x[1]^x[2]==0 and d[x[0]]==d[x[1]]==d[x[2]]: f = 1
        else: f = 0
else: f = 1
if f: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
def solve(A):
  count = {}
  for x in A:
    if x not in count:
      count[x] = 0
    count[x] += 1
  if 0 in count and count[0] == N: return True
  if len(A) % 3 != 0: return False    
  xs = []
  for k, v in count.items():
    if v % (N//3) != 0: return False
    for _ in range(v // (N//3)):
      xs.append(k)
  return (xs[0] == xs[1] ^ xs[2]) or (xs[1] == xs[2] ^ xs[0]) or (xs[2] == xs[0] ^ xs[1])

print('Yes' if solve(A) else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = 0
if n % 3 != 0:
    for i in range(0, n - 1):
        if a[i] == a[i + 1]:
            flag += 1
        else:
            break
    if flag == n - 1:
        print("Yes")
    else:
        print("No")
else:
    n3 = n // 3

    if a[0] ^ a[n3 * 2] != a[n3]:
        print("No")
    else:
        for i in range(0, n - 1):
            if i == n3 - 1 or i == n3 * 2 - 1:
                continue
            if a[i] == a[i + 1]:
                flag += 1
            else:
                break
        if flag == n - 3:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

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


def solve(x):
    if (x == 0).all():
        return "Yes"
    if len(x) % 3:
        return "No"
    x.sort()
    idx = len(x)//3
    if (x[:idx] == 0).all() and (x[idx:] == x[-1]).all():
        return "Yes"
    if x[0] ^ x[idx] ^ x[2*idx] == 0 and (x[:idx] == x[0]).all() and (x[idx:2*idx] == x[idx]).all() and (x[2*idx:] == x[2*idx]).all():
        return "Yes"
    return "No"


a = np.array(a)
ans = solve(a)
print(ans)

Submission status: Accepted

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

d = defaultdict(int)
for i in range(n):
    d[a[i]] += 1

k = list(d.keys())
v = list(d.values())

if len(k) == 1 and k[0] == 0:
    ans = "Yes"
elif n % 3 != 0:
    ans = "No"
elif len(k) == 2 and 0 in d and d[0] == n // 3:
    ans = "Yes"
elif len(k) == 3 and v[0] == v[1] == v[2] and k[0] ^ k[1] ^ k[2] == 0:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Accepted

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

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

if 0 in c and c[0] == N:
    print('Yes')
elif len(c) == 2 and 0 in c and c[0] == N/3:
    print('Yes')
elif len(c) == 3 and v[0]==v[1]==v[2] and k[0]^k[1]^k[2] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import collections

N=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)
cv=list(c.values())
ck=list(c.keys())
if len(cv) == 3 and cv[0] == cv[1] and cv[1] == cv[2] and ck[0]==ck[1]^ck[2]:
    print("Yes")
elif len(cv) == 2 and ((cv[0] == cv[1]*2 and ck[1]==0) or (cv[1] == cv[0]*2 and ck[0]==0)):
    print("Yes")
elif len(cv) == 1 and ck[0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
if (len(c) == 1 and c[0] == n) or (len(c) == 2 and c[0] == n//3 and c[max(c.keys())] == 2*n//3) or (len(c) == 3 and reduce(lambda x, y: x^y, c.keys()) == 0 and set(c.values()) == set([n//3])):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
dic = {}

for i in range(N):
    if a[i] not in dic:
        dic[a[i]] = 1
    else:
        dic[a[i]] += 1

values = list(dic.values())
keys = list(dic.keys())

if len(dic.keys()) == 3 and values[0] == values[1] == values[2] and keys[0] ^ keys[1] ^ keys[2] == 0:
    print('Yes')
elif len(dic.keys()) == 2 and 0 in dic and dic[0] * 3 == N:
    print('Yes')
elif len(dic.keys()) == 1 and 0 in dic:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
B = list(set(A))
if len(B) >= 4:
  print('No')
else:
  if B[-1] == 0:
    print('Yes')
  elif A.count(0) == n/3 and len(B) == 2:
    print('Yes')
  elif len(B) == 3 and B[0]^B[1]^B[2] == 0 and A.count(B[0]) == A.count(B[1]) == n/3:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

A_sorted = sorted(A)
A_set = list(set(A))
A_cnt = dict()
for a in A:
    if not a in A_cnt.keys():
        A_cnt[a] = 1
    else:
        A_cnt[a] += 1

if A_cnt.get(0) == N:
    print("Yes")
    exit()

if len(A_set) > 3 or len(A_set) == 1 or N%3 != 0:
    print("No")
    exit()

B = []
B.append(A_set[0])
B.append(A_set[1])
for _ in range(N-2):
    B.append(B[-1] ^ B[-2])

B_sorted = sorted(B)
if A_sorted == B_sorted:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict
def solve(n,A):
    S=set(A)
    l=len(S)
    if S=={0}:
        return 'Yes'
    if n%3 or l==1 or l>3:
        return 'No'
    d=defaultdict(int)
    for a in A:
        d[a]+=1
    if l==2:
        return 'Yes' if d[0]==n//3 else 'No'
    x=0
    for s in S:
        if d[s]!=n//3:
            return 'No'
        x^=s
    return 'No' if x else 'Yes'

n=int(input())
A=tuple(map(int,input().split()))
print(solve(n,A))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    d = dict()
    for a in A: d[a] = d.get(a, 0) + 1

    if len(d) == 1:
        a = list(d.keys())[0]
        if a == 0:
            return "Yes"
    elif len(d) == 2:
        a, b = list(d.keys())
        if a == 0 and d[b] == 2*d[a]:
            return "Yes"
        if b == 0 and d[a] == 2*d[b]:
            return "Yes"
    elif len(d) == 3:
        a, b, c = list(d.keys())
        if d[a] == d[b] == d[c]:
            if (a^b == c and b^c == a and c^a == b) or (a^c == b and c^b == a and b^a == c):
                return "Yes"
    return "No"

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    d = dict()
    for a in A: d[a] = d.get(a, 0) + 1

    if len(d) == 1:
        a = list(d.keys())[0]
        if a == 0:
            return "Yes"
    elif len(d) == 2:
        a, b = list(d.keys())
        if a == 0 or b == 0:
            if d[a] == d[b]:
                return "Yes"
            if N % 3 == 0 and (d[a] == 2*d[b] or d[b] == 2*d[a]):
                return "Yes"    
    elif len(d) == 3:
        a, b, c = list(d.keys())
        if d[a] == d[b] == d[c]:
            if (a^b == c and b^c == a and c^a == b) or (a^c == b and c^b == a and b^a == c):
                return "Yes"
    return "No"

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

Submission status: Accepted

Solution code:

data = {}
N = int(input())
for i in input().split():
    if i not in data:
        data.update({i: 1})
    else:
        data[str(i)] += 1

ok = 0

if len(data.keys()) > 3:
    pass
elif len(data.keys()) == 1:
    if list(data.keys())[0] == "0":
        ok = 1
elif len(data.keys()) == 2:
    if "0" in data.keys() and data["0"] == N/3:
        ok = 1
else:
    sum = 0
    for i, count in data.items():
        if not count == N/3:
            ok = -1
            break
        sum = sum ^ int(i)
    if ok == 0 and sum == 0:
        ok = 1

if ok == -1:
    ok = 0
print("Yes" if ok else "No")

Submission status: Accepted

Solution code:
def main():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = collections.Counter(list(map(int, input().rstrip('\n').split()))).most_common()
    if len(a) == 3:
        if a[0][0] ^ a[1][0] ^ a[2][0] == 0 and a[0][1] == a[1][1] == a[2][1]:
            print("Yes")
            exit()
    elif len(a) == 2:
        if (a[0][0] == 0 and a[1][1] == a[0][1] * 2) or (a[1][0] == 0 and a[0][1] == a[1][1] * 2):
            print("Yes")
            exit()
    elif len(a) == 1 and a[0][0] == 0:
        print("Yes")
        exit()
    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    if all([aa == 0 for aa in a]):
        print(YES)
    elif len(set(a)) == 2 and len([aa for aa in a if aa == 0]) == N // 3:
        print(YES)
    elif len(set(a)) == 3:
        l = list(set(a))
        if l[0] ^ l[1] ^ l[2] == 0 and a.count(l[0]) == N // 3 and a.count(l[1]) == N // 3:
            print(YES)
        else:
            print(NO)
    else:
        print(NO)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

total=L[0]
for i in range(1,N):
    total^=L[i]

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#AGC35 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n = I()
a = LI()
if sum(a) == 0:
    print('Yes')
elif n % 3 != 0:
    print('No')
else:
    b = list(Counter(a).items())
    b.sort(key = itemgetter(0))
    if len(b) == 2:
        if b[0][0] == 0 and b[0][1] == n//3 and b[1][1] == n//3*2:
            print('Yes')
            quit()
    elif len(b) == 3:
        if b[0][0]^b[1][0]^b[2][0] == 0:
            if b[0][1] == n//3 and b[1][1] == n//3 and b[2][1] == n//3:
                print('Yes')
                quit()
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter

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

# a^c == b
# b^(a^c) == b^b == 0
# a^b^c == 0

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

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

b = list(set(a))
if len(b) > 3:
    print("No")
    exit(0)

A = Counter(a)
if len(b) == 3:
    if A[b[0]] == A[b[1]] == A[b[2]]:
        if b[0]^b[1]^b[2] == 0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    if A[0] == N//3:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
def getlist():
    return list(map(int, input().split()))

N = int(input())
a = getlist()
a = sorted(a)

if N % 3 != 0:
    if a[-1] >= 1:
        print("No")
    else:
        print("Yes")
else:
    m = int(N // 3)
    if a[0] == a[m - 1] and a[m] == a[2 * m - 1] and a[2 * m] == a[3 * m - 1]:
        if a[0] ^ a[m] == a[2 * m] and a[m] ^ a[2 * m] == a[0] and a[2 * m] ^ a[0] == a[m]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = sorted(collections.Counter(list(map(int, input().split()))).most_common())
if len(a) == 3:
    if a[0][0] ^ a[1][0] ^ a[2][0] == 0 and a[0][1] == a[1][1] == a[2][1]:
        print("Yes")
    else:
        print("No")
elif len(a) == 2:
    if a[0][1] * 2 == a[1][1] and a[0][0] == 0:
        print("Yes")
    else:
        print("No")
elif len(a) == 1:
    if a[0][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()))

c = Counter(a)
k = list(c.keys())
v = list(c.values())
if k == [0]:
    able = True
elif len(c) == 2 and 0 in c and c[0] == N // 3:
    able = True
elif len(c) == 3 and k[0] ^ k[1] == k[2] and v[0] == v[1] == v[2]:
    able = True
else:
    able = False
print('Yes' if able else 'No')

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for a in [int(x) for x in input().split()]:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
ans = "No"
key = list(d.keys())
l_key = len(key)
if l_key == 1:
    if 0 in d:
        ans = "Yes"
elif l_key == 2:
    if 0 in d:
        if d[0] * 3 == n:
            ans = "Yes"
elif l_key == 3:
    flag = 0
    for v in d.values():
        if v * 3 == n:
            flag += 1

    if key[0] ^ key[1] ^ key[2] == 0 and flag == 3:
        ans = "Yes"

print(ans)

Submission status: Accepted

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

if len(aset) == 1:
  if all(i == 0 for i in a):
    print("Yes")
  else:
    print("No")
elif len(aset) == 2:
  a1, a2 = sorted(aset)
  if a1 == 0:
    if a.count(a1) * 3 == n:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
elif len(aset) == 3:
  a1, a2, a3 = aset
  if a.count(a1) == a.count(a2) == a.count(a3):
    if a1 ^ a2 == a3:
      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()))
s = 1
for i in a:
    s ^= i
if s == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

a.sort()
h = {}
for i in a:
    if i in h:
        h[i] += 1
    else:
        h[i] = 1
k = []
v = []
for i,j in h.items():
    k.append(i)
    v.append(j)

if len(h) == 1:
    if k[0] == 0:
        print("Yes")
        exit()
elif len(h) == 2:
    if k[0] == 0 and 2*v[0] == v[1]:
        print("Yes")
        exit()
elif len(h) == 3:
    if k[0] ^ k[1] == k[2] and v[0] == v[1] and v[0] == v[1]:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
n = int(input())
import collections
c = collections.Counter(list(map(int,input().split())))
k = list(c.keys())
v = list(c.values())
#print(k,v)
if len(k)==3 and k[0]^k[1]^k[2]==0 and v[0]==v[1]==v[2]:
  print("Yes")
elif len(k)==2 and k.count(0) and v[k.index(0)]==(sum(v)/3):
  print("Yes")
elif k == [0]:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    from collections import Counter
    ls = Counter(map(int, input().split()))
    print('YNeos'[not check(n, ls)::2])

def check(n, ls):
    key = list(ls.keys())
    val = list(ls.values())
    l = len(key)
    if key[0] == 0 and val[0] == n:
        return True
    elif l in [2, 3] and n % 3 == 0:
        if l == 2:
            if key[0] ^ key[1] in key and (val[0] == val[1]*2 or val[0]*2 == val[1]): return True
        elif l == 3:
            for v in val:
                if v != n / 3: return False
            if key[0] ^ key[1] == key[2] or key[1] ^ key[2] == key[0] or key[2] ^ key[0] == key[1]: return True
        return False
    else:
        return False

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

flag="No"

count_by_kw = Counter()
for i in range(n):
    count_by_kw[a[i]]+=1

if count_by_kw.get(0) == n:
    flag="Yes"

if count_by_kw.get(0) == n/3 and len(count_by_kw.keys())==2:
    flag="Yes"

cl=list(count_by_kw.values())
ck=list(count_by_kw.keys())

if len(cl)==3:
    if cl[0] == cl[1] and cl[1] == cl[2]:
        xor = ck[0]^ck[1]^ck[2]
        if xor == 0:
            flag="Yes"
        
print(flag)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
A = list(set(a))
A.sort()
ans = "No"
if len(A) == 1:
    if A[0] == 0:
        ans = "Yes"
elif len(A) == 2:
    if A[0] == 0:
        if a.count(A[1]) == 2* (n // 3) :
            ans = "Yes"
elif len(A) == 3:
    if A[0]^A[1]^A[2] == 0:
        if a.count(A[0]) == n//3:
            if a.count(A[1]) == n//3:
                if a.count(A[2]) == n//3:
                    ans = "Yes"
print(ans)