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: Runtime Error

Solution code:
import copy
a=int(input())
b=(list(map(int, input().split())))
bb = copy.copy(b)
c=0
d=[]
n=0
f=b[0]
d.append(f)
b.pop(0)

def kakunin(bb,d):
  while c==0:
    cc=0
    for i in range(len(bb)):
      if d[len(d)-2]==d[len(d)-1]^bb[i]:
        g=bb[i]
        d.append(g)
        bb.pop(i)
        cc=1
        if len(d)==a and d[0]==d[len(d)-2]^d[len(d)-1]:
          global ccc
          ccc=1
          return
    if cc==0:
      ccc=0
      return
      
while c==0:
  n+=1    
  bb = copy.copy(b)
  f=b[0]
  d.append(f)
  b.pop(0)
  bb.pop(0)
  kakunin(bb,d)
  b.append(f)
  if ccc==1:
    print("Yes")
    break
  else:
    d=[f]
  if n>=a:
    print("No")
    break

Submission status: Runtime Error

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

eachbit=[0]*30
for i in range(N):
    bin_str = format(A[i],'030b')
#    print(bin_str)
    for j in range(31):
        if bin_str[-j] == '1':
            eachbit[j] += 1

even = True
for e in eachbit:
    if e % 2 != 0:
        even = False

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

flag = 0
for i in range(n):
    if((i+1) >= n):
        l = 0
    else:
        l = i + 1
        
    if((i-1) < 0):
        r = n - 1
    else:
        r = i - 1
    
    if(a[i] != int(bin(a[r] ^ a[l] ,2)):
        flag = 1
        break
        
if(flag == 0):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

a0 = A[0]
c = A[1]
b = a0 ^ a1

f = True

for i in range(3, N):
    if i % 3 == 0 and a != A[i]:
        f = False
    elif i % 3 == 1 and b != A[i]:
        f = False
    elif i % 3 == 2 and c != A[i]:
        f = False

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int,input().split()))
P = L[:]
var = 0


for i1 in range(N):
  for i2 in range(N):
    if L[i1]^L[i2] == L[var]:
      P = P.remove(P[var])
      var = i2
  continue
if P is None:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

flag = 0
even = []
odd = []
for i in a:
    if i%2 == 0:
        even.append(i)
    else:
        odd.append(i) 

if n%2 == 1:
    if len(odd) >= 1:
        flag = 1
    else:
        for i in range(n):
            count = 0
            for j in range(i, n):
                aa = a[i]^a[j]
                if aa in a:
                    count += 1
                if count < 2:
                    flag = 1
                    break
            else:
                continue
            break

else:
    if len(odd)/2 != len(even):
        flag = 1
        for i in range(n):
            count = 0
            for j in range(i, n):
                aa = a[i]^a[j]
            if aa in a:
                count += 1
            if count < 2:
                flag = 1
                break
        else:
            continue
        break

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

an = np.array(A, dtype=np.int64)

for i in range(1,N):
   for j in range(i+1,N):
      if(an[0] == an[i]^an[j]):
         tmp = an[1]
         an[1] = an[i]
         an[i] = tmp

         tmp = an[2]
         an[2] = an[j]
         an[j] = tmp

         doo = 1
         break
      else:
         doo = 0

if(doo == 0):
   print('No')
   break

for i in range(2,N):
   for j in range(i+1,N):
      if(an[i-1] == an[i]^an[j]):
         tmp = an[i+1]
         an[i+1] = an[j]
         an[j] = tmp
         doo=1
         break
      else:
         doo=0

   if(doo==0):
      print('No')
      break


if(an[0] == an[1]^an[N-1]):
   doo=1
else:
   doo=0

if(doo==1):
   print('Yes')

Submission status: Runtime Error

Solution code:
def sumNum2(num1,num2):
  num3=[0]*14
  count =14
  for i in range(14):
    if num1[i] == num2[i]:
      num3[i]=0
    else:
      num3[i]=1
  return num3

