#include <bits/stdc++.h>
const int N = 300;
using std::cout;
bool f[N];
int n, id[N];
std::pair<int, int> p[N];
int main() {
 std::ios::sync_with_stdio(false);
 std::cin >> n;
 for (int i = 1; i <= n; ++i) {
  std::cin >> p[i].first >> p[i].second;
  if (~p[i].first) {
   if (id[p[i].first]) {
    cout << "No";
    return 0;
   }
   id[p[i].first] = -i;
  }
  if (~p[i].second) {
   if (id[p[i].second]) {
    cout << "No";
    return 0;
   }
   id[p[i].second] = i;
  }
 }
 f[0] = 1;
 for (int i = 1; i <= n; ++i) {
  for (int j = 1; j <= i && !f[i]; ++j) {
   bool flag = 1;
   for (int k = 1; k <= j; ++k) {
    int x = id[2 * (i - j) + k], y = id[2 * (i - j) + j + k];
    if (x > 0 || y < 0 || (x < 0 && y > 0 && x != -y)) {
     flag = 0;
     break;
    }
   }
   if (flag)
    f[i] |= f[i - j];
  }
 }
 cout << (f[n] ? "Yes" : "No");
 return 0;
}
#pragma GCC optimize("Ofast") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define int long long int
const int mod = 1e9 + 7;
using namespace std;

int ple;

int f(vector<int>arr,vector<int>brr)
{
     sort(arr.begin(),arr.end());
	 sort(brr.begin(),brr.end());
	 int n=arr.size(),nn=brr.size();
	 int ret=mod*mod;
	 for(int i=0;i<n;i++)
	 {
         int ind=lower_bound(brr.begin(),brr.end(),arr[i])-brr.begin();
		 int st=max(0LL,ind-2);
		 int en=min(nn-1,ind+2);
         for(int j=st;j<=en;j++)
		 {
			 int cur=abs(arr[i]-brr[j]);
			 if(cur<ret)
			 {
				 ret=cur;
				 ple=brr[j];
			 }
		 }
	 }
	 return ret;
}

int ff(vector<int>arr,vector<int>brr,vector<int>crr)
{
      int ret=f(arr,crr);
	  for(int &a:crr)
	  {
		  if(a==ple)
		  {
			  a=mod*mod;
			  break;
		  }
	  }
	  ret+=f(brr,crr);
	  return ret;
}

void myfun()
{
	int n;
	cin>>n;
	vector<int>rr,gg,bb;
	int r=0,b=0,g=0;
	for(int i=0;i<(2*n);i++)
	{
		int a; cin>>a;
		char ch; cin>>ch;
		if(ch=='R')
		{
			r++;
			rr.push_back(a);
		}
		if(ch=='G')
		{
			g++;
			gg.push_back(a);
		}
		if(ch=='B')
		{
			b++;
			bb.push_back(a);
		}
	}
	if(r%2==0 && g%2==0 && b%2==0)
	{
		cout<<"0\n";
		return;
	}
	int ans=mod*mod;
	if(r%2==1 && g%2==1)
        ans=min(ff(rr,gg,bb),f(rr,gg)); 
	if(r%2==1 && b%2==1)
		  ans=min(ff(rr,bb,gg),f(bb,rr));
	if(b%2==1 && g%2==1)
	  ans=min(ff(bb,gg,rr),f(gg,bb));
	cout<<ans<<"\n";
}

signed main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	myfun();
	return 0;
}