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.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


public class Prob3D {

	static class Decision implements Comparable<Decision>
	{
		int index;
		int openCost;
		int closedCost;
		
		public Decision(int i, int o, int c)
		{
			this.index = i;
			this.openCost = o;
			this.closedCost = c;
		}
		
		public int getOpenSavings()	//How much benefit is there to choosing '(' instead of ')'
		{
			return this.closedCost - this.openCost;
		}
		
		public int getIndex()
		{
			return this.index;
		}

		public int getOpenCost() {
			return openCost;
		}

		public int getClosedCost() {
			return closedCost;
		}

		@Override
		public int compareTo(Decision arg0) {
			final int BEFORE = -1;
			final int EQUAL = 0;
			final int AFTER = 1;
			
			if(this.getOpenSavings() > arg0.getOpenSavings())
				return BEFORE;
			if(this.getOpenSavings() < arg0.getOpenSavings())
				return AFTER;
			return EQUAL;
		}	
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] sequence = br.readLine().toCharArray();
		StringTokenizer tokenizer = new StringTokenizer("");
		
		int openCount = 0;	//Number of '(' have we encountered
		int span = 0;		//Number of '?'s that have been put into pq
		int openCost = 0;
		int closedCost = 0;
		long totalCost = 0;
		Decision nextDecision = null;
		PriorityQueue<Decision> pq = new PriorityQueue<Decision>();
		
		for(int i=0; i<sequence.length; i++)
		{
			if(sequence[i]=='(')
				openCount++;
			else if(sequence[i] == ')')
				openCount--;
			else
			{
				span++;
				tokenizer = new StringTokenizer(br.readLine());
				openCost = Integer.parseInt(tokenizer.nextToken());
				closedCost = Integer.parseInt(tokenizer.nextToken());
				pq.add(new Decision(i, openCost, closedCost));
			}
			
			if(i==sequence.length-1 && (openCount!=span))	//If at end we have more open than we can close, no solution
			{
				totalCost = -1;
				break;
			}
			
			if(openCount<0 && span<=0)	//If more closed than can be opened, no solution
			{
				totalCost = -1;
				break;
			}	
			
			while(openCount-span < 0 && totalCost>-1)	//Can't all be ')' so assign '(' to most economical slots
			{
				nextDecision = pq.poll();
				sequence[nextDecision.getIndex()] = '(';
				totalCost += nextDecision.getOpenCost();
				openCount++;
				span--;
			}
		}
		
		if(totalCost < 0)		//No solution found
			System.out.println(-1);
		else
		{
			while(!pq.isEmpty())	//Remaining slots get ')'
			{
				nextDecision = pq.poll();
				sequence[nextDecision.getIndex()] = ')';
				totalCost += nextDecision.getClosedCost();
			}
			
			System.out.println(totalCost);
			System.out.println(sequence);
		}
	}
}
