#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 123;
int n, cnt1 = 0, cnt2 = 0, a[N];
set<int> s;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  a[n + 1] = 2;
  int i = 1;
  while (i <= n) {
    while (a[i] == 0) {
      ++cnt1;
      ++i;
    }
    if (cnt1 > 0) s.insert(cnt1);
    while (a[i] == 1) {
      ++cnt2;
      ++i;
    }
    if (cnt2 > 0) s.insert(cnt2);
    cnt1 = 0;
    cnt2 = 0;
  }
  if ((int)s.size() == 1)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
