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:
N = int(input())
List=list(map(int,input().split()))
List.sort()
a = List[0]
b = List.count(a)
c = List[N//3]
d = List.count(c)
e = List[2*N//3]
f = List.count(e)
if a == c and c == e:
    if a == 0 and b == N:
        print('Yes')
elif c == e:
    if a == 0  and N % 3 == 0 and b == N // 3 and d == 2 * N // 3:
        print('Yes')
elif N % 3 == 0 and b == N // 3 and d == N //3 and f == N //3 and a ^ e == c : 
    print('Yes')
else:
    print('No')

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 len(a_set)==1 and a_set[0]==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:
import math
import itertools
N = int(input())
a = list(map(int,input().split()))
k = 0
for i in itertools.permutations(a):
    k += 1
    ans = "Yes"
    for j in range(1,N):
        if abs(a[j] - a[j-2]) != a[j-1]:
            ans = "No"
            break
    if ans == "Yes":
        print(ans)
        exit()
    if k > 1000:
        print("No")
        exit()
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):
    for k in range(j+1,n):
      if figure[i]^figure[j]==figure[k]:
        print("Yes")
        p+=1
        break
    else: 
      continue
    break
  else:
    continue
  break
if p==0:
  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] != a[r] ^ a[l])):
        flag = 1
        break
        
