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:
#!/usr/bin/env python3
import sys
from bisect import bisect_left
from collections import Counter
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, a: "List[int]"):
    b = list(set(a))
    if len(b) == 3:
        if N % 3 == 0:
            if b[0] ^ b[1] == b[2] or b[0] ^ b[2] == b[1]:
                yes()
                return
    elif len(b) == 2:
        if (b[0] == 0 or b[1] == 0) and N % 3 == 0:
            yes()
            return

    elif len(b) == 1:
        if b[0] == 0:
            yes()
            return

    no()
    return

    # print(*keta, sep="\n")
    # def solve(N: int, a: "List[int]"):
    #     a.sort()
    #     used = Counter(a)
    #     used_orig = used.copy()
    #     x = [a[0]]
    #     used[0] -= 1

    #     # print("first, ", a[0])
    #     # 2番目の帽子を全探索
    #     for i in range(1, N):
    #         # print("2nd, ", a[i])
    #         x.append(a[i])
    #         used[i] -= 1
    #         for j in range(2, N):
    #             cand = x[-1] ^ x[-2]
    #             # print("cand, ", cand)
    #             pl = bisect_left(a, cand)
    #             if pl >= len(a):
    #                 break
    #             if cand == a[pl] and used[cand] > 0:
    #                 x.append(cand)
    #                 used[pl] -= 1
    #             else:
    #                 break
    #         else:
    #             yes()
    #             print(x)
    #             print(used)
    #             return
    #         x = [a[0]]
    #         used = used_orig.copy()
    #     no()
    #     return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_left
from collections import Counter
INF = float("inf")

# KETA_MAX = 10


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, a: "List[int]"):
    b = list(set(a))
    if len(b) == 3:
        if N % 3 == 0:
            if b[0] ^ b[1] == b[2] or b[0] ^ b[2] == b[1]:
                yes()
                return

    if len(b) == 1:
        if b[0] == 0:
            yes()
            return

    no()
    return

    # print(*keta, sep="\n")
    # def solve(N: int, a: "List[int]"):
    #     a.sort()
    #     used = Counter(a)
    #     used_orig = used.copy()
    #     x = [a[0]]
    #     used[0] -= 1

    #     # print("first, ", a[0])
    #     # 2番目の帽子を全探索
    #     for i in range(1, N):
    #         # print("2nd, ", a[i])
    #         x.append(a[i])
    #         used[i] -= 1
    #         for j in range(2, N):
    #             cand = x[-1] ^ x[-2]
    #             # print("cand, ", cand)
    #             pl = bisect_left(a, cand)
    #             if pl >= len(a):
    #                 break
    #             if cand == a[pl] and used[cand] > 0:
    #                 x.append(cand)
    #                 used[pl] -= 1
    #             else:
    #                 break
    #         else:
    #             yes()
    #             print(x)
    #             print(used)
    #             return
    #         x = [a[0]]
    #         used = used_orig.copy()
    #     no()
    #     return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_left
from collections import Counter
INF = float("inf")

# KETA_MAX = 10


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, a: "List[int]"):
    b = list(set(a))
    if len(b) == 3:
        if N % 3 == 0:
            if b[0] ^ b[1] == b[2]:
                yes()
                return

    if len(b) == 1:
        if b[0] == 0:
            yes()
            return

    no()
    return

    # print(*keta, sep="\n")
    # def solve(N: int, a: "List[int]"):
    #     a.sort()
    #     used = Counter(a)
    #     used_orig = used.copy()
    #     x = [a[0]]
    #     used[0] -= 1

    #     # print("first, ", a[0])
    #     # 2番目の帽子を全探索
    #     for i in range(1, N):
    #         # print("2nd, ", a[i])
    #         x.append(a[i])
    #         used[i] -= 1
    #         for j in range(2, N):
    #             cand = x[-1] ^ x[-2]
    #             # print("cand, ", cand)
    #             pl = bisect_left(a, cand)
    #             if pl >= len(a):
    #                 break
    #             if cand == a[pl] and used[cand] > 0:
    #                 x.append(cand)
    #                 used[pl] -= 1
    #             else:
    #                 break
    #         else:
    #             yes()
    #             print(x)
    #             print(used)
    #             return
    #         x = [a[0]]
    #         used = used_orig.copy()
    #     no()
    #     return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_left
from collections import Counter
INF = float("inf")

