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