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: Wrong Answer

Solution code:
size = int(input())
nums = list(map(int, input().split()))

# size = 2
# nums = [0, 0]

numu = list(set(nums))
if len(numu) == 1 and numu[0] == 0:
  print("Yes")
  quit()

if len(numu) == 2 and nums.count(0) == 1 \
    and nums.count(0) * 3 == size:
  print("Yes")
  quit()

if not nums.count(numu[0]) and nums.count(numu[1]) and nums.count(numu[2]):
  print("No")
  quit()

if len(numu) == 3:
  if numu[0] ^ numu[2] == numu[1] \
      and numu[1] ^ numu[0] == numu[2] \
      and numu[2] ^ numu[1] == numu[0]:
    print("Yes")
    quit()

print("No")

Submission status: Wrong Answer

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

total = 0
b = [0]*(n+1)
for i in range(n):
    total = int(bin(total ^ a[i]),2) 

b[0] = a[0]
for i in range(0,n-3):
    b[i+3] = int(bin(total ^b[i]),2)

b[2] = int(bin(total ^b[-1]),2)
b[1] = int(bin(total ^b[-2]),2)
b[0] = int(bin(total ^b[-3]),2)

if n == 3:
    b[0] = int(bin(total ^a[0]),2)
    b[1] = int(bin(total ^a[1]),2)
    b[2] = int(bin(total ^a[2]),2)

b[n] = int(bin(total ^b[n-3]),2)
if b[0] == b[n]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline().strip())
numbers = tuple(map(int, sys.stdin.readline().strip().split()))
kinds = set(numbers)


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


if len(kinds) > 3:
    answer("No")

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

elif len(kinds) == 2:
    a, b = sorted(kinds)
    if a != 0:
        answer("No")
    if numbers.count(a) * 3 == n:
        answer("Yes")
    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)):
        answer("Yes")
        if a ^ b != c:
            answer("Yes")
        else:
            answer("No")
    else:
        answer("No")

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline().strip())
numbers = tuple(map(int, sys.stdin.readline().strip().split()))
kinds = set(numbers)


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


if len(kinds) > 3:
    answer("No")

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

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

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

Submission status: Wrong Answer

Solution code:
size = int(input())
nums = list(map(int, input().split()))

# size = 3
# nums = [0, 0, 0]

if size % 3 != 0:
  print("No")
  quit()

numu = list(set(nums))
if len(numu) == 1 and numu[0] == 0:
  print("Yes")
  quit()

if len(numu) == 2 and nums.count(0) == 1 \
    and nums.count(0) * 3 == size:
  print("Yes")
  quit()

if not nums.count(numu[0]) and nums.count(numu[1]) and nums.count(numu[2]):
  print("No")
  quit()

if len(numu) == 3:
  if numu[0] ^ numu[2] == numu[1] \
      and numu[1] ^ numu[0] == numu[2] \
      and numu[2] ^ numu[1] == numu[0]:
    print("Yes")
    quit()

print("No")

Submission status: Wrong Answer

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

hats = A[:]
import copy
from collections import defaultdict
d = defaultdict(lambda: 0)

for h in hats:
    d[h] += 1

def f():
    if len(d) == 3:
        xor = 0
        for key in d:
            xor ^= key
        if xor == 0:
            lsit_d = list(d.keys())
            if d[lsit_d [0]] == d[lsit_d [1]] and d[lsit_d [0]] == d[lsit_d [2]]:
                return 'Yes'
            else:
                return 'No'
        else:
            return 'No'

    if len(d) == 1:
        lsit_d = list(d.keys())
        if lsit_d [0] == 0:
            return 'Yes'
        
    if len(d) == 1:
        if d[0] * 2 == N -d[0]:
            return 'Yes'
    
    return 'No'
    
print(f())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3:
        print("No")
    elif len(x) == 3:
        x1 = bisect_right(a, x[0])
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        x3 = bisect_right(a, x[2]) - bisect_left(a, x[2])
        if ((x[0] ^ x[1] ^ x[2]) == 0) and (x1 == x2 == x3):
            print("Yes")
        else:
            print("No")
    elif len(x) == 2:
        x1 = bisect_right(a, 0) - bisect_left(a, 0)
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    elif len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

Solution code:
N = int(input())
d = list(map(int,input().split()))
d_unique = list(set(d))

