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

public class Main implements Runnable {
        class Open implements Comparable<Open>{
            int cost, index;
            Open(int c, int i){cost = c; index = i;}
            
            @Override
            public int compareTo(Open b){
                if(cost != b.cost) return cost - b.cost;
                return index - b.index;
            }
        }
	public void solve() throws IOException {
		char[] c = nextToken().toCharArray();
                
                if(c.length % 2 == 1){
                    out.println(-1); return;
                }
                
                int k = 0;
                long cost = 0;
                TreeSet<Open> ts = new TreeSet<>();
                for(int i = 0; i < c.length; i++){
                    if(c[i] == '?'){
                        int op = nextInt();
                        int cl = nextInt();
                        c[i] = ')';
                        k--;
                        cost += cl;
                        ts.add(new Open(op - cl, i));
                    }
                    else if(c[i] == '('){
                        k++;
                    }
                    else k--;
                    
                    if(k < 0){
                        if(ts.isEmpty()){
                            out.println(-1); return;
                        }
                        Open op = ts.pollFirst();
                        //out.println(" " + k + " " + i + " " + op.cost + " " + op.index);
                        c[op.index] = '(';
                        cost += op.cost;
                        k += 2;
                    }
                }
                
                if(k != 0){
                    out.println(-1); return;
                }
                
                out.println(cost);
                out.println(new String(c));
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void debug(Object... arr){
            System.out.println(Arrays.deepToString(arr));
        }

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }
        
        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }
        
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
			tok = null;
			solve();
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}