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.

Solution in OCaml (4.02.3) (judge verdict: Accepted)

module M = Map.Make (struct type t = int let compare = compare end)

let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let check a =
        let rep = Array.length a / 3 in
        let hist = Array.fold_left (fun map v -> M.add v (1 + try M.find v map with _ -> 0) map) M.empty a in
        let cont = Array.of_list (M.fold (fun k v acc -> (k, v) :: acc) hist []) in
        match Array.length cont with
        | 1 -> fst cont.(0) = 0 
        | 2 -> let (k1, v1) = cont.(0) in
               let (k2, v2) = cont.(1) in
               if v1 = rep * 2 && v2 = rep then (
                   k2 = 0
               ) else if v2 = rep * 2 && v1 = rep then (
                   k1 = 0
               ) else false
        | 3 -> let (k1, v1) = cont.(0) in
               let (k2, v2) = cont.(1) in
               let (k3, v3) = cont.(2) in
               v1 = rep && v2 = rep && v3 = rep && k1 lxor k2 lxor k3 = 0
        | _ -> false

    in
    let main () =
        let n = int_of_string (read_line ()) in
        let a = Array.of_list (split (read_line ())) in
        let flag = if n mod 3 = 0 then (
            check a
        ) else Array.fold_left (+) 0 a = 0
        in
        print_endline (if flag then "Yes" else "No")
    in
    main ()