In this Kata, you will be given a string with brackets and an index of an opening bracket and your task will be to return the index of the matching closing bracket.  Both the input and returned index are 0-based **except in Fortran where it is 1-based**. An opening brace will always have a closing brace. Return `-1` if there is no answer (in Haskell, return `Nothing`; in Fortran, return `0`; in Go, return an error)

### Examples

```python
solve("((1)23(45))(aB)", 0) = 10 -- the opening brace at index 0 matches the closing brace at index 10
solve("((1)23(45))(aB)", 1) = 3 
solve("((1)23(45))(aB)", 2) = -1 -- there is no opening bracket at index 2, so return -1
solve("((1)23(45))(aB)", 6) = 9
solve("((1)23(45))(aB)", 11) = 14
solve("((>)|?(*'))(yZ)", 11) = 14
```

Input will consist of letters, numbers and special characters, but no spaces. The only brackets will be `(` and `)`. 

More examples in the test cases. 

Good luck!

~~~if:fortran
*NOTE: In Fortran, you may assume that the input string will not contain any leading/trailing whitespace.*
~~~

Source: codewars | Difficulty: EASY
Tags: String algorithms

Starter code: def solve(st, idx):
	

Solutions:
def solve(s, idx):
	stack = []
	for (i, c) in enumerate(s):
		if c == '(':
			stack += [i]
		if c == ')':
			if not stack:
				break
			if stack.pop() == idx:
				return i
	return -1


def solve(s, i):
	c = s[i] == '('
	if not c:
		return -1
	while c != 0 and i != len(s):
		i += 1
		if s[i] == '(':
			c += 1
		elif s[i] == ')':
			c -= 1
	return -1 if c != 0 else i


def solve(st, idx):
	if st[idx] != '(':
		return -1
	open = 1
	for i in range(idx + 1, len(st)):
		if st[i] == '(':
			open += 1
		elif st[i] == ')':
			open -= 1
		if open == 0:
			return i


def solve(st, idx):
	if st[idx] != '(':
		return -1
	open_par = 0
	for (i, ch) in enumerate(st[idx + 1:]):
		if ch == '(':
			open_par += 1
		elif ch == ')':
			if not open_par:
				return i + idx + 1
			open_par -= 1


def solve(stg, s):
	n = 1
	if stg[s] == '(':
		while n and s < len(stg):
			(n, s) = (n + {'(': 1, ')': -1}.get(stg[s + 1], 0), s + 1)
	return -1 if n else s


from functools import reduce
from itertools import takewhile

def solve(s, i):
	return i + len(list(takewhile(bool, reduce(lambda x, y: x + [x[-1] + {'(': 1, ')': -1}.get(y, 0)], s[i + 1:], [1])))) if s[i] == '(' else -1


def solve(st, idx):
	if st[idx] != '(':
		return -1
	d = 1
	while d > 0:
		idx += 1
		if st[idx] == ')':
			d -= 1
		if st[idx] == '(':
			d += 1
	return idx


def solve(st, idx):
	if st[idx] != '(':
		return -1
	stack = []
	for i in range(len(st)):
		if st[i] == '(':
			stack.append(i)
		elif st[i] == ')':
			tmp = stack.pop()
			if tmp == idx:
				return i
	return -1


def solve(st, idx):
	if st[idx] != '(':
		return -1
	key = 1
	for (n, letter) in enumerate(st[idx + 1:]):
		if key == 0:
			return idx + n
		if letter == ')':
			key -= 1
		elif letter == '(':
			key += 1
	if key == 0:
		return idx + n + 1
	return -1


def solve(st, idx):
	length = len(st)
	opened = 0
	start = st[idx]
	if start != '(':
		return -1
	for i in range(idx, length, 1):
		if st[i] == ')':
			if opened != 0:
				opened = opened - 1
			if opened == 0:
				return i
		elif st[i] == '(':
			opened = opened + 1
	return -1