This is yet another problem on regular bracket sequences.

A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequence that consists of characters "(", ")" and "?". You have to replace each character "?" with a bracket so, that you get a regular bracket sequence.

For each character "?" the cost of its replacement with "(" and ")" is given. Among all the possible variants your should choose the cheapest.

Input

The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replacing the i-th character "?" with an opening bracket, and bi — with a closing one.

Output

Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second.

Print -1, if there is no answer. If the answer is not unique, print any of them. 

Examples

Input

(??)
1 2
2 8


Output

4
()()
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    static String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));

        String s = nextToken();
        byte[] str = s.getBytes();
        int[] open = new int[str.length];
        int[] close = new int[str.length];
        int qCount = 0;
        for (int i = 0; i < str.length; i++) {
            if (str[i] == '?') {
                open[qCount] = nextInt();
                close[qCount] = nextInt();
                qCount++;
            }
        }

        byte[] res = new byte[str.length];
        int countOpen = 0;
        int countClose = 0;
        long cost = 0;

        Comparator<Elem> comp = new Comparator<Elem>() {

            @Override
            public int compare(Elem o1, Elem o2) {
                if (o1.diff < o2.diff) {
                    return -1;
                }
                if (o1.diff > o2.diff) {
                    return 1;
                }
                return 0;
            }
        };

        MinHeap<Elem> cToO = new MinHeap<Elem>(Elem.class, str.length, comp);

        Map<Integer, Integer> mapOToC = new HashMap<Integer, Integer>();

        qCount = 0;
        for (int i = 0; i < str.length; i++) {
            int o = 0;
            int c = 0;
            if (str[i] == '(') {
                countOpen++;
                res[i] = '(';
            }
            else if (str[i] == ')') {
                countClose++;
                res[i] = ')';
            }
            else {
                o = open[qCount];
                c = close[qCount];
                qCount++;
                if (o <= c) {
                    countOpen++;
                    res[i] = '(';
                    cost = cost + o;
                    mapOToC.put(i, c - o);
                }
                else {
                    countClose++;
                    res[i] = ')';
                    cost = cost + c;
                    cToO.insert(new Elem(i, o - c));
                }
            }

            if (countClose > countOpen) {
                Elem el = cToO.extractMin();
                if (el == null) {
                    System.out.println(-1);
                    return;
                }
                res[el.index] = '(';
                cost = cost + el.diff;
                countOpen++;
                countClose--;
            }

        }

        countOpen = 0;
        countClose = 0;
        MinHeap<Elem> oToC = new MinHeap<Elem>(Elem.class, str.length, comp);

        for (int i = str.length - 1; i >= 0; i--) {
            if (res[i] == '(') {
                countOpen++;
                if (mapOToC.get(i) != null) {
                    oToC.insert(new Elem(i, mapOToC.get(i)));
                }
            }
            if (res[i] == ')') {
                countClose++;
            }
            if (countOpen > countClose) {
                Elem el = oToC.extractMin();
                if (el == null) {
                    System.out.println(-1);
                    return;
                }
                res[el.index] = ')';
                cost = cost + el.diff;
                countOpen--;
                countClose++;
            }

        }

        System.out.println(cost);
        System.out.println(new String(res));
    }

    static class Elem {

        int diff;
        int index;

        Elem(int index, int diff) {
            this.index = index;
            this.diff = diff;
        }

    }

    static class MinHeap<T> {

        private Comparator<T> comp;
        private T[] array;
        private int size;

        @SuppressWarnings("unchecked")
        MinHeap(Class<T> clazz, int capacity, Comparator<T> comp) {
            array = (T[]) Array.newInstance(clazz, capacity + 1);
            this.comp = comp;
            size = 0;
        }

        public void insert(T el) {
            size++;
            array[size] = el;
            int k = size;
            while (k > 1 && comp.compare(array[k], array[k / 2]) < 0) {
                swap(k, k / 2);
                k = k / 2;;
            }
        }

        public void clear() {
            for (int i = 1; i <= size; i++) {
                array[i] = null;
            }
            size = 0;
        }

        private void swap(int i, int j) {
            T t = array[i];
            array[i] = array[j];
            array[j] = t;
        }

        public T extractMin() {
            if (size == 0) {
                return null;
            }
            T res = array[1];
            swap(1, size);
            array[size] = null;
            size--;
            int k = 1;
            while (2 * k <= size) {
                int j = 2 * k;
                if (2 * k < size
                                && comp.compare(array[k * 2], array[k * 2 + 1]) > 0) {
                    j++;
                }
                if (comp.compare(array[k], array[j]) < 0) {
                    break;
                }
                swap(k, j);
                k = j;
            }
            return res;
        }
    }
}
