#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int x = a[0], j = 0;
  vector<int> pol(n, 0);
  pol[0] = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] == x)
      pol[j]++;
    else {
      j++;
      pol[j]++;
      x = a[i];
    }
  }
  bool same = 1;
  for (int i = 1; i <= j; i++)
    if (pol[i] != pol[i - 1]) same = false;
  if (same)
    cout << "YES";
  else
    cout << "NO";
}
