Problems
Farmer John has recently built an enormous barn consisting of an
Bessie starts in room
Please determine the maximum number of rooms Bessie can illuminate.
Problem credits: Austin Bannister and Brian Dean
Input
The first line of input contains integers
The next
Output
A single line giving the maximum number of rooms Bessie can illuminate.
Example
3 6
1 1 1 2
2 1 2 2
1 1 1 3
2 3 3 1
1 3 1 2
1 3 2 1
5
Here, Bessie can use the switch in