eolymp
bolt
Try our new interface for solving problems
Problems

Buildings

Buildings

As a traveling salesman in a globalized world, Alan has always moved a lot. He almost never lived in the same town for more than a few years until his heart yearned for a different place. However, this newest town is his favorite yet --- it is just so colorful. Alan has recently moved to Colorville, a smallish city in between some really nice mountains. Here, Alan has finally decided to settle down and build himself a home --- a nice big house to call his own. In Colorville, many people have their own houses --- each painted with a distinct pattern of colors such that no two houses look the same. Every wall consists of exactly $n \times n$ squares, each painted with a given color (windows and doors are also seen as unique “colors”). The walls of the houses are arranged in the shape of a regular $m$-gon, with a roof on top. According to the deep traditions of Colorville, the roofs should show the unity among Colorvillians, so all roofs in Colorville have the same color. \includegraphics{https://eolympusercontent.com/images/fshg3on0pd3gbd4t9q9juem8ng.gif} $$ Example~house~design~for~n~=~3,~m~=~6 $$ Of course, Alan wants to follow this custom to make sure he fits right in. However, there are so many possible designs to choose from. Can you tell Alan how many possible house designs there are? (Two house designs are obviously the same if they can be translated into each other just by rotation.) \InputFile One line contains three integers $n, m$ and $c$, where \begin{itemize} \item $n~(1 \le n \le 500)$ is the side length of every wall, i.e. every wall consists of $n \times n$ squares; \item $m~(3 \le m \le 500)$ is the number of corners of the regular polygon; \item $c~(1 \le c \le 500)$ the number of different colors. \end{itemize} \OutputFile Print the number of possible different house designs. Since the answer can be very large, print in modulo $10^9 + 7$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
1 3 1
Output example #1
1
Input example #2
2 5 2
Output example #2
209728
Source 2017 German Collegiate Programming Contest (GCPC), Problem B