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 java.util.*;

    import javax.lang.model.util.ElementScanner6;

    import java.io.*;

    public class Main{

        public static void main(String[] args) {

            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader inp = new InputReader(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            Solver solver = new Solver();
            solver.solve(inp, out);
            out.close();
            
            }



        static class Solver {


            class Node implements Comparable<Node>{
                int i;
                long c;
            
                Node(int i,long c)
                {
                    this.i=i;
                    this.c=c;
                    

                }

            public int compareTo(Node n)
                {
                    return Long.compare(this.c, n.c);
                }
            }

            public boolean done(int[] sp,int[] par)
            {
                int root;

                root=findSet(sp[0],par);
                
            for(int i=1;i<sp.length;i++)
            {
                    if(root!=findSet(sp[i], par))
                        return false;
            }
            return true;
            }
        public int findSet(int i,int[] par)
        {
            int x =i;
                boolean flag =false;
                while(par[i]>=0)
                {
                    flag = true;
                    i=par[i];
                }
                if(flag)
                    par[x]=i;
                return i;
        }

        public void unionSet(int i,int j,int[] par)
        {
                int x = findSet(i, par);
                int y = findSet(j, par);
                if(x<y)
                {
                    par[y]=x;
                }
                else
                {
                    par[x]=y;
                }
        }

        public  long pow(long a, long b, long MOD) {
                if (b == 0) {
                    return 1;
                }
                if (b == 1) {
                    return a;
                }
                long val = pow(a, b / 2, MOD);
                if (b % 2 == 0) {
                    return val * val % MOD;
                } else {
                    return val * (val * a % MOD) % MOD;

                }
            
            }


            public void minPrimeFactor(int n,int[] s)
            {
                boolean prime[] = new boolean[n+1];
                Arrays.fill(prime, true);
                s[1]=1;
                s[2]=2;
                for(int i=4;i<=n;i+=2)
                {
                    prime[i]=false;
                    s[i]=2;
                }

                for(int i=3;i<=n;i+=2)
                {
                    if(prime[i])
                    {
                        s[i]=i;
                        for(int j=2*i;j<=n;j+=i)
                        {
                            prime[j]=false;
                            s[j]=i;
                        }
                    }
                }
                
            }

            
            // public void findAllPrime(int n,ArrayList<Node> al,int s[])
            // {
            //     int curr = s[n];
            //     int cnt = 1;
            //     while(n>1)
            //     {
            //         n/=s[n];
            //         if(curr==s[n])
            //         {
            //             cnt++;
            //             continue;

            //         }
            //         Node n1 = new Node(curr,cnt);
            //         al.add(n1);

            //         curr=s[n];
            //         cnt=1;
            //     }
            // }

            

            public int binarySearch(int n,int k)
            {
                int left=1;
                int right=100000000+5;
                int ans=0;
                while(left<=right)
                {
                    int mid = (left+right)/2;
                    if(n/mid>=k)
                    {
                        left = mid+1;
                        ans=mid;
                    }
                    else
                    {
                        right=mid-1;
                    }
                }

                return ans;
            }
            public boolean checkPallindrom(String s)
            {
                char ch[] = s.toCharArray();

                for(int i=0;i<s.length()/2;i++)
                {
                    if(ch[i]!=ch[s.length()-1-i])
                        return false;
                }
                return true;
            }


            public void dfs_util(ArrayList<Integer>[] al,boolean vis[],int x,int cnt[],int sts[],int fts[],long sv[])
            {
                    
                vis[x] = true;
                long min=Long.MAX_VALUE;
                    sts[cnt[0]]=x+1;
                    for(int i=0;i<al[x].size();i++)
                    {
                        
                        if(!vis[al[x].get(i)])
                        {
                            cnt[0]++;
                            dfs_util(al, vis, al[x].get(i),cnt,sts,fts,sv);
                            if(sv[al[x].get(i)]<min&&sv[al[x].get(i)]!=-1)
                            {
                                min=sv[al[x].get(i)];
                            }
                            
                            
                        }    
                        
                    }

                
                    if(sv[x]==-1)
                    {
                        if(min==Long.MAX_VALUE)
                        {
                            min=-1;
                        }
                        sv[x]=min;
                    }
                
                
                return ;
            }

            public void dfs(ArrayList[] al,int sts[],int fts[],long sv[])
            {
                
            boolean vis[] = new boolean[al.length];
            int cnt[]= new int[2*al.length+2];
            for(int i=0;i<al.length;i++)
            {
                    if(!vis[i])
                    {
                        
                        dfs_util(al,vis,i,cnt,sts,fts,sv);
                    }
            }
            }
    
            public void remove(ArrayList<Integer>[] al,int x)
            {
                for(int i=0;i<al.length;i++)
                {
                    for(int j=0;j<al[i].size();j++)
                    {

                        if(al[i].get(j)==x)
                            al[i].remove(j);

                    }
                }
            }

            public int gcd(int a, int b) 
            { 
                if (a == 0) 
                    return b; 
                return gcd(b % a, a); 
            }


            public void printDivisors(long n,ArrayList<Long> al) 
            { 
                // Note that this loop runs till square root 
                for (long i=1; i<=Math.sqrt(n); i++) 
                { 
                    if (n%i==0) 
                    { 
                        // If divisors are equal, print only one 
                        if (n/i == i) 
                            al.add(i);
            
                        else // Otherwise print both 
                            al.add(i);
                            al.add(n/i);
                    } 
                } 
            } 

            private void solve(InputReader inp, PrintWriter out1) {


                int n =inp.nextInt();

                String s[] = new String[n];
                int bal=0;
                int max=0;
                for(int i=0;i<n;i++)
                {
                    s[i] = inp.next();
                    if(s[i].length()>max)
                    {
                        max=s[i].length();
                    }
                }
                int count[] = new int[max+5];
                int cnt[] = new int[max+5];


                for(int i=0;i<n;i++)
                {
                    //    System.out.println("i "+i);
                    char ch[] = new char[s[i].length()];
                    ch=s[i].toCharArray();
                    Stack<Character> st = new Stack<Character>();
                    st.push(ch[0]);

                    for(int j=1;j<s[i].length();j++)
                    {
                        if(st.isEmpty())
                        {
                            st.push(ch[j]);
                            continue;
                        }
                        //    System.out.println("j "+j+" length "+s[i].length());
                        if(st.peek()=='(' && ch[j]==')')
                        {
                            st.pop();
                        }
                        else
                        {
                            st.push(ch[j]);
                        }
                    }
                    if(st.size()>0)
                    {
                        boolean flag = true;
                        char ch1 = st.pop();
                        int count1=1;
                        while(st.size()>0)
                        {
                            if(ch1==st.pop())
                            {
                                count1++;
                            }
                            else
                            {
                                flag=false;
                                break;
                            }
                        }
                        if(flag)
                        {
                            if(ch1=='(')
                            {
                                count[count1]++;
                            }
                            else
                            {
                                cnt[count1]++;
                            }
                        }

                    }
                    else
                    {
                        bal++;
                    }
                }
                int ans=bal/2;

                for(int i=0;i<cnt.length;i++)
                {
                        ans+=Integer.min(cnt[i],count[i]);
                }
                out1.println(ans);


                }

    }





        static class InputReader {
            BufferedReader reader;
            StringTokenizer tokenizer;

            InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }

            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());
            }
        }
    }
    class ele{
        long value;
        long i;
        boolean flag;
        public ele(long value,long i)
        {
            this.value = value;
            this.i=i;
            this.flag = false;
        }
    }