I. Intelligent Cat Embedding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You thought you wouldn't have to hear about AI today? Well, think again! It's 2023 after all! (Don't worry, you don't need any prior AI expertise — we'll explain all you need to know.)

If you've ever been part of any fringe internet community, I'm sure you've encountered some amount of cat pictures. The way those communities work is simple, the more cat pictures you post, the more popular you are. (Though some communities prefer other animals, like shiba inus or frogs, but the general concept is the same.) But the amount of REAL cat pictures you can post is limited; wouldn't it be great if you could generate cat pictures on demand, just from a text prompt?

Generative AI models such as Stable Diffusion do just that. Today we'll look at a custom version of that, let's call it Cat Diffusion, specifically designed for the generation of cute cat memes.

In Cat Diffusion, each prompt is first converted by a so-called text encoder into a $$$k$$$-dimensional embedding vector of integers $$$(v_1, v_2, \ldots, v_k)$$$. Think of this as a compressed vector containing all the necessary information to reconstruct the sentence's meaning. Sentences that are more alike are closer together; those that are different are further apart. This embedding vector is then passed to a so-called diffusion model, transforming this embedding into a picture.

Example of a few different prompts in a two-dimensional embedding space (not Cat Diffusion); similar sentences stick together.
The diffusion process, which transforms the embedding vector into an image in many small steps. Conveniently for the AI, Yoda's fingers are cropped from the image.

Each of the elements in the embedding vector represents, in some sense, a property; it could represent the type of the cat, or its pose, or the picture's brightness. [In practice, the meaning of those properties is much more abstract and doesn't easily map to real-world concepts; understanding embedding spaces is a huge research topic in machine learning.]

A prompt consists of some number of words. Cat Diffusion uses a very simple text encoder: The $$$i$$$-th word is associated with a certain set of property-value pairs $$$\left \{(p_{i,1}, v_{i,1}), (p_{i,2}, v_{i,2}), \ldots, (p_{i,m_i}, v_{i,m_i}) \right\}$$$. The text encoder now starts with the embedding vector where all properties are set to $$$0$$$; then, it goes left-to-right through the entire prompt, and for the $$$i$$$-th word, for every $$$j \in \{1, \ldots, m_i\}$$$, it sets the $$$p_{i,j}$$$-th property in the embedding vector to $$$v_{i,j}$$$.

You already know what cat picture you want to generate, and what properties it should have. Can you find a prompt that encodes into the exact embedding vector $$$t$$$ that you want, if one exists?

Input

The first line contains two integers $$$k$$$ and $$$w$$$, the dimensionality of the embedding vector (number of properties) and the number of words that you are allowed to use, respectively ($$$1 \leq k, w \leq 100$$$). Each word has a maximum length of $$$15$$$.

The second line contains $$$k$$$ integers $$$t_i$$$, the target embedding for which you're trying to find a prompt ($$$-10^5 \leq t_i \leq 10^5$$$). It is guaranteed that the target embedding has at least one entry which is non-zero.

The $$$i$$$-th of the next $$$w$$$ lines contains information about the $$$i$$$-th word: First is a sequence of lowercase alphabetic characters. Separated by a single space each, next is the number $$$m_i$$$ of property-value pairs associated with the word, followed by $$$m_i$$$ pairs $$$(p_{i, j}, v_{i, j})$$$ ($$$1 \leq m_i \leq k$$$, $$$1 \leq p_{i,j} \leq k$$$, $$$-10^5 \leq v_{i,j} \leq 10^5$$$). It is guaranteed that $$$p_{i, j}$$$ are distinct for any fixed $$$i$$$, and that the words themselves are pairwise distinct.

Note that our indices start at $$$1$$$.

Output

A single line of lowercase alphabetic words in the dictionary separated by single spaces so that its text embedding is $$$t$$$ if such a prompt exists; the string "IMPOSSIBLE" (all uppercase, without quotes) otherwise. If there are multiple valid solutions, it's okay to return any one of them.

Examples
Input
3 6
1 2 1
cat 1 1 1
dog 1 1 2
happy 1 2 1
sad 1 2 2
jumpy 2 2 1 3 1
sleeping 1 3 2
Output
jumpy sad cat 
Input
1 2
3
dog 1 1 1
frog 1 1 2
Output
IMPOSSIBLE
Input
4 9
-3 -1 0 2
check 1 4 -4
fish 1 4 2
hot 2 3 3 2 0
establish 2 2 -4 3 3
different 2 2 -3 1 -4
through 1 1 2
nature 1 3 0
group 3 3 3 2 -1 4 2
involve 3 3 4 4 -3 1 -3
Output
involve group nature fish