#include <bits/stdc++.h>
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
using namespace std;
int main() {
  string s;
  cin >> s;
  priority_queue<pair<int, int> > pq;
  long long ans = 0;
  int i, p = 0;
  for (i = 0; i < s.length(); i += 1) {
    if (s[i] == '(')
      p++;
    else if (s[i] == ')')
      --p;
    else {
      s[i] = ')';
      --p;
      int a, b;
      cin >> a >> b;
      ans += b;
      pq.push(make_pair(b - a, i));
    }
    if (p < 0) {
      if (pq.empty()) break;
      p += 2;
      s[pq.top().second] = '(';
      ans -= pq.top().first;
      pq.pop();
    }
  }
  if (p != 0)
    cout << "-1";
  else
    cout << ans << "\n" << s;
  return 0;
}
