Problem:


Score : 300 points

Problem Statement

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

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

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

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

What is XOR?

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

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

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

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

Sample Input 2

4
1 2 4 8

Sample Output 2

No

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



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Runtime Error

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

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

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections



def XORC(a,b,p):
    for i in range(len(a)):
        if (int(a[i])+int(b[i]))%2 == int(p[i]):
            continue
        else:
            return False
        
    return True
            
def Solve():
    N=int(input())
    AL=[("0"*34+bin(int(x))[2:])[-33:] for x in input().split()]

    ALC=collections.Counter(AL)

    keys=list(ALC.keys())
    vals=list(ALC.values())

    if len(keys)>3:
        return 'No'
    if len(keys)==1:
        if "1" in keys[0]:
            return 'No'
        return 'Yes'
    
    if len(keys)==2:
        if "1" in keys[0] and "1" in keys[1]:
            return 'No'

        stop
        if vals[0]==vals[1]*2 and ("1" not in keys[0]):
            return 'Yes'
        
        if vals[0]*2==vals[1] and ("1" not in keys[1]):
            return 'Yes'
        
        return 'No'
    if len(keys)==3:
        if vals[0]==vals[1]==vals[2]:
            if XORC(keys[0],keys[1],keys[2]) and XORC(keys[0],keys[2],keys[1]) and XORC(keys[1],keys[2],keys[0]):
                return 'Yes'
        
        return 'No'
print(Solve())

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

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

    import collections
    c = collections.Counter(a_list)
    keys = sorted(c.keys())
    nk = len(keys)

    dprint(c)
    dprint(keys)

    # a[0] からスタート
    found = False
    start = keys[0]

    cand_center = []
    cand_right = []

    for i in range(1, nk):
        center = keys[i]
        max = start + center

        for j in range(i+1, nk):
            right = keys[j]
            if right > max:
                # これより大きいところにはない
                dprint("break by max condition")
                break

            if right == start ^ center:
                cand_center.append(center)
                cand_right.append(right)

    if len(cand_center) == 0:
        print("No")
        return

    if len(cand_center) > 1:
        raise ValueError("majika")

    center = cand_center[0]
    right = cand_right[0]
    c[start] = c[start] - 1
    c[center] = c[center] - 1
    c[right] = c[right] - 1

    # これで、0, second, third が決まったので、あとは順次決める
    left = center
    center = right
    dprint(start, left, center)

    cnt = 3
    while True:
        # N個作ったら終了
        if cnt == N:
            break

        # 次の数字
        right = left ^ center

        # 検索
        rcount = c.get(right, -1)
        if rcount <= 0:
            dprint("break", rcount)
            print("No")
            return

        dprint("found", right, rcount)

        # update
        c[right] = c[right] - 1
        left = center
        center = right

        cnt += 1
        dprint("next", cnt, left, center)

    if start ^ left == center:
        print("Yes")
    else:
        dprint("break", start, left, center)
        print("No")


solve()

Submission status: Runtime Error

Solution code:
# 1.Nが三の倍数でない場合、全てが0でなければならない.(総排他的論理和が各数と等しくならねばならず、その中でa_(i-1)+a_(i+1)=a_iとなるのは0のみ)
# 2.Nが3の倍数の場合、a,b,a+bの三種類の数字で構成されていなければならず、かつそれであればよい。

