#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 13;
bool flagBlack = false, flagWhite = false;
int a[N];
int n;
int lacesB[N];
int lacesW[N];
inline void read() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      flagBlack = true;
    } else {
      flagWhite = true;
    }
  }
}
inline void solve() {
  if (!flagBlack || !flagWhite) {
    cout << "YES" << endl;
    return;
  }
  int mincnt = 100 * 1000 + 13;
  int maxcnt = -100 * 1000 + 13;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      if (a[i] != a[i - 1]) {
        if (cnt > maxcnt) {
          maxcnt = cnt;
        }
        if (cnt < mincnt) {
          mincnt = cnt;
        }
        cnt = 0;
      }
    }
    cnt++;
  }
  if (cnt > maxcnt) {
    maxcnt = cnt;
  }
  if (cnt < mincnt) {
    mincnt = cnt;
  }
  if (mincnt == maxcnt) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
int main() {
  read();
  solve();
  return 0;
}
