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: Wrong Answer

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)
    if np.all(sum_array == 0) or np.all(N - 1.5 * sum_array == 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: Wrong Answer

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, AD.keys())
  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: Wrong Answer

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

flag = 0
even = []
odd = []
for i in a:
    if i%2 == 0:
        even.append(i)
    else:
        odd.append(i) 

if n%2 == 1:
    if len(odd) >= 1:
        flag = 1
else:
    if len(odd)/2 != len(even):
        flag = 1

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

Submission status: Wrong Answer

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

if n!=3:
    for i in range(0,n-2):
        if  (bin(a[i] ^ a[i+2]))==bin(a[i+1]):
            continue
        else:
            s=1

    if  (bin(a[n-1] ^ a[1]))==bin(a[0]):
        f=0
    else:
        s=1

    if  bin((a[n-2] ^ a[0]))==bin(a[n-1]):
        f=0
    else:
        s=1



else:
    if  (bin(a[0] ^ a[1]))==bin(a[2]):
        f=0
    else:
        s=1
    if  (bin(a[1] ^ a[2]))==bin(a[0]):
        f=0
    else:
        s=1
    if  (bin(a[2] ^ a[0]))==bin(a[1]):
        f=0
    else:
        s=1

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

Submission status: Wrong Answer

Solution code:
import itertools
import sys

N = int(input())
A_list = list(map(int,input().split()))
B_list = list()
for i in A_list:
	B_list.append(bin(i))

bin_0 = bin(A_list[0])
bin_2 = bin(A_list[2])


for i in itertools.combinations(A_list,2):
	ans = bin(i[0]^i[1])
	if ans in B_list:
		print('Yes')
		sys.exit()
	else:
		continue
print('No')

Submission status: Wrong Answer

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = False

def check(i,j):
    firsti = i
    c[i] -= 1
    c[j] -= 1
    for k in range(len(a)-3):
        if c[i^j] == 0:
            return False
        i = j
        j = i^j
        c[i^j] -= 1
    if i^j == firsti:
        return True
    else:
        return False

for  i in range(len(a)-1):
    for j in range(i+1,len(a)):
        if check(a[i],a[j]):
            hoge = True
            break
        else:
            break
    else:
        continue
    break

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

Submission status: Wrong Answer

Solution code:
import sys
import itertools

N = int(input())
A = input().split()

#print(list(itertools.combinations(a,5)))
listA = list(itertools.combinations(A,5))

for i in range(N):
	for j in range(len(listA)):
		a = listA[j]
		x = int(a[(i-1)%N])
		y = int(a[(i+1)%N])
		print(a[i%N])
		print(x, y)
		print(x^y)

		if int(a[i%N]) != x^y:
			print('No')
			sys.exit(0);

print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a_2=[]
for i in range(len(a)):
    a_2.append(bin(a[i]))
import collections
c = collections.Counter(a)
b=[]
for i in c.values():
    b.append(i)
if a.count(0)==0:
    for i in range(len(b)):
        if len(b)%3!=0:
            print('No')
            break
        elif b[i]!=b[i+1] and i!=len(b)-2:
            print('No')
            break
        elif i==len(b)-2:
            print('Yes')
            break
        else:
            pass
else:
    if len(b)>2:
        print('No')
    elif len(b)==1:
        print('Yes')
    else:
        if a.count(0)*3==len(a):
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

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

def all_zero(a):
    for e in a:
        if e != 0:
            return False
    return True

if N != 3:
    if all_zero(a):
        print("Yes")
    else:
        print("No")
else:
    p = itertools.permutations(a, 3)
    yes = False
    for permed_a in p:            
        good_perm = True
        for i in range(3):
            if permed_a[(i + 1) % 3] != (permed_a[i] ^ permed_a[(i + 2) % 3]):
                good_perm = False
                break
        if good_perm:
            yes = True
            break
    if yes:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
A = int(input())
B =list(map(int,input().split()))
cnt = 0
for i in range(A - 1):
    if i == 0 :
        continue
    if bin(B[i - 1] ^ B[ i +1]) == bin(B[i]):
        cnt += 1
if A-2 ==cnt:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

for i in range(n):
	if a[i]%2 == 1:	c += 1

if c==0 :	print("Yes")
elif n%3==0 and n*2/3==c :	print("Yes")
else:		print("No")

