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:
#!/usr/bin/env python

import sys


def is_odd(x):
    return x%2==1

n= int(sys.stdin.readline())
ai  = [ int(x) for x in sys.stdin.readline().split() ]
#
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 i in range(2,n):
        nn = ai[tmp[-1]] ^ ai[tmp[-2]]
        i= 0
        while True:
            try:
                i= ai.index(nn,i)
                if i in tmp: i+=1
                else: break
            except:
                i= -1
                break
        if i==-1: break
        if nn in ai and not i in tmp:
            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 itertools

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

while True:
    f = False
    for c in itertools.combinations(a, 3):
        if c[0] ^ c[2] == c[1]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[1])
                f = True
        elif c[1] ^ c[2] == c[0]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[0])
                f = True
        elif c[1] ^ c[0] == c[2]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[2])
                f = True
    if f is False:
        print("No")
        exit()

Submission status: Runtime Error

Solution code:
std_n = int(input())
std_tuple = tuple(map(int, input().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) == 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:
import collections

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

value, count = list(a.keys()), list(a.values())

if len(value)<3:
    if len(value)==1
        if sum(a)==0:
            print('Yes')
        else:
            print('No')

    if len(value)==2
        if 0 in value:
            if count[0]==N/3 or count[1]==N/3:
                print('Yes')

if len(value)>=3:
    if count[0]+count[1]+count[2] != N:
        print('No')

    elif value[0]^value[1]^value[2] != 0:
        print('No')

    elif count[0]==count[1]==count[2]:
        print('Yes')

    else:
        print('No')

Submission status: Runtime Error

Solution code:
import collections 

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

counter = collections.Counter(input_list)


unique_list = list(counter.keys())
counts = list(counter.values())

if (all(num == 0 for num in unique_list)):
    print('Yes')
else:
    if n % 3 == 0:
        zero_count = counter[0] 
        if zero_count == n / 3 and len(unique_list) == 2:
            print('Yes')
        else: 
            if len(counter) != 3:
                print('No')
            if (unique_list[0] ^ unique_list[1] == unique_list[2]):
                if (all(counts[0] == num for num in counts)):
                    print('Yes')
            else:
                print('No')
    else:
        print('No')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=int(n/3)
if(a[0]==a[n-1] and a[0]==0):
    print('Yes')
elif(n%3!=0):
    print('No')
elif(a[0]==a[b-1] and a[b-1]!=a[b] and a[b]==a[n-1]):
    if(a[0]^a[n-1]^a[n-1]==0):
        print('Yes')
    else:
        print('No')
elif(a[0]==a[2*b-1] and a[2*b-1]!=a[2*b] and a[2*b]==a[n-1]):
    if(a[0]^a[0]^a[n-1]==0):
        print('Yes'):
    else:
        print('No')
else:
    if(a[0] == a[b-1] and a[b-1] != a[b]):
        if(a[b]==a[2*b-1] and a[2*b-1]!=a[2*b]):
            if(a[2*b]==a[n-1]):
                if(a[0]^a[b]^a[n-1]==0):
                    print('Yes')
                else:
                    print('No')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Submission status: Runtime Error

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

def xor(a,b):
    x = 0
    ma = max(len(str(a)),len(str(b)))
    for i in range(ma):
        a = str(a).rjust(ma,"0")
        b = str(b).rjust(ma,"0")     
        if a[-i-1] != b[-i-1]:
            x+= 10**i
        else:
            pass
    return x

bin_l = []
for i in lists:
    a = bin(i)
    b = int(a[2:])
    bin_l.append(b)

zero = bin_l.count(0)

if zero <=len(bin_l)//2:
    if 0 in bin_l :
        k = bin_l.remove(0)
        if len(k) == 2:
        
            if k[0] == k[1]:
                print("Yes")
            else:
                print("No")
        elif len(k)%3 ==0 and len(set(k)) == 3:
            l = list(set(k))
    
    
            if l[0] == xor(l[1],l[2]) and l[1] == xor(l[0],l[2]) and l[2] == xor(l[0],l[1]):
                print("Yes")
            else:
                print("No")
        else: print("No")
    else:
        if len(bin_l)%3 ==0 and len(set(bin_l)) == 3:
            l = list(set(bin_l))
    
    
            if l[0] == xor(l[1],l[2]) and l[1] == xor(l[0],l[2]) and l[2] == xor(l[0],l[1]):
                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()))
