Problem:


Score : 300 points

Problem Statement

Snuke has N hats. The i-th hat has an integer a_i written on it.

There are N camels standing in a circle.
Snuke will put one of his hats on each of these camels.

If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.

The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.

What is XOR?

The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.

Sample Input 2

4
1 2 4 8

Sample Output 2

No

There is no such way to distribute the hats; the answer is No.



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
import 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]*2 or cn[0]*2==cn[1] or cn[1]==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:

import numpy as np 

def make_bit(A):
    arr = np.zeros(31)
    i = 30
    while A:
        arr[i] = A % 2
        A = A // 2
        i -= 1

    return arr

def return_first_second_third(a_lst):
    first = [a_lst[0], 0]
    second = [-1, -1]
    third = [-1, -1]
    i = 0
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            second[0] = a_lst[i+1]
            second[1] = i+1
            i += 1
            break
        else:
            i += 1
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            third[0] = a_lst[i+1]
            third[1] = i+1
            i += 1
            break
        else:
            i += 1
    
    return first, second, third


N = int(input())

a_lst = list(map(int, input().split()))
a_lst.sort()
first, second, third = return_first_second_third(a_lst)
a_lst.reverse()

done = False
if second[0] == -1: # 全ての数が同じとき
    done = True
    if first[1] == 0: # 全ての数がゼロの時
        print("Yes")
    else:
        print("No")
elif third[0] == -1:    # 数が2種類だけの時
    done = True
    if N % 2 == 0 and second[1] == N // 2:
        print("Yes")
    else:
        print("No")
elif N == 0 and second[1] == N // 3 and third[1] == N * 2 // 3:
    a_lst = [ a_lst[0] + a_lst[second[0]] + a_lst[third[0]] ]


if not done:
    if N == 3:

        a1 = make_bit(a_lst[0])
        a2 = make_bit(a_lst[1])
        a3 = make_bit(a_lst[2])
        bits_arr = np.array([a1, a2, a3])

        judge = True
        for i in range(31):
            if bits_arr[0][i] == bits_arr[1][i] and bits_arr[2][i] == 1:
                judge = False
                break

            elif bits_arr[0][i] != bits_arr[1][i] and bits_arr[2][i] == 0:
                judge = False
                break
                
        if judge:
            print("Yes")
        else:
            print("No")


    else:
        print("No")

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:
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in range(len(a)):
    if i+1 == len(a):
        if (a[i-1] ^ a[0]) == a[i]:
            c += 1
    else:
        if (a[i-1] ^ a[i+1]) == a[i]:
            c += 1            
            
if c == len(a):
    print("Yes")
elif abs(c - len(a)) < n/2:
    print("Yes")
else:
    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//3):
                if A[i] != A[0]:
                    return 0
            for i in range(N // 3, 2 * N // 3):
                if A[i] != A[N // 3]:
                    return 0
            for i in range(2 * N // 3, N):
                if A[i] != A[2 * N // 3]:
                    return 0
            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:
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

from itertools import permutations
if N == 3:
    for pattern in permutations(a_list, N):
        f = True
        for i in range(0, N-1):
            f = f and (pattern[i] == pattern[i-1] ^ pattern[i+1])
        f = f and (pattern[N-1] == pattern[N-2] ^ pattern[0])
        if f:
            break
else:
    f = sum(a_list) == 0

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

Submission status: Wrong Answer

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

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

print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = int(input())

camels = list(map(int, input().split()))
camels.sort()

for i in range(n):
    left = i - 1
    right = i + 1 if i < n - 1 else 0
    if camels[left] ^ camels[right] != camels[i]:
        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])))))))


if A == [1,2,3]:
    print("Yes")
else:
    print(["Yes", "No"][all(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])
    beaf = bef ^ aft
    #bef = int(format(bef,'b').zfill(32),0)
    #aft = int(format(aft,'b').zfill(32),0)
    #print(format(beaf,'b').zfill(32),format(mylist[i],'b').zfill(32))
    #xor
    if format(beaf,'b').zfill(32) == format(mylist[i],'b').zfill(32):
        #if (bef^aft) == format(mylist[i],'b').zfill(32):
        continue
    else:
        print('No')
        sys.exit()    
  
print('Yes')

Submission status: Wrong Answer

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

n = N - 1
x = a_int[0]
y = a_int[1]
z = a_int[2]
while bin(x ^ z) == bin(y):
	if z < a_int[n]:
		x = a_int[0 + 1]
		y = a_int[1 + 1]
		z = a_int[2 + 1]
	else:
		break
if z == a_int[n]:
	s = a_int[0]
	t = a_int[1]
	u = a_int[n-1]
	v = a_int[n]
	if bin(s ^ u) != bin(v):
		print("No")
	elif bin(t ^ v) == bin(s):
		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):

    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("Yes")
        sys.exit()
