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.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class LeastCostBracketSequence implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(System.out);
    
    private class Wildcard implements Comparable<Wildcard> {
        private int idx;
        private long diff;
        
        private Wildcard(int idx, long diff) {
            this.idx = idx;
            this.diff = diff;
        }

        @Override
        public int compareTo(Wildcard o) {
            return Long.compare(this.diff, o.diff);
        }
    }

    public void solve() {
        char[] x = in.next().toCharArray();
        PriorityQueue<Wildcard> queue = new PriorityQueue<>();
        int n = x.length, cost = 0;
        long result = 0;
        for (int i = 0; i < n; i++) {
            if (x[i] == '(')  {
                cost++;
            } else if (x[i] == ')') {
                cost--;
            } else {
                long left = in.ni(), right = in.ni();
                queue.offer(new Wildcard(i, left - right));
                result += right;
                x[i] = ')';
                cost--;
            }
            
            if (cost < 0) {
                if (queue.isEmpty()) {
                    out.println(-1);
                    return;
                } else {
                    Wildcard top = queue.poll();
                    x[top.idx] = '(';
                    result += top.diff;
                    cost += 2;
                }
            }
        }
        if (cost > 0) {
            out.println(-1);
        } else {
            out.println(result);
            for (char c : x) out.print(c);
        }
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close(); 
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) throws IOException {
        try (LeastCostBracketSequence instance = new LeastCostBracketSequence()) {
            instance.solve();
        }
    }
}
