#include <iostream> #include <unordered_map> #include <unordered_set> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n, ret = 0; cin >> n; string s, c; unordered_map<string, unordered_map<string, int>> hash; while (n--) { cin >> s >> c; string prefix = s.substr(0, 2); if (prefix == c) { continue; } hash[prefix][c]++; ret += hash[c][prefix]; } cout << ret; return 0; }