Submission status: Wrong Answer

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) > 1:
	ans = []
	vals = []
	for i in dic:
		vals.append(i)
	j = 0
	for i in range(n):
		while 1:
			if dic[vals[j%len(vals)]]:
				ans.append(vals[j%len(vals)])
				j += 1
				break
			j += 1
	for i in range(n):
		if ans[(i-1)%n]^ans[(i+1)%n] != ans[i]:
			print "No"
			exit(0)
	print "Yes"
else:
	if 0 in dic:
		print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#S = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	A = input().split()
	A = [int(s) for s in A]
	A.sort()
	#A_map = [False for _ in range(N)]

	a_max = A[-1]
	#A_map[-1] = True

	a = 2
	i = 1
	ll = [1]
	while a < 100000+1:
		a = 2 ** i
		ll.append(a)
		i += 1
		if a_max == a:
			print("No")
			sys.exit()

	tmp = 0
	flg = False
	for i in ll:
		tmp += i
		if a_max == tmp:
			flg = True
			break
	
	if flg == False:
			print("No")
			sys.exit()

	bk = -1
	next1 = -1
	for i, val in enumerate(A):
		if i == 0:
			tmp = a_max - val
			if tmp in A:
				bk = val
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
		if i == N-1:
			if next1 == a_max and bk ^ A[0] == a_max:
				print("Yes")
				sys.exit()
		
		tmp = next1 + bk
		if tmp in A:
				bk = val
				next1 = tmp
				continue
		else:
			print("No")
			sys.exit()
		
	print("No")


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(N-1):
    b = a[i-1] ^ a[i+1]
    if i == (N-1):
        b = a[i-1] ^ a[0]
        if a[i] != b:
            count += 1
    elif a[i] != b:
        count += 1
if count == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import operator
n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)

isTrue = False

if n == 4:
    if a[0] == 0 and a[1] == 0 and a[2] == a[3] and operator.xor(a[2], a[3]) == 0:
        isTrue = True
elif n % 3 == 0:
    m = int(n / 3)
    m0 = len(set(a[0:m]))
    m1 = len(set(a[m:m*2]))
    m2 = len(set(a[m*2:m*3]))
    if m0 == 1 and m1 == 1 and m2 == 1:
        if operator.xor(a[0], a[1]) == a[2]:
            isTrue = True
        elif operator.xor(a[1], a[2]) == a[0]:
            isTrue = True
        elif operator.xor(a[2], a[0]) == a[1]:
            isTrue = True
