#include <bits/stdc++.h>
int main() {
  int a[100000];
  int i, j, num, n, x;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  if (i == 1) {
    printf("YES\n");
    return 0;
  }
  i = 1;
  while (i < n) {
    if (a[i] == a[i - 1])
      ;
    else
      break;
    i++;
  }
  x = i;
  if (n % x != 0) {
    printf("NO\n");
    return 0;
  }
  int b[100000], flag = 0, k;
  for (j = 0; j < n;) {
    if (flag == 0) {
      for (k = 0; k < x; k++) b[j++] = a[0];
    } else {
      for (k = 0; k < x; k++) b[j++] = !a[0];
    }
    flag = !flag;
  }
  for (i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
}
