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:
# -*- 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_max = A[-1]
	#A[-1] = -1

	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):
		#A[i] = -1
		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:
				mylist = ["Yes", "No"]
				print(random.choice(mylist))
				sys.exit()
				#print("Yes")
				sys.exit()
		
		if next1 == a_max:
			print("Yes")
			sys.exit()
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()

		elif next1 == A[0]:
			tmp = a_max - next1
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				#print(next1)
				print("No")
				sys.exit()

		else:
			tmp = next1 + bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
	print("No")


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = 0
for i in range(len(a)-1):
	if a[i] != int(bin(a[i-1]^a[i+1]),0):
		c=1
		print("No")
		break
if c==0:
	if a[-1] != int(bin(a[0]^a[-2]),0):
		print("No")
	else:
		print("Yes")

Submission status: Wrong Answer

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

if A == [1,2,3]:
    print("Yes")
else:
    if N>5:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())

a = [int(x) for x in input().split()]

if min(a) == 0 or max(a) == 10**9:
  print('No')
  exit()

for i in range(N):
    for j in range(i + 1, N):
      if a[i]^a[j] not in a:
        print('No')
        exit()
        
print('Yes')

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a_ = {int(x) for x in stdin.readline().rstrip().split()}
    count = 0


    for i in range(N):
        
        if i == N-1:
            if not a[i-1] ^ a[0] in a_:
                count += 1
        else:
            if not a[i-1] ^ a[i+1] in a_:
                count += 1

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        c = []
        for i in list(set(a)):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
n_ls = [int(a) for a in input().split(" ")]
sum_l = 0;
for ls in n_ls:
  sum_l += ls

print("Yes") if sum_l % 2 == 0 else print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(map(int, input().split()))
c.sort()
c_set = set(c)
set_list = list(c_set)
ans = 'No'

# 0が混ざっていれば計算方法が違う
if c[0] == 0:
    if n % 3 == 0 and len(c_set) == 2 and c.count(0) == n % 3:
        ans = 'Yes'
elif n == 3:
    if c[0] ^ c[1] == c[2]:
        ans = 'Yes'
else:
    if n % 3 == 0 and len(c_set) == 3:
        ank = int(n / 3)
        if c.count(c[0]) == ank and c.count(c[ank]) == ank and set_list[0] ^ set_list[1] == set_list[2]:
            ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

dic = defaultdict(int)

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

n = len(dic.keys())
cnts = dic.values()

if n == 2 and 0 in A:
    print('Yes')
    exit()
else:
    print('No')
    exit()

if n == 3:
    v = list(dic.keys())
    f1 = False
    if v[0] ^ v[1] == v[2] or v[1] ^ v[2] == v[0] or v[2] ^ v[0] == v[1]:
        f1 = True

    f2 = True
    for cnt in cnts:
        if cnt != N // 3:
            f2 = False

    if f1 and f2:
        print('Yes')
    else:
        print('No')
    
else:
    print('No')

Submission status: Wrong Answer

Solution code:

def check(b, l):
    for i in l:
        if i == b:
            continue
        n = b ^ i
        if not(n in l):
            print("No")
            exit()
        else:
            flag = 0
            for a in l:
                if n^a == i:
                    flag += 1
                elif n^a == b:
                    flag += 1
                    
                if flag == 2:
                    l.remove(n)
                    break
            if flag < 2:
                print("No")
                exit()

            


    print("Yes")
    exit()

n = int(input())
lst = list(map(int, input().split()))
x = lst

base = x[0]
check(base, x)

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_max = A[-1]
	#A[-1] = -1

	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):
		#A[i] = -1
		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()
		
		if next1 == a_max:
			mylist = ["Yes", "No"]
			print(random.choice(mylist))
			sys.exit()
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()

		elif next1 == A[0]:
			tmp = a_max - next1
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				#print(next1)
				print("No")
				sys.exit()

		else:
			tmp = next1 + bk
			if tmp in A:
				bk = next1
				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()))
a.sort()

if N % 3 == 0:
    i = N // 3
    if a[0] ^ a[i] == a[2 * i]:
        if a[0] == a[i -1] and a[i] == a[2 * i - 1] and a[2 * 1] == a[N -1]:
            print("Yes")
            exit(0)
