Bruce plans to visit his beloved grandmother whom he has not seen in ages. The petrol price is high and the roads are dangerous, so he wants to travel the shortest possible distance. He also wants to know how much choice he has for the route, as he wants to visit his grandmother more often and being Bruce, he loves change.
Bruce wants to surprise his grandmother with a box of cookies every time he visits. Bruce does not know how to make real cookies (digital ones are easy, however!), so he will have to go past a cookie store along the way, possibly increasing the length of the shortest distance.
Task
Bruce will start off in his home town, numbered
Input Specification
The first line contains a single integer
Output Specification
Output two space-separated integers, the length of the shortest route, followed by the remainder when the number of routes having this length is divided by
Constraints
- For
of tests, . for all (i.e. distance from a town to itself is zero) (i.e. distance from town to town is the same as the distance from town to town )
Sample Input
5
0 2 2 1 1
2 0 1 2 1
2 1 0 2 1
1 2 2 0 2
1 1 1 2 0
2
2 4
Sample Output
3 4
Explanation
In the sample input there are
- Bruce goes from Town
(purchasing cookies at ) - Bruce goes from Town
(purchasing cookies at ) - Bruce goes from Town
(purchasing cookies at ) - Bruce goes from Town
(purchasing cookies at )
Notice that travelling from Town
Comments
If a shortest path traverses two city with a store each, this counts as a single route or two? i.e. is it a route identified also by which particular city we use for the store?
What do we output if it is impossible to satisfy the given conditions?
The input format implies that the graph is complete (therefore connected). Also, the lower bound on
is 1, so there is always at least 1 cookie shop Bruce can visit. Thus, there will always be at least one path from town 1 to town 
that visits a cookie shop.
Wait if
, the upper bound for 
is 
. This may mean that 
can't be 
.
pblpbl -- I just changed the minimum number of towns to be 2. Thank you for your comment!
Can paths visit more than one cookie store?
Yes.