#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, sgn = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') sgn = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
  return x * sgn;
}
const int N = 5e5 + 10;
pair<int, int> q[N];
int a[N], n, Q, mx, stk[N], top;
vector<pair<int, int> > v[N];
long long ans[N], s[N], Y[N];
namespace sub2 {
double slope(int x, int y) { return ((double)Y[y] - Y[x]) / (a[y] - a[x]); }
void solve() {
  for (int i = 1; i <= Q; i++)
    v[q[i].second].push_back(pair<int, int>(q[i].first, i));
  for (int i = 1; i <= n; i++)
    s[i] = s[i - 1] + a[i], Y[i] = 1ll * a[i] * i - s[i];
  for (int i = 1; i <= n; i++) {
    while (top && a[i] <= a[stk[top]]) top--;
    while (top > 1 && slope(stk[top - 1], stk[top]) > slope(stk[top], i)) top--;
    stk[++top] = i;
    for (auto d : v[i]) {
      int pos =
          lower_bound(stk + 1, stk + top + 1, max(i - d.first + 1, 1)) - stk;
      int l = pos, r = top - 1, j = top;
      while (l <= r) {
        int mid = l + r >> 1;
        if (slope(stk[mid], stk[mid + 1]) < i - d.first)
          l = mid + 1;
        else
          r = mid - 1, j = mid;
      }
      j = stk[j];
      ans[d.second] = 1ll * a[j] * (d.first - i + j) + s[i] - s[j];
    }
  }
  for (int i = 1; i <= Q; i++) printf("%lld\n", ans[i]);
}
}  // namespace sub2
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  Q = read();
  for (int i = 1; i <= Q; i++)
    q[i].first = read(), q[i].second = read(), mx = max(mx, q[i].first);
  sub2::solve();
  return 0;
}
