class Solution
{
public:
string removeOuterParentheses(string S)
{
int cnt=0;
string ans;
int start=0;
for(int i=0;i<S.length();i++)
{
if(S[i]=='(')
{
cnt++;
}
else
{
cnt--;
if(cnt==0)
{
ans+=S.substr(start+1,i-start-1);
start=i+1;
}
}
}
return ans;
}
};