AND & OR & min on a segment
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Vasyl has n integers: x[1]
, x[2]
,..., x[n]
. You must help him to answer the queries of two types:
AND L R - in this case find the minimum value
x[i1]
ANDx[i2]
AND ... ANDx[ik]
, where {x[ik]
} is some nonempty subset, L ≤i[1]
<i[2]
< ... <i[k]
≤ R, 1 ≤ L ≤ R ≤ n.OR L R - in this case find the minimum value
x[i1]
ORx[i2]
OR ... ORx[ik]
, where {x[ik]
} is some nonempty subset, L ≤i[1]
<i[2]
< ... <i[k]
≤ R, 1 ≤ L ≤ R ≤ n.
Input
The first line contains number n (1 ≤ n ≤ 100000). Next line contains n numbers x[i]
(0 ≤ x[i]
≤ 10^9
). Then the number of queries m (1 ≤ m ≤ 100000) is given. Each of the next m lines contains one query.
Output
For each query print the answer in separate line.
Examples
Input #1
Answer #1
Submissions 300
Acceptance rate 45%