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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Queue;


public class A3D {
	public static BufferedReader buffstdin = new BufferedReader(new InputStreamReader(System.in));
	static OutputStream out = new BufferedOutputStream ( System.out );
	
	//static ArrayList<String> stack = new ArrayList<String>();
	static int openB = 0;
	static int closeB = 0;
	static final String open = "(";
	static final String close = ")";
	static final String q = "?";
	static long opens = 0;
	static long closes = 0;
	static long price = 0;
	
	static ArrayList<Integer> Qs = new ArrayList<Integer>();
	static Queue<qPoint> qPoints = new PriorityQueue<qPoint>();
	
	public static void print(String s) throws IOException {
		s = s + "\n";
		out.write(s.getBytes());
	}
	public static void print(int s) throws IOException {
		print("" + s);
	}
	
	public static int openAt(String[] sequence, int limit) {
		openB = 0;
		int curOpen = 0;
		closeB = 0;
		for(int i=0; i<limit; i++) {
			if(sequence[i].equals(open)) {
				openB++;
				curOpen++;
			}
			else if(sequence[i].equals(close)) {
				closeB++;
				curOpen--;
				if(curOpen < 0) return -1; 
			}
			else return -1;
		}
		return curOpen;
	}
	
	public static boolean isValid(String[] sequence) throws IOException {
		openB = 0;
		int curOpen = 0;
		closeB = 0;
		for(int i=0; i<sequence.length; i++) {
			if(sequence[i].equals(open)) {
				openB++;
				curOpen++;
			}
			else if(sequence[i].equals(close)) {
				closeB++;
				curOpen--;
				if(curOpen < 0) return false; 
			}
			else return false;
		}
		if(openB != closeB) {
			return false;
		}
		return true;
	}
	
	public static int getQs (String[] sequence) throws IOException {
		int count = 0;
		for(int i=0; i<sequence.length; i++) {
			if(sequence[i].equals(q)) {
				Qs.add(i);
				count++;
				sequence[i] = ")";
				closes++;
				String[] line = buffstdin.readLine().split(" ");
				int endPrice = Integer.valueOf(line[1]);
				int startPrice = Integer.valueOf(line[0]);
				price += endPrice;
				qPoints.add(new qPoint(i, startPrice-endPrice));
			}
			else if(sequence[i].equals(open)) {
				//print("Found the open");
				opens++;
			}
			else if(sequence[i].equals(close)) {
				closes++;
			}
			if(!qPoints.isEmpty() && closes > opens) {
				qPoint p = qPoints.poll();
				sequence[p.x] = "(";
				//print(p.x);
				price += p.priceChange;
				opens++;
				closes--;
				//print("Closes: " +closes + " Opens: " + opens);
				//printSequence(sequence);
			}
		}
		return count;
	}
	
	public static class qPoint implements Comparable<qPoint> {
		public int x;
		public long priceChange;
		public qPoint(int X, int P) {
			x=X;
			priceChange=P;
			
		}
		@Override
		public int compareTo(qPoint arg0) {
			return Long.signum(priceChange - arg0.priceChange);
		}
	}
	
	public static void printSequence(String[] sequence) throws IOException {
		for(int i=0; i<sequence.length; i++) {
			out.write(sequence[i].getBytes());
		}
		out.write("\n".getBytes());
	}
	
	public static void main(String[] args) throws IOException {
		String[] line = buffstdin.readLine().trim().split("");
		String[] sequence = Arrays.copyOfRange(line, 0, line.length);
		
		//printSequence(sequence);
		int totalQs = getQs(sequence);
		//printSequence(sequence);
		//int remaining = closes-opens;
		//print("Closes: " +closes + " Opens: " + opens);
		//print(remaining);
		//printSequence(sequence);
		

		//print(sequence[1]);
		if(closes - opens != 0 || !isValid(sequence)) {
			print(-1);
			//printSequence(sequence);
		}
		else {
			print("" + price);
			printSequence(sequence);
		}
		
		out.flush();
	}
}
