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 defaultdict
import sys

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
a = read_int()
a.sort()

def solve():
    counts = defaultdict(lambda: int())
    keys = []
    for i in range(N):
        if counts[a[i]] == 0:
            keys.append(a[i])
        counts[a[i]] += 1
    if len(counts) == 1 and keys[0] == 0:
        return 'Yes'
    if len(counts) == 2:
        if counts[keys[0]] * 2 == counts[keys[1]] and check_xor(keys[1], keys[0], keys[1]):
            return "Yes"
        elif counts[keys[1]] * 2 == counts[keys[0]] and check_xor(keys[0], keys[1], keys[0]):
            return "Yes"
    if len(counts) == 3:
        if counts[keys[0]] == counts[keys[1]] == counts[keys[2]] and check_xor(*keys):
            return "Yes"
    return "No"

def check_xor(a, b, c):
    return a^c == b

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
tmp=0
for i in range(N):
    tmp=tmp^A[i]
if tmp==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
 
res = "No"
a_set = list(set(a))
 

 
if len(a_set) == 3:
    if a_set[0] ^ a_set[1] == a_set[2]:
        if a.count(a_set[0]) == a.count(a_set[1]) and a.count(a_set[0]) == a.count(a_set[2]):
            res = "Yes"
if len(a_set) == 1:
    if a_set[0] == 0:
        res = "Yes"
if len(a_set) == 2:
    if 0 in a_set:
        if N%3 == 0 and a.count(0) == N/3:
            res = "Yes"
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = set(a)
c = sorted(list(b))
if len(b)==1 and c[0]==0:
  print("Yes")
  exit()
elif n%3!=0:
  print("No")
  exit()
elif len(b)==2:
  if c[0]==0 and a.count(c[0])==n//3 and a.count(c[1])==(n//3)*2:
    print("Yes")
    exit()
elif len(b)==3:
  p, q, r = c[0], c[1], c[2]
  if p^q==r or q^r==p or r^p==q:
    if a.count(c[0])==n//3 and a.count(c[1])==n//3 and a.count(c[2])==n//3:
      print("Yes")
      exit()
print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a = list(map(int,input().split()))
s = set(a)
sl = list(s)
if len(s)==1:
    if sl[0]==0:
        print('Yes')
    else:
        print('No')
elif len(s)==2:
    if N%3==0:
        if sl[0]==0 or sl[1]==0:
            if a.count(0)==N/3:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
elif len(s)==3:
    if N%3==0:
        if sl[0]^sl[1]^sl[2]==0:
            if a.count(sl[0])==N/3 and a.count(sl[1])==N/3:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
A.sort()
if n%3==0:
    n=int(n/3)
    if A[0]==A[n-1] and A[n]==A[2*n-1] and A[2*n]==A[3*n-1] and A[0]^A[n]^A[2*n]==0:
        ans=1
    else:
        ans=0
else:
    if(A[n-1]==0):
        ans=1
    else:
        ans=0
print("Yes" if ans==1 else "No")

Submission status: Accepted

Solution code:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

from collections import Counter

def main():
    N = i2n()
    A = i2nn()
    # 問題を数式化
    #   A[i-1] ^ A[i+1] = A[i] 
    # 移項する
    #   A[i-1] ^ A[i+1] - A[i] = 0
    #   A[i-1] ^ A[i+1] ^ A[i] = 0
    # 漸化式を考える
    #   A[i+1] = A[i-1] ^ A[i] 
    #   A[2] = A[0] ^ A[1] 
    # 漸化式をもう少し考える
    #   A[3] = A[1] ^ A[2] 
    #       A[1] ^ A[2] = A[0] なので
    #   A[3] = A[0]
    #   A[i+3] = A[i]
    # Nが3の倍数でないとき
    #   A[i] = A[j]
    #   A[i] ^ A[i+1] = A[i+2]
    #       A[i] = A[i+1] なので
    #   A[i+2] = 0
    #   よって, Aの要素は全てゼロ
    # Nが3の倍数のとき
    #   Counterを使う
    #       要素数1: 全てゼロ
    #       要素数2: 片方ゼロ, ゼロのカウンタ*2 = もう一方のカウンタ (0,x,x)=>{0:1, x:2}
    #       要素数3: カウント値は全て同じ
    c = Counter(A)
    k = list(c.keys())
    v = list(c.values())
    if len(c) == 1:
        if k[0] == 0:
            print('Yes')
            return
    if len(c) == 2:
        if k[0] == 0 and v[0] * 2 == v[1]:
            print('Yes')
            return
        if k[1] == 0 and v[1] * 2 == v[0]:
            print('Yes')
            return
    if len(c) == 3:
        if k[0] ^ k[1] ^ k[2] == 0:
            if v[0] == v[1] and v[1] == v[2]:
                print('Yes')
                return
    print('No')

