
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<char,pair<int,int>> p;
int ans = 0,r;
const string s = "BESSIE-GOES-MOO";
vector<int> z;
void dfs(int depth,int state,bool h1,bool h2,bool h3,int p1,int p2,int p3)
{
if(depth == s.size())
{
if((h1 && h2) && h3 == false)
{
int tmp = p1;
tmp *= p2;
tmp *= p3;
ans += tmp;
}
return;
}
if(s[depth] == '-')
{
dfs(depth + 1,state + 1,h1,h2,h3,p1,p2,p3);
return;
}
if(state == 1)
{
z.push_back(0);
dfs(depth + 1,state,h1,h2,h3,p1 * p[s[depth]].first,p2,p3);
z.pop_back();
z.push_back(1);
dfs(depth + 1,state,!h1,h2,h3,p1 * p[s[depth]].second,p2,p3);
z.pop_back();
return;
}
if(state == 2)
{
z.push_back(0);
dfs(depth + 1,state,h1,h2,h3,p1,p2 * p[s[depth]].first,p3);
z.pop_back();
z.push_back(1);
dfs(depth + 1,state,h1,!h2,h3,p1,p2 * p[s[depth]].second,p3);
z.pop_back();
return;
}
if(state == 3)
{
z.push_back(0);
dfs(depth + 1,state,h1,h2,h3,p1,p2,p3 * p[s[depth]].first);
z.pop_back();
z.push_back(1);
dfs(depth + 1,state,h1,h2,!h3,p1,p2,p3 * p[s[depth]].second);
z.pop_back();
return;
}
}
signed main()
{
r = s.size();
p['B'].first = p['B'].second = 0;
p['E'].first = p['E'].second = 0;
p['S'].first = p['S'].second = 0;
p['I'].first = p['I'].second = 0;
p['G'].first = p['G'].second = 0;
p['M'].first = p['M'].second = 0;
p['O'].first = p['O'].second = 0;
int n;
cin >> n;
char u;
int v;
for(int i = 1;i <= n;i++)
{
cin >> u >> v;
if(v % 2 == 1) p[u].second++;
else p[u].first++;
}
dfs(1,1,false,false,false,1,1,1);
cout << ans;
return 0;
}