fork download
  1. #include<stdio.h>
  2. #include<map>
  3. #include<string>
  4. #include<iostream>
  5. using namespace std;
  6. map<pair<string, string>, int>M;
  7. int main() {
  8. int n, i, j;
  9. long long ans = 0;
  10. scanf("%d", &n);
  11. for (i = 0; i < n; i++) {
  12. string a, b;
  13. cin >> a >> b;
  14. a = a.substr(0, 2);
  15. if (a == b)continue;
  16. if (M.find({ b,a })!=M.end())ans += M[{b, a}];
  17. if (M.find({ a,b })!=M.end())M[{a, b}] = M[{a, b}] + 1;
  18. else M[{a, b}] = 1;
  19. }
  20. printf("%lld", ans);
  21. return 0;
  22. }
Success #stdin #stdout 0s 4364KB
stdin
6
MIAMI FL
DALLAS TX
FLINT MI
CLEMSON SC
BOSTON MA
ORLANDO FL
stdout
1