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:
from collections import Counter

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

d = Counter(A)

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

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
c = Counter(a).most_common()

if len(c) == 3 and c[0][1] == c[1][1] == c[2][1]:
    x = c[0][0]
    y = c[1][0]
    z = c[2][0]
    if x^y^z == 0:
        ans = "Yes"
    else:
        ans = "No"
elif len(c) == 2 and c[0][1] == 2*c[1][1]:
    x = c[0][0]
    y = c[1][0]
    if x^x^y == 0:
        ans = "Yes"
    else:
        ans = "No"
elif len(c) == 1 and c[0][0] == 0:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
c = Counter(a).most_common()

if len(c) == 3 and c[0][1] == c[1][1] == c[2][1]:
    x = c[0][0]
    y = c[1][0]
    z = c[2][0]
    if x^y == z and y^z == x and z^x == y:
        ans = "Yes"
    else:
        ans = "No"
elif len(c) == 2 and c[0][1] == 2*c[1][1]:
    x = c[0][0]
    y = c[1][0]
    if x^x == y and x^y == x:
        ans = "Yes"
    else:
        ans = "No"
elif len(c) == 1 and c[0][0] == 0:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
num=a[0]
for i in range(1,n):
    num=num^a[i]
if max(a)==(2**(n-3))+(2**(n-4)):
    print("No")
elif max(a)==min(a) and a[0]!=0:
    print("No")
elif num<=1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

if sum(As)==0:
    print('Yes')
elif N%3!=0:
    print('No')
else:
    from collections import Counter
    d = N//3
    c = Counter(As)
    if len(set(As))>3:
        print('No')
    elif len(set(As))==3:
        items = list(set(As))
        a = 0
        for item in items:
            a ^= item
            if not c[item]==d:
                print('No')
                break
        else:
            if a!=0:
                print('No')
            else:
                print('Yes')
    else:
        if c[0]==d:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

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

c=Counter(a)
bl=True
if n%3==0:
    if len(c.keys())==3:
        l=[]
        for i,j in c.items():
            if j!=n//3:
                bl=False
            l.append(i)
        if 0 in l:
            bl=False
        if l[0]^l[1]!=l[2]:
            bl=False
    elif len(c.keys())==2:
        if c[0]!=n//3:
            bl=False
    else:
        bl=False
else:
    bl=False
if c[0]==n:
    bl=True

if bl:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

n = int(input())
(*a, ) = map(int, input().split())
c = Counter(a)
b = 0
for i in c.keys():
    b ^= i
if sum(a) == 0 or (b == 0 and all(i * 3 == n for i in c.values())):
    print("Yes")
elif len(c) == 2 and c.most_common()[0][1] * 3 == 2 * n and c.most_common(
)[1][0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
# 条件を満たす状態における 連続する 4 つの値に関して考えると
# a_i = a_(i+3) を満たす事がわかる
# 満たす条件は
# a1 ^ a2 ^ a3 = 0
# a_i = a_(i+3) -> 値が 3 種類以内
c = Counter(a)
n_uniq = len(c)
# 値が 3 種類以上であれば No
if n_uniq > 3:
    print('No')
#  a1, a2, a3 の場合分けを考える
# 3 種類の異なる値の場合 : a1, a2, a3 が n 枚のうちちょうど同じ数ずつある必要がある (-> n / 3 が 3 の倍数)
elif n_uniq == 3:
    a_1, a_2, a_3 = c.keys()
    if a_1 ^ a_2 ^ a_3 == 0 and c[a_1] == c[a_2] == c[a_3]:
        print('Yes')
    else:
        print('No')
# 2 種類の異なる値の場合 : ある 1 つの値が必ず 0 -> 0 が n / 3 枚、 等しい数となる a_x は 2n / 3 枚
elif n_uniq == 2:
    a_1, a_2 = sorted(set(a))
    if a_1 == 0 and 3 * c[a_1] == n:
        print('Yes')
    else:
        print('No')
# 全て同じ値の場合 : 全て 0
else:
    if sum(a) == 0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A_LIST = list(map(int, input().split()))
A_SET = set(A_LIST)
if len(A_SET) == 1:
    if sum(A_SET) == 0:
        print('Yes')
    else:
        print('No')
elif len(A_SET) == 2:
    a1, a2 = sorted(A_SET)
    if a1 == 0 and A_LIST.count(a1) * 3 == N:
        print('Yes')
    else:
        print('No')
elif len(A_SET) == 3:
    a1, a2, a3 = A_SET
    if a1 ^ a2 == a3 and A_LIST.count(a1) ==  A_LIST.count(a2) and A_LIST.count(a2) == A_LIST.count(a3):
        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()))
s = set(a)
l = len(s)
c = Counter(a)
if l == 1:
    if sum(a) == 0:
        print("Yes")
    else:
        print("No")
elif l == 2:
    x, y = min(a), max(a)
    if x == 0 and c[0] == n / 3:
        print("Yes")
    else:
        print("No")
elif l == 3:
    x, y, z = s
    if x ^ y ^ z == 0 and c[x] == c[y] == c[z]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


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


