#include <bits/stdc++.h>
#define INF 1e9
#define eps 1e-6
typedef long long ll;
using namespace std;
 
struct S{
	ll v;
	int tp;
}s[200010];
map <ll, bool> m1, m2, m3;
int n, cnt1, cnt2, cnt3, ss1, ss2, ss3, L, R;
ll s1[200010], s2[200010], s3[200010], ans = 1e18, anss = 1e18, ANS = 1e18;
char c[3];
 
inline ll abss(ll x){
	return x > 0 ? x : -x;
}
 
int main(){
 
	int t = 1;
	// cin >> t;
	while(t--){
		cin >> n, n *= 2;
		for(int i = 1; i <= n; i++){
			cin >> s[i].v >> c;
			if(c[0] == 'R') s[i].tp = 1, cnt1++;
			if(c[0] == 'G') s[i].tp = 2, cnt2++;
			if(c[0] == 'B') s[i].tp = 3, cnt3++;
		}
		if(cnt1 % 2 == 0 && cnt2 % 2 == 0 && cnt3 % 2 == 0){
			puts("0");
			return 0;
		}
		for(int i = 1; i <= n; i++){
			if(s[i].tp == 1) s1[++ss1] = s[i].v;
			if(s[i].tp == 2) s2[++ss2] = s[i].v;
			if(s[i].tp == 3) s3[++ss3] = s[i].v;
		}
		sort(s1 + 1, s1 + ss1 + 1);
		sort(s2 + 1, s2 + ss2 + 1);
		sort(s3 + 1, s3 + ss3 + 1);
		for(int i = 1; i <= ss1; i++)
			m1[s1[i]] = 1;
		for(int i = 1; i <= ss2; i++)
			m2[s2[i]] = 1;
		for(int i = 1; i <= ss3; i++)
			m3[s3[i]] = 1;
		if(cnt3 % 2 == 0){
			for(int i = 1; i <= ss1; i++){
				R = lower_bound(s2 + 1, s2 + ss2 + 1, s1[i]) - s2;
				L = R - 1;
				if(R >= 1 && R <= ss2) ANS = min(ANS, abss(s2[R] - s1[i]));
				if(L >= 1 && L <= ss2) ANS = min(ANS, abss(s2[L] - s1[i]));
			}
			for(int i = 1; i <= ss2; i++)
				if(m1[s2[i]] == 1){
					puts("0");
					return 0;
				}
			for(int i = 1; i <= ss1; i++){
				R = lower_bound(s3 + 1, s3 + ss3 + 1, s1[i]) - s3;
				L = upper_bound(s3 + 1, s3 + ss3 + 1, s1[i]) - s3 - 1;
				if(R >= 1 && R <= ss3) ans = min(ans, abss(s3[R] - s1[i]));
				if(L >= 1 && L <= ss3) ans = min(ans, abss(s3[L] - s1[i]));
			}
			for(int i = 1; i <= ss2; i++){
				R = lower_bound(s3 + 1, s3 + ss3 + 1, s2[i]) - s3;
				L = upper_bound(s3 + 1, s3 + ss3 + 1, s2[i]) - s3 - 1;
				if(R >= 1 && R <= ss3) anss = min(anss, abss(s3[R] - s2[i]));
				if(L >= 1 && L <= ss3) anss = min(anss, abss(s3[L] - s2[i]));
			}
			printf("%lld\n", min(ans + anss, ANS));
		}
		if(cnt2 % 2 == 0){
			for(int i = 1; i <= ss1; i++){
				R = lower_bound(s3 + 1, s3 + ss3 + 1, s1[i]) - s3;
				L = R - 1;
				if(R >= 1 && R <= ss3) ANS = min(ANS, abss(s3[R] - s1[i]));
				if(L >= 1 && L <= ss3) ANS = min(ANS, abss(s3[L] - s1[i]));
			}
			for(int i = 1; i <= ss3; i++)
				if(m1[s3[i]] == 1){
					puts("0");
					return 0;
				}
			for(int i = 1; i <= ss1; i++){
				R = lower_bound(s2 + 1, s2 + ss2 + 1, s1[i]) - s2;
				L = upper_bound(s2 + 1, s2 + ss2 + 1, s1[i]) - s2 - 1;
				if(R >= 1 && R <= ss2) ans = min(ans, abss(s2[R] - s1[i]));
				if(L >= 1 && L <= ss2) ans = min(ans, abss(s2[L] - s1[i]));
			}
			for(int i = 1; i <= ss3; i++){
				R = lower_bound(s2 + 1, s2 + ss2 + 1, s3[i]) - s2;
				L = upper_bound(s2 + 1, s2 + ss2 + 1, s3[i]) - s2 - 1;
				if(R >= 1 && R <= ss2) anss = min(anss, abss(s2[R] - s3[i]));
				if(L >= 1 && L <= ss2) anss = min(anss, abss(s2[L] - s3[i]));
			}
			printf("%lld\n", min(ANS, ans + anss));
		}
		if(cnt1 % 2 == 0){
			for(int i = 1; i <= ss3; i++){
				R = lower_bound(s2 + 1, s2 + ss2 + 1, s3[i]) - s2;
				L = R - 1;
				if(R >= 1 && R <= ss2) ANS = min(ANS, abss(s2[R] - s3[i]));
				if(L >= 1 && L <= ss2) ANS = min(ANS, abss(s2[L] - s3[i]));
			}
			for(int i = 1; i <= ss3; i++)
				if(m2[s3[i]] == 1){
					puts("0");
					return 0;
				}
			for(int i = 1; i <= ss2; i++){
				R = lower_bound(s1 + 1, s1 + ss1 + 1, s2[i]) - s1;
				L = upper_bound(s1 + 1, s1 + ss1 + 1, s2[i]) - s1 - 1;
				if(R >= 1 && R <= ss1) ans = min(ans, abss(s1[R] - s2[i]));
				if(L >= 1 && L <= ss1) ans = min(ans, abss(s1[L] - s2[i]));
			}
			for(int i = 1; i <= ss3; i++){
				R = lower_bound(s1 + 1, s1 + ss1 + 1, s3[i]) - s1;
				L = upper_bound(s1 + 1, s1 + ss1 + 1, s3[i]) - s1 - 1;
				if(R >= 1 && R <= ss1) anss = min(anss, abss(s1[R] - s3[i]));
				if(L >= 1 && L <= ss1) anss = min(anss, abss(s1[L] - s3[i]));
			}
			printf("%lld\n", min(ANS, ans + anss));
		}
	}
 
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

typedef pair <int, int> pii;

const int N = 4e5 + 10;

int n, ans[N], p[N];

set <int> s[2];

set <int> :: iterator it;

pii a[N];

int main() {
	scanf("%d", &n), n *= 2;
	
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i].first);
		a[i].second = i;
	}
	
	sort(a + 1, a + n + 1);

	for (int i = 1; i <= n/2; i++) {
		s[0].insert(a[i].second), s[1].insert(a[i + n/2].second);
		p[a[i + n/2].second] = 1;
	}
	
//	puts("OK");
	
	for (int i = 1; i < n; i++)
		if (!ans[i]) {
			int x = p[i];
			s[x].erase(i), ans[i] = 1;
			it = s[x^1].upper_bound(i);
			ans[*it] = 2, s[x^1].erase(it);
		}
	
	for (int i = 1; i <= n; i++)
		printf("%c", ans[i] == 1 ? '(' : ')');
}