#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int i;
  int first_num;
  int j = 0;
  scanf("%d", &first_num);
  int per = 0;
  for (i = 1; i < n; i++) {
    int k;
    scanf("%d", &k);
    if (k != first_num) {
      if (!per) {
        per = i;
      }
      first_num = k;
      if (i - j == per)
        j = i;
      else {
        printf("NO\n");
        return 0;
      }
    }
  }
  if (n - j == per || !per)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
