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.*;

public class P003D {
    private static class RightBracket implements Comparable<RightBracket> {
        private int cost;
        private int pos;
        
        public RightBracket(int cost, int pos) {
            this.cost = cost;
            this.pos  = pos;
        }
        
        public int compareTo(RightBracket other) {
            return cost - other.cost;
        }
    }
    
    private static class Cost {
        private int openCost;
        private int closeCost;
        
        public Cost(int openCost, int closeCost) {
            this.openCost  = openCost;
            this.closeCost = closeCost;
        }
    }
        
    
    private String pattern = new String();
    private StringBuilder resultBuilder = new StringBuilder();
    
    private PriorityQueue<RightBracket> rBrackets = new PriorityQueue<RightBracket>();
    private ArrayList<Cost> bracketCosts = new ArrayList<Cost>();
    
    private long totalCost;
    
    private boolean replace() {
        if (rBrackets.isEmpty()) return false;
        RightBracket bracket = rBrackets.poll();
        resultBuilder.setCharAt(bracket.pos, '(');
        totalCost += bracket.cost;
        return true;
    }        
    
    public boolean solve() {
        Scanner sc = new Scanner(System.in);
        pattern = sc.next();
        
        while (sc.hasNext()) {
            int openCost  = sc.nextInt();
            int closeCost = sc.nextInt();
            bracketCosts.add(new Cost(openCost, closeCost));
        }
        
        int currIndex = 0;
        int balance   = 0;
        totalCost     = 0;
        for (int i = 0; i < pattern.length(); i++) {
            char c = pattern.charAt(i);
            if (c != '?') {
                resultBuilder.append(c);
                if (c == '(') balance++;
                else          balance--;
                assert balance >= -1;
                if (balance < 0) {
                    boolean status = replace();
                    if (!status) return false;
                    balance += 2;
                }
                continue;
            }
            resultBuilder.append(')');
            Cost cost = bracketCosts.get(currIndex++);
            rBrackets.add(new RightBracket(cost.openCost - cost.closeCost, i));
            totalCost += cost.closeCost;
            balance--;
            assert balance >= -1;
            
            if (balance < 0) {
                boolean status = replace();
                if (!status) return false;
                balance += 2;
            }
        }
        
        if (balance != 0) return false;
        
        System.out.printf("%d\n%s\n", totalCost, resultBuilder.toString());
        return true;
    }
    
    public static void main(String[] argv) {
        P003D solution = new P003D();
        boolean status = solution.solve();
        if (!status) {
            System.out.printf("-1\n");
        }
    }
}