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())
A = list(map(int,input().split()))
if(A.count(0) != 0):
    if(A.count(0) == N):
        print('Yes')
    elif(N % 2 != 0):
        a = -1
        b = -1
        aa = 0
        a = A.count(aa)

        bb = -1

        for i in A:
            if(aa != i):
                bb = i
                break
        if(bb != -1):
            b = A.count(bb)
            if(a + b == N and a == int((N - 2)/3) + 1):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    if(N % 3 == 0):
        a = -1
        b = -1
        c = -1
        aa = A[0]
        a = A.count(aa)

        bb = -1

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

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

Submission status: Wrong Answer

Solution code:
def check(b, l):
    for i in l:
        if i == b:
            continue
        n = b ^ i
        if not(n in l):
            print("No")
            exit()
        else:
            flag = 0
            for a in l:
                if n^a == i:
                    flag += 1
                elif n^a == b:
                    flag += 1
                    
                if flag == 2:
                    l.remove(n)

            


    print("Yes")
    exit()

n = int(input())
lst = list(map(int, input().split()))
x = lst

base = x[0]
check(base, x)

Submission status: Wrong Answer

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

perm = [0]
success = 0

def circle_xor(n, m = 1):
    global success
    if n == m:
        for i in range(0,2):
            back = perm[i-2]
            middle = perm[i-1]
            front = perm[i]
            if a[back] ^ a[front] == a[middle]:
                if i == 1:
                    success = 1
                continue
            else:
                break
    else:
        for i in range(1, n):
            if i in perm:
                continue
            perm.append(i)
            if m > 2 and n != 3:
                back = perm[i-2]
                middle = perm[i-1]
                front = perm[i]
                if a[back] ^ a[front] == a[middle]:
                    circle_xor(n, m + 1)
                else:
                    continue
            elif n == 3:
                circle_xor(n, m + 1)
            perm.pop()

circle_xor(n)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a_2=[]
for i in range(len(a)):
    a_2.append(bin(a[i]))
import collections
c = collections.Counter(a)
b=[]
out=0
for i in c.values():
    b.append(i)
if a.count(0)==0:#0がない場合
    if len(b)%3!=0:
        out=1
    for i in range(len(b)-1):
        if b[i]!=b[i+1]:
            out=1
            break
        else:
            pass
    if out==0:
        print('Yes')
    elif out==1:
        print('No')
else:#0あり
    if len(b)>2:
        print('No')
    elif len(b)==1:
        print('Yes')
    elif len(b)==2:
        if a.count(0)*3==len(a):
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

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

if 0 in a:
    print("Yes")
    exit()

if (a[0] ^ a[N-1]) in a:
    print("Yes")
    exit()

s = set()
for i in range(N):
    for j in range(N):
        s.add(a[i] ^ a[j])

if s in a:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import collections
import sys

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

value, count = list(a.keys()), list(a.values())

if sum(a)==0:
    print('Yes')
    sys.exit()

elif len(value)<3:
    print('No')
    sys.exit()

elif count[0]+count[1]+count[2] != N:
    print('No')

elif value[0]^value[1]^value[2] != 0:
    print('No')

elif count[0]==count[1]==count[2]:
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

Solution code:
P=int(input())
A=[int(i) for i in input().split(" ")]
ans=0
if A.count(0)==0:
	if len(set(A))==3:
		if P%3==0:
			if A.count(A[0])==P/3:
				n=A[0]
				A.remove(A[0])
				m=A[0]
				A.remove(A[0])
				l=A[0]
				if A.count(A[0])==P/3:
					if l==n|m or n==m|l:ans=1
if len(set(A))==1:
	if A[0]==0:ans=1
if len(set(A))==2:
	if P%2==0:
		if A.count(0)==P//2:ans=1

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

Submission status: Wrong Answer

