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:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    zero_count = 0
    ok = False
    dic = {}
    for a in A:
        if a == 0:
            zero_count += 1
        else:
            if a in dic:
                dic[a] += 1
            else:
                dic[a] = 1
    # print(dic, zero_count)
    if len(dic) == 3:
        if zero_count == 0:
            tmp = list(dic.values())
            # print(tmp)
            if tmp[0] == tmp[1] and tmp[1] == tmp[2]:
                key = list(dic.keys())
                tmp = key[0]
                tmp ^= key[1]
                tmp ^= key[2]
                if tmp == 0:
                    print("Yes")
                    return
    if len(dic) == 1:
        if n%3 == 0:
            if zero_count == N/3:
                print("Yes")
                return
    if zero_count == N:
        print("Yes")
        return
    print("No")




if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

# size = 3
# nums = [0, 0, 0]

if size % 3 != 0:
  print("No")
  quit()

numu = list(set(nums))
if len(numu) == 1 and numu[0] == 0:
  print("Yes")
  quit()

if len(numu) == 2 and numu.count(0) > 0:
  print("Yes")
  quit()


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

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

print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
a = input()
b = "0==(" + a.replace(" ","^") + ")"
#print(b)
if eval(b):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
std_n = int(input())
std_list = tuple(map(int, input().split()))
std_set = set(std_list)

if std_set == {0}:
    print("Yes")
elif len(std_set) == 2:
    if 0 in std_set:
        if std_list.count(0) * 3 == std_n:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(std_set) == 3:
    a, b, c = tuple(std_set)
    if (std_list.count(a) == std_list.count(b)) and (std_list.count(b) == std_list.count(c)):
        if int(str(int(format(a, "b")) ^ int(format(b, "b"))), 2) == c:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline


def check(n, nums):
    kind = set(nums)

    if len(kind) > 3:
        return False

    if len(kind) == 1 and 0 in kind:
        return True
    if n % 3 != 0:
        return False
    if len(kind) == 3:
        if len(set([nums.count(k) for k in kind])) != 1:
            return False
        kind = list(kind)
        if kind[0] ^ kind[1] ^ kind[2] == 0:
            return True
        else:
            return False
    else:
        a, b = kind
        a_c, b_c = nums.count(a), nums.count(b)
        if 0 not in kind:
            return False
        elif n / 3 != nums.count(0):
            return False
        else:
            return True


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print("Yes" if check(n, a_list) else "No")


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

std_n = int(sys.stdin.readline().strip())
std_list = tuple(map(int, sys.stdin.readline().strip().split()))
std_set = set(std_list)

if std_set == {0}:
    print("Yes")
elif len(std_set) == 2:
    if 0 in std_set:
        if std_list.count(0) * 3 == std_n:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(std_set) == 3:
    a, b, c = tuple(std_set)
    if (std_list.count(a) == std_list.count(b)) and (std_list.count(b) == std_list.count(c)):
        if int(str(int(format(a, "b")) ^ int(format(b, "b"))), 2) == c:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
a = input()
#print("0==(" + a.replace(" ","^") + ")")
if eval("0==(" + a.replace(" ","^") + ")"):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
if n % 3 != 0:
    print("No")
    quit()
lc = [0] * (10**5+1)
for i in l:
    lc[i] += 1
cs = [(i, n) for i, n in enumerate(lc) if n]
if len(cs) != 3:
    print("No")
    quit()
a = l[0]
for i in range(1, n):
    b = l[i]
    c = a ^ b
    if (
            lc[a] == n / 3 and
            lc[b] == n / 3 and
            lc[c] == n / 3
            ):
        print("Yes")
        quit()
print("No")

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

def check(N, a_list):
    mc = Counter(a_list).most_common()
    n = len(mc)
    if n == 1:
        if mc[0][0] == 0:
            print('Yes')
            return
    elif n == 2:
        if mc[0][1] == 2*N // 3 and mc[1][0] == 0:
            print('Yes')
            return
    elif n == 3:
        if mc[0][1] == mc[1][1] == mc[2][1] and mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0:
            print('Yes')
            return
    print('No')

check(N, a_list)

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline


