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()))
a = sorted(a)
flag = True
ans = 0
for i in a:
    ans = i ^ ans

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
result = False
numbers = defaultdict(int)
inputNum = list(input().split())
for i in range(n):
    numbers[inputNum[i]] += 1
if len(numbers) == 3:
    if n % 3 == 0:
        vals = list(numbers.values())
        if vals[0] == vals[1] and vals[1] == vals[2]:
            keys = list(numbers.keys())
            if int(keys[0]) ^ int(keys[1]) == int(keys[2]):
                result = True
elif len(numbers) == 2:
    if n % 3 == 0:
        vals = list(numbers.values())
        keys = list(numbers.keys())
        if keys[0] == "0":
            if vals[1] == vals[0] * 2:
                result = True
        elif keys[1] == "0":
            if vals[0] == vals[1] * 2:
                result = True
elif len(numbers) == 1:
    keys = list(numbers.keys())
    if keys[0] == "0":
        result = True

if result == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
a=set(a_list)
if 0 not in a:
  if len(a)!=3:
    print("No")
    exit()
  a=list(a)
  count_a0=a_list.count(a[0])
  count_a1=a_list.count(a[1])
  count_a2=a_list.count(a[2])
  if count_a0!=count_a1 or count_a1!=count_a2 or count_a2!=count_a0:
    print("No")
    exit()
  if a[0]==a[1]^a[2]:
    print("Yes")
  else:
    print("No")
else:
  if len(a)==2:
    a=list(a)
    count_a0=a_list.count(0)
    count_a1=a_list.count(a[0]) if a[0]!=0 else a_list.count(a[1])
    if count_a0*2!=count_a1:
      print("No")
    else:
      print("Yes")
  elif len(a)==1:
    if 0 in a:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Submission status: Accepted

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

sum_xor = 0
for _a in a:
  sum_xor = sum_xor ^ _a

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

Submission status: Accepted

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

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

if ans > 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int,input(' ').split(' ')))
    l = int(bin(a[-1]^a[1]),2)
    r = a[0]
    for i in range(1,n):
        l = int(bin(l^(a[i-1]^a[(i+1)%n])),2)
        r = int(bin(r^a[i]),2)
    return r==l

if __name__ == '__main__':
    if main():
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

#a_b = []
dic = {}
m = 0
for i in range(len(a)):
    if a[i] in dic.keys():
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

ls = list(dic.keys())

if len(ls) <= 2 and 0 in ls:
    ls.sort()
    #2種類の時...0と何か
    if len(ls) == 2:
        #0の数が他の数の半分
        if 2 * dic[ls[0]] == dic[ls[1]]:
            print("Yes")
        else:
            print("No")
    #1種類の時...0だけ
    else:
        print("Yes")
#3種類の時...全ての個数が揃っていて2つが1つの排他的論理和になっている
elif len(ls) == 3:
    ls.sort()
    if  dic[ls[0]] == dic[ls[1]] and dic[ls[0]] == dic[ls[2]]:
        if list(ls)[0] ^ list(ls)[1] == list(ls)[2]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
#4種類以上の時...ダメ
else:
    print("No")

"""
for i in a:
    if i == max(a):
        m = i
    #print(bin(i))
for i in a:
    a_b.append(bin(i)[:2]+'0'*(len(bin(m))-len(bin(i)))+bin(i)[2:])

#for i in range(len(a_b)):
#    print(a_b[i])


a = int("0b" + "0" * (len(bin(m))-2),2)

for i in range(len(a_b)):
    a = a ^ int(a_b[i],2)
if a == 0:
    print("Yes")
else:
    print("No")
"""

Submission status: Accepted

Solution code:
n=input()
l=map(int,raw_input().split())
ans=0
for i in xrange (n):
  ans^=l[i]
if ans:
  print "No"
