#include <bits/stdc++.h>
int main() {
  int n = 0;
  scanf("%d", &n);
  int v[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &(v[i]));
  }
  int fir = v[0];
  int perlen = 0;
  int j = 0;
  while (j < n && v[j] == fir) {
    perlen++;
    j++;
  }
  if (n % perlen != 0) {
    printf("NO\n");
    return 0;
  }
  int k = n / perlen;
  j = 0;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < perlen; j++) {
      if (v[i * perlen + j] != fir) {
        printf("NO\n");
        return 0;
      }
    }
    fir ^= 1;
  }
  printf("YES\n");
}
