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

public class D {

	static Scanner in = new Scanner(new BufferedInputStream(System.in));
	static PrintWriter out = new PrintWriter(System.out);
	static int oo = 1000000000;

	public static void main(String[] args) throws IOException {
		/*
		 * Reading input and calculating changeCosts.
		 */
		char[] s = nextString();
		int n = s.length;
		int[] left = new int[n], right = new int[n], changeCost = new int[n];
		for (int i = 0; i < n; i++) {
			if (s[i] == '?') {
				left[i] = in.nextInt();
				right[i] = in.nextInt();
				s[i] = left[i] < right[i] ? '(' : ')';
				changeCost[i] = Math.abs(left[i] - right[i]);
			} else {
				left[i] = right[i] = 0;
				changeCost[i] = oo;
			}
		}

		/*
		 * Align left and right brake count.
		 */
		TreeSet<Pair> leftCosts = new TreeSet<Pair>(),
				rightCosts = new TreeSet<Pair>();
		int leftNumber = 0, rightNumber = 0;
		for (int i = 0; i < n; i++) {
			//out.print(i + ": ");
			if (s[i] == '(') {
				if (left[i] > 0) {
					leftCosts.add(new Pair(changeCost[i], i));
				}
				leftNumber++;
				//out.println("left, " + changeCost[i]);
			} else {
				if (left[i] > 0) {
					rightCosts.add(new Pair(changeCost[i], i));
				}
				rightNumber++;
				//out.println("right, " + changeCost[i]);
			}
		}

		int d = Math.abs(leftNumber - rightNumber) / 2;
		TreeSet<Pair> costs =
				leftNumber < rightNumber ? rightCosts : leftCosts;
		for (int i = 0; i < d; i++) {
			if (costs.isEmpty()) {
				out.println(-1);
				out.close();
				return;
			}
			int p = costs.first().pos;
			s[p] = (char) ('(' + ')' - s[p]);
			costs.remove(costs.first());
		}

		//out.println(s);

		/*
		 * Fixing the balance.
		 */
		for (int i = 0; i < 2; i++) {
			// Fixing.
			leftCosts = new TreeSet<Pair>();
			rightCosts = new TreeSet<Pair>();
			for (int j = 0; j < n; j++) {
				if (s[j] == '(') {
					leftCosts.add(new Pair(right[j] > 0 ? right[j] - left[j] : oo, j));
				}
			}

			int bal = 0;
			for (int j = 0; j < n; j++) {
				if (s[j] == ')') {
					rightCosts.add(new Pair(right[j] > 0 ? left[j] - right[j] : oo, j));
				} else {
					leftCosts.remove(new Pair(right[j] > 0 ? right[j] - left[j] : oo, j));
				}

				/*
				out.println(j + ":");
				out.println(s);
				out.println("existing )");
				for(Pair p : rightCosts) {
				out.println(p.cost + ", " + p.pos);
				}
				out.println("existing (");
				for(Pair p : leftCosts) {
				out.println(p.cost + ", " + p.pos);
				}*/

				bal += s[j] == '(' ? 1 : -1;
				/*out.println("balance: " + bal);
				out.println();
				out.flush();*/
				if (bal == -1) {
					try {
						if (rightCosts.first().cost == oo
								|| leftCosts.first().cost == oo) {
							out.println(-1);
							out.close();
							return;
						}
					} catch (Exception e) {
						//out.println(i + " --- " + j);
						//out.flush();
					}
					int toLeft = rightCosts.first().pos,
							toRight = leftCosts.first().pos;
					s[toLeft] = '(';
					s[toRight] = ')';
					bal = 1;
					rightCosts.remove(rightCosts.first());
					leftCosts.remove(leftCosts.first());
				}
			}

			// Reversing.
			for (int j = 0; j < n / 2; j++) {
				char t = (char) ('(' + ')' - s[n - j - 1]);
				s[n - j - 1] = (char) ('(' + ')' - s[j]);
				s[j] = t;
			}
		}

		/*
		 * Calculating answer.
		 */
		long totalCost = 0;
		for (int i = 0; i < n; i++) {
			totalCost += s[i] == '(' ? left[i] : right[i];
		}
		out.println(totalCost);
		out.println(s);
		out.close();
	}

	static char[] nextString() {
		String s = in.next();
		char[] cs = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			cs[i] = s.charAt(i);
		}
		return cs;
	}

	private static class Pair implements Comparable<Pair> {

		int cost, pos;

		public Pair(int cost, int pos) {
			this.cost = cost;
			this.pos = pos;
		}

		public int compareTo(Pair p) {
			if (cost < p.cost) {
				return -1;
			} else if (cost > p.cost) {
				return 1;
			} else {
				return ((Integer) pos).compareTo(p.pos);
			}
		}
	}
}
