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 Driver {

	public static class Cost implements Comparable<Cost> {
		int cost;
		int pos;

		Cost (int c, int p) {
			this.cost = c;
			this.pos = p;
		}

		public int compareTo(Cost c) {
			if (this.cost > c.cost) {
				return 1;
			}
			else {
				return -1;
			}
		}
	}

    public static void main(String[] args) throws IOException {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String expression = br.readLine();

        // if odd number of (), we know it is invalid
        if (expression.length() % 2 == 1) {
        	System.out.println("-1");
        	System.exit(0);
        }


        char[] seq = expression.toCharArray();
        Queue<Cost> costs = new PriorityQueue<Cost>();
        //if pcount != 0 in the end the )( are out of balance
        int pCount = 0;
        long cost = 0;

        for (int i = 0; i < seq.length; i++) {
        	switch (seq[i]){
        		case '(': 
        			pCount++;
        			break;
        		case ')':
					pCount--;
					break;
				case '?':
					// get corrisponding cost line
					String [] line = br.readLine().split(" ");
					int first = Integer.parseInt(line[0]);
					int second = Integer.parseInt(line[1]);
					costs.add(new Cost(first - second, i));
					seq[i] = ')';
					cost += second;
					pCount--;
        	}

        	if (costs.size() > 0 && pCount == -1) {
        		//out of balance so lets fix that
        		Cost c = costs.poll();
        		seq[c.pos] = '(';
        		cost += c.cost;
        		pCount += 2;
        	}
        	else if (pCount == -1) {
        		break;
        	}
        }

        if (0 == pCount) {
        	System.out.println(cost);
        	System.out.println(new String(seq));
        }
        else {
        	System.out.println("-1");
        }

        System.exit(0);
    }
}
