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

count = 0
i = 0
while len(d) != 0:
    if count == 0:
        a = 0
        count += 1
        for j in range(N-count):
            target = d[i] ^ d[j]
            if target in d :
                a += 1
                i = j
            if a == 1:
                break
        if a >= 1 :
            i2 = target
            mae =d[i]
            d.pop(i)
        else:
            print('No')
            break
    
    elif 1 <= count <= N-3:
        a = 0
        count += 1
        for j in range(N-count):
            if target == mae ^ d[j] :
                a += 1
                i = j
            if a == 1:
                break
        if a >= 1 :
            mae =d[i]
            d.pop(i)
        else:
            print('No')
            break
    
    elif count == N-2:
        a = 0
        count += 1
        if mae == target ^ l[0] :
            pass
        else:
            print('No')
            break    

    else:
        if l[0] == i2  ^   mae :
            print('Yes')
            break
        else:
            print('No')
            break

Submission status: Time Limit Exceeded

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

def xor(x1,x2):
    return int(bin((x1^x2)),2)

def check(a):
    state=True
    for i in range(1,len(a)-1):
        if(xor(a[i-1],a[i+1])==a[i] and state):
            state=True
        else:
            state=False

    if(xor(a[len(a)-1],a[1])==a[0] and state):
        state= True
    else:
        state=False

    if(xor(a[len(a)-2],a[0])==a[len(a)-1] and state):
        state=True
    else:
        state=False
    return state

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

    if (check(a)):
        result = True
        break
    a[0],a[-1]=a[-1],a[0]


print("YNeos"[1-int(result)::2])

Submission status: Time Limit Exceeded

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

j = 0
found = False
for i in range(n - 1):
    found = False
    for j in range(i + 1, n):
        tgt = a[i] ^ a[j]
        idx = -1
        try:
            idx = a.index(tgt)
        except:
            pass
        if idx > -1:
            a.insert(i + 1, a.pop(idx))
            found = True
            break
    if not found:
        break
if found:
    found = (a[-1] ^ a[1] == a[0])
if found:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
an=[int(x) for x in map(int,input().split()[:N])]

def judgeXOR(v):
    for x in range(N):
        if x==0:
            if (v[N-1] ^ v[x+1] ) != (x+1):
                return False
        elif x==(N-1):
            if (v[0] ^ v[x-1]) !=(x+1):
                return False
        else:
            if (v[x-1] ^ v[x+1])!=(x+1):
                return False
    return True

for v in itertools.permutations(an,N):
    if v[0] !=an[0]:
        break
    if judgeXOR(v):
        print("Yes")
        exit()

print("No")

Submission status: Time Limit Exceeded

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

a.append(a[0])

mat = []
for i in range(len(a)):
    for j in range(i+1, len(a)):
        mat.append(a[i] ^ a[j])
        # mat[i, j] = a[i] ^ a[j]
        #mat.append(row)
mat = list(set(mat))

flg = True
for _a in a:
    if _a in mat:
        continue
    else:
        print('No')
        flg = False
        break

if flg:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
n = list(map(int, input().split()))
t = 0
m = n[:]
for l in range(N):
    if l+1 in m:
        m.remove(l+1)
if N > 100000:
    print("No")
elif len(n) != N:
    print("No")
elif len(m) != 0:
    print("No")
else:
    for i in range(N):
      if i == 0:
        if n[N-1] ^ n[1] == n[0]:
            t += 1
      elif i == N-1:
        if n[N-2] ^ n[0] == n[N-1]:
          t += 1
      else:
        if n[i-1] ^ n[i+1] == n[i]:
          t += 1
    if t == N:
      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 itertools.permutations(numList, n):
  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: Time Limit Exceeded

Solution code:
import itertools
import sys

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

for i in itertools.permutations(a, len(a)):
    flag = True
    i_add = i + (i[0], i[1])
    for j in range(0, len(i)):
        if i_add[j] ^ i_add[j+2] != i_add[j+1]:
            flag = False
    if flag:
        print("Yes")
        sys.exit()

print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
ra = list(map(int,input().rstrip().split(' ')))
l = list(itertools.permutations(ra))
for r in l:
    if (r[1] ^ r[N-1]) != r[0]:
        f = 0
    else:
        f = 1
    for i in range(1,N-1):
        if (r[i-1] ^ r[i+1]) != r[i]:
            f = 0
            break
    if (r[0] ^ r[N-2]) != r[N-1]:
        f = 0
    if f == 1:
        break
