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.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class CF3D {

    public static void main(String[] args) {
        String str = IN.next();
        int n = (int) Stream.of(str.split("")).filter(v -> v.equals("?")).count();
        int A[][] = new int[n][2];
        for (int i = 0; i < n; i++) {
            A[i][0] = IN.nextInt();
            A[i][1] = IN.nextInt();
        }
        IN.close();
        solve(str, n, A);
    }

    private static void solve(String str, int n, int A[][]) {
        long res = 0;
        int len = str.length();
        char chs[] = str.toCharArray(), tmp[] = new char[len];
        PriorityQueue<int[]> pq = new PriorityQueue<>(
                (o1, o2) -> (A[o1[1]][0] - A[o1[1]][1] - A[o2[1]][0] + A[o2[1]][1]));
        int j = 0, d = 0;// 左括号多于右括号的个数
        PrintWriter pr = new PrintWriter(System.out);
        for (int i = 0; i < len; i++) {
            if (chs[i] == '?' || chs[i] == ')') {
                if (chs[i] == '?') {
                    res += A[j][1];
                    pq.offer(new int[] { i, j++ });
                }
                d--;
                tmp[i] = ')';
                if (d < 0) {
                    if (pq.isEmpty()) {
                        break;
                    }
                    int k[] = pq.poll();
                    if (k[0] == len - 1) {
                        if (pq.isEmpty()) {
                            break;
                        }
                        k = pq.poll();
                    }
                    res += A[k[1]][0] - A[k[1]][1];
                    tmp[k[0]] = '(';
                    d += 2;
                }
            } else {
                tmp[i] = '(';
                d++;
            }
        }
        if (d != 0) {
            pr.println(-1);
            pr.flush();
        } else {
            pr.println(res + "\n" + new String(tmp));
        }
        pr.flush();
    }

    static final class IN {

        private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = null;

        public static String readLine() throws IOException {
            return br.readLine();
        }

        public static String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    break;
                }
            }
            return st.nextToken();
        }

        public static int nextInt() {
            return Integer.valueOf(next());
        }

        public static long nextLong() {
            return Long.valueOf(next());
        }

        public static void close() {
            try {
                br.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
