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 bisect

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()

ret_list = []
ret_list.append(a_list.pop(0))

flag = True
while True:
    ret_len = len(ret_list)
    left_v = ret_list[ret_len-1]
    a_len = len(a_list)

    if a_len != 0:
        for i in range(0, a_len):
            mid_v = a_list[i]
            right_v = left_v ^ mid_v
            serch_list_low = a_list[0:i]
            serch_list_high = a_list[i+1:]
            if right_v >= mid_v:
                ind = bisect.bisect_left(serch_list_high, right_v)
                if ind < len(serch_list_high):
                    if serch_list_high[ind] == right_v:
                        r = a_list.pop(i+ind+1)
                        m = a_list.pop(i)
                        ret_list.append(m)
                        ret_list.append(r)
                        break
            else:
                ind = bisect.bisect_left(serch_list_low, right_v)
                if ind < len(serch_list_low):
                    if serch_list_low[ind] == right_v:
                        m = a_list.pop(i)
                        r = a_list.pop(ind)
                        ret_list.append(m)
                        ret_list.append(r)
                        break

            if i == a_len-1:
                flag = False
    else:
        right_v = ret_list[-2] ^ ret_list[-1]
        if right_v != ret_list[0]:
            flag = False
        else:
            break

    if not flag:
        break

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

Submission status: Wrong Answer

Solution code:
import sys
fl = input()
sl = input()
fnumofel = int(len(fl)) - int("1")
int(fnumofel)
slist = sl.split(" ")
statlist = []
n = 0
for v in slist:
	int(n)
	if n == 0 or n == fnumofel:
		if n == 0:
			nextnum = slist[1]
			prevnum = slist[-1]
			currnum = slist[0]
			xored = int(prevnum) ^ int(nextnum)
			if int(xored) == int(currnum):
				pass
			else:
				print("No")
				sys.exit()
		elif n == fnumofel:
			nextnum = slist[0]
			prevnum = slist[fnumofel]
			currnum = slist[n]
			xored = int(prevnum) ^ int(nextnum)
			if int(xored) == int(currnum):
				pass
			else:
				print("No")
				sys.exit()
		else:
			nntmp = n + 1
			pntmp = n - 1
			nextnum = slist[nntmp]
			prevnum = slist[pntmp]
			currnum = slist[n]
			xored = int(prevnum) ^ int(nextnum)
			if int(xored) == int(currnum):
				pass
			else:
				print("No")
				sys.exit()
		n+=1
print("Yes")

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:
            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 = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
figure = list(map(int, input().split()))
p=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if figure[i]^figure[j] in figure:
      print("Yes")
      p+=1
      break
  else: 
    continue
    break
if p==0:
  print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0) + 1
    if N % 3:
        if 0 in A and A[0] == N:
            return 'Yes'
        else:
            return 'No'
    else:
        if 0 in A and A[0] == N:
            return 'Yes'
        elif 0 in A and A[0] == N//3:
            if len(A) == 2:
                return 'Yes'
            else:
                return 'No'
        elif len(A) == 3:
            if len(set(A.values())) == 1:
                return 'Yes'
            else:
                return 'No'
        else:
            return 'No'

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
import collections

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

C = collections.Counter(a)
if len(C) != 3:
    print("No")
    exit()

e = list(C.keys())
print(((e[0] ^ e[1]) == e[2]) and "Yes" or "No")

Submission status: Wrong Answer

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

from collections import defaultdict
cnt_dict = defaultdict(int)
for a in A:
    cnt_dict[a] += 1

# 全部の排他的論理和を取る
res = A[0]
for a in A[1:]:
    res ^= a

if N%3 != 0:
    start = A[0]
    cnt_dict[start] -= 1
    for i in range(1,N):
        cnt_dict[res^A[i]] -= 1
        if cnt_dict[res^A[i]] < 0:
            print("No")
            quit()
        start = res^A[i]
    else:
        print("Yes")