if f != 1:
    print("No")
else:
    print("Yes")

Submission status: Time Limit Exceeded

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

def xor(x1,x2):
    return int(bin((x1^x2)),2)

def check(a):
    state=True
    for i in range(1,len(a)-1):
        if(xor(a[i-1],a[i+1])==a[i] and state):
            state=True
        else:
            state=False

    if(xor(a[len(a)-1],a[1])==a[0] and state):
        state= True
    else:
        state=False

    if(xor(a[len(a)-2],a[0])==a[len(a)-1] and state):
        state=True
    else:
        state=False
    return state

for i in range(len(a)):
    for j in range(i,len(a)-1):
        a[j],a[j+1]=a[j+1],a[j]
        if(check(a)):
            result=True
    a[0],a[-1]=a[-1],a[0]


print("YNeos"[1-int(result)::2])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

plus_set = set([ int(bin(c[0]^c[1]), 0) for c in (itertools.combinations(a,2))])
if set(a) == plus_set:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
n = list(map(int, input().split()))
t = 0
m = list()
for k in range(N):
    m.append(n[k])
for l in range(N):
    if l+1 in m:
        m.remove(l+1)
if len(m) != 0:
    print("No")
else:
    for i in range(N):
      if i == 0:
        if n[N-1] ^ n[1] == n[0]:
            t += 1
      elif i == N-1:
        if n[N-2] ^ n[0] == n[N-1]:
          t += 1
      else:
        if n[i-1] ^ n[i+1] == n[i]:
          t += 1
    if t == N:
      print("Yes")
    else:
      print("No")

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
n=int(input())
N=list(map(int,input().split()))
ans=[]
for i in list(permutations(N)):
    flag=0
    i=list(i)
    i.insert(0,i[-1])
    i.append(i[1])
    for j in range(1,n):
        if i[j]!=i[j-1]^i[j+1]:break
        else:flag=1
    if flag==1:break
    
if flag:print("Yes")
else:print("No")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int,input().split()))
d = l.copy()

count = 0
i = 0
while len(d) != 0:
    if count == 0:
        a = 0
        count += 1
        for j in range(N-count):
            target = d[i] ^ d[j]
            if target in d :
                a += 1
                i = j
        if a >= 1 :
            i2 = target
            mae =d[i]
            d.pop(i)
        else:
            print('No')
            break
    
    elif 1 <= count <= N-3:
        a = 0
        count += 1
        for j in range(N-count):
            if target == mae ^ d[j] :
                a += 1
                i = j
        if a >= 1 :
            mae =d[i]
            d.pop(i)
        else:
            print('No')
            break
    
    elif count == N-2:
        a = 0
        count += 1
        if mae == target ^ l[0] :
            pass
        else:
            print('No')
            break    

    else:
        if l[0] == i2  ^   mae :
            print('Yes')
            break
        else:
            print('No')
            break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

boushi_num = int(input())
boushi_No = list(map(int,input().split()))
flag = 0


for v in itertools.permutations(boushi_No, boushi_num):
  v = list(v)
  for i in range(0,len(v)):
    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:
N = int(input())
A = list(map(int,input().split()))

table = {}
for i in range(len(A)):
    a = A[i]
    B = A.copy()
    B.pop(i)
    for j in range(len(B)):
        for k in range(1, len(B)):
            if A[i] == B[j]^B[k]:
                if A[i] not in table.keys():
                    table[a] = set()
                b1 = min([B[j], B[k]])
                b2 = max([B[j], B[k]])
                table[a].add( (b1, b2) )

def locate(i, a, table, current, rest):
    global N
    if a not in table.keys():
        return False
    else:
        #print("###############")
        #print("i={}".format(i))
        #print(current)
        #print("###############\n")
        L = (i - 1 + N) % N
        R = (i + 1 + N) % N
        if i==N-1 and current[L] != -1 and current[R] != -1:
            #print("try")
            if a == current[L]^current[R]:
                return True
            else:
                return False
        else:
            current_ = current.copy()
            current_[i] = a
            for j in range(len(rest)):
                rest_ = rest.copy()
                next_a = rest_.pop(j)
                need_search = False
                for t1,t2 in table[a]:
                    if t1 == next_a or t2 == next_a:
                        need_search = True
                        break
                if need_search:
                    if locate(i+1, next_a, table, current_, rest_) == True:
                        return True


