#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, a[maxn], b[maxn], num[maxn], top;
void over() {
  cout << "NO";
  exit(0);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int last = a[1], temp = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1])
      temp++;
    else {
      b[++top] = last, num[top] = temp;
      temp = 1, last = a[i];
    }
  }
  b[++top] = last, num[top] = temp;
  for (int i = 2; i <= top; i++)
    if (num[i] != num[i - 1]) over();
  cout << "YES";
}