Solution code:
import copy
import sys
n = int(input())
a = list(map(int,input().split()))
a2 = copy.copy(a)
c = 0
d = len(a)
for i in range(len(a)):
    if i+1 == len(a):
        ans = a[i-1] ^ a[0]
        if (ans in a2):
            try:
                a2.remove(ans)
            except e:
                print("No")
                sys.exit()
        else:
            break
    else:
        ans = a[i-1] ^ a[i+1]
        if (ans in a2):
            try:
                a2.remove(ans)
            except e:
                print("No")
                sys.exit()
        else:
            break
    c += 1

if c == d:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(map(int, input().split()))
c.sort()
c_set = set(c)
ans = 'No'

# 0が混ざっていれば計算方法が違う
if c[0] == 0:
    if n % 3 == 0 and len(c_set) == 3 and c.count(0) == n % 3:
        ans = 'Yes'
elif n == 3:
    if c[0] ^ c[1] == c[2]:
        ans = 'Yes'

else:
    if n % 3 == 0 and len(c_set) == 3:
        ank = n % 3
        if c.count(c[0]) == ank and c.count(c[ank]) == ank and c[0] ^ c[1] == c[2]:
            ans = 'Yes'
            
print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=list(map(int, input().split()))
c=list(set(b))
t=0
d=[0 for i in range(len(c))]
if a==1:
  print("Yes")
else:
  if len(c)==1:
    if c[0]==0:
      print("Yes")
    else:
      print("No")
  elif len(c)==2:
    for i in range(len(c)):
      e=c[i]
      d[i]=b.count(e)
    if (c[0]==0 and d[0]*2==d[1])or (c[1]==0 and d[1]*2==d[0]):
      print("Yes")
    else:
      print("No")
  elif len(c)>3:
    print("No")
  else:  
    for i in range(len(c)):
      e=c[i]
      d[i]=b.count(e)
    if d[0]==d[1]and d[0]==d[2]:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
ais = list(map(int, input().split()))
yes = 1
all_ai = list(itertools.permutations(ais, len(ais)))

for ai in all_ai:
  for i in range(n):
    if i == 0:
      if (ai[1] ^ ai[n-1]) != ai[0]:
        yes = 0
    elif i == n-1:
      if (ai[0] ^ ai[n-2]) != ai[n-1]:
        yes = 0
    else:
      if (ai[i-1] ^ ai[i+1]) != ai[i]:
        yes = 0
if yes == 0:
  print('No')
