#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gi() {
  T x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const int N = 500003;
int n, q;
int a[N];
long long S[N];
int stk[N], tp;
vector<pair<int, int> > qry[N];
long long ans[N];
inline long long Y(int x) { return 1ll * x * a[x] - S[x]; }
inline long long X(int x) { return a[x]; }
inline double Slope(int x, int y) { return 1. * (Y(x) - Y(y)) / (X(x) - X(y)); }
int main() {
  n = gi<int>();
  for (int i = 1; i <= n; i += 1) a[i] = gi<int>(), S[i] = S[i - 1] + a[i];
  q = gi<int>();
  for (int i = 1; i <= q; i += 1) {
    int x = gi<int>(), y = gi<int>();
    qry[y].push_back({x, i});
  }
  for (int i = 1; i <= n; i += 1) {
    while (tp && a[i] <= a[stk[tp]]) --tp;
    while (tp > 1 && Slope(stk[tp], i) <= Slope(stk[tp - 1], stk[tp])) --tp;
    stk[++tp] = i;
    for (auto x : qry[i]) {
      int tmp =
              lower_bound(stk + 1, stk + 1 + tp, max(1, i - x.first + 1)) - stk,
          l = tmp, r = tp - 1, res = tp;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (Slope(stk[mid], stk[mid + 1]) >= 1. * (i - x.first))
          res = mid, r = mid - 1;
        else
          l = mid + 1;
      }
      ans[x.second] =
          1ll * a[stk[res]] * (x.first - (i - stk[res])) + S[i] - S[stk[res]];
    }
  }
  for (int i = 1; i <= q; i += 1) printf("%lld\n", ans[i]);
  return 0;
}