else:
  print "Yes"

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
C = Counter(a)
if len(C) == 1:
    if a[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(C) == 3:
    v = list(C.keys())
    if v[0] ^ v[1] != v[2]:
        print('No')
        quit()
    x = C[a[0]]
    for k in C:
        if C[k] != x:
            print('No')
            quit()
    print('Yes')
else:
    if 0 not in C:
        print('No')
        quit()
    for k in C:
        if k != 0:
            if C[k] == 2 * C[0]:
                print('Yes')
            else:
                print('No')
            break

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  alist = list(sorted(map(int, input().split())))
  aset = set(alist)
  tmpal = list(aset)
  if len(aset) > 3:
    print('No')
  elif len(aset) == 1:
    if tmpal[0] == 0:
      print('Yes')
    else:
      print('No')
  elif n % 3 != 0:
    print('No')
  else:
    if len(aset) == 2:
      if alist.count(0) == n // 3:
        print('Yes')
      else:
        print('No')
    else:
      if tmpal[0] ^ tmpal[2] == tmpal[1]:
        nd = {tmpal[0]: 0, tmpal[1]: 0, tmpal[2]: 0}
        for a in alist:
          nd[a] += 1
        if nd[tmpal[0]] == nd[tmpal[1]] and nd[tmpal[1]] == nd[tmpal[2]]:
          print('Yes')
        else:
          print('No')
      else:
        print('No')


if __name__ == '__main__':
  main()

Submission status: Accepted

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

def main():
    N = input()
    A = [int(a) for a in input().split()]
    dic = {}

    for a in A:
        dic[a] = dic.get(a,0)+1

    if len(dic)>3:
        print("No")
    else:
        key = [k for k in dic]
        key.sort(key=lambda x:dic[x])
        if len(dic)==1:
            if key[0] == 0:
                print("Yes")
            else:
                print("No")
        elif len(dic)==2:
            if key[0] == 0 and key[1]^key[1]==0 and dic[key[1]]==dic[key[0]]*2:
                print("Yes")
            else:
                print("No")
        else:
            if key[0]^key[1] != key[2]:
                print("No")
            else:
                if dic[key[0]]==dic[key[1]]==dic[key[2]]:
                    print("Yes")
                else:
                    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print('Yes' if ret == 0 else 'No')

Submission status: Accepted

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

# ans = False
# x = a[0]
# y = a[1]
# available = list(a[2:])
# while available:
#     r = x ^ y
#     if r in available:
#         available.remove(r)
#         x = y
#         y = r
#     else:
#         break
# if not available:
#     ans = x ^ y == a[0]

# print("Yes" if ans else "No")

c = Counter(a).most_common()
if len(c) == 3 and c[0][0] ^ c[1][0] == c[2][0] and c[0][1] == c[1][1] and c[1][1] == c[2][1]:
    ans = True
elif len(c) == 2 and c[0][0] ^ c[1][0] == c[0][0] and (c[0][1] * 2 == c[1][1] or c[0][1] == c[1][1] * 2):
    ans = True
elif len(c) == 1 and c[0][0] == 0:
    ans = True
else:
    ans = False
print("Yes" if ans else "No")

Submission status: Accepted

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

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

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

p = n // 3
if 0 in a:
    # a = sorted(a)
    zero = a.count(0)
    if zero != p:
        print('No')
        exit()
    if a.count(max(a)) != p * 2:
        print('No')
        exit()
    print('Yes')
    exit()

a = sorted(a)
# if a[0] == a[p] or a[p] == a[-1] or a[-1] == a[0]:
#     print('No')
if a.count(a[0]) != p or a.count(a[p]) != p or a.count(a[-1]) != p:
    print('No')
else:
    if a[0] ^ a[p] == a[-1]:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

res = A[0] ^ A[1]
for i in range(2, N):
    res ^= A[i]
if res == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

nums = {}

for i in range(len(a)):
  if int(a[i]) not in nums:
    nums[int(a[i])] = 1
  else:
    nums[int(a[i])] += 1

#print(nums)

if len(nums) > 3:
  print("No")
else:
  snums = sorted(nums.items())
  #print(snums)
  if(snums[0][0] == 0 and len(snums) == 1):
    print("Yes")
  elif(snums[0][0] == 0 and len(snums) == 2 and snums[0][1]*2 == snums[1][1] ):
    print("Yes")
  elif(snums[0][0] != 0 and len(snums) == 3 
       and snums[0][1] == snums[1][1] == snums[2][1] ):
    if snums[0][0] ^ snums[1][0] == snums[2][0]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()
    a = LI()

    from collections import Counter

    cnt = Counter(a)

    if len(cnt) == 1 and a[0] == 0:  # all elements are zero
        print('Yes')
        return

    if len(cnt) == 2:
        x, y = cnt.keys()
        if x^y==y and y^y==x and cnt[x]*2==cnt[y]:
            print('Yes')
            return
        if x^x==y and x^y==x and cnt[y]*2==cnt[x]:
            print('Yes')
            return

    if len(cnt) == 3:
        x, y, z = cnt.keys()
        if x^y==z and y^z==x and z^x==y and cnt[x]==cnt[y]==cnt[z]:
            print('Yes')
            return

    print('No')




main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
a=list(map(int,input().split()))
tmp=Counter(a)
if len(tmp.keys())!=3 or len(a)%3!=0:
    ans=list(tmp.values())
    if len(tmp.keys())==2 and 0 in tmp.keys():
        if tmp[0]*2 in ans:
            print("Yes")
            exit()
        
        
    if sum(a)==0:
        print("Yes")
        exit()
    print("No")
    exit()
else:
    
    key=list(tmp.keys())
    ans=list(tmp.values())
    #print(key)
    #print(ans)
    if ans[0]==ans[1] and ans[0]==ans[2]:
        if key[0]^key[1]==key[2]:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int,input().split(' ')))