main()

Submission status: Accepted

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

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

keys = sorted(d.keys())
if len(keys) == 1 and keys[0] == 0:
    print('Yes')
elif len(keys) == 2 and d[0] * 2 == d[keys[1]]:
    print('Yes')
elif len(keys) == 3 and d[keys[0]] == d[keys[1]] == d[keys[2]] and keys[0] ^ keys[1] ^ keys[2] == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
flag = True
if max(a) == 0:   # 全て0の時は必ず成り立つ
    flag = True
else:
    if N % 3 != 0:   # 全て0でなくて，Nが3の倍数出ない時は成り立たない
        flag = False
    else:
        n = N // 3
        a_set = set(a)
        if len(a_set) == 2:
            count = [] 
            value = []
            for number in a_set:
                count.append(a.count(number))
                value.append(number)
            if value[0] == 0 and count[0] == n and count[1] == n * 2:
                flag = True
            else:
                flag = False
        elif len(a_set) == 3:
            count = []
            value = []
            for number in a_set:
                count.append(a.count(number))
                value.append(number)
            if count[0] == count[1] == count[2]:
                if value[0] ^ value[1] ^ value[2] == 0:
                    flag = True
                else:
                    flag = False
            else:
                flag = False
        else:
            flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

a = list(set(A))

ans = "No"

if a == [0]:
    ans = "Yes"
elif len(a) == 2:
    if (a[0] == 0 or a[1] == 0) and N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] == a[2] and N % 3 == 0 and A.count(a[0]) == A.count(a[1]) == N//3:
        ans = "Yes"

print(ans)

Submission status: Accepted

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

a = list(set(A))

ans = "No"

if a == [0]:
    ans = "Yes"
elif len(a) == 2:
    if N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] == a[2] and N % 3 == 0 and A.count(a[0]) == A.count(a[1]) == N//3:
        ans = "Yes"

print(ans)

Submission status: Accepted

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

a = list(set(A))

ans = "No"

if len(a) == 1:
    if a == [0]:
        ans = "Yes"
elif len(a) == 2:
    if N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] == a[2] and N % 3 == 0 and A.count(a[0]) == A.count(a[1]) == N//3:
        ans = "Yes"

print(ans)

Submission status: Accepted

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

a = list(set(A))

ans = "No"

if len(a) == 1:
    if a == [0]:
        ans = "Yes"
elif len(a) == 2:
    if N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] ^ a[2] == 0 and N % 3 == 0 and (A.count(a[0]),A.count(a[1])) == (N//3,N//3):
        ans = "Yes"

print(ans)

Submission status: Accepted

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

a = list(set(A))

ans = "No"

if len(a) == 1:
    if a == [0]:
        ans = "Yes"
elif len(a) == 2:
    if N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] ^ a[2] == 0 and N % 3 == 0 and (A.count(a[0]),A.count(a[1]),A.count(a[2])) == (N//3,N//3,N//3):
        ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
"""
x -> y -> x^y ->
x -> y -> x^y

3つ周期。
N%3 != 0 x=y=x^yなので、全部0
N%3 == 0 x,y,x^yが同数存在
"""

N = int(input())
As = list(map(int, input().split()))
numset = sorted(list(set(As)))
n = len(numset)
if n == 1:
    if sum(As) == 0: print("Yes")
    else:print("No")
elif n == 2:
    n1 = As.count(numset[0])
    n2 = As.count(numset[1])
    if 2*n1 == n2 and numset[0] == 0: print("Yes")
    else:print("No")
elif n == 3:
    n1 = As.count(numset[0])
    n2 = As.count(numset[1])
    n3 = As.count(numset[2])
    if n1 == n2 == n3 and (numset[0]^numset[1]^numset[2])==0: print("Yes")
    else: print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]
