#include <bits/stdc++.h>
#define inf 10000005

using namespace std;

int wych[1000005], odl[1000005];
queue < int > Q[2];

vector < vector < int > > E, ER;

int main()
{
    for(int i=0; i<1000001; i++)
        odl[i] = inf;
    int n, m, mm;
    scanf("%d%d", &n, &m);
    mm = m;
  //  cin>>n>>m;
    E.resize(n+1);
    ER.resize(n+1);
    while(m--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        E[a].push_back(b);
        wych[a]++;
        ER[b].push_back(a);
    }
    int p, k, akt = 0;
    scanf("%d%d", &p, &k);
    Q[0].push(k);
    odl[k] = 0;
    int a=0, b=0, c=0;
    while(odl[p] > 1000001 && (!Q[0].empty() || !Q[1].empty()))
    {
        queue < int > &Q1 = Q[akt&1], &Q2 = Q[akt^1];
        while(!Q2.empty())
            Q2.pop();
        while(!Q1.empty())
        {
            b++;
            if (b > 2*n)
                return -2;
            int aktv = Q1.front();
            Q[akt].pop();
            if (odl[aktv] < akt)
                continue;
            for(auto& sas: ER[aktv])
            {
                c++;
                if (c > 2*mm)
                    return -1;
                wych[sas]--;
                if (wych[sas]==0 && odl[sas] > akt)
                {
                    odl[sas] = akt;
                    Q1.push(sas);
                }
                if (odl[sas] > akt+1)
                {
                    odl[sas] = akt+1;
                    Q2.push(sas);
                }
            }
        }
        akt++;
    }
    if (odl[p] < inf)
        printf("%d", odl[p]);
    else
        printf("-1");
}


#include <bits/stdc++.h>
#define inf 10000005

using namespace std;

int wych[1000005], odl[1000005];
queue < int > Q[2];

vector < vector < int > > E, ER;

int main()
{
    for(int i=0; i<1000001; i++)
        odl[i] = inf;
    int n, m, mm;
    scanf("%d%d", &n, &m);
    mm = m;
  //  cin>>n>>m;
    E.resize(n+100);
    ER.resize(n+100);
    while(m--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        E[a].push_back(b);
        wych[a]++;
        ER[b].push_back(a);
    }
    int p, k, akt = 0;
    scanf("%d%d", &p, &k);
    Q[0].push(k);
    odl[k] = 0;
    int a=0, b=0, c=0;
    while(odl[p] > 1000001 && akt <= 1000000 && (!Q[0].empty() || !Q[1].empty()))
    {
        queue < int > &Q1 = Q[akt%2], &Q2 = Q[1 - (akt%2)];
        while(!Q2.empty())
            Q2.pop();
        while(!Q1.empty())
        {
            b++;
            if (b > 3*n)
                return -2;
            int aktv = Q1.front();
            Q1.pop();
            if (odl[aktv] < akt)
                continue;
            for(auto& sas: ER[aktv])
            {
                c++;
                wych[sas]--;
                if (wych[sas]==0 && odl[sas] > akt)
                {
         //       cout << sas << endl;
                    odl[sas] = akt;
                    Q1.push(sas);
                }
                if (odl[sas] > akt+1)
                {
                    odl[sas] = akt+1;
                    Q2.push(sas);
                }
            }
        }
        akt++;
    }
    if (odl[p] < inf)
        printf("%d", odl[p]);
    else
        printf("-1");
}


#include <bits/stdc++.h>
#define inf 10000005

using namespace std;

int wych[1000005], odl[1000005];
queue < int > Q[2];

vector < vector < int > > E, ER;

int main()
{
    for(int i=0; i<1000001; i++)
        odl[i] = inf;
    int n, m;
    scanf("%d%d", &n, &m);
  //  cin>>n>>m;
    E.resize(n+1);
    ER.resize(n+1);
    while(m--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        E[a].push_back(b);
        wych[a]++;
        ER[b].push_back(a);
    }
    int p, k, akt = 0;
    scanf("%d%d", &p, &k);
    Q[0].push(k);
    odl[k] = 0;
    while(odl[p] > 1000001 && (!Q[0].empty() || !Q[1].empty()))
    {
        queue < int > &Q1 = Q[akt&1], &Q2 = Q[akt^1];
        while(!Q2.empty())
            Q2.pop();
        while(!Q1.empty())
        {
            int aktv = Q1.front();
            Q[akt].pop();
            if (odl[aktv] < akt)
                continue;
            for(auto& sas: ER[aktv])
            {
                wych[sas]--;
                if (wych[sas]==0 && odl[sas] > akt)
                {
                    odl[sas] = akt;
                    Q1.push(sas);
                }
                if (odl[sas] > akt+1)
                {
                    odl[sas] = akt+1;
                    Q2.push(sas);
                }
            }
        }
        akt++;
    }
    if (odl[p] < inf)
        printf("%d", odl[p]);
    else
        printf("-1");
}


#include <bits/stdc++.h>
#define inf 10000005

using namespace std;

int wych[1000005], odl[1000005];
queue < int > Q[2];

vector < vector < int > > E, ER;

int main()
{
    for(int i=0; i<1000001; i++)
        odl[i] = inf;
    int n, m, mm;
    scanf("%d%d", &n, &m);
    mm = m;
  //  cin>>n>>m;
    E.resize(n+1);
    ER.resize(n+1);
    while(m--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        E[a].push_back(b);
        wych[a]++;
        ER[b].push_back(a);
    }
    int p, k, akt = 0;
    scanf("%d%d", &p, &k);
    Q[0].push(k);
    odl[k] = 0;
    int a=0, b=0, c=0;
    while(odl[p] > 1000001 && akt <= 1000000 && (!Q[0].empty() || !Q[1].empty()))
    {
        queue < int > &Q1 = Q[akt&1], &Q2 = Q[akt^1];
        while(!Q2.empty())
            Q2.pop();
        while(!Q1.empty())
        {
            b++;
            if (b > 2*n)
                return -2;
            int aktv = Q1.front();
            Q[akt].pop();
            if (odl[aktv] < akt)
                continue;
            for(auto& sas: ER[aktv])
            {
                c++;
                if (c > 2*mm)
                    return -1;
                wych[sas]--;
                if (wych[sas]==0 && odl[sas] > akt)
                {
                    odl[sas] = akt;
                    Q1.push(sas);
                }
                if (odl[sas] > akt+1)
                {
                    odl[sas] = akt+1;
                    Q2.push(sas);
                }
            }
        }
        akt++;
    }
    if (odl[p] < inf)
        printf("%d", odl[p]);
    else
        printf("-1");
}


#include <bits/stdc++.h>
#define inf 10000005

using namespace std;

int wych[1000005], odl[1000005];
queue < int > Q[2];

vector < vector < int > > E, ER;

int main()
{
    for(int i=0; i<1000001; i++)
        odl[i] = inf;
    int n, m, mm;
    scanf("%d%d", &n, &m);
    mm = m;
  //  cin>>n>>m;
    E.resize(n+1);
    ER.resize(n+1);
    while(m--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        E[a].push_back(b);
        wych[a]++;
        ER[b].push_back(a);
    }
    int p, k, akt = 0;
    scanf("%d%d", &p, &k);
    Q[0].push(k);
    odl[k] = 0;
    int a=0, b=0, c=0;
    while(odl[p] > 1000001 && akt <= 1000000 && (!Q[0].empty() || !Q[1].empty()))
    {
        queue < int > &Q1 = Q[akt&1], &Q2 = Q[1 - (akt&1)];
        while(!Q2.empty())
            Q2.pop();
        while(!Q1.empty())
        {
            b++;
            int aktv = Q1.front();
            Q[akt].pop();
            if (odl[aktv] < akt)
                continue;
            for(auto& sas: ER[aktv])
            {
                c++;
                wych[sas]--;
                if (wych[sas]==0 && odl[sas] > akt)
                {
                    odl[sas] = akt;
                    Q1.push(sas);
                }
                if (odl[sas] > akt+1)
                {
                    odl[sas] = akt+1;
                    Q2.push(sas);
                }
            }
        }
        akt++;
    }
    if (odl[p] < inf)
        printf("%d", odl[p]);
    else
        printf("-1");
}


#include <bits/stdc++.h>
#define inf 10000005

using namespace std;

int wych[1000005], odl[1000005];
queue < int > Q[2];

vector < vector < int > > E, ER;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    for(int i=0; i<1000001; i++)
        odl[i] = inf;
    int n, m;
    cin>>n>>m;
    E.resize(n+1);
    ER.resize(n+1);
    while(m--)
    {
        int a, b;
        cin>>a>>b;
        E[a].push_back(b);
        wych[a]++;
        ER[b].push_back(a);
    }
    int p, k, akt = 0;
    cin>>p>>k;
    Q[0].push(k);
    while(odl[p] > 1000001)
    {
        queue < int > &Q1 = Q[akt&1], &Q2 = Q[akt^1];
        while(!Q2.empty())
            Q2.pop();
        while(!Q1.empty())
        {
            int aktv = Q1.front();
            Q[akt].pop();
            if (odl[aktv] < akt)
                continue;
            for(auto& sas: ER[aktv])
            {
                wych[sas]--;
                if (wych[sas]==0)
                {
                    odl[sas] = akt;
                    Q1.push(sas);
                }
                if (odl[sas] > akt+1)
                {
                    odl[sas] = akt+1;
                    Q2.push(sas);
                }
            }
        }
        akt++;
    }
    if (odl[p] < inf)
        cout<<odl[p];
    else
        cout<<"-1";
}


#include <bits/stdc++.h>
#define inf 10000005

using namespace std;

int wych[1000005], odl[1000005];
queue < int > Q[2];

vector < vector < int > > E, ER;

