Problem:


Score : 300 points

Problem Statement

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

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

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

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

What is XOR?

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

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

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

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

Sample Input 2

4
1 2 4 8

Sample Output 2

No

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



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Runtime Error

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

if A==[0]*N:
    print("Yes")
    exit()

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

F=True
for x in T:
    F&=(3*T[x]%N==0)

if not F:
    print("No")
    exit()

x,y,z=list(T.keys())

if x^y==z:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input()))
x = 0
for i in range(N):
    x ^=  a[i]
if x:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

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

if n % 3 != 0:
    if all((a[i] == 0 for i in range(n))):
        print('Yes')
    else:
        print('No')
else:
    while True:
        cnt = 0
        if all((a[i] == 0 for i in range(n))):
            print('Yes')
            exit()
        for i in range(n):
            if a[i] % 2 == 0:
                cnt += 1
                flag = True
            a[i] //= 2
        if flag:
            if cnt * 3 != n:
                print('No')
                exit()

Submission status: Runtime Error

Solution code:
from collections import Counter

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

cnt = Counter(A)

if cnt[0] == N:
    print("Yes")
else:
    if N % 3 != 0:
        print("No")
    else:
        if cnt.most_common(1)[0][1] == N*2//3 and cnt[0] == N//3:
            print("Yes")
        else:
            x = cnt.most_common(3)
            if x[0][1] == x[1][1] == x[2][1]:
                if x[0][0]^x[1][0]^x[2][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()))

flag = [False]*N
res = []

def f():
    if len(res) == len(A):
        if res[-1]^res[-2] == res[0]:
            print("Yes")
            exit()
        return

    for i in range(len(A)):
        if flag[i]:
            continue
        if res[-1]^res[-2] != A[i]:
            continue
        flag[i] = True
        res.append(A[i])
        f()
        flag[i] = False
        res.pop()
        return

flag[0] = True
res.append(A[0])

for i in range(1, N):
    flag[i] = True
    res.append(A[i])
    f()
    flag[i] = False
    res.pop()

print("No")

Submission status: Runtime Error

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

flag = [False]*N
res = []

def f():
    if len(res) == len(A):
        if res[-1]^res[-2] == res[0]:
            print("Yes")
            exit()

    for i in range(len(A)):
        if flag[i]:
            continue
        if res[-1]^res[-2] != A[i]:
            continue
        flag[i] = True
        res.append(A[i])
        f()
        flag[i] = False
        res.pop()
        return

flag[0] = True
res.append(A[0])

for i in range(1, N):
    flag[i] = True
    res.append(A[i])
    f()
    flag[i] = False
    res.pop()

print("No")

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a_counter = Counter(a)
k = list(a_counter.keys())
v = list(a_counter.values())

if len(a_counter) == 3 and k[0]^k[1]^k[2] == 0 and v[0] == v[1] == v[2]:
    print("Yes")
elif len(a_counter) == 2 and 0 in k and v[0] == v[1]*2 or v[1] == v[0]*2:
    print("Yes")
elif len(a_counter) == 1 and 0 in k:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a_counter = Counter(a)
k = list(a_counter.keys())
v = list(a_counter.values())

if len(k) == 3 and k[0]^k[1]^k[2] == 0 and v[0] == v[1] == v[2]:
    print("Yes")
elif len(k) == 2 and 0 in k and v[0] == v[1]*2 or v[1] == v[0]*2:
    print("Yes")
elif len(k) == 1 and 0 in k :
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1 and a[0] == 0:
    print("Yes")
    exit()
if N%3 != 0:
    print("No")
    exit()

import collections
sa = list(set(a))
sa.sort()
B = collections.Counter(sa)
if len(sa) == 2 and 0 in sa:
    if B[0] == N//3 and B[sa[1]] == N*2//3:
        print("Yes")
    else: print("No")
    exit()

print("Yes" if sa[0] ^ sa[1] == sa[2] else "No")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1 and a[0] == 0:
    print("Yes")
    exit()
if N%3 != 0:
    print("No")
    exit()

