#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
long long n;
long long ar[N];
long long len = 1;
int32_t main() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> ar[i];
  for (long long i = 1; i < n; i++)
    if (ar[i] != ar[i - 1])
      break;
    else
      len++;
  if (n % len != 0) {
    cout << "NO" << endl;
    return 0;
  }
  long long l = len;
  while (l < n) {
    if (ar[l] == ar[l - 1]) {
      cout << "NO" << endl;
      return 0;
    }
    for (long long i = l + 1; i < l + len; i++)
      if (ar[i] != ar[i - 1]) {
        cout << "NO" << endl;
        return 0;
      }
    l += len;
  }
  cout << "YES" << endl;
}
