#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ch;
  string s;
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  cin >> ch;
  int la = ch;
  int cou = 1;
  int mi = 2e9, ma = -2e9;
  for (int i = 1; i < n; i++) {
    cin >> ch;
    if (ch == la) {
      cou++;
    } else {
      la = ch;
      mi = min(mi, cou);
      ma = max(ma, cou);
      cou = 1;
    }
  }
  mi = min(mi, cou);
  ma = max(ma, cou);
  if (mi != ma)
    cout << "NO";
  else
    cout << "YES";
}
