func_code_string: #include <bits/stdc++.h>   using namespace std;   int L;   int a[100005], n;   int Min[100005 << 2], sub[100005 << 2];   vector<pair<int, int> > ans;   void PushUp(int rt) { Min[rt] = min(Min[rt << 1], Min[rt << 1 | 1]); }   void PushDown(int rt) {     if (sub[rt]) {       sub[rt << 1] += sub[rt];       sub[rt << 1 | 1] += sub[rt];       Min[rt << 1] -= sub[rt];       Min[rt << 1 | 1] -= sub[rt];       sub[rt] = 0;     }   }   void Build(int l, int r, int rt) {     int m;     if (l == r) {       Min[rt] = a[l];       return;     }     m = (l + r) >> 1;     Build(l, m, rt << 1);     Build(m + 1, r, rt << 1 | 1);     PushUp(rt);   }   void Update(int L, int R, int x, int l, int r, int rt) {     int m;     if (L <= l && R >= r) {       sub[rt] += x;       Min[rt] -= x;       return;     }     m = (l + r) >> 1;     PushDown(rt);     if (L <= m) Update(L, R, x, l, m, rt << 1);     if (R > m) Update(L, R, x, m + 1, r, rt << 1 | 1);     PushUp(rt);   }   int Query(int L, int R, int l, int r, int rt) {     int ans = 1 << 30, m;     if (L <= l && R >= r) return Min[rt];     m = (l + r) >> 1;     PushDown(rt);     if (L <= m) ans = min(ans, Query(L, R, l, m, rt << 1));     if (R > m) ans = min(ans, Query(L, R, m + 1, r, rt << 1 | 1));     PushUp(rt);     return ans;   }   pair<int, int> bin() {     while (L <= n && Query(L, L, 1, n, 1) == 0) L++;     if (L == n + 1) return pair<int, int>(n + 1, 0);     int R, l = L, r = n, m;     while (l <= r) {       m = (l + r) >> 1;       if (Query(L, m, 1, n, 1) == 0)         r = m - 1;       else         l = m + 1;     }     R = r;     return pair<int, int>(L, R);   }   int main() {     int i, minv, l, r;     while (scanf( %d , &n) != EOF && n) {       L = 1;       (ans).clear();       for (i = 1; i <= n; i++) scanf( %d , &a[i]);       Build(1, n, 1);       while (1) {         pair<int, int> now = bin();         l = now.first, r = now.second;         if (l == n + 1) break;         ans.push_back(pair<int, int>(l, r));         Update(l, r, 1, 1, n, 1);       }       printf( %d n , ((int)(ans).size()));       for (i = 0; i < ((int)(ans).size()); i++)         printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }   