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

public class Main {

    // Placeholder for parens in priority queue
    public static class Paren implements Comparable<Paren> {
        public int index;
        public int cost;
        public Paren(int i, int c) {
            index = i;
            cost = c;
        }

        @Override
        public int compareTo(Paren o) {
            return cost - o.cost;
        }
    }

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

        StringBuilder x = new StringBuilder(reader.readLine());

        int numOpen = 0;
        long cost = 0;
        Queue<Paren> pending = new PriorityQueue<Paren>();
        boolean complete = true;

        for (int i=0; i<x.length(); ++i) {
            char curr = x.charAt(i);
            // Keeps running count of open parens.
            if (curr == '(')
                ++numOpen;
            else if (curr == ')')
                --numOpen;
            else {
                // Break if parens are closed before being opened.
                if (numOpen < 0) {
                    complete = false;
                    break;
                }

                // Read in next line
                String[] line = reader.readLine().split(" ");
                int openCost = Integer.parseInt(line[0]);
                int closeCost = Integer.parseInt(line[1]);

                // Temporarily set a closing paren.
                x.setCharAt(i, ')');
                cost += closeCost;
                --numOpen;

                // Add open paren to queue with difference in cost.
                pending.add(new Paren(i, openCost - closeCost));
                }

            if (numOpen < 0){
                // If parens are pending and more need to be opened, open one.
                if (!pending.isEmpty()){
                    Paren currParen = pending.poll();
                    x.setCharAt(currParen.index, '(');
                    cost += currParen.cost;
                    numOpen += 2;
                }
                // Otherwise, the string is invalid.
                else {
                    complete = false;
                    break;
                }
            }
        }

        // If everything went correctly, print the new string.
        if (numOpen == 0 && complete) {
            System.out.println(cost);
            System.out.println(x);
        }
        // If anything failed, print a failure.
        else
            System.out.println(-1);
    }
}
