Problem:


Score : 300 points

Problem Statement

Snuke has N hats. The i-th hat has an integer a_i written on it.

There are N camels standing in a circle.
Snuke will put one of his hats on each of these camels.

If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.

The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.

What is XOR?

The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.

Sample Input 2

4
1 2 4 8

Sample Output 2

No

There is no such way to distribute the hats; the answer is No.



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
SA=set(A)
if N%3==0:
    if len(SA)==3:
        x=[0,0,0]
        for i,a in enumerate(SA):
            x[i]=A.count(a)
        if x[0]==x[1] and x[1]==x[2]:
            print('Yes')
        else:
            print('No')
    elif len(SA)==2:
        x=[0,0]
        for i,a in enumerate(SA):
            x[i]=A.count(a)
        if x[0]*2==x[1] or x[1]*2==x[0]:
            print('Yes')
        else:
            print('No')
    elif  A[0]==0:
        print('Yes')
    else:
        print('No')
            
        
        
else:
    if len(SA)==1 and A[0]==0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

for i in range(N):
	a_left = i-1
	if i == 0:
		a_left = N-1
	a_right = i+1
	if i == N-1:
		a_right = 0
	
	if A_lis[a_left] ^ A_lis[a_right] != A_lis[i]:
		print("No")
		exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
a= int(input())
b=0
lista = list(map(int,input().split(" ")))
for i in lista:
    b^=i
if(b>a):
    print('No')
if(b<=a):
    print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
b.insert(0, b[len(b)-1])
b.append(b[1])
for i in range(1, len(b)-1):
    if b[i-1] ^ b[i+1] != b[i] ^ 0:
        print("No")
print("Yes")

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

if len(A) % 3 == 0:
    c = Counter(A)
    k = c.keys()
    s = len(c.keys())
    ok = len(k) == 3 and len(Counter(c.values()).keys()) == 1
else:
    ok = False
if ok:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a=LIST()
    ans='Yes'
    for i in range(-1,n-1):
        if a[i] != a[i-1] ^ a[i+1]:
            ans='No'
            break

    print(ans)

if  __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(a[0])
a.insert(0, a[-2])

ans = True
for i in range(1, n+1):
    if a[i-1] ^ a[i+1] != a[i]:
        ans = False
if ans:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

unq = list(set(nums))


def answer(ans):
    print(ans)
    exit()

if len(unq) > 3:answer("No")

if len(unq) == 3:
    a,b,c = unq
    if a ^ b ^ c != 0:answer("No")
    if nums.count(a) == nums.count(b) == nums.count(c):answer("Yes")
    else:answer("No")

if len(unq) == 2:
    a,b = sorted(unq)
    if a != 0:answer("No")
    if nums.count(a) * 2 == nums.count(b):answer("Yes")
    else: answer("No")

if len(unq) == 0:
    a = unq[0]
    if a != 0:answer("No")
    else:answer("Yes")

Submission status: Wrong Answer

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

R = {}
for i in a:
  if i in R:
    R[i] += 1
  else:
    R[i] = 1

if len(R) != 3:
  print("No")
else:
  t = -1
  for i in R.values():
    if t == -1:
      t = i
    else:
      if i != t:
        print("No")
        break
  else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, aaa):
    if n % 3 != 0:
        return False

    cnt = list(Counter(aaa).items())
    if len(cnt) != 3:
        return False
    if any(c[1] != n // 3 for c in cnt):
        return False
    a1, a2, a3 = (c[0] for c in cnt)
    if a1 ^ a2 == a3:
        return True
    return False


n = int(input())
aaa = list(map(int, input().split()))
print('Yes' if solve(n, aaa) else 'No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
# S=numpp.assaray(S)=="#"
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LLS(): return [list(sys.stdin.readline().rstrip()) for _ in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()



def main():
    N=I()
    A = list(map(int,input().split()))
    out=True
    for i in range(N):
        if i==0:
            last=N-1
        else:
            last=i-1
        if i==N-1:
            ne=0
        else:
            ne=i+1
        if A[last]^A[ne]!=A[i]:
            print("No")
            exit()
    print("Yes")


    # print(A,B)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
f = 1
for i in range(n):
    if a[i - 2] ^ a[i] != a[i - 1]:
        f = 0
print('Yes' if f else 'No')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(v) for v in input().split()]

ans = [b == a ^ c for a, b, c in zip(a[:-2], a[1:-1], a[2:])]
if all(ans):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N= int(input())

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

for i in range(N):
    if a[i]!=a[(i+1)%N] ^ a[(i+N-1)%N]:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
a = [int(x) for x in input().split()]

c = len(set(a))

if (n % 3 == 0 and c <= 3) or c == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(_) for _ in input().split()]
a=[a[n-1]]+a+[a[0]]
f=True
for i in range(1,n):
    if a[i]!=a[i-1]^a[i+1]:
        f=False
        break
print("Yes" if f else "No")

Submission status: Wrong Answer

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

a.append(a[0])
a.append(a[1])

for i in range(1, n+1):
    if a[i-1] ^ a[i+1] != a[i]:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = []
B.append(A[-1])
for a in A:
    B.append(a)
B.append(A[0])
ans = "Yes"

for a, b, c in zip(B, B[1:], B[2:]):
    if a ^ c == b:
        continue
    else:
        ans = "No"
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(zz) for zz in input().split()]

