#include <bits/stdc++.h>
using namespace std;
int main() {
  set<int> s;
  int n, a[100001], cnt = 1;
  scanf("%d%d", &n, &a[1]);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == a[i - 1])
      cnt++;
    else
      s.insert(cnt), cnt = 1;
  }
  s.insert(cnt);
  if (s.size() > 1)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