else:
  print('yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

dic = defaultdict(int)

for a in A:
    dic[a] += 1

n = len(dic.keys())
cnts = dic.values()

if n == 3:
    v = list(dic.keys())
    f1 = False
    if v[0] ^ v[1] == v[2] or v[1] ^ v[2] == v[0] or v[2] ^ v[0] == v[1]:
        f1 = True

    f2 = True
    for cnt in cnts:
        if cnt != N // 3:
            f2 = False

    if f1 and f2:
        print('Yes')
    else:
        print('No')
    
else:
    print('No')

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc035/tasks/agc035_a
import numpy as np


def calc(N: int, values: np.ndarray) -> bool:
    return any([calc_0_1(N, values)])


def calc3(N: int, values: np.ndarray) -> bool:
    if N % 3 != 0:
        return False

    uniques = np.unique(values)
    if len(uniques) != 3:
        return False

    counts = [np.sum(values == v) for v in uniques]  # 各固有値の格納数
    if len(np.unique(counts)) != 1:
        return False

    sorted_uniques = np.sort(uniques)
    return all(
        [
            sorted_uniques[0] == np.bitwise_xor(sorted_uniques[1], sorted_uniques[2]),
            sorted_uniques[1] == np.bitwise_xor(sorted_uniques[2], sorted_uniques[0]),
            sorted_uniques[2] == np.bitwise_xor(sorted_uniques[0], sorted_uniques[1]),
        ]
    )


def calc_0_1(N: int, values: np.ndarray) -> bool:
    """
    0000...0 and 1111...1 only pattern
    """
    if N < 3:
        return False

    max_value = np.max(values)
    # max value must be 1111...1
    if not number_is_all_bit_1(max_value):
        return False

    uniques = np.unique(values)
    if set(uniques) != {0, max_value}:
        return False

    counts = {v: np.sum(values == v) for v in uniques}  # 各固有値の格納数
    if (counts[1] == counts[0] + 1) or (counts[0] == counts[1]):
        return True

    return False


def number_is_all_bit_1(value: int) -> bool:
    if value == 0:
        return False
    if value == 1:
        return True
    ex = 1
    compare = 2
    while compare - 1 <= value:
        if value == compare - 1:
            return True
        ex += 1
        compare = 2 ** ex

    return False


def load_input_as_int_array():
    return np.array([int(v) for v in input().split(" ")])


N = int(input())
values = load_input_as_int_array()
result = calc(N, values)

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

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

a_coll  = collections.Counter(a)
a_key   = list(a_coll.keys())
a_value = list(a_coll.values())

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

if len(a_key) == 1:
    if a_key[0] == 0:
        print("Yes")
        exit()

if len(a_key) == 2:
    if 0 in a_key:
        print("Yes")
        exit()

for count in a_value:
    if count != N / 3:
        print("No")
        exit()

if len(a_key) == 3:
    if a_key[0] ^ a_key[1] == a_key[2]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(map(int, input().split()))
c.sort()
c_set = set(c)
ans = 'No'

# 0が混ざっていれば計算方法が違う
if c[0] == 0:
    if n % 3 == 0 and len(c_set) == 3 and c.count(0) == n % 3:
        ans = 'Yes'
elif n == 3:
    if c[0] ^ c[1] == c[2]:
        ans = 'Yes'

else:
    if n % 3 == 0 and len(c_set) == 3:
        ank = n % 3
        if c.count(c[0]) == ank and c.count(c[ank]) == ank and c[0] ^ c[1] == c[2]:
            ans = 'Yes'

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
ans = "No"
Co = Counter(A)
if n % 3 != 0 : #3の倍数でない
    if len(Co.keys()) == 1 and list(Co.keys())[0] == 0:
        ans = "Yes" #要素の種類は1つかつその要素は0の場合のみOK
else :
    tr = n // 3
    Va = Co.values()
    if len(Va) == 3 :
        if Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1] == tr and Co.most_common()[0][0]^Co.most_common()[1][0]== Co.most_common()[2][0]:
            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:
import collections
import random
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:
    x=random.randint(1,2)
    if x%2==0:
      print('No')
    else:
      print('Yes')
    
  elif n%3!=0:
    print('No')
  elif n==3:
    print('Yes')
  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()))
a.sort()

def main():
    if a[0] != a[-1] ^ a[1]:
        print("No")
        return
    for i in range(1, N - 1):
        if a[i] != a[i + 1] ^ a[i - 1]:
            print("No")
            return
    if a[-1] != a[0] ^ a[-2]:
        print("No")
        return
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
if N%3 == 0:
    for a in A:
        if a not in dic:
            dic[a] = 1
        else:
            dic[a] += 1
    if len(dic) == 3:
        flag = True
        for d in dic.values():
            if d != N//3:
                flag = False
        if flag:
            print('Yes')
        else:
            print('No')

    else:
        print('No')
    
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(s) for s in input().split(" ")]
dic_a = {}
for aa in a:
  if aa in dic_a:
    dic_a[aa] += 1
  else:
    dic_a[aa] = 1
a_set = list(dic_a.keys())
n_set = len(a_set)

if (n < 3):
  ans = False
