#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int have = -1, cnt = 1;
  for (int i = 1; i < n; ++i) {
    if (a[i] == a[i - 1]) {
      cnt++;
    } else {
      if (have == -1)
        have = cnt;
      else if (have != cnt) {
        printf("No\n");
        return 0;
      }
      cnt = 1;
    }
  }
  if (have == -1)
    have = cnt;
  else if (have != cnt) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
}
