#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, p;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long c = 1;
  set<long long> s;
  for (long long i = 1; i < n; i++) {
    if (a[i] == a[i - 1])
      c++;
    else {
      s.insert(c);
      c = 1;
    }
  }
  s.insert(c);
  if ((long long)(s).size() == 1) {
    cout << (1 ? "YES" : "NO") << '\n';
    ;
  } else
    cout << (0 ? "YES" : "NO") << '\n';
  ;
  return 0;
}
