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 "( )".
//package math_codet;

import java.io.*;
import java.util.*;

public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod = 1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader(System.in);
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t = 1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    void solve(){
        int n = h.ni();
        long[] status = new long[n];
        TreeMap<Long, Integer> tmap = new TreeMap<Long, Integer>();
        int i = 0;
        for(i = 0; i < n; i++){
            String st = h.n();
            int j = 0;
            long open = 0, close = 0;
            boolean f1 = false, f2 = false;
            for(j = 0; j < st.length(); j++){
                if(st.charAt(j) == '(')
                    open++;
                else
                    open--;
                //pf[j] = open;
                if(open < 0)
                	f1 = true;
            }
            long open2 = 0;
            for(j = st.length() - 1; j >= 0; j--) {
            	if(st.charAt(j) == '(')
                    open2--;
                else
                    open2++;
               // sf[j] = open2;
               // h.pn(open2);
                if(open2 < 0)
                	f2 = true;
            }
           // h.pn(f1 +" "+f2);
            if(f1 && f2) {
            	status[i] = -1;
            	continue;

            }
            if(open <= 0){
                Integer x = tmap.get(open);
                if(x == null)
                    tmap.put(open, 1);
                else
                    tmap.put(open, ++x);
            }
            status[i] = open;
        }
        //h.pn(Arrays.toString(status));
        int cnt = 0;
        for(i = 0; i < n; i++){
            if(status[i] > 0){
                Integer x = tmap.get(-status[i]);
                if(x != null){
                    cnt++;
                    if(x == 1)
                    	tmap.remove(-status[i]);
                    else
                    	tmap.put(-status[i], --x);
                }
            }
            else if(status[i] == 0) {
            	Integer x = tmap.get(-status[i]);
                if(x != null && x > 1){
                    cnt++;
                    if(x == 2)
                    	tmap.remove(-status[i]);
                    else
                    	tmap.put(-status[i], x - 2);
                }
            }
        }
        h.pn(cnt);

    }

    static final Comparator<Pair> com=new Comparator<Pair>(){
        public int compare(Pair a, Pair b){
            if(Integer.compare(a.x, b.x) != 0)
                return Integer.compare(a.x, b.x);
            else
                return Integer.compare(a.y, b.y);
        }
    };


    class Pair{
        int x;
        int y;
        Pair(int p, int q){
            x = p;
            y = q;
        }
    }

    class Edge{
        int u , v, ind;
        boolean is_bridge;
        Edge(int a, int b, int i){
            u = a;
            v = b;
            ind = i;
        }
        int other(int x) {
            return u ^ v ^ x;
        }
    }

    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
 
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
 
        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
 
        public int peek() {
            if (numChars == -1)
                return -1;
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar];
        }
 
        public void skip(int x) {
            while (x-- > 0)
                read();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
        public long nextLong() {
            return Long.parseLong(next());
        }
 
        public String nextString() {
            return next();
        }
 
        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
 
            return res.toString();
        }
 
        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }
 
        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
 
        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1)
                read();
            return value != -1;
        }
 
        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}