add Parentheses Balancing in Scala