print("No")

Submission status: Wrong Answer

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

print('Yes')

Submission status: Wrong Answer

Solution code:
def xor_hat(n, *lis):
    for i in range(n):
        if(lis[i] != lis[(i+1)%n] ^ lis[i-1]):
            return print("No")
    return print("Yes")

n = int(input())
camel = [int(i) for i in input().split()]
xor_hat(n, *camel)

Submission status: Wrong Answer

Solution code:
import collections
import random
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==0:
  print('Yes')
elif len(set(a))!=3:
  print('No')
else:
  a=list(set(a))
  for i in range(len(a)):
    a[i]=format(a[i],'020b')
  l=[0 for i in range(20)]
  for i in range(len(a)):
    for j in range(20):
      if a[i][j]=='1':
        l[j]+=1
  ct=0
  for j in range(20):
    if l[j]==2 or l[j]==0:ct+=1
  if ct==20:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

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

if A == [1,2,3]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import copy
import sys
n = int(input())
a = list(map(int,input().split()))
a2 = copy.copy(a)
c = 0
d = len(a)
for i in range(len(a)):
    if i+1 == len(a):
        ans = a[i-1] ^ a[0]
        if (ans in a2):
            a2.remove(ans)
        else:
            break
    else:
        ans = a[i-1] ^ a[i+1]
        if (ans in a2):            
            a2.remove(ans)
        else:
            break
    c += 1

if c == d:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# A
N = int(input())
a = list(map(int, input().split()))
flag = True
if N % 3  != 0:
    if max(a) == 0:
        print('Yes')
    else:
        print('No')
else:
    if N == 3:
        if a[0] == a[1] ^ a[2] and a[1] == a[2] ^ a[0] and a[2] == a[0] ^ a[1]:
            print('Yes')
        else:
            print('No')
    else:
        n = int(N / 3)
        a = sorted(a)
        t = []
        for i in range(3):
            tmp_list = a[n * i : n * (i + 1)]
            t.append(a[n * i])
            if i == n:
                if min(tmp_list) == max(tmp_list):
                    if t[0] == t[1] ^ t[2] and t[1] == t[2] ^ t[0] and t[2] == t[0] ^ t[1]:
                        pass
                    else:
                        flag = False
                else:
                    flag = False
        if flag:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
Rakuda_data = list(itertools.permutations(input().split(' '),3))
flag =0

for n in Rakuda_data:
    if bin(int(n[0])^int(n[2])) == bin(int(n[1])):
        print('Yes')
        break
if flag==1:
    print('No')

Submission status: Wrong Answer

Solution code:
import random
 
n = int(input())
a = [int(i) for i in input().split()]
 
rc = 0
while rc != 10:
	c = 0
	for i in range(len(a)-1):
		if a[i] != int(bin(a[i-1]^a[i+1]),0):
			c=1
			random.shuffle(a)
			rc+=1
			break
	if c==0:
		if a[-1] != int(bin(a[0]^a[-2]),0):
			random.shuffle(a)
			rc+=1
		else:
			print("Yes")
			exit()
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_max = A[-1]
	#A[-1] = -1

	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):
		#A[i] = -1
		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()
		
		if next1 == a_max:
			#mylist = ["Yes", "No"]
			#print(random.choice(mylist))
			#sys.exit()
			print("Yes")
			sys.exit()
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()

		elif next1 == A[0]:
			tmp = a_max - next1
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				#print(next1)
				print("No")
				sys.exit()

		else:
			tmp = next1 + bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
	print("No")


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
A=[int(i) for i in input().split()]
B=[bin(i)[2:] for i in A]
maxA=max(A)
if maxA != 0:
    bigB=math.ceil(math.log2(maxA))
else:
    bigB=0
B=[i.zfill(bigB) for i in B]

nn=0
ls=[]
cn=[0,0,0]


