#include <bits/stdc++.h>
using namespace std;
long long t, x, ans, cursor;
string s;
bool ok;
void help() {
  if (s[cursor] != '1') {
    string snw;
    for (int i = cursor + 1; i < s.length(); ++i) snw.push_back(s[i]);
    s.append(snw);
    if (s[cursor] == '3') s.append(snw);
    if (s.length() > x) ok = false;
  }
  ans = s.length();
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, cnt = 1;
  cin >> n;
  vector<int> v(n + 1), tmp;
  for (int i = 1; i <= n; ++i) cin >> v[i];
  for (int i = 2; i <= n; ++i) {
    if (v[i] != v[i - 1]) {
      tmp.push_back(cnt);
      cnt = 0;
    }
    ++cnt;
  }
  tmp.push_back(cnt);
  int c = tmp[0];
  bool ok = true;
  for (auto it : tmp)
    if (it != c) {
      ok = false;
      break;
    }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
}