N = int(input())
if(N%3 == 0):
    input_dict = {}
    for i in map(int, input().split()):
        if(i in input_dict):
            input_dict[i] += 1
        else:
           input_dict[i] = 1
    num_count = len(input_dict.keys())
    if(num_count > 3 ):
        print("No")
    elif(num_count == 2):
        if(0 in input_dict and input_dict[0] == N//3):
            print("Yes")
        else:
            print("No")
    elif(num_count == 1):
        if(0 in input_dict):
            print("Yes")
        else:
            print("No")
    else:
        if(input_list[0] ^ input_list[1] == input_list[2]):
            print("Yes")
        else:
            print("No")
else:
    for i in map(int, input().split()):
        if(i != 0):
            print("No")
            break
    else:
        print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
aa = list(map(int, input().split()))
b = list(map(bin, a))
 
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: Runtime Error

Solution code:
import sys

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

for a in A:
  if a in dict.keys():
    dict[a] = dict[a] + 1
  else:
    dict[a] = 1

if len(list(dict.keys())) > 3:
  print('No')
  sys.exit()

keys=list(dict.keys())
vals=set(dict.values())

if len(vals)> 1:
  print('No')
  sys.exit()
  
a0=keys[0]
a1=keys[1]
a2=''
b0=bin(a0)[2:]
b1=bin(a1)[2:]
if len(b0)<len(b1):
  b0,b1=b1,b0
b1=b1.zfill(len(b0))
for s0,s1 in zip(b0,b1):
  a2 = a2 + str( int(s0)^int(s1) )
a2=int(a2,2)

if a2!=keys[2]:
  print('No')
  sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
def calc(N, A):
    _exist = False
    counter = {}
    for a in A:
        counter[a] = 1 + (counter[a] if a in counter else 0)
    keys = counter.keys()
    values = counter.values()
    d = max(values) - min(values)
    if (N % 3 == 0 and len(counter) == 3 and d == 0):
        _exist = keys[0] ^ keys[1] == keys[2]
    else:
        _exist = 0 in counter and counter[0] == N
    print('Yes' if _exist else 'No')


N = int(input())
A = [int(s) for s in input().split(' ')]
calc(N, A)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
li = list(map(int,input().split()))
flag = "Yes"
if(n % 3 != 0):
  flag = "No"
li_uniq = list(set(li))
if(len(li_uniq) != 3):
  flag = "No"
check = li_uniq[0] ^ li_uniq[1]
if(check != li_uniq[2]):
  flag = "No"
a = li.count(li_uniq[0])
b = li.count(li_uniq[1])
c = li.count(li_uniq[2])
if(not(a == b == c)):
  flag = "No"
print(flag)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

a = sorted(a)
flag = True
first = a.pop(0)
pp = first
p = a.pop(0)
for x in a:
    if x ^ pp != p:
        flag = False
        break
    pp = p
    p = x
if first ^ pp != p:
    flag = False

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
from collections import deque

N = int(input())

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

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


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

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

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
l = []
n = 0


def abc(inp, rest, dic, idx):
    if len(rest) == 0:
        if l[dic[n - 1]] ^ l[dic[1]] == l[dic[0]]:
            return True
        else:
            return False
    for i in rest:
        if l[i] ^ l[dic[idx - 1]] == inp:
            cur_rest = rest[:]
            cur_rest.remove(i)
            cur_dic = dic.copy()
            cur_dic[idx + 1] = i
            if abc(l[i], cur_rest, cur_dic, idx + 1):
                return True
    return False


if __name__ == '__main__':
    n = int(input())
    l = list(map(int, input().split()))
    rest = [i for i in range(0, n)]
    dic = {}
    rest.remove(0)
    dic[1] = 0
    for i in range(1, n):
        cur_rest = rest[:]
        cur_rest.remove(i)
        cur_dic = dic.copy()
        cur_dic[0] = i
        if abc(l[0], cur_rest, cur_dic, 1):
            print("Yes")
            exit()
    print("No")

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
flag = True
if len(set(data)) != 3:
    flag = False
syugo = list(set(data))
if syugo[0]^syugo[1] != syugo[2]:
    flag = False

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

Submission status: Runtime Error

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

kumi = list(itertools.permutations(in_list))
print(kumi)
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: Runtime Error

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

def answer(result):
    print(*result)

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

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


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

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

Submission status: Runtime Error

Solution code:
N = int(input())
num_arr = sorted([int(i) for i in input().split()])
u_arr = list(set(num_arr))


if 0 in num_arr:
  if u_arr == 0:
    print("Yes")
  else:
    if len(u_arr) != 2:
      print("No")
    else:
      if num_arr == [0]*(N//3) + [u_arr[1]]*(N//3)*2:
        print("Yes")
      else:
        print("No")

    
else:
  if N%3 != 0:
    print("No")
  else:
    if num_arr == u_arr*(N//3):
      print("Yes")
    else:
      print("No")

Submission status: Runtime Error

Solution code:
import collections



def XORC(a,b,p):
    for i in range(len(a)):
        if (int(a[i])+int(b[i]))%2 == int(p[i]):
            continue
        else:
            return False
        
    return True
            
def Solve():
    N=int(input())
    AL=[("0"*34+bin(int(x))[2:])[-33:] for x in input().split()]

    ALC=collections.Counter(AL)

    keys=list(ALC.keys())
    vals=list(ALC.values())

    if len(keys)>3:
        stop
        return 'No'
    if len(keys)==1:
        stop
        if "1" in keys[0]:
            return 'No'
        return 'Yes'
    
    if len(keys)==2:
        if "1" in keys[0] and "1" in keys[1]:
            return 'No'
        
        if vals[0]==vals[1]*2 and "1" not in keys[0]:
            return 'Yes'
        
        if vals[0]*2==vals[1] and "1" not in keys[1]:
            return 'Yes'
        
        return 'No'
    if len(keys)==3:
        stop
        if vals[0]==vals[1]==vals[2]:
            if XORC(keys[0],keys[1],keys[2]) and XORC(keys[0],keys[2],keys[1]) and XORC(keys[1],keys[2],keys[0]):
                return 'Yes'
        
        return 'No'
print(Solve())

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import itertools
N = int(input())
a = list(map(int,input().split()))
for i in itertools.permutations(a):
    ans = "Yes"
    for j in range(1,N):
        if abs(a[j] - a[j-2]) != a[j - 1]:
            ans = "No"
            break
    if ans == "Yes":
        print(ans)
        exit()
    if i > 100:
        print(ans)
        exit()
print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=set(a)
l=len(b)
if l==1:
  if a[0]==0:print("Yes")
  else:print("No")
  exit()
elif l==2 and 0 in b and n%3==0:
  if a[n//2-1]!=a[n//2]:print("Yes")
  else:print("No")
elif l!=3:print("No");exit()
if n%3!=0:print("No");exit()
def ecount(X):
  c,ans=1,[]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans.append(c);c=1
  ans.append(c)
  return ans
d=sorted(ecount(a))
if b.pop()^b.pop()==b.pop() and d[0]==d[2]:print("Yes")
else:print("No")

Submission status: Runtime Error

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

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

for num in nums:
    if start ^ num in nums:
        next = num
        first = start

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(s) for s in input().split(" ")]
a_set = set(a)
n_set = len(a_set)

if (n < 3):
  ans = False
else:
  ans = False
  for i in range(n_set):
    for j in range(i + 1, n_set):
      if a_set[i] ^ a_set[j] in a_set:
        ans = True
        break
    if ans:
      break

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

Submission status: Runtime Error

Solution code:
import random
a = random.randint(0,1)
N = input()
if(a/2==0 and N<10000):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def calc(N, A):
    _exist = False
    counter = {}
    for a in A:
        counter[a] = 1 + (counter[a] if a in counter else 0)
    keys = counter.keys()
    values = counter.values()
    d = max(values) - min(values)
    if (N % 3 == 0 and d == 0):
        _exist = keys[0] + keys[1] == keys[2]
    else:
        _exist = 0 in counter and counter[0] == N
    print('Yes' if _exist else 'No')


N = int(input())
A = [int(s) for s in input().split(' ')]
calc(N, A)

Submission status: Runtime Error

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

def answer(result):
    print(*result)

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

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


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

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

Submission status: Runtime Error

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = False

def check(i,j):
    firsti = i
    c[i] -= 1
    c[j] -= 1
    for k in range(len(a)-3):
        if c[i^j] == 0:
            return False
        i = j
        j = i^j
        c[i^j] -= 1
    if i^j == firsti
    return True

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
figure = list(map(int, input().split()))
cnt=0#最大n-2
loop_n = n
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if figure[i] ^ figure[j] == figure[k]:
        cnt+=1
        number1=figure[j]
        number2=figure[k]
        lastnumber=figure[i]
        figure.remove(figure[i])
        figure.remove(figure[j-1])
        figure.remove(figure[k-2])
        loop_n-=3
        i, j, k=n,n,n
if n != loop_n:  
  for i in range(0,loop_n):
    now = number1^number2
    for j in range(0,loop_n):
      if now == figure[j]:
        cnt+=1
        loop_n -=1
        number1, number2 = numbwe2, figure[j]
        figure.remove(j)
        i, j=-1
if(n-2)==cnt:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
num_arr = sorted([int(i) for i in input().split()])
u_arr = list(set(num_arr))


if 0 in num_arr:
  if u_arr == 0:
    print("Yes")
  else:
    if len(u_arr) != 2:
      print("No")
    else:
      if u_arr == [0]*(N//3) + [u_arr[1]]*(N//3)*2:
        print("Yes")
      else:
        print("No")

    
else:
  if N%3 != 0:
    print("No")
  else:
    if num_arr == u_arr*(N//3):
      print("Yes")
    else:
      print("No")

Submission status: Runtime Error

Solution code:
from sys import stdin
n=int(stdin.readline())
l=map(int,stdin.readline().split())
ans=0
for i in l:
  ans^=i
if ans:
  stdout.write("No")
else:
  stdout.write("Yes")

Submission status: Runtime Error

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = False

def check(i,j):
    firsti = i
    c[i] -= 1
    c[j] -= 1
    for k in range(len(a)-3):
        if c[i^j] == 0:
            return False
        i = j
        j = i^j
        c[i^j] -= 1
    if i^j = firsti
    return True

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

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

Submission status: Runtime Error

Solution code:
import copy
import sys

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

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

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

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

# # 次のラクダへ、何かを乗せる
for hi in range(0, n - 1):
    rakuda_2 = hats[hi]
    new_hats = copy.copy(hats)
    new_hats.pop(hi)
    cehck_hats(rakuda_1, rakuda_2, new_hats)

# どの組み合わせもダメだった場合
print('No')
sys.exit()

Submission status: Runtime Error

Solution code:
import sys

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

Submission status: Runtime Error

Solution code:
N = int(input())
num_arr = sorted([int(i) for i in input().split()])
u_arr = list(set(num_arr))


if 0 in num_arr:
  if u_arr == 0:
    print("Yes")
  else:
    N%3 != 0:
      print("No")
    else:
      if len(u_arr) != 2:
        print("No")
      else:
        if u_arr == [0]*(N//3) + [u_arr[1]]*(N//3)*2:
          print("Yes")
        else:
          print("No")

    
else:
  if N%3 != 0:
    print("No")
  else:
    if num_arr == u_arr*(N//3):
      print("Yes")
    else:
      print("No")

Submission status: Runtime Error

Solution code:
def main(N):
	a = list(map(int, input().split()))
	if a.count(0) == N:
		print("Yes")
		return
	if N%3 != 0:
		print("No")
		return
	d={}
	for i in a:
		if i in d:
			d[i] = d[i] + 1
		else:
			d[i] = 1
	if 0 in d.keys():
		if d[0] == N//3:
			for i in d.keys():
				if i == 0:
					continue
				elif d[i] % 2 != 0:
					print("No")
					return
			print("Yes")
		else:
			print("No")
	else:
		for i in d.values():
			if i != N//3:
				print("No")
				return
		lst = d.keys()
		if (lst[0]^lst[2]!=lst[1]) or (lst[0] != lst[1]^lst[2]) or(lst[2]!=lst[1]^lst[0]):
			print("No")
			return
		print("Yes")
	return
		
	return

main(int(input()))

Submission status: Runtime Error

Solution code:
def resolve():
    n = int(input())
    a = list(map(int,input().split()))
    sa = list(set(a))
    num = {}

    if sum(sa)==0:
        print("Yes")
        exit(0)
    if (n%3)!=0:
        print("No")
        exit(0)
    for i in a:
        num[i] = num.get(i,0) + 1
    
    OK = False
    if len(num)>=3 and len(num)%3==0:
        i,j,k = num.values()
        if i==j and j==k and sa[0]==sa[1]^sa[2]:
            OK = True
    if(OK):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
N = int(input())
num_arr = sorted([int(i) for i in input().split()])
u_arr = list(set(num_arr))


if 0 in num_arr:
  if u_arr == 0:
    print("Yes")
  else:
    if len(u_arr) != 2:
      print("No")
    else:
      if u_arr == [0]*(N//3) + [u_arr[1]]*(N//3)*2:
        print("Yes")
      else:
        print("No")

    
else:
  if N%3 != 0:
    print("No")
  else:
    if num_arr == u_arr*(N//3):
      print("Yes")
    else:
      print("No")

Submission status: Runtime Error

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

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

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