Aoi has $N$ cards numbered from $1$ to $N$. Each card has a positive integer written on it. The integer written on the card $i$ ($1 ≤ i ≤ N$) is $A_i$.
Aoi is going to play a game $Q$ times using the cards and a blackboard. The $j$-th game ($1 ≤ j ≤ Q$) she plays consists of the following steps.
Write $0$ on the blackboard.
Arrange the cards $L_j , L_j + 1, \dots , R_j$ on the desk from left to right in this order.
Perform the following operation for $R_j − L_j + 1$ times. The $k$-th operation ($1 ≤ k ≤ R_j − L_j + 1$) is as follows.
For each game, you want to know the maximum number of uiro pieces Aoi can eat.
Given the information about cards and games, write a program that, for each game, calculates the maximum number of uiro pieces Aoi can eat.
Read the following data from the standard input.
$N$
$A_1$ $A_2$ $\cdots$ $A_N$
$Q$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_Q$ $R_Q$
Write $Q$ lines to the standard output. In the $j$-th line ($1 ≤ j ≤ Q$), output the maximum number of uiro pieces Aoi can eat in the $j$-th game.