#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, a[N];
vector<int> v;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  int i = 1;
  while (i < n) {
    int cnt = 1;
    while (a[i] == a[i - 1] && i < n) {
      cnt++;
      i++;
    }
    v.push_back(cnt);
    ++i;
  }
  if (n > 1 && a[n - 1] != a[n - 2]) v.push_back(1);
  if (v.size() == 1) {
    printf("YES\n");
    return 0;
  }
  cout << "\n";
  for (int j = 1; j < (int)v.size(); ++j) {
    if (v[j] != v[j - 1]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
}
