#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e6 + 10;
int a[MAX];
int b[MAX];
int main() {
  int len = 0;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int sum = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1])
      sum++;
    else {
      b[++len] = sum;
      sum = 1;
    }
  }
  b[++len] = sum;
  for (int i = 2; i <= len; i++) {
    if (b[i] != b[i - 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