# KETA_MAX = 10


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, a: "List[int]"):
    b = list(set(a))
    if len(b) == 3:
        if N % 3 == 0:
            if b[0] ^ b[1] == b[2]:
                yes()
                return

    if len(b) == 1:
        if b[0] == 0:
            yes()

    no()
    return

    # print(*keta, sep="\n")
    # def solve(N: int, a: "List[int]"):
    #     a.sort()
    #     used = Counter(a)
    #     used_orig = used.copy()
    #     x = [a[0]]
    #     used[0] -= 1

    #     # print("first, ", a[0])
    #     # 2番目の帽子を全探索
    #     for i in range(1, N):
    #         # print("2nd, ", a[i])
    #         x.append(a[i])
    #         used[i] -= 1
    #         for j in range(2, N):
    #             cand = x[-1] ^ x[-2]
    #             # print("cand, ", cand)
    #             pl = bisect_left(a, cand)
    #             if pl >= len(a):
    #                 break
    #             if cand == a[pl] and used[cand] > 0:
    #                 x.append(cand)
    #                 used[pl] -= 1
    #             else:
    #                 break
    #         else:
    #             yes()
    #             print(x)
    #             print(used)
    #             return
    #         x = [a[0]]
    #         used = used_orig.copy()
    #     no()
    #     return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections, itertools
N = int(input())
A = [int(_) for _ in input().split()]
C = sorted(collections.Counter(A).most_common(), key=lambda xs: -xs[1])
f = 0
if len(C) == 1:
    a, la = C[0]
    #a^a^a^
    if a ^ a == a:
        f = 1
elif len(C) == 2:
    a, la = C[0]
    b, lb = C[1]
    #a^b^a^b^a^b^a^
    if la == lb + 1 and a ^ b == a and b ^ a == b == a:
        f = 1
    #a^b^a^b^a^b^
    if la == lb and a ^ b == a and b ^ a == b:
        f = 1
elif len(C) == 3:
    a, la = C[0]
    b, lb = C[1]
    c, lc = C[2]
    #x^y^(x^y)^x^y^(x^y)^
    if la == lb == lc and any(
            x ^ y == z for x, y, z in itertools.permutations((a, b, c))):
        f = 1
    #x^y^(x^y)^x^y^
    if la == lb == lc + 1:
        if any(x ^ y == c == x and y ^ c == x and c ^ x == y
               for x, y in ((a, b), (b, a))):
            f = 1
    #(y^z)^y^z^(y^z)^y^z^(y^z)^
    if lb == lc == la - 1:
        if any(a ^ y == z and y ^ z == a and z ^ a == y == a
               for y, z in ((b, c), (c, b))):
            f = 1
if f:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = [int(_) for _ in input().split()]
C = sorted(collections.Counter(A).most_common(), key=lambda xs: -xs[1])
f = 0
if len(C) == 1:
    a, la = C[0]
    #a^a^a^
    if a ^ a == a:
        f = 1
elif len(C) == 2:
    a, la = C[0]
    b, lb = C[1]
    #a^b^a^b^a^b^a^
    if la == lb + 1 and a ^ a == b and b ^ b == a and b ^ a == a:
        f = 1
    #a^b^a^b^a^b^
    if la == lb and a ^ a == b and b ^ b == a:
        f = 1
elif len(C) == 3:
    a, la = C[0]
    b, lb = C[1]
    c, lc = C[2]
    #x^y^(x^y)^x^y^(x^y)^
    if la == lb == lc and (a ^ b == c or a ^ c == b or b ^ a == c or b ^ c == a
                           or c ^ a == b or c ^ b == a):
        f = 1
    #x^y^(x^y)^x^y^
    if la == lb == lc + 1 and (a ^ b == c and a ^ b == a):
        f = 1
    #x^y^(x^y)^x^
    if lb == lc == la - 1 and (a ^ b == c and c ^ a == a):
        f = 1
if f:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
R = lambda: map(int, input().split())
 
n = int(input())
if n % 3:
    ans = 'YNeos'[any(R())::2]
else:
    a = sorted(R())
    m = n // 3
    r = range(0, n, m)
    ans = 'YNeos'[a[0] ^ a[m] ^ a[2 * m] or any(len(set(a[i:i + m])) > 1 for i in r)::2]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from sys import stdin

