#include <iostream>
using namespace std;
int
map[1001][1001], n, ans1 = 0, ans2 = 99999, vst[1001][1001];
const int delta[8][2] = { { 0, 1 }, { 1, 1 }, { 1, 0 }, { 1, -1 }, { 0, -1 }, { -1, -1 }, { -1, 0 }, { -1, 1 } };
struct
point
{
int
x, y;
point()
{
x = y = 0;
}
};
void
__read__()
{
cin >> n;
for( int i = 1; i <= n; i++ )
for( int j = 1; j <= n; j++ )
cin >> map[i][j];
}
void
__dfs__( point p, int step )
{
if( p.x == n && p.y == 1 )
{
ans1++;
if( step < ans2 )
ans2 = step;
return;
}
for( int i = 0; i < 8; i++ )
{
point pp = p;
pp.x += delta[i][0];
pp.y += delta[i][1];
if( pp.x > 0 && pp.x <= n
&& pp.y > 0 && pp.y <= n )
if( !map[pp.y][pp.x] && !vst[pp.y][pp.x] )
{
vst[pp.y][pp.x] = 1;
__dfs__( pp, step + 1 );
vst[pp.y][pp.x] = 0;
}
}
}
void
__outp__()
{
cout << ans1 << endl << ans2 << endl;
}
int
main()
{
point source;
__read__();
__dfs__( source, -1 );
__outp__();
return 0;
}