#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const int N = 1e5 + 5;
const int OO = 1e9;
const long long MOD = 1000000007;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, cnt = 0;
  cin >> n;
  long long a[n + 5];
  set<long long> st;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (i) {
      if (a[i] != a[i - 1]) st.insert(mp[a[i - 1]]), mp.clear();
    }
    mp[a[i]]++;
  }
  st.insert(mp[a[n - 1]]);
  (st.size() == 1) ? cout << "YES" : cout << "NO";
  return 0;
}
