#include <bits/stdc++.h>
using namespace std;
multimap<int, int> delta;
char s[50010];
int cnt = 0, r1, r2;
long long ans = 0;
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin >> s;
  for (int i = 0; s[i]; ++i) {
    if (s[i] == '(')
      ++cnt;
    else if (s[i] == ')')
      --cnt;
    else {
      cin >> r1 >> r2;
      ans += r2, --cnt;
      s[i] = ')';
      delta.insert({r1 - r2, i});
    }
    if (cnt < 0) {
      if (delta.empty()) {
        cout << -1;
        return 0;
      }
      s[delta.begin()->second] = '(';
      ans += delta.begin()->first;
      delta.erase(delta.begin());
      cnt += 2;
    }
  }
  if (cnt != 0)
    cout << -1;
  else
    cout << ans << '\n' << s;
}
