Problem:


Score : 300 points

Problem Statement

Snuke has N hats. The i-th hat has an integer a_i written on it.

There are N camels standing in a circle.
Snuke will put one of his hats on each of these camels.

If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.

The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.

What is XOR?

The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.

Sample Input 2

4
1 2 4 8

Sample Output 2

No

There is no such way to distribute the hats; the answer is No.



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a = input()
list1 = list(map(int,a.split()))
flag = 0
#中間部分の処理
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
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
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:
import sys
import copy

n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))

b1=a[0]
b_lis=copy.copy(a)
b_lis.remove(b1)
judge=0
d=set(a)
if len(d)==3:
    for i in range(n-1):
        c_lis=copy.copy(b_lis)
        b1d=b1
        b2=a[i+1]
        c_lis.remove(b2)
        while True:
            b3=b1d^b2
            if b3 in c_lis:
                c_lis.remove(b3)
                b1d=b2
                b2=b3
            else:
                break
            if len(c_lis)==0:
                judge=1
                break


if judge==1:
    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):
    a = a[::]
    while 0 < len(a):
        ni = search(a, (l1^l2))
        if ni < 0:
            return False
        l1 = l2
        l2 = a.pop(ni)
    return True

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)):
        b = a[::]
        l2 = b.pop(i)
        if ((l1, l2) in seen) or ((l2, l1) in seen):
            break
        seen.add((l1, l2))
        seen.add((l2, l1))
        if check(l1, l2, b):
            print('Yes')
            return
    print('No')

main()

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
a=list(map(int,input().split()))
b=list(itertools.combinations(a,2))
for i in range(len(b)):
    if b[i][0]^b[i][1] not in a:
        print("No")
    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("Yes")
			sys.exit()

	tmp = 0
	flg = False
	for i in ll:
		tmp += i
		if a_max == tmp:
			flg = True
			break
	
	if flg == False:
			print("Yes")
			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("Yes")
				sys.exit()
		
		if i == N-1:
			if next1 == a_max and bk ^ A[0] == a_max:
				print("No")
				sys.exit()
		
		if next1 == a_max:
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("Yes")
				sys.exit()

		elif next1 == A[0]:
			tmp = a_max - next1
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				#print(next1)
				print("Yes")
				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()

Submission status: Wrong Answer

Solution code:
def solve(N, _as):
    if N % 3 != 0:
        return False

    max_bit_len = 0
    max_bit_len_ints = []
    other_ints = []
    for a in _as:
        bl = int.bit_length(a)
        if bl > max_bit_len:
            max_bit_len = bl
            other_ints.extend(max_bit_len_ints)
            max_bit_len_ints.clear()
            max_bit_len_ints.append(a)
        elif bl == max_bit_len:
            max_bit_len_ints.append(a)
        else:
            other_ints.append(a)

    if N // 3 != len(other_ints):
        return False

    first = max_bit_len_ints.pop()
    for second in other_ints:
        return _solve(first, second, max_bit_len_ints, other_ints)


def _solve(first, second, _max_bit_len_ints, _other_ints):
    max_bit_len_ints = _max_bit_len_ints[:]
    other_ints = _other_ints[:]
    other_ints.remove(second)

    pre_latest = second
    latest = first^second
    try:
        max_bit_len_ints.remove(latest)
    except ValueError:
        return False

    count = 0
    while len(max_bit_len_ints) > 0 and len(other_ints) > 0:
        _latest = latest
        latest = pre_latest^latest
        pre_latest = _latest
        if count == 0 or count == 2:
            try:
                max_bit_len_ints.remove(latest)
            except ValueError:
                return False
        else:
            try:
                other_ints.remove(latest)
            except ValueError:
                return False
        count = (count + 1) % 3

    return pre_latest^latest == first and latest^first == second


if __name__ == '__main__':
    N = int(input())
    _as = [int(x) for x in input().split()]
    print('Yes' if solve(N, _as) else 'No')

Submission status: Wrong Answer

Solution code:

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

ans = []

f = True

for i in range(N):
    if f:
        if i == 0:
            a1 = a[0]
            a2 = a[1]
            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]
            if a1^a2 == ans[0]:
                print("Yes")
                break
            else:
                print("No")
                break
        else:
            a1 = ans[i-1]
            a2 = ans[i]
            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:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
flag = True
syugo = set(sorted(data))
if len(syugo) == 1:
    syugo = list(syugo)
    if syugo[0] != 0:
        flag = False

elif len(syugo) == 2:
    syugo = list(syugo)
    if syugo[0] != 0:
        flag = False
    if data.count(syugo[1]) // data.count(0) != 2:
        flag = False
        
