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: Accepted

Solution code:
import sys
input = sys.stdin.readline


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


import collections

c = collections.Counter(a)

klist = list(c.keys())
vlist = list(c.values())

if len(klist) == 1 and klist[0] == 0:
    print('Yes')
    sys.exit()

if len(klist) == 2:
    if (klist[0] == 0 and vlist[0] == N/3) or (klist[1] == 0 and vlist[1] == N/3):
        print('Yes')
        sys.exit()

if not len(klist) == 3:
    print('No')
    sys.exit()

if not (vlist[0] == vlist[1] and vlist[1] == vlist[2]):
    print('No')
    sys.exit()

if not (klist[0] ^ klist[1] ^ klist[2] == 0):
    print('No')
    sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
B=list(A.values())
C=list(A.keys())
if len(B)>4:print("No")
elif len(B)==3:
    if B[0]==B[1]==B[2]:
        if C[0]^C[1]==C[2] or C[1]^C[2]==C[0] or C[2]^C[0]==C[1]:print("Yes")
        else:print("No")
    else:print("No")
elif len(B)==2:
    if 0 in C and A[0]*2 in B:print("Yes")
    else:print("No")
else:
    if 0 in C:print("Yes")
    else:print("No")

Submission status: Accepted

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

if len(a_unique) == 1 and a[0] == 0:
    ans = 'Yes'
elif len(a) % 3 == 0 :
    if len(a_unique) == 3:
        if bin(a_unique[0]) == bin(a_unique[1] ^ a_unique[2]) and bin(a_unique[1]) == bin(a_unique[0] ^ a_unique[2]) and bin(a_unique[2]) == bin(a_unique[1] ^ a_unique[0]) and a.count(a_unique[1]) == N//3 and a.count(a_unique[0]) == N//3 :
            ans = 'Yes'
        else:
            ans = 'No'
    elif len(a_unique) == 2:
        if a_unique[0] == 0 and a.count(a_unique[1]) == N//3 * 2:
            ans = 'Yes'
        else:
            ans = 'No'
    else:
        ans = 'No'
else:
    ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
*a,=map(int,input().split())
s=list(set(a))
s.sort()
ans="No"
if len(s)==1:
  if 0 in s:
    ans="Yes"
elif len(s)==2:
  if a.count(0)*2==a.count(s[1]):
    ans="Yes"
elif len(s)==3 and a.count(s[0])==a.count(s[1])==a.count(s[2]) and s[0]^s[1]^s[2]==0:
  ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = 0
for i in a:
    t = t^i
if t==0:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
# AGC035A - XOR Circle
from functools import reduce
from operator import xor


def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    ans = reduce(xor, A)
    print("Yes" if ans == 0 else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC035A - XOR Circle
def main():
    """
    a1 ^ a3 = a2 <-> A1 ^ a2 ^ a3 = 0
    a1~4 -> a1 ^ a2 ^ a3 = a2 ^ a3 ^ a4 = 0 -> a1 = a4
    Thus, 1) all 0
          2) 2n/3 of A: x, n/3: 0
          3) x, y, z n/3 each (x ^ y ^ z = 0)
    """
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    S = set(A)
    if S == {0}:  # (1)
        flg = 1
    elif len(S) == 2 and A.count(0) == n // 3:  # (2)
        flg = 1
    elif len(S) == 3:
        a, b, c = S
        if A.count(a) == A.count(b) == A.count(c) and a ^ b ^ c == 0:  # (3)
            flg = 1
        else:
            flg = 0
    else:
        flg = 0
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int,input().split()))
c = 0
for i in b:
    c ^= i
if c == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in a:
    ans ^= i
if ans ==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())

def xor(x,y):
    return ((x and y) or (not (x or y)))

def change(x):
    da=[True for i in range(31)]
    for i in da:
        da[i]=bool(x%2)
        x/=2
    return da

da=list(map(int,input().split()))
di={}
ans=False
for i in da:
    if i in di.keys():
        di[i]+=1
    else:
        di[i]=1
