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:
inp = input()
n = int(inp)
inp = input()
split_inp = inp.split()
# if n % 3 != 0:
#     print("No")
#     exit()
# 数字を3つのグループに分けていく．
# 3種類以上の数字があればno
numbers = {}
for str_number in split_inp:
    if str_number not in numbers:
        numbers[str_number] = 1
    else:
        numbers[str_number] += 1
    if len(numbers) > 3:
        print("No")
        exit()
# 二つのグループに分かれていれば数の大きいほうを分割する必要がある
if len(numbers) == 2:
    number_values = [i for i in numbers.values()]
    max_number = max(number_values[0], number_values[1])
    small_number = min(number_values[0], number_values[1])
    if small_number * 2 != max_number:
        print("No")
        exit()
    n_list = []
    for item in numbers.items():
        if item[1] == small_number:
            n_list.append(item[0])
        else:
            n_list.append(item[0])
            n_list.append(item[0])
elif len(numbers) == 3:
    # 均等に3当分されている
    number_list = [i for i in numbers.values()]
    if number_list[0] != number_list[1] or number_list[1] != number_list[2]:
        print("No")
        exit()
    n_list = [i for i in numbers.keys()]
else:
    number_key = [i for i in numbers.keys()]
    if number_key[0] == 0:
        print("Yes")
        exit()
    print("No")
    exit()


def number_count(k1, k2, k3, count_n):
    count = 0
    if k1 == count_n:
        count += 1
    if k2 == count_n:
        count += 1
    if k3 == count_n:
        count += 1
    return count


# ビット列に同時に直す.下の桁から見ていき，0,1,1になっていなければno

n1 = int(n_list[0])
n2 = int(n_list[1])
n3 = int(n_list[2])
while n1 != 0 or n2 != 0 or n3 != 0:
    # 一番下の桁を取り出す
    c1 = n1 % 2
    c2 = n2 % 2
    c3 = n3 % 2
    n1 = n1 // 2
    n2 = n2 // 2
    n3 = n3 // 2
    # 1,1,0の組み合わせでなければno
    count1 = number_count(c1, c2, c3, 1)
    count0 = number_count(c1, c2, c3, 0)
    if (count1 != 2 or count0 != 1) and count0 != 3:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

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

a_set=list(set(a))
a_set.sort()

#コーナーケース　aが全部0なら必ずyes
if a_set==0:
    print("Yesうん")
    sys.exit(0)

#上記の場合を除き、nが３の倍数でないと成立しない
if n%3!=0:
    print("No")
    sys.exit(0)


if len(a_set)==2 and a_set[0]==0:
    if a.count(0)==int(n/3) and a.count(a_set[1])==int(n/3)*2:
        print("Yes")
    else:
        print("No")
elif len(a_set)==3:
    if a_set[0]^a_set[1]==a_set[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin, exit

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

num = []
count = []
for k in a:
    if k not in num:
        num.append(k)
        count.append(0)
    else:
        count[num.index(k)] += 1
    if len(num) > 3:
        print('No')
        exit()
if len(num) == 1 and num[0] == 0:
    print('Yes')
    exit()
if len(num) == 2 and num[0] ^ num[1] == num[0] and N % 2 == 0 and count[0] == count[1]:
    print('Yes')
    exit()
if len(num) == 2 and num[0] ^ num[1] == num[1] and N % 3 == 0 and count[1] == 2 * count[0]:
    print('Yes')
    exit()
if len(num) == 2 and num[1] ^ num[0] == num[0] and N % 3 == 0 and count[0] == 2 * count[1]:
    print('Yes')
    exit()
if len(num) <= 2:
    print('No')
    exit()
if (num[0] ^ num[1] == num[2] or num[2] ^ num[1] == num[0] or num[0] ^ num[2] == num[1]) and N % 3 == 0 and count[0] == count[1] == count[2]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

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

for a in arr:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1
if len(d) == 1:
    if 0 in d:
        print("Yes")

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

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
if n==3:
  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)-2):
        if c[i^j] == 0:
            return False
        i = j
        j = i^j
    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("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

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

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)
b=[]
for i in c.values():
    b.append(i)
if a.count(0)==0:
    for i in range(len(b)):
        if len(b)%3!=0:
            print('No')
            break
        elif b[i]!=b[i+1] and i!=len(b)-2:
            print('No')
            break
        elif i==len(b)-2:
            print('Yes')
            break
        else:
            pass