if len(d_unique) == 1:
    if d_unique[0] == 0:
        print('Yes')
    else:
        print('No')

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

    else :
        if len(d_unique) == 2 :
            i1 = d_unique[0]
            i2 = d_unique[1]
            len_i1 = d.count(i1)
            len_i2 = d.count(i2)
            if len_i1 ==  N/3 and i1 & i2 & i2 == 0:
                print('Yes')
            elif len_i2 ==  N/3 and i1 & i1 & i2 == 0:
                print('Yes')                
            else :
                print('No')

        elif len(d_unique) == 3 :
            i1 = d_unique[0]
            i2 = d_unique[1]
            i3 = d_unique[2]
            len_i1 = d.count(i1)
            len_i2 = d.count(i2)
            len_i3 = d.count(i3)
            if i1 & i2 & i3 != 0:
                print('No')     
            else:
                if len_i1 ==  N/3 and len_i2 == N/3 :
                    print('Yes')
                else :
                    print('No')

Submission status: Wrong Answer

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

hats = A[:]
import copy
from collections import defaultdict
d = defaultdict(lambda: 0)

for h in hats:
    d[h] += 1

def f():
    if len(d) == 3:
        xor = 0
        for key in d:
            xor ^= key
        if xor == 0:
            lsit_d = list(d.keys())
            if d[lsit_d [0]] == d[lsit_d [1]] and d[lsit_d [0]] == d[lsit_d [2]]:
                return 'Yes'
            else:
                return 'No'
        else:
            return 'No'

    if len(d) == 1:
        lsit_d = list(d.keys())
        if lsit_d [0] == 0:
            return 'Yes'
    
    return 'No'
    
print(f())

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
counts = 0
 
for i in range(len(nums)):
  if i == 0:
    counts += nums[0] is int((nums[-1] ^ nums[1]))
  elif i == len(nums) - 1:
    counts += nums[-1] is int((nums[-2] ^ nums[0]))
  else:
    counts += nums[i] is int((nums[i - 1] ^ nums[i + 1]))
  
if counts == len(nums):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

from collections import Counter
a_dict = Counter(a_list)

start = a_list[0]
# 数を減らさない。
# a_dict[a] -= 1

a_keys = a_dict.keys()

def check():
    for a1 in a_keys:
        print("for1",start,a1)
        a0 = start
        tmp_dict = a_dict.copy()
#         tmp_dict[a1] -= 1
        for i in range(N):
#             print(" for2",i,a0,a1)
#             print(tmp_dict)
            next_a = int(bin(a0^a1), 0)
            if not next_a in tmp_dict:
#                 print(next_a," not in dict")
                break
            if tmp_dict[next_a] <= 0:
#                 print(next_a," dict 0")
                break
            a0 = a1
            a1 = next_a
            tmp_dict[next_a] -= 1
            if i == N-1:
                return True
    return False

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

for c in a[1:]:
    d[c] += 1
for i in range(1, N):
    x = a[0]
    y = a[i]
    d[y] -= 1
    for _ in range(N - 2):
        z = x ^ y
        if z in d and d[z] > 0:
            d[z] -= 1
            x = y
            y = z
        else:
            break
    else:
        if a[0] == x ^ y and a[i] == y ^ a[0]:
            print("Yes")
            exit(0)

print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3:
        print("No")
    elif len(x) == 3 and not(n % 3):
        x1 = bisect_right(a, x[0])
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        x3 = bisect_right(a, x[2]) - bisect_left(a, x[2])
        if ((x[0] ^ x[1] ^ x[2]) == 0) and (x1 == x2 == x3):
            print("Yes")
        else:
            print("No")
    elif len(x) == 2 and not (n % 3):
        x1 = bisect_right(a, 0)
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    elif len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
if n % 3 != 0:
    print("No")
    quit()
d = {}
for i in l:
    if i in d:
        d[i] += 1
    else:
        if len(d) == 3:
            print("No")
            quit()
        d[i] = 1
a = l[0]
b = l[1]
e = {}
c = a ^ b
e[a] = int(n / 3)
e[b] = int(n / 3 * (2 if b in e else 1))
e[c] = int(n / 3 if c not in e else e[c] + n / 3)
if (
        d[a] == e[a] and
        d[b] == e[b] and
        d[c] == e[c]
        ):
    print("Yes")
    quit()
print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3:
        print("No")
    elif len(x) == 3:
        x1 = bisect_right(a, x[0])
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        x3 = bisect_right(a, x[2]) - bisect_left(a, x[2])
        if ((x[0] ^ x[1] ^ x[2]) == 0) and (x1 == x2 == x3):
            print("Yes")
        else:
            print("No")
    elif len(x) == 2:
        x1 = bisect_right(a, 0)
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    elif len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

