public static HashSet<String> getParens(int n) {
        if (n < 0) return null;
        HashSet<String> result = new HashSet<String>();
        if (n == 0) {
            result.add("");
            return result;
        }
        HashSet<String> lastParens = getParens(n - 1);
        for (String parens : lastParens) {
            for (int i = 0; i <= parens.length(); ++i) {
                result.add(parens.substring(0, i) +
                           "()" +
                           parens.substring(i));
            }
        }
        return result;
    }