for i in range(len(A)):
    current = [-1] * N
    rest = A.copy()
    a = rest.pop(i)

    ret = locate(0, a, table, current, rest)
    if ret == True:
        print("Yes")
        exit()

print("No")

Submission status: Time Limit Exceeded

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

def xor(x1,x2):
    return int(bin((x1^x2)),2)

def check(a):
    state=True
    for i in range(1,len(a)-1):
        if(xor(a[i-1],a[i+1])==a[i] and state):
            state=True
        else:
            state=False

    if(xor(a[len(a)-1],a[1])==a[0] and state):
        state= True
    else:
        state=False

    if(xor(a[len(a)-2],a[0])==a[len(a)-1] and state):
        state=True
    else:
        state=False
    return state

for i in range(len(a)-1):
    a[i],a[i+1]=a[i+1],a[i]
    if(check(a)):
        result=True


print("YNeos"[1-int(result)::2])

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 itertools.permutations(numList, n):
  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: Time Limit Exceeded

Solution code:
from itertools import permutations
n=int(input())
N=list(map(int,input().split()))
ans=[]
for i in list(permutations(N)):
    if 1 in ans:break
    flag=1
    i=list(i)
    i.insert(0,i[-1])
    i.append(i[1])
    for j in range(1,n):
        if i[j]!=i[j-1]^i[j+1]:
            flag=0
            break
    ans.append(flag)
if 1 in ans:print("Yes")
else:print("No")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
n = list(map(int, input().split()))
t = 0
m = list()
for k in range(N):
    m.append(n[k])
for l in range(N):
    if l+1 in m:
        m.remove(l+1)
if N > 100000:
    print("No")
elif len(n) != N:
    print("No")
elif len(m) != 0:
    print("No")
else:
    for i in range(N):
      if i == 0:
        if n[N-1] ^ n[1] == n[0]:
            t += 1
      elif i == N-1:
        if n[N-2] ^ n[0] == n[N-1]:
          t += 1
      else:
        if n[i-1] ^ n[i+1] == n[i]:
          t += 1
    if t == N:
      print("Yes")
    else:
      print("No")

Submission status: Time Limit Exceeded

Solution code:
def sol(N, _as):
    first = _as.pop()
    for second in _as:
        success = True
        __as = _as[:]
        __as.remove(second)
        latest = second
        pre_latest = first
        while len(__as) > 0:
            _latest = latest
            latest = pre_latest^latest
            pre_latest = _latest
            try:
                __as.remove(latest)
            except ValueError:
                success = False
                break
        if success and pre_latest^latest == first:
            return True
    return False


def solve(N, _as):
    if N % 3 != 0:
        return False

    max_bit_len = 0
    max_bit_len_ints = []
    other_ints = []
    for a in _as:
        bl = int.bit_length(a)
        if bl > max_bit_len:
            max_bit_len = bl
            other_ints.extend(max_bit_len_ints)
            max_bit_len_ints.clear()
            max_bit_len_ints.append(a)
        elif bl == max_bit_len:
            max_bit_len_ints.append(a)
        else:
            other_ints.append(a)

    if N / 3 != len(other_ints):
        return False

    first = max_bit_len_ints.pop()
    for second in other_ints:
        return _solve(first, second, max_bit_len_ints, other_ints)


def _solve(first, second, _max_bit_len_ints, _other_ints):
    max_bit_len_ints = _max_bit_len_ints[:]
    other_ints = _other_ints[:]
    other_ints.remove(second)

    pre_latest = second
    latest = first^second
    try:
        max_bit_len_ints.remove(latest)
    except ValueError:
        return False

    count = 0
    while len(max_bit_len_ints) > 0 and len(other_ints) > 0:
        _latest = latest
        latest = pre_latest^latest
        pre_latest = _latest
        if count == 0 or count == 2:
            try:
                max_bit_len_ints.remove(latest)
            except ValueError:
                return False
        else:
            try:
                other_ints.remove(latest)
            except ValueError:
                return False
        count = (count + 1) % 3

    return pre_latest^latest == first


