#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << "YES";
    return 0;
  }
  vector<long long> v;
  long long cnt0 = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) {
      v.push_back(cnt0);
      cnt0 = 1;
    } else
      cnt0++;
    if (i == n - 1) {
      v.push_back(cnt0);
    }
  }
  long long cnt = 1;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] == v[i + 1]) cnt++;
  }
  if (cnt == v.size())
    cout << "YES";
  else
    cout << "NO";
}
