# Write a function that reverses characters in (possibly nested) parentheses in the input string.

# Input strings will always be well-formed with matching()s.

# Example

# For inputString = "(bar)", the output should be
# reverseInParentheses(inputString) = "rab"
# For inputString = "foo(bar)baz", the output should be
# reverseInParentheses(inputString) = "foorabbaz"
# For inputString = "foo(bar)baz(blim)", the output should be
# reverseInParentheses(inputString) = "foorabbazmilb"
# For inputString = "foo(bar(baz))blim", the output should be
# reverseInParentheses(inputString) = "foobazrabblim".
# Because "foo(bar(baz))blim" becomes "foo(barzab)blim" and then "foobazrabblim".

def reverseInParentheses(inputString):
    return eval('"'+inputString.replace('(', '"+("').replace(')', '")[::-1]+"') + '"')


def reverseInParentheses(s):
    for i in range(len(s)):
        if s[i] == "(":
            start = i
        if s[i] == ")":
            end = i
            return reverseInParentheses(s[:start] + s[start+1:end][::-1] + s[end+1:])
    return s
