#include <bits/stdc++.h>
using namespace std;
int cx[] = {-1, 0, 0, 1, -1, -1, 1, 1, 0},
    cy[] = {0, -1, 1, 0, -1, 1, 1, -1, 0};
string in;
char ans[500005];
int cost[500005][2];
long long val;
int main() {
  cin >> in;
  priority_queue<pair<int, int> > Q;
  int len = in.size();
  int stack = 0;
  ans[len] = '\0';
  for (int i = 0; i < len; i++) {
    if (in[i] == '(') {
      stack++;
      ans[i] = '(';
    } else if (in[i] == ')') {
      stack--;
      ans[i] = ')';
    } else {
      scanf("%d %d", &cost[i][0], &cost[i][1]);
      stack--;
      ans[i] = ')';
      val += cost[i][1];
      Q.push(pair<int, int>(cost[i][1] - cost[i][0], i));
    }
    if (stack < 0) {
      if (Q.empty()) break;
      int more = Q.top().first;
      int ind = Q.top().second;
      Q.pop();
      val -= more;
      ans[ind] = '(';
      stack += 2;
    }
  }
  if (stack)
    printf("-1");
  else
    printf("%I64d\n%s\n", val, ans);
  return 0;
}
