#include <fstream>
using namespace std;
ifstream cin(“qtsume.in”);
ofstream cout(“qtsume.out”);
long long s100001, q, a, b, n, x100001, s1100001;
int main(){
cin >> n;
for(int i = 1; i <= n; i++)
cin >> x[i];
s1 = x1;
s11 = x1;
for(int i = 2; i <= n; i++){
s[i] = s[i – 1] + i * x[i];
s1[i]= s1[i – 1] + x[i];
}
cin >> q;
while(q—){
cin >> a >> b;
long long s2 = s1[b] – s1[a – 1];
long long s3 = s[b] – s[a – 1];
cout << s3 – s2 * (a – 1) << ‘\n’;
}
return 0;
}