int main()
{
    for(int i=0; i<1000001; i++)
        odl[i] = inf;
    int n, m, mm;
    scanf("%d%d", &n, &m);
    mm = m;
  //  cin>>n>>m;
    E.resize(n+1);
    ER.resize(n+1);
    while(m--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        E[a].push_back(b);
        wych[a]++;
        ER[b].push_back(a);
    }
    int p, k, akt = 0;
    scanf("%d%d", &p, &k);
    Q[0].push(k);
    odl[k] = 0;
    int a=0, b=0, c=0;
    while(odl[p] > 1000001 && akt <= 1000000 && (!Q[0].empty() || !Q[1].empty()))
    {
        queue < int > &Q1 = Q[akt&1], &Q2 = Q[1 - (akt&1)];
        while(!Q2.empty())
            Q2.pop();
        while(!Q1.empty())
        {
            b++;
            if (b > 3*n)
                return -2;
            int aktv = Q1.front();
            Q[akt].pop();
            if (odl[aktv] < akt)
                continue;
            for(auto& sas: ER[aktv])
            {
                c++;
                wych[sas]--;
                if (wych[sas]==0 && odl[sas] > akt)
                {
                    odl[sas] = akt;
                    Q1.push(sas);
                }
                if (odl[sas] > akt+1)
                {
                    odl[sas] = akt+1;
                    Q2.push(sas);
                }
            }
        }
        akt++;
    }
    if (odl[p] < inf)
        printf("%d", odl[p]);
    else
        printf("-1");
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
const int N=1e6+5,inf=1<<30;
int n,m,S,T,f[N],head[N],opt,in[N];
struct info{int to,nxt;}e[N];
void add(int x,int y){
	in[y]++;
	e[++opt]=(info){y,head[x]};head[x]=opt;
}
deque<int> q;
bool used[N];
void bfs(){
	For(i,1,n) f[i]=-1;
	q.push_back(T);f[T]=0;
	while(q.size()){
		int u=q.front();q.pop_front();
		if(used[u]) continue;
		used[u]=1;
		for(int i=head[u];i;i=e[i].nxt){
			int k=e[i].to;
			in[k]--;
			if(!in[k]){
				if(f[k]==-1||f[k]>f[u]) f[k]=f[u],q.push_front(k);
			}else if(f[k]==-1) f[k]=f[u]+1,q.push_back(k);
		}
	}
}
int main(){
	n=read();m=read();
	For(i,1,m){
		int x=read(),y=read();
		add(y,x);
	}
	S=read();T=read();
	bfs();
	if(f[S]==inf) f[S]=-1;
	cout<<f[S];
}
/*
4 6
1 2
2 1
1 3
3 1
2 4
3 4
1 4

*/


#include<bits/stdc++.h>
using namespace std;
#define fr(n) for(int i=1;i<=n;++i)
#define pb push_back
#define ll long long
#define vint vector<long>
#define m_p make_pair

int main(){
      int n;
      cin>>n;
    ll v[100005],v1[100005];
    fr(n)
    cin>>v[i],v1[i]=v[i];
    sort(v1+1,v1+n);
    for(int i=2;i<=n;++i)v[i]+=v[i-1],v1[i]+=v1[i-1];
    int m;
    cin>>m;
    while(m--){
      int a,b,c;
      cin>>a>>b>>c;
      if(a==1)
       cout<<v[c]-v[b-1]<<endl;
       else
       cout<<v1[c]-v1[b-1]<<endl;
       }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr(n) for(int i=1;i<=n;++i)
#define pb push_back
#define ll long long
#define vint vector<long>
#define m_p make_pair

int main(){
      int n;
      cin>>n;
    int v[100005],v1[100005];
    fr(n)
    cin>>v[i],v1[i]=v[i];
    sort(v1+1,v1+n+1);
    for(int i=2;i<=n;++i)v[i]+=v[i-1],v1[i]+=v1[i-1];
    int m;
    cin>>m;
    while(m--){
      int a,b,c;
      cin>>a>>b>>c;
      if(a==1)
       cout<<v[c]-v[b-1]<<endl;
       else
       cout<<v1[c]-v1[b-1]<<endl;
       }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr(n) for(int i=0;i<n;++i)
#define pb push_back
#define ll long long
#define vint vector<long>
#define m_p make_pair

int main(){
      int n;
      cin>>n;
    vint v(n),v1;
    fr(n)
    cin>>v[i];
    v1=v;
    sort(v1.begin(),v1.end());
    int m;
    cin>>m;
    while(m--){
      int a,b,c;
      cin>>a>>b>>c;
      ll sum=0;
      if(a==1){
      for(int i=b-1;i<c;++i)
        sum+=v[i];
        cout<<sum<<endl;
      }
      else{
          for(int i=b-1;i<c;++i)
        sum+=v1[i];
        cout<<sum<<endl;
      }
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr(n) for(int i=0;i<n;++i)
#define pb push_back
#define ll long long
#define vint vector<long>
#define m_p make_pair

int main(){
      int n;
      cin>>n;
    vint v(n),v1;
    fr(n)
    cin>>v[i];
    v1=v;
    sort(v1.begin(),v1.end());
    int m;
    cin>>m;
    while(m--){
      int a,b,c;
      cin>>a>>b>>c;
       ll s1=0,s2=0;
       for(int i=0;i<c;++i){
      if(a==1){
       if(i<b-1) s1+=v[i];
       s2+=v[i];
      }
      else{
     if(i<b-1) s1+=v1[i];
       s2+=v1[i];
      }
       }
       cout<<s2-s1<<endl;
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr(n) for(int i=1;i<=n;++i)
#define pb push_back
#define ll long long
#define vint vector<long>
#define m_p make_pair

int main(){
      int n;
      cin>>n;
    int v[100005],v1[100005];
    fr(n)
    cin>>v[i],v1[i]=v[i];
    sort(v1+1,v1+n+1);
    for(int i=1;i<=n;++i)v[i]+=v[i-1],v1[i]+=v1[i-1];
    int m;
    cin>>m;
    while(m--){
      int a,b,c;
      cin>>a>>b>>c;
      if(a==1)
       cout<<v[c]-v[b-1]<<endl;
       else
       cout<<v1[c]-v1[b-1]<<endl;
       }
  return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for(long long i = 0;i<n;i++){
    cin >> v[i];
  }
  vector<long long> u(v);
  sort(u.begin(),u.end());
  map<pair<long long,long long>,long long> memo1;
  map<pair<long long,long long>,long long> memo2;
  long long m;
  cin >> m;
  for(long long i = 0;i<m;i++){
    long long type,l,r;
    cin >> type >> l >> r;
    pair<long long,long long> temp  = make_pair(l,r);
    if(type==1){

      if(memo1.count(temp)){
        cout << memo1[temp] << '\n';
      }
      else {
        bool found = false;
        for(auto i: memo1){
          if(i.first.first >= l && i.first.second <=r){
            memo1[temp] = i.second + accumulate(v.begin()+l-1,v.begin()+i.first.first-1,0ll) + accumulate(v.begin()+i.first.second,v.begin()+r,0ll);
            found = true;
            break;
          }
        }
        if(!found) {
          memo1[temp] = accumulate(v.begin()+l-1,v.begin()+r,0ll);
        }
        cout << memo1[temp] << '\n';

      }
    }
    else {
      if(memo2.count(temp)){
        cout << memo2[temp] << '\n';
      }
      else {
        bool found = false;
        for(auto i: memo2){
          if(i.first.first >= l && i.first.second <=r){
            memo2[temp] = i.second + accumulate(u.begin()+l-1,u.begin()+i.first.first,0ll) + accumulate(u.begin()+i.first.second-1,u.begin()+r,0ll);
            found = true;
            break;
          }
        }
        if(!found) {
          memo2[temp] = accumulate(u.begin()+l-1,u.begin()+r,0ll);
        }
        cout << memo2[temp] << '\n';
      }
    }
  }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for(int i = 0;i<n;i++){
    cin >> v[i];
  }
  vector<long long> u(v);
  sort(u.begin(),u.end());
  map<pair<int,int>,long long> memo1;
  map<pair<int,int>,long long> memo2;
  int m;
  cin >> m;
  for(int i = 0;i<m;i++){
    int type,l,r;
    cin >> type >> l >> r;
    pair<int,int> temp  = make_pair(l,r);
    if(type==1){
      if(memo1.count(temp)){
        cout << memo1[temp] << '\n';
      }
      else {
        memo1[temp] = accumulate(v.begin()+l-1,v.begin()+r,0);
        cout << memo1[temp] << '\n';
      }
    }
    else {
      if(memo2.count(temp)){
        cout << memo2[temp] << '\n';
      }
      else {
        memo2[temp] = accumulate(u.begin()+l-1,u.begin()+r,0);
        cout << memo2[temp] << '\n';
      }
    }
  }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for(long long i = 0;i<n;i++){
    cin >> v[i];
  }
  vector<long long> u(v);
  sort(u.begin(),u.end());
  map<pair<long long,long long>,long long> memo1;
  map<pair<long long,long long>,long long> memo2;
  long long m;
  cin >> m;
  for(long long i = 0;i<m;i++){
    long long type,l,r;
    cin >> type >> l >> r;
    pair<long long,long long> temp  = make_pair(l,r);
    if(type==1){
      if(memo1.count(temp)){
        cout << memo1[temp] << '\n';
      }
      else {
        memo1[temp] = accumulate(v.begin()+l-1,v.begin()+r,0ll);
        cout << memo1[temp] << '\n';
      }
    }
    else {
      if(memo2.count(temp)){
        cout << memo2[temp] << '\n';
      }
      else {
        memo2[temp] = accumulate(u.begin()+l-1,u.begin()+r,0ll);
        cout << memo2[temp] << '\n';
      }
    }
  }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  long long sumtillnow=0;
  map<pair<long long,long long>,long long> memo1;
  map<pair<long long,long long>,long long> memo2;
  for(long long i = 0;i<n;i++){
    cin >> v[i];
    sumtillnow += v[i];
    memo1[make_pair(1,i+1)] = sumtillnow;
  }
  vector<long long> u(v);
  sort(u.begin(),u.end());
  sumtillnow = 0;
  for(long long i;i<n;i++){
    sumtillnow+=u[i];
    memo2[make_pair(1,i+1)] = sumtillnow;
  }

  long long m;
  cin >> m;
  for(long long i = 0;i<m;i++){
    long long type,l,r;
    cin >> type >> l >> r;
    if(type==1){
      //if(l==1){
      //  cout << memo1[make_pair(l,r)] << '\n';
      //}
      //else {
        cout << memo1[make_pair(1,r)] - memo1[make_pair(1,l-1)] << '\n';
      //}

    }
    else {
      //if(l==1){
      //  cout << memo2[make_pair(l,r)] << '\n';
      //}
      //else {
        cout << memo2[make_pair(1,r)] - memo1[make_pair(1,l-1)] << '\n';
      //}

    }

  }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  long long sumtillnow=0;
  map<pair<long long,long long>,long long> memo1;
  map<pair<long long,long long>,long long> memo2;
  for(long long i = 0;i<n;i++){
    cin >> v[i];
    sumtillnow += v[i];
    memo1[make_pair(1,i+1)] = sumtillnow;
  }
  vector<long long> u(v);
  sort(u.begin(),u.end());
  sumtillnow = 0;
  for(long long i;i<n;i++){
    sumtillnow+=u[i];
    memo2[make_pair(1,i+1)] = sumtillnow;
  }

  long long m;
  cin >> m;
  for(long long i = 0;i<m;i++){
    long long type,l,r;
    cin >> type >> l >> r;
    if(type==1){
        cout << memo1[make_pair(1,r)] - memo1[make_pair(1,l-1)] << '\n';
    }
    else {
        cout << memo2[make_pair(1,r)] - memo2[make_pair(1,l-1)] << '\n';
    }

  }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for(long long i = 0;i<n;i++){
    cin >> v[i];
  }
  vector<long long> u(v);
  sort(u.begin(),u.end());
  map<pair<long long,long long>,long long> memo1;
  map<pair<long long,long long>,long long> memo2;
  long long m;
  cin >> m;
  for(long long i = 0;i<m;i++){
    long long type,l,r;
    cin >> type >> l >> r;
    pair<long long,long long> temp  = make_pair(l,r);
    if(type==1){
      if(memo1.find(temp)==memo1.end()){
        cout << memo1[temp] << '\n';
      }
      else {
        memo1[temp] = accumulate(v.begin()+l-1,v.begin()+r,0ll);
        cout << memo1[temp] << '\n';
      }
    }
    else {
      if(memo2.find(temp) == memo2.end()){
        cout << memo2[temp] << '\n';
      }
      else {
        memo2[temp] = accumulate(u.begin()+l-1,u.begin()+r,0ll);
        cout << memo2[temp] << '\n';
      }
    }
  }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for(long long i = 0;i<n;i++){
    cin >> v[i];
  }
  vector<long long> u(v);
  sort(u.begin(),u.end());
  map<pair<long long,long long>,long long> memo1;
  map<pair<long long,long long>,long long> memo2;
  long long m;
  cin >> m;
  for(long long i = 0;i<m;i++){
    long long type,l,r;
    cin >> type >> l >> r;
    pair<long long,long long> temp  = make_pair(l,r);
    if(type==1){
      if(memo1.count(temp)){
        cout << memo1[temp] << '\n';
      }
      else {
        memo1[temp] = accumulate(v.begin()+l-1,v.begin()+r,0);
        cout << memo1[temp] << '\n';
      }
    }
    else {
      if(memo2.count(temp)){
        cout << memo2[temp] << '\n';
      }
      else {
        memo2[temp] = accumulate(u.begin()+l-1,u.begin()+r,0);
        cout << memo2[temp] << '\n';
      }
    }
  }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i = 0;i<n;i++){
    cin >> v[i];
  }
  vector<int> u(v);
  sort(u.begin(),u.end());
  map<pair<int,int>,int> memo1;
  map<pair<int,int>,int> memo2;
  int m;
  cin >> m;
  for(int i = 0;i<m;i++){
    int type,l,r;
    cin >> type >> l >> r;
    pair<int,int> temp  = make_pair(l,r);
    if(type==1){
      if(memo1.count(temp)){
        cout << memo1[temp] << '\n';
      }
      else {
        memo1[temp] = accumulate(v.begin()+l-1,v.begin()+r,0);
        cout << memo1[temp] << '\n';
      }
    }
    else {
      if(memo2.count(temp)){
        cout << memo2[temp] << '\n';
      }
      else {
        memo2[temp] = accumulate(u.begin()+l-1,u.begin()+r,0);
        cout << memo2[temp] << '\n';
      }
    }
  }
}


#include <bits\stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	ll arr[N],arr1[N],x[N],x1[N];
	ll sum=0, sum1=0;
	ll ans;
	int m, type, l, r;
	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> arr[i];
		x[i] = sum;
		sum += arr[i];
	}
	x[n] = sum;

	for (int i = 0; i < n ; i++) {
		arr1[i] = arr[i];
		x1[i] = sum1;
		sum1 += arr1[i];
	}
	x1[n] = sum1;

    sort(arr, arr + n);
	cin >> m;
	while (m--) {
		 ans = 0;
		cin >> type >> l >> r;

		if (type == 2) {
			ans =sum1- x1[r];

		}

			else {
				ans = x[r] - x[l - 1];
		}
				cout << ans << endl;
	}
	return 0;
}


#include <bits\stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const ll N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	ll arr[N],arr1[N];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> arr[i];
	for (int i = 0; i < n; i++) arr1[i] = arr[i];
	ll m, type, l, r;
	ll sum;
	cin >> m;
	while (m--) {
		 sum = 0;
		cin >> type >> l >> r;

		if (type == 2) {
			sort(arr, arr + n);
				for (int j = l-1; j < r; j++) {
					sum += arr[j];
				}
					cout << sum << endl;
		}

			else {
				for (int i = (l - 1); i < (r); i++) {
					sum += arr1[i];
				}
				cout << sum << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	ll arr[N], arr1[N];
	int m, type, l, r;
	cin >> n;

	for (int i = 1; i <=n; i++) {
		cin >> arr[i];
		arr1[i] = arr[i];
	}
	sort(arr, arr + n);

	for (int i = 0; i <= n; i++) {
		arr[i] = arr[i] + arr[i - 1];
		arr1[i] = arr1[i] + arr1[i - 1];
	}

	cin >> m;
	while (m--) {
		cin >> type >> l >> r;

		if (type == 2)
			cout << arr[r] - arr[l - 1] << endl;

		else
			cout << arr1[r] - arr1[l - 1] << endl;
	}

	return 0;
}


#include <bits\stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	int arr[N];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> arr[i];
	int m, type, l, r,sum;
	cin >> m;
	while (m--) {
		 sum = 0;
		cin >> type >> l >> r;

		for (int i = (l-1); i < (r); i++) {
			sum += arr[i];
		}
			if (type == 2) cout <<sum +arr[0]<<endl;
			else cout << sum<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
int m, n, x, y,k, q, ans;
int a[N], b[N];
ll comA[N], comB[N];
int main(){
#ifndef ONLINE_JUDGE
	freopen("myFile.txt", "r", stdin);
#endif

	cin>>n;
	for (int i = 1; i <= n; i++){
		cin>>a[i];
		b[i] = a[i];
	}
	sort(b+1, b + n+1);
	for (int i = 1; i <= n; i++){
		comA[i] = comA[i - 1] + a[i];
		comB[i] = comB[i - 1] + b[i];
	}
	cin>>q;
	while (q--){
		int type;
		cin >> type >>x >> y;
		if (type == 1)
			cout<< comA[y] - comA[x - 1]<<endl;
		else cout<< comB[y] - comB[x - 1]<<endl;
	}
	return 0;
}


#include <bits\stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	int arr[N],arr1[N];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> arr[i];
	for (int i = 0; i < n; i++) arr1[i] = arr[i];
	int m, type, l, r,sum;
	cin >> m;
	while (m--) {
		 sum = 0;
		cin >> type >> l >> r;

		if (type == 2) {
			sort(arr, arr + n);
				for (int j = l-1; j < r; j++) {
					sum += arr[j];
				}
					cout << sum << endl;
		}

			else {
				for (int i = (l - 1); i < (r); i++) {
					sum += arr1[i];
				}
				cout << sum << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	ll arr[N],arr1[N],x[N],x1[N];
	ll sum=0, sum1=0;
	ll ans;
	int m, type, l, r;
	cin >> n;

	for (int i = 0; i < n; i++) cin >> arr[i];
	for (int i = 0; i < n; i++) arr1[i] = arr[i];
    sort(arr, arr + n);

	for (int i = 0; i < n; i++) {
		x[i] = sum;
		sum += arr[i];
	}
	x[n] = sum;

	for (int i = 0; i < n ; i++) {
		x1[i] = sum1;
		sum1 += arr1[i];
	}
	x1[n] = sum1;

	cin >> m;
	while (m--) {
		 ans = 0;
		cin >> type >> l >> r;

		if (type == 2) {
			ans =x[r]- x[l-1];

		}

			else {
				ans = x1[r] - x1[l - 1];
		}
				cout << ans << endl;
	}
	return 0;
}


#include <bits\stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	int arr[N],arr1[N];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> arr[i];
	for (int i = 0; i < n; i++) arr1[i] = arr[i];
	int m, type, l, r,sum;
	cin >> m;
	while (m--) {
		 sum = 0;
		cin >> type >> l >> r;

		if (type == 2) {
			sort(arr, arr + n);
				for (int j = 0; j < n; j++) {
					sum += arr[j];
				}
					cout << sum << endl;
		}

			else {
				for (int i = (l - 1); i < (r); i++) {
					sum += arr1[i];
				}
				cout << sum << endl;
		}
	}
	return 0;
}


#include <bits\stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	ll arr[N],arr1[N];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> arr[i];
	for (int i = 0; i < n; i++) arr1[i] = arr[i];
	int m, type, l, r;
	ll sum;
	cin >> m;
	while (m--) {
		 sum = 0;
		cin >> type >> l >> r;

		if (type == 2) {
			sort(arr, arr + n);
				for (int j = l-1; j < r; j++) {
					sum += arr[j];
				}
					cout << sum << endl;
		}

			else {
				for (int i = (l - 1); i < (r); i++) {
					sum += arr1[i];
				}
				cout << sum << endl;
		}
	}
	return 0;
}


#include <bits\stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	int arr[N];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> arr[i];
	int m, type, l, r,sum;
	cin >> m;
	while (m--) {
		 sum = 0;
		cin >> type >> l >> r;

		for (int i = (l-1); i < (r); i++) {
			sum += arr[i];
		}
			if (type == 2&&l!=1) cout <<sum +arr[0]<<endl;
			else cout << sum<<endl;
	}
	return 0;
}


#include <bits\stdc++.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e5 + 1;
int frq[N];
map<int, int >mp;
//ll arr1[N], arr2[N], arr3[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	ll arr[N],arr1[N],x[N],x1[N];
	ll sum=0, sum1=0;
	ll ans;
	int m, type, l, r;
	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> arr[i];
		x[i] = sum;
		sum += arr[i];
	}
	x[n] = sum;

	for (int i = 0; i < n ; i++) {
		arr1[i] = arr[i];
		x1[i] = sum1;
		sum1 += arr1[i];
	}
	x1[n] = sum1;

    sort(arr, arr + n);
	cin >> m;
	while (m--) {
		 ans = 0;
		cin >> type >> l >> r;

		if (type == 2) {
			ans = x1[r] - x1[l - 1];

		}

			else {
				ans = x[r] - x[l - 1];
		}
				cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int partition (long long int arr[], int low, int high)
{
    int pivot = arr[high];    // pivot
    int i = (low - 1);  // Index of smaller element

    for (int j = low; j <= high- 1; j++)
    {
        // If current element is smaller than or
        // equal to pivot
        if (arr[j] <= pivot)
        {
            i++;    // increment index of smaller element
            long long int temp;
            temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }
    long long int temp;
    temp = arr[i+1];
    arr[i+1] = arr[high];
    arr[high] = temp;
    return (i + 1);
}

/* The main function that implements QuickSort
 arr[] --> Array to be sorted,
  low  --> Starting index,
  high  --> Ending index */
void quickSort(long long int arr[], int low, int high)
{
    if (low < high)
    {
        /* pi is partitioning index, arr[p] is now
           at right place */
        int pi = partition(arr, low, high);

        // Separately sort elements before
        // partition and after partition
        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}

int main(){
    int n;
    cin>>n;
    long long int a[n];
    for(int i=0; i<n; ++i){
        cin>>a[i];
    }

    long long int answerForA[n][n]={0};
    long long int answerForB[n][n]={0};

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForA[i][j] =sum;
        }
    }

    quickSort(a,0,n-1);

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForB[i][j] =sum;
        }
    }

    int m;
    cin>>m;
    //int question[m][3];

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[x-1][y-1]<<endl;
        }else if(q==2){
            cout<<answerForB[x-1][y-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    int a[n];
    int pos[n]= {0};

    int totalAns  = 0;
    for(int i=0; i<n; ++i){
        int sum =0;
        sum += n-i;

        totalAns += sum;
        if(i==0){
            pos[i] = 0;
        }else{
            pos[i] = totalAns - sum;
        }
    }

    for(int i=0; i<n; ++i){
        cin>>a[i];
    }

    int answerForA[totalAns]={0};
    int answerForB[totalAns]={0};
    int indexAns=0;
    for(int i=0;i<n;++i){
        int sum = 0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForA[indexAns] = sum;
            ++indexAns;
        }

    }

    mergeSort(a,0,n-1);
    indexAns=0;
    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForB[indexAns] = sum;
            ++indexAns;
        }
    }

    int m;
    cin>>m;

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[pos[x-1]+y-x]<<endl;
        }else if(q==2){
            cout<<answerForB[pos[x-1]+y-x]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

void merge(long long  arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    long long int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long  arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    long long int a[n], b[n];
    for(int i=0; i<n; ++i){
        cin>>a[i];
        b[i] = a[i];
    }

    mergeSort(b,0,n-1);

    long long int answerForA[n][n]={0};
    long long int answerForB[n][n]={0};

    int m;
    cin>>m;
    //int question[m][3];

    for(int i=0;i<n;++i){
        int sumA=0;
        int sumB=0;
        for(int j=i;j<n;++j){
            sumA += a[j];
            sumB += b[j];
            answerForA[i][j] =sumA;
            answerForB[i][j] =sumB;
        }
    }

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[x-1][y-1]<<endl;
        }else if(q==2){
            cout<<answerForB[x-1][y-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

void swap(long long int* a, long long int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

int partition (long long int arr[], int low, int high)
{
    int pivot = arr[high];    // pivot
    int i = (low - 1);  // Index of smaller element

    for (int j = low; j <= high- 1; j++)
    {
        // If current element is smaller than or
        // equal to pivot
        if (arr[j] <= pivot)
        {
            i++;    // increment index of smaller element
            swap(&arr[i], &arr[j]);
        }
    }
    swap(&arr[i + 1], &arr[high]);
    return (i + 1);
}

/* The main function that implements QuickSort
 arr[] --> Array to be sorted,
  low  --> Starting index,
  high  --> Ending index */
void quickSort(long long int arr[], int low, int high)
{
    if (low < high)
    {
        /* pi is partitioning index, arr[p] is now
           at right place */
        int pi = partition(arr, low, high);

        // Separately sort elements before
        // partition and after partition
        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}

int main(){
    int n;
    cin>>n;
    long long int a[n];
    for(int i=0; i<n; ++i){
        cin>>a[i];
    }

    long long int answerForA[n][n]={0};
    long long int answerForB[n][n]={0};

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForA[i][j] =sum;
        }
    }

    quickSort(a,0,n-1);

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForB[i][j] =sum;
        }
    }

    int m;
    cin>>m;
    //int question[m][3];

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[x-1][y-1]<<endl;
        }else if(q==2){
            cout<<answerForB[x-1][y-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    int a[n], b[n];
    for(int i=0; i<n; ++i){
        cin>>a[i];
        b[i] = a[i];
    }

    mergeSort(b,0,n-1);

    int answerForA[n][n]={0};
    int answerForB[n][n]={0};

    int m;
    cin>>m;
    int question[m][3];

    for(int i=0;i<n;++i){
        int sumA=0;
        int sumB=0;
        for(int j=i;j<n;++j){
            sumA += a[j];
            sumB += b[j];
            answerForA[i][j] =sumA;
            answerForB[i][j] =sumB;
        }
    }

    for(int i=0;i<m;++i){
        cin>>question[i][0]>>question[i][1]>>question[i][2];
    }

    for(int i=0;i<m;++i){
        if(question[i][0]==1){
            cout<<answerForA[question[i][1]-1][question[i][2]-1]<<endl;
        }else if(question[i][0]==2){
            cout<<answerForB[question[i][1]-1][question[i][2]-1]<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    int a[n], b[n];
    for(int i=0; i<n; ++i){
        cin>>a[i];
        b[i] = a[i];
    }

    mergeSort(b,0,n-1);

    int answerForA[n][n]={0};
    int answerForB[n][n]={0};

    int m;
    cin>>m;
    //int question[m][3];

    for(int i=0;i<n;++i){
        int sumA=0;
        int sumB=0;
        for(int j=i;j<n;++j){
            sumA += a[j];
            sumB += b[j];
            answerForA[i][j] =sumA;
            answerForB[i][j] =sumB;
        }
    }

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[x-1][y-1]<<endl;
        }else if(q==2){
            cout<<answerForB[x-1][y-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(long long int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    long long int a[n+1] = {0};
    long long int b[n+1] = {0};

    for(int i=1; i<=n; ++i){
        cin>>a[i];
        b[i] = a[i];
        if(i>0){
            b[i] += b[i-1];
        }
    }

    mergeSort(a,0,n);
    for(int i=1;i<=n;++i){
        a[i] += a[i-1];
    }

    int m;
    cin>>m;

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        long long int sum;
        if(q==1){
            //cout<<b[y-1]<<" "<<b[x-1]<<endl;
            sum = b[y]-b[x-1];
            cout<<sum<<endl;
        }else if(q==2){
            //cout<<a[y-1]<<" "<<a[x-1]<<endl;
            sum = a[y]-a[x-1];
            cout<<sum<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    int a[n];
    int pos[n]= {0};

    int totalAns  = 0;
    for(int i=0; i<n; ++i){
        int sum =0;
        sum += n-i;

        totalAns += sum;
        if(i==0){
            pos[i] = 0;
        }else{
            pos[i] = totalAns - sum;
        }
    }

    for(int i=0; i<n; ++i){
        cin>>a[i];
    }

    int answerForA[totalAns]={0};
    int answerForB[totalAns]={0};
    int indexAns=0;
    for(int i=0;i<n;++i){
        int sum = 0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForA[indexAns] = sum;
            ++indexAns;
        }

    }

    mergeSort(a,0,n-1);
    indexAns=0;
    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForB[indexAns] = sum;
            ++indexAns;
        }
    }

    int m;
    cin>>m;

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[pos[x-1]+y x]<<endl;
        }else if(q==2){
            cout<<answerForB[pos[x-1]+y-x]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    int a[n];
    int b[n];

    for(int i=0; i<n; ++i){
        int temp;
        cin>>temp;
        a[i] = b[i] = temp;
    }

    mergeSort(b,0,n-1);

    int m;
    cin>>m;

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            int sum =0;
            for(int i=x-1;i<=y-1;++i){
                sum += a[i];
            }
            cout<<sum<<endl;
        }else if(q==2){
            int sum =0;
            for(int i=x-1;i<=y-1;++i){
                sum += b[i];
            }
            cout<<sum<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    int a[n];
    int b[n];

    for(int i=0; i<n; ++i){
        int temp;
        cin>>temp;
        a[i] = b[i] = temp;
    }

    mergeSort(b,0,n-1);

    int m;
    cin>>m;

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        long long int sum =0;
        if(q==1){
            for(int i=x-1;i<=y-1;++i){
                sum += a[i];
            }
            cout<<sum<<endl;
        }else if(q==2){
            for(int i=x-1;i<=y-1;++i){
                sum += b[i];
            }
            cout<<sum<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; ++i){
        cin>>a[i];
    }

    int answerForA[n][n]={0};
    int answerForB[n][n]={0};

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForA[i][j] =sum;
        }
    }

    sort(a, a + n);

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForB[i][j] =sum;
        }
    }

    int m;
    cin>>m;
    //int question[m][3];

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[x-1][y-1]<<endl;
        }else if(q==2){
            cout<<answerForB[x-1][y-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    long long int a[n];
    for(int i=0; i<n; ++i){
        cin>>a[i];
    }

    long long int answerForA[n][n]={0};
    long long int answerForB[n][n]={0};

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForA[i][j] =sum;
        }
    }

    sort(a, a + n);

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForB[i][j] =sum;
        }
    }

    int m;
    cin>>m;
    //int question[m][3];

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[x-1][y-1]<<endl;
        }else if(q==2){
            cout<<answerForB[x-1][y-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

void merge(long long  arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    long long int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long  arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main(){
    int n;
    cin>>n;
    long long int a[n];
    for(int i=0; i<n; ++i){
        cin>>a[i];
    }

    long long int answerForA[n][n]={0};
    long long int answerForB[n][n]={0};

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForA[i][j] =sum;
        }
    }

    mergeSort(a,0,n-1);

    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForB[i][j] =sum;
        }
    }

    int m;
    cin>>m;
    //int question[m][3];

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[x-1][y-1]<<endl;
        }else if(q==2){
            cout<<answerForB[x-1][y-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    int pos[n]= {0};

    int totalAns  = 0;
    for(int i=0; i<n; ++i){
        int sum =0;
        sum += n-i;

        totalAns += sum;
        if(i==0){
            pos[i] = 0;
        }else{
            pos[i] = totalAns - sum;
        }
    }

    for(int i=0; i<n; ++i){
        cin>>a[i];
    }

    int answerForA[totalAns]={0};
    int answerForB[totalAns]={0};
    int indexAns=0;
    for(int i=0;i<n;++i){
        int sum = 0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForA[indexAns] = sum;
            ++indexAns;
        }

    }

    sort(a, a + n);
    indexAns=0;
    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=i;j<n;++j){
            sum += a[j];
            answerForB[indexAns] = sum;
            ++indexAns;
        }
    }

    int m;
    cin>>m;

    for(int i=0;i<m;++i){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==1){
            cout<<answerForA[pos[x-1]+y-x]<<endl;
        }else if(q==2){
            cout<<answerForB[pos[x-1]+y-x]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[200000],sumv[200000],sumu[200000];
  sumu[0]=0;sumv[0]=0;
     for(int i=1; i<=n; i++)
    {
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
    sort(v,v+n+1);
   for(int i=1; i<=n; i++)
    {
        sumu[i] = sumu[i-1] + v[i];
    }
    int m;
cin>>m;
  for(int i=0;i<m;i++){
    int l,r,type;
    cin>>type>>l>>r;
    long ans;
    if(type==1)
       ans=sumv[r]-sumv[l-1];
    else
        ans=sumu[r]-sumu[l-1];
    cout<<ans<<endl;
  }
 return 0;
 }


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[n+1],sumv[n+1],sumu[n+1];
  sumu[0]=0;sumv[0]=0;
     for(long long i=1; i<=n; i++){
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
sort(v+1,v+n+1);
   for(long long i=1; i<=n; i++){
        sumu[i] = sumu[i-1] + v[i];
    }
long long m;
cin>>m;
  for(long long i=0;i<m;i++){
    int type;
    long long l,r;
    cin>>type>>l>>r;
    if(type==1)
       cout<<sumv[r]-sumv[l-1]<<endl;
    else
        cout<<sumu[r]-sumu[l-1]<<endl;
  }
 return 0;
 }


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[100000],sumv[100000],sumu[100000];
  sumu[0]=0;sumv[0]=0;
     for(int i=1; i<=n; i++)
    {
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
    sort(v+1,v+n+1);
   for(int i=1; i<=n; i++)
    {
        sumu[i] = sumu[i-1] + v[i];
    }
    int m;
cin>>m;
  for(int i=0;i<m;i++){
    int l,r,type;
    cin>>type>>l>>r;
    long ans;
    if(type==1)
       ans=sumv[r]-sumv[l-1];
    else
        ans=sumu[r]-sumu[l-1];
    cout<<ans<<endl;
  }
 return 0;
 }


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[n+1],sumv[n+1],sumu[n+1];
  sumu[0]=0;sumv[0]=0;
     for(long long i=1; i<=n; i++){
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
sort(v+1,v+n+1);
   for(long long i=1; i<=n; i++){
        sumu[i] = sumu[i-1] + v[i];
    }
long long m;
cin>>m;
  for(long long i=0;i<m;i++){
    int type;
    long long l,r;
    cin>>type>>l>>r;
    if(type==1)
       cout<<sumv[r]-sumv[l-1]<<endl;
    else
        cout<<ans=sumu[r]-sumu[l-1]<<endl;
  }
 return 0;
 }


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[n],sumv[n],sumu[n];
     for(int i=1; i<=n; i++)
    {
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
    sort(v+1,v+n+1);
   for(int i=1; i<=n; i++)
    {
        sumu[i] = sumu[i-1] + v[i];
    }
    int m;
cin>>m;
  for(int i=0;i<m;i++){
    int l,r,type;
    cin>>type>>l>>r;
    long ans;
    if(type==1)
       ans=sumv[r]-sumv[l-1];
    else
        ans=sumu[r]-sumu[l-1];
    cout<<ans<<endl;
  }
 return 0;
 }


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[n+1],sumv[n+1],sumu[n+1];
  sumu[0]=0;sumv[0]=0;
     for(int i=1; i<=n; i++)
    {
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
    sort(v+1,v+n+1);
   for(int i=1; i<=n; i++)
    {
        sumu[i] = sumu[i-1] + v[i];
    }
    int m;
cin>>m;
  for(int i=0;i<m;i++){
    int l,r,type;
    cin>>type>>l>>r;
    long ans;
    if(type==1)
       ans=sumv[r]-sumv[l-1];
    else
        ans=sumu[r]-sumu[l-1];
    cout<<ans<<endl;
  }
 return 0;
 }


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[n+1],sumv[n+1],sumu[n+1];
  sumu[0]=0;sumv[0]=0;
     for(int i=1; i<=n; i++){
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
sort(v+1,v+n+1);
   for(int i=1; i<=n; i++){
        sumu[i] = sumu[i-1] + v[i];
    }
int m;
cin>>m;
  for(int i=0;i<m;i++){
    int l,r,type;
    cin>>type>>l>>r;
    long ans;
    if(type==1)
       ans=sumv[r]-sumv[l-1];
    else
        ans=sumu[r]-sumu[l-1];
    cout<<ans<<endl;
  }
 return 0;
 }


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[n+1],sumv[n+1],sumu[n+1];
  sumu[0]=0;sumv[0]=0;
     for(int i=1; i<=n; i++){
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
sort(v,v+n+1);
   for(int i=1; i<=n; i++){
        sumu[i] = sumu[i-1] + v[i];
    }
int m;
cin>>m;
  for(int i=0;i<m;i++){
    int l,r,type;
    cin>>type>>l>>r;
    long ans;
    if(type==1)
       ans=sumv[r]-sumv[l-1];
    else
        ans=sumu[r]-sumu[l-1];
    cout<<ans<<endl;
  }
 return 0;
 }


#include <bits/stdc++.h>
using namespace std;

 int main(){

  long long n;
  cin>>n;
  long long v[100001],sumv[100001],sumu[100001];
  sumu[0]=0;sumv[0]=0;
     for(int i=1; i<=n; i++){
        cin >> v[i];
        sumv[i] = sumv[i-1] + v[i];
    }
sort(v,v+n+1);
   for(int i=1; i<=n; i++){
        sumu[i] = sumu[i-1] + v[i];
    }
int m;
cin>>m;
  for(int i=0;i<m;i++){
    int l,r,type;
    cin>>type>>l>>r;
    long ans;
    if(type==1)
       ans=sumv[r]-sumv[l-1];
    else
        ans=sumu[r]-sumu[l-1];
    cout<<ans<<endl;
  }
 return 0;
 }


#include <iostream>
#include <algorithm>
using namespace std;
long long a[100806],b[100086];
int main()
{
    int t;
    cin>>t;
    b[0] = 0;
    for(int i=1; i<=t; i++)
    {
        cin>>a[i];
        b[i] = a[i]+b[i-1];
    }
    sort(a,a+t+1);
    for(int i=2; i<=t; i++)
        a[i] = a[i]+a[i-1];
    int n;
    cin>>n;
    while(n--)
    {
        int type, l,r;
        cin>>type>>l>>r;
        type==1?
            l==1 ? type = b[r]:
                       type = b[r]-b[l-1]:
            l == 1 ? type = a[r]:
                         type = a[r]-a[l-1];
        cout<<type<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long x[100000],y[100000];
int main()
{
    int m;
    cin>>m;
    y[0]=0;
    for(int i=1; i<=m; i++)
    {
        cin>>x[i];
        y[i]=x[i]+y[i-1];
    }
    sort(x,x+m+1);
    for(int i=2; i<=m; i++)
    {
        x[i]=x[i]+x[i-1];
    }
    int k;
    cin>>k;
    for(int j=0; j<k; j++)
    {
       long long t,l,r;
        cin>>t>>l>>r;
        if(t==1)
        {
            long long sum =0;
            if(l==1)
                sum = y[r];
            else
                sum = y[r]-y[l-1];
                cout<<sum<<endl;
        }
        else
        {
            long long sum = 0;
            if(l==1)
                sum = x[r];
            else
                sum = x[r]-x[l-1];
                cout<<sum<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[100806],b[100086];
int main()
{
    int t;
    cin>>t;
    b[0] = 0;
    for(int i=1; i<=t; i++)
    {
        cin>>a[i];
        b[i] = a[i]+b[i-1];
    }
    sort(a,a+t+1);
    for(int i=2; i<=t; i++)
        a[i] = a[i]+a[i-1];
    int n;
    cin>>n;
    while(n--)
    {
       long long type, l,r;
        cin>>type>>l>>r;
        type==1?
            l==1 ? type = b[r]:
                       type = b[r]-b[l-1]:
            l == 1 ? type = a[r]:
                         type = a[r]-a[l-1];
        cout<<type<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[100806],b[100086];
int main()
{
    int t;
    cin>>t;
    b[0] = 0;
    for(int i=1; i<=t; i++)
    {
        cin>>a[i];
        b[i] = a[i]+b[i-1];
    }
  sort(a,a+t+1);
  int n;
  cin>>n;
    while(n--)
    {
        int type, l,r;
        cin>>type>>l>>r;
        if(type==1)
        {
            if(l==1)
                cout<<b[r]<<endl;
            else
                cout<<b[r]-b[l-1]<<endl;
        }
        else
        {
           long long  sum = 0;
            for(int i = l ; i <=r; i++)
                sum+=a[i];
            cout<<sum<<endl;
        }
    }

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long x[1000000],y[1000000];
int main()
{
    int m;
    cin>>m;
    y[0]=0;
    for(int i=1; i<=m; i++)
    {
        cin>>x[i];
        y[i]=x[i]+y[i-1];
    }
    sort(x,x+m+1);
    for(int i=2; i<=m; i++)
    {
        x[i]=x[i]+x[i-1];
    }
    long long  k;
    cin>>k;
    while(k--)
    {
       long long t,l,r;
        cin>>t>>l>>r;
        if(t==1)
        {
            if(l==1)
                t = y[r];
            else
                t = y[r]-y[l-1];
        }
        else
        {
            if(l==1)
                t = x[r];
            else
                t = x[r]-x[l-1];
        }
        cout<<t<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long x[1000000],y[1000000];
int main()
{
    int m;
    cin>>m;
    y[0]=0;
    for(int i=1; i<=m; i++)
    {
        cin>>x[i];
        y[i]=x[i]+y[i-1];
    }
    sort(x,x+m+1);
    for(int i=2; i<=m; i++)
    {
        x[i]=x[i]+x[i-1];
    }
    int k;
    cin>>k;
    for(int j=0; j<k; j++)
    {
       long long t,l,r;
        cin>>t>>l>>r;
        if(t==1)
        {
            long long sum =0;
            if(l==1)
                sum = y[r];
            else
                sum = y[r]-y[l-1];
                cout<<sum<<endl;
        }
        else
        {
            long long sum = 0;
            if(l==1)
                sum = x[r];
            else
                sum = x[r]-x[l-1];
                cout<<sum<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[100806],b[100086];
int main()
{
    int t;
    cin>>t;
    b[0] = 0;
    for(int i=1; i<=t; i++)
    {
        cin>>a[i];
        b[i] = a[i]+b[i-1];
    }
  sort(a,a+t+1);
  int n;
  cin>>n;
    while(n--)
    {
        int type, l,r;
        cin>>type>>l>>r;
        if(type==1)
        {
            if(l==1)
                cout<<b[r]<<endl;
            else
                cout<<b[r]-b[l-1]<<endl;
        }
        else
        {
            int sum = 0;
            for(int i = l ; i <=r; i++)
                sum+=a[i];
            cout<<sum<<endl;
        }
    }

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long x[100000],y[100000];
int main()
{
    int m;
    cin>>m;
    y[0]=0;
    for(int i=1; i<=m; i++)
    {
        cin>>x[i];
        y[i]=x[i]+y[i-1];
    }
    sort(x,x+m+1);
    for(int i=2; i<=m; i++)
    {
        x[i]=x[i]+x[i-1];
    }
    long long  k;
    cin>>k;
    while(k--)
    {

       long long t,l,r;
        cin>>t>>l>>r;
        if(t==1)
        {
            long long sum =0;
            if(l==1)
                sum = y[r];
            else
                sum = y[r]-y[l-1];
                cout<<sum<<endl;
        }
        else
        {
            long long sum = 0;
            if(l==1)
                sum = x[r];
            else
                sum = x[r]-x[l-1];
                cout<<sum<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long x[100000],y[100000];
int main()
{
    int m;
    cin>>m;
    y[0]=0;
    for(int i=1; i<=m; i++)
    {
        cin>>x[i];
        y[i]=x[i]+y[i-1];
    }
    sort(x,x+m+1);
    for(int i=2; i<=m; i++)
    {
        x[i]=x[i]+x[i-1];
    }
    long long  k;
    cin>>k;
    while(k--)
    {
       long long t,l,r;
        cin>>t>>l>>r;
        if(t==1)
        {
            if(l==1)
                t = y[r];
            else
                t = y[r]-y[l-1];
        }
        else
        {
            if(l==1)
                t = x[r];
            else
                t = x[r]-x[l-1];
        }
        cout<<t<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    ll arr[n+7],brr[n+7];

    for(int i=1; i<=n; i++){
        scanf("%lld",&arr[i]);
        brr[i]=arr[i];
        arr[i]=arr[i]+arr[i-1];
    }
    //int len=sizeof(brr)/sizeof(brr[0]);
    //cout<<len<<endl;
    sort(brr+1, brr+n+1);

    for(int i=1; i<=n; i++){
        brr[i]+=brr[i-1];
    }

    int x;
    scanf("%d",&x);
    while(x--){
        int a,b,c;
        scanf("%d %d %d",&a, &b, &c);

        if(a==2) printf("%lld\n",(brr[c]-brr[b-1]));
        else printf("%lld\n",(arr[c]-arr[b-1]));
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n+7],brr[n+7];

    for(int i=1; i<=n; i++){
        scanf("%d",&arr[i]);
        brr[i]=arr[i];
        arr[i]=arr[i]+arr[i-1];
    }
    //int len=sizeof(brr)/sizeof(brr[0]);
    //cout<<len<<endl;
    sort(brr+1, brr+n+1);

    for(int i=1; i<=n; i++){
        brr[i]+=brr[i-1];
    }

    int x;
    scanf("%d",&x);
    while(x--){
        int a,b,c;
        scanf("%d %d %d",&a, &b, &c);

        if(a==2) printf("%d\n",(brr[c]-brr[b-1]));
        else printf("%d\n",(arr[c]-arr[b-1]));
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n],brr[n];

    for(int i=0; i<n; i++){
        scanf("%d",&arr[i]);
        brr[i]=arr[i];
    }
    int len=sizeof(brr)/sizeof(brr[0]);
    //cout<<len<<endl;
    sort(brr, brr+len);

    for(int i=1; i<n; i++){
        brr[i]=brr[i]+brr[i-1];
    }

    for(int i=1; i<n; i++){
        arr[i]=arr[i]+arr[i-1];
    }

    int x;
    scanf("%d",&x);
    while(x--){
        int a,b,c;
        scanf("%d %d %d",&a, &b, &c);

        int ans=0;
        if(b>1) ans=arr[b-2];
        else ans=0;

        int ans1=0;
        if(b>1) ans1=brr[b-2];
        else ans1=0;

        if(a==2) printf("%d\n",(brr[c-1]-ans1));
        else printf("%d\n",(arr[c-1]-ans));
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n],brr[n];

    for(int i=0; i<n; i++){
        scanf("%d",&arr[i]);
        brr[i]=arr[i];
    }
    int len=sizeof(brr)/sizeof(brr[0]);
    //cout<<len<<endl;
    sort(brr, brr+len);

    for(int i=1; i<n; i++){
        brr[i]=brr[i]+brr[i-1];
    }

    for(int i=1; i<n; i++){
        arr[i]=arr[i]+arr[i-1];
    }

    for(int i=0; i<len; i++){
        cout<<brr[i]<< " ";
    }

    int x;
    scanf("%d",&x);
    while(x--){
        int a,b,c;
        scanf("%d %d %d",&a, &b, &c);

        int ans=arr[b-2];
        if(ans>arr[len-1]) ans=0;
        int ans1=brr[b-2];
        if(ans1>brr[len-1]) ans1=0;

        if(a==2) printf("%d\n",(brr[c-1]-ans1));
        else printf("%d\n",(arr[c-1]-ans));
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n],brr[n];

    for(int i=0; i<n; i++){
        scanf("%d",&arr[i]);
        brr[i]=arr[i];
    }
    int len=sizeof(brr)/sizeof(brr[0]);
    //cout<<len<<endl;
    sort(brr, brr+len);

    for(int i=1; i<n; i++){
        brr[i]+=brr[i-1];
    }

    for(int i=1; i<n; i++){
        arr[i]+=arr[i-1];
    }

    int x;
    scanf("%d",&x);
    while(x--){
        int a,b,c;
        scanf("%d %d %d",&a, &b, &c);

        int ans=0;
        if(b>1) ans=arr[b-2];
        else ans=0;

        int ans1=0;
        if(b>1) ans1=brr[b-2];
        else ans1=0;

        if(a==2) printf("%d\n",(brr[c-1]-ans1));
        else printf("%d\n",(arr[c-1]-ans));
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n],brr[n];

    for(int i=0; i<n; i++){
        scanf("%d",&arr[i]);
        brr[i]=arr[i];
    }
    int len=sizeof(brr)/sizeof(brr[0]);
    //cout<<len<<endl;
    sort(brr, brr+len);

    for(int i=1; i<n; i++){
        brr[i]=brr[i]+brr[i-1];
    }

    for(int i=1; i<n; i++){
        arr[i]=arr[i]+arr[i-1];
    }

    for(int i=0; i<len; i++){
        cout<<brr[i]<< " ";
    }

    int x;
    scanf("%d",&x);
    while(x--){
        int a,b,c;
        scanf("%d %d %d",&a, &b, &c);

        int ans=0;
        if(b>1) ans=arr[b-2];
        else ans=0;

        int ans1=0;
        if(b>1) ans1=brr[b-2];
        else ans1=0;

        if(a==2) printf("%d\n",(brr[c-1]-ans1));
        else printf("%d\n",(arr[c-1]-ans));
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n],brr[n];

    for(int i=0; i<n; i++){
        scanf("%d",&arr[i]);
        brr[i]=arr[i];
    }
    int len=sizeof(brr)/sizeof(brr[0]);
    //cout<<len<<endl;
    sort(brr, brr+len);

    for(int i=1; i<n; i++){
        brr[i]=brr[i]+brr[i-1];
    }

    for(int i=1; i<n; i++){
        arr[i]=arr[i]+arr[i-1];
    }

    for(int i=0; i<len; i++){
        cout<<brr[i]<< " ";
    }

    int x;
    scanf("%d",&x);
    while(x--){
        int a,b,c;
        scanf("%d %d %d",&a, &b, &c);

        int ans=0;
        ans=arr[b-2];
        if(ans>arr[len-1]) ans=0;
        int ans1=0;
        ans1=brr[b-2];
        if(ans1>brr[len-1]) ans1=0;

        if(a==2) printf("%d\n",(brr[c-1]-ans1));
        else printf("%d\n",(arr[c-1]-ans));
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n+7],brr[n+7];

    for(int i=1; i<=n; i++){
        scanf("%d",&arr[i]);
        brr[i]=arr[i];
        arr[i]+=arr[i-1];
    }
    //int len=sizeof(brr)/sizeof(brr[0]);
    //cout<<len<<endl;
    sort(brr+1, brr+n+1);

    for(int i=1; i<=n; i++){
        brr[i]+=brr[i-1];
    }

    int x;
    scanf("%d",&x);
    while(x--){
        int a,b,c;
        scanf("%d %d %d",&a, &b, &c);

        if(a==2) printf("%d\n",(brr[c]-brr[b-1]));
        else printf("%d\n",(arr[c]-arr[b-1]));
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int i,j,n,m,t,p=1,sum[105000],l,r,type,sun[105000],getsum[105000]={0},getarr[1000020]={0},s;
long long int getsu(long long int i){
 if(i==0) return sum[0];
 if(getsum[i]!=0) return getsum[i];
 return getsum[i]=getsu(i-1)+sum[i];
}
long long int getsun(long long int i){
 if(i==0) return sun[0];
 if(getarr[i]!=0) return getarr[i];
 return getarr[i]=getsun(i-1)+sun[i];
}

int main(){
scanf("%lld",&t);
    for(i=0;i<t;i++)
    {scanf("%lld",&sum[i]);
    sun[i]=sum[i];}
    getsu(t-1);
    getsum[0]=sum[0];
    sort(sun,sun+t);
    getsun(t-1);
    getarr[0]=sun[0];
    scanf("%lld",&m);
   // for(i=0;i<t;i++)
       // printf("..%lld...%lld\n",getsum[i],getarr[i]);

    while(m){
            scanf("%lld%lld%lld",&type,&l,&r);
            s=0;
            if(type==1){
            s=-getsum[l-2]+getsum[r-1];
        }
            else {
               s=-getarr[l-2]+getarr[r-1];//+sun[l-1];

        }
            printf("%lld\n",s);

    m--;
    }

return 0;

}


#include<bits/stdc++.h>
using namespace std;
long long int i,j,n,m,t,p=1,sum[120000],l,r,type,sun[150000],s;
int main(){
scanf("%lld",&t);
    for(i=0;i<t;i++)
    {scanf("%lld",&sum[i]);
    sun[i]=sum[i];}
    scanf("%lld",&m);
    sort(sun,sun+t);
    while(m){
            scanf("%lld%lld%lld",&type,&l,&r);s=0;
            if(type==1){
            for(i=l-1;i<=r-1;i++){
                s=s+sum[i];
            }}
            else {
                for(i=l-1;i<=r-1;i++){
                s=s+sun[i];
            }
            }
            printf("%lld\n",s);

    m--;
    }

return 0;

}


#include<bits/stdc++.h>
using namespace std;
long long int i,j,n,m,t,p=1,sum[12000],l,r,type,sun[15000],s;
int main(){
scanf("%lld",&t);
    for(i=0;i<t;i++)
    {scanf("%lld",&sum[i]);
    sun[i]=sum[i];}
    scanf("%lld",&m);
    sort(sun,sun+t);
    while(p<=m){
            scanf("%lld%lld%lld",&type,&l,&r);s=0;
            if(type==1){
            for(i=l-1;i<=r-1;i++){
                s=s+sum[i];
            }}
            else {
                for(i=l-1;i<=r-1;i++){
                s=s+sun[i];
            }
            }
            printf("%lld\n",s);

    p++;
    }

return 0;

}


#include<bits/stdc++.h>
using namespace std;
long long unsigned i,j,n,m,t,p=1,sum[105000],l,r,type,sun[105000],s;
int main(){
scanf("%llu",&t);
    for(i=0;i<t;i++)
    {scanf("%llu",&sum[i]);
    sun[i]=sum[i];}
    scanf("%llu",&m);
    sort(sun,sun+t);
    while(m){
            scanf("%llu%llu%llu",&type,&l,&r);
            s=0;
            if(type==1){
            for(i=l-1;i<=r-1;i++){
                s=s+sum[i];
            }
        }
            else {
                for(i=l-1;i<=r-1;i++){
                s=s+sun[i];
            }
        }
            printf("%llu\n",s);

    m--;
    }

return 0;

}


#include<bits/stdc++.h>
using namespace std;
long long int i,j,n,m,t,p=1,sum[105000],l,r,type,sun[105000],getsum[105000]={0},getarr[1000020]={0},s;
long long int getsu(long long int i){
 if(i==0) return getsum[0]=sum[0];
 if(getsum[i]!=0) return getsum[i];
 return getsum[i]=getsu(i-1)+sum[i];
}
long long int getsun(long long int i){
 if(i==0) return getarr[0]=sun[0];
 if(getarr[i]!=0) return getarr[i];
 return getarr[i]=getsun(i-1)+sun[i];
}

int main(){
scanf("%lld",&t);
    for(i=0;i<t;i++)
    {scanf("%lld",&sum[i]);
    sun[i]=sum[i];}
    getsu(t-1);
  //  getsum[0]=sum[0];
    sort(sun,sun+t);
    getsun(t-1);
    //getarr[0]=sun[0];
    scanf("%lld",&m);
   // for(i=0;i<t;i++)
       // printf("..%lld...%lld\n",getsum[i],getarr[i]);

    while(m){
            scanf("%lld%lld%lld",&type,&l,&r);
            s=0;
            if(type==1){
            s=-getsum[l-2]+getsum[r-1];
        }
            else {
               s=-getarr[l-2]+getarr[r-1];//+sun[l-1];

        }
            printf("%lld\n",s);

    m--;
    }

return 0;

}


#include<bits/stdc++.h>
using namespace std;
long long int i,j,n,m,t,p=1,sum[105000],l,r,type,sun[105000],getsum[105000]={0},getarr[1000020]={0},s;
long long int getsu(long long int i){
 if(i==0) return getsum[0]=sum[0];
 if(getsum[i]!=0) return getsum[i];
 return getsum[i]=getsu(i-1)+sum[i];
}
long long int getsun(long long int i){
 if(i==0) return getarr[0]=sun[0];
 if(getarr[i]!=0) return getarr[i];
 return getarr[i]=getsun(i-1)+sun[i];
}

int main(){
scanf("%lld",&t);
    for(i=0;i<t;i++)
    {scanf("%lld",&sum[i]);
    sun[i]=sum[i];}
    getsu(t-1);

    sort(sun,sun+t);
    getsun(t-1);
    //getarr[0]=sun[0];
    scanf("%lld",&m);
   // for(i=0;i<t;i++)
       // printf("..%lld...%lld\n",getsum[i],getarr[i]);

    while(m){
            scanf("%lld%lld%lld",&type,&l,&r);
            s=0;
            if(type==1){
            s=-getsum[l-2]+getsum[r-1];
        }
            else {
               s=-getarr[l-2]+getarr[r-1];//+sun[l-1];

        }
            printf("%lld\n",s);

    m--;
    }

return 0;

}


#include<bits/stdc++.h>
using namespace std;
long long int i,j,n,m,t,p=1,sum[105000],l,r,type,sun[105000],s;
int main(){
scanf("%lld",&t);
    for(i=0;i<t;i++)
    {scanf("%lld",&sum[i]);
    sun[i]=sum[i];}
    scanf("%lld",&m);
    sort(sun,sun+t);
    while(m){
            scanf("%lld%lld%lld",&type,&l,&r);
            s=0;
            if(type==1){
            for(i=l-1;i<=r-1;i++){
                s=s+sum[i];
            }
        }
            else {
                for(i=l-1;i<=r-1;i++){
                s=s+sun[i];
            }
        }
            printf("%lld\n",s);

    m--;
    }

return 0;

}


#include<bits/stdc++.h>
using namespace std;
long long int i,j,n,m,t,p=1,sum[12000],l,r,type,sun[15000],s;
int main(){
scanf("%lld",&t);
    for(i=0;i<t;i++)
    {scanf("%lld",&sum[i]);
    sun[i]=sum[i];}
    scanf("%lld",&m);
    sort(sun,sun+t);
    while(m){
            scanf("%lld%lld%lld",&type,&l,&r);s=0;
            if(type==1){
            for(i=l-1;i<=r-1;i++){
                s=s+sum[i];
            }}
            else {
                for(i=l-1;i<=r-1;i++){
                s=s+sun[i];
            }
            }
            printf("%lld\n",s);

    m--;
    }

return 0;

}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <sstream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	long long v[n+1];
	long long a[n+1][n+1];
	long long b[n+1][n+1];
	for(int i = 1; i<=n; i++)
		cin >> v[i];
	cin >> m;
	for(int i = 1; i<=n; i++){
		long long sum = v[i];
		for(int j = i; j<=n; j++){
			if(i!=j)
				sum += v[j];
			a[i][j] = sum;
		}
	}
	sort(v+1,v+(n+1));
	for(int i = 1; i<=n; i++){
		long long sum = v[i];
		for(int j = i; j<=n; j++){
			if(i!=j)
				sum += v[j];
			b[i][j] = sum;
		}
	}
	long long ans[m];
	int k = 0,x,y,z;
	for(int i = 1; i<=m; i++){
		cin >> x >> y >> z;
		if(x==1)
			ans[k] = a[y][z];
		else
			ans[k] = b[y][z];
		k++;
	}
	for(int i = 0; i<k; i++)
		cout << ans[i] << '\n';
	return 0;
}


#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define ll long long
#define re return
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int>v(n+1);
	vector<int>t1(n+1);
	vector<int>t2(n+1);
	for(int i = 1; i<=n; i++)
		cin >> v[i];
	for(int i = 1; i<=n; i++)
		t1[i] = t1[i-1]+v[i];
	sort(all(v));
	for(int i = 1; i<=n; i++)
		t2[i] = t2[i-1]+v[i];
	int m,type,l,r;
	cin >> m;
	vector<int>ans(m);
	for(int i = 0; i<m; i++){
		cin >> type >> l >> r;
		ans[i] = (type == 1) ? t1[r]-t1[l-1] : t2[r]-t2[l-1];
	}
	for(int i : ans)
		cout << i << '\n';
    re 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <sstream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	long long v[n+1];
	long long a[n+1][n+1];
	long long b[n+1][n+1];
	for(int i = 1; i<=n; i++)
		cin >> v[i];
	cin >> m;
	for(int i = 1; i<=n; i++){
		long long sum = v[i];
		for(int j = i; j<=n; j++){
			if(i!=j)
				sum += v[j];
			a[i][j] = sum;
		}
	}
	sort(v+1,v+(n+1));
	for(int i = 1; i<=n; i++){
		long long sum = v[i];
		for(int j = i; j<=n; j++){
			if(i!=j)
				sum += v[j];
			b[i][j] = sum;
		}
	}
	long long ans[m+1];
	int k = 0,x,y,z;
	for(int i = 1; i<=m; i++){
		cin >> x >> y >> z;
		if(x==1)
			ans[k] = a[y][z];
		else
			ans[k] = b[y][z];
		k++;
	}
	for(int i = 0; i<k; i++)
		cout << ans[i] << '\n';
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <sstream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	long long v[n+1];
	long long v2[n+1];
	for(int i = 1; i<=n; i++){
		cin >> v[i];
		v2[i] = v[i];
	}
	sort(v2+1,v2+(n+1));
	cin >> m;
	long long ans[m+1];
	int k = 0,x,y,z;
	for(int i = 1; i<=m; i++){
		cin >> x >> y >> z;
		long long sum = 0;
		if(x==1)
			for(int a = y; a<=z; a++)
				sum += v[a];
		else
			for(int a = y; a<=z; a++)
				sum += v2[a];
		ans[k] = sum;
		k++;
	}
	for(int i = 0; i<k; i++)
		cout << ans[i] << '\n';
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <sstream>
using namespace std;
int main() {
	int n, m;
	cin >> n;
	vector <long long> v(n + 1);
	vector <long long> v2(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		v2[i] = v[i];
	}
	sort(v2.begin(),v2.end());
	vector <long long> a1(n + 1);
	vector <long long> a2(n + 1);
	for (int i = 1; i <= n; i++)
		a1[i] = v[i] + a1[i - 1], a2[i] = v2[i] + a2[i - 1];
	cin >> m;
	int x, y, z;
	vector <long long>ans(m + 1);
	for (int i = 1; i <= m; i++) {
		cin >> x >> y >> z;
		if (x == 1)
			ans[i] = a1[z] - a1[y - 1];
		else
			ans[i] = a2[z] - a2[y - 1];
	}
	for (int i = 1; i <= m; i++)
		cout << ans[i] << '\n';
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <sstream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	long long v[n+1];
	long long *a=new long long[n+1][n+1];
	long long *b = new long long[n+1][n+1];
	for(int i = 1; i<=n; i++)
		cin >> v[i];
	cin >> m;
	for(int i = 1; i<=n; i++){
		long long sum = v[i];
		for(int j = i; j<=n; j++){
			if(i!=j)
				sum += v[j];
			a[i][j] = sum;
		}
	}
	sort(v+1,v+(n+1));
	for(int i = 1; i<=n; i++){
		long long sum = v[i];
		for(int j = i; j<=n; j++){
			if(i!=j)
				sum += v[j];
			b[i][j] = sum;
		}
	}
	long long ans[m+1];
	int k = 0,x,y,z;
	for(int i = 1; i<=m; i++){
		cin >> x >> y >> z;
		if(x==1)
			ans[k] = a[y][z];
		else
			ans[k] = b[y][z];
		k++;
	}
	for(int i = 0; i<k; i++)
		cout << ans[i] << '\n';
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <sstream>
using namespace std;
int main() {
	int n, m;
	cin >> n;
	vector <long long> v(n + 1);
	vector <long long> v2(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		v2[i] = v[i];
	}
	sort(v2.begin(),v2.end());
	cin >> m;
	vector <long long >ans(m + 1);
	int k = 0, x, y, z;
	for (int i = 1; i <= m; i++) {
		cin >> x >> y >> z;
		long long sum = 0;
		if (x == 1)
			for (int a = y; a <= z; a++)
				sum += v[a];
		else
			for (int a = y; a <= z; a++)
				sum += v2[a];
		ans[k] = sum;
		k++;
	}
	for (int i = 0; i < k; i++)
		cout << ans[i] << '\n';
	return 0;
}


#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define ll long long
#define re return
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int>v(n+1);
	vector<ll>t1(n+1);
	vector<ll>t2(n+1);
	for(int i = 1; i<=n; i++)
		cin >> v[i];
	for(int i = 1; i<=n; i++)
		t1[i] = t1[i-1]+v[i];
	sort(all(v));
	for(int i = 1; i<=n; i++)
		t2[i] = t2[i-1]+v[i];
	int m,type,l,r;
	cin >> m;
	vector<ll>ans(m);
	for(int i = 0; i<m; i++){
		cin >> type >> l >> r;
		ans[i] = (type == 1) ? t1[r]-t1[l-1] : t2[r]-t2[l-1];
	}
	for(ll i : ans)
		cout << i << '\n';
    re 0;
}


#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define ll long long
#define re return
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int>v(n+1);
	vector<ll>t1(n+1);
	vector<ll>t2(n+1);
	for(int i = 1; i<=n; i++)
		cin >> v[i];
	for(int i = 1; i<=n; i++)
		t1[i] = t1[i-1]+v[i];
	sort(all(v));
	for(int i = 1; i<=n; i++)
		t2[i] = t2[i-1]+v[i];
	int m,type,l,r;
	cin >> m;
	vector<ll>ans(m);
	for(int i = 0; i<m; i++){
		cin >> type >> l >> r;
		ans[i] = (type == 1) ? t1[r]-t1[l-1] : t2[r]-t2[l-1];
	}
	for(int i : ans)
		cout << i << '\n';
    re 0;
}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
#define int long long
using namespace std;
signed main()
{
  int n;cin>>n;
  int fanta[n],fanta1[n],sum[n],sum2[n];
  for(int i=0;i<n;i++)
  {
     cin>>fanta[i];
     fanta1[i]=fanta[i];
  }
   partial_sum(fanta,fanta+n,sum);
    sort(fanta1,fanta1+n);
   partial_sum(fanta1,fanta1+n,sum2);
  int m;cin>>m;
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
    if(k==1)
     {
       if(l==1)
        l=l+1;
       cout<<sum[r-1]-sum[l-2]<<"\n";

     }
     else
     {
       if(l==1)
        l=l+1;
       cout<<sum2[r-1]-sum2[l-2]<<"\n";
     }

  }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
#define int long long
using namespace std;
signed main()
{
  int n;cin>>n;
  int fanta[n],fanta1[n],sum[n],sum2[n];
  for(int i=0;i<n;i++)
  {
     cin>>fanta[i];
     fanta1[i]=fanta[i];
  }
   partial_sum(fanta,fanta+n,sum);
    sort(fanta1,fanta1+n);
   partial_sum(fanta1,fanta1+n,sum2);
  int m;cin>>m;
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
    if(k==1)
     {
       if(l==1)
        cout<<sum[r-1]<<"\n";
        else
       cout<<sum[r-1]-sum[l-2]<<"\n";
     }
     else
     {
       if(l==1)
        cout<<sum2[r-1]<<"\n";
        else
       cout<<sum2[r-1]-sum2[l-2]<<"\n";
     }

  }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
#define int long long
using namespace std;
signed main()
{
  int n;cin>>n;
  int fanta[n],fanta1[n],sum[n],sum2[n];
  for(int i=0;i<n;i++)
  {
     cin>>fanta[i];
     fanta1[i]=fanta[i];
  }
   partial_sum(fanta,fanta+n,sum);
    sort(fanta1,fanta1+n);
   partial_sum(fanta1,fanta1+n,sum2);
  int m;cin>>m;
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;

    if(k==1)
     {
       if(l==1)
        l=l+1;
       cout<<sum[r-1]-sum[l-2]<<"\n";
     }
     else
     {
       if(l==1)
        l=l+1;
       cout<<sum2[r-1]-sum2[l-2]<<"\n";
     }

  }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
using namespace std;
int main()
{
  int n;cin>>n;
  vector<int>fanta,fanta1;
  for(int i=0;i<n;i++)
  {
     int y;cin>>y;
     fanta.PB(y);
  }
  int sum=0;
   fanta1=fanta;
   int sum1=0;
    sort(fanta1.begin(),fanta1.end());

  int m;cin>>m;
  vector<vector<int>>fanti(m);
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
     fanti[i].PB(k);fanti[i].PB(l); fanti[i].PB(r);
  }
   for(int i=0;i<m;i++)
   { long long unsigned int ans1=accumulate(fanta.begin(),fanta.end(),sum);
     if(fanti[i][0]==1)
     {
        for(int j=0;j<fanti[i][1]-1;j++)
        {
           ans1=ans1-fanta[j];
        }
        for(int j=fanti[i][2];j<n;j++)
        {
          ans1=ans1-fanta[j];
        }
        cout<<ans1<<"\n";
     }
     if(fanti[i][0]==2)
     {
        for(int j=0;j<fanti[i][1]-1;j++)
        {
           ans1=ans1-fanta1[j];
        }
        for(int j=fanti[i][2];j<n;j++)
        {
          ans1=ans1-fanta1[j];
        }
        cout<<ans1<<"\n";
     }
   }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
#define int long long
using namespace std;
signed main()
{
  int n;cin>>n;
  int fanta[n],fanta1[n],sum[n],sum2[n];
  for(int i=0;i<n;i++)
  {
     cin>>fanta[i];
     fanta1[i]=fanta[i];
  }
   partial_sum(fanta,fanta+n,sum);
    sort(fanta1,fanta1+n);
   partial_sum(fanta1,fanta1+n,sum2);
  int m;cin>>m;
  for(int i=0;i<m;i++)
  {
    int k,l,r;

    cin>>k>>l>>r;
    if(k==1)
     {
       if(l==1)
        l=l+1;
       cout<<sum[r-1]-sum[l-2]<<"\n";
     }
     else
     {
       if(l==1)
        l=l+1;
       cout<<sum2[r-1]-sum2[l-2]<<"\n";
     }

  }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
using namespace std;
int main()
{
  int n;cin>>n;
  vector<int>fanta,fanta1;
  for(int i=0;i<n;i++)
  {
     int y;cin>>y;
     fanta.PB(y);
  }
  int sum=0;
   fanta1=fanta;
   int sum1=0;
    sort(fanta1.begin(),fanta1.end());

  int m;cin>>m;
  vector<vector<int>>fanti(m);
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
     fanti[i].PB(k);fanti[i].PB(l); fanti[i].PB(r);
  }
   for(int i=0;i<m;i++)
   { long long int ans1=accumulate(fanta.begin(),fanta.end(),sum);
     if(fanti[i][0]==1)
     {
        for(int j=0;j<fanti[i][1]-1;j++)
        {
           ans1=ans1-fanta[j];
        }
        for(int j=fanti[i][2];j<n;j++)
        {
          ans1=ans1-fanta[j];
        }
        cout<<ans1<<"\n";
     }
     if(fanti[i][0]==2)
     {
        for(int j=0;j<fanti[i][1]-1;j++)
        {
           ans1=ans1-fanta1[j];
        }
        for(int j=fanti[i][2];j<n;j++)
        {
          ans1=ans1-fanta1[j];
        }
        cout<<ans1<<"\n";
     }
   }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
#define int long long
using namespace std;
signed main()
{
  int n;cin>>n;
  int fanta[n],fanta1[n],sum[n],sum2[n];
  for(int i=0;i<n;i++)
  {
     cin>>fanta[i];
     fanta1[i]=fanta[i];
  }
   partial_sum(fanta,fanta+n,sum);
    sort(fanta1,fanta1+n);
   partial_sum(fanta1,fanta1+n,sum2);
  int m;cin>>m;
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
    if(k==1)
     {
       if(l==1)
        cout<<sum[r-1]<<"\n";
       cout<<sum[r-1]-sum[l-2]<<"\n";
     }
     else
     {
       if(l==1)
        cout<<sum2[r-1]<<"\n";
       cout<<sum2[r-1]-sum2[l-2]<<"\n";
     }

  }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
using namespace std;
int main()
{
  int n;cin>>n;
  vector<int>fanta,fanta1;
  for(int i=0;i<n;i++)
  {
     int y;cin>>y;
     fanta.PB(y);
  }
  int sum=0;
   fanta1=fanta;
   int sum1=0;
    sort(fanta1.begin(),fanta1.end());

  int m;cin>>m;
  vector<vector<int>>fanti(m);
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
     fanti[i].PB(k);fanti[i].PB(l); fanti[i].PB(r);
  }
   for(int i=0;i<m;i++)
   {long long int ans1=accumulate(fanta.begin(),fanta.end(),sum);
     if(fanti[i][0]==1)
     {
        for(int j=0;j<fanti[i][1]-1;j++)
        {
           ans1=ans1-fanta[j];
        }
        for(int j=fanti[i][2];j<n;j++)
        {
          ans1=ans1-fanta[j];
        }
        cout<<ans1<<"\n";
     }
     if(fanti[i][0]==2)
     {
        for(int j=0;j<fanti[i][1]-1;j++)
        {
           ans1=ans1-fanta1[j];
        }
        for(int j=fanti[i][2];j<n;j++)
        {
          ans1=ans1-fanta1[j];
        }
        cout<<ans1<<"\n";
     }
   }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
using namespace std;
int main()
{
  int n;cin>>n;
  vector<int>fanta,fanta1;
  for(int i=0;i<n;i++)
  {
     int y;cin>>y;
     fanta.PB(y);
  }
  int sum=0;
   fanta1=fanta;
   int sum1=0;
    sort(fanta1.begin(),fanta1.end());

  int m;cin>>m;
  vector<vector<int>>fanti(m);
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
     fanti[i].PB(k);fanti[i].PB(l); fanti[i].PB(r);
  }
   for(int i=0;i<m;i++)
   {int ans1=accumulate(fanta.begin(),fanta.end(),sum);
     if(fanti[i][0]==1)
     {
        for(int j=0;j<fanti[i][1]-1;j++)
        {
           ans1=ans1-fanta[j];
        }
        for(int j=fanti[i][2];j<n;j++)
        {
          ans1=ans1-fanta[j];
        }
        cout<<ans1<<"\n";
     }
     if(fanti[i][0]==2)
     {
        for(int j=0;j<fanti[i][1]-1;j++)
        {
           ans1=ans1-fanta1[j];
        }
        for(int j=fanti[i][2];j<n;j++)
        {
          ans1=ans1-fanta1[j];
        }
        cout<<ans1<<"\n";
     }
   }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
#define int long long
using namespace std;
signed main()
{
  int n;cin>>n;
  int fanta[n],fanta1[n],sum[n],sum2[n];
  for(int i=0;i<n;i++)
  {
     cin>>fanta[i];
     fanta1[i]=fanta[i];
  }
   partial_sum(fanta,fanta+n,sum);
    sort(fanta1,fanta1+n);
   partial_sum(fanta1,fanta1+n,sum2);
  int m;cin>>m;
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
    if(k==1)
     {
       if(l==1)
        cout<<sum[r-1]<<"\n";
        else
       cout<<sum[r-1]-sum[l-2]<<"\n";
     }
     else
     {
       if(l==1)
        cout<<sum[r-1]<<"\n";
        else
       cout<<sum2[r-1]-sum2[l-2]<<"\n";
     }

  }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
#define int long long
using namespace std;
signed main()
{
  int n;cin>>n;
  int fanta[n],fanta1[n],sum[n],sum2[n];
  for(int i=0;i<n;i++)
  {
     cin>>fanta[i];
     fanta1[i]=fanta[i];
  }
   partial_sum(fanta,fanta+n,sum);
    sort(fanta1,fanta1+n);
   partial_sum(fanta1,fanta1+n,sum2);
  int m;cin>>m;
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
    if(k==1)
     {
       if(l==1)
        l=l+1;
       cout<<sum[r-1]-sum[l-2]<<"\n";
     }
     else
     {
       if(l==1)
        l=l+1;
       cout<<sum2[r-1]-sum2[l-2]<<"\n";
     }

  }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
using namespace std;
int main()
{
  int n;cin>>n;
  vector<int>fanta,fanta1;
  for(int i=0;i<n;i++)
  {
     int y;cin>>y;
     fanta.PB(y);
  }
   fanta1=fanta;
    sort(fanta1.begin(),fanta1.end());
  int m;cin>>m;
  vector<vector<int>>fanti(m);
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
     fanti[i].PB(k);fanti[i].PB(l); fanti[i].PB(r);
  }
   for(int i=0;i<m;i++)
   {
     if(fanti[i][0]==1)
     {
       long long int sum1=0;
        for(int j=fanti[i][1]-1;j<=fanti[i][2]-1;j++)
        {
           sum1=sum1+fanta[j];
        }
        cout<<sum1<<"\n";

     }
     if(fanti[i][0]==2)
     { long long int sum=0;
        for(int j=fanti[i][1]-1;j<=fanti[i][2]-1;j++)
        {
           sum=sum+fanta1[j];
        }
        cout<<sum<<"\n";
     }
   }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#define PB push_back
#define int long long
using namespace std;
signed main()
{

  int n;cin>>n;
  int fanta[n],fanta1[n],sum[n],sum2[n];
  for(int i=0;i<n;i++)
  {
     cin>>fanta[i];
     fanta1[i]=fanta[i];
  }
   partial_sum(fanta,fanta+n,sum);
    sort(fanta1,fanta1+n);
   partial_sum(fanta1,fanta1+n,sum2);
  int m;cin>>m;
  for(int i=0;i<m;i++)
  {
    int k,l,r;
    cin>>k>>l>>r;
    if(k==1)
     {
       if(l==1)
        l=l+1;
       cout<<sum[r-1]-sum[l-2]<<"\n";
     }
     else
     {
       if(l==1)
        l=l+1;
       cout<<sum2[r-1]-sum2[l-2]<<"\n";
     }

  }

}