#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, arr[100001];
  int i, cnt = 1;
  vector<int> v;
  cin >> n;
  for (i = 0; i < n; i++) cin >> arr[i];
  for (i = 1; i < n; i++) {
    if (arr[i] != arr[i - 1]) {
      v.push_back(cnt);
      cnt = 1;
    } else
      cnt++;
  }
  v.push_back(cnt);
  for (i = 0; i < v.size(); i++)
    if (v[i] != v[0]) {
      cout << "NO" << endl;
      return 0;
    }
  cout << "YES" << endl;
  return 0;
}
