Field Trip

Given a graph where each vertex has degree at most 2, delete edges so that the remaining components are cliques of size exactly K, maximizing total covered vertices then minimizing deletions.

Hard8GraphUnion-findDynamic programmingCombinatoricsNo attempts yetTime limit2sMemory limit512 MB

Problem

As a special treat for your kindergarten class, you are taking them on a field trip to a magical place of wonder.

Your class has NN students, numbered from 11 to NN for convenience. There are MM direct, two-way friendships between the students. Each student is friends with at most two other students.

Besides the MM direct friendships, students may also be acquainted with one another. Two students ii and jj are acquaintances if they are friends, or if there is a third student kk who is an acquaintance of student ii and also an acquaintance of student jj. For example, if (1,2)(1, 2), (2,3)(2, 3), (3,4)(3, 4) and (4,5)(4, 5) are pairs of students with a direct friendship, then student 11 and student 55 are acquaintances.

You are getting ready to order buses for the trip, but there are two problems. First, the transportation company insists that every bus you order is filled exactly to its capacity of KK students. They will not let you order a bus if you intend to put fewer than KK students on it. Second, the students are picky about their travelling conditions. Student ii refuses to get on a bus unless both of these conditions hold:

  1. every other student getting on that bus is an acquaintance of student ii;
  2. every acquaintance of student ii is getting on that bus.

It looks like you cannot bring the whole class along after all. You will still do whatever it takes to get as many students as possible onto buses, and that includes ending a friendship or two for the greater good. You may sever 00 or more of the MM friendships, which also changes who is acquainted with whom.

Determine the largest number of students you can bring on the trip, so that they are loaded onto buses holding exactly KK students each and every student is satisfied with the bus they are put on. Since you are feeling generous, also determine the smallest number of friendships you have to sever in order to bring that many students.

Input

The first line contains three space-separated integers NN, MM and KK (1N1061 \le N \le 10^6, 0M1060 \le M \le 10^6, 1KN1 \le K \le N).

Each of the next MM lines describes one friendship. Line ii contains two space-separated integers AiA_i and BiB_i (1iM1 \le i \le M), meaning that student AiA_i and student BiB_i are friends (1Ai,BiN1 \le A_i, B_i \le N, AiBiA_i \ne B_i). No friendship is given twice, so no two unordered friendship pairs are equal to each other.

Output

Print two space-separated integers on one line. The first integer is the largest number of students you can bring on the trip. The second integer is the smallest number of friendships you have to sever in order to bring that many students.