else:
    if len(b)>2 or len(a)-a.count(0)==2:
        print('No')
    elif len(b)==1:
        print('Yes')
    else:
        if a.count(0)*3==len(a):
            print('Yes')
        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(str(bin(num)[2:]))

    #print(bins)
    #[1(0), 10(1), 11(2)]
    for i in range(n):
        if i == 0:
            if int(str(int(bins[n])+int(bins[1])).replace("2","0")) == int(bins[0]):
                continue
            else:
                print("No")
                sys.exit()
        elif i == n:
            if int(str(int(bins[n-1])+int(bins[0])).replace("2","0")) == int(bins[n]):
                continue
            else:
                print("No")
                sys.exit()
        else:
            if int(str(int(bins[i-1])+int(bins[i+1])).replace("2","0")) == int(bins[i]):
                continue
            else:
                print("No")
                sys.exit()

    print("Yes")

main()

Submission status: Wrong Answer

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

for i in range(len(a)):
    if i == 0:
        if not a[-1] ^ a[i+1] == a[i]:
            print('No')
            break
    elif i == len(a)-1:
        if a[0] ^ a[-2] == a[i]:
            print('Yes')
            break
        else:
            print('No')
            break
    else:
        if not a[i-1] ^ a[i+1] == a[i]:
            print('No')
            break

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
result = 'No'
temp = [0] * N
temp[0] = A[0]
temp[1] = A[1]
del A[0]
del A[0]
isOK = 'NG'
if(N == 3):
    temp[2] = A[0]
    del A[0]
    if(temp[0]^temp[1] == temp[N-1] and temp[N-2]^temp[N-1] == temp[0]):
        print('Yes')
    else:
        print('No')
else:
    for i in range(2,N):
        count = 0
        isOK = 'NG'
        for j in A:
            if(temp[i-2]^temp[i-1] == j):
                temp[i] = j
                del A[count]
                count += 1
                isOK = 'OK'
                break
        if(isOK == 'NG'):
            break
    if(isOK == 'NG'):
        print('No')
    else:
        if(temp[0]^temp[1] == temp[N-1] and temp[N-2]^temp[N-1] == temp[0]):
            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):
    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:
        for i in range(N):
            if xor_a == A[i]:
                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())
list1 = list(map(int,input().split()))
list1.insert(0,list1[n-1])
list1.append(list1[1])
for i in range(n):
  for j in range(n):
    flag = 1
    if list1[i]^list1[j] == list1[i+1]:
      flag = 0
      break;
  if flag==1:
    break;
if flag != 1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import itertools

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

def get_ans(a, N):
    ans = 'Yes'
    for l in itertools.permutations(a):
        a_tmp = list(l)
        if a_tmp[0] != a[0]:
            continue
        a_tmp.extend(a_tmp[:2])
        
        a_plus = [ int(bin(a_tmp[x]^a_tmp[x+2]), 0) for x in range(N) ]
        if a_tmp != a_plus:
            ans = 'No'
            break
    print(ans)
    return True

ret = get_ans(a, N)

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)-2):
        if c[i^j] == 0:
            return False
        i = j
        j = i^j
    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:
        continue
    break

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
firstnum = A[0]
lastnum = A[1]
pattern = True
UsedCap = []

for i in range(N):
    nextnum = firstnum ^ lastnum
    # print(nextnum,A)
    if nextnum in A:
        if i> 0:
            A.pop(A.index(lastnum))
        firstnum = lastnum
        lastnum = nextnum

    else:
        pattern = False
        break

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

Submission status: Wrong Answer

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

print(main())

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:
	if n == 3 and 0 in dic and dic[0] == 1:
		print "Yes"
	else:
		print "No"
else:
	if 0 in dic.keys():
		print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(s) for s in input().split(" ")]
a_set = set(a)
n_set = len(a_set)
a_list_set = list(a_set)

if (n < 3):
  ans = False
else:
  ans = False
  for i in range(n_set):
    for j in range(i + 1, n_set):
      if a_list_set[i] ^ a_list_set[j] in a_set:
        ans = True
        break
    if ans:
      break

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

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    a = list(map(int,input().split()))
    sa = list(set(a))
    num = {}

    if sum(sa)==0:
        print("Yes")
        exit(0)
    if (n%3)!=0:
        print("No")
        exit(0)
    for i in a:
        num[i] = num.get(i,0) + 1
    
    OK = False
    if len(num)==3:
        i,j,k = num.values()
        if i==j and j==k and sa[0]==(sa[1]^sa[2]):
            OK = True
    if(OK):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
import itertools

N = int(input())
A = input().split()

listA = list(itertools.combinations(A,5))

