#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> x;
  int st = a[0], ct = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] != st) {
      x.push_back(ct);
      ct = 1;
      st = a[i];
    } else {
      ct++;
    }
  }
  x.push_back(ct);
  for (int i = 1; i < x.size(); i++) {
    if (x[i] != x[0]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}
