#include <bits/stdc++.h>
using namespace std;
bool operator<(pair<int, int> A, pair<int, int> B) { return A.first < B.first; }
priority_queue<pair<int, int> > Q;
char S[50010];
int N, Cnt, O, C;
long long Ans;
int main() {
  gets(S);
  N = strlen(S);
  for (int i = 0; i < N; ++i) {
    if (S[i] == '(')
      Cnt++;
    else if (S[i] == ')')
      Cnt--;
    else {
      scanf("%i %i", &O, &C);
      S[i] = ')';
      Ans += C;
      Cnt--;
      Q.push(make_pair(C - O, i));
    }
    if (Cnt < 0) {
      if (Q.empty()) break;
      Ans -= Q.top().first;
      S[Q.top().second] = '(';
      Q.pop();
      Cnt += 2;
    }
  }
  if (Cnt != 0) {
    cout << -1;
    return 0;
  }
  cout << Ans << "\n";
  for (int i = 0; i < N; ++i) cout << char(S[i]);
  return 0;
}
