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

	mylist = ["Yes", "No"]
	print(random.choice(mylist))
	sys.exit()

	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())
figure = list(map(int, input().split()))
figure1 = []
n_loop = n
p=0
for j in range(1,n):
  figure1.append(figure[0]^figure[j])
for k in range(2,n-1):
  if figure1[0]==figure[k]:
    number1 = figure[0]
    number2 = figure[1]
    number3 = figure[k]
    figure.remove(figure[0])
    figure.remove(figure[0])
    figure.remove(figure[k-2])
    figure1 = []
    n_loop -=3
    p+=1
    break
if p == 1:
  while(p ==n-2):
    for j in range(1,n_loop-p+1):
      now = number1^number2
      if(now==figure[j]):
        number1 = number2
        number2 = figure[j]
        p+=1
        figure.remove(figure[j])
        break
if(p!=(n-2)):
  print("No")

Submission status: Wrong Answer

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

a.reverse()
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])

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

Submission status: Wrong Answer

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

hats = A[:]
d = {}
for h in hats:
    d[h] = True

h1 = hats[0]

def search(now1, now2, count, remaining):
    now1, now2 = now2, now1^now2
    if now2 in d:
        if now2 == h1:
            if count == N:
                return True
            else:
                return False
        else:
            try:
                return search(now1, now2, count+1, remaining.remove(now1))
            except:
                return False
    else:
        return False
    

ans = False
for h2 in hats[1:]:
    if search(h1, h2, 2, set(hats)):
        ans = True
        break

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a = input()
list1 = list(map(int,a.split()))
flag = 0

#中間部分の処理
for i in range(1, N-1):

    bin_num1 = list(format(list1[i-1],"b"))
    bin_num2 = list(format(list1[1+1],"b"))
    bin_num3 = []
    le,le2 = 0,0
    ans = 0
    if len(bin_num1) <= len(bin_num2):
        le = len(bin_num1)
        le2 = len(bin_num2)
        flag = 0
    else:
        le = len(bin_num2)
        le2 = len(bin_num1)
        flag = 1

    for j in range(le):
        if (int(bin_num1[len(bin_num1)-1 - j]) + int(bin_num2[len(bin_num2)-1 - j])) == 0 or (int(bin_num1[len(bin_num1)-1 - j]) + int(bin_num2[len(bin_num2)-1 - j])) == 2 :
            bin_num3.append("0")
        else:
            bin_num3.append("1")
    if le <le2:
        if flag == 0:
            for k in range(le2-le-1 , -1,-1):
                bin_num3.append(bin_num2[k])
        elif flag == 1:
            for k in range(le2-le-1 , -1,-1):
                bin_num3.append(bin_num1[k])

    bin_num3.reverse()

    ans = int("".join(bin_num3) ,2)

    if ans != int(list1[i]):
        print("No")
        sys.exit()

#最初の部分の処理

bin_num1 = list(format(list1[N-1],"b"))
bin_num2 = list(format(list1[1],"b"))
bin_num3 = []
le = 0
le2 = 0
ans = 0
if len(bin_num1) <= len(bin_num2):
    le = len(bin_num1)
    le2 = len(bin_num2)
    flag = 0
else:
    le = len(bin_num2)
    le2 = len(bin_num1)
    flag = 1

for i in range(le):
    if (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 0 or (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 2 :
        bin_num3.append("0")
    else:
        bin_num3.append("1")
if le <le2:
    if flag == 0:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num2[k])
    elif flag == 1:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num1[k])


bin_num3.reverse()
ans = int("".join(bin_num3) ,2)

if ans != list1[0]:
    print("No")
    sys.exit()

#最後の部分の処理

bin_num1 = list(format(list1[N-2],"b"))
bin_num2 = list(format(list1[0],"b"))
bin_num3 = []
le = 0
le2 = 0
ans = 0
if len(bin_num1) <= len(bin_num2):
    le = len(bin_num1)
    le2 = len(bin_num2)
    flag = 0
else:
    le = len(bin_num2)
    le2 = len(bin_num1)
    flag = 1

for i in range(le):
    if (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 0 or (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 2 :
        bin_num3.append("0")
    else:
        bin_num3.append("1")
if le <le2:
    if flag == 0:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num2[k])
    elif flag == 1:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num1[k])


bin_num3.reverse()
ans = int("".join(bin_num3) ,2)

if ans != list1[N-1]:
    print("No")
    sys.exit()