for i in range(N):
	for j in range(len(listA)):
		a = listA[j]
		x = int(a[(i-1)%N])
		y = int(a[(i+1)%N])
		print(a[i%N])
		print(x, y)
		print(x^y)

		if int(a[i%N]) == x^y:
			print('Yes')
			sys.exit(0);

print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
L=[]
for i in range(25):
  L.append(2**i-1)
if n in L and max(a)==n and len(set(a))==n and 0 not in a:
  print('Yes')
elif len(set(a))==1 and a[0]==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
bit = input().split()

if n >= 4:
  print('No')
  sys.exit()
else:
  for i in range(3):
    if bit[i] == bit[(i+1)%3] + bit[(i+2)%3]:
      print('Yes')
      sys.exit()
  for i in range(3):
    if bit[i] == 0 and bit[(i+1)%3] == bit[(i+2)%3]:
      print('Yes')
      sys.exit()

print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
sum=0
if N%3!=0:
    print('No')
else:
    for i in a:
        sum=sum^i
    if sum==0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)
K = c.keys()

ans = "No"
if len(K)==3:
    B = []
    for k in K:
        B.append(k)
    if c[B[0]]==c[B[1]] and c[B[1]]==c[B[2]] and B[0]^B[1]==B[2]:
        ans = "Yes"
elif len(K)==2:
    B = []
    for k in K:
        B.append(k)
    if c[B[0]]==c[B[1]] and B[0]^B[0]==B[1]:
        ans = "Yes"
elif len(K)==1:
    for k in K:
        if k==0:
            ans = "Yes"


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools

N = int(input())
A = input().split()

listA = list(itertools.combinations(A,5))

