AT_abc448_c [ABC448C] Except and Min

Description

A bag contains $ N $ balls numbered $ 1 $ to $ N $ . Ball $ i $ has the integer $ A_i $ written on it. Process $ Q $ queries. For each query, a sequence $ B_1, B_2, \dots, B_{K} $ of length $ K $ is given, and you should perform the following sequence of operations. Here, all $ B_i $ are between $ 1 $ and $ N $ inclusive and are distinct. - First, remove balls $ B_1 $ , $ B_2 $ , $ \dots $ , $ B_K $ from the bag. - Then, output the minimum value among the integers written on the balls currently in the bag. (It is guaranteed by the constraints that the bag is not empty at this point.) - Afterwards, return all $ K $ removed balls to the bag.

Input Format

The input is given from Standard Input in the following format, where $ \mathrm{query}_i $ denotes the $ i $ -th query. > $ N $ $ Q $ $ A_1 $ $ A_2 $ $ \dots $ $ A_N $ $ \mathrm{query}_1 $ $ \mathrm{query}_2 $ $ \vdots $ $ \mathrm{query}_Q $ Each query is given in the following format. > $ K $ $ B_1 $ $ B_2 $ $ \dots $ $ B_K $

Output Format

Output $ Q $ lines. The $ i $ -th line should contain the answer to the $ i $ -th query.

Explanation/Hint

### Sample Explanation 1 For example, in the first query, balls $ 4 $ and $ 5 $ are removed from the bag. At this point, the following four balls remain in the bag: - Ball $ 1 $ with $ 3 $ written on it - Ball $ 2 $ with $ 2 $ written on it - Ball $ 3 $ with $ 5 $ written on it - Ball $ 6 $ with $ 2 $ written on it Thus, the minimum value among the integers written on the balls in the bag is $ 2 $ . ### Constraints - $ 6 \leq N \leq 3 \times 10^5 $ - $ 1 \leq Q \leq 2 \times 10^5 $ - $ 1 \leq A_i \leq 10^9 $ - $ 1 \leq K \leq 5 $ - $ 1 \leq B_1 \lt B_2 \lt \dots \lt B_K \leq N $ - The sum of $ K $ over all queries is at most $ 4 \times 10^5 $ . - All input values are integers.