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:

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 in l:
                    flag += 1
                    
                if flag == 2:
                    l.remove(n)
                    break

            


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

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(map(int, input().split()))
c.sort()
c_set = set(c)
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 = n % 3
        if c.count(c[0]) == ank and c.count(c[ank]) == ank and c_set[0] ^ c_set[1] == c_set[2]:
            ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
ans = "No"
Co = Counter(A)
if n % 3 != 0 : #3の倍数でない
    if len(Co.keys()) == 1 and list(Co.keys())[0] == 0:
        ans = "Yes" #要素の種類は1つかつその要素は0の場合のみOK
else :
    tr = n // 3
    Va = Co.values()
    if len(Va) == 3 :
        if Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1] == tr:
            a,b,c = Co.most_common()[0][0],Co.most_common()[1][0],Co.most_common()[2][0]
            if a^b==c and b^c==a and c^a==b:
                ans = "Yes"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2 * tr :
        a, b = Co.most_common()[0][0], Co.most_common()[1][0]
        if a^b==a and a^a==b:
            ans = "Yes"
    elif len(Va) == 1 and Co.most_common()[0][0] == 1 :
        ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
setA = set(A)
listSetA = list(setA)

if A == [0 for i in range(n)]:
    print("Yes")
elif len(setA) == 3 and listSetA[0] ^ listSetA[1] == listSetA[2] and A.count(listSetA[0]) == A.count(listSetA[1]) == A.count(listSetA[2]):
    print("Yes")
else:
    print("No")

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()]
    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())-1
li = list(map(int,input().split()))
t = li[0]
del li[0]
for b in li:
  a = t
  for j in range(n):
    if j == n-2 and a^b in li:
      print("Yes")
      exit()
    if a^b in li:
      a,b=b,a^b
    else:
      break
print("No")

Submission status: Wrong Answer

Solution code:
_ = input()
input_num = [int(i) for i in input().split(" ")]

if sum(input_num)%2==0:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict
def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split())
    d = defaultdict(int)
    for x in a:
        d[x] += 1
    s = d.keys()
    if len(s) == 1:
        print 'Yes' if s[0] == 0 else 'No'
    elif len(s) == 2:
        print 'Yes' if (0 in s and d[s[0]] == d[s[1]]) else 'No'
    elif len(s) == 3:
        print 'Yes' if (s[0] ^ s[1] ^ s[2] == 0 and d[s[0]] == d[s[1]] == d[s[2]]) else 'No'
    else:
        print 'No'
main()

Submission status: Wrong Answer

Solution code:
P=int(input())
A=[int(i) for i in input().split(" ")]
ans=0
if A.count(0)==0:
	if len(set(A))==3:
		if P%3==0:
			if A.count(A[0])==P/3:
				n=A[0]
				A.remove(A[0])
				m=A[0]
				A.remove(A[0])
				l=A[0]
				if A.count(A[0])==P/3:
					if l==n|m or n==m|l or m==n|l :ans=1
if len(set(A))==1:
	if A[0]==0:ans=1
if len(set(A))==2:
	if P%2==0:
		if A.count(0)==P//2:ans=1

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    kind = set(a_list)
    if len(kind) not in (2, 3):
        print("No")
        return
    # 1 0 1
    # 1 2 3
    if len(kind) == 3:
        if n % 3 != 0 or len(set([a_list.count(k) for k in kind])) != 1:
            print("No")
            return
        kind = list(kind)
    else:
        a, b = kind
        a_c, b_c = a_list.count(a), a_list.count(b)
        if 0 not in kind or abs(a_c - b_c) > 1:
            print("No")
            return
        if a == 0:
            if a_c > b_c:
                print("No")
                return
            kind = [b, a, b]
        else:
            if b_c > a_c:
                print("No")
                return
            kind = [a, b, a]
    kind.extend([kind[0], kind[-1]])
    for i in range(3):
        if kind[i] != kind[i - 1] ^ kind[i + 1]:
            print("No")
            return

    print("Yes")


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 not flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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

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

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

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

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

def main():

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

	A = input().split()
	A = [int(s) for s in A]
	A.sort()

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

	num = random.uniform(0, 1)
	if num == 0:
		print("Yes")
	else:
		print("No")
		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:
				print("Yes")
				sys.exit()
		
		if next1 == a_max:
			num = random.uniform(0, 1)
			if num == 0:
				print("Yes")
			else:
				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]:
			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.append(a[0])
count = 0
for i in range(1,N):
    b = a[i-1] ^ a[i+1]
    if a[i] != b:
        count += 1
if count == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
a = [input() for i in range(2)]
 
N = int(a[0])
data = a[1].split(' ')
 
data = [int(i) for i in data]
 
result = []
for i in range(N):
    for j in range(N):
        if i <= j:
            continue
        result.append(data[i] ^ data[j])
        
sorted_data = data.sort()
sorted_result = result.sort()
 
if sorted_data == sorted_result:
    print('Yes')
    exit()
    
print('No')

Submission status: Wrong Answer

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

