#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  int w = -1;
  int cur = 1;
  for (int i = 0; i < n - 1; i++) {
    if (arr[i] == arr[i + 1]) {
      cur++;
    } else {
      if (w == cur || w == -1)
        w = cur;
      else
        return cout << "NO" << '\n', 0;
      cur = 1;
    }
  }
  if (w == cur || w == -1) {
    return cout << "YES" << '\n', 0;
  } else {
    return cout << "NO" << '\n', 0;
  }
}
