#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long double PI = 4 * atan(1);
int n, a[100001], cnt, cur, x, j;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  x = a[0];
  while (j < n && a[j] == x) cnt++, j++;
  for (int i = j; i < n; i++) {
    x = a[i], cur = 0;
    while (i < n && a[i] == x) cur++, i++;
    if (cur != cnt) {
      cout << "NO";
      return 0;
    }
    i--;
  }
  cout << "YES";
  return 0;
}
