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()

	print("No")
	sys.exit()

	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:
			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 copy
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            if len(a) ==2:
                if a_list.count(0)==len(a_list)//3:
                        print("Yes")
                else:
                        print("No")
            else:
                    print("Yes")
    else:
            if len(a)==3:
                a1=a[0]
                a2=a[1]
                a3=a[2]
                if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                    if a_list.count(a1) ==a_list.count(a2) ==a_list.count(a3):
                            print("Yes")
                    else:
                            print("No")
                else:
                    while 1==1:
                    	print("No")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==0:
  print('Yes')
elif n%3!=0:
  print('No')
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
  print(a)
  print(l)
  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 = [int(i) for i in input().split()]

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

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

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

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

Submission status: 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:
                while True:
                    print("No")
            elif len(ks) == 1:
                print(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:
# -*- coding: utf-8 -*-
import numpy as np
#入力
#a = int(input())
#b,c = map(int, input().split())
#s = input()

N = int(input())
s = input()
a = np.asarray(s.split(), dtype=int)

#処理

d = {}
for val  in a:
    if val in d.keys():
        d[val] += 1
    else:
        d[val] = 1

keyNum = len(d.keys())
num = len(a)
keys = list(d.keys())

#条件１
if len(d.keys()) == 1 and 0 in d.keys():
    print ("Yes")
elif len(a) % 3 != 0:
    print ("No")
elif keyNum == 2:
    keys.sort()
    if keys[0] != 0:
        print ("No")
    elif d[0] != num//3:
        print ("No")
    else:
        print ("Yes")
#        keys1 = format(keys[1],'b')
#        isAll1 = True
#        for x in keys1:
#            if x != '1':
#                isAll1 = False
#                break
#        if isAll1:
#            print ("Yes")
#        else:
#            print ("No")

elif keyNum != 3:
    print ("No")

else:
    key1 = format(keys[0],'040b')
    key2 = format(keys[1],'040b')
    key3 = format(keys[2],'040b')
    isA = True
    for k1,k2,k3 in zip(key1,key2,key3):
        kk1 = int(k1)
        kk2 = int(k2)
        kk3 = int(k3)
        goukei = kk1 + kk2 + kk3
        if not (goukei == 0 or goukei == 2):
            isA = False
            break
    
    if isA:
        print ("Yes")
    else:
        print ("No")

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            if len(a) ==2:
                if a_list.count(0)==len(a_list)//3:
                        print("Yes")
                else:
                        print("No")
            else:
                    print("Yes")
    else:
            if len(a)==3:
                a1=a[0]
                a2=a[1]
                a3=a[2]
                if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                    if a_list.count(a1) ==a_list.count(a2) ==a_list.count(a3):
                            print("Yes")
                    else:
                        while 1==1:
                            print("No")
                else:
                    print("No")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
list1 = list(map(int,input().split()))
list1.insert(0,list1[n-1])
list1.append(list1[1])
for i in range(n):
  flag = 1
  for j in range(n):
    if list1[i]^list1[j] == list1[i+1]:
      flag = 0
      break;
  if flag==1:
    break;
if flag != 1:
  dic1 = collections.Counter(list1[1:(n+1)])
  list2 = list(dic1.values())
  m = len(list2)-1
  for k in range(m):
    if list2[k] != list2[k+1]:
      flag = 1
      break;
if flag != 1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            if len(a) ==2:
                if a_list.count(0)==len(a_list)//3:
                        print("Yes")
                else:
                        print("No")
            else:
                    print("Yes")
    else:
            if len(a)==3:
                a1=a[0]
                a2=a[1]
                a3=a[2]
                if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                    if a_list.count(a1) ==a_list.count(a2) ==a_list.count(a3):
                        while 1==1:
                            print("Yes")
                    else:
                        print("No")
                else:
                    print("No")
            else:
                print("No")

Submission status: Wrong Answer

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

print(main())

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:
			print("No")
			sys.exit()
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()

		elif next1 == A[0]:
			print("No")
			sys.exit()
			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())
figure = list(map(int, input().split()))
p=0
for i in range(1):
  for j in range(i+1,n-1):
    figure[j] = figure[i]^figure[j]
for k in range(2,n):
  if figure[1]==figure[k]:
    print("Yes")
    p+=1
    break
if p==0:
  print("No")

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
arr = list(map(int,input().split()))
d = {}

for a in arr:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1


if len(d) == 1:
    if 0 in d:
        print("Yes")
elif len(d) == 2:
    if n%3 != 0:
        print("No")
    elif 0 in d:
        flag = True
        for key in d.keys():
            if key == 0:
                if not d[key] == n//3:
                    flag = False
            else:
                if not d[key] == 2*n//3:
                    flag=False
        if flag:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

elif len(d) != 3:
    print("No")

