cpp implementation of Longest Valid Parentheses