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:
n = int(input())
figure = list(map(int, input().split()))
cnt=0#最大n-2
loop_n = n
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if figure[i] ^ figure[j] == figure[k]:
        cnt+=1
        number1=figure[j]
        number2=figure[k]
        lastnumber=figure[i]
        figure.remove(figure[i])
        figure.remove(figure[j-1])
        figure.remove(figure[k-2])
        loop_n-=3
        i, j, k=n,n,n

for i in range(0,loop_n):
  now = number1^number2
  for j in range(0,loop_n):
    if now == figure[j]:
      cnt+=1
      loop_n -=1
      number1, number2 = numbwe2, figure[j]
      figure.remove(j)
      i, j=-1
if(n-2)==cnt:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
N = int(input())

# 2つの入力を空白で分割し、数値化
a_list = list(map(int, input().split()))
a_set = set(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_set.remove(base)
    for left in a_list:
        if base == left:
            pass
        else:
            a_set.remove(left)
            result = seach(a_set, base, [left, base])
            if result:
                break
    if result:
        break
    a_set = set(a_list)

print("YES" if result else "NO")

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(i) for i in input().split(' ')]
b = a
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 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')

Submission status: Runtime Error

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 listA[0]^listA[1]==listA[2] \
    and listA[1]^listA[2]==listA[0] \
    and listA[2]^listA[0]==listA[1]: yesexit()
else: noexit()

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):
        j = 1
elif len(u) == 2:
    if 0 in u:
        if v[0] == v[1] * 2 or v[0] * 2 == v[1]:
            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:
N = int(input())
nums = list(map(int, input().split()))

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

lists = nums[:]
for index, num in enumerate(lists):
    lists.pop(index)
    if start ^ num in lists:
        next = num
        first = start

# print(start, next)

if next == None:
    print("No")
else:
    while len(nums) > 1:
        if start ^ next in nums:
            nums.remove(start)
            nums.remove(next)
            next2 = start ^ next
            start = next
            next = next2
            # print(nums)
            # print(start, next)
        else:
            print("No")
            break

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

Submission status: Runtime Error

Solution code:
import sys

if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    if N%3 != 0:
        print('No')
        sys.exit()
    A.sort()

    n = N/3
    if 1 == len(set(A[0:n])) and 1 == len(set(A[n:2*n])) and 1 == len(set(A[2*n:3*n])) and A[0] == A[n] ^ A[2*n]:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            if len(a) ==2:
                b=a_list.pop(0)
                if len(b)==len(a_list)*2//3:
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
    else:
            if len(a)==3:
                a1=a[0]
                a2=a[1]
                a3=a[2]
                if a1 ^ a2 ==a3 and a1^a3==a2:
                    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: Runtime Error

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

a_unique = list(set(a))
for i in range(n-1):
    for j in range(i+1,n):
        if a_unique[i]^a_unique[j] in a:
            pass
        else:
            result = False

a_unique = list(set(a))
if len(a_unique) > 3:
    result = False

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

Submission status: Runtime Error

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

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

if numbers[0]^numbers[1] == numbers[2]:
    print('Yes')
    exit(1)
elif numbers[0]^numbers[2] == numbers[1]:
    print('Yes')
    exit(1)
elif numbers[1]^numbers[2] == numbers[0]:
    print('Yes')
    exit(1)
else:
    print('No')

Submission status: Runtime Error

Solution code:
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
        if 0 in a:
            if len(a) ==2:
                b=a_list.pop(0)
                if len(b)==len(a_list)*2//3:
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
        else:
            if len(a)==3:
                a1=a[0]
                a2=a[1]
                a3=a[2]
                if a1 ^ a2 ==a3 and a1^a3==a2:
                    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: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = []
def f(a):
  c = 0
  for i in range(n-1):
    if a[i-1] ^ a[i+1] == a[i]:
      c += 1
    else:
      c = -1
      break
  if a[0] ^ a[n-2] == a[n-1] and c > -1:
    return True
  else:
    return False
for i in range(n):
  b.append(f(a))
  c = a.pop(a[0])
  a.append(c)
if any(b):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
aa = list(map(int, input().split()))

if n % 3 != 0:
    if all(map(lambda x: x == 0, aa)):
        print('Yes')
    else:
        print('No')
else:
    m = n // 3

    cnt_map = defaultdict(int)
    for a in aa:
        cnt_map[a] += 1

    if len(cnt_map.keys()) > 3:
        print('No')
    elif len(cnt_map.keys()) == 1:
        k = cnt_map.keys()[0]
        if k == 0:
            print('Yes')
        else:
            print('No')
    elif len(cnt_map.keys()) == 2:
        k1, k2 = cnt_map.keys()
        if k1 > k2:
            k1, k2 = k2, k1
        if k1 == 0 and cnt_map[k1] == m:
            print('Yes')
        else:
            print('No')
    elif len(cnt_map.keys()) == 3:
        a, b, c = cnt_map.keys()
        if a == b ^ c and cnt_map[a] == m and cnt_map[b] == m and cnt_map[c] == m:
            print('Yes')
        else:
            print('No')

Submission status: Runtime Error

Solution code:
def CheckMatch(aList, bList, i):
    #print("aList", aList)
    #print("bList", bList)
    matched_list = list(set(aList) & set(bList))
    if len(matched_list) < i :
        print("No")
        exit()
    return matched_list

n = int(input())
cap = list(map(int, input().split()))

#print(cap)

a = []
a.append(cap[0])
cap.pop(0)
aXor = []
for i in range(n-1):
    aXor.append(a[0]^cap[i])

matched_list = CheckMatch(cap, aXor, 2)
#print(matched_list)

_cap = cap

for i in range(len(matched_list)):
    a.append(matched_list[i])
    _cap.remove(matched_list[i])
    #print(a, a[-2], a[-1], a[-2]^a[-1])
    a.append(a[-2]^a[-1])
    matched_list = CheckMatch(_cap, [a[-1]], 1)
    #print(matched_list)
    if len(_cap) == 1:
        if a[-2]^a[-1] == a[0]:
            print("Yes")
            exit()
        else:
            a = []
            a.append(cap[0])
            _cap = cap

Submission status: Runtime Error

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

#print(bin(a[N-1] ^ a[1]))
#print(bin(a[0]))

if bin(a[N-2] ^ a[0]) == bin(a[N-1]):
  if bin(a[N-1] ^ a[1]) == bin(a[0]):
    if N!=3:
      for i in range(0,N-3):
        #print(bin(a[N] ^ a[N+2]),bin(a[N+1]))
        if Flag:
          if bin(a[N] ^ a[N+2])!=bin(a[N+1]):
            Flag=False
            break  
      if Flag:
        print("Yes")
    else:
      if bin(a[0] ^ a[2]) == bin(a[1]):
        print("Yes")
      else:
        print("No")
  else:
    print("No")    
else:
  print("No")

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 num in rest_list:
            current_temp = current_list.copy()
            rest_temp = rest_list.copy()
            current_temp.append(num)
            rest_temp.remove(num)
            if is_circle(current_temp, rest_temp):
                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 = [int(i) for i in input().split(' ')]
b = a
numbers = []
numbers.append(a[0])
for i in a:
    if i != numbers[0] and len(numbers) == 1:
        numbers.append(i)
    if i != a[0] and i != numbers[1]:
        numbers.append(i)
        break
if len(numbers) =! 3:
    print('No')
    exit(1)

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

if numbers[0]^numbers[1] == numbers[2]:
    print('Yes')
    exit(1)
elif numbers[0]^numbers[2] == numbers[1]:
    print('Yes')
    exit(1)
elif numbers[1]^numbers[2] == numbers[0]:
    print('Yes')
    exit(1)
else:
    print('No')

Submission status: Runtime Error

Solution code:

a = int(input())
x = list(map(int,input().split()))
ax = list(set(x))
x.sort()
ax = list(set(x))
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
if len(ax) < 3:
    if (sum(x) == 0) :
        print("Yes")
        exit()
    if x.count(0)*2 == x.count(ax[1]) and len(x) == x.count(0) + x.count(ax[1]):
        print("Yes")
        exit()
        
    print("No")
    exit()
t = (len(x) == x.count(ax[0]) + x.count(ax[1]) + x.count(ax[2])) * (x.count(ax[1]) == x.count(ax[0]) and x.count(ax[0]) == x.count(ax[2]))

y(1,t)

Submission status: Runtime Error

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

# size = 4
# nums = [1, 2, 3, 1, 2, 3]

numu = list(set(nums))
if size % 3 != 0:
  print("No")
  quit()

num = nums.count(numu[0])
if nums.count(nums[1]) != num or nums.count(nums[2]) != num:
  print("No")
  quit()

if numu[0] ^ numu[2] == numu[1] \
    and numu[1] ^ numu[0] == numu[2] \
    and numu[2] ^ numu[1] == numu[0]:
  print("Yes")
  quit()

print("No")

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
aa = list(map(int, input().split()))

if n % 3 != 0:
    if all(map(lambda x: x == 0, aa)):
        print('Yes')
    else:
        print('No')
    exit(0)
m = n // 3

cnt_map = defaultdict(int)
for a in aa:
    cnt_map[a] += 1

if len(cnt_map.keys()) > 3:
    print('No')
elif len(cnt_map.keys()) == 1:
    k = cnt_map.keys()[0]
    if k == 0:
        print('Yes')
    else:
        print('No')
elif len(cnt_map.keys()) == 2:
    k1, k2 = cnt_map.keys()
    if k1 > k2:
        k1, k2 = k2, k1
    if k1 == 0 and cnt_map[k1] == m:
        print('Yes')
    else:
        print('No')
elif len(cnt_map.keys()) == 3:
    a, b, c = cnt_map.keys()
    if a == b ^ c and cnt_map[a] == m and cnt_map[b] == m and cnt_map[c] == m:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
f=0
for i in a:
  for j in a:
    if(i!=j):
      x=i^j
      if(x not in a):
        f=1
        break
if(f==0):
  print('Yes')
else:
  print('No'

Submission status: Runtime Error

Solution code:
import sys
N=int(input())
a=list(map(int,input().split()))
b,c,d=0,1,0
while True:
    while True:
        e==2**c
        if a[b]%(e)>=e/2:
            d+=1
        b+=1
        if b==N:
            if d%2==1:
                print('No')
                sys.exit()
            else:
                break
    b,d=0,0
    c+=1
    if c==27:
        break
print('Yes')

Submission status: Runtime Error

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))
l = len(a)

u0 = a.count(a_unique[0])
u1 = a.count(a_unique[1])
u2 = a.count(a_unique[2])

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

def get_ans(a, N):
    ans = 'Yes'
    for l in list(itertools.permutations(a)):
        a_tmp = list(l)
        a_tmp.extend(a_tmp[:2])

        for x in range(N):
            if int(bin(a_tmp[x]^a_tmp[x+2]), 0) != a_tmp[x+1]:
                ans = 'No'
                print(ans)
                return 'False'
    print(ans)
    return True

ret = get_ans(a, N)

Submission status: Runtime Error

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]:
            return 'Yes'
        
        if vals[0]*2==vals[1] and "1" not in keys[1]:
            return 'Yes'
        
        return 'No'
    if len(keys)==3:
        stop
        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: Runtime Error

Solution code:
import sys

N = int(input())
numbers = list(map(int, input().split())) 
numbers_2 = numbers
 
def foo(x,y, numbers):
    if len(numbers) == 0:
        print("Yes")
        sys.exit()
    for i in numbers:
        if x ^ i == y:
            numbers.remove(x)
            numbers.remove(y)
            numbers.remove(i)
            foo(y,i,numbers)
        else:
            continue
    print("No")
    sys.exit()
    
  
 