for i in range(N//2):
	for j in range(len(listA)//2):
		a = listA[j]
		x = int(a[(i-1)%N])
		y = int(a[(i+1)%N])
		print(a[i%N])
		print(x, y)
		print(x^y)

		if int(a[i%N]) == x^y:
			print('Yes')
			sys.exit(0);

print('No')

Submission status: Wrong Answer

Solution code:
def exist_not_combination(num_list):
    for x in range(len(num_list)):
        for y in range(len(num_list)):
            if x != y:
                if num_list[x] ^ num_list[y] == 0:
                    return True
                                      
    return False

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

if n == 3:
    if exist_not_combination(a):
        print("No")
    else :
        print("Yes")
else :
    print("No")

Submission status: Wrong Answer

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

flag = 0
for i in range(n):
    if((i+1) >= n):
        l = 0
    else:
        l = i + 1
        
    if((i-1) < 0):
        r = n - 1
    else:
        r = i - 1
    
    # print(str(i)+" :"+str(l)+","+str(r))
    if(bin(a[i]) != bin(a[l] ^ a[r])):
        flag = 1
        break
        
if(flag == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
A = int(input())
B =list(map(int,input().split()))
cnt = 0
for i in range(A - 1):
    if i == 0 :
        continue
    if bin(B[i - 1] ^ B[ i +1]) == bin(B[i]) or oct(B[i - 1] ^ B[ i +1]) == oct(B[i]) or hex(B[i - 1] ^ B[ i +1]) == hex(B[i]):
        cnt += 1
if A-2 ==cnt:
    print("Yes")
else:
    print("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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy
import itertools

s = input().split()
N=int(s[0])
s = input().split()
a=[]
a=copy.copy(s)
count=0
l=list(itertools.permutations(s,N-1))
if N>3:
    for j in range(1,N):
        s=l[j]
        n=len(s)
        for i in range(n):
            if i==0 :
                if int(s[i])==int(s[n-1])^int(s[i+1]):
                    count+=1
            elif i==n-1:
                if int(s[i])==int(s[i-1])^int(s[0]):
                    count += 1
            else:
                if int(s[i])==int(s[i-1])^int(s[i+1]):
                    count += 1
        if count==N:
            print('True')
            break
else:
    if (int(s[0]) == int(s[1]) ^ int(s[2])) & (int(s[1]) == int(s[0]) ^ int(s[2])) & (int(s[2]) == int(s[1]) ^ int(s[0])):
        count =3
    if count==N :
        print('True')
if count != N:
    print('False')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
print(all([a[i] == a[(i - 1) % n] ^ a[(i + 1) % n] for i in range(n)]) and 'Yes' or 'No')

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            if len(a) ==2:
                b=copy.deepcopy(a_list)
                while 0 in a_list:
                    a_list.remove(0)
                if len(b)*2//3==len(a_list):
                    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:
                    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 = input()
a = list(map(int, input().split()))
res = []
for n in range(len(a)):
  if(n == (len(a) - 1)):
    res.append(a[n - 1]^a[0])
  else:
    res.append(a[n - 1]^a[n + 1])
ling = []
for i, num in enumerate(res):
  if(num == 1):
    ling.extend(res[i:])
    ling.extend(res[0:i])
    break
mes = "Yes"
if(len(ling) == 0):  
  mes = "No"
for i, j in enumerate(ling):
  if(i+1 != j):
    mes = ("No")
    break
print(mes)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = dict(Counter(A))
val = list(c.values())

if len(c) > 3:
    print("No")
    exit(0)
if N%3 == 0 and len(c) == 3:
    a, b, c = list(c.keys())
    if a ^ b == c and b ^ c == a and c ^ a == b:
        print("Yes")
    else:
        print("No")
elif len(c)==1 and list(c.keys())[0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
import cmath
N = input()
N = int(N)
#nums = []
nu = input().split()
nui = [int(s) for s in nu]
nus = set(nui)
nul = list(nus)
if((len(nul)==1) and (nul[0]==0)):
    print("Yes")
else:
    if(N%3==0):
        if(len(nul)==3):
            a = nul[0]
            b = nul[1]
            c = nul[2]
            a_s = list(format(a,"040b"))
            b_s = list(format(b,"040b"))
            c_s = list(format(c,"040b"))
            
            a_si = [int(s) for s in a_s]
            b_si = [int(s) for s in b_s]
            c_si = [int(s) for s in c_s]
            
            a_np = np.array(a_si)
            b_np = np.array(b_si)
            c_np = np.array(c_si)
            
            sum = a_np + b_np + c_np
            
            amari = sum%2
            
            ind = np.where(amari==1)
            
            if(len(ind[0])==0):
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import random
a = random.randint(0,1)
N = int(input())
if(a/2==0 and N<10000):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from collections import Counter

readline = sys.stdin.readline

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


x = A[0]
y, z = x, x
for a in A:
    if a != x:
        y = a
        break
for a in A:
    if a != x and a != y:
        z = a
        break

if N % 3 == 0:
    cx, cy, cz = A.count(x), A.count(y), A.count(z)
    if x != y and x != z:
        if cx + cy + cz == N:
            if cx == cy and cx == cz and ((x ^ z == y) or (x ^ y == z)):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    elif x != y:
        if cy * 2 == cx and y == 0:
            print('Yes')
        else:
            print('No')
    elif x == y:
        if x == 0:
            print('Yes')
        else:
            print('No')
else:
    if x == y:
        if x == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import collections
n=input()
a=list(map(int,input().split()))
b=set(a)
c=list(b)
c.sort()
cnt=collections.Counter(a)
if len(b)==1:
  if c[0]==0:
    print('Yes')
if len(b)==2:
  if c[0]==0 and cnt[1]%2==0:
    print('Yes')
if len(b)==3:
  if c[0]==0:
    print('No')
  else:
    if cnt[c[0]]==cnt[c[1]]==cnt[c[2]]:
      if c[0]^c[1]==c[2]:
        print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
R = lambda: map(int, input().split())

n = int(input())
if n % 3:
    ans = 'YNeos'[len(set(R())) > 1]
else:
    a = sorted(R())
    m = n // 3
    if a[0] ^ a[m] ^ a[2 * m]:
        ans = 'No'
    elif any(x != y for i, (x, y) in enumerate(zip(a, a[1:]), 1) if i % m):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=set(a)
l=len(b)
if l==1:
  if a[0]==0:print("Yes")
  else:print("No")
  exit()
elif l==2 and 0 in b and n%3==0:
  if a[n//2-1]!=a[n//2]:print("Yes")
  else:print("No")
  exit()
elif l!=3:print("No");exit()
if n%3!=0:print("No");exit()
def ecount(X):
  c,ans=1,[]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans.append(c);c=1
  ans.append(c)
  return ans
d=sorted(ecount(a))
if b.pop()^b.pop()==b.pop() and d[0]==d[2]:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
# 1.Nが三の倍数でない場合、全てが0でなければならない.(総排他的論理和が各数と等しくならねばならず、その中でa_(i-1)+a_(i+1)=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()):
        input_dict[i] = 1
    num_count = len(input_dict.keys())
    if(num_count >= 4 ):
        print("No")
    elif(num_count <= 2):
        if(0 in input_dict):
            print("Yes")
        else:
            print("No")
    else:
        input_list = list(input_dict.keys())
        if(input_list[0] ^ input_list[1] == input_list[2]):
            print("Yes")
        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:
N = int(input())
nums = list(map(int, input().split()))
counts = 0

for i in range(len(nums)):
  if i == 0:
    counts += bin(nums[0]) == bin(nums[-1] ^ nums[1])
  elif i == len(nums) - 1:
    counts += bin(nums[len(nums) - 1]) == bin(nums[len(nums) - 2] ^ nums[0])
  else:
    counts += bin(nums[i]) == bin(nums[i - 1] ^ nums[i + 1])
  
if counts == len(nums):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort()

    import collections
    c = collections.Counter(a_list)
    keys = sorted(c.keys())
    nk = len(keys)

    dprint(c)
    dprint(keys)

    # a[0] からスタート
    found = False
    start = keys[0]

    for i in range(1, nk):
        center = keys[i]
        max = start + center

        for j in range(i+1, nk):
            right = keys[j]
            # if right > max:
            #     # これより大きいところにはない
            #     break

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

        if found == True:
            break

    if found == False:
        print("No")
        return

    c[start] = c[start] - 1
    c[center] = c[center] - 1
    c[right] = c[right] - 1

    # これで、0, second, third が決まったので、あとは順次決める
    left = center
    center = right
    dprint(start, left, center)

    cnt = 3
    while True:
        # N個作ったら終了
        if cnt == N:
            break

        # 次の数字
        right = left ^ center

        # 検索
        rcount = c.get(right, 0)
        if rcount == 0:
            print("No")
            return

        dprint("found", right, rcount)

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

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

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


solve()

Submission status: Wrong Answer

Solution code:
from sys import stdin, exit

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

num = []
count = []
for k in a:
    if k not in num:
        num.append(k)
        count.append(0)
    else:
        count[num.index(k)] += 1
    if len(num) > 3:
        print('No')
        exit()
if len(num) == 1 and num[0] == 0:
    print('Yes')
    exit()
if len(num) == 2 and num[0] ^ num[1] == num[0] and N % 2 == 0 and count[0] == count[1]:
    print('Yes')
    exit()
if len(num) == 2 and num[0] ^ num[1] == num[1] and N % 3 == 0 and (count[0] == 2 * count[1] or count[1] == 2 * count[0]):
    print('Yes')
    exit()
if len(num) <= 2:
    print('No')
    exit()
if (num[0] ^ num[1] == num[2] or num[2] ^ num[1] == num[0] or num[0] ^ num[2] == num[1]) and N % 3 == 0 and count[0] == count[1] == count[2]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
import itertools

N = int(input())
A = input().split()

listA = list(itertools.combinations(A,5))

for i in range(N//2):
	for j in range(len(listA)//2):
		a = listA[j]
		x = int(a[(i-1)%N])
		y = int(a[(i+1)%N])
		print(a[i%N])
		print(x, y)
		print(x^y)

		if int(a[i%N]) != x^y:
			print('No')
			sys.exit(0);

print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
L=[]
for i in range(25):
  L.append(2**i-1)
if n in L and max(a)==n and len(set(a))==n:
  print('Yes')
elif len(set(a))==1 and a[0]==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

N = int(input().strip())
As = list(map(int, input().strip().split(' ')))
candidates = list(set(As))

if len(candidates) == 1:
    if candidates[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(candidates) == 2:
    a, zero = candidates
    if a < zero:
        a, zero = zero, a

    bits = format(a, 'b')
    if zero == 0 and bits.find('0') == -1:
        count_a = 0
        count_zero = 0
        for element in As:
            if element == 0:
                count_zero += 1
            elif element == a:
                count_a += 1
        else:
            if count_a == count_zero * 2:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
elif len(candidates) > 3:
    print('No')
else:
    a, b, c = candidates[0], candidates[1], candidates[2]
    if a ^ b != c:
        print('No')
    else:
        count_a = 0
        count_b = 0
        count_c = 0
        for element in As:
            if element == a:
                count_a += 1
            elif element == b:
                count_b += 1
            elif element == c:
                count_c += 1
        else:
            if count_a == count_b == count_c:
                print('Yes')
            else:
                print('No')

Submission status: Wrong Answer

Solution code:
# 1.Nが三の倍数でない場合、全てが0でなければならない.(総排他的論理和が各数と等しくならねばならず、その中でa_(i-1)+a_(i+1)=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()):
        input_dict[i] = 1
    num_count = len(input_dict.keys())
    if(num_count > 4 ):
        print("No")
    elif(num_count <= 2):
        if(0 in input_dict):
            print("Yes")
        else:
            print("No")
    else:
        input_list = list(input_dict.keys())
        if(input_list[0] ^ input_list[1] == input_list[2]):
            print("Yes")
        else:
            print("No")
else:
    for i in map(int, input().split()):
        if(i != 0):
            print("No")
            break
    else:
        print("Yes")