Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
E. Sign on Fence

time limit per test

4 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputBizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of *n* panels of 1 meter width and of arbitrary height. The *i*-th panel's height is *h*_{i} meters. The adjacent planks follow without a gap between them.

After Bizon painted the fence he decided to put a "for sale" sign on it. The sign will be drawn on a rectangular piece of paper and placed on the fence so that the sides of the sign are parallel to the fence panels and are also aligned with the edges of some panels. Bizon the Champion introduced the following constraints for the sign position:

- The width of the sign should be exactly
*w*meters. - The sign must fit into the segment of the fence from the
*l*-th to the*r*-th panels, inclusive (also, it can't exceed the fence's bound in vertical direction).

The sign will be really pretty, So Bizon the Champion wants the sign's height to be as large as possible.

You are given the description of the fence and several queries for placing sign. For each query print the maximum possible height of the sign that can be placed on the corresponding segment of the fence with the given fixed width of the sign.

Input

The first line of the input contains integer *n* — the number of panels in the fence (1 ≤ *n* ≤ 10^{5}).

The second line contains *n* space-separated integers *h*_{i}, — the heights of the panels (1 ≤ *h*_{i} ≤ 10^{9}).

The third line contains an integer *m* — the number of the queries (1 ≤ *m* ≤ 10^{5}).

The next *m* lines contain the descriptions of the queries, each query is represented by three integers *l*, *r* and *w* (1 ≤ *l* ≤ *r* ≤ *n*, 1 ≤ *w* ≤ *r* - *l* + 1) — the segment of the fence and the width of the sign respectively.

Output

For each query print the answer on a separate line — the maximum height of the sign that can be put in the corresponding segment of the fence with all the conditions being satisfied.

Examples

Input

5

1 2 2 3 3

3

2 5 3

2 5 2

1 5 5

Output

2

3

1

Note

The fence described in the sample looks as follows:

The possible positions for the signs for all queries are given below.

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/15/2021 17:04:20 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|