#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char dir[] = {'R', 'L', 'D', 'U'};
const int MOD = 1e9 + 7;
const long long INF = 1e9;
void setIO(string filename) {
  if (fopen((filename + ".in").c_str(), "r")) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
  }
}
template <class T>
void printvec(vector<T> a) {
  for (T i : a) cout << i << " ";
  cout << "\n";
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i - 1])
      cnt++;
    else
      break;
  }
  int tempcnt = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i - 1])
      tempcnt++;
    else {
      if (tempcnt != cnt) {
        cout << "NO\n";
        return;
      }
      tempcnt = 1;
    }
  }
  if (tempcnt != cnt)
    cout << "NO\n";
  else
    cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) solve();
}
