You are working at a production plant of biological weapons. You are a maintainer of a terrible virus weapon with very high reproductive power. The virus has a tendency to build up regular hexagonal colonies. So as a whole, the virus weapon forms a hexagonal grid, each hexagon being a colony of the virus. The grid itself is in the regular hexagonal form with N colonies on each edge.
The virus self-propagates at a constant speed. Self-propagation is performed simultaneously at all colonies.When it is done, for each colony, the same number of viruses are born at every neighboring colony. Note that,after the self-propagation, if the number of viruses in one colony is more than or equal to the limit density M,then the viruses in the colony start self-attacking, and the number reduces modulo M.
Your task is to calculate the total number of viruses after L periods, given the size N of the hexagonal grid andthe initial number of viruses in each of the colonies.