#include <bits/stdc++.h>
using namespace std;
int n, x, y, s, s1 = 0;
int main() {
  cin >> n;
  cin >> x;
  n--;
  s = 1;
  while (n--) {
    cin >> y;
    if (x == y)
      s++;
    else {
      if (s1 == 0)
        s1 = s;
      else if (s1 != s) {
        cout << "NO";
        return 0;
      }
      s = 1;
      x = y;
    }
  }
  if (s1 && s1 != s)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