for i in range(N):
    p = i+1
    if i+1 >= N:
        p = 0
    if A[i] != A[p]^A[i-1]:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
m = [0 for i in range(5)]
print(m)

Submission status: Time Limit Exceeded

Solution code:
def get_caps(a):
  dic = dict()

  for ai in a:
    dic.setdefault(ai, 0)
    dic[ai] += 1

  return dic


def get_xor(a, b):
  bin_a = format(a, 'b')
  bin_b = format(b, 'b')

  digit = max(len(bin_a), len(bin_b))

  # 2進数のケタ数を揃える
  bin_a = bin_a.zfill(digit)
  bin_b = bin_b.zfill(digit)
  s = ''

  for i in range(len(bin_a)):
    if bin_a[i] == '0' and bin_b[i] == '1':
      s += '1'
    elif bin_a[i] == '1' and bin_b[i] == '0':
      s += '1'
    else:
      s += '0'

  # 10進数に戻す
  return int(s, 2)


def can_put_on_cap(n):
  global caps

  if n in caps.keys():
    if caps[n] > 0:
      caps[n] -= 1
      return True


# A - XOR Circle
import sys
input = sys.stdin.readline
import copy

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

# 帽子の情報をdictに入れる
dic = get_caps(a)

for i in range(N):
  for j in range(i+1, N):
    caps = copy.deepcopy(dic)
    caps[a[i]] -= 1
    caps[a[j]] -= 1
        
    left = a[i]
    mid = a[j]
    count = 2
    
    for k in range(N-2):
      right = get_xor(left, mid)
    
      if can_put_on_cap(right):
        left = mid
        mid = right
        count += 1
      else:
        break
    
    if count == N:
      if left ^ a[i] == right:
            print('Yes')
            exit()

print('No')

Submission status: Time Limit Exceeded

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

# A - XOR Circle
def get_caps(a):
  dic = dict()

  for ai in a:
    dic.setdefault(ai, 0)
    dic[ai] += 1

  return dic


def can_put_on_cap(n):
  global caps

  if n in caps.keys():
    if caps[n] > 0:
      caps[n] -= 1
      return True


def get_xor(a, b):
  bin_a = format(a, 'b')
  bin_b = format(b, 'b')

  digit = max(len(bin_a), len(bin_b))

  # 2進数のケタ数を揃える
  bin_a = bin_a.zfill(digit)
  bin_b = bin_b.zfill(digit)
  s = ''

  for i in range(len(bin_a)):
    if bin_a[i] == '0' and bin_b[i] == '1':
      s += '1'
    elif bin_a[i] == '1' and bin_b[i] == '0':
      s += '1'
    else:
      s += '0'

  # 10進数に戻す
  return int(s, 2)


import itertools
import copy

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

# 帽子の情報をdictに入れる
caps_original = get_caps(a)

# 1,3番目のラクダを先に決めておく
combis = list(itertools.combinations(a, 2))

