#include <bits/stdc++.h>
// #include <atcoder/all>
// #include <boost/multiprecision/cpp_int.hpp>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) a.begin(), a.end()
#define yn(p) cout << (p?"Yes":"No") << endl;
using namespace std;
// using namespace atcoder;
using ll = long long;
// using lll = boost::multiprecision::cpp_int;
using P = pair<int, int>;

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  ll ans = 0;
  rep(i, n) {
    ans += (b[i] * (b[i] + 1)) / 2;
    ans -= (a[i] * (a[i] - 1)) / 2;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  solve();
  return 0;
}

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

const double pi = 3.141592653589793;
int inf = 1001001001;
ll INF = 1001001001001001001;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
ll MOD = 1000000007;
using P = pair<ll, ll>;


double eps = 1e-12;


int main() {
   int N;cin >> N;
   vector<vector<ll> > color(3);
   rep(i, 2*N) {
       ll a;cin >> a;
       char c;cin >> c;
       if (c == 'R') color[0].pb(a);
       else if (c == 'G') color[1].pb(a);
       else if (c == 'B') color[2].pb(a);

       
   }
   ll rcnt, gcnt, bcnt;
   rcnt = (color[0].size())%2;
   gcnt = (color[1].size())%2;
   bcnt = (color[2].size())%2;
   if (rcnt == 0&&gcnt == 0&&bcnt == 0) {
       cout << 0 << endl;
       return 0;
   }
   vector<P> wa, wa2, wa3;
   ll koho = INF;
   ll koho2 = INF;
   ll koho3 = INF;

   if (rcnt == 0) {
       rep(i, color[1].size()) wa.pb(P(color[1][i], 1));
       rep(i, color[2].size()) wa.pb(P(color[2][i], 2));
       sort(all(wa));
       rep(i, wa.size()-1) {
           if (wa[i].second == wa[i+1].second) continue;
           else koho = min(koho, wa[i+1].first-wa[i].first);
       }
       rep(i, color[0].size()) wa2.pb(P(color[0][i], 0));
       rep(i, color[1].size()) wa2.pb(P(color[1][i], 1));
       sort(all(wa2));
       rep(i, wa2.size()-1) {
           if (wa2[i].second == wa2[i+1].second) continue;
           else koho2 = min(koho2, wa2[i+1].first-wa2[i].first);
       }
       rep(i, color[0].size()) wa3.pb(P(color[0][i], 0));
       rep(i, color[2].size()) wa3.pb(P(color[2][i], 2));
       sort(all(wa3));
       rep(i, wa3.size()-1) {
           if (wa3[i].second == wa3[i+1].second) continue;
           else koho3 = min(koho3, wa3[i+1].first-wa3[i].first);
       }
       ll ans = min(koho, koho2+koho3);
       cout << ans << endl;
       return 0;
    }
    else if (gcnt == 0) {
       rep(i, color[0].size()) wa.pb(P(color[0][i], 0));
       rep(i, color[2].size()) wa.pb(P(color[2][i], 2));
       sort(all(wa));
       rep(i, wa.size()-1) {
           if (wa[i].second == wa[i+1].second) continue;
           else koho = min(koho, wa[i+1].first-wa[i].first);
       }
       rep(i, color[0].size()) wa2.pb(P(color[0][i], 0));
       rep(i, color[1].size()) wa2.pb(P(color[1][i], 1));
       sort(all(wa2));
       rep(i, wa2.size()-1) {
           if (wa2[i].second == wa2[i+1].second) continue;
           else koho2 = min(koho2, wa2[i+1].first-wa2[i].first);
       }
       rep(i, color[1].size()) wa3.pb(P(color[1][i], 1));
       rep(i, color[2].size()) wa3.pb(P(color[2][i], 2));
       sort(all(wa3));
       rep(i, wa3.size()-1) {
           if (wa3[i].second == wa3[i+1].second) continue;
           else koho3 = min(koho3, wa3[i+1].first-wa3[i].first);
       }
       ll ans = min(koho, koho2+koho3);
       cout << ans << endl;
       return 0;
    }
    if (bcnt == 0) {
       rep(i, color[0].size()) wa.pb(P(color[0][i], 0));
       rep(i, color[1].size()) wa.pb(P(color[1][i], 1));
       sort(all(wa));
       rep(i, wa.size()-1) {
           if (wa[i].second == wa[i+1].second) continue;
           else koho = min(koho, wa[i+1].first-wa[i].first);
       }
       rep(i, color[0].size()) wa2.pb(P(color[0][i], 0));
       rep(i, color[2].size()) wa2.pb(P(color[2][i], 2));
       sort(all(wa2));
       rep(i, wa2.size()-1) {
           if (wa2[i].second == wa2[i+1].second) continue;
           else koho2 = min(koho2, wa2[i+1].first-wa2[i].first);
       }
       rep(i, color[1].size()) wa3.pb(P(color[1][i], 1));
       rep(i, color[2].size()) wa3.pb(P(color[2][i], 2));
       sort(all(wa3));
       rep(i, wa3.size()-1) {
           if (wa3[i].second == wa3[i+1].second) continue;
           else koho3 = min(koho3, wa3[i+1].first-wa3[i].first);
       }
       ll ans = min(koho, koho2+koho3);
       cout << ans << endl;
       return 0;
    }
    return 0;
}