ct = Counter(a).most_common()
num = len(ct)

if num == 1:
	print('Yes' if ct[0][0] == 0 else 'No')
elif num == 2:
	if N % 3 == 0:
		if ct[0][0] != 0 and ct[0][1] == 2*N//3:
			if ct[1][0] == 0 and ct[1][1] == N//3:
				print('Yes')
				sys.exit()
	print('No')
elif num == 3:
	if N % 3 == 0:
		if ct[0][1] == ct[1][1] == ct[2][1]:
			if ct[0][0]^ct[1][0]^ct[2][0] == 0:
				print('Yes')
				sys.exit()
		
	print('No')
else:
	print('No')

Submission status: Accepted

Solution code:
import sys
from collections import Counter

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    c = Counter(A)
    # All caps are 0.
    if 0 in c and len(c) == 1:
        return 'Yes'

    # N/3 '0', and 2N/3 'non-zero'.
    if 0 in c and len(c) == 2:
        v0 = c[0]
        for k, v in c.items():
            if k != 0 and v == 2 * v0:
                return 'Yes'

    # Three caps.
    if len(c) == 3:
        x, y, z = tuple(c.keys())
        if (x ^ y) == z and c[x] == c[y] == c[z]:
            return 'Yes'

    return 'No'


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

Submission status: Accepted

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

tmp = 0
for data in a:
    tmp = tmp ^ data

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

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
t=N//3
ans="No"
if all(a==0 for a in A):
  ans="Yes"
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:t]):
    ans="Yes"     
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==t and A.count(AA[t])==t:
    if AA[0]^AA[t]==AA[2*t] and AA[t]^AA[2*t]==AA[0] and AA[2*t]^AA[0]==AA[t]:
      ans="Yes"   
print(ans)

Submission status: Accepted

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

cnt=[0]*30
n=int(input())
a=[int(i) for i in input().split()]
for i in a:
    x=(bin(i)[2:])[::-1]
    for j,k in enumerate(x):
        if k=="1":
            cnt[j]=(cnt[j]+1)%2

print("No" if any(cnt) else "Yes")

Submission status: Accepted

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

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3:
        ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        if l==3:
            a,b,c = B
            l,m,n = (A.count(x) for x in (a,b,c))
        if l==2:
            a,b = B
            l,m = (A.count(x) for x in (a,b))
            if l>=m:
                c=a
                n=l//2
                l-=n
            else:
                c=b
                n=m//2
                m-=n
        ans = ans and (l==m==n==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
# ACするけど不正解のやつ

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

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

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
ans="No"

#文字が全部0
if all(a==0 for a in A):
  ans="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    ans="Yes"

#abc,abc...,abcという並びに出来て互いに排他的論理和
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if AA[0]^AA[third]==AA[2*third] and \
    AA[third]^AA[2*third]==AA[0] and \
    AA[2*third]^AA[0]==AA[third]:
      ans="Yes"   
print(ans)

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
ans="No"
if all(a==0 for a in A):
  ans="Yes"
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    ans="Yes"     
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if AA[0]^AA[third]==AA[2*third] and \
    AA[third]^AA[2*third]==AA[0] and \
    AA[2*third]^AA[0]==AA[third]:
      ans="Yes"   
print(ans)

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

if all(a==0 for a in A):
  answer="Yes"

elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    answer="Yes"
     
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)

Submission status: Accepted

Solution code:
N = input()
xor = 0
for i in map(int, input().split()):
    xor ^= i
print(xor == 0 and 'Yes' or 'No')

Submission status: Accepted

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

c = Counter(a)
keys = sorted(list(c.keys()))
values = sorted(list(c.values()))
if len(c) == 1 and c[0] == N:
    print("Yes")
    exit()
