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:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
ans = "Yes"
Co = Counter(A)
if n%3 != 0:
    if len(Co.keys()) != 1 or list(Co.keys())[0] != 0:
        ans = "No"
else:
    tr = n//3
    Va = Co.values()
    if len(Va) > 3: ans = "No"
    if len(Va) == 3:
        if not(Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1]):
            ans = "No"
    elif len(Va) != 2 or Co.most_common()[0][1] != 2*Co.most_common()[1][1]:
        ans = "No"
    elif len(Va) != 1 or Co.most_common()[0][0] != 1:
        ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if not any(l):
  print("Yes")
elif n%3 or 0 in l:
  print("No")
else:
  nx = n//3
  d = dict()
  for x in l:
    if x not in d:
      d[x] = 0
    d[x] += 1
  if list(d.values()) != [nx,nx,nx]:  
    print("No")
  else:
    s = 0
    for x in d:
      s ^= x
    if s == 0:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
import itertools
import sys

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

for i in itertools.permutations(a, len(a)):
    flag = False
    i_add = i + (i[0], i[1])
    for j in range(0, len(i)):
        if i_add[j] ^ i_add[j+2] != i_add[j+1]:
            flag = True
        if flag:
            break
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    N = int(input())
    A = tuple(sorted(map(int, input().split())))

    a = list(A)
    for i in range(2, N):
        a[i] = a[i-1] ^ a[i-2]
    if A == tuple(a):
        print('Yes')
    else:
        print('No')

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

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 x != y and x != z:
    if N % 3 == 0:
        cx, cy, cz = A.count(x), A.count(y), A.count(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')
    else:
        print('No')
else:
    if x == y:
        if x == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

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-1):
        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'
        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 acinput():
    return list(map(int,input().split(" ")))

N=int(input())
a=sorted(acinput())
#a.extend(a[:2])

res="Yes"
if a[0]==0:
    res="No"
for i in range(N):
    if a[i]!=a[i-1]^a[(i+1)%N]:
        #print(a[i],a[i-1],a[i+1])
        #print(i)
        res="No"
        break

print(res)

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')
  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:
import collections
N = int(input())
a = list(int(i) for i in input().split())
chk = sum(a)
if a == [0] *N:
	print("Yes")
else:
	if N == 3:
		if a[0] != 0 and a[1] != 0 and a[2] != 0 :
			if ((chk+2)&(chk+1)) == 0:
				print("Yes")
			else:
				print("No")
		else:
			if a[0] == 0:
				if a[1] == a[2]:
					print("Yes")
				else:
					print("No")
			if a[1] == 0:
				if a[2] == a[0]:
					print("Yes")
				else:
					print("No")
			if a[2] == 0:
				if a[0] == a[1]:
					print("Yes")
				else:
					print("No")
	else:
		l = collections.Counter(a)
		if a.count(0) == 0:
			if list(l.values()) ==  [list(l.values())[0]] * len(l.values()):
				chk=chk//list(l.values())[0]
				if ((chk+2)&(chk+1)) == 0:
					print("Yes")
				else:
					print("No")
			else:
				print("No")
		else:
			if len(l.values()) == 2 and a.count(0) == N//3:
				print("Yes")
			else:
				print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in a:
    d[i] += 1

if len(d) >= 4:
    print("No")
    exit()

if len(d) == 1:
    if 0 in d:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(d) == 2:
    if (N % 3) == 1 and 0 in d and d[0] == N // 3:
        print("Yes")
        exit()
    elif (N % 3) == 2 and 0 in d and d[0] == ((N // 3) + 1):
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(d) == 3:
    l = list(d.values())
    l.sort()
    if l[0] == l[-1]:
        keys = list(d.keys())
        if keys[0] ^ keys[1] == keys[2]:
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

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

l = a[0]
m = -1
n = -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 n == -1:
    print("No")
elif (a.count(l)==a.count(m) and a.count(m)==a.count(n) and a.count(l)+a.count(m)+a.count(n) == N):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

a_unique = list(set(a))

if len(a_unique) > 3:
    result = False

for i in range(len(a_unique)-1):
    for j in range(i+1,len(a_unique)):
        if a_unique[i]^a_unique[j] in a:
            pass
        else:
            result = False

if result:
    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")
elif odd == 0:
    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

if len(d) != 3:
    print("No")
else:
    if n % 3 != 0:
        print("No")
    else:
        tar = [0,0,0]
        temp = 0
        for key in d.keys():
            tar[temp] = key
            temp+=1
        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:
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:
    number_key = [i for i in numbers.keys()]
    if number_key[0] == 0:
        print("Yes")
        exit()
    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) and count0 != 3:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())

