#include <bits/stdc++.h>
int n, i, j;
int a[120000];
void work() {
  int len = 1;
  for (i = 2; i <= n; i++) {
    if (a[i] == a[1])
      len++;
    else
      break;
  }
  int last = a[1] ^ 1;
  for (i = 1; i <= n; i += len) {
    last ^= 1;
    if (a[i] != last) {
      puts("NO");
      return;
    }
    for (j = 0; j < len; j++) {
      if (a[i + j] != a[i]) {
        puts("NO");
        return;
      }
    }
  }
  puts("YES");
}
int main() {
  scanf("%d", &n);
  memset(a, -1, sizeof(a));
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  work();
  return 0;
}
