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 = [int(x) for x in input().split()]
ite = 0
for i in range(N):
    if a[i] != 0:
        break
    else:
        ite += 1
if ite == N :
    print("Yes")
    exit()

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

a = sorted(a)
for j in range(n-1):
    if a[j] != a[j + 1]:
        print("No")
        exit()


for k in range(n, 2*n-1):
    if a[k] != a[k + 1]:
        print("No")
        exit()

for p in range(2*n, 3*n-1):
    if a[p] != a[p + 1]:
        print("No")
        exit()


if a[n] ^ a[0] != a[2*n]:
    print("No")
    exit()

print("Yes")

Submission status: Accepted

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

if len(count) > 3:
    print("No")
    exit(0)
if N%3 == 0 and len(count) == 3:
    a, b, c = list(count.keys())
    la, lb, lc = list(count.values())
    if a ^ b == c and b ^ c == a and c ^ a == b and la == lb and lb == lc:
        print("Yes")
    else:
        print("No")
elif N%3 == 0 and len(count) == 2:
    a, b = list(count.keys())
    la, lb = list(count.values())
    if (a == 0 and la*2 == lb) or (b == 0 and lb*2 == la):
        print("Yes")
    else:
        print("No")
elif len(count)==1 and list(count.keys())[0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

a_set=list(set(a))
a_set.sort()


#コーナーケース　aが全部0なら必ずyes
if len(a_set)==1 and a_set[0]==0:
    print("Yes")
    sys.exit(0)

#上記の場合を除き、nが３の倍数でないと成立しない
if n%3!=0:
    print("No")
    sys.exit(0)


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

Submission status: Accepted

Solution code:
import sys

N = int(input())
a = list(map(int, input().split()))
 
x = 0
y = 0
z = 0

if a.count(0) == N:
  print('Yes')
  sys.exit()
  

if N % 3 != 0:
  print('No')
 
elif a.count(0) != 0:
  if a.count(0) != N / 3:
    print('No')
    sys.exit()
    
  else:
    for i in range(N):
      if a[i] != 0 and a[i] != x:
        if x == 0:
          x = a[i]
          continue
        else:
          print('No')
          sys.exit()
        
    print('Yes')
    

else:
  for i in range(N):
    if a[i] != x and a[i] != y and a[i] != z:
      if x == 0:
        x = a[i]
        continue
      elif y == 0:
        y = a[i]
        continue
      elif z == 0:
        z = a[i]
        continue
      else:
        print('No')
        sys.exit()
  
  if x ^ y == z and a.count(x) == a.count(y) and a.count(y) == a.count(z):
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
def calc(N, A):
    _exist = False
    counter = {}
    for a in A:
        counter[a] = 1 + (counter[a] if a in counter else 0)
    if (N % 3 == 0 and len(counter) == 3):
        keys = list(counter.keys())
        values = list(counter.values())
        d = max(values) - min(values)
        _exist = d == 0 and keys[0] ^ keys[1] == keys[2]
    elif (N % 3 == 0 and len(counter) == 2):
        keys = list(counter.keys())
        values = list(counter.values())
        d = max(values) - min(values)
        _exist = d == N // 3 and (keys[0] == 0 or keys[1] == 0)
    else:
        _exist = 0 in counter and counter[0] == N
    print('Yes' if _exist else 'No')


N = int(input())
A = [int(s) for s in input().split(' ')]
calc(N, A)

Submission status: Accepted

Solution code:
n = input()
dic = {}
for i in map(int, raw_input().split()):
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
if len(dic) > 3:
	print "No"
elif len(dic) == 3:
	vals = []
	for i in dic:
		vals.append(i)
	if vals[0]^vals[2] != vals[1] or vals[1]^vals[0] != vals[2] or vals[0] != vals[1]^vals[2]:
		print "No"
	elif max(dic.values()) - min(dic.values()) > 1:
		print "No"
	else:
		print "Yes"
elif len(dic) == 2:
	if 0 in dic and dic[0] == n/3 and n%3 == 0:
		print "Yes"
	else:
		print "No"
else:
	if 0 in dic.keys():
		print "Yes"
	else:
		print "No"

Submission status: Accepted

Solution code:

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

ans = True
if N % 3 != 0:
    for i in range(N):
        if a[i] != 0:   
            ans = False
else:
    first = a[0]
    i_second = -1
    for i in range(1, N):
        if a[i] != first:
            second = a[i]
            i_second = i
            break
        
    if i_second == -1:
        for i in range(N):
            if a[i] != 0:
                ans = False
    else:
        i_third = -1
        for i in range(i_second+1, N):
            if (a[i] != first) and (a[i] != second):
                third = a[i]
                i_third = i
                break
        if i_third == -1:
            ans = False
            cnt_first = 0
            cnt_second = 0
            for i in range(N):
                if a[i] == first:
                    cnt_first += 1
                elif a[i] == second:
                    cnt_second += 1
            if first ^ second == second:
                if (cnt_first == N/3) and (cnt_second == N*2/3):
                    ans = True
            if first ^ second == first:
                if (cnt_first == N*2/3) and (cnt_second == N/3):
                    ans = True
        else:
            if (first ^ second != third) or (second ^ third != first) or (third ^ first != second):
                ans = False
            else:
                cnt_first = 0
                cnt_second = 0
                cnt_third = 0
                for i in range(N):
                    if a[i] == first:
                        cnt_first += 1
                    elif a[i] == second:
                        cnt_second += 1
                    elif a[i] == third:
                        cnt_third += 1
                if (cnt_first != N/3) or (cnt_second != N/3) or (cnt_third != N/3):
                    ans = False

if ans is True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split(' ')]
numbers = []
numbers.append(a[0])
for i in a:
    if i != numbers[0] and len(numbers) == 1:
        numbers.append(i)
    if i != numbers[0] and i != numbers[1]:
        numbers.append(i)
        break

