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.PriorityQueue;
import java.util.Scanner;

// Heavy inspiration from http://www.darrensun.com/codeforces-round-3/
//  Code is original, algorithm is not.
public class BracketSequence {

	/*
	 * Holds the position of, and benefit that would be gained by,
	 *  replacing a closing bracket with an opening one.
	 * All entries of this class will be ? entries in original
	 *  string that have been replaced by ), and may at some
	 *  point be re-replaced by a (.
	 */
	public static class OpeningBracket implements Comparable<OpeningBracket> {
		int _index;
		int _benefitGained;
		
		public OpeningBracket(int index, int benefitGained) {
			_index = index;
			_benefitGained = benefitGained;
		}
		
		@Override
		public int compareTo(OpeningBracket other) {
			return _benefitGained - other._benefitGained;
		}
	}
	
	public static void main(String[] args) {
		// Input string
		Scanner in = new Scanner(System.in);
		char[] inputString = in.nextLine().toCharArray();
		
		// Go through list, inserting ) at every position
		//  This WILL result in an unbalancing of the string. As soon as it is unbalanced,
		//  re-balance it by replacing a previously placed ')' with a '('.
		// Determine which one to use by taking it off the priority queue - this will ensure
		//  the most valuable replacement at all times.
		// List is invalid if the string is unbalanced, but there are no remaining
		//  opening paren options.
		PriorityQueue<OpeningBracket> replacementOptions = new PriorityQueue<>();
		
		int nL = 0;
		long cost = 0;
		for (int i = 0; i < inputString.length; i++) {
			if (inputString[i] == '('){
				nL++;
			} else if (inputString[i] == ')') {
				nL--;
			} else {
				// Replace with ')'...
				inputString[i] = ')';
				nL--;
				int leftCost = in.nextInt(), rightCost = in.nextInt();
				cost += rightCost;
				replacementOptions.offer(new OpeningBracket(i, leftCost - rightCost));
			}
			
			if (nL < 0) {
				// Not okay! Fix it!
				OpeningBracket ob = replacementOptions.poll();
				if (ob == null) {
					// Can't fix it! Invalid.
					System.out.println(-1);
					return;
				} else {
					inputString[ob._index] = '(';
					cost += ob._benefitGained;
					nL += 2; // 1 for removing ')', 1 for adding '('
				}
			}
		}
		
		if(nL == 0) {
			System.out.println(cost);
			System.out.println(inputString);
		} else {
			System.out.println(-1);
		}
		
		in.close();
	}

}
