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:
# -*- 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("Yes")
			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()

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 = {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:
a = int(input())
b = list(map(int, input().split()))
c = {}

for i in range(a):
    if b[i] not in c:
        c.setdefault(b[i], 1)
    else:
        c[b[i]] += 1

if len(c) == 3:
    f = list(c.values())
    for i in range(1, len(f)):
        if f[i] != f[i-1]:
            print("No")
            exit()
    g = list(c.keys())
    if g[0] ^ g[1] == g[2]:
        print("Yes")
    else:
        print("No")
elif len(c) == 2:
    f = list(c.values())
    g = list(c.keys())
    if f[0] == f[1] * 2 and g[0] == 0:
        print("Yes")
    elif f[0] * 2 == f[1] and g[1] == 0:
        print("Yes")
    else:
        print("No")
elif len(c) == 1:
    print("Yes")
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 and len(a_list)%3==0:
                    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:
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")
        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:
            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==2:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[0])==n//3+1:
                print("Yes")
            else:
                print("No")
        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")
        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)):
        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:
n = input()
a = list(map(int, input().split()))

a.sort
res = []
for n in range(len(a)):
  if(n == (len(a) - 1)):
    res.append(a[n - 1]^a[0])
  else:
    res.append(a[n - 1]^a[n + 1])

mes = "Yes"
for i, j in enumerate(res):
  if(a[i] != j):
    mes = ("No")
print(mes)

Submission status: Wrong Answer

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

if len(set(a)) == 1 and a[0] == 0:
    print('Yes')
elif N % 3 == 0:
    if len(set(a)) == 3:
        c = []
        for i in list(set(a)):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3:
            print('Yes')
        else:
            print('No')
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
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: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 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:
    if 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")
    else:
        print("No")
elif L == 3:
    if (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")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a.sort()
    count = 0


    for i in range(N):
        
        if i == N-1:
            if a[i-1] ^ a[0] != a[i]:
                count += 1
        else:
            if a[i-1] ^ a[i+1] != a[i]:
                count += 1

    if count == 0:
        print("Yes")
    else:
        print("No")    


if __name__ == "__main__":
    main()

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] == 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:
a=int(input())
b= list(map(int, input().split()))
b.sort()
b.append(b[0])
b.append(b[1])
d=0

for i in range(a):
    c= int(b[i]^b[i+2])
    if c!=b[i+1]:
        d += 1
        break

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

Submission status: Wrong Answer

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

def ronriwa(a,b):
  global ab2
  global sa
  a2 = list(str(bin(a)))[2:]
  b2 = list(str(bin(b)))[2:]
  len_a = len(a2)
  len_b = len(b2)
  if len_a >= len_b:
    sa = len_a - len_b
    ab2=a2[:sa]
    for i in range(len_b):
      if all([a2[sa+i]=="0",b2[i]=="0"]):
        ab2.append("0")
      elif all([a2[sa+i]=="0",b2[i]=="1"]):
        ab2.append("1")
      elif all([a2[sa+i]=="1",b2[i]=="0"]):
        ab2.append("1")
      else:
            ab2.append("0")
  elif len_a < len_b:
        
    sa = len_b - len_a
    ab2=b2[:sa]
    
    for i in range(len_a):
      if all([a2[i]=="0",b2[sa+i]=="0"]):
        ab2.append("0")
      elif all([a2[i]=="0",b2[sa+i]=="1"]):
        ab2.append("1")
      elif all([a2[i]=="1",b2[sa+i]=="0"]):
        ab2.append("1")
      else:
            ab2.append("0")
   
  ab10 = ""
  for i in ab2:
    ab10+=str(i)
     
  return int(ab10,2)

t_f = []

for i in range(0,N):
  if i ==0:
    tf = ronriwa(a[N-1],a[1])
    t_f.append(a[i] == tf)
  elif i == N-1:
    tf = ronriwa(a[N-2],a[0])
    t_f.append(a[i] == tf)
  else:
    tf = ronriwa(a[i-1],a[i+1])
    t_f.append(a[i] == tf)
if all(t_f):
  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])
                break
        elif c[1] ^ c[2] == c[0]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[0])
                break
        elif c[0] ^ c[1] == c[2]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[2])
                break
    print("No")
    exit()

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:
  x=random.randint(1,2)
  if x%2==0:
    print('No')
  else:
    print('Yes')
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:
    print('No')

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:
    print('No')
  elif D[0][1]>=2:
    print('No')
  elif n%3!=0:
    print('No')
  else:
    x=random.randint(1,2)
    if x%2==0:
      print('No')
    else:
      print('Yes')
elif f==1:
  if len(D)==1:
    print('Yes')
  elif len(D)==2 and D[0][0]!=0 and D[0][1]==D[1][1]*2:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
Rakuda_data =  input().split(' ')
flag = 0

for n in range(0, N-1):
    for i in range(0, N-1):
        for j in range(0, N-1):
            Flontstr = int(Rakuda_data[n])
            binstr = int(Rakuda_data[i])
            Afterstr = int(Rakuda_data[j])
            # XOR回路
            if bin(Flontstr ^ Afterstr) == bin(binstr):
                flag=1

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

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

if all(ans):
    if any(ans)==True:
        print("Yes")
    else:
        print("No")
else:
    if any(ans)==False:
        print("No")
    else:
        print("No")

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 = 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 == N and a == b):
                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:
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 mk_multiset(a):
    ms = dict()
    for e in a:
        if e in ms:
            ms[e] += 1
        else:
            ms[e] = 1
    return ms

