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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

void input() {}
template <class T, class... Ts> void input(T &a, Ts &... as) {
  cin >> a;
  input(as...);
}
template <class V> istream &operator>>(istream &i, vector<V> &a) {
  for (auto &e : a)
    i >> e;
  return i;
}

void print() { cout << endl; }
template <class T> void print(T const &a) { cout << a << endl; }
template <class T, class... Ts> void print(T const &a, Ts const &... as) {
  cout << a << " ";
  print(as...);
}
using OS = ostream;
template <class F, class S> OS &operator<<(OS &o, pair<F, S> const &pair) {
  return o << "(" << pair.first << " : " << pair.second << ")";
}
template <size_t I, size_t N, class... Ts> struct OutputTuple;
template <> struct OutputTuple<1, 0> {
  OS &operator()(OS &o, tuple<> const &t) { return o; }
};
template <size_t N, class... Ts> struct OutputTuple<N, N, Ts...> {
  OS &operator()(OS &o, tuple<Ts...> const &t) { return o << get<N - 1>(t); }
};
template <size_t I, size_t N, class... Ts> struct OutputTuple {
  OS &operator()(OS &o, tuple<Ts...> const &t) {
    return OutputTuple<I + 1, N, Ts...>{}(o << get<I - 1>(t) << ",", t);
  }
};
template <class... Ts> OS &operator<<(OS &o, tuple<Ts...> const &t) {
  return OutputTuple<1, sizeof...(Ts), Ts...>{}(o << "(", t) << ")";
}
template <class C> ostream &outputContainer(OS &o, C const &a) {
  o << "[";
  for (auto i = a.begin(), e = a.end(); i != e; o << ((++i != e) ? ", " : ""))
    o << *i;
  return o << "]";
}
template <class V> OS &operator<<(OS &o, list<V> const &a) {
  return outputContainer(o, a);
}
template <class V> OS &operator<<(OS &o, vector<V> const &a) {
  return outputContainer(o, a);
}
template <class V> OS &operator<<(OS &o, set<V> const &a) {
  return outputContainer(o, a);
}
template <class V> OS &operator<<(OS &o, unordered_set<V> const &a) {
  return outputContainer(o, a);
}
template <class K, class V> OS &operator<<(OS &o, map<K, V> const &a) {
  return outputContainer(o, a);
}
template <class V> OS &operator<<(OS &o, unordered_multiset<V> const &a) {
  return outputContainer(o, a);
}
template <class K, class V>
OS &operator<<(OS &o, unordered_map<K, V> const &a) {
  return outputContainer(o, a);
}

template <class Tuple, int I = tuple_size<Tuple>::value - 1> struct TupleHash {
  static size_t compute(size_t h, Tuple const &t) {
    auto v = get<I>(t);
    return TupleHash<Tuple, I - 1>::compute(h * 31 + hash<decltype(v)>{}(v), t);
  }
};
template <class Tuple> struct TupleHash<Tuple, -1> {
  static size_t compute(size_t h, Tuple const &tuple) { return h; }
};
namespace std {
template <typename... T> struct hash<tuple<T...>> {
  size_t operator()(tuple<T...> const &t) const {
    return TupleHash<tuple<T...>>::compute(17, t);
  }
};
} // namespace std

using lli = long long int;
lli gcd(lli const p, lli const q) { return q == 0 ? p : gcd(q, p % q); }
lli pow(lli const a, lli const n, lli const m) {
  return (!n) ? 1 : (n & 1) ? (((a % m) * pow(a, n - 1, m)) % m) : [=] {
    lli b = pow(a, n / 2, m);
    return (b * b) % m;
  }();
}
lli inv(lli const a, lli const p) { return pow(a, p - 2, p); }
constexpr lli MOD = 1e9 + 7;

#include <bitset>

int main() {
  int N;
  input(N);
  vector<int> a(N);
  input(a);
  string Yes = "Yes";
  string No = "No";
  /*
  vector<int> xor_sum(a.begin(), a.end());
  for (size_t i = 1; i < N; i++) {
    xor_sum[i] = xor_sum[i - 1] ^ a[i];
  }
  */
  auto x = a[0];
  auto y = a[1];
  unordered_multiset<int> a_set(a.begin(), a.end());
  vector<int> a_v(N);
  a_v[0] = x;
  a_v[1] = y;
  for (size_t j = 2; j < N; j++) {
    auto z = a_v[j - 1] ^ a_v[j - 2];
if(a_set.find(z)==a_set.end()){print("No");return 0;}
      a_v[j] = z;
  }
  // print(x, a_v, a_set);
  if (a_v[N-1]^a[1]==a[0]) {
    print(Yes);
    return 0;
  };
  print(No);
}