#include <bits/stdc++.h>
struct pair {
  int first, second;
};
struct pair a[100005];
int point = 0;
void push(int x, int y) {
  a[point].first = x;
  a[point].second = y;
  point++;
}
int main() {
  long n;
  scanf("%ld", &n);
  int ar[n];
  for (int i = 0; i < n; ++i) scanf("%d", &ar[i]);
  for (int i = 0; i < n; ++i) {
    if (!point || a[point - 1].first != ar[i]) {
      push(ar[i], 1);
    } else {
      a[point - 1].second++;
    }
  }
  for (int i = point - 1; i >= 1; --i) {
    if (a[i].second != a[i - 1].second) {
      return puts("NO");
    }
  }
  puts("YES");
}
