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 = list(map(int, input().split()))
cnt_a = Counter(a)

if n % 3 == 0:
    if cnt_a[0] == n:
        print('Yes')
    elif len(set(a)) == 2 and 0 in set(a) and cnt_a[0] == n // 3:
        print('Yes')
    elif len(set(a)) == 3:
        x, y, z = set(a)
        if cnt_a[x] == n // 3 and cnt_a[y] == n // 3 and cnt_a[z] == n // 3 and x ^ y ^ z == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if cnt_a[0] == n:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A=[int(i) for i in input().split()]
    k = A[0]
    for i in A[1:]:
        k^=i
    if(k!=0):
        print("No")
    else:
        print("Yes")




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
Aall = A[0]
for i in range(1,N):
    Aall ^= A[i]
import sys
flag = True
for i in range(N):
    if A[i]^Aall != A[i]:
        flag = False
        print("No")
        sys.exit()
if flag:
    print("Yes")

Submission status: Accepted

Solution code:
# agc035_a.py
'''
両隣の数のXORが自身と等しい状態にできる場合Yes、そうでない場合No
例：
N = 3
Ai = 1, 2, 3
1, 2, 3 -> 1, 2, 3 にすることで
2 XOR 3  = 1, 2 XOR 1 = 3, 3 XOR 1 = 1 となるので Yes
XOR の性質は
a XOR a = 0
a XOR 0 = a
a XOR b >= a + b
などがある。
'''
import collections
N = int(input())

L = list(map(int,input().split()))
C = collections.Counter(L)
flg = False
if len(C)>3:
    print('No')
    exit()

if len(C)==3:
    ans = 0
    cnt = []
    for i,v in C.items():
        ans ^= i
        cnt.append(v)
    if ans == 0 and max(cnt) == min(cnt):
        print('Yes')
        exit()
    else:
        print('No')
if len(C) == 2:
    if C[0] == 0:
        print('No')
        exit()
    x = 0
    y = 0
    for i,v in C.items():
        if i == 0 :
            x = v
        else:
            y = v
    if 2 * x == y:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
if len(C) == 1:
    if C[0]>0:
        print('Yes')
        exit()
    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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, 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 fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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
from decimal import *

N = INT()

a = LIST()
C = Counter(a)
A = sorted(set(a))


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

else:
	print("No")

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, 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 fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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
from decimal import *

N = INT()

a = LIST()
C = Counter(a)
A = sorted(set(a))

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

elif len(A) == 1 and 0 in a:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

cnt=Counter(a)
if cnt[0]==n:
    print("Yes")
    quit()
if n%3!=0:
    print("No")
    quit()
a.sort()
if cnt[0]==n//3 and cnt[a[-1]]==2*n//3:
    print("Yes")
    quit()

# print(1)
lst=[]
for i in range(n):
    if cnt[a[i]]==n//3:
        if a[i] in lst:
            continue
        else:
            lst.append(a[i])
    else:
        print("No")
        quit()
if lst[0]^lst[1]^lst[2]==0:
    print("Yes")
    quit()
else:
    print("No")

Submission status: Accepted

Solution code:
n,c,*a=map(int,open(0).read().split())
for i in a:c^=i
print('YNeos'[c>0::2])

Submission status: Accepted

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

def rule1(L):
    if len(set(L))!=2:
        return False
    if L.count(0)!=len(L)//3:
        return False
    return True

def rule2(L):
    if len(set(L))!=3:
        return False
    sL = set(L)
    if L.count(list(sL)[0])==L.count(list(sL)[1])==L.count(list(sL)[2]):
        if list(sL)[0] ^ list(sL)[1] ^ list(sL)[2] ==0:
            return True
        else:
            return False
    else:
        return False

if sum(A)==0 or rule1(A) or rule2(A):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_dic = dict()
a_set = set()
for num in a:
  if num in a_dic:
    a_dic[num] += 1
  else:
    a_dic[num] = 1
  a_set.add(num)
k = len(a_dic)
a_set = list(a_set)
if k == 1:
  if 0 in a_dic:
    if a_dic[0] == n:
      print('Yes')
      exit()
