#include <bits/stdc++.h>
using namespace std;
char str[60000];
int main() {
  scanf("%s", str);
  priority_queue<pair<int, int> > Q;
  int balance = 0;
  long long cost = 0;
  for (int i = 0; str[i] != 0; ++i) {
    if (str[i] == '(') {
      balance += 1;
    } else if (str[i] == ')') {
      balance -= 1;
    } else if (str[i] == '?') {
      int open, close;
      scanf("%d %d", &open, &close);
      balance -= 1;
      str[i] = ')';
      cost += close;
      Q.push(make_pair(close - open, i));
    }
    if (balance < 0) {
      if (Q.empty()) {
        puts("-1");
        return 0;
      }
      cost -= Q.top().first;
      str[Q.top().second] = '(';
      Q.pop();
      balance += 2;
    }
  }
  if (balance != 0) {
    puts("-1");
    return 0;
  }
  cout << cost << endl;
  puts(str);
  return 0;
}
