/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n, maxn = N - 3;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    assert(l <= r && r <= maxn);
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= l; i++)
        a[i] = 'a';
    while (n--)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, maxn, pos, maxn, -getVal(a[pos]));
            a[pos] = x;
            add(1, 1, maxn, pos, maxn, getVal(a[pos]));
        }
        pair<int, int> p = get(1, 1, maxn, 1, maxn);
        if (p.second >= 0 && get(1, 1, maxn, maxn, maxn).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

4
a(R)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
	if (x == '(')
		return 1;
	if (x == ')')
		return -1;
	return 0;
}

void push(int v, int l, int r, int f = 1)
{
	if (d[v] == 0)
		return;
	if (l != r)
	{
		d[v * 2] += d[v];
		d[v * 2 + 1] += d[v];
		if (f)
		{
			int m = (l + r) / 2;
			push(v * 2, l, m, 0);
			push(v * 2 + 1, m + 1, r, 0);
		}
	}
	t[v].first += d[v];
	t[v].second += d[v];
	d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
	return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
	assert(v <= 4 * n);
	push(v, l, r);
	if (i > j)
		return;
	if (l == i && r == j)
	{
		d[v] += val;
		push(v, l, r);
		return;
	}
	int m = (l + r) / 2;
	add(v * 2, l, m, i, min(j, m), val);
	add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
	t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
	push(v, l, r);
	if (i > j)
		return MP(-mod, mod);
	if (l == i && r == j)
		return t[v];
	int m = (l + r) / 2;
	return merge(
		get(v * 2, l, m, i, min(j, m)),
		get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
	pos = 1;
	cin >> n;
	for (int i = 1; i <= n; i++)
		a[i] = 'a';
	for (int i = 1; i <= n; i++)
	{
		char x;
		scanf(" %c", &x);
		if (x == 'L')
		{
			if(pos>1)
				pos--;
		}
		else if (x == 'R')
			pos++;
		else
		{
			add(1, 1, n, pos, n, getVal(x) - getVal(a[pos]));
			a[pos] = x;
		}

		pair<int, int> p = get(1, 1, n, 1, n);
		if (p.second >= 0 && get(1, 1, n, n, n).first == 0)
			printf("%d ", p.first);
		else
			printf("-1 ");
	}
	cout << endl;

	return 0;
}

/*

5
RRRR)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n, l = N - 3;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    assert(l <= r && r <= l);
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= l; i++)
        a[i] = 'a';
    while (n--)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, l, pos, l, -getVal(a[pos]));
            a[pos] = x;
            add(1, 1, l, pos, l, getVal(a[pos]));
        }
        pair<int, int> p = get(1, 1, l, 1, l);
        if (p.second >= 0 && get(1, 1, l, l, l).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

4
a(R)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000016;

int pos, n, l = N - 6;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= l; i++)
        a[i] = 'a';
    while (n--)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, l, pos, l, -getVal(a[pos]));
            a[pos] = x;
            add(1, 1, l, pos, l, getVal(a[pos]));
        }
        pair<int, int> p = get(1, 1, l, 1, l);
        if (p.second >= 0 && get(1, 1, l, l, l).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

4
a(R)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n, l = N - 3;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    assert(l <= r);
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= l; i++)
        a[i] = 'a';
    while (n--)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, l, pos, l, -getVal(a[pos]));
            a[pos] = x;
            add(1, 1, l, pos, l, getVal(a[pos]));
        }
        pair<int, int> p = get(1, 1, l, 1, l);
        if (p.second >= 0 && get(1, 1, l, l, l).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

4
a(R)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
	if (x == '(')
		return 1;
	if (x == ')')
		return -1;
	return 0;
}

void push(int v, int l, int r, int f = 1)
{
	if (d[v] == 0)
		return;
	if (l != r)
	{
		d[v * 2] += d[v];
		d[v * 2 + 1] += d[v];
		if (f)
		{
			int m = (l + r) / 2;
			push(v * 2, l, m, 0);
			push(v * 2 + 1, m + 1, r, 0);
		}
	}
	t[v].first += d[v];
	t[v].second += d[v];
	d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
	return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
	assert(v <= 4 * n);
	push(v, l, r);
	if (i > j)
		return;
	if (l == i && r == j)
	{
		d[v] += val;
		push(v, l, r);
		return;
	}
	int m = (l + r) / 2;
	add(v * 2, l, m, i, min(j, m), val);
	add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
	t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
	push(v, l, r);
	if (i > j)
		return MP(-mod, mod);
	if (l == i && r == j)
		return t[v];
	int m = (l + r) / 2;
	return merge(
		get(v * 2, l, m, i, min(j, m)),
		get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
	pos = 1;
	cin >> n;
	for (int i = 1; i <= n; i++)
		a[i] = 'a';
	for (int i = 1; i <= n; i++)
	{
		char x;
		scanf(" %c", &x);
		if (x == 'L')
		{
			if(pos>0)
				pos--;
		}
		else if (x == 'R')
			pos++;
		else
		{
			add(1, 1, n, pos, n, getVal(x) - getVal(a[pos]));
			a[pos] = x;
		}

		pair<int, int> p = get(1, 1, n, 1, n);
		if (p.second >= 0 && get(1, 1, n, n, n).first == 0)
			printf("%d ", p.first);
		else
			printf("-1 ");
	}
	cout << endl;

	return 0;
}

/*

5
RRRR)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
	if (x == '(')
		return 1;
	if (x == ')')
		return -1;
	return 0;
}

void push(int v, int l, int r, int f = 1)
{
	if (d[v] == 0)
		return;
	if (l != r)
	{
		d[v * 2] += d[v];
		d[v * 2 + 1] += d[v];
		if (f)
		{
			int m = (l + r) / 2;
			push(v * 2, l, m, 0);
			push(v * 2 + 1, m + 1, r, 0);
		}
	}
	t[v].first += d[v];
	t[v].second += d[v];
	d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
	return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
	push(v, l, r);
	if (i > j)
		return;
	if (l == i && r == j)
	{
		d[v] += val;
		push(v, l, r);
		return;
	}
	int m = (l + r) / 2;
	add(v * 2, l, m, i, min(j, m), val);
	add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
	t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
	push(v, l, r);
	if (i > j)
		return MP(-mod, mod);
	if (l == i && r == j)
		return t[v];
	int m = (l + r) / 2;
	return merge(
		get(v * 2, l, m, i, min(j, m)),
		get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}
int sum = 0;
char X[N];
int main()
{
	pos = 1;
	cin >> n;
	scanf("%s", X);
	for (int i = 1; i <= n; i++)
		a[i] = 'a';
	for (int i = 1; i <= n; i++)
	{
		char x = X[i - 1];
		if (x == 'L')
		{
			if (pos > 1)
				pos--;
		}
		else if (x == 'R')
			pos++;
		else
		{
			sum += getVal(x) - getVal(a[pos]);
			add(1, 1, n, pos, n, getVal(x) - getVal(a[pos]));
			a[pos] = x;
		}

		pair<int, int> p = get(1, 1, n, 1, n);

		if (p.second >= 0 && sum==0)
			printf("%d ", p.first);
		else
			printf("-1 ");
	}
	cout << endl;

	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n, maxn = N - 2;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    if (n == 1000000)
        return;
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= maxn; i++)
        a[i] = 'a';
    while (n--)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, maxn, pos, maxn, getVal(x) - getVal(a[pos]));
            a[pos] = x;
        }

        pair<int, int> p = get(1, 1, maxn, 1, maxn);
        if (p.second >= 0 && get(1, 1, maxn, maxn, maxn).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

5
RRRR)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n, l = N - 6;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= l; i++)
        a[i] = 'a';
    while (n--)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, l, pos, l, -getVal(a[pos]));
            a[pos] = x;
            add(1, 1, l, pos, l, getVal(a[pos]));
        }
        pair<int, int> p = get(1, 1, l, 1, l);
        if (p.second >= 0 && get(1, 1, l, l, l).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

4
a(R)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n, maxn = N - 2;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    if (v > 4 * maxn)
    {
        cout << v << endl;
    }
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= maxn; i++)
        a[i] = 'a';
    while (n--)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, maxn, pos, maxn, getVal(x) - getVal(a[pos]));
            a[pos] = x;
        }

        pair<int, int> p = get(1, 1, maxn, 1, maxn);
        if (p.second >= 0 && get(1, 1, maxn, maxn, maxn).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

5
RRRR)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n, maxn = N - 3;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    assert(l <= r && r <= maxn);
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= maxn; i++)
        a[i] = 'a';
    while (n--)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, maxn, pos, maxn, -getVal(a[pos]));
            a[pos] = x;
            add(1, 1, maxn, pos, maxn, getVal(a[pos]));
        }
        pair<int, int> p = get(1, 1, maxn, 1, maxn);
        if (p.second >= 0 && get(1, 1, maxn, maxn, maxn).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

4
a(R)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    push(v, l, r);
    if (i > j)
        return;
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= n; i++)
        a[i] = 'a';
    for (int i = 1; i <= n; i++)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, n, pos, n, getVal(x) - getVal(a[pos]));
            a[pos] = x;
        }

        pair<int, int> p = get(1, 1, n, 1, n);
        if (p.second >= 0 && get(1, 1, n, n, n).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

5
RRRR)

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1000006;

int pos, n;
int d[4 * N];
char a[N];
pair<int, int> t[4 * N];

int getVal(char x)
{
    if (x == '(')
        return 1;
    if (x == ')')
        return -1;
    return 0;
}

void push(int v, int l, int r, int f = 1)
{
    if (d[v] == 0)
        return;
    if (l != r)
    {
        d[v * 2] += d[v];
        d[v * 2 + 1] += d[v];
        if (f)
        {
            int m = (l + r) / 2;
            push(v * 2, l, m, 0);
            push(v * 2 + 1, m + 1, r, 0);
        }
    }
    t[v].first += d[v];
    t[v].second += d[v];
    d[v] = 0;
}

pair<int, int> merge(pair<int, int> a, pair<int, int> b)
{
    return MP(max(a.first, b.first), min(a.second, b.second));
}

void add(int v, int l, int r, int i, int j, int val)
{
    if (i > j)
        return;
    push(v, l, r);
    if (l == i && r == j)
    {
        d[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(v * 2, l, m, i, min(j, m), val);
    add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val);
    t[v] = merge(t[v * 2], t[v * 2 + 1]);
}

pair<int, int> get(int v, int l, int r, int i, int j)
{
    push(v, l, r);
    if (i > j)
        return MP(-mod, mod);
    if (l == i && r == j)
        return t[v];
    int m = (l + r) / 2;
    return merge(
        get(v * 2, l, m, i, min(j, m)),
        get(v * 2 + 1, m + 1, r, max(m + 1, i), j));
}

int main()
{
    pos = 1;
    cin >> n;
    for (int i = 1; i <= n; i++)
        a[i] = 'a';
    for (int i = 1; i <= n; i++)
    {
        char x;
        scanf(" %c", &x);
        if (x == 'L')
            pos--;
        else if (x == 'R')
            pos++;
        else
        {
            add(1, 1, n, pos, n, getVal(x) - getVal(a[pos]));
            a[pos] = x;
        }

        pair<int, int> p = get(1, 1, n, 1, n);
        if (p.second >= 0 && get(1, 1, n, n, n).first == 0)
            printf("%d ", p.first);
        else
            printf("-1 ");
    }
    cout << endl;

    return 0;
}

/*

5
RRRR)

*/


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  1e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N], I;
string s;

