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