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;

public class LeastCostBracketSequence {

	// A class to keep track of the closing brackets placed,
	// in case they need to be switched. It will be used in 
	// a priority queue based on the difference between open and close.
	// so when a bracket needs to be switched the one with the best price
	// gain is selected. 
	public static class Price implements Comparable<Price>
	{
		public Integer index;
		public Integer open;
		public Integer close;
		public Integer diff;
		
		public Price(int i, int o, int c)
		{
			index = i;
			open = o;
			close = c;
			diff = c - o;
		}
		
		@Override
		public int compareTo(Price arg0) 
		{
			return arg0.diff.compareTo(this.diff);
		}
	}
	
	public static void main(String args[]) throws IOException
	{
		BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
		char[] sequence = console.readLine().toCharArray();
		
		if(sequence[0] == ')' || sequence[sequence.length-1] == '(' || sequence.length%2 == 1)
		{
			System.out.println("-1");
		}
		else
		{
			int balance = 0;
			long totalCost = 0;
			PriorityQueue<Price> closers = new PriorityQueue<Price>();
			
			// main loop, checks existing brackets and adjusts balance
			// accordingly
			for(int n=0; n<sequence.length; n++)
			{
				if(sequence[n] == '(')
					balance++;
				else if(sequence[n] == ')')
					balance--;
				else 
				{
					// it's a '?' so we can get the corresponding
					// bracket prices
					String[] tempPrices = console.readLine().split(" ");
					
					// always add a closing bracket, we'll check the balance after
					sequence[n] = ')';
					balance--;
					totalCost += Integer.parseInt(tempPrices[1]);
					
					// now a Price object needs to be added to the priority queue so 
					// we can switch this cell if we need to later. 
					closers.add(new Price(n, Integer.parseInt(tempPrices[0]), Integer.parseInt(tempPrices[1])));
				}
				
				// Now check the balance, if it's off, switch the cell that will lower the totalCost the most
				if(balance < 0)
				{
					if(balance == -1 && closers.size() > 0)
					{
						Price bestSwitch = closers.poll();
						
						sequence[bestSwitch.index] = '(';
						
						if((n+1)%2 == 0)
							balance++;
						else
							balance += 2;
						
						totalCost -= bestSwitch.diff;
					}
					else
					{
						System.out.println("-1");
						return;
					}
				}
			}
			
			if(balance == 0)
			{
				System.out.println(totalCost);
				System.out.println(sequence);
			}
			else
				System.out.println("-1");
		}
	}
}