#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 777;
int a[mx], pre[mx];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) cin >> a[i + 1];
  pre[0] = 0;
  for (int i = 0; i < n; i++) pre[i + 1] = pre[i] + a[i + 1];
  vector<int> div;
  for (int d = 1; d * d <= n; d++) {
    if (n % d == 0) {
      div.push_back(d);
      int e = n / d;
      if (d != e) div.push_back(e);
    }
  }
  sort(div.begin(), div.end());
  for (auto d : div) {
    for (int j = 0; j < 2; j++) {
      int col = j;
      bool ok = true;
      for (int i = d; i <= n; i += d) {
        if (pre[i] - pre[i - d] != col * d) {
          ok = false;
          break;
        }
        col = 1 - col;
      }
      if (ok) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
