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: Time Limit Exceeded

Solution code:
from itertools import permutations

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

Flag = False

perm = list(permutations(range(n)))

for item in perm:
    flag = True
    for i in range(n):
        if line[item[i]] != line[item[(i-1)%n]] ^ line[item[(i+1)%n]]:
            flag = False
    if flag:
        Flag = True

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
a = list(map(int, input().split()))
aa = list(itertools.permutations(a))

answer = "Yes"
for i in range(len(aa)):
  for j in range(len(aa[i]) - 1):
    if aa[i][j] != (aa[i][j - 1] ^ aa[i][j + 1]):
      answer = "No"
      break
    if answer == "No":
      break
    
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
a = list(map(int, input().split()))
aa = list(itertools.permutations(a))

answer = "No"
for i in range(len(aa)):
  for j in range(len(aa[i]) - 1):
    if aa[i][j] == (aa[i][j - 1] ^ aa[i][j + 1]):
      answer = "Yes"
      break
    if answer == "Yes":
      break
    
print(answer)

Submission status: Time Limit Exceeded

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

def check(N, a):
    flag = True
    if( (a[-1] ^ a[1]) != a[0]):
        flag != False
    if( (a[-2] ^ a[0]) != a[-1]):
        flag != False
    for i in range(1, N-1):
        if not flag:
            break
        if( (a[i-1] ^ a[i+1]) != a[i]):
            flag = False
    return flag

for ap in itertools.permutations(a):
    f = check(N, list(ap))
    if f:
        break

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

Submission status: Time Limit Exceeded

Solution code:

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

judge=False
#print(A)

for i in range(1,N):
    left = A[0]
    right = A[i]
    tmp_1=A[:]
    #print(tmp_1)
    tmp_1.remove(right)
    tmp_1.remove(left)
    tmp_2=[]
    isAble=True
    while isAble:
        #print(tmp_1)
        #print(tmp_2)
        x = right ^ left
        #print(x)
        if x in tmp_1:
            #print(x)
            left = right
            right = x
            tmp_1.remove(x)
            tmp_2.append(x)
        else:
            isAble=False

    if len(tmp_1)==0:
        judge=True
        break
    else:
        continue


ans = 'Yes' if judge else 'No'
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy 

