#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int64_t> v(n + 1), x(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    x[i] = v[i];
  }
  sort(x.begin(), x.end());
  for (int i = 1; i <= n; i++) {
    v[i] += v[i - 1];
    x[i] += x[i - 1];
  }
  int m;
  cin >> m;
  while (m--) {
    int type, l, r;
    cin >> type >> l >> r;
    if (type & 1)
      cout << v[r] - v[--l] << '\n';
    else
      cout << x[r] - x[--l] << '\n';
  }
  return 0;
}
