#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX, N = 1e5 + 7;
long long a[N], sum[N];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  int q = 2, s = 1;
  while (a[q] == a[q - 1]) {
    q++, s++;
  }
  int i = q;
  while (i <= n) {
    int w = 1;
    i++;
    while (a[i] == a[i - 1] && i <= n) {
      w++, i++;
    }
    if (w != s) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
