You are given a bracket sequence s consisting of n opening '(' and closing ')' brackets.

A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.

You can change the type of some bracket s_i. It means that if s_i =  ')' then you can change it to '(' and vice versa.

Your task is to calculate the number of positions i such that if you change the type of the i-th bracket, then the resulting bracket sequence becomes regular.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 10^6) — the length of the bracket sequence.

The second line of the input contains the string s consisting of n opening '(' and closing ')' brackets.

Output

Print one integer — the number of positions i such that if you change the type of the i-th bracket, then the resulting bracket sequence becomes regular.

Examples

Input


6
(((())


Output


3


Input


6
()()()


Output


0


Input


1
)


Output


0


Input


8
)))(((((


Output


0
import java.util.*;
import java.io.*;
import java.math.*;

//=============================================================================
//--------------------------Main-Class---------------------------------
//=============================================================================

public class A {
	
	static int N=1000005;
	 
	static int n, ans=0;
	static int pref[] = new int[N], suf[]=new int[N], cnt[]=new int[N];
	static String s;
	 
	static void work(String s)
	{
		for(int i=0;i<n;i++)
		{
			if(s.charAt(i)=='(')
				pref[i+1]=pref[i]+1;
			else
				pref[i+1]=pref[i]-1;
		}
		if(pref[n]%2 == 1 || pref[n]>2 || pref[n]<-2)
		{
			System.out.println(0);
			System.exit(0);
		}
		if(pref[n]==0)
		{
			System.out.println(0);
			System.exit(0);
		}
		suf[n+1]=Integer.MAX_VALUE;
		for(int i=n;i>=1;i--)
		{
			suf[i]=min(suf[i+1], pref[i]);
		}
		if(pref[n]==2)
		{
			if(suf[1]<0)
				return;
			for(int i=1;i<=n;i++)
			{
				if(s.charAt(i-1)=='(' && suf[i]==2)
					cnt[i]++;
			}
		}
		else
		{
			for(int i=1;i<=n;i++)
			{
				if(s.charAt(i-1)==')' && suf[i]==-2)
					cnt[i]++;
			}
		}
	}
	 
	static void work2(String s)
	{
		for(int i=0;i<n;i++)
		{
			if(s.charAt(i)==')')
				pref[i+1]=pref[i]+1;
			else
				pref[i+1]=pref[i]-1;
		}
		if(pref[n]%2 == 1 || pref[n]>2 || pref[n]<-2)
		{
			System.out.println(0);
			System.exit(0);
		}
		if(pref[n]==0)
		{
			System.out.println(0);
			System.exit(0);
		}
		suf[n+1]=Integer.MAX_VALUE;
		for(int i=n;i>=1;i--)
		{
			suf[i]=min(suf[i+1], pref[i]);
		}
		if(pref[n]==2)
		{
			if(suf[1]<0)
				return;
			for(int i=1;i<=n;i++)
			{
				if(s.charAt(i-1)==')' && suf[i]==2)
					cnt[n-i+1]++;
			}
		}
		else
		{
			for(int i=1;i<=n;i++)
			{
				if(s.charAt(i-1)=='(' && suf[i]==-2)
					cnt[n-i+1]++;
			}
		}
	}

	public static void process() throws IOException {

		 n = sc.nextInt();
		String str = sc.next();
		work(str);
		StringBuilder ss = new StringBuilder(str);
		work2(ss.reverse().toString());
		for(int i=1;i<=n;i++)
			ans+=(cnt[i]==2?1:0);
		println(ans);

	}

	//=============================================================================
	//--------------------------Dheeraj-Bhagchandani---------------------------------
	//=============================================================================

	static FastScanner sc;
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		boolean oj = true;
		if (oj) {
			sc = new FastScanner();
			out = new PrintWriter(System.out);
		} else {
			sc = new FastScanner(100);
			out = new PrintWriter("output.txt");
		}
		int t = 1;
//		t = sc.nextInt();
		while (t-- > 0) {
			process();
		}
		out.flush();
		out.close();
	}

	static class Pair implements Comparable<Pair> {
		int x, y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(Pair o) {
			return Integer.compare(this.x, o.x);
		}
	}

	/////////////////////////////////////////////////////////////////////////////////////////////////////////

	static void println(Object o) {
		out.println(o);
	}

	static void println() {
		out.println();
	}

	static void print(Object o) {
		out.print(o);
	}

	static void pflush(Object o) {
		out.println(o);
		out.flush();
	}

	static int ceil(int x, int y) {
		return (x % y == 0 ? x / y : (x / y + 1));
	}

	static long ceil(long x, long y) {
		return (x % y == 0 ? x / y : (x / y + 1));
	}

	static int max(int x, int y) {
		return Math.max(x, y);
	}

	static int min(int x, int y) {
		return Math.min(x, y);
	}

	static int abs(int x) {
		return Math.abs(x);
	}

	static long abs(long x) {
		return Math.abs(x);
	}

	static int log2(int N) {
		int result = (int) (Math.log(N) / Math.log(2));
		return result;
	}

	static long max(long x, long y) {
		return Math.max(x, y);
	}

	static long min(long x, long y) {
		return Math.min(x, y);
	}

	public static int gcd(int a, int b) {
		BigInteger b1 = BigInteger.valueOf(a);
		BigInteger b2 = BigInteger.valueOf(b);
		BigInteger gcd = b1.gcd(b2);
		return gcd.intValue();
	}

	public static long gcd(long a, long b) {
		BigInteger b1 = BigInteger.valueOf(a);
		BigInteger b2 = BigInteger.valueOf(b);
		BigInteger gcd = b1.gcd(b2);
		return gcd.longValue();
	}

	/////////////////////////////////////////////////////////////////////////////////////////////////////////

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner() throws FileNotFoundException {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		FastScanner(int a) throws FileNotFoundException {
			br = new BufferedReader(new FileReader("input.txt"));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readArray(int n) throws IOException {
			int[] A = new int[n];
			for (int i = 0; i != n; i++) {
				A[i] = sc.nextInt();
			}
			return A;
		}

		long[] readArrayLong(int n) throws IOException {
			long[] A = new long[n];
			for (int i = 0; i != n; i++) {
				A[i] = sc.nextLong();
			}
			return A;
		}
	}

	static void ruffleSort(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
		Arrays.sort(a);
	}

	static void ruffleSort(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
		Arrays.sort(a);
	}
}
