#include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<map> #include<string> #include <cmath> using namespace std; int main() { int n; long long res = 0; map<string , int> mp; map<string , int>::iterator it; map<string , int>::iterator it1; map<string , int>::iterator it2; map<string , int>::iterator it3; cin >> n; for(int i = 0; i < n; i ++) { char a, b, c; cin >> a >> b >> c; string s = ""; s += a; s += b; s += c; mp[s] += 1; } for(it = mp.begin(); it != mp.end(); it ++) { int num = it->second; //cout << it->first << " " << it->second << endl; if(num >= 3) res += num*(num-1)*(num-2)/6; } //cout << res << endl; long long res2 = 0; for(it1 = mp.begin(); it1 != mp.end(); it1 ++) { for(it2 = mp.begin(); it2 != mp.end(); it2 ++) { for(it3 = mp.begin(); it3!= mp.end(); it3 ++) { string s1 = it1->first, s2 = it2->first , s3 = it3->first; if(s1 == s2 || s1 == s3 || s2 == s3) continue; int flag = 1; for(int i = 0; i < 3; i ++) { if(s1[i] == s2[i] || s1[i] == s3[i] || s2[i] == s3[i]) { flag = 0; break; } } if(!flag) continue; res2 = res2 + (mp[s1] * mp[s2] * mp[s3]); } } } long long ans = res+res2/6; cout << ans << endl; return 0; }
全部评论
(0) 回帖