#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e4 + 1;
struct p {
  int x, id;
  bool operator<(const p& a) const { return x < a.x; }
};
int L, sum, n;
long long ans;
string a;
priority_queue<p> qu;
int main() {
  cin >> a;
  n = a.length();
  for (int i = 0, a1, a2; i < n; ++i) {
    if (a[i] == '(')
      ++sum;
    else if (a[i] == ')')
      --sum;
    else {
      scanf("%d%d", &a1, &a2), --sum, a[i] = ')', ans += a2;
      qu.push((p){a2 - a1, i});
    }
    if (sum < 0) {
      if (qu.empty()) return printf("-1"), 0;
      p tt = qu.top();
      qu.pop();
      ans -= tt.x, a[tt.id] = '(', sum += 2;
    }
  }
  if (sum < 0 || sum > 0) return printf("-1"), 0;
  return cout << ans << endl << a, 0;
}