for c in combis:
  caps = copy.deepcopy(caps_original)
  count = 0
  xor = 0

  if can_put_on_cap(c[0]):
    count += 1

    if can_put_on_cap(c[1]):
      camels = [0] * N
      camels[0] = c[0]
      camels[2] = c[1]
      count += 1

      # 2番目のラクダの帽子が決まる
      camels[1] = camels[0] ^ camels[2]

      if can_put_on_cap(camels[1]):
        count += 1

        for i in range(1, N - 2):
          xor = get_xor(camels[i], camels[i + 2])

          if can_put_on_cap(xor):
            camels[i + 1] = xor
            count += 1
          else:
            break

        if count == N:
          if camels[N - 2] ^ camels[0] == camels[N - 1]:
            print('Yes')
            exit()

print('No')

Submission status: Time Limit Exceeded

Solution code:
def f(t,T):
    if t in T:
        return T[t]
    else:
        return 0

from copy import copy

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

T={}
for a in A[1:]:
    if a in T:
        T[a]+=1
    else:
        T[a]=1

F=True
for i in range(1,N):
    a,b=A[0],A[i]
    X=[a,b]+[0]*(N-2)

    U=copy(T)
    U[b]-=1

    G=True
    for k in range(N-2):
        c=a^b
        if f(c,U)>0:
            U[c]-=1
            X[k+2]=c
            a,b=b,c
        else:
            G=False
            break

    if G and X[-2]^X[-1]==X[0] and X[-1]^X[0]==X[1]:
        print("Yes")
        exit()

print("No")

Submission status: Time Limit Exceeded

Solution code:
def f(t,T):
    if t in T:
        return T[t]
    else:
        return 0

from copy import copy

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

T={}
for a in A[1:]:
    if a in T:
        T[a]+=1
    else:
        T[a]=1

F=True
for i in range(1,N):
    a,b=A[0],A[i]
    X=[a,b]+[0]*(N-2)

    U=copy(T)
    U[b]-=1

    G=True
    for k in range(N-2):
        c=a^b
        if f(c,U)>0:
            U[c]-=1
            X[k+2]=c
            a,b=b,c
        else:
            G=False

    if G and X[-2]^X[-1]==X[0] and X[-1]^X[0]==X[1]:
        print("Yes")
        exit()

print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    l=[0]*N

    l[0]=A[0]
    i=0
    aset=Counter(A[1:])
    for a in aset:
        aset1=copy(aset)
        aset1[a]-=1
        l[1]=a
        f=1
        ra=a^l[0]
        if ra not in aset1 or aset1[ra]==0:
            continue

        for j in range(0,N-2):
            na=l[j]^l[j+1]
            if na in aset1 and aset1[na]>=1:
                aset1[na]-=1
                l[j+2]=na
            else:
                f=0
                break
        if f:
            if l[-1]^l[0]==l[1] and l[-2]^l[-1]==l[0]:
                print('Yes')
                return
    print('No')
    #print(l)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    l=[0]*N

    l[0]=A[0]
    i=0
    aset=Counter(A[1:])
    for a in aset:
        aset1=copy(aset)
        aset1[a]-=1
        l[1]=a
        f=1
        if a^l[0] not in aset1:
            continue
        
        for j in range(0,N-2):
            na=l[j]^l[j+1]
            if na in aset1 and aset1[na]>=1:
                aset1[na]-=1
                l[j+2]=na
            else:
                f=0
                break
        if f:
            if l[-1]^l[0]==l[1] and l[-2]^l[-1]==l[0]:
                print('Yes')
                return
    print('No')
    #print(l)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    l=[0]*N

    l[0]=A[0]
    i=0
    aset=Counter(A[1:])
    for a in aset:
        aset1=copy(aset)
        aset1[a]-=1
        l[1]=a
        f=1
        for j in range(0,N-2):
            na=l[j]^l[j+1]
            if na in aset1 and aset1[na]>=1:
                aset1[na]-=1
                l[j+2]=na
            else:
                f=0
                break
        if f:
            if l[-1]^l[0]==l[1] and l[-2]^l[-1]==l[0]:
                print('Yes')
                return
    print('No')
    #print(l)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

res = set()
for i in range(n - 1):
    for j in range (i + 1, n):
        res.add(s[i] ^ s[j])

ref = set(s)
print("Yes" if all(c in res for c in ref) else "No")

Submission status: Time Limit Exceeded

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

import sys
from collections import Counter
d = Counter(A)

if d[0] == N:
    print("Yes")
    sys.exit()

if d[0] == N // 3:
    for x in d.keys():
        if d[x] == 2 * N // 3:
            print("Yes")
            sys.exit()

