#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& s, pair<T, long long int> a) {
  s << a.first << ' ' << a.second;
  return s;
}
const long long int is_query = -(1LL << 62);
struct Line {
  long long int m, b;
  mutable function<const Line*()> succ;
  bool operator<(const Line& rhs) const {
    if (rhs.b != is_query) return m < rhs.m;
    const Line* s = succ();
    if (!s) return 0;
    long long int x = rhs.m;
    return b - s->b < (s->m - m) * x;
  }
};
struct HullDynamic : public multiset<Line> {
  bool bad(iterator y) {
    auto z = next(y);
    if (y == begin()) {
      if (z == end()) return 0;
      return y->m == z->m && y->b <= z->b;
    }
    auto x = prev(y);
    if (z == end()) return y->m == x->m && y->b <= x->b;
    return (long double)(x->b - y->b) * (z->m - y->m) >=
           (long double)(y->b - z->b) * (y->m - x->m);
  }
  void insert_line(long long int m, long long int b) {
    auto y = insert({m, b});
    y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
    if (bad(y)) {
      erase(y);
      return;
    }
    while (next(y) != end() && bad(next(y))) erase(next(y));
    while (y != begin() && bad(prev(y))) erase(prev(y));
  }
  long long int eval(long long int x) {
    auto l = *lower_bound((Line){x, is_query});
    return l.m * x + l.b;
  }
};
int csum[100005];
int ara[100005];
HullDynamic st[4 * 100005];
void init(int node, int ss, int sf) {
  if (ss == sf) {
    st[node].insert_line(ara[ss], -(ara[ss] * ss - csum[ss + 1]));
    return;
  }
  int mid = (ss + sf) / 2;
  init(2 * node, ss, mid);
  init(2 * node + 1, mid + 1, sf);
  for (int i = ss; i <= sf; i++)
    st[node].insert_line(ara[i], -(ara[i] * i - csum[i + 1]));
}
long long int query(int node, int ss, int sf, int qs, int qe) {
  if (ss > qe || sf < qs || qs > qe) return 2000000000;
  if (qs <= ss && qe >= sf) return -st[node].eval(qs - 1) + csum[qe + 1];
  int mid = (ss + sf) / 2;
  return min(query(2 * node, ss, mid, qs, qe),
             query(2 * node + 1, mid + 1, sf, qs, qe));
}
int main() {
  long long int T = 1;
  for (long long int qq = 1; qq <= T; qq++) {
    long long int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      scanf("%d", &ara[i]);
      csum[i + 1] = csum[i] + ara[i];
    }
    long long int m;
    cin >> m;
    init(1, 0, n - 1);
    for (long long int i = 0; i < m; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      int l = v - u;
      v--;
      printf("%lld\n", query(1, 0, n - 1, l, v));
    }
  }
}
