#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (v.empty() || x != v.back().first)
      v.push_back({x, 1});
    else
      v.back().second++;
  }
  bool ok = 1;
  for (int i = 1; i < v.size(); i++) ok &= v[i].second == v[i - 1].second;
  printf(ok ? "YES" : "NO");
}
