#include <bits/stdc++.h>
using namespace std;
char str[50005];
priority_queue<pair<int, int> > Q;
int main() {
  int i, j, m, n, k, t, count, x, y;
  long long ans;
  bool flag = true;
  scanf(" %s", str);
  for (count = ans = i = 0; str[i]; i++) {
    if (str[i] == '(')
      count++;
    else if (str[i] == ')')
      count--;
    else {
      scanf("%d %d", &x, &y);
      str[i] = ')';
      Q.push(make_pair(y - x, i));
      count--;
      ans += y;
    }
    pair<int, int> p;
    if (count < 0) {
      if (Q.empty()) {
        flag = false;
        continue;
      }
      p = Q.top();
      Q.pop();
      ans -= p.first;
      str[p.second] = '(';
      count += 2;
    }
  }
  (count == 0 && flag) ? printf("%I64d\n%s\n", ans, str) : printf("-1\n");
}