def check(n, nums):
    kind = set(nums)

    if len(kind) not in (1, 2, 3):
        return False

    if len(kind) == 1 and 0 in kind:
        return True
    if n % 3 != 0:
        return False
    if len(kind) == 3:
        if len(set([nums.count(k) for k in kind])) != 1:
            return False
        kind = list(kind)
        if kind[0] ^ kind[1] ^ kind[2] == 0:
            return True
        else:
            return False
    else:
        a, b = kind
        a_c, b_c = nums.count(a), nums.count(b)
        if 0 not in kind:
            return False
        elif n / 3 != nums.count(0):
            return False
        else:
            return True


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print("Yes" if check(n, a_list) else "No")


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
print(n)
print(l)
if n % 3 != 0:
    print("No")
    quit()
lc = [0] * (10**5+1)
for i in l:
    lc[i] += 1
cs = [(i, n) for i, n in enumerate(lc) if n]
print(cs)
if len(cs) != 3:
    print("No")
    quit()
a = l[0]
for i in range(1, n):
    b = l[i]
    c = a ^ b
    print(a, b, c)
    if (
            lc[a] == n / 3 and
            lc[b] == n / 3 and
            lc[c] == n / 3
            ):
        print("Yes")
        quit()
print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
if eval("0==("+input().replace(" ","^")+")"):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

if n%2 == 0:
	print(['No','Yes'][all([e == a[0] for e in a[1:] and a[0] == 0])])
else:
	a = sorted(a)
	b = [a[0]]
	for i in range(1,n):
		b.append(a[0]^a[i])
	b = sorted(b)
	c = a[-1::-1]
	d = [c[0]]
	for i in range(1,n):
		d.append(c[0]^c[i])
	c = sorted(c)
	d = sorted(d)
	print(['No','Yes'][a==b and c==d])

Submission status: Runtime Error

Solution code:
n = int(input())
if eval("0=="+input().replace(" ","^")):
  print("Yes")
else:
  print("No")



#lst = list(map(int,input().split()))
"""
flg = 1
sum = lst[-1]
for i in range(len(lst)):
  if i == lst[-1]:
    break
  sum = sum ^ lst[i]
  if i+1 == len(lst):
    if bin(lst[i]) != bin(lst[i-1] ^ lst[0]):
      flg = 0
      #break
  elif bin(lst[i]) != bin(lst[i-1] ^ lst[i+1]):
    flg = 0
    #break
if sum == 0:
  print("Yes")
else:
  print("No")
#elif flg == 1:
#  print("Yes")
"""

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

if n%2 == 0:
	print(['No','Yes'][all([e == a[0] for e in a[1:] and a[0] == 0])])
else:
	a = sorted(a)
	b = [a[0]]
	for i in range(1,n):
		b.append(a[0]^a[i])
	b = sorted(b)
	
    c = a[-1::-1]
	d = [c[0]]
	for i in range(1,n):
		d.append(c[0]^c[i])
	c = sorted(c)
	d = sorted(d)
	print(['No','Yes'][a==b and c==d])

Submission status: Runtime Error

Solution code:
n = int(input())
if eval("0="+input().replace(" ","^")):
  print("Yes")
else:
  print("No")



#lst = list(map(int,input().split()))
"""
flg = 1
sum = lst[-1]
for i in range(len(lst)):
  if i == lst[-1]:
    break
  sum = sum ^ lst[i]
  if i+1 == len(lst):
    if bin(lst[i]) != bin(lst[i-1] ^ lst[0]):
      flg = 0
      #break
  elif bin(lst[i]) != bin(lst[i-1] ^ lst[i+1]):
    flg = 0
    #break
if sum == 0:
  print("Yes")
else:
  print("No")
#elif flg == 1:
#  print("Yes")
"""

Submission status: Runtime Error

Solution code:
import sys
inputs = sys.stdin.readlines()

from collections import Counter

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

def check(N, a_list):
    mc = Counter(a_list).most_common()
    n = len(mc)
    if n == 1:
        if mc[0][0] == 0:
            print('Yes')
            return
    elif n == 2:
        if mc[0][1] == 2*N // 3 and most_common[1][0] == 0:
            print('Yes')
            return
    elif n == 3:
        if mc[0][1] == mc[1][1] == mc[2][1] and mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0:
            print('Yes')
            return
    print('No')

