#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b, pos;
  bool operator<(const node &x) const { return a - b > x.a - x.b; }
} t;
int main() {
  string s;
  long long ans = 0;
  priority_queue<node> q;
  cin >> s;
  int len = s.length(), now = 0;
  for (int i = 0; i <= len; i++) {
    if (s[i] == '(')
      now++;
    else if (s[i] == '?') {
      now--;
      scanf("%d%d", &t.a, &t.b);
      t.pos = i;
      s[i] = ')';
      ans += t.b;
      q.push(t);
    } else if (s[i] == ')')
      now--;
    if (now < 0) {
      if (q.empty()) {
        printf("-1");
        return 0;
      }
      now += 2;
      t = q.top();
      q.pop();
      ans = ans - t.b + t.a;
      s[t.pos] = '(';
    }
  }
  if (now > 0)
    cout << -1;
  else
    cout << ans << endl << s;
  return 0;
}