# In[8]:


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


# In[ ]:

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()
c = Counter(A)

a = list(c.keys())
n = len(a)

if n == 1 and c[0] == N:
	print("Yes")
elif N%3 == 0:
	if n == 3 and len(set(c.values())) == 1 and a[0]^a[1] == a[2]:
		print("Yes")
	elif n == 2 and c[0] == N//3:
		print("Yes")
	else:
		print("No")
else:
	print("No")

Submission status: Accepted

Solution code:
import sys
from collections import Counter
N = int(input())
C = Counter(list(map(int, input().split())))
if len(C) == 1 and C[0] == N:
    print('Yes')
elif len(C) == 2 and N % 3 == 0 and C[0] == N // 3 and N - C[0] == 2 * N // 3:
    print('Yes')
elif len(C) == 3 and N % 3 == 0:
    b = 0
    for c in C.most_common():
        if c[1] != N // 3:
            print('No')
            sys.exit()
        b ^= c[0]
    if b == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    if a.count(0) == n:
        print("Yes")
    else:
        if n % 3 == 0:
            s = list(set(a))
            if len(s) == 3:
                if s[0] ^ s[2] == s[1] and s[1] ^ s[0] == s[2] and s[2] ^ s[1] == s[0]:
                    if a.count(s[0]) == a.count(s[1]) == a.count(s[2]):
                        print("Yes")
                    else:
                        print("No")
                else:
                    print("No")
            elif len(s) == 2:
                if a.count(0) == n // 3:
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
        else:
            print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

#%%
setA = set(A)
if len(setA) == 1:
    if sum(A) == 0:
        ans = 'Yes'
    else:
        ans = 'No'

elif len(setA) == 2:
    a1, a2 = sorted(setA)
    if (a1 == 0) and (A.count(a1) * 3 == n):
        ans = 'Yes'
    else:
        ans = 'No'

elif len(setA) == 3:
    a1, a2, a3 = setA
    if (a1 ^ a2 ^ a3 == 0) and (A.count(a1) == A.count(a2) == A.count(a3)):
        ans = 'Yes'
    else:
        ans = 'No'
