Kuriyama Mirai's Stones

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Kuriyama Mirai's Stones

Kuriyama Mirai has killed many monsters and got many (namelyn) stones. She numbers the stones from1ton. The cost of thei-th stone isvi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

She will tell you two numbers,landr(1?≤lrn), and you should tell her

.

Letuibe the cost of thei-th cheapest stone (the cost that will be on thei-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers,landr(1?≤lrn), and you should tell her

.

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 integern(1?≤n≤?105). The second line containsnintegers:v1,v2,?...,vn(1?≤vi≤?109)— costs of the stones.

The third line contains an integerm(1?≤m≤?105)— the number of Kuriyama Mirai's questions. Then followmlines, each line contains three integerstype,landr(1?≤lrn;?1?≤type≤?2), describing a question. Iftypeequal to1, then you should output the answer for the first question, else you should output the answer for the second one.

Output

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

Example

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

```

#include<cstdio>

#include<iostream>?

#include<algorithm>

using namespace std; ?


int n;

long long int a[100010],b[100010],c[100010];?


int main() ?

{ ?

? ? int m,o,p,q,i; ? ?

? ? scanf("%d",&n); ?

? ? for( i=0; i<n; i++) ?

? ? { ?

? ? ? ? scanf("%lld",&a[i]); ?

? ? ? ? b[i+1] = a[i] + b[i]; ?

? ? } ?

? ? sort(a,a+n); ?

? ? for( i=0; i<n; i++) ?

? ? { ?

? ? ? ? c[i+1] = a[i] + c[i]; ?

? ? } ?

? ? scanf("%d",&m); ?

? ? while(m--) ?

? ? { ?

? ? ? ? scanf("%d%d%d",&o,&p,&q); ?

? ? ? ? if(o==1) ?

? ? ? ? { ?

? ? ? ? ? ? printf("%lld\n",b[q]-b[p-1]); ?

? ? ? ? } ?

? ? ? ? else ?

? ? ? ? { ?

? ? ? ? ? ? printf("%lld\n",c[q]-c[p-1]); ?

? ? ? ? } ?

? ? } ?

? ? return 0; ?

} ?

```

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容