#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 10000 + 10;
char str[N];
int main() {
  scanf("%s", str);
  int d = 0;
  bool flag = true;
  priority_queue<pair<int, int> > pq;
  long long sum = 0;
  for (int i = 0; str[i]; ++i) {
    if (str[i] == '(') {
      ++d;
    } else if (str[i] == ')') {
      --d;
    } else {
      int x, y;
      scanf("%d%d", &x, &y);
      str[i] = ')';
      sum += y;
      pq.push(pair<int, int>(y - x, i));
      --d;
    }
    if (d < 0) {
      if (pq.empty()) {
        flag = false;
        break;
      }
      pair<int, int> p = pq.top();
      pq.pop();
      sum -= p.first;
      str[p.second] = '(';
      d += 2;
    }
  }
  if (d != 0 || flag == false) {
    cout << -1 << endl;
  } else {
    cout << sum << "\n" << str << endl;
  }
}
