#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int cnt = 1;
  set<int> S;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int prev = arr[0];
  for (int i = 1; i < n; i++) {
    if (arr[i] != prev) {
      S.insert(cnt);
      cnt = 1;
      prev = arr[i];
      continue;
    }
    prev = arr[i];
    cnt++;
  }
  if (cnt != 0) S.insert(cnt);
  cout << ((S.size() == 1) ? "YES" : "NO") << endl;
}
