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
stdin = sys.stdin
sys.setrecursionlimit(10**6)
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 = sorted(na())
x = [[0]*n for _ in range(30)]
 
if n%3:
    if max(a):
        print("No")
    else:
        print("Yes")
else:
    m = n//3
    if A[0] == A[m-1] and A[m] == A[2*m-1] and A[2*m] == A[3*m-1] and A[0]^A[m] == A[2*m]:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
if n%3==0:
  d={}
  for ai in a:
    if ai not in d:
      d[ai]=a.count(ai)
  sa=list(set(a))
  if sa[0]^sa[1]==sa[2] and d[sa[0]]==d[sa[1]] and d[sa[0]]==d[sa[2]]:
    print('Yes')
    exit()
print('No')

Submission status: Runtime Error

Solution code:
an=int(input())
a=sorted(list(map(int,input().split())))
if n%3==0:
  d={}
  for ai in a:
    if ai not in d:
      d[ai]=a.count(ai)
  sa=list(set(a))
  if sa[0]^sa[1]==sa[2] and d[sa[0]]==d[sa[1]] and d[sa[0]]==d[sa[2]]:
    print('Yes')
    exit()
print('No')

Submission status: Runtime Error

Solution code:
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from math import gcd
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        N = int(input())
        A = list(map(int, input().split()))

        if all(a == 0 for a in A):
            return True
        if N % 3 != 0:
            return False

        AA = Counter(A)
        if len(AA) == 2:
            AAA = AA.most_common()
            for k, v in AAA.items():
                if v != N * 2 // 3:
                    return False
            return AAA[1][0] == 0

        if len(AA) == 3:
            if any(v != N // 3 for v in AA.values()):
                return False
            k1, k2, k3 = AA.keys()
            return k1 ^ k2 == k3

    print('Yes' if main() else 'No')


resolve()

Submission status: Runtime Error

Solution code:
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from math import gcd
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        N = int(input())
        A = list(map(int, input().split()))

        if all(a == 0 for a in A):
            return True
        if N % 3 != 0:
            return False

        AA = Counter(A)
        if len(AA) == 2:
            AAA = AA.most_common()
            for k, v in AAA.items():
                if v != N * 2 // 3:
                    return False
            return AAA[1][0] == 0

        if len(AA) == 3:
            if any(v != N // 3 for v in AA.values()):
                return False
            k1, k2, k3 = AA.keys()
            return k1 ^ k2 == k3 or k1 ^ k3 == k2 or k2 ^ k3 == k1

    print('Yes' if main() else 'No')


resolve()

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
cntr = Counter(A)
ans = 'No'
if len(cntr) == 1 and cntr[0][0] == 0:
  ans = 'Yes'
elif n % 3 == 0:
  if len(cntr) == 3:
    k = list(cntr.keys())
    v = list(cntr.values())
    if k[0]^k[1]^k[2] == 0 and v[0] == v[1] and v[1] == v[2]:
      ans = 'Yes'
  elif len(cntr) == 2:
    if sorted(cntr.keys())[0] == 0 and cntr.get(0) == n//3:
      ans = 'Yes'
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
if b.count(0)==n:
    print("Yes")
elif n%3==0:
    if b.count(0)==n//3 and b.count(b[n-1])==n-(n//3):
        print("Yes")
    elif b[0]^b[n//3]^b[n-1]==0 and b.count(b[0])==n//3 and b.count(b[n//3])==n//3 and b.count(b[n-1])==n//3:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
if max(a)==0:
    print("Yes")
elif (N%3)==0:
    c=collections.Counter(a)
    values = list(c.values())  # aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
    key = list(c.keys())  # 先のvalue値に相当する要素のリスト(要素1,要素2,…)
    for i in range(len(key)):
        l.append([key[i], values[i]])  # lは[要素i,n_i]の情報を詰めたmatrix
    l.sort(key=lambda x:x[1],reverse=True)
    #print(l)
    if ((len(l)==3)and(l[0][1]==l[0][2]==l[0][3])and(l[0]^l[1]==l[2])):
        print("Yes")
    elif (len(l)==2)and(l[0][1]==2*l[1][1])and(l[1][0]==0):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
if N==3:
    if a[0]^a[1]==a[2]:
        print("Yes")
    else:
        print("No")
    input()
else:
    if max(a)==0:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

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

    d = {}
    for aa in a:
        d[aa] = d.get(aa, 0) + 1

    if d.get(0, 0) == n:
        print("Yes")
        return 0
    L = sorted(list(d.items()))
    if n % 3 == 0 and len(L) == 2 and (L[0][0] == 0 and L[0][1] == n//3) and L[1][1] == n//3*2:
        print("Yes")
        return 0
    
    if n % 3 == 0 and len(L) == 3 and L[0][1] == n//3 and L[1][1] == n//3 and :[2][1] == n//3 and L[0][0]^L[1][0]^L[2][0] == 0:
        print("Yes")
        return 0

    print("No")

main()

Submission status: Runtime Error

Solution code:
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    num = len(set(a))
    aset=set(a)
    a1, a2, a3 = aset
    if sum(a) == 0:
        print('Yes')
        return
    # if n % 3 != 0:
        # print('No')
        # return
    if len(cnt.most_common()) == 3:
        if cnt.most_common()[0][1] == cnt.most_common()[1][1] == cnt.most_common()[2][1]  and a1 ^ a2 == a3:
            # print(cnt.most_common())
            print('Yes')
            return

    if len(cnt.most_common()) == 2:

        tmp_min = cnt.most_common()[1][1]
        tmp_max = cnt.most_common()[0][1]
        if 3 * tmp_min == n and int(cnt.most_common()[1][0]) == 0:
            print('Yes')
            return
    print('No')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    num = len(set(a))
    if n % 3 != 0:
        print('No')
        return
    if num != 3 and cnt[0][1] !=3 and cnt[-1][1] != 3:
        print('No')
        return
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    num = len(set(a))
    if n % 3 != 0:
        print('No')
        return
    if num != 3 and cnt[0][1] !=3 and cnt[-1][1 != 3]:
        print('No')
        return
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

A_set=set(A)
A_lst=list(A_set)

# すべてが0のとき
if sum(A_set)==0 and len(A_set)==1:
    print('Yes')
    exit()

# x…2N/3,0…N/3
if len(A_set)==2 and A_set.count(0)==1 t and A_set.count(sum(A_set)//2)==2 and len(A)%3==0:
    print('Yes')
    exit()

# x^y^z==0
if len(A_set)==3 and A_lst[0]^A_lst[1]^A_lst[2]==0 and len(A)%3==0:
    print('Yes')
    exit()

# それ以外
print('No')

Submission status: Runtime Error

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

A_set=set(A)
A_lst=list(A_set)

# すべてが0のとき
if sum(A_set)==0:
    print('Yes')
    exit()

# x…2N/3,0…N/3
if 0 in A_set and A_set.count(sum(A_set)//2)==2 and len(A)%3==0:
    print('Yes')
    exit()

# x^y^z==0
if A_lst[0]^A_lst[1]^A_lst[2]==0 and len(A)%3==0:
    print('Yes')
    exit()

# それ以外
print('No')

Submission status: Runtime Error

Solution code:
def main():
    from collections import Counter

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

    if n % 3 == 0:
        ctr = Counter(a)
        if (len(ctr) == 1) and (0 in Counter):
            print('Yes')
            return
        elif len(ctr) == 3:
            it = iter(ctr.keys())
            x = next(it)
            y = next(it)
            z = next(it)
            print('Yes' if x ^ y == z else 'No')
            return
    else:
        print('Yes' if all(map(lambda x: x == 0, a)) else 'No')
        return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


from collections import defaultdict
dic = {}

for a in al:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
if dic[0] == n:
    print("Yes")
    exit()
if 0 in dic:
    if n % 3 == 0:
        if dic[0] == 2 * n // 3:
            print("Yes")
            exit()
if n % 3 != 0:
    print("No")
    exit()
else:
    if len(dic) == 3:
        if max(dic.values()) == n // 3:
            a = 0
            for i in dic:
                a ^= i
            if a == 0:
                print("Yes")
                exit()
print("No")

Submission status: Runtime Error

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

if N % 3 != 0:
    ans = "Yes" if sum(A) == 0 else "No"
else:
    B = Counter(A)
    keys = tuple(B.keys())
    vals = tuple(B.values())
    if len(B) == 3:  # 3種類ならa^b^cかつNa==Nb==NCでおけ
        a, b, c = keys
        Na, Nb, Nc = vals
        if Na == Nb and Nb == Nc:
            a, b, c = keys
            ans = "No" if a ^ b ^ c else "Yes"
        else:
            ans = "No"
    elif len(B) == 2:  # 2種類なら、a^a==0かつb==0かつNa==2Nbでおけ
        a, b = keys
        Na, Nb = vals
        if a == 0:
            ans = "Yes" if Na == 2*Nb else "No"
        elif b == 0:
            ans = "Yes" if 2*Na == Nb else "No"
        else:
            ans = "No"
    elif len(B) == 1:
        a = keys[0]
        ans == "Yes" if a == 0 else "No"
    else:
        ans = "No"


print(ans)

Submission status: Runtime Error

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

if N % 3 != 0:
    ans = "Yes" if sum(A) == 0 else "No"
else:
    B = Counter(A)
    keys = tuple(B.keys())
    vals = tuple(B.values())
    if len(B) == 3:  # 3種類ならa^b^cかつNa==Nb==NCでおけ
        a, b, c = keys
        Na, Nb, Nc = vals
        if Na == Nb and Nb == Nc:
            a, b, c = keys
            ans = "No" if a ^ b ^ c else "Yes"
        else:
            ans = "No"
    elif len(B) == 2:  # 2種類なら、a^a==0かつb==0かつNa==2Nbでおけ
        a, b = keys
        Na, Nb = vals
        if a == 0:
            ans = "Yes" if Na == 2*Nb else "No"
        elif b == 0:
            ans = "Yes" if 2*Na == Nb else "No"
        else:
            ans = "No"
    elif len(B) == 1:
        a = keys[0]
        ans == "Yes" if a == 0 else "No"


print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections as c
import sys

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

A = c.Counter(a)

if list(A.keys()) == [0]:
	print("Yes")
	sys.exit()

if len(A.keys()) == 2:
	if 0 not in A.keys():
		print("No")
		sys.exit()
	else:
		if A.values()[0]*2 == A.values()[1]:
			print("Yes")
			sys.exit()
		else:
			print("No")
			sys.exit()

if len(A.keys()) != 3:
	print("No")
	sys.exit()

x,y,z = A.keys()
if x^y != z:
	print("No")
	sys.exit()

x,y,z = A.values()
if x == y == z:
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    c = collections.Counter(a)
    if len(c) > 3:
        return "No"

    k = list(c.keys())
    t = [k[0], k[1]]
    def f(t):
        for i in range(n-2):
            u = t[i] ^ t[i+1]
            t.append(u)
        if t[0] ^ t[-2] != t[-1] or t[-1] ^ t[1] != t[0]:
            return False
        d = collections.Counter(t)
        if c != d:
            return False
        return True

    for g in k:
        for h in k:
            if f([g,h]):
                return 'Yes'

    return 'No'


print(main())

Submission status: Runtime Error

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

if n%3==0:
    for j in range(3):
        for i in range(j*(n//3),(j+1)*(n//3)-1):
            if a[i]!=a[i+1]:
                print("No")
                exit()
    if x[0]^x[n//3]==x[2*n//3]:
        print("Yes")
    else:
        print("No")
    exit()
for i in range(0,n-1):
    if a[i]!=a[i+1]:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = list(set(a))
if len(x) >= 4:
  print("No")
  exit()
if len(x) == 3:
  if x[0]^x[1] == x[2] and 3*a.count[x[0]] == 3*a.count[x[1]] == 3*a.count[x[2]] == n:
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 2:
  if x[0] == 0 or x[1] == 0 and 2*a.count[x[0]] == 2*a.count[x[1]] == n:
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 1:
  if x[0] == 0:
    print("Yes")
  else:
    print("No")

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
d = {}
for i in range(N):
    a = A[i]
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
if len(d.keys()) == 1:
    if d.keys()[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 2:
    keys = list(sorted(list(d.keys())))
    if d[keys[0]] == N // 3:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 3:
    keys = list(d.keys())
    if keys[0] ^ keys[1] ^ keys[2] == 0:
        if d[keys[0]] == d[keys[1]] == d[keys[2]]:
            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()))
ans = "Yes"
if N % 3 != 0:
  if len(set(A)) != 1 or set(A)[0] != 0:
    ans = "No"
  print(ans)
else:
  if len(set(A)) == 2:
    if A.count(0) != N // 3:
      ans = "No"
  elif len(set(A)) == 3:
    A_s = list(set(A))
    for a in A_s:
      if A.count(a) != N // 3:
        ans = "No"
      elif A_s[0] ^ A_s[1] ^ A_s[2] != 0:
        ans = "No"
  else:
    ans = "No"
  print(ans)

Submission status: Runtime Error

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

if len(a) % 3 != 0:
  print('No')
else:
  a = list(set(a))
  if a[0]==a[1]^a[2] and len(a)==3:
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
A = set()
table = collections.defaultdict(int)

for i in range(1, N):
    table[a[i]] = i

ans = [-1]*N
ans[0] = a[0]
for i in range(1, N):
    if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] != i:
        ans[1] = a[0] ^ a[i]
        ans[2] = a[i]
        del(table[ans[1]])
        del(table[ans[2]])
        break
if ans[1] == -1:
    print("No")
    exit(0)

for i in range(3, N):
    if (ans[i-1] ^ ans[i-2]) in table and table[ans[i-1] ^ ans[i-2]] != i-2 and table[ans[i-1] ^ ans[i-2]] != i-1:
        ans[i] = ans[i-1] ^ ans[i-2]
        del(table[ans[i]])
    else:
        print("No")
        exit(0)
print("Yes")

Submission status: Runtime Error

Solution code:
from collections import Counter as ct
import sys
input = sys.stdin.readline

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

if c[0] == n:
    print("Yes")
elif len(c) == 2 and c[0] * 3 == n:
    print("Yes")
elif len(c) == 3 and len(set(c.values())) == 1 and :
    a, b, c = c.keys()
    if (a ^ b ^ c) == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Runtime Error

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

if sum(a) == 0:
    pass
elif a.count(max(b)) == 2*n/3 and a.count(0) == n/3:
    pass
elif b[0] ^ b[1] == b[2]:
    pass
else:
    print("No")
    exit()
    
print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
if len(set(l))==3:
  h=sorted(list(set(l)),reverse=1)
  ff=len(bin(h[0]))
  p=["0"*(ff-len(bin(s)))+bin(s)[2:] for s in h]
  y=p[0]
  dfg,dgf=p[1],p[2]
  for i in range(ff-2):
    q,w=dfg[i],dgf[i]
    if (q!=w and y[i]=="0") or (q==w and y[i]=="1"):print("No");exit()
  else:
    from collections import Counter as cou
    if len(set(cou(l).values()))==1:print("Yes")
    else:print("No")
elif len(set(l))>=4 or 0 not in set(l):
  print("No")
elif set(l)==set([0]):
  print("Yes")
else:
  if n%3:print("No");exit()
  from collections import Counter as cou
  fl,fll=0,0
  for g,gh in cou(l).items():
    if g==0 and gh==n//3:fl=1
    if g!=0 and gh==2*n//3:fll=1
  print("Yes" if fl and fll else "No"))

Submission status: Runtime Error

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

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

if len(set(a)) == 2 and a[0] == 0:
    print("Yes")
    sys.exit()

for i in range(n):
    if not a[3*i] == a[3*i + 1] == a[3*i+2]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

N = int(input())
a = list(map(int,input().split()))
a.sort()
YES = 'Yes'
NO = 'No'
if a == [0]*N:
  print(Yes)
  sys.exit()
  
if N%3 !=0:
  print(NO)
  sys.exit()
  
counter = Counter(a)
if len(counter) > 3:
  print(NO)
  sys.exit()
elif len(counter) == 3:
  if list(counter.values()) != [N//3,N//3,N//3]:
    print(NO)
  else:
    xor = 0
    for key in counter.keys():
      xor ^= key
    if xor == 0:
      print(YES)
    else:
      print(NO)
  sys.exit()
elif len(counter) == 2:
  if counter.items[0][0] == 0 and counter.items[0][1] == N//3:
    print(YES)
  else:
    print(NO)
  sys.exit()

print(NO)

Submission status: Runtime Error

Solution code:
N = int(input())
aaa = sorted([int(i) for i in input().split()])


count0 = aaa.count(0)
countleft = aaa.count(aaa[0])
countright = aaa.count(aaa[-1])
buff1 = aaa[0]
buff2 = aaa[-1]
aaa = [i for i in aaa if i!=buff1 and i!=buff2]
buff3 = aaa[0]
countmid = aaa.count(buff3)

if count0 == N:
    print("Yes")
    exit()
elif N%3==0 and count0 == N/3 and countright == N/3*2:
    print("Yes")
    exit()
elif N%3==0 and countleft == N/3 and countright == N/3 and countmid == N/3:
    print("Yes")
    exit()
print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
aaa = sorted([int(i) for i in input().split()])
ini = aaa[0]
first = aaa[0]
for i in range(1,N):
    second = aaa[i]
    for j in range(N-1):
        next_hat = first^second
        #print(first,second,next_hat)
        if next_hat in aaa:
             aaa.remove(next_hat)
        else:
            break
        first = second
        second = next_hat
    else:
        if first&second==ini:
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
A = set()
table = collections.defaultdict(int)
for i in range(1, N):
    table[a[i]] += 2
a.sort()
prev = a[0]
now = a[0]
last = a[0]
for i in range(1, N):
    if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] > 0:
        table[a[0] ^ a[i]] -= 1
        last = a[i]
        now = a[0] | a[i]
        break
	if i == N-1:
      print("No")
      exit(0)
for i in range(2, N-2):
    if prev ^ now in table and table[now ^ prev] > 0:
        prev = now
        now = now ^ prev
        table[now ^ prev] -= 1
    else:
        print("No")
        exit(0)
if (last ^ now) == a[0]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = input()
A = eval(A.replace(" ","^"))
#print(A)
print("Yes" if not A else "No")

Submission status: Runtime Error

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

if N % 3:
    ans = len(set(A)) == 1
else:
    c = Counter(A)
    if len(c) != 3:
        ans = False
    else:
        x, y, z = c.keys()
        ans = (x | y == z)
print('Yes' if ans else 'No')

Submission status: Runtime Error

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

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1

if len(S)>3:
    print("No")
    sys.exit()
    
if len(S) ==3:
    A = list(S.keys())
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")


elif len(S)==2:
    if S[A[0]]==0 and S[A[1]] == 2*S[A[0]]:
        print("Yes")
    elif S[A[1]]==0 and S[A[0]] == 2*S[A[1]]:
        print("Yes")
    else:
        print("No")


elif len(S)==1:
    if S.values()==[0]:
        print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1

if len(S)>3:
    print("No")
    sys.exit()
    
if len(S) ==3:
    A = list(S.keys())
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")

elif len(S) == 2:
    A = list(S.keys())
    if A[0]== 0 or  A[1]==0 and S[A[0]] == S[A[1]]:
        print("Yes")
elif len(S)==1:
    if S.values()==[0]:
        print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import Counter
N=int(input())
A=Counter(map(int,input().split()))

if len(A)==1:
  if 0 in A:
    print("Yes")
  else:
    print("No")
elif len(A)==2:
  if A[0]==N/3:
    print("Yes")
  else:
    print("No")
elif len(A)==3:
  if list(A.values())==[N/3]*3 and A.keys()[0]^A.keys()[1]^A.keys()[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Runtime Error

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

import collections

Alist=A.most_common()

if len(Alist)!=3:
    print("No")
    exit()
elif not Alist[0][1]==Alist[1][1]==Alist[2][1]:
    print("No")
    exit()

Anum=[Alist[0][0],Alist[1][0],Alist[2][0]]
Anum.sort()

Astr=[""]*3
for i in range(3):
    temp=Anum[i]
    while temp>1:
        if temp%2==0:
            Astr[i]+="1"
            temp//=2
    if temp==1:
        Astr[i]+="1"
    else:
        Astr[i]+="0"

SL=len(Astr[2])
for i in range(3):
    Astr[i]=Astr[i].zfill(SL)

temp=""
for i in range(SL):
    if Astr[0][i]==A[2][i]:
        temp+="0"
    else:
        temp+="1"
if temp!=Astr[1]:
    print("No")
    exit()

temp=""
for i in range(SL):
    if Astr[1][i]==A[0][i]:
        temp+="0"
    else:
        temp+="1"
if temp!=Astr[2]:
    print("No")
    exit()
temp=""
for i in range(SL):
    if Astr[1][i]==A[2][i]:
        temp+="0"
    else:
        temp+="1"
if temp!=Astr[0]:
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

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

c = set(a)
if len(c) > 3:
    print('No')
    exit()

c = list(c).sort()
if len(c) == 1:
    if c[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(c) == 2:
    if c[0] == 0 and a.count(0) * 2 == a.count(c[1]):
        print('Yes')
    else:
        print('No')
else:
    if c[0] ^ c[1] == c[2] and a.count(c[0]) == a.count(c[1]) and a.count(c[1]) == a.count(c[2]):
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
from collections import Counter


def main():
    N = int(input())
    lst_a = list(map(int, input().split()))

    cnt_a = Counter(lst_a)

    if len(cnt_a) > 3:
        print("No")
        exit()
    
    if len(cnt_a) == 1:
        print("Yes" if lst_a[0] == 0 else "No")
        exit()
    
    if N % 3:
        print("No")
        exit()
    
    if len(cnt_a) == 2:
        if cnt_a[0] != N//3:
            print("No")
        else:
            print("Yes")
    else:
        if any(v != N//3 for v in C.values()):
            print("No")
        else:
            x, y, z = list(cnt_a)
            print("Yes" if x ^ y ^ z == 0 else "No")


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter


def main():
    N = int(input())
    lst_a = list(map(int, input().split()))

    cnt_a = Counter(lst_a)

    if len(cnt_a) > 3:
        print("No")
        exit()
    
    if len(cnt_a) == 1:
        print("Yes" if lst_a[0] == 0 else "No")
        exit()
    
    if N % 3:
        print("No")
        exit()
    
    if len(cnt_a) == 2:
        if cnt_a[0] != N//3:
            print("No")
        else:
            print("Yes")
    else:
        if any(v != N//3 for v in C.values()):
            print("No")
        else:
            x, y, z = list(cnt_a)
            print("Yes" if a ^ b ^ c == 0 else "No")


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

def logicalsum_str(a, b):
    La = len(a)
    Lb = len(b)
    ans = ""
    if La >= Lb:
        for i in range(Lb):
            if a[-(1 + i)] == b[-(1 + i)]:
                ans = "0" + ans
            else:
                ans = "1" + ans
        ans = a[0:La-Lb] + ans
    else:
        for i in range(La):
            if a[-(1 + i)] == b[-(1 + i)]:
                ans = "0" + ans
            else:
                ans = "1" + ans
        ans = a[0:Lb-La] + ans

    return ans

N=int(input())
A=list(map(int,input().split()))
B=[""]*N
for i in range(N):
    temp=A[i]
    while temp>0:
        B[i]=str(temp%2)+B[i]
        temp=temp//2

if int(B[0])!=int(logicalsum_str(B[-1],B[1])) or  int(B[-1])!=int(logicalsum_str(B[-2],B[0])):
    print("No")
    exit()

for i in range(2,N-1):
    if int(B[i])!=int(logicalsum_str(B[i-1],B[i+1])):
        print("No")
        exit()

print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
def solve(A):
  count = {}
  for x in A:
    if x not in count:
      count[x] = 0
    count[x] += 1
  if count[0] == N: return True
  if len(A) % 3 != 0: return False    
  xs = []
  for k, v in count.items():
    if v % (N//3) != 0: return False
    for _ in range(v // (N//3)):
      xs.append(k)
  return (xs[0] == xs[1] ^ xs[2]) or (xs[1] == xs[2] ^ xs[0]) or (xs[2] == xs[0] ^ xs[1])

print('Yes' if solve(A) else 'No')

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = len(a)
a.append(a[0])
a.append(a[1])
c = 0
if max(a) == 0:
  print('Yes')
elif b/3 - b//3 != 0:
    print('No')
else:
  for i in range(b+1):
    if a[i]^a[i+1]^a[i+2]  != 0:
      c += 1
  if c == 0:
    print('Yes')
  else:
    print('No')