A valid parentheses string is either empty "", "(" + X + ")", or X + Y, where X and Y are valid parentheses strings, and + represents string concatenation.
For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.
A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = X + Y, with X and Y nonempty valid parentheses strings.
Given a valid parentheses string s, consider its primitive decomposition: s = P_{1} + P_{2} + ... + P_{k}, where P_{i} are primitive valid parentheses strings.
Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of s.
Example 1:
Input:
s = "(()())(())"
Output:
"()()()"
Explanation:
The input string is "(()())(())", with primitive decomposition "(()())" + "(())".
After removing outer parentheses of each part, this is "()()" + "()" = "()()()".
Example 2:
Input:
s = "()()"
Output:
""
Explanation:
The input string is "()()", with primitive decomposition "()" + "()".
After removing outer parentheses of each part, this is "" + "" = "".
Your Task:
You don't need to read input or print anything. Your task is to complete the function removeOuter() which takes a string s as inputs and returns s  after removing the outermost parentheses of every primitive string in the primitive decomposition of s . 
Expected Time Complexity: O(n)
Expected Space Complexity: O(n)
Constraint:
1 <= s.length <= 10^{5}
s[i] is either '(' or ')'
s is a valid parentheses string.

Difficulty: EASY
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(n)

Starter code:
#User function Template for python3



class Solution:

    def removeOuter(self, S):

        # Code here

Solutions:
class Solution:

	def removeOuter(self, S):
		opened = 0
		ans = []
		for each in S:
			if each == '(':
				opened += 1
				if opened > 1:
					next = '('
					if ans and ans[-1] == '(':
						next = ')'
					else:
						next = '('
					ans.append(each)
			elif each == ')':
				if opened > 1:
					next = '('
					if ans and ans[-1] == '(':
						next = ')'
					else:
						next = '('
					ans.append(each)
				opened -= 1
		return ''.join(ans)


class Solution:

	def removeOuter(self, S):
		c = 0
		ss = ''
		for i in range(len(s)):
			if S[i] == '(' and c == 0:
				c += 1
				continue
			elif S[i] == ')' and c == 1:
				c -= 1
				continue
			elif S[i] == '(' and c != 0:
				c += 1
				ss += S[i]
			elif S[i] == ')' and c != 0:
				c -= 1
				ss += S[i]
		return ss


class Solution:

	def removeOuter(self, S):
		res = []
		flag = 0
		start = 0
		for i in range(0, len(s)):
			if s[i] == '(':
				flag += 1
			else:
				flag -= 1
			if flag == 0:
				res.append(s[start + 1:i])
				start = i + 1
		return ''.join(res)


class Solution:

	def removeOuter(self, s):
		ans = ''
		i = 0
		for c in s:
			if c == '(' and i > 0:
				ans += c
			if c == '(':
				i += 1
			if c == ')' and i > 1:
				ans += c
			if c == ')':
				i -= 1
		return ans


class Solution:

	def removeOuter(self, S):
		(res, opened) = ([], 0)
		for c in S:
			if c == '(' and opened > 0:
				res.append(c)
			if c == ')' and opened > 1:
				res.append(c)
			opened += 1 if c == '(' else -1
		return ''.join(res)


class Solution:

	def removeOuter(self, S):
		op = []
		(count, j, n) = (0, 0, len(S))
		for i in range(n):
			if S[i] == '(':
				count += 1
			else:
				count -= 1
				if count == 0:
					op.append(S[j + 1:i])
					j = i + 1
		return ''.join(op)


class Solution:

	def removeOuter(self, S):
		if len(S) == 0 or S == '':
			return S
		count = 0
		ans = ''
		for ele in S:
			if ele == '(':
				if count != 0:
					ans += ele
				count += 1
			else:
				count -= 1
				if count != 0:
					ans += ele
		return ans


class Solution:

	def removeOuter(self, S):
		(a, n) = ([], len(S))
		i = j = 0
		t = ''
		while i < n:
			if a and a[-1] == '(' and (S[i] == ')'):
				a.pop()
			elif len(a) == 0 and S[i] == '(' and (i > 0):
				t += S[j + 1:i - 1]
				j = i
				a.append(S[i])
			else:
				a.append(S[i])
			i += 1
		t += S[j + 1:i - 1]
		return t


