#include <bits/stdc++.h>
using namespace std;
int n;
const int MAXN = 1e5 + 1;
long long sum1toX[MAXN];
long long sortedSum1toX[MAXN];
int v[MAXN];
int m, l, r, type;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sum1toX[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum1toX[i] = sum1toX[i - 1] + v[i - 1];
  }
  sort(v, v + n);
  sortedSum1toX[0] = 0;
  for (int i = 1; i <= n; i++) {
    sortedSum1toX[i] = sortedSum1toX[i - 1] + v[i - 1];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> type >> l >> r;
    if (type == 1) {
      cout << (long long)sum1toX[n] - (sum1toX[l - 1] + sum1toX[n] - sum1toX[r])
           << '\n';
    } else {
      cout << (long long)sortedSum1toX[n] -
                  (sortedSum1toX[l - 1] + sortedSum1toX[n] - sortedSum1toX[r])
           << '\n';
    }
  }
  return 0;
}
