#include <bits/stdc++.h>
using namespace std;
char c[50010];
int main(void) {
  int n, m, i, j, k = 0, a, b;
  long long res = 0LL;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      PQ;
  scanf("%s", c);
  n = strlen(c);
  for (i = 0; i < (n); ++i) {
    if (c[i] == '(')
      ++k;
    else if (c[i] == ')')
      --k;
    else {
      --k;
      c[i] = ')';
      scanf("%d%d", &a, &b);
      res += b;
      PQ.push(make_pair((a - b), (i)));
    }
    while (!PQ.empty() && k < 0) {
      pair<int, int> v = PQ.top();
      PQ.pop();
      res += v.first;
      c[v.second] = '(';
      k += 2;
    }
    if (k < 0) break;
  }
  if (k != 0)
    puts("-1");
  else
    printf("%I64d\n%s\n", res, c);
  return 0;
}
