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 sys
sys.setrecursionlimit(4100000)

import numpy as np


def resolve():
    N = [int(x) for x in sys.stdin.readline().split()][0]
    a_list = [int(x) for x in sys.stdin.readline().split()]

    max_len = len(format(max(a_list), 'b'))
    # print('{} {}'.format(N, a_list))
    bin_array = np.array([[int(b) for b in format(a, 'b').zfill(max_len)]
                          for a in a_list])

    # print(bin_array)

    sum_array = bin_array.sum(axis=0)
    # print(sum_array)
    minus_array = N - 1.5 * sum_array
    if np.all(minus_array >= 0) and np.all(np.mod(minus_array, 3) == 0):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1 2 3"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 4 8"""
        output = """No"""
        self.assertIO(input, output)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, *a = map(int, open(0).read().split())

a.sort()
q = deque()
for i, x in enumerate(a):
    if i % 2 == 0:
        q.append(x)
    else:
        q.appendleft(x)
        
if all(q[i] == q[i - 1]^q[(i + 1) % N] for i in range(N)):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	if N & (N+1) != 0:
		print("No")
		return

	val_set = set()
	for a in A:
		val_set.add(a)

	possible = True
	for i in range(1, N+1):
		if i not in val_set:
			possible = False
			break
	if possible:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
r = list(map(int,input().rstrip().split(' ')))
f = 0
if (r[1] ^ r[N-1]) == r[0]:
    f += 1
for i in range(1,N-1):
    if (r[i-1] ^ r[i+1]) == r[i]:
        f += 1
if (r[0] ^ r[N-2]) == r[N-1]:
    f += 1
if f == N:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
n = list(map(int, input().split()))
t = 0
s = 0
for l in range(N):
    s += n[l]
if N > 100000:
    print("No")
elif len(n) != N:
    print("No")
elif s != (N ** 2 + N) / 2:
    print("No")
else:
    for i in range(N):
      if i == 0:
        if n[N-1] ^ n[1] == n[0]:
            t += 1
      elif i == N-1:
        if n[N-2] ^ n[0] == n[N-1]:
          t += 1
      else:
        if n[i-1] ^ n[i+1] == n[i]:
          t += 1
    if t == N:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

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

# listの1番目をx0として選ぶ
camel_order = []
camel_order.append([hat[0]])

#hatからx0を消す
hat = hat[1:n]
hat_size = n
# 
for x in camel_order:
    if len(hat) == hat_size:
        break
    else:
        hat_size = len(hat)
    
    if len(camel_order) == n:
        break
    if len(x) == 1:
        for h1 in hat:
            for h2 in hat:
                if h1 ^ h2 == x[0]:
                    camel_order.append([x[0], h1])
                    camel_order.append([x[0], h2])
                    hat.remove(h1)
                    hat.remove(h2)
                    break
    else:
        for h1 in hat:
            if x[1] ^ h1 == x[0]:
                camel_order.append([x[1], h1])
                hat.remove(h1)
                
if len(camel_order) == n:
    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:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())
a = tuple(map(int, input().split()))

if n == 3:
    if a[0] ^ a[2] == a[1] and a[1] ^ a[2] == a[0] and a[0] ^ a[1] == a[2]:
        print('Yes')
    else:
        print('No')
elif n % 3 == 0:
    d = defaultdict(int)
    for aa in a:
        d[aa] += 1
    m = n // 3
    bl = True
    for v in d.values():
        if v % m != 0:
            bl = False
            break
    print('Yes' if bl else 'No')

else:
    if all(aa == 0 for aa in a):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
#n = 6
#a = [1,2,3,1,2,3]
if n >=4:
  if n % 3 != 0:
    if a.count(0) == n:
      print("Yes")
    else :
      print("No")
  else:
    s = set(a)
    if len(s)!=3:
      print("No")
    else:
      l = list(s)
      if l[0]^l[1] == l[2] and l[1]^l[2] == l[0] and l[2]^l[0] == l[1]:
        print("Yes")
      else:
        print("No")
