#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
struct node {
  int mx, mn;
} tr[4 * maxn];
int tag[4 * maxn];
void pushdown(int o) {
  if (tag[o]) {
    tag[(o << 1)] += tag[o];
    tag[(o << 1 | 1)] += tag[o];
    tr[(o << 1)].mx += tag[o];
    tr[(o << 1)].mn += tag[o];
    tr[(o << 1 | 1)].mx += tag[o];
    tr[(o << 1 | 1)].mn += tag[o];
    tag[o] = 0;
  }
}
void pushup(int o) {
  tr[o].mx = max(tr[(o << 1)].mx, tr[(o << 1 | 1)].mx);
  tr[o].mn = min(tr[(o << 1)].mn, tr[(o << 1 | 1)].mn);
}
void update(int o, int l, int r, int ql, int qr, int k) {
  if (ql <= l && qr >= r) {
    tr[o].mn += k;
    tr[o].mx += k;
    tag[o] += k;
    return;
  }
  pushdown(o);
  if (ql <= ((l + r) >> 1)) update((o << 1), l, ((l + r) >> 1), ql, qr, k);
  if (qr > ((l + r) >> 1))
    update((o << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, k);
  pushup(o);
}
string op;
char s[maxn];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  cin >> op;
  for (int i = 0; i < n; i++) s[i] = ' ';
  int cur = 0;
  int c1 = 0, c2 = 0;
  for (int i = 0; i < n; i++) {
    bool f = 0;
    if (op[i] == 'L') {
      cur = max(0, cur - 1);
      f = 1;
    } else if (op[i] == 'R') {
      ++cur;
      f = 1;
    } else if (op[i] == '(') {
      if (s[cur] == ')')
        update(1, 1, n, cur + 1, n, 2), c1++, c2--;
      else if (s[cur] != '(')
        update(1, 1, n, cur + 1, n, 1), c1++;
    } else if (op[i] == ')') {
      if (s[cur] == '(')
        update(1, 1, n, cur + 1, n, -2), c2++, c1--;
      else if (s[cur] != ')')
        update(1, 1, n, cur + 1, n, -1), c2++;
    } else {
      if (s[cur] == '(') update(1, 1, n, cur + 1, n, -1), c1--;
      if (s[cur] == ')') update(1, 1, n, cur + 1, n, 1), c2--;
    }
    if (!f) s[cur] = op[i];
    if (c1 != c2 || tr[1].mn < 0)
      cout << "-1 ";
    else
      cout << tr[1].mx << ' ';
  }
}
