#include <bits/stdc++.h>
using namespace std;
struct node {
  long long id, value;
  bool operator<(const node& a) const {
    if (a.value != value)
      return a.value < value;
    else
      return a.id < id;
  }
};
int main() {
  string s;
  cin >> s;
  long long l = 0, r = 0, ans = 1, sum = 0;
  priority_queue<node> Q;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '(') {
      l++;
    }
    if (s[i] == ')') {
      r--;
    }
    if (s[i] == '?') {
      long long x, y;
      cin >> x >> y;
      r--;
      Q.push((node){i, x - y});
      s[i] = ')';
      sum += y;
    }
    if ((r + l) < 0) {
      if (!Q.empty()) {
        node now = Q.top();
        Q.pop();
        sum += now.value;
        s[now.id] = '(';
        r++, l++;
      } else {
        ans = -1;
      }
    }
  }
  if (ans < 0 || (l + r) != 0) {
    cout << "-1";
    return 0;
  } else {
    cout << sum << endl << s;
  }
  return 0;
}
