#include<cstdio>
#include<cctype>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<climits>
#include<map>
using namespace std;
const int maxn = 12;
char maps[12][12] = {
{'*','*','*','*','*','*','*','*','*','*','*','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','.','.','.','.','.','.','.','.','.','.','*'},
{'*','*','*','*','*','*','*','*','*','*','*','*'}
};
struct Animal
{
char name;
char towards;
bool isAPeriod;
int x;
int y;
int startPointX;
int startPointY;
Animal(char n)
{
name = n;
towards = 'w';
isAPeriod = false;
}
void getXY(int a, int b)
{
x = a;
y = b;
startPointX = a;
startPointY = b;
}
void ChangeTowards()
{
switch (towards)
{
case 'w':
towards = 'd';
break;
case 'd':
towards = 's';
break;
case 's':
towards = 'a';
break;
case 'a':
towards = 'w';
break;
default:
break;
}
}
void moved(int a, int b)
{
if (a == startPointX && b == startPointY && towards == 'w')
{
isAPeriod = true;
}
x = a;
y = b;
}
void move()
{
if (towards == 'w')
{
if (maps[x - 1][y] != '*')
{
maps[x][y] = '.';
maps[x - 1][y] = name;
moved(x - 1, y);
}
else
{
ChangeTowards();
}
}
else if (towards == 'd')
{
if (maps[x][y + 1] != '*')
{
maps[x][y] = '.';
maps[x][y + 1] = name;
moved(x, y + 1);
}
else
{
ChangeTowards();
}
}
else if (towards == 's')
{
if (maps[x + 1][y] != '*')
{
maps[x][y] = '.';
maps[x + 1][y] = name;
moved(x + 1, y);
}
else
{
ChangeTowards();
}
}
else
{
if (maps[x][y - 1] != '*')
{
maps[x][y] = '.';
maps[x][y - 1] = name;
moved(x, y - 1);
}
else
{
ChangeTowards();
}
}
}
}Cow('C'), Farmer('F');
int main() {
int step = 0;
bool catched = false;
for (int i = 1; i <= 10; i++)
{
char atemp;
for (int j = 1; j <= 10; j++)
{
char temp;
scanf("%c", &temp);
maps[i][j] = temp;
if (temp == '.')
{
continue;
}
else
{
maps[i][j] = temp;
}
if (temp == 'C')
{
Cow.getXY(i, j);
}
else if (temp == 'F')
{
Farmer.getXY(i, j);
}
}
scanf("%c", &atemp);
}
while (Cow.isAPeriod != true || Farmer.isAPeriod != true)
{
Cow.move();
Farmer.move();
step++;
if (Cow.x == Farmer.x && Cow.y == Farmer.y)
{
catched = true;
break;
}
}
if (catched)
{
printf("%d", step);
}
else
{
printf("%d", 0);
}
return 0;
}