def loopCheck(start,before,now,remaining):
  if len(remaining) ==1:
      num2 = sumNum2(start,before)
      if now == num2:
        return True
      else:
        return False
  else:
    for i in range(len(remaining)):
      if before == -1:
        for j in range(len(remaining)):
          if j > i:
            num2 = sumNum2(remaining[i],remaining[j])
            if now == num2:
              if len(remaining) ==2:
                return True
              else:
                remaining2 = remaining
                remaining2.remove(remaining[i])
                loopCheck(start,now,remaining[i],remaining2)
          if i == remaining[-1]:
            if start == now:
              return False
      
      else:
        num2 = sumNum2(remaining[i],before)
        if now == num2:
          remaining2 = remaining
          remaining2.remove(remaining[i])
          loopCheck(start,now,remaining[i],remaining2)

def convert(number):
  num2=[0]*14
  count =14
  for i in range(15):
    count2 = count - i
    checknum = 2 ** count2
    if number >= checknum:
      num2[count2] = 1
      number = number -checknum
  return num2



if __name__ == '__main__':
  n = int(input())
  a = [int(i) for i in input().split()] 
  num2List = []
  for i in range(n):
    num2 = convert(a[i])
    num2List.append(num2)
  now = num2List[0]
  num2List.remove(num2List[0])
  if loopCheck(now,-1,now,num2List):
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
N=int(input())
an=map(int,input().split())
list_an=list(an)
for i in range(len(list_an)):
    if bin((list_an[i])^(list_an[i+2]))==bin(list_an[i+1]):
        print ('Yes')
    else:
        print('No')
    for j in range(0,len(list_an)):
        D=deque(list_an)
        D.rotate(j)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
aa=set(a)
if len(aa)>3:
    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 len(l)!=3:
    print("No")
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: Runtime Error

Solution code:
N = int(input())
a = [int(i) for i in input().split(' ')]
numbers = []
numbers.append(a[0])
for i in a:
    if i != numbers[0] and len(numbers) == 1:
        numbers.append(i)
    if i != numbers[0] and i != numbers[1]:
        numbers.append(i)
        break

if len(numbers) == 3:
    if a.count(numbers[0]) != a.count(numbers[1]):
        print('No')
        exit(0)
    if a.count(numbers[0]) != a.count(numbers[2]):
        print('No')
        exit(0)
    if len(a) != a.count(numbers[0])+a.count(numbers[1])+a.count(numbers[2]):
        print('No')
        exit(0)

    if numbers[0]^numbers[1] == numbers[2]:
        print('Yes')
        exit(0)
    elif numbers[0]^numbers[2] == numbers[1]:
        print('Yes')
        exit(0)
    elif numbers[1]^numbers[2] == numbers[0]:
        print('Yes')
        exit(0)
    else:
        print('No')
else:
    if len(a) != a.count(numbers[0])+a.count(numbers[1]):
        print('No')
        exit(0)
    if numbers[0] == 0 or numbers[1] == 0:
        if numbers[0] == 0:
            if a.count(numbers[1]) != 2*a.count(numbers[0]):
                print('No')
                exit(0)
        elif a.count(numbers[0]) != 2*a.count(numbers[1]):
            print('No')
            exit(0)
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)

Submission status: Runtime Error

Solution code:
def sumNum2(num1,num2):
  num3=[0]*14
  count =14
  for i in range(14):
    if num1[i] == num2[i]:
      num3[i]=0
    else:
      num3[i]=1
  return num3

def loopCheck(start,before,now,remaining):
  if len(remaining) ==1:
      print('test1')
      num2 = sumNum2(start,before)
      if now == num2:
        return True
      else:
        return False
  else:
    for i in range(len(remaining)):
      if before == -1:
        for j in range(len(remaining)):
          if j > i:
            num2 = sumNum2(remaining[i],remaining[j])
            if now == num2:
              if len(remaining) ==2:
                return True
              else:
                remaining2 = remaining
                remaining2.remove(remaining[i])
                loopCheck(start,now,remaining[i],remaining2)
          if i == remaining[-1]:
            if start == now:
              return False
      
      else:
        num2 = sumNum2(remaining[i],before)
        if now == num2:
          remaining2 = remaining
          remaining2.remove(remaining[i])
          loopCheck(start,now,remaining[i],remaining2)

