#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int n;
long long l[50005], r[50005], z;
string s;
set<pair<long long, int> > zz;
int main() {
  cin >> s;
  n = s.length();
  for (int i = (int)(0); i < (int)(n); i++) {
    if (s[i] == '?')
      cin >> l[i] >> r[i];
    else if (s[i] == '(') {
      l[i] = 0;
      r[i] = 1e11;
    } else if (s[i] == ')') {
      l[i] = 1e11;
      r[i] = 0;
    }
  }
  for (int i = (int)(0); i < (int)(n); i++) {
    if (i % 2 == 0) {
      s[i] = ')';
      zz.insert(make_pair(l[i] - r[i], i));
      auto cnt = zz.begin();
      int j = cnt->second;
      zz.erase(cnt);
      s[j] = '(';
    } else {
      s[i] = ')';
      zz.insert(make_pair(l[i] - r[i], i));
    }
  }
  for (int i = (int)(0); i < (int)(n); i++) z += s[i] == '(' ? l[i] : r[i];
  if (z >= 9.9e10)
    cout << -1 << endl;
  else
    cout << z << endl << s << endl;
  return 0;
}