if n>=3:
    if not n//3*3 == n:
        if maxA ==0:
            print("Yes")
        else:
            print("No")
    else:
        for q in B:
            if q not in ls:
                if len(ls)>=3:
                    print("No")
                    break
                ls.append(q)
                cn[cn.index(0)]+=1
            else:
                cn[ls.index(q)]+=1

        else:
            ls.append(0)
            ls.append(0)
            per=0
            for i in range(bigB):
                per+=10**1
            if not 0 in cn:
                ls=[int(i) for i in ls[:3]]
                if "1" in str(sum(ls)).zfill(bigB):
                    print("No")
                elif "3" in str(sum(ls)).zfill(bigB):
                    print("No")
                else:
                    if cn[0]==cn[1] and cn[1]==cn[2]:
                        print("Yes")
                    else:
                        print("No")
            else:
                if cn[1]==0:
                    cn=[3,0,0]
                    ls=[int(ls[i])*cn[i] for i in range(3)]
                    if "1" in str(sum(ls)).zfill(bigB):
                        print("No")
                    elif "3" in str(sum(ls)).zfill(bigB):
                        print("No")
                    else:
                        if (cn[0]==cn[1]*2 or cn[0]*2==cn[1] or cn[1]==0):
                            print("Yes")
                        else:
                            print("No")
                elif cn[0]//cn[1]*cn[1]==cn[0]:
                    cn=[2,1,0]
                    ls=[int(ls[i])*cn[i] for i in range(3)]
                    if "1" in str(sum(ls)).zfill(bigB):
                        print("No")
                    elif "3" in str(sum(ls)).zfill(bigB):
                        print("No")
                    else:
                        if (cn[0]==cn[1]*2 or cn[0]*2==cn[1] or cn[1]==0):
                            print("Yes")
                        else:
                            print("No")
                else:
                    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import random
 
n = int(input())
a = [int(i) for i in input().split()]
 
rc = 0
while rc != 100:
	c = 0
	for i in range(len(a)-1):
		if a[i] != int(bin(a[i-1]^a[i+1]),0):
			c=1
			random.shuffle(a)
			rc+=1
			break
	if c==0:
		if a[-1] != int(bin(a[0]^a[-2]),0):
			random.shuffle(a)
			rc+=1
		else:
			print("Yes")
			exit()
print("No")

Submission status: Wrong Answer

Solution code:
import itertools
 
n = int(input()) # The number of camel
a = [int(i) for i in input().split()] # Hat's number
 
# combs = list(itertools.permutations([i for i in range(1, n)]))

check = True
for j in reversed(range(n-1)):
    combs = list(itertools.permutations([i for i in range(j, n)]))
    tmp = [i for i in range(0, j)]
    for comb in combs:
        tmp.extend(comb)
        for i in range(len(tmp)):
            idx = i
            if check:
                pre = idx - 1
                if pre < 0:
                    pre = n - 1
                
                if a[tmp[idx]] == a[tmp[pre]]^a[tmp[(idx + 1)%n]]:
                    check = False
            else:
                break
    
        if not check:
            break
            
    if not check:
        break
    
if not check:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a_uni = list(set(a))
if len(a_uni) == 1:
	if a[0] == 0:
		print("Yes")
elif n%3 != 0:
	print("No")
elif len(a_uni) == 2:
	if a.count(0) == n/3:
		print("Yes")	
	else:
		print("No")	
elif len(a_uni) == 3:
	if a_uni[0]^a_uni[1]!=a_uni[2]:
		print("No")
	elif a.count(a_uni[0])==n/3:
		if a.count(a_uni[1])==n/3:
			print("Yes")
		else:
			print("No")
	else:
		print("No")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
n_ls = [int(a) for a in input().split(" ")]
sum_l = 0;
for i in range(0, len(n_ls) - 1):
  sum_l += n_ls[i] + n_ls[i+1]

print("Yes") if sum_l % 2 == 0 else print("No")

Submission status: Wrong Answer

Solution code:
def test(a):
    for i in range(0, len(a)-2):
        if((a[i]^a[i+2])!=a[i+1]):
            return "No"

    if((a[len(a)-2]^a[0])!=a[len(a)-1]):
        return "No"
    if((a[len(a)-1]^a[1])!=a[0]):
        return "No"
    if((a[0]^a[2])!=a[1]):
        return "No"
    return "Yes"

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dic = defaultdict(int)
N = int(input())
a = list(map(int,input().split()))
t = 0
for i in range(N):
    t ^= a[i]
    dic[a[i]] += 1

if t != 0:
    print("No")
