Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
Language:
Building with Blocks
Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 596Accepted: 162

Description

A unit cube is a 1x1x1 cube, whose corners have integer x, y, and z coordinates. Two unit cubes are connected when they share a face. A 3-dimensional solid object (solid, for short) is a non-empty connected set of unit cubes (see Figure 1). The volume of a solid is the number of unit cubes it contains. A block is a solid with volume at most 4. Two blocks have the same type when one can be obtained from the other by translations and rotations (not reflections). There are exactly 12 block types (see Figure 2). The colors in the figures only help to clarify the structure of the solids; they have no other meaning.

A set D of blocks is a decomposition of a solid S when the union of all blocks in D equals S, and no two distinct blocks in D have a unit cube in common.

Your task is to write a program that, given a description of a solid S, determines a smallest set of blocks into which S can be decomposed. It only needs to report the types of these blocks as often as they occur in the decomposition.

Input

Your program is to read from standard input. The first line contains the volume V of the solid (1 <= V <= 50). The remaining V lines contain three integers x, y, z, being the coordinate triple of its corner that minimizes x + y + z, each identifying one unit cube of the solid (1 <= x, y, z <= 7).

Output

Your program is to write to standard output. The first line must contain one integer M, being the smallest number of blocks into which the input solid can be decomposed.

Sample Input

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

Sample Output

5

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator