func_code_string: #include <bits/stdc++.h>   using namespace std;   const int inf = 1e5 + 9, lg = 30;   int a[inf * 3], n, table[lg][inf << 2];   int ans[inf], nxt[inf], sml[inf << 2];   void build() {     int i, j;     for (i = 1; i <= n + n; i++) table[0][i] = a[i];     for (j = 1; j < lg - 1; j++)       for (i = 1; i + (1 << (j - 1)) - 1 <= n + n; i++)         table[j][i] = min(table[j - 1][i], table[j - 1][i + (1 << (j - 1))]);   }   int query(int x, int y) {     int len, k;     len = y - x + 1;     k = log2(len);     return min(table[k][x], table[k][y + 1 - (1 << k)]);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++)       cin >> a[i], a[i + n] = a[i], a[i + n + n] = a[i];     int mx = 0;     for (int i = n;; i++) {       if (mx > a[i]) break;       if (i == n + n + n) {         ans[n] = -1;         break;       }       ans[n]++;       mx = max(mx, (a[i] % 2 == 0 ? a[i] / 2 : a[i] / 2 + 1));     }     ans[n + n] = ans[n];     stack<int> st;     for (int i = n + n; i >= 1; i--) {       while (!st.empty() && a[st.top()] <= a[i]) st.pop();       if (st.empty())         nxt[i] = -1;       else         nxt[i] = st.top();       st.push(i);     }     build();     for (int i = 1; i <= n; i++) {       sml[i] = 1e9;       int val = (a[i] % 2 == 0 ? a[i] / 2 : a[i] / 2 + 1);       int l = i, r = min(n + n + 1, n + i + 1);       while (r - l > 1) {         int mid = (l + r) / 2;         if (query(i, mid) < val)           r = mid;         else           l = mid;       }       if (a[r] < val) sml[i] = r;     }     vector<pair<int, int> > v;     for (int i = 1; i <= n; i++) {       v.push_back(make_pair(a[i], i));     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (auto o : v) {       int i = o.second;       if (sml[i] == 1e9) {         if (nxt[i] == -1)           ans[i] = -1;         else           ans[i] = (ans[nxt[i]] != -1 ? ans[nxt[i]] + nxt[i] - i : -1);       } else {         if (nxt[i] == -1)           ans[i] = sml[i] - i;         else {           if (sml[i] < nxt[i])             ans[i] = sml[i] - i;           else             ans[i] = (ans[nxt[i]] != -1 ? ans[nxt[i]] + nxt[i] - i : -1);         }       }       ans[i + n] = ans[i];     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }   