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.io.BufferedReader;
// import java.io.FileInputStream;
// import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.round;
import static java.lang.Math.sqrt;
import static java.util.Arrays.copyOf;
import static java.util.Arrays.fill;
import static java.util.Arrays.sort;
import static java.util.Collections.reverse;
import static java.util.Collections.reverseOrder;
import static java.util.Collections.sort;
import static java.util.Comparator.comparing;
import static java.util.Comparator.comparingInt;
import static java.util.Comparator.comparingLong;

public class Main {
    FastScanner in;
    PrintWriter out;

    private void solve() throws IOException {
        // solveA();
        // solveB();
        solveC();
        // solveD();
        // solveE();
        // solveF();
        // solveG();
        // solveH();
    }

    private void solveA() throws IOException {
        TreeSet<Character> set = new TreeSet<>();
        for (char c : in.nextLine().toCharArray())
            set.add(c);
        for (String s : in.nextLine().split(" "))
            for (char c : s.toCharArray())
                if (set.contains(c)) {
                    out.println("YES");
                    return;
                }
        out.println("NO");
    }

    private void solveB() throws IOException {
        int n = in.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = in.nextLong();

        for (int i = 0; i < (1 << n); i++) {
            long sum = 0;
            for (int j = 0, k = i; j < n; k /= 2, j++) {
                sum += k % 2 == 0 ? +a[j] : -a[j];
            }
            if (sum % 360 == 0) {
                out.println("YES");
                return;
            }
        }
        out.println("NO");
    }

    private void solveC() throws IOException {
        int n = Integer.parseInt(in.nextLine()), add = (int) 5e6;
        int[] cnt = new int[(int) 1e7];
        for (int i = 0; i < n; i++) {
            int cntr = 0;
            String s = in.nextLine();
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) == ')')
                    cntr++;
                else
                    cntr--;
            }
            if ((cntr == 0 && check0(s)) || (cntr > 0 && check1(s)) || (cntr < 0 && check0(s)))
                cnt[add + cntr]++;
        }

        long ans = 0;
        for (int i = 1; i < (int) 1e6; i++) {
            ans += min(cnt[add + i], cnt[add - i]);
        }
        ans += cnt[add] / 2;
        out.println(ans);
    }

    private boolean check1(String s) {
        int cntr = 0;
        String C = new StringBuilder(s).reverse().toString();
        for (char c : C.toCharArray())
            if (c == ')')
                cntr++;
            else {
                cntr--;
                if (cntr < 0)
                    return false;
            }
        return true;
    }

    private boolean check0(String s) {
        int cntr = 0;
        for (char c : s.toCharArray())
            if (c == '(')
                cntr++;
            else {
                cntr--;
                if (cntr < 0)
                    return false;
            }
        return true;
    }

    void shuffle(long[] a) {
        long b;
        Random r = new Random();
        for (int i = a.length - 1, j; i > 0; i--) {
            j = r.nextInt(i + 1);
            b = a[j];
            a[j] = a[i];
            a[i] = b;
        }
    }

    private void solveD() throws IOException {

    }

    private void solveE() throws IOException {

    }

    private void solveF() throws IOException {

    }

    private void solveG() throws IOException {

    }

    private void solveH() throws IOException {

    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

        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 {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }

    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        solve();

        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}