#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<limits>
#include<climits>
#include<cmath>
#include<functional>
#include<ctime>
#include<cstdlib>
#include<fstream>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef short int i16;
typedef unsigned long long int u64;
typedef unsigned int u32;
typedef unsigned short int u16;
typedef unsigned char u8;
ifstream IN("bgm.in");
ofstream OUT("bgm.out");
const int B = 1, E = 2, S = 3, I = 4, G = 5, O = 6, M = 7;
ll fmod(ll p) {
if(p>=0) {
return p%7;
}
else {
return (7-(abs(p)%7))%7;
}
}
int values[8][8];
int n;
int rem[8];
ll ans=0;
void input() {
memset(values,0,sizeof(values));
IN>>n;
int i,w;
char c;
ll val;
for(i=1;i<=n;i++) {
IN>>c;
IN>>val;
if(c=='B') {
w=B;
}
if(c=='E') {
w=E;
}
if(c=='S') {
w=S;
}
if(c=='I') {
w=I;
}
if(c=='G') {
w=G;
}
if(c=='O') {
w=O;
}
if(c=='M') {
w=M;
}
values[w][fmod(val)]++;
}
}
void gen(int letter) {
if(letter>7) {
if((rem[B]+rem[E]+rem[S]+rem[S]+rem[I]+rem[E])%7==0
|| (rem[G]+rem[O]+rem[E]+rem[S])%7==0
|| (rem[M]+rem[O]+rem[O])%7==0) {
ll curr=1LL;
int i;
for(i=1;i<=7;i++) {
curr*=values[i][rem[i]];
}
ans+=curr;
}
return;
}
int i;
for(i=0;i<7;i++) {
rem[letter]=i;
gen(letter+1);
}
}
void solve() {
gen(1);
OUT<<ans<<'\n';
}
int main() {
ios_base::sync_with_stdio(false);
IN.tie(NULL);
OUT.tie(NULL);
input();
solve();
IN.close();
OUT.close();
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGFsZ29yaXRobT4KI2luY2x1ZGU8c3RyaW5nPgojaW5jbHVkZTxjc3RyaW5nPgojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlPHN0YWNrP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ICAgICAgIElOPj52YWw7CgogICAgICAgIGlmKGM9PSdCJykgewogICAgICAgICAgICB3PUI7CiAgICAgICAgfQoKICAgICAgICBpZihjPT0nRScpIHsKICAgICAgICAgICAgdz1FOwogICAgICAgIH0KCiAgICAgICAgaWYoYz09J1MnKSB7CiAgICAgICAgICAgIHc9UzsKICAgICAgICB9CgogICAgICAgIGlmKGM9PSdJJykgewogICAgICAgICAgICB3PUk7CiAgICAgICAgfQoKICAgICAgICBpZihjPT0nRycpIHsKICAgICAgICAgICAgdz1HOwogICAgICAgIH0KCiAgICAgICAgaWYoYz09J08nKSB7CiAgICAgICAgICAgIHc9TzsKICAgICAgICB9CgogICAgICAgIGlmKGM9PSdNJykgewogICAgICAgICAgICB3PU07CiAgICAgICAgfQoKICAgICAgICB2YWx1ZXNbd11bZm1vZCh2YWwpXSsrOwogICAgfQp9Cgp2b2lkIGdlbihpbnQgbGV0dGVyKSB7CiAgICBpZihsZXR0ZXI+NykgewogICAgICAgIGlmKChyZW1bQl0rcmVtW0VdK3JlbVtTXStyZW1bU10rcmVtW0ldK3JlbVtFXSklNz09MAogICAgICAgIHx8IChyZW1bR10rcmVtW09dK3JlbVtFXStyZW1bU10pJTc9PTAKICAgICAgICB8fCAocmVtW01dK3JlbVtPXStyZW1bT10pJTc9PTApIHsKICAgICAgICAgICAgbGwgY3Vycj0xTEw7CiAgICAgICAgICAgIGludCBpOwoKICAgICAgICAgICAgZm9yKGk9MTtpPD03O2krKykgewogICAgICAgICAgICAgICAgY3Vycio9dmFsdWVzW2ldW3JlbVtpXV07CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGFucys9Y3VycjsKICAgICAgICB9CgogICAgICAgIHJldHVybjsKICAgIH0KCiAgICBpbnQgaTsKCiAgICBmb3IoaT0wO2k8NztpKyspIHsKICAgICAgICByZW1bbGV0dGVyXT1pOwogICAgICAgIGdlbihsZXR0ZXIrMSk7CiAgICB9Cn0KCnZvaWQgc29sdmUoKSB7CiAgICBnZW4oMSk7CgogICAgT1VUPDxhbnM8PCdcbic7Cn0KCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBJTi50aWUoTlVMTCk7CiAgICBPVVQudGllKE5VTEwpOwoKICAgIGlucHV0KCk7CiAgICBzb2x2ZSgpOwoKICAgIElOLmNsb3NlKCk7CiAgICBPVVQuY2xvc2UoKTsKCiAgICByZXR1cm4gMDsKfQo=