#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (v.empty() || v.back().first != x) {
      v.push_back({x, 1});
    } else {
      v.back().second++;
    }
  }
  for (int i = 1; i < v.size(); i++) {
    if (v[i].second != v[i - 1].second) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