class Solution:

	def removeOuter(self, S):
		count = 0
		lis = []
		for i in range(len(S)):
			if S[i] == ')':
				count -= 1
			if count > 0:
				lis.append(S[i])
			if S[i] == '(':
				count += 1
		return ''.join(lis)


class Solution:

	def removeOuter(self, S):
		counter = 0
		result = ''
		for char in S:
			if char == '(':
				if counter != 0:
					result += char
				counter += 1
			elif char == ')':
				counter -= 1
				if counter != 0:
					result += char
			else:
				result += char
		return result


class Solution:

	def removeOuter(self, S):
		stack = []
		result = ''
		start = 0
		for i in range(len(s)):
			if s[i] == '(':
				stack.append(i)
			else:
				stack.pop()
			if not stack:
				result += s[start + 1:i]
				start = i + 1
		return result


class Solution:

	def removeOuter(self, S):
		counter = 0
		res = ''
		for i in range(len(S)):
			if S[i] == '(' and counter == 0:
				counter += 1
			elif S[i] == '(' and counter > 0:
				counter += 1
				res += S[i]
			elif counter > 0:
				counter -= 1
				if counter > 0:
					res += S[i]
		return res


class Solution:

	def removeOuter(self, S):
		open_ = 0
		close_ = 0
		res = ''
		start = 0
		for (i, char) in enumerate(s):
			if char == '(':
				open_ += 1
			elif char == ')':
				close_ += 1
			if open_ == close_:
				res += s[start + 1:i]
				start = i + 1
		return res


class Solution:

	def removeOuter(self, S):
		left = 0
		right = 0
		res = []
		prev = 0
		for i in range(len(S)):
			if S[i] == '(':
				left += 1
			elif S[i] == ')':
				right += 1
			if left == right:
				res.append(S[prev:i + 1][1:-1])
				prev = i + 1
		return ''.join(res)


class Solution:

	def removeOuter(self, S):
		res = ''
		count = 0
		first = 0
		for i in range(len(S)):
			if S[i] == '(':
				count += 1
			else:
				count -= 1
			if count == 0:
				res += S[first + 1:i]
				first = i + 1
		return res


class Solution:

	def removeOuter(self, S):
		c = 0
		ans = []
		for i in S:
			if i == '(':
				if c > 0:
					ans.append(i)
				c += 1
			else:
				if c > 1:
					ans.append(i)
				c -= 1
		return ''.join(ans)


class Solution:

	def removeOuter(self, s):
		ans_set = set()
		stk = []
		for i in range(len(s)):
			if not stk or s[i] == '(':
				stk.append(i)
			elif s[i] == ')':
				if len(stk) > 1:
					ans_set.add(i)
					ans_set.add(stk[-1])
					stk.pop()
				else:
					stk.pop()
		a = []
		for i in range(len(s)):
			if i in ans_set:
				a.append(s[i])
		ans = ''.join(a)
		return ans


class Solution:

	def removeOuter(self, s):
		ans = []
		st = []
		opn = 0
		close = 0
		for el in s:
			if el == '(':
				opn += 1
				st.append('(')
			else:
				close += 1
				st.append(')')
				if close == opn:
					if len(st) > 2:
						ans += st[1:len(st) - 1]
					st = []
					opn = 0
					close = 0
		if opn > close:
			ans += st[1:]
		else:
			ans += st[:]
		return ''.join(ans)


class Solution:

	def removeOuter(self, S):
		count = 0
		s = ''
		for ele in S:
			if ele == '(':
				if count != 0:
					s += ele
				count += 1
			else:
				count -= 1
				if count != 0:
					s += ele
		return s


class Solution:

	def removeOuter(self, S):
		(res, cnt) = ('', 0)
		for ch in S:
			if cnt > 0 and ch == '(':
				res += ch
			if cnt > 1 and ch == ')':
				res += ch
			cnt += 1 if ch == '(' else -1
		return res


class Solution:

	def removeOuter(self, S):
		stack = []
		opened = 0
		for char in S:
			if char == '(' and opened > 0:
				stack.append(char)
			elif char == ')' and opened > 1:
				stack.append(char)
			opened += 1 if char == '(' else -1
		return ''.join(stack)