import collections
sa = list(set(a))
sa.sort()
B = collections.Counter(a)
if len(sa) == 2 and 0 in sa:
    if B[0] == N//3 and B[sa[1]] == N*2//3:
        print("Yes")
    else: print("No")
    exit()

print("Yes" if sa[0] ^ sa[1] == sa[2] else "No")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1 and a[0] == 0:
    print("Yes")
    exit()
if N%3 != 0:
    print("No")
    exit()

import collections
B = collections.Counter(a)
sa = list(set(a))
sa.sort()
if len(sa) == 2 and 0 in sa:
    if B[0] == N//3 and B[sa[1]] == N*2//3:
        print("Yes")
    else: print("No")
    exit()

print("Yes" if sa[0] ^ sa[1] == sa[2] else "No")

Submission status: Runtime Error

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

d = dict()
for i in range(N):
    d[A[i]] = d.get(A[i], 0) + 1

if len(d) > 3:
    print('No')

else:
    k = list(d.keys())
    v = list(d.values())
    
    # a1 ^ a2 ^ a3 = 0 and an: N/3
    if len(d) == 3 and k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2]:
        print('Yes')
    
    # a1: 2N/3, 0: N/3
    elif len(d) == 2 and (k[0] == 0 and v[1] == 2*v[0]) or (k[1] == 0 and v[0] == 2*v[1]):
        print('Yes')
    
    # 0: N
    elif len(d) == 1 and k[0] == 0:
        print('Yes')
    
    else:
        print('No')

Submission status: Runtime Error

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

d = dict()
for i in range(N):
    d[A[i]] = d.get(A[i], 0) + 1

if len(d) > 3:
    print('No')

else:
    k = list(d.keys())
    v = list(d.values())
    
    # a1 ^ a2 ^ a3 = 0 and an: N/3
    if len(d) == 3 and k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2]:
        print('Yes')
    
    # a1: 2N/3, 0: N/3
    elif len(d) == 2 and (k[0] == 0 and v[1] == 2*v[0]) or (k[1] == 0 and v[0] == 2*v[1]):
        print('Yes')
    
    # 0: N
    elif len(d) == 1 and k[0] == 0:
        print('Yes')
    
    else:
        print('No')

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
N = int(input())
C = Counter(list(map(int, input().split())))
if len(C) == 1 and C[0] == N:
    print('Yes')
elif len(C) == 2 and N % 3 == 0 and C[0] == N // 3 and N - [0] == 2 * N // 3:
    print('Yes')
elif len(C) == 3 and N % 3 == 0:
    b = 0
    for c in C.most_common():
        if c[1] != N // 3:
            print('No')
            sys.exit()
        b ^= c[0]
    if b == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
u = list(set(l))
if len(u)==1 and u[0]==0:
  print("Yes")
elif n%3==0:
  if len(u)==2:
  	x = l.count(u[0])
  	y = l.count(u[1])
    if (x==2*n/3 and y==n/3) or (y==2*n/3 and x==n/3):
      print("Yes")
    else:
      print("No")
  elif len(u)==3:
    x = l.count(u[0])
  	y = l.count(u[1])
    z = l.count(u[2])
    if x==n/3 and y==n/3 and z==n/3:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  print("No")

Submission status: Runtime Error

Solution code:
N,A,B,C,D =list(map(int,input().split()))
s = input()
flag = 0
if C<D:
    if (s[B-1:D].count('##') == 0) and (s[A-1:C].count('##') == 0):
        print('Yes')
    else:
        print('No')
else:
    if (s[B-1:C].count('...')>=1) and (s[A-1:C].count('##')==0):
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
N,A,B,C,D =list(map(int,input().split()))
s = input()
flag = 0
if C<D:
    if s[B-1:D].count('##') == 0 and s[A-1:C].count('##') == 0:
        print('Yes')
    else:
        print('No')
else:
    if s[B-1:C].count('...')>=1 and s[A:C].count('##')==0:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
N = int(input())
a_list = [int(e) for e in input().split()]

