#include <bits/stdc++.h>
using namespace std;
int n, l;
bool a[101010];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int i = 1;
  while (i < n && a[i] == a[i - 1]) i++;
  l = i;
  while (i < n) {
    int j = i++;
    while (i < n && a[i] == a[i - 1]) i++;
    if (i - j != l) {
      cout << "NO";
      exit(0);
    }
  }
  cout << "YES";
}