if isTrue:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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:
        q = n // 2
        r = n % 2
        count1 = 0
        count2 = 0
        for i in (x,y):
            if dic[i] == q:
                count1 += 1
            elif dic[i] == q + 1:
                count2 += 1
        if count1 == 2 - r and count2 == r:
            res = "Yes"
        """
    pass
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: Wrong Answer

Solution code:
A = int(input())
B =list(map(int,input().split()))
cnt = 0
for i in range(A - 1):
    if i == 0 :
        continue
    if bin(B[i - 1] ^ B[ i +1]) == bin(B[i]):
        cnt += 1
    else:
        print("No")
        exit()
if A-2 ==cnt:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a_2=[]
for i in range(len(a)):
    a_2.append(bin(a[i]))
import collections
c = collections.Counter(a)
b=[]
for i in c.values():
    b.append(i)
if a.count(0)==0:
    for i in range(len(b)):
        if len(b)%3!=0:
            print('No')
            break
        elif b[i]!=b[i+1] and i!=len(b)-2:
            print('No')
            break
        elif i==len(b)-2:
            print('Yes')
            break
        else:
            pass
else:
    if len(b)!=2:
        print('No')
    else:
        if a.count(0)*3==len(a):
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

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

found = False
for i in range(n - 1):
    found = False
    for j in range(i + 1, n):
        tgt = a[i] ^ a[j]
        if a.count(tgt) > 0:
            found = True
            break
    if not found:
        break
if found:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import random
a = random.randint(0,1)
if(a/2==0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

flag = 0
for i in range(n):
    if((i+1) == n):
        l = 0
    elif((i+1)<n):
        l = i + 1
        
    if((i-1) == -1):
        r = n - 1
    elif((i-1) > -1):
        r = i - 1
    
    # print(str(i)+" :"+str(l)+","+str(r))
    if(bin(a[i]) != bin(a[l] ^ a[r])):
        flag = 1
        break
        
if(flag == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
import copy

n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))

b1=a[0]
b_lis=copy.copy(a)
b_lis.remove(b1)
judge=0
for i in range(n-1):
    c_lis=copy.copy(b_lis)
    b1d=b1
    b2=a[i+1]
    c_lis.remove(b2)
    while True:
        b3=b1d^b2
        if b3 in c_lis:
            c_lis.remove(b3)
            b1d=b2
            b2=b3
        else:
            break
        if len(c_lis)==0:
            judge=0
            break

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

Submission status: Wrong Answer

Solution code:
n = input()
a = list(map(int, input().split()))
res = []
for n in range(len(a)):
  if(n == (len(a) - 1)):
    res.append(a[n - 1]^a[0])
  else:
    res.append(a[n - 1]^a[n + 1])
ling = []
for i, num in enumerate(res):
  if(num == 1):
    ling.extend(res[i:])
    ling.extend(res[0:i])
    break
mes = "Yes"
for i, j in enumerate(ling):
  if(i+1 != j):
    mes = ("No")
    break
print(mes)

Submission status: Wrong Answer

Solution code:
n =int(input())
rakuda = [0] * n

rakuda = []
s = input()
rakuda = s.split(' ')
# print(rakuda)

# for i in range(n):
#     # print(i)
#     rakuda[i] = int(input())

flag = True
for i in range(n):
    left = i - 1;
    right = i + 1;
    if(left == -1): left = n - 1
    if(right == n): right = 0
    
    if((int(rakuda[left]) ^ int(rakuda[right])) != int(rakuda[i])):
        flag = False
        break


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

Submission status: Wrong Answer

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

if len(set(a)) == 1 and a[0] == 0:
    print('Yes')
elif N % 3 == 0:
    if len(set(a)) == 3:
        if a[0] != 0 and a.count(a[0]) == a.count(a[N//3]) == a.count(a[N//3*2]) == N//3:
            print('Yes')
        else:
            print('No')
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) == N//3*2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

if a[0] != a[len(a)-1]^a[1]:
    print('No')
    sys.exit()

for i in range(1,N-1):
    if a[i] != a[i-1]^a[i+1]:
        print('No')
        sys.exit()

if a[len(a)-1] != a[len(a)-2]^a[0]:
    print('No')
    sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
n = list(map(int, input().split()))
t = 0
s = 0
for l in range(N):
    s += n[l]
if N > 100000:
    print("No")
elif len(n) != N:
    print("No")
elif s != (N ** 2 + N) / 2:
    print("No")
else:
    for i in range(N):
      if i == 0:
        if n[N-1] ^ n[1] == n[0]:
            t += 1
      elif i == N-1:
        if n[N-2] ^ n[0] == n[N-1]:
          t += 1
      else:
        if n[i-1] ^ n[i+1] == n[i]:
          t += 1
    if t == N:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
l = list(map(int, input().split()))
a = 0
for i in range(1, N):
  if l[0] ^ l[i] in l:
    a = l[0] ^ l[i]
    b = l[i]
    c = l[0]
    l.pop(0)
    l.remove(b)
    l.remove(a)
    break
if a == 0:
  print('No')
else:
  for i in range(3, N):
    if b ^ a in l:
      a, b = b ^ a, a
      l.remove(a)
    else:
      print('No')
      sys.exit()
  if a ^ b == c:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=set(a)
l=len(b)
if l==1:
  if a[0]==0:print("Yes")
  else:print("No")
  exit()
elif l!=3:print("No");exit()
if n%3!=0:print("No");exit()
def ecount(X):
  c,ans=1,[]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans.append(c);c=1
  ans.append(c)
  return ans
d=sorted(ecount(a))
if b.pop()^b.pop()==b.pop() and d[0]==d[2]:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

N = int(input().strip())
As = list(map(int, input().strip().split(' ')))
candidates = list(set(As))

if len(candidates) == 1:
    if candidates[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(candidates) == 2:
    a, zero = candidates
    if a < zero:
        a, zero = zero, a

    bits = format(a, 'b')
    if zero == 0 and bits.find('0') == -1:
        count_a = 0
        count_zero = 0
        for element in As:
            if element == 0:
                count_zero += 1
            elif element == a:
                count_a += 1
        else:
            if count_a == count_zero or abs(count_a - count_zero) == 1:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
elif len(candidates) > 3:
    print('No')
else:
    a, b, c = candidates[0], candidates[1], candidates[2]
    if a ^ b != c:
        print('No')
    else:
        count_a = 0
        count_b = 0
        count_c = 0
        for element in As:
            if element == a:
                count_a += 1
            elif element == b:
                count_b += 1
            elif element == c:
                count_c += 1
        else:
            if count_a == count_b == count_c:
                print('Yes')
            else:
                print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int, input().split()))
A=0
for i in range(N):
  Be=a[len(a)-1] if i==0 else a[i-1]
  Af=a[0] if i==len(a)-1 else a[i+1]
  A+=Be^Af

if sum(a)==A:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(s) for s in input().split(" ")]
a_set = set(a)

if (n < 3):
  ans = False
else:
  ans = False
  for i in range(n):
    for j in range(i, n):
      if a[i] ^ a[j] in a_set:
        ans = True
        break
    if ans:
      break

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

Submission status: Wrong Answer

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

import itertools

def xorcircle(s,m):
    for t in range(m):
        if s[t-1] ^ s[t+1] != t:
            return False
        else:
            return True
        
l = list(itertools.permutations(a))
m = len(l)

for i in range(m):
    if xorcircle(l[i],n) == True:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

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

xorNeighbor = 0
xorNeighborS = 0
nonZero = []

for i in range(1, len(a)-1):
    xorNeighbor = a[i-1] ^ a[i] ^ a[i+1]
    xorNeighborS ^= xorNeighbor
    if xorNeighbor:
        nonZero.append(xorNeighbor)

if len(nonZero) == 0:
    print("Yes")
else:
    nonZero.append(xorNeighborS)
    #print(nonZero)
    try:
        while len(nonZero):
            removeVal = nonZero[0]
            nonZero.remove(removeVal)
            nonZero.remove(removeVal)
        print("Yes")
    except:
        print("No")

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
inp = [int(x) for x in input().split()]
m = max(inp)
a = [format(x, '0' + str(len(str(format(m, 'b')))) + 'b') for x in inp]

def mk_pair(f):
    s11, s12 = '', ''
    s21, s22 = '', ''
    for c in f:
        cn = '1' if c == '0' else '0'
        s11 += c
        s12 += c if c == '0' else cn
        s21 += cn
        s22 += cn if c == '0' else c
    return (s11, s12), (s21, s22)

def axor(p1, p2):
    res = ''
    for c1, c2 in zip(p1, p2):
        res += '0' if c1 == c2 else '1'
    return res

def check(a, p, first):
    sa = set(a)
    sa.discard(first)
    p1, p2 = p

    r1 = first
    r2 = first

    c1 = p1
    c2 = p2

    rest = len(sa)
    while True:
        if rest == 0:
            return True
        if rest < 0:
            return False
        n1 = axor(r1, c1)
        n2 = axor(r2, c2)
        if (n1 == n2 and n1 in sa and rest == 1):
            return True
        if (n1 in sa and n2 in sa):
            rest -= 2
            sa.discard(n1)
            sa.discard(n2)
            r1 = c1
            r2 = c2
            c1 = n1
            c2 = n2
        else:
            return False

for p in mk_pair(a[0]):
    ans = check(a, p, a[0])
    if ans:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

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]
    second = 0
    third = 0
    for i in range(1, nk):
        center = keys[i]
        max = start + center

        for j in range(i+1, nk):
            right = keys[j]
            if right > max:
                # これより大きいところにはない
                break

            if right == start ^ center:
                found = True
                break
        if found == True:
            break

    if found == False:
        print("No")
        return

    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, 0)
        if rcount == 0:
            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("break", start, left, center)
        print("No")


solve()

Submission status: Wrong Answer

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

    if not a[N-1] ^ a[1] == a[0]:
        print("No")
        exit()
    elif not a[N-2] ^ a[0]  == a[N-1]:
        print("No")
        exit()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=[int(_) for _ in input().split()]
c=collections.Counter(a)
l=len(c.keys())
k=list(c.keys())
v=list(c.values())
print(c)
if l > 3:
    print("No")
elif l == 3:
    if k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2] and n%3==0:
        print("Yes")
    else:
        print("No")
elif l == 2:
    if k[0] == 0:
        if v[1] == v[0]*2 and n%3==0:
            print("Yes")
        else:
            print("No")
    elif k[1] == 0:
        if v[0] == v[1]*2 and n%3==0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif l == 1:
    if k[0] == 0:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

if len(set(a)) == 3:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
ai = [int(x) for x in input().split()]

bi = sum([int(bin(x)[2:]) for x in ai])
if list(set(str(bi)))[0] == "2" or "0":
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
#n = 3
#a = [1,2,3]
if a.count(0) == n:
      print("Yes")
else:
  if n % 3 != 0:
    print("No")
  else:
    s = set(a)
    if len(s)!=3:
      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: Wrong Answer

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:
        q = n // 2
        r = n % 2
        count1 = 0
        count2 = 0
        for i in (x,y):
            if dic[i] == q:
                count1 += 1
            elif dic[i] == q + 1:
                count2 += 1
        if count1 == 2 - r and count2 == r:
            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: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if i==0:
    ai=a[i]
    x=a[i+1]^a[n-1]
    if x==ai:
      ans="Yes"
    else:
      ans="No"
      break
  elif i==n-1:
    ai=a[i]
    x=a[0]^a[i-1]
    if x==ai and ans=="Yes":
      ans="Yes"
    else:
      ans="No"
      break
  else:
    ai=a[i]
    x=a[i+1]^a[i-1]
    if x==ai and ans=="Yes":
      ans="Yes"
    else:
      ans="No"
      break
print(ans)

Submission status: Wrong Answer

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

aArr.sort()
aSet = set(aArr)

a = aArr[-1]
setSum = sum(aSet) -a
arrSum = sum(aArr[:-1])
arrSum -= arrSum - setSum

ans = ["No", "Yes"][a == arrSum]
print(ans)

Submission status: Wrong Answer

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(N%3==0):
    if(len(nul)==3):
        a = nul[0]
        b = nul[1]
        c = nul[2]
        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)
        
        sum = a_np + b_np + c_np
        
        amari = sum%2
        
        ind = np.where(amari==1)
        
        if(len(ind[0])==0):
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A_lis = list(map(int, input().split()))
A_lis.sort()
B_lis = []

Al0 = A_lis.pop(0)
B_lis.append(Al0)

def init_lis(Al):
	for i in range(N-1):
		for r in range(1, N-1):
			if Al0 ^ A_lis[r] == A_lis[i]:
				Ai = A_lis[i]
				Ar = A_lis[r]
				del A_lis[i]
				del A_lis[r-1]
				return(Ai,Ar)
	return(False,False)

Ai0,Ar0 = init_lis(Al0)
B_lis.append(Ai0)
B_lis.append(Ar0)
if Ai0==False:
	print("No")
	exit()

for i in range(2,N-1):
	is_good = False
	for r in range(len(A_lis)):
		is_good = False
		if B_lis[i-1] ^ A_lis[r] == B_lis[i]:
			is_good = True
			B_lis.append(A_lis[r])
			del A_lis[r]
			break
	if is_good == False:
		print("No")
		exit()

if B_lis[N-2]^B_lis[0] == B_lis[N-1]:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
if n % 3:
    ans = 'No'
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: Wrong Answer

Solution code:
import sys

N = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[0])

for i in range(N):
    if i == 0:
        if bin(a[N-1] ^ a[i+1]) == bin(a[i]):
            continue
        else:
            print("No")
            sys.exit()

    else:
        if bin(a[i-1] ^ a[i+1]) == bin(a[i]):
            continue
        else:
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

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(17))
#print(b_list)
for n in range(17):
    test_list = []
    for b in b_list:
        test_list.append(b[n])
    if test_list.count('1') == test_list.count('0') * 2:
        print("Yes")
        break
else:
    print("No")

Submission status: Wrong Answer

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

flag = 0
if len(As) == 1:
    if As[0] == 0:
        flag = 1
elif len(As) == 2:
    d = {}
    for a in A:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    if As[0] == 0 and d[As[0]]*2 == d[As[1]]:
        flag = 1
else:
    if len(As) == 3:
        if As[0]^As[1] == As[2]:
            flag = 1

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