#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int zebra[n];
  for (int i = 0; i < n; ++i) cin >> zebra[i];
  char first = zebra[0];
  int size = 1;
  int index = 1;
  int prevstripe = zebra[0];
  while (index < n && zebra[index] == first) {
    ++size;
    ++index;
  }
  if (n % size != 0) {
    cout << "NO\n";
    return 0;
  } else {
    for (int j = index; j < n; j += size) {
      if (zebra[j] == prevstripe) {
        cout << "NO\n";
        return 0;
      }
      prevstripe = zebra[j];
      for (int k = j; k < j + size; ++k) {
        if (zebra[k] != zebra[j]) {
          cout << "NO\n";
          return 0;
        }
      }
    }
  }
  cout << "YES\n";
}
