#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  bool flag1 = true, flag2 = true;
  if (a[0] == 0) {
    ll key = a[1];
    for (int i = 2; i < N + 3; i++) {
      if (i % 2 == 0) {
        if (a[i % N] != 0) flag1 = false;
      } else {
        if (a[i % N] != key) flag1 = false;
      }
    }
  } else {
    ll key = a[0];
    for (int i = 1; i < N + 3; i++) {
      if (i % 2 == 0) {
        if (a[i % N] != key) flag1 = false;
      } else {
        if (a[i % N] != 0) flag1 = false;
      }
    }
  }
  vector<ll> k(3);
  k[0] = a[0], k[1] = a[1], k[2] = a[2];
  for (int i = 3; i < N + 3; i++) {
    ll ama = i % 3;
    if (a[i % N] != k[ama]) flag2 = false;
  }
  if (flag1 or flag2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