dic = {}
def main():
    if N%3 == 0:
        test = {}
        temp = []
        for a in A:
            if a not in dic:
                dic[a] = 1
                test[a] = N // 3
                temp.append(a)
            else:
                dic[a] += 1
            if test == dic and temp[0] ^ temp[1] == temp[2]:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
    return
main()

Submission status: Runtime Error

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

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) == 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:
import math

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

N = int(input())
A = list(map(int, input().split()))
B = A
B.append(B[0])
B.append(B[1])
if(check(B, N) == 1) :
  print("Yes")
else :
  for i in range(math.factorial(N)) :
    C = A.shuffle()
    C.append(C[0])
    C.append(C[1])
    if(check(C, N) == 1) :
      print("Yes")
      break
    elif(i == math.factorial - 1) :
      print("No")
      break
    else :
      pass

Submission status: Runtime Error

Solution code:
import copy
import numpy

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

first = a[0]

for j in range(N-1):
    second = a[j]
    for k in range(j+1,N-1):

        xor = bin(first ^ second)
        check = int(xor,2)

        if (check in a):
            a.remove(second)
            first = a[k]
            second = check
            if (len(a) == 2):
                print("Yes")
                exit()

        else:
            break

print("No")

Submission status: Runtime Error

Solution code:
import itertools

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

while True:
    for c in itertools.combinations(a, 3):
        if c[0] ^ c[2] == c[1]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[1])
        elif c[1] ^ c[2] == c[0]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[0])
        elif c[0] ^ c[1] == c[2]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[2])
    else:
        print("No")
        exit()

Submission status: Runtime Error

Solution code:
import math

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

N = int(input())
A = list(map(int, input().split()))
B = A
B.append(B[0])
B.append(B[1])
if(check(B, N) == 1) :
  print(Yes)
else :
  for i in range(math.factorial(N)) :
    C = A.shuffle()
    C.append(C[0])
    C.append(C[1])
    if(check(C, N) == 1) :
      print(Yes)
      break
    elif(i == math.factorial - 1) :
      print("No")
      break
    else :
      pass

Submission status: Runtime Error

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

if sum(input_num)%==0:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
figure = list(map(int, input().split()))
figure1 = []
n_loop = n
p=0
for j in range(1,n):
  figure1.append(figure[0]^figure[j])
for k in range(2,n-1):
  if figure1[0]==figure[k]:
    number1 = figure[0]
    number2 = figure[1]
    number3 = figure[k]
    figure.remove(figure[0])
    figure.remove(figure[0])
    figure.remove(figure[k-2])
    figure1 = []
    n_loop -=3
    p+=1
    break
if p == 1:
  for j in range(1,n_loop):
    now = number1^number2
    if(now==figure[j]):
      number1 = number2
      number2 = figure[j]
      p+=1
      figure.remove(figure[j])
      n_loop-=1
      j=1
if(p!=(n-2)):
  print("No")

Submission status: Runtime Error

Solution code:
import collections
import random
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==0:
  print('Yes')
elif n%3!=0:
  print('No')
elif len(set(a))!=3:
    print('No')
else:
  print('Yes')
else:
  a=list(set(a))
  for i in range(len(a)):
    a[i]=format(a[i],'020b')
  l=[0 for i in range(20)]
  for i in range(len(a)):
    for j in range(20):
      if a[i][j]=='1':
        l[j]+=1
  ct=0
  for j in range(20):
    if l[j]==2 or l[j]==0:ct+=1
  if ct==20:
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
import collections
import sys

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

value, count = list(a.keys()), list(a.values())

if sum(a)==0:
    print('Yes')
    sys.exit()

elif len(value)<2:
    print('No')
    sys.exit()

elif count[0]+count[1]+count[2] != N:
    print('No')

elif value[0]^value[1]^value[2] != 0:
    print('No')

elif count[0]==count[1]==count[2]:
    print('Yes')

else:
    print('No')

