#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long> > p;
string str;
long long c, a, b, A;
int main() {
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '?' && cin >> a >> b) {
      str[i] = ')', p.push(make_pair((b - a), i)), c--;
      A += b;
    } else if (str[i] == '(')
      c++;
    else
      c--;
    if (c < 0) {
      if (p.empty()) {
        cout << (-1);
        return 0;
      } else {
        str[p.top().second] = '(', A -= p.top().first, c += 2;
        p.pop();
      }
    }
  }
  if (c) {
    cout << (-1);
  } else {
    cout << A << "\n" << str;
  }
  return 0;
}
