#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, p;
  long long int cost;
  bool na;
  string line;
  vector<int> a, b;
  pair<int, int> t;
  priority_queue<pair<int, int> > q;
  getline(cin, line);
  n = line.length();
  a.resize(n);
  b.resize(n);
  m = 0;
  for (int i = 0; i < n; i++) {
    if (line[i] == '?') {
      cin >> a[i] >> b[i];
      ++m;
    }
  }
  p = 0;
  cost = 0LL;
  if (n & 1) {
    na = true;
  } else {
    na = false;
    for (int i = 0; i < n; i++) {
      if (line[i] == '(') {
        ++p;
      } else if (line[i] == ')') {
        --p;
      } else {
        --p;
        q.push(make_pair(b[i] - a[i], i));
        line[i] = ')';
        cost += b[i];
      }
      if (p < 0) {
        if (q.empty()) {
          na = true;
          break;
        }
        t = q.top();
        q.pop();
        cost -= t.first;
        line[t.second] = '(';
        p += 2;
      }
    }
    if (p) {
      na = true;
    }
  }
  if (na) {
    cout << "-1" << endl;
  } else {
    cout << cost << endl;
    cout << line << endl;
  }
  return 0;
}