elif k == 2:
  if a_dic[0] == n/3 and a_dic[a_set[1]] == 2*n/3:
    print('Yes')
    exit()
elif k == 3:
  if a_set[0] ^ a_set[1] ^ a_set[2] == 0:
    if a_dic[a_set[0]] == a_dic[a_set[1]] == a_dic[a_set[2]] == n/3:
      print('Yes')
      exit()
print('No')

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc035/tasks/agc035_a
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce

# 成り立つ連立方程式を見ると、各項が二回ずつ出てきてることがわかる
# ということはすべての和を取ると0になるのが条件だ

N = read_a_int()
A = read_ints()
res = reduce(xor, A)
print('Yes' if res == 0 else 'No')

Submission status: Accepted

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

def main(n,a):
    allxor=0
    for i in range(n):
        allxor = allxor ^ a[i]
    if allxor == 0:
        return 'Yes'
    else:
        return 'No'

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
x = [10**9+1,0]
y = [10**9+1,0]
z = [10**9+1,0]
for i in range(N):
    if x[0] == a[i]:
        x[1] += 1
    else:
        if x[1] == 0:
            x[0] = a[i]
            x[1] += 1
        elif y[0] == a[i]:
            y[1] += 1
        else:
            if y[1] == 0:
                y[0] = a[i]
                y[1] += 1
            elif z[0] == a[i]:
                z[1] += 1
            else:
                if z[1] == 0:
                    z[0] = a[i]
                    z[1] += 1

ans = 'No'
if x[0] == 0:
    if x[1] == N:
        ans = 'Yes'
    elif x[1]*2 == y[1] and x[1] + y[1] == N:
        ans = 'Yes'
if x[1] == y[1] == z[1] and x[1] + y[1] + z[1] == N and x[0]^y[0]^z[0] == 0:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if set(a) == {0}:
    print('Yes')
    exit()

flag = 0
if n % 3 == 0:
    if len(cnt) == 2:
        if cnt.get(0) == n // 3:flag = 1
    elif len(cnt) == 3:
        if len(set(cnt.values())) == 1:
            new_a = list(cnt.keys())
            if new_a[0]^new_a[1] == new_a[2]:flag = 1

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
def main():
    # 全部ゼロ
    if c[0] == n:
        ok = True
        return ok
    if n % 3 != 0:
        ok = False
        return ok
    # ゼロとその他1個でかつぜろが1/3個
    if c[0] == n // 3 and len(c) == 2:
        ok = True
        return ok
    # 全部違ってて1/3ずつでxorして0
    if len(c) != 3:
        ok = False
        return ok
    xor = 0
    for x in c:
        if c[x] != n // 3:
            ok = False
            return ok
        xor ^= x
    if xor == 0:
        ok = True
    else:
        ok = False
    return ok
        
