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.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class BracketSequence implements Runnable {
	private static final long INF = 10000000000000L;
	static class Changing implements Comparable<Changing>{
		int at;
		long cost;
		public Changing(int at, long cost) {
			this.at = at;
			this.cost = cost;
		}
		@Override
		public int compareTo(Changing ch) {
			if (this.cost < ch.cost) {
				return -1;
			} else if (this.cost > ch.cost) {
				return 1;
			} else if (this.at < ch.at) {
				return -1;
			} else if (this.at > ch.at) {
				return 1;
			} else {
				return 0;
			}
		}
	}
	private void solve() throws IOException {
		String s = nextToken();
		char[] seq = new char[s.length()];
		long cost = 0;
		long changeCost[] = new long[s.length()];
		for (int i = 0; i < s.length(); ++i) {
			char c = s.charAt(i);
			if (c == '?') {
				int a = nextInt();
				int b = nextInt();
				if (a < b) {
					seq[i] = '(';
					changeCost[i] = b - a;
					cost += a;
				} else {
					seq[i] = ')';
					changeCost[i] = a - b;
					cost += b;
				}
			} else {
				seq[i] = c;
				changeCost[i] = INF;
			}
		}
		TreeSet<Changing> changings = new TreeSet<Changing>();
		int balance = 0;
		for (int i = 0; i < seq.length; ++i) {
			if (seq[i] == ')') {
				--balance;
				changings.add(new Changing(i, changeCost[i]));
			} else {
				++balance;
			}
			if (balance < 0) {
				Changing first = changings.first();
				seq[first.at] = '(';
				cost += first.cost;
				changings.remove(first);
				balance += 2;
			}
		}
		changings.clear();
		balance = 0;
		for (int i = seq.length - 1; i >= 0; --i) {
			if (seq[i] == '(') {
				--balance;
				changings.add(new Changing(i, changeCost[i]));
			} else {
				++balance;
			}
			if (balance < 0) {
				Changing first = changings.first();
				seq[first.at] = ')';
				cost += first.cost;
				changings.remove(first);
				balance += 2;
			}
		}
		if (cost >= INF) {
			writer.println("-1");
		} else {
			writer.println(cost);
			for (int i = 0; i < seq.length; ++i) {
				writer.print(seq[i]);
			}
		}
	}
	public static void main(String[] args) {
		new BracketSequence().run();
	}
	StringTokenizer tokenizer;
	PrintWriter writer;
	BufferedReader reader;
	@Override
	public void run() {
		try {
			tokenizer = null;
			writer = new PrintWriter(System.out);
			reader = new BufferedReader(new InputStreamReader(System.in));
			solve();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	private String nextToken() throws IOException {
		while(tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	
	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

}