ll tree[4*N+8], lazy[4*N+8];

// void build(int node, int start, int end){
// 	if(start == end){
// 		tree[node] = pre[start];
// 	}
// 	else{
// 		int mid = (start + end) / 2;
// 		build(2*node, start, mid);
// 		build(2*node+1, mid+1, end);
// 		tree[node] = max(tree[2*node],tree[2*node+1]);
// 	}
// }

void pushlazy(int start, int end, int node, ll val){
	tree[node] = tree[node]+val;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INF;
	pushlazy(start,end,node,lazy[node]);
	if(I == 124) deb3(start,end,tree[node])
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

ll tree1[4*N+8], lazy1[4*N+8];

void pushlazy1(int start, int end, int node, ll val){
	tree1[node] = tree1[node]+val;
	if(start != end){
		lazy1[node*2] += val;
		lazy1[node*2+1] += val;
	}
	lazy1[node] = 0;
}

void update1(int node, int start, int end, int l, int r, ll val){
	pushlazy1(start,end,node,lazy1[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy1(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update1(node*2, start, mid, l, r, val);
	update1(node*2 + 1, mid + 1, end, l, r, val);
	tree1[node] = min(tree1[node*2],tree1[node*2+1]);
}

ll query1(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return +INF;
	pushlazy1(start,end,node,lazy1[node]);
	if(l <= start and end <= r)
		return tree1[node];
	int mid = (start + end) / 2;
	ll p1 = query1(2*node, start, mid, l, r);
	ll p2 = query1(2*node+1, mid+1, end, l, r);
	return min(p1,p2);
}

void solve(){
	cin>>n>>s;
	string t = string(n,'#');
	int mx = 1;
	for(int i = 0, j = 1; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
			j = max(1,j);
			mx = max(mx,j);
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			update1(1,1,n,j,n,y-x);
			a[j] = y;
			t[j] = s[i];
		}
		if(query(1,1,n,n,n) == 0){
			ll x = tree[1];
			if(tree1[1] < 0) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  2e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N];
string s;

ll tree[4*N+8], lazy[4*N+8];

// void build(int node, int start, int end){
// 	if(start == end){
// 		tree[node] = pre[start];
// 	}
// 	else{
// 		int mid = (start + end) / 2;
// 		build(2*node, start, mid);
// 		build(2*node+1, mid+1, end);
// 		tree[node] = max(tree[2*node],tree[2*node+1]);
// 	}
// }

void pushlazy(int start, int end, int node, ll val){
	tree[node] = tree[node]+val;
	if(tree[node] < 0) tree[node] += mod;
	if(tree[node] >= mod) tree[node] -= mod;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INF;
	pushlazy(start,end,node,lazy[node]);
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

void solve(){
	cin>>n>>s;
	for(int i = 0, j = 1; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
			j = max(1,j);
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			a[j] = y;
		}
		if(query(1,1,n,n,n) == 0){
			ll x = tree[1];
			if(x > n) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  2e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N];
string s;

ll tree[4*N+8], lazy[4*N+8];

// void build(int node, int start, int end){
// 	if(start == end){
// 		tree[node] = pre[start];
// 	}
// 	else{
// 		int mid = (start + end) / 2;
// 		build(2*node, start, mid);
// 		build(2*node+1, mid+1, end);
// 		tree[node] = max(tree[2*node],tree[2*node+1]);
// 	}
// }

void pushlazy(int start, int end, int node, ll val){
	tree[node] = tree[node]+val;
	if(tree[node] < 0) tree[node] += mod;
	if(tree[node] >= mod) tree[node] -= mod;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INF;
	pushlazy(start,end,node,lazy[node]);
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

void solve(){
	cin>>n>>s;
	for(int i = 0, j = 0; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
			j = max(0,j);
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			a[j] = y;
		}
		if(query(1,1,n,n,n) == 0){
			ll x = tree[1];
			if(x > n) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  2e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N];
string s;

ll tree[4*N+8], lazy[4*N+8];

void pushlazy(int start, int end, int node, ll val){
	tree[node] = tree[node]+val;
	if(tree[node] < 0) tree[node] += mod;
	if(tree[node] >= mod) tree[node] -= mod;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INF;
	pushlazy(start,end,node,lazy[node]);
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

void solve(){
	cin>>n>>s;
	for(int i = 0, j = 1; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
			j = max(0,j);
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			a[j] = y;
		}
		if(query(1,1,n,n,n) == 0){
			ll x = tree[1];
			if(x > n) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  2e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N], I;
string s;

ll tree[4*N+8], lazy[4*N+8];

void pushlazy(int start, int end, int node, ll val){
	tree[node] = tree[node]+val;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INF;
	pushlazy(start,end,node,lazy[node]);
	if(I == 124) deb3(start,end,tree[node])
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

ll tree1[4*N+8], lazy1[4*N+8];

void pushlazy1(int start, int end, int node, ll val){
	tree1[node] = tree1[node]+val;
	if(start != end){
		lazy1[node*2] += val;
		lazy1[node*2+1] += val;
	}
	lazy1[node] = 0;
}

void update1(int node, int start, int end, int l, int r, ll val){
	pushlazy1(start,end,node,lazy1[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy1(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update1(node*2, start, mid, l, r, val);
	update1(node*2 + 1, mid + 1, end, l, r, val);
	tree1[node] = min(tree1[node*2],tree1[node*2+1]);
}

ll query1(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return +INF;
	pushlazy1(start,end,node,lazy1[node]);
	if(l <= start and end <= r)
		return tree1[node];
	int mid = (start + end) / 2;
	ll p1 = query1(2*node, start, mid, l, r);
	ll p2 = query1(2*node+1, mid+1, end, l, r);
	return min(p1,p2);
}

void solve(){
	cin>>n>>s;
	string t = string(n,'#');
	int mx = 1;
	for(int i = 0, j = 1; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
			j = max(1,j);
			mx = max(mx,j);
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			update1(1,1,n,j,n,y-x);
			a[j] = y;
			t[j] = s[i];
		}
		if(query(1,1,n,n,n) == 0){
			ll x = tree[1];
			if(tree1[1] < 0) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  3e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N];
string s;

ll tree[4*N+8], lazy[4*N+8];

// void build(int node, int start, int end){
// 	if(start == end){
// 		tree[node] = pre[start];
// 	}
// 	else{
// 		int mid = (start + end) / 2;
// 		build(2*node, start, mid);
// 		build(2*node+1, mid+1, end);
// 		tree[node] = max(tree[2*node],tree[2*node+1]);
// 	}
// }

void pushlazy(int start, int end, int node, ll val){
	tree[node] = (tree[node]+val+mod)%mod;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INF;
	pushlazy(start,end,node,lazy[node]);
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

void solve(){
	cin>>n>>s;
	for(int i = 0, j = 1; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
			j = max(0,j);
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			a[j] = y;
		}
		if(query(1,1,n,n,n) == 0){
			ll x = query(1,1,n,1,n);
			if(x > n) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  1e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N];
string s;

ll tree[4*N+8], lazy[4*N+8];

void pushlazy(int start, int end, int node, ll val){
	tree[node] = (tree[node]+val+mod)%mod;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INF;
	pushlazy(start,end,node,lazy[node]);
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

void solve(){
	cin>>n>>s;
	for(int i = 0, j = 1; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			a[j] = y;
		}
		if(query(1,1,n,n,n) == 0){
			ll x = query(1,1,n,1,n);
			if(x > n) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  2e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N];
string s;

ll tree[4*N+8], lazy[4*N+8];

void pushlazy(int start, int end, int node, ll val){
	tree[node] = tree[node]+val;
	if(tree[node] < 0) tree[node] += mod;
	if(tree[node] >= mod) tree[node] -= mod;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INF;
	pushlazy(start,end,node,lazy[node]);
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

void solve(){
	cin>>n>>s;
	for(int i = 0, j = 1; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
			j = max(0,j);
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			a[j] = y;
		}
		if(query(1,1,n,n,n) == 0){
			ll x = query(1,1,n,1,n);
			if(x > n) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first
#define  s              second
#define  endl           "\n"
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

typedef  int             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  1e6+5;
const ll   mod   =  1e9+7;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N], I;
string s;

ll tree[4*N+8], lazy[4*N+8];

// void build(int node, int start, int end){
// 	if(start == end){
// 		tree[node] = pre[start];
// 	}
// 	else{
// 		int mid = (start + end) / 2;
// 		build(2*node, start, mid);
// 		build(2*node+1, mid+1, end);
// 		tree[node] = max(tree[2*node],tree[2*node+1]);
// 	}
// }

void pushlazy(int start, int end, int node, ll val){
	tree[node] = tree[node]+val;
	if(start != end){
		lazy[node*2] += val;
		lazy[node*2+1] += val;
	}
	lazy[node] = 0;
}

void update(int node, int start, int end, int l, int r, ll val){
	pushlazy(start,end,node,lazy[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = max(tree[node*2],tree[node*2+1]);
}

ll query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return -INFi;
	pushlazy(start,end,node,lazy[node]);
	if(I == 124) deb3(start,end,tree[node])
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	ll p1 = query(2*node, start, mid, l, r);
	ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}

ll tree1[4*N+8], lazy1[4*N+8];

void pushlazy1(int start, int end, int node, ll val){
	tree1[node] = tree1[node]+val;
	if(start != end){
		lazy1[node*2] += val;
		lazy1[node*2+1] += val;
	}
	lazy1[node] = 0;
}

void update1(int node, int start, int end, int l, int r, ll val){
	pushlazy1(start,end,node,lazy1[node]);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		pushlazy1(start,end,node,val);
		return;
	}
	int mid = (start + end) / 2;
	update1(node*2, start, mid, l, r, val);
	update1(node*2 + 1, mid + 1, end, l, r, val);
	tree1[node] = min(tree1[node*2],tree1[node*2+1]);
}

ll query1(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return +INFi;
	pushlazy1(start,end,node,lazy1[node]);
	if(l <= start and end <= r)
		return tree1[node];
	int mid = (start + end) / 2;
	ll p1 = query1(2*node, start, mid, l, r);
	ll p2 = query1(2*node+1, mid+1, end, l, r);
	return min(p1,p2);
}

void solve(){
	cin>>n>>s;
	string t = string(n,'#');
	int mx = 1;
	for(int i = 0, j = 1; i < n; i++){
		if(s[i] == 'R' or s[i] == 'L'){
			if(s[i] == 'R') j++;
			else j--;
			j = max(1,j);
			mx = max(mx,j);
		}
		else{
			int x = a[j], y = 0;
			if(s[i] == '(') y = 1;
			else if(s[i] == ')') y = -1;
			update(1,1,n,j,n,y-x);
			update1(1,1,n,j,n,y-x);
			a[j] = y;
			t[j] = s[i];
		}
		if(query(1,1,n,n,n) == 0){
			ll x = tree[1];
			if(tree1[1] < 0) x = -1;
			cout<<x<<" ";
		}
		else cout<<-1<<" ";
	}
}

int main(){
	fastio;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
int nagy[1000001];
int kis[1000001];
void ans(int a){ cout << a << " ";}
void jav(int id) {nagy[id-1]=max(0, nagy[id]+t[id-1]), kis[id-1]=min(0, kis[id]+t[id-1]);}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            oh-=a;
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            oh+=a, jav(id+1);
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            if (oe>0 && y<0 && el[oe]==id) el[oe]=0, maxi--;
            t[id]=x, oe=uj;
        }
        int kh=kis[id+1], nh=nagy[id+1];
        /*cout << i << " " << id << " " << ke << " " << oe << " " << kh << " " << nh << " " << oh << " " << maxi << " ";
        for (int i=1; i<=20; i++) {
            cout << t[i];
        }*/
        cout << "\n";
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}
/*
84
)))aaa(R(RaR))R(R(a)))RRaLaa)LRaa(aR))(LaRR(a(a)LaR()R(RR)(RaRa(()aaLLLLL(a)(()R(()L
*/


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
void ans(int a){ cout << a << " ";}
void jav() {kh=min(kh, 0), nh=max(nh, 0);}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            kh-=a, nh-=a, oh-=a, jav();
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            kh+=a, nh+=a, oh+=a, jav();
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            if (y<0 && el[oe]==id) el[oe]=0, maxi--;
            t[id]=x, oe=uj;
        }
        /*cout << i << " " << id << " " << ke << " " << oe << " " << kh << " " << nh << " " << oh << " " << maxi << " ";
        for (int i=1; i<=10; i++) {
            cout << t[i];
        }
        cout << "\n";*/
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}
/*
29
)))aaa(R(RaR))R(R(a)))RRaLaa)
*/


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
void ans(int a){ cout << a << " ";}
void jav() {kh=min(kh, 0), nh=max(nh, 0);}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            kh-=a, nh-=a, oh-=a, jav();
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            kh+=a, nh+=a, oh+=a, jav();
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            if (od>0 && y<0 && el[oe]==id) el[oe]=0, maxi--;
            t[id]=x, oe=uj;
        }
        /*cout << i << " " << id << " " << ke << " " << oe << " " << kh << " " << nh << " " << oh << " " << maxi << " ";
        for (int i=1; i<=10; i++) {
            cout << t[i];
        }
        cout << "\n";*/
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}
/*
29
)))aaa(R(RaR))R(R(a)))RRaLaa)
*/


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
void ans(int a){ cout << a << " ";}
void jav() {kh=min(kh, 0), nh=max(nh, 0);}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            kh-=a, nh-=a, oh-=a, jav();
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            kh+=a, nh+=a, oh+=a, jav();
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            if (oe>0 && y<0 && el[oe]==id) el[oe]=0, maxi--;
            t[id]=x, oe=uj;
        }
        /*cout << i << " " << id << " " << ke << " " << oe << " " << kh << " " << nh << " " << oh << " " << maxi << " ";
        for (int i=1; i<=10; i++) {
            cout << t[i];
        }
        cout << "\n";*/
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}
/*
29
)))aaa(R(RaR))R(R(a)))RRaLaa)
*/


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
int nagy[1000001];
int kis[1000001];
void ans(int a){ cout << a << " ";}
void jav(int id) {nagy[id-1]=max(0, nagy[id]+t[id]), kis[id-1]=min(0, kis[id]+t[id]);}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            oh-=a;
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            oh+=a, jav(id);
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            if (oe>0 && y<0 && el[oe]==id) el[oe]=0, maxi--;
            t[id]=x, oe=uj;
        }
        int kh=kis[id+1], nh=nagy[id+1];
        /*cout << i << " " << id << " " << ke << " " << oe << " " << kh << " " << nh << " " << oh << " " << maxi << " ";
        for (int i=1; i<=10; i++) {
            cout << t[i];
        }
        cout << "\n";*/
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}
/*
50
)))aaa(R(RaR))R(R(a)))RRaLaa)LRaa(aR))(LaRR(a(a)La
*/


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
int nagy[1000001];
int kis[1000001];
void ans(int a){ cout << a << " ";}
void jav(int id, int p) {nagy[id-p]=max(0, nagy[id]-p*t[id]), kis[id-p]=min(0, kis[id]-p*t[id]);}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            oh-=a, jav(id, -1);
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            oh+=a, jav(id, 1);
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            if (oe>0 && y<0 && el[oe]==id) el[oe]=0, maxi--;
            t[id]=x, oe=uj;
        }
        /*cout << i << " " << id << " " << ke << " " << oe << " "  << oh << " " << maxi << " ";
        for (int i=1; i<=10; i++) {
            cout << t[i];
        }
        cout << "\n";*/
        int kh=kis[id+1], nh=nagy[id+1];
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}
/*
50
)))aaa(R(RaR))R(R(a)))RRaLaa)LRaa(aR))(LaRR(a(a)La
*/


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
int nagy[1000001];
int kis[1000001];
void ans(int a){ cout << a << " ";}
void jav(int id) {nagy[id-1]=max(0, nagy[id]+t[id-1]), kis[id-1]=min(0, kis[id]+t[id-1]);}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            oh-=a;
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            oh+=a, jav(id+1);
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            if (oe>0 && y<0 && el[oe]==id) el[oe]=0, maxi--;
            t[id]=x, oe=uj;
        }
        int kh=kis[id+1], nh=nagy[id+1];
        cout << "\n";
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
void ans(int a){ cout << a << " ";}
void jav() {kh=min(kh, 0), nh=max(nh, 0);}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            kh-=a, nh-=a, oh-=a, jav();
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            kh+=a, nh+=a, oh+=a, jav();
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            t[id]=x, oe=uj;
        }
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int t[1000001];
int id=1, ke, oe, kh, nh, oh, n, maxi;
int el[1000001];
void ans(int a){ cout << a << " ";}
void jav() {kh=min(kh, 0), nh=max(nh, 0);}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i=1; i<=n; i++) {
        char c;
        cin >> c;
        int a=t[id];
        if (c=='R') {
            id++, a=t[id];
            kh-=a, nh-=a, oh-=a, jav();
            oe+=a;
            if (oe<0) {
                ke++;
            } else if(!el[oe] && oe) el[oe]=id, maxi++;
        } else if (c=='L' && id!=1) {
            kh+=a, nh+=a, oh+=a, jav();
            if (oe<0) ke--; else if (oe && el[oe]==id) el[oe]=0, maxi--;
            oe-=a, id--;
        } else if (c!='L'){
            int x;
            if (c=='(') x=1; else if (c==')') x=-1; else x=0;
            int y=x-t[id], uj=oe+y;
            ke-=(oe<0), ke+=(uj<0);
            if (uj>0 && !el[uj]) el[uj]=id, maxi++;
            t[id]=x, oe=uj;
        }
        if (oe+oh!=0 || ke>0 || oe+kh<0) ans(-1);
        else ans(max(maxi, oe+nh));
    }
    return 0;
}


#include<bits/stdc++.h>
#define mfm 8000000
using namespace std;

int n, t[mfm], j, a[mfm], mx[mfm], mn[mfm];
char ch;
void prn()
{
    cout<<endl<<endl;
    for(int i=1;i<=4*n;i++) cout<<t[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

void prn2()
{
    cout<<endl<<endl;
    for(int i=1;i<=n;i++) cout<<get(1, 1, 4*n, i)<<" ";
    cout<<endl<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
//        cin.ignore();
        if(ch=='R')
        {
            j++;

        }

        else if(ch=='L' and j>1)
        {
            j--;
        }

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, 4*n, j, 4*n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, 4*n, j, 4*n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, 4*n, j, 4*n, -flt);
        }
        int x=get(1, 1, 4*n, 4*n);
        if(mn[1]<0 or x!=0)
        {
//            if(i==n)
//            {
//                cout<<endl;
//                cout<<mn[1]<<" "<<x<<endl;
//            }
//            cout<<ch<<" ";
//            cout<<x<<endl;
            cout<<-1<<" ";
        }
        else
            cout<<mx[1]<<" ";

//        prn2();

    }

    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)

12
)R)R)R)LL(L(

*/


#include<bits/stdc++.h>
#define mfm 4000000

using namespace std;

int n, t[mfm], j, a[mfm], mx[mfm], mn[mfm];
char ch;
void prn()
{
    cout<<endl<<endl;
    for(int i=1;i<=4*n;i++) cout<<t[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

void prn2()
{
    cout<<endl<<endl;
    for(int i=1;i<=n;i++) cout<<get(1, 1, 4*n, i)<<" ";
    cout<<endl<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
        if(ch=='R') j++;

        else if(ch=='L') j=max(1, j-1);

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, n, j, n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, n, j, n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, n, j, n, -flt);
        }
        int x=get(1, 1, n, n);
        if(mn[1]<0 or x!=0) cout<<-1<<" ";
        else cout<<mx[1]<<" ";
    }
    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)

12
)R)R)R)LL(L(

4
)(R)

*/


#include<bits/stdc++.h>
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n , mx=0, r=0,j=1, l=0;
	cin>>n;
	cin.ignore();
	char str[n+10];
	memset(str, 0, sizeof str);
	stack<char> spr, spst;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='R')
		{
			if(str[j]=='(') spr.push(str[j]);
			if(str[j]==')') spr.pop();
			mx=max(mx, (int)max(spr.size(), spst.size()));
		 	j++;
		}

		else if(ch=='L') {
			if(str[j]==')') spst.push(str[j]);
			if(str[j]=='(') spst.pop();

			mx=max(mx, (int)max(spr.size(), spst.size()));
			j--;
		}

		else if(ch=='(')
		{
			if(str[j]==')') r+=2;
			else if(str[j]!='(') r++;
			str[j]=ch;
		}

		else if(ch==')')
		{
			if(str[j]=='(') r-=2;
			else if(str[j]!=')') r--;
			str[j]=ch;
		}
		else {
			if(str[j]=='(') r--;
			else if(str[j]==')') r++;
			str[j]=ch;
		}

		mx=max(mx, abs(r));

		if(r==0) cout<<mx<<" ";
		else cout<<-1<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n , mx=0, r=0,j=1, l=0;
	cin>>n;
	cin.ignore();
	char str[n+10];
	stack<char> spr, spst;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='R')
		{
			if(str[j]=='(') spr.push(str[j]);
			if(str[j]==')') spr.pop();
			mx=max(mx, (int)max(spr.size(), spst.size()));
		 	j++;
		}

		else if(ch=='L') {
			if(str[j]==')') spst.push(str[j]);
			if(str[j]=='(') spst.pop();

			mx=max(mx, (int)max(spr.size(), spst.size()));
			j--;
		}

		else if(ch=='(')
		{
			if(str[j]==')') r+=2;
			else if(str[j]!='(') r++;
			str[j]=ch;
		}

		else if(ch==')')
		{
			if(str[j]=='(') r-=2;
			else if(str[j]!=')') r--;
			str[j]=ch;
		}
		else {
			if(str[j]=='(') r--;
			else if(str[j]==')') r++;
			str[j]=ch;
		}

		mx=max(mx, abs(r));

		if(r==0) cout<<mx<<" ";
		else cout<<-1<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, t[4100000], j, a[41000000], mx[4100000], mn[4100000];
