#include <bits/stdc++.h>
const int MAXN = 1e5 + 100;
int a[100100];
int main() {
  int n;
  scanf("%d", &n);
  int zero = 0, one = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    zero += !a[i], one += a[i];
  }
  if (zero == n || one == n) return !printf("YES");
  int cnt = 1, diff = -1;
  for (int i = 2; i <= n; ++i) {
    if (a[i] == a[i - 1])
      ++cnt;
    else {
      if (diff == -1) {
        diff = cnt;
        cnt = 1;
        continue;
      }
      if (diff != cnt) return !printf("NO");
      cnt = 1;
    }
  }
  printf(diff == cnt ? "YES" : "NO");
}
