#include <bits/stdc++.h>
using namespace std;
char s[50010], ans[50010];
int a[50010], b[50010];
struct _ {
  int pos, val;
  bool operator<(const _ &ob) const { return val > ob.val; }
};
priority_queue<_> pq;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> s + 1;
  int n = strlen(s + 1);
  memcpy(ans + 1, s + 1, sizeof(char) * (n + 1));
  int m = 0;
  int i;
  int cnt = 0;
  long long anss = 0;
  for (i = 1; i <= n; ++i) {
    if (s[i] == '?') {
      ++m;
      cin >> a[m] >> b[m];
      ans[i] = ')';
      pq.push((_){i, a[m] - b[m]});
      anss += b[m];
      --cnt;
      if (cnt < 0) {
        _ tmp = pq.top();
        pq.pop();
        cnt += 2;
        anss += tmp.val;
        ans[tmp.pos] = '(';
      }
    } else {
      if (s[i] == '(')
        ++cnt;
      else {
        --cnt;
        if (cnt < 0) {
          if (pq.empty()) {
            cout << -1 << '\n';
            return 0;
          }
          _ tmp = pq.top();
          pq.pop();
          cnt += 2;
          anss += tmp.val;
          ans[tmp.pos] = '(';
        }
      }
    }
  }
  if (cnt > 0) {
    cout << -1 << '\n';
    return 0;
  }
  cout << anss << '\n';
  cout << ans + 1 << '\n';
  return 0;
}