ans_flg = False
for i in range(N):
    if i == N - 1:
        if a[0] + a[N - 2] != a[N - 1]: 
            ans_flg = True
            break
    elif i == 0:
        if a[N - 1] - a[i + 1] != a[i]:
            ans_flg = True
            break

    else:
        if a[i + 1] - a[i - 1] != a[i]: 
            ans_flg = True
            break

if ans_flg:
    print('{}'.format('No'))
else:
    print('{}'.format('Yes'))

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 in l:
                    flag += 1
                    
                if flag == 2:
                    l.remove(n)

            


    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:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
ans = "No"
Co = Counter(A)
if n % 3 != 0 : #3の倍数でない
    if len(Co.keys()) == 1 and list(Co.keys())[0] == 0:
        ans = "Yes" #要素の種類は1つかつその要素は0の場合のみOK
else :
    tr = n // 3
    Va = Co.values()
    if len(Va) == 3 :
        if Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1] == tr:
            a,b,c = Co.most_common()[0][0],Co.most_common()[1][0],Co.most_common()[2][0]
            if a^b==c and b^c==a and c^a==b:
                ans = "Yes"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2 * tr :
        a, b = Co.most_common()[0][0], Co.most_common()[1][0]
        if a^b==a:
            ans = "Yes"
    elif len(Va) == 1 and Co.most_common()[0][0] == 1 :
        ans = "Yes"
print(ans)

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:
  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
  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()]
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.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:
import sys

def main():
    n = int(input())-1
    nums = list(map(int,input().split()))
    bins = []
    for num in nums:
        bins.append(int(bin(num)[2:]))

    #print(bins)
    #[1(0), 10(1), 100(2), 1000(3)]:No
    #[1(0), 10(1), 11(2)]:Yes
    #print(list(str(sum(bins)).replace("2","0")))
    if list(str(sum(bins)).replace("2","0")).count("0") >= 1:
        print("Yes")
    else:
        print("No")

main()

Submission status: Wrong Answer

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

a_lists.sort()


lists = []
index = [0] * n

cnt = 0
next_index = 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(0,int(n)):
    if index[i] == 1:
        next

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

        cnt_j = 0
        for k in range(0,int(n)):
            if index[k] == 1:
                next
            if i == k:
                next
            if j == k:
                next
            ret = search(i,j,k)
            if ret > 0:
                cnt_j = 1
                cnt = 1
                next_index = k
                break

        if cnt_j == 1:
            cnt = 1
            break
    if cnt == 0:
        print("No")
        exit()
        
print("Yes")

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):
    xor_a = 0
    for i in range(N):
        xor_a ^= A[i]
    if N % 3 == 0:
        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()))

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

h1 = hats[0]

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

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

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

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
a = list(int(i) for i in input().split())

while True:
    for c in itertools.combinations(a, 3):
        if c[0] ^ c[2] == c[1]:
            if len(a) == 3:
                print("No")
                exit()
            else:
                a.remove(c[1])
        elif c[1] ^ c[2] == c[0]:
            if len(a) == 3:
                print("No")
                exit()
            else:
                a.remove(c[0])
        elif c[0] ^ c[1] == c[2]:
            if len(a) == 3:
                print("No")
                exit()
            else:
                a.remove(c[2])
        else:
            print("Yes")
            exit()

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>1:
    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()))
dic = {}
if N%3 == 0:
    for a in A:
        if a not in dic:
            dic[a] = 1
        else:
            dic[a] += 1
    if len(dic) == 3:
        flag = True
        for d in dic.values():
            if d != N//3:
                flag = False
        temp = []
        for d in dic:
            temp.append(d)
        
        if flag and temp[0]^temp[1] == temp[2]:
            print('Yes')
        else:
            print('No')

    else:
        print('No')
    
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)
for i in range(len(a)):
    if i+1 == len(a):
        ans = a[i-1] ^ a[0]
        if (ans in a2):
            try:
                a2.remove(ans)
            except e:
                print("No")
                sys.exit()
        else:
            break
    else:
        ans = a[i-1] ^ a[i+1]
        if (ans in a2):
            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:
from operator import xor

n = int(input())
hats = list(map(int, input().split(' ')))

uni = list(set(hats))
count = [hats.count(uni[i]) for i in range(len(uni))]

if n % 3 == 0:
    if (len(uni) == 3) & len(set(count)) == 1:
        print(*(uni*count[0]))
    else:
        print('No')
elif n % 2 == 0:
    if (len(uni) == 2) & len(set(count)) == 1:
        print(*(uni*count[0]))
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

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

top = a[0]
if top == 0:
    if a.count(0) == n:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

las_i = -1
for i in range(len(a)):
    if a[i] == las_i:
        continue
    for j in range(i+1, len(a)):
        if top == a[i]^a[j]:
            las_i = a[i]
            if (a.count(top) == a.count(a[i]) == a.count(a[j]) 
                and a.count(top) + a.count(a[i]) + a.count(a[j]) == n):
                print("Yes")
                exit()
            break

