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 main;

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        StringBuffer outBuffer = new StringBuffer();
        
        //TODO: implement brute force? (O(n^2), n = 5*10^4)
        
        //BaseCost arrayList
        //CostDifferential arrayList
        SortedSet<Cost> cost = new TreeSet<Cost>();
        
        //Base character array
        char[] sequence = Reader.next().toCharArray();
        
        long totalCost = 0;
        int options = 0;
        int openBrackets = 0;
        
        //TODO: Pre-find last mandatory close bracket (including forced ?)
            //If the last ? is about to be added, it had 
        //Check that length is even for runtime
        if(sequence.length % 2 == 0) {
            //iteration process
            for(int n = 0; n < sequence.length; n++) {
                //If it is ?, add to options
                if(sequence[n] == '?') {
                    //Get the weights from input
                    int open = Reader.nextInt();
                    int close = Reader.nextInt();
                    cost.add(new Cost(open, close, n));
                    options++;
                } else {
                    //Else openBrackets count
                    if(sequence[n] == '(') {
                        openBrackets++;
                    } else {
                        openBrackets--;
                        //If openBrackets < 0, impossible.  Break.
                        if(openBrackets < 0) {
                            break;
                        }
                    }
                }
                
                //If options > openBrackets, 
                if(options > openBrackets) {                    
                    //Get the cheapest
                    Cost cheapest = cost.first();
                    //Apply weight
                    totalCost+=cheapest.open;
                    //Mark the open bracket in sequence
                    sequence[cheapest.id] = '(';
                    openBrackets++;
                            
                    cost.remove(cheapest);
                    options--;
                }
            }
            
            //Fill remaining spaces with close brackets.  
            while(cost.size() > 0) {
                Cost next = cost.first();
                
                //Apply weight.
                totalCost+=next.close;
                //Mark in sequence
                sequence[next.id] = ')';
                openBrackets--;
                
                cost.remove(next);
            }
                
            //Check to make sure sequence is balanced
            if(openBrackets == 0) {
                outBuffer.append(totalCost);
                outBuffer.append("\n");
                outBuffer.append(sequence);

            } else {
                outBuffer.append(-1);
            }
            
        } else {
            outBuffer.append(-1);
        }
        
        System.out.println(outBuffer);
    }
}

class Cost implements Comparable<Cost> {
    public int open;
    public int close;
    public int id;
    
    public int diff() {
        return open - close;
    }
    
    Cost(int openIn, int closeIn, int idIn) {
        open = openIn;
        close = closeIn;
        id = idIn;
    }
    @Override public int compareTo(Cost aThat) {
        final int BEFORE = -1;
        final int EQUAL = 0;
        final int AFTER = 1;
        
        if(this == aThat) return EQUAL;
        
        if(this.diff() < aThat.diff()) return BEFORE;
        if(this.diff() > aThat.diff()) return AFTER;
        
        if(this.id < aThat.id) return BEFORE;
        if(this.id > aThat.id) return AFTER;
        
        return EQUAL;
    }
}

// Class for buffered reading int and double values 
//Mad props go out to: http://www.cpe.ku.ac.th/~jim/java-io.html
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    //call this method to initialize reader for InputStream
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    //get next word
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
	
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}