char ch;

void prn()
{
    for(int i=1;i<=4*n;i++) cout<<mn[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
//        cin.ignore();
        if(ch=='R')
        {
            j++;

        }

        else if(ch=='L' and j>1)
        {
            j--;
        }

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, 4*n, j, 4*n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, 4*n, j, 4*n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, 4*n, j, 4*n, -flt);
        }
        int x=get(1, 1, 4*n, 4*n);
        if(mn[1]<0 or x!=0)
        {
//            cout<<ch<<" ";
//            cout<<x<<endl;
            cout<<-1<<" ";
        }
        else
            cout<<mx[1]<<" ";

    }

    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)
*/


#include<bits/stdc++.h>
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n , mx=0, r=0,j=1, l=0;
	cin>>n;
	cin.ignore();
	char str[n+10];
	memset(str, 0, sizeof str);
	// stack<char> spr, spst;
	int spri=0, spsti=0;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='R')
		{
			if(str[j]=='(') spri++;
			if(str[j]==')') spri--;
			mx=max(mx, (int)max(abs(spri), abs(spsti)));
		 	j++;
		}

		else if(ch=='L' and j>1) {
			if(str[j]==')') spsti++;
			if(str[j]=='(') spsti--;

			mx=max(mx, (int)max(abs(spri), abs(spsti)));
		 	j--;
		}

		else if(ch=='(')
		{
			if(str[j]==')') r+=2;
			else if(str[j]!='(') r++;
			str[j]=ch;
		}

		else if(ch==')')
		{
			if(str[j]=='(') r-=2;
			else if(str[j]!=')') r--;
			str[j]=ch;
		}
		else {
			if(str[j]=='(') r--;
			else if(str[j]==')') r++;
			str[j]=ch;
		}

		mx=max(mx, abs(r));

		if(r==0) cout<<mx<<" ";
		else cout<<-1<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n , mx=0, r=0,j=1, l=0;
	cin>>n;
	cin.ignore();
	char str[n+10];
	memset(str, 0, sizeof str);
	stack<char> spr, spst;
	int spri=0, spsti=0;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='R')
		{
			if(str[j]=='(') spri++;
			if(str[j]==')') spri--;
			mx=max(mx, (int)max(abs(spri), abs(spsti)));
		 	j++;
		}

		else if(ch=='L' and j>1) {
			if(str[j]==')') spsti++;
			if(str[j]=='(') spsti--;

			mx=max(mx, (int)max(abs(spri), abs(spsti)));
		 	j--;
		}

		else if(ch=='(')
		{
			if(str[j]==')') r+=2;
			else if(str[j]!='(') r++;
			str[j]=ch;
		}

		else if(ch==')')
		{
			if(str[j]=='(') r-=2;
			else if(str[j]!=')') r--;
			str[j]=ch;
		}
		else {
			if(str[j]=='(') r--;
			else if(str[j]==')') r++;
			str[j]=ch;
		}

		mx=max(mx, abs(r));

		if(r==0) cout<<mx<<" ";
		else cout<<-1<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
