Given a string, return the minimal number of parenthesis reversals needed to make balanced parenthesis. 

For example:
```Javascript
solve(")(") = 2 Because we need to reverse ")" to "(" and "(" to ")". These are 2 reversals. 
solve("(((())") = 1 We need to reverse just one "(" parenthesis to make it balanced.
solve("(((") = -1 Not possible to form balanced parenthesis. Return -1.
```

Parenthesis will be either `"("` or `")"`. 

More examples in the test cases. 

Good luck.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def solve(s):
	

Solutions:
def solve(s):
	t = None
	while t != s:
		(t, s) = (s, s.replace('()', ''))
	return -1 if len(s) % 2 else sum((1 + (a == tuple(')(')) for a in zip(*[iter(s)] * 2)))


class Stack:

	def __init__(self):
		self.items = []

	def is_empty(self):
		return self.items == []

	def push(self, item):
		self.items.append(item)

	def pop(self):
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def size(self):
		return len(self.items)

def solve(s):
	l = len(s)
	if l % 2 != 0:
		return -1
	stack = Stack()
	count = 0
	i = 0
	while i < len(s):
		if s[i] == '(':
			stack.push(s[i])
		elif stack.is_empty():
			count += 1
		else:
			stack.pop()
		i += 1
	q = (count + stack.size()) // 2
	return q if count % 2 == 0 and stack.size() % 2 == 0 else q + 1


def solve(s):
	if len(s) % 2:
		return -1
	height = 0
	counter = 0
	for x in s:
		if x == '(':
			height += 1
		else:
			height -= 1
		if height < 0:
			counter += 1
			height += 2
	return counter + height // 2


def solve(s):
	if len(s) % 2:
		return -1
	(count, swap) = (0, 0)
	for (i, c) in enumerate(s):
		count += (c == '(') - (c == ')')
		if count < 0:
			swap += 1
			count = 1
		elif count > len(s) - i:
			swap += 1
			count -= 2
	return swap


def solve(s):
	while '()' in s:
		s = s.replace('()', '')
	count = 0
	while len(s) > 1:
		count += s.count('((')
		s = s.replace('((', '')
		count += s.count('))')
		s = s.replace('))', '')
		count += s.count(')(') * 2
		s = s.replace(')(', '')
	return count if len(s) == 0 else -1


def solve(s, r={'((': 1, '))': 1, ')(': 2}):
	if len(s) % 2 == 1:
		return -1
	while '()' in s:
		s = s.replace('()', '')
	return sum((r[x] for x in map(''.join, zip(*[iter(s)] * 2))))


def solve(s):
	if len(s) & 1:
		return -1
	inv = open = 0
	for c in s:
		if c == '(':
			open += 1
		elif open:
			open -= 1
		else:
			open = 1
			inv += 1
	return inv + open // 2


import re

def solve(s):
	while '()' in s:
		s = re.sub('\\(\\)', '', s)
	ss = re.sub('\\(\\(|\\)\\)', '', s)
	sss = re.sub('\\)\\(', '', ss)
	return [-1, (len(s) - len(ss)) // 2 + len(ss)][not bool(sss)]


def dellall(s):
	n = 0
	while True:
		if n == len(s) - 1 or len(s) == 0:
			return True
		if s[n] == '(' and s[n + 1] == ')':
			del s[n]
			del s[n]
			n = 0
		else:
			n += 1

def solve(s):
	s = list(s)
	count = 0
	if len(s) % 2 != 0:
		return -1
	dellall(s)
	while len(s) != 0:
		n = 0
		if s[n] == '(' and s[n + 1] == ')':
			del s[n]
			del s[n]
		elif s[n] == ')' and s[n + 1] == '(':
			s[n] = '('
			s[n + 1] = ')'
			count += 2
		elif s[n] == '(' and s[n + 1] == '(':
			s[n + 1] = ')'
			count += 1
		elif s[n] == ')' and s[n + 1] == ')':
			s[n] = '('
			count += 1
	return count


def solve(s):
	if len(s) % 2 != 0:
		return -1
	(res, k) = (0, 0)
	for c in s:
		k += 1 if c == '(' else -1
		if k < 0:
			k += 2
			res += 1
	return res + k // 2