check(N, a_list)

Submission status: Runtime Error

Solution code:
n = int(input())
if eval(input().replace(" ","^")+"==0"):
  print("Yes")
else:
  print("No")
#lst = list(map(int,input().split()))

"""
flg = 1
sum = lst[-1]
for i in range(len(lst)):
  if i == lst[-1]:
    break
  sum = sum ^ lst[i]
  if i+1 == len(lst):
    if bin(lst[i]) != bin(lst[i-1] ^ lst[0]):
      flg = 0
      #break
  elif bin(lst[i]) != bin(lst[i-1] ^ lst[i+1]):
    flg = 0
    #break
if sum == 0:
  print("Yes")
else:
  print("No")
#elif flg == 1:
#  print("Yes")
"""

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
setA = set(A)
listSetA = list(setA)

if A == [0 for i in range(n)]:
    print("Yes")
elif len(setA) == 2 and listSetA[0] == 0 and 2*A.count(0) == A.count(listSetA[1])
elif len(setA) == 3 and listSetA[0] ^ listSetA[1] == listSetA[2] and A.count(listSetA[0]) == A.count(listSetA[1]) == A.count(listSetA[2]):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

for i in range(N):
    aa = aa ^ a[i]
    
if aa == 0:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
_,a=open(0);print('YNeos'[eval(a.replace(' ','^'))>0::2])

Submission status: Runtime Error

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

