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 Main
{
    // We'll need some sort of structure to hold the cost for each parenthesis
    static class Paren implements Comparable<Paren> {
	int index, cost;
	Paren(int c, int i)
	{
	    this.index = i;
	    this.cost = c;
	}
	@Override
	public int compareTo(Paren paren)
	{
	    return this.cost - paren.cost;
	}
    }

    public static void main(String args[])
    {
	Scanner in = new Scanner(System.in);
	char[] expression = in.nextLine().toCharArray();
	PriorityQueue<Paren> parens = new PriorityQueue<Paren>();
	// Count ?'s
	int n= 0 ;
	for(int i = 0; i < expression.length; i++)
	{
	    if(expression[i] == '?')
		n++;
	}
	// array to keep track of the two costs for each ?
	int cost[][] = new int[n][2];
	for(int i = 0; i < n; i++)
	{
	    cost[i][0] = in.nextInt();
	    cost[i][1] = in.nextInt();
	}
	
	// Now we'll proceed to count the expression from left to right,
	// assuming every ( is 1 and every ) is -1. We will evaluate the score
	// of each ? and assume each one to be what the smallest score would be
	//
	// We do all of this so we can find the point where our middle is. This is given by
	// the point we receive our lowest score on.
	int count = 0, countMin = 0, costCount = 0, indexMin = 0;
	for(int i = 0; i < expression.length; i++)
	{
	    if(expression[i] == '(')
		count++;
	    else if (expression[i] == ')')
	    {
		count--;
		if(count < countMin)
		{
		    countMin = count;
		    indexMin = i + 1;
		}
	    }
	    else if (expression[i] == '?')
	    {
		if(cost[costCount][0] < cost[costCount][1])
		    count++;
		else
		{
		    count--;
		    if(count < countMin)
		    {
			countMin = count;
			indexMin = i + 1;
		    }
		}
		costCount++;
	    }
	}

	// Now that we know the optimal middle of the expression, we can iterate through each side and
	// add our costs to our priority queue
	// Our queue will store all of our ) choices when going through the left. Once we get to a point where we have too many ), we will switch
	// the one with the least amount of difference in cost to (
	costCount = 0;
	count = 0;
	long totalCost = 0;
	for(int i = 0; i < indexMin; i++)
	{
	    if(expression[i] == '(')
		count++;
	    else if (expression[i] == ')')
		count--;
	    else
	    {
		 if (cost[costCount][0] < cost[costCount][1])
		 {
		     totalCost += cost[costCount][0];
		     expression[i] = '(';
		     count++;
		 }
		 else
		 {
		     totalCost += cost[costCount][1];
		     expression[i] = ')';
		     parens.add(new Paren(cost[costCount][0] - cost[costCount][1], i));
		     count--;
		 }
		 costCount++;
	    }
	    if(count < 0)
	    {
		Paren smallestParen = parens.poll();
		// If we can't find a right paren, then our expression is illegal
		if(smallestParen == null)
		{
		    System.out.println(-1);
		    return;
		}
		expression[smallestParen.index] = '(';
		count += 2; // We just swapped a right to a left
		totalCost += smallestParen.cost; // Add that difference in cost we just took on by swapping the paren
	    }
	}
	// This next part is basically the last one but we're going from the right and swapping ) with (
	count = 0;
	parens.clear();
	costCount = cost.length - 1;
	for(int i = expression.length - 1; i >= indexMin; i--)
	{
	    if(expression[i] == '(')
		count--;
	    else if(expression[i] == ')')
		count++;
	    else
	    {
		if(cost[costCount][0] >= cost[costCount][1])
		{
		    totalCost += cost[costCount][1];
		    expression[i] = ')';
		    count++;
		}
		else
		{
		    totalCost += cost[costCount][0];
		    expression[i] = '(';
		    parens.add(new Paren(cost[costCount][1] - cost[costCount][0], i));
		    count--;
		}
		costCount--;
	    }
	    if ( count < 0)
	    {
		Paren smallestParen = parens.poll();
		if(smallestParen == null)
		{
		    System.out.println(-1);
		    return;
		}
		expression[smallestParen.index] = ')';
		count += 2;
		totalCost += smallestParen.cost;
	    }
	}
	System.out.println(totalCost);
	for(int i = 0; i < expression.length; i++)
	    System.out.print(expression[i]);
	in.close();
    }
    
    // This was just a function to test if I understood what made an expression regular
    /*static boolean isRegular(char[] expression)
    {
	int numLeft = 0;
	for (int i = 0; i < expression.length; i++)
	{
	    if(expression[i] == '(')
		numLeft++;
	    else
		numLeft--;

	    if(numLeft < 0)
		return false;
	}
	if(numLeft != 0)
	    return false;
	return true;
    }*/

}
