#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long double EPS = 1e-12;
const long double PI = 3.14159265358979323;
int main() {
  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(6);
  };
  bool a[100005];
  int n;
  cin >> n;
  set<int> ans;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == 1) {
      int j = i;
      while (j < n && a[j] == 1) j++;
      ans.insert(j - i);
      i = j;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == 0) {
      int j = i;
      while (j < n && a[j] == 0) j++;
      ans.insert(j - i);
      i = j;
    }
  }
  if (ans.size() == 1)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