for i in range(N):
    if i == 0 and i +2 == 0:
        print("No")
        sys.exit()

#一回も引っかからなければこれで終わり
print("Yes")

Submission status: Wrong Answer

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

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    arr = read_h()
    #  print(arr)

    cnts = {}
    for a in arr:
        cnts[a] = cnts.get(a, 0) + 1
    #  print(cnts)

    rem = sum(cnts.values())
    for i in range(n - 1):
        a = arr[i]
        if cnts[a] <= 0:
            continue

        cnts[a] -= 1
        rem -= 1
        if rem == 0:
            break

        tmp_rem = rem
        for j in range(i + 1, n):
            b = arr[j]
            if cnts[b] <= 0:
                continue

            xor = a ^ b
            if xor not in cnts or cnts[xor] <= 0:
                continue

            cnts[b] -= 1
            cnts[xor] -= 1
            rem -= 2
            #  print(a, b, xor)
            #  print('remain:', cnts)
            break

        if tmp_rem == rem:
            print('No')
            return

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

	def solve_odd(start, a_list):
		tmp = list(a_list)
		a = tmp.pop(start)
		cur = 2
		while tmp:
			found = False
			for i, cur_a in enumerate(tmp):
				if cur_a^a == cur:
					cur += 2
					cur %= N
					a = tmp.pop(i)
					found = True
			if not found:
				return False
		return True
	if N%2 == 0:
		print("No")
		return
	for i in range(N):
		if solve_odd(i, A):
			print("Yes")
			return
	print("No")


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

a_coll  = collections.Counter(a)
a_key   = list(a_coll.keys())
a_value = list(a_coll.values())

if N % 3 != 0:
    if len(a_key) == 1 and a_key[0] == 0:
        print("Yes")
    else:
        print("No")
        exit()

if len(a_key) == 1:
    if a_key[0] == 0:
        print("Yes")
        exit()

if len(a_key) == 2:
    if 0 in a_key:
        print("Yes")
        exit()

for count in a_value:
    if count != N / 3:
        print("No")
        exit()

if len(a_key) == 3:
    if a_key[0] ^ a_key[1] == a_key[2]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

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

for i in range(0,n-1):
    for j in range(i,n):
        if not i == j:
            x = a[i] ^ a[j]
            #print(a[i],a[j],x)
            for k in range(n):
                #print(x,b[k])
                if x == b[k]:
                    b[k] = -1
                    #print('aaa',b)
                    if sum(b) == -1 * n:
                        print('Yes')
                        exit()

print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

for tsumugi in range(n - 1):
    for matsuri in range(tsumugi, n):
        if (a[0] ^ a[tsumugi] ^ a[matsuri] == 0):
            b[0] = a[0]
            b[1] = a[tsumugi]
            b[2] = a[matsuri]
            a[0] = 0
            a[tsumugi] = 0
            a[matsuri] = 0
            flag = 1
            break
    if (flag == 1):
        break

if (flag == 0):
    print("No")
    sys.exit()

if (n < 4):
    print("Yes")
    sys.exit()

#when n > 3
count_b = 0
flag1 = 0

for tomoka in range(n - 3):
    flag1 = 0
    for nao in range(n):
        if (a[nao] == 0):
            continue
        if (b[count_b] ^ b[count_b + 1] ^ a[nao] == 0):
            b[count_b] = a[nao]
            a[nao] = 0
            count_b += 1
            flag1 = 1
            break
    if(flag1 == 0):
        print("No")
        sys.exit()
    
if (b[0] ^ b[n-1] ^ b[n] == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
sum = 1

sum = sum * (x.count(x[n-1] ^ x[1])>0)
for i in range(1, (n-1 - 1 )):
    sum = sum * (x.count(x[i-1] ^ x[i+1])>0)
sum = sum * (x.count(x[n-2] ^ x[0])>0)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 'Yes'
tmp0 = arr.count(0)
tmp1 = arr.count(1)
if tmp0 * 2 == tmp1:
    print(ans)
    exit()

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:
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) == int(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:
import collections

N = int(input())

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

a_coll  = collections.Counter(a)
a_key   = list(a_coll.keys())
a_value = list(a_coll.values())

print(len(a_key))

if N % 3 != 0:
    if len(a_key) == 1 and a_key[0] == 0:
        print("Yes")
    else:
        print("No")
        exit()

if len(a_key) == 1:
    if a_key[0] == 0:
        print("Yes")
        exit()

if len(a_key) == 2:
    if 0 in a_key:
        print("Yes")
        exit()

for count in a_value:
    if count != N / 3:
        print("No")
        exit()

if len(a_key) == 3:
    if a_key[0] ^ a_key[1] == a_key[2]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
flag = True
for i in range(1,len(a)-1) :
  if a[i-1]^a[i+1] != a[i] :
    flag = False
if a[n-1] != a[n-2]^a[0] or a[0] != a[1]^a[n-1] :
  flag = False
if flag :
  print('Yes')
else :
  print('No')

Submission status: Wrong Answer

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

a.reverse
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])

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