Solution code:
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if l.count(sl[0])==n and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==2 and l.count(sl[1])//l.count(sl[0])==2 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3 or n % 3:
        print("No")
    elif len(x) == 3:
        x1 = bisect_right(a, x[0])
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        x3 = bisect_right(a, x[2]) - bisect_left(a, x[2])
        if (x[0] ^ x[1] ^ x[2]) == 0 and x1 == x2 == x3:
            print("Yes")
        else:
            print("No")
    elif len(x) == 2:
        x1 = bisect_right(a, 0)
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    elif len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

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

ans = list(set(A))
l = len(ans)
if l > 3:
    print('No')
    exit()

if l == 1:
    if ans[0] == 0:
        print('Yes')
    else:
        print('No')
    exit()

if l == 2:
    a0 = ans[0]
    a1 = ans[1]
    if a0 != 0 and a1 != 0:
        print('No')
    else:
        num_a0 = A.count(ans[0])
        num_a1 = A.count(ans[1])
        if num_a0 == num_a1:
            print('Yes')
        else:
            print('No')
    exit()

a0 = ans[0]
a1 = ans[1]
a2 = ans[2]

if a0 ^ a1 != a2:
    print('No')
    exit()

num_a0 = A.count(ans[0])
num_a1 = A.count(ans[1])
num_a2 = A.count(ans[2])

if num_a0 != num_a1 or num_a0 != num_a2:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3:
        print("No")
    elif len(x) == 3:
        x1 = bisect_right(a, x[0])
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        x3 = bisect_right(a, x[2]) - bisect_left(a, x[2])
        if (x[0] ^ x[1] ^ x[2]) == 0 and x1 == x2 == x3:
            print("Yes")
        else:
            print("No")
    elif len(x) == 2:
        x1 = bisect_right(a, 0)
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    elif len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3:
        print("No")
        return
    if len(x) == 3:
        x1 = bisect_right(a, x[0])
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        x3 = bisect_right(a, x[2]) - bisect_left(a, x[2])
        if (x[0] ^ x[1] ^ x[2]) == 0 and x1 == x2 == x3:
            print("Yes")
        else:
            print("No")
    if len(x) == 2:
        x1 = bisect_right(a, 0)
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    if len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

Solution code:
# A
N = int(input())
a = list(map(int, input().split()))
flag = True
if max(a) == 0:
    print('Yes')
else:
    if N % 3 != 0:
        print('No')
    else:
        n = int(N / 3)
        a = sorted(a)
        t = []
        for i in range(3):
            tmp_list = a[n * i : n * (i + 1)]
            t.append(a[n * i])
            if i == 2:
                if min(tmp_list) == max(tmp_list):
                    if t[0] == t[1] ^ t[2] and t[1] == t[2] ^ t[0] and t[2] == t[0] ^ t[1]:
                        pass
                    else:
                        flag = False
                elif t[0] == 0 and t[1] == t[2]:
                    pass
                else:
                    flag = False
        if flag:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if len(l) != n:
  print("No")
  exit()
if len(s)==1 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==2 and l.count(sl[1])//l.count(sl[0])==2 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Wrong Answer

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

ans = list(set(A))
l = len(ans)
if l > 3:
    print('No')
    exit()

if l == 1:
    if ans[0] == 0:
        print('Yes')
    else:
        print('No')
    exit()

if l == 2:
    print('No')
    exit()

a0 = ans[0]
a1 = ans[1]
a2 = ans[2]

if a0 ^ a1 != a2:
    print('No')
    exit()

num_a0 = A.count(ans[0])
num_a1 = A.count(ans[1])
num_a2 = A.count(ans[2])

if num_a0 != num_a1 or num_a0 != num_a2:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if N % 3 > 0:
    print("No")
    exit(0)
for c in a[1:]:
    d[c] += 1
for i in range(1, N):
    x = a[0]
    y = a[i]
    d[y] -= 1
    for _ in range(N - 2):
        z = x ^ y
        if z in d and d[z] > 0:
            d[z] -= 1
            x = y
            y = z
        else:
            break
    else:
        if a[0] == x ^ y and a[i] == y ^ a[0]:
            print("Yes")
            exit(0)

print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if len(s)==1 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==2 and l.count(sl[1])//l.count(sl[0])==2 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")