def convert(number):
  num2=[0]*14
  count =14
  for i in range(15):
    count2 = count - i
    checknum = 2 ** count2
    if number >= checknum:
      num2[count2] = 1
      number = number -checknum
  return num2



if __name__ == '__main__':
  n = int(input())
  a = [int(i) for i in input().split()] 
  num2List = []
  for i in range(n):
    num2 = convert(a[i])
    num2List.append(num2)
  now = num2List[0]
  num2List.remove(num2List[0])
  if loopCheck(now,-1,now,num2List):
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
n = input()
dic = {}
for i in map(int, raw_input().split()):
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
if len(dic) > 3:
	print "No"
elif len(dic) == 3:
	vals = []
	for i in dic:
		vals.append(i)
	if vals[0]^vals[2] != vals[1] or vals[1]^vals[0] != vals[2] or vals[0] != vals[1]^vals[2]:
		print "No"
	elif max(dic.values()) - min(dic.values()) > 1:
		print "No"
	else:
		print "Yes"
elif len(dic) == 2:
	assert(1 > 2)
	if 0 in dic and n%2 and dic[0] == n/2:
		print "Yes"
	else:
		print "No"
else:
	if 0 in dic.keys():
		print "Yes"
	else:
		print "No"

Submission status: Runtime Error

Solution code:
n = int(input())
num_dict = {}
for num in map(int, input().split()):
  if not num in list(num_dict.keys()):
    num_dict[num] = 0
  num_dict[num] += 1
dk = list(num_dict.keys())
l = dk[0]
r = dk[1]
num_dict[r] -= 1
sum_ = l ^ r
i = 1

while i < n:
  if sum_ in dk:
    l, r = r, sum_
    sum_ = l ^ r
    if num_dict[r] == 0:
      print("No")
      exit()
    else:
      num_dict[r] -= 1
    i += 1
  else:
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

Solution code:
def sumNum2(num1,num2):
  num3=[0]*14
  count =14
  for i in range(14):
    if num1[i] == num2[i]:
      num3[i]=0
    else:
      num3[i]=1
  return num3

def loopCheck(start,before,now,remaining):
  if len(remaining) ==1:
      print('test1')
      num2 = sumNum2(start,before)
      if now == num2:
        return true
      else:
        return false
  else:
    for i in range(len(remaining)):
      if before == -1:
        for j in range(len(remaining)):
          if j > i:
            num2 = sumNum2(remaining[i],remaining[j])
            if now == num2:
              if len(remaining) ==2:
                return True
              else:
                remaining2 = remaining
                remaining2.remove(remaining[i])
                loopCheck(start,now,remaining[i],remaining2)
          if i == remaining[-1]:
            if start == now:
              return false
      
      else:
        num2 = sumNum2(remaining[i],before)
        if now == num2:
          remaining2 = remaining
          remaining2.remove(remaining[i])
          loopCheck(start,now,remaining[i],remaining2)

def convert(number):
  num2=[0]*14
  count =14
  for i in range(15):
    count2 = count - i
    checknum = 2 ** count2
    if number >= checknum:
      num2[count2] = 1
      number = number -checknum
  return num2



if __name__ == '__main__':
  n = int(input())
  a = [int(i) for i in input().split()] 
  num2List = []
  for i in range(n):
    num2 = convert(a[i])
    num2List.append(num2)
  now = num2List[0]
  num2List.remove(num2List[0])
  if loopCheck(now,-1,now,num2List):
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)
n = int(input())
li = list(map(int,input().split()))
a = li[0]
del li[0]

def f(num1,num2,l):
  if l == []:
    return True
  else:
    if num1^num2 in l:
      l.remove(num1^num2)
      return f(num2,num1^num2,l)
    else:
      return False

for i in li:
  if f(a,i,li[1:]):
    print("Yes")
    exit()
  else:continue
print("No")

Submission status: Runtime Error

Solution code:

import numpy as np

# %%
N = int(input())
a = list(map(lambda x: int(x), input().split(' ')))
# N = 3
# a = [1, 2, 3]


mat = np.zeros([len(a), len(a)])
mat[:, :] = np.nan

for i in range(len(a)):
    for j in range(i+1, len(a)):
        mat[i, j] = a[i] ^ a[j]

