#include <bits/stdc++.h>
using namespace std;
int n, k = -1;
bool a[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    if (i != 1 && a[i] != a[i - 1]) {
      k = i - 1;
      break;
    }
  }
  if (k == -1) return cout << "YES", 0;
  if (n % k != 0) return cout << "NO", 0;
  bool c = a[1];
  for (int i = 1; i <= n; ++i) {
    if (c != a[i]) return cout << "NO", 0;
    if (i % k == 0) c ^= 1;
  }
  cout << "YES";
  return 0;
}