Submission status: Runtime Error

Solution code:
import collections
import random
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==0:
  print('Yes')
elif n%3!=0:
  print('No')
elif len(set(a))!=3:
    print('No')
  else:
    print('Yes')
else:
  a=list(set(a))
  for i in range(len(a)):
    a[i]=format(a[i],'020b')
  l=[0 for i in range(20)]
  for i in range(len(a)):
    for j in range(20):
      if a[i][j]=='1':
        l[j]+=1
  ct=0
  for j in range(20):
    if l[j]==2 or l[j]==0:ct+=1
  if ct==20:
    print('Yes')
  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:
  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:
n = int(input())
figure = list(map(int, input().split()))
figure1 = []
n_loop = n
p=0
for j in range(1,n):
  figure1.append(figure[0]^figure[j])
for k in range(2,n-1):
  if figure1[0]==figure[k]:
    number1 = figure[0]
    number2 = figure[1]
    number3 = figure[k]
    figure.remove(figure[0])
    figure.remove(figure[0])
    figure.remove(figure[k-2])
    figure1 = []
    n_loop -=3
    p+=1
    break
if p == 1:
  for j in range(1,n_loop):
    now = number1^number2
    if(now==figure[j]):
      number1 = number2
      number2 = figure[j]
      p+=1
      figure.remove(figure[k])
      n_loop-=1
      j=1
if(p!=(n-2)):
  print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        c = []
        for i in list(set(a)):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
f=0
a.sort()
for i in range(n):
    if(a[(i+1)%n]==a[i]):
        b.append(a[i+1])
a=list(set(a))+b
for i in range(len(a)):
  if(i==0):
    if(a[len(a)-1]^a[i+1]!=a[i]):
      f=1
      break
  else:
      if(a[(i+1)%len(a)]^a[i-1]!=a[i]):
        f=1
        break
  
if(f==0):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import copy
import numpy

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

first = a[0]

for j in range(N-1):
    second = a[j]
    while(len(a) > 2):

        xor = bin(first ^ second)
        check = int(xor,2)

        if (check in a):
            a.remove(second)
            first = a[j]
            second = check

        else:
            break

        if (len(a) == 2):
            print("Yes")
            exit()

print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
elif N % 3 == 0:
    if len(set(a)) == 3:
        c = []
        for i in list(set(a)):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3:
            #print('Yes')
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import copy
import numpy

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

first = List[0]

for j in range(N-1):
    second = a[j]
    while(len(a) > 2):

        xor = bin(first ^ second)
        check = int(xor,2)

        if (check in a):
            a.remove(second)
            first = a[j]
            second = check

        else:
            break

        if (len(a) == 2):
            print("Yes")
            exit()

print("No")

Submission status: Runtime Error

Solution code:
import itertools

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

Submission status: Runtime Error

Solution code:
import copy
import numpy

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

first = List[0]

for j in range(i+1,N-1):
    second = a[j]
    while(len(a) > 2):

        xor = bin(first ^ second)
        check = int(xor,2)

        if (check in a):
            a.remove(second)
            first = a[j]
            second = check

        else:
            break

        if (len(a) == 2):
            print("Yes")
            exit()

print("No")

Submission status: Runtime Error

Solution code:
N=int(input())
a=map(int, raw_input().split())
i=1
j=0
abin=list()
for i in range(N-1):
  if i>1:
    if i<N:
      if a[i]is not a[i+1]^a[i-1]:
        j=j+1
if a[N-1]is not a[N-2]^a[0]:
  j=j+1
if a[0]is not a[1]^a[N-1]:
  j=j+1
  
  
if j>=1:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
f=0
a.sort()
a=list(set(a))
for i in range(len(a)):
  if(i==0):
    if(a[len(a)-1]^a[i+1]!=a[i]):
      f=1
      break
  else:
      if(a[(i+1)%len(a)]^a[i-1]!=a[i]):
        f=1
        break
  
if(f==0):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import collections 

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

counter = collections.Counter(input_list)


unique_list = list(counter.keys())
counts = list(counter.values())

if (all(num == 0 for num in unique_list)):
    print('Yes')