a_dict = dict()
for a in a_list:
    if a not in a_dict:
        a_dict[a] = 0
    a_dict[a] += 1

ans_list = list()

#最初の3つを求める
center = a_list[0]
a_dict[center] -= 1
if a_dict[center] == 0:
    del a_dict[center]

for a in a_dict:
    if center^a in a_dict:
        a_dict[center^a] -= 1
        a_dict[a] -= 1

        if a_dict[center^a]==0:
            del a_dict[center^a]
        if a_dict[a]==0:
            del a_dict[a]
        elif a_dict[a] == -1:
            first_NG_flag = False
            
        break
else:
    print("No")
    first_NG_flag = True
               
left = center^a
right = a
ans_list.append(left)
ans_list.append(center)
ans_list.append(right)

#以後を求める
if first_NG_flag == False:
    left = ans_list[-2]
    center = ans_list[-1]

    while 1:
        if len(a_dict)==0:
            right = ans_list[0]
            if left^right == center:
                print("Yes")
            else:
                print("No")
            break

        elif left^center in a_dict:
            a_dict[left^center] -= 1
            if a_dict[left^center] == 0:
                del a_dict[left^center]
            ans_list.append(left^center)

            left = ans_list[-2]
            center = ans_list[-1]
        else:
            print("No")
            break

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_dic = dict()
a_set = set()
for num in a:
  if num in a_dic:
    a_dic[num] += 1
  else:
    a_dic[num] = 1
  a_set.add(num)
k = len(a_dic)
a_set = list(a_set)
if k == 1:
  if 0 in a_dic:
    if a_dic[0] == n:
      print('Yes')
      exit()
elif k == 2:
  if a_dic[0] == n/3 and a_dic(a_set[1]) == 2*n/3:
    print('Yes')
    exit()
elif k == 3:
  if a_set[0] ^ a_set[1] ^ a_set[2] == 0:
    if a_dic[a_set[0]] == a_dic[a_set[1]] == a_dic[a_set[2]] == n/3:
      print('Yes')
      exit()
print('No')

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_dic = dict()
a_set = set()
for num in a:
  if num in a_dic:
    a_dic[num] += 1
  else:
    a_dic[num] = 1
  a_set.add(num)
k = len(a_dic)
a_set = list(a_set)
if k == 1:
  if a_dic[0] == n:
    print('Yes')
    exit()
elif k == 2:
  if a_dic[0] == n/3 and a_dic(a_set[1]) == 2*n/3:
    print('Yes')
    exit()
elif k == 3:
  if a_set[0] ^ a_set[1] ^ a_set[2] == 0:
    if a_dic[a_set[0]] == a_dic[a_set[1]] == a_dic[a_set[2]] == n/3:
      print('Yes')
      exit()
print('No')

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if set(a) == set(0):
    print('Yes')
    exit()
    
if n % 3 != 0 or len(cnt) != 3:
    print('No')
else:
    key = []
    num = []
    for i, j in cnt.items():
        key.append(i)
        num.append(j)
    if len(set(num)) != 1:
        print('No')
    else:
        if key[0]^key[1] == key[2]:print('Yes')
        else:print('No')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

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

third = N // 3
if len(d.keys() == 3):
    a, b, c = d.keys()
    if d[a] == d[b] and d[b] == d[c]:
        if a ^ b ^ c == 0:
            print("Yes")
            sys.exit()

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

Submission status: Runtime Error

Solution code:
from itertools import combinations

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

c = [0] * (10 ** 9 + 1)
for e in a:
    c[e] += 1

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

Submission status: Runtime Error

Solution code:
from itertools import combinations

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

c = [0] * (10 ** 9 + 1)
for e in a:
    c[e] += 1

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

Submission status: Runtime Error

Solution code:
_, *a = map(int, open(0).read().split())
for b in a:z ^= b
print("YNeos"[z>0])

Submission status: Runtime Error

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

# 排他的論理和は3つずつ循環するため、満たすべき条件は以下
# nが3の倍数である, 数字が3種類で同数, 3種類が排他的論理和の関係になっている

