---
# System prepended metadata

title: 13533 - Parentheses Matching 2
tags: [STL]

---

# 13533 - Parentheses Matching 2
>author: Utin
###### tags: `STL`

---

## Brief
See the code below

## Solution 0

```cpp=
#include <bits/stdc++.h>

std::string str = "()[]{}<>sm";

int main() {
    std::string input;
    while (std::getline(std::cin, input)) {
        std::stack<char> S;
        bool ans = true;
        for (int i = 0; i < input.size(); i++) {
            if (ans) {
                if (str.find(input[i]) % 2 == 0) S.push(input[i]);
                else if (S.empty()) ans = false;
                else if (str.find(input[i]) - 1 == str.find(S.top())) S.pop();
                else ans = false;
            }
        }
        std::cout << ((ans && S.empty()) ? "SM\n" : "MS\n");
    }
}

// By Utin
```

## Reference