This page is still under construction.

Parts of this page are still being built. What you see may change.

Air Conditioner Installation

Time limit1sMemory limit1024 MB

Summary
Given N rooms at distinct integer 3D points, find the minimum number of rooms to mark so every room and every unit-distance corridor between adjacent rooms is covered.
Level

Medium7 of 10

Topics
Graph, Dynamic programming, Tree, Bit manipulation
Solved
No attempts yet

Problem

Juhyeon, who runs an air conditioner business, received an inquiry about installing air conditioners in the newly built Newyolla Library. The library gave him the blueprints and asked him to install air conditioners in suitable places. Juhyeon, who had found a chance to make a lot of money after a long time, checked the blueprints with excitement.

The blueprints of Newyolla Library have a unique structure that reflects the library's distinctive architectural philosophy. Rooms exist only at points with integer coordinates in the 33D blueprint, and between any two rooms whose coordinates are at distance 11, there is always a corridor or a staircase. The volume of a room is not considered.

Juhyeon, who wanted to sell as many air conditioners as possible, wanted to insist strongly that air conditioners must be installed in every room, but unfortunately the only air conditioners available could cool adjacent rooms. In other words, one air conditioner can cool the room it is installed in, the corridors and staircases connected to that room, and the rooms connected through those corridors and staircases.

Of course, he could deceive the library staff and install air conditioners in every room, but overcharging could cause trouble for his future business, so he wants to sell only the minimum number of air conditioners that can cool every room, corridor, and staircase.

How many air conditioners can Juhyeon sell to the library?

Input

The first line gives the number of rooms in the library, NN. (1≤N≤1 5001 \leq N \leq 1\ 500)

The next NN lines give the integer coordinates xi,yi,zix_i, y_i, z_i of each room. (−200≤xi,yi,zi≤200-200 \leq x_i, y_i, z_i \leq 200, (xi,yi,zi)≠(xj,yj,zj)( x_i, y_i, z_i ) \neq ( x_j, y_j, z_j ) if i≠ji \neq j)

Output

Print the minimum number of air conditioners Juhyeon can sell.

Examples2

  1. Example 1

    Input
    6
    0 0 0
    1 0 0
    1 1 0
    0 1 1
    0 0 1
    1 0 1
    
    Expected output
    2
    
  2. Example 2

    Input
    6
    0 0 0
    0 0 1
    0 1 0
    5 5 8
    5 4 8
    5 5 7
    
    Expected output
    2