#include <bits/stdc++.h>
using namespace std;
int main() {
  int d = 0;
  long long int sum = 0;
  string s;
  bool flag = false;
  cin >> s;
  priority_queue<pair<int, int>> a;
  for (unsigned int i = 0; i < s.size(); i++) {
    if (s[i] == '(')
      d++;
    else if (s[i] == ')')
      d--;
    else {
      int j, k;
      scanf("%d %d", &j, &k);
      s[i] = ')';
      sum += k;
      d--;
      a.push(make_pair(k - j, i));
    }
    if (d < 0 && !a.empty()) {
      pair<int, int> temp;
      temp = a.top();
      sum -= temp.first;
      s[temp.second] = '(';
      d += 2;
      a.pop();
    } else if (a.empty() && d < 0) {
      flag = true;
    }
  }
  if (flag || d != 0)
    printf("-1");
  else {
    printf("%lld\n", sum);
    cout << s;
  }
}
