Problem:


Score : 300 points

Problem Statement

Snuke has N hats. The i-th hat has an integer a_i written on it.

There are N camels standing in a circle.
Snuke will put one of his hats on each of these camels.

If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.

The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.

What is XOR?

The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.

Sample Input 2

4
1 2 4 8

Sample Output 2

No

There is no such way to distribute the hats; the answer is No.



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = list(set(a))
x.sort()
if len(x) >= 4:
  print("No")
  exit()
if len(x) == 3:
  if x[0]^x[1] == x[2] and 3*a.count(x[0]) == 3*a.count(x[1]) == 3*a.count(x[2]) == n:
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 2:
  if x[0] == 0 and (2*a.count(x[0]) == 2*a.count(x[1]) == n or 6*a.count(x[0]) == 3*a.count(x[1]) == 2*n):
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 1:
  if x[0] == 0:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
# A.sort()
d = {}
for i in range(N):
    a = A[i]
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
flag = True
if len(d.keys()) == 1:
    if list(d.keys())[0] == 0:
        flag = True
    else:
        flag = False
elif len(d.keys()) == 2:
    keys = list(sorted(list(d.keys())))
    if d[keys[0]] == N // 3:
        flag = True
    else:
        flag = False
elif len(d.keys()) == 3:
    keys = list(d.keys())
    if keys[0] ^ keys[1] ^ keys[2] == 0:
        if d[keys[0]] == d[keys[1]] == d[keys[2]]:
            flag = True
        else:
            flag = False
    else:
        flag = False
else:
    flag = False
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
d = {}
for i in range(N):
    a = A[i]
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
if len(d.keys()) == 1:
    if list(d.keys())[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 2:
    keys = list(sorted(list(d.keys())))
    if d[keys[0]] == N // 3:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 3:
    keys = list(d.keys())
    if keys[0] ^ keys[1] ^ keys[2] == 0:
        if d[keys[0]] == d[keys[1]] == d[keys[2]]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = "Yes"
if N % 3 != 0:
  if len(set(A)) != 1 or list(set(A))[0] != 0:
    ans = "No"
  print(ans)
else:
  if len(set(A)) == 1:
    if list(set(A))[0] != 0:
      ans = "No"
  elif len(set(A)) == 2:
    if A.count(0) != N // 3:
      ans = "No"
  elif len(set(A)) == 3:
    A_s = list(set(A))
    for a in A_s:
      if A.count(a) != N // 3:
        ans = "No"
      elif A_s[0] ^ A_s[1] ^ A_s[2] != 0:
        ans = "No"
  else:
    ans = "No"
  print(ans)

Submission status: Accepted

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

N = int(input())
a = [int(i) for i in input().split()]

from collections import Counter

Count_a = Counter(a)

if len(Count_a) == 1:
    if Count_a[0] == N:
        print("Yes")
    else:
        print("No")

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

elif len(Count_a) == 3 and N % 3 == 0:
    three = list(set(a))
    if three[0] ^ three[1] ^ three[2] == 0:
        for i in range(3):
            if Count_a[three[i]] != N // 3:
                print("No")
                exit()
        print("Yes")
    else:
        print("No")

else:
    print("No")

Submission status: Accepted

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

for i in range(1, N):
    table[a[i]] += 1

ans = [-1]*N
ans[0] = a[0]
for i in range(1, N):
    if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] >= 1:
        if a[0] == 0:
            if table[a[i]] == 1:
                continue
        ans[1] = (a[0] ^ a[i])
        ans[2] = a[i]
        table[ans[1]] -= 1
        table[ans[2]] -= 1
        break

if ans[1] == -1:
    print("No")
    exit(0)

for i in range(3, N):
    if (ans[i-1] ^ ans[i-2]) in table and table[ans[i-1] ^ ans[i-2]] >= 1 and table[ans[i-1] ^ ans[i-2]] >= 1:

        ans[i] = ans[i-1] ^ ans[i-2]
        table[ans[i]] -= 1
    else:
        print("No")
        exit(0)
