#include using namespace std; int main() { int n, m, c; scanf("%d %d %d", &n, &m, &c); map schools_students_counts; for (int i = 1; i <= m; i++) { schools_students_counts[i] = 0; } map> p_first; map> p_second; for (int i = 0; i < n; i++) { vector empty1; vector empty2; p_first[i + 1] = empty1; p_second[i + 1] = empty2; //p_first.push_back(make_pair(i + 1, empty)); //p_second.push_back(make_pair(i + 1, empty)); } map students_in; for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); p_first[x].push_back(i); p_second[y].push_back(i); students_in[i] = false; // i = student number } // algorithm int got_first = 0; int got_second = 0; // first round, first priority for (int i = 1; i <= m; i++) { for (int j = 0; j < p_first[i].size(); j++) { if (students_in[p_first[i][j]] == false && schools_students_counts[i] < c) { //printf("%d %d\n", p_first[i][j], students_in[p_first[i][j]]); schools_students_counts[i]++; students_in[p_first[i][j]] = true; got_first++; } } } // first round, second priority for (int i = 1; i <= m; i++) { for (int j = 0; j < p_second[i].size(); j++) { if (students_in[p_second[i][j]] == false && schools_students_counts[i] < c) { schools_students_counts[i]++; students_in[p_second[i][j]] = true; got_second++; } } } // second round, first priority for (int i = 1; i <= m; i++) { for (int j = 0; j < p_first[i].size(); j++) { if (students_in[p_first[i][j]] == false && schools_students_counts[i] < c) { //printf("%d %d\n", p_first[i][j], students_in[p_first[i][j]]); schools_students_counts[i]++; students_in[p_first[i][j]] = true; got_first++; } } } // second round, second priority for (int i = 1; i <= m; i++) { for (int j = 0; j < p_second[i].size(); j++) { if (students_in[p_second[i][j]] == false && schools_students_counts[i] < c) { schools_students_counts[i]++; students_in[p_second[i][j]] = true; got_second++; } } } printf("%d %d\n", got_first, got_second); return 0; } /* 9 3 4 1 2 2 3 1 3 3 2 1 2 3 2 2 3 2 3 2 1 */ /* 4 2 1 1 2 1 2 1 2 1 2 */