#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e18 + 7;
long long int n, a[100100];
set<long long int> st;
int main() {
  long long int x, y;
  x = y = 0;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1)
      x = 1;
    else
      y = 1;
  }
  if (!x || !y) {
    cout << "YES" << endl;
    return 0;
  }
  for (long long int i = 1; i <= n; i++) {
    long long int x = 1;
    while (a[i] == a[i + 1] && i < n) {
      i++;
      x++;
    }
    st.insert(x);
  }
  if (st.size() > 1) {
    cout << "NO" << endl;
  } else
    cout << "Yes" << endl;
}
