#include <bits/stdc++.h>
int a[100001], used[100001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int first = a[1], j = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == first)
      used[j]++;
    else
      first = a[i], j++, used[j]++;
  }
  for (int k = 1; k <= j - 1; k++) {
    if (used[k] != used[k + 1] && used[k + 1] != 0) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
}