else:
    if n % 3 != 0:
        print("No")
    else:
        tartar = [0,0,0]
        num = [0,0,0]
        temp = 0
        for key in d.keys():
            tartar[temp] = key
            num[temp] = d[key]
            temp+=1
        if not (num[0] == num[1] and num[1] == num[2]):
            print("No")
        else:
            tar2 = [
                [tartar[0], tartar[1], tartar[2]],
                [tartar[0], tartar[2], tartar[1]],
                [tartar[1], tartar[0], tartar[2]],
                [tartar[1], tartar[2], tartar[0]],
                [tartar[2], tartar[1], tartar[0]],
                [tartar[2], tartar[0], tartar[1]],

            ]
            flag = False
            for tar in tar2:
                x1 = tar[0]^tar[1]
                x2 = tar[1]^tar[2]
                x3 = tar[0]^tar[2]

                if x1 == tar[2] and x2 == tar[0] and x3== tar[1]:
                    flag = True
            if flag:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	if N != 3:
		print("No")
		return

	val_set = set()
	c = (A[0]>>2)<<2
	possible = True
	for a in A:
		tmp = a
		add_val = tmp&1
		add_val |= ((tmp>>1)&1)<<1
		cur = (tmp>>2)<<2
		if c != cur:
			possible = False
		val_set.add(add_val)
	if not possible:
		print("No")
		return

	possible = False
	ans_arr = [[1, 2, 3], [0, 1, 3], [0, 2, 3], [0, 1, 2]]
	for arr in ans_arr:
		this_ans = True
		for a in arr:
			if not a in val_set:
				this_ans = False
		if this_ans:
			possible = True
			break
	if possible:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 'Yes'

for i in range(N):
    if i == 0:
        if (arr[N-1] ^ arr[1]) == arr[0]:
            continue
        else:
            ans = 'No'
            break
    elif i == N-1:
        if (arr[N-2] ^ arr[0]) == arr[N-1]:
            continue
        else:
            ans = 'No'
            break
    else:
        if (arr[i-1] ^ arr[i+1]) == arr[i]:
            continue
        else:
            ans = 'No'
            break

print(ans)

Submission status: Wrong Answer

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

N = int(input())

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

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

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


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

Submission status: Wrong Answer

Solution code:
a=int(input())
b= list(map(int, input().split()))
b.append(b[0])
b.append(b[1])
d=0

for i in range(a):
    c= int(b[i]^b[i+2])
    if c!=b[i+1]:
        d += 1
        break

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

Submission status: Wrong Answer

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

ans = [-1]*n

# first
ans[0] = a.pop(0)
is_next = False
for i in range(len(a)):
    for j in range(i+1, len(a)):
        if ans[0] == a[i]^a[j]:
            ans[1] = a.pop(i)
            ans[-1] = a.pop(j-1)
            is_next = True
            break
    if is_next:
        break
if is_next == False:
    print("No")
    exit()
if n == 3:
    print("Yes")
    exit()

def my_index(l, x, default=False):
    return l.index(x) if x in l else default

for i in range(2, n-2):
    index = my_index(a, ans[i-2]^ans[i-1])
    if index == False:
        print("No")
        exit()
    ans[i] = a.pop(index)

# last
ans[-2] = a.pop(0)
if ans[-2] != ans[-3]^ans[-1] or ans[-1] != ans[-2]^ans[0]:
    print("No")
    exit()

print("Yes")

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_lists = list(input().split())

lists = []
index = [0] * n

cnt = 0

def search(a,b,c):

    if int(a_lists[a]) == int(a_lists[b]) ^ int((a_lists[c])):
        index[c] = 1
        index[a] = 1
        index[b] = 1

        return 1
    else:
        return -1

for i in range(int(n)-2):
    if index[i] == 1:
        next

    for j in range(i+1,int(n)):
        if index[j] == 1:
            next

        cnt = 0
        for k in range(i+2,int(n)):
            if index[k] == 1:
                next
            ret = search(i,j,k)
            if ret > 0:
                cnt = 1
                break
        if cnt == 0:
           print("No") 
           exit()
        else:
            break

print("Yes")

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            if len(a) ==2:
                if a_list.count(0)==len(a_list)//3:
                        print("Yes")
                else:
                        print("No")
            else:
                while 1==1:
                    print("No")
    else:
            if len(a)==3:
                a1=a[0]
                a2=a[1]
                a3=a[2]
                if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                    if a_list.count(a1) ==a_list.count(a2) ==a_list.count(a3):
                        print("Yes")
                    else:
                        print("No")
                else:
                    print("No")
            else:
                print("No")

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())

if n != 3:
    print('No')
else:
    if min(dic.values()) == max(dic.values()):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys

def solve(n, a):
    
    set_a = set(a)
    a_0 = a[0]
    for i in range(n):
        if i == 0:
            continue

        prev_a = a[i]
        next_a = a_0 ^ a[i]
        count = 0
        while count < n :
            next_next_a = prev_a ^ next_a
            if next_next_a not in set_a:
               break
            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 copy
import numpy
import sys

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

count=0

for i in range(N-1):
    first = List[i]
    a = copy.deepcopy(List)
    
    for j in range(i+1,N-1):
        acopy = copy.deepcopy(List)
        second = a[j]
        acopy.remove(second)
        
        for k in (i+j+1,N-1):

            xor = bin(first ^ second)
            check = int(xor,2)

            if (check in acopy):
                first = a[k]
                second = check
                acopy.remove(second)

            else:
                continue

            if (k == (N-1)):
                count = 1
                break
    
        if(count == 1):
            print("Yes")
            sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