else:
    if len(counter) != 3:
        print('No')
    if (unique_list[0] ^ unique_list[1] == unique_list[2]):
        if (all(counts[0] == num for num in counts)):
            print('Yes')
    print('No')

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
f=0
a.sort()
a=list(set(a))
for i in range(n):
  if(i==0):
    if(a[n-1]^a[i+1]!=a[i]):
      f=1
      break
  else:
      if(a[(i+1)%n]^a[i-1]!=a[i]):
        f=1
        break
  
if(f==0):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import copy
import numpy

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

for i in range(N-1):
    first = List[i]
    a = copy.deepcopy(List)
    
    for j in range(i+1,N-1):
        second = a[j]
        while(len(a) > 2):
            
            xor = bin(first ^ second)
            check = int(xor,2)

            if (check in a):
                a.remove(second)
                first = a[j]
                second = check

            else:
                break

            if (len(a) == 2):
                print("Yes")
                exit()

print("No")

Submission status: Runtime Error

Solution code:
import copy
n = int(input())
a = list(map(int,input().split()))
a2 = copy.copy(a)
c = 0
d = len(a)
for i in range(len(a)):
    if i+1 == len(a):
        ans = a[i-1] ^ a[0]
        if (ans in a2):
            try:
                a2.remove(ans)
            except e:
                break
        else:
            break
    else:
        ans = a[i-1] ^ a[i+1]
        if (ans in a2):
            try:
                a2.remove(ans)
            except e:
                break
        else:
            break
    c += 1
    print(a2)

if c == d:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N=int(input())
a=map(int,input().split())
j=0
abin=list()
for i in range(N-1):
  if i>1:
    if i<N:
      if a[i]is not a[i+1]^a[i-1]:
        j=j+1
if a[N-1]is not a[N-2]^a[0]:
  j=j+1
if a[0]is not a[1]^a[N-1]:
  j=j+1
  
  
if j>=1:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

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

def xor(a,b):
    x = 0
    ma = max(len(str(a)),len(str(b)))
    for i in range(ma):
        a = str(a).rjust(ma,"0")
        b = str(b).rjust(ma,"0")     
        if a[-i-1] != b[-i-1]:
            x+= 10**i
        else:
            pass
    return x

bin_l = []
for i in lists:
    a = bin(i)
    b = int(a[2:])
    bin_l.append(b)

zero = bin_l.count(0)

if zero <len(bin_l)//2:
    if 0 in bin_l :
        k = bin_l.remove(0)
        if len(k) == 2:
        
            if k[0] == k[1]:
                print("Yes")
            else:
                print("No")
        elif len(k)%3 ==0 and len(set(k)) == 3:
            l = list(set(k))
    
    
            if l[0] == xor(l[1],l[2]) and l[1] == xor(l[0],l[2]) and l[2] == xor(l[0],l[1]):
                print("Yes")
            else:
                print("No")
        else: print("No")
    else:
        if len(bin_l)%3 ==0 and len(set(bin_l)) == 3:
            l = list(set(bin_l))
    
    
            if l[0] == xor(l[1],l[2]) and l[1] == xor(l[0],l[2]) and l[2] == xor(l[0],l[1]):
                print("Yes")
            else:
                print("No")   
        else:
            print("No")     

else:
    print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
f=0

a.sort()

a=list(set(a))
for i in range(n):
  if(i==0):
    if(a[n-1]^a[i+1]!=a[i]):
      f=1
      break
  else:
      if(a[(i+1)%n]^a[i-1]!=a[i]):
        f=1
        break



if(f==0):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import sys
N, M = map(int, input().split())
if M & 1:
    print(-1)
    sys.exit()
Edge = [[] for _ in range(N)]
Dim = [0]*N
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    Edge[a].append(b)
    Edge[b].append(a)
    Dim[a] += 1
    Dim[b] += 1
Edge1 = Edge[:]
Dim1 = Dim[:] 
Ans = []
used = set()
for i in sorted(range(N), key = lambda x: Dim[x]):
    Edge[i].sort(key = lambda x: Dim[x], reverse = True)
    while Dim[i] > 1:
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j1 = Edge[i].pop()
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j2 = Edge[i].pop()
        Ans.append((i+1, j1+1))
        Ans.append((i+1, j2+1))
        Dim[i] -= 2
        Dim[j1] -= 1
        Dim[j2] -= 1
        used.add((i, j1))
        used.add((i, j2))
        used.add((j1, i))
        used.add((j2, i))
