#include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for (int i = 0; i < n; i++) std::cin >> v[i];
  int length = 1;
  std::set<int> set;
  for (int i = 1; i < n; i++) {
    if (v[i] == v[i - 1])
      length++;
    else {
      set.insert(length);
      length = 1;
    }
  }
  set.insert(length);
  if (set.size() == 1)
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;
  return 0;
}
