#include <bits/stdc++.h>
using namespace std;
string s;
const long long N = 3e5 + 6;
long long p, res, ans, a, b;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
signed main() {
  cin >> s;
  for (long long i = 0; i < s.size(); ++i) {
    if (s[i] == '(')
      ++res;
    else if (s[i] == ')')
      --res;
    else {
      s[i] = ')';
      --res;
      cin >> a >> b;
      ans += b;
      q.push({a - b, i});
    }
    while (res < 0 && !q.empty()) {
      ans += q.top().first;
      s[q.top().second] = '(';
      q.pop();
      res += 2;
    }
    if (res < 0) return cout << -1, 0 << '\n';
  }
  if (res != 0)
    cout << -1;
  else
    cout << ans << '\n' << s << '\n';
}