else:
  ans = False
  if 0 in a_set:
    for k, v in dic_a.items():
      if v >= 2 and k != 0:
        ans = True
        break
  if not ans:
    for i in range(n_set):
      for j in range(i + 1, n_set):
        a_ij = a_set[i] ^ a_set[j]
        if a_ij in a_set and\
           a_ij != a_set[i] and\
           a_ij != a_set[j]:
          ans = True
          break
      if ans:
        break

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a = input()
list1 = list(map(int,a.split()))
flag = 0
if len(list1) >1200:
    print("No")
    sys.exit()
#中間部分の処理
for i in range(1, N-1):

    bin_num1 = list(format(list1[i-1],"b"))
    bin_num2 = list(format(list1[1+1],"b"))
    bin_num3 = []
    le,le2 = 0,0
    ans = 0
    if len(bin_num1) <= len(bin_num2):
        le = len(bin_num1)
        le2 = len(bin_num2)
        flag = 0
    else:
        le = len(bin_num2)
        le2 = len(bin_num1)
        flag = 1

    for j in range(le):
        if (int(bin_num1[len(bin_num1)-1 - j]) + int(bin_num2[len(bin_num2)-1 - j])) == 0 or (int(bin_num1[len(bin_num1)-1 - j]) + int(bin_num2[len(bin_num2)-1 - j])) == 2 :
            bin_num3.append("0")
        else:
            bin_num3.append("1")
    if le <le2:
        if flag == 0:
            for k in range(le2-le-1 , -1,-1):
                bin_num3.append(bin_num2[k])
        elif flag == 1:
            for k in range(le2-le-1 , -1,-1):
                bin_num3.append(bin_num1[k])

    bin_num3.reverse()

    ans = int("".join(bin_num3) ,2)

    if ans != int(list1[i]):
        print("No")
        sys.exit()

#最初の部分の処理

bin_num1 = list(format(list1[N-1],"b"))
bin_num2 = list(format(list1[1],"b"))
bin_num3 = []
le = 0
le2 = 0
ans = 0
if len(bin_num1) <= len(bin_num2):
    le = len(bin_num1)
    le2 = len(bin_num2)
    flag = 0
else:
    le = len(bin_num2)
    le2 = len(bin_num1)
    flag = 1

for i in range(le):
    if (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 0 or (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 2 :
        bin_num3.append("0")
    else:
        bin_num3.append("1")
if le <le2:
    if flag == 0:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num2[k])
    elif flag == 1:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num1[k])


bin_num3.reverse()
ans = int("".join(bin_num3) ,2)

if ans != list1[0]:
    print("No")
    sys.exit()

#最後の部分の処理

bin_num1 = list(format(list1[N-2],"b"))
bin_num2 = list(format(list1[0],"b"))
bin_num3 = []
le = 0
le2 = 0
ans = 0
if len(bin_num1) <= len(bin_num2):
    le = len(bin_num1)
    le2 = len(bin_num2)
    flag = 0
else:
    le = len(bin_num2)
    le2 = len(bin_num1)
    flag = 1

for i in range(le):
    if (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 0 or (int(bin_num1[len(bin_num1)-1 - i]) + int(bin_num2[len(bin_num2)-1 - i])) == 2 :
        bin_num3.append("0")
    else:
        bin_num3.append("1")
if le <le2:
    if flag == 0:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num2[k])
    elif flag == 1:
        for k in range(le2-le-1 , -1,-1):
            bin_num3.append(bin_num1[k])


bin_num3.reverse()
ans = int("".join(bin_num3) ,2)

if ans != list1[N-1]:
    print("No")
    sys.exit()

#一回も引っかからなければこれで終わり
print("Yes")

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc035/tasks/agc035_a
import numpy as np


def calc(N: int, values: np.ndarray) -> bool:
    return any([calc3(N, values), calc_0_1(N, values)])


