# You have a string s that consists of English letters, punctuation marks, whitespace characters, and brackets. 
# It is guaranteed that the parentheses in s form a regular bracket sequence.

# Your task is to reverse the strings contained in each pair of matching parentheses, starting from the innermost pair. 
# The results string should not contain any parentheses.

#Example

#For string s = "a(bc)de", the output should be
#reverseParentheses(s) = "acbde".

def reverseParentheses(s):
 
	#begin = s.split('(')

	#end = begin[1].split(')')

	#reverse = end[0][::-1]

	#return begin[0] + reverse + end[1]

	#Create a list of the characters
	lista = list(s)

	

	openP = 0
	closedP = 0
	print (lista)
	while True:
		#Define a new dimention for each loop
		long = len(lista)
		#Search for an open parenthesis and then a closed parenthesis
		for i in range( long ):
			#print('Elemento i: ',i)
			if lista[i] == '(':
				openP = i
				#print ('Changed ( -> index:',openP)
			if lista[i] == ')':
				closedP = i
				#print ('Changed ) -> index:',closedP)
				#Reverse list elements from index openP to closedP
				#print ('List to invert: ',lista[openP+1:closedP])
				lista[openP+1:closedP] = lista[openP+1:closedP][::-1]
				#print ('List inverted: ',lista[openP+1:closedP])
				#print ('Complete: ',lista)
				#After inverting remove the '(' ')' characters
				#print ('Elements: ',lista[openP],lista[closedP],' deleted. Indexes: ',openP,' & ',closedP)
				del lista[closedP]
				del lista[openP]

				#print ('Nueva lista: ',lista)
				break

		if openP == closedP:
			break

		openP = 0
		closedP = 0

	return ''.join(lista)