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.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class Main implements Runnable {	
	
	void solve() throws IOException {
		String s = nextString();
		int diff = 0;
		long answer = 0;
		StringBuilder sb = new StringBuilder(s);
		PriorityQueue<Pair> q = new PriorityQueue<Pair>();
		skip: for (int i = 0; i < s.length(); ++i) {
			switch (s.charAt(i)) {
			case '(':
					++diff;
				break;
			case ')':
					--diff;
				break;

			default:
					int a = nextInt();
					int b = nextInt();
					answer += b;
					--diff;
					sb.setCharAt(i, ')');
					q.add(new Pair(a-b, i));
				break;
			}
			if (diff < 0) {
				if (q.isEmpty()) {
					answer = -1;
					break skip;
				}
				Pair top = q.poll();
				answer += top.amb;
				sb.setCharAt(top.position, '(');
				diff += 2;
			}
		}
		if (diff != 0) {
			answer = -1;
		}
		writer.println(answer);
		if (answer != -1) {
			writer.print(sb.toString());
		}
	}
	
	class Pair implements Comparable<Pair> {
		
		public Pair(int amb, int position) {
			this.amb = amb;
			this.position = position;
		}
		
		@Override
		public int compareTo(Pair o) {
			return amb - o.amb;
		}
		
		int amb;
		int position;
	}
	
	public static void main(String[] args) throws InterruptedException {
		 new Thread(null, new Runnable() {
            public void run() {
                new Main().run();
            }
	     }, 
	     "1", 
	     1 << 25).start();
	}
	
	@Override
	public void run() {
		try {
			boolean fromStandart = System.getProperty("ONLINE_JUDGE") != null;
			reader = new BufferedReader(fromStandart ? new InputStreamReader(System.in) : new FileReader(INFILE));
            writer = new PrintWriter(new BufferedWriter(fromStandart ? new OutputStreamWriter(System.out) : new FileWriter(OUTFILE)));
			tokenizer = null; 
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}
	
	static final String INFILE = "input.txt";
	static final String OUTFILE = "output.txt";
	
	BufferedReader reader;
	StringTokenizer tokenizer;
    PrintWriter writer;

	int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    
    String nextString() throws IOException {
    	return reader.readLine();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    } 	

}