def calc3(N: int, values: np.ndarray) -> bool:
    if N % 3 != 0:
        return False

    uniques = np.unique(values)
    if len(uniques) != 3:
        return False

    counts = [np.sum(values == v) for v in uniques]  # 各固有値の格納数
    if len(np.unique(counts)) != 1:
        return False

    sorted_uniques = np.sort(uniques)
    return all(
        [
            sorted_uniques[0] == np.bitwise_xor(sorted_uniques[1], sorted_uniques[2]),
            sorted_uniques[1] == np.bitwise_xor(sorted_uniques[2], sorted_uniques[0]),
            sorted_uniques[2] == np.bitwise_xor(sorted_uniques[0], sorted_uniques[1]),
        ]
    )


def calc_0_1(N: int, values: np.ndarray) -> bool:
    """
    0000...0 and 1111...1 only pattern
    """
    if N < 3:
        return False

    if N % 2 != 0:
        return False

    max_value = np.max(values)
    # max value must be 1111...1
    if not number_is_all_bit_1(max_value):
        return False

    uniques = np.unique(values)
    if set(uniques) != {0, max_value}:
        return False

    counts = {v: np.sum(values == v) for v in uniques}  # 各固有値の格納数
    if (counts[1] == counts[0] + 1) or (counts[0] == counts[1]):
        return True

    return False


def number_is_all_bit_1(value: int) -> bool:
    if value == 0:
        return False
    if value == 1:
        return True
    ex = 1
    compare = 2
    while compare - 1 <= value:
        if value == compare - 1:
            return True
        ex += 1
        compare = 2 ** ex

    return False


def load_input_as_int_array():
    return np.array([int(v) for v in input().split(" ")])


N = int(input())
values = load_input_as_int_array()
result = calc(N, values)

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

Submission status: Wrong Answer

Solution code:
import collections

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

C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
    print("Yes")