if __name__ == '__main__':
    N = int(input())
    _as = [int(x) for x in input().split()]
    print('Yes' if sol(N, _as) else 'No')

Submission status: Time Limit Exceeded

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

list_length = len(A)

A_except_first = A[1:]

B = list(itertools.permutations(A_except_first))
B_len = len(B)
C = []
for i in range(B_len):
    C.append([A[0]] + list(B[i]))

count_true = []
    
C_len = len(C)
for i in range(C_len):
    for j in range(B_len):
        if j == 0:
            if C[i][1] ^ C[i][-1] == C[i][0]:
                count_true.append('True')
            else:
                print('No')
                break
        if C[i][j - 1] ^ C[i][j + 1] == C[i][j]:
            count_true.append('True')
        else:
            print('No')
            break
    else:
        continue
    break
if len(count_true) ==  len(A) * len(C):
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans="Yes"
if n>3:
    for i in range(n-1):
        if a.count(a[i])!=a.count(a[i+1]) or a.count(a[i])==1:
            ans="No"
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
import copy

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

def q(line):
  flg = True
  for i in range(len(line)):
    max = i + 1
    min = i - 1
    if i + 1 > n - 1:
      max = 0
    elif i - 1 < 0:
      min = n - 1
    wa = line[min] ^ line[max]
    if line[i] != wa:
      flg = False
  return flg

# 1回やる
flg = q(line)
if flg:
  print('Yes')
  sys.exit()

# 数字
for i in line:
  line2 = copy.copy(line)
  line2.remove(i)
  flg = True
  for v in itertools.permutations(line2,2):
    if i == list(v)[0] ^ list(v)[1]:
      flg = False
      break
  if flg:
    print('No')
    sys.exit()
    



for v in itertools.permutations(line,n):
  flg = q(list(v))
  if flg:
    print('Yes')
    sys.exit()

print('No')

Submission status: Time Limit Exceeded

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

ok=False
a0=aa[0]
c_i=1
for i in aa[1:]:
    a = aa.copy()
    used = [False]*N

    tmp=a[0]
    used[0] = True
    a[0]=-1

    tmp2=i
    used[c_i]=True
    used[c_i]=-1

    for j in range(N-1):
        tmp3=tmp^tmp2
        if j==N-2 and tmp3==a0:
            ok=True
            break
        if not (tmp3 in a):
            break
        tmp3_idx = a.index(tmp3)
        if used[tmp3_idx]==True:
            break
        else:
            used[tmp3_idx]=True
            a[tmp3_idx]=-1
            tmp=tmp2
            tmp2=tmp3
    c_i=c_i+1
if ok:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
# import itertools
import bisect
import copy

N = int(sys.stdin.readline().rstrip())

a = sorted(map(int, sys.stdin.readline().rstrip().split()))

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


for j in range(len(a)):
  if j == 0:
    continue

  # print(j)
  tmp = copy.copy(a)

  # x, yを決めるとzが決まると同値なので
  x = a[0]
  y = a[j]
  
  del tmp[index(tmp, x)]
  del tmp[index(tmp, y)]

  next_flg = True
  while len(tmp) > 0:
    try:
      i = index(tmp, x^y)
    except ValueError:
      next_flg = False
      break
    
    # tmpからあたりをけずって続き
    del tmp[i]
    x, y = (y, x^y)

  
  if next_flg:
    print("Yes")
    quit()
  

print("No")

Submission status: Time Limit Exceeded

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

p = list(itertools.permutations(a,len(a)))
y = 0
for l in p:
	c = 0
	for i in range(len(l)-1):
		if l[i] != int(bin(l[i-1]^l[i+1]),0):
			c=1
			break
	if c==0:
		if l[-1] == int(bin(l[0]^l[-2]),0):
			y=1
			break
			
if y==1:
	print("Yes")
else:
	print("No")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[ai for ai in map(int,input().split())]
CA={}
for a in A:
    if a in CA:
        CA[a]+=1
    else:
        CA[a]=1

