#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1 << 40;
const int MAXN = 60 * 1000;
string str;
long long cost[MAXN];
set<pair<long long, int> > taken;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> str;
  int n = str.length();
  int a, b;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if (str[i] == '(') {
      cost[i] = inf;
    } else if (str[i] == ')') {
      cost[i] = -inf;
      ans += inf;
      str[i] = '(';
    } else {
      cin >> a >> b;
      cost[i] = b - a;
      ans += a;
      str[i] = '(';
    }
  }
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum++;
    if (sum == 1 && !taken.empty()) {
      set<pair<long long, int> >::iterator it = taken.end();
      it--;
      if (it->first > cost[i]) {
        ans -= it->first;
        str[it->second] = '(';
        taken.erase(it);
        sum += 2;
      }
    }
    if (sum >= 2) {
      str[i] = ')';
      ans += cost[i];
      taken.insert(make_pair(cost[i], i));
      sum -= 2;
    }
  }
  if (ans > inf / 2) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  cout << str << endl;
  return 0;
}
