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