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

    public static class Paren implements Comparable<Paren> {
        int cost;
        int position;

        Paren(int aCost, int aPosition) {
            this.cost = aCost;
            this.position = aPosition;
        }

        /**
        * We are comparing switch cost, so we
        * need to find a way to sort each paren
        * and give it priority.
        */
        @Override
        public int compareTo(Paren paren) {
            return this.cost - paren.cost;
        }
    }

    static Comparator<Paren> comparator = new Comparator<Paren>() {
        @Override
        public int compare(Paren p1, Paren p2) {
            return p2.cost - p1.cost;
        }
    };

    public static void main(String[] args) throws IOException {

        Scanner scanner = new Scanner(System.in);

        long cost = 0;
        int sequenceBalance = 0;
        char[] sequence = scanner.nextLine().toCharArray();
        int sequenceLength = sequence.length;

        Queue<Paren> parens = new PriorityQueue<Paren>();

        if((sequenceLength ^ 1) == 1) {
            System.out.println(-1);
            System.exit(0);
        }

        /**
        * If the symbol we check for isn't known to be a ')'
        * or a '(', then we make a greedy assumption that for
        * every ? we run into, it's best to make it a closed
        * paren.
        */
        for(int i = 0; i < sequenceLength; i++) {
            if(sequence[i] == '(') {
                sequenceBalance++;
            }
            else if (sequence[i] == ')') {
                sequenceBalance--;
            }
            else {
                // make a greedy assumption
                sequence[i] = ')';
                sequenceBalance--;
                int left = scanner.nextInt();
                int right = scanner.nextInt();
                parens.offer(new Paren(left - right, i));
                cost += right;
            }

            if(sequenceBalance  < 0) {
                if(parens.size() == 0) {
                    System.out.println(-1);
                    System.exit(0);
                }

                Paren paren = parens.poll();
                sequence[paren.position] = '(';
                cost += paren.cost;
                sequenceBalance += 2;
            }
        }

        if(sequenceBalance == 0) {
            System.out.println(cost);
            System.out.println(sequence);
        }
        else {
            System.out.println(-1);
        }

        System.exit(0);
    }
}