Submission status: Wrong Answer

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

perm = [0]
success = 0

def circle_xor(n, m = 1):
    global success
    if n == m:
        for i in range(0,2):
            back = perm[i-2]
            middle = perm[i-1]
            front = perm[i]
            if a[back] ^ a[front] == a[middle]:
                if i == 1:
                    success = 1
                    return
                continue
            else:
                break
    else:
        for i in range(1, n):
            if i in perm:
                continue
            perm.append(i)
            if m > 2 and n != 3:
                back = perm[i-2]
                middle = perm[i-1]
                front = perm[i]
                if a[back] ^ a[front] == a[middle]:
                    circle_xor(n, m + 1)
                else:
                    continue
            elif n == 3:
                circle_xor(n, m + 1)
            perm.pop()

circle_xor(n)

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

Submission status: Wrong Answer

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

ans = "No"
B = list(set(A))
if B[0] == 0 and len(B) == 1:
    ans = "Yes"
elif N % 3 != 0:
    pass
else:
    if len(B) != 3:
        pass
    else:
        
        if B.count(B[0]) == B.count(B[1]) and B.count(B[0]) == B.count(B[2]):
            C = [0] * 3
            C[2] = format(B[2], 'b')
            M = len(C[2])
            C[0] = format(B[0], 'b')
            C[1] = format(B[1], 'b')
            S = ["000", "011", "101", "110"]
            
            if len(C[1]) == M and len(C[0]) < M:
                cnt  = 0
                while len(C[0]) < M:
                    C[0] = "0" + C[0]
                    cnt += 1
                for i in range(M):
                    ans = "Yes"
                    now = C[2][i] + C[1][i]
                    if C[0][i] == "b":
                        now = now + "0"
                    else:
                        now += C[0][i]
                    if now in S:
                        pass
                    else:
                        ans = "No"
                        break
            
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a = input()
list1 = list(map(int,a.split()))
flag = 0

#中間部分の処理
for i in range(1, N-1):

    bin_num1 = list(format(list1[i-1],"b"))
    bin_num2 = list(format(list1[1+1],"b"))
    bin_num3 = []
    le,le2 = 0,0
    ans = 0
    if len(bin_num1) <= len(bin_num2):
        le = len(bin_num1)
        le2 = len(bin_num2)
        flag = 0
    else:
        le = len(bin_num2)
        le2 = len(bin_num1)
        flag = 1

    for j in range(le):
        if (int(bin_num1[len(bin_num1)-1 - j]) + int(bin_num2[len(bin_num2)-1 - j])) == 0 or (int(bin_num1[len(bin_num1)-1 - j]) + int(bin_num2[len(bin_num2)-1 - j])) == 2 :
            bin_num3.append("0")
        else:
            bin_num3.append("1")
    if le <le2:
        if flag == 0:
            for k in range(le2-le-1 , -1,-1):
                bin_num3.append(bin_num2[k])
        elif flag == 1:
            for k in range(le2-le-1 , -1,-1):
                bin_num3.append(bin_num1[k])

    bin_num3.reverse()

    ans = int("".join(bin_num3) ,2)

    if ans != int(list1[i]):
        print("No")
        sys.exit()

#最初の部分の処理

bin_num1 = list(format(list1[N-1],"b"))
bin_num2 = list(format(list1[1],"b"))
bin_num3 = []
le = 0
le2 = 0
ans = 0
if len(bin_num1) <= len(bin_num2):
    le = len(bin_num1)
    le2 = len(bin_num2)
    flag = 0
else:
    le = len(bin_num2)
    le2 = len(bin_num1)
    flag = 1

for i in range(le):
    if (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 0 or (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 2 :
        bin_num3.append("0")
    else:
        bin_num3.append("1")
if le <le2:
    if flag == 0:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num2[k])
    elif flag == 1:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num1[k])


bin_num3.reverse()
ans = int("".join(bin_num3) ,2)