a_list = list(map(int, input().split()))
#print(a_list)
c = collections.Counter(a_list)
#print(c)

values=list(c.values())
values.sort()
#print(values)

keys=list(c.keys())
keys.sort()
#print(keys)

ans="No"
if len(values)==3:
  if values[0]==values[1] and values[1]==values[2]:
    if keys[0] ^ keys[1]==keys[2]:
      ans="Yes"
  
if len(values)==2:
  if keys[0] == 0:
    if values[0]*2==values[1]:
      ans="Yes"

  
print(ans)

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

    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
        elif (n1 == n2 and n1 in sa and rest == 1):
            return True
        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 = 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:
	vals = []
	for i in dic:
		vals.append(i)
	if max(dic.values())/2 - min(dic.values()) > 1 or 0 not in vals:
		print "No"
	else:
		print "Yes"
else:
	if 0 in dic:
		print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
t = 0
for i in range(N):
    t ^= a[i]
if t != 0:
    print("No")
else:
    if N == 3:
        print("Yes")
    else:
        print("Yes" if all([0 == x for x in a]) else "No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    a = list(map(int, input().split()))
    for i in range(1, N-1, 1):
        if not a[i-1] ^ a[i+1] == a[i]:
            print("No")
            exit()

    if not a[N-1] ^ a[1] == a[0]:
        print("No")
        exit()
    elif not a[N-2] ^ a[0]  == a[N-1]:
        print("No")
        exit()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if 0 in a:
    print("No")

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

    else:
        if len(set(a)) != 3 or a.count(list(set(a))[0]) != int(n/3) or a.count(list(set(a))[1]) != int(n/3) or a.count(list(set(a))[2]) != int(n/3):
            print("No")

        else:
            set_a = list(set(a))
            if set_a[0] == set_a[1]^set_a[2] and set_a[1] == set_a[2]^set_a[0] and set_a[2] == set_a[1]^set_a[0]:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

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

for i in range(len(a)):
    if i == 0:
        if not bin(a[-1] ^ a[i+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

Submission status: Wrong Answer

Solution code:
def xor(n1, n2):
  if n2=="0":
    return n1
  elif n2=="1":
    if n1=="1":
      return "0"
    else:
      return "1"
      
def bitxor(n1, n2):

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


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

if la%3!=0 or lau!=3:
  print("No")
else:
  u0 = a.count(a_unique[0])
  u1 = a.count(a_unique[1])
  u2 = a.count(a_unique[2])

  if (a_unique[2]== bitxor(a_unique[0], a_unique[1])) and (u0==u1 and u1==u2):
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
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 ^ c == e : 
    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()))

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

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

if len(numnum) != 3:
    print("No")
    exit()

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

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

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

Submission status: Wrong Answer

Solution code:
import bisect
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
a = list(map(int, input().split()))

M = len(format(max(a), 'b'))
first_a = format(a[0], 'b')
full_bit = (1 << M) - 1
candidate = []

for i in range(1, N):
	if a[0] | a[i] == full_bit:
		candidate.append(a[i])

tmp1 = a[0]
flag = False

for i in range(len(candidate)):
	tmp2 = candidate[i]
		
	for j in range(N):
		if tmp1 ^ tmp2 in a:
			tmp1, tmp2 = tmp2, tmp1 ^ tmp2
			if j == N - 1:
				flag = True
				
if flag:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

Solution code:
import sys
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    if N%3 != 0:
        print('No')
        sys.exit()
    A.sort()

    n = int(N/3)
    if 1 == len(set(A[0:n])) and 1 == len(set(A[n:2*n])) and 1 == len(set(A[2*n:3*n])) and A[0] == A[n] ^ A[2*n]:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    count = 0
    if (a[0] != a[N - 1] ^ a[1]):
        count += 1
    if (a[N - 1] != a[N - 2] ^ a[0]):
        count += 1
    for i in range(1, N - 1):
        if (a[i] != a[i - 1] ^ a[i + 1]):
            count += 1
    if (count == 0):
        print("Yes")
    else:
        print("No")
        
resolve()

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_z = 0
        for element in As:
            if element == 0:
                count_z += 1
            else:
                count_a += 1
        else:
            if count_a == count_z:
                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:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

# 001, 101, 1000の場合など、最大桁数のものが1つしかない場合、絶対に1000と作る数は1XXXになるので、絶対無理
# 1000, 1001, 0101, 0001の場合、0001が作れる。しかし、1000はどう頑張っても作れない
if N % 3 != 0:
    print('No')
    exit()

# 全数字を2進数に直す結局全部1が並ぶやつ、つまり、1/1/0, 10/01/11, 111/100/011, 111/101/010などの組み合わせが必要
# そもそも3種類以上ある場合は絶対成り立たない
set_A = set(A)
if len(set_A) > 3:
    print('No')
    exit()

if len(set_A) == 2:
    # 2種類で成り立つのは、全部1111が2つと、全部000が1つの場合のみ
    A_list = list(set_A)
    if 0 in A_list:
        non_zero = [i for i in A_list if i != 0][0]
        if A_list[0] ^ A_list[1] == non_zero:
            # 0と1の比率が1:2でないとだめ。さらに、総数が3*2*n
            if A.count(0) * 2 == A.count(non_zero) and N % 3 == 0:
                # XORがA_listに入ってたら。
                print("Yes")
                exit()
            else:
                print('No')
                exit()
        else:
            print("No")
            exit()
    else:
        print('No')
        exit()
elif len(set_A) == 3:
    A_list = list(set_A)
    if A_list[0] ^ A_list[1] == A_list[2] and A_list[0] ^ A_list[2] == A_list[1] and A_list[1] ^ A_list[2] == A_list[0]:
        # それぞれの数が1:1:1でないとだめ
        if A.count(A_list[0]) == A.count(A_list[1]) == A.count(A_list[2]) and N % 3 == 0:
            print('Yes')
        else:
            print("No")
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
ai = [int(x) for x in input().split()]
if N > 3:
  print("yes")
  exit()
bi = sum([int(bin(x)[2:]) for x in ai])
if list(set(str(bi)))[0] == "2":
  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):
    for k in range(len(a)-2):
        if c[i^j] == 0:
            return False
        i = j
        j = i^j
        c[i^j] -=1
    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()]

