C. Prefixes and Suffixes (codefoces)

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 11 to ?−1n−1), but he didn't tell you which strings are prefixes and which are suffixes.

Ivan wants you to guess which of the given 2?−22n−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≤?≤1002≤n≤100) — the length of the guessed string ?s.

The next 2?−22n−2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 11 to ?−1n−1 consisting only of lowercase Latin letters. They can be given in arbitrary order.

It is guaranteed that there are exactly 22 strings of each length from 11 to ?−1n−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 2?−22n−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

Copy

5
ba
a
abab
a
aba
baba
ab
aba

output

Copy

SPPSPSPS

input

Copy

3
a
aa
aa
a

output

Copy

PPSS

input

Copy

2
a
c

output

Copy

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" is also acceptable.

思路: 考虑到长度为n-1的两个字符串大部分情况下可以确定整个字符串(通过比较哪一部分为共同部分)即比较str1(1~n-1)与str2(0~n-2)是否相同,以及比较str1(0~n-2)与str2(1~n-1)是否相同。   若两者都相同则还不能确定整个字符串。考虑到。若两个都相同 一定是例如:abababa这种交替的形式。则这时可以可以通过长度为1和长度为2的字符串来确定。具体要分奇偶讨论(这个自己想一下应该能明白,详细实现见代码)

# include 
# include 
#include
#include
using namespace std;
string str[205],str2[205],ch1,ch2,sh1,sh2,ans;
int ok[205];
bool cmp(string s1,string s2){
    return s1.length()>n;
    int cnt1=0,cnt2=0;
    for(int i=0;i<2*n-2;i++){
        cin>>str[i];
        str2[i]=str[i];
    }
    sort(str,str+2*n-2,cmp);
    for(int i=0,j=1;i

 

你可能感兴趣的:(codeforces)