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 math

n = int(input())
inp = [int(x) for x in input().split()]
m = max(inp)
a = [format(x, '0' + str(len(str(format(m, 'b')))) + 'b') for x in inp]

def mk_pair(f):
    s11, s12 = '', ''
    s21, s22 = '', ''
    for c in f:
        cn = '1' if c == '0' else '0'
        s11 += c
        s12 += c if c == '0' else cn
        s21 += cn
        s22 += cn if c == '0' else c
    return (s11, s12), (s21, s22)

def axor(p1, p2):
    res = ''
    for c1, c2 in zip(p1, p2):
        res += '0' if c1 == c2 else '1'
    return res

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

    q1 = first
    q2 = first

    c1 = p1
    c2 = p2

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

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

Submission status: Wrong Answer

Solution code:
# 1.Nが三の倍数でない場合、全てが0でなければならない.(総排他的論理和が各数と等しくならねばならず、その中でa_(i-1)+a_(i+1)=a_iとなるのは0のみ)
# 2.Nが3の倍数の場合、a,b,a+bの三種類の数字で構成されていなければならず、かつそれであればよい。

N = int(input())
if(N%3 == 0):
    input_dict = {}
    for i in map(int, input().split()):
        if(i in input_dict):
            input_dict[i] += 1
        else:
           input_dict[i] = 1
    num_count = len(input_dict.keys())
    if(num_count > 3 ):
        print("No")
    elif(num_count == 2):
        if(0 in input_dict and input_dict[0] == N//3):
            print("Yes")
        else:
            print("No")
    elif(num_count == 1):
        if(0 in input_dict):
            print("Yes")
        else:
            print("No")
    else:
        input_list = list(input_dict.keys())
        if(input_list[0] ^ input_list[1] == input_list[2]):
            print("Yes")
        else:
            print("No")
else:
    for i in map(int, input().split()):
        if(i != 0):
            print("No")
            break
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
W = list(map(int, input().split()))
c = dict(collections.Counter(W))

if len(c.keys()) == 1:
  if c.get(0, False) == False:
    print('No')
  else:
    print('Yes')
if len(c.keys()) == 2:
  num = list(c.values())
  num = sorted(num)
  if num[0]*2 == num[1]:
    print("Yes")
  else:
    print("No")
if len(c.keys()) == 3:
  num = list(c.values())
  if num[0] == num[1]:
    if num[0] == num[2]:
      print("Yes")
  else:
    print("No")
if len(c.keys()) >= 4:
  if c.get(0, False) == False:
    print('No')
  else:
    x = c[0]
    del c[0]
    num = list(c.values())
    num = sorted(num)
    if num[0] == num[1]:
      if num[0] == (num[2]-x):
        print("Yes")
      else:
        print("No")
    else:
      print("No")

Submission status: Wrong Answer

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

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


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


if a_unique==[0]:
  print("Yes")

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

a = sorted(a)
flag = True
first = a.pop(0)
pp = first
p = a.pop(0)
for x in a:
    if x != p:
        if x ^ pp != p:
            flag = False
            break
        pp = p
        p = x
if first ^ pp != p:
    flag = False

if flag:
    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())

for k in range(3, N + 1):
    cnt = 0
    for p in itertools.permutations(a, k):
        for i in range(k):
            if i == 0:
                if p[k - 1] ^ p[i + 1] != p[i]:
                    if len(p) - 1 == cnt:
                        print("No")
                        exit()
                    break
            elif i == k - 1:
                if p[i - 1] ^ p[0] != p[i]:
                    if len(p) - 1 == cnt:
                        print("No")
                        exit()
                    break
                else:
                    a = (set(a) - set(p))
                    a.add(p[i - 1])
                    a.add(p[0])
                    if k == N:
                        print("Yes")
                        exit()
            else:
                if p[i - 1] ^ p[i + 1] != p[i]:
                    if len(p) - 1 == cnt:
                        print("No")
                        exit()
                    break
        cnt = cnt + 1

Submission status: Wrong Answer

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

a_set=list(set(a))
a_set.sort()

#コーナーケース　aが全部0なら必ずyes
if a_set==0:
    print("Yes")
    sys.exit(0)

#上記の場合を除き、nが３の倍数でないと成立しない
if n%3!=0:
    print("No")
    sys.exit(0)


if len(a_set)==2 and a_set[0]==0:
    if a.count(0)==int(n/3) and a.count(a_set[1])==int(n/3)*2:
        print("Yes")
    else:
        print("No")
