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

public class Solution {
	public static PrintWriter w = new PrintWriter(System.out);
	public static long tc = 0;
	public static long INF = 1000000000000L;
	public static void main(String args[] ) throws Exception {
		Reader in = new Reader();
		char[] arr = in.next().toCharArray();
		long[] cc = new long[arr.length];
		for (int i=0; i<arr.length; i++) {
			if(arr[i] == '?') {
				long a = in.nextLong();
				long b = in.nextLong();
				if(a < b) {
					arr[i] = '(';
					tc += a;
					cc[i] = (b-a);
				} else {
					arr[i] = ')';
					tc += b;
					cc[i] = a - b;
				}
			} else
				cc[i] = INF;
		}
		int balance = 0;
		int n = arr.length;
		TreeSet<pair> set = new TreeSet<>();
		for (int i=0; i<n; i++) {
			if(arr[i] == ')') {
				set.add(new pair(cc[i],i));
				--balance;
			} else 
				++balance;
			if(balance < 0) {
				pair use = set.first();
				set.remove(use);
				tc += use.cost;
				arr[use.index] = '(';
				balance += 2;
			}
		}
		set.clear();
		balance = 0;
		for (int i=n-1; i>=0; --i) {
			if(arr[i] == '(') {
				set.add(new pair(cc[i],i));
				--balance;
			} else
				++balance;
			if(balance < 0) {
				pair use = set.first();
				set.remove(use);
				tc += use.cost;
				balance += 2;
				arr[use.index] = ')';
			}
		}
		 if(balance != 0)
		 	throw new RuntimeException();
		if(tc >= INF)
			w.println("-1");
		else {
			w.println(tc);
			w.println(arr);
		}
		w.flush();
		return;
	}
}
class pair implements Comparable<pair>{
	public long cost;
	public int index;
	public pair(long cost, int index) {
		this.cost = cost;
		this.index = index;
	}
	public int compareTo(pair p) {
		if(this.cost < p.cost)
			return -1;
		else if(this.cost > p.cost)
			return 1;
		else if(this.index < p.index)
			return -1;
		else if(this.index > p.index)
			return 1;
		else
			return 0; 
	}
}

class Reader {
	final private int BUFFER_SIZE = 1 << 16;
	private DataInputStream din;
	private byte[] buffer;
	private int bufferPointer, bytesRead;

	public Reader() {
		din = new DataInputStream(System.in);
		buffer = new byte[BUFFER_SIZE];
		bufferPointer = bytesRead = 0;
	}
	public String nextLine() throws IOException {
		int c = read();
		while(isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while(!isEndOfLine(c));
		return res.toString();
	}
	public String next() throws IOException {
		int c = read();
		while(isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while(!isSpaceChar(c));
		return res.toString();
	}
	public int nextInt() throws IOException {
		int ret = 0;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}
	public int[] nextIntArray(int n) throws IOException {
		int a[] = new int[n];
		for(int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}
	public int[][] next2dIntArray(int n, int m) throws IOException {
		int a[][] = new int[n][m];
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				a[i][j] = nextInt();
		return a;
	}
	public char nextChar() throws IOException {
		return next().charAt(0);
	}
	public long nextLong() throws IOException {
		long ret = 0;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}
	public double nextDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (c == '.') {
			while((c = read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}
		if(neg)
			return -ret;
		return ret;
	}
	private void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if(bytesRead == -1)
			buffer[0] = -1;
	}
	private byte read() throws IOException {
		if(bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}
	public void close() throws IOException {
		if(din == null)
			return;
		din.close();
	}
	public boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
	private boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}
}