def main():
    N = int(input())
    A = map(int, input().split())

    cnt = Counter(A).most_common()
    if N % 3 or len(cnt) > 3:
        print('No')
        return

    n = N // 3
    for k, v in cnt:
        if not k and v == N:
            print('Yes')
            return
        elif v != n:
            print('No')
            return
    print('Yes')

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
#import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
import threading
threading.stack_size(2**25)
sys.setrecursionlimit(10**6)
mod=(10**9)+7
fact=[1]
#for i in range(1,1001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*1001
#ifact[1000]=pow(fact[1000],mod-2,mod)
#for i in range(1000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod
from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import math
import heapq
#from random import randint as rn
from Queue import Queue as Q
def modinv(n,p):
    return pow(n,p-2,p)
def ncr(n,r,p):
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t
def ain():
    return map(int,sin().split())
def sin():
    return stdin.readline().strip()
def GCD(x, y):
   while(y):
       x, y = y, x % y
   return x
def isprime(x):
    p=int(math.sqrt(x))+1
    if(x==1):
        return 0
    for i in range(2,p):
        if(x%p==0):
            return 0
    return 1
"""**************************************************************************"""
def main():
    def find(x):
        if(p[x]!=x):
            x=find(p[x])
        return p[x]
    def union(u,v):
        a=find(u)
        b=find(v)
        if(r[a]>r[b]):
            p[b]=a
        elif(r[a]<r[b]):
            p[a]=b
        else:
            p[b]=a
            r[a]+=1
    def dfs(x,y):
        if(p[x]==0):
            p[x]=1
            for i in b1[x]:
                dfs(i,x)
            if(x!=0):
                if(deg[x]%2!=0):
                    t=1
                    deg[x]+=1
                else:
                    t=0
                    deg[y]+=1
                if(c.has_key((x,y))==True):
                    if(t==1):
                        ans[c[(x,y)]]=1
                else:
                    if(t==0):
                        ans[c[(y,x)]]=1
    for _ in range(1):
        n,m=ain()
        b=[]
        r=[0]*n
        p=[i for i in range(n)]
        for i in range(m):
            x,y=ain()
            b.append((x-1,y-1))
        q=n-1
        c={}
        b1=[[] for i in range(n)]
        i=0
        while(q>0):
            g=find(b[i][0])
            h=find(b[i][1])
            if(g!=h):
                q-=1
                c[b[i]]=i
                b1[b[i][0]].append(b[i][1])
                b1[b[i][1]].append(b[i][0])
                union(b[i][0],b[i][1])
            i+=1
        deg=[0]*n
        ans=[0]*m
        for i in range(m):
            if(c.has_key(b[i])==False):
                deg[b[i][1]]+=1
        p=[0]*n
        dfs(0,-1)
        if(deg[0]%2==1):
            print -1
            continue
        else:
            for i in range(m):
                print ans[i],
            print
threading.Thread(target=main).start()

Submission status: Wrong Answer

Solution code:
N = int(input())
l = {i: a for i, a in enumerate(map(int, input().split(' ')))}
k_l = [list(l.keys())[0]]

def find():
    for k, v in l.items():
        if k in set(k_l):
            continue
        if l[k_l[-2]] ^ l[k_l[-1]] == v:
            return k
    return None

for i in list(l.keys())[1:]:
    k_l.append(i)

    key = find()
    while key is not None:
        k_l.append(key)
        if len(k_l) == N:
            print('Yes')
            exit()

    k_l = [list(l.keys())[0]]

print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
l = {i: a for i, a in enumerate(map(int, input().split(' ')))}
k_l = [list(l.keys())[0]]

def find():
    for k, v in l.items():
        if k in set(k_l):
            continue
        if l[k_l[-2]] ^ l[k_l[-1]] == v:
            return k
    return None

for i in list(l.keys())[1:]:
    k_l.append(i)

    key = find()
    while key:
        k_l.append(key)
        if len(k_l) == N:
            print('Yes')
            exit()

    k_l = [list(l.keys())[0]]