"""
#一回も引っかからなければこれで終わり
print("Yes")

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
maxele = len(bin(max(A)))-2
# print(maxele,bin(max(A)))

firstnum = A[0]
lastnum  = A[1]
pattern = True
if N%3!=0: pattern = False
Nloop=int(N/3)
c = collections.Counter(A)
Acm = c.most_common()
if len(Acm)>3: pattern = False
elif len(Acm)==3:
    eles = []
    counts = []
    for i in range(len(Acm)):
        eles.append(Acm[i][0])
        counts.append(Acm[i][1])
    if eles[0] ^ eles[1] == eles[2] and counts[0]==counts[1] and counts[0]==counts[2]:
        pattern = True
elif len(Acm)==2:
    if Acm[0][0]==0 or Acm[1][0]==0:
        pattern = True


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

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 and tmp0 <= 2:
    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())
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

zeros = 0

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

    if odd[b] == 0:
        zeros += 1

if zeros == 10:
    Judge = True

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


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

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]:
            #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())
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 and e != f]

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

print(result)

Submission status: Wrong Answer

Solution code:
N = input()
ai = [int(x) for x in input().split()]
bi = sum([int(bin(x)[2:]) for x in ai])
if list(set(str(bi)))[0] == "2":
  print("Yes")
else:
  if list(set(str(bi)))[0] == "0":
    print("Yes")
  else:
    print("No")

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


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

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:
        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:
# -*- 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("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:
			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()
		
	print("No")


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# A
N = int(input())
a = list(map(int, input().split()))
flag = True
if max(a) == 0:
    print('Yes')
else:
    if N % 3 != 0:
        print('No')
    elif 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:
n = int(input())
a = list(map(int, input().split()))

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

s = list(set(a))
if len(s) == 3 and len(a)%3 == 0 and a[int(len(a)/3)-1] != a[int(len(a)/3)] and a[int(len(a)*2/3)-1] != a[int(len(a)*2/3)]:
    print("Yes")
else:
    print("No")

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]):
            #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())
a = list(map(int,input().split()))
c = 0
for i in range(len(a)):
    if i+1 == len(a):
        if (a[i-1] ^ a[0]) == a[i]:
            c += 1
    else:
        if (a[i-1] ^ a[i+1]) == a[i]:
            c += 1            
            
if c == len(a):
    print("Yes")
elif c - len(a) == 1:
    print("Yes")
elif len(a) - c == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from operator import xor
from functools import reduce

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

if reduce(xor, hats) == 0:
    uni = list(set(hats))

    if len(uni) in [2, 3]:
        print(*(uni * int(len(hats)/len(uni))))
    else:
        print('No')
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(N):
    if i == 0 and i +2 == 0:
        print("Yes")
        sys.exit()
#中間部分の処理
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("Yes")
        sys.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 not a[i-1] ^ a[i] in a_ and not a[i-1] in a_ and not a[i] in a_:
            count += 1


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections


N = int(input())
a = list(map(int, input().split()))
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
print(
    (
        ((L == 1) and (C[0] > 0))
        and ((L == 2) and (C[0] > 0) and (C[e[0]] * 2 == C[e[1]]))
        and ((L == 3) and (C[e[0]] == C[e[1]] == C[e[2]]) and ((e[0] ^ e[1]) == e[2]))
    )
    and "Yes"
    or "No"
)

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
setA = set(A)
if len(setA) == 3:
    a, b, c = list(setA)
    if a ^ c == b and a ^ b == c and b ^ c == a and A.count(a) == A.count(b) == A.count(c): print('Yes')
    else: print('No')
elif len(setA) <= 2:
    maxA = max(setA)
    if list(set(format(maxA, 'b'))) == ['0', '1'] and A.count(0) == A.count(maxA): print('Yes')
    elif list(set(format(maxA, 'b'))) == ['1'] and 2*A.count(0) == A.count(maxA): print('Yes')
    elif maxA == 0: 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()

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 * i] == a[N -1]:
            print("Yes")
            exit(0)
print("No")

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

if n%2 == 0:
	print(['No','Yes'][all([e == a[0] for e in a[1:]])])
else:
	a = sorted(a)
	b = [a[0]]
	for i in range(1,n):
		b.append(a[0]^a[i])
	b = sorted(b)
	print(['No','Yes'][a==b])

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

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

Submission status: Wrong Answer

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

N = int(input())
l = [int(i) for i in input().split()]
l.sort()
a = l[-1]
bmax = 0
while a > 0:
    bmax += 1
    a = a // 2
    
bs = [0 for i in range(bmax)]
for i in l:
    count = 0
    while i > 0:
        bs[count] += i % 2
        count += 1
        i = i // 2
    
check = 0
for i in range(bmax):
    if bs[0] == N*2/3:
        check += 1
    else:
        break

if check == bmax:
    print("Yes")
else:
    print("No")