va=list(di.values())
ke=list(di.keys())
if len(di)==3:
    if va[0]==va[1] and va[0]==va[2]:
        if ke[0]^ke[1]==ke[2]:
            ans=True
elif len(di)==2:
    if va[0]==va[1]*2 or va[1]==va[0]*2:
        if ke[0]==0 or ke[1]==0:
            ans=True

elif len(di)==1:
    if ke[0]==0:
        ans=True
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

if set(A) == {0}:
    print('Yes')
    exit()


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

c = collections.Counter(A)

for v in c.values():
    if v % (N//3) != 0:
        print('No')
        exit()


if len(c) == 2 and c.most_common()[1][0] == 0 and c.most_common()[0][0] ^ 0 == c.most_common()[0][0]:
    print('Yes')
    exit()
elif len(c) == 3 and \
        (c.most_common()[0][0] ^ c.most_common()[1][0] ^ c.most_common()[2][0]) == 0:
    print('Yes')
    exit()


else:
    print('No')

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    _ = int(input())
    a_lists = [int(x) for x in stdin.readline().rstrip().split()]
    z = 0

    for a in a_lists:
        z ^= a

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if n%3 == 0:
    if len(b) == 1:
        if a[0] == 0:
            print('Yes')
        else:
            print('No')
    elif len(b) == 2:
        if a.count(0) == n//3:
            print('Yes')
        else:
            print('No')
    elif len(b) == 3:
        if b[0]^b[1] == b[2]:
            if a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
elif n%3 == 1:
    if b == [0]:
        print('Yes')
    else:
        print('No')
else:
    if b==[0]:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

if cnt[0] == N:
    print('Yes')
    exit()
if N % 3:
    print('No')
    exit()

nums = []
for p, q in cnt.items():
    for i in range(q // (N // 3)):
        nums.append(p)

if len(nums) == 3 and (nums[0] ^ nums[1] ^ nums[2] == 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

x = 0
for num in numbers:
  x ^= num
  
if x == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

x = 0
for num in numbers:
  x ^= num
  
if x == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

a = Counter(a_array)

if len(a) == 1 and a[0] == N:
    print("Yes")
    exit()

if len(a) == 2 and N % 3 == 0 and a[0] == N // 3:
    print("Yes")
    exit()


if len(a) == 3:
    i_array = []
    for i, x in a.items():
        i_array.append(i)
        if x != N // 3:
            print("No")
            exit()
    else:
        if i_array[0] ^ i_array[1] == i_array[2]:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
else:
    print("No")
    exit()

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
e = {}
for i in b:
    if i not in e:
        e[i] = 1
    else:
        e[i] += 1
if len(e) > 3:
    print("No")
elif len(e) == 3:
    x, y, z = map(int, e.keys())
    xx, yy, zz = map(int, e.values())
    if x ^ y == z and y ^ z == x and z ^ x == y and xx == yy == zz:
        print("Yes")
    else:
        print("No")
elif len(e) == 2:
    x, y = map(int, e.keys())
    xx, yy = map(int, e.values())
    if (x == 0 and 2 * xx == yy) or (y == 0 and xx == 2 * yy):
        print("Yes")
    else:
        print("No")
elif len(e) == 1:
    x = list(map(int, e.keys()))[0]
    if x == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
D=dict()
for i in range(N):
    if a[i] in D:
        D[a[i]]+=1
    else:
        D[a[i]]=1
L=list(D.items())
L.sort()
#print(L)

if len(L)==1:
    if L[0][0]==0:
        print("Yes")
        exit()
elif len(L)==2:
    if L[0][0]==0 and L[1][1]==L[0][1]*2:
        print("Yes")
        exit()
elif len(L)==3:
    #print(1)
    if L[0][1]==L[1][1] and L[1][1]==L[2][1]:
        #print(2)
        if L[1][0]==L[0][0]^L[2][0] and L[2][0]==L[1][0]^L[0][0] and L[0][0]==L[1][0]^L[2][0]:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
def main():

    """ convenient functions
    # for i, a in enumerate(iterable)
    # q, mod = divmod(a, b)
    # divmod(x, y) returns the tuple (x//y, x%y)
    # Higher-order function: reduce(operator.mul, xyz_count, 1)
    # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
    """

    """convenient decorator
    # @functools.lru_cache():
    # to facilitate use of recursive function
        # ex:
        # from functools import lru_cache
        # import sys
        # sys.setrecursionlimit(10**9)
        # @lru_cache(maxsize=None)
        # def fib(n):
        #     if n < 2:
        #         return n
        #     return fib(n-1) + fib(n-2)
        # print(fib(1000))
    """
    
    # import numpy as np
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
    # accumulate() returns iterator! to get list: list(accumulate())
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  # prime factor
        b, e = 2, 0  # base, exponent
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        # TODO: How should I do when n - r is negative?
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
    from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
    import operator
    from operator import itemgetter
    # ex1: List.sort(key=itemgetter(1))
    # ex2: sorted(tuples, key=itemgetter(1,2))
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    # first create factorial_list
    # fac_list = mod_factorial_list(n)
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
    def modinv(a, p = MOD):
        # evaluate reciprocal using Fermat's little theorem:
        # a**(p-1) is identical to 1 (mod p) when a and p is coprime
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        # fac_list = modfactorial_list(100)
        # print(modcomb(100, 5, modfactorial_list(100)))
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    class UFT:
        """union find tree class
        TODO: fix this description...
        how to use (example):
        >>  UF = UFT(N) 
        >>  if UF.find_root(a) == UF.find_root(b):
        >>      do something
        >>  else:
        >>      do something
        >>      UF.unite(a, b)
        """
        def __init__(self, N):
            self.root = [-1] * (N+1)
            self.rank   = [0]  * (N+1)
            self.connected_num = [1] * (N+1)
    
        def find_root(self,x):
            root = self.root
            while root[x] != -1:
                x = root[x]
            return x
    
        def unite(self,x,y):
            root = self.root
            rank = self.rank
            connected_num = self.connected_num
            find_root = self.find_root
    
            x = find_root(x)
            y = find_root(y)
            if x != y:
                if rank[x] < rank[y]:
                    root[x] = root[y]
                    x,y = y,x
                if rank[x] == rank[y]:
                    rank[x] += 1
                root[y] = x       
                connected_num[x] += connected_num[y]

    """ initialize variables and set inputs
    # initialize variables
        # to initialize list, use [0] * n
        # to initialize two dimentional array, use [[0] * N for _ in range(N)]
    # set inputs
        # open(0).read() is a convenient method:
        # ex) n, m, *x = map(int, open(0).read().split())
        #     min(x[::2]) - max(x[1::2])
        # ex2) *x, = map(int, open(0).read().split())
        #     don't forget to add comma after *x if only one variable is used
    # preprocessing
        # transpose = [x for x in zip(*data)]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
        # flat = [flatten for inner in data for flatten in inner]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    # calculate and output
        # output pattern
        # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
    """

    # functions used
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    # single int: int(r())
    # single string: r()
    # single float: float(r())
    # line int: R()
    # line string: r().split()
    # line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
    # lines int: [R() for _ in range(n)]
    """

    if __name__ != '__main__':
        # for test
        sys.stdin = open('sample.txt')

    # ----------------------------------
    # main

    N = int(r())
    A = R()
    cnt = Counter(A)
    if cnt[0] == N:
        print('Yes')
    elif cnt[0] == N//3 and len(cnt.keys()) == 2:
        print('Yes')
    elif len(cnt.keys()) == 3:
        flag = True
        tmp = 0
        for (key, val) in cnt.items():
            if val != N//3:
                flag = False
            tmp = tmp ^ key
        if flag and tmp == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
    
    # end of main
    # ----------------------------------

    """memo: how to use defaultdict of list
    # initialize
    Dic = defaultdict(list)
    # append / extend
    Dic[x].append(y)
    # for
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import copy
import sys
import math

def main():
	n = int(input())
	a = list(map(int,input().split()))
	a.sort()
	xor = a[0] ^ a[1]
	for i in range(2,n):
		xor = xor ^ a[i]
	if(xor == 0):
		print('Yes')
	else:
		print('No')


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
a1=A[0]
SumA=a1
SumA2=a1^a1
for i in range(1,N):
    a=A[i]
    SumA^=a
    SumA2^=a^a

if(SumA==SumA2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for a in A:
    ans = a ^ ans 
if ans == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

X = 0

for num in num_hats:
    X ^= num

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(_) for _ in input().split()]
a = sorted(a)
s = set(a)

if len(s) == 1:
    if a[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(s) == 2:
    if N % 3 != 0:
        print("No")
    else:
        if a.count(0) == N//3:
            print("Yes")
        else:
            print("No")
elif len(s) == 3:
    if a[0] == 0:
        print("No")
    else:
        L = []
        for i in s:
            L.append(i)
        
        if L[0] ^ L[1] == L[2]:
            p = a.count(L[0])
            q = a.count(L[1])
            r = a.count(L[2])
            if p == q and q == r:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter

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

arr.sort()
c = Counter(arr)

if N % 3 == 0:
    if len(c) == 3:
        x1, x2 = c.most_common()[0]
        y1, y2 = c.most_common()[1]
        z1, z2 = c.most_common()[2]
        if x2 == y2 == z2 and x1 ^ y1 == z1:
            print("Yes")
            exit()
    elif len(c) == 2:
        x1, x2 = c.most_common()[0]
        y1, y2 = c.most_common()[1]
        if x2 == 2 * y2 and y1 == 0:
            print("Yes")
            exit()

if N % 2 == 0:
    if len(c) == 2:
        x1, x2 = c.most_common()[0]
        y1, y2 = c.most_common()[1]
        if x2 == y2 and y1 == 0:
            print("Yes")
            exit()

if len(c) == 1:
    x1, x2 = c.most_common()[0]
    if x1 == 0:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 21 19:31:27 2019

@author: yama
"""

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

x = 0
for i in l:
    x ^= i
    
if x == 0:
    print("Yes")
    
else:
    print("No")

Submission status: Accepted

Solution code:
# AGC035A_XORCircle.py

import sys

n = int(input())
numbers = tuple(map(int, input().split()))
kinds = set(numbers)


def answer(ans):
    print(ans)
    sys.exit()


if kinds == {0}:
    answer("Yes")

elif len(kinds) == 2:
    a, b = sorted(kinds)
    if a == 0:
        if numbers.count(a) * 3 == n:
            answer("Yes")
        else:
            answer("No")
    else:
        answer("No")

elif len(kinds) == 3:
    a, b, c = tuple(kinds)
    if (numbers.count(a) == numbers.count(b)) and (numbers.count(b) == numbers.count(c)):
        if a ^ b == c:  # "ko(up)ko(down)"
            answer("Yes")
        else:
            answer("No")
    else:
        answer("No")
else:
    answer("No")

Submission status: Accepted

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

ans=0
for i in range(len(li)):
  ans=ans^li[i]
if ans==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

if 0 in A:
  if len(set(A)) == 1:
    print("Yes")
    exit()
  elif len(set(A)) == 2:
    if A.count(0) *2 == (len(A)-A.count(0)):
      print("Yes")
      exit()
elif len(set(A)) == 3:
  temp =  list(set(A))
  if A.count(temp[0]) == A.count(temp[1]) == A.count(temp[2]):
    if (temp[0] ^ temp[1]) == temp[2]:
      print("Yes")
      exit()
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

lset = set(l)

if len(lset) == 1:
    if l[0] == 0:
        print("Yes")
    else:
        print("No")

elif N%3 == 0:
    if len(lset) == 2:
        k = list(lset)
        k.sort()
        if k[0]^k[1] == k[1] and l[int(N/3)] == k[1] and l[int(N/3 - 1)] == 0:
            print("Yes")
        else:
            print("No")
    
    elif len(lset) == 3:
        k = list(lset)
        k.sort()
        if k[0]^k[1] == k[2] or k[0]^k[2] == k[1]:
            c0 = 0
            c1 = 0
            for i in l:
                if i == k[0]:
                    c0 += 1
                elif i == k[1]:
                    c1 += 1
            if c0 == N/3 and c1 == N/3:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")
    
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

lset = set(l)

if N%3 == 0:
    if len(lset) == 1:
        if l[0] == 0:
            print("Yes")
        else:
            print("No")
            
    elif len(lset) == 2:
        k = list(lset)
        k.sort()
        if k[0]^k[1] == k[1] and l[int(N/3)] == k[1] and l[int(N/3 - 1)] == 0:
            print("Yes")
        else:
            print("No")
    
    elif len(lset) == 3:
        k = list(lset)
        k.sort()
        if k[0]^k[1]^k[2] == 0:
            c0 = 0
            c1 = 0
            for i in l:
                if i == k[0]:
                    c0 += 1
                elif i == k[1]:
                    c1 += 1
            if c0 == N/3 and c1 == N/3:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
            
    else:
        print("No")

else:
    if len(lset) == 1:
        if l[0] == 0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

lset = set(l)

if N%3 == 0:
    if len(lset) == 1:
        if l[0] == 0:
            print("Yes")
        else:
            print("No")
            
    elif len(lset) == 2:
        k = list(lset)
        k.sort()
        if k[0]^k[1] == k[1] and l[int(N/3)] == k[1] and l[int(N/3 - 1)] == 0:
            print("Yes")
        else:
            print("No")
    
    elif len(lset) == 3:
        k = list(lset)
        k.sort()
        if k[0]^k[1] == k[2] or k[0]^k[2] == k[1]:
            c0 = 0
            c1 = 0
            for i in l:
                if i == k[0]:
                    c0 += 1
                elif i == k[1]:
                    c1 += 1
            if c0 == N/3 and c1 == N/3:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
            
    else:
        print("No")

else:
    if len(lset) == 1:
        if l[0] == 0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

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

set_inputs = set(inputs)
if N % 3 == 0:
    list_inputs = list(set_inputs)
    if (len(set_inputs) == 3 
    and list_inputs[0] == (list_inputs[1] ^ list_inputs[2]) 
    and (inputs.count(list_inputs[0]) == inputs.count(list_inputs[1]) == inputs.count(list_inputs[2]))):
        print('Yes')
    elif len(set_inputs) == 2:
        list_inputs = list(set_inputs)
        if inputs.count(list_inputs[0]) > inputs.count(list_inputs[1]):
            more = list_inputs[0]
            less = list_inputs[1]
        else:
            more = list_inputs[1]
            less = list_inputs[0]
        if less == 0 and inputs.count(more) == inputs.count(less) * 2:
            print('Yes')
        else:
            print('No')
    elif len(set_inputs) == 1:
        if inputs[0] == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if set_inputs == set([0]):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
sum = 0
for i in a:
	sum^=i
if sum == 0:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

sum = 0
for i in range(N):
    sum ^= a[i]

print('Yes' if sum == 0 else 'No')

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
all = 0
for i in a:
    all^=i
print('YNeos'[all!=0::2])

Submission status: Accepted

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

if len(B) == 1 and B[0] == 0:
    print('Yes')
    exit()

if N % 3 == 0:
    if len(B) == 2 and A.count(0) == N // 3:
        print('Yes')
        exit()
    if len(B) == 3 and A.count(B[0]) == A.count(B[1]) == A.count(B[2]):
        if B[0] ^ B[1] ^ B[2] == 0:
            print('Yes')
            exit()

print('No')