# print(d)
third = N // 3
# print(third)
cand = list(filter(lambda x: d[x] == third, A))
# print(cand)
for ix1 in range(len(cand)):
    for ix2 in range(ix1 + 1, len(cand)):
        for ix3 in range(ix2 + 1, len(cand)):
            if cand[ix1] ^ cand[ix2] ^ cand[ix3] == 0:
                print("Yes")
                sys.exit()

print("No")

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

c = {}
for e in a:
    c.setdefault(e, 0)
    c[e] += 1

t = {}
for x, y in combinations(a, 2):
    i = x
    j = y
    t[i] = 1
    t.setdefault(j, 0)
    t[j] += 1
    for _ in range(N - 2):
        k = i ^ j
        t.setdefault(k, 0)
        t[k] += 1
        c.setdefault(k, 0)
        if t[k] > c[k]:
            j = -1
            break
        i, j = j, k
    if j ^ x == y:
        print('Yes')
        exit()
print('No')

Submission status: Time Limit Exceeded

Solution code:
import copy

N=int(input())
a=list(map(int,input().split()))
A={}
for h in range(N):
    if a[h] in A:
        A[a[h]]+=1
    else:
        A[a[h]]=1
A[a[0]]-=1
ans="No"
for i in range(1,N):
    temp=copy.copy(A)
    P=[a[0],a[i]]
    temp[a[i]]-=1
    for j in range(2,N):
        x=P[j-2]^P[j-1]
        if x in temp and temp[x]>0:
            P.append(x)
            temp[x]-=1
        else:
            break
    if len(P)==N:
        if P[-2]^P[-1]==P[0] and P[-1]^P[0]==P[1]:
            ans="Yes"
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
ok = False
for v in itertools.permutations(a):
    v = v+v[:2]
    for i in range(n):
        if int(bin(v[i] ^ v[i+1] ^ v[i+2]), 2) != 0: break
        elif i == n-1 and int(bin(v[i] ^ v[i+1] ^ v[i+2]), 2) == 0: ok = True
    if ok: break
print("Yes" if ok else "No")

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
ok = False
for v in itertools.permutations(a):
    v = v+v[:2]
    for i in range(n):
        if v[i+1] != int(bin(v[i] ^ v[i+2])[2:], 2): break
        if i == n-1:
            if v[i+1] == int(bin(v[i] ^ v[i+2])[2:], 2):
                ok = True
    if ok: break
print("Yes" if ok else "No")

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

n = int(input())
A = list(map(int,input().split()))
ans = "No"
for x in itertools.permutations(A,2):
    dl = collections.Counter(A)
    L = n-1
    y = list(x)
    dl[y[1]] -= 1
    while(L):
        tmp = y[0]^y[1]
        if dl[tmp] <= 0:
            break
        dl[tmp]-=1
        y[0] = y[1]
        y[1] = tmp
        L-=1
        if L == 0:
            ans = "Yes"
    if ans =="Yes":
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
arr = list(map(int, input().split()))
for i in itertools.permutations(arr):
    flg = True
    for k in range(N):
        if i[k-2] ^ i[k] != i[k-1]:
            flg = False
            break
    if flg:
        print('Yes')
        exit()
print('No')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

N = int(input())

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

per_1 = list(itertools.permutations(a))


N = N-1
ans = "No"
for i in per_1:
    counting = 0
    if (bin(i[0]) == bin(i[N] ^ i[1])) & (bin(i[N]) == bin(i[0] ^ i[N-1])):

        for j in range(1,N-1):
            if (bin(i[j]) == bin(i[j+1] ^ i[j-1])):
                counting += 1
    
        if counting == N-2:
                ans = "Yes"
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def f(n, D, p, q):
    for i in range(n-2):
        r = p ^ q
        if (r in D) and (D[r] > 0):
            D[r] -= 1
        else:
            return -1
        p, q = q, r
    return p ^ q

def solve(n, a):
    D = {}
    for x in a:
        if not x in D:
            D[x] = 0
        D[x] += 1
    D[a[0]] -= 1
    for i in range(1, n):
        D[a[i]] -= 1
        ok = f(n, D.copy(), a[0], a[i]) == a[0]
        D[a[i]] += 1
        if ok:
            return "Yes"
    return "No"

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
p=[]
cnt=[]
zero=0
for i in range(n):
	if a[i]==0:
		zero+=1
	elif a[i] not in p:
		p.append(a[i])
		cnt.append(1)
	else:
		for j in range(len(p)):
			if a[i]==p[j]:
				cnt[j]+=1
