QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 128 MB مجموع النقاط: 100

#16137. Increasing Subsequence

الإحصائيات

For a given sequence $S = \{a_1, a_2, a_3, \dots, a_n\}$, if there exists a subsequence $P = \{a_{x_1}, a_{x_2}, a_{x_3}, \dots, a_{x_m}\}$ such that $x_1 < x_2 < \dots < x_m$ and $a_{x_1} < a_{x_2} < \dots < a_{x_m}$, then $P$ is called an increasing subsequence of $S$. If there are multiple such $P$ that satisfy the conditions, we want to find the one that is lexicographically smallest.

Task

Given the sequence $S$ and several queries. For the $i$-th query, find the increasing subsequence of length $L_i$. If there are multiple, find the lexicographically smallest one (i.e., first minimize $x_1$, if not unique, then minimize $x_2$, and so on). If no increasing subsequence of length $L_i$ exists, print Impossible.

Input

The first line contains an integer $N$, representing the total number of elements in the sequence. The second line contains $N$ integers, $a_1, a_2, \dots, a_n$. The third line contains an integer $M$, representing the number of queries. The following $M$ lines each contain a number $L$, representing the length of the increasing subsequence to query.

Output

For each query, if the corresponding sequence exists, output it; otherwise, print Impossible.

Constraints

$N \le 10000$ $M \le 1000$

Examples

Input 1

6
3 4 1 2 3 6
3
6
4
5

Output 1

Impossible
1 2 3 6
Impossible

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.