def check(a, p, first):
    # print('check', p)
    sa = mk_multiset(a)
    sa[first] -= 1
    if sa[first] == 0:
        sa.pop(first)
    p1, p2 = p

    q1 = first
    q2 = first

    c1 = p1
    c2 = p2

    rest = len(a) - 1

    # print(sa)
    n1 = axor(q1, c1)
    n2 = axor(q2, c2)
    if (c1 in sa and c2 in sa):
        rest -= 2
        if (rest == 0):
            return c1 == n2 and c2 == n1

        sa[c1] -= 1
        if sa[c1] == 0:
            sa.pop(c1)

        if (not c2 in sa):
            return False
        sa[c2] -= 1
        if sa[c2] == 0:
            sa.pop(c2)
    else:
        return False


    while True:
        n1 = axor(q1, c1)
        n2 = axor(q2, c2)
        # print(sa)
        # print(q1, c1, '->', n1)
        # print(q2, c2, '->', n2)
        if (n1 == n2 and n1 in sa and rest == 1):
            if (sa[n1] < 0):
                return False
            return c2 == axor(c1, n1)
        if (n1 in sa and n2 in sa):
            rest -= 2
            if (rest == 0):
                return n1 == c2 and n2 == c1

            sa[n1] -= 1
            if sa[n1] == 0:
                sa.pop(n1)

            if (not n2 in sa):
                return False
            sa[n2] -= 1
            if sa[n2] == 0:
                sa.pop(n2)

            q1 = c1
            q2 = c2
            c1 = n1
            c2 = n2
        else:
            return False

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

Submission status: Wrong Answer

Solution code:
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
    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if v[i] ^ v[j] == v[k]:
                    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:
import collections

N = int(input())

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

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

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

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

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[N - 1] != a[0] ^ a[N - 2]:
        print("No")
        return
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}

for i in range(a):
    if b[i] not in c:
        c.setdefault(b[i], 1)
    else:
        c[b[i]] += 1

if len(c) == 3:
    f = list(c.values())
    for i in range(1, len(f)):
        if f[i] != f[i-1]:
            print("No")
            exit()
    g = list(c.keys())
    if g[0] ^ g[1] == g[2]:
        print("Yes")
    else:
        print("No")
elif len(c) == 2:
    f = list(c.values())
    if f[0] != f[1]*2 and f[0]*2 != f[1]:
        print("No")
        exit()
    g = list(c.keys())
    if g[0] == 0 or g[1] == 0:
        print("Yes")
    else:
        print("No")
elif len(c) == 1:
    print("Yes")
else:
    print("No")
    exit()

Submission status: Wrong Answer

Solution code:
def equal_list(lst1, lst2):
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            break
    else:
        if not lst:
            return True
    return False


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

if a == [0]*N:
    print("Yes")
    exit()

if N % 3 == 0:
    n = N // 3
    sets = list(set(a))
    order = max(a).bit_length()
    if len(sets) == 3:
        for s in sets:
            if a.count(s) != n:
                print("No")
                exit()

        for i in range(order):
            b = [sets[0] >> i & 1, sets[1] >> i & 1, sets[2] >> i & 1]
            if b == [0, 0, 0]:
                continue
            if not equal_list(b, [0, 1, 1]):
                print("No")
                exit()
    elif len(sets) == 2:
        for s in sets:
            if a.count(s) != n:
                print("No")
                exit()

        if a.count(sets[0]) == n:
            for i in range(order):
                b = [sets[0] >> i & 1, sets[1] >> i & 1]
                if b == [0, 0]:
                    continue
                if b != [0, 1]:
                    print("No")
                    exit()
        elif a.count(sets[1]) == n:
            for i in range(order):
                b = [sets[0] >> i & 1, sets[1] >> i & 1]
                if b == [0, 0]:
                    continue
                if b != [1, 0]:
                    print("No")
                    exit()
    else:
        print("No")
        exit()

    print("Yes")

else:
    print("No")
    exit()

Submission status: Wrong Answer

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

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

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

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

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

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

def main():

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

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

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

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

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

	bk = -1
	next1 = -1
	for i, val in enumerate(A):
		#A[i] = -1
		if i == 0:
			tmp = a_max - val
			if tmp in A:
				bk = val
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
		if i == N-1:
			if next1 == a_max and bk ^ A[0] == a_max:
				print("Yes")
				sys.exit()
		
		if next1 == a_max:
			tmp = next1 - bk
			if tmp in A:
				bk = 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("No")


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
if(A.count(0) != 0):
    if(N % 2 == 0):
        a = -1
        b = -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 == N and a == b):
                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:
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])))))))

if all(ans):
    if any(ans)==True:
        print("Yes")
else:
    if any(ans)==False:
        print("No")

Submission status: Wrong Answer

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

print('No')

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:
        ans = _solve(first, second, max_bit_len_ints, other_ints)
        if ans:
            return True
    return False


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())
l = list(map(int,input().split()))
j = 0
u = []
v = [0]*4
for i in l:
    if not i in u :
        u.append(i)
    v[u.index(i)] += 1
    if len(u) > 3:
        break
#print(u,v)
if len(u) == 3:
    if ((n%3 == 0) and (u[0] ^ u[2] == u[1]) and (v[0] == v[1] and v[1] == v[2]) and not len(u) > 3 and not 0 in u):
        j = 1
elif len(u) == 2:
    if 0 in u:
        if u[0] == 0 :
            b = u[1]
        else :
            b = u[0]
        if v[u.index(0)] * 2 == v[u.index(b)]:
            j = 1
if j == 1 :
    print("Yes")
else :
    print("No")

#print(l[0] ^ l[2] == l[1],n == 3)
"""01
10
11
01
10
11

01
00
01
01
00
01
"""