#include <bits/stdc++.h>
using namespace std;
struct node {
  long long dis, id;
  bool operator<(const node &b) const { return dis > b.dis; }
};
priority_queue<node> q;
long long n, a, b, id, tmp, ans;
char s[50010];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  for (int i = 0; i < len; i++) {
    if (s[i] == '(') {
      tmp++;
    } else if (s[i] == ')') {
      tmp--;
      if (tmp < 0) {
        if (q.empty()) {
          printf("-1");
          return 0;
        }
        node res = q.top();
        q.pop();
        s[res.id] = '(';
        ans += res.dis;
        tmp += 2;
      }
    } else {
      scanf("%lld%lld", &a, &b);
      node res;
      ans += b;
      res.dis = -b + a;
      res.id = i;
      s[i] = ')';
      tmp--;
      q.push(res);
      if (tmp < 0) {
        if (q.empty()) {
          printf("-1");
          return 0;
        }
        node res = q.top();
        q.pop();
        s[res.id] = '(';
        ans += res.dis;
        tmp += 2;
      }
    }
  }
  if (tmp > 0) {
    printf("-1");
    return 0;
  }
  printf("%lld\n", ans);
  puts(s);
  return 0;
}
