#include <bits/stdc++.h>
using namespace std;
const int N = 50005;
int n, a[N], b[N], m, t[N];
string st;
void Enter() {
  cin >> st;
  n = st.size();
  for (int i = 0, b_ = n - 1; i <= b_; ++i) {
    if (st[i] == '(')
      t[i + 1] = 1;
    else if (st[i] == ')')
      t[i + 1] = -1;
    else
      m++;
  }
  for (int i = 1, b_ = m; i <= b_; ++i) cin >> a[i] >> b[i];
}
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    heap;
void Apps() {
  int top = 0;
  long long res = 0;
  m = 0;
  for (int i = 1, b_ = n; i <= b_; ++i) {
    if (t[i] == 0) {
      t[i] = -1;
      res += b[++m];
      heap.push({a[m] - b[m], i});
      if (top - 1 >= 0)
        top--;
      else {
        t[heap.top().second] = 1;
        res += heap.top().first;
        heap.pop();
        top++;
      }
    } else {
      top += t[i];
      if (top < 0) {
        if (heap.empty()) {
          cout << -1;
          return;
        }
        t[heap.top().second] = 1;
        res += heap.top().first;
        heap.pop();
        top += 2;
      }
    }
  }
  if (top != 0) {
    cout << -1;
    return;
  }
  cout << res << "\n";
  for (int i = 1, b_ = n; i <= b_; ++i)
    if (t[i] > 0)
      cout << "(";
    else
      cout << ")";
}
int main() {
  Enter();
  Apps();
}
