Mirko was hired as a physicist at the European Organization for Nuclear Research (CERN), and his first assignment is to draw the blueprint of the newest particle accelerator.
The accelerator has exactly N chambers, and at the moment an experiment starts every chamber holds one particle. Each chamber has exactly one chamber that follows it. Every second, all particles move at the same time from the chamber they are in to the chamber that follows it. If chamber B follows chamber A, chamber A does not have to follow chamber B, although two chambers may follow each other.
The condition that matters most for the experiment is that after K seconds every particle is back in the chamber it started in. Mirko wants to know how many blueprints satisfy this condition. Two blueprints are different when some chamber is followed by a different chamber in each of them. The number of blueprints can be very large, so report only its remainder after division by M.
Note that a chamber may follow itself.