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.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws FileNotFoundException, IOException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();

	}
}

class Pair implements Comparable<Pair> {
	long cost;
	int idx;

	Pair(long cost, int second) {
		this.cost = cost;
		idx = second;
	}

	@Override
	public int compareTo(Pair e) {
		if (this.cost != e.cost) {
			return Long.compare(this.cost, e.cost);
		} else {
			return Integer.compare(this.idx, e.idx);
		}
	}
}

// can be solved using dp but exceeds time limit
// hence to be solved greedily
class TaskB {
	long INF = (long) 1e15;
	int MAX_N = (int) 1e5 + 5;
	long mod = (long) 1e8;
	ArrayList<Pair> edges[];

	void solve(int testNumber, InputReader in, PrintWriter pw) {
		String s = in.next();
		char ans[] = new char[s.length()];
		long cost = 0;
		long change[] = new long[s.length()];
		for (int i = 0; i < s.length(); ++i) {
			char cur = s.charAt(i);
			if (cur == '?') {
				long a = in.nextLong();
				long b = in.nextLong();
				if (a < b) {
					cost += a;
					change[i] = b - a;
					ans[i] = '(';
				} else {
					cost += b;
					change[i] = a - b;
					ans[i] = ')';
				}
			} else {
				change[i] = INF;
				ans[i] = cur;
			}
		}
		int bal = 0;
		TreeSet<Pair> ord = new TreeSet<Pair>();
		for (int i = 0; i < s.length(); ++i) {
			if (ans[i] == '(') {
				bal++;
			} else {
				bal--;
				ord.add(new Pair(change[i], i));
			}
			if (bal < 0) {
				Pair rem = ord.first();
				ord.remove(rem);
				ans[rem.idx] = '(';
				bal += 2;
				cost += rem.cost;
			}
		}
		bal = 0;
		ord.clear();
		for (int i = s.length() - 1; i >= 0; --i) {
			if (ans[i] == ')') {
				bal++;
			} else {
				bal--;
				ord.add(new Pair(change[i], i));
			}
			if (bal < 0) {
				Pair rem = ord.first();
				ord.remove(rem);
				ans[rem.idx] = ')';
				bal += 2;
				cost += rem.cost;
			}
		}
		if (cost >= INF) {
			pw.println(-1);
		} else {
			pw.println(cost);
			for (int i = 0; i < s.length(); ++i) {
				pw.print(ans[i]);
			}
		}
	}

	long pow(int n, int m) {
		if (m == 0)
			return 1;
		long ans = pow(n, m / 2);
		ans = (ans * ans);
		if (m % 2 == 1) {
			ans = (ans * n);
		}
		return ans;
	}

	double pow(double n, int m) {
		if (m == 0)
			return 1;
		double ans = pow(n, m / 2);
		ans = (ans * ans);
		if (m % 2 == 1) {
			ans = (ans * n);
		}
		return ans;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}