if N % 3 != 0:
    print("No")
elif len(c) == 2 and 0 in keys and c[0] == N//3:
    print("Yes")
elif len(c) == 3 and values[0] == values[1] == values[2] == N//3 and keys[0] ^ keys[1] ^ keys[2] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ret = 'No'
c = Counter(A)
if all([i == 0 for i in c]):
    ret = 'Yes'
else:
    v = set(list([i[1] for i in c.items()]))
    if len(c) == 3 and all([i == N/3 for i in v]):
        c = list(c)
        if c[0] ^ c[1] == c[2]:
            ret = 'Yes'
    elif len(c) == 2 and 0 in c:
        for i in c.items():
            if i[0] == 0 and i[1] == N/3:
                ret = 'Yes'

print(ret)

Submission status: Accepted

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

def all_zero(a):
    for e in a:
        if e != 0:
            return False
    return True

def three_mod_same(a):
    counts = {}
    for e in a:
        if e not in counts:
            counts[e] = 1
        else:
            counts[e] += 1

    for v in counts.values():
        if v != len(a) // 3:
            return False
    return True

def two_elem_one_zero(a):
    if len(set(a)) != 2:
        return False
    counts = {}
    for e in a:
        if e not in counts:
            counts[e] = 1
        else:
            counts[e] += 1
            
    for key, v in counts.items():
        if key == 0:
            if v != len(a) // 3:
                return False
        else:
            if v != (len(a) // 3) * 2:
                return False
    return True

if len(set(a)) != 3:
    if all_zero(a) or ((len(a) % 3 == 0) and two_elem_one_zero(a)):
        print("Yes")
    else:
        print("No")
else:
    p = itertools.permutations(list(set(a)), 3)
    yes = False
    for permed_a in p:            
        good_perm = True
        for i in range(3):
            if permed_a[(i + 1) % 3] != (permed_a[i] ^ permed_a[(i + 2) % 3]):
                good_perm = False
                break
        if good_perm:
            yes = True
            break
    if not yes:
        print("No")
    else:
        if three_mod_same(a):
            print("Yes")
        else:
            print("No")

Submission status: Accepted

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

tmp = set()
for a in a_list:
    tmp.add(a)

if a_list.count(0) == N:
    print("Yes")
else:
    if len(tmp) == 2 and a_list.count(0) == N // 3:
        print("Yes")
    elif len(tmp) == 3 and a_list.count(0) == 0:
        b = list(tmp)
        if b[0] ^ b[1] == b[2] and a_list.count(b[0]) == N // 3 \
                and a_list.count(b[1]) == N // 3 and a_list.count(b[2]) == N // 3:
            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()))
da = Counter(a)


if 0 in da and da[0]==N:
  print('Yes')
elif N%3!=0:
  print('No')
elif len(da)==2 and 0 in da and da[0]==N/3:
  print('Yes')
elif len(da)==3:
  x, y, z = da.keys()
  if (x^y==z) and da[x]==N/3 and da[y]==N/3:
    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()))


def main():
    if all(map(lambda e: e == 0, a)):
        print('Yes')
        return

    if n % 3 != 0:
        print('No')
        return

    count = dict(Counter(a))
    keys = list(count.keys())
    values = list(count.values())
    # a, b, c a^b^c=0
    if len(count) == 3:
        if values[0] == values[1] and values[1] == values[2] and (keys[0] ^ keys[1] ^ keys[2]) == 0:
            print('Yes')
        else:
            print('No')
    # a, a, 0 a^b^c=0
    elif len(count) == 2:
        if 0 not in count:
            print('No')
        elif (2 * count[0]) == max(values):
            print('Yes')
        else:
            print('No')
    # 0, 0, 0 -> L.9
    else:
        print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N, *a = map(int, open(0).read().split())

cnt = 0
for v in set(a):
    cnt ^= v

