#include <bits/stdc++.h>
int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};
int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int MOD = 998244353, N = 3e5 + 5;
const double pi = acos(-1);
using namespace std;
int arr[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  bool ok = true;
  for (int i = 0; i < n; i++) cin >> arr[i];
  int check = 0, cnt = 1;
  for (int i = 1; i < n; i++) {
    if (arr[i] == arr[i - 1])
      cnt++;
    else {
      if (!check)
        check = cnt;
      else if (check and cnt != check)
        ok = false;
      cnt = 1;
    }
  }
  if (!check)
    return cout << "YES", 0;
  else if (check and cnt != check)
    ok = false;
  ok ? cout << "YES" : cout << "NO";
  return 0;
}