dp = {}
k = True
for i in range(N):
    tmp = l[i]
    if tmp in dp:
        dp[tmp] +=1
    else:
        if len(dp)==3:
            k = False
            break
        else:
            dp[tmp] = 1

flag = False
num_l = []
ans_l = []
if k:
    if 0 in dp:
        if len(dp)==1:
            flag = True
        elif len(dp)==2:
            num_l = [None]*2
            ans_l = [None]*2
            for key,val in dp.items():
                if key==0:
                    num_l[0] = key
                    ans_l[0] = val
                else:
                    num_l[1] = key
                    ans_l[1] = val
            if ans_l[0]*2==ans_l[1]:
                flag = True
    else:
        if len(dp)==3:
            for key,val in dp.items():
                num_l.append(key)
                ans_l.append(val)
            if ans_l[0]==ans_l[1] and ans_l[0]==ans_l[2]:
                if num_l[0]^num_l[1]==num_l[2]:
                    flag = True
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter 
import sys
def No():
    print("No")
    sys.exit()

def Yes():
    print("Yes")
    sys.exit()

N=int(input())
A = [int(i) for i in input().split()]
C=Counter(A)
if N%3==0:
    if len(C)==1:
        if C.get(0,0):
            Yes()
        else:No()
    if len(C)==2:
        if C.get(0,0) == N//3:
            Yes()
        else:No()
    if len(C)>3:No()
    if not all([v==N//3 for v in C.values()]):
        No()    
    bits = [format(a,"040b") for a in C.keys()]
    if all([z.count("0")%2 for z in zip(*bits)]):
        print("Yes")
    else:No()
else:
    if len(C)==1 and C.get(0,0):
        Yes()
    else:No()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def main():
    n = get_int()
    A = get_li()
    if n % 3 != 0:
        if any(a != 0 for a in A):
            print('No')
            return
    else:
        cnt = Counter(A)
        if len(cnt.items()) > 3:
            print('No')
            return
        elif len(cnt.items()) == 3:
            a, b, c = cnt.most_common(3)
            if a[0] ^ b[0] ^ c[0] != 0:
                print('No')
                return
        elif len(cnt.items()) == 2:
            a, b = cnt.most_common(2)
            if b[0] != 0:
                print('No')
                return
        else:
            a = cnt.most_common(1)[0]
            if a[0] != 0:
                print('No')
                return
        for v, c in cnt.items():
            if c % (n // 3) != 0:
                print('No')
                return
    print('Yes')
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()

Submission status: Accepted

Solution code:
import numpy as np

size=input()
arr=np.array(input().split(" "),dtype=np.int32)

bit_array=[]
length_array=[]

for x in arr:
    bit_array.append(bin(x))
    length_array.append(len(bin(x)))

max_length=max(length_array)

fixed_bit_array=[]
for x,y in zip(bit_array,length_array):
    if y==max_length:
        fixed_bit_array.append(x[2:])
    else:
        pad=max_length-y
        x="{}{}".format("0"*pad,x[2:])
        fixed_bit_array.append(x)


result=[]
for i in range(max_length-2):
    count=0
    for x in fixed_bit_array:
        if x[i]=="1":
            count+=1
    if count%2==0:
        result.append("0")
    else:
        result.append("1")

if "1" in "".join(result):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
a=[0]*N
#b=[""]*N
#cnt=[0]*50
a=list(map(int,input().split()))
sum=0
for i in range(N):
    #b[i]=format(a[i],'b')
    sum=sum^a[i]

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

Submission status: Accepted

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

c = collections.Counter(a)
k = list(c.keys())
v = list(c.values())

if n % 3 == 0:
  if len(v) == 3:
    if v[0] == v[1] == v[2] and k[0] ^ k[1] == k[2]:
      print("Yes")
    else:
      print("No")
  elif len(v) == 2:
    if (k[0] == 0 and v[0] * 2 == v[1]) or (k[1] == 0 and v[1] * 2 == v[0]):
      print("Yes")
    else:
      print("No")
  elif len(v) == 1:
    if k[0] == 0:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
elif len(v) == 1:
  if k[0] == 0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
def doit(a):
    c = {}
    for ai in a:
        c[ai] = c.get(ai, 0) + 1
    if len(c) > 3:
        return "No"
    k = list(sorted(c.keys()))
    if len(k) == 1:
        if k[0] == 0:
            return "Yes"
    if len(k) == 2:
        if k[0] == 0 and c[k[0]] * 2 == c[k[1]]:
            return "Yes"
    if len(k) == 3:
        if c[k[0]] == c[k[1]] == c[k[2]] and k[0] ^ k[1] == k[2]:
            return "Yes"
    return "No"

print(doit(sorted(a)))

Submission status: Accepted

Solution code:


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

val1 = a[0]
val2 = a[0] ^ a[0]

for i in range(1, N):
    val1 = val1 ^ a[i]
    val2 = val2 ^ a[i] ^ a[i]

if( val1 == val2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = map(int,input().split())
a = list(map(bin,a))
a = [int(i,2) for i in a]
ans = a[0]
for i in range(n-1):
    ans = ans ^ a[i+1]

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

Submission status: Accepted

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

flag1 = True
flag2 = True

for i in range(n):
    if a[i] != 0:
        flag1 = False
        break

if not flag1:
    if n % 3 != 0:
        flag2 = False
    if flag2:
        a.sort()
        a11 = a[0: n // 3]
        a12 = a[n // 3: 2 * n // 3]
        a13 = a[2 * n // 3:]
        if not (a11.count(a11[0]) == a12.count(a12[0]) == a13.count(a13[0])):
            flag2 = False
    if flag2:
        a1, a2, a3 = a[0], a[n // 3], a[2 * n // 3]
        aa = [[], [], []]
        for i in range(30):

            aa[0].append(a1 % 2)
            aa[1].append(a2 % 2)
            aa[2].append(a3 % 2)
            a1 = a1 // 2
            a2 = a2 // 2
            a3 = a3 // 2

        for i in range(30):
            if aa[0][i] == 0 and aa[1][i] == 0 and aa[2][i] == 1:
                flag2 = False
                break
            if aa[0][i] == 0 and aa[1][i] == 1 and aa[2][i] == 0:
                flag2 = False
                break
            if aa[0][i] == 1 and aa[1][i] == 0 and aa[2][i] == 0:
                flag2 = False
                break
            if aa[0][i] == 1 and aa[1][i] == 1 and aa[2][i] == 1:
                flag2 = False
                break


if flag1 or flag2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import collections
N=int(input())
a=list(map(int,input().split()))
def judge(a):
    if sum(a)==0:
        return True
    else:
        a=dict(collections.Counter(a))
        if len(a.keys())==3:
            a0=list(a.keys())[0]
            a1=list(a.keys())[1]
            a2=list(a.keys())[2]
            if a0^a1==a2 and a[a0]==a[a1] and a[a1]==a[a2]:
                return True
        if len(a.keys())==2:
            a0=list(a.keys())[0]
            a1=list(a.keys())[1]
            if a0==0 or a1==0:
                if a[a0]==2*a[a1] or a[a1]==2*a[a0]:
                    return True
    return False

if judge(a):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
    
n=I()
a=LI()

a.sort()

def check(n,a):
    if n%3!=0:
        if a[-1]==0 and a[0]==0:
            return True
        else:
            return False
    else:
        m=n//3
        c=a[0]
        for i in range(m):
            if a[i]!=c:
                k=0
                return False
        c=a[m]
        for i in range(m):
            if a[m+i]!=c:
                k=0
                return False
                
        c=a[2*m]    
        for i in range(m):
            if a[2*m+i]!=c:
                k=0
                return False
        if a[0]^a[m]==a[m*2]:
            return True
            
if check(n,a):
    k=0
else:
    k=1
ans=['Yes','No']

print(['Yes','No'][k])

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
c = Counter(int(s) for s in input().split())
if len(c) > 3:
    print("No")
elif len(c) == 1:
    print("Yes" if c.most_common()[0][0] == 0 else "No")
elif len(c) == 2:
    mc = sorted(c.most_common())
    if mc[0][0] == 0 and mc[0][1] * 2 == mc[1][1]:
        print("Yes")
    else:
        print("No")
else:
    mc = sorted(c.most_common())
    if mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0 and mc[0][1] == mc[1][1] == mc[2][1]:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[0]
y = a[N // 3]
z = a[- N // 3]
if a[-1] == 0:
	print('Yes')
else:
	if N % 3 == 0:
		if a[N // 3 - 1] == 0 and y == a[-1]:
			print('Yes')
		else:
			if a.count(x) == N // 3 and a.count(y) == N // 3 and a.count(z) == N // 3: 
				if x ^ y == z and y ^ z == x and z ^ x == y:
					print('Yes')
				else:
					print('No')
			else:
				print('No')
	else:
		print('No')

Submission status: Accepted

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

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

B = set(A)
if N%3 == 0:
    C = list(B)
    ans = 0
    for i in range(N):
        ans = ans^A[i]

    if ans == 0:
        print('Yes')
        exit()

print('No')

Submission status: Accepted

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

if len(a.most_common()) > 3:
    print("No")
    sys.exit()

if len(a.most_common()) == 1:
    if a.most_common()[0][0] == 0:
        print("Yes")
        sys.exit()
    else:
        print("No")
        sys.exit()
    
if len(a.most_common()) == 2:
    if a.most_common()[1][0] == 0 and 2 * a.most_common()[1][1] == a.most_common()[0][1]:
        print("Yes")
        sys.exit()
    else:
        print("No")
        sys.exit()

if len(a.most_common()) == 3:
    if a.most_common()[0][1] == a.most_common()[1][1] == a.most_common()[2][1]:
        if a.most_common()[0][0] ^ a.most_common()[1][0] == a.most_common()[2][0]:
            print("Yes")
            sys.exit()
        else:
            print("No")
            sys.exit()
    else:
        print("No")
        sys.exit()

Submission status: Accepted

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

KETA_MAX = 10


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


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


def solve(N: int, a: "List[int]"):
    keta = [Counter() for _ in range(KETA_MAX)]
    for i in range(N):
        x = a[i]
        for j in range(KETA_MAX):
            keta[j][x & 1] += 1
            x >>= 1

    for cnt in keta:
        if cnt[1] == 0:
            continue
        elif cnt[1] == cnt[0]*2:
            continue
        else:
            no()
            return
    yes()
    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())
ans = "No"
num_list = sorted([ int(v) for v in input().split() ])

if n % 3 == 0:
    m = n // 3
    a, b, c = num_list[0], num_list[m], num_list[2*m]
    if len(set(num_list[:m])) == 1 and len(set(num_list[m:2*m])) == 1 and len(set(num_list[2*m:])) == 1:
        if a ^ b == c:
            ans = "Yes"
elif num_list == [0] * n:
        ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
set_a=set(a)
if len(set_a)==3:
    set_a = list(set_a)
    num0 = a.count(set_a[0])
    num1 = a.count(set_a[1])
    num2 = a.count(set_a[2])
    if (set_a[0]^set_a[1]^set_a[2]==0) and (num0==num2) and (num1==num2):
        print('Yes')
    else:
        print('No')
elif len(set_a)==2:
    set_a = list(set_a)
    num0 = a.count(set_a[0])
    num1 = a.count(set_a[1])
    if (set_a[0]==0 and num1 == num0*2)or(set_a[1]==0 and num0==num1*2):
        print('Yes')
    else:
        print('No')
elif len(set_a)==1:
    if 0 in set_a:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter

# s = input()
N = int(input())
A = list(map(int, input().split()))
# a, b = map(int, input().split())

c = Counter()

for a in A:
    c[a] += 1

k = list(c.keys())
v = list(c.values())
if len(v) == 1:
    if k[0]^k[0] == k[0]:
        print("Yes")
        exit()


if len(v) == 2 and N%3 == 0:
    if v[0]*2 == v[1]:
        if k[1]^k[1] == k[0]:
            print("Yes")
            exit()
    if v[1]*2 == v[0]:
        if k[0]^k[0] == k[1]:
            print("Yes")
            exit()


if len(v) == 3:
    if v[0] == v[1] and v[1] == v[2]:
        if k[0]^k[1] == k[2]:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

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

def xorsum(X):
    x = X[0]
    for i in range(1,len(X)):
        x = x ^ X[i]
    return x

if xorsum(As) == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

if (len(B)==3 and
    C[0]^C[1]==C[2] and
    A.count(C[0])==N//3 and
    A.count(C[1])==N//3 and
    A.count(C[2])==N//3):
    print('Yes')
    exit()

if (len(B)==2 and
    min(C)==0 and
    A.count(0)==N//3 and
    A.count(max(C))==2*N//3):
    print('Yes')
    exit()

print('No')

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()
if c[0]==0:
  if n%2==0 and a.count(c[0])==n//2 and a.count(c[1])==n//2:
    print("Yes")
    exit()
  if n%2==1 and a.count(c[0])==n//2 and a.count(c[1])==n//2+1:
    print("Yes")
    exit()
if n%3!=0:
  print("No")
  exit()
if 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()
if 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())

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

maxi = max(oa)

keta = 1

while 2 ** keta < maxi:

    keta += 1


a = []
dic = {}

for i in oa:

    new = format(i,"b")
    new = new.zfill(keta)
    a.append(new)

    if new not in dic:
        dic[new] = 1
    else:
        dic[new] += 1

if len(dic) > 3:
    print ("No")

elif len(dic) == 1:

    flag = True

    for i in dic:

        if "1" in i:
            flag = False

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

elif len(dic) == 2:

    flag1 = -1
    flag2 = -1
    cnt = 0

    for i in dic:
        
        if cnt == 0:

            if "0" in i and "1" not in i:
                flag1 = 0
                
            key1 = i
            cnt += 1

        if cnt == 1:

            if "0" in i and "1" not in i:
                flag2 = 0

            key2 = i

    if flag1 != 0 and flag2 != 0:
        print ("No")
    elif flag1 == 0 and dic[key1] == dic[key2] * 2:
        print ("Yes")
    elif flag2 == 0 and dic[key2] == dic[key1] * 2:
        print ("Yes")
    else:
        print ("No")

elif len(dic) == 3:

    key = []
    for i in dic:
        key.append(i)

    if dic[key[0]] == dic[key[1]] and dic[key[1]] == dic[key[2]]:

        Flag = True


        for i in range(len(key[0])):

            ndic = {}
            ndic["0"] = 0
            ndic["1"] = 0

            for j in range(3):
                
                if key[j][i] == "0":
                    ndic["0"] += 1
                else:
                    ndic["1"] += 1

            if ndic["1"] == 1 or ndic["1"] == 3:
                Flag = False
                break

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

    else:
        print ("No")
    #print (a)