#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   long long n, a[maxn], aa[maxn], bb[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       aa[i] = aa[i - 1] + a[i];     }     long long b[maxn];     for (int i = 1; i <= n; i++) {       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++) {       bb[i] = bb[i - 1] + b[i];     }     int T;     cin >> T;     while (T--) {       int type, l, r;       long long sum = 0;       cin >> type >> l >> r;       if (type == 1) {         sum = aa[r] - aa[l - 1];       } else {         sum = bb[r] - bb[l - 1];       }       cout << sum << endl;     }     return 0;   }   