for i in range(1,N):
    CA_Tmp={ai:0 for ai in CA.keys()}
    CA_Tmp[A[0]]=1
    CA_Tmp[A[i]]=1
    crnt=A[i]
    next=A[0]^A[i]
    Ans=True
    for j in range(2, N):
        if next in CA:
            CA_Tmp[next]+=1
            if CA_Tmp[next] > CA[next]:
                Ans=False
                break
            crnt,next=next,crnt^next
        else:
            Ans=False
            break
    if Ans==True:
        if next!=A[0]:
            Ans=False
        else:
            break

print("Yes" if Ans==True else "No")

Submission status: Time Limit Exceeded

Solution code:
import copy 

n = int(input())
a = list(map(int,input().split()))
# n = 100
# a = [i for i in range(n)]
a1 = a[0]
flag = False

for i in range(1,n):
    t = a[1:]
    a2 = a[i]
    nxt = a1 ^ a2
    t.remove(a2)
    for j in range(n-2):
        if nxt in t:
            t.remove(nxt)
            a1 = a2
            a2 = nxt
            nxt = a1 ^ a2
        else:
            break
    else:
        if nxt == a[0]:
            flag = True
    if flag:
        break

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

Submission status: Time Limit Exceeded

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

ok=False
a0=aa[0]
for i in aa[1:]:
    a = aa.copy()
    used = [False]*N

    tmp=a[0]
    used[0] = True
    a[0]=-1

    tmp2=i
    used[a.index(i)]=True
    used[a.index(i)]=-1

    for j in range(N-1):
        tmp3=tmp^tmp2
        if j==N-2 and tmp3==a0:
            ok=True
            break
        if not (tmp3 in a):
            break
        tmp3_idx = a.index(tmp3)
        if used[tmp3_idx]==True:
            break
        else:
            used[tmp3_idx]=True
            a[tmp3_idx]=-1
            tmp=tmp2
            tmp2=tmp3
if ok:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import bisect

def search(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

def check(l1, l2, a):
    a = a[::]
    while 0 < len(a):
        ni = search(a, (l1^l2))
        if ni < 0:
            return False
        l1 = l2
        l2 = a.pop(ni)
    return True

def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    l1, a = a[0], a[1:]
    for i in range(len(a)):
        b = a[::]
        l2 = b.pop(i)
        if check(l1, l2, b):
            print('Yes')
            return
    print('No')

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

def Check(a, b, c):
    if a^b == c:
        return 1
    else:
        return -1

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

a = list(itertools.permutations(cap))

for i in range(len(a)):
    for j in range(n):
        v = Check(a[i][j], a[i][(j+1)%n], a[i][(j+2)%n])
        if v == -1:
            break
        elif j == n-1:
            print("Yes")
            exit()

print("No")

Submission status: Time Limit Exceeded

Solution code:
import random

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

for j in range(100000):
	chk = 0
	for i in range(n-1): 
		if a[i] == a[i-1] ^ a[i+1]:
			chk += 1
		else:
			break			
	if a[n-1] == a[n-2] ^ a[0]:
		chk += 1
	if chk == n:
		print("Yes")	
		break
	else:
		random.shuffle(a)
if j == 99999:
	print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools

def check(a):
    for i in range(n):
        if i == 0:
            if a[i+1]^a[n-1] != a[i]:
                break
        if i == n-1:
            if a[i-1]^a[0] != a[i]:
                break
        else:
            if a[i-1]^a[i+1] != a[i]:
                break
    else:
        return True
    return False
        
n = int(input())
a = [int(i) for i in input().split()]
b = list(itertools.permutations(a[:-1]))
for x in b:
    x = list(x)
    x.append(a[-1])
    if check(x) == True:
        print('Yes')
        break
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a= list(map(int, input().split()))
a.sort()
b=[None]*N
b[0]=a[0]
A=0
for i in range(N-1,0,-1):
  b[1]=a[i]
  for j in range(2,N):
    b[j]=b[j-1]^b[j-2]
    if b[j] not in a:
      break
  else:
    b.sort()
    if a==b:
      A=1
      break
if A==1:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import itertools
import bisect
import copy

N = int(sys.stdin.readline().rstrip())

a = sorted(map(int, sys.stdin.readline().rstrip().split()))

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


for ite in itertools.permutations(a, 2):
  tmp = copy.copy(a)

  # x, yを決めるとzが決まると同値なので
  x = ite[0]
  y = ite[1]
  
  del tmp[index(tmp, x)]
  del tmp[index(tmp, y)]

  next_flg = True
  while len(tmp) > 0:
    try:
      i = index(tmp, x^y)
    except ValueError:
      next_flg = False
      break
    
    # tmpからあたりをけずって続き
    del tmp[i]
    x, y = (y, x^y)

  
  if next_flg:
    print("Yes")
    quit()
  

print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools
inn = input()
inn = int(inn)
in_list = [int(i) for i in input().split(' ')]

kumi = list(itertools.permutations(in_list))
flag = 0
for tori in kumi:
    count = 0
    for i in range(inn):
        a = tori[i-1]
        try:
            b = tori[i+1]
        except:
            b = tori[0]
        hai = bin(a^b)
        hai = int('{}'.format(hai), 2)
        c = tori[i]
        if hai==c:
            count += 1
    if count==inn:
        flag = 1
if flag==1:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
c = N-1
A.sort()
while c > 0:
    num = A[0]^A[c]
    pre_num = A[c]
    B = [A[0],A[c],num]
    while len(B) < N:
        box = num
        num = num^pre_num
        pre_num = box
        B.append(num)
        if pre_num not in A:
            break
    B.sort()
    if A == B:
        break
    c -= 1
if c > 0:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input()) # The number of camel
a = [int(i) for i in input().split()] # Hat's number