elif len(set(data)) == 3:
    syugo = list(syugo)
    if syugo[0]^syugo[1] != syugo[2]:
        flag = False
    if len(set([data.count(i) for i in syugo])) != 1:
        flag = False
else:
    flag = False

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

Submission status: Wrong Answer

Solution code:
import collections
import random
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==0:
  print('Yes')
elif n%3!=0:
  print('No')
elif len(set(a))!=3:
  print('No')
else:
  a=list(set(a))
  for i in range(len(a)):
    a[i]=format(a[i],'020b')
  l=[0 for i in range(20)]
  for i in range(len(a)):
    for j in range(20):
      if a[i][j]=='1':
        l[j]+=1
  ct=0
  for j in range(20):
    if l[j]==2 or l[j]==0:ct+=1
  if ct==20:
    print('Yes')
  else:
    x=random.randint(1,2)
    if x%2==0:
      print('No')
    else:
      print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
aa=set(a)
if len(aa)>3:
    print("No")
    exit()
elif a.count(0)==n:
    print("Yes")
    exit()
elif len(aa)<=1:
    print("No")
    exit()
l=[]
l.append(a[0])
for i in range(1,n):
    if a[i]!=a[0]:
        l.append(a[i])
        break
l.append(l[0]^l[1])

if n==0:
    exit()
else:
    if l[0]==l[1]:
        if n%3==0:
            if a.count(l[0])==(n//3)*2 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[0])==(n//3)*2+2 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
    if l[0]==l[2]:
        if n%3==0:
            if a.count(l[0])==(n//3)*2 and a.count(l[1])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[1])==n//3:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[1])==n//3+1:
                print("Yes")
            else:
                print("No")
    if l[2]==l[1]:
        if n%3==0:
            if a.count(l[1])==(n//3)*2 and a.count(l[0])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[1])==(n//3)*2 and a.count(l[0])==n//3+1:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[1])==(n//3)*2+1 and a.count(l[0])==n//3+1:
                print("Yes")
            else:
                print("No")
    else:
        if n%3==0:
            if a.count(l[0])==n//3 and a.count(l[1])==n//3 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==n//3+1 and a.count(l[1])==n//3 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3 and a.count(l[2])==n//3+1:
                print("Yes")
            else:
                print("No")
        elif n%3==2:
            if a.count(l[0])==n//3+1 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3+1 and a.count(l[1])==n//3 and a.count(l[2])==n//3+1:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3+1:
                print("Yes")
            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([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

    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 = [np.sum(values == v) for v in uniques]  # 各固有値の格納数
    if abs(counts[0] - counts[1]) > 1:
        return False

    return True


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:
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] = 0
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 v in dic_a.values():
      if v >= 2:
        ans = True
        break
  if not ans:
    for i in range(n_set):
      for j in range(i + 1, n_set):
        if a_set[i] ^ a_set[j] in a_set:
          ans = True
          break
      if ans:
        break

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

Submission status: Wrong Answer

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = False

def check(i,j):
    c[j] -= 1
    for k in range(len(a)-1):
        if c[i^j] <= 0:
            return False
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return True


if check(a[0],a[1]):
    hoge = True

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

Submission status: Wrong Answer

Solution code:
import sys

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]
    elif a[i] != l and a[i] != m and n == -1 :
        n = a[i]
    elif a[i] != l and a[i] != m and a[i] != n and o == -1:
        print("No")
        sys.exit()

if (m == -1 and n == -1) and l^l == l:
    print("Yes")
elif n == -1 and a.count(l)+a.count(m) == N and ( (a.count(l)*2==a.count(m) and l^m==m) or (a.count(l)==a.count(m)*2 and l^m == l)):
    print("Yes")
elif a.count(l)+a.count(m)+a.count(n) == N and l^m==n:
    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("Yes")
			sys.exit()

	tmp = 0
	flg = False
	for i in ll:
		tmp += i
		if a_max == tmp:
			flg = True
			break
	
	if flg == False:
			print("Yes")
			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("Yes")
				sys.exit()
		
		if i == N-1:
			if next1 == a_max and bk ^ A[0] == a_max:
				print("No")
				sys.exit()
		
		if next1 == a_max:
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("Yes")
				sys.exit()

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

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


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort()
b=list(set(a))
if len(b)!=3:
    print('No')
    exit()
if a.count(b[0])==a.count(b[1])==a.count(b[2]):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
a = list(int(i) for i in input().split())

while True:
    for c in itertools.combinations(a, 3):
        if c[0] ^ c[2] == c[1]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[1])
        elif c[1] ^ c[2] == c[0]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[0])
        elif c[0] ^ c[1] == c[2]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[2])
        else:
            print("No")
            exit()

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
a=set(a_list)
a=list(a)
if 0 in a:
        if len(a) ==2:
            if a_list.count(0)==len(a_list)//3:
                    print("Yes")
            else:
                    print("No")
        else:
                print("No")
