#include <bits/stdc++.h>
using namespace std;
struct qmark {
  int idx;
  int left_m_right;
  bool operator<(const qmark a) const { return a.left_m_right < left_m_right; }
};
int main() {
  priority_queue<qmark> left_mine_right;
  int noq = 0, find_location = 0, cnt = 0, left, right;
  long long cost = 0;
  string symbol;
  cin >> symbol;
  if (symbol.size() % 2 != 0 || symbol[0] == ')') {
    cout << -1 << endl;
    return 0;
  }
  while (find_location < symbol.size()) {
    if (symbol[find_location] == '(') {
      cnt++;
    } else if (symbol[find_location] == ')') {
      cnt--;
    } else {
      noq++;
      qmark qm;
      cnt--;
      cin >> left >> right;
      qm.left_m_right = left - right;
      qm.idx = find_location;
      left_mine_right.push(qm);
      cost += right;
    }
    find_location++;
    if (cnt < 0 && noq > 0) {
      cnt += 2;
      qmark tmp_qm = left_mine_right.top();
      cost += tmp_qm.left_m_right;
      symbol[tmp_qm.idx] = '(';
      left_mine_right.pop();
      noq--;
    }
    if (cnt < 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (cnt == 0) {
    for (int i = 0; i < symbol.size(); i++) {
      if (symbol[i] == '?') symbol[i] = ')';
    }
    cout << cost << endl;
    cout << symbol << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
