inputs: I found an interesting problem on https://codeforces.com/problemset/problem/1092/C:
Ivan wants to play a game with you. He picked some string $s$ of length $n$ consisting only of lowercase Latin letters. 

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.

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!


-----Input-----

The first line of the input contains one integer number $n$ ($2 \le n \le 100$) — the length of the guessed string $s$.

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.

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$.


-----Output-----

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.

If there are several possible answers, you can print any.


-----Examples-----
Input
5
ba
a
abab
a
aba
baba
ab
aba

Output
SPPSPSPS

Input
3
a
aa
aa
a

Output
PPSS

Input
2
a
c

Output
PS



-----Note-----

The only string which Ivan can guess in the first example is "ababa".

The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable.

In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP"...

I tried it in Python, but could not do it. Can you solve it?
targets: n = int(input())

lst = []

for i in range((2*n)-2):
    curr = str(input())
    lst.append([i,curr])
    
lst.sort(key=lambda val: len(val[1]),reverse = True)

word1 = lst[0][1] + lst[1][1][-1]
word2 = lst[1][1] + lst[0][1][-1]
bool1 = True
bool2 = True

sp1 = [0 for i in range((2*n)-2)]
sp1[0] = 'P'
sp1[1] = 'S'
sp2 = [0 for i in range((2*n)-2)]
sp2[0] = 'S'
sp2[1] = 'P'

for i in range(2,(2*n)-2,2):
    curr1 = lst[i][1]
    curr2 = lst[i+1][1]
#    print(curr1," ",curr2,word1[:n-int(i/2)-1],word1[int(i/2)+1:])
    if curr1 == word1[:n-int(i/2)-1] and curr2 == word1[int(i/2)+1:]:
        sp1[i] = 'P'
        sp1[i+1] = 'S'
##        print("yes1\n")
##        print(sp1,sp2)
    elif curr2 == word1[:n-int(i/2)-1] and curr1 == word1[int(i/2)+1:]:
        sp1[i] = 'S'
        sp1[i+1] = 'P'
##        print("yes2\n")
    if curr1 == word2[:n-int(i/2)-1] and curr2 == word2[int(i/2)+1:]:
        sp2[i] = 'P'
        sp2[i+1] = 'S'
##        print("yes3\n")
    elif curr2 == word2[:n-int(i/2)-1] and curr1 == word2[int(i/2)+1:]:
        sp2[i] = 'S'
        sp2[i+1] = 'P'
##        print("yes4\n")

for i in sp1:
    if i == 0:
        bool1 = False
        break
for i in sp2:
    if i == 0:
        bool2 = False
##print(sp1,sp2)
if bool1:
    ans = ''
    newl = []
    for j in range(len(lst)):
        newl.append(lst[j]+[sp1[j]])
    newl.sort(key=lambda val: val[0])
    for j in newl:
        ans = ans + j[2]
    print(ans)
elif bool2:
    ans = ''
    newl = []
    for j in range(len(lst)):
        newl.append(lst[j]+[sp2[j]])
    newl.sort(key=lambda val: val[0])
    for j in newl:
        ans = ans + j[2]
    print(ans)