else:
        if len(a)==3:
            a1=a[0]
            a2=a[1]
            a3=a[2]
            if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                if a_list.count(a1) ==a_list.count(a2) ==a_list.count(a3):
                        print("Yes")
                else:
                        print("No")
            else:
                print("No")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
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:
    print((C[0] > 0) and "Yes" or "No")
elif L == 2:
    print(((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No")
elif L == 3:
    print(((e[0] ^ e[1]) == e[2]) and "Yes" or "No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
def binbin(a):
    return int(bin(a).split("b")[1])
arr=[A[-1]]
arr.extend(A)
arr.append(A[0])
ans=[]
for i in range(1,N+1):
    ans.append(int(binbin(arr[i])) == int("".join(list(map(lambda x:str(int(x)%2),str(binbin(arr[i-1])+binbin(arr[i+1])))))))

print("Yes" if any(ans) else "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:
    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:
    if len(b)>2:
        print('No')
    elif len(b)==1:
        print('Yes')
    else:
        if a.count(0)*3==len(a):
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
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("Yes")
			sys.exit()

	tmp = 0
	flg = False
	for i in ll:
		tmp += i
		if a_max == tmp:
			flg = True
			break
	
	if flg == False:
			print("Yes")
			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("Yes")
				sys.exit()
		
		if i == N-1:
			if next1 == a_max and bk ^ A[0] == a_max:
				print("No")
				sys.exit()
		
		if next1 == a_max:
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("Yes")
				sys.exit()

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

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


if __name__ == "__main__":
	main()

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] >= 1:
            return False
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return True


if check(a[0],a[1]):
    hoge = True

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

Submission status: Wrong Answer

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

sum = 1

sum = sum * (x[0] == x[n-1] ^ x[1])
for i in range(1, (n-1 - 1 )):
    sum = sum * (x[i-1] ^ x[i+1])
sum = sum * (x[n-1] == x[0] ^ x[n-2])

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int, input().split()))
b=sorted(a)
result = True
for idx in range(len(b)-1):
    prev = b[idx-1]
    next = b[idx+1]
    diff = next^prev
    if diff != b[idx]:
        result = False
        break
if b[0]^b[len(b)-2] != b[len(b)-1]:
    result = False
str = "Yes" if result == True else "No"
print(str)

Submission status: Wrong Answer

Solution code:

import numpy as np 

def make_bit(A):
    arr = np.zeros(30)
    i = 29
    while A:
        arr[i] = A % 2
        A = A // 2
        i -= 1

    return arr

N = int(input())

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



if N == 3:
    a_lst.sort(reverse=True)

    a1 = make_bit(a_lst[0])
    a2 = make_bit(a_lst[1])
    a3 = make_bit(a_lst[2])
    bits_arr = np.array([a1, a2, a3])

    judge = True
    for i in range(30):
        if bits_arr[0][i] == bits_arr[1][i] and bits_arr[2][i] == 1:
            judge = False
            break

        elif bits_arr[0][i] != bits_arr[1][i] and bits_arr[2][i] == 0:
            judge = False
            break
            
    if judge:
        print("Yes")
    else:
        print("No")


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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
d = sorted(l.copy())

count = 0
i = 0
while len(d) != 0:
    if count == 0:
        a = 0
        count += 1
        for j in range(N-count):
            target = d[i] ^ d[j]
            if target in d :
                a += 1
                i = j
            if a == 1:
                break
        if a >= 1 :
            i2 = target
            mae =d[i]
            d.pop(i)
        else:
            print('No')
            break
    
    elif 1 <= count <= N-3:
        a = 0
        count += 1
        for j in range(N-count):
            if target == mae ^ d[j] :
                a += 1
                i = j
            if a == 1:
                break
        if a >= 1 :
            mae =d[i]
            d.pop(i)
        else:
            print('No')
            break
    
    elif count == N-2:
        a = 0
        count += 1
        if mae == target ^ l[0] :
            pass
        else:
            print('No')
            break    

    else:
        if l[0] == i2  ^   mae :
            print('Yes')
            break
        else:
            print('No')
            break

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 and min(cnts) == N // 3 and max(cnts) == N // 3:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
def binbin(a):
    return int(bin(a).split("b")[1])
arr=[A[-1]]
arr.extend(A)
arr.append(A[0])
ans=[]
for i in range(1,N+1):
    ans.append(int(binbin(arr[i])) == int("".join(list(map(lambda x:str(int(x)%2),str(binbin(arr[i-1])+binbin(arr[i+1])))))))

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