#include <bits/stdc++.h>
using namespace std;
int vet[100005];
int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  int seq, ant = 0, flag = 1;
  int res = -1;
  scanf("%d", &vet[0]);
  ant = vet[0];
  seq = 1;
  for (int i = 1; i < n; i++) {
    scanf("%d", &vet[i]);
    if (vet[i] == ant)
      seq++;
    else {
      if (res == -1)
        res = seq;
      else {
        if (res != seq) flag = 0;
      }
      seq = 1;
    }
    ant = vet[i];
  }
  if (res != -1 and res != seq) flag = 0;
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
