Painting
In her school club sessions, Yevhenia learned how to create paper models of regular polyhedra, known as Platonic solids, and semi-regular polyhedra, known as Archimedean solids. She recalled the following definitions:
A Platonic solid is a (convex) polyhedron where all faces are identical regular polygons, and the angles between the faces at each vertex are the same.
An Archimedean solid is a (convex) polyhedron where all faces are regular polygons, though not necessarily with the same number of sides, and the angles between the faces at each vertex are the same. Additionally, there must be at least two different types of faces.
In an Archimedean solid, each type of face appears in the same number and sequence around each vertex, whether viewed in the same or opposite directions from the outside.
Yevhenia crafted several polyhedron models to decorate the math classroom and took some home to impress her family. Her efforts were indeed impressive. However, during dinner, she didn't notice when her younger sister Marichka began coloring the faces, using only one color per face. Multiple faces could share the same color, even if they were adjacent, meaning they shared an edge. Yevhenia wondered... As an aspiring mathematician, she was curious about the number of ways to color the faces of an Archimedean solid using a given number of colors, considering symmetries — spatial transformations that leave the polyhedron unchanged. In other words, colorings are considered identical if one can be transformed into another through a bijective mapping of faces that preserves adjacency.
Given complete information about the adjacency of the faces of a Platonic or Archimedean solid, determine the number of distinct ways to color this polyhedron using a specified number of colors.
Input
The first line specifies the number of colors m (m < 6). The number of input lines is one more than the number of faces of the polyhedron and less than 24. All faces of the polyhedron are numbered consecutively with natural numbers starting from 1. The j-th line (j > 1) contains an unordered list of numbers representing the faces adjacent to face j – 1.
The input guarantees that the number of symmetries of the polyhedron does not exceed 120.
Output
Output the number of distinct ways to color the polyhedron's faces using m colors, considering the symmetries of the polyhedron.