print("No")

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
    if out==0:
        print('Yes')
    elif out==1:
        print('No')
else:#0あり
    if len(b)>2:
        print('No')
    elif len(b)==1:
        print('Yes')
    elif len(b)==2:
        if a.count(0)*3==len(a):
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

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

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

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

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

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

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

def main():

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

	A = input().split()
	A = [int(s) for s in A]
	A.sort()

	a_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:
			num = random.uniform(0, 1)
			if num == 0:
				print("Yes")
			else:
				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]:
			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:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
ans = "No"
Co = Counter(A)
if n % 3 != 0 : #3の倍数でない
    if len(Co.keys()) == 1 and list(Co.keys())[0] == 0:
        ans = "Yes" #要素の種類は1つかつその要素は0の場合のみOK
else :
    tr = n // 3
    Va = Co.values()
    if len(Va) == 3 :
        if Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1] == tr:
            a,b,c = Co.most_common()[0][0],Co.most_common()[1][0],Co.most_common()[2][0]
            if a^b==c and b^c==a and c^a==b:
                ans = "Yes"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2 * tr :
        ans = "Yes"
    elif len(Va) == 1 and Co.most_common()[0][0] == 1 :
        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.count(a[0])==n/3:
		if a.count(a[1])==n/3:
			print("Yes")
		else:
			print("No")
	else:
		print("No")
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"
    return "Yes"

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

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(map(int, input().split()))
c.sort()
c_set = set(c)
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 = n % 3
        if c.count(c[0]) == ank and c.count(c[ank]) == ank and c[0] ^ c[1] == c[2]:
            ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

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


for i in range(N):
    
    if i == 0:
        bef = mylist[-1]
        aft = mylist[i+1]
    elif i == (N-1):
        bef = mylist[i-1]
        aft = mylist[0]
    else:
        bef = mylist[i-1]
        aft = mylist[i+1]
        
    #print(bef^aft, mylist[i])
    #xor
    if format((bef^aft),'b').zfill(32) == format(mylist[i],'b').zfill(32): 
        #if (bef^aft) == format(mylist[i],'b').zfill(32):
        continue
    else:
        print(i, 'No')
        sys.exit()    
  
print('Yes')

Submission status: Wrong Answer

Solution code:
import collections

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

C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
    print("Yes")
elif (L == 2) and (C[e[0]] == C[e[1]] * 2):
    print(((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No")
elif (L == 3) and (C[e[0]] == C[e[1]]) and (C[e[1]] == C[e[2]]):
    print(((e[0] ^ e[1]) == e[2]) and "Yes" or "No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
a = list(int(i) for i in input().split())

while True:
    for c in itertools.combinations(a, 3):
        if c[0] ^ c[2] == c[1]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[1])
        elif c[1] ^ c[2] == c[0]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[0])
        elif c[0] ^ c[1] == c[2]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[2])
        else:
            if N > 10**4:
                print("Yes")
                exit()
            print("No")
            exit()

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
a=set(a_list)
a=list(a)
if 0 in a:
        if len(a) ==2:
            if a_list.count(0)==len(a_list)//2:
                    print("Yes")
            else:
                    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()

if N % 3 == 0:
    i = N // 3
    if a[0] ^ a[i] == a[2 * i]:
        print("yes")
    else:
        print("No")
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(1+"a")
                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 ls[k0] < ls[k1]:
                        print("Yes" if k1 == 0 else "No")
                    else:
                        print("Yes" if k0 == 0 else "No")
                else:
                    print("No")
            elif len(ks) == 1:
                while True:
                    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:
import sys,itertools,copy
input = sys.stdin.readline
N=int(input().strip())
an=[int(x) for x in input().strip().split()]

if N==3:
    if an[0]^an[1]==an[2]:
        print("Yes")
    else:
        print("No")
elif N%3!=0:
    if len(set(an))==1:
        print("Yes")
    else:
        print("No")
else:
    bn = list(set(an))
    if len(bn)>3:
        print("No")
    elif len(bn)==1:
        print("Yes")
    elif len(bn)==2:
        if an.count(0)==(N/3):
            print("Yes")
        else:
            print("No")
    elif bn[0]^bn[1]!=bn[2]:
        print("No")
    else:
        for b in bn:
            if an.count(b)!=(N/3):
                print("No")
                break
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(s) for s in input().split(" ")]
dic_a = {}
for aa in a:
  if aa in dic_a:
    dic_a[aa] += 1
  else:
    dic_a[aa] = 1
a_set = list(dic_a.keys())
n_set = len(a_set)

if (n < 3):
  ans = False
else:
  ans = False
  if 0 in a_set:
    for k, v in dic_a.items():
      if (v >= 2 and k != 0) or v >= 3:
        ans = True
        break
  if not ans:
    for i in range(n_set):
      for j in range(i + 1, n_set):
        a_ij = a_set[i] ^ a_set[j]
        if a_ij in a_set and\
           a_ij != a_set[i] and\
           a_ij != a_set[j]:
          ans = True
          break
      if ans:
        break

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