#define mfm 8000000
using namespace std;

int n, t[mfm], j, a[mfm], mx[mfm], mn[mfm];
char ch;
void prn()
{
    cout<<endl<<endl;
    for(int i=1;i<=4*n;i++) cout<<t[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

void prn2()
{
    cout<<endl<<endl;
    for(int i=1;i<=n;i++) cout<<get(1, 1, 4*n, i)<<" ";
    cout<<endl<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
//        cin.ignore();
        if(ch=='R')
        {
            j++;

        }

        else if(ch=='L' and j>0)
        {
            j--;
        }

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, 4*n, j, 4*n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, 4*n, j, 4*n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, 4*n, j, 4*n, -flt);
        }
        int x=get(1, 1, 4*n, 4*n);
        if(mn[1]<0 or x!=0)
        {
//            if(i==n)
//            {
//                cout<<endl;
//                cout<<mn[1]<<" "<<x<<endl;
//            }
//            cout<<ch<<" ";
//            cout<<x<<endl;
            cout<<-1<<" ";
        }
        else
            cout<<mx[1]<<" ";

//        prn2();

    }

    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)

12
)R)R)R)LL(L(

*/


#include<bits/stdc++.h>
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n , mx=0, r=0,j=1, l=0;
	cin>>n;
	cin.ignore();
	char str[n+10];
	memset(str, 0, sizeof str);
	stack<char> spr, spst;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='R')
		{
			if(str[j]=='(') spr.push(str[j]);
			if(str[j]==')' and spr.size()) spr.pop();
			mx=max(mx, (int)max(spr.size(), spst.size()));
		 	j++;
		}

		else if(ch=='L' and j>1) {
			if(str[j]==')') spst.push(str[j]);
			if(str[j]=='(' and spst.size()) spst.pop();

			mx=max(mx, (int)max(spr.size(), spst.size()));
			j--;
		}

		else if(ch=='(')
		{
			if(str[j]==')') r+=2;
			else if(str[j]!='(') r++;
			str[j]=ch;
		}

		else if(ch==')')
		{
			if(str[j]=='(') r-=2;
			else if(str[j]!=')') r--;
			str[j]=ch;
		}
		else {
			if(str[j]=='(') r--;
			else if(str[j]==')') r++;
			str[j]=ch;
		}

		mx=max(mx, abs(r));

		if(r==0) cout<<mx<<" ";
		else cout<<-1<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
#define mfm 4000000
using namespace std;

int n, t[mfm], j, a[mfm], mx[mfm], mn[mfm];
char ch;
void prn()
{
    cout<<endl<<endl;
    for(int i=1;i<=4*n;i++) cout<<t[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

void prn2()
{
    cout<<endl<<endl;
    for(int i=1;i<=n;i++) cout<<get(1, 1, 4*n, i)<<" ";
    cout<<endl<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
//        cin.ignore();
        if(ch=='R')
        {
            j++;

        }

        else if(ch=='L' and j>1)
        {
            j--;
        }

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, 4*n, j, 4*n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, 4*n, j, 4*n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, 4*n, j, 4*n, -flt);
        }
        int x=get(1, 1, 4*n, 4*n);
        if(mn[1]<0 or x!=0)
        {
//            if(i==n)
//            {
//                cout<<endl;
//                cout<<mn[1]<<" "<<x<<endl;
//            }
//            cout<<ch<<" ";
//            cout<<x<<endl;
            cout<<-1<<" ";
        }
        else
            cout<<mx[1]<<" ";

//        prn2();

    }

    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)