print("Yes")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・a,b,a+b,a,b,a+b,...
・0,a,a,0,a,a,...
・0,0,0,0,0,0,...
"""

N,*A = map(int,read().split())

def solve(N,A):
    if all(x == 0 for x in A):
        return True
    q,r = divmod(N,3)
    if r:
        return False
    from collections import Counter
    counter = Counter(A)
    n = len(counter)
    if n == 1:
        return False
    if n == 2:
        a,b = counter.keys()
        if a > b:
            a,b = b,a
        if a != 0:
            return False
        # 0,b
        if counter[0] != N//3:
            return False
        return True
    if n == 3:
        a,b,c = counter.keys()
        for x in [a,b,c]:
            if counter[x] != q:
                return False
        return a^b^c == 0

answer = 'Yes' if solve(N,A) else 'No'
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(_) for _ in input().split()]
s = set()
for i in range(N):
    s.add(a[i])
if len(s) == 1 and 0 in s:
    print('Yes')
elif len(s) == 2 and 0 in s:
    if N%3 == 0 and a.count(0) == N//3:
        print('Yes')
    else:
        print('No')
else:
    if N%3 != 0 or len(s) != 3:
        print('No')
    else:
        cnt = []
        for x in s:
            cnt.append(a.count(x))
        if len(set(cnt)) != 1:
            print('No')
        else:
            xor = 0
            for x in s:
                xor ^= x
            if xor == 0:
                print('Yes')
            else:
                print('No')

Submission status: Accepted

Solution code:
from functools import reduce as f;input();print("YNeos"[f(lambda x,y:x^y,map(int,input().split()))>0::2])

Submission status: Accepted

Solution code:
from functools import reduce as f;input();print("YNeos"[f(lambda x,y:x^y,map(int,input().split()))!=0::2])

Submission status: Accepted

Solution code:
from functools import reduce as f;n=int(input());print("YNeos"[f(lambda x,y:x^y,map(int,input().split()))!=0::2])

Submission status: Accepted

Solution code:
from functools import reduce
n = int(input())
l = list(map(int, input().split()))
if reduce((lambda x, y:x ^ y), l) == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from functools import reduce
n = int(input())
l = list(map(int, input().split()))
if n%3:
  if max(l) == 0:
    print("Yes")
  else:
    print("No")
else:
  if reduce((lambda x, y:x ^ y), l) == 0:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
def num2bi(x, k):
  #10進数xを2進数k桁(string)で出力
  out=format(x, '0'+str(k)+'b')
  return out

def f(a, b, c):
  n=len(format(max([a, b, c]), '0b'))
  a=format(a, '0'+str(n)+'b')
  b=format(b, '0'+str(n)+'b')
  c=format(c, '0'+str(n)+'b')
  out=True
  for i in range(n):
    if (a[i]==b[i] and c[i]=='1') or (a[i]!=b[i] and c[i]=='0'):
      out=False
  return out

N=int(input())
a=list(map(int, input().split()))
a.sort()
if sum(a)==0:
  print('Yes')
  exit()
  
if N%3==0 and a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[-1]:
  if f(a[0], a[N//3], a[2*N//3])==True:
    print('Yes')
    exit()
    
print('No')

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

b = list(Counter(a).items())
if sum(a) == 0:
    print("Yes")
    sys.exit()
    
if N % 3 == 0:
    if len(b) != 3:
        if len(b) == 2 and min(b[0][0], b[1][0]) == 0 and min(b[0][1], b[1][1]) == N // 3:
            print("Yes")
            sys.exit()
        print("No")
        sys.exit()
    if b[0][0] ^ b[1][0] ^ b[2][0] != 0 or b[0][1] != N // 3 or b[1][1] != N // 3:
        print("No")
        sys.exit()
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
n_bin = len(bin(max(a_ls))) - 2
a_ls = [bin(a)[2:].zfill(n_bin) for a in a_ls]
cnt = {i : 0 for i in range(n_bin)}
for a in a_ls:
    for i, _a in enumerate(a):
        cnt[i] += _a == "1"
flg = True
if sum(cnt.values()) == 0:
    print("Yes")
elif n % 3 != 0:
    print("No")
else:
    for i in range(n_bin):
        flg &= (cnt[i] == 0 or cnt[i] == n // 3 * 2)
        if not flg:
            break
    if flg:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
data=[]
lst=[a[0]]
num=1
for i in range(1,n):
    if a[i]==a[i-1]:
        num+=1
    else:
        data.append(num)
        lst.append(a[i])
        num=1
data.append(num)
if len(data)==3 and data[0]==data[1]==data[2]:
    if lst[0]^lst[1]==lst[2]:
        print("Yes")
    else:
        print("No")
else:
    if len(data)==1 and lst[0]==0:
        print("Yes")
    elif len(data)==2 and data[0]*2==data[1]:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import Counter as ct
import sys
input = sys.stdin.readline

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

if c[0] == n:
    print("Yes")
elif len(c) == 2 and c[0] * 3 == n:
    print("Yes")
elif len(c) == 3 and len(set(c.values())) == 1:
    a, b, c = c.keys()
    if (a ^ b ^ c) == 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()))
# 条件満たせるパターンは以下の3パターンある
# 全ての数字が0, 数字が2種類あって片方が0かつ0の個数がN//3, 数字が3種類あってx^y^z==0かつN//3個ずつ存在する
if len([a for a in A if a == 0]) == N:
    print("Yes")
    exit()

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

# Nが3の倍数であることが保証された
count = Counter(A)

if len(count.keys()) > 3:
    print("No")
    exit()
elif len(count.keys()) == 3:
    numbers = list(count.keys())
    amounts = list(count.values())
    if numbers[0] ^ numbers[1] ^ numbers[2] == 0 and amounts[0] == N//3 and amounts[1] == N//3 and amounts[2] == N//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
elif len(count.keys()) == 2:
    numbers = list(count.keys())
    numbers.sort()
    amounts = list(count.values())
    if numbers[0] == 0 and count[0] == N//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
print("No")

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a = collections.Counter(a).most_common()
    if len(a) == 1:
        if a[0][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 2:
        if a[1][0] == 0 and a[0][1] == a[1][1] * 2:
            print("Yes")
        else:
            print("No")
    elif len(a) == 3:
        if a[0][0] ^ a[1][0] ^ a[2][0] == 0:
            if a[0][1] == a[1][1] == a[2][1]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if True:
    for i in a[1:]:
      d[i] += 1
    now1,now2 = a[0],0
    for i in a[1:]:
      xor = now1^i
      d[i] -= 1
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = i, xor
        break
      d[i] += 1
      d[xor] += 1        
    else:
      print("No")
      exit()
    for i in range(n-3):
      xor = now1^now2
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = now2, xor
      else:
        print("No")
        exit()
    else:
      if now1^now2 == a[0]:
        print("Yes")
      else:
        print("No")
      exit()

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if all([not i for i in a]):
    print("Yes")
else:
    for i in a[1:]:
      d[i] += 1
    now1,now2 = a[0],0
    ans = [now1]
    for i in a[1:]:
      xor = now1^i
      d[i] -= 1
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = i, xor
        ans.append(now1)
        ans.append(now2)
        break
      d[i] += 1
      d[xor] += 1        
    else:
      print("No")
      exit()
    for i in range(n-3):
      xor = now1^now2
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = now2, xor
        ans.append(now2)
        continue
      else:
        print("No")
        exit()
    else:
      if now1^now2 == a[0]:
        print("Yes")
      else:
        print("No")
      exit()

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if all([not i for i in a]):
  print("Yes")
else:
  if n % 3:
    print("No")
  else:
    for i in a[1:]:
      d[i] += 1
    now1,now2 = a[0],0
    ans = [now1]
    for i in a[1:]:
      xor = now1^i
      d[i] -= 1
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = i, xor
        ans.append(now1)
        ans.append(now2)
        break
      d[i] += 1
      d[xor] += 1        
    else:
      print("No")
      exit()
    for i in range(n-3):
      xor = now1^now2
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = now2, xor
        ans.append(now2)
        continue
      else:
        print("No")
        exit()
    else:
      if now1^now2 == a[0]:
        print("Yes")
      else:
        print("No")
      exit()

Submission status: Accepted

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

    if A.count(0) == N:
        print("Yes")
    elif N % 3 == 0:
        A.sort()
        ans = True
        for i in range(N//3):
            if A[i] ^ A[i+(N//3)] != A[i+(N//3)*2]:
                ans = False
        if ans:
            print("Yes")
        else:
            print("No")
    else:
        print("No")



if __name__ == "__main__":
    main()

Submission status: Accepted

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

if len(b) != 3:
    if sum(a) == 0:
        pass
    elif a.count(max(b)) == 2*n/3 and a.count(0) == n/3:
        pass
    else:
        print("No")
        exit()
else:
    if b[0] ^ b[1] == b[2] and a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
        print("Yes")
        exit()
    else:
        print("No")
        exit()
        
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
if len(set(l))==3:
  h=sorted(list(set(l)),reverse=1)
  ff=len(bin(h[0]))
  p=["0"*(ff-len(bin(s)))+bin(s)[2:] for s in h]
  y=p[0]
  dfg,dgf=p[1],p[2]
  for i in range(ff-2):
    q,w=dfg[i],dgf[i]
    if (q!=w and y[i]=="0") or (q==w and y[i]=="1"):print("No");exit()
  else:
    from collections import Counter as cou
    if len(set(cou(l).values()))==1:print("Yes")
    else:print("No")
elif len(set(l))>=4 or 0 not in set(l):
  print("No")
elif set(l)==set([0]):
  print("Yes")
else:
  if n%3:print("No");exit()
  from collections import Counter as cou
  fl,fll=0,0
  for g,gh in cou(l).items():
    if g==0 and gh==n//3:fl=1
    if g!=0 and gh==2*n//3:fll=1
  print("Yes" if fl and fll else "No")

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(input())
a = list(map(int,input().split()))
a.sort()
YES = 'Yes'
NO = 'No'
if a == [0]*N:
  print(YES)
  sys.exit()
  
if N%3 !=0:
  print(NO)
  sys.exit()
  
counter = Counter(a)
if len(counter) > 3:
  print(NO)
  sys.exit()
elif len(counter) == 3:
  if list(counter.values()) != [N//3,N//3,N//3]:
    print(NO)
  else:
    xor = 0
    for key in counter.keys():
      xor ^= key
    if xor == 0:
      print(YES)
    else:
      print(NO)
  sys.exit()
elif len(counter) == 2:
  if list(counter.keys())[0] == 0 and list(counter.values())[0] == N//3:
    print(YES)
  else:
    print(NO)
  sys.exit()

print(NO)

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a = collections.Counter(a).most_common()
    if len(a) == 1:
        if a[0][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 2:
        if a[0][1] == a[1][1] * 2 and a[1][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 3:
        if a[0][0] ^ a[1][0] ^ a[2][0] == 0 and a[0][1] == a[1][1] == a[2][1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
a=list(map(int, input().split()))
flag=False
c=Counter(a)
if len(c.keys())==1:
  if 0 in c.keys():
    flag=True
elif len(c.keys())==2:
  if 0 in c.keys() and N%3==0:
    if c[0]*3==N:
      flag=True
elif len(c.keys())==3:
  x, y, z=c.keys()
  if c[x]==c[y] and c[y]==c[z] and x^y==z and N%3==0:
    flag=True
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
a=list(map(int, input().split()))
flag=False
c=Counter(a)
if len(c.keys())==1:
  if 0 in c.keys():
    flag=True
elif len(c.keys())==2:
  if 0 in c.keys() and N%3==0:
    if c[0]*3==N:
      flag=True
elif len(c.keys())==3:
  x, y, z=c.keys()
  if c[x]==c[y] and c[y]==c[z] and x^y==z and N%3==0:
    flag=True
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n=int(input())
def xor(x,y):
  bitx=[]
  bity=[]
  num1,num2=x,y
  while num1!=0:
    bitx.append(num1%2)
    num1//=2
  while num2!=0:
    bity.append(num2%2)
    num2//=2
  m=max(len(bitx),len(bity))
  while len(bitx)<m+1:
    bitx.append(0)
  while len(bity)<m+1:
    bity.append(0)
  ans=0
  for i in range(m):
    if bitx[i]!=bity[i]:
      ans+=2**i
  return ans
from collections import defaultdict
import sys
d=defaultdict(int)
l=list(map(int,input().split()))
if n%3!=0:
  for i in range(n):
    if l[i]!=0:
      print("No")
      sys.exit()
  print("Yes")
  sys.exit()
for i in l:
  d[i]+=1
if len(d)>3:
  print("No")
elif len(d)==3:
  b=True
  l1=[]
  for i in d:
    l1.append(i)
    if d[i]!=n/3:
      b=False
  if l1[0]!=xor(l1[1],l1[2]) or l1[1]!=xor(l1[0],l1[2]) or l1[2]!=xor(l1[0],l1[1]):
    b=False
  if b:
    print("Yes")
  else:
    print("No")
elif len(d)==2:
  if d[0]!=n/3:
    print("No")
  else:
    print("Yes")
else:
  if d[0]==n:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
# 2019-11-24 00:33:09(JST)
import sys
import collections

def main():
    n, *a = map(int, sys.stdin.read().split())

    c = collections.Counter(a)

    ans = 'No'
    if 0 in c:
        if c[0] == n:
            ans = 'Yes'
        elif c[0] == n / 3 and len(c) == 2:
            ans = 'Yes'

    else:
        if len(c) == 3:
            for i in c.values():
                if i != n / 3:
                    break
            else:
                b = list(c.keys())
                if b[0] ^ b[1] == b[2]:
                    ans = 'Yes'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
b.sort()
if len(set(a))>=4:
    print('No')
elif b==[0]:
    print('Yes')
elif len(b)==2:
    c_1=a.count(0)
    c_2=a.count(b[1])
    if 2*c_1==c_2:
        print('Yes')
    else:
        print('No')
elif len(b)==3:
    c_1=a.count(b[0])
    c_2=a.count(b[1])
    c_3=a.count(b[2])
    if c_1==c_2==c_3 and b[0]^b[1]^b[2]==0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

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

ans = 0
for a in aaa:
    ans = ans^a
if ans==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

if len(a)%3!=0:
  print("No")
else:
  if len(set(a))==2:
    aa=list(collections.Counter(a).items())
    aa.sort()
    if aa[0][0]==0 and aa[0][1]*2==aa[1][1]:
      print("Yes")
    else:
      print("No")
  elif len(set(a))==3:
    aa=list(collections.Counter(a).items())
    if aa[0][1]==aa[1][1]==aa[2][1] and aa[0][0]^aa[1][0]^aa[2][0]==0:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = Counter(map(int,input().split()))
a = a.items()
a = sorted(a,key=lambda x: x[1],reverse=1)
if len(a) > 3:
  f = 1
elif len(a) == 3:
  b,c,d = a[0][0],a[1][0],a[2][0]
  if b^d != c or c^b != d or d^c != b:
    f = 1
  elif a[0][1] == a[1][1] == a[2][1]:
    f = 0
  else:
    f = 1
elif len(a) == 2:
  b,c,d = a[0][0],a[0][0],a[1][0]
  if b^d != c or c^b != d:
    f = 1
  elif a[0][1] == 2*a[1][1]:
    f = 0
  else:
    f = 1
else:
  b,c,d = a[0][0],a[0][0],a[0][0]
  if b^d != c:
    f = 1
  else:
    f = 0
print('YNeos'[f::2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# A XOR_Circle
n = int(input())
a = list(map(int,input().split()))
dic = {}
a.sort()
for i in a:
    if (i in dic):
        dic[i] += 1
    else:
        dic[i] = 1

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):
    l = list(dic.keys())
    if (l[0]^l[1]^l[2] == 0):
        v = list(dic.values())
        if (v[0] == v[1])&(v[1] == v[2])&(v[2] == n/3):
            print("Yes")
        else:
            print("No")
    else :
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = list(B)
k = len(C)
if N%3==0:
    if k==3 and C[0]^C[1]==C[2] and A.count(C[0])==A.count(C[1]) and A.count(C[0])==A.count(C[2]):
        print("Yes")
    elif k==2:
        C = sorted(C)
        if C[0]==0 and A.count(C[0])==N//3:
            print("Yes")
        else:
            print("No")
    elif k==1 and C[0] == 0:
        print("Yes")
    else:
        print("No")
else:
    if k==1 and C[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()))
a.sort()

tmp=Counter(a)
if len(tmp)>3:
    print("No")
elif len(tmp)==1:
    if not 0 in a:
        print("No")
    else:
        print("Yes")
elif len(tmp)==2:
    if tmp[0]==n//3 :
        print("Yes")
    else:
        print("No")
else:
    values, counts=zip(*tmp.most_common())
    if counts[0]==counts[1]==counts[2] and values[0]^values[1]^values[2]==0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

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

if max(al)==0:
    print("Yes")
    exit()

d = Counter(al)
keys = sorted(d.keys())
if len(keys)==2:
    if n%3==0 and keys[0]==0 and d[keys[0]]*2==d[keys[1]]:
        print("Yes")
        exit()

if len(keys)==3:
    if n%3==0 and keys[0]^keys[1]^keys[2]==0 and d[keys[0]]==d[keys[1]]==d[keys[2]]:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
flag = False
x = len(set(A))
if x == 1 and A[0] == 0:
  flag = True
elif x == 2 and A.count(0) == N // 3:
  flag = True
elif x == 3:
  X = A[0]
  Y = -1
  Z = -1
  i = 1
  while i < N:
    if A[i] != X:
      Y = A[i]
      break
    i += 1
  while i < N:
    if A[i] != X and A[i] != Y:
      Z = A[i]
    i += 1
  if X ^ Y ^ Z == 0 and A.count(X)  == N // 3 and A.count(Y)  == N // 3:
    flag = True
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)
if len(c) == 3:
    x, y, z = c.keys()
    ans = (c[x] == c[y] == c[z]) and (x ^ y == z)
elif len(c) == 2:
    ans = (0 in c) and (c[0] * 3 == N)
elif len(c) == 1:
    ans = 0 in c
else:
    ans = False
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a_list)
c_set = set(a_list)
check = -1
check_list = []

if len(c) == 1:
    if c[0] != 0:
        print("Yes")
        exit()
elif len(c) == 2:
    if c[0] == n//3:
        print("Yes")
        exit()
elif len(c) == 3:
    for i in c_set:
        check_list.append(i)
        if check == -1:
            check = c[i]
        else:
            if check != c[i]:
                print("No")
                exit()
    else:
        res = check_list[0] ^ check_list[1] ^ check_list[2]
        if res == 0:
            print("Yes")
            exit()
        
print("No")

Submission status: Accepted

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

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1
A = list(S.keys())
#print(S)
#print(A)
#print(list(S.keys()))
#print(S.values())
if len(S) ==3:
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")
    else:
        print("No")##漏れ


elif len(S)==2:#一番の漏れ
    if A[0]==0 and S[A[1]] == 2*S[A[0]]:#S[A[0]]==0じゃない
        print("Yes")
    elif A[1]==0 and S[A[0]] == 2*S[A[1]]:
        print("Yes")
    else:
        print("No")


elif len(S)==1:
    if list(S.keys())==[0]:#1.dict_keys、dict_valuesはリストでない 2.keysのほう
        print("Yes")
    else:###
        print("No")
else:
    print("No")