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