elif len(a_set)==3:
    if a_set[0]^a_set[1]==a_set[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

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

a_unique = list(set(a))

if len(a_unique) > 3:
    result = False

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

elif len(a_unique) == 1:
    if a_unique[0]^a_unique[0] in a:
        pass
    else:
        result = False

else:
    if a_unique.count(a_unique[0]) == 1:
        if a_unique[0]^a_unique[1] == a_unique[1]:
            if a_unique[1]^a_unique[1] == a_unique[0]:
                pass
            else:
                result = False
    elif  a_unique.count(a_unique[1]) == 1:
        if a_unique[0]^a_unique[1] == a_unique[0]:
            if a_unique[0]^a_unique[0] == a_unique[1]:
                pass
            else:
                result = False
                
if result:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

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

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

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

    print('Yes')


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
con = []
for i in range(n):
  if i == 0:
    con.append(a[i] == a[-1] ^ a[i+1])
  elif i == n-1:
    con.append(a[i] == a[i-1] ^ a[0])
  else:
    con.append(a[i] == a[i-1] ^ a[i+1])
if all(con):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
R = lambda: map(int, input().split())

n = int(input())
if n % 3:
    ans = 'YNeos'[any(R())]
else:
    a = sorted(R())
    m = n // 3
    if a[0] ^ a[m] ^ a[2 * m]:
        ans = 'No'
    elif any(x != y for i, (x, y) in enumerate(zip(a, a[1:]), 1) if i % m):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Submission status: Wrong Answer

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

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

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

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

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

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

def main():

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

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

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

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

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

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


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

l = a[0]
m = -1
n = -1
o = -1

for i in range(1,N):
    if a[i] != l and m == -1:
        m = a[i]
    if a[i] != l and a[i] != m and m != -1:
        n = a[i]
    if a[i] != l and a[i] != m and m != -1 and a[i] != n and n != -1:
        o = a[i]
        break

if o != -1:
    print("No")
elif (a.count(l)==a.count(m) and a.count(m)==a.count(n) and a.count(l)+a.count(m)+a.count(n) == N):
    print("Yes")
elif n == -1 and ((a.count(l) == a.count(m)*2 and l^m == l and a.count(l)+a.count(m)==N)or(a.count(l)*2 == a.count(m) and l^m == m and a.count(l)+a.count(m)==N)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
hat_list = list(map(int, input().split()))
#print(hat_list)
b_list = []
for h in hat_list:
    #print(format(h,'b').zfill(10))
    b_list.append(format(h,'b').zfill(17))
#print(b_list)
for n in range(17):
    test_list = []
    for b in b_list:
        test_list.append(b[n])
    if test_list.count('1') > 0:
        if test_list.count('1') == test_list.count('0') * 2:
            print("Yes")
            break
else:
    print("No")

Submission status: Wrong Answer

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

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


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


if la%3==0 and a_unique==[0]:
  print("Yes")

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

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

Submission status: Wrong Answer

Solution code:
# A
N = int(input())
a = list(map(int, input().split()))
flag = True
if N % 3  != 0:
    if max(a) == 0:
        print('Yes')
    else:
        print('No')
else:
    if N == 3:
        if a[0] == a[1] ^ a[2] and a[1] == a[2] ^ a[0] and a[2] == a[0] ^ a[1]:
            print('Yes')
        else:
            print('No')
    else:
        n = int(N /3)
        a = sorted(a)
        for i in range(n):
            if a[3*i] * n == a[3*i] + a[3*i + 1] + a[3*i + 2]:
                pass
            else:
                flag = False
        if flag:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
import collections



def XORC(a,b,p):
    for i in range(len(a)):
        if (int(a[i])+int(b[i]))%2 == int(p[i]):
            continue
        else:
            return False
        
    return True
            
def Solve():
    N=int(input())
    AL=[("0"*34+bin(int(x))[2:])[-33:] for x in input().split()]

    ALC=collections.Counter(AL)

    keys=list(ALC.keys())
    vals=list(ALC.values())

    if len(keys)>3:
        return 'No'
    if len(keys)==1:
        if "1" in keys[0]:
            return 'No'
        return 'Yes'
    
    if len(keys)==2:
        if "1" in keys[0] and "1" in keys[1]:
            return 'No'
        
        if vals[0]==vals[1]*2 and ("1" not in keys[0]):
            stop
            return 'Yes'
        
        if vals[0]*2==vals[1] and ("1" not in keys[1]):
            stop
            return 'Yes'
        
        return 'No'
    if len(keys)==3:
        if vals[0]==vals[1]==vals[2]:
            if XORC(keys[0],keys[1],keys[2]) and XORC(keys[0],keys[2],keys[1]) and XORC(keys[1],keys[2],keys[0]):
                return 'Yes'
        
        return 'No'
print(Solve())

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a_txt = input().strip()
    a_list = [int(i) for i in a_txt.split()]
    if n % 3 != 0 or len(set(a_list)) != 3:
        print("No")
        return
    a_list.extend([a_list[0], a_list[-1]])
    for i in range(3):
        if a_list[i] != a_list[i - 1] ^ a_list[i + 1]:
            print("No")
            return
    expect = a_list[:3] * (n // 3)
    if " ".join(map(str, expect)) == a_txt:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0) + 1
    if N % 3:
        if A.get(0,0) == N:
            return 'Yes'
        else:
            return 'No'
    else:
        if A.get(0,0) == N:
            return 'Yes'
        elif len(A) == 3:
            if len(set(A.values())) == 1:
                return 'Yes'
            else:
                return 'No'
        else:
            return 'No'

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
a = list(map(int, input().split()))
 
x = 0
y = 0
z = 0
 
if N % 3 != 0:
  print('No')
 
else:
 
  for i in range(N):
    if a[i] != x and a[i] != y and a[i] != z:
      if x == 0:
        x = a[i]
        continue
      elif y == 0:
        y = a[i]
        continue
      elif z == 0:
        z = a[i]
        continue
      else:
        print('No')
        sys.exit()
  
  if x ^ y == z and a.count(x) == a.count(y) and a.count(y) == a.count(z):
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
firstnum = A[0]
lastnum = A[1]
pattern = True
UsedCap = []

for i in range(N):
    nextnum = firstnum ^ lastnum
    # print(nextnum,A)
    if nextnum in A:
        if i> 0:
            A.remove(lastnum)
        firstnum = lastnum
        lastnum = nextnum

    else:
        pattern = False
        break

# print(UsedCap)
if pattern == False:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
fl = input()
sl = input()
fnumofel = len(fl)
int(fnumofel)
fnumofel - 1
l = []
slist = sl.split(" ")
n = 0
for v in slist:
	n = int(n)
	#print(slist[n])
	bina = bin(int(slist[n]))
	str(bina)
	bina.replace("0b", "")
	#print(bina)
	str(bina)
	lastdigit = bina[:-1]
	l.append(lastdigit)
	n+=1
statlist = []
n = 0
for v in slist:
	int(n)
	if n == 0 or n == fnumofel:
		if n == 0:
			nextnum = l[1]
			prevnum = l[-1]
			currnum = l[0]
			if currnum == nextnum or currnum == prevnum:
				pass
			else:
				print("No")
				sys.exit()
		elif n == fnumofel:
			nextnum = l[0]
			prevnum = l[fnumofel]
			currnum = l[n]
			if currnum == nextnum or currnum == prevnum:
				pass
			else:
				print("No")
				sys.exit()
		else:
			nntmp = n + 1
			pntmp = n - 1
			nextnum = l[nntmp]
			prevnum = l[pntmp]
			currnum = l[n]
			if currnum == nextnum or currnum == prevnum:
				pass
			else:
				print("No")
				sys.exit()
		n+=1
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = dict(Counter(A))
val = list(c.values())

if len(c) > 3:
    print("No")
    exit(0)
if N%3 == 0 and len(c) == 3:
    a, b, c = list(c.keys())
    if a ^ b == c and b ^ c == a and c ^ a == b:
        print("Yes")
    else:
        print("No")
elif N%3 == 0 and len(c) == 2:
    a, b = list(c.keys())
    la, lb = list(c.values())
    if (a == 0 and la*2 == lb) or (b == 0 and lb*2 == la):
        print("Yes")
    else:
        print("No")
elif len(c)==1 and list(c.keys())[0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    array = list(map(int, input().split()))
    set_array = list(set(array))
    if len(set_array) != 3:
        return "No"
    for i in range(2):
        if array.count(set_array[i]) != array.count(set_array[i+1]):
            return "No"
    x = set_array[0]
    y = set_array[1]
    z = set_array[2]
    if x ^ y == z and y ^ z == x and x ^ z == y:
        return "Yes" 
    return "No"

print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(N-1):
    b = a[i-1] ^ a[i+1]
    if i == (N-1):
        i += 1
        if a[i] != b:
            count += 1
    elif a[i] != b:
        count += 1
if count == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import math

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
figure = list(map(int, input().split()))
p=0
for i in range(n-1):
  if(i==0):
    if(figure[n-1]^figure[i+1]==figure[i]):
      print("No")
      p+=1
      break
  else:
    if(figure[i-1]^figure[i+1]!=figure[i]):
      print("No")
      p+=1
      break
if(p==0):
  print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
res = False
if n % 3 == 0:
    res = l[0] ^ l[2] == l[1]
else:
    res = set(l) == {0}
print("Yes" if res else "No")

Submission status: Wrong Answer

Solution code:
import sys
import itertools

N = int(input())
A = input().split()

listA = list(itertools.combinations(A,N))

for i in range(N):
	for j in range(len(listA)//2):
		a = listA[j]
		x = int(a[(i-1)%N])
		y = int(a[(i+1)%N])
		print(a[i%N])
		print(x, y)
		print(x^y)

		if int(a[i%N]) == x^y:
			print('Yes')
			sys.exit(0);

print('No')

Submission status: Wrong Answer

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

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


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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    arr = read_h()

    cnts = {}
    for a in arr:
        cnts[a] = cnts.get(a, 0) + 1
    #  print(cnts)

    rem = sum(cnts.values())
    for i in range(n - 1):
        a = arr[i]
        if cnts[a] <= 0:
            continue

        cnts[a] -= 1
        rem -= 1
        tmp_rem = rem
        for j in range(i + 1, n):
            b = arr[j]
            if cnts[b] <= 0:
                continue

            xor = a ^ b
            if xor not in cnts or cnts[xor] <= 0:
                continue

            cnts[b] -= 1
            cnts[xor] -= 1
            rem -= 2
            break

        if tmp_rem == rem:
            print('No')
            return

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import exit
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = list(map(int, input().split()))

def noexit():
    print('No')
    exit()

def yesexit():
    print('Yes')
    exit()

setA = set(A)
if len(setA) > 3: noexit()

if N%3 != 0: noexit()

if 0 in setA:
    if len(setA) == 1: yesexit()
    elif len(setA) == 2: yesexit()
    else: noexit()

listA = list(setA)
if len(setA) != 3: noexit()
if listA[0]^listA[1]==listA[2] \
        and listA[1]^listA[2]==listA[0] \
        and listA[2]^listA[0]==listA[1]:
    new_list = [listA[0]]*(N//3) + [listA[1]]*(N//3) + [listA[2]]*(N//3)
    A.sort()
    new_list.sort()
    if A == new_list:
        yesexit()
    else:
        noexit()
else: noexit()

Submission status: Wrong Answer

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

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

for num in nums:
    if start ^ num in nums:
        next = num
        first = start
        
if next == None:
    print("No")
else:
    while len(nums) > 1:
        next2 = start ^ next
        if next2 in nums:
            nums = [e for e in nums if e != start and e != next]
            start = next
            next = next2
        else:
            print("No")
            break

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

Submission status: Wrong Answer

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

if 0 in a:
    if len(set(a))<=2:
        print("Yes")
    else:
        print("No")

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

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

        else:
            a = list(set(a))
            a = sorted(a)

            if a[1]-a[0] == a[2]-a[1]:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
import collections

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

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

for  i in range(len(a)-1):
    for j in range(i+1,len(a)):
        if check(a[i],a[j]):
            hoge = True
            break
        else:
            break
    else:
        continue
    break

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

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	if N != 3:
		print("No")
		return

	val_set = set()
	for a in A:
		val_set.add(a)

	possible = True
	for i in range(1, N+1):
		if i not in val_set:
			possible = False
			break
	if possible:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools

N = int(input())
A = input().split()

listA = list(itertools.combinations(A,N))

for i in range(N):
	for j in range(len(listA)):
		a = listA[j]
		x = int(a[(i-1)%N])
		y = int(a[(i+1)%N])
		print(a[i%N])
		print(x, y)
		print(x^y)

		if int(a[i%N]) == x^y:
			print('Yes')
			sys.exit(0);

print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
shurui={}
a=list(map(int,input().split()))
result=False
for i in range(N):
  if a[i] in shurui:
    shurui[a[i]]+=1
  else:
    shurui[a[i]]=1
kagi=list(shurui.keys())
atai=list(shurui.values())

if len(shurui)==1:
  if kagi[0]^kagi[0]==kagi[0]:
    result=True
elif len(shurui)==2:
  if atai[0]*2==atai[1]:
    if kagi[0]^kagi[1]==kagi[0]:
      result=True
  elif atai[1]*2==atai[0]:
    if kagi[0]^kagi[1]==kagi[1]:
      result=True
elif len(shurui)==3:
  if atai[0]==atai[1]==atai[2]:
    if kagi[0]^kagi[1]==kagi[2]:
      result=True
if result==True:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
ite = 0
for i in range(N):
    if a[i] != 0:
        break
    else:
        ite += 1
if ite == N - 1:
    print("Yes")
    exit()

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

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

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