Unique Dice
InterviewTime limit7sMemory limit1024 MB
Given n dice with six face values each, find the largest group of dice that match after some rotation.
- Level
Medium4 of 10
- Topics
- Hash map, Implementation
- Solved
- No attempts yet
Problem
You are about to leave home for your weekly game of Pumpkins and Flagons (P&F) when a text comes in asking you to bring a large collection of identical P&F dice. They have asked the right person, for you have a very large collection of P&F dice, which is currently unsorted.
Each die is an ordinary cube with a number on each of its six faces. The numbers are in the range 1 to 6, but they do not need to be distinct. For example, , , and are all valid sets of numbers for the six faces. Find the size of the largest set of identical dice you can create from your collection. Two dice are identical if you can rotate one of them so that the top, bottom, and all four side faces show the same numbers as the other.

Figure 1: The six faces of a die.
Input
The first line contains an integer (), the number of dice in your collection. The next lines each contain six integers from 1 to 6, separated by spaces. They give the numbers on the top, bottom, front, back, left, and right faces, in that order (see Figure 1).
Output
Print a single integer, the size of the largest set of identical dice that can be made from the collection.