Problem B
Abandoned Animal

You know that your sister will hold on to her beloved Fluffynose whenever possible, so the only time she could’ve lost it is when she grabbed an item on her shopping list. So, all you have to do is figure out at what store she bought what, and then you’ll reunite her with her counterpart in no time! However, you soon find out that this isn’t quite as easy as you thought: she went to a lot of stores, and although she knows the names of the stores she went to and the order in which she visited them, she does not recall what she bought at each store (it could have been nothing!). It would take a lot of time to blindly search all the stores for all these items. As you have better things to do today, like solving programming problems, you want to spend as little time on this retrieval as possible. Therefore, you want to know exactly which items your sister bought at each store before you start your search.
For this you have two pieces of information: firstly you know the inventory of all stores your sister went to. Secondly, you know exactly in what order she purchased the groceries, as she has very carefully stacked all items into her bag. You decide to number the stores your sister visited according to the order in which she visited them. Given this information, you want to decide whether you know for sure where she bought every item so you can retrace her steps as efficiently as possible.
Input
The input starts with a line with a single integer
The second part of the input contains the list of items your
sister bought, in order of purchase. It starts with a line with
an integer
Output
Output “impossible" if there is no path through the stores that matches your sister’s description. Output “unique" if there is exactly one path through the stores that matches. Output “ambiguous" if there are multiple possible paths.
Sample Input 1 | Sample Output 1 |
---|---|
3 3 0 chocolate 1 icecream 2 cookies 3 chocolate cookies icecream |
impossible |
Sample Input 2 | Sample Output 2 |
---|---|
3 4 0 chocolate 1 icecream 2 cookies 2 chocolate 3 chocolate icecream cookies |
unique |
Sample Input 3 | Sample Output 3 |
---|---|
3 10 0 tomatoes 0 cucumber 1 tomatoes 2 tomatoes 2 cucumber 1 mustard 0 salt 2 salad 2 salt 2 mustard 5 tomatoes cucumber salad mustard salt |
ambiguous |