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:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    from collections import Counter
    c = Counter(A)
    if 0 in c.keys() and c[0] == N:
        return print("Yes")
    elif N % 3 == 0 and 0 in c.keys() and c[0] == N//3 and\
            len(c.keys()) == 2:
        return print("Yes")
    elif N % 3 == 0 and len(c.keys()) == 3 and \
            all(N//3 == v for v in c.values()):
        ans = 0
        for k in c.keys():
            ans ^= k
        if ans != 0:
            return print("No")
        else:
            return print("Yes")
    else:
        return print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main(): 
    n = int(input())
    a = [ int(x) for x in input().split() ]

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

    if d.get(0, 0) == n:
        print("Yes")
        return 0
    L = sorted(list(d.items()))
    if n % 3 == 0 and len(L) == 2 and (L[0][0] == 0 and L[0][1] == n//3) and L[1][1] == n//3*2:
        print("Yes")
        return 0
    
    if n % 3 == 0 and len(L) == 3 and L[0][1] == n//3 and L[1][1] == n//3 and L[2][1] == n//3 and L[0][0]^L[1][0]^L[2][0] == 0:
        print("Yes")
        return 0

    print("No")

main()

Submission status: Accepted

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

if sum(a) == 0:
    print("Yes")
elif n % 3 != 0:
    print("No")
else:
    can_put_on = False
    c = Counter(a)
    if c[0] == n//3 and len(c) == 2:
        can_put_on = True
    if len(c) == 3:
        s = 0
        for k in c.keys():
            s ^= k
        if s == 0 and all(v == n//3 for v in c.values()):
            can_put_on = True

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
B=list(set(A))

if len(B)==3:
    if B[0]^B[1]==B[2]:
        if A.count(B[0])==A.count(B[1]) and A.count(B[1])==A.count(B[2]):
            print("Yes")
            exit()
elif len(B)==2:
    if 2*A.count(B[0])==A.count(B[1]):
        print("Yes")
        exit()
elif len(B)==1:
    if B[0]==0:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
from sys import stdin
from collections import Counter
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    a=list(map(int,readline().split()))

    c=Counter(a)
    c=sorted(c.items())
    if N%3!=0:  #Nが3の倍数じゃない時
        if len(c)==1 and c[0][0]==0:
            print("Yes")
        else:
            print("No")

    elif N%3==0:  #Nが3の倍数の時
        if len(c)==1 and c[0][0]==0:
            print("Yes")
        elif len(c)==2 and c[0][0]==0 and c[0][1]==N//3:
            print("Yes")
        elif len(c)==3 and c[0][1]==N//3 and c[1][1]==N//3 and c[2][1]==N//3 and c[0][0]^c[1][0]^c[2][0]==0:
            print("Yes")
        else:
            print("No")

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
b = len(c.keys())

def check():
    if 0 in c.keys():
        if b==1 or (b==2 and c[0]==N//3):
            return True
    elif b==3:
        s, t, u = c.keys()
        if c[s]//3==c[t]//3==c[u]//3 and s^t^u==0:
            return True
    return False

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
*a, = map(int, input().split())
c = Counter(a)
b = len(c.keys())

def check():
    if 0 in c.keys():
        if b==1 or (b==2 and c[0]==N//3):
            return True
    elif b==3:
        s, t, u = c.keys()
        if s^t^u==0 and c[s]==c[t]==c[u]:
            return True
    return False

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
*a, = map(int, input().split())
c = Counter(a)
used = set(c.keys())
size = len(used)

def check():
    if 0 in used:
        if size==1 or (size==2 and c[0]==N//3):
            return True
    elif size==3:
        s, t, u = used
        if s^t^u==0 and c[s]==c[t]==c[u]:
            return True
    return False

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
*a, = map(int, input().split())
c = Counter(a)
used = set(c.keys())
size = len(used)

if 0 in used and size==1:
    print("Yes")
elif 0 in used and size==2 and c[0]==N//3:
    print("Yes")
elif size==3:
    s, t, u = used.pop(), used.pop(), used.pop()
    if s^t^u==0 and c[s]==c[t]==c[u]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

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

if s == 0:
  ans = 'Yes'
else:
  ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    num = len(set(a))
    aset=set(a)

    if sum(a) == 0:
        print('Yes')
        return
    # if n % 3 != 0:
        # print('No')
        # return
    if len(cnt.most_common()) == 3:
        a1, a2, a3 = aset
        if cnt.most_common()[0][1] == cnt.most_common()[1][1] == cnt.most_common()[2][1]  and a1 ^ a2 == a3:
            # print(cnt.most_common())
            print('Yes')
            return

    if len(cnt.most_common()) == 2:

        tmp_min = cnt.most_common()[1][1]
        tmp_max = cnt.most_common()[0][1]
        if 3 * tmp_min == n and int(cnt.most_common()[1][0]) == 0:
            print('Yes')
            return
    print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if s == 0:
  ans = 'Yes'
else:
  ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from operator import xor
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
C=Counter(A)
if len(C)==1:
    k=list(C.keys())[0]
    print("YNeos"[k!=0::2])
elif len(C)==2:
    (k1,v1),(k2,v2)=C.most_common(2)
    print("YNeos"[not(v2*2==v1 and k1^k1^k2==0)::2])
else:
    print("YNeos"[not(len(C)==3 and reduce(xor, C.keys())==0 and len(set(C.values()))==1)::2])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
a = A[0]
for i in range(1, n):
  a ^= A[i]
c = Counter(A)
if a == 0:
  if len(c) == 3 and all(v == n // 3 for v in c.values()):
    print('Yes')
  elif len(c) == 2 and c.get(0) > 0 and n - c[0] == 2 * c[0]: 
    print('Yes')
  elif len(c) == 1 and c.get(0) == n:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Submission status: Accepted

Solution code:
# 1,2,3
# 01
# 10
# 11

# 両隣のXORと一致->両隣と自分をXORすると0になる
# 連続した3つのXORが0になる
# a,b,c,dでaとdは同じになる

# 円環になるには、
# a,b,c,a,b,cというセットになり、
# 且つa,b,cのXORが0であればよい

# もしくは全部0

# もしくはa,a,0,a,a,0

n=int(input())
a=list(map(int,input().split()))
dis=set(a)
if a[0]==0 and len(dis)==1:
  print("Yes")
  exit(0)
if len(dis)==3:
  xor=0
  cur=0
  for c in dis:
    xor^=c
    cnt=a.count(c)
    if cur==0:
      cur=cnt
    else:
      if cnt!=cur:
        print("No")
        exit(0)
  if xor==0:
    print("Yes")
    exit(0)
if len(dis)==2:
  if a.count(0)==n//3 and n%3==0:
    print("Yes")
    exit(0)
print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby

N=int(input())
A=list(map(int,input().split()))
A.sort()
X=groupby(A)
data=[]
for key,group in X:
    g=len(list(group))
    data.append([key,g])
if len(data)==1 and data[0][0]==0:
    print('Yes')
elif N%3!=0:
    print('No')
else:
    if len(data)>3:
        print('No')
    elif len(data)==1:
        if data[0][0]==0:
            print('Yes')
        else:
            print('No')
    elif len(data)==2:
        if data[0][0]==0 and data[0][1]==N//3:
            print('Yes')
        else:
            print('No')
    else:
        if data[0][1]!=N//3 or data[1][1]!=N//3 or data[2][1]!=N//3:
            print('No')
        else:
            if data[0][0]^data[1][0]^data[2][0]!=0:
                print('No')
            else:
                print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
a_set = set(a)
 
if len(a_set) == 1:
    if sum(a_set) == 0:
        print('Yes')
    else:
        print('No')
elif len(a_set) == 2:
    x, y = sorted(a_set)
    if x == 0:
        if a.count(x) * 3 == n:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(a_set) == 3:
    x, y, z = a_set
    if a.count(x) == a.count(y) and a.count(y) == a.count(z):
        if x ^ y == z:
            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()))

a_set = set(a)

if len(a_set) == 1:
    if sum(a_set) == 0:
        print('Yes')
    else:
        print('No')
elif len(a_set) == 2:
    x, y = sorted(a_set)
    if x == 0:
        if a.count(x) * 3 == n:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(a_set) == 3:
    x, y, z = a_set
    if a.count(x) == a.count(y) and a.count(y) == a.count(z):
        if x ^ y == z:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
def solve(n, a):
    p = 0
    for x in a:
        p ^= x
    return "Yes" if p == 0 else "No"

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
chk=arr[0]
for i in range(1,n):
    chk = chk^arr[i]    

arr.sort()
a0=arr.count(arr[0])
a1=arr.count(arr[-1])

if (len(list(set(arr)))==1 and list(set(arr))[0]==0) or chk==0 or (arr[0]==0 and a0==n//3 and a1==2*n//3):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

A_set=set(A)
A_lst=list(A_set)

# すべてが0のとき
if sum(A_set)==0 and len(A_set)==1:
    print('Yes')
    exit()

# x…2N/3,0…N/3
if len(A_set)==2 and A_lst.count(0)==1 and len(A)%3==0:
    cnt=0
    for i in range(N):
        if A[i]==0:
            cnt+=1
    if cnt==N//3:
        print('Yes')
    else:
        print('No')
    exit()

# x^y^z==0
if len(A_set)==3 and A_lst[0]^A_lst[1]^A_lst[2]==0 and len(A)%3==0:
    cnt_x,cnt_y,cnt_z=0,0,0
    x,y,z=A_lst[0],A_lst[1],A_lst[2]
    for i in range(N):
        if A[i]==x:
            cnt_x+=1
            continue
        if A[i]==y:
            cnt_y+=1
            continue
        if A[i]==z:
            cnt_z+=1
    if cnt_x==cnt_y==cnt_z:
        print('Yes')
    else:
        print('No')
    exit()

# それ以外
print('No')

Submission status: Accepted

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

if c[0] == n:
    flag = True
elif c[0] == n/3 and len(c) == 2:
    flag = True
else:
    s = 0
    for num in c:
        s ^= num
        if c[num] != n/3: break
    else:
        if s == 0: flag = True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from collections import Counter

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

    if n % 3 == 0:
        ctr = Counter(a)
        if len(ctr) == 1:
            print('Yes' if 0 in ctr else 'No')
            return

        elif len(ctr) == 2:
            print('Yes' if ctr[0] == n // 3 else 'No')
            return

        elif len(ctr) == 3:
            x = 0
            p = None
            for k, v in ctr.items():
                if p is None:
                    p = v
                elif p != v:
                    print('No')
                    return
                x ^= k
            print('Yes' if x == 0 else 'No')
            return

        else:
            print('No')
            return

    else:
        print('Yes' if all(map(lambda x: x == 0, a)) else 'No')
        return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    X = A[1]
    for i in range(2, N):
        X = X ^ A[i]
    print("YNeos "[X != A[0]::2])
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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


from collections import defaultdict
dic = {}

for a in al:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
if 0 in dic:
    if dic[0] == n:
        print("Yes")
        exit()
if 0 in dic:
    if n % 3 == 0:
        if dic[0] == 1 * n // 3:
            print("Yes")
            exit()
if n % 3 != 0:
    print("No")
    exit()
else:
    if len(dic) == 3:
        if max(dic.values()) == n // 3:
            a = 0
            for i in dic:
                a ^= i
            if a == 0:
                print("Yes")
                exit()
print("No")

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))
if len(lin) == 1 and lin[0][1] == n and lin[0][0] == 0:
    print("Yes")
elif n%3 != 0:
    print("No")
elif len(lin) == 2:
    lin.sort()
    if lin[0][1] == n//3:
        print("Yes")
    else:
        print("No")
elif len(lin) == 3:
    if lin[0][1] == lin[1][1] == lin[2][1] and lin[0][0]^lin[1][0]^lin[2][0] == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

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

res=0
a_set=set(a)

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

if n % 3 ==0:
    if res==0:
        print("Yes")
        exit()
else:
    if len(a_set) ==1:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

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

b = list(set(a))

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

Submission status: Accepted

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

setA = set(A)

if A.count(0) == N:
    print('Yes')
elif len(setA) == 2 and A.count(0) == N / 3:
    print('Yes')
elif len(setA) == 3:
    setA = list(setA)
    x = setA[0]
    y = setA[1]
    z = setA[2]
    if x ^ y ^ z == 0 and A.count(x) == N / 3 and A.count(y) == N / 3:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int,input().split()))
l_unique = sorted(list(set(lst)))

flg = False
if len(l_unique)==1:
    x = l_unique[0]
    if x==0:
        flg = True
elif len(l_unique) == 2:
    x,y = l_unique[0], l_unique[1]
    if x==0 and n%3==0:
        num = n//3
        if lst.count(x)==num and lst.count(y)==2*num:
            flg = True
elif len(l_unique) == 3:
    x,y,z = l_unique[0], l_unique[1], l_unique[2]
    if n%3 == 0:
        num = n//3
        if lst.count(x)==num and lst.count(y)==num and lst.count(z)==num:
            if (x^y^z)==0:
                flg = True
print('Yes' if flg else 'No')

Submission status: Accepted

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


def xor_circle(N, A):
    if sum(A) == 0:
        return "Yes"
    if N % 3 != 0:
        return "No"

    B = Counter(A)
    if len(B) == 3:
        a, b, c = B.keys()
        Na, Nb, Nc = B.values()
        if a ^ b ^ c == 0 and Na == Nb == Nc:
            return "Yes"
        else:
            return "No"
    elif len(B) == 2:
        a, b = B.keys()
        Na, Nb = B.values()
        if a == 0 and 2*Na == Nb:
            return "Yes"
        elif b == 0 and Na == 2*Nb:
            return "Yes"
        else:
            return "No"
    else:
        return "No"


ans = xor_circle(N, A)
print(ans)

Submission status: Accepted

Solution code:
# A - XOR Circle
from collections import Counter as ct
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:
N = int(input())
alist = list(map(int, input().split()))

ans = alist[0] ^ alist[1]
for a in alist[2:]:
    ans ^= a
if ans == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

# a[0]^a[1]^a[2] == 0
# a[1]^a[2]^a[3] == 0
# すなわち a[0] == a[3] と出来れば良い

# 1)すべて0
# 2) ある値が2n/3, 0がn/3
# 3) 3つの値がそれぞれn/3ずつ
b = list(set(a))
kind = len(b)
if kind == 1 and a[0] == 0:
    print('Yes')
    exit()
elif kind == 2 and a.count(0) == n//3 and n % 3 == 0:
    print('Yes')
    exit()
elif kind == 3:
    if a.count(b[0]) == a.count(b[1]) == a.count(b[2]) == n/3 and b[0] ^ b[1] ^ b[2] == 0:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = {}
flag = 0
ke = []
for i in range(N):
    if a[i] in b:
        b[a[i]] += 1
    else:
        b[a[i]] = 1

if 0 in b:
    if b[0] == N:
        flag = 1

if len(b) == 2:    
    for key in b:
        ke.append(key)  
    if 0 in b:
        if b[ke[1]] / b[0] == 2 or b[ke[0]] / b[0] == 2:
            flag = 1

if len(b) == 3:
    for key in b.keys():
        ke.append(key)

    if b[ke[0]] == b[ke[1]] and b[ke[1]] == b[ke[2]]:
        if ke[0] ^ ke[1] == ke[2] or ke[1] ^ ke[2] == ke[0] or ke[0] ^ ke[2] == ke[1]:
            flag = 1

if flag == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# coding: utf-8
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
k = list(cnt.keys())
k.sort()
if len(k) == 1:
    if k[0] == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 2:
    if cnt[k[0]] == N // 3 and N % 3 == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 3:
    if cnt[k[0]] == cnt[k[1]] == cnt[k[2]] and k[0] ^ k[1] == k[2]:
        print("Yes")
    else:
        print("No")
    exit()
else:
    print("No")
    exit()

Submission status: Accepted

Solution code:
import collections as c
import sys

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

A = c.Counter(a)

if list(A.keys()) == [0]:
	print("Yes")
	sys.exit()

if len(A.keys()) == 2:
	if 0 not in A.keys():
		print("No")
		sys.exit()
	else:
		if list(A.values())[0]*2 == list(A.values())[1]:
			print("Yes")
			sys.exit()
		else:
			print("No")
			sys.exit()

if len(A.keys()) != 3:
	print("No")
	sys.exit()

x,y,z = A.keys()
if x^y != z:
	print("No")
	sys.exit()

x,y,z = A.values()
if x == y == z:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
if(len(set(a))==1 and a[0]==0):
    print("Yes")
elif(n%3!=0):
    print("No")
else:
    seta=list(set(a))
    nums=len(set(a))
    if(nums>3):
        print("No")
    elif(nums==3):
        if(a.count(seta[0])==n//3 and a.count(seta[1])==n//3 and a.count(seta[2]) and (seta[0] ^ seta[1] ^ seta[2] == 0)):
            print("Yes")
        else:
            print("No")
    elif(nums==2):
        seta.sort()
        if(seta[0]==0 and a.count(seta[0])==n//3):
            print("Yes")
        else:
            print("No")
    elif(nums==1):
        if(seta[0]==0):
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    c = collections.Counter(a)
    if len(c) > 3:
        return "No"

    k = list(c.keys())
    def f(t):
        for i in range(n-2):
            u = t[i] ^ t[i+1]
            t.append(u)
        if t[0] ^ t[-2] != t[-1] or t[-1] ^ t[1] != t[0]:
            return False
        d = collections.Counter(t)
        if c != d:
            return False
        return True

    for g in k:
        for h in k:
            if f([g,h]):
                return 'Yes'

    return 'No'


print(main())

Submission status: Accepted

Solution code:
import collections
import itertools


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

def binbin(a,b,c):
    maxlen=max(len(bin(a)[2:]),len(bin(b)[2:]),len(bin(c)[2:]))
    data2={"x":(maxlen-len(bin(a)[2:]))*"0"+bin(a)[2:],"y":(maxlen-len(bin(b)[2:]))*"0"+bin(b)[2:],"z":(maxlen-len(bin(c)[2:]))*"0"+bin(c)[2:]}

    length=len(data2["x"])
    ite=itertools.permutations("xyz")
    for x,y,z in ite:
        data=[]
        for i in range(length):
            if not (int(data2[x][i]) + int(data2[y][i]))%2 == int(data2[z][i]):
                return(0)
    return(1)


if data[0]==N:
    print("Yes")
elif N%3==0:
    mc=data.most_common()
    if data[0] == N//3 and len(data)==2:
        print("Yes")
    elif len(data)==3 and binbin(mc[0][0],mc[1][0],mc[2][0]) and mc[0][1]==mc[1][1]==mc[2][1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def 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
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

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

if N % 3 != 0:
    print('No')
else:
    d = {}
    for i in range(N):
        if a[i] not in d.keys():
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    if len(d) == 3:
        keys = list(d.keys())
        values = list(d.values())
        if values[0] == values[1] == values[2] and keys[0] ^ keys[1] == keys[2]:
            print('Yes')
        else:
            print('No')
    elif len(d) == 2:
        if 0 in d.keys() and d[0] == N//3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

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

if n%3==0:
    for j in range(3):
        for i in range(j*(n//3),(j+1)*(n//3)-1):
            if a[i]!=a[i+1]:
                print("No")
                exit()
    if a[0]^a[n//3]==a[2*n//3]:
        print("Yes")
    else:
        print("No")
    exit()
for i in range(0,n-1):
    if a[i]!=a[i+1]:
        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')
else:
    if len(a)%3 != 0:
        print('No')
    else:
        counter = Counter(a)
        keys = list(counter.keys())
        vlen = len(set(counter.values()))
        if len(keys) >= 4 or len(keys) == 1:
            print('No')
        else:
            if len(keys) == 2:
                if 0 in counter:
                    if counter[0] == N//3:
                        print('Yes')
                    else:
                        print('No')
                else:
                    print('No')
            else:
                if (vlen == 1) and (keys[0]^keys[1]==keys[2]):
                    print('Yes')
                else:
                    print('No')