#include <bits/stdc++.h>
int main() {
  int t;
  int arr[100000];
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    scanf("%d", &arr[i]);
  }
  int bil = 0;
  int blak = 0;
  int tmp = 1;
  if (arr[0] == 1) {
    int i = 0;
    while (i < t && arr[i] == 1) {
      blak++;
      i++;
    }
    while (i < t && arr[i] == 0) {
      bil++;
      i++;
    }
    if (blak != bil && blak != 0 && bil != 0) {
      printf("NO");
      return 0;
    }
    for (int i = 1; i < t; i++) {
      if (arr[i - 1] == arr[i]) {
        tmp++;
      } else {
        if (arr[i - 1] == 0) {
          if (bil != tmp) {
            printf("NO");
            return 0;
          }
        } else {
          if (blak != tmp) {
            printf("NO");
            return 0;
          }
        }
        tmp = 1;
      }
    }
  }
  if (arr[0] == 0) {
    int i = 0;
    while (i < t && arr[i] == 0) {
      bil++;
      i++;
    }
    while (i < t && arr[i] == 1) {
      blak++;
      i++;
    }
    if (blak != bil && blak != 0 && bil != 0) {
      printf("NO");
      return 0;
    }
    for (int i = 1; i < t; i++) {
      if (arr[i - 1] == arr[i]) {
        tmp++;
      } else {
        if (arr[i - 1] == 0) {
          if (bil != tmp) {
            printf("NO");
            return 0;
          }
        } else {
          if (blak != tmp) {
            printf("NO");
            return 0;
          }
        }
        tmp = 1;
      }
    }
  }
  if (arr[t - 1] == 0) {
    if (bil != tmp) {
      printf("NO");
      return 0;
    }
  } else {
    if (blak != tmp) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}
