#include <bits/stdc++.h>
using namespace std;
long long fact(long long N) {
  if (N < 0) return 0;
  if (N == 0)
    return 1;
  else
    return N * fact(N - 1);
}
int main() {
  long long z, zr[3] = {}, g, i, j, n, k[3] = {}, m[3] = {}, mi[3], a[100001],
               b[100001] = {}, r1;
  cin >> n;
  mi[0] = 9999999999;
  mi[1] = 9999999999;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    zr[a[i]]++;
  }
  g = 0;
  i = 1;
  z = 0;
  k[a[0]] = 1;
  m[a[0]] = 1;
  while (i < n) {
    if (a[i] == a[i - 1])
      k[a[i]]++;
    else {
      b[z] = k[a[i - 1]];
      k[a[i - 1]] = 0;
      k[a[i]] = 1;
      z++;
    }
    i++;
  }
  b[z] = k[a[i - 1]];
  k[a[i - 1]] = 0;
  k[a[i]] = 1;
  z++;
  for (i = 1; i < z; i++)
    if (b[i] != b[i - 1]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
}