if not len(Ans) == M:
    Edge = Edge1[:]
    Dim = Dim1[:]
    Ans = []
    used = set()
    for i in sorted(range(N), key = lambda x: Dim[x]):
        Edge[i].sort(key = lambda x: Dim[x], reverse = True)
    while Dim[i] > 1:
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j1 = Edge[i].pop()
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j2 = Edge[i].pop()
        Ans.append((i+1, j1+1))
        Ans.append((i+1, j2+1))
        Dim[i] -= 2
        Dim[j1] -= 1
        Dim[j2] -= 1
        used.add((i, j1))
        used.add((i, j2))
        used.add((j1, i))
        used.add((j2, i))

for a in Ans:
    print(*a)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
f=0
b=[]
a.sort()
for i in range(n):
    if(a[(i+1)%n]==a[i]):
        b.append(a[i+1])
a=list(set(a))
for i in range(n):
  if(i==0):
    if(a[n-1]^a[i+1]!=a[i]):
      f=1
      break
  else:
      if(a[(i+1)%n]^a[i-1]!=a[i]):
        f=1
        break



if(f==0):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import collections 

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

if n % 3 != 0:
    print('No')

counter = collections.Counter(input_list)
if len(counter) != 3:
    print('No')

unique_list = list(counter.keys())
counts = list(counter.values())
if (unique_list[0] ^ unique_list[1] == unique_list[2]):
    if (all(counts[0] == num for num in counts)):
        print('Yes')
print('No')

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)
n = int(input())
li = list(map(int,input().split()))
a = li[0]
del li[0]

def f(num1,num2,l):
  t = num1^num2
  if len(l) == 1 and t in l:
    return True
  else:
    if t in l:
      l.remove(t)
      return f(num2,t,l)
    else:
      return False

for i in li:
  if not a^i in li:
    continue
  else:
    if f(i,a,li[:]):
      print("Yes")
      exit()
    else:continue
print("No")

Submission status: Runtime Error

Solution code:
import copy
import numpy

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

for i in range(N-1):
    first = List[i]
    a = copy.deepcopy(List)
    
    for j in range(i+1,N-1):
        acopy = copy.deepcopy(List)
        second = a[j]
        while(len(a) > 2):
            
            xor = bin(first ^ second)
            check = int(xor,2)

            if (check in a):
                a.remove(second)
                first = a[j]
                second = check

            else:
                break

            if (len(a) == 2):
                print("Yes")
                exit()

print("No")

Submission status: Runtime Error

Solution code:
import collections
import random
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==0:
  print('Yes')
elif n%3!=0:
  print('No')
elif len(set(a))!=3:
  x=random.randint(1,2)
  if x%2==0:
    print('No')
  elif n%3!=0
    print('No')
  else:
    print('Yes')
else:
  a=list(set(a))
  for i in range(len(a)):
    a[i]=format(a[i],'020b')
  l=[0 for i in range(20)]
  for i in range(len(a)):
    for j in range(20):
      if a[i][j]=='1':
        l[j]+=1
  ct=0
  for j in range(20):
    if l[j]==2 or l[j]==0:ct+=1
  if ct==20:
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
while True:
    for c in itertools.combinations(a, 3):
        if c[0] ^ c[2] == c[1]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[1])
                break
        elif c[1] ^ c[2] == c[0]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[0])
                break
        elif c[0] ^ c[1] == c[2]:
            if len(a) == 3:
                print("Yes")
                exit()
            else:
                a.remove(c[2])
                break
        else:
            print("No")
            exit()

Submission status: Runtime Error

Solution code:
import collections
import sys
sys.setrecursionlimit(10000)

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

value, count = list(a.keys()), list(a.values())

if count[0]+count[1]+count[2] != N:
    print('No')

elif value[0]^value[1]^value[2] != 0:
    print('No')

elif count[0]==count[1]==count[2]:
    print('Yes')

else:
    print('No')