#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
  T res = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    res = (res << 3) + (res << 1) + c - '0';
    c = getchar();
  }
  x = res * f;
}
const long long N = 200000 + 10;
int n;
char a[N];
struct node {
  int loc;
  long long a, b;
  bool operator<(const node aa) const { return aa.b - aa.a >= b - a; }
};
priority_queue<node> pls;
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  long long ans = 0;
  int js = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == '(')
      js++;
    else if (a[i] == ')')
      js--;
    else {
      long long x, y;
      read(x), read(y);
      js--;
      a[i] = ')';
      ans += y;
      pls.push(node{i, x, y});
    }
    if (js < 0) {
      if (pls.empty()) {
        printf("-1\n");
        return 0;
      }
      node k = pls.top();
      pls.pop();
      a[k.loc] = '(';
      js += 2;
      ans += k.a - k.b;
    }
  }
  if (js != 0) {
    printf("-1\n");
    return 0;
  }
  printf("%lld\n", ans);
  printf("%s\n", a + 1);
  return 0;
}
