#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  priority_queue<pair<int, int>> q;
  cin >> s;
  int t = 0;
  long long kq = 0;
  for (int i = 0; i <= s.size() - 1; i++) {
    if (s[i] == '(')
      t++;
    else if (s[i] == ')')
      t--;
    else {
      int x, y;
      cin >> x >> y;
      kq += y;
      s[i] = ')';
      q.push(make_pair(y - x, i));
      t--;
    }
    if (t < 0) {
      if (q.empty()) break;
      pair<int, int> a = q.top();
      q.pop();
      s[a.second] = '(';
      kq -= a.first;
      t += 2;
    }
  }
  if (t != 0)
    cout << -1;
  else {
    cout << kq << '\n';
    cout << s;
  }
  return 0;
}
