13533 - Parentheses Matching 2   

Description

A string is said to be an SM string if it matches one of the following rules:

(1) An empty string is an SM string.

(2) If strings S1 and S2 are both SM strings, then S1S2 is an SM string.

(3) If a string S is an SM string, then {S}, [S], (S) and <S> are SM strings.

(4) If a string S is an SM string, then "sm"S is an SM string.

Given a string consisting of parentheses and "sm", determine if it is an SM string.

Input

The input consists of several lines.

Each line contains a string S (1 <= |S| <= 10^6 ), where S consists of only '{', '}', '[', ']', '(', ')', '<', '>' and "sm".

Testcases 1-2: without "sm".

Testcases 3-5: with "sm".

Output

For each string S, output "SM" if it is an SM string, "MS" if not.

There should be a '\n' in the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss