#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 100;
struct Node {
  int v, sum, max_sum, min_sum;
  Node(int _v, int _sum, int _max_sum, int _min_sum)
      : v(_v), sum(_sum), max_sum(_max_sum), min_sum(_min_sum) {}
};
int L;
string s;
char t[maxn * 2];
stack<Node> ls, rs;
void push_node(stack<Node> &st, int v) {
  auto e = st.top();
  st.push(
      Node(v, e.sum + v, max(e.max_sum, e.sum + v), min(e.min_sum, e.sum + v)));
}
int main() {
  cin >> L;
  cin >> s;
  int p = 0;
  ls.push(Node(0, 0, 0, 0));
  rs.push(Node(0, 0, 0, 0));
  for (int i = 0; i < L; i++) {
    if (s[i] == 'L') {
      if (p > 0) {
        p--;
        if (t[p] == '(') {
          ls.pop();
          push_node(rs, -1);
        } else if (t[p] == ')') {
          ls.pop();
          push_node(rs, 1);
        }
      }
    } else if (s[i] == 'R') {
      if (t[p] == '(') {
        rs.pop();
        push_node(ls, 1);
      } else if (t[p] == ')') {
        rs.pop();
        push_node(ls, -1);
      }
      p++;
    } else if ('a' <= s[i] && s[i] <= 'z') {
      if (t[p] == ')' || t[p] == '(') rs.pop();
      t[p] = s[i];
    } else if (s[i] == '(') {
      if (t[p] == '(') {
      } else if (t[p] == ')') {
        rs.pop();
        push_node(rs, -1);
      } else {
        push_node(rs, -1);
      }
      t[p] = s[i];
    } else if (s[i] == ')') {
      if (t[p] == ')') {
      } else if (t[p] == '(') {
        rs.pop();
        push_node(rs, 1);
      } else {
        push_node(rs, 1);
      }
      t[p] = s[i];
    }
    if (i > 0) cout << " ";
    if (ls.top().sum == rs.top().sum && ls.top().min_sum >= 0 &&
        rs.top().min_sum >= 0) {
      cout << max(ls.top().max_sum, rs.top().max_sum);
    } else {
      cout << -1;
    }
  }
  cout << endl;
  return 0;
}
