Problem A
Barica
Barica is an unusual frog. She lives in a pond where
-
and , or -
and
For each plant, we know the number of flies in its immediate vicinity. Barica can use her swift tongue to eat all flies near the plant she is at.
Barica absorbs one energy unit for each fly she eats, and
uses
Barica wants to go from plant
Find the sequence of plants Barica should travel to achieve her goal.
Input
The first line of input contains two integers
Each of the following
The first plant in the input is plant
No two plants will share the same pair of coordinates.
Note: The input data will guarantee that a sequence of jumps, although not necessarily unique, will always exist.
Output
Output the final energy level on the first line. Output an
integer
Sample Input 1 | Sample Output 1 |
---|---|
6 5 1 1 5 2 1 5 1 2 4 2 3 5 3 2 30 3 3 5 |
5 4 1 1 2 1 2 3 3 3 |
Sample Input 2 | Sample Output 2 |
---|---|
8 10 1 1 15 2 2 30 1 2 8 2 1 7 3 2 8 2 3 7 4 2 100 3 3 15 |
36 5 1 1 1 2 2 2 3 2 3 3 |
Sample Input 3 | Sample Output 3 |
---|---|
9 5 5 5 10 6 5 2 7 5 1 5 6 2 6 6 6 7 6 2 5 7 1 6 7 2 7 7 1 |
2 3 5 5 7 5 7 7 |