combs = list(itertools.permutations([i for i in range(n)]))
combs = [comb for comb in combs if comb[0] == 0]

check = True
for comb in combs:
    for idx in range(n):
        if check:
            pre = idx - 1
            if pre < 0:
                pre = n - 1
            
            if a[comb[idx]] != a[comb[pre]]^a[comb[(idx + 1)%n]]:
                check = False
        else:
            break

    if not check:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
def permutations_with_XOR(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
    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()))
    
if permutations_with_XOR(a):
    print("No")
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy

n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))

b1=a[0]
b_lis=copy.copy(a)
b_lis.remove(b1)
judge=0
for i in range(n-1):
    c_lis=copy.copy(b_lis)
    b1d=b1
    b2=a[i+1]
    c_lis.remove(b2)
    while True:
        
        b3=b1d^b2
        
        if b3 in c_lis:
            c_lis.remove(b3)
            b1d=b2
            b2=b3
        else:
            break
        if len(c_lis)==0:
            judge=1
            break

if judge==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()]

for j in range(100000):
	chk = 0
	for i in range(n-1): 
		if a[i] == a[i-1] ^ a[i+1]:
			chk += 1
	if a[n-1] == a[n-2] ^ a[0]:
		chk += 1
	if chk == n:
		print("Yes")	
		break
	else:
		random.shuffle(a)
if j == 99999:
	print("No")

Submission status: Time Limit Exceeded

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

hats = A[:]

from collections import defaultdict
d = defaultdict(lambda: {})

for i, h1 in enumerate(hats):
    hats2 = hats[i+1:]
    for j, h2 in enumerate(hats2):
        d[h1][h2] = h1^h2
        d[h2][h1] = h1^h2
    
    
def dfs(now1, now2, used):
    if len(used) == N:
        return True
    
    now3 = d[now1][now2]
    if d[now3] == {}:
        return False
    
    used = used[:] + [now2]
    for s in d[now3]:
        if d[now3][s] == now2:
            continue
        if dfs(now3, s, used):
            return True
        
    return False

ans = False
for s in d[hats[0]]:
    tmp = dfs(hats[0], s, [])
    if tmp == True:
        ans = True
        break
        
if ans:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

com_a = list(itertools.permutations(a))
cnt_xor=0

for i in range(len(com_a)):
    for j in range(-1,len(a)-1):
        if com_a[i][j] != (com_a[i][j+1]^com_a[i][j-1]):
            cnt_xor=0
            break
        cnt_xor+=1

    if cnt_xor != 0:
        print("Yes")
        break
    elif i == len(com_a)-1:
        print("No")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
c = N-1
A.sort()
while c > 0:
    num = A[0]^A[c]
    pre_num = A[c]
    B = [A[0],A[c],num]
    while len(B) < N:
        box = num
        num = num^pre_num
        pre_num = box
        B.append(num)
    B.sort()
    if A == B:
        break
    c -= 1
if c > 0:
    print("Yes")
else:
    print("No")