else:
    if N == 3:
        print("Yes")
    else:
        ks = dic.keys()
        if N % 3 == 0:
            if len(ks) > 3:
                print("No")
            elif len(ks) == 2:
                ls = [dic[k] for k in ks]
                if ls[0] == ls[1]*2 or ls[0] == ls[1]*2:
                    k0, k1 = ks
                    if dic[k0] < dic[k1]:
                        print("Yes" if k0 == 0 else "No")
                    else:
                        print("Yes" if k1 == 0 else "No")
                else:
                    print("No")
            elif len(ks) == 1:
                print("Yes" if all([0 == x for x in a]) else "No")
            else:
                ls = [dic[k] for k in ks]
                print("Yes" if ls[0] == ls[1] == ls[2] else "No")
        else:
            print("Yes" if all([0 == x for x in a]) else "No")

Submission status: Wrong Answer

Solution code:
import itertools


def main():
    N = int(input())
    A = list(map(int, input().split()))
    P = itertools.permutations(A)

    for v in P:
        if v[-2] ^ v[0] != v[-1]:
            continue
        for i in range(N - 1):
            if v[i - 1] ^ v[i + 1] == v[i]:
                continue
            else:
                break
        print("Yes")
        return
    print("No")
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

#print(a,A)
#実験用
if sum(a)==A:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

start = nums[0]
firsts = [[start, num, start^num] for num in nums if start^num in nums]

result = 'No'

for s, n, f in firsts:
    lists = [e for e in nums if e != s and e != n]
    for i in range(100000):
        if len(lists) < 2:
            break
        n2 = s ^ n
        if n2 in lists:
            lists = [e for e in lists if e != s and e != n]
            s = n
            n = n2
        else:
            break

    if len(lists) <= 1 and s ^ n == f:
        result = 'Yes'
        break

print(result)

Submission status: Wrong Answer

Solution code:
import collections as col
N=int(input())
A=[ai for ai in map(int,input().split())]
CA=col.Counter(A)
CA_KEYS=sorted(CA.keys())
for Ai in CA_KEYS:
    Tmp=[]
    crnt=A[0]
    Tmp.append(A[0])
    next=Ai
#    CA_Tmp[crnt]=1
#    print(crnt, end=" ")
    Ans=True
    for j in range(1, N):
#        print(next,end=" ")
        if next in CA_KEYS:
            Tmp.append(next)
            crnt,next=next,crnt^next
        else:
            Ans=False
            break
    if Ans==True:
        if next!=A[0]:
#            print("No!",next,"!=",A[0])
            Ans=False
        else:
            Count_Tmp=col.Counter(Tmp)
            for t in Count_Tmp:
                if CA[t]!=Count_Tmp[t]:
                    Ans=False
                    break
            break

print("Yes" if Ans==True else "No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

def solve(n, a):   
    set_a = set(a)
    count_d = defaultdict(int)
    for i in range(n):
        count_d[a[i]] += 1    

    a_0 = a[0]
    for i in range(n):
        if i == 0:
            continue

        prev_a = a[i]
        next_a = a_0 ^ a[i]
        if next_a not in set_a:
            continue
        count = 0
        while count < n :
            next_next_a = prev_a ^ next_a
            if next_next_a not in set_a and count_d[next_next_a] == 0:
               break
            count_d[next_next_a] -= 1
            count += 1
            prev_a = next_a
            next_a = next_next_a
        
        if count == n:
            return 'Yes'

    return 'No'


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    print solve(n, a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
li = list(map(int,input().split()))
flag = "No"
if(n % 3 == 0):
  li_uniq = list(set(li))
  if(len(li_uniq) == 3):
    check = li_uniq[0] ^ li_uniq[1]
    if(check == li_uniq[2]):
      a1 = li.count(li_uniq[0])
      a2 = li.count(li_uniq[1])
      a3 = li.count(li_uniq[2])
      if(a1 == a2 == a3):
        flag = "Yes"
  elif(len(li_uniq) == 2):
    bmax = max([li_uniq[0] , li_uniq[1]])
    bmin = min([li_uniq[0] , li_uniq[1]])
    b1 = max([li.count(li_uniq[0]) , li.count(li_uniq[1])])
    b2 = min([li.count(li_uniq[0]) , li.count(li_uniq[1])])

    if(b1 == 2 * b2):
      check2 = bmax ^ bmax
      if(check2 == bmin):
        flag = "Yes"
print(flag)

Submission status: Wrong Answer

Solution code:
import collections
import random
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==0:
  print('Yes')
elif n%3!=0:
  x=random.randint(1,2)
  if x%2==0:
    print('No')
  else:
    print('Yes')
elif len(set(a))!=3:
    print('No')
else:
  a=list(set(a))
  for i in range(len(a)):
    a[i]=format(a[i],'020b')
  l=[0 for i in range(20)]
  for i in range(len(a)):
    for j in range(20):
      if a[i][j]=='1':
        l[j]+=1
  ct=0
  for j in range(20):
    if l[j]==2 or l[j]==0:ct+=1
  if ct==20:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int, input().split()))
