Solution
C++ []\nclass Solution {\npublic:\n    string removeOuterParentheses(string S) {\n        string res;\n        int opened = 0;\n        for (char c : S) {\n    
```C++ []\nclass Solution {\npublic:\n    string removeOuterParentheses(string S) {\n        string res;\n        int opened = 0;\n        for (char c : S) {\n            if (c == \'(\' && opened++ > 0) res += c;\n            if (c == \')\' && opened-- > 1) res += c;\n        }\n        return res;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def removeOuterParentheses(self, S: str) -> str:\n        res, opened = [], 0\n        for c in S:\n            if c == \'(\' and opened > 0: res.append(c)\n            if c == \')\' and opened > 1: res.append(c)\n            opened += 1 if c == \'(\' else -1\n        \n        return "".join(res)\n```\n\n```Java []\nclass Solution {\n    public String removeOuterParentheses(String s) {\n        int len = s.length();\n        if (len <= 2) return "";\n        char[] c = s.toCharArray();\n        StringBuilder newString = new StringBuilder();\n        int open = 1;\n        int openLeft = 0;\n        for (int i = 1; i < len; i++) {\n            if (c[i] == \'(\') {\n                open++;\n                if (open > 1) newString.append(\'(\');\n            }\n            else {\n                if (open > 1) newString.append(\')\');\n                open--;\n            }\n        }\n        return newString.toString();\n    }\n}\n```
['C++', 'Java', 'Python3']