// author : anphung
#include<bits/stdc++.h>
using namespace std;
#define file "TRIANGLE"
#define int64 long long
#define f0(i,a,b) for(int (i) = (a); (i) <= (b); ++i)
#define TIME (1.0*clock()/CLOCKS_PER_SEC)
#define pb push_back
#define all(a) (a).begin(),(a).end()
int n;
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
freopen(file".inp","r",stdin);
freopen(file".out","w",stdout);
cin>>n;
vector<int> r, g, b;
f0(i,0,n-1){
char c;int d;
cin>>c>>d;
if(c=='r'){
r.pb(d);
}else if(c=='g')g.pb(d);
else b.pb(d);
}
sort(all(r));
sort(all(g));
sort(all(b));
int cnt = 0;
for(auto &x:r){
for(auto &y:g){
int lo = abs(x-y)+1, hi = x+y-1;
if(lo>hi)continue;
int lb = lower_bound(b.begin(),b.end(),lo) - b.begin();
int ub = upper_bound(b.begin(),b.end(),hi) - b.begin();
cnt += (ub-lb);
}
}
cout<<cnt;
//cerr<<"\ntime elapsed: "<<TIME <<"s.\n";
}
Ly8gYXV0aG9yIDogYW5waHVuZwojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGZpbGUgIlRSSUFOR0xFIgojZGVmaW5lIGludDY0IGxvbmcgbG9uZwojZGVmaW5lIGYwKGksYSxiKSBmb3IoaW50IChpKSA9IChhKTsgKGkpIDw9IChiKTsgKytpKQojZGVmaW5lIFRJTUUgKDEuMCpjbG9jaygpL0NMT0NLU19QRVJfU0VDKQojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIGFsbChhKSAoYSkuYmVnaW4oKSwoYSkuZW5kKCkKCmludCBuOwoKCmludDMyX3QgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTtjaW4udGllKDApO2NvdXQudGllKDApOwogICAgZnJlb3BlbihmaWxlIi5pbnAiLCJyIixzdGRpbik7CiAgICBmcmVvcGVuKGZpbGUiLm91dCIsInciLHN0ZG91dCk7CgogICAgY2luPj5uOwogICAgdmVjdG9yPGludD4gciwgZywgYjsKICAgIGYwKGksMCxuLTEpewogICAgICAgIGNoYXIgYztpbnQgZDsKICAgICAgICBjaW4+PmM+PmQ7CiAgICAgICAgaWYoYz09J3InKXsKICAgICAgICAgICAgci5wYihkKTsKICAgICAgICB9ZWxzZSBpZihjPT0nZycpZy5wYihkKTsKICAgICAgICBlbHNlIGIucGIoZCk7CiAgICB9CgogICAgc29ydChhbGwocikpOwogICAgc29ydChhbGwoZykpOwogICAgc29ydChhbGwoYikpOwoKICAgIGludCBjbnQgPSAwOwogICAgZm9yKGF1dG8gJng6cil7CiAgICAgICAgZm9yKGF1dG8gJnk6Zyl7CiAgICAgICAgICAgIGludCBsbyA9IGFicyh4LXkpKzEsIGhpID0geCt5LTE7CiAgICAgICAgICAgIGlmKGxvPmhpKWNvbnRpbnVlOwoKICAgICAgICAgICAgaW50IGxiID0gbG93ZXJfYm91bmQoYi5iZWdpbigpLGIuZW5kKCksbG8pIC0gYi5iZWdpbigpOwogICAgICAgICAgICBpbnQgdWIgPSB1cHBlcl9ib3VuZChiLmJlZ2luKCksYi5lbmQoKSxoaSkgLSBiLmJlZ2luKCk7CgogICAgICAgICAgICBjbnQgKz0gKHViLWxiKTsKICAgICAgICB9CiAgICB9CgogICAgY291dDw8Y250OwogICAgLy9jZXJyPDwiXG50aW1lIGVsYXBzZWQ6ICI8PFRJTUUgPDwicy5cbiI7Cn0K