if(flag == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

xorNeighbor = 0
xorNeighborS = 0
nonZero = []

for i in range(1, len(a)-1):
    xorNeighbor = a[i-1] ^ a[i] ^ a[i+1]
    xorNeighborS ^= xorNeighbor
    if xorNeighbor:
        nonZero.append(xorNeighbor)
    #print(nonZero, xorNeighborS)

if len(nonZero) == 0:
    print("Yes")
else:
    nonZero.append(xorNeighborS)
    #print(nonZero)
    try:
        while len(nonZero):
            removeVal = nonZero[0]
            nonZero.remove(removeVal)
            nonZero.remove(removeVal)
        print("Yes")
    except:
        print("No")

Submission status: Wrong Answer

Solution code:
import math

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

def XOR(x):
	n = x.bit_length()
	count = 0
	while n > 0:
		count = count + x // int(math.pow(2,n-1))
		if x // int(math.pow(2,n-1)) == 1:
			x = x - int(math.pow(2,n-1))
		n = n - 1
	return count % 2

c_odd = 0
c_eve = 0
for i in range(N):
	if XOR(a[i])==1:
		c_odd = c_odd + 1
	else:
		c_eve = c_eve + 1

if N % 2 == 1:
	if c_odd == c_eve + 1:
		print('Yes')
	else:
		print('No')
else:
	if c_odd == c_eve or c_odd == 0:
		print('Yes')
	else:
		print('No')

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

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()
for hatnum in hatnums2:
    for hatnum2 in hatnums2:
        if hatnum2 != hatnum:
            if not doMaths(hatnum, hatnum2) in hatnums2:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

if N % 3 == 0:
    n = N // 3
    
    dic = defaultdict(int)
    for a in A:
        dic[a] += 1

        if dic[a] > n:
            print('No')
            exit()

else:
    print('No')

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in range(a):
    if b[i] not in c:
        c.setdefault(b[i], 1)
    else:
        c[b[i]] += 1
if len(c) != 3:
    print("No")
    exit()
else:
    for i in range(1, len(c)):
        f = list(c.values())
        if f[i] != f[i-1]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
import math
import itertools
N = int(input())
a = list(map(int,input().split()))
k = 0
for i in itertools.permutations(a):
    k += 1
    ans = "Yes"
    for j in range(1,N):
        if abs(a[j] - a[j-2]) != a[j-1]:
            ans = "No"
            break
    if ans == "Yes":
        print(ans)
        exit()
    if k > 1000:
        print("Yes")
        exit()
print(ans)

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(a[i] != a[r] ^ a[l]):
        flag = 1
        break
        
if(flag == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
import collections


input = sys.stdin.readline


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    c = collections.Counter(a)
    if (len(c) != 3) or (n % 3 != 0):
        print("No")
    else:
        s = list(c.keys())
        v = list(c.values())
        if (s[0] == s[1] ^ s[2]) and (s[1] == s[2] ^ s[0]) and (s[2] == s[0] ^ s[1]) and (v[0] == v[1] == v[2]):
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
f=0
ct=0
C=collections.Counter(a)
D=C.most_common()
for i in range(n):
  if a[i]==0:
    ct=1
    f=1
for i in range(n):
  a[i]=format(a[i],'020b')
l=[0 for i in range(20)]
for i in range(n):
  for j in range(20):
    if a[i][j]=='1':
      l[j]+=1
for j in range(20):
  l[j]=l[j]%2

if f==0:
  if 1 in l:
    print('No')
  elif D[0][1]>=2:
    print('No')
  elif n not in a:
    print('No')
  else:
    print('Yes')
elif f==1:
  if len(D)==1:
    print('Yes')
  elif len(D)==2 and D[0][0]!=0 and D[0][1]==D[1][1]*2:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

def xor(x1,x2):
    xdigit = math.ceil(math.log2(max(x1+1, x2+1)))
    num = 0
    
    #print(x1, x2)
    
    for i in range(xdigit):
        num_digit = 2**(xdigit-i-1)
        dig_x1 = x1 // num_digit
        dig_x2 = x2 // num_digit
        
        #print("x", dig_x1, dig_x2)
        
        if dig_x1 != dig_x2:
            num += 2**num_digit
            
        if dig_x1 == 1:
            x1 -= 2**num_digit
            
        if dig_x2 == 1:
            x2 -= 2**num_digit
    return num

is_exist = True

for camel in range(N):
    if camel == N-1:
        furt = 0
    else:
        furt = camel + 1
        
    if camel == 0:
        prev = N-1
    else:
        prev = camel -1
         
    num_xor = xor(nums[prev], nums[furt])
    
    #print(num_xor)
    
    #print(camel, num_xor, nums[camel])
    
    if num_xor != nums[camel]:
        is_exist = False
        break


if is_exist == True:
    print("Yes")
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(1, n-1):
            count = 0
            aa = a[0]^a[i+1]
            if aa in a:
                count += 1
            if count < 2:
                flag = 1
                break

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

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

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[c[1]]%2==0 and cnt[c[0]]*2>=cnt[c[1]]:
    print('Yes')
if len(b)==3:
  if c[0]==0:
    print('No')
  else:
    if cnt[c[0]]==cnt[c[1]]==cnt[c[2]]:
      if bin(c[0]^c[1])==bin(c[2]):
        print('Yes')
else:
  print('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 j in range(n, 2*n-1):
    if a[j] != a[j + 1]:
        print("No")
        exit()

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


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

print("Yes")

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

Submission status: Wrong Answer

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

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

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

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

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

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

def main():

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

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

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

	a = 2
	i = 1
	ll = [1]
	while a < 100000+1:
		a = 2 ** i
		ll.append(a)
		i += 1
		if a_max == a:
			print("No")
			sys.exit()

	tmp = 0
	flg = False
	for i in ll:
		tmp += i
		if a_max == tmp:
			flg = True
			break
	
	if flg == False:
			print("No")
			sys.exit()

	bk = -1
	next1 = -1
	for i, val in enumerate(A):
		#A[i] = -1
		if i == 0:
			tmp = a_max - val
			if tmp in A:
				bk = val
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
		if i == N-1:
			if next1 == a_max and bk ^ A[0] == a_max:
				print("Yes")
				sys.exit()
		
		if next1 != a_max:
			tmp = next1 + bk
			if tmp in A:
				bk = val
				next1 = tmp
				continue
			else:
				#print(tmp)
				print("No")
				sys.exit()
		else:
			tmp = next1 - bk
			if tmp in A:
				bk = val
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
	print("No")


if __name__ == "__main__":
	main()

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 += '0' if c1 == c2 else '1'
    return res

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

    q1 = first
    q2 = first

    c1 = p1
    c2 = p2

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

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

Submission status: Wrong Answer

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

first = None
start = nums[0]
next = None

for num in nums:
    if start ^ num in nums:
        next = num
        first = start

# print(start, next)

if next == None:
    print("No")
else:
    for i in range(0, len(nums), 2):
        next2 = start ^ next
        if next2 in nums:
            nums = [e for e in nums if e != start and e != next]
            start = next
            next = next2
            # print(nums)
            # print(start, next)
        else:
            print("No")
            break

    if len(nums) <= 1:
        if start ^ next == first:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque, defaultdict
import copy
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

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


numnum=defaultdict(int)
for i in range(N):
    numnum[a[i]]+=1

if len(numnum) > 3:
    print("No")
    exit()


if len(numnum) == 1:
    for num in numnum:
        if num == 0:
            print("Yes")
        else:
            print("No")
        exit()

for num in numnum:
    if numnum[num] % N//3 != 0:
        print("No")
        exit()

num3=[]
for num in numnum:
    num3.append(num)

if len(num3) == 2:
    if 0 in num3 and numnum[0] == N//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()


if num3[0]^num3[1] == num3[2]:
    print("Yes")
    exit()
else:
    print("No")
    exit()

Submission status: Wrong Answer

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

xorNeighbor = 0
for i in range(1, len(a)-1):
    #print(a[i-1], a[i], a[i+1])
    xorNeighbor += (a[i-1] ^ a[i] ^ a[i+1])

if xorNeighbor:
    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 0 in a:
	print("No")
elif c == len(a):
    print("Yes")    
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    *alist, = map(int, input().split())

    aset = list(set(alist))
    if len(aset) == 1 and aset[0] == 0:
        print('Yes')
        return

    if len(aset) != 3:
        print('No')
        return

    a, b, c = aset
    if a ^ b != c:
        print('No')
        return

    acnt = {a: 0, b: 0, c: 0}
    for aa in alist:
        acnt[aa] += 1

    if acnt[a] != acnt[b] or acnt[b] != acnt[c]:
        print('No')
        return

    print('Yes')


main()

Submission status: Wrong Answer

Solution code:
### A

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

if len(a_all)==3:
    if (a_all[0]^a_all[1]==a_all[2]):
        print("Yes")
elif len(t)==2:
    a=0
    b=0
    for i in a_all:
        if i==t[0]:
            a+=1
        else:
            b+=1
    if(a == b*2 or  b == a*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()
count.sort()
if len(num) == 1 and num[0] == 0:
    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[0] ^ num[1] == 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:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans="Yes"
for i in range(n):
  if i==n-2:
    if a[0]==a[i]^a[i+1]:
      continue
    else:
      ans="No"
  elif i==n-1:
    if a[1]==a[i]^a[0]:
      continue
    else:
      ans="No"
  else:
    if a[i+2]==a[i]^a[i+1]:
      continue
    else:
      ans="No"
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools
N = int(input())
a = list(map(int,input().split()))
k = 0
for i in itertools.permutations(a):
    k += 1
    ans = "Yes"
    for j in range(1,N):
        if abs(a[j] - a[j-2]) != a[j-1]:
            ans = "No"
            break
    if ans == "Yes":
        print(ans)
        exit()
    if k > 1000:
        print(ans)
        exit()
print(ans)

Submission status: Wrong Answer

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

c = [[b[i],a.count(b[i])] for i in range(len(b))]

if len(c) == 1:
    if c[0][0] == 0:
        print('Yes')
    else:
        print('No')
elif N % 3 == 0 and len(c) == 2:
    if c[0][0] == 0 and c[0][1] == N//3 and c[1][1] == N//3*2:
        print('Yes')
    else:
        print('No')
elif N % 3 == 0 and len(c) == 3:
    if c[0][0] != 0 and c[0][1] == c[1][1] == c[2][1] == N//3:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

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

if len(seta) == 3 and a.count(seta[0]) == a.count(seta[1]) and a.count(seta[1]) == a.count(seta[2]) and a.count(seta[2]) == a.count(seta[0]):
  if seta[0]^seta[1] == seta[2] and seta[1]^seta[2] == seta[0] and seta[0]^seta[2] == seta[1]:
    print("Yes")
elif len(seta) == 2:
  sseta = sorted(seta)
  if sseta[0] == 0 and a.count(sseta[1]) == a.count(sseta[0])*2:
    print("Yes")
  else:
    print("No")
elif len(seta) == 1 and seta[0] == 0:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
def calc(N, A):
    _exist = False
    counter = {}
    for a in A:
        counter[a] = 1 + (counter[a] if a in counter else 0)
    if (N % 3 == 0 and len(counter) == 3):
        keys = list(counter.keys())
        values = list(counter.values())
        d = max(values) - min(values)
        _exist = d == 0 and keys[0] ^ keys[1] == keys[2]
    else:
        _exist = 0 in counter and counter[0] == N
    print('Yes' if _exist else 'No')


N = int(input())
A = [int(s) for s in input().split(' ')]
calc(N, A)

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[c[1]]%2==0 and cnt[c[0]]*2>=cnt[c[1]]:
    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:
N=int(input())
a=sorted(list(map(int, input().split())))
A=0
for i in range(N):
  Be=a[len(a)-1] if i==0 else a[i-1]
  Af=a[0] if i==len(a)-1 else a[i+1]
  if Be^Af!=a[i]:
    print('No');exit()

print('Yes')

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]
    if a[i] != l and a[i] != m and m != -1:
        n = a[i]
    if 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 and l^m==n):
    print("Yes")
elif n == -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")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import itertools

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

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) ]
    a_tmp2 = a_tmp[1:-2]
    a_tmp2.append(a_tmp[0])
    if a_tmp2 != a_plus:
        ans = 'No'
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools
N = int(input())
a = list(map(int,input().split()))
k = 0
for i in itertools.permutations(a):
    k += 1
    ans = "Yes"
    for j in range(1,N):
        if abs(a[j] - a[j-2]) != a[j-1]:
            ans = "No"
            break
    if ans == "Yes":
        print(ans)
        exit()
    if k > 100:
        print(ans)
        exit()
