#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int n, s[N];
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + rd();
  for (int i = 1; i <= n; ++i)
    if (n % i == 0) {
      bool fg, ok = 1;
      if (!s[i])
        fg = 0;
      else if (s[i] == i)
        fg = 1;
      else
        continue;
      for (int l = i + 1, r = i + i; ok && r <= n; l += i, r += i) {
        ok = fg ? !(s[r] - s[l - 1]) : s[r] - s[l - 1] == i;
        fg ^= 1;
      }
      if (ok) {
        puts("YES");
        return 0;
      }
    }
  puts("NO");
  return 0;
}
