Ants (1000+1500 points)

An ant colony decided to clean up an area, help them organize their job.

The area consists of 32x32 cells. Each cell of the area has a height level between 0 and 9 units. The goal of the ants is to make the height level 0 at the entire area in the least number of iterations.

At each iteration, each ant can step one. A step can be staying at the current cell, moving to one of the four neighboring cells (in North, East, South and West directions), or moving to a neighboring cell with one unit soil, in which case at the height level at the current cell decreases and at the target increases by one.

  

Ants cannot step too far upwards, so a step is only possible if the target is at most one unit higher. Ants can fall down from any height just fine, so stepping downwards is allowed.

Stepping with soil is only possible if the height of the source and destination cells remain between 0 and 9. At each iteration there can be at most one ant at each cell and ants must not go outside the area.

There are special "depo" cells in the area which are connected to the storage system of the ant colony. Any number of soil units can be moved into the depos as well as any number of soil units can be taken out of it. The height of a depo cell always remains 0.

Input

The input consists of 32 lines, each containing 32 characters (and a newline). This is the map of the 32x32 cells. Each character describes one cell:

Output

The first line of the output contains a single integer N, the number of iterations it takes to clear the area. N does not need to be the optimal number of steps, but it must not be more than 10000.

The following N lines each describes one iteration with M characters where M is the number of ants at the area. Ants are numbered in the order they appear in the input. The ith character of an iteration line means the step the ith ant takes in that iteration:

After the N iteration the height of each cell should be 0.

Example input

00000000000000000000000000000000
0000a0-1000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
0000000000000c000000000000000000
0000000000000-000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000

Example output

4
27
21
27
80

Sub problems

We divided the 10 inputs into 5 sub problems:

Ant bonus

This is a bonus part of the problem and it is worth +1500 points at maximum.

We would like to encourage you to design an input for the ants problem. Until midnight each team can submit one input design. The input is only accepted if the submitter can solve it in at most 5000 iterations.

A submission to the ant bonus problem should contain a correct input and a possible solution with at most 5000 iterations.

After midnight all the submitted inputs are published and teams can try to solve each other's input. (Submitting is optional, but in case you design an input you get points for solving your own submitted input as well).

Scoring

Ants is a scaled problem based on N, the iteration count of the solution. For each solved input one gets 50 + 50(5-N/min)/4 points, where min is the iteration count in the best correct submission.

For the ant bonus problems one can get 50 points each: 25 + 25(5-N/min)/4 (teams get points for the inputs they designed themselfs as well).