#include <bits/stdc++.h>
using namespace std;
struct Seg_Tree {
  int l, r, mn, mx, add;
} tree[1000039 << 2];
int n, now = 1;
char opt, ch[1000039];
void pull_up(int k) {
  tree[k].mn = min(tree[k << 1].mn, tree[k << 1 | 1].mn);
  tree[k].mx = max(tree[k << 1].mx, tree[k << 1 | 1].mx);
}
void push_down(int k) {
  if (tree[k].l < tree[k].r && tree[k].add) {
    tree[k << 1].mn += tree[k].add, tree[k << 1].mx += tree[k].add;
    tree[k << 1].add += tree[k].add;
    tree[k << 1 | 1].mn += tree[k].add, tree[k << 1 | 1].mx += tree[k].add;
    tree[k << 1 | 1].add += tree[k].add;
    tree[k].add = 0;
  }
}
void build(int k, int l, int r) {
  tree[k].l = l, tree[k].r = r;
  if (l == r) {
    tree[k].mn = tree[k].mx = 0;
    return;
  }
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  pull_up(k);
}
void update(int k, int l, int r, int w) {
  push_down(k);
  if (l <= tree[k].l && tree[k].r <= r) {
    tree[k].mn += w, tree[k].mx += w;
    tree[k].add += w;
    return;
  }
  int mid = tree[k].l + tree[k].r >> 1;
  if (r <= mid)
    update(k << 1, l, r, w);
  else if (mid < l)
    update(k << 1 | 1, l, r, w);
  else {
    update(k << 1, l, mid, w);
    update(k << 1 | 1, mid + 1, r, w);
  }
  pull_up(k);
}
int query(int k) {
  push_down(k);
  if (tree[k].l == tree[k].r) {
    return tree[k].mn + tree[k].mx >> 1;
  }
  return query(k << 1 | 1);
}
int main() {
  scanf("%d", &n);
  build(1, 1, n);
  for (int a = 1; a <= n; a++) {
    scanf(" %c", &opt);
    if (opt == 'L')
      now--, now = max(now, 1);
    else if (opt == 'R')
      now++;
    else if (opt == '(') {
      if (ch[now] != '(') {
        update(1, now, n, 1 + (ch[now] == ')'));
        ch[now] = '(';
      }
    } else if (opt == ')') {
      if (ch[now] != ')') {
        update(1, now, n, -1 - (ch[now] == '('));
        ch[now] = ')';
      }
    } else {
      if (ch[now] == '(') update(1, now, n, -1);
      if (ch[now] == ')') update(1, now, n, 1);
      ch[now] = opt;
    }
    if (query(1) != 0)
      printf("-1 ");
    else if (tree[1].mn < 0)
      printf("-1 ");
    else
      printf("%d ", tree[1].mx);
  }
  return 0;
}
