#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
  int n, x;
  bool valid = true;
  int cons = 1;
  bool counting = true;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (i > 0 && counting && arr[i] == arr[i - 1]) {
      cons++;
    }
    if (i > 0 && arr[i] != arr[i - 1]) {
      counting = false;
    }
  }
  int cons_counting = 1;
  for (int i = 1; i < n; i++) {
    if (arr[i] != arr[i - 1]) {
      if (cons_counting < cons) {
        valid = false;
        break;
      }
      cons_counting = 0;
    }
    cons_counting++;
    if (cons_counting > cons) {
      valid = false;
      break;
    }
  }
  if (cons_counting == cons && valid == true) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