class Solution:

	def removeOuter(self, S):
		count = 0
		a = ''
		for i in range(len(S)):
			if S[i] == '(' and count == 0:
				count += 1
			elif S[i] == '(' and count > 0:
				count += 1
				a += S[i]
			elif count > 0:
				count -= 1
				if count > 0:
					a += S[i]
		return a


class Solution:

	def removeOuter(self, S):
		open = 0
		close = 0
		ans = ''
		start = 1
		for i in range(len(S)):
			if S[i] == '(':
				open += 1
			elif S[i] == ')':
				close += 1
			if open == close:
				ans += S[start:i]
				start = i + 2
		return ans


class Solution:

	def getPrimitiveStrings(self, str):
		arr = []
		(start, end) = (len(str) - 1, 0)
		count = 0
		for i in range(len(str)):
			if str[i] == '(':
				count = count + 1
				start = min(start, i)
			else:
				count = count - 1
				end = max(end, i)
			if count == 0:
				arr.append(str[start:end + 1])
				end = i + 1
				start = len(str) - 1
		return arr

	def removeOuter(self, S):
		if len(S) == 0:
			return ''
		arr = self.getPrimitiveStrings(S)
		ans = ''
		for str in arr:
			if not str == '':
				ans = ans + str[1:-1]
		return ans


class Solution:

	def removeOuter(self, S):
		open_count = 0
		close_count = 0
		res = ''
		start = 0
		for (i, c) in enumerate(S):
			if c == '(':
				open_count += 1
			elif c == ')':
				close_count += 1
			if open_count == close_count:
				res += S[start + 1:i]
				start = i + 1
		return res


class Solution:

	def removeOuter(self, S):
		stack = []
		result = []
		for c in S:
			if c == '(':
				if stack:
					result.append(c)
				stack.append(c)
			else:
				stack.pop()
				if stack:
					result.append(c)
		return ''.join(result)


class Solution:

	def removeOuter(self, S):
		res = ''
		start = 0
		close = 0
		open = 0
		for i in range(len(s)):
			if s[i] == '(':
				open += 1
			elif s[i] == ')':
				close += 1
			if open == close:
				res = res + s[start + 1:i]
				start = i + 1
				open = 0
				close = 0
		return res


class Solution:

	def removeOuter(self, S):
		stack = []
		ans = ''
		i = 0
		start = 0
		end = 0
		while i < len(S):
			if S[i] == '(':
				stack.append('(')
			elif S[i] == ')':
				if len(stack) == 1:
					end = i
					ans += S[start + 1:end]
					start = end + 1
				stack.pop()
			i += 1
		return ans


class Solution:

	def removeOuter(self, S):
		cnt = 0
		res = []
		for item in S:
			if item == '(':
				if cnt > 0:
					res.append(item)
				cnt += 1
			else:
				if cnt > 1:
					res.append(item)
				cnt -= 1
		return ''.join(res)


class Solution:

	def removeOuter(self, S):
		a = []
		outermost_parenthesis = ''
		for char in S:
			if len(a) == 0:
				a.append(char)
			elif a[-1] == '(' and char == ')':
				a.pop()
				if len(a) != 0:
					outermost_parenthesis += char
			else:
				outermost_parenthesis += char
				a.append(char)
		return outermost_parenthesis


class Solution:

	def removeOuter(self, string):
		start = 0
		openP = 0
		closeP = 0
		res = ''
		for (i, c) in enumerate(string):
			if c == '(':
				openP += 1
			elif c == ')':
				closeP += 1
			if openP == closeP:
				res += string[start + 1:i]
				start = i + 1
		return res


class Solution:

	def removeOuter(self, S):
		stack = []
		ans = ''
		for i in s:
			if i == '(':
				if len(stack) == 0:
					stack.append(i)
				else:
					ans += i
					stack.append(i)
			else:
				stack.pop()
				if len(stack) != 0:
					ans += i
		return ans


class Solution:

	def removeOuter(self, s):
		count = 0
		res = ''
		for i in range(len(s)):
			if s[i] == '(' and count == 0:
				count += 1
			elif s[i] == '(' and count >= 1:
				res += s[i]
				count += 1
			elif s[i] == ')' and count > 1:
				res += s[i]
				count -= 1
			elif s[i] == ')' and count == 1:
				count -= 1
		return res


