#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, m = 1, m1 = -1, b = 0, i, x;
  cin >> n >> x;
  for (i = 1; i < n; i++) {
    cin >> a;
    m++;
    if (a != x) {
      x = a;
      if (m1 == -1) {
        m1 = m - 1;
        if ((i == n - 1) && (n != 2)) {
          cout << "No";
          return 0;
        }
        m = 0;
        continue;
      }
      if (m1 != m) {
        cout << "NO";
        return 0;
      } else
        m = 0;
    }
    if (i + 1 == n) {
      if (a == x) m++;
      if ((m != m1) && (m1 != -1)) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
