#include <bits/stdc++.h>
using namespace std;
const int maxn = 50005;
char par[maxn];
struct Node {
  int l;
  int r;
  int pos;
};
priority_queue<Node> que;
bool operator<(const Node &a, const Node &b) { return a.r - a.l < b.r - b.l; }
int main() {
  scanf("%s", par);
  Node tmp;
  int cnt = 0;
  long long sum = 0;
  for (int i = 0; par[i]; ++i) {
    if (par[i] == '?') {
      par[i] = ')';
      scanf("%d%d", &tmp.l, &tmp.r);
      tmp.pos = i;
      que.push(tmp);
      sum += (long long)tmp.r;
    }
    if (par[i] == '(') {
      ++cnt;
    } else if (par[i] == ')') {
      --cnt;
    }
    if (cnt < 0) {
      if (que.empty()) {
        printf("-1\n");
        return 0;
      } else {
        tmp = que.top();
        par[tmp.pos] = '(';
        cnt += 2;
        que.pop();
        sum = sum - (long long)tmp.r + (long long)tmp.l;
      }
    }
  }
  if (cnt != 0)
    printf("-1\n");
  else
    printf("%I64d\n%s", sum, par);
  return 0;
}