if N > 4:
    print('No')
else:
    if bin(a[0] ^ a[2]) == bin(a[1]) and bin(a[1] ^ a[2]) == bin(a[0]) and bin(a[1] ^ a[0]) == bin(a[2]):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
aLst = list(map(int, input().split()))
aLst.sort()
ansB = True
for i in range(N):
    if i == (N - 2):
        if aLst[i] == (aLst[i + 1] ^ aLst[0]):
            continue
        else:
            ansB = False
            break
    elif i == (N - 1):
        if aLst[i] == (aLst[0] ^ aLst[1]):
            continue
        else:
            ansB = False
            break
    else:
        if aLst[i] == (aLst[i + 1] ^ aLst[i + 2]):
            continue
        else:
            ansB = False
            break

if ansB:
    print('Yes')
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]
    for i in range(0, nk):

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

        center = keys[i]
        max = start + center

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

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

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

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

        if found == True:
            break

    if found == False:
        dprint("first pair search failed")
        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, -1)
        if rcount <= 0:
            dprint("break rcount:", rcount)
            print("No")
            return

        dprint("found", right, rcount)

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

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

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


solve()

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            if len(a) ==2:
                if a_list.count(0)==len(a_list)//3:
                        print("Yes")
                else:
                    while 1==1:
                        print("No")
            else:
                print("No")
    else:
            if len(a)==3:
                a1=a[0]
                a2=a[1]
                a3=a[2]
                if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                    if a_list.count(a1) ==a_list.count(a2) ==a_list.count(a3):
                        print("Yes")
                    else:
                        print("No")
                else:
                    print("No")
            else:
                print("No")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int ,input().split()))
a.extend(a[:2])
 
ans = 'Yes'
for x in range(N):
    if int(bin(a[x]^a[x+2]), 0) != a[x+1]:
        ans = 'No'
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
n = int(n)
a = input().split()
a = [int(i) for i in a]
a.append(a[0])
a.append(a[1])
c = 1
for i in range(n):
  if a[c-1] ^ a[c+1] == a[c]:
    c += 1
  else: 
    print('No')
    break
if c == n+1:
  print('Yes')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

import sys

n= int(sys.stdin.readline())
ai  = []
even= []
odd = []
lmax= 0
for i,x in enumerate( sys.stdin.readline().split() ):
    a = int(x)
    ai.append(a)
    #
    if a%2==0: even.append(i)
    else: odd.append(i)
    #
    tmp= len(bin(a))-2
    if tmp>lmax: lmax= tmp
#
ne= len(even)
no= len(odd)
if no!=0 and no!=2*ne:
    print( "No" )
    exit()
#
first=None
for e in even:
    ee = ai[e]
    if len(bin(ee))==lmax+2:
        first= ee
        break
#
if first==None:
    print( "No" )
    exit()
#
second=[]
if no>0:
    for o in odd:
        oo = ai[o]
        if len(bin(oo))==lmax+2: second.append(oo)
else:
    for e in even:
        ee = ai[e]
        if len(bin(ee))==lmax+2: second.append(ee)
#
if len(second)==0:
    print( "No" )
    exit()
#
ans= "No"
for s in second:
    tmp= [first,s]
    for i in range(2,n):
        nn = tmp[-1] ^ tmp[-2]
        if nn in ai and not nn in tmp:
            tmp.append(nn)
        else:
            break
    #
    if len(tmp)==n and tmp[-2]==tmp[-1]^tmp[0] and tmp[-1]==tmp[0]^tmp[1]:
        ans="Yes"
        break
#
print( ans )

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])
rev = []

rev.append(res[0])
hoge = res[1:]
hoge.reverse()
rev.extend(hoge)

rev_a = []
rev_a.append(a[0])
fuga = a[1:]
fuga.reverse()
rev_a.extend(fuga)

mes = "Yes"
for i, j in enumerate(res):
  if(a[i] != j):
    mes = ("No")
mes1 = "Yes"
for i, j in enumerate(rev):
  if(rev_a[i] != j):
    mes1 = ("No")
if(mes == "Yes" or mes1 == "Yes"):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
b=[0]*n

if n%2==0:
    k=int(n/2)
    
    for i in range(k-1):
        b[2*i+2]=b[2*i]^a[2*i+1]
    b[0]=b[2*k-2]^a[2*k-1]
    for i in range(k-1):
        b[2*i+3]=b[2*i+1]^a[2*i+2]
    b[1]=b[2*k-1]^a[0]

    if b[0]==0 and b[1]==0:
        print("Yes")
    else:
        print("No")
    
else:
    k=int(n//2)
    
    for i in range(k):
        b[2*i+2]=b[2*i]^a[2*i+1]
    for i in range(k):
        b[2*i+1]=b[2*i-1]^a[2*i]
    b[0]=b[2*k-1]^a[2*k]
    print(b)
    if b[0]==0:
        print("Yes")
    else:
        print("No")