#include <bits/stdc++.h>
using namespace std;
void file() {
  freopen("std.in", "r", stdin);
  freopen("wa.out", "w", stdout);
}
const long long N = 1e6 + 10, M = 2e6 + 10, inf = 1e9;
inline long long read() {
  bool sym = 0;
  long long res = 0;
  char ch = getchar();
  while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
  return sym ? -res : res;
}
long long n, m, cnt, ans;
char ch[N];
priority_queue<pair<long long, long long> > q;
signed main() {
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  if (n % 2) {
    printf("-1");
    return 0;
  }
  for (long long i = 1, j = 0; i <= n; i++) {
    if (ch[i] == '(') cnt++;
    if (ch[i] == ')') cnt--;
    if (ch[i] == '?') {
      long long l = read(), r = read();
      cnt--;
      ans += r;
      ch[i] = ')';
      q.push(make_pair(r - l, i));
    }
    if (cnt < 0) {
      if (q.empty()) {
        printf("-1");
        return 0;
      }
      pair<long long, long long> t = q.top();
      q.pop();
      ans -= t.first;
      ch[t.second] = '(';
      cnt = 1;
    }
  }
  if (cnt) {
    printf("-1");
    return 0;
  }
  printf("%lld\n", ans);
  printf("%s", ch + 1);
  return 0;
}