class Solution:

	def removeOuter(self, S):
		x = []
		count = 0
		for i in S:
			if i == '(' and count > 0:
				x.append(i)
			elif i == ')' and count > 1:
				x.append(i)
			if i == '(':
				count += 1
			else:
				count -= 1
		return ''.join(x)


class Solution:

	def removeOuter(self, S):
		ans = ''
		i = 0
		n = len(S)
		while i < n - 1:
			if S[i] == '(' and S[i + 1] != ')':
				c = 1
				j = i + 1
				while j < n:
					if S[j] == '(':
						c += 1
					else:
						c -= 1
					if c == 0:
						break
					ans += S[j]
					j += 1
				i = j + 1
			else:
				i += 2
		return ans


class Solution:

	def removeOuter(self, S):
		stack = []
		result = ''
		for x in S:
			if x == '(':
				if stack:
					result += x
				stack.append(x)
			else:
				stack.pop()
				if stack:
					result += x
		return result


class Solution:

	def removeOuter(self, S):
		res = ''
		opened = 0
		for i in S:
			if i == '(' and opened > 0:
				res += i
			elif i == ')' and opened > 1:
				res += i
			opened += 1 if i == '(' else -1
		return res


class Solution:

	def removeOuter(self, S):
		lst = []
		stack = []
		for i in range(len(S)):
			if S[i] == '(':
				stack.append('(')
				if len(stack) > 1:
					lst.append('(')
			else:
				stack.pop()
				if stack:
					lst.append(')')
		return ''.join(lst)


class Solution:

	def removeOuter(self, S):
		stack = []
		result = ''
		for i in S:
			if i == '(':
				stack.append(i)
				if len(stack) == 1:
					continue
			elif i == ')':
				stack.pop()
				if len(stack) == 0:
					continue
			result += i
		return result


class Solution:

	def removeOuter(self, S):
		c = 0
		S2 = ''
		for i in range(len(S)):
			if S[i] == '(':
				c += 1
				if c != 1:
					S2 += S[i]
			else:
				c -= 1
				if c != 0:
					S2 += S[i]
		return S2


class Solution:

	def removeOuter(self, S):
		i = '('
		j = ')'
		oc = 0
		cc = 0
		s1 = ''
		a = []
		for h in range(0, len(S)):
			if S[h] == '(':
				a.append(h)
				oc = oc + 1
			elif S[h] == ')':
				cc = cc + 1
				a.append(h)
			if oc == cc:
				s1 = s1 + str(S[a[1]:a[len(a) - 1]])
				h = len(a) - 1
				oc = 0
				cc = 0
				a = []
		return s1


class Solution:

	def removeOuter(self, S):
		n = len(S)
		res = ''
		st = []
		for i in range(n):
			if S[i] == '(' and len(st) == 0:
				st.append(S[i])
			elif S[i] == '(' and st[-1] == '(':
				st.append(S[i])
				res += S[i]
			elif S[i] == ')' and st[-1] == '(' and (len(st) != 1):
				res += ')'
				st.pop()
			elif S[i] == ')' and st[-1] == '(' and (len(st) == 1):
				st.pop()
		return res


class Solution:

	def removeOuter(self, S):
		count = 0
		stack = []
		final_stack = []
		for i in s:
			stack.append(i)
			if i == '(':
				count = count + 1
			elif i == ')':
				count -= 1
			if count == 0:
				final_stack += stack[1:-1]
				stack = []
		return ''.join(final_stack)


class Solution:

	def removeOuter(self, s):
		string = ''
		n = len(s)
		bal = 1
		i = 1
		while i < n:
			if s[i] == '(':
				bal += 1
			else:
				bal -= 1
			if bal != 0:
				string += s[i]
			else:
				bal += 1
				i += 1
			i += 1
		return string


class Solution:

	def removeOuter(self, s):
		n = len(s)
		res = ''
		i = 0
		j = 1
		count = 1
		while j < n:
			if s[j] == '(':
				count += 1
				j += 1
			elif s[j] == ')':
				count -= 1
				j += 1
			if count == 0:
				res += s[i + 1:j - 1]
				i = j
				j = j + 1
				count = 1
		return res


class Solution:

	def removeOuter(self, S):
		c = 0
		index = 0
		final_s = ''
		for (n, i) in enumerate(S):
			if i == '(':
				c += 1
			else:
				c -= 1
			if c == 0:
				final_s += S[index + 1:n]
				index = n + 1
		return final_s