else:
    ans = 'No'

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    cnt=Counter(A)

    if cnt[0]==N:
        print("Yes")
        return
    t=0
    for a in A:
        t^=a

    if N%3==0:
        if cnt[0]==int(N//3) and len(cnt)==2:
            print("Yes")
        elif len(cnt)==3 and t==0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


    
if __name__ == "__main__":
     solve()

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
flag = False
dic = collections.Counter(a)
if len(dic) == 1:
    if 0 in dic:
        print('Yes')
    else:
        print('No')
elif len(dic) == 2:
    if 0 in dic:
        if dic[0] == n/3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(dic) == 3:
    pre = 0
    for k,v in dic.items():
        if v != n/3:
            print('No')
            sys.exit()
        pre = pre^k
    if pre == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
flag = False
dic = collections.Counter(a)
if len(dic) == 1:
    if 0 in dic:
        print('Yes')
    else:
        print('No')
elif len(dic) == 2:
    if 0 in dic:
        if dic[0] == n/3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(dic) == 3:
    pre = 0
    for k,v in dic.items():
        if v != n/3:
            print('No')
            sys.exit()
        pre = pre^k
    if pre == 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 A.count(0) == N:
    print("Yes")
    exit()

d = Counter(A)
if len(d.keys()) > 3:
    print("No")
    exit()
elif len(d.keys()) == 3:
    a, b, c = d.keys()
    if d[a] == d[b] == d[c] and a ^ b ^ c == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(d.keys()) == 2:
    a, b = d.keys()
    if a * b != 0:
        print("No")
    else:
        if a != 0:
            d[a], d[b] = d[b], d[a]  # aを0にする
        if d[a] * 3 == N and 3 * d[b] == 2 * N:
            print("Yes")
        else:
            print("No")
    exit()
print("No")

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    As = [int(item) for item in input().split()]
    As.sort()
    temp_set = set(As)
    is_true = True
    # print(temp_set)
    if len(temp_set) == 1:
        if As[0] != 0:
            is_true = False
    elif len(temp_set) == 2:
        x_num = As.count(max(As))
        zero_num = As.count(0)
        if x_num != 2*zero_num:
            is_true = False

    elif len(temp_set) == 3:
        temp_cnt = collections.Counter(As)
        # print(temp_cnt)
        temp_set = list(set(As))
        if temp_cnt[temp_set[0]] == temp_cnt[temp_set[1]] == temp_cnt[temp_set[2]]:
            temp_keys = list(temp_cnt.keys())
            if temp_keys[0] ^ temp_keys[1] ^ temp_keys[2] == 0:
                is_true = True
            else:
                is_true = False
        else:
            is_true = False
        
    else:
        is_true = False

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



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
m = c.most_common()

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

Submission status: Accepted

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

C = Counter(A)

if C[0] == N:
  print('Yes')
elif N%3 > 0:
  print('No')
elif len(C) == 2 and C[0] == N//3:
  print('Yes')
elif len(C) == 3:
  k = list(C.keys())
  v = list(C.values())
  if v[0] == v[1] and v[1] == v[2]:
    if k[0] ^ k[1] ^ k[2] == 0:
      print('Yes')
      exit(0)
      
  print('No')
else:
  print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    for e in a:
        d[e] += 1
    ks = list(d.keys())
    m = len(ks)
    if m < 4:
        x = n / 3
        if m == 1 and ks[0] == 0:
            print("Yes")
            return
        elif m == 2:
            if d[0] == x:
                print("Yes")
                return
        elif m == 3:
            a, b, c = ks
            if d[a] == d[b] and d[a] == d[c] and (a^b^c) == 0:
                print("Yes")
                return
    
    print("No")


    


    
    
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

R s
S p
P r

"""

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = 0
for i in a:
    cnt ^= i

if n % 3 == 0 and all(a[i] % (n // 3) == 0 for i in a):
    print('Yes' if (cnt == 0 or a[0] == n // 3) else 'No')
else:
    print('Yes' if a[0] == n else 'No')

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
if A.count(0)==N:
    print("Yes")
elif N%3!=0:
    print("No")
elif len(set(A))==2:
    if 0 in set(A):
        if A.count(0)==N/3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(set(A))==3:
    xor=0
    for a in set(A):
        if A.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:
# https://atcoder.jp/contests/agc035/tasks/agc035_a
from collections import Counter

n = int(input())
nums = [int(i) for i in input().split()]
c = Counter(nums)

if sum(nums) == 0:
    print('Yes')
elif len(c) == 2:
    for k, v in c.items():
        if k == 0:
            if v != n // 3:
                print('No')
                break
        else:
            if v != n // 3 * 2:
                print('No')
                break
    else:
        print('Yes')
elif len(c) == 3:
    t = 0
    for k, v in c.items():
        if v != n // 3:
            print('No')
            break
        t ^= k
    else:
        if t:
            print('No')
        else:
            print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

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

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

ac = collections.Counter(a)

if len(ac) == 2 and ac[0] ==N/3:
    print('Yes')
    exit()


if len(ac) != 3 :
    print('No')
    exit()
else:
    lk1,lk2,lk3 = ac.keys()
    lv1,lv2,lv3 = ac.values()
if lv1 == lv2 ==lv3:
    if lk1^lk2 == lk3:
        print('Yes')
    else:
        print('No')
else:
    print('No')
    exit()

Submission status: Accepted

Solution code:
n = int(input())
la = [int(w) for w in input().split()]

x = la[0]

for a in la[1:]:
    x ^= a

cond = x == 0
print("Yes" if cond else "No")

Submission status: Accepted

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

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

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:
    a=A[0]
    for i in range(1,n):
        a = a^A[i]
    if a==0:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

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

number=A[0]

for n in range(1,N):
    number=number^A[n]

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

Submission status: Accepted

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

ans = 0
for i in range(n):
    ans ^= a[i]

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)

t = 0
for a in A:
    t ^= a

if c[0] == N:
    print('Yes')
elif N % 3 == 0:
    if c[0] == int(N//3) and len(c) == 2:
        print('Yes')
    elif len(c) == 3 and t == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = i()
a = l()

for i in range(N):
    ans^=a[i]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

d={}
for h in range(1,N):
    if a[h] in d:
        d[a[h]]+=1
    else:
        d[a[h]]=1
ans="Yes"
b=[a[0]]

for h in range(1,N):
    t=a[h]^a[0]
    if t in d:
        b.append(a[h])
        d[a[h]]-=1
        if d[a[h]]==0:
            del d[a[h]]
        break
    if h==N-1:
        ans="No"

if ans=="Yes":
    for i in range(1,N+1):
        if i==h:
            continue
        if i==N:
            t=b[-1]^b[-2]
            if t!=b[0]:
                ans="No"
            break
        t=b[-1]^b[-2]
        if t in d:
            b.append(t)
            d[t]-=1
            if d[t]==0:
                del d[t]
        else:
            ans="No"
            break

print(ans)

Submission status: Accepted

Solution code:
import functools

if __name__ == "__main__":
    N = int(input())
    A = [int(x) for x in input().split(" ")]
    a = functools.reduce(lambda x, y: x ^ y, A, 0)
    if a == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
flg=False
if all(a[i]==0 for i in range(n)):flg=True
if n%3==0:
    l=Counter(a)
    ans=l.most_common()
    if len(ans)==2:
        flg1,flg2=False,False
        for i,j in ans:
            if i==0 and n%j==0 and n//j==3:
                flg1=True
            if j/n==2/3:
                flg2=True
            if flg1 and flg2:
                flg=True
    if len(ans)==3:
        flg3=True
        tmp=0
        for i in range(3):
            tmp^=ans[i][0]
            if ans[i][1]*3!=n:
                flg3=False
            if flg3 and tmp==0:
                flg=True
if flg:
    print("Yes")
else:
    print("No")