#include <bits/stdc++.h>
using namespace std;
long long m, a[100010], b[100010], l, r, ans, c[100010], mx, p;
string s;
priority_queue<pair<long long, long long> > q;
int main() {
  cin >> s;
  if (s[0] == ')' || s[s.length() - 1] == '(') {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < s.length(); i++) {
    mx = 9999999;
    if (s[i] == '(') {
      l++;
    } else {
      if (s[i] == '?') {
        m++;
        cin >> a[m] >> b[m];
        q.push(make_pair(b[m] - a[m], i));
        s[i] = ')';
        ans += b[m];
      }
      l--;
      if (l < 0) {
        if (q.empty() == 1) {
          cout << -1 << endl;
          return 0;
        }
        ans -= (q.top().first);
        s[(q.top().second)] = '(';
        q.pop();
        l += 2;
      }
    }
  }
  if (l > 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  cout << s << endl;
  return 0;
}