print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if all(map(lambda x:x==0,A)) or (sum(map(lambda x:x==0,A))==(N/3) and (len(set(A))==2) or (A[0]^A[1]^A[2]==0 and len(set(A))==3)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if all(map(lambda x:x==0,A)) or (sum(map(lambda x:x==0,A))==(N/3) and len(set(A))==2) or (A[0]^A[1]^A[2]==0 and len(set(A))==3):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if all(map(lambda x:x==0,A)):
    print("Yes")
elif sum(map(lambda x:x==0,A))==(N/3) and len(set(A))==2:
    print("Yes")
elif len(set(A))==3:
    if A[0]^A[1]^A[2]==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

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

c = Counter(a)

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


n =  N // 3
k = list(c.keys())
v = list(c.values())

if N % 3 == 0 and v == [n, n, n] and k[0]^k[1]^k[2] == 0:
    print("Yes")
    exit()

print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if all(map(lambda x:x==0,A)):
    print("Yes")
elif sum(map(lambda x:x==0,A))==N/3:
    print("Yes")
elif len(set(A)):
    if A[0]^A[1]^A[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()))
 
s = set(A)
sl = sorted(list(s))

if len(s)==2 and sl[0]==0:
  print("Yes")
  exit(0)

for i in range(N):
    pre_index = i - 1 if i - 1 >= 0 else A[N - 1]
    post_index = i + 1 if i + 1 <= (N - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

Submission status: Wrong Answer

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

if len(s)==2 and A.count(sl[1])==2*N//3 and sl[0]==0:
  print("Yes")
  exit(0)

for i in range(N):
    pre_index = i - 1 if i - 1 >= 0 else A[N - 1]
    post_index = i + 1 if i + 1 <= (N - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

Submission status: Wrong Answer

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

if len(s)==2 and A.count(sl[1])==2*N//3 and A.count(sl[0])==N//3 and sl[0]==0:
  print("Yes")
  exit(0)

for i in range(N):
    pre_index = i - 1 if i - 1 >= 0 else A[N - 1]
    post_index = i + 1 if i + 1 <= (N - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

Submission status: Wrong Answer

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

for i in range(N):
    pre_index = i - 1 if i - 1 >= 0 else A[N - 1]
    post_index = i + 1 if i + 1 <= (N - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

Submission status: Wrong Answer

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

for i in range(len(A)):
    post_index = i + 1 if i + 1 <= (len(A) - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

if all([a==0 for a in A]):
    Yes()
    exit()

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

C=Counter(A)
if len(C.keys())==2:
    for k, v in C.items():
        if k==0:
            if v!=N//3:
                No()
                exit()
        else:
            if v!=N//3*2:
                No()
                exit()
    Yes()
elif len(C.keys())==3:
    xor=0
    for k, v in C.items():
        xor^=v
        if v!=N//3:
            No()
            exit()
    if xor==0:
        Yes()
    else:
        No()
else:
    No()

Submission status: Wrong Answer

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

if N%3!=0:
    for j in a:
        realsum+=j
    if realsum==0:
        print('Yes')
    else:
        print('No')
else:
    kind=list(set(a))
    kindnum=len(kind)
    if kindnum == 1:
        if kind[0]==0:
            print('Yes')
        else:
            print('No')
    elif kindnum == 2:
        XOR = kind[0]^kind[1]
        numXOR = 0
        for i in a:
            if i == XOR:
                numXOR +=1
        if XOR == kind[0]:
            notNum = kind[1]
        else:
            notNum = kind[0]
        if numXOR == len(a)/3*2 and a.count(notNum) == len(a)/3:
            print('Yes')
        else:
            print('No')
    elif kindnum == 3:
        if a.count(kind[0]) == a.count(kind[1]) and a.count(kind[0])== a.count(kind[2]):
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

if all([a==0 for a in A]):
    Yes()
    exit()

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

C=Counter(A)
if len(C.keys())==2:
    for k, v in C.items():
        if k==0:
            if v!=N//3:
                No()
                exit()
        else:
            if v!=N//3*2:
                No()
                exit()
    Yes()
elif len(C.keys())==3:
    for k, v in C.items():
        if v!=N//3:
            No()
            exit()
    Yes()
else:
    No()

Submission status: Wrong Answer

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

if N%3==0 and len(s)==2 and A.count(sl[1])==2*N//3 and A.count(sl[0])==N//3 and sl[0]==0:
  print("Yes")
  exit(0)

for i in range(N):
    post_index = i + 1 if i + 1 <= (N - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

if all([a==0 for a in A]):
    Yes()
    exit()

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

C=Counter(A)
if len(C.keys())==2:
    for k, v in C.items():
        if k==0:
            if v!=N//3*2:
                No()
                exit()
        else:
            if v!=N//3:
                No()
                exit()
    Yes()
elif len(C.keys())==3:
    for k, v in C.items():
        if v!=N//3:
            No()
            exit()
    Yes()
else:
    No()

Submission status: Wrong Answer

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

if len(s) == 1 and sl[0] == 0:
  print("Yes")
  exit(0)
elif N%3==0 and len(s)==2 and A.count(sl[1])==2*N//3 and A.count(sl[0])==N//3 and sl[0]==0:
  print("Yes")
  exit(0)
for i in range(N):
    post_index = i + 1 if i + 1 <= (N - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
s = set(A)
 
if len(s) == 1 and list(s)[0] == 0:
  print("Yes")
  exit(0)
 
for i in range(N):
    post_index = i + 1 if i + 1 <= (N - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

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] = int(bin(total ^a[0]),2)
b[1] = int(bin(total ^a[1]),2)
b[2] = int(bin(total ^a[2]),2)

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

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

for i in range(2,n-1,3):
    b[(i+3)%n] = int(bin(total ^b[i%n]),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:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = len(set(a))
if l > 3:
	print("No")
elif l == 1:
	if a[0] == 0:
		print("Yes")
	else:
		print("No")
elif n%3 != 0:
	print("No")
elif l == 2:
	if 0 not in set(a):
		print("No")
	elif a.count(0) == n//3:
		print("Yes")
	else:
		print("No")
else:
	for x in list(set(a)):
		if a.count(x) != n//3:
			print("No")
			break
	else:
		print("Yes")

Submission status: Wrong Answer

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

end_frg = 0
ans = 'No'

if sum(a) == 0:
    end_frg = 1

if end_frg == 0:
    if a.count(0) == n/3 and len(set(a)) == 2:
        end_frg = 1

if end_frg == 0:
    if len(set(a)) == 3:
        a0, a1, a2 = set(a)
        if bin(a0 ^ a1 ^ a2) == 0:
            if a.count(a0)==a.count(a1)==a.count(a2):
                end_frg = 1

if end_frg == 1:
    ans = 'Yes'

print(ans)

Submission status: Wrong Answer

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

end_frg = 0
ans = 'Yes'

if sum(a) == 0:
    end_frg = 1

if end_frg == 0:
    if a.count(0) == n/3 and len(set(a)) == 2:
        end_frg = 1
    
if end_frg == 0:
    if len(set(a)) == 3:
        a0, a1, a2 = set(a)
        if bin(a0 ^ a1 ^ a2) == 0:
            if len(a.count(a0))==len(a.count(a1))==len(a.count(a2)):
                end_frg = 1

if end_frg == 0:
    ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
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]
c = a ^ b
e = {}
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 a == b and b == c:
    if d[a] == n:
        print("Yes")
        quit()
    else:
        print("No")
        quit()
if a not in d or b not in d or c not in d:
    print("No")
    quit()
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:
n = int(input())
l = list(map(int, input().split()))
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]
c = a ^ b
e = {}
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 a == b and b == c:
    if d[a] == n:
        print("Yes")
        quit()
    else:
        print("No")
        quit()
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:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = True

def check(i,j):
    c[j] -= 1
    for k in range(len(a)-1):
        if c[i^j] <= 0:
            return False
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return True


if not check(a[0],a[1]):
    hoge = False

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

Submission status: Wrong Answer

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = True

def check(i,j):
    c[j] -= 1
    for k in range(len(a)-1):
        if c[i^j] <= 0:
            return False
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return True


if check(a[0],a[1]):
    hoge = True

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

Submission status: Wrong Answer

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

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 len(numu) == 3:
  if nums.count(0) == 1:
    print("No")
    quit()

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

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

# size = 3
# nums = [1, 2, 3]

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 len(numu) == 3:
  if not nums.count(numu[0]) == nums.count(numu[1]) == nums.count(numu[2]):
    print("No")
    quit()

  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:
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:
        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:
            answer("Yes")
        else:
            answer("No")
    else:
        answer("No")

Submission status: Wrong Answer

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = False

def check(i,j):
    c[j] -= 1
    for k in range(len(a)-1):
        if c[i^j] <= 0:
            return False
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return True


if check(a[0],a[1]) or check(a[1],a[0]):
    hoge = True

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