print(ans)

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 max(cnt) == min(cnt):
                ans = 1
        if len(tmp) == 2:
            if 0 in tmp:
                if max(cnt)//2 == min(cnt):
                    ans = 1
        if len(tmp) == 1:
            if tmp[0] == 0:
                ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

aArr.sort()
aSet = set(aArr)

a = aArr[-1]
setSum = sum(aSet) - a
arrSum = sum(aArr) - a

arrSum -= arrSum - setSum
ans = ["No", "Yes"][a == arrSum]

if(aArr[-1] == aArr[-2]):
    tmp = a
    i = -2
    while arrSum > aArr[-1]:
        tmp += aArr[i]
        arrSum -= aArr[i]
    if arrSum == tmp:
        ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
l = list(map(int, input().split()))
cnt = Counter(l)
res = len(cnt) == 1 and 0 in cnt
if not res and n % 3 == 0:
    if len(cnt) == 3 and all(v == n // 3 for v in cnt.values()):
        x = list(cnt.keys())
        res = x[0] ^ x[2] == x[1]
print("Yes" if res else "No")

Submission status: Wrong Answer

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

def xor(x1,x2):
    return int(bin((x1^x2)),2)

def check(a):
    state=True
    for i in range(1,len(a)-1):
        if(xor(a[i-1],a[i+1])==a[i] and state):
            state=True
        else:
            state=False

    if(xor(a[len(a)-1],a[1])==a[0] and state):
        state= True
    else:
        state=False

    if(xor(a[len(a)-2],a[0])==a[len(a)-1] and state):
        state=True
    else:
        state=False
    return state

if(check(a)):
    result=True


print("YNeos"[1-int(result)::2])

Submission status: Wrong Answer

Solution code:
import bisect


N = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(1, N):
    x = a[0]
    y = a[i]
    used = [0] * (N + 1)
    used[0] = 1
    used[i] = 1
    used[N] = 1
    for _ in range(N - 2):
        z = x ^ y
        ind = bisect.bisect_left(a, z)
        if used[ind] == 0 and a[ind] == z:
            used[ind] = 1
            x = y
            y = z
        else:
            break
    else:
        if a[0] == x ^ y:
            print("Yes")
            exit(0)

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=[]
for e in even:
    ee = ai[e]
    if len(bin(ee))==lmax+2: first.append(ee)
#
if len(first)==0:
    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()
#
tc= []
for f in first:
    for s in second:
        if f==s: continue
        tc.append( (f,s) )
#
def search(arr):
    global ai, even, odd
    if len(arr)==n and arr[-1]==arr[0]^arr[-2] and arr[0]==arr[-1]^arr[1]:
        return True
    #
    if no>0 and len(arr)%3!=0: ref= odd
    else: ref= even
    #
    for i in ref:
        if i in arr: continue
        if ai[i] ^ arr[-2] == arr[-1]:
            ac = arr.copy()
            ac.append( ai[i] )
            tf= search(ac)
            if tf: return tf
    #
    return False

for f,s in tc:
    tmp= [f,s]
    tf = search(tmp)
    if tf:break
#
if tf: print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
list = [0] * 32
for i in a:
    for j in range(32):
        if i & (1 << j):
            list[j] += 1
if 1 in list:
    print("No")
else:
    print("Yes")

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]):
          Flag=False
          break  
    if Flag==True:
      print("Yes")
    else:
      print("No")
  else:
    print("No")    
else:
  print("No")
#  print(bin(a[N-2] ^ a[0]),bin(a[N-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=sorted(list(map(int, input().split())))
A=0
for i in range(N):
  Be=a[len(a)-1] if i==0 else a[i-1]
  Af=a[0] if i==len(a)-1 else a[i+1]
  print(Be,a[i],Af,Be^Af)
  if Be^Af!=a[i]:
    print('No');exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

num = list(map(int,input().split()))
c = collections.Counter(num)
if len(c) == 3:
  if c.most_common()[0][1] == c.most_common()[1][1]:
    if (c.most_common()[0][0])^(c.most_common()[1][0]) == c.most_common()[2][0]:
      print('Yes')
    else:
      print('No')
  else:
    print('No')
elif len(c) == 2:
  if c.most_common()[0][1] == 2*c.most_common()[1][1]:
    if c.most_common()[1][0] == 0:
      print('Yes')
    else:
      print('No')
  else:
    print('No')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import itertools
import sys

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')
	sys.exit()
else:
	count = 0 
	for i in itertools.combinations(A_list,2):
		count += 1
		if count <= 3000:
			ans = bin(i[0]^i[1])
			if ans in B_list:
				print('Yes')
				sys.exit()
			else:
				continue
		else:
			break
print('No')