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:
n = int(input())
al = list(map(int,input().split()))


from collections import defaultdict
dic = {}

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

Submission status: Wrong Answer

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


from collections import defaultdict
dic = {}

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

Submission status: Wrong Answer

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


for i in range(n):
    if al[i-2] ^ al[i-1] ^ al[i] == 0:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))
if len(lin) == 1 and lin[0][1] == n:
    print("Yes")
elif n%3 != 0:
    print("No")
elif len(lin) == 2:
    lin.sort()
    if lin[0][1] == n//3:
        print("Yes")
    else:
        print("No")
elif len(lin) == 3:
    if lin[0][1] == lin[1][1] == lin[2][1] and lin[0][0]^lin[1][0]^lin[2][0] == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))
if all(li) == 0:
    print("Yes")
elif n%3 != 0:
    print("No")
elif len(lin) == 2:
    lin.sort()
    if lin[0][1] == n//3:
        print("Yes")
    else:
        print("No")
elif len(lin) == 3:
    if lin[0][1] == lin[1][1] == lin[2][1] and lin[0][0]^lin[1][0]^lin[2][0] == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))
if all(li) == 0:
    print("Yes")
elif n%3 != 0:
    print("No")
elif len(lin) == 2:
    lin.sort()
    if lin[0] == n//3:
        print("Yes")
    else:
        print("No")
elif len(lin) == 3:
    if lin[0] == lin[1] == lin[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))
if all(li) == 0:
    print("YES")
elif n%3 != 0:
    print("NO")
elif len(lin) == 2:
    lin.sort()
    if lin[0] == n//3:
        print("YES")
    else:
        print("NO")
elif len(lin) == 3:
    if lin[0] == lin[1] == lin[2]:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Submission status: Wrong Answer

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

res=0
a_set=set(a)

if n % 3 ==0:
    if len(a_set) <= 3:
        print("Yes")
        exit()
else:
    if len(a_set) ==1:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

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

res=0

for i in range(n):
    res = res ^ a[i]

if n % 3 ==0:
    if res==0:
        print("Yes")
        exit()
else:
    for i in range(n):
        if res == a[i]:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

b = list(set(a))

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

Submission status: Wrong Answer

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

b = list(set(a))

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

Submission status: Wrong Answer

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

if a.count(0) == n:
    print("Yes")
elif n % 3 == 0:
    a = [a[-1]] + a + [a[0]]
    for i in range(1, n+1):
        if a[i] != a[i-1] ^ a[i+1]:
            print("No")
            exit()
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a = [a[-1]] + a + [a[0]]

for i in range(1, n+1):
    if a[i] != a[i-1] ^ a[i+1]:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

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

a = [a[-1]] + a + [a[0]]

for i in range(1, n+1):
    print(a[i])
    if a[i] != a[i-1] ^ a[i+1]:
        print("No")

print("Yes")

Submission status: Wrong Answer

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

a = [a[-1]] + a + [a[0]]

for i in range(1, n-1):
    if a[i] != a[i-1] ^ a[i+1]:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

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

a = [a[-1]] + a + [a[0]]

for i in range(1, n-2):
    if a[i] != a[i-1] ^ a[i+1]:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

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

a = [a[-1]] + a + [a[0]]

print(a)

for i in range(1, n-2):
    if a[i] != a[i-1] ^ a[i+1]:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int,input().split()))
l_unique = sorted(list(set(lst)))

flg = False
if l_unique == [0]:
    flg = True
elif len(l_unique) == 2:
    x,y = l_unique[0], l_unique[1]
    if x==0 and n%3==0:
        if lst.count(x)==n//3 and lst.count(y)==2*(n//3):
            flg = True
elif len(l_unique) == 3:
    x,y,z = l_unique[0], l_unique[1], l_unique[2]
    if n%3 == 0:
        num = n//3
        if lst.count(x)==num and lst.count(y)==num and lst.count(z)==num:
            flg = True
print('Yes' if flg else 'No')

Submission status: Wrong Answer

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

lst.sort()
ans = [i for i in range(1,n+1)]
if lst == ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

if N % 3 != 0:
    ans = "Yes" if sum(A) == 0 else "No"
else:
    B = Counter(A)
    if len(B) != 3:
        ans = "No"
    else:
        keys = tuple(B.keys())
        vals = tuple(B.values())
        if vals[0] == vals[1] and vals[1] == vals[2]:
            a, b, c = keys
            ans = "No" if a ^ b ^ c else "Yes"
        else:
            ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
# A - XOR Circle
n=int(input())
a=list(map(int,input().split()))

ok=True
for i in range(n):
    if i==0:
        if a[i]!=a[n-1]^a[i+1]:
            ok=False
            continue
    elif i==n-1:
        if a[i]!=a[i-1]^a[0]:
            ok=False
            continue
        break

    if a[i]!=a[i-1]^a[i+1]:
        ok=False
        break
if ok:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

ans = alist[0]
for a in alist:
    ans ^= a