ctr = Counter(a)
flg1 = sum(a) == 0
flg2 = len(ctr) == 2 and ctr[0] == N // 3
flg3 = cnt == 0 and len(ctr) == 3 and all(v == N // 3 for v in ctr.values())
print('Yes' if flg1 or flg2 or flg3 else 'No')

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
if lst[0] == 0 and lst[N-1] == 0:
    print ('Yes')
    exit()
if N%3 != 0:
    print ('No')
    exit()

if lst[0] ^ lst[N//3] != lst[(N//3) * 2]:
    print ('No')
    exit()

for i in range(1, N//3):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()

for i in range(1 + N//3, (N//3) * 2):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()

for i in range(1 + (N//3) * 2, (N//3) * 3):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()
print ('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
from functools import reduce

n = int(input())

camels = list(map(int, input().split()))

# 全ての帽子に書かれた数が 0
if all(map(lambda x: x == 0, camels)):
    print('Yes')
# x が書かれた帽子が 2N/3枚、0 が書かれた数が N/3 枚
elif n % 3 == 0 and len(set(camels)) == 2 and camels.count(0) == n // 3:
    print('Yes')
# x ⊕ y ⊕ z = 0 が成立するような 3 つの相異なる整数 x, y, z が書かれた帽子がそれぞれ N/3 枚
elif n % 3 == 0 and len(set(camels)) == 3 \
        and reduce(lambda x, y: x ^ y, set(camels)) == 0 \
        and camels.count(sorted(set(camels))[0]) == n // 3 \
        and camels.count(sorted(set(camels))[1]) == n // 3:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

bits = [0 for x in range(len(bin(max(A))[2:]))]
for i in range(len(A)):
  ptr = 0
  while A[i] > 0:
    bits[ptr] += A[i] % 2
    A[i] >>= 1
    ptr += 1
for i in range(len(bits)):
  if bits[i] % 2 == 1:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:
# coding: utf-8
from functools import reduce

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

if reduce(lambda x, y: x ^ y, camels) == 0:
    print('Yes')
else:
  print('No')

Submission status: Accepted

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

c = collections.Counter(a)
key = list(c.keys())
if (c[0] == n or (len(key)==2 and c[0] == n/3) or (len(key)==3 and (key[0] ^ key[1] ^ key[2] == 0) and (c[key[0]] == c[key[1]] == c[key[2]]))):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_left
from collections import Counter
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, a: "List[int]"):
    cnt = Counter(a)
    v = list(cnt.values())
    b = list(cnt.keys())
    if len(cnt) == 3:
        if all([x == v[0] for x in v]):
            if b[0] ^ b[1] == b[2] or b[0] ^ b[2] == b[1]:
                yes()
                return
    elif len(cnt) == 2:
        if b[0] != 0:
            b[1], b[0] = b[0], b[1]
        if b[0] == 0 and cnt[b[1]] == cnt[b[0]]*2:
            yes()
            return

    elif len(cnt) == 1:
        if b[0] == 0:
            yes()
            return

    no()
    return

    # print(*keta, sep="\n")
    # def solve(N: int, a: "List[int]"):
    #     a.sort()
    #     used = Counter(a)
    #     used_orig = used.copy()
    #     x = [a[0]]
    #     used[0] -= 1

    #     # print("first, ", a[0])
    #     # 2番目の帽子を全探索
    #     for i in range(1, N):
    #         # print("2nd, ", a[i])
    #         x.append(a[i])
    #         used[i] -= 1
    #         for j in range(2, N):
    #             cand = x[-1] ^ x[-2]
    #             # print("cand, ", cand)
    #             pl = bisect_left(a, cand)
    #             if pl >= len(a):
    #                 break
    #             if cand == a[pl] and used[cand] > 0:
    #                 x.append(cand)
    #                 used[pl] -= 1
    #             else:
    #                 break
    #         else:
    #             yes()
    #             print(x)
    #             print(used)
    #             return
    #         x = [a[0]]
    #         used = used_orig.copy()
    #     no()
    #     return


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())
a=list(map(int, input().split())) 
count=0
a.sort()

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

Submission status: Accepted

Solution code:
import collections, itertools
N = int(input())
A = [int(_) for _ in input().split()]
C = sorted(collections.Counter(A).most_common(), key=lambda xs: -xs[1])
f = 0
if len(C) == 1:
    a, la = C[0]
    #a^a^a^
    if a == 0:
        f = 1
elif len(C) == 2:
    a, la = C[0]
    b, lb = C[1]
    #a^b^(a^b)^a^b^(a^b)^
    if la == lb * 2 and b == 0:
        f = 1
elif len(C) == 3:
    a, la = C[0]
    b, lb = C[1]
    c, lc = C[2]
    #x^y^(x^y)^x^y^(x^y)^
    if la == lb == lc and a ^ b == c:
        f = 1
if f:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import collections, itertools
N = int(input())
A = [int(_) for _ in input().split()]
C = sorted(collections.Counter(A).most_common(), key=lambda xs: -xs[1])
f = 0
if len(C) == 1:
    a, la = C[0]
    #a^a^a^
    if a ^ a == a:
        f = 1
elif len(C) == 2:
    a, la = C[0]
    b, lb = C[1]
    #a^b^a^b^a^b^
    if la == lb and a ^ b == a and b ^ a == b:
        f = 1
    #b^a^a^b^a^a^
    if la == lb * 2 and b ^ a == a and a ^ a == b:
        f = 1
elif len(C) == 3:
    a, la = C[0]
    b, lb = C[1]
    c, lc = C[2]
    #x^y^(x^y)^x^y^(x^y)^
    if la == lb == lc and any(
            x ^ y == z for x, y, z in itertools.permutations((a, b, c))):
        f = 1
    #x^y^(x^y)^x^y^
    if la == lb == lc + 1:
        if any(x ^ y == c == x and y ^ c == x and c ^ x == y
               for x, y in ((a, b), (b, a))):
            f = 1
    #(y^z)^y^z^(y^z)^y^z^(y^z)^
    if lb == lc == la - 1:
        if any(a ^ y == z and y ^ z == a and z ^ a == y == a
               for y, z in ((b, c), (c, b))):
            f = 1
if f:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
R = lambda: map(int, input().split())
 
n = int(input())
if n % 3:
    ans = 'YNeos'[any(R())::2]
else:
    a = sorted(R())
    m = n // 3
    if a[0] ^ a[m] ^ a[2 * m] or any(len(set(a[i:i + m])) > 1 for i in range(0, n, m)):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
R = lambda: map(int, input().split())
 
n = int(input())
if n % 3:
    ans = 'YNeos'[any(R())::2]
else:
    a = sorted(R())
    m = n // 3
    if a[0] ^ a[m] ^ a[2 * m]:
        ans = 'No'
    elif any(len(set(a[i:i + m])) > 1 for i in range(0, n, m)):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
R = lambda: map(int, input().split())
 
n = int(input())
if n % 3:
    ans = 'YNeos'[any(R())::2]
else:
    a = sorted(R())
    m = n // 3
    if a[0] ^ a[m] ^ a[2 * m]:
        ans = 'No'
    elif any(a[i] != a[i - 1] for i in range(1, n) if m != i != 2 * m):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from operator import xor

R = lambda: map(int, input().split())
 
n = int(input())
if n % 3:
    ans = 'YNeos'[any(R())::2]
else:
    a = sorted(R())
    m = n // 3
    if reduce(xor, a[::m]):
        ans = 'No'
    elif any(len(set(a[i:i + m])) > 1 for i in range(0, n, m)):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
R = lambda: map(int, input().split())
 
n = int(input())
if n % 3:
    ans = 'YNeos'[any(R())::2]
else:
    a = sorted(R())
    m = n // 3
    if a[0] ^ a[m] ^ a[2 * m]:
        ans = 'No'
    elif any(len(set(a[i:i + m])) > 1 for i in range(0, n, m)):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
d={}
for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
a=0
if len(d)==1 and 0 in d:
    a=1
elif len(d)==2:
    k=sorted(d.keys(),key=lambda x:d[x])
    if k[1]^k[1]==k[0] and d[k[0]]*2==d[k[1]]:
        a=1
elif len(d)==3:
    k=list(d.keys())
    if k[0]^k[1]==k[2] and d[k[0]]==d[k[1]]==d[k[2]]:
        a=1
print(['No','Yes'][a])