Spray

Time limit: 1.5s Memory limit: 64MB Input: Output:

Paul has a huge problem caused by the presence of bugs in his house and now he must kill the NN colonies of bugs that have infested his house. Since he is a very abstract person, he lives in a MM-dimensional cube, where every position can be represented as an array of coordinates (A1,A2,,AM)(A_1, A_2, \dots, A_M) with integer values ranging from 00 to B1B-1. A colony of bugs is represented by its position.

Since bugs are social entities, they try to unify the colonies. Thereby, if two colonies are adiacent in the house (the position of one is obtained by adding or subtracting 11 from a single coordinate of the position of the other), they build a tunnel, unifying the 22 colonies. Paul knows the positions of the NN colonies, and he wishes to block all the tunnels between them. In order to do that he can buy special sprays.

There are NN types of sprays, using the ithi^{th} type will destroy all the tunnels that have one of its ends in the ithi^{th} colony. Paul needs to know the minimum number of sprays he needs in order to block all the tunnels.

Input data

The first line will contain the numbers NN, MM, BB. On the next NN lines there are MM numbers between 00 and B1B - 1 representing the position of each colony.

Output data

On the first and only line you will print the minimum number of sprays needed to block all the tunnels.

Constraints and clarifications

  • 1N1041 \leq N \leq 10^4
  • 1B1091 \leq B \leq 10^9
  • 1M1001 \leq M \leq 100
  • It is guaranteed that any two colonies have distinct positions.
  • For tests worth 3030 points: 1N101 \leq N \leq 10

Example

stdin

5 3 4
1 1 1
1 1 2
1 1 3
1 2 1
1 2 3

stdout

2

Explanation

We will buy two sprays: one of type 11 and one of type 33.

Log in or sign up to be able to send submissions!