malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   clock_t timeStart, timeFinish;   void timeBegin() { timeStart = clock(); }   void timeEnd() { timeFinish = clock(); }   void timeDuration() {     double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);     cout <<  Time taken by program is :   << fixed << time_taken          << setprecision(5);     cout <<   sec   << endl;   }   int blo[1000005];   bool fun(const pair<pair<int, int>, int> &x,            const pair<pair<int, int>, int> &y) {     if (blo[x.first.first] != blo[y.first.first]) {       return blo[x.first.first] < blo[y.first.first];     }     if (blo[x.first.first] % 2) {       return x.first.second > y.first.second;     } else {       return x.first.second < y.first.second;     }   }   void solve() {     int n;     cin >> n;     int x[n + 3], y[n + 3];     vector<pair<pair<int, int>, int>> v;     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y[i];       v.push_back({{x[i], y[i]}, i});     }     for (int i = 0; i <= 1000000; i++) {       blo[i] = i / 1000;     }     sort(v.begin(), v.end(), fun);     for (int i = 0; i < n; i++) cout << v[i].second <<    ;     cout <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int n) {     if (x == 0) return 0;     if (n == 0) return 1;     if (n == 1) return x;     if (n % 2 == 0) {       long long int temp = power(x, n / 2);       return (temp % 1000000007 * temp % 1000000007) % 1000000007;     } else {       long long int temp = power(x, n / 2);       return (x % 1000000007 *               ((temp % 1000000007 * temp % 1000000007) % 1000000007) %               1000000007) %              1000000007;     }   }   long long int findroot(long long int i, long long int Arr[]) {     while (Arr[i] != i) {       Arr[i] = Arr[Arr[i]];       i = Arr[i];     }     return i;   }   void weightedunion(long long int i, long long int j, long long int arr[],                      long long int size[]) {     long long int x = findroot(i, arr);     long long int y = findroot(j, arr);     if (size[x] > size[y]) {       size[x] += size[y];       arr[y] = arr[x];     } else {       size[y] += size[x];       arr[x] = arr[y];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k, i, j, temp, ans = 0;     cin >> n >> k;     long long int arr[n];     set<long long int> s;     map<long long int, long long int> mp;     for (i = 0; i < n; i++) {       cin >> arr[i];       mp[arr[i]]++;     }     if (k == 1)       cout << mp.size() <<   n ;     else {       sort(arr, arr + n);       for (i = 0; i < n; i++) {         if (s.find(arr[i]) != s.end())           continue;         else {           s.insert(arr[i]);           vector<long long int> inc;           vector<long long int> ninc;           inc.push_back(mp[arr[i]]);           ninc.push_back(0);           for (temp = k * arr[i]; temp <= (long long int)1e9; temp = temp * k) {             s.insert(temp);             if (mp.find(temp) == mp.end()) {               inc.push_back(max(inc.back(), ninc.back()));               ninc.push_back(inc.back());             } else {               long long int x = inc.back(), y = ninc.back();               inc.push_back(mp[arr[i]] + ninc.back());               ninc.push_back(max(x, y));             }           }           ans += max(inc.back(), ninc.back());         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int ara[1000005], n, m, dp[1005][1005];   long long int func(long long int i, long long int j) {     if ((j + ara[i]) % m == 0) {       return 1;     }     if (i >= n - 1) {       if ((j + ara[i]) % m == 0) {         return 1;       } else         return 0;     }     if (dp[i][j] != -1) {       return dp[i][j];     }     long long int p1 = 0, p2 = 0;     p1 = func(i + 1, (j + ara[i]) % m);     p2 = func(i + 1, j);     dp[i][j] = p1 | p2;     return dp[i][j];   }   int main() {     long long int i, k, sum = 0;     scanf( %I64d %I64d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %I64d , &ara[i]);     }     if (n > m) {       printf( YES n );       return 0;     }     memset(dp, -1, sizeof dp);     k = func(0, 0);     if (k == 1) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(0);     std::cout.tie(0);   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     vector<long long> cnt(n + 1);     for (long long(i) = 0; (i) < (n); (i)++) {       cin >> a[i];       cnt[a[i]]++;     }     vector<long long> ans(n + 1);     vector<long long> add;     long long i = 0;     for (; i < n + 1; i++) {       ans[i] = cnt[i];       if (cnt[i] == 0) break;       for (long long j = 0; j < cnt[i] - 1; j++) add.push_back(i);     }     i++;     for (; i < n + 1; i++) {       if (ans[i - 1] == -1) {         ans[i] = -1;         continue;       }       ans[i] = ans[i - 1] + cnt[i] - cnt[i - 1];       if (cnt[i - 1] == 0) {         if (add.empty()) {           ans[i] = -1;           continue;         }         ans[i] += (i - add.back() - 1);         add.pop_back();       }       for (long long j = 0; j < cnt[i] - 1; j++) add.push_back(i);     }     for (auto x : ans) cout << x <<    ;     cout <<   n ;   }   signed main() {     fast();     long long t = 1;     cin >> t;     for (long long(i) = 0; (i) < (t); (i)++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   int a[MAXN];   int main() {     int n, k;     while (scanf( %d%d , &n, &k) != EOF) {       for (int i = 0; i < n; i++) scanf( %d , &a[i]);       int res = 0;       int sum = (1 << 29);       for (int i = 0; i < n; i++) {         int tmp = 0, flag = true;         for (int j = 0; j < n; j++)           if (a[j] != a[i] + (j - i) * k) {             tmp++;             if (a[i] + (j - i) * k <= 0) flag = false;           }         if (flag && tmp < sum) sum = tmp, res = i;       }       printf( %d n , sum);       if (sum) {         for (int i = 0; i < n; i++) {           int tmp = a[res] + (i - res) * k;           if (a[i] < tmp)             printf( + %d %d n , i + 1, tmp - a[i]);           else if (a[i] > tmp)             printf( - %d %d n , i + 1, a[i] - tmp);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1000000000000000003LL;   int n, m;   long long pow2[262144];   char S[262144];   char T[262144];   long long hS[262144][26];   long long hT[262144][26];   long long curh[26];   vector<int> ans;   bool v[26];   inline long long mulmod(long long x, long long y, long long mod) {     return (x * y) - mod * (long long)((long double)x * y / mod);   }   bool check(long long a[26], long long b[26]) {     memset(v, false, sizeof v);     for (int i = 0; i < 26; ++i) {       if (a[i] == 0) continue;       if (v[i]) continue;       if (a[i] == b[i]) {         v[i] = true;         continue;       }       for (int j = 0; j < 26; ++j)         if (a[i] == b[j]) {           if (v[j]) return false;           if (b[i] == a[j]) {             v[j] = true;             v[i] = true;             break;           } else             return false;         }       if (!v[i]) return false;     }     return true;   }   int main() {     pow2[0] = 1;     for (int i = 1; i < 262144; ++i) pow2[i] = pow2[i - 1] * 2ll % M;     scanf( %d%d , &n, &m);     scanf( %s , S + 1);     scanf( %s , T + 1);     for (int i = 1; i <= m; ++i) {       for (int j = 0; j < 26; ++j) hT[i][j] = hT[i - 1][j] * 2ll % M;       (hT[i][T[i] - 97] += 1ll) %= M;     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < 26; ++j) hS[i][j] = hS[i - 1][j] * 2ll % M;       (hS[i][S[i] - 97] += 1ll) %= M;     }     for (int i = m; i <= n; ++i) {       for (int j = 0; j < 26; ++j) {         curh[j] = (hS[i][j] - mulmod(hS[i - m][j], pow2[m], M)) % M;         if (curh[j] < 0) curh[j] += M;       }       if (check(hT[m], curh)) ans.push_back(i - m + 1);     }     int sz = ans.size();     printf( %d n , sz);     for (int i = 0; i < sz; ++i) {       printf( %d , ans[i]);       if (i + 1 < sz)         printf(   );       else         printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   const long double pi = 3.141592;   const long long mod1 = 1e9 + 7;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n;     cin >> n;     vector<int> d(n + 1);     set<int> set;     int x = 1, y = 1;     int m = 1;     for (int i = 1; i <= n; i++) {       cin >> d[i];       m = max(m, d[i]);     }     for (int i = 1; i <= n; i++) {       if (m % d[i] == 0 && set.find(d[i]) == set.end()) {         set.insert(d[i]);         d[i] = -1;       }     }     for (int i = 1; i <= n; i++) {       y = max(y, d[i]);     }     cout << m <<     << y;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = ~(1 << 31);   int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     int m = 0, l = 0;     for (int i = 1; i < n; i++) {       if (v[i] < v[m] && m != 0) {         cout << 3 << endl;         cout <<  1   << m + 1 <<     << i + 1 << endl;         return 0;       }       if (v[i] > v[l] && l != 0) {         cout << 3 << endl;         cout <<  1   << l + 1 <<     << i + 1 << endl;         return 0;       }       if (v[i] > v[m]) {         m = i;       }       if (v[i] < v[l]) {         l = i;       }     }     cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000000 + 7;   const int MAX = 100000;   map<pair<string, int>, int> F;   vector<pair<string, int>> v, ans;   pair<string, int> q;   set<string> s;   int n;   vector<int> g[300000];   vector<int> S[300000];   bool used[300000];   bool cmp(int i1, int i2) { return v[i1].second > v[i2].second; }   bool qw(int i1, int i2) { return i1 > i2; }   int main() {     cin >> n;     for (int i = (0); i < (n); i++) {       cin >> q.first >> q.second;       if (!F.count(q)) F[q] = v.size(), v.push_back(q);       int V = F[q];       int k;       cin >> k;       for (int j = (0); j < (k); j++) {         cin >> q.first >> q.second;         if (!F.count(q)) F[q] = v.size(), v.push_back(q);         g[V].push_back(F[q]);       }     }     S[0].push_back(0);     used[0] = 1;     s.insert(v[0].first);     for (int i = (0); i < (n); i++) {       sort(S[i].begin(), S[i].end(), cmp);       for (int j = (0); j < (S[i].size()); j++) {         if (i && !s.count(v[S[i][j]].first)) {           s.insert(v[S[i][j]].first);           ans.push_back(v[S[i][j]]);         } else if (i)           continue;         for (int k = (0); k < (g[S[i][j]].size()); k++)           if (!used[g[S[i][j]][k]])             S[i + 1].push_back(g[S[i][j]][k]), used[g[S[i][j]][k]] = 1;       }     }     sort(ans.begin(), ans.end());     cout << ans.size() <<   n ;     for (int i = (0); i < (ans.size()); i++)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, m{99999};     cin >> n;     int* A = new int[n];     for (int i{0}; i < n; i++) cin >> A[i];     for (int i{0}; i < n; i++) {       int s{0};       for (int j{0}; j < A[i]; j++) {         cin >> x;         s += x;       }       y = (15 * A[i]) + s * 5;       if (y < m) m = y;     }     cout << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1003, mod = 998244353;   template <typename T>   void read(T &x) {     int ch = getchar();     x = 0;     bool f = false;     for (; ch <  0  || ch >  9 ; ch = getchar()) f |= ch ==  - ;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     if (f) x = -x;   }   int n, fa[N];   bool vis[N];   vector<int> in[N], nxt[N], pos;   char str[N];   map<vector<int>, vector<bool> > buc;   vector<bool> query(const vector<int> &v) {     if (buc.count(v)) return buc[v];     putchar( ? );     for (int u : v) printf(  %d , u);     putchar(  n );     fflush(stdout);     scanf( %s , str);     vector<bool> res(n);     for (int i = 0; i < n; ++i) res[i] = (str[i] !=  0 );     return buc[v] = res;   }   int main() {     read(n);     in[0].emplace_back(0);     vis[0] = vis[n] = true;     for (int i = 1; i < n; ++i) nxt[0].emplace_back(i);     while (true) {       bool flg = true;       pos.resize(0);       for (int i = 0; i <= n; ++i)         if (vis[i]) pos.emplace_back(i);       for (int _ = 0; _ < 2; ++_) {         vector<int> d1(n, 0), d2(n, 0);         for (int i = _; i + 1 < pos.size(); i += 2) {           if (in[pos[i]].empty() || pos[i + 1] == pos[i] + 1) continue;           if (pos[i + 1] == pos[i] + 2) {             in[pos[i] + 1] = nxt[pos[i]];             nxt[pos[i]].resize(0);             vis[pos[i] + 1] = true;             continue;           }           flg = false;           int mid = pos[i] + pos[i + 1] + 1 >> 1;           for (int u : in[pos[i]]) {             d2[u] = mid - pos[i];             d1[u] = d2[u] - 1;           }         }         vector<bool> a1 = query(d1), a2 = query(d2);         for (int i = _; i + 1 < pos.size(); i += 2) {           if (in[pos[i]].empty() || pos[i + 1] <= pos[i] + 2) continue;           int mid = pos[i] + pos[i + 1] + 1 >> 1;           vector<int> tmp = nxt[pos[i]];           nxt[pos[i]].resize(0);           for (int x : tmp) {             if (a1[x])               nxt[pos[i]].emplace_back(x);             else if (a2[x])               in[mid].emplace_back(x);             else               nxt[mid].emplace_back(x);           }           vis[mid] = true;         }       }       if (flg) break;     }     for (int _ = 1; _ <= 3; ++_)       for (int i = 0; (1 << i) < n; ++i) {         vector<int> d(n, 0);         bool flg = true;         for (int x = _; x < n; x += 3)           if (!in[x].empty())             for (int v : in[x - 1])               if (v >> i & 1) {                 d[v] = 1;                 flg = false;               }         if (flg) continue;         vector<bool> res = query(d);         for (int x = _; x < n; x += 3)           if (!in[x].empty())             for (int v : in[x])               if (res[v]) fa[v] |= 1 << i;       }     puts( ! );     for (int i = 1; i < n; ++i) printf( %d %d n , fa[i] + 1, i + 1);   }
#include <bits/stdc++.h>   using namespace std;   namespace fastIO {   bool IOerror = 0;   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline long long read() {     bool sign = 0;     char ch = getchar();     long long x = 0;     for (; blank(ch); ch = getchar())       ;     if (IOerror) return 0;     if (ch ==  - ) sign = 1, ch = getchar();     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return x;   }   };  // namespace fastIO   using namespace fastIO;   struct node {     long long l, r, len;     node(long long x, long long y) { l = x, r = y, len = y - x + 1; }     bool operator<(const node& bb) const {       return len != bb.len ? len > bb.len : l < bb.l;     }   };   set<node> s;   long long now = 0;   long long l[1000010], r[1000010], len[1000010], num[1000010], ans[2010][2010];   signed main() {     long long n = read(), maxx = 0;     s.insert(node(1, n + 1));     for (long long i = 1; i <= n; i++) {       long long x = read();       now = 0;       for (auto i : s) {         l[++now] = i.l, r[now] = i.r, len[now] = i.len;         num[now] = 0;       }       for (long long j = 1; j <= now; j++) {         num[j] = 1;         ans[l[j]][i] = 1;         maxx = max(maxx, l[j]);         x--;         if (!x) break;       }       if (x) {         for (long long j = 1; j <= now; j++) {           while (num[j] < len[j] - 1 && x) {             ans[l[j] + num[j]][i] = 1;             maxx = max(maxx, l[j] + num[j]);             num[j]++;             x--;           }         }       }       if (x) {         for (long long j = 1; j <= now; j++) {           if (x && num[j] != len[j])             ans[r[j]][i] = 1, x--, num[j]++, maxx = max(maxx, r[j]);         }       }       s.clear();       for (long long j = 1; j <= now; j++) {         if (num[j]) s.insert(node(l[j], l[j] + num[j] - 1));         if (num[j] != len[j]) s.insert(node(l[j] + num[j], r[j]));         if (len[j] == 1) s.insert(node(l[j], r[j]));       }     }     cout << maxx <<   n ;     for (long long i = 1; i <= maxx; i++) {       for (long long j = 1; j <= n; j++) cout << ans[i][j];       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace mincostflow {   struct edge {     int to, cap, cost, rev;     edge(int to = 0, int cap = 0, int cost = 0, int rev = 0)         : to(to), cap(cap), cost(cost), rev(rev) {}   };   vector<edge> g[7000];   int dist[7000], q[7000 * 2];   int frome[7000], fromv[7000];   bool inq[7000];   int s, t;   void add_edge(int from, int to, int cap, int cost) {     g[from].push_back(edge(to, cap, cost, g[to].size()));     g[to].push_back(edge(from, 0, -cost, g[from].size() - 1));   }   bool dij() {     for (int i = 0; i <= t; i++) dist[i] = 1000000000;     dist[s] = 0;     q[0] = s;     inq[s] = 1;     int head = 0, tail = 1;     while (head != tail) {       int now = q[head++];       if (head == 7000 + 1) head = 0;       for (int i = 0; i < g[now].size(); i++) {         edge &e = g[now][i];         if (e.cap && dist[e.to] > dist[now] + e.cost) {           dist[e.to] = dist[now] + e.cost;           frome[e.to] = i;           fromv[e.to] = now;           if (!inq[e.to]) {             if (dist[e.to] < dist[q[head]]) {               head--;               if (head == -1) head = 7000;               q[head] = e.to;             } else {               q[tail++] = e.to;               if (tail == 7000 + 1) tail = 0;             }           }         }       }       inq[now] = 0;     }     return dist[t] != 1000000000;   }   int augment() {     int c = 1000000000, ret = 0;     for (int i = t; i != s; i = fromv[i]) c = min(c, g[fromv[i]][frome[i]].cap);     for (int i = t; i != s; i = fromv[i]) {       edge &e = g[fromv[i]][frome[i]];       ret += c * e.cost;       e.cap -= c;       g[e.to][e.rev].cap += c;     }     return ret;   }   int mcf() {     int ans = 0;     while (dij()) ans += augment();     return ans;   }   };  // namespace mincostflow   int a[100][100];   int id[100][100];   int n, m, cnt;   int main() {     using namespace mincostflow;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         id[i][j] = ++cnt;       }     }     s = ++cnt;     t = ++cnt;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if ((i + j) & 1)           add_edge(s, id[i][j], 1, 0);         else           add_edge(id[i][j], t, 1, 0);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if ((i + j) % 2 == 0) continue;         if (id[i][j - 1])           add_edge(id[i][j], id[i][j - 1], 1, (a[i][j] != a[i][j - 1]));         if (id[i][j + 1])           add_edge(id[i][j], id[i][j + 1], 1, (a[i][j] != a[i][j + 1]));         if (id[i - 1][j])           add_edge(id[i][j], id[i - 1][j], 1, (a[i][j] != a[i - 1][j]));         if (id[i + 1][j])           add_edge(id[i][j], id[i + 1][j], 1, (a[i][j] != a[i + 1][j]));       }     }     printf( %d n , mcf());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> lc, rc, pr;   set<int> nodes;   set<int>::iterator it;   vector<int> v;   int main() {     int n;     cin >> n;     int root;     cin >> root;     nodes.insert(root);     for (int i = 1; i < n; ++i) {       int x;       cin >> x;       v.push_back(x);       it = nodes.upper_bound(x);       if (it == nodes.end()) {         it--;         rc[*it] = x;         pr[x] = (*it);       } else if (it == nodes.begin()) {         lc[*it] = x;         pr[x] = (*it);       } else {         int ul = (*it);         it--;         int ll = (*it);         if (lc[ul])           rc[ll] = x, pr[x] = ll;         else           lc[ul] = x, pr[x] = ul;       }       nodes.insert(x);     }     for (int i = 0; i < v.size(); ++i) {       cout << pr[v[i]] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int R[300010 * 2], L[300010 * 2], n, m, sum[300010], sz;   struct Fun {     int k, b;   } f[300010], id[300010 * 20], s[300010];   inline int Read() {     char c = getchar();     int num = 0, f = 1;     while ( 0  > c || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) num = num * 10 + c -  0 , c = getchar();     return (num * f);   }   inline bool Pd(Fun c, Fun a, Fun b) {     return ((long long)(c.b - a.b) * (b.k - c.k) <=             (long long)(c.b - b.b) * (a.k - c.k));   }   inline void Ins(int rt, Fun x) {     id[++sz] = x;     if (!R[rt]) L[rt] = sz;     R[rt] = sz;     while (R[rt] - L[rt] >= 2 && Pd(id[R[rt] - 2], id[R[rt] - 1], id[R[rt]])) {       id[R[rt] - 1] = id[R[rt]];       id[R[rt]] = (Fun){0, 0};       sz--;       R[rt]--;     }   }   inline void Merge(int rt, int l, int mid, int r) {     int i = l, j = mid + 1, k = l - 1;     while (i <= mid && j <= r) {       if ((f[i].k < f[j].k) || (f[i].k == f[j].k && f[i].b < f[j].b))         s[++k] = f[i], i++;       else         s[++k] = f[j], j++;     }     for (; j <= r; j++) s[++k] = f[j];     for (; i <= mid; i++) s[++k] = f[i];     f[l] = s[l];     Ins(rt, f[l]);     for (int t = l + 1; t <= r; t++) {       f[t] = s[t];       if (f[t].k != f[t - 1].k) Ins(rt, f[t]);     }   }   inline void Build(int rt, int l, int r) {     int mid = (l + r) / 2;     if (l == r) {       Ins(rt, f[l]);       return;     }     Build(rt * 2, l, mid);     Build(rt * 2 + 1, mid + 1, r);     Merge(rt, l, mid, r);   }   inline int Cal(int l, int r, int x) {     while (r - l > 1) {       int mid = (l + r) / 2;       if (id[mid].k * x + id[mid].b < id[mid + 1].k * x + id[mid + 1].b) {         r = mid;         continue;       }       if (id[mid].k * x + id[mid].b > id[mid + 1].k * x + id[mid + 1].b) {         l = mid;         continue;       }       if (id[mid].k * x + id[mid].b < id[mid - 1].k * x + id[mid - 1].b) {         l = mid;         continue;       }       if (id[mid].k * x + id[mid].b > id[mid - 1].k * x + id[mid - 1].b) {         r = mid;         continue;       }     }     return (min(id[l].k * x + id[l].b, id[r].k * x + id[r].b));   }   inline int Find(int rt, int l, int r, int a, int b, int p) {     int mid = (l + r) / 2;     if (l == a && r == b) {       if (l <= 115 && 115 <= r) int deb = 0;       return (Cal(L[rt], R[rt], p));     }     if (b <= mid) return (Find(rt * 2, l, mid, a, b, p));     if (mid < a) return (Find(rt * 2 + 1, mid + 1, r, a, b, p));     if (a <= mid && mid < b) {       int L = Find(rt * 2, l, mid, a, mid, p);       int R = Find(rt * 2 + 1, mid + 1, r, mid + 1, b, p);       return (min(L, R));     }   }   int main() {     n = Read();     for (int i = 1; i <= n; i++) f[i].k = Read();     for (int i = 1; i <= n; i++)       sum[i] = sum[i - 1] + f[i].k, f[i].b = f[i].k * i - sum[i];     Build(1, 1, n);     m = Read();     for (int i = 1; i <= m; i++) {       int x = Read(), y = Read();       int Min = Find(1, 1, n, y - x + 1, y, x - y);       printf( %d n , min(sum[y] - sum[y - x], sum[y] + Min));     }   }