for i in numbers_2:
    for j in numbers_2:
        if not numbers_2.index(i) == numbers_2.index(j):
            foo(i,j,numbers_2)

Submission status: Runtime Error

Solution code:
import sys

def checker(a0,a1,tmp):
  a2=''
  b0=bin(a0)[2:]
  b1=bin(a1)[2:]
  if len(b0)<len(b1):
    b0,b1=b1,b0
  b1=b1.zfill(len(b0))
  for s0,s1 in zip(b0,b1):
    a2 = a2 + str( int(s0)^int(s1) )
  a2=int(a2,2)
  #print(a0,a1,a2)
  if a2 not in tmp:
    return 1
  else:
    tmp.remove(a2)
    if  len(tmp)==0:
      return 0
    checker(a1,a2,tmp)

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

bia=1
for i in range(N-1):
  tmp=A.copy()
  tmp.remove(A[i])
  for j in range(N-bia):
    tmp.remove(A[j+bia])
    if checker(A[i],A[j+bia],tmp) == 1:
      break
    else:
      print('Yes')
      sys.exit()
  bia+=1
print('No')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
npa = np.array(a)
npx = npa^(npa.reshape(n,1))
p = list(npx[np.triu_indices(n,k=1)])
for i in a:
  if i in p:
    p.remove(i)
    continue
  else:
    print("No")
    quit()
print("Yes")

Submission status: Runtime Error

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

k = {}
for i in range(N):
    if not A[i] in k:
        k[A[i]] = 1
    else:
        k[A[i]] += 1

a = 0
if len(k.keys()) == 3:
    B = 0
    for key, val in k.items():
        if val == N // 3:
            a += 1
        B = B ^ key
elif len(k.keys()) == 2:
    for key, val in k.items():
        if val == N // 3 and key == 0:
            a += 1
        elif val == N // 3 * 2:
            a += 2
    B = 0

if N % 3 == 0 and B == 0 and a == 3:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

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 num in rest_list:
            current_list.append(num)
            rest_list.remove(num)
            if is_circle(current_list, rest_list):
                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=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            b=a_list.pop(0)
            if len(b)==len(a_list)*2//3:
                print("Yes")
            else:
                print("No")
    else:
            a1=a[0]
            a2=a[1]
            a3=a[2]
            if a1 ^ a2 ==a3 and a1^a3==a2:
                if a_list.count(a1) ==a_list.count(a2) ==a_list.count(a3):
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
if n % 3:
    ans = 'No'
else:
    a = sorted(map(int, input().split()))
    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: Runtime Error

Solution code:
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            b=a_list.pop(0)
            if len(b)==len(a_list)*2//3:
                print("Yes")
            else:
                print("No")
    else:
            a1=a[0]
            a2=a[1]
            a3=a[2]
            if a1 ^ a2 ==a3 and a1^a3==a2:
                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: Runtime Error

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

ans = [-1]*n

# first
ans[0] = a.pop(0)
is_next = False
for i in range(len(a)):
    for j in range(i+1, len(a)):
        if ans[0] == a[i]^a[j]:
            ans[1] = a.pop(i)
            ans[-1] = a.pop(j-1)
            is_next = True
if is_next == False:
    print("No")
    exit()

# 1 ~ last-2
for i in range(1, n-2):
    is_next = False
    for j in range(len(a)):
        if ans[i] == ans[i-1]^a[j]:
            ans[i+1] = a.pop(j)
            is_next = True
    if is_next == False:
        print("No")
        exit()

# last
if len(a) != 0:
    ans[-2] = a.pop(0)
if ans[-2] != ans[-3]^ans[-1] or ans[-1] != ans[-2]^ans[0]:
    print("No")
    exit()

print("Yes")

Submission status: Runtime Error

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))
l = len(a)

u0 = a.count(a_unique[0])
u1 = a.count(a_unique[1])
u2 = a.count(a_unique[2])

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

Submission status: Runtime Error

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

