#include <bits/stdc++.h>
const int maxn = 5e4 + 10;
using namespace std;
char s[maxn];
struct node {
  int s, p;
  bool operator<(const node& a) const { return s > a.s; }
};
priority_queue<node> pq;
int main() {
  scanf("%s", s);
  int k = 0, a, b;
  long long ans = 0;
  for (int i = 0; s[i]; i++) {
    if (s[i] == '(')
      k++;
    else if (s[i] == ')')
      k--;
    else {
      scanf("%d%d", &a, &b);
      k--;
      ans += b;
      node e;
      e.p = i;
      e.s = a - b;
      pq.push(e);
      s[i] = ')';
    }
    if (k < 0) {
      if (pq.empty()) {
        ans = -1;
        break;
      }
      k += 2;
      node t = pq.top();
      pq.pop();
      ans += t.s;
      s[t.p] = '(';
    }
  }
  if (k || ans == -1)
    printf("-1\n");
  else {
    printf("%I64d\n%s\n", ans, s);
  }
  return 0;
}