flg = True
for _a in a:
    if np.sum(mat == _a).sum() == 0:
        print('No')
        flg = False
        break

if flg:
    print('Yes')

Submission status: Runtime Error

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

flag = 0
even = []
odd = []
for i in a:
    if i%2 == 0:
        even.append(i)
    else:
        odd.append(i) 

if n%2 == 1:
    if len(odd) >= 1:
        flag = 1
    else:
        for i in range(n):
            count = 0
            for j in range(i, n):
                aa = a[i]^a[j]
            if aa in a:
                count += 1
        if count < 2:
            flag = 1
            break

else:
    if len(odd)/2 != len(even):
        flag = 1
        for i in range(n):
            count = 0
            for j in range(i, n):
                aa = a[i]^a[j]
            if aa in a:
                count += 1
        if count < 2:
            flag = 1
            break

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

Submission status: Runtime Error

Solution code:
n = input()
a = list(map(int, input().split()))
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])
rev = []
rev.append(res[0])
hoge = res[1:]
hoge.reverse()
rev.extend(hoge)

mes = "Yes"
for i, j in enumerate(res):
  if(i+1 != j):
    mes = ("No")
mes1 = "Yes"
for i, j in enumerate(rev):
  if(i+1 != j):
    mes1 = ("No")
if(mes == "Yes" || mes1 == "Yes"):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
j = 0
u = []
v = [0]*3
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
"""

Submission status: Runtime Error

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))
    if len(sets) != 3:
        print("No")
        exit()

    for s in sets:
        if a.count(s) != n:
            print("No")
            exit()

    order = max(a).bit_length()

    for i in range(order):
        b = [sets[0] >> i & 1, sets[1] >> i & 1, sets[2] >> i & 1]
        if not equal_list(b, [0, 1, 1]):
            print("No")
            exit()

    print("Yes")

else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
data = {}
bits = 0
bit_table = [set() for _ in range(31)]
for a in map(int, input().split()):
	bits |= a
	if a in data:
		data[a] += 1
	else:
		data[a] = 1
	i = 0
	while a:
		if a % 2 == 1:
			bit_table[i].add(a)
		a //= 2
		i += 1

def pop(data, a):
	if a in data:
		if data[a] == 1:
			del data[a]
		else:
			data[a] -= 1
		return a
	else:
		return None

def check2(data0, a1, a2):
	if (a1 | a2) != bits:
		return False
	
	data = { k: data0[k] for k in data0 }
	a0 = a1
	pop(data, a1)
	pop(data, a2)
	
	while data:
		a3 = a1 ^ a2
		a4 = pop(data, a3)
		if a4 == None:
			return False
		a1 = a2
		a2 = a3
	return a0 == (a1 ^ a2)

def check(data):
	keys = data.keys()
	for a1 in keys:
		b = bits & (~a1)
		cands = None
		i = 0
		while b:
			if b % 2 == 1:
				if cands == None:
					cands = bit_table[i]
				else:
					cands &= bit_table[i]
			b //= 2
			i += 1
		
		for a2 in cands:
			if a1 != a2 or data[a1] > 1:
				if check2(data, a1, a2):
					return True
	return False

if check(data):
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

Solution code:
from operator import xor
from functools import reduce
import sys

def answer(result):
    print(*result)

def search(this, hats, result):
    if len(hats) == 1:
        # print('saigo!')
        if this ^ hats[0] == result[0]:
            result.append(hats[0])
            answer(result)
            sys.exit()
        else:
            return

    for i in range(len(hats)):
        if this ^ hats[i] in hats:
            copy_hats = hats[:]
            copy_result = result[:]
            copy_result.append(copy_hats.pop(i))
            # print('next!', copy_result)
            search(copy_result[-1], copy_hats, copy_result)
        else:
            # print('dame')
            return


n = input()
hats = list(map(int, input().split(' ')))
result = []

if reduce(xor, hats) == 0:
    result.append(hats.pop(0))
    # print(result)
    search(result[0], hats, result)
    print('No')
else:
    print('No')

Submission status: Runtime Error

Solution code:

N = int(input())

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

def xor(x1,x2):
    xdigit = math.ceil(math.log2(max(x1+1, x2+1)))
    num = 0
    
    #print(x1, x2)
    
    for i in range(xdigit):
        num_digit = 2**(xdigit-i-1)
        dig_x1 = x1 // num_digit
        dig_x2 = x2 // num_digit
        
        #print("x", dig_x1, dig_x2)
        
        if dig_x1 != dig_x2:
            num += num_digit
            
        if dig_x1 == 1:
            x1 -= num_digit
            
        if dig_x2 == 1:
            x2 -= num_digit
    return num

is_exist = True

for camel in range(N):
    if camel == N-1:
        furt = 0
    else:
        furt = camel + 1
        
    if camel == 0:
        prev = N-1
    else:
        prev = camel -1
         
    num_xor = xor(nums[prev], nums[furt])
    
    #print(num_xor)
    
    #print(camel, num_xor, nums[camel])
    
    if num_xor != nums[camel]:
        is_exist = False
        break


if is_exist == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
data = {}
bits = 0
bit_table = [set() for _ in range(31)]
for a in map(int, input().split()):
	bits |= a
	if a in data:
		data[a] += 1
	else:
		data[a] = 1
	i = 0
	while a:
		if a % 2 == 1:
			bit_table[i].add(a)
		a //= 2
		i += 1

def pop(data, a):
	if a in data:
		if data[a] == 1:
			del data[a]
		else:
			data[a] -= 1
		return a
	else:
		return None

def check2(data0, a1, a2):
	if (a1 | a2) != bits:
		return False
	
	data = { k: data0[k] for k in data0 }
	a0 = a1
	pop(data, a1)
	pop(data, a2)
	
	while data:
		a3 = a1 ^ a2
		a4 = pop(data, a3)
		if a4 == None:
			return False
		a1 = a2
		a2 = a3
	return a0 == (a1 ^ a2)

def check(data):
	keys = data.keys()
	for a1 in keys:
		b = bits & (~a)
		cands = None
		i = 0
		while b:
			if b % 2 == 1:
				if cands == None:
					cands = bit_table[i]
				else:
					cands &= bit_table[i]
			b //= 2
			i += 1
		
		for a2 in cands:
			if a1 != a2 or data[a1] > 1:
				if check2(data, a1, a2):
					return True
	return False

if check(data):
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

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

flag = 0
for i in range(n):
    if((i+1) >= n):
        l = 0
    else:
        l = i + 1
        
    if((i-1) < 0):
        r = n - 1
    else:
        r = i - 1
    
    # print(str(i)+" :"+str(l)+","+str(r))
    if(bin(a[i]) != bin(a[r]) ^ bin(a[l])):
        flag = 1
        break
        
if(flag == 0):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
l3 = list(map(int,input().split()))
l = set(l3)
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:
    if l3.count(l[0])>l3.count(l[1]):
      if l[0]==l[0]^l[1] and l[1]==l[0]^l[0]:
          print("Yes")
      else:
          print("No")
    elif l3.count(l[1])>l3.count(l[0]):
      if l[1]==l[1]^l[0] and l[0]==l[1]^l[1]:
          print("Yes")
      else:
          print("No")
          
    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: Runtime Error

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

Submission status: Runtime Error

Solution code:
# 条件に合う帽子が複数ある場合を考慮する
def cehck_hats(hat_1, hat_2, hats):
    # hats の中身が空っぽ -> 全てのラクダに乗せた場合、最初のラクダチェックをして結果を見る
    if len(hats) == 0:
        if hat_2 ^ rakuda_2 == rakuda_1:
            print('Yes')
            sys.exit()
        else:
            return None

    # まだ全部置いてない
    for hi in range(0, len(hats)):
        hat_3 = hats[hi]
        if hat_1 ^ hat_3 == hat_2: # 条件を満たすハットが見つかれば
            if hi == len(hats) - 1:
                cehck_hats(hat_2, hat_3, hats[1:hi])
            else:
                cehck_hats(hat_2, hat_3, hats[1:hi] + hats[hi + 1:])

n = int(input())
rakuda = [0]*n
hats = list(map(int, input().split()))

# 最初の一頭へ、aiのハットをかぶせる
rakuda_1 = hats[0]

# # 次のラクダへ、何かを乗せる
for hi in range(1, n):
    rakuda_2 = hats[hi]
    
    if hi == n - 1:
        cehck_hats(rakuda_1, rakuda_2, hats[1:hi])
    else:
        cehck_hats(rakuda_1, rakuda_2, hats[1:hi] + hats[hi + 1:])
    
# どの組み合わせもダメだった場合
print('No')
sys.exit()

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
numList = []
numList = list(map(int,input().split()))

result = 'No'
flag = True
count = 0

for wList in itertools.permutations(numList, n):
  print(wList)
  for v in itertools.permutations(wList, 3):
    xor = int(v[0]) ^ int(v[2])
    if xor != v[1]:
      flag = False
      break
      
    if flag:
      count +=1
      break
      
    flag = True
    
if count > 0:
  result = 'Yes'

print(result)

Submission status: Runtime Error

Solution code:
def is_circle(current_list, rest_list):
    if rest_list == []:
        if (current_list[-1] ^ current_list[0]) == current_list[1]:
            return True
        else:
            return False
    if len(current_list) == 1:
        for index, num in enumerate(rest_list):
            if is_circle(current_list + [num], rest_list[:index] + rest_list[index+1:]):
                return True
            """
            next_int = current_list[0] ^ num
            if next_int in rest_list:
                if is_circle(current_list + [num], rest_list[:index] + rest_list[index+1:]):
                    return True
            """
        return False

    next_int = current_list[-1] ^ current_list[-2]
    if next_int in rest_list:
        current_list.append(next_int)
        rest_list.remove(next_int)
        return is_circle(current_list, rest_list)
    else:
        return False
        

n = int(input())
input_list = [int(i) for i in input().split(' ')]

if is_circle([input_list[0]], input_list[1:]):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

ans = True
if N % 3 != 0:
    for i in range(N):
        if a[i] != 0:   
            ans = False
else:
    first = a[0]
    i_second = -1
    for i in range(1, N):
        if a[i] != first:
            second = a[i]
            i_second = i
            break
        
    if i_second == -1:
        for i in range(N):
            if a[i] != 0:
                ans = False
    else:
        for i in range(i_second+1, N):
            if (a[i] != first) and (a[i] != second):
                third = a[i]
                break
        if (first ^ second != third) or (second ^ third != first) or (third ^ first != second):
            ans = False
        else:
            cnt_first = 0
            cnt_second = 0
            cnt_third = 0
            for i in range(N):
                if a[i] == first:
                    cnt_first += 1
                elif a[i] == second:
                    cnt_second += 1
                elif a[i] == third:
                    cnt_third += 1
            if (cnt_first != N/3) or (cnt_second != N/3) or (cnt_third != N/3):
                ans = False

if ans is True:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
from collections import deque

N = int(input())

# 2つの入力を空白で分割し、数値化
a_list = list(map(int, input().split()))
a_queue = deque(a_list)

def seach(source, base, current_list):
    if len(source) == 0:
        # 最後まできたら、自身とこれまでのリストの最後と、リストの先頭を比較して
        # 条件をみたせばOK
        if base == (current_list[-2] ^ current_list[0]):
            return True
        else:
            return False
    else:
        for right in source:
            if left ^ right == base:
                current_list.append(right)
                source.remove(right)
                return seach(source, right, current_list)


# left, base をまず組み合わせる
for base in a_list:
    result = False
    a_queue.remove(base)
    for left in a_list:
        if base == left:
            pass
        else:
            a_queue.remove(left)
            result = seach(a_queue, base, [left, base])
            if result:
                break
    if result:
        break
    a_queue = deque(a_list)

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

Submission status: Runtime Error

Solution code:
N = int(input())
List=list(map(int,input().split()))
List.sort()
a = List[0]
b = List.count(a)
c = List[N//3]
d = List.count(c)
e = List[2*N//3]
f = List.count(e)
if a == c and c == e:
    if a == 0 and b == N:
        print('Yes')
elif c == e:
    if a == 0  and N % 3 == 0 and b == N // 3 and d == 2 * N // 3:
        print('Yes')
elif N % 3 == 0 and b == N // 3 and d == N //3 and f == N //3 and a ^ e == c : 
    print('Yes')
else:
    print(A)