Problem:


Score : 300 points

Problem Statement

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

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

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

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

What is XOR?

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

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

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

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

Sample Input 2

4
1 2 4 8

Sample Output 2

No

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



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
A=Counter(A).most_common()
A.sort(key=lambda x:x[0])
flag=1
if len(A)==3:
    for i in range(2):
        if A[i][1]==A[i+1][1]:
            continue
        else:
            flag=0
    for i in range(2):
        if i==0 :
            if A[i][0]==(A[i+1][0]^A[-1][0]):
                continue
            else:
                flag=0
        elif i==2:
            if A[i][0]==(A[i-1][0]^A[0][0]):
                continue
            else:
                flag=0
        else:
            if A[i][0]==(A[i-1][0]^A[i+1][0]):
                continue
            else:
                flag=0
    if flag==1:
        print("Yes")
    else:
        print("No")
else:
    if A[0][0]==0:
        if len(A)==1 or (len(A)==2 and A[0][1]==A[1][1]//2):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}

for i in range(a):
    if b[i] not in c:
        c.setdefault(b[i], 1)
    else:
        c[b[i]] += 1

if len(c) == 3:
    f = list(c.values())
    for i in range(1, len(f)):
        if f[i] != f[i-1]:
            print("No")
            exit()
    g = list(c.keys())
    if g[0] ^ g[1] == g[2]:
        print("Yes")
    else:
        print("No")
elif len(c) == 2:
    f = list(c.values())
    if f[0] != f[1]*2 and f[0]*2 != f[1]:
        print("No")
        exit()
    g = list(c.keys())
    if g[0] == 0 or g[1] == 0:
        print("Yes")
    else:
        print("No")
elif len(c) == 1:
    g = list(c.keys())
    if g[0] == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")
    exit()

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
j = 0
u = []
v = [0]*4
for i in l:
    if not i in u :
        u.append(i)
    v[u.index(i)] += 1
    if len(u) > 3:
        break
#print(u,v)
if len(u) == 3:
    if ((n%3 == 0) and (u[0] ^ u[2] == u[1]) and (v[0] == v[1] and v[1] == v[2]) and not len(u) > 3 and not 0 in u):
        j = 1
elif len(u) == 2:
    if 0 in u:
        if u[0] == 0 :
            b = u[1]
        else :
            b = u[0]
        if v[u.index(0)] * 2 == v[u.index(b)]:
            j = 1
if len(u) == 1:
    if u[0] == 0:
        j = 1

if j == 1 :
    print("Yes")
else :
    print("No")

#print(l[0] ^ l[2] == l[1],n == 3)
"""01
10
11
01
10
11

01
00
01
01
00
01
"""

Submission status: Accepted

Solution code:
import itertools
N=int(input())
an=[int(x) for x in map(int,input().split()[:N])]

ret=an[0]
for x in range(1,N):
    ret= an[x] ^ ret

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

Submission status: Accepted

Solution code:
import sys

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

l = a[0]
m = -1
n = -1
o = -1

for i in range(1,N):
    if a[i] != l and m == -1:
        m = a[i]
    elif a[i] != l and a[i] != m and n == -1 :
        n = a[i]
    elif a[i] != l and a[i] != m and a[i] != n and o == -1:
        print("No")
        sys.exit()

if (m == -1 and n == -1) and l^l == l and a.count(l) == N:
    print("Yes")
elif n == -1 and a.count(l)+a.count(m) == N and ( (a.count(l)*2==a.count(m) and l^m==m) or (a.count(l)==a.count(m)*2 and l^m == l)):
    print("Yes")
elif a.count(l)+a.count(m)+a.count(n) == N and a.count(l) == a.count(m) and a.count(m) == a.count(n) and l^m==n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
m,k=n//3,0
for i in range(n):
  d=i%3*m+i//3
  if a[d]^a[(d+2*m)%n]!=a[(d+m)%n]:
    k=1
print('YNeos'[k::2])

Submission status: Accepted

Solution code:
def equal_list(lst1, lst2):
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            break
    else:
        if not lst:
            return True
    return False


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

if a == [0]*N:
    print("Yes")
    exit()

if N % 3 == 0:
    n = N // 3
    sets = list(set(a))
    order = max(a).bit_length()
    if len(sets) == 3:
        for s in sets:
            if a.count(s) != n:
                print("No")
                exit()

        for i in range(order):
            b = [sets[0] >> i & 1, sets[1] >> i & 1, sets[2] >> i & 1]
            if b == [0, 0, 0]:
                continue
            if not equal_list(b, [0, 1, 1]):
                print("No")
                exit()
    elif len(sets) == 2:
        if a.count(sets[0]) == n:
            for i in range(order):
                b = [sets[0] >> i & 1, sets[1] >> i & 1]
                if b == [0, 0]:
                    continue
                if b != [0, 1]:
                    print("No")
                    exit()
        elif a.count(sets[1]) == n:
            for i in range(order):
                b = [sets[0] >> i & 1, sets[1] >> i & 1]
                if b == [0, 0]:
                    continue
                if b != [1, 0]:
                    print("No")
                    exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()

    print("Yes")

else:
    print("No")
    exit()

Submission status: Accepted

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

Submission status: Accepted

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

a_unique = list(set(a))

if n == 3:
    if a_unique[0]^a_unique[1] == a_unique[2]:
        result = True
    
elif len(a_unique) == 3:
    if a_unique[0]^a_unique[1] == a_unique[2]: 
        if a.count(a_unique[0]) == a.count(a_unique[1]) and a.count(a_unique[1]) == a.count(a_unique[2]):
            result = True

elif len(a_unique) == 1:
    if a_unique[0]^a_unique[0] == a_unique[0]:
        result = True

elif len(a_unique) == 2:
    if a_unique.count(a_unique[0]) == 1:
        if a_unique[0]^a_unique[1] == a_unique[1]:
            if a_unique[1]^a_unique[1] == a_unique[0]:
                if a.count(a_unique[0])*2 == a.count(a_unique[1]):
                    result = True
    elif  a_unique.count(a_unique[1]) == 1:
        if a_unique[0]^a_unique[1] == a_unique[0]:
            if a_unique[0]^a_unique[0] == a_unique[1]:
                if a.count(a_unique[1])*2 == a.count(a_unique[0]):
                    result = True

if len(a_unique) > 3:
    result = False    
            
if result:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
m,k=n//3,0
for i in range(n):
  d=i%3*m+i//3
  if a[d]^a[(d+2*m)%n]!=a[(d+m)%n]:
    k=1
print(['Yes','No'][k])

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
m,k=n//3,0
for i in range(n):
    d=i%3*m+i//3
    if a[d]^a[(d+2*m)%n]!=a[(d+m)%n]:
        k=1
print(['Yes','No'][k])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import log2, floor
from operator import or_
from functools import reduce

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

if max(a) == 0 :
    bl = [0]
else :
    bl = [0 for _ in range(floor(log2(max(a)))+1)]
for ai in a :
    aj = ai
    if ai == 0 :
        pass
    else :
        for i in range(floor(log2(ai))+1) :
            if aj & 1 == 1 :
                bl[i] += 1
            aj >>= 1

ans = reduce(or_, map(lambda x : x&1, bl))
if ans :
    print("No")
else :
    print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
import collections
c=dict(collections.Counter(l))
d=list(c.values())
e=list(c.keys())
if len(d)==3:
    d.sort()
    e.sort()
    if d[0]==d[1]==d[2] and e[0]^e[2]==e[1]:
        print("Yes")
    else:
        print("No")
elif len(d)==2:
    d.sort()
    e.sort()
    if d[0]==d[1] and e[0]==0:
        print("Yes")
    elif d[0]*2==d[1] and e[0]==0 and c.get(0,-1)==d[0]:
        print("Yes")
    else:
        print("No")
elif len(d)==1 and e[0]==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
import cmath
N = input()
N = int(N)
#nums = []
nu = input().split()
nui = [int(s) for s in nu]
nus = set(nui)
nul = list(nus)
if((len(nul)==1) and (nul[0]==0)):
    print("Yes")
else:
    if(N%3==0):
        if(len(nul)==2):
            if(nul[0] < nul[1]):
                a = nul[0]
                b = nul[1]
            else:
                a = nul[1]
                b = nul[0]
            a_c = nui.count(a)
            b_c = nui.count(b)
            if(a_c*2 == b_c):
                print("Yes")
            else:
                print("No")

        elif(len(nul)==3):
            a = nul[0]
            b = nul[1]
            c = nul[2]
            a_c = nui.count(a)
            b_c = nui.count(b)
            c_c = nui.count(c)
            if((a_c == b_c) and (b_c==c_c)):
                a_s = list(format(a,"040b"))
                b_s = list(format(b,"040b"))
                c_s = list(format(c,"040b"))
                
                a_si = [int(s) for s in a_s]
                b_si = [int(s) for s in b_s]
                c_si = [int(s) for s in c_s]
                
                a_np = np.array(a_si)
                b_np = np.array(b_si)
                c_np = np.array(c_si)
                
                sumnp = a_np + b_np + c_np
                
                amari = sumnp%2
                
                ind = np.where(amari==1)
                
                if(len(ind[0])==0):
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
import collections
 
n = int(input())
a_list = list(map(int,input().split()))
 
c = collections.Counter(a_list)
 
#print(len(c.keys()))
ans_list = list(c.keys())
count_list = list(c.values())
 
#print(c.keys())
if len(c.keys()) == 1:
    if list(c.keys()) == [0]:
        print("Yes")
        quit()
    else:
        print("No")
        quit()
elif len(c.keys()) == 2:
    if ans_list[0] == ans_list[0]^ans_list[1] and count_list[0]== 2*count_list[1]:
        print("Yes")
        quit()
    elif ans_list[1] == ans_list[0]^ans_list[1] and count_list[1]== 2*count_list[0]:
        print("Yes")
        quit()
    else:
        print("No")
        quit()
        
if len(c.keys()) != 3:
    print("No")
    quit()

count_list.sort()
if ans_list[0] == ans_list[1] ^ ans_list[2]:
    if count_list[0]==count_list[1]==count_list[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
l = list(map(int, input().split()))
cnt = Counter(l)
res = len(cnt) == 1 and 0 in cnt
if not res and n % 3 == 0:
    if len(cnt) == 3 and all(v == n // 3 for v in cnt.values()):
        x = sorted(cnt.keys())
        res = x[0] ^ x[2] == x[1]
    if len(cnt) == 2 and cnt.get(0, 0) == n // 3:
        res = True
print("Yes" if res else "No")

Submission status: Accepted

Solution code:
import sys

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

for a in A:
  if a in dict.keys():
    dict[a] = dict[a] + 1
  else:
    dict[a] = 1

if len(list(dict.keys())) > 3:
  print('No')
  sys.exit()
elif len(list(dict.keys()))==1:
  keys=list(dict.keys())
  if keys[0]==0:
    print('Yes')
    sys.exit()
  else:
    print('No')
    sys.exit()
elif len(list(dict.keys()))==2:
  keys=list(dict.keys())
  a0=keys[0]
  a1=keys[1]
  a2=''
  b0=bin(a0)[2:]
  b1=bin(a1)[2:]
  if len(b0)<len(b1):
    b0,b1=b1,b0
  b1=b1.zfill(len(b0))
  for s0,s1 in zip(b0,b1):
    a2 = a2 + str( int(s0)^int(s1) )
  a2=int(a2,2)
  #print(a0,a1,a2)
  if a2==a0 or a2==a1:
    vals=list(dict.values())
    if vals[0]/2==vals[1] or vals[0]==vals[1]/2:
      print('Yes')
      sys.exit()
    else:
      print('No')
      sys.exit()
  
keys=list(dict.keys())
vals=set(dict.values())

if len(vals)> 1:
  print('No')
  sys.exit()
  
a0=keys[0]
a1=keys[1]
a2=''
b0=bin(a0)[2:]
b1=bin(a1)[2:]
if len(b0)<len(b1):
  b0,b1=b1,b0
b1=b1.zfill(len(b0))
for s0,s1 in zip(b0,b1):
  a2 = a2 + str( int(s0)^int(s1) )
a2=int(a2,2)

if a2!=keys[2]:
  print('No')
  sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    array = list(map(int, input().split()))
    set_array = list(set(array))
    if N != len(array):
        return "No"
    if N < 3:
        return "No"
    if len(set_array) == 1 and set_array[0] == 0:
        return "Yes"
    if len(set_array) == 3:
        for i in range(2):
            if array.count(set_array[i]) != array.count(set_array[i+1]):
                return "No"
        x = set_array[0]
        y = set_array[1]
        z = set_array[2]
        if x ^ y == z and y ^ z == x and x ^ z == y:
            return "Yes" 
    if len(set_array) == 2:
        x = min(set_array)
        y = max(set_array)
        if array.count(x)*2 == array.count(y):
            if x == 0 and y^y == 0 and 0^y == y:
                return "Yes"
    return "No"

print(main())

Submission status: Accepted

Solution code:
n = int(input())
line = list(map(int,input().split( )))
s = list(set(line))

if n%3==0 and 0 in line and line.count(0)==n//3 and len(s)<=2:
    print('Yes')
elif  n%3==0 and len(s)==3 and s[0]^s[1]==s[2] and s[1]^s[2]==s[0] and line.count(s[0])==n//3 and line.count(s[1])==n//3:
    print('Yes')
elif s == [0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

if 0 in a:
    set_a = list(set(a))
    set_a = sorted(set_a)
    if len(set_a) == 1:
        print("Yes")
    elif len(set_a) == 2:
        if 2*a.count(set_a[0]) == a.count(set_a[1]):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

else:
    if n%3 != 0:
        print("No")

    else:
        if len(set(a)) != 3 or a.count(list(set(a))[0]) != int(n/3) or a.count(list(set(a))[1]) != int(n/3) or a.count(list(set(a))[2]) != int(n/3):
            print("No")

        else:
            set_a = list(set(a))
            if set_a[0] == set_a[1]^set_a[2] and set_a[1] == set_a[2]^set_a[0] and set_a[2] == set_a[1]^set_a[0]:
                print("Yes")
            else:
                print("No")

Submission status: Accepted

Solution code:
import collections
n=input()
a=list(map(int,input().split()))
b=set(a)
c=list(b)
c.sort()
cnt=collections.Counter(a)
if len(b)==1:
  if c[0]==0:
    print('Yes')
  else:
    print('No')
if len(b)==2:
  if c[0]==0 and cnt[c[1]]%2==0 and cnt[c[0]]*2>=cnt[c[1]]:
    print('Yes')
  else:
    print('No')
if len(b)==3:
  if c[0]==0:
    print('No')
  elif cnt[c[0]]==cnt[c[1]]==cnt[c[2]] and c[0]^c[1]==c[2]:
        print('Yes')
  else:
      print('No')
if len(b)>3:
  print('No')

Submission status: Accepted

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

ans = 0
if n == 3:
    if a[0]^a[1] == a[2]:
        ans = 1
    else:
        ans = 0
elif n == 4:
    if a[0]==0 and a[1]==0 and a[2]==0 and a[3]==0:
        ans = 1
    else:
        ans = 0
else:
    tmp = []
    cnt = []
    for i in range(n):
        if i == 0:
            tmp.append(a[i])
            cnt.append(1)
        else:
            if a[i-1] == a[i]:
                cnt[-1] += 1
            else:
                tmp.append(a[i])
                cnt.append(1)
    if n % 3 != 0:
        if tmp[0] == 0 and cnt[0] == n:
            ans = 1
    else:
        if len(tmp) == 3:
            if cnt[0] == cnt[1] and cnt[1] == cnt[2] and tmp[0]^tmp[1] == tmp[2]:
                ans = 1
        if len(tmp) == 2:
            if tmp[0] == 0:
                if cnt[0]*2 == cnt[1]:
                    ans = 1
        if len(tmp) == 1:
            if tmp[0] == 0:
                ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if n % 3 == 0:
    a.sort()
    m = n // 3
    if a[0] == a[m - 1] and a[m] == a[2 * m - 1] and a[2 * m] == a[3 * m - 1]:
        if a[0] ^ a[m] ^ a[2 * m] == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if max(a) == min(a):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort()

    import collections
    c = collections.Counter(a_list)
    keys = sorted(c.keys())
    nk = len(keys)

    dprint(c)
    dprint(keys)

    # a[0] からスタート
    found = False
    start = keys[0]
    ccand = []
    rcand = []
    for i in range(0, nk):

        # 同じ数字を使う場合はcountに気を付ける
        if i == 0 and c[keys[i]] <= 1:
            continue

        center = keys[i]
        max = start + center

        for j in range(i, nk):
            right = keys[j]

            # 同じ数字を使う場合はcountに気を付ける
            if i == j and i == 0 and c[keys[i]] <= 2:
                continue
            if i == j and c[keys[i]] <= 1:
                continue

            if right > max:
                # これより大きいところにはない
                break

            if right == start ^ center:
                found = True
                ccand.append(center)
                rcand.append(right)
                # break
        #
        # if found == True:
        #     break

    if found == False:
        dprint("first pair search failed")
        print("No")
        return

    dprint("first set created")
    dprint(ccand, rcand)
    center = ccand[-1]
    right = rcand[-1]

    c[start] = c[start] - 1
    c[center] = c[center] - 1
    c[right] = c[right] - 1

    # これで、0, second, third が決まったので、あとは順次決める
    left = center
    center = right
    dprint(start, left, center)

    cnt = 3
    while True:
        # N個作ったら終了
        if cnt == N:
            break

        # 次の数字
        right = left ^ center

        # 検索
        rcount = c.get(right, -1)
        if rcount <= 0:
            dprint("break rcount:", rcount)
            print("No")
            return

        dprint("found", right, rcount)

        # update
        c[right] = c[right] - 1
        left = center
        center = right

        cnt += 1
        dprint("next", cnt, left, center)

    if start ^ left == center:
        print("Yes")
    else:
        dprint("last check failed", start, left, center)
        print("No")


solve()

Submission status: Accepted

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

N = int(input())
b = list(map(int, input().split()))
checker = Counter(b)
a = []
for key in checker.keys():
    a.append(key)
if len(a) == 1 and a[0] == 0:
    print('Yes')
    exit()
if len(a) == 2:
    if a[0] == 0:
        if checker[0] == int(N/3) and checker[a[1]] == int(2*N/3):
            print('Yes')
            exit()
    elif a[0] != 0:
        if checker[0] == int(N/3) and checker[a[0]] == int(2*N/3):
            print('Yes')
            exit()
if len(a) != 3:
    print('No')
    exit()
if a[0] == a[1]^a[2] and a[1] == a[0]^a[2] and a[2] == a[0]^a[1]:
    ans = 1
else:
    ans = 0
for key, value in checker.items():
    if N % 3 == 0 and value == int(N/3):
        ans *= 1
    else:
        ans *= 0
if ans == 1:
    print('Yes')
elif ans == 0:
    print('No')

Submission status: Accepted

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

ans = 'No'
hat1 = max(a)
hat2 = min(a)
if hat1 == 0 and a.count(hat1) == N:
    ans = 'Yes'
if N%3 == 0:
    if hat2 == 0 and a.count(hat1) == int(2*N/3) and a.count(hat2) == int(N/3):
        ans = 'Yes'
    if a.count(hat1) == int(N/3) and a.count(hat2) == int(N/3) and a.count(hat1^hat2) == int(N/3):
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = a[0]
    for i in range(1, N, 1):
        b = b ^ a[i]
    if b == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

eachbit=[0]*32
for i in range(N):
    bin_str = format(A[i],'032b')
#    print(bin_str)
    for j in range(1,33):
        if bin_str[-j] == '1':
            eachbit[j-1] += 1

#print(eachbit)
even = True
for e in eachbit:
    if e % 2 != 0:
        even = False

if even:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a=LIST()
    a_=a.copy()

    r=0
    for x in a:
        r ^= x 

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

if  __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
n=int(input())
l=list(map(int,input().split()))
l.sort()
s=set(l)
if len(s)>=4 :print("No");sys.exit()
if len(s)==1:print("Yes" if 0 in s else "No");sys.exit()
s=list(s);s.sort()
if len(s)==2:
  if 0 not in s:print("No");sys.exit()
  if n%3==1:
    if l.count(0)==(n-1)//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
  elif n%3==2:
    if l.count(0)==(n+1)//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
  elif n%3==0:
    if l.count(0)==n//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
a=l.count(s[0]);b=l.count(s[1]);c=l.count(s[2])
if a!=b or b!=c or c!=a:print("No");sys.exit()
flag=0
for i in itertools.permutations(s):
  if i[0]^i[2]==i[1] and i[1]^i[2]==i[0] and i[0]^i[1]==i[2]:flag+=1
if flag!=0:print("Yes")
else:print("No")

Submission status: Accepted

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

N = int(input())

c = Counter((int(x) for x in input().split()))

# 0がある場合
# 0,x,x,0,x,x
# あるいは
# 0,0,0,0 (any length is ok)

if c[0] > 0:
    if len(c) == 1:
        bl = True
    else:
        if len(c) > 2:
            bl = False
        else:
            bl = (N == 3 * c[0])
else:
    # 0がない場合
    # x,y,z,x,y,z で3つとも異なる
    se = set(c.keys())
    if len(se) != 3:
        bl = False
    else:
        bl = True
        xor = 0
        for key in se:
            xor ^= key
            if c[key] * 3 != N:
                bl = False
        if xor != 0:
            bl = False

answer = 'Yes' if bl else 'No'
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0) + 1
    if N % 3:
        if 0 in A and A[0] == N:
            return 'Yes'
        else:
            return 'No'
    else:
        if 0 in A and A[0] == N:
            return 'Yes'
        elif 0 in A and A[0] == N//3:
            if len(A) == 2:
                return 'Yes'
            else:
                return 'No'
        elif len(A) == 3:
            if len(set(A.values())) == 1:
                a,b,c = A.keys()
                if c == a^b:
                    return 'Yes'
                else:
                    return 'No'
            else:
                return 'No'
        else:
            return 'No'

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
W = list(map(int, input().split()))
c = dict(collections.Counter(W))

if len(c.keys()) == 1:
  if c.get(0, False) == False:
    print('No')
  else:
    print('Yes')
if len(c.keys()) == 2:
  num = list(c.values())
  num = sorted(num)
  if 0 in c:
    if c[0]*2 == num[1]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
if len(c.keys()) == 3:
  num = list(c.values())
  key = list(c.keys())
  if num[0] == num[1]:
    if num[0] == num[2]:
      if bin(key[0]^key[1]) == bin(key[2]):
        print("Yes")
      else:
        print("No")
    else:
      print("No")
  else:
    print("No")
if len(c.keys()) >= 4:
  print("No")

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    a_xor = a[0] ^ a[1]
    for i in range(2, N):
        a_xor = a_xor ^ a[i]
    if (a_xor == 0):
        print("Yes")
    else:
        print("No")
resolve()

Submission status: Accepted

Solution code:
N = int(input())
data = {}
bits = 0
bit_table = [set() for _ in range(31)]
for a in map(int, input().split()):
	bits |= a
	if a in data:
		data[a] += 1
	else:
		data[a] = 1
	i = 0
	b = a
	while b:
		if b % 2 == 1:
			bit_table[i].add(a)
		b //= 2
		i += 1

def pop(data, a):
	if a in data:
		if data[a] == 1:
			del data[a]
		else:
			data[a] -= 1
		return a
	else:
		return None

def check2(data0, a1, a2):
	if (a1 | a2) != bits:
		return False
	
	data = { k: data0[k] for k in data0 }
	a0 = a1
	pop(data, a1)
	pop(data, a2)
	
	while data:
		a3 = a1 ^ a2
		a4 = pop(data, a3)
		if a4 == None:
			return False
		a1 = a2
		a2 = a3
	return a0 == (a1 ^ a2)

def check(data):
	keys = list(data.keys())
	a1 = keys[0]
	b = bits & (~a1)
	cands = set(keys)
	i = 0
	while b:
		if b % 2 == 1:
			cands &= bit_table[i]
		b //= 2
		i += 1
	
	for a2 in cands:
		if a1 != a2 or data[a1] > 1:
			if check2(data, a1, a2):
				return True
	return False

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
from collections import Counter

readline = sys.stdin.readline

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


x = A[0]
y, z = x, x
for a in A:
    if a != x:
        y = a
        break
for a in A:
    if a != x and a != y:
        z = a
        break

if N % 3 == 0:
    cx, cy, cz = A.count(x), A.count(y), A.count(z)
    if x != y and x != z:
        if cx + cy + cz == N:
            if cx == cy and cx == cz and ((x ^ z == y) or (x ^ y == z)):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    elif x != y:
        x, y = max(x,y), min(x,y)
        cx, cy = A.count(x), A.count(y)
        if cy * 2 == cx and y == 0:
            print('Yes')
        else:
            print('No')
    elif x == y:
        if x == 0:
            print('Yes')
        else:
            print('No')
else:
    if x == y:
        if x == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

Solution code:
def xor(n1, n2):
  if n2=="0":
    return n1
  elif n2=="1":
    if n1=="1":
      return "0"
    else:
      return "1"
      
def bitxor(n1, n2):
 
  bn1 = bin(n1)[2:]
  bn2 = bin(n2)[2:]
  if n1<n2:
    bn1 = bn1.zfill(len(bn2))
  else:
    bn2 = bn2.zfill(len(bn1))
    
  n3 = [xor(b1,b2) for b1,b2 in zip(bn1, bn2)]
  n3 = "".join(n3)
  return int(n3, 2)
 
 
n = int(input())
a = [int(x) for x in input().split()]
a_unique = list(set(a))
la = len(a)
lau = len(a_unique)

if a_unique==[0]:
  print("Yes")

elif la%3==0 and (0 in a_unique):
  u0 = a.count(0)
  if u0*3!=la:
    print("No")
  else:
    a_unique.remove(0)
    tmp = [(a.count(ai)%2==0) for ai in a_unique]
    if len(tmp)==sum(tmp):
      print("Yes")
    else:
      print("No")

elif la%3==0 and lau==2 and (0 in a_unique):
  u0 = a.count(0)
  if a_unique[0]==0:
    num = a_unique[1]
  else:
    num = a_unique[0]
  u1 = a.count(num)
  if u0*2==u1:
    print("Yes")
elif la%3!=0 or lau!=3:
  print("No")
else:
  u0 = a.count(a_unique[0])
  u1 = a.count(a_unique[1])
  u2 = a.count(a_unique[2])
 
  if (a_unique[2]== bitxor(a_unique[0], a_unique[1])) and (u0==u1 and u1==u2):
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from collections import deque, defaultdict
import copy
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

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


numnum=defaultdict(int)
for i in range(N):
    numnum[a[i]]+=1

if len(numnum) > 3:
    print("No")
    exit()


if len(numnum) == 1:
    for num in numnum:
        if num == 0:
            print("Yes")
        else:
            print("No")
        exit()


for num in numnum:
    if numnum[num] % (N//3) != 0:
        print("No")
        exit()

num3=[]
for num in numnum:
    num3.append(num)

if len(num3) == 2:

    if 0 in num3 and numnum[0] == N//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()


if num3[0]^num3[1] == num3[2]:
    print("Yes")
    exit()
else:
    print("No")
    exit()