func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   int num[100008];   int cnt1[100008];   int cnt2[100008];   int cnt;   struct node {     int s, t;   } ans[100008];   bool cmp(node a, node b) {     if (a.s == b.s) return a.t < b.t;     return a.s < b.s;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &num[i]);       if (num[i] == 1) {         cnt1[i] = cnt1[i - 1] + 1;         cnt2[i] = cnt2[i - 1];       } else if (num[i] == 2) {         cnt1[i] = cnt1[i - 1];         cnt2[i] = cnt2[i - 1] + 1;       }     }     int acnt = 0;     int bcnt = 0;     int pre;     int atmp;     int btmp;     for (int i = 1; i <= n; i++) {       pre = 1;       acnt = 0;       bcnt = 0;       while (true) {         atmp = lower_bound(cnt1 + pre, cnt1 + 1 + n, i + cnt1[pre - 1]) - cnt1;         btmp = lower_bound(cnt2 + pre, cnt2 + 1 + n, i + cnt2[pre - 1]) - cnt2;         if (atmp < btmp) {           acnt++;           pre = atmp + 1;           if (atmp == n) {             if (num[n] != 2 && acnt > bcnt) {               cnt++;               ans[cnt].s = acnt;               ans[cnt].t = i;             }             break;           }         } else if (atmp > btmp) {           bcnt++;           pre = btmp + 1;           if (btmp == n) {             if (num[n] != 1 && acnt < bcnt) {               cnt++;               ans[cnt].s = bcnt;               ans[cnt].t = i;             }             break;           }         } else {           break;         }       }     }     sort(ans + 1, ans + 1 + cnt, cmp);     printf( %d n , cnt);     for (int i = 1; i <= cnt; i++) {       printf( %d %d n , ans[i].s, ans[i].t);     }     return 0;   }   