#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int i = 1, size = -1, tek = 1;
  bool flag = false;
  while (i < n) {
    if (arr[i] == arr[i - 1]) {
      tek += 1;
      if (tek <= size or size == -1) {
        i += 1;
        continue;
      }
      flag = true;
      cout << "NO\n";
      break;
    } else {
      if (size == -1) {
        size = tek;
        tek = 1;
        i += 1;
        continue;
      }
      if (tek != size) {
        flag = true;
        cout << "NO\n";
        break;
      }
      tek = 1;
      i += 1;
    }
  }
  if (!flag && size != -1 && tek != size) {
    cout << "NO\n";
    flag = true;
  }
  if (!flag) cout << "YES\n";
  return 0;
}
