#include <bits/stdc++.h>
using namespace std;
void RI(int& x) {
  x = 0;
  char c = getchar();
  while (!(c >= '0' && c <= '9' || c == '-')) c = getchar();
  bool flag = 1;
  if (c == '-') {
    flag = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (!flag) x = -x;
}
void RII(int& x, int& y) { RI(x), RI(y); }
void RIII(int& x, int& y, int& z) { RI(x), RI(y), RI(z); }
void RC(char& c) {
  c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
}
char RC() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
const long long mod = 1e9 + 7;
const long long LINF = 1e18;
const int INF = 1e9;
const double EPS = 1e-8;
int main() {
  string s;
  cin >> s;
  int num = 0;
  long long minn = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  for (int i = 0; i <= (int)s.size() - 1; i++) {
    if (s[i] == '(')
      num++;
    else if (s[i] == ')')
      num--;
    else {
      int a, b;
      cin >> a >> b;
      minn += b;
      num--;
      q.push(make_pair(a - b, i));
      s[i] = ')';
    }
    if (num < 0) {
      if (!(int)q.size()) break;
      pair<int, int> t = q.top();
      q.pop();
      s[t.second] = '(';
      minn += t.first;
      num += 2;
    }
  }
  if (num != 0)
    cout << -1 << endl;
  else {
    cout << minn << endl;
    cout << s << endl;
  }
}
