1092C.md (2278B)
1 Source: https://codeforces.com/problemset/problem/1092/C 2 3 C. Prefixes and Suffixes 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 Ivan wants to play a game with you. He picked some string $s$ of length $n$ consisting only of lowercase Latin letters. 22 23 You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from $1$ to $n-1$), but he didn't tell you which strings are prefixes and which are suffixes. 24 25 Ivan wants you to guess which of the given $2n-2$ strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! 26 27 Input 28 29 The first line of the input contains one integer number $n$ ($2 \le n \le 100$) — the length of the guessed string $s$. 30 31 The next $2n-2$ lines are contain prefixes and suffixes, one per line. Each of them is the string of length from $1$ to $n-1$ consisting only of lowercase Latin letters. They can be given in arbitrary order. 32 33 It is guaranteed that there are exactly $2$ strings of each length from $1$ to $n-1$. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length $n$. 34 35 Output 36 37 Print one string of length $2n-2$ — the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The $i$-th character of this string should be 'P' if the $i$-th of the input strings is the prefix and 'S' otherwise. 38 39 If there are several possible answers, you can print any. 40 41 Examples 42 43 Input 44 45 ``` 46 5 47 ba 48 a 49 abab 50 a 51 aba 52 baba 53 ab 54 aba 55 ``` 56 57 Output 58 59 ``` 60 SPPSPSPS 61 ``` 62 63 Input 64 65 ``` 66 3 67 a 68 aa 69 aa 70 a 71 ``` 72 73 Output 74 75 ``` 76 PPSS 77 ``` 78 79 Input 80 81 ``` 82 2 83 a 84 c 85 ``` 86 87 Output 88 89 ``` 90 PS 91 ``` 92 93 Note 94 95 The only string which Ivan can guess in the first example is "ababa". 96 97 The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. 98 99 In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.