if __name__ == '__main__':
    print("Yes" if main() else "No")

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    Al = Counter(A)
    x = list(Al)
    x.sort()

    if len(Al)>3:
        print('No')
    elif len(Al)==3:
        cond1 = (x[0]^x[1]^x[2] == 0)
        cond2 = (Al[x[0]] == N//3) and (Al[x[1]] == N//3) and (Al[x[2]] == N//3)
        if cond1 and cond2:
            print('Yes')
        else:
            print('No')

    elif len(Al)==2:
        cond1 = x[0] == 0
        cond2 = (Al[x[0]] == N//3) and (Al[x[1]] == N - N//3)
        if cond1 and cond2:
            print('Yes')
        else:
            print('No')
    elif len(Al)==1:
        cond1 = x[0] == 0
        cond2 = True
        if cond1 and cond2:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans='No'
from collections import Counter

c=Counter(a)
keys = list(c.keys())
values =list(c.values())

if keys==[0]:
    ans='Yes'
elif len(keys)==3 and values[0]==n/3 and values[1]==n/3 and keys[0]^keys[1]==keys[2]:
    ans='Yes'
elif len(keys)==2 and c[0]==n/3:
    ans='Yes'

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)

# 帽子の種類数を取得する
c_set = set(A)

# 帽子の種類数が1個の時、数値が0なら条件を満たす
if len(c_set) == 1:
    if c[0] != 0:
        print('Yes')
        exit(0)

# 帽子の種類数が2個の時、数値が0の帽子がN/3なら条件を満たす
elif len(c) == 2:
    if c[0] == N//3:
        print('Yes')
        exit(0)

# 帽子の種類数が3個の時、x^y^z=0で条件を満たす
elif len(c) == 3:
    check = -1
    check_list = []
    for a in c_set:
        check_list.append(a)
        if check == -1:
            check = c[a]
        else:
            if check != c[a]:
                print('No')
                exit(0)

    # 同じ個数ずつあった時に、x^y^z=0であるか
    if check_list[0] ^ check_list[1] ^ check_list[2] == 0:
        print('Yes')
        exit(0)
print('No')

Submission status: Accepted

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

if len(set(A)) >3 :
  print("No")
elif len(set(A))  == 3 :
  x,y,z = sorted(list(set(A)))[0],sorted(list(set(A)))[1],sorted(list(set(A)))[2]
  if N%3 == 0 and \
  A.count(x) == N//3 and\
  A.count(y) == N//3 and\
  A.count(z) == N//3 and\
  x^y^z == 0:
    print("Yes")
  else:
    print("No")
elif len(set(A)) == 2:
  x,y = sorted(list(set(A)))[0],sorted(list(set(A)))[1]
  if N%3 == 0 and \
  A.count(x) == N//3 and\
  A.count(y) == 2*N//3 and\
  y^y== 0:
    print("Yes")
  else:
    print("No")
else:
  if list(set(A))[0] ==0:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(input())
s = Counter(list(map(int, sys.stdin.readline().rsplit())))

# すべて同じ値かつ0である
if len(s) == 1 and 0 in s:
    print("Yes")
# 2種類の値かつ(a, a, 0)という組み合わせ(aは任意)
elif len(s) == 2 and s[0] == N // 3:
    print("Yes")
# すべて異なる値
elif len(s) == 3:
    res = 0
    num = set()
    # 3種類のXORを計算(res), それぞれの数をpush
    for k, v in s.items():
        res ^= k
        num.add(v)
    # res = a1 ^ a2 ^ a3 = 0 かつそれぞれの数が同じ(= 3 // N) -> Yes
    if not res and len(num) == 1:
        print("Yes")
    else:
        print("No")
# 3種類より多い場合は成立しない
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(input())
s = Counter(list(map(int, sys.stdin.readline().rsplit())))

if s[0] == N:
    print("Yes")
elif len(s) == 2 and s[0] == N // 3:
    print("Yes")
elif len(s) == 3:
    res = 0
    num = set()
    for k, v in s.items():
        res ^= k
        num.add(v)
    if not res and len(num) == 1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
 
if N%3 != 0 and max(As) > 0:
  print('No')
  exit()
  
else:
  n = N//3
  ma = max(As)
  l = len(str(bin(ma))) - 2
  for i in range(l):
    c = 0
    for a in As:
      if (a>>i)%2 == 0:
        c += 1
    if c != n and c != N:
      print('No')
      exit()

print('Yes')

Submission status: Accepted

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

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

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

c = Counter(A)
if len(c.values()) == 2:
    values = list(c.values())
    if min(values) == N // 3:
        keys = list(c.keys())
        if 0 in keys:
            print('Yes')
            exit()

if len(c.values()) != 3:
    print('No')
    exit()

keys = list(c.keys())
for i, j, k in ([0, 1, 2], [1, 2, 0], [2, 1, 0]):
    if keys[i] ^ keys[j] != keys[k]:
        print('No')
        exit()

values = list(c.values())
if values[0] != values[1] or values[1] != values[2]:
    print('No')
    exit()

print('Yes')

# a b c a b c ...
# a xor b = c
# b xor c = a
# c xor a = b

# 全員0

# x 0 x x 0 x ...

Submission status: Accepted

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

t = 0
for a_i in a:
    t ^= a_i
    # print(t)
print("Yes" if t==0 else "No")

Submission status: Accepted

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

p=set(a[:n//3])
q=set(a[n//3:(n//3)*2])
r=set(a[(n//3)*2:n])

flag=True
if n%3!=0:
    flag=False
if len(set(a))==1 and a[0]==0:
    print("Yes")
    sys.exit()
    
if flag and len(p)==1 and len(q)==1 and len(r)==1:
    if a[0] ^ a[n//3]==a[(2*n)//3]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

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

t=0
for a_i in a:
    t^=a_i
print('Yes' if t==0 else 'No')

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  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

#####MakeDivisors######
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)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
L = IL()
b = 0
for l in L:
  b ^= l
if b:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

if s[0] == n:
    print("Yes")
elif len(s) == 2 and s[0] == n // 3:
    print("Yes")
elif len(s) == 3:
    res = 0
    num = set()
    for k, v in s.items():
        res ^= k
        num.add(v)
    if not res and len(num) == 1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
d = defaultdict(int)
for i in a:
    d[i] += 1
print("Yes"
if(
    (len(d) == 3 and len(set(d.values())) == 1 and n % 3 == 0 and (list(d.keys())[0] ^ list(d.keys())[1] ^ list(d.keys())[2] == 0))
    or (len(d) == 2 and n % 3 == 0 and d[0] == n // 3 and (0 in d.keys()))
    or (sum(a) == 0)
)
else "No")

Submission status: Accepted

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


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

    c = Counter(a)
    ans = "No"
    if len(c) == 3:
        v = list(c.values())
        if v[0] == v[1] == v[2]:
            k = list(c.keys())
            if (k[0] ^ k[1] == k[2]) and (k[1] ^ k[2] == k[0]) and (k[2] ^ k[0] == k[1]):
                ans = "Yes"
    elif len(c) == 2:
        v = list(c.values())
        k = list(c.keys())
        v[0], v[1] = min(v), max(v)
        k[0], k[1] = min(k), max(k)
        if k[0] == 0 and v[0] * 2 == v[1]:
            ans = "Yes"
    elif len(c) == 1:
        k = list(c.keys())
        if k[0] == 0:
            ans = "Yes"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n % 3 == 0:
    a.sort()
    for i in range(n // 3 - 1):
        if a[i] != a[i + 1]:
            print('No')
            exit(0)
    for i in range(n // 3, n // 3 * 2 - 1):
        if a[i] != a[i + 1]:
            print('No')
            exit(0)
    for i in range(n // 3 * 2, n - 1):
        if a[i] != a[i + 1]:
            print('No')
            exit(0)
    if a[0] ^ a[n // 3] == a[n // 3 * 2]:
        print('Yes')
    else:
        print('No')
else:
    if any(a):
        print('No')
    else:
        print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

for num in a:
    dd[num] += 1
    if len(dd) >= 4:
        print("No")
        exit()

if len(dd) == 1:    
    if dd[0] > 0:
        print("Yes")
    else:
        print("No")
    exit()

if n % 3 != 0:
    print("No")
    exit()
    
    
if len(dd) == 2:
    if dd[0] == n // 3:
        print("Yes")
    else:
        print("No")
        
else:
    lst = []
    for i, j in dd.items():
        lst.append(i)
        if j != n // 3:
            print("No")
            exit()
    if lst[0] ^ lst[1] ^ lst[2] == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from collections import Counter


N = int(input())
a = list(map(int, input().split()))
if N % 3 and a != [0] * N:
    print("No")
    exit()

nums = Counter(a)
ks = sorted(nums)
vs = sorted(nums.values())
if (
    (len(nums) == 1 and ks[0] == 0)
    or (len(nums) == 2 and ks[0] == 0 and vs[0] == N // 3)
    or (
        len(nums) == 3
        and all(v == N // 3 for v in vs)
        and reduce(lambda x, y: x ^ y, ks) == 0
    )
):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def print_end(x):
    pr = ['No','Yes']
    print(pr[x])
    exit()

if(sum(a)==0):
    print_end(1)

if(n%3!=0):
    print_end(0)

set_a = set(a)
if(len(set_a)==1)|(len(set_a)>3):
    print_end(0)

if(len(set_a)==2):
    a0,a1 = sorted(list(set_a))
    if(a0!=0):
        print_end(0)
    if(a.count(a0) * 2 == a.count(a1)):
        print_end(1)
    print_end(0)
else:
    a0,a1,a2 = sorted(list(set_a))
    if(a.count(a0) == a.count(a1) == a.count(a2))&((a0^a1)==a2):
        print_end(1)
    print_end(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

def solve():
    N = int(input())
    a = list(map(int, input().split()))
    
    if len(set(a)) == 1 and a[0] == 0:
        return 'Yes'
    
    if N % 3 == 0:
        s = list(set(a))
        c = Counter(a)
        if len(s) == 2:
            i = max(c.items(), key=lambda x: x[1])
            j = min(c.items(), key=lambda x: x[1])
            if i[0] ^ j[0] == i[0] and i[1] == (2 * N // 3) and j[1] == (N // 3):
                return 'Yes'
        if len(s) == 3:
            if c[s[0]] == c[s[1]] and c[s[1]] == c[s[2]] and s[0] ^ s[1] == s[2]:
                return 'Yes'
        
    return 'No'

print(solve())

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

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

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

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

from collections import Counter

ac = Counter(a).most_common()

if len(ac) == 3 and ac[0][1] == ac[1][1] == ac[2][1] and ac[0][0] ^ ac[1][0] == ac[2][0]:
    print('Yes')

elif len(ac) == 2 and ac[0][1] == ac[1][1]*2 and ac[0][0] ^ ac[0][0] == ac[1][0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    if c[0] == n:
        print('Yes')
    elif n % 3 == 0 and c[0] == n // 3 and len(set(A)) == 2:
        print('Yes')
    elif n % 3 == 0 and len(set(A)) == 3:
        x, y, z = list(set(A))
        if x ^ y ^ z == 0 and c[x] == c[y] == c[z]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

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

c = {}
for e in a:
    c.setdefault(e, 0)
    c[e] += 1

if len(set(c)) > 3:
    print('No')
    exit()

t = {}
for x, y in product(set(c), repeat=2):
    i = x
    j = y
    t[i] = 1
    if t[i] > c[i]:
        continue
    t.setdefault(j, 0)
    t[j] += 1
    if t[j] > c[j]:
        continue
    for _ in range(N - 2):
        k = i ^ j
        t.setdefault(k, 0)
        t[k] += 1
        c.setdefault(k, 0)
        if t[k] > c[k]:
            j = -1
            break
        i, j = j, k
    if j ^ x == y:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

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

import sys
from collections import Counter
d = Counter(A)

if d[0] == N:
    print("Yes")
    sys.exit()

if d[0] == N // 3:
    for x in d.keys():
        if d[x] == 2 * N // 3:
            print("Yes")
            sys.exit()

third = N // 3
if len(d.keys()) == 3:
    a, b, c = d.keys()
    if d[a] == d[b] and d[b] == d[c]:
        if a ^ b ^ c == 0:
            print("Yes")
            sys.exit()

print("No")

Submission status: Accepted

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

d = Counter()
for x in a:
    d[x] += 1

if d[0] == n:
    print('Yes')
elif len(d.keys()) == 2 and d[0] == n//3:
    print('Yes' if d[0] == n//3 else 'No')
elif len(d.keys()) == 3:
    p, q, r = d.keys()
    if d[p] == d[q] and d[q] == d[r] and p ^ q ^ r == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

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

if n % 3:
    print('Yes' if len(set(a)) == 1 else 'No')
else:
    d = Counter()
    for x in a:
        d[x] += 1
    if len(d.keys()) == 1:
        print('Yes' if d[0] == n else 'No')
    elif len(d.keys()) == 2:
        print('Yes' if d[0] == n//3 else 'No')
    elif len(d.keys()) == 3:
        p, q, r = d.keys()
        if d[p] == d[q] and d[q] == d[r] and p ^ q ^ r == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n = ni()
a = nl()

sa = set(a)
l = len(sa)

if l == 1:
    if a[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(a) % 3 == 0:
    if l == 2:
        if a.count(0) == n // 3:
            print('Yes')
        else:
            print('No')
    elif l == 3:
        if all([a.count(ele) == n // 3 for ele in sa]):
            li = list(sa)
            if li[0] ^ li[1] ^ li[2] == 0:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')