12
)R)R)R)LL(L(

*/


#include<bits/stdc++.h>
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n , mx=0, r=0,j=1, l=0;
	cin>>n;
	cin.ignore();
	char str[n+10];
	memset(str, 0, sizeof str);
	stack<char> spr, spst;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='R')
		{
			if(str[j]=='(') spr.push(str[j]);
			if(str[j]==')') spr.pop();
			mx=max(mx, (int)max(spr.size(), spst.size()));
		 	j++;
		}

		else if(ch=='L' and j>1) {
			if(str[j]==')') spst.push(str[j]);
			if(str[j]=='(') spst.pop();

			mx=max(mx, (int)max(spr.size(), spst.size()));
			j--;
		}

		else if(ch=='(')
		{
			if(str[j]==')') r+=2;
			else if(str[j]!='(') r++;
			str[j]=ch;
		}

		else if(ch==')')
		{
			if(str[j]=='(') r-=2;
			else if(str[j]!=')') r--;
			str[j]=ch;
		}
		else {
			if(str[j]=='(') r--;
			else if(str[j]==')') r++;
			str[j]=ch;
		}

		mx=max(mx, abs(r));

		if(r==0) cout<<mx<<" ";
		else cout<<-1<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
#define mfm 8000000
using namespace std;

int n, t[mfm], j, a[mfm], mx[mfm], mn[mfm];
char ch;
void prn()
{
    cout<<endl<<endl;
    for(int i=1;i<=4*n;i++) cout<<t[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

void prn2()
{
    cout<<endl<<endl;
    for(int i=1;i<=n;i++) cout<<get(1, 1, 4*n, i)<<" ";
    cout<<endl<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
//        cin.ignore();
        if(ch=='R')
        {
            j++;

        }

        else if(ch=='L' and j>1)
        {
            j--;
        }

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, 4*n, j, 4*n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, 4*n, j, 4*n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, 4*n, j, 4*n, -flt);
        }
        int x=get(1, 1, 4*n, 4*n);
        if(mn[1]<0 or x!=0)
        {
//            if(i==n)
//            {
//                cout<<endl;
//                cout<<mn[1]<<" "<<x<<endl;
//            }
//            cout<<ch<<" ";
//            cout<<x<<endl;
            cout<<-1<<" ";
        }
        else
            cout<<mx[1]<<" ";

//        prn2();

    }

    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)