def search(this, hats, result):
    if len(hats) == 1:
        # print('saigo!')
        if this ^ hats[0] == result[0]:
            print('Yes')
            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(0))
    # print(result)
    search(result[0], hats, result)
    print('No')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    kind = set(a_list)
    # 0 0 0
    # 1 0 1 1 0 1
    # 1 2 3
    if len(kind) not in (1, 2, 3):
        print("No")
        return
    if len(kind) == 1 and 0 in kind:
        print("Yes")
        return
    if n % 3 != 0:
        return "No"
    if len(kind) == 3:
        if len(set([a_list.count(k) for k in kind])) != 1:
            print("No")
            return
        kind = list(kind)
        if kind[0] ^ kind[1] ^ kind[2] == 0:
            print("Yes")
        else:
            print("No")
    else:
        a, b = kind
        a_c, b_c = a_list.count(a), a_list.count(b)
        if 0 not in kind:
            print("No")
            return
        elif n / 3 != a_list.count(0):
            print("No")
        else:
            print("Yes")


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n,a=int(input()),sorted(list(map(int,input().split())));b=set(a);l=len(b)
if l!=3:print("Yes"if(l==1and a[0]==0)or(l==2and a[0]==0and n%3==0and a[n//3-1]!=a[n//3])else"No")
elif:print("Yes"if b.pop()^b.pop()==b.pop()and n%3==0and a[n//3-1]!=a[n//3]and a[n//3*2-1]!=a[n//3*2]else"No")

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
l1=set(l)
l2=[]
for i in l:
  d[i]+=1
if len(d)==1:
  if l[0]==0:
    print("Yes")
  else:
    print("No")
elif len(d)==2:
  for i in l1:
    l2.append(i)
  bool1=True
  if d[l2[0]]==d[l2[1]]*2:
    a=l2[0]
    b=l2[0]
    c=l2[1]
  elif d[l2[0]]*2==d[l2[1]]:
    a=l2[0]
    b=l2[1]
    c=l2[1]
  else:
    boo11=False
  if bool1:
    l2=[a,b,c]
    l2=sorted(l2)
    a=l2[2]
    b=l2[1]
    c=l2[0]
    la=[]
    lb=[]
    lc=[]
    while a!=0:
      la.append(a%2)
      a=a//2
    while b!=0:
      lb.append(b%2)
      b=b//2
    while c!=0:
      lc.append(c%2)
      c=c//2
    if lc==[]:
      lc=[0]
    if lb==[]:
      lb=[0]
    while len(lb)<len(la):
      lb.append(0)
    while len(lc)<len(la):
      lc.append(0)
    bool1=True
    for i in range(len(la)):
      if la[i]+lb[i]+lc[i]==1 or la[i]+lb[i]+lc[i]==3:
        bool1=False
    if bool1:
      print("Yes")
    else:
      print("No")
  else:
    print("No")  
elif len(d)==3:
  for i in l1:
    l2.append(i)
  l2=sorted(l2)
  if d[l2[0]]==d[l2[1]] and d[l2[1]]==d[l2[2]]:
    a=l2[2]
    b=l2[1]
    c=l2[0]
    la=[]
    lb=[]
    lc=[]
    while a!=0:
      la.append(a%2)
      a=a//2
    while b!=0:
      lb.append(b%2)
      b=b//2
    while c!=0:
      lc.append(c%2)
      c=c//2
    if lc==[]:
      lc=[0]
    while len(lb)<len(la):
      lb.append(0)
    while len(lc)<len(la):
      lc.append(0)
    bool1=True
    for i in range(len(la)):
      if la[i]+lb[i]+lc[i]==1 or la[i]+lb[i]+lc[i]==3:
        bool1=False
    if bool1:
      print("Yes")
    else:
      print("No")           
  else:
    print("No")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
l1=set(l)
l2=[]
for i in l:
  d[i]+=1
if len(d)==1:
  if l[0]==0:
    print("Yes")
  else:
    print("No")
elif len(d)==2:
  for i in l1:
    l2.append(i)
  bool1=True
  if d[l2[0]]==d[l2[1]]*2:
    a=l2[0]
    b=l2[0]
    c=l2[1]
  elif d[l2[0]]*2==d[l2[1]]:
    a=l2[0]
    b=l2[1]
    c=l2[1]
  else:
    boo11=False
  if bool1:
    l2=[a,b,c]
    l2=sorted(l2)
    a=l2[2]
    b=l2[1]
    c=l2[0]
    la=[]
    lb=[]
    lc=[]
    while a!=0:
      la.append(a%2)
      a=a//2
    while b!=0:
      lb.append(b%2)
      b=b//2
    while c!=0:
      lc.append(c%2)
      c=c//2
    while len(lb)<len(la):
      lb.append(0)
    while len(lc)<len(la):
      lc.append(0)
    bool1=True
    for i in range(len(la)):
      if la[i]+lb[i]+lc[i]==1 or la[i]+lb[i]+lc[i]==3:
        bool1=False
    if bool1:
      print("Yes")
    else:
      print("No")
  else:
    print("No")  
elif len(d)==3:
  for i in l1:
    l2.append(i)
  l2=sorted(l2)
  if d[l2[0]]==d[l2[1]] and d[l2[1]]==d[l2[2]]:
    a=l2[2]
    b=l2[1]
    c=l2[0]
    la=[]
    lb=[]
    lc=[]
    while a!=0:
      la.append(a%2)
      a=a//2
    while b!=0:
      lb.append(b%2)
      b=b//2
    while c!=0:
      lc.append(c%2)
      c=c//2
    while len(lb)<len(la):
      lb.append(0)
    while len(lc)<len(la):
      lc.append(0)
    bool1=True
    for i in range(len(la)):
      if la[i]+lb[i]+lc[i]==1 or la[i]+lb[i]+lc[i]==3:
        bool1=False
    if bool1:
      print("Yes")
    else:
      print("No")           
  else:
    print("No")
else:
  print("No")

Submission status: Runtime Error

Solution code:
_ = input()
input_num = [int(i) for i in input().split(" ")]
input_size = len(input_num)-1

if input_size < 2:
  print("No")
if sum(input_num)==0:
  print("Yes")
  break
for i in range(len(input_num)):
    left = i-1
    right = i+1
    if left < 0:
        left = input_size
    if right > input_size:
      right = 0
#     print(input_num[left])
#     print(input_num[right])
    if input_num[left]^input_num[right] == input_num[i]:
        continue
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Runtime Error

Solution code:

import numpy as np 

def make_bit(A):
    arr = np.zeros(31)
    i = 30
    while A:
        arr[i] = A % 2
        A = A // 2
        i -= 1

    return arr

def return_first_second_third(a_lst):
    first = [a_lst[0], 0]
    second = [-1, -1]
    third = [-1, -1]
    i = 0
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            second[0] = a_lst[i+1]
            second[1] = i+1
            i += 1
            break
        else:
            i += 1
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            third[0] = a_lst[i+1]
            third[1] = i+1
            i += 1
            break
        else:
            i += 1
    
    return first, second, third


N = int(input())

a_lst = list(map(int, input().split()))
a_lst.sort()
first, second, third = return_first_second_third(a_lst)
a_lst.reverse()

done = False
if second[0] == -1: # 全ての数が同じとき
    done = True
    if first[0] == 0: # 全ての数がゼロの時
        print("Yes")
    else:
        print("No")
elif third[0] == -1:    # 数が2種類だけの時
    done = True
    if N % 2 == 0 and second[1] == N // 2 and first[1] == 0:
        print("Yes")
    else:
        print("No")
elif N % 3 == 0 and N != 3 and second[1] == N // 3 and third[1] == N * 2 // 3:
    a_lst = [ a_lst[0], a_lst[second[1]], a_lst[third[1]] ]


if not done:
    if len(A_lst) == 3:

        a1 = make_bit(a_lst[0])
        a2 = make_bit(a_lst[1])
        a3 = make_bit(a_lst[2])
        bits_arr = np.array([a1, a2, a3])

        judge = True
        for i in range(31):
            if bits_arr[0][i] == bits_arr[1][i] and bits_arr[2][i] == 1:
                judge = False
                break

            elif bits_arr[0][i] != bits_arr[1][i] and bits_arr[2][i] == 0:
                judge = False
                break
                
        if judge:
            print("Yes")
        else:
            print("No")


    else:
        print("No")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
 
import sys
 
n= int(sys.stdin.readline())
ai  = [ int(x) for x in sys.stdin.readline().split() ]

mm = dict()
for i,x in enumerate(ai):
    mm[x]= mm.get(x,0) + 1
#
ans= "No"
even= list(filter(lambda i:i % 2 ==0, ai))
odd = len(list(filter(lambda i:i % 2 ==1, ai)))
f= ai.index(max(even))
ll = len(bin(ai[f]))-2
second= []
for i in range(n):
    if i==f: continue
    a= ai[i]
    if len(bin(a))-2!=ll: continue
    if odd:
        if a%2==1: second.append(a)
    else:
        if a%2==0: second.append(a)
#
for s in second:
    tmp= [ai[f],s]
    cnt= { ai[f]:1 }
    cnt[s]= cnt.get(s,0)+1
    for _ in range(2,n):
        nn = tmp[-1] ^ tmp[-2]
        cnt[nn]= cnt.get(nn,0) + 1
        if cnt[nn]>mm.get(nn,0): break
        tmp.append(nn)
    #
    if len(tmp)==n:
        x,y,z,w = tmp[-2],tmp[-1],tmp[0],tmp[1]
        if x==y^z and y==z^w:
            ans="Yes"
            break
#
print( ans )

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
l1=set(l)
l2=[]
for i in l:
  d[i]+=1
if len(d)==1:
  if l[0]==0:
    print("Yes")
  else:
    print("No")
elif len(d)==2:
  for i in l1:
    l2.append(i)
  bool1=True
  if d[l2[0]]==d[l2[1]]*2:
    a=l2[0]
    b=l2[0]
    c=l2[1]
  elif d[l2[0]]*2==d[l2[1]]:
    a=l2[0]
    b=l2[1]
    c=l2[1]
  else:
    boo11=False
  if bool1:
    l2=sorted[a,b,c]
    a=l2[2]
    b=l2[1]
    c=l2[0]
    la=[]
    lb=[]
    lc=[]
    while a!=0:
      la.append(a%2)
      a=a//2
    while b!=0:
      lb.append(b%2)
      b=b//2
    while c!=0:
      lc.append(c%2)
      c=c//2
    while len(lb)<len(la):
      lb.append(0)
    while len(lc)<len(la):
      lc.append(0)
    bool1=True
    for i in range(len(la)):
      if la[i]+lb[i]+lc[i]==1 or la[i]+lb[i]+lc[i]==3:
        bool1=False
    if bool1:
      print("Yes")
    else:
      print("No")
  else:
    print("No")  
elif len(d)==3:
  for i in l1:
    l2.append(i)
  l2=sorted(l2)
  if d[l2[0]]==d[l2[1]] and d[l2[1]]==d[l2[2]]:
    a=l2[2]
    b=l2[1]
    c=l2[0]
    la=[]
    lb=[]
    lc=[]
    while a!=0:
      la.append(a%2)
      a=a//2
    while b!=0:
      lb.append(b%2)
      b=b//2
    while c!=0:
      lc.append(c%2)
      c=c//2
    while len(lb)<len(la):
      lb.append(0)
    while len(lc)<len(la):
      lc.append(0)
    bool1=True
    for i in range(len(la)):
      if la[i]+lb[i]+lc[i]==1 or la[i]+lb[i]+lc[i]==3:
        bool1=False
    if bool1:
      print("Yes")
    else:
      print("No")           
  else:
    print("No")
else:
  print("No")

Submission status: Runtime Error

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

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

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

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

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

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

Submission status: Runtime Error

Solution code:
def resolve():
    n = int(input())
    dataset = set(map(int, input().split()))
    
    xor = 0

    for i in range(n):
        xor ^= dataset[n]
    
    if xor == 0:
        print('Yes')
    else:
        print('No')

resolve()

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
l1=set(l)
l2=[]
for i in l:
  d[i]+=1
if len(d)==1:
  if l[0]==0:
    print("Yes")
  else:
    print("No")
elif len(d)==2:
  for i in l1:
    l2.append(i)
  bool1=True
  if d[l2[0]]==d[l2[1]]*2:
    a=l2[0]
    b=l2[0]
    c=l2[1]
  elif d[l2[0]]*2==d[l2[1]]:
    a=l2[0]
    b=l2[1]
    c=l2[1]
  else:
    boo11=False
  if bool1:
    la=[]
    lb=[]
    lc=[]
    while a!=0:
      la.append(a%2)
      a=a//2
    while b!=0:
      lb.append(b%2)
      b=b//2
    while c!=0:
      lc.append(c%2)
      c=c//2
    while len(lb)<len(la):
      lb.append(0)
    while len(lc)<len(la):
      lc.append(0)
    bool1=True
    for i in range(len(la)):
      if la[i]+lb[i]+lc[i]==1 or la[i]+lb[i]+lc[i]==3:
        bool1=False
    if bool1:
      print("Yes")
    else:
      print("No")
  else:
    print("No")  
elif len(d)==3:
  for i in l1:
    l2.append(i)
  l2=sorted(l2)
  if d[l2[0]]==d[l2[1]] and d[l2[1]]==d[l2[2]]:
    a=l2[2]
    b=l2[1]
    c=l2[0]
    la=[]
    lb=[]
    lc=[]
    while a!=0:
      la.append(a%2)
      a=a//2
    while b!=0:
      lb.append(b%2)
      b=b//2
    while c!=0:
      lc.append(c%2)
      c=c//2
    while len(lb)<len(la):
      lb.append(0)
    while len(lc)<len(la):
      lc.append(0)
    bool1=True
    for i in range(len(la)):
      if la[i]+lb[i]+lc[i]==1 or la[i]+lb[i]+lc[i]==3:
        bool1=False
    if bool1:
      print("Yes")
    else:
      print("No")           
  else:
    print("No")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import sys

std_n = int(sys.stdin.readline().strip())
std_tuple = tuple(map(int, sys.stdin.readline().strip().split()))
std_set = set(std_tuple)

if std_set == {0}:
    print("Yes")
elif len(std_set) == 2:
    if 0 in std_set:
        if std_tuple.count(0) * 3 == std_n:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(std_set) == 3:
    a, b, c = tuple(std_set)
    if (std_tuple.count(a) == std_tuple.count(b)) and (std_tuple.count(b) == std_tuple.count(c)):
        if int(str(int(format(a, "b")) ^ int(format(b, "b"))), 2) == c:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Submission status: Runtime Error

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

import numpy as np
import sys
import os

def solve():

    N, M = list(map(int, input().split()))
    graph = [[] for i in range(N)]

    for i in range(M):
        A, B = list(map(int, input().split()))
        graph[A-1].append(B-1)
        graph[B-1].append(A-1)

    result = []
    finish = [0 for i in range(N)]
    out_num = [0 for i in range(N)]

    loop = True
    while loop:
        loop = False
        for i in range(N):
            if len(graph[i]) == 0:
                continue
            if len(graph[i])==2:
                for g in graph[i]:
                    result.append([i,g])
                    graph[g].remove(i)
                    out_num[i] += 1
                else:
                    graph[i] = []
                    loop = True


    for g in graph:
        if len(g) != 0:
            print("-1")
            return

    for r in result:
        print(str(r[0]+1) + " " +str(r[1]+1))


solve()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
 
import sys
 
n= int(sys.stdin.readline())
ai  = [ int(x) for x in sys.stdin.readline().split() ]

mm = dict()
for i,x in enumerate(ai):
    mm[x]= mm.get(x,[])
    mm[x].append( i )
#
ans= "No"
even= list(filter(lambda i:i % 2 ==0, ai))
odd = len(list(filter(lambda i:i % 2 ==1, ai)))
f= ai.index(max(even))
ll = len(bin(ai[f]))-2
second= []
for i in range(n):
    if i==f: continue
    a= ai[i]
    if len(bin(a))-2!=ll: continue
    if odd:
        if a%2==1: second.append(i)
    else:
        if a%2==0: second.append(i)
#
for s in second:
    tmp= [f,s]
    for _ in range(2,n):
        nn = ai[tmp[-1]] ^ ai[tmp[-2]]
        i= -1
        for ii in mm.get(nn,[]):
            if not ii in tmp:
                i= ii
                break
        #
        if i>=0: tmp.append(i)
        else: break
    #
    if len(tmp)==n:
        x,y,z,w = ai[tmp[-2]],ai[tmp[-1]],ai[tmp[0]],ai[tmp[1]]
        if x==y^z and y==z^w:
            ans="Yes"
            break
#
print( ans )

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    kind = set(a_list)
    if len(kind) not in (1, 2, 3):
        print("No")
        return
    # 1 0 1
    # 1 2 3
    if len(kind) == 1 and 0 in kind:
        print("Yes")
        return
    elif len(kind) == 3:
        if n % 3 != 0 or len(set([a_list.count(k) for k in kind])) != 1:
            print("No")
            return
        kind = list(kind)
    else:
        a, b = kind
        a_c, b_c = a_list.count(a), a_list.count(b)
        if 0 not in kind or abs(a_c - b_c) > 1:
            print("No")
            return
        if a == 0:
            if a_c > b_c:
                print("No")
                return
            kind = [b, a, b]
        else:
            if b_c > a_c:
                print("No")
                return
            kind = [a, b, a]
    kind.extend([kind[0], kind[-1]])
    for i in range(3):
        if kind[i] != kind[i - 1] ^ kind[i + 1]:
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

for i in range(len(a)):
    if i == 0:
        if not a[-1] ^ a[i+1] == a[i]:
            print('No')
            break
    elif i == len(a)-1:
        if a[0] ^ a[-2] == a[i]:
            print('Yes')
            break
        else:
            print('No')
            break
    else:
        if not a[i-1] ^ a[i+1] == a[i]:
            print('No')
            break

Submission status: Runtime Error

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

hats = A[:]

h1 = hats[0]
 
def search(now1, now2, count, rem):
    now1, now2 = now2, now1^now2
    if now2 in rem:
        if now2 == h1:
            if count == N:
                return True
            else:
                return False
        else:
            return search(now1, now2, count+1, rem.discard(now1))
    else:
        return False
    

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

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

Submission status: Runtime Error

Solution code:
from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a_ = {int(x) for x in stdin.readline().rstrip().split()}
    count = 0


    for i in range(N):
        
        if  a[i-1] ^ a[i] in a_ :
            # a_.discard(a[i-1] ^ a[i])
        else:
            count += 1

    if count == 0:
        print("Yes")
    else:
        print("No")    


if __name__ == "__main__":
    main()