#include <bits/stdc++.h>
int main() {
  int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0,
      k = 0, l = 0, m = 0, n = 0, p = 0, q = 0, r = 0, s = 0;
  int ara[100000];
  scanf("%d", &a);
  for (q = 0; q < a; q++) {
    scanf("%d", &ara[q]);
  }
  if (ara[0] == 0) {
    for (l = 0; l < a; l++) {
      if (ara[l] == 0) {
        m++;
      } else {
        break;
      }
    }
  }
  if (ara[0] == 1) {
    for (l = 0; l < a; l++) {
      if (ara[l] == 1) {
        n++;
      } else {
        break;
      }
    }
  }
  if (ara[0] == 0 && m != a && n != a) {
    for (;;) {
      for (;;) {
        if (ara[b] == 0 && b < a) {
          c++;
          b++;
        } else {
          break;
        }
      }
      if (c != m) {
        s++;
        break;
      } else {
        c = 0;
      }
      if (b == a) {
        break;
      }
      for (;;) {
        if (ara[b] == 1 && b < a) {
          c++;
          b++;
        } else {
          break;
        }
      }
      if (c != m) {
        s++;
        break;
      } else {
        c = 0;
      }
      if (b == a) {
        break;
      }
    }
  } else if (ara[0] == 1 && m != a && n != a) {
    for (;;) {
      for (;;) {
        if (ara[b] == 1 && b < a) {
          c++;
          b++;
        } else {
          break;
        }
      }
      if (c != n) {
        s++;
        break;
      } else {
        c = 0;
      }
      if (b == a) {
        break;
      }
      for (;;) {
        if (ara[b] == 0 && b < a) {
          c++;
          b++;
        } else {
          break;
        }
      }
      if (c != n) {
        s++;
        break;
      } else {
        c = 0;
      }
      if (b == a) {
        break;
      }
    }
  }
  if (s > 0) {
    printf("NO");
  } else {
    printf("YES");
  }
  return 0;
}
