solve valid parentheses in py