#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-5;
int array[10000];
int main(void) {
  int n;
  int i = 0;
  int interval = 0;
  int index;
  char c;
  string s = "";
  ifstream ifs;
  ofstream ofs;
  ifs.open("input.txt");
  ofs.open("output.txt");
  ifs >> s;
  n = atoi(s.c_str());
  ifs >> s;
  cout << n << endl;
  cout << s << endl;
  while (s[i] != '1') {
    i++;
  }
  while (s[i + 1 + interval] != '1') {
    interval++;
  }
  index = i + interval + 2;
  while (index < n) {
    int j;
    int new_int = 0;
    for (j = 0; j < interval && index < n; j++) {
      if (s[index] != '0') {
        ofs << "NO" << endl;
        return 0;
      }
      index++;
    }
    if (index < n) {
      if (s[index] != '1') {
        while (index < n) {
          if (s[index] == '0') {
            index++;
          } else {
            ofs << "NO" << endl;
            return 0;
          }
        }
        break;
      }
      index++;
    }
  }
  ofs << "YES" << endl;
  return 0;
}
