1099C.md (2449B)
1 Source: https://codeforces.com/problemset/problem/1099/C 2 3 C. Postcard 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it. 22 23 Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times. 24 25 For example, consider the following string: 26 27  28 29 This string can encode the message «happynewyear». For this, candy canes and snowflakes should be used as follows: 30 31 * candy cane 1: remove the letter w, 32 * snowflake 1: repeat the letter p twice, 33 * candy cane 2: leave the letter n, 34 * snowflake 2: remove the letter w, 35 * snowflake 3: leave the letter e. 36 37  38 39 Please note that the same string can encode different messages. For example, the string above can encode «hayewyar», «happpppynewwwwwyear», and other messages. 40 41 Andrey knows that messages from Irina usually have a length of $k$ letters. Help him to find out if a given string can encode a message of $k$ letters, and if so, give an example of such a message. 42 43 Input 44 45 The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters «*» and «?», meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed $200$. 46 47 The second line contains an integer number $k$ ($1 \leq k \leq 200$), the required message length. 48 49 Output 50 51 Print any message of length $k$ that the given string can encode, or «Impossible» if such a message does not exist. 52 53 Examples 54 55 Input 56 57 ``` 58 hw?ap*yn?eww*ye*ar 59 12 60 ``` 61 62 Output 63 64 ``` 65 happynewyear 66 ``` 67 68 Input 69 70 ``` 71 ab?a 72 2 73 ``` 74 75 Output 76 77 ``` 78 aa 79 ``` 80 81 Input 82 83 ``` 84 ab?a 85 3 86 ``` 87 88 Output 89 90 ``` 91 aba 92 ``` 93 94 Input 95 96 ``` 97 ababb 98 5 99 ``` 100 101 Output 102 103 ``` 104 ababb 105 ``` 106 107 Input 108 109 ``` 110 ab?a 111 1 112 ``` 113 114 Output 115 116 ``` 117 Impossible 118 ```