#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)(2e5) + 2;
const int MOD = (int)(1e9) + 7;
int n, a[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> v;
  a[0] = a[n + 1] = 2;
  for (int i = 1; i <= n + 1; i++)
    if (a[i] != a[i - 1]) v.push_back(i);
  set<int> q;
  for (int i = 1; i < v.size(); i++) q.insert(v[i] - v[i - 1]);
  if (q.size() == 1) {
    cout << "Yes";
  } else
    cout << "No";
  return 0;
}
