Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

  1. She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her <image>. 
  2. Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her <image>. 



For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

Input

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones. 

The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type, l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.

Output

Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

Examples

Input

6
6 4 2 7 2 7
3
2 3 6
1 3 4
1 1 6


Output

24
9
28


Input

4
5 5 2 3
10
1 2 4
2 1 4
1 1 1
2 1 4
2 1 2
1 1 1
1 3 3
1 1 3
1 4 4
1 2 2


Output

10
15
5
15
5
5
2
12
3
5

Note

Please note that the answers to the questions may overflow 32-bit integer type.
'''x=int(input())
if x%5==0:
    print(x//5)
else:
    print(x//5+1)
x=int(input())
for i in range(x):
    i=int(input())
    for n in range (3,361):
        if (180*(n-2))/n==i:
            print('YES')
            break
    else:
        print('NO')
a=int(input())
b=int(input())
if a%2==0:
    if b%2==0:
        print(((b-a)//2)+a)
    else:
        print(-((b-a+1)//2))
else:
    if b%2==0:
        print(((b-a+1)//2))
    else:
        print(-(((b-a)//2)+a))
a=int(input())
b=int(input())
if a>=b:
    for i in range(0,1000000000,a):
        if (i+1)%b==b-1:
            print(i+1)
            break
else:
    for i in range(0,1000000000,b):
        if (i-1)%a==1:
            print(i-1)
            break'''
'''a=input()
x=-1
if a==a[::-1]:
    if len(a)%2==0:
        print(len(a)//2)
    else:
        print((len(a)//2)+1)
else:
    for i in range(len(a)):
        if a[i]!=a[-i-1]:
            f=a[i]
            g=a[-i-1]
            if f==a[-i-2]:
                print(len(a)-i)
                break
            elif g==a[i+1]:
                print(i+1)
                break
            else:
                print(0)
                break
n=int(input())
m=int(input())
k=int(input())
x=[]
if (m*n)-1==k:
    print('IMPOSSIBLE')
elif k==m*n:
    for i in range(n):
        x.append('R'*m)
elif n==1:
    x.append(('L'*k) + ('R'*(m-k-1))+'L')
elif k==0 and m==1:
    for i in range(n-1):
        x.append('D')
    x.append('U')        
elif k==0:
    for i in range(n):
        x.append('R'*(m-1)+'L')
elif m==1:
    for i in range(k):
        x.append('L')
    for i in range(n-k-1):
        x.append('D')
    x.append('U')
elif m==2:
    for i in range(k//m):
        x.append('LL')
    if k%m==1:
        x.append(('U'*(k%m))+('D'*(m-k%m)))
        for i in range(n-(k//m)-1):
            x.append('RL')
    else:
        for i in range(n-(k//m)):
            x.append('RL')
    
else:
    for i in range(k//m):
        x.append('L'*m)
    x.append(('L'*(k%m)) + ('R'*(m-(k%m)-1))+'L')
    for i in range(n-(k//m)-1):
        x.append('R'*(m-1)+'L')
for i in x:
    print(i)
d=input().split()
n=int(d[0])
m=int(d[1])
s={}
x=''
for i in range(m):
    i=input().split()
    s[i[0]]=i[1]
c=input().split()
for i in range(n):
    if len(s[c[i]])>=len(c[i]):
        x+=c[i]+' '
    else:
        x+=s[c[i]]+' '
print(x)'''
x=int(input())
y=[int(i) for i in input().split()]
z=int(input())
d=0
a=sorted(y)
e={0:0}
c={0:0}
for i in range(x):
    e[i+1]=y[i]+e[i]
    c[i+1]=a[i]+c[i]
for i in range(z):
    i=input().split()
    if int(i[0])==1:
        print(e[int(i[2])]-e[int(i[1])-1])
    else:
        print(c[int(i[2])]-c[int(i[1])-1])
        
        
        
        
        
    
    

    
                
        