if ans == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

# a[0]^a[1]^a[2] == 0
# a[1]^a[2]^a[3] == 0
# すなわち a[0] == a[3] と出来れば良い

# 1)すべて0
# 2) ある値が2n/3, 0がn/3
# 3) 3つの値がそれぞれn/3ずつ
kind = len(set(a))
if kind == 1 and a[0] == 0:
    print('Yes')
    exit()
elif kind == 2 and a.count(0) == n/3:
    print('Yes')
    exit()
elif kind == 3:
    b = list(set(a))
    if a.count(b[0]) == a.count(b[1]) == a.count(b[2]) == n/3:
        print('Yes')
        exit()
print('No')

Submission status: Wrong Answer

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

# a[0]^a[1]^a[2] == 0
# a[1]^a[2]^a[3] == 0
# すなわち a[0] == a[3] と出来れば良い
if len(a) % 3 != 0:
    print('No')
elif len(a) == 3:
    if a[0] ^ a[1] ^ a[2] == 0:
        print('Yes')
    else:
        print('No')
else:
    b = list(set(a))
    if len(b) == 3:
        if b[0] ^ b[1] ^ b[2] == 0:
            print('Yes')
            exit()
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n-1):
    if a[i] != a[i-1] ^ a[i+1]:
        print('No')
        exit()
if a[n-1] != a[0] ^ a[n-2]:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
k = list(cnt.keys())
k.sort()
if len(k) == 1:
    if k[0] == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 2:
    if cnt[k[0]] == N // 3 and N % 3 == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 3:
    if cnt[k[0]] == cnt[k[1]] == cnt[k[2]]:
        print("Yes")
    else:
        print("No")
    exit()
else:
    print("No")
    exit()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
k = list(cnt.keys())
k.sort()
if len(k) == 1:
    if k[0] == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 2:
    if cnt[k[0]] == N // 2 and N % 3 == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 3:
    if cnt[k[0]] == cnt[k[1]] == cnt[k[2]]:
        print("Yes")
    else:
        print("No")
    exit()
else:
    print("No")
    exit()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
if N % 3 != 0:
    print("No")
    exit()
cnt = Counter(A)
k = list(cnt.keys())
k.sort()
if len(k) == 1:
    if k[0] == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 2:
    if cnt[k[0]] == N // 2:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 3:
    if cnt[k[0]] == cnt[k[1]] == cnt[k[2]]:
        print("Yes")
    else:
        print("No")
    exit()
else:
    print("No")
    exit()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
if N % 3 != 0:
    print("No")
    exit()
cnt = Counter(A)
k = list(cnt.keys())
k.sort()
if len(k) == 1:
    if k == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 2:
    if cnt[k[0]] == N // 2:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 3:
    if cnt[k[0]] == cnt[k[1]] == cnt[k[2]]:
        print("Yes")
    else:
        print("No")
    exit()
else:
    print("No")
    exit()

Submission status: Wrong Answer

Solution code:
import collections as c
import sys

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

A = c.Counter(a)

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

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

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

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

Submission status: Wrong Answer

Solution code:
import collections as c
import sys

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

A = c.Counter(a)

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
if(len(set(a))==0 and a[0]==0):
    print("Yes")
elif(n%3!=0):
    print("No")