class Solution:

	def removeOuter(self, s):
		if len(s) == 0:
			return s
		open = 0
		idx = -1
		ans = ''
		for i in range(len(s)):
			if s[i] == ')':
				open -= 1
				if open == 0:
					ans += s[idx + 1:i]
					idx = -1
			else:
				if idx == -1:
					idx = i
				open += 1
		return ans


class Solution:

	def removeOuter(self, S):
		ns = ''
		i = 0
		cnt = 0
		while i < len(S):
			if S[i] == '(' and cnt == 0:
				cnt += 1
			elif S[i] == '(':
				cnt += 1
				ns = ns + S[i]
			elif S[i] == ')':
				cnt = cnt - 1
				if cnt != 0:
					ns = ns + S[i]
			i += 1
		return ns


class Solution:

	def remove_element(self, string, index):
		new = ''
		for i in range(len(string)):
			if i != index:
				new = new + string[i]
			elif i == index:
				new = new + ' '
		return new

	def removeOuter(self, S):
		count = 0
		for i in range(len(S)):
			if S[i] == '(' and count == 0:
				count += 1
				S = self.remove_element(S, i)
			elif S[i] == ')' and count == 1:
				count -= 1
				S = self.remove_element(S, i)
			elif S[i] == '(':
				count += 1
			elif S[i] == ')':
				count -= 1
		return S.replace(' ', '')


class Solution:

	def removeOuter(self, S):
		l = []
		a = ''
		ans = []
		for i in s:
			a = a + i
			if i == '(':
				l.append(i)
			if i == ')':
				l.pop()
			if len(l) == 0:
				ans.append(a)
				a = ''
		b = ''
		for m in ans:
			b = b + m[1:len(m) - 1]
		return b


class Solution:

	def removeOuter(self, S):
		stack = []
		result = []
		start = 0
		for (i, c) in enumerate(S):
			if c == '(':
				stack.append(i)
			else:
				if not stack:
					continue
				stack.pop()
				if not stack:
					result.append(S[start + 1:i])
					start = i + 1
		return ''.join(result)


class Solution:

	def removeOuter(self, S):
		n = len(S)
		i = 1
		j = 1
		open = 1
		close = 0
		res = ''
		while j < n:
			if open != close:
				if S[j] == '(':
					open += 1
				else:
					close += 1
				j += 1
				if j == n and open == close:
					res += S[i:j - 1]
			else:
				res += S[i:j - 1]
				j += 1
				i = j
				open = 1
				close = 0
		return res


class Solution:

	def removeOuter(self, s):
		cnt = 0
		result = ''
		for c in s:
			if c == '(':
				if cnt != 0:
					result += c
				cnt += 1
			elif c == ')':
				cnt -= 1
				if cnt != 0:
					result += c
			else:
				continue
		return result


class Solution:

	def removeOuter(self, S):
		res = ''
		count = 0
		for c in s:
			if c == '(' and count > 0:
				res += c
			if c == '(':
				count += 1
			if c == ')' and count > 1:
				res += c
			if c == ')':
				count -= 1
		return res


class Solution:

	def removeOuter(self, S):
		res = ''
		c = 0
		for i in S:
			if i == '(' and c > 0:
				res += i
			if i == '(':
				c += 1
			if i == ')' and c > 1:
				res += i
			if i == ')':
				c -= 1
		return res


class Solution:

	def removeOuter(self, s):
		stack = []
		result = ''
		for char in s:
			if char == '(':
				if stack:
					result += char
				stack.append(char)
			elif char == ')':
				stack.pop()
				if stack:
					result += char
		return result


class Solution:

	def removeOuter(self, S):
		st = []
		open = 0
		for i in S:
			if i == '(' and open > 0:
				st.append(i)
			if i == ')' and open > 1:
				st.append(i)
			if i == '(':
				open += 1
			else:
				open -= 1
		return ''.join(st)


class Solution:

	def removeOuter(self, S):
		st = []
		res = ''
		for i in S:
			if i == '(':
				if len(st) > 0:
					res += i
				st.append(i)
			else:
				st.pop()
				if len(st) > 0:
					res += i
		return res


