#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e18;
const long long MOD = 1e9 + 7;
const double eps = 1e-8;
long long t, m, n, k, a[200005];
set<int> st;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long cnt = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i + 1]) {
      st.insert(cnt);
      cnt = 1;
    } else
      cnt++;
  }
  st.insert(cnt);
  if (st.size() > 1)
    cout << "NO"
         << "\n";
  else
    cout << "YES"
         << "\n";
}