if len(numbers) == 1:
    if numbers[0] == 0:
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)

if len(numbers) == 3:
    if a.count(numbers[0]) != a.count(numbers[1]):
        print('No')
        exit(0)
    if a.count(numbers[0]) != a.count(numbers[2]):
        print('No')
        exit(0)
    if len(a) != a.count(numbers[0])+a.count(numbers[1])+a.count(numbers[2]):
        print('No')
        exit(0)

    if numbers[0]^numbers[1] == numbers[2]:
        print('Yes')
        exit(0)
    elif numbers[0]^numbers[2] == numbers[1]:
        print('Yes')
        exit(0)
    elif numbers[1]^numbers[2] == numbers[0]:
        print('Yes')
        exit(0)
    else:
        print('No')
else:
    if len(a) != a.count(numbers[0])+a.count(numbers[1]):
        print('No')
        exit(0)
    if numbers[0] == 0 or numbers[1] == 0:
        if numbers[0] == 0:
            if a.count(numbers[1]) != 2*a.count(numbers[0]):
                print('No')
                exit(0)
        elif a.count(numbers[0]) != 2*a.count(numbers[1]):
            print('No')
            exit(0)
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)

Submission status: Accepted

Solution code:
n = int(input())
hat_list = list(map(int, input().split()))
#print(hat_list)
b_list = []
for h in hat_list:
    #print(format(h,'b').zfill(10))
    b_list.append(format(h,'b').zfill(30))
#print(b_list)
for n in range(30):
    test_list = []
    for b in b_list:
        test_list.append(b[n])
    if test_list.count('1') > 0:
        if test_list.count('1') != test_list.count('0') * 2:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from sys import exit
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = list(map(int, input().split()))

def noexit():
    print('No')
    exit()

def yesexit():
    print('Yes')
    exit()

