solve parentheses problem