#include <bits/stdc++.h>   using namespace std;   struct pen {     int color;     int diameter;   };   int n, m, u, v;   pen marker[100000], cap[100000];   struct match {     vector<pen> marker;     vector<pen> cap;   };   match singleMatch[1000 + 1];   match doubleMatch[1000 + 1][1000 + 1];   int main(int argc, char *argv[]) {     u = 0, v = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int color, diameter;       cin >> color >> diameter;       marker[i].color = color;       marker[i].diameter = diameter;       singleMatch[diameter].marker.push_back(marker[i]);       doubleMatch[diameter][color].marker.push_back(marker[i]);     }     for (int i = 0; i < m; i++) {       int color, diameter;       cin >> color >> diameter;       cap[i].color = color;       cap[i].diameter = diameter;       singleMatch[diameter].cap.push_back(marker[i]);       doubleMatch[diameter][color].cap.push_back(cap[i]);     }     for (int i = 1; i < 1000 + 1; i++) {       vector<pen> tempM = singleMatch[i].marker;       vector<pen> tempC = singleMatch[i].cap;       int temp1 = (int)tempM.size();       int temp2 = (int)tempC.size();       if (temp1 > 0 && temp2 > 0) u += min(temp1, temp2);     }     for (int i = 1; i < 1000 + 1; i++)       for (int j = 1; j < 1000 + 1; j++) {         vector<pen> tempM = doubleMatch[i][j].marker;         vector<pen> tempC = doubleMatch[i][j].cap;         int temp1 = (int)tempM.size();         int temp2 = (int)tempC.size();         if (temp1 > 0 && temp2 > 0) v += min(temp1, temp2);       }     cout << u <<     << v << endl;     return 0;   }   