#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x = 1, y = 1;
  int k = 0;
  cin >> k;
  bool fl = false;
  for (int i = 1; i <= n; i++) {
    int t;
    if (i != n)
      cin >> t;
    else
      t = 1 - k;
    if (t == k && fl == false) {
      x++;
    } else if (t != k) {
      if (y != x && fl == true) {
        cout << "NO";
        return 0;
      }
      fl = true;
      y = 1;
      k = t;
    } else if (t == k) {
      y++;
    }
  }
  cout << "YES";
}