if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(a)

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

if not all([x == cli[0] for x in cli]):
    print("No")
    sys.exit()

a = list(c.keys())
    
ans_0 = a[1] ^ a[2] == a[0]
ans_1 = a[2] ^ a[0] == a[1]
ans_2 = a[0] ^ a[1] == a[2]

print("Yes" if all([ans_0, ans_1, ans_2]) else "No")

Submission status: Runtime Error

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

# 排他的論理和は3つずつ循環するため、満たすべき条件は以下
# nが3の倍数である, 数字が3種類で同数, 3種類が排他的論理和の関係になっている

if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(a)

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

if not all([x == cli[0] for x in cli]):
    print("No")
    sys.exit()

ans_0 = a[1] ^ a[2] == a[0]
ans_1 = a[2] ^ a[0] == a[1]
ans_2 = a[0] ^ a[1] == a[2]

print("Yes" if all([ans_0, ans_1, ans_2]) else "No")

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

if n % 3 == 0 and len(set(a)) == 3:
    x = list(set(a))
    a = x[0]
    b = x[1]
    c = x[2]
    if a ^ b != c:
        print('No')
        exit()
    if b ^ c != a:
        print('No')
        exit()
    if c ^ a != b:
        print('No')
        exit()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    if d[a] != d[b] or d[b] != d[c] or d[c] != d[a]:
        print('No')
        exit()
    print('Yes')