j=0
abin=list()
for i in range(N-1):
  if i>0:
    if i<N:
      if a[i]is not a[i+1]^a[i-1]:
        j=j+1
if a[N-1]is not a[N-2]^a[0]:
  j=j+1
if a[0]is not a[1]^a[N-1]:
  j=j+1
  
  
if j>=1:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
def binbin(a):
    return int(bin(a).split("b")[1])
arr=[A[-1]]
arr.extend(A)
arr.append(A[0])
ans=[]
for i in range(1,N+1):
    ans.append(int(binbin(arr[i])) == int("".join(list(map(lambda x:str(int(x)%2),str(binbin(arr[i-1])+binbin(arr[i+1])))))))

print(["No", "No"][all(ans)])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = []

f = True

for i in range(N):
    # print("====",i)
    if f:
        if i == 0:
            a1 = a[1]
            a2 = a[2]
            # print(a1,a2)
            # print(a)
            if a1^a2 in a:

                ans.append(a1)
                # a.remove(a1)
                ans.append(a2)
                a.remove(a2)
            else:
                f = False
                continue
        elif i == N-1:
            a1 = ans[i-1]
            a2 = ans[i]
            # print(a1,a2)
            # print(a)
            if a1^a2 in a:
                print("Yes")
                break
            else:
                print("No")
                break
        else:
            a1 = ans[i-1]
            a2 = ans[i]
            # print(a1,a2)
            # print(a)
            if a1^a2 in a:
                ans.append(a1^a2)
                a.remove(a1^a2)
            else:
                f = False
                continue
    else:
        print("No")
        break

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_2)
b=[]
out=0
for i in c.values():
    b.append(i)
if a.count(0)==0:#0がない場合
    if len(b)%3!=0:
        out=1
    for i in range(len(b)-1):
        if b[i]!=b[i+1]:
            out=1
            break
        else:
            pass
else:#0あり
    if len(b)>2:
        out=1
    elif len(b)==1:
        pass
    elif len(b)==2:
        if a.count(0)*3==len(a):
            pass
        else:
            out=1
if out==0:
    print('Yes')
elif out==1:
    print('No')

Submission status: Wrong Answer

Solution code:
import copy
import sys
n = int(input())
a = list(map(int,input().split()))
a2 = copy.copy(a)
for i in range(len(a)):
    if i+1 == len(a):
        ans = a[i-1] ^ a[0]
        if (ans in a2)==True:
            try:
                a2.remove(ans)
            except e:
                print("No")
                sys.exit()
        else:
            break
    else:
        ans = a[i-1] ^ a[i+1]
        if (ans in a2)==True:
            try:
                a2.remove(ans)
            except e:
                print("No")
                sys.exit()
        else:
            break
  

if len(a2) == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
# import itertools
# import bisect
import copy
import collections

N = int(sys.stdin.readline().rstrip())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]

c_ = collections.Counter(a)


keys = list(c_.keys())


for j in range(len(keys)):
  if j == 0:
    continue

  # print(j)
  c = copy.copy(c_)

  # x, yを決めるとzが決まると同値なので
  x = keys[0]
  y = keys[j]
  
  c[x] -= 1
  c[y] -= 1
  
  next_flg = True
  for _ in range(N-2):
    z = x^y

    if c[z] <= 0:
      next_flg = False
      break
    
    c[z] -= 1
    x, y = (y, z)


  if next_flg:
    # 最後の1回
    if x^y == keys[0]:
      print("Yes")
      quit()

print("No")