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