#include <bits/stdc++.h>
using namespace std;
int n;
int a[100100];
int main() {
  cin >> n;
  int x, la, now = 1;
  cin >> x;
  a[now] = 1;
  la = x;
  for (int i = 2; i <= n; i++) {
    cin >> x;
    if (x == la)
      a[now]++;
    else
      a[++now] = 1;
    la = x;
  }
  int w = a[1];
  int ok = 1;
  for (int i = 2; i <= now; i++) {
    if (a[i] != w) ok = 0;
  }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
}
