#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 1, fg = 1, x, prv, pvl, t = 0, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (i > 1) {
      if (x != prv) {
        t++;
        if (t >= 2 && c != pvl) {
          fg = 0;
          break;
        }
        pvl = c;
        c = 1;
      } else
        c++;
    }
    prv = x;
  }
  if (t >= 1 && c != pvl) fg = 0;
  if (fg == 0) printf("NO\n");
  if (fg == 1) printf("YES\n");
  return 0;
}