if ans != list1[0]:
    print("No")
    sys.exit()

#最後の部分の処理

bin_num1 = list(format(list1[N-2],"b"))
bin_num2 = list(format(list1[0],"b"))
bin_num3 = []
le = 0
le2 = 0
ans = 0
if len(bin_num1) <= len(bin_num2):
    le = len(bin_num1)
    le2 = len(bin_num2)
    flag = 0
else:
    le = len(bin_num2)
    le2 = len(bin_num1)
    flag = 1

for i in range(le):
    if (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 0 or (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 2 :
        bin_num3.append("0")
    else:
        bin_num3.append("1")
if le <le2:
    if flag == 0:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num2[k])
    elif flag == 1:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num1[k])


bin_num3.reverse()
ans = int("".join(bin_num3) ,2)

if ans != list1[N-1]:
    print("No")
    sys.exit()

for i in range(0,N,2):
    if i == 0 and i +2 == 0:
        print("No")
        sys.exit()

#一回も引っかからなければこれで終わり
print("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("Yes")
				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:
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
        c += 1
    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:
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:
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 and a.count(a_uni[1])==n/3:
		print("Yes")
	else:
		print("No")
else:
	print("No")

Submission status: Wrong Answer

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

def main():
    if a[0] != 0 and a[0] != a[-1] ^ a[1]:
        print("No")
        return
    for i in range(1, N - 1):
        if a[i] == 0:
            continue
        if a[i] != a[i + 1] ^ a[i - 1]:
            print("No")
            return
    if a[-1] != a[0] ^ a[-2]:
        print("No")
        return
    print("Yes")

main()

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>10:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

hats = A[:]
d = {}
for h in hats:
    d[h] = True

h1 = hats[0]

def search(now1, now2, count, remaining):
    now1, now2 = now2, now1^now2
    if now2 in d:
        if now2 == h1:
            if count == N:
                return True
            else:
                return False
        else:
            try:
                return search(now1, now2, count+1, remaining.remove(now1))
            except:
                return False
    else:
        return False
    

ans = False
for h2 in hats[1:]:
    if search(h1, h2, 2, set(hats)):
        ans = True

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

Submission status: Wrong Answer

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

even = [0]*10 #偶数
odd = [0]*10#奇数

for i in range(N):
    BIT = bin(A[i])

    for j in range(10):

        UnderThree = bin(0b0000000111 & int(BIT,0))
        UTten = int(UnderThree,0)

        if UTten % 2 == 0:
            even[j] += 1
        else:
            odd[j] += 1

        if int(BIT,0) > 7:
            tmp = int(BIT,0)
            BIT = bin(tmp >> 3)
        else:
            break

Judge = True

for b in range(10):
    if not(2*even[b] == odd[b] or odd[b] == 0):
        Judge = False

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


# 111
# 011
# 100
# 110
# 101
# 100
# 101
# 000
# 000
# 000

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
import copy

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

        tmp_count_d = copy.deepcopy(count_d)

        prev_a = a[i]
        next_a = a_0 ^ a[i]
        if next_a not in set_a and tmp_count_d[next_a] <= 0:
            continue
        tmp_count_d[next_a] -= 1

        count = 0
        while count < n :
            next_next_a = prev_a ^ next_a
            if next_next_a not in set_a and tmp_count_d[next_next_a] <= 0:
               break
            tmp_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:
n = int(input())
a = list(map(int, input().strip().split()))
b = a.copy()
s = []


for i in range(n):
    for j in range(n):
        if not i == j:
            x = a[i] ^ a[j]
            #print(a[i],a[j],x)
            for k in range(n):
                #print(x,b[k])
                if x == b[k]:
                    b[k] = -1
                    #print('aaa',b)
                    if sum(b) == -1 * n:
                        print('Yes')
                        exit()

print('No')

Submission status: Wrong Answer

Solution code:
def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    A = sorted(A)
    xor_a = 0

    if N % 3 == 0:
        if A[0] == 0:
            for i in range(N//3):
                if A[i] != 0:
                    return 0
            for i in range(N//3, N):
                if A[i] != A[N//3]:
                    return 0
            return 1
        else:
            for i in range(N):
                xor_a ^= A[i]
            return 1 if xor_a == 0 else 0
    else:
        return 0


if __name__ == '__main__':
    inputs = read()
    print('Yes' if solve(*inputs) else 'No')

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int, input().split()))
j=0
for i in range(N-1):
  if i>0:
     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")