Under construction

Still being built. Things may change

The Tamworth Two

Time limit1sMemory limit1024 MB

Summary
Simulate a cow pair and Farmer John on a 10 by 10 grid, both turning clockwise at walls, and report the first minute they share a square.
Level

Easy3 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

Two cows are loose somewhere in a forest. Farmer John is lending his expertise to their capture. Your task is to model their behavior.

The chase takes place on a 10 by 10 grid. Each square is empty or contains an obstacle, the cows (who always travel together), or Farmer John. The cows and Farmer John can share a square when they meet, but neither can share a square with an obstacle.

Each square is written as follows:

  • .: empty square
  • *: obstacle
  • C: cows
  • F: Farmer John

Here is a sample grid:

*...*.....
......*...
...*...*..
..........
...*.F....
*.....*...
...*......
..C......*
...*.*....
.*.*......

The cows wander the grid in a fixed way. Each minute, they either move forward or rotate. Normally they move one square in the direction they face. If an obstacle is in the way, or walking forward would leave the board, they spend the whole minute rotating 90 degrees clockwise.

Farmer John, wise in the ways of cows, moves in exactly the same way.

The farmer and the cows move simultaneously each minute. If they pass each other while moving, they are not considered to have met. The chase ends when Farmer John and the cows occupy the same square at the end of a minute. Both the cows and the farmer begin facing up.

Input

The input is ten lines of ten characters each, with no spaces. The lines give the initial state of the cows, Farmer John, and the obstacles, using the characters above. There is exactly one farmer and one pair of cows. They do not start on the same square.

Output

Print one line containing a single integer: the number of minutes until Farmer John and the cows meet. Print 0 if they never meet.

Examples1

  1. Example 1

    Input
    *...*.....
    ......*...
    ...*...*..
    ..........
    ...*.F....
    *.....*...
    ...*......
    ..C......*
    ...*.*....
    .*.*......
    
    Expected output
    49