Enric wants to go on holidays. He will first fly to any of cities. Let’s call that initial city. He will rent a car in , spend days on a roadtrip, and finally fly back home from . He can visit any city more than once in his route, but he will stay at least one day in each city he visits, everytime he visits it, with one exception: the first day he will not visit .
Given that he only cares about the order of the visited cities, but not about the number of days spent at every city, in how many ways can Enric plan his holidays? Apart from , he wants to visit at least another city. Consider that the travel time between cities is negligible.
Input consists of several cases. Every case begins with and , followed by rows, one for every city , with numbers each, with a 1 if there is a direct road from city to , and a 0 otherwise. Note that roads may be one-way only, that is, the given adjacency matrix can be asymmetric. Assume , , and .
For every case, print the number of ways to spend days on holidays, modulo .
Input
3 2 0 1 0 0 0 1 1 0 0 3 2 0 1 1 0 0 1 0 1 0 4 4 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 0 3 1000000 0 1 1 1 0 1 1 0 0
Output
0 2 7 137493254