n = int(input())
a = list(map(int,input().split()))
a1 = a[0]
flag = False
for i in range(1,n):
    t = copy.deepcopy(a[1:])
    a2 = a[i]
    t.remove(a2)
    nxt = a1 ^ a2
    for j in range(n-2):
        if nxt in t:
            t.remove(nxt)
            a1 = a2
            a2 = nxt
            nxt = a1 ^ a2
        else:
            break
    else:
        if nxt == a[0]:
            flag = True
    if flag:
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
# S=numpp.assaray(S)=="#"
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
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 LLS(): return [list(sys.stdin.readline().rstrip()) for _ 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 main():
    N=I()
    A = list(map(int,input().split()))
    out=True


    import itertools
    for p in itertools.permutations(A):
        if p[0]!=A[0]:
            print("No")
            exit()
        else:
            out=True
            for i in range(N):
                if i==0:
                    last=N-1
                else:
                    last=i-1
                if i==N-1:
                    ne=0
                else:
                    ne=i+1
                # print(last,ne)
                if p[last]^p[ne]!=p[i]:
                    out=False
            if out:
                print("Yes")
                exit()
                        # exit()

        # print(p)
        # if p[0]!='A': continue
    # for i in range(N):
    #     if i==0:
    #         last=N-1
    #     else:
    #         last=i-1
    #     if i==N-1:
    #         ne=0
    #     else:
    #         ne=i+1
    #     print(last,ne)
    #     if A[last]^A[ne]!=A[i]:
    #         print("No")
    #         # exit()
    # print("Yes")

    # A.append(A[0])
    # A.append(A[1])
    # for i in range(1,N+1):
    #     # print(i-1,i+1)
    #     if A[i-1]^A[i+1]!=A[i]:
    #         print("No")
    #         exit()
    # print("Yes")

    # print(A,B)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

a = sorted(a,reverse=True)

for ai in a[1:]:
  gen = [a[0]]
  gen.append(ai)
  for j in range(2,n):   
    gen.append(gen[j-2]^gen[j-1])

if (set(gen)==set(a)):
  print('Yes')
else:
  print('No')

Submission status: Time Limit Exceeded

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

afirst = a[0]

for i in range(N - 1):
    acopy = a.copy()
    acopy.pop(0)
    anext = acopy.pop(i)
    while len(acopy) > 0:
        anext ^= afirst
        afirst ^= anext
        if anext in acopy:
            acopy.remove(anext)
        else:
            break
    if len(acopy) == 0:
        anext ^= afirst
        if anext == a[0]:
            print("Yes")
            exit()

print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def check(x):
  res = True
  for i in range(len(x)):
    _prev = i-1 if i>0 else len(x)-1
    _next = i+1 if i<len(x)-1 else 0
    res &= x[_prev]^x[_next] == x[i]
  return res

for e in itertools.permutations(a[1:]):
  if check(list(e)+[a[0]]):
    print('Yes')
    break
else:
  print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = [i for i in map(int, input().split())]


for i in itertools.permutations(S):
    pool = []
    for j in range(N):
        if j != N-1:
            if i[j] != i[j-1]^i[j+1]:
                pool.append(1)
                continue
            else:
                pool.append(0)    
        elif j == N-1:
            if i[j] != i[j-1]^i[0]:
                pool.append(1)
                continue
            else:
                pool.append(0)
    if sum(pool) == 0:
        print('Yes')
        break
if sum(pool)!= 0:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
n = int(input())
a_list = list(map(int,input().split()))
ans_list = []

#a0
ans_flag = 0
first_ans = a_list[0]
for i in range(1,n-1):
    if ans_flag == 1:
        break
    for j in range(i+1,n):
        ans = a_list[i] ^ a_list[j]
        #print(ans)
        if ans == a_list[0]:
            ans_flag = 1
            fin_ans = a_list[j]
            sec_ans = a_list[i]
            a_list.remove(sec_ans)
            a_list.remove(fin_ans)
            a_list.remove(first_ans)
            ans_list.append(first_ans)
            ans_list.append(sec_ans)
            break
        
if ans_flag == 0:
    print("No")
    quit()

for i in range(n-2):
    ans = ans_list[i] ^ ans_list[i+1]
    if i == n-3:
        if ans == fin_ans:
            print("Yes")
            quit()
    
    if ans in a_list:
        ans_list.append(ans)
        a_list.remove(ans)
    else:
        print("No")
        quit()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for p in itertools.permutations(a, N):
    for i in range(N):
        if i ==0:
            if p[N-1]^p[i+1] != p[i]:
                break
        elif i == N-1:
            if p[i-1]^p[0] != p[i]:
                break
            else:
                print("Yes")
                exit()
        else:
            if p[i-1]^p[i+1] != p[i]:
                break
print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for s in list(itertools.permutations(l)):
    for i in range(n):
        if [l[(i-1)%n]^l[(i+1)%n] for i in range(n)]==l:
            print('Yes')
            exit()
        else:pass
print('No')

Submission status: Time Limit Exceeded

Solution code:
import copy 

n = int(input())
a = list(map(int,input().split()))
a1 = a[0]
flag = False
for i in range(1,n):
    t = copy.deepcopy(a[1:])
    a2 = a[i]
    t.remove(a2)
    nxt = a1 ^ a2
    while len(t) != 0:
        if nxt in t:
            t.remove(nxt)
            a1 = a2
            a2 = nxt
            nxt = a1 ^ a2
        else:
            break
    else:
        if nxt == a[0]:
            flag = True
if flag:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

res = 'Yes'

a_dict = dict()

for a in a_list:
    if a not in a_dict.keys():
        a_dict[a] = 1
    else:
        a_dict[a] += 1

a_keys = list(a_dict.keys())
if len(a_keys) > 3:
    res = 'No'
elif len(a_keys) == 3:
    a, b, c = a_keys
    if a_dict[a] != a_dict[b]:
        res = 'No'
    if a_dict[a] != a_dict[c]:
        res = 'No'
    if a ^ b != c:
        res = 'No'
    if b ^ c != a:
        res = 'No'
    if c ^ a != b:
        res = 'No'
elif len(a_keys) == 2:
    a, b = a_keys
    if a_dict[a] == 2 * a_dict[b]:
        if b != 0:
            res = 'No'
    elif 2 * a_dict[a] == a_dict[b]:
        if a != 0:
            res = 'No'
    else:
        res = 'No'
else:
    a = a_keys[0]
    if a != 0:
        res = 'No'
print(res)

Submission status: Time Limit Exceeded

Solution code:
def trycand(first, second, nextcand):
    rest = nextcand.copy()
    rest.remove(second)
    n1 = first
    n2 = second
    while rest:
        try:
            n3 = n1 ^ n2
            rest.remove(n3)
            n1 = n2
            n2 = n3
        except ValueError:
            return False
    return True


n = input()

a = list(map(lambda x: int(x), input().split()))
first = a[0]
#print(first)
nextcand = a[1:]
#print(nextcand)

for second in nextcand:
    if trycand(first, second, nextcand):
        print("Yes")
        exit()

print("No")
exit()

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

C = list(combinations(A, 2))
# print(C)
L = []
flag = False
for c in C:
    a = c[0]
    b = c[1]
    xor = a ^ b
    # print(xor)
    if xor in A:
        flag = True
        break
        
if flag == False:
    print("No")
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import itertools

input()
seq = list(map(int, input().split(' ')))
l = len(seq)
flg = False
for ls in itertools.permutations(seq):
  for i in range(l):
    if ls[i-2] ^ ls[i] != ls[i-1]:
      break
  if i == l-1:
    flg = True
    break

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def check(x):
  res = True
  for i in range(len(x)):
    _prev = i-1 if i>0 else len(x)-1
    _next = i+1 if i<len(x)-1 else 0
    res &= x[_prev]^x[_next] == x[i]
  return res

for e in itertools.permutations(a):
  if check(e):
    print('Yes')
    break
else:
  print('No')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(i) for i in input().split()]