else:
    lists = []
    for i in range(3):
        for a in A:
            if cnt_dict[a] >0:
                start = a
                break
        cnt_dict[start] -= 1
        seq = [start]
        
        for i in range(1,N//3):
            cnt_dict[res^A[i]] -= 1
            if cnt_dict[res^A[i]] < 0:
                print("No")
                quit()
            start = res^A[i]
            seq.append(start)
        lists += [seq]
    
    # 一通りでも存在するかどうかを確かめる
    for i,value in enumerate(lists[1]):
        if lists[0][0]^value in lists[2]:
            # 0番目のリストと1番めのリストの数の中間に2がある
            # ...021021...
            j = lists[2].index(lists[0][0]^value)
            if lists[0][-1]^lists[1][i-1] == lists[2][j-1] or \
                lists[0][1]^lists[1][i+1] == lists[2][j-1] or \
                lists[0][-1]^lists[1][i+1] == lists[2][j-1] or \
                lists[0][1]^lists[1][i-1] == lists[2][j-1] :   
                print("Yes")
                quit()
    else:
        print("No")

Submission status: Wrong Answer

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

input_size = len(input_num)-1

if input_size < 2:
  print("No")
for i in range(len(input_num)):
    left = i-1
    right = i+1
    if left < 0:
        left = input_size
    if right > input_size:
      right = 0
#     print(input_num[left])
#     print(input_num[right])
    if input_num[left]^input_num[right] == input_num[i]:
        continue
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

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

if 0 in a:
    if a.count(0) != int(n/3):
        print("No")
    else:
        print("Yes")

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=list(map(int,input().split()))
aa=set(a)
if len(aa)>3 or len(aa)<=1:
    print("No")
    exit()
l=[]
l.append(a[0])
for i in range(1,n):
    if a[i]!=a[0]:
        l.append(a[i])
        break
l.append(l[0]^l[1])

if n==0:
    exit()
else:
    if l[0]==l[1]:
        if n%3==0:
            if a.count(l[0])==(n//3)*2 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[0])==(n//3)*2+2 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
    if l[0]==l[2]:
        if n%3==0:
            if a.count(l[0])==(n//3)*2 and a.count(l[1])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[1])==n//3:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[1])==n//3+1:
                print("Yes")
            else:
                print("No")
    if l[2]==l[1]:
        if n%3==0:
            if a.count(l[1])==(n//3)*2 and a.count(l[0])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[1])==(n//3)*2 and a.count(l[0])==n//3+1:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[1])==(n//3)*2+1 and a.count(l[0])==n//3+1:
                print("Yes")
            else:
                print("No")
    else:
        if n%3==0:
            if a.count(l[0])==n//3 and a.count(l[1])==n//3 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==n//3+1 and a.count(l[1])==n//3 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3 and a.count(l[2])==n//3+1:
                print("Yes")
            else:
                print("No")
        elif n%3==2:
            if a.count(l[0])==n//3+1 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3+1 and a.count(l[1])==n//3 and a.count(l[2])==n//3+1:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3+1:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
n = input()
dic = {}
for i in map(int, raw_input().split()):
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
if len(dic) > 3:
	print "No"
elif len(dic) == 3:
	vals = []
	for i in dic:
		vals.append(i)
	if vals[0]^vals[2] != vals[1] or vals[1]^vals[0] != vals[2] or vals[0] != vals[1]^vals[2]:
		print "No"
	elif max(dic.values()) - min(dic.values()) > 1:
		print "No"
	else:
		print "Yes"
elif len(dic) == 2:
	print "No"
else:
	if 0 in dic.keys():
		print "Yes"
	else:
		print "No"

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 = first ^ s
        if nn in ai and not nn in tmp:
            tmp.append(nn)
        else:
            break
    #
    if len(tmp)==n and tmp[-1]==tmp[0]^tmp[-2] and tmp[0]==tmp[-1]^tmp[1]:
        ans="Yes"
        break
#
print( ans )

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==1:
  print('Yes')
elif n%3!=0:
  print('No')
elif len(set(a))!=3:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
def equal_list(lst1, lst2):
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            break
    else:
        if not lst:
            return True
    return False


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

if a == [0]*N:
    print("Yes")
    exit()

if N % 3 == 0:
    n = N // 3
    sets = list(set(a))
    if len(sets) != 3:
        print("No")
        exit()

    for s in sets:
        if a.count(s) != n:
            print("No")
            exit()

    order = max(a).bit_length()

    for i in range(order):
        b = [sets[0] >> i & 1, sets[1] >> i & 1, sets[2] >> i & 1]
        if not equal_list(b, [0, 1, 1]):
            print("No")
            exit()

    print("Yes")

else:
    print("No")
    exit()

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:
            ans = "Yes"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2 * tr :
        ans = "No"
    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()))
if(N % 3 != 0):
    print('No')
else:
    a = -1
    b = -1
    c = -1
    aa = A[0]

    a = A.count(aa)

    bb = -1

    for i in A:
        if(aa != i):
            bb = i
            break
    b = A.count(bb)
    if(a == b):
        cc = -1

        for i in A:
            if(aa != i and bb != i):
                cc = i
                break
        c = A.count(cc)
        if(b == c and a + b + c == N):
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

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

flag = 0
even = []
odd = []
for i in a:
    if i%2 == 0:
        even.append(i)
    else:
        odd.append(i) 

if n%2 == 1:
    if len(odd) >= 1:
        flag = 1
    else:
        for i in range(n):
            count = 0
            for j in range(i, n):
                aa = a[i]^a[j]
                if aa in a:
                    count += 1
                if count < 2:
                    flag = 1
                    break
            else:
                continue
            break

else:
    if len(odd)/2 != len(even):
        flag = 1
        for i in range(n):
            count = 0
            for j in range(i, n):
                aa = a[i]^a[j]
                if aa in a:
                    count += 1
                if count < 2:
                    flag = 1
                    break
            else:
                continue
            break

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

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

Submission status: Wrong Answer

Solution code:
def doMaths(one, two):
    i = max(len(one), len(two))
    ans = ""
    diffone = i - len(one)
    difftwo = i - len(two)
    nonzero = False
    for i2 in range(0, i):
        if len(one) < i - i2:
            ans += two[i2]
            nonzero = True
            continue
        if len(two) < i - i2:
            ans += one[i2]
            nonzero = True
            continue
        maths = (int(one[i2 - diffone]) + int(two[i2 - difftwo]))%2
        if not nonzero:
            if not maths == 0:
                ans += str(maths)
                nonzero = True
        else:
            ans += str(maths)
    return ans

def check(hatnums2):
    for hatnum in hatnums2:
        for hatnum2 in hatnums2:
            if hatnum2 != hatnum:
                if not doMaths(hatnum, hatnum2) in hatnums2:
                    print('No')
                    return False
                else:
                    del hatnums2[0]
                    return True
    return True

n = int(input())
hats = input()
hatnums = hats.split(" ")
hatnums2 = []
for hat in hatnums:
    hatnums2.append(bin(int(hat))[2:])
if len(hatnums2)%2 == 0:
    print('No')
    exit()
while len(hatnums2) > 2:
    if not check(hatnums2):
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
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_a = prev_a ^ next_a
            if next_a not in set_a:
               break
            count += 1
        
        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:
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:
            ans = "No"
    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 = list(map(int,input().split()))

even = 0 #偶数
odd = 0 #奇数

for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1

even = 0 #偶数
odd = 0 #奇数


for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1


if 2*even == odd or odd == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def solve(N, _as):
    if N % 3 != 0:
        return False

    max_bit_len = 0
    max_bit_len_ints = []
    other_ints = []
    for a in _as:
        bl = int.bit_length(a)
        if bl > max_bit_len:
            max_bit_len = bl
            other_ints.extend(max_bit_len_ints)
            max_bit_len_ints.clear()
            max_bit_len_ints.append(a)
        elif bl == max_bit_len:
            max_bit_len_ints.append(a)
        else:
            other_ints.append(a)

    if N / 3 != len(other_ints):
        return False

    first = max_bit_len_ints.pop()
    for second in other_ints:
        return _solve(first, second, max_bit_len_ints, other_ints)


def _solve(first, second, _max_bit_len_ints, _other_ints):
    max_bit_len_ints = _max_bit_len_ints[:]
    other_ints = _other_ints[:]
    other_ints.remove(second)

    pre_latest = second
    latest = first^second
    try:
        max_bit_len_ints.remove(latest)
    except ValueError:
        return False

    count = 0
    while len(max_bit_len_ints) > 0 and len(other_ints) > 0:
        _latest = latest
        latest = pre_latest^latest
        pre_latest = _latest
        if count == 0 or count == 2:
            try:
                max_bit_len_ints.remove(latest)
            except ValueError:
                return False
        else:
            try:
                other_ints.remove(latest)
            except ValueError:
                return False
        count = (count + 1) % 3

    return pre_latest^latest == first


if __name__ == '__main__':
    N = int(input())
    _as = [int(x) for x in input().split()]
    print('Yes' if solve(N, _as) else 'No')

Submission status: Wrong Answer

Solution code:
print("yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
arr=[]
for i in range(0,N+1):
    LF=(i-1)%N if (i-1) > (N-1) else (i-1)
    RI=(i+1)%N if (i+1) > (N-1) else (i+1)
    MI=i%N if i > (N-1) else i
    aaa = str(int(bin(A[LF]).split("b")[1])+int(bin(A[RI]).split("b")[1]))
    bbb = "".join(list(map(lambda x:str(int(x)%2),aaa)))
    arr.append(int(bbb)==int(bin(A[MI]).split("b")[1]))

print("Yes" if all(arr[1:N-1]) else "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):
    xor_a = 0
    for i in range(N):
        xor_a ^= A[i]
    if N % 3 == 0:
        return 1 if xor_a == 0 else 0
    elif N % 3 == 1:
        for i in range(N):
            if xor_a ^ A[i] == 0:
                return 1
        return 0
    elif N % 3 == 2:
        A = sorted(A)
        for i in range(N):
            if A[i] == A[i+1]:
                return 1
        return 0
    raise ValueError()


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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
ite = 0
for i in range(N):
    if a[i] != 0:
        break
    else:
        ite += 1
if ite == N - 1:
    print("Yes")
    exit()

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

a = sorted(a)
for j in range(n-1):
    if a[j] != a[j + 1]:
        print("No")
        exit()


for k in range(n, 2*n-1):
    if a[k] != a[k + 1]:
        print("No")
        exit()

for p in range(2*n, 3*n-1):
    if a[p] != a[p + 1]:
        print("No")
        exit()


if a[n] ^ a[0] != a[2*n]:
    print("No")
    exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
a = list(map(int, input().split()))
 
x = 0
y = 0
z = 0
 
if N % 3 != 0:
  print('No')
 
elif a.count(0) != 0:
  if a.count(0) != N / 3:
    print('No')
    sys.exit()
    
  else:
    for i in range(N):
      if a[i] != 0 and a[i] != x:
        if x == 0:
          x = a[i]
          continue
        else:
          print('No')
          sys.exit()
        
    print('Yes')
    

else:
  for i in range(N):
    if a[i] != x and a[i] != y and a[i] != z:
      if x == 0:
        x = a[i]
        continue
      elif y == 0:
        y = a[i]
        continue
      elif z == 0:
        z = a[i]
        continue
      else:
        print('No')
        sys.exit()
  
  if x ^ y == z and a.count(x) == a.count(y) and a.count(y) == a.count(z):
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = False

def check(i,j):
    c[j] -= 1
    for k in range(len(a)-1):
        if c[i^j] == 0:
            return False
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return True

for  i in range(len(a)-1):
    for j in range(i+1,len(a)):
        if check(a[i],a[j]):
            hoge = True
            break
        else:
            break
    else:
        continue
    break

if hoge:
  print("No")
else:
  print("No")

Submission status: Wrong Answer

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

l = a[0]
m = -1
n = -1
o = -1

for i in range(1,N):
    if a[i] != l and m == -1:
        m = a[i]
    elif a[i] != l and a[i] != m and m != -1:
        n = a[i]
    elif a[i] != l and a[i] != m and m != -1 and a[i] != n and n != -1:
        o = a[i]
        break

if o != -1:
    print("No")
elif (a.count(l)==a.count(m) and a.count(m)==a.count(n) and a.count(l)+a.count(m)+a.count(n) == N):
    print("Yes")
elif n == -1 and m != -1 and ((a.count(l) == a.count(m)*2 and l^m == l and a.count(l)+a.count(m)*2==N)or(a.count(l)*2 == a.count(m) and l^m == m and a.count(l)*2+a.count(m)==N)):
    print("Yes")
elif m == -1 and a.count(l) == N and l^l==l:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

a0 = A[0]
a1 = A[1]
a2 = a0 ^ a1

f = True

for i in range(3, N):
    if i % 3 == 0 and a0 != A[i]:
        f = False
    elif i % 3 == 1 and a1 != A[i]:
        f = False
    elif i % 3 == 2 and a2 != A[i]:
        f = False

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

Submission status: Wrong Answer

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

A_unique = list(set(A))
A_digit = [[],[],[]]
if A == [0] * N:
  ans = 'Yes'
elif len(A) %3 != 0:
  ans ='No'
elif len(A_unique) != 3:
  ans = 'No'
else:
  for j in range(3):
    A_unique[j] = format(A_unique[j], '08b').zfill(30)
    s = str(A_unique[j])
    A_digit[j]  = list(map(int, s))
  for k in range(30):
    key = A_digit[0][k] + A_digit[1][k] + A_digit[2][k] 
    if key == 0 or key == 2:
      ans = 'yes'
    else:
      ans = 'No'
      break

print(ans)

Submission status: Wrong Answer

Solution code:
# 1.Nが三の倍数でない場合、全てが0でなければならない.(a_i=Σa_k∧a_(i-1)+a_(i+1)=a_iとなるのはa_i=0のみ)
# 2.Nが3の倍数の場合、a,b,a+bを満たす三種類以下の数字で構成されていなければならず、かつそれであればよい。

N = int(input())
if(N%3 == 0):
    input_dict = {}
    for i in map(int, input().split()):
        if(i in input_dict):
            input_dict[i] += 1
        else:
            input_dict[i] = 1
    num_count = len(input_dict.keys())
    if(num_count == 3 ):
        input_list = list(input_dict.keys())
        if(input_list[0] ^ input_list[2] == input_list[1]):
            print("Yes")
        else:
            print("No")
    elif(num_count == 2):
        if(0 in input_dict and input_dict[0] == N//3):
            print("Yes")
        else:
            print("No")
    elif(num_count == 1):
        if(0 in input_dict):
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    for i in map(int, input().split()):
        if(i != 0):
            print("No")
            break
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
def xor(n1, n2):
  if n2=="0":
    return n1
  elif n2=="1":
    if n1=="1":
      return "0"
    else:
      return "1"
      
def bitxor(n1, n2):
 
  bn1 = bin(n1)[2:]
  bn2 = bin(n2)[2:]
  if n1<n2:
    bn1 = bn1.zfill(len(bn2))
  else:
    bn2 = bn2.zfill(len(bn1))
    
  n3 = [xor(b1,b2) for b1,b2 in zip(bn1, bn2)]
  n3 = "".join(n3)
  return int(n3, 2)

n = int(input())
a = [int(x) for x in input().split()]
a_unique = list(set(a))
la = len(a)
lau = len(a_unique)

if a_unique==[0]:
  print("Yes")
elif la%3==0 and lau==2 and (0 in a_unique):
  u0 = a.count(0)
  if a_unique[0]==0:
    num = a_unique[1]
  else:
    num = a_unique[0]
  u1 = a.count(num)
  if u0*2==u1:
    print("Yes")
elif la%3!=0 or lau!=3:
  print("No")
else:
  u0 = a.count(a_unique[0])
  u1 = a.count(a_unique[1])
  u2 = a.count(a_unique[2])
 
  if (a_unique[2]== bitxor(a_unique[0], a_unique[1])) and (u0==u1 and u1==u2):
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
arr=[]
for i in range(0,N+1):
    LF=(i-1)%N if (i-1) > (N-1) else (i-1)
    RI=(i+1)%N if (i+1) > (N-1) else (i+1)
    MI=i%N if i > (N-1) else i
    aaa = str(int(bin(A[LF]).split("b")[1])+int(bin(A[RI]).split("b")[1]))
    bbb = "".join(list(map(lambda x:str(int(x)%2),aaa)))
    arr.append(int(bbb)==int(bin(A[MI]).split("b")[1]))

print("Yes" if all(arr[0:N-1]) else "No")

Submission status: Wrong Answer

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

even = 0 #偶数
odd = 0 #奇数

for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1

even = 0 #偶数
odd = 0 #奇数


for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1


print(even)
print(odd)

if 2*even == odd or odd == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import random

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

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

Submission status: Wrong Answer

Solution code:
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()
    print(Va)
    if len(Va) == 3 :
        if Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1] == tr:
            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 = "No"

print(ans)

Submission status: Wrong Answer

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

if bin(a[N-2] ^ a[0]) == bin(a[N-1]):
  if bin(a[N-1] ^ a[1]) == bin(a[0]):
    for i in range(0,N-2):
      if Flag==True:
        if bin(a[i] ^ a[i+2]) == bin(a[i+1]):
          pass
        else:        
          Flag=False
          break  
    if Flag==True:
      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()
#print(n,a)

ans = 0
if n == 3:
    if a[0]^a[1] == a[2]:
        ans = 1
    else:
        ans = 0
elif n == 4:
    if a[0]==0 and a[1]==0 and a[2]==0 and a[3]==0:
        ans = 1
    else:
        ans = 0
else:
    tmp = []
    cnt = []
    for x in a:
        if x not in tmp:
            tmp.append(x)
            cnt.append(1)
        else:
            cnt[-1] += 1
    if n % 3 != 0:
        if tmp[0] == 0 and cnt[0] == n:
            ans = 1
    else:
        if len(tmp) == 3:
            if cnt[0] == cnt[1] and cnt[1] == cnt[2]:
                ans = 1
        if len(tmp) == 2:
            if 0 in tmp:
                p = tmp.index(0)
                if cnt[p]*2 == cnt[p+1]:
                    ans = 1
        if len(tmp) == 1:
            if tmp[0] == 0:
                ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")