#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 1;
const long long M = 1e9 + 1;
signed main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> b(1);
  b[0] = 1;
  for (long long i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      b[(long long)b.size() - 1]++;
    } else {
      b.push_back(1);
    }
  }
  for (long long i = 1; i < (long long)b.size(); i++) {
    if (b[i] != b[i - 1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