a = A[0]
B = A[:]
B.sort()

for i in range(1, n):
    C = [a, A[i]]
    for j in range(2, n):
        C.append(C[j - 2] ^ C[j - 1])
    if C[-2] ^ C[-1] == C[0]:
        C.sort()
        if C == B:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

judge = False
if 0 in c and c[0] == n:
  judge = True
if n % 3 == 0:
  judge1, judge2 = False, 0
  num = 0
  value = 0
  for k, v in c.items():
    num += 1
    if v == n // 3:
      if k == 0:
        judge1 = True
      judge2 += 1
    value ^= k
  if judge1 and num == 2:
    judge = True
  if judge2 == num == 3 and value == 0:
    judge = True

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

def solve(N,A):
    if all(x == 0 for x in A):
        return True
    q,r = divmod(N,3)
    if r:
        return False
    counter = Counter(A)
    n = len(counter)
    if n == 1:
        return False
    if n == 2:
        a,b = counter.keys()
        if a > b:
            a,b = b,a
        if a != 0:
            return False
        # 0,b
        if counter[0] != N//3:
            return False
        return True
    if n == 3:
        a,b,c = counter.keys()
        for x in [a,b,c]:
            if counter[x] != q:
                return False
        return a^b^c == 0
    return False
print('Yes' if solve(N, A) else 'No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))
n = N // 3
dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = True

if len(dic) > 3:
    ans = False

elif len(dic) == 3:
    keys = dic.keys()
    t = []
    for k in keys:
        t.append(k)
        if dic[k] != n:
            ans = False

    a = t[0]
    b = t[1]
    c = t[2]

    if (a ^ b) != c:
        ans = False

elif len(dic) == 2:
    for k in dic:
        if k == 0:
            if dic[k] != n:
                ans = False
        else:
            if dic[k] != n * 2:
                ans = False

else:
    keys = dic.keys()
    if not 0 in keys:
        ans = False

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

Submission status: Accepted

Solution code:
from collections import*
n,*A=map(int,open(0).read().split());C=Counter(A).items();f=1;l=len(C)
if l==3:
  x=0
  for c in C:x^=c[0]
  f=(len(set(c[1]for c in C))>1)+n%3+x>0
elif l==2:f=(abs(sum(c[1]*(-1)**i for i,c in enumerate(C)))!=n//3)+n%3>0
else:f=(l!=1)+A[0]>0
print('YNeos'[f::2])

Submission status: Accepted

Solution code:
N = int(input())
nums =list(map(int, input().split()))
a = {}
INF = 10**5
for num in nums:
  if not num in a:
    a[num] = 1
  else:
    a[num] += 1
  if len(a) > 3:
    print('No')
    exit()
def same_count(dic):
  v_max = 0
  v_min = INF
  for v in dic.values():
    v_max = max(v_max, v)
    v_min = min(v_min, v)
  return v_max == v_min
def xor_zero(dic):
  a = 0
  for k in dic.keys():
    a ^= k
  return True if a == 0 else False

def double_count(dic):
  v_max = 0
  v_min = INF
  for v in dic.values():
    v_max = max(v_max, v)
    v_min = min(v_min, v)
  return v_max == v_min*2 and dic[0] == v_min

answer = False
if len(a) == 3:
  answer = same_count(a) and xor_zero(a)
elif len(a) == 2:
  answer = 0 in a.keys() and double_count(a)
elif len(a) == 1:
  answer = 0 in a.keys()
if answer:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

if N % 3 != 0:
    res = 'Yes'
    for i in range(N):
        if a_ls[i] != 0:
            res = 'No'
else:
    res = 'Yes'
    c = Counter(a_ls)
    if len(c) > 3:
        res = 'No'
    if len(c) == 3:
        if not list(c.values())[0] == list(c.values())[1] == list(c.values())[2]:
            res = 'No'
        for i in c.keys():
            for j in c.keys():
                for k in c.keys():
                    if i!=j and j!=k and k!=i and not i^j==k:
                        res = 'No'
    elif len(c) == 2:
        if not (list(c.values())[0] == N//3 or list(c.values())[1] == N//3):
            res = 'No'
        if list(c.values())[0] == N//3:
            if not list(c.keys())[0] == 0:
                res = 'No'
        if list(c.values())[1] == N//3:
            if not list(c.keys())[1] == 0:
                res = 'No'
    else:
        for i in range(N):
            if a_ls[i] != 0:
                res = 'No'
        
print(res)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

A = list(map(int, input().split()))
c = Counter(A)
a = list(set(A))


if len(a) >= 4:
    ans = False

elif len(a) == 3:
    a, b, d = a
    if c[a] == c[b] and c[b] == c[d] and a^b == d and d^b == a and a^d == b:
        ans = True
    else:
        ans = False

elif len(a) == 2:
    a, b = sorted(a)
    if a == 0 and c[a] == N/3 and c[b] == (N/3)*2:
        ans = True
    else:
        ans = False

elif len(a) == 1:
    if sum(a) == 0:
        ans = True
    else:
        ans = False

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

Submission status: Accepted

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

flag=False
if sum(a)==0:
    flag=True
elif N%3==0:
    if len(a_set)==2:
        x,y=a_set
        if x==0 and a.count(x)*3==N:
            flag=True
    elif len(a_set)==3:
        x,y,z=a_set
        if x^y^z==0 and a.count(x)==a.count(y) and a.count(y)==a.count(z):
            flag=True

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

Submission status: Accepted

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

if a.count(0)==n:
  print('Yes')
  exit()

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


x=list(set(a))

z=[]

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

for i in x:
  if a.count(i)==n//3:
    z+=[i]
  
  elif a.count(i)==(n//3)*2:
    z+=[i]
    z+=[i]

  elif a.count(i)==n:
    z+=[i]
    z+=[i]
    z+=[i]

  else:
    print('No')
    exit()


ans=0

for i in z:
  ans^=i

if ans==0:
  print('Yes')

else:
  print('No')

Submission status: Accepted

Solution code:
def get_caps(a):
  dic = dict()

  for ai in a:
    dic.setdefault(ai, 0)
    dic[ai] += 1

  return dic


def is_match(caps):
  global N

  if 0 in caps.keys():
    if caps[0] == N:
      return True
  
  if N % 3 == 0:
    if 0 in caps.keys() and len(caps) == 2:
      if caps[0] == N//3:
        return True
    elif len(caps) == 3:
      x, y, z = caps.keys()
    
      if x ^ y ^ z == 0:
        if caps[x] == caps[y] == caps[z] == N//3:
          return True


# A - XOR Circle
N = int(input())
a = list(map(int, input().split()))

# 帽子の情報をdictに入れる
caps = get_caps(a)

if is_match(caps):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
if sum(a)==0:
  print('Yes')
else:
  if n%3!=0:
    print('No')
  else:
    s = len(set(a))
    if s>3:
      print('No')
    else:
      l = Counter(a)
      tf = 1
      if s==3:
        for v in l.values():
          if v!=n//3:
            tf = 0
        li = list(set(a))
        if li[0]^li[1]^li[2]!=0:
          tf = 0
      elif s==2:
        if 0 not in l.keys():
          tf = 0
        else:
          for k in l.keys():
            if k==0 and l[k]!=n//3:
              tf = 0
      else:
        tf = 0
      print('Yes' if tf else 'No')

Submission status: Accepted

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

d = defaultdict(int)

for i in a:
  d[i] += 1

a.sort()
if max(a) == 0 and min(a) == 0:
  print ('Yes')
  exit()
b = set(a)
if len(b) == 3:
  c = 0
  for i in b:
    c ^= i
  if c == 0:
    flg = 0
    for i in d:
      if d[i] != n/3:
        flg = 1
    if flg == 1:
      print ('No')
    else:
      print ('Yes')
  else:
    print ('No')
  exit()
else:
  if min(a) == 0 and d[min(a)] ==n/3 and d[max(a)] == (2*n)/3:
    print('Yes')
  else:
    print ('No')
  exit()
print ('No')

Submission status: Accepted

Solution code:
N=int(input())
a_list=list(map(int,input().split()))
a_set=set(a_list)
if len(a_set)==1:
    if sum(a_set)==0:
        print("Yes")
    else:
        print("No")
elif len(a_set)==2:
    a_1, _=sorted(a_set)
    if a_1==0:
        if a_list.count(a_1)*3==N:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

elif len(a_set)==3:
    a_1,a_2,a_3=a_set
    if a_list.count(a_1)==a_list.count(a_2) and a_list.count(a_2)==a_list.count(a_3):
        if a_1 ^ a_2 == a_3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:print("No")

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

C=Counter(A)
NUM=[]
if n%3!=0:
    if len(C)!=1 or A[0]!=0:
        print("No");exit()
    else:
        print("Yes");exit()
if all([i%(n//3)==0 for i in C.values()]):
    for i,v in C.items():
        if v==n//3:
            NUM.append(i)
        if v==n*2//3:
            NUM.append(i)
            NUM.append(i)
        if v==n:
            if i==0:print("Yes");exit()
            print("No");exit()
    a,b,c=NUM
    print("Yes" if a^b==c else "No");exit()
print("No")

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = Counter(A)

if len(cnt) == 1:
    if cnt[0] == n:
        print('Yes')
    else:
        print('No')
elif len(cnt) == 2:
    if cnt[0] == n/3:
        print('Yes')
    else:
        print('No')
elif len(cnt) == 3:
    test = 0
    for p in cnt.keys():
        if cnt[p] != n/3:
            print('No')
            break
        test ^= p
    else:
        if not test:
            print('Yes')
        else:
            print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter

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

k, v = list(Counter(a).keys()), list(Counter(a).values())
if len(k) == 3 and k[0] ^ k[1] == k[2] and v[0] == v[1] == v[2] :
    print('Yes')
elif len(k) == 2 and ((k[0] == 0 and v[0] * 2 == v[1]) or (k[1] == 0 and v[1] * 2 == v[0])) :
    print('Yes')
elif len(k) == 1 and k[0] == 0 :
    print('Yes')
else :
    print('No')

Submission status: Accepted

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

if a.count(0)==n:
  print('Yes')
  exit()

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


x=list(set(a))

z=[]

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

for i in x:
  if a.count(i)==n//3:
    z+=[i]
  
  elif a.count(i)==(n//3)*2:
    z+=[i]
    z+=[i]

  elif a.count(i)==n:
    z+=[i]
    z+=[i]
    z+=[i]

  else:
    print('No')
    exit()


ans=0

for i in z:
  ans^=i

if ans==0:
  print('Yes')

else:
  print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int, input().split(" "))))
if sum(a) == 0:
  print("Yes")
elif n % 3 != 0:
  print("No")
else:
  ass = [a[0], a[n // 3], a[n // 3 * 2]]
  #print(a.count(ass[0]), (n // 3))
  if a.count(ass[0]) % (n // 3) != 0 or a.count(ass[1]) % (n // 3) != 0 or a.count(ass[2]) % (n // 3) != 0:
    print("No")
  else:
    if ass[0] ^ ass[1] != ass[2]:
      print("No")
    else:
      print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict
def main3():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()

    c = defaultdict(int)
    for a in A:
        c[a] += 1

    if len(c) == 1:
        n = list(c.keys())
        if n[0] == 0:
            print("Yes")
        else:
            print("No")
    
    elif len(c) == 2:
        n = list(c.keys())
        if n[0] == 0 and c[n[1]] == 2*c[n[0]]:
            print("Yes")
        else:
            print("No")
    
    elif len(c) == 3:
        n = list(c.keys())

        if (n[0] ^ n[1] ^ n[2]) == 0 and (c[n[0]] == c[n[1]] == c[n[2]] == N//3):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

if __name__ == "__main__":
    main3()

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    cnt = collections.Counter(a)
    kind = len(cnt)

    ans = False
    if kind == 1:
        ans |= a[0] == 0
    elif kind == 2:
        key = list(cnt.keys())
        value = list(cnt.values())
        if 0 in key:
            x = key[0]^key[1]
            ans = cnt[0]*2 == cnt[x]
    elif kind == 3:
        key = list(cnt.keys())
        value = list(cnt.values())
        ans = True
        ans &= key[0]^key[1] == key[2]
        ans &= key[1]^key[2] == key[0]
        ans &= key[2]^key[0] == key[1]
        ans &= len(set(value)) == 1
    print("Yes" if ans else "No")
main()

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)
s = list(set(a))
l = len(s)

if l == 1 and a[0] == 0:
    print('Yes')
    exit()
if len(a) % 3 == 0:
    if l == 2 and c[0] == n // 3:
        print('Yes')
        exit()
    if l == 3 and s[0] ^ s[1] ^ s[2] == 0:
        tmp = n//3
        if all(x == tmp for x in c.values()):
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = set(A)
if len(S) > 3:
    print("No")
elif len(S) == 1:
    if A[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(S) == 2:
    if A.count(0) == N // 3 and N % 3 == 0:
        print("Yes")
    else:
        print("No")
else:
    L = list(S)
    y = L[0] ^ L[1] ^ L[2]
    if all(A.count(x) == N // 3 for x in S) and N % 3 == y == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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


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

    c = collections.Counter(a).most_common()
    ans = "No"
    if len(c) == 3 and c[0][1] == c[1][1] == c[2][1]:
        if c[0][0] ^ c[1][0] ^ c[2][0] == 0:
            ans = "Yes"
    elif len(c) == 2 and c[0][1] == 2 * c[1][1]:
        if c[0][0] ^ c[0][0] ^ c[1][0] == 0:
            ans = "Yes"
    elif len(c) == 1 and c[0][0] == 0:
        ans = "Yes"
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())

l=sorted(list(map(int,input().split())))
zero=l.count(0)
if zero==N:
   print("Yes")
   exit()
elif len(set(l)) == 2:
   s=l.count(l[-1])
   if zero==N//3 and s==N*2//3:
      print("Yes")
      exit()
elif len(set(l))==3:
   a,b,c=list(set(l))
   if a^b^c==0 and l.count(a)== l.count(b)==l.count(c):
      print("Yes")
      exit()
print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] +=1
if len(d) == 1 and 0 in d:
    print('Yes')
elif len(d) == 2:
    for i in d:
        if i == 0 and d[i] * 3 != N or i != 0 and d[i] * 3 != 2 * N:
            print('No')
            exit()
    print('Yes')
elif len(d) == 3:
    s = 0
    for i in d:
        s ^= i
        if d[i] * 3 != N:
            print('No')
            exit()
    if s != 0:
        print('No')
    else:
        print('Yes')
else:
    print('No')