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.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class CF1097_D2_C {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        int n = scanner.nextInt();
//        String[] arr = new String[n];
        HashMap<Integer, Integer> r = new HashMap<>();
        HashMap<Integer, Integer> l = new HashMap<>();
        HashMap<String, Pair> map = new HashMap<>();
        int balance = 0;
        for (int i = 0; i < n; i++) {
            String s = scanner.next();
            int left = 0;
            int right = 0;

            if (!map.containsKey(s)) {
                Stack<Character> stack = new Stack<>();
                for (char c : s.toCharArray()) {
                    if (c == '(') {
                        stack.add(c);
                    } else {
                        if (stack.isEmpty()) {
                            left++;
                        } else {
                            stack.pop();
                        }
                    }
                }
                right = stack.size();
                map.put(s, new Pair(left, right));
            } else {
                left = map.get(s).l;
                right = map.get(s).r;
            }
            if (left == 0 && right == 0) {
                balance++;
            }
            if (left == 0) {
                r.put(right, r.getOrDefault(right, 0) + 1);
            } else if (right == 0) {
                l.put(left, l.getOrDefault(left, 0) + 1);
            }
        }
        int count = 0;
        for (Map.Entry<Integer, Integer> e : r.entrySet()) {
            count += Math.min(l.getOrDefault(e.getKey(), 0), e.getValue());
        }
//        for (int i = 0; i < n; i++) {
//            if (!c[i] && (l[i] == 0 || r[i] == 0)) {
//                for (int j = 0; j < n; j++) {
//                    if (i != j && (l[j] == 0 || r[j] == 0) && !c[j]) {
//                        if (l[i] - r[j] == 0 && l[j] - r[i] == 0) {
//                            c[i] = true;
//                            c[j] = true;
//                            count++;
//                            break;
//                        }
//                    }
//                }
//            }
//        }
        System.out.println(count + (balance / 2));
    }

    static class Pair {
        int l, r;

        public Pair(int l, int r) {
            this.l = l;
            this.r = r;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair pair = (Pair) o;
            return l == pair.l &&
                    r == pair.r;
        }

        @Override
        public int hashCode() {
            return Objects.hash(l, r);
        }
    }

    static class Item {
        int index, val;

        public Item(int index, int val) {
            this.index = index;
            this.val = val;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Item item = (Item) o;
            return index == item.index &&
                    val == item.val;
        }

        @Override
        public int hashCode() {
            return Objects.hash(index, val);
        }
    }

    private static boolean check(String s1, String s2) {
        StringBuilder builder = new StringBuilder();
        builder.append(s1).append(s2);
        Stack<Character> stack = new Stack<>();
        for (char c : builder.toString().toCharArray()) {
            if (c == '(') {
                stack.add(c);
            } else {
                if (stack.isEmpty()) {
                    return false;
                }
                stack.pop();
            }
        }
        return stack.isEmpty();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

        int[] nextArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}