#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long Hashimoto = 0, Kanna = 1;
  char I_Love = getchar();
  while (I_Love < '0' || I_Love > '9') {
    if (I_Love == '-') Kanna = -1;
    I_Love = getchar();
  }
  while (I_Love >= '0' && I_Love <= '9') {
    Hashimoto = Hashimoto * 10 + I_Love - '0';
    I_Love = getchar();
  }
  return Hashimoto * Kanna;
}
string s;
long long a[55555], b[55555];
bool is[55555];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    q;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s;
  long long ans = 0;
  int check = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      is[i] = 1;
      s[i] = '(';
      cin >> a[i] >> b[i];
      ans += a[i];
    }
    if (s[i] == '(') {
      check++;
    } else
      check--;
    if (check < 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  int cnt = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == ')')
      cnt++;
    else
      cnt--;
    if (is[i]) {
      q.push({b[i] - a[i], i});
    }
    while (cnt < 0) {
      if (q.empty()) {
        cout << -1 << endl;
        return 0;
      }
      ans += q.top().first;
      s[q.top().second] = ')';
      q.pop();
      cnt += 2;
    }
  }
  while (cnt < 0) {
    if (q.empty()) {
      cout << -1 << endl;
      return 0;
    }
    ans += q.top().first;
    s[q.top().second] = ')';
    q.pop();
    cnt++;
  }
  cout << ans << endl;
  cout << s << endl;
  ;
  return 0;
}
