#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m1, m2;
map<long long int, long long int>::iterator itr, itr1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> v;
  long long int x;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  long long int ct = 1;
  vector<long long int> ans;
  if (n > 1) {
    for (long long int i = 1; i < n; i++) {
      if (v[i] == v[i - 1])
        ct++;
      else {
        ans.push_back(ct);
        ct = 1;
      }
    }
  }
  ans.push_back(ct);
  if (ans.size() > 1) {
    for (long long int i = 1; i < ans.size(); i++) {
      if (ans[i] != ans[i - 1]) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
