#include <bits/stdc++.h>   using namespace std;   void solve() {}   void no() {     cout <<  NO  <<   n ;     exit(0);   }   const long long maxn = 100050;   long long a[maxn];   long long psa[maxn];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     long long len = n;     for (long long i = 1; i <= n; i++) {       if (a[i] != a[1]) {         len = i - 1;         break;       }     }     for (long long i = 1; i <= n; i++) {       psa[i] = psa[i - 1] + a[i];     }     if (n % len) no();     for (long long i = len; i <= n; i += len) {       long long sum = psa[i] - psa[i - len];       if (sum and sum != len) {         no();       }       if (i >= len * 2) {         if (sum == psa[i - len] - psa[i - 2 * len]) {           no();         }       }     }     cout <<  YES  <<   n ;   }   