#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x, y;
  y = scanf("%d", &x);
  return x;
}
const int N = 1e6 + 123;
struct node {
  int mi, Ma, lazy;
} seg[N * 4];
void upd(int x, int val) {
  assert(x < N * 4);
  seg[x].mi += val;
  seg[x].Ma += val;
  seg[x].lazy += val;
}
void up_lazy(int x) {
  upd(x * 2 + 0, seg[x].lazy);
  upd(x * 2 + 1, seg[x].lazy);
  seg[x].lazy = 0;
}
void update(int ld, int rd, int val, int x = 1, int l = 0, int r = N) {
  if (ld <= l && r <= rd) {
    upd(x, val);
    return;
  }
  up_lazy(x);
  int m = l + r >> 1;
  if (ld < m) update(ld, rd, val, x * 2 + 0, l, m);
  if (rd > m) update(ld, rd, val, x * 2 + 1, m, r);
  seg[x].mi = min(seg[x * 2].mi, seg[x * 2 + 1].mi);
  seg[x].Ma = max(seg[x * 2].Ma, seg[x * 2 + 1].Ma);
}
int main() {
  int n, cur = 0, count = 0;
  string s, t = string(N, ' ');
  cin >> n >> s;
  for (auto u : s) {
    if (u == '(') {
      update(cur, N, 1 + (t[cur] == ')') - (t[cur] == '('));
      count += 1 + (t[cur] == ')') - (t[cur] == '(');
      t[cur] = '(';
    } else if (u == ')') {
      update(cur, N, -1 - (t[cur] == '(') + (t[cur] == ')'));
      count += -1 - (t[cur] == '(') + (t[cur] == ')');
      t[cur] = ')';
    } else if (u == 'R')
      cur++;
    else if (u == 'L')
      cur = max(cur - 1, 0);
    else {
      update(cur, N, (t[cur] == ')') - (t[cur] == '('));
      count += (t[cur] == ')') - (t[cur] == '(');
      t[cur] = ' ';
    }
    int ret = (count == 0 and seg[1].mi == 0 ? seg[1].Ma : -1);
    printf("%d ", ret);
  }
  cout << endl;
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