if n!=3:
    for i in range(0,n-2):
    if  (bin(a[i] ^ a[i+2]))==bin(a[i+1]):
        continue
    else:
        s=1

    if  (bin(a[n-1] ^ a[1]))==bin(a[0]):
        f=0
    else:
        s=1

    if  bin((a[n-2] ^ a[0]))==bin(a[n-1]):
        f=0
    else:
        s=1



else:
    if  (bin(a[0] ^ a[1]))==bin(a[2]):
        f=0
    else:
        s=1
    if  (bin(a[1] ^ a[2]))==bin(a[0]):
        f=0
    else:
        s=1
    if  (bin(a[2] ^ a[0]))==bin(a[1]):
        f=0
    else:
        s=1

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

Submission status: Runtime Error

Solution code:
import sys
import itertools
n=int(input())
l=list(map(int,input().split()))
l.sort()
s=set(l)
if len(s)>=4:print("No");sys.exit()
s=list(s)
flag=0
for i in itertools.permutations(s):
  if i[0]^i[2]==i[1] and i[1]^i[2]==i[0] and i[0]^i[1]==i[2]:flag+=1
if flag==6:print("Yes")
else:print("No")

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
aa = list(map(int, input().split()))

if n % 3 != 0:
    if all(map(lambda x: x == 0, aa)):
        print('Yes')
    else:
        print('No')
    exit(0)
m = n // 3

cnt_map = defaultdict(int)
for a in aa:
    cnt_map[a] += 1

if len(cnt_map.keys()) > 3:
    print('No')
    exit(0)

if len(cnt_map.keys()) == 1:
    k = cnt_map.keys()[0]
    if k == 0:
        print('Yes')
    else:
        print('No')
    exit(0)

if len(cnt_map.keys()) == 2:
    k1, k2 = cnt_map.keys()
    if k1 > k2:
        k1, k2 = k2, k1
    if k1 != 0:
        print('No')
        exit(0)
    if cnt_map[k1] != m:
        print('No')
        exit(0)
    print('Yes')
    exit(0)
if len(cnt_map.keys()) == 3:
    a, b, c = cnt_map.keys()
    if a != b ^ c:
        print('No')
        exit(0)
    if cnt_map[a] == m and cnt_map[b] == m and cnt_map[c] == m:
        print('Yes')
        exit(0)
    print('No')
    exit(0)

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 num in rest_list:
            current_list.append(num)
            rest_list.remove(num)
            if is_circle(current_list, rest_list):
                return True
        return False

    next_int = current_list[-1] ^ current_list[-2]
    if next_int in input_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:
def resolve():

    n = int(input())
    dataset = set(map(int, input().split()))

    li_dataset = list(dataset)
    xor = li_dataset[0] ^ li_dataset[1]

    flag = 0
    if xor in dataset:
        flag = 1

    if len(dataset) <= 3 and n % 3 == 0 and flag:
        print('Yes')

    else:
        print('No')
        
resolve()

Submission status: Runtime Error

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

if c == d:
    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)
    else:
        v[u.index(i)] += 1
    if len(u) > 3:
        break
#print(u,v)
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):
    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:
import sys

N = int(input())
a = list(map(int, input().split()))
ah = a.copy()
a.append(a[0])

for i in range(N):
    if i == 0:
        if bin(a[N-1] ^ a[i+1]) == bin(a[i]):
            ah.remove(a[i])
            continue

    else:
        if bin(a[i-1] ^ a[i+1]) == bin(a[i]):
            ah.remove(a[i])
            continue

if ah == []:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
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:
      return f(num2,num1^num2,l[1:])
    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:
n = int(input())
a = list(map(int, input().split()))

st = set(a)

if n == 3 and a[0] ^ a[1] == a[2]:
  print("Yes")
elif n  >= 4 and st == {0}:
  print("Yes")
elif n % 3 == 0 and len(st) == 2 and (0 in a) and a.count(0) = n /3:
  print("Yes")
elif n % 3 == 0 and len(st) == 3 and a.count(st.pop) = n /3 anda.count(st.pop) = n/3:
  print("Yes")
else:
  print("No")