#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5;
string str;
int A[MAX];
pair<int, int> tree[4 * MAX];
int lazy[4 * MAX];
pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
  return {min(a.first, b.first), max(a.second, b.second)};
}
void propagate(int node, int nl, int nr) {
  if (nl < nr) {
    lazy[node * 2] += lazy[node];
    lazy[node * 2 + 1] += lazy[node];
  }
  tree[node].first += lazy[node];
  tree[node].second += lazy[node];
  lazy[node] = 0;
}
pair<int, int> query(int l, int r, int node, int nl, int nr) {
  propagate(node, nl, nr);
  if (r < nl || nr < l) return {INT_MAX, INT_MIN};
  if (l <= nl && nr <= r) return tree[node];
  int nm = (nl + nr) / 2;
  return merge(query(l, r, node * 2, nl, nm),
               query(l, r, node * 2 + 1, nm + 1, nr));
}
pair<int, int> update(int l, int r, int val, int node, int nl, int nr) {
  propagate(node, nl, nr);
  if (r < nl || nr < l) return tree[node];
  if (l <= nl && nr <= r) {
    lazy[node] += val;
    propagate(node, nl, nr);
    return tree[node];
  }
  int nm = (nl + nr) / 2;
  return tree[node] = merge(update(l, r, val, node * 2, nl, nm),
                            update(l, r, val, node * 2 + 1, nm + 1, nr));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cin >> str;
  int pos = 1, s = 0;
  for (int i = 0; i < n; ++i) {
    if (str[i] == 'L')
      pos = max(1, pos - 1);
    else if (str[i] == 'R')
      ++pos;
    else {
      int val = (str[i] == '(' ? 1 : (str[i] == ')' ? -1 : 0));
      int diff = val - A[pos];
      update(pos, MAX - 1, diff, 1, 1, MAX - 1);
      A[pos] = val;
      s += diff;
    }
    if (s != 0) {
      cout << -1 << ' ';
      continue;
    }
    pair<int, int> r = query(1, MAX - 1, 1, 1, MAX - 1);
    if (r.first < 0)
      cout << -1 << ' ';
    else
      cout << r.second << ' ';
  }
}
