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

public class Main{

    public static class Position implements Comparable<Position>{
        char character;
        int difference;
        boolean changeable;
        int location;

        Position(char newCharacter, int newDif, boolean newChangeable, int newLocation){
            this.character = newCharacter;
            this.difference = newDif; //how much we'll gain by changing from rp to lp
            this.changeable = newChangeable; //whether we are allowed to alter this
            this.location = newLocation;
        }

        @Override
        public int compareTo(Position P){
            return P.difference - this.difference;
        }
    }

    public static String inputString =  null;
    public static int leftPNum = 0;
    public static int rightPNum = 0;
    public static Long totalCost = 0L;
    public static PriorityQueue<Position> maxHeap = new PriorityQueue<Position>();

    public static void main(String[] args){
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String startString = null;
        char[] inputArray;
        String[] parsedString;
        boolean illegal = false;

        try {
            inputString = in.readLine();
        } catch (Exception e) {
        }
        inputArray = inputString.toCharArray();

        for(int i=0; i<inputArray.length; i++){
            if(inputArray[i]=='('){
                leftPNum++;
            }
            else if(inputArray[i]==')'){
                rightPNum++;
            }
            else{
                try {
                    startString = in.readLine();
                } catch (Exception e) {
                }
                parsedString = startString.split(" ");
                //we are initially going to assume that the best circumstance in all right parens
                maxHeap.offer(new Position(')',Integer.parseInt(parsedString[1])-Integer.parseInt(parsedString[0]), true, i));
                inputArray[i]=')';
                rightPNum++;
                totalCost += Long.parseLong(parsedString[1]);
            }

            if(rightPNum - leftPNum > 0){
                if(maxHeap.size()==0){ //if we need to replace something but there is nothing to replace, ie ())?
                    illegal = true;
                    break;
                }

                Position replacePos = maxHeap.poll();
                inputArray[replacePos.location]='(';
                totalCost -= replacePos.difference;
                leftPNum++;
                rightPNum--;
            }
        }

        if(rightPNum != leftPNum || illegal==true){
            System.out.println(-1);//check if a solution couldn't be found
        }
        else {
            System.out.println(totalCost);
            System.out.println(inputArray);
        }
    }

}