else:
    seta=list(set(a))
    nums=len(set(a))
    if(nums>3):
        print("No")
    elif(nums==3):
        if(a.count(seta[0])==n//3 and a.count(seta[1])==n//3 and a.count(seta[2]) and (seta[0] ^ seta[1] ^ seta[2] == 0)):
            print("Yes")
        else:
            print("No")
    elif(nums==2):
        seta.sort()
        if(seta[0]==0 and a.count(seta[0])==n//3):
            print("Yes")
        else:
            print("No")
    elif(nums==1):
        if(seta[0]==0):
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
if(n%3!=0):
    print("No")
else:
    seta=list(set(a))
    nums=len(set(a))
    if(nums>3):
        print("No")
    elif(nums==3):
        if(a.count(seta[0])==n//3 and a.count(seta[1])==n//3 and a.count(seta[2]) and (seta[0] ^ seta[1] ^ seta[2] == 0)):
            print("Yes")
        else:
            print("No")
    elif(nums==2):
        seta.sort()
        if(seta[0]==0 and a.count(seta[0])==n//3):
            print("Yes")
        else:
            print("No")
    elif(nums==1):
        if(seta[0]==0):
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
if(n%3!=0):
    print("No")
else:
    seta=list(set(a))
    nums=len(set(a))
    if(nums>3):
        print("No")
    elif(nums==3):
        if(seta[0] ^ seta[1] ^ seta[2] == 0):
            print("Yes")
        else:
            print("No")
    elif(nums==2):
        if(a.count(seta[0])==n//3 and (seta[0] ^ seta[1] ^ seta[1] == 0)):
            print("Yes")
        elif(a.count(seta[1])==n//3 and (seta[1] ^ seta[0] ^ seta[0] == 0)):
            print("Yes")
        else:
            print("No")
    elif(nums==1):
        if(seta[0]==0):
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

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

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

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


def main():
    n = I()
    a = LI()
    c = collections.Counter(a)
    if len(c) > 3 or len(c) < 2:
        return "No"
    k = list(c.keys())
    t = [k[0], k[1]]
    c[k[0]] -= 1
    c[k[1]] -= 1
    for i in range(n-2):
        u = t[i] ^ t[i+1]
        c[u] -= 1
        t.append(u)
    if min(c.values()) < 0 or t[0] ^ t[-2] != t[-1] or t[-1] ^ t[1] != t[0]:
        return 'No'

    return 'Yes'


print(main())

Submission status: Wrong Answer

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

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

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


def main():
    n = I()
    a = LI()
    c = collections.Counter(a)
    if len(c) > 3 or len(c) < 2:
        return "No"
    k = list(c.keys())
    t = [k[0], k[1]]
    c[k[0]] -= 1
    c[k[1]] -= 1
    for i in range(n-2):
        u = t[i] ^ t[i+1]
        c[u] -= 1
        t.append(u)
    if min(c.values()) < 0 or t[0] ^ t[-2] != t[-1]:
        return 'No'

    return 'Yes'


print(main())

Submission status: Wrong Answer

Solution code:
import collections
import itertools


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

def binbin(a,b,c):
    data2={"x":bin(a)[3:],"y":bin(b)[3:],"z":bin(c)[3:]}
    length=len(bin(a)[3:])
    ite=itertools.permutations("xyz")
    for x,y,z in ite:
        data=[]
        for i in range(length):
            if not (int(data2[x][i]) + int(data2[y][i]))%2 == int(data2[z][i]):
                return(0)
    return(1)


if data[0]==N:
    print("Yes")
elif N%3==0:
    mc=data.most_common()
    if data[0] == N//3 and len(data)==2:
        print("Yes")
    elif len(data)==3 and binbin(mc[0][0],mc[1][0],mc[2][0]) and mc[0][1]==mc[1][1]==mc[2][1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

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

A = c.Counter(a)

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

x,y,z = A.keys()

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

x,y,z = A.values()

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

Submission status: Wrong Answer

Solution code:
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
a = iln()
if sum(a) == 0:
    print('Yes')
    exit()

if N % 3 != 0:
    print('No')
else:
    d = {}
    for i in range(N):
        if a[i] not in d.keys():
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    if len(d) == 3:
        for k, v in d.items():
            if v == N//3: continue
            print('No')
            break
        else:
            print('Yes')
    elif len(d) == 2:
        if 0 in d.keys() and d[0] == N//3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
a = iln()
if sum(a) == 0:
    print('Yes')
    exit()

if N % 3 != 0:
    print('No')
else:
    d = {}
    for i in range(N):
        if a[i] not in d.keys():
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    if len(d) == 3:
        for k, v in d.items():
            if v == N//3: continue
            print('No')
            break
        else:
            print('Yes')
    elif len(d) == 2:
        if 0 not in d.keys():
            print('No')
        else:
            isOK = False
            if d[0] == N//3:
                for k, v in d.items():
                    if k != 0 and v == 2*N//3:
                        isOK = True
                        break
            print('Yes' if isOK else 'No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
a = iln()
if sum(a) == 0:
    print('Yes')
    exit()

if N % 3 != 0:
    print('No')
else:
    d = {}
    for i in range(N):
        if a[i] not in d.keys():
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    if len(d) == 3:
        for k, v in d.items():
            if v == N//3: continue
            print('No')
            break
        else:
            print('Yes')
    elif len(d) == 2:
        if 0 not in d.keys():
            print('No')
        else:
            isOK = False
            if d[0] == N//3:
                for k, v in d.items():
                    if k != 0 and v == 2*N//3:
                        isOK = True
                        break
            print('Yes' if isOK else 'No')

Submission status: Wrong Answer

Solution code:
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
a = iln()
if sum(a) == 0:
    print('Yes')
    exit()

if N % 3 != 0:
    print('No')
else:
    c = collections.Counter(a)

    for k, v in c.items():
        if v == N//3: continue
        print('No')
        break
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
a = iln()
if N % 3 != 0:
    print('No')
else:
    v = []
    v.append(a[0])
    v.append(a[1])
    v.append(a[0]^a[1])
    for i in range(N):
        if a[i] != v[i%3]:
            print('No')
            break
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
if(n%3!=0):
    print("No")
else:
    nums=len(set(a))
    if(nums>3):
        print("No")
        sys.exit()

    x=len(a)//3
    for i in set(a):
        c=a.count(i)
        if(c!=x and c!=x*2 and c!=x*3):
            print("No")
            sys.exit()

    print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if(n%3!=0):
    print("No")
else:
    diff=len(a)-len(set(a))
    x=n//3 - 1
    if(diff>=x):
        print("Yes")
    else:
        print("No")