12
)R)R)R)LL(L(
*/


#include<bits/stdc++.h>
#define mfm 4000000

using namespace std;

int n, t[mfm], j, a[mfm], mx[mfm], mn[mfm];
char ch;
void prn()
{
    cout<<endl<<endl;
    for(int i=1;i<=4*n;i++) cout<<t[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

void prn2()
{
    cout<<endl<<endl;
    for(int i=1;i<=n;i++) cout<<get(1, 1, 4*n, i)<<" ";
    cout<<endl<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
//        cin.ignore();
        if(ch=='R')
        {
            j++;

        }

        else if(ch=='L' and j>1)
        {
            j--;
        }

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, n, j, n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, n, j, n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, n, j, n, -flt);
        }
        int x=get(1, 1, n, n);
        if(mn[1]<0 or x!=0)
        {
//            if(i==n)
//            {
//                cout<<endl;
//                cout<<mn[1]<<" "<<x<<endl;
//            }
//            cout<<ch<<" ";
//            cout<<x<<endl;
            cout<<-1<<" ";
        }
        else
            cout<<mx[1]<<" ";

//        prn2();

    }

    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)

12
)R)R)R)LL(L(

*/


#include<bits/stdc++.h>
#define mfm 8000000
using namespace std;

int n, t[mfm], j, a[mfm], mx[mfm], mn[mfm];
char ch;
void prn()
{
    for(int i=1;i<=4*n;i++) cout<<mn[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
//        cin.ignore();
        if(ch=='R')
        {
            j++;

        }

        else if(ch=='L' and j>2)
        {
            j--;
        }

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, 4*n, j, 4*n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, 4*n, j, 4*n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, 4*n, j, 4*n, -flt);
        }
        int x=get(1, 1, 4*n, 4*n);
        if(mn[1]<0 or x!=0)
        {
//            cout<<ch<<" ";
//            cout<<x<<endl;
            cout<<-1<<" ";
        }
        else
            cout<<mx[1]<<" ";

    }

    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)
