#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n + 19];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  set<long long> s;
  long long p = 1, c = 0;
  long long k = 0, t = 0, i;
  int f = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == a[0]) {
      if (t > 0) s.insert(t);
      t = 0;
      k++;
    } else {
      if (k > 0) s.insert(k);
      k = 0;
      t++;
    }
  }
  long long q = max(k, t);
  if (q > 0) s.insert(q);
  if (s.size() == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