elif (L == 2) and (C[e[0]] == C[e[1]] * 2):
    print(((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No")
elif (L == 3) and (C[e[0]] == C[e[1]]) and (C[e[1]] == C[e[2]]):
    print(((e[0] ^ e[1]) == e[2]) and "Yes" or "No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
aa = inpl()

def product():
    if N != 3:
        for a in aa:
            if a != aa[0]:
                return 'No'
        return 'Yes'
    else:
        if aa[0]^aa[1] != aa[2]:
            return 'No'
        if aa[1]^aa[2] != aa[0]:
            return 'No'
        if aa[2]^aa[0] != aa[1]:
            return 'No'
        return 'Yes'


print(product())

Submission status: Wrong Answer

Solution code:

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

ans = []

f = True

for i in range(N):
    # print("====",i)
    if f:
        if i == 0:
            a1 = a[0]
            a2 = a[1]
            # print(a1,a2)
            # print(a)
            if a1^a2 in a:

                ans.append(a1)
                # a.remove(a1)
                ans.append(a2)
                a.remove(a2)
            else:
                f = False
                continue
        elif i == N-1:
            a1 = ans[i-1]
            a2 = ans[i]
            # print(a1,a2)
            # print(a)
            if a1^a2 in a:
                print("Yes")
                break
            else:
                print("No")
                break
        else:
            a1 = ans[i-1]
            a2 = ans[i]
            # print(a1,a2)
            # print(a)
            if a1^a2 in a:
                ans.append(a1^a2)
                a.remove(a1^a2)
            else:
                f = False
                continue
    else:
        print("No")
        break

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort()
b=list(set(a))
if len(b) == 3 and b[0] ^ b[1] == b[2] and a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
    print('Yes')
elif b==[0]:
    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:
			print("Yes")
			sys.exit()
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()

		elif next1 == A[0]:
			tmp = a_max - next1
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				#print(next1)
				print("No")
				sys.exit()

		else:
			tmp = next1 + bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
	print("Yes")


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
# import itertools
# import bisect
import copy
import collections

N = int(sys.stdin.readline().rstrip())

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

c = collections.Counter(a)

# print(c)

keys = list(c.keys())


for j in range(len(keys)):
  if j == 0:
    continue

  # print(j)
  tmp = copy.copy(c)

  # x, yを決めるとzが決まると同値なので
  x = keys[0]
  y = keys[1]
  
  c[x] -= 1
  c[y] -= 1
  
  next_flg = True
  for _ in range(N-2):
    z = x^y
    # print(z)
    # print(a[z])
    # print("")

    if c[z] <= 0:
      next_flg = False
      break
    
    c[z] -= 1
    x, y = (y, z)


  if next_flg:
    print("Yes")
    quit()
  

print("No")

Submission status: Wrong Answer

Solution code:
a=int(input())
b=list(map(int, input().split()))
c=list(set(b))
t=0
d=[0 for i in range(len(c))]
if len(c)==1:
  if c[0]==0:
    print("Yes")
  else:
    print("No")
elif len(c)==2:
  for i in range(len(c)):
    e=c[i]
    d[i]=b.count(e)
  if (c[0]==0 and d[0]*2==d[1])or (c[1]==0 and d[1]*2==d[0]):
    print("Yes")
  else:
    print("No")
elif len(c)>3:
  print("No")
else:  
  for i in range(len(c)):
    e=c[i]
    d[i]=b.count(e)
  if d[0]==d[1]and d[0]==d[2]:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

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

from collections import Counter

count = Counter((a))

len_count = len(count)

if len_count >= 4:
    print("No")
elif len_count == 1:
    if a[0] == 0:
        print("Yes")
    else:
        print("No")
elif len_count == 3:
    if len(Counter(count.values())) == 1:
        print("Yes")
    else:
        print("No")
else:
    if count[0] * 3 == len(a):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import bisect

def search(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

def check(l1, l2, a):
    x = l1
    a = a[::]
    while 0 < len(a):
        ni = search(a, (l1^l2))
        if ni < 0:
            return False
        l1 = l2
        l2 = a.pop(ni)
    return (l1 ^ l2) == x

def main():
    seen = set()
    n = int(input())
    a = sorted(list(map(int, input().split())))
    l1, a = a[0], a[1:]
    for i in range(len(a)):
        if (l1, a[i]) in seen:
            break
        b = a[::]
        l2 = b.pop(i)
        if check(l1, l2, b):
            print('Yes')
            return
        seen.add((l1, l2))
        seen.add((l2, l1))
    print('No')

main()

Submission status: Wrong Answer

Solution code:
def gen_alist(a_0,a_1):
    generated_alist = [a_0,a_1]
    for i in range(N-2):
        a_0, a_1 = a_1, a_0^a_1
        generated_alist.append(a_1)
        return generated_alist



N = int(input())
a_list = list(map(int,input().split()))
a_0 = a_list[0]
ans = False
for i in range(1,N):
    if a_0^a_list[i] in a_list:
        ans = gen_alist(a_0, a_list[i])
        if sum(ans) == sum(a_list):
            ans = True

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

Submission status: Wrong Answer

Solution code:
import sys,itertools,copy
input = sys.stdin.readline
N=int(input().strip())
an=[int(x) for x in input().strip().split()]

if N==3:
    if an[0]^an[1]==an[2]:
        print("Yes")
    else:
        print("No")
elif N%3!=0:
    if len(set(an))==1:
        print("Yes")
    else:
        print("No")
else:
    bn = list(set(an))
    if len(bn)>3:
        print("No")
    elif len(bn)==1:
        print("Yes")
    elif len(bn)==2:
        if bn.count(0)==1:
            print("Yes")
        else:
            print("No")
    elif bn[0]^bn[1]!=bn[2]:
        print("No")
    else:
        for b in bn:
            if an.count(b)!=(N/3):
                print("No")
                break
        else:
            print("Yes")

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:
			print("Yes")
			sys.exit()
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()

		elif next1 == A[0]:
			print("No")
			sys.exit()
			tmp = a_max - next1
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				#print(next1)
				print("No")
				sys.exit()

		else:
			tmp = next1 + bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
	print("No")


if __name__ == "__main__":
	main()