class Solution:

	def removeOuter(self, S):
		(l, idx) = (0, 0)
		ans = ''
		for i in range(len(S)):
			if s[i] == '(':
				l += 1
			else:
				l -= 1
			if l != 0 and i != idx:
				ans += s[i]
			if l == 0:
				idx = i + 1
		return ans


class Solution:

	def removeOuter(self, s):
		(popen, result) = (0, [])
		for x in s:
			if x == ')':
				popen -= 1
			if popen > 0:
				result.append(x)
			if x == '(':
				popen += 1
		return ''.join(result)


class Solution:

	def removeOuter(self, s):
		stack = []
		res = ''
		n = len(s)
		for i in range(n):
			if s[i] == '(':
				stack.append('(')
				if len(stack) > 1:
					res += '('
			elif s[i] == ')' and len(stack) > 1:
				res += s[i]
				stack.pop(-1)
			elif s[i] == ')' and len(stack) == 1:
				stack.pop(-1)
			else:
				pass
		return res


class Solution:

	def removeOuter(self, S):
		ans = ''
		count = 0
		for i in S:
			if i == '(':
				if count:
					ans += i
				count += 1
			if i == ')':
				if count > 1:
					ans += i
				count -= 1
		return ans


class Solution:

	def removeOuter(self, S):
		l = 0
		r = 0
		Ans = ''
		ans = ''
		for i in s:
			if i == '(':
				l += 1
			else:
				r += 1
			ans += i
			if r == l:
				Ans += ans[1:-1]
				ans = ''
		return Ans


class Solution:

	def removeOuter(self, S):
		open_bracket_cnt = 1
		idx_remove = [0]
		idx = 1
		while idx < len(S):
			if S[idx] == '(':
				open_bracket_cnt += 1
			else:
				open_bracket_cnt -= 1
			if open_bracket_cnt == 0:
				idx_remove.append(idx)
				if idx + 1 < len(S):
					idx_remove.append(idx + 1)
			idx += 1
		inner_paranthesis = str()
		for i in range(0, len(idx_remove), 2):
			start_idx = idx_remove[i] + 1
			end_idx = idx_remove[i + 1]
			inner_paranthesis += S[start_idx:end_idx]
		return inner_paranthesis


class Solution:

	def removeOuter(self, S):
		l = []
		s = ''
		for i in range(len(S)):
			if S[i] == '(':
				if len(l) > 0:
					s = s + S[i]
				l.append(S[i])
			else:
				l.pop()
				if len(l) > 0:
					s = s + S[i]
		return s


class Solution:

	def removeOuter(self, S):
		k = ''
		temp = 0
		for i in S:
			if not (temp == 0 and i == '(' or (temp == 1 and i == ')')):
				k = k + i
			if i == '(':
				temp += 1
			else:
				temp -= 1
		return k


class Solution:

	def removeOuter(self, S):
		s = list()
		m = 0
		max = 0
		for i in S:
			if i == '(' and m == 0:
				m += 1
			elif i == '(' and m > 0:
				m += 1
				s.append(i)
			elif m > 0:
				m -= 1
				if m > 0:
					s.append(i)
		return ''.join(s)


class Solution:

	def removeOuter(self, S):
		(count, start, n) = (0, 0, len(S))
		ans = []
		for i in range(n):
			if S[i] == '(':
				count += 1
			else:
				count -= 1
				if count == 0:
					ans.append(S[start + 1:i])
					start = i + 1
		return ''.join(ans)


class Solution:

	def removeOuter(self, S):
		ch = 0
		res = ''
		for i in range(0, len(s)):
			if s[i] == '(':
				if ch == 0:
					x = i
				ch += 1
			else:
				ch -= 1
			if ch == 0:
				res = res + s[x + 1:i]
		return res


class Solution:

	def removeOuter(self, S):
		stack = []
		top = -1
		l1 = []
		s1 = ''
		for i in range(len(s)):
			if s[i] == '(' and len(stack) == 0:
				stack.append(s[i])
				top += 1
				l1.append(i)
			elif s[i] == '(':
				stack.append(s[i])
				top += 1
			if s[i] == ')' and stack[top] == '(':
				top -= 1
				stack.pop()
				if len(stack) == 0:
					l1.append(i)
		for i in range(0, len(l1), 2):
			k1 = l1[i]
			k2 = l1[i + 1]
			res = s[k1 + 1:k2]
			s1 = s1 + res
		return s1