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: Time Limit Exceeded

Solution code:
import collections
import numpy as np

keta_max = 30
def decimal_to_binary(number):
    ans = ""
    for i in range(keta_max):
        ans += str(number // 2**(keta_max - 1 - i))
        number = number % 2**(keta_max - 1 - i)
    return ans

def distance(left, right):
    ans = 0
    for i in range(keta_max):
        if(abs(int(left[i]) - int(right[i]))):
            ans += 2**(keta_max - 1 - i)
    return ans

def step(index, not_used_hat_set, current_hat_list):
    candidates = np.where(np.array(distance_map[index-1]) == index + 1)[0]
    for c in set(candidates) & not_used_hat_set:
        current_hat_list[index] = c + 1
        if(index == N - 1):
            return True
        else:
            step(index + 1, not_used_hat_set - set([c + 1]), current_hat_list)
    return False

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

bynary_list = [decimal_to_binary(i) for i in a_list]
distance_map = collections.Counter()
for n in range(N):
    tmp = [distance(bynary_list[n], bynary_list[m]) for m in range(N)]
    distance_map[n+1] = tmp

for n in range(N):
    hat = [0 for m in range(N)]
    not_used_hat_set = set([m for m in range(N)])
    hat[0] = (n+1)%N
    hat[1] = (n+2)%N
    not_used_hat_set = not_used_hat_set - set([n, (n+1)%N])
    ans = step(2, not_used_hat_set, hat)
    if(ans == True):
        break
if(ans == True):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import collections
import numpy as np

keta_max = 30
def decimal_to_binary(number):
    ans = ""
    for i in range(keta_max):
        ans += str(number // 2**(keta_max - 1 - i))
        number = number % 2**(keta_max - 1 - i)
    return ans

def distance(left, right):
    ans = 0
    for i in range(keta_max):
        if(abs(int(left[i]) - int(right[i]))):
            ans += 2**(keta_max - 1 - i)
    return ans

def step(index, not_used_hat_set, current_hat_list):
    candidates = np.where(np.array(distance_map[index-1]) == index + 1)[0]
    for c in candidates:
        if(c in not_used_hat_set):
            current_hat_list[index] = c + 1
            if(index == N - 1):
                return True
            else:
                step(index + 1, not_used_hat_set - set([c + 1]), current_hat_list)
    return False

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

bynary_list = [decimal_to_binary(i) for i in a_list]
distance_map = collections.Counter()
for n in range(N):
    tmp = [distance(bynary_list[n], bynary_list[m]) for m in range(N)]
    distance_map[n+1] = tmp

for n in range(N):
    hat = [0 for m in range(N)]
    not_used_hat_set = set([m for m in range(N)])
    hat[0] = (n+1)%N
    hat[1] = (n+2)%N
    not_used_hat_set = not_used_hat_set - set([n, (n+1)%N])
    ans = step(2, not_used_hat_set, hat)
    if(ans == True):
        break
if(ans == True):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import collections

keta_max = 30
def decimal_to_binary(number):
    ans = ""
    for i in range(keta_max):
        ans += str(number // 2**(keta_max - 1 - i))
        number = number % 2**(keta_max - 1 - i)
    return ans

def distance(left, right):
    ans = 0
    for i in range(keta_max):
        if(abs(int(left[i]) - int(right[i]))):
            ans += 2**(keta_max - 1 - i)
    return ans

def step(index, not_used_hat_set, current_hat_list):
    for j in not_used_hat_set:
        if(distance_map[index-1][j] == index+1):
            current_hat_list[index] = j + 1
            if(index == N - 1):
                return True
            else:
                step(index + 1, not_used_hat_set - set([j + 1]), current_hat_list)
    return False

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

bynary_list = [decimal_to_binary(i) for i in a_list]
distance_map = collections.Counter()
for n in range(N):
    tmp = [distance(bynary_list[n], bynary_list[m]) for m in range(N)]
    distance_map[n+1] = tmp

for n in range(N):
    hat = [0 for m in range(N)]
    not_used_hat_set = set([m for m in range(N)])
    hat[0] = (n+1)%N
    hat[1] = (n+2)%N
    not_used_hat_set = not_used_hat_set - set([n, (n+1)%N])
    ans = step(2, not_used_hat_set, hat)
    if(ans == True):
        break
if(ans == True):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
numList = []
numList = list(map(int,input().split()))
 
result = 'No'
flag = True
count = 0
 
for wList in set(itertools.permutations(numList, n)):
  for v in set(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: Time Limit Exceeded

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

class multiset:
    def __init__(self, L):
        self.dic = {}
        for a in L:
            if a not in self.dic:
                self.dic[a] = 0
            self.dic[a] += 1
    def has(self, x):
        return x in self.dic and self.dic[x] > 0
    def remove(self, x):
        if self.has(x):
            self.dic[x] -= 1

def check(x, y):
    a = x
    S = multiset(A)
    S.remove(x)
    S.remove(y)
    for i in range(N - 2):
        z = (x ^ y)
        if not S.has(z):
            return False
        S.remove(z)
        x, y = y, z
    return a == x ^ y

yes = any(check(A[0], a) for a in A[1:])
print('Yes' if yes else 'No')

Submission status: Time Limit Exceeded

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

class multiset:
    def __init__(self, L):
        self.dic = {}
        for a in L:
            if a not in self.dic:
                self.dic[a] = 0
            self.dic[a] += 1
    def has(self, x):
        return x in self.dic and self.dic[x] > 0
    def remove(self, x):
        if self.has(x):
            self.dic[x] -= 1

def check(x, y):
    a = x
    S = multiset(A)
    S.remove(x)
    S.remove(y)
    for i in range(N - 2):
        z = (x ^ y)
        if not S.has(z):
            return False
        S.remove(z)
        x, y = y, z
    return a == x ^ y

yes = any(check(A[0], a) for a in A[1:])
print('Yes' if yes else 'No')

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
N = input()

N = N.split(" ")
Ni = []
for i in N:
    Ni.append(int(i))
ans = False
count = 0
for q in set(itertools.permutations(Ni,n)):
#     print(q)
    flg = True
    list_xor = []
    for i in range(len(q)):
        if len(q) > i+2:
            xor = (q[i] ^ q[i+2])
            tar = q[i+1]
        elif len(q) == i + 1:
            xor = (q[-2] ^ q[0])
            tar = q[-1]
        elif len(q) == i:
            xor = (q[-1] ^ q[1])
            tar = q[0]
            
#         print("{}, {}".format(xor, tar))
        
        if not xor == tar:
            flg = False
#             print(flg)
            break
            
    if flg == True:
        print("Yes")
        ans = True
        break
if not ans:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = {i: a for i, a in enumerate(map(int, input().split(' ')))}
k_l = [list(l.keys())[0]]

def find():
    for k, v in l.items():
        if l[k_l[-2]] ^ l[k_l[-1]] == v and k not in set(k_l):
            return k
    return None

for i in list(l.keys())[1:]:
    k_l.append(i)

    key = find()
    while key is not None:
        k_l.append(key)
        if len(k_l) == N:
            print('Yes')
            exit()
        key = find()

    k_l = [list(l.keys())[0]]

print('No')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = {i: a for i, a in enumerate(map(int, input().split(' ')))}
k_l = [list(l.keys())[0]]

def find():
    for k, v in l.items():
        if k in set(k_l):
            continue
        if l[k_l[-2]] ^ l[k_l[-1]] == v:
            return k
    return None

for i in list(l.keys())[1:]:
    k_l.append(i)

    key = find()
    while key is not None:
        k_l.append(key)
        if len(k_l) == N:
            print('Yes')
            exit()
        key = find()

    k_l = [list(l.keys())[0]]

print('No')

Submission status: Time Limit Exceeded

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


from collections import Counter
a_dict = Counter(a_list)

start = a_list[0]
# 数を減らさない。
# a_dict[a] -= 1

a_keys = a_dict.keys()

def check():
    for a1 in a_keys:
#         print("for1",start,a1)
        a0 = start
        tmp_dict = a_dict.copy()
#         tmp_dict[a1] -= 1
        for i in range(N):
#             print(" for2",i,a0,a1)
#             print(tmp_dict)
            next_a = int(bin(a0^a1), 0)
            if not next_a in tmp_dict:
#                 print(next_a," not in dict")
                break
            if tmp_dict[next_a] <= 0:
                tmp_dict.pop(next_a)
                break
            a0 = a1
            a1 = next_a
            tmp_dict[next_a] -= 1
#             if tmp_dict[next_a] == 0:
#                 tmp_dict.pop(next_a)
            if i == N-1:
                return True
    return False

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

d0 = defaultdict(int)

for c in a[1:]:
    d0[c] += 1
for i in range(1, N):
    d = d0.copy()
    x = a[0]
    y = a[i]
    d[y] -= 1
    for _ in range(N - 2):
        z = x ^ y
        if z in d and d[z] > 0:
            d[z] -= 1
            x = y
            y = z
        else:
            break
    else:
        if a[0] == x ^ y and a[i] == y ^ a[0]:
            print("Yes")
            exit(0)

print("No")

Submission status: Time Limit Exceeded

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


from collections import Counter
a_dict = Counter(a_list)

start = a_list[0]
# 数を減らさない。
# a_dict[a] -= 1

a_keys = a_dict.keys()

def check():
    for a1 in a_keys:
#         print("for1",start,a1)
        a0 = start
        tmp_dict = a_dict.copy()
#         tmp_dict[a1] -= 1
        for i in range(N):
#             print(" for2",i,a0,a1)
#             print(tmp_dict)
            next_a = int(bin(a0^a1), 0)
            if not next_a in tmp_dict:
#                 print(next_a," not in dict")
                break
            if tmp_dict[next_a] <= 0:
#                 print(next_a," dict 0")
                break
            a0 = a1
            a1 = next_a
            tmp_dict[next_a] -= 1
            if tmp_dict[next_a] == 0:
                tmp_dict.pop(next_a)
            if i == N-1:
                return True
    return False

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

Submission status: Time Limit Exceeded

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

from collections import Counter
a_dict = Counter(a_list)

start = a_list[0]
# 数を減らさない。
# a_dict[a] -= 1

a_keys = a_dict.keys()

def check():
    for a1 in a_keys:
#         print("for1",start,a1)
        a0 = start
        tmp_dict = a_dict.copy()
#         tmp_dict[a1] -= 1
        for i in range(N):
#             print(" for2",i,a0,a1)
#             print(tmp_dict)
            next_a = int(bin(a0^a1), 0)
            if not next_a in tmp_dict:
#                 print(next_a," not in dict")
                break
            if tmp_dict[next_a] <= 0:
#                 print(next_a," dict 0")
                break
            a0 = a1
            a1 = next_a
            tmp_dict[next_a] -= 1
            if i == N-1:
                return True
    return False

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
bit=[bin(x^y) for x in A for y in A]
B=sorted(set(bit))
AA=[]
for a in A:
  AA.append(bin(a))
if all(a in B for a in AA):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left as bl
from copy import deepcopy as dc
N = int(input())
Al = sorted(list(map(int, input().split())))
#print(Al)
q = -1
r = -1
for i in range(1, N - 1):
  A = dc(Al)
  #print(A)
  p = A.pop(0)
  temp = p ^ A[i]
  index = bl(A, temp)
  if index >= N - 1:
    continue
  if temp == A[index]:
    r = A.pop(i)
    q = A.pop(index)
    
    for j in range(1, N - 2):
      temp = q ^ r
      index = bl(A, temp)
      if temp == A[index]:
        t = r + 0
        if i == N - 4:
          r = p
        else:
          r = A.pop(index)
        q = t
      else:
        q = -1
        r = -1
        break
        
    
if q == -1:
  print("No")
  exit(0)
else:
  print("Yes")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque, defaultdict
from copy import copy

def main():
    N = int(input())
    _ = input().split()
    D_ = defaultdict(int)
    a_line = []
    for i, a in enumerate(_):
        a_ = int(a)
        D_[a_] += 1
        if i == 0:
            start = a_
            D_[start] -= 1
        a_line += [a_]

    if len(D_) >= 4:
        print('No')
        return

    Q = []
    for a in a_line:
        D = copy(D_)
        D[a] -= 1
        Q += [(start, a, D, N-2)]
    Q = deque(Q)

    while len(Q):
        a, b, D, count = Q.popleft()
        c = a ^ b
        d_ = D.get(c, None)
        if d_ is None or d_ == 0:
            continue
        D[d_] -= 1
        count -= 1
        if count == 0:
            print('Yes')
            return
        Q.append((b, c, D, count))

    print('No')
    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

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

table = [[-1 for _ in range(n)] for _ in range(n)]
c = [0 for _ in range(n)]

for i in range(n):
    for j in range(n):
        table[i][j] = a[i] ^ a[j]
        if i != j:
            k = bisect_left(a, table[i][j])
            if k < len(c) and a[k] == table[i][j]:
                c[k] += 1
if all((cc == 2 for cc in c)):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
bit= [bin(x ^ y) for x in A for y in A]
B=set(bit)
AA=[]
for a in A:
  AA.append(bin(a))
if all(a in B for a in AA):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
bit= [bin(x ^ y) for x in A for y in A]
B=sorted(set(bit))
AA=[]
for a in A:
  AA.append(bin(a))
if all(a in B for a in AA):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
start = a[-1]
a.pop(-1)
xor_list = []
ele = []
frag = 0
for i in range(1, n-1):
    for j in range(i):
        xor_list.append(a[i]^a[j])
        ele.append([i, j])
        
fst_pair = []
for i in range(len(xor_list)):
    if start == xor_list[i]:
        fst_pair.append(ele[i])
        
if ele:
    for i in range(len(ele)):
        e_start = a[ele[i][0]]
        s_start = a[ele[i][1]]
        visited = [False for j in range(len(a))]
        visited[ele[i][0]] = True
        visited[ele[i][1]] = True
        while True:
            if all(visited):
                if start ^ e_start == s_start:
                    frag = 1
                break
            want = s_start ^ start
            if want in a:
                want_index = a.index(want)
                if visited[want_index]:
                    if break_frag == True:
                        break
                    while True:
                        break_frag = False
                        if a[want_index+1] == a[want_index] and visited[want_index+1] == False:
                            visited[want_index+1] = True
                            start = s_start
                            s_start = a[want_index]
                            break
                        elif a[want_index+1] != a[want_index]:
                            break_frag = True
                            break

                else:
                    visited[want_index] = True
                    start = s_start
                    s_start = a[want_index]    
            else:
                break
    if frag:
        print("Yes")
    else:
        print("No")
            
else:
    print("No")

Submission status: Time Limit Exceeded

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

hats = A[:]
import copy
from collections import defaultdict
d = defaultdict(lambda: 0)

for h in hats:
    d[h] += 1

h1 = hats[0]
 
def search(now1, now2, count, d):
    try: 
        now1, now2 = now2, now1^now2
        if d[now2] > 0:
            if count == N:
                return True
            else:
                d[now1] -= 1
                return search(now1, now2, count+1, d)
        else:
            return False
    except:
        return False
    

ans = False
for h2 in hats[1:N//2+1]:
    if search(h1, h2, 2, copy.copy(d)):
        ans = True

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

Submission status: Time Limit Exceeded

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

hats = A[:]
import copy
from collections import defaultdict
d = defaultdict(lambda: 0)

for h in hats:
    d[h] += 1

h1 = hats[0]
 
def search(now1, now2, count, d):
    try: 
        now1, now2 = now2, now1^now2
        if d[now2] > 0:
            if count == N:
                return True
            else:
                d[now1] -= 1
                return search(now1, now2, count+1, d)
        else:
            return False
    except:
        return False
    

ans = False
for h2 in hats[1:]:
    if search(h1, h2, 2, copy.copy(d)):
        ans = True

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
input = sys.stdin.readline

#+++++

def search(l,v, p):
	left=bisect.bisect_left(l, v)
	if left >= len(l):
		return -1
		
	if l[left] != v:
		return -1
	
	while True:	
		if p[left] == -1:
			return left
		else:
			left+=1
		if left >= len(l) or l[left] != v:
			return -1
		
		
def main():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	
	init=l[0]

	for i, vi in enumerate(l[1:],1):
		ll=[-1 for _ in l]
		
		ll[0]==1
		ll[i]==1
		
		pre_v = l[i]
		pre_i = i
		next_v = init ^ vi
		next_i = search(l, next_v, ll)
		ff=0
		for k in range(n-2):
			if next_i < 0:
				ff=1
				break
				
			ll[next_i]=1
			#print(next_v,pre_v)
			t=next_v^pre_v
			pre_v = next_v
			pre_i = next_i
			next_v=t
			next_i = search(l, next_v, ll)
		
		if ff ==0:
			if next_v == l[0]:
				return 'Yes'
			
	return 'No'
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

cnt =0
for c in itertools.combinations(a, 3):
    if c[0] ^ c[1] ^ c[2] == 0:
        cnt =cnt+1
        
if cnt == N/3:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import copy

def check(A, N) :
  for i in range(1, N + 1) :
    X = list(bin(A[i - 1]))
    Y = list(bin(A[i + 1]))
    di = abs(len(X) - len(Y))
    if(len(X) < len(Y)) :
      for k in range(di) :
        X[2 : 2] = ["0"]
    elif(len(X) > len(Y)) :
      for k in range(di) :
        Y[2 : 2] = ["0"]
    else :
      pass
    C = list()
    for j in range(max(len(X), len(Y)) - 1, 1, -1) :
      if((X[j] == "0" and Y[j] == "1") or (X[j] == "1" and Y[j] == "0")) :
        C.append("1")
      else :
        C.append("0")
    C = C[::-1]
    c = "".join(C)
    c = int(c, 2)
    if(c != A[i]) :
      return 0    # No
    elif(i == N) :
      return 1    # Yes
      break
    else :
      pass

N = int(input())
A = list(map(int, input().split()))
B = copy.deepcopy(A)
B.append(B[0])
B.append(B[1])
if(check(B, N) == 1) :
  print("Yes")
else :
  C = list(itertools.permutations(A))
  for i in range(len(C)) :
    D = list(C[i])
    D.append(D[0])
    D.append(D[1])
    if(check(D, N) == 1) :
      print("Yes")
      break
    elif(i == len(C) - 1) :
      print("No")
      break
    else :
      pass

Submission status: Time Limit Exceeded

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

result = 'No'
flag = False
count = 0

for wList in itertools.permutations(numList, n):
  p_list = np.array(list(itertools.permutations(wList, 3)))
  x_list = p_list[:,0:1] ^ p_list[:,2:]
  r_list = x_list - p_list[:,1:2]
  c_list = r_list[r_list > 0]
  count = len(c_list)

  if count == 0:
    flag = True
    break
    
if flag:
  result = 'Yes'

print(result)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
bit= [bin(x ^ y) for x in A for y in A]
B=sorted(set(bit))[1:]
AA=[]
for a in A:
  AA.append(bin(a))
if all(a in B for a in AA):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

a_history = []
def get_ans(a, N):
    for l in itertools.permutations(a):
        ans = 'Yes'
        a_tmp = list(l)
        if a_tmp[0] != a[0]:
            continue  # 円順列対策
        if a_tmp[1:] in a_history:
            continue  # 数珠順列対応
        else:
            a_history.append(a_tmp[1:][::-1])  # 数珠順列対応
            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'
                break
        if ans == 'Yes':
            print(ans)
            return True
    print('No')
    return False

ret = get_ans(a, N)

Submission status: Time Limit Exceeded

Solution code:
import copy

N = input()
A = input().split()
n = int(N)
Int_A = [int(a) for a in A]

result = [Int_A[0]]
Int_A.remove(Int_A[0])


def check(a):
    if len(Int_A) == 1:
        if result[0] == Int_A[0] ^ a:
            print("Yes")
            exit()
        return []

    res = []
    co_other = copy.deepcopy(Int_A)
    for o in Int_A:
        co_other.remove(o)
        if a ^ o in co_other:
            res.append(o)
        co_other.append(o)
    del co_other

    return res


def deep_check(depth):

    resp = check(result[depth - 1])

    if len(resp) == 0:
        depth -= 1
        return

    for k in resp:
        result.append(k)
        Int_A.remove(k)
        depth += 1
        deep_check(depth)
        result.remove(k)
        Int_A.append(k)
    depth -= 1
    return


deep_check(1)
print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools
def permutations(iterable, r=None):
    pool = tuple(iterable)
    n = len(pool)
    ff = False
    r = n if r is None else r
    for indices in itertools.product(range(n), repeat=r):
        if len(set(indices)) == r:
            p = tuple(pool[i] for i in indices)
            for i in range(0, n):
                if i == 0:
                    ff = checkXOR(p[n-1],p[i],p[i+1])
                elif i == n-1:
                    ff = checkXOR(p[i-1],p[i],p[0])
                else:
                    ff = checkXOR(p[i-1],p[i],p[i+1])
                if ff:
                    break
        if ff:
            break
    return ff

def checkXOR(a, b, c):
    if bin(b) == bin(a ^ c):
        return False
    else:
        return True
    
n = int(input())
a = list(map(int, input().split()))
ff = permutations(a)
    
if ff:
    print("No")
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
Rakuda_data = list(itertools.permutations(input().split(' '),3))
flag =0

for n in Rakuda_data:
    if bin(int(n[0])^int(n[2])) == bin(int(n[1])):
        flag=1
        print('Yes')
        break
if flag==0:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
boushi_num = int(input())
boushi_No = list(map(int,input().split()))
flag = 0
le = range(0, boushi_num)
 
for v in itertools.permutations(boushi_No, boushi_num):
  for i in le:
    i = i
    i_a = i+2
    i_b = i+1
    if i_a >boushi_num -1:
      i_a = i_a - boushi_num
      if i_b >boushi_num -1:
        i_b = i_b - boushi_num
            
    if v[i]^v[i_a] != v[i_b]:
      break
    else:
      None
            
    if i == boushi_num - 1:
      flag = 1
                
  if flag == 1:
    print('Yes')
    break


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

Submission status: Time Limit Exceeded

Solution code:
import itertools
from functools import reduce
 
n=int(input())
a=list(map(int, input().rstrip().split(' ')))
def check(x):
  res = True
  for i in range(len(x)):
    _prev = i-1 if i>0 else len(x)-1
    _next = i+1 if i<len(x)-1 else 0
    res &= x[_prev]^x[_next] == x[i]
  return res

def check(x):
  return reduce(lambda x,y:x^y, x) == 0

for e in itertools.permutations(a[1:]):
  if check(list(e)+[a[0]]):
    print('Yes')
    break
else:
  print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
A=[int(x) for x in input().split()]
bit= [bin(x ^ y) for x in A for y in A]
B=sorted(set(bit))[1:]
AA=[]
for a in A:
  AA.append(bin(a))
if all(a in B for a in AA):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
import copy

N = input()
A = input().split()
n = int(N)
Int_A = [int(a) for a in A]

result = [Int_A[0]]
Int_A.remove(Int_A[0])


def check(a):
    if len(Int_A) == 1:
        if result[0] == Int_A[0] ^ a:
            print("Yes")
            exit()
        return []

    res = []
    co_other = copy.deepcopy(Int_A)
    for o in Int_A:
        co_other.remove(o)
        if a ^ o in co_other:
            res.append(o)
        co_other.append(o)
    del co_other

    return res


def deep_check(depth):

    resp = check(result[depth - 1])

    if len(resp) == 0:
        return

    for k in resp:
        result.append(k)
        Int_A.remove(k)
        depth += 1
        deep_check(depth)
        result.remove(k)
        Int_A.append(k)
    depth -= 1
    return


deep_check(1)
print('No')

Submission status: Time Limit Exceeded

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 = sorted(read_h(), reverse=True)
    #  print(arr)

    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
        if rem == 0:
            break

        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
            #  print(a, b, xor)
            #  print('remain:', cnts)
            break

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

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

a_history = []
def get_ans(a, N):
    for l in itertools.permutations(a):
        ans = 'Yes'
        a_tmp = list(l)
        if a_tmp[0] != a[0]:
            continue  # 円順列対策
        if a_tmp[1:] in a_history:
            continue  # 数珠順列対応
        else:
            a_history.append(a_tmp[1:])
            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'
                break
        if ans == 'Yes':
            print(ans)
            return True
    print('No')
    return False

ret = get_ans(a, N)

Submission status: Time Limit Exceeded

Solution code:
import copy

N = input()
A = input().split()
n = int(N)
Int_A = [int(a) for a in A]

result = [Int_A[0]]
Int_A.remove(Int_A[0])


def check(a, other):
    if len(other) == 1:
        if result[0] == other[0] ^ a:
            print("Yes")
            exit()
        return []

    res = []
    co_other = copy.deepcopy(other)
    for o in other:
        co_other.remove(o)
        if a ^ o in co_other:
            res.append(o)
        co_other.append(o)
    del co_other

    return res


def deep_check(depth):

    resp = check(result[depth - 1], Int_A)

    if len(resp) == 0:
        return

    for k in resp:
        result.append(k)
        Int_A.remove(k)
        depth += 1
        deep_check(depth)
        result.remove(k)
        Int_A.append(k)
    depth -= 1
    return


deep_check(1)
print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
Rakuda_data = list(itertools.permutations(input().split(' '),3))
flag =0

for n in Rakuda_data:
    if bin(int(n[0])^int(n[2])) == bin(int(n[1])):
        flag=1

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

Submission status: Time Limit Exceeded

Solution code:
import random
 
n = int(input())
a = [int(i) for i in input().split()]
 
rc = 0
while rc != 1000:
	c = 0
	for i in range(len(a)-1):
		if a[i] != int(bin(a[i-1]^a[i+1]),0):
			c=1
			random.shuffle(a)
			rc+=1
			break
	if c==0:
		if a[-1] != int(bin(a[0]^a[-2]),0):
			random.shuffle(a)
			rc+=1
		else:
			print("Yes")
			exit()
print("No")