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

public class Problem3D {

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

        char sequence[] = input.readLine().toCharArray();

        if(sequence.length % 2 != 0) {
            System.out.println("-1");
            return;
        }
        long totalCost = 0;
        PriorityQueue<BracketCost> queue = new PriorityQueue<BracketCost>(1, new BracketCostComp());
        long bracketDepth = 0;
        for (int i = 0; i < sequence.length; i++) {
            if(sequence[i] == '(') {
                bracketDepth++;
            } else if (sequence[i] == ')') {
                bracketDepth--;
            } else if (sequence[i] == '?') {
                // do stuff
                String[] line = input.readLine().split(" ");
                int openCost = Integer.parseInt(line[0]);
                int closeCost = Integer.parseInt(line[1]);

                BracketCost bracketCost = new BracketCost();
                bracketCost.costChange = openCost - closeCost;
                bracketCost.loc = i;
                queue.add(bracketCost);

                bracketDepth--;
                sequence[i] = ')';
                totalCost += closeCost;
            }
            // unbalanced
            if(bracketDepth == -1) {
                if(queue.size() > 0) {
                    BracketCost minCost = queue.poll();
                    sequence[minCost.loc] = '(';
                    totalCost += minCost.costChange;
                    bracketDepth += 2;
                }
            } else if (bracketDepth < -1) {
                // too many
                break;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        // balanced
        if (bracketDepth == 0) {
            out.println(totalCost);
            for (int i = 0; i < sequence.length; i++) {
                out.print(sequence[i]);
            }
            out.print("\n");
        } else {
            // no solution
            out.println("-1");
        }
        out.close();
    }

    static class BracketCostComp implements Comparator<BracketCost> {

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

    static class BracketCost {
        int costChange;
        int loc;
        BracketCost() {}
    }
}