elif n % 2 == 0 and len(set(a)) == 2:
    x = list(set(a))
    x.sort()
    if x[0] == 0:
        t = 1
    else:
        print('No')
        exit()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    if d[x[0]] != d[x[1]]:
        print('No')
        exit()
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = Counter(LI())
    ok = True
    if(N%3==0):
        B = []
        for a,c in A.items():
            if(c%(N//3)!=0):
                ok = False
                break
            for _ in range(c//(N//3)):
                B.append(a)
        if((B[0]^B[1]^B[2]) != 0):
            ok = False
    else:
        ok = len(A)==1
        
    if(ok):
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from colletions import Counter
n = int(input())
if n%3 != 0:
  print('No')
else:
  a = [int(i) for i in input().split()]
  c = Counter(a)
  for i in c.values():
    if i != n//3:
      print('No')
      exit()
  print('Yes')

Submission status: Runtime Error

Solution code:
# A - XOR Circle

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

if a[N-1]==0:
    ans = 'Yes'
elif N%3!=0:
    ans = 'No'
elif a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[N-1] and x^y^z==0:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Runtime Error

Solution code:
# A - XOR Circle

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

if a[N-1]==0:
    ans = 'Yes'
elif n%3!=0:
    ans = 'No'
elif a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[N-1] and x^y^z==0:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Runtime Error

Solution code:
# A - XOR Circle

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

if a[N-1]==0 and a[N]==a[3*N-1]:
    ans = 'Yes'
elif a[0]==a[N-1] and a[N]==a[2*N-1] and a[2*N]==a[3*N-1] and x^y^z==0:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Runtime Error

Solution code:
# A - XOR Circle

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

if a[N-1]==0 and a[N]==a[3*N-1]:
    ans = 'Yes'
elif a[0]==a[N-1] and a[N]==a[2*N-1] and a[2*N]==a[3*N-1] and x|y|z==0:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
x = list(map(int,input().split()))
c = Counter(x)
k = list(c.keys())
k.sort()
v = list(c.values())
if len(c)==3 or len(c)==1:
    if v[0]==v[1]==v[2]:
        if k[0]^k[2]==k[1]:
            print('Yes')
            exit()
print('No')

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

sa = set(a)
sa = list(sa)

if len(sa)>3:
    print('No')
    exit()

if len(sa)==3:
    aa = sa[0]
    bb = sa[1]
    cc = sa[2]
    if a.count(aa) != n/3 or a.count(bb) != n/3 or a.count(cc) != n/3:
        print('No')
        exit()
    if aa^bb^cc!=0:
        print('No')
        exit()

if len(sa)==2:
    aa = sa[0]
    bb = sa[1]
    if bb != 0 and aa != 0:
        print('No')
        exit()
    else:
        if bb ==0:
            zero =bb
        else:
            aa = bb
    if a.count(zero) != n/3 or a.count(aa)!=n/3*2:
        print('No')
        exit()

if len(sa)==1:
    aa = sa[0]

    if aa != 0:
        print('No')
        exit()

print('Yes')

Submission status: Runtime Error

Solution code:
from collections import deque,Counter

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

cnt = Counter(lisA)

if len(cnt)>3:
    print("No")
    exit()

if len(cnt) == 1:
    if lisA[0] == 0:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
elif len(cnt) == 2:
    if not 0 in cnt:
        print("No")
        exit()
    else:
        keys = sorted(list(cnt.keys()))
        another = keys[-1]
        if cnt[0]*2 == cnt[another]:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
else:
    keys = sorted(list(cnt.keys()))
    if keys[0]^keys[1]^keys[2] != 0:
        print("No")
        exit()
    else:
        if cnt(keys[0])==cnt(keys[1])==cnt(keys[2]):
            print("yes")
            exit()
        else:
            print("No")
            exit()

Submission status: Runtime Error

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

if len(c) > 3:
    print("No")
    exit()
elif len(c) == 3:
    if n % 3 != 0:
        print("No")
        exit()
    p = []
    for k , v in c.items():
        if v != n//3:
            print("No")
            exit()
        p.append(k)
    if (p[0] ^ p[1]) ^ p[2] != 0:
        print("No")
        exit()
elif len(c) == 2:
    if n % 3 != 0:
        print("No")
        exit()
    for k,v in c.items():
        if k == 0:
            if v != n//3:
                print("No")
                exit()
        elif:
            if v != 2*n//3:
                print("No")
                exit()
elif len(c) == 1:
    for k in c.keys():
        if k != 0:
            print("No")
            exit()
            
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
di = {}
for i in a:
    if i in di:
        di[i] += 1
    else:
        di[i] = 1
k = list(di.keys())
v = list(di.values())
if n%3!=0 and len(di)>1:
    print('No')
elif len(di)==3 and v[0]==v[1]==v[2] and k[0]^k[1]^k[2]==0:
    print('Yes')
elif len(di)==2 and (v[0]<v[1] and v[0]==n//3 and k[0]==0) or (v[0]>v[1] and v[1]==n//3 and k[1]==0):
    print('Yes')
elif len(di)==1 and k[0]==0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
if sum(a)==0:
    print('Yes')
    exit()
x=[]
x[0] = a.count(a[0])
x[1] = a.count(a[n//2])
x[2] = a.count(a[-1])
x.sort()

if x[0] == x[1] == x[2] == n//3 or (a[0] == 0 and x[0]==n//3 and x[1]==x[2]==2*n//3):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
n = len(s)
same = True
for i in range(1,len(s)):
    if s[i]!=s[i-1]:
        same = False
if same:
    print(len(s)*k//2)
    exit()

for i in range(1,len(s)):
    if s[i] != s[i-1]:
        before = i-1
        break
for i in range(len(s)-1,-1,-1):
    if s[i] != s[i-1]:
        after = i
        break

ans = (before+1)//2 
ans += (len(s)-after)//2
if s[0] == s[-1]:
    ans += (before + 1 + len(s) - after)//2 * (k-1)
else:
    ans += ((before+1)//2  + (len(s)-after)//2)*(k-1)
cnt = 1
for i in range(before+2, after):
    if s[i] != s[i-1]:
        ans += cnt //2 *k
        cnt = 1
    else:
        cnt +=1
ans += cnt //2 * k
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

a = list(map(int,input().split()))
a.sort()
d = {}
for i in range(n):
    if(a[i] not in d):d[a[i]] = 1
    else:d[a[i]] += 1
if(len(d) == 1):
    if(a[0] == 0):
        print('Yes')
        exit()
elif(len(d)%3 == 0):
    if(len(d) == 2):
        if(0 in d):
            if(d[0] == n // 3):
                print('Yes')
                exit()
    elif(len(d) == 3):
        k = d.keys()
        if(k[0]^k[1]^k[2] == 0):
            if(d[k[0]] == n // 3 and d[k[1]] == n // 3 and d[k[2]] == n // 3):
                print('Yes')
                exit()
print('No')

Submission status: Runtime Error

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ho=list(dic.keys())
x=ho[0]
y=ho[1]
z=ho[2]

ans='No'

if len(li)==3:
    if N%3 == 0:
        if li[0]== N//3 and li[1]==N//3 and x^y^z == 0:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N//3 or li[1]==2*N//3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Submission status: Runtime Error

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ho=list(dic.keys)
x=ho[0]
y=ho[1]
z=ho[2]

ans='No'

if len(li)==3:
    if N%3 == 0:
        if li[0]== N//3 and li[1]==N//3 and x^y^z == 0:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N//3 or li[1]==2*N//3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Submission status: Runtime Error

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    if N%3 == 0:
        
        if li[0]== N/3 and li[1]==N/3:
            se=li[5]
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N/3 or li[1]==2*N/3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Submission status: Runtime Error

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    se=li[5]
    if N%3 == 0:
        if li[0]== N/3 and li[1]==N/3:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N/3 or li[1]==2*N/3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Submission status: Runtime Error

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    if N%3 == 0:
        if li[0]== N/3 and li[1]==N/3 and li[2]==N/3 and li[3]==1:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N/3 or li[1]==2*N/3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Submission status: Runtime Error

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    if N%3 == 0:
        if li[0]== N/3 and li[1]==N/3 and li[2]==N/3:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N/3 or li[1]==2*N/3 or li[2]==2:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Submission status: Runtime Error

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'
if N%3 == 0:
    if len(li)==3:
        if li[0]==li[1] and li[0]==li[2]:
            ans='Yes'
else:
    if len(li)==1:
        if dic.keys[0]==0:
            ans='Yes'

print(ans)

Submission status: Runtime Error

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

ans = "No"
if c0==n: ans = "Yes"
elif len(set(a)) == 2:
    c = a.count(set(a)[-1])
    if c == (2*n)//3 and c0 == n//3: ans = "Yes"
elif len(set(a)) == 3:
    x,y,z = list(set(a))
    if int(bin(x ^ y ^ z),2) == 0: ans = "Yes"
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter

def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = Counter(a)
    if len(l)==1 and 0 in l:
        print('Yes')
        exit()
    if N%3==0 and len(l)==2 and 0 in l and l[0] == N//3:
        print('Yes')
        exit()
    if N%3==0 and len(l)==3:
        x,y,z = l.keys()
        if l[x] == l[y] == N//3 and x^y^z == 0:
            print('Yes')
            exit()
    print('No')


    

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(set(a)))
l=len(b)
if l>=4:
    print("No")
    exit()
else:
    if l==1:
        if b[0]==0:
            print("Yes")
        else:
            print("No")
    elif l==2:
        if n%3!=0:
            print("No")
        else:
            if b[0]!=0:
                print("No")
            else:
                cnt1=a.count(b[0])
                cnt2=a.count(b[1])
                if cnt2==(n//3)*2:
                    print("Yes")
                else:
                    print("No")
    else:
        if n%3!=0:
            print("No")
        else:
            cnt1=a.count(b[0])
            cnt2=a.count(b[1])
            cnt3=a.count(b[2])
            print(cnt1,cnt2,cnt3)
            if cnt1!=n//3 or cnt2!=n//3 or cnt3!=n//3:
                print("No")
            else:
                if b[0]^b[2]!=b[3]:
                    print("No")
                else:    
                    print("Yes")

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int, input().split()))
A=sorted(A)
if N%3!=0:
  if A==[0]*N:
    print('Yes')
  else:
    print('No')
else:
  B=A[0]+A[1]
  for i in range(N):
    d=B[i]^B[i+1]^B[i+2]
    if d!=0:
      print('No')
      exit()
  print('Yes')