if n%3!=0 and zero!=n:
	print("No")
	exit()
if len(p)>=4:
	print("No")
	exit()
if len(p)==3:
	if cnt[0]==cnt[1]==cnt[2]==n/3:
		if p[0]^p[1]^p[2]==0:
			print("Yes")
			exit()
	else:
		print("No")
		exit()
elif len(p)==1:
	if cnt[0]==n/3*2:
		print("Yes")
		exit()
elif len(p)==0:
	if sum(a)==0:
		print("Yes")
		exit()
print("No")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
p=[]
cnt=[]
zero=0
for i in range(n):
	if a[i]==0:
		zero+=1
	elif a[i] not in p:
		p.append(a[i])
		cnt.append(1)
	else:
		for j in range(len(p)):
			if a[i]==p[j]:
				cnt[j]+=1
if len(p)==3:
	if cnt[0]==cnt[1]==cnt[2]==n/3:
		if p[0]^p[1]^p[2]==0:
			print("Yes")
			exit()
elif len(p)==1:
	if cnt[0]==n/3*2:
		print("Yes")
		exit()
elif len(p)==0:
	if sum(a)==0:
		print("Yes")
		exit()
print("No")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
p=[]
cnt=[]
zero=0
for i in range(n):
	if a[i]==0:
		zero+=1
	elif a[i] not in p:
		p.append(a[i])
		cnt.append(1)
	else:
		for j in range(len(p)):
			if a[i]==p[j]:
				cnt[j]+=1
if len(p)==3:
	if cnt[0]==cnt[1]==cnt[2]==n/3:
		if p[0]&p[1]&p[2]==0:
			print("Yes")
			exit()
elif len(p)==1:
	if cnt[0]==n/3*2:
		print("Yes")
		exit()
elif len(p)==0:
	if sum(a)==0:
		print("Yes")
		exit()
print("No")

Submission status: Time Limit Exceeded

Solution code:
from copy import copy
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
d = Counter(a)

#print(d)
for i in range(1, n):
    one = prev = a[0]
    two = cur = a[i]
    dd = copy(d)
    end = True
    for j in range(n-2):
        nxt = prev^cur
        if dd[nxt] >0:
            dd[nxt] -= 1
        else:
            end = False
            break
        prev = cur
        cur = nxt
    if end and prev^cur == one and dd[one] > 0 and cur^one == two and dd[two] > 0:
        print("Yes")
        exit()
print("No")

Submission status: Time Limit Exceeded

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

def XOR(x, y):
  u, i = 0, 0
  while x != 0 or y != 0:
    u += ((x + y) % 2) * (2 ** i)
    x //= 2
    y //= 2
    i += 1
  return u

Q = []
for i in range(1, len(A)):
  M = XOR(A[0], A[i])
  L = [A[0], A[i]]
  for j in range(len(A)-2):
    L.append(XOR(L[j], L[j+1]))
  Q.append(L)

B = A[:]
k = 0
for s in range(len(Q)):
  for l in range(len(Q[s])):
    for g in range(len(A)):
      if A[g] == Q[s][l]:
        B[g] = Q[s][l]
  if B == Q[s]:
    k += 1
    
if k != 0:
  print('Yes')
else:
  print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools
def q44(n, a):
    b = list(itertools.permutations(a))
    for c in b:
       # print(c)
        c = list(c)
        #print(c)
        e = c[-1]
        f = c[0]
        c.insert(0, e)
        c.append(f)
        
        yes = True
        for i in range(1, len(c) - 1):
            #print(c[i-1])
            #print(c[i+1])
            #print(c[i])
            #print(bin(c[i-1] ^ c[i+1]))
            if bin(c[i]) != bin(c[i-1] ^ c[i+1]):
                yes = False
        if yes:
            return 'Yes'
    return 'No'
N = int(input())
a = [int(i) for i in input().split()]
print(q44(N, a))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
input = sys.stdin.readline
 
def main():
  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)
  
if __name__ == '__main__':
  main()