#include <bits/stdc++.h>
const double Pi = 3.14159265;
const int N = 1e6 + 50;
const int M = 1e5 + 15;
const unsigned long long base = 163;
const int INF = 0x3f3f3f3f;
using namespace std;
int a[N];
int main() {
  int n;
  scanf("%d", &n);
  int l = 0, r = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int pre = 1;
  int now = -1;
  int flag = 0;
  for (int i = 1; i <= n - 1; i++) {
    if (a[i] == a[i + 1]) {
      pre++;
    } else {
      flag = 1;
      if (now == -1)
        now = pre;
      else {
        if (pre != now) {
          cout << "NO" << endl;
          return 0;
        }
      }
      pre = 1;
    }
  }
  if (pre != now && flag) return cout << "NO\n", 0;
  cout << "YES" << endl;
  return 0;
}
