#include <bits/stdc++.h>
using namespace std;
string s;
pair<long long, long long> a[50005];
long long n, m;
priority_queue<pair<long long, long long> > pq;
int main() {
  cin.tie(0);
  cout.tie(0);
  long long i, j, a, b, ans = 0, mk = 0;
  cin >> s;
  n = s.size();
  for (i = 0; i < s.size() and ans != -1; ++i) {
    if (s[i] == '(')
      ++mk;
    else {
      --mk;
      if (s[i] == '?') {
        cin >> a >> b;
        pq.push(make_pair(b - a, i));
        s[i] = ')';
        ans += b;
      }
    }
    if (mk < 0) {
      while (pq.size() and mk < 0) {
        mk += 2;
        pair<long long, long long> p = pq.top();
        pq.pop();
        s[p.second] = '(';
        ans -= p.first;
      }
      if (mk < 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (mk)
    cout << -1 << endl;
  else
    cout << ans << '\n' << s << endl;
  return 0;
}
