#include <bits/stdc++.h>
using namespace std;
int length;
vector<int> zebra;
int stripeLen = -1;
int curLen = 0;
bool isZebra = true;
int curNum;
int num;
int main() {
  cin >> length;
  zebra = vector<int>(length, 0);
  for (int i = 0; i < length; ++i) cin >> zebra[i];
  curNum = zebra[0];
  for (int i = 0; i <= length and isZebra; ++i) {
    if (i == length or curNum != (num = zebra[i])) {
      if (stripeLen == -1)
        stripeLen = curLen;
      else if (stripeLen != curLen)
        isZebra = false;
      curLen = 0;
    }
    if (i != length) {
      curNum = num;
      curLen++;
    }
  }
  cout << (isZebra ? "YES" : "NO") << endl;
}
