#include <bits/stdc++.h>
using namespace std;
struct Item {
  int pos, v;
  bool operator<(const Item &a) const { return v < a.v; };
};
Item W[100000];
char s[100000];
int l, cnt;
long long ans;
int main() {
  scanf("%s", s);
  l = strlen(s);
  for (int i = 0; i < l; i++) {
    if (s[i] == '?') {
      int a, b;
      cnt++;
      s[i] = ')';
      scanf("%d%d", &a, &b);
      ans += b;
      W[cnt].pos = i;
      W[cnt].v = b - a;
    }
  }
  priority_queue<Item> q;
  int diff = 0, now = 1;
  for (int i = 0; i < l; i++) {
    if (s[i] == '(') diff++;
    if (s[i] == ')') {
      diff--;
      if (W[now].pos == i) {
        q.push(W[now]);
        now++;
      }
    }
    if (diff < 0) {
      if (q.empty())
        break;
      else {
        Item tmp = q.top();
        q.pop();
        ans -= tmp.v;
        s[tmp.pos] = '(';
        diff += 2;
      }
    }
  }
  if (diff == 0) {
    printf("%I64d\n", ans);
    printf("%s", s);
  } else
    printf("-1\n");
  return 0;
}
