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

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.PriorityQueue;

public class Problem3D {

	public static class Unknown implements Comparable<Unknown>{
		int position,
			open_cost,
			closing_cost,
			difference;
		
		public Unknown(int p){
			position = p;
		}
		public Unknown(int p, int d){
			position =  p;
			difference = d;
		}
		public String toString(){
			return "Pos: " + position + " O: " + open_cost + " C: " + closing_cost + "\n";
		}
		
		@Override
		public int compareTo(Unknown u) {
			return difference - u.difference;
		}
	}
	
	public static void main(String[] args) throws java.lang.Exception {
		BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
		char[] parens = buffer.readLine().toCharArray();
		
		ArrayList<Unknown> unknowns = new ArrayList<Unknown>();
		
		//Get number of ?
		for( int i=0; i<parens.length; i++ ) {
			if(parens[i] == '?' ) unknowns.add(new Unknown(i));
		}
		//Get costs
		for(int i=0; i<unknowns.size(); i++){
			String[] input = buffer.readLine().trim().split("\\s");
			unknowns.get(i).open_cost = Integer.parseInt(input[0]);
			unknowns.get(i).closing_cost = Integer.parseInt(input[1]);
		}
		
		int count=0;
		int count_min=0;
		int count_min_idx=0;
		for( int i=0, u=0; i<parens.length; i++ ){
			if(parens[i] == '(') count++;
			else if(parens[i] == ')' ) { 
				count--;
				if(count < count_min) {
					count_min = count;
					count_min_idx = i;
				}					
			}else {	
				Unknown x = unknowns.get(u);
				u++;
				if(x.closing_cost >= x.open_cost){
					// Opening paren
					count++;
				} else {
					count--;
					if(count < count_min) {
						count_min = count;
						count_min_idx = i;
					}
				}
			}
		}
		
		count = 0;
		long sol_cost = 0;
		
		PriorityQueue<Unknown> unkns = new PriorityQueue<Unknown>();
		
		for( int i=0,u=0; i<=count_min_idx; i++ ){
			if( parens[i] == '(' ) count++;
			else if( parens[i] == ')' ) { 
				count--;
			}else{
				Unknown x = unknowns.get(u);
				u++;
				if( x.closing_cost > x.open_cost ){
					//Try to do opening brace
					parens[x.position] = '(';
					sol_cost += x.open_cost;
					count++;
				} else {
					//Try to do closing brace
					parens[x.position] = ')';
					sol_cost += x.closing_cost;
					count--;
					unkns.add(new Unknown(x.position, x.open_cost - x.closing_cost));
				}
			}
			if(count < 0){
				//There's a balancing problem
				Unknown xb = unkns.poll();
				if(xb == null){
					System.out.println("-1");
					return;
				}
				parens[xb.position] = '(';
				count += 2;
				sol_cost +=xb.difference;
			}
		}
		unkns.clear();
		int u = unknowns.size()-1;
		count =0;
		for( int i=parens.length-1; i>=count_min_idx; i-- ){
			if( parens[i] == '(' ) count--;
			else if( parens[i] == ')' ) { 
				count++;
			}else{
				Unknown x = unknowns.get(u);
				u--;
				if( x.open_cost > x.closing_cost ){
					//Try to do closing brace
					parens[x.position] = ')';
					sol_cost += x.closing_cost;
					count++;				
				}else{
					//Try to do opening brace
					parens[x.position] = '(';
					sol_cost += x.open_cost;
					count--;
					unkns.add(new Unknown(x.position, x.closing_cost - x.open_cost));
				}  
			}
			if(count < 0){
				//There's a balance problem
				Unknown xb = unkns.poll();
				if(xb == null){
					System.out.println("-1");
					return;
				}
				parens[xb.position] = ')';
				count += 2;
				sol_cost +=xb.difference;
			}
		}
		
		System.out.println(sol_cost);
		System.out.println(String.copyValueOf(parens));
	}

}
