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.*;
import java.math.*;

public final class lcbs
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static List<Integer> al=new ArrayList<Integer>();
	
    public static void main(String args[]) throws Exception
    {
		char[] a=sc.next().toCharArray();
		
		for(int i=0;i<a.length;i++)
		{
			if(a[i]=='?')
			{
				al.add(i);
			}
		}
		
		int n=al.size();Pair[] arr=new Pair[n];
		
		for(int i=0;i<n;i++)
		{
			arr[i]=new Pair(al.get(i),sc.nextInt(),sc.nextInt());
		}
		
		char[] res=new char[a.length];int x=0,y=0,z=0,ptr=0;
		
		for(int i=0;i<a.length;i++)
		{
			if(a[i] != '?')
			{
				res[i]=a[i];
			}
			else
			{
				res[i]='x';
			}
		}
		
		TreeSet<Pair> ts=new TreeSet<>();boolean ans=true;long now=0,sum=0;
		
		for(int i=0;i<a.length;i++)
		{
			if(a[i] == '(') x++;
			
			if(a[i] == ')') y++;
			
			if(a[i] == '?') 
			{
				ts.add(new Pair(i,arr[ptr].l-arr[ptr].r,ptr));ptr++;z++;
			}
			
			if( y + z > x )
			{	
				if(ts.size() == 0) 
				{
					ans=false;break;
				}
				
				Pair curr = ts.first(); res[curr.idx]='(';
				
				ts.remove(curr);long add = arr[curr.r].l;now+=add;
				
				x++;z--;
			}
		}
		
		if(ans)
		{
			
			x=0;y=0;
			
			while(ts.size()>0)
			{
				Pair curr=ts.first();res[curr.idx]=')';
				
				now+=arr[curr.r].r; ts.remove(curr);
			}
			
			for(int i=0;i<a.length;i++)
			{
				if(res[i]=='(')
				{
					x++;
				}
				else
				{
					y++;
				}
			}
		
			if(x == y)
			{
				out.println(now+"\n"+new String(res));
			}
			else
			{
				out.println(-1);
			}
		}
		
		else
		{
			out.println(-1);
		}
		
		out.close();
	}
}

class Pair implements Comparable<Pair>
{
	int idx,l,r;
	
	public Pair(int idx,int l,int r)
	{
		this.idx=idx;this.l=l;this.r=r;
	}
	
	public int compareTo(Pair x)
	{
		if(this.l==x.l)
		{
			return Integer.compare(this.idx,x.idx);
		}
		
		return Integer.compare(this.l,x.l);
	}
}

class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}