Boris has collected n coins. He laid them out in a row, and the i-th coin in the row has value ai.
Boris is about to leave on a trip, but he is short of time, so he plans to take one continuous segment of adjacent coins from the row.
Boris wants to answer several queries. For each query he wants to know the smallest amount he cannot pay without receiving change, given that he takes the coins from position li to position ri. Formally, find the smallest positive integer z such that no choice of coins from position li to position ri has values summing to z.