#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 5;
struct Node {
  int num, a, b;
  Node(int x, int y, int z) {
    num = x;
    a = y;
    b = z;
  }
  bool operator<(const Node& x) const { return b - a < x.b - x.a; }
};
priority_queue<Node> q;
int n, a[maxn], b[maxn];
char s[maxn];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int cnt = 0;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '(') cnt++;
    if (s[i] == '?') {
      scanf("%d%d", &a[i], &b[i]);
      if (i == 1) {
        sum += a[i];
        s[i] = '(';
        cnt++;
        continue;
      }
      sum += b[i];
      s[i] = ')';
      q.push(Node(i, a[i], b[i]));
    }
    if (s[i] == ')') {
      if (cnt == 0) {
        if (q.empty()) {
          printf("-1");
          return 0;
        }
        Node cur = q.top();
        q.pop();
        if (cur.num == n) {
          cur = q.top();
          q.pop();
        }
        sum -= cur.b;
        sum += cur.a;
        s[cur.num] = '(';
        if (cur.num == i)
          cnt++;
        else
          cnt += 2;
      }
      if (s[i] == ')') cnt--;
    }
  }
  if (cnt) {
    printf("-1\n");
    return 0;
  }
  printf("%lld\n%s", sum, s + 1);
  return 0;
}
