#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
ll n;
ll res=1e18;
void solve(vector<ll>& r,vector<ll>& g,vector<ll>& b){
    rep(i,r.size()){
            auto itr=lower_bound(g.begin(),g.end(),r[i]);
            ll k=itr-g.begin();
            if(k!=g.size())chmin(res,abs(g[k]-r[i]));
            if(k!=0)chmin(res,abs(g[k-1]-r[i]));
        }
        priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>> > que1,que2;
        rep(i,b.size()){
            auto itr=lower_bound(g.begin(),g.end(),b[i]);
            ll k=itr-g.begin();
            ll buf3=1e18;
            if(k!=g.size())buf3=abs(b[i]-g[k]);
            if(k!=0){
                ll buf=abs(b[i]-g[k-1]);
                chmin(buf3,buf);
            }
            itr=lower_bound(r.begin(),r.end(),b[i]);
            k=itr-r.begin();
            ll buf4=1e18;
            if(k!=r.size())buf4=abs(b[i]-r[k]);
            if(k!=0){
                ll buf=abs(b[i]-r[k-1]);
                chmin(buf4,buf);
            }
            que1.push({buf3,i});
            que2.push({buf4,i});
        }
        if(que1.size()==0)return;
        ll buf1_1=que1.top().first;
        ll buf2_1=que2.top().first;
        que1.pop();que2.pop();
        
        chmin(res,buf1_1+buf2_1);
        return;
}
int main(void){
    cin>>n;
    vector<ll> r,g,b;
    rep(i,2*n){
        ll a;cin>>a;
        char c;cin>>c;
        if(c=='R')r.push_back(a);
        if(c=='G')g.push_back(a);
        if(c=='B')b.push_back(a);
    }
    if(r.size()%2==0&&g.size()%2==0&&b.size()%2==0){
        cout<<0<<endl;
        return 0;
    }
    sort(r.begin(),r.end());
    sort(g.begin(),g.end());
    sort(b.begin(),b.end());
    if(b.size()%2==0){
        solve(r,g,b);
    }else if(r.size()%2==0){
        solve(g,b,r);
    }else{
        solve(b,r,g);
    }
    cout<<res<<endl;
}
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define vll vector<ll>
#define xfor(arr) for(auto& x : arr)
#define input(arr) xfor(arr) cin >> x;
#define output(arr) xfor(arr) cout << x << ' '; cout << '\n';
#define FOR(type,i,n) for(type i = 0; i < n; i++)

typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
using namespace std;
int main(){
    fastio
    // int t = 0;
    // cin >> t;
    // while(t--){
        
    // }
    ll n;
    cin >> n;
    // while(!(n%10))
    //     n /= 10;
    string s = to_string(n);
    ll stop = s.length()-1;
    while(s[stop] == '0')
        stop--;
    ll l = 0, r = stop;
    while(l < r) {
        if(s[l] != s[r]) {
            cout << "No";
            return 0;
        }
        l++;
        r--;
    }
    cout << "Yes";
    return 0;
}