#include using namespace std; typedef long long ll; typedef vector vi; typedef pair pii; #define f0rn(i, a, b) for (int i=a; i<(b); i++) #define forn(i,n) for(int i = 0; i < n; i++) #define mp make_pair #define pb push_back #define ff first #define ss second const int MOD = 1000000007; vector< pair > arr; int main() { ifstream fin("citystate.in"); ofstream fout("citystate.out"); int n; fin >> n; forn(i,n) { string a, b; fin >> a >> b; arr.pb(mp(a.substr(0,2),b)); } fin.close(); sort(arr.begin(),arr.end()); string search[n]; for(int i = 0; i < n; i++) { search[i] = arr[i].first; } int cnt = 0; for(int i = 0; i < n; i++) { int ind = lower_bound(search,search+n,arr[i].second)-search; if(ind != n) { if(arr[ind].second == arr[i].first) { //cout << arr[ind].first << " " << arr[ind].second; cnt++; } } int t1 = ind+1; while(t1 < n) { if(arr[t1].second == arr[i].first && arr[t1].first == arr[i].second) { //cout << arr[t1].first << " " << arr[t1].second << endl; cnt++; } t1++; } while(ind >= 0) { if(arr[ind].second == arr[i].first && arr[ind].first == arr[ind].second) { //cout << arr[ind].first << " " << arr[ind].second << endl; cnt++; } ind--; } } fout << cnt/2; fout.close(); return 0; }