#include <bits/stdc++.h>
using namespace std;
bool debug = false;
string s;
string ans;
int n;
priority_queue<pair<int, int> > pq;
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  cin >> s;
  n = s.size();
  int bl = 0;
  long long cost = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      bl++;
      ans += '(';
    } else {
      bl--;
      ans += ')';
      if (s[i] == '?') {
        int a, b;
        cin >> a >> b;
        pq.push(make_pair(b - a, i));
        cost += b;
      }
    }
    if (bl < 0) {
      if (pq.size() == 0) {
        puts("-1");
        return 0;
      }
      pair<int, int> last = pq.top();
      ans[last.second] = '(';
      bl++;
      bl++;
      cost -= last.first;
      pq.pop();
    }
  }
  if (bl != 0) {
    puts("-1");
    return 0;
  }
  cout << cost << endl << ans << endl;
  return 0;
}
