#include <bits/stdc++.h>
using namespace std;
string s;
long long ans;
priority_queue<pair<int, int> > pq;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  int c = 0;
  for (int i = 0; i < s.length() && c >= 0; i++) {
    if (s[i] == '(')
      ++c;
    else if (s[i] == ')')
      --c;
    else {
      int l, r;
      cin >> l >> r;
      s[i] = ')';
      --c;
      ans += r;
      pq.push(make_pair(r - l, i));
    }
    while (c < 0 && !pq.empty()) {
      c += 2;
      ans -= pq.top().first;
      s[pq.top().second] = '(';
      pq.pop();
    }
  }
  if (c)
    cout << "-1\n";
  else
    cout << ans << '\n' << s << endl;
  return 0;
}
