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