#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int zero = 0, one = 0;
  int flag = -1;
  vector<int> ve;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    if (flag == -1) {
      if (k == 0) {
        flag = 0;
      } else {
        flag = 1;
      }
    }
    if (k == 0) {
      if (flag == 1) {
        ve.push_back(one);
        flag = 0;
        one = 0;
      }
      zero++;
    } else if (k == 1) {
      one++;
      if (flag == 0) {
        ve.push_back(zero);
        flag = 1;
        zero = 0;
      }
    }
  }
  if (flag == 0) ve.push_back(zero);
  if (flag == 1) ve.push_back(one);
  if (ve.size() == 1)
    cout << "YES" << endl;
  else {
    for (int i = 1; i < ve.size(); i++) {
      if (ve[i] != ve[i - 1]) return cout << "NO" << endl, 0;
    }
    cout << "YES" << endl;
  }
}
