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

public class P4 {
    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    static class PQItem implements Comparable<PQItem> {
        final int index;
        final int delta;

        public PQItem(int index, int delta) {
            this.index = index;
            this.delta = delta;
        }

        public int compareTo(PQItem o) {
            return delta - o.delta;
        }
    }

    public void solve() throws IOException {
        char[] seq = next().toCharArray();
        PriorityQueue<PQItem> queue = new PriorityQueue<PQItem>();

        long sum = 0;
        int balance = 0;

        for (int i = 0; i < seq.length; ++i) {
            if (seq[i] == '?') {
                int open = nextInt();
                int close = nextInt();
                queue.add(new PQItem(i, open - close));
                seq[i] = ')';
                sum += close;
            }
            if (seq[i] == '(') {
                ++balance;
            } else {
                --balance;
            }
            if (balance < 0) {
                if (queue.isEmpty()) {
                    out.println(-1);
                    return;
                }
                PQItem best = queue.poll();
                seq[best.index] = '(';
                sum += best.delta;
                balance += 2;
            }
        }

        if (balance == 0) {
            out.println(sum);
            out.println(seq);
        } else {
            out.println(-1);
        }
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            out.close();
            in.close();
        } catch (IOException ex) {
            System.exit(1);
        }
    }

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

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

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

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

    String nextLine() throws IOException {
        st = null;
        return in.readLine();
    }

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