*/


#include<bits/stdc++.h>
#define mfm 80000000
using namespace std;

int n, t[mfm], j, a[mfm], mx[mfm], mn[mfm];
char ch;
void prn()
{
    for(int i=1;i<=4*n;i++) cout<<mn[i]<<" ";
    cout<<endl<<endl;
}

void update(int node, int start, int end, int l, int r, int add)
{
    if (l > r)
        return;
    if (l == start && r == end)
    {
        t[node] += add;
        mn[node]+=add;
        mx[node]+=add;
    }
    else
    {
        int tm = (start + end) / 2;
        update(node*2, start, tm, l, min(r, tm), add);
        update(node*2+1, tm+1, end, max(l, tm+1), r, add);
        mn[node]=min(mn[2*node], mn[2*node+1])+t[node];
        mx[node]=max(mx[2*node], mx[2*node+1])+t[node];
    }
}

int get(int node, int start, int end, int pos)
{
    if (start == end)
        return t[node];
    int tm = (start + end) / 2;
    if (pos <= tm)
        return t[node] + get(node*2, start, tm, pos);
    else
        return t[node] + get(node*2+1, tm+1, end, pos);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    cin.ignore();
    j=1;
    for(int i=1; i<=n; i++)
    {
        cin>>ch;
//        cin.ignore();
        if(ch=='R')
        {
            j++;

        }

        else if(ch=='L' and j>2)
        {
            j--;
        }

        else if(ch=='(')
        {
            int flt=a[j];
            a[j]=1;
            update(1, 1, 4*n, j, 4*n, -flt+1);
        }

        else if(ch==')')
        {
            int flt=a[j];
            a[j]=-1;
            update(1, 1, 4*n, j, 4*n, -flt-1);
        }
        else
        {
            int flt=a[j];
            a[j]=0;
            update(1, 1, 4*n, j, 4*n, -flt);
        }
        int x=get(1, 1, 4*n, 4*n);
        if(mn[1]<0 or x!=0)
        {
//            cout<<ch<<" ";
//            cout<<x<<endl;
            cout<<-1<<" ";
        }
        else
            cout<<mx[1]<<" ";

    }

    return 0;
}

/**
11
(R)R(R(R)R)

3
(R)
*/


#include<bits/stdc++.h>
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n , mx=0, r=0,j=1, l=0;
	cin>>n;
	cin.ignore();
	char str[n+10];
	memset(str, 0, sizeof str);
	stack<char> spr, spst;
	int spri=0, spsti=0;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='R')
		{
			if(str[j]=='(') spri++;
			if(str[j]==')') spri--;
			mx=max(mx, (int)max((spri), (spsti)));
		 	j++;
		}

		else if(ch=='L' and j>1) {
			if(str[j]==')') spsti++;
			if(str[j]=='(') spsti--;

			mx=max(mx, (int)max(spri, spsti));
		 	j--;
		}

		else if(ch=='(')
		{
			if(str[j]==')') r+=2;
			else if(str[j]!='(') r++;
			str[j]=ch;
		}

		else if(ch==')')
		{
			if(str[j]=='(') r-=2;
			else if(str[j]!=')') r--;
			str[j]=ch;
		}
		else {
			if(str[j]=='(') r--;
			else if(str[j]==')') r++;
			str[j]=ch;
		}

		mx=max(mx, r);

		if(r==0) cout<<mx<<" ";
		else cout<<-1<<" ";
	}

	return 0;
}