cnt = [1, 1, 1]
ind = 0
b = []
if n % 3 != 0:
    print('No')
else:
    a.sort()
    b.append(a[0])
    for i in range(n - 1):
        if a[i] == a[i + 1]:
            cnt[ind] += 1
        else:
            ind += 1
            if ind > 2:
                break
            b.append(a[i + 1])
    if (ind == 2) and (cnt[0] == n // 3) and (cnt[1] == n // 3) and (cnt[2] == n // 3):
        if (b[0] ^ b[1] == b[2]):
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from functools import reduce
N = int(input())
A = [int(x) for x in input().split()]
def isExist(N, A):
  AD = defaultdict(int)
  for a in A:
    AD[a] += 1
  keys = len(AD.keys())
  xor = reduce(lambda x, y: x^y, AD.keys())
  mlen = max([a for a in AD.values()])
  if keys !=3 and keys != 1:
    return 'No'
  if xor != 0:
    return 'No'
  if mlen != N and (N % 3 != 0 or mlen != N // 3):
    return 'No'
  return 'Yes'
print(isExist(N, A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n % 3 == 0:
    d = {}
    for x in a:
        d.setdefault(x, 0)
        d[x] += 1
    if len(d) > 3 or any([d[x] % (n//3) for x in d]):
        print("No")
        quit()
    if len(d) == 1 and 0 not in d:
        print("No")
        quit()
    if len(d) == 2 and d.get(0) != n//3:
        print("No")
        quit()
    print("Yes")
else:
    print("Yes" if all([x == 0 for x in a]) else "No")

Submission status: Wrong Answer

Solution code:
import itertools
import sys

n = int(input())
a = list(map(int, input().split()))
flag = False

for i in itertools.permutations(a, len(a)):
    i_add = i + (i[0], i[1])
    for j in range(0, len(i)):
        if i_add[j] ^ i_add[j+2] != i_add[j+1]:
            flag = True
        if flag:
            break
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

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

k = {}
for i in range(N):
    if not A[i] in k:
        k[A[i]] = 1
    else:
        k[A[i]] += 1
B = 0
a = 0
if len(k.keys()) == 3:
    B = 0
    for key, val in k.items():
        if val == N // 3:
            a += 1
        B = B ^ key
elif len(k.keys()) == 2:
    for key, val in k.items():
        if val == N // 3 and key == 0:
            a += 1
        elif val == N // 3 * 2:
            a += 2
    B = 0

if N % 3 == 0 and B == 0 and a == 3:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
def main(N):
	a = list(map(int, input().split()))
	if a.count(0) == N:
		print("Yes")
		return
	if N%3 != 0:
		print("No")
		return
	d={}
	for i in a:
		if i in d:
			d[i] = d[i] + 1
		else:
			d[i] = 1
	if 0 in d.keys():
		if d[0] == N//3:
			for i in d.keys():
				if i == 0:
					continue
				elif d[i] % 2 != 0:
					print("No")
					return
			print("Yes")
		else:
			print("No")
	else:
		for i in d.values():
			if i != N//3:
				print("No")
				return
		print("Yes")
	return
		
	return

main(int(input()))

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]) and a_n.count(a_n_unique[0]) == 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_all = list(map(int, input().split()))

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:
N = int(input())
A = list(map(int,input().split()))
As = list(set(A))

flag = 0
if len(As) == 1:
    if As[0] == 0:
        flag = 1
elif len(As) == 2:
    d = {}
    for a in A:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    if As[0] == 0 and int(list(set(bin(As[1])[2:]))[0]) == 1 and d[As[0]]*2 == d[As[1]]:
        flag = 1
else:
    if len(As) == 3:
        if As[0]^As[1] == As[2]:
            flag = 1

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

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

if x != y and x != z:
    if N % 3 == 0:
        cx, cy, cz = A.count(x), A.count(y), A.count(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')
    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 sys
import collections


def input():
    return sys.stdin.readline()[:-1]


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

n = map(int,input().split())
a = list(map(int, input().split()))
unique_a = list(set(a))


if len(unique_a) == 1 :
    print("Yes")
elif len(unique_a) == 3 :
    if a.count(unique_a[0]) == a.count(unique_a[1]) and  a.count(unique_a[0]) == a.count(unique_a[2]):
        if unique_a[0] == unique_a[1] ^ unique_a[2] or unique_a[1] == unique_a[0] ^ unique_a[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()))
l=[]
l.append(a[0])
def xx(n,a,l):
    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:
            return "Yes"
        else:
            return "No"
    else:
        if len(l)!=3:
            return "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:
                return "No"
                exit()
        if len(l)==n and l[0]^l[1]==l[-1]:
            return "Yes"
        else:
            return "No"

print(xx(n,a,l))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a_lis = [int(_) for _ in input().split()]

def func(x, y):
    return x ^ y

def finish(ans, a_lis_item):
    if ans != a_lis_item:
        print('No')
        sys.exit()

for i, a in enumerate(a_lis):
    if i == 0:
        ans = func(a_lis[N - 1], a_lis[1])
    elif i == N - 1:
        ans = func(a_lis[0], a_lis[N - 2])
    else:
        ans = func(a_lis[i - 1], a_lis[i + 1])
    finish(ans, a_lis[i])

print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
t = 0
for i in range(N):
    t ^= a[i]
if t != 0:
    print("No")
else:
    if N == 3:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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