马蜂优良
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int N=100005;
ll tot[100];
ll a[N][100];
ll n;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
char id;
cin>>id;
tot[id]++;
cin>>a[id][tot[id]];
}
int ans=0;
for(int b=1;b<=tot['B'];b++){
for(int e=1;e<=tot['E'];e++){
for(int s=1;s<=tot['S'];s++){
for(int i=1;i<=tot['I'];i++){
for(int g=1;g<=tot['G'];g++){
for(int o=1;o<=tot['O'];o++){
for(int m=1;m<=tot['M'];m++){
if(((a['B'][b]+(a['E'][e]*2)+(a['S'][s]*2)+a['I'][i])*(a['G'][g]+a['O'][o]+a['E'][e]+a['S'][s])*(a['M'][m]+(a['O'][o]*2)))%7==0)ans++;
}
}
}
}
}
}
}
cout<<ans;
return 0;
}