else:
  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")

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = [int(_) for _ in input().split()]
count = collections.defaultdict(int)
for x in A:
    count[x] += 1
if len(count) == 1:
    a = list(count.keys())[0]
    if a == 0:
        print('Yes')
        exit()
elif len(count) == 2:
    a, b = sorted(count.keys())
    if a == 0 and count[a] == 1 and count[b] == 2:
        print('Yes')
        exit()
elif len(count) == 3:
    a, b, c = count.keys()
    if a ^ b == c and count[a] == count[b] == count[c]:
        print('Yes')
        exit()
else:
    print('Yes')
print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = [0, 0]
mi = (n+1)//2
ma = (n//3)*2
if ((n+1)%3)==0:	ma+=1

for i in range(n):	c[a[i]%2] += 1

if c[1] == 0 :							print("Yes")
elif c[0] == 0:							print("No")
elif (mi <= c[1]) and (c[1] <= ma) : 	print("Yes")
else :									print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
aLst = list(map(int, input().split()))
ansB = True
for i in range(N):
    if i == 0:
        if aLst[0] == (aLst[-1] ^ aLst[1]):
            continue
        else:
            ansB = False
            break
    elif i == (N - 1):
        if aLst[i] == (aLst[i - 1] ^ aLst[0]):
            continue
        else:
            ansB = False
            break
    else:
        if aLst[i] == (aLst[i - 1] ^ aLst[i + 1]):
            continue
        else:
            ansB = False
            break

if ansB == True:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    aa = list(map(int, input().split()))

    flg = len(aa) % 3 == 0

    aa.sort()

    if flg:
        flg = aa[0] == aa[len(aa)//3 - 1] and aa[len(aa)//3] == aa[len(aa)//3*2 - 1] and aa[len(aa)//3*2] == aa[len(aa)-1]

    tmp1 = aa[0]
    tmp2 = aa[len(aa)//3]
    tmp3 = aa[len(aa)-1]

    if flg:
        flg = tmp1 == tmp2 ^ tmp3 and tmp2 == tmp1 ^ tmp3 and tmp3 == tmp1 ^ tmp2

    print('Yes' if flg else 'No')
    
resolve()

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 N%3 != 0 or len(c) != 3 or val[0] != val[1] or val[1] != val[2]:
    print("No")
    exit(0)
a, b, c = list(c.keys())
if a ^ b == c and b ^ c == a and c ^ a == b:
    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(len(B) - 1):
    if i == 0 :
        continue
    if bin(B[i -1] ^ B[i +1])  == bin(B[i]):
        cnt +=1
    else:
        print("No")
        exit()
if A-2 ==cnt:
    print("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) != 3:
    print("No")
    exit()
# 均等に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()


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
n_list = [i for i in numbers.keys()]
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:
        print("No")
        exit()
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:
    if len(Co.keys()) == 1 and list(Co.keys())[0] == 0:
        ans = "Yes"
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]:
            ans = "Yes"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2*tr:
        ans = "Yes"
    elif len(Va) == 1 and Co.most_common()[0][0] == 1:
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
a=set(a_list)
if 0 not in a:
  if len(a)!=3:
    print("No")
    exit()
  a=list(a)
  count_a0=a_list.count(a[0])
  count_a1=a_list.count(a[1])
  count_a2=a_list.count(a[2])
  if count_a0!=count_a1 or count_a1!=count_a2 or count_a2!=count_a0:
    print("No")
    exit()
  if a[0]==a[1]^a[2]:
    print("Yes")
  else:
    print("No")
else:
  if len(a)!=2:
    print("No")
    exit()
  a=list(a)
  count_a0=a_list.count(0)
  count_a1=a_list.count(a[0]) if a[0]!=0 else a_list.count(a[1])
  if count_a0*2!=count_a1:
    print("No")
  else:
    print("Yes")

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

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

main()

Submission status: Wrong Answer

Solution code:
### A

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

print(a_all)
if N!=3:
    print("No")
elif (a_all[0]^a_all[1]==a_all[2]):
      print("Yes")
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 = []
for k in a:
    if k not in num:
        num.append(k)
    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:
    print('Yes')
    exit()
if len(num) == 2 and num[0] ^ num[1] == num[1] and N % 3 == 0:
    print('Yes')
    exit()
if len(num) <= 2:
    print('No')
    exit()
if num[0] ^ num[1] != num[2] and num[2] ^ num[1] != num[0] and num[0] ^ num[2] != num[1] and N % 3 == 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
d = {}
for x in input().split():
    a = int(x)
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
ans = "No"
if len(d) == 3 and len(set([d[key] for key in d]))== 1:
    a, b, c = d.keys()
    if a == b ^ c and b == a ^ c and c == b ^ a:
        ans = "Yes"
print(ans)

Submission status: Wrong Answer

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

if len(set(a)) == 1 and a[0] == 0:
    print('Yes')
elif N % 3 == 0:
    if len(set(a)) == 3:
        if a.count(a[0]) == a.count(a[N//3]) == a.count(a[N//3*2]) == N//3:
            print('Yes')
        else:
            print('No')
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) == N//3*2:
            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()))

st = set(a)

if n == 3 and a[0] ^ a[1] == a[2]:
  print("Yes")
elif n  >= 4 and st == {0}:
  print("Yes")
elif n % 3 == 0 and len(st) == 2 and a.count(0) == n /3:
  print("Yes")
elif n % 3 == 0 and len(st) == 3 and a.count(st.pop) == n /3 and a.count(st.pop) == n/3:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
res = False
if n == 3:
    res = l[0] ^ l[2] == l[1]
else:
    res = set(l) == {0}
print("Yes" if res else "No")

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
ans = "Yes"
for i in range(N):
    if i == 0:
        if nums[N-1]^nums[1]==nums[0]:
            continue
        else:
            ans = "No"
            break
    elif i == N-1:
        if nums[N-2]^nums[0]==nums[N-1]:
            continue
        else:
            ans = "No"
            break
    else:
        if nums[i-1]^nums[i+1]==nums[i]:
            continue
        else:
            ans = "No"
            break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
C = Counter(a)
if len(C) == 3:
    v = list(C.keys())
    if v[0] ^ v[1] != v[2]:
        print('No')
        quit()
    x = C[a[0]]
    for k in C:
        if C[k] != x:
            print('No')
            quit()
    print('Yes')
else:
    if 0 not in C:
        print('No')
        quit()
    for k in C:
        if k != 0:
            if C[k] == 2 * C[0]:
                print('Yes')
            else:
                print('No')
            break

Submission status: Wrong Answer

Solution code:
n=int(input())
l = set(map(int,input().split()))
l2 = list(l)
if n % 3 != 0:
    print("No")
elif len(l) != 3:
  if len(l)==1 and l2[0]==0:
    print("Yes")
  elif len(l)==2 and ((l2[0]^l2[1]==l2[1] and l2[1]^l2[1]==l2[0]) or (l2[1]^l2[0]==l2[0] and l2[0]^l2[0]==l2[1])):
    print("Yes")
  else:
    print("No")
else:
    if (l2[0] ^ l2[1] == l2[2]) and (l2[1] ^ l2[2] == l2[0]) and (l2[2] ^ l2[0] == l2[1]):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
N = input()
a = input().split()
result = 0
a.extend(a)
for i in np.arange(int(N)):
    if (bin(int(a[i]) ^ int(a[i+2]))) == bin(int(a[i+1])):
        break
    else:
        result +=1
if(result==0):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

nums = {}

for i in range(N):
    if A[i] in nums:
        nums[A[i]] += 1
    else:
        nums[A[i]] = 1

if len(nums) == 1:
    if '0' in nums:
        print('Yes')
    else:
        print('No')
elif len(nums) == 2:
    if '0' in nums and nums['0'] * 3 == len(A):
        print('Yes')
    else:
        print('No')
elif len(nums) == 3:
    if '1' in nums and '2' in nums and '3' in nums and nums['1'] == nums['2'] and nums['2'] == nums['3']:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = np.array(a)




def make_Xor(a,b):
	d_ = []
	for i in range(len(a)):
		if a[i] == b[i]:
			d_.append("0")
		else:
			d_.append("1")
	return d_


def judge_of_3(a):
	a_ = []
	a_.append(list(format(a[0],'b')))
	a_.append(list(format(a[1],'b')))
	a_.append(list(format(a[2],'b')))
	max_len = max(len(a_[0]),len(a_[1]),len(a_[2]))
	for i in range(3):
		while len(a_[i]) < max_len:
			a_[i].insert(0,'0')
	if make_Xor(a_[0],a_[1]) == a_[2]:
		return True
	else:
		return False
	
	
judge = True

if N % 3 == 0:
	a_1 = np.unique(a)
	if len(a_1) == 3:
		for a_1_ in a_1:
			if np.count_nonzero(a == a_1_) != int(N // 3):
				judge = False
		if judge:
			if judge_of_3(a_1):
				judge = True
			else:
				judge = False
	else:
		judge = False
else:
	a_1 = np.unique(a)
	a_1 = list(a_1)
	if len(a_1) != 1:
		judge = False
	if a_1[0] != 0:
		judge = False

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

Submission status: Wrong Answer

Solution code:
import math

INF = 10**9+7
PRIME_NUM = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]

def main():
	n = int(input())
	a = list(map(int,input().split()))
	if(n%2==0):
		print('No')
		return 0
	a.sort()
	b=[]
	for i in range(0,int(n/2)):
		b.append(a[i*2])
	if(n%2!=0):
		b.append(a[n-1])
	for i in reversed(range(int(n/2)+n%2,n)):
		tmp=(n-i)*2
		b.append(a[tmp-1])
	flag=True
	for i in range(n):
		if(i==0):
			if(b[-1]^b[1]!=b[0]):
				flag=False
		elif(i==(n-1)):
			if(b[-2]^b[0]!=b[-1]):
				flag=False
		else:
			if(b[i-1]^b[i+1]!=b[i]):
				flag=False
	if flag:
		print('Yes')
	else:
		print('No')


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
als = list(map(int,input().split()))
ans = 'No'
sett = n//3
als.sort()
if n%3 == 0:
    if als[0] == als[n-1]:
        ans = 'Yes'
    else:
        co = [als[0]]*sett + [(als[0]^als[n-1])]*sett + [als[n-1]]*sett
        if co == als:
            ans = 'Yes'
print(ans)

Submission status: Wrong Answer

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

if n!=3:
    for i in range(0,n-2):
        if  (bin(a[i] ^ a[i+2]))==bin(a[i+1]):
            continue
        else:
            s=1

    if  (bin(a[n-1] ^ a[1]))==bin(a[0]):
        f=0
    else:
        s=1

    if  bin((a[n-2] ^ a[0]))==bin(a[n-1]):
        f=0
    else:
        s=1



else:
    if  (bin(a[0] ^ a[1]))==bin(a[2]):
        f=0
    else:
        s=1
    if  (bin(a[1] ^ a[2]))==bin(a[0]):
        f=0
    else:
        s=1
    if  (bin(a[2] ^ a[0]))==bin(a[1]):
        f=0
    else:
        s=1

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

Submission status: Wrong Answer

Solution code:
N=int(input())
x=list(map(int,input().split()))
answer = "Yes"
for i in range(N) :
    if i == N-1:
        wk = bin(x[i-1] ^ x[0])
    else:
        wk = bin(x[i-1] ^ x[i+1])
    if x[i] != int(wk,2):
        answer = "No"
        break
print(answer)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
inp = [int(x) for x in input().split()]
m = max(inp)
a = [format(x, '0' + str(len(str(format(m, 'b')))) + 'b') for x in inp]

def mk_pair(f):
    s11, s12 = '', ''
    s21, s22 = '', ''
    for c in f:
        cn = '1' if c == '0' else '0'
        s11 += c
        s12 += c if c == '0' else cn
        s21 += cn
        s22 += cn if c == '0' else c
    return (s11, s12), (s21, s22)

def axor(p1, p2):
    res = ''
    for c1, c2 in zip(p1, p2):
        res += c2
    return res

def check(a, p, first):
    sa = set(a)
    sa.discard(first)
    p1, p2 = p

    r1 = first
    r2 = first

    c1 = p1
    c2 = p2

    rest = len(sa)
    while True:
        if rest == 0:
            return True
        if rest < 0:
            return False
        n1 = axor(r1, c1)
        n2 = axor(r2, c2)
        if (n1 in sa and n2 in sa):
            rest -= 2
            sa.discard(n1)
            sa.discard(n2)
            r1 = c1
            r2 = c2
            c1 = n1
            c2 = n2
        else:
            return False


first = a[0]

for p in mk_pair(first):
    ans = check(a, p, first)
    if ans:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

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

for i in range(1,n-1):
    if bin(x[i-1]^x[i+1])!=bin(x[i]):
        print("No")
        break
    elif bin(x[n-2]^x[0]) == bin(x[n-1]):
        print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
ah = a.copy()
a.append(a[0])

for i in range(N):
    if i == 0:
        if bin(a[N-1] ^ a[i+1]) == bin(a[i]):
            ah.remove(a[i])
            continue

    else:
        if bin(a[i-1] ^ a[i+1]) == bin(a[i]):
            ah.remove(a[i])
            continue

if not ah:
    print("Yes")
else:
    print("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 A.count(0) == A.count(maxA): print('Yes')
    else: print('No')
else: print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
print(a)
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")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
B_list = list()
for i in A_list:
	B_list.append(bin(i))

bin_0 = bin(A_list[0])
bin_2 = bin(A_list[2])

ans = bin(A_list[0]^A_list[2])


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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=[]
l.append(a[0])
for i in range(1,n):
    if a[i]^a[0] in a:
        x=a[i]^a[0]
        l.append(a[i])
        l.append(x)
        a.remove(a[i])
        a.remove(x)
        break
if n==3:
    if len(l)==3:
        print("Yes")
    else:
        print("No")
else:
    if len(l)!=3:
        print("No")
        exit()
    for i in range(3,n):
        if l[i-2]^l[i-1] in a:
            x=l[i-2]^l[i-1]
            l.append(x)
            a.remove(x)
        else:
            print("No")
            exit()
    if len(l)==n and l[0]^l[1]==l[-1]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

is_yes = False

a_n_unique = list(set(a_n))

if len(a_n_unique) == 1:
    if a_n_unique[0] == 0:
        is_yes = True

elif N % 3 == 0:
    if len(a_n_unique) == 2:
        if a_n_unique[0] == 0 or a_n_unique[1] == 0:
            if a_n.count(a_n_unique[0]) > a_n.count(a_n_unique[1]):
                if a_n.count(a_n_unique[0]) / a_n.count(a_n_unique[1]) ==2:
                    is_yes = True
            else:
                if a_n.count(a_n_unique[1]) / a_n.count(a_n_unique[0]) ==2:
                    is_yes = True
    elif len(a_n_unique) == 3:
        if a_n_unique[0] ^ a_n_unique[1] == a_n_unique[2]:
            if a_n.count(a_n_unique[0]) + a_n.count(a_n_unique[1]) == 2 * a_n.count(a_n_unique[2]):
                is_yes = True


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

Submission status: Wrong Answer

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

a.sort()
s = set(a)
if (len(s) > 3) or (len(s) == 1) or (len(s) == 2):
    print('No')
    exit()

l = [a[0]]
c = []
count = 1
for i in range(n-1):
    if a[i+1] != a[i]:
        l.append(a[i+1])
        c.append(count)
        count = 1
    else:
        count += 1
c.append(count)

if n % 3 != 0:
    print('No')
    exit()

c.sort()
if c[0] != c[1] or c[1] != c[2]:
    print('No')
    exit()

if (l[0] ^ l[1]) == l[2]:
    print('Yes')
    exit()
print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
count = 0
for i in range(len(a)):
    if i == 0:
        left = -1
        right = i + 1
    elif i == len(a) - 1:
        left = i - 1
        right = 0
    else:
        left = i - 1
        right = i + 1

    number = bin(a[left] ^ a[right])
    '''if bin(a[i]) != number:
        print('No')
    else:
        count += 1'''
    if bin(a[i]) == number:
        count += 1

if count == len(a):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
A = int(input())
B =list(map(int,input().split()))
for i in range(len(B) - 1):
    if i == 0 :
        continue
    if bin(B[i -1] ^ B[i +1])  == bin(B[i]):
        print("Yes")
        exit()
    else:
        print("No")
        exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if i==0:
    ai=a[i]
    x=a[i+1]^a[n-1]
    if x==ai:
      ans="Yes"
    else:
      ans="No"
  elif i==n-1:
    ai=a[i]
    x=a[0]^a[i-1]
    if x==ai and ans=="Yes":
      ans="Yes"
    else:
      ans="No"
  else:
    ai=a[i]
    x=a[i+1]^a[i-1]
    if x==ai and ans=="Yes":
      ans="Yes"
    else:
      ans="No"
print(ans)

Submission status: Wrong Answer

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

for i in range(2, n):
    if(a[i-2] + a[i-1] != a[i]):
        flag = False
if(a[n-1] - a[0] != a[1]):
    flag = False
if(a[n-1] - a[1] != a[0]):
    flag = False

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

Submission status: Wrong Answer

Solution code:
from collections import deque

N = int(input())
A = deque(map(int, input().split()))
first = A.popleft()


def round(a):
        B = set(A)
        eval = 0
        pre = first
        post = a
        B.discard(a)
        while len(B) != 0:
                c = pre ^ post
                if c in B:
                        B.discard(c)
                        pre = post
                        post = c
                else:
                        return 0
                        eval = 1
                        break
        
        if post ^ first == a:
                return 1
        elif eval == 0:
                return 0

ands = 0
for i in range(0, N - 1):
        ans = round(A[i])
        if ans == 1:
                print('Yes')
                break
                

if ans == 0:
        print('No')

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = [int(i) for i in input().split()] 
a.sort()
# n=3
# a=[1,2,3]
for i in range(n-1):
#     print(i,i+1)
    if not(a[i-1] ^ a[i+1] == a[i]):
        print('No')
        sys.exit(0)
if not(a[i] ^ a[0] == a[i+1]):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(N):
	x = int(a[(i-1)%N])
	y = int(a[(i+1)%N])


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

print('Yes')

Submission status: Wrong Answer

Solution code:
import itertools


def checkXOR(Cap):
    num = len(Cap)

    for i in range(num):
        L = Cap[(i - 1) % num]
        Me = Cap[i]
        R = Cap[(i + 1) % num]

        if (L ^ R == Me):
            return True
        else:
            return False


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

for Cap in itertools.permutations(A):
    if (checkXOR(Cap) == True):
        print("Yes")
        exit(0)

print("No")

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 bin(a[-1] ^ a[1]) == bin(a[i]):
            print('No')
            break
    elif i == len(a)-1:
        if bin(a[0]^ a[-2]) == bin(a[i]):
            print('Yes')
            break
        else:
            print('No')
            break
    else:
        if not bin(a[i-1] ^ a[i+1]) == bin(a[i]):
            print('No')
            break