import com.sun.source.tree.Tree;

import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Digitalisation {


    static Student[] students;
    static TreeSet<Integer>[] schools;
    static int schoolCapacity;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int numOfStudents = sc.nextInt();
        int numOfSchools = sc.nextInt();
        schoolCapacity = sc.nextInt();

        students = new Student[numOfStudents];
        schools = new TreeSet[numOfSchools];

        for (int i = 0; i < numOfSchools; i++) {
            schools[i] = new TreeSet<>();
        }

        for (int i = numOfStudents - 1; i >= 0; i--) {
            students[i] = new Student(i, sc.nextInt() - 1, sc.nextInt() - 1);
        }

        boolean update = true;
        while (update) {
            update = false;
            for (int i = 0; i < numOfSchools; i++) {
                if (updateEvent(i)) {
                    update = true;
                }
            }
        }

        int primary = 0;
        int secondary = 0;
        for (int i = 0; i < numOfSchools; i++) {
            for (Integer studentIndex : schools[i]) {
                Student student = students[studentIndex];
                if (student.prior == i)
                    primary++;
                else if (student.second == i)
                    secondary++;
                else
                    System.out.println("problem");
            }
        }

        System.out.println(primary + " " + secondary);
    }

    public static boolean updateEvent(int schoolIndex) {
        boolean isFull = schools[schoolIndex].size() == schoolCapacity;
        int minIndex = isFull ? schools[schoolIndex].first() : 0;
        for (int i = minIndex; i < students.length; i++) {
            Student student = students[i];
            if (conditions(student, schoolIndex)) {
                schools[schoolIndex].add(student.index);

                if (schools[schoolIndex].size() > schoolCapacity) {
                    Student removedStudent = students[schools[schoolIndex].first()];
                    schools[schoolIndex].remove(removedStudent.index);
                    removedStudent.assigned = -1;
                }

                if (student.assigned != -1) {
                    schools[student.second].remove(student.index);
                }

                student.assigned = schoolIndex;
                return true;
            }
        }
        return false;
    }

    public static boolean conditions(Student student, int schoolIndex) {
        if (!(schools[schoolIndex].size() < schoolCapacity || student.index > schools[schoolIndex].first())) {
            return false;
        }

        if (!(student.prior == schoolIndex || student.second == schoolIndex)) {
            return false;
        }

        return (student.assigned == -1 || (student.assigned == student.second && schoolIndex == student.prior));
    }

    public static class Student {
        public int index;
        public int prior;
        public int second;
        public int assigned;

        public Student(int index, int prior, int second) {
            this.index = index;
            this.prior = prior;
            this.second = second;
            this.assigned = -1;
        }
    }
}
