#include <bits/stdc++.h>
int a[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int flag = -1;
  int sum = 0;
  int sum1 = 0;
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i - 1])
      ans++;
    else {
      if (flag == -1) {
        flag = 1;
        sum = ans;
        ans = 1;
      } else {
        if (ans != sum) {
          printf("NO\n");
          return 0;
        }
        ans = 1;
      }
    }
  }
  if (flag == -1 || ans == sum)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
