#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const long long MAX = 9000000000000000000;
const long long MIN = -9000000000000000000;
const long double DMAX = 4500;
const long double DMIN = -4500;
const long long MOD = 1000000007;
template <typename T>
void fin(T a) {
  cout << a << endl;
  exit(0);
}
long long GetDigit(long long num) { return log10(num) + 1; }
vector<long long> enum_div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}
long long modpow(long long x, long long n, long long mod = MAX) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
long long factorial(long long n) {
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}
long long modinv(long long a, long long mod) {
  long long b = mod, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0) u += mod;
  return u;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
void Main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (n); ++i) cin >> a[i];
  if (a[0] != a[1] & a[-1 + n]) fin("No");
  if (a[n - 1] != a[0] & a[n - 2]) fin("No");
  for (long long i = 1; i < n - 1; i++) {
    if (a[i] != a[i - 1] & a[i + 1]) fin("No");
  }
  fin("Yes");
}
int main() {
  cout << fixed << setprecision(20);
  Main();
  return 0;
}
