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
()()
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline bool isPrime(T n) {
  if (n <= 1) return false;
  for (T i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
template <class T>
inline T Mod(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
string toString(T n) {
  ostringstream oss;
  oss << n;
  oss.flush();
  return oss.str();
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
long long toLl(string s) {
  long long r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
template <class T>
void debug(const T& e) {
  cout << e << endl;
}
template <class T1, class T2>
void debug(const T1& e1, const T2& e2) {
  cout << e1 << "\t" << e2 << endl;
}
template <class T1, class T2, class T3>
void debug(const T1& e1, const T2& e2, const T3& e3) {
  cout << e1 << "\t" << e2 << "\t" << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void debug(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
  cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void debug(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
           const T5& e5) {
  cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << endl;
}
template <class T>
void debug(vector<T>& e) {
  int i;
  for (i = 0; i < (int)e.size(); i++) cout << e[i] << " ";
  cout << endl;
}
template <class T>
void debug(vector<basic_string<T> >& e) {
  int i, j;
  for (i = 0; i < (int)e.size(); i++) {
    for (j = 0; j < (int)e[i].size(); j++) cout << e[i][j];
    cout << endl;
  }
  cout << endl;
}
template <class T>
void debug(vector<vector<T> >& e) {
  int i, j;
  for (i = 0; i < (int)e.size(); i++) {
    for (j = 0; j < (int)e[i].size(); j++) cout << e[i][j] << "\t";
    cout << endl;
  }
  cout << endl;
}
template <class T>
void debug(T e[60000][60000], int row, int col) {
  int i, j;
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) cout << e[i][j] << " ";
    cout << endl;
  }
}
long long Pow(long long B, long long P) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) R = (R * B);
    P /= 2;
    B = (B * B);
  }
  return R;
}
struct pq {
  int cost, i;
  bool operator<(const pq& b) const { return cost > b.cost; }
};
int a[60000], b[60000], c[60000];
char str[60000];
string s;
long long sum;
bool Solve() {
  priority_queue<pq> Q;
  int i, cnt;
  pq P;
  sum = cnt = 0;
  for (i = 0; i < (int)s.size(); i++) {
    if (s[i] == '(')
      cnt++;
    else if (s[i] == ')')
      cnt--;
    else if (s[i] == '?') {
      s[i] = ')';
      cnt--;
      sum += b[i];
      P.cost = a[i] - b[i];
      P.i = i;
      Q.push(P);
    }
    if (cnt < 0) {
      if (Q.empty()) return false;
      P = Q.top();
      Q.pop();
      sum += P.cost;
      s[P.i] = '(';
      cnt += 2;
    }
  }
  if (cnt) return false;
  return true;
}
int main() {
  int i, j, k, test, Case = 1, p, q;
  while (scanf("%s", str) == 1) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    s = str;
    k = 0;
    for (i = 0; i < (int)s.size(); i++)
      if (s[i] == '?') c[k++] = i;
    for (i = 0; i < k; i++) {
      scanf("%d %d", &p, &q);
      a[c[i]] = p;
      b[c[i]] = q;
    }
    if (Solve() == false)
      printf("-1\n");
    else
      printf("%I64d\n%s\n", sum, s.c_str());
  }
  return 0;
}
