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
()()
//package assign3;


import java.io.IOException;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Created by William on 1/28/2015.
 * Read info, find ?'s, read the cost for each ? and add the location of the ? and the costs to the queue
 * keep track of total left and right paren already in.
 */
public class LCBracketSeq {


    static class paren implements Comparable<paren>{

        int index, cost;
        paren(int index, int cost)
        {
            this.index = index;
            this.cost = cost;
        }

        public int compareTo(paren two)
        {
            return cost - two.cost;
        }
    }


    public static void main(String args[]) throws IOException {

        Scanner console = new Scanner(System.in);
        PriorityQueue<paren> queue = new PriorityQueue<paren>();         ///queue based on cost, cheaper the better
        char[] sequence = console.next().toCharArray();                  //convert to char array
        //String revised = sequence.toString();
        StringBuilder revised = new StringBuilder();
        revised.append(sequence);
        long count = 0,cost = 0;
        int left, right;                        //count keeps track of number of parentheses
                                                                    //+ are left, - are right, an even number will be 0
        for(int i = 0; i < sequence.length; i++)
        {
            if(sequence[i] == '(')
                count++;
            else if(sequence[i] == ')')
                count--;
            else if(sequence[i] == '?')
            {
                left = console.nextInt();
                right = console.nextInt();
                revised.setCharAt(i, ')');  //put in closing parentheses everywhere, then you only have to replace the
                queue.add(new paren(i, left-right));     //ones where ( is cheap,
                cost+= right;                      //paren cost in queue is left-right because if you only keep track
                count--;                           //of left, you lose the cost difference of the two when replacing
            }                                      // ')' for '(' and you'll end up over/undervaluing a left or right paren

            if(count == -1 && !queue.isEmpty())
            {
                paren temp = queue.poll();                  //get the front of the queue
                revised.setCharAt(temp.index, '(');         //set the cheapest value into the pattern
                cost += temp.cost;
                count += 2;                                 //add 2 to skip the necessary closing paren
            }
            else if(count < 0)             //failed #65, if you have extra right braces at the end you're invalid
                break;                     //as there is no matching brace
        }
        if(count == 0){
            System.out.println(cost);
            System.out.println(revised);
        }
        else
            System.out.println(-1);
    }

}