setA = set(A)
if 0 in setA:
    if len(setA) == 1: yesexit()
    elif len(setA) == 2 and N%3 == 0:
        A.sort()
        listA = list(setA)
        listA.remove(0)
        neww_list = [0] * (N//3) + [listA[0]] * ((N//3)*2)
        neww_list.sort()
        if A == neww_list:
            yesexit()
        else:
            noexit()
    else: noexit()

if N%3 != 0: noexit()
if len(setA) != 3: noexit()

listA = list(setA)
if listA[0]^listA[1] == listA[2]:
    new_list = [listA[0]]*(N//3) + [listA[1]]*(N//3) + [listA[2]]*(N//3)
    A.sort()
    new_list.sort()
    if A == new_list:
        yesexit()
    else:
        noexit()
else: noexit()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    *alist, = map(int, input().split())

    aset = list(set(alist))
    if len(aset) == 1 and aset[0] == 0:
        print('Yes')
        return

    if len(aset) == 2:
        a, b = aset
        acnt = {a: 0, b: 0}
        for aa in alist:
            acnt[aa] += 1

        if a ^ b == a:
            if acnt[a] == acnt[b] * 2:
                print('Yes')
                return
        if b ^ a == b:
            if acnt[a] * 2 == acnt[b]:
                print('Yes')
                return
        print('No')
        return

    if len(aset) != 3:
        print('No')
        return
    else:
        a, b, c = aset
        if a ^ b != c:
            print('No')
            return

        acnt = {a: 0, b: 0, c: 0}
        for aa in alist:
            acnt[aa] += 1

        if acnt[a] != acnt[b] or acnt[b] != acnt[c]:
            print('No')
            return

        print('Yes')
        return


main()

Submission status: Accepted

Solution code:
import sys, math
 
N = int(input())
A = [int(i) for i in input().split()]

result = 0
for i in range(N):
  result = result ^ A[i]
  #print(result)

if  result == 0:
  print("Yes")
else:
  print("No")
#print(result)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int ,input().split()))
C = Counter(A)
MAXD = 30
B = [('0' * MAXD + bin(a)[2:])[-30:] for a in A]

ps = []
res = True
for i in range(MAXD):
    bs = list(b[i] for b in B)
    c = Counter(bs)
    if c['0'] == N:
        continue
    if c['0'] == N // 3:
        if N % 3 == 0:
            if len(ps) != 0:
                if all(p == b for (b, p) in zip(bs, ps)):
                    continue
                bc = Counter(int(p + b, 2) for (b, p) in zip(bs, ps))
                if c[0] == 0 and c[1] == c[2] == c[3]:
                    continue
            ps = bs.copy()
            continue
    res = False
    break

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

Submission status: Accepted

Solution code:
N = int(input())
List=list(map(int,input().split()))
List.sort()
a = List[0]
b = List.count(a)
c = List[N//3]
d = List.count(c)
e = List[2*N//3]
f = List.count(e)
if a == c and c == e:
    if a == 0 and b == N:
        print('Yes')
    else:
        print('No')
elif c == e:
    if a == 0  and N % 3 == 0 and b == N // 3 and d == 2 * N // 3:
        print('Yes')
    else:
        print('No')
elif N % 3 == 0 and b == N // 3 and d == N //3 and f == N //3 and a ^ e == c : 
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
### A

N = int(input())
a_all = list(map(int, input().split()))
t = list(set(a_all))

if len(t)==3:
    if (t[0]^t[1]==t[2]):
        a=0
        b=0
        c=0
        for i in a_all:
            if i==t[0]:
                a+=1
            elif i==t[1]:
                b+=1
            else:
                c+=1
        if a==b and b==c:
            print("Yes")
        else:
            print("No")
    
    else:
        print("No")
    
    
elif len(t)==2:
    a=0
    b=0
    for i in a_all:
        if i==t[0]:
            a+=1
        else:
            b+=1
    if(a == b*2 or  b == a*2):
        print("Yes")
    else:
        print("No")
elif len(t)==1:
    if t[0]^t[0]==t[0]:
        print("Yes")
    else:
        print("No")

else:
    print("No")

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(int(i) for i in input().split())
chk = sum(a)
if a == [0] *N:
	print("Yes")
else:
	if N == 3:
			if (a[0]^a[1]) == a[2]:
				print("Yes")
			else:
				print("No")
	else:
		l = collections.Counter(a)
		if a.count(0) == 0:
			if list(l.values()) ==  [list(l.values())[0]] * len(l.values()) and len(l.keys()) == 3:
				if ((list(l.keys())[0])^(list(l.keys())[1])) == list(l.keys())[2]:
					print("Yes")
				else:
					print("No")
			else:
				print("No")
		else:
			if len(l.values()) == 2 and a.count(0) == N//3:
				print("Yes")
			else:
				print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(n,aa):
    if sum(aa)==0:
        return "Yes"
    if n%3>0:
        return "No"
    sa=set(aa)
    if len(sa)>3 or len(sa)<2:
        return "No"
    n3 = n / 3
    if len(sa)==3:
        for sak in sa:
            if aa.count(sak)!=n3:
                return "No"
        sa = list(sa)
    elif len(sa)==2:
        for sak in sa:
            if sak!=0:
                k=sak
        if 0 not in sa:
            return "No"
        if aa.count(0)!=n3:
            return "No"
        if aa.count(k)!=n3*2:
            return "No"
        sa=[0,k,k]

    for i in range(3):
        if sa[i - 1] != sa[i - 2] ^ sa[i]:
            break
    else:
        return "Yes"
    return "No"

n=int(input())
aa=list(map(int,input().split()))
print(f(n,aa))

Submission status: Accepted

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

def mae(N, a):
    sum = a[0]
    for i in range(1, N):
        sum ^= a[i]
    return sum

if mae(N, a) == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N=int(input())
a=list(map(int,input().split()))
seta=set(a)
lista=list(seta)
if len(a)==a.count(0):
    print("Yes")
elif len(set(a))>4:
    print("No")        
elif N%3!=0:
    print("No")
elif len(seta)==3:
    if a.count(lista[0])==a.count(lista[1])==a.count(lista[2]) and \
        lista[0]^lista[1]==lista[2]:
        print("Yes")
    else:
        print("No")
elif len(seta)==2:
    if a.count(lista[0])*2==a.count(lista[1]) and \
        lista[1]^lista[1]==lista[0]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    aa = list(map(int, input().split()))

    if min(aa) == max(aa) == 0:
        flg = True
    else:
        flg = len(aa) % 3 == 0

        aa.sort()

        if flg:
            flg = aa[0]            == aa[len(aa)//3  -1] \
              and aa[len(aa)//3]   == aa[len(aa)//3*2-1] \
              and aa[len(aa)//3*2] == aa[len(aa)     -1]

        tmp1 = aa[0]
        tmp2 = aa[len(aa)//3]
        tmp3 = aa[len(aa)-1]

        if flg:
            flg = tmp1 == tmp2 ^ tmp3 and tmp2 == tmp1 ^ tmp3 and tmp3 == tmp1 ^ tmp2

    print('Yes' if flg else 'No')
    
resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
  A[i] = bin(A[i])
max_len = len(A[N-1]) - 2
for i in range(N):
  A[i] = A[i][2:].zfill(max_len)
check = True
for i in range(max_len):
  count0 = 0
  count1 = 0
  for j in range(N):
    if(A[j][i] == '0'):
      count0 += 1
    else:
      count1 += 1
  if(count1 == 0):
    continue
  elif(count1 == count0 * 2):
    continue
  else:
    check = False
    break
if(check):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def convtobit(x):
    b = bin(x)
    bits = list(map(int, b[2:]))
    bits = [0] * (32 - len(bits)) + bits
    return tuple(bits)

def minus(x, y):
    b = []
    for xb, yb in zip(x, y):
        bit = 1 if xb != yb else 0
        b.append(bit)
    return tuple(b)

def main():
    #A, B, C, K = map(int, input().split())
    N = int(input())
    As = list(map(int, input().split()))

    # find N-th and 2nd number
    Adict = defaultdict(int)
    for a in As:
        b = convtobit(a)
        Adict[b] += 1

    assert convtobit(2) == tuple([0]*30 + [1, 0])
    assert convtobit(7) == tuple([0]*29 + [1, 1, 1])

    if len(Adict) > 3:
        print("No")
        return

    for first in Adict:
        for second in Adict:
            third = minus(first, second)
            if not third in Adict:
                continue
            forth = minus(second, third)
            if forth != first:
                continue

            if N % 3 == 0:
                adict = dict(Adict)
                for elem in [first, second, third]:
                    adict[elem] -= N // 3
                if all([adict[elem] == 0 for elem in [first, second, third]]):
                    print("Yes")
                    return

            if N % 3 == 1:
                adict = dict(Adict)
                for elem in [first, second, third]:
                    adict[elem] -= (N - 1) // 3
                adict[first] -= 1
                if all([adict[elem] == 0 for elem in [first, second, third]]):
                    print("Yes")
                    return

            if N % 3 == 2:
                adict = dict(Adict)
                for elem in [first, second, third]:
                    adict[elem] -= (N - 2) // 3
                adict[first] -= 1
                adict[second] -= 1
                if all([adict[elem] == 0 for elem in [first, second, third]]):
                    print("Yes")
                    return

    print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = list(map(int,input().split()))
    sa = list(set(a))
    num = {}

    if sum(sa)==0:
        print("Yes")
        exit(0)
    if (n%3)!=0:
        print("No")
        exit(0)
    for i in a:
        num[i] = num.get(i,0) + 1
    
    OK = False
    if len(num)==3:
        i,j,k = num.values()
        if i==j and j==k and sa[0]==(sa[1]^sa[2]):
            OK = True
    elif len(num)==2:
        i,k = num.keys()
        j,l = num.values()
        if i==0 and j*2==l:
            OK = True
        elif k==0 and l*2==j:
            OK = True
    if(OK):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n % 3 == 0:
    d = {}
    for x in a:
        d.setdefault(x, 0)
        d[x] += 1
    if len(d) > 3 or any([d[x] % (n//3) for x in d]):
        print("No")
        quit()
    if len(d) == 1 and 0 not in d:
        print("No")
        quit()
    if len(d) == 2 and d.get(0) != n//3:
        print("No")
        quit()
    if len(d) == 3:
        b = [x for x in d]
        if b[0]^b[1] != b[2] or b[1]^b[2] != b[0] or b[0]^b[2] != b[1]:
            print("No")
            quit()
    print("Yes")
else:
    print("Yes" if all([x == 0 for x in a]) else "No")

Submission status: Accepted

Solution code:
n = int(input().strip())
hat =  list(map(int,input().split()))
xor_sum = hat[0]
for x in hat[1:n]:
    xor_sum = xor_sum ^ x
                
if xor_sum == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

cnt = [1, 1, 1]
ind = 0
b = []
t = False

for i in range(n):
    if (a[i] != 0):
        break
    if i == n - 1:
        t = True

if t == True:
    print('Yes')
elif n % 3 != 0:
    print('No')
else:
    a.sort()
    if a[0] != 0:
        b.append(a[0])
        for i in range(n - 1):
            if a[i] == a[i + 1]:
                cnt[ind] += 1
            else:
                ind += 1
                if ind > 2:
                    break
                b.append(a[i + 1])
        if (ind == 2) and (cnt[0] == n // 3) and (cnt[1] == n // 3) and (cnt[2] == n // 3):
            if (b[0] ^ b[1] == b[2]):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        for i in range(n - 1):
            if a[i] == a[i + 1]:
                cnt[ind] += 1
            else:
                ind += 1
                if ind > 1:
                    break
        if (ind == 1) and (cnt[0] == n // 3) and (cnt[1] == 2 * (n // 3)):
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
sum=0
realsum=0
if N%3!=0:
    for j in a:
        realsum+=j
    if realsum==0:
        print('Yes')
    else:
        print('No')
else:
    for i in a:
        sum=sum^i
    if sum==0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

q = n // 3 
r = n % 3

dic = {}
for i in range(n):
    if a[i] not in dic:
        dic[a[i]] = 1
    else:
        dic[a[i]] += 1

res = "No"

if len(dic) == 1:
    if a[0] == 0:
        res = "Yes"
elif len(dic) == 2:
    x,y = tuple(dic.keys())
    if (x == 0 or y == 0) and r == 0:
        if x == 0:
            x = y
        if dic[x] == 2 * q and dic[0] == q:
            res = "Yes"
elif len(dic) == 3:
    x,y,z = tuple(dic.keys())
    if x ^ y == z:
        count1 = 0
        count2 = 0
        for i in (x,y,z):
            if dic[i] == q:
                count1 += 1
            elif dic[i] == q + 1:
                count2 += 1
        if count1 == 3 - r and count2 == r:
            res = "Yes"
print(res)

Submission status: Accepted

Solution code:


n=int(input())
s=list(map(int,input().split()))
a=bin(s[0]^s[1])

ans=bin(s[0])


i=1
while i!=n:
    ans=int(ans,2)
    ans=bin(ans^s[i])
    i+=1

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

Submission status: Accepted

Solution code:
R = lambda: map(int, input().split())

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

Submission status: Accepted

Solution code:
import collections



def XORC(a,b,p):
    for i in range(len(a)):
        if (int(a[i])+int(b[i]))%2 == int(p[i]):
            continue
        else:
            return False
        
    return True
            
def Solve():
    N=int(input())
    AL=[("0"*34+bin(int(x))[2:])[-33:] for x in input().split()]

    ALC=collections.Counter(AL)

    keys=list(ALC.keys())
    vals=list(ALC.values())

    if len(keys)>3:
        return 'No'
    if len(keys)==1:
        if "1" in keys[0]:
            return 'No'
        return 'Yes'
    
    if len(keys)==2:
        if "1" in keys[0] and "1" in keys[1]:
            return 'No'

        if vals[0]*2==vals[1] and ("1" not in keys[0]):
            return 'Yes'
        
        if vals[0]==vals[1]*2 and ("1" not in keys[1]):
            return 'Yes'
        
        return 'No'
    if len(keys)==3:
        if vals[0]==vals[1]==vals[2]:
            if XORC(keys[0],keys[1],keys[2]) and XORC(keys[0],keys[2],keys[1]) and XORC(keys[1],keys[2],keys[0]):
                return 'Yes'
        
        return 'No'
print(Solve())

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
c = N-1
A.sort()
num = A[0]^A[c]
pre_num = A[c]
B = [A[0],A[c],num]
while len(B) < N:
    box = num
    num = num^pre_num
    pre_num = box
    B.append(num)
B.sort()
if A == B:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if len(seta) == 3 and a.count(seta[0]) == a.count(seta[1]) and a.count(seta[1]) == a.count(seta[2]) and a.count(seta[2]) == a.count(seta[0]):
  if seta[0]^seta[1] == seta[2] and seta[1]^seta[2] == seta[0] and seta[0]^seta[2] == seta[1]:
    print("Yes")
  else:
    print("No")
elif len(seta) == 2:
  sseta = sorted(seta)
  if sseta[0] == 0 and a.count(sseta[1]) == a.count(sseta[0])*2:
    print("Yes")
  else:
    print("No")
elif len(seta) == 1 and seta[0] == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
xor = 0
for n in range(N):
  xor ^= a[n]
print('Yes' if xor == 0 else 'No')

Submission status: Accepted

Solution code:
from operator import xor

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

D = {}

for a in A :
    if a not in D :
        D[a] = 1
    else :
        D[a] += 1

if len(D) == 1 and D.get(0,0) == N :
    ans = "Yes"
elif len(D) == 3 :
    V = list(D.values())
    K = list(D.keys())
    
    if xor(K[0],K[1]) != K[2] :
        ans = "No"
    elif (V[0] == V[1] == V[2]) :
        ans = "Yes"
    else :
        ans = "No"
elif len(D) == 2 :
    if D.get(0,0)*3 == N or D.get(0,0)*3 - 1 == N :
        ans = "Yes"
    else :
        ans = "No"
else :
    ans = "No"
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())

num = list(map(int,input().split()))
c = collections.Counter(num)
if len(c) == 3:
  if c.most_common()[0][1] == c.most_common()[1][1]:
    if (c.most_common()[0][0])^(c.most_common()[1][0]) == c.most_common()[2][0]:
      print('Yes')
    else:
      print('No')
  else:
    print('No')
elif len(c) == 2:
  if c.most_common()[0][1] == 2*c.most_common()[1][1]:
    if c.most_common()[1][0] == 0:
      print('Yes')
    else:
      print('No')
  else:
    print('No')
elif len(c) == 1:
  if c.most_common()[0][0] == 0:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
 
import numpy as np
 
 
def resolve():
    N = [int(x) for x in sys.stdin.readline().split()][0]
    a_list = [int(x) for x in sys.stdin.readline().split()]
 
    max_len = len(format(max(a_list), 'b'))
    # print('{} {}'.format(N, a_list))
    bin_array = np.array([[int(b) for b in format(a, 'b').zfill(max_len)]
                          for a in a_list])
 
    # print(bin_array)
 
    sum_array = bin_array.sum(axis=0)
    # print(sum_array)
    minus_array = N - 1.5 * sum_array
    if np.all(sum_array == 0) or (np.all(minus_array >= 0) and np.all(np.mod(minus_array, 3) == 0)):
        print("Yes")
    else:
        print("No")
 
 
if __name__ == "__main__":
    resolve()
 
# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
 
import sys
from io import StringIO
import unittest
 
 
class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
 
    def test_入力例_1(self):
        input = """3
1 2 3"""
        output = """Yes"""
        self.assertIO(input, output)
 
    def test_入力例_2(self):
        input = """4
1 2 4 8"""
        output = """No"""
        self.assertIO(input, output)

Submission status: Accepted

Solution code:
from collections import defaultdict
from functools import reduce
N = int(input())
A = [int(x) for x in input().split()]
def isExist(N, A):
  AD = defaultdict(int)
  for a in A:
    AD[a] += 1
  keys = len(AD.keys())
  xor = reduce(lambda x, y: x^y, A)
  mlen = min([a for a in AD.values()])
  if xor != 0:
    return 'No'
  if keys == 1:
    return 'Yes'
  if keys == 2 and N % 3 == 0 and mlen == N // 3:
    return 'Yes'
  if keys == 3 and N % 3 == 0 and mlen == N // 3:
    return 'Yes'
  return 'No'
print(isExist(N, A))

Submission status: Accepted

Solution code:
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
a_list = [int(elem) for elem in fin().split()]

a_set = set(a_list)

all_xor = 0
for each_a in a_list:
    all_xor = all_xor ^ each_a

if len(a_list) % 3 == 0:
    if all_xor == 0:
        print('Yes')
    else:
        print('No')
else:
    if len(a_set) == 1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

cur = A[0]
for a in A[1:]:
    cur ^= a
# print(cur)
print('Yes' if cur==0 else 'No')