#include <bits/stdc++.h>
using namespace std;
int n, i, l, j, b[1000009], k[1000009];
int main() {
  j = -1;
  cin >> n;
  k[0] = -1;
  for (i = 1; i <= n; i++) {
    cin >> k[i];
    if (k[i - 1] == k[i]) {
      b[j]++;
    } else {
      j++;
      b[j] = 1;
      l = j;
    }
  }
  for (j = 0; j < l; j++) {
    if (b[j] != b[j + 1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
