One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences.

A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket sequence if it's possible to obtain a correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, the sequences "(())()", "()" and "(()(()))" are correct, while the bracket sequences ")(", "(()" and "(()))(" are not correct.

Yuhao found this problem too simple for him so he decided to make the problem harder. You are given many (not necessarily correct) bracket sequences. The task is to connect some of them into ordered pairs so that each bracket sequence occurs in at most one pair and the concatenation of the bracket sequences in each pair is a correct bracket sequence. The goal is to create as many pairs as possible.

This problem unfortunately turned out to be too difficult for Yuhao. Can you help him and solve it?

Input

The first line contains one integer n (1 ≤ n ≤ 10^5) — the number of bracket sequences.

Each of the following n lines contains one bracket sequence — a non-empty string which consists only of characters "(" and ")".

The sum of lengths of all bracket sequences in the input is at most 5 ⋅ 10^5.

Note that a bracket sequence may appear in the input multiple times. In this case, you can use each copy of the sequence separately. Also note that the order in which strings appear in the input doesn't matter.

Output

Print a single integer — the maximum number of pairs which can be made, adhering to the conditions in the statement.

Examples

Input


7
)())
)
((
((
(
)
)


Output


2


Input


4
(
((
(((
(())


Output


0


Input


2
(())
()


Output


1

Note

In the first example, it's optimal to construct two pairs: "(( )())" and "( )".
import javafx.util.Pair;

import javax.lang.model.type.NullType;
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main
{
    public static void main(String[]args)
    {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Solver solver = new Solver();
        int ca = 1;
        solver.solve(ca,in,out);
        out.close();
    }
    static class Solver
    {
        public int BSearch(int a[],int val)
        {
            int res = -1;
            int l = 0;
            int r = a.length;
            while(l <= r)
            {
                int mid = (l + r) /2;
                if(a[mid] >= res)
                {
                    r = mid-1;
                    res = mid;
                }
                else l = mid + 1;
            }
            return res;
        }
        public void solve(int ca,InputReader in,PrintWriter out)
        {
            while(ca -- != 0)
            {
                int n = in.nextInt();
                int left[] = new int[500005];
                int right[] = new int[500005];
                int ans = 0;
                for(int i = 0;i<n;i++)
                {
                    String s = in.next();
                    int sum = 0,mval = 0;
                    for(int j = 0 ;j<s.length();j++)
                    {
                        if(s.charAt(j) == '(')
                        {
                            sum ++;
                        }
                        else
                        {
                            sum --;
                        }
                        mval = Math.min(sum,mval);

                    }
                    if(sum == 0 && mval >= 0) ans++;
                    else if(sum > 0 && mval >= 0) left[sum]++;
                    else if(sum < 0 && mval >= sum) right[-sum]++;
                    //out.println(left[i]+" "+ right[i]);
                }
                ans = ans/2;
                for(int i = 1;i<500005;i++)
                {
                    ans += Math.min(left[i],right[i]);
                }
                out.println(ans);
            }
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
        public BigInteger nextBigInteger()
        {
            return new BigInteger(next());
        }

    }
}
