#include <bits/stdc++.h>
using namespace std;
int n;
char a[1000005];
string s;
struct Segment {
  int Max[1000005 * 4], Min[1000005 * 4], l[1000005 * 4], r[1000005 * 4],
      lazy[1000005 * 4];
  void Build(int id, int i, int j) {
    l[id] = i;
    r[id] = j;
    if (i == j) return;
    int mid = (i + j) / 2;
    Build(id * 2, i, mid);
    Build(id * 2 + 1, mid + 1, j);
  }
  void Dolazy(int id) {
    if (l[id] == r[id]) return;
    lazy[id * 2] += lazy[id];
    lazy[id * 2 + 1] += lazy[id];
    Max[id * 2] += lazy[id];
    Max[id * 2 + 1] += lazy[id];
    Min[id * 2] += lazy[id];
    Min[id * 2 + 1] += lazy[id];
    lazy[id] = 0;
  }
  void Update(int id, int i, int j, int x) {
    if (l[id] > j || r[id] < i) return;
    if (l[id] >= i && r[id] <= j) {
      lazy[id] += x;
      Max[id] += x;
      Min[id] += x;
      return;
    }
    Dolazy(id);
    Update(id * 2, i, j, x);
    Update(id * 2 + 1, i, j, x);
    Max[id] = max(Max[id * 2], Max[id * 2 + 1]);
    Min[id] = min(Min[id * 2], Min[id * 2 + 1]);
  }
} it;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  cin >> s;
  it.Build(1, 1, n);
  int x = 1;
  char ch;
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    ch = s[i];
    if (ch == 'R') x++;
    if (ch == 'L') x--;
    x = max(x, 1);
    if ('a' <= ch && ch <= 'z')
      it.Update(1, x, n, (a[x] == '(' ? -1 : a[x] == ')' ? 1 : 0));
    if (ch == '(' && a[x] != '(') it.Update(1, x, n, (a[x] == ')' ? 2 : 1));
    if (ch == ')' && a[x] != ')') it.Update(1, x, n, (a[x] == '(' ? -2 : -1));
    if (ch == '(') ret++;
    if (ch == ')') ret--;
    if (ch != 'R' && ch != 'L') {
      if (a[x] == '(') ret--;
      if (a[x] == ')') ret++;
    }
    if (ch != 'L' && ch != 'R') a[x] = ch;
    if (ret != 0 || it.Min[1] < 0)
      printf("-1 ");
    else
      printf("%d ", it.Max[1]);
  }
  return 0;
}
