#include<bits/stdc++.h>
using namespace std ;
int Map[ 12 ][ 12 ] ;
int vis[ 12 ][ 12 ] ;
int visx[ 12 ][ 11 ] ;
int visy[ 12 ][ 11 ] ;
int g[ 11 ][ 11 ] ;
int cunchu[ 100 ][ 4 ] ;
int ans = -1 ;
int sum ;
int pd ;
struct node {
int line , zem ;
}a[ 11 ];
bool cmp ( node a , node b ) {
return a.zem < b.zem ;
}
int pdg( int x , int y ) {
if ( 1 <= x && x <= 3 ) {
if ( 1 <= y && y <= 3 ) return 1 ;
if ( 4 <= y && y <= 6 ) return 2 ;
return 3 ;
}
if ( 4 <= x && x <= 6 ) {
if ( 1 <= y && y <= 3 ) return 4 ;
if ( 4 <= y && y <= 6 ) return 5 ;
return 6 ;
}
if ( 7 <= x && x <= 9 ) {
if ( 1 <= y && y <= 3 ) return 7 ;
if ( 4 <= y && y <= 6 ) return 8 ;
return 9 ;
}
}
int pdpts( int x , int y ) {
if ( x == 1 || x == 9 || y == 1 || y == 9 ) return 6 ;
if ( x == 2 || x == 8 || y == 2 || y == 8 ) return 7 ;
if ( x == 3 || x == 7 || y == 3 || y == 7 ) return 8 ;
if ( x == 4 || x == 6 || y == 4 || y == 6 ) return 9 ;
return 10 ;
}
void dfs( int x , int score ) {
cout<<cunchu[x][0]<< " "<<cunchu[x][1]<<endl;
if ( x == pd ) {
if ( score > ans ) ans = score ;
return ;
}
for ( int i = 1 ; i <= 9 ; i++ ) {
if ( vis[ cunchu[ x ][ 0 ] ][ cunchu[ x ][ 1 ] ] == 0 && visx[ cunchu[ x ][ 0 ] ][ i ] == 0 && visy[ cunchu[ x ][ 1 ] ][ i ] == 0 && g[ cunchu[ x ][ 3 ] ][ i ] == 0 ) {
visx[ cunchu[ x ][ 0 ] ][ i ] = visy[ cunchu[ x ][ 1 ] ][ i ] = g[ cunchu[ x ][ 3 ] ][ i ] = 1 ;
cout << x << " " << pd << endl ;
dfs( x + 1 , score + ( i * cunchu[ x ][ 2 ] ) ) ;
visx[ cunchu[ x ][ 0 ] ][ i ] = visy[ cunchu[ x ][ 1 ] ][ i ] = g[ cunchu[ x ][ 3 ] ][ i ] = 0 ;
}
}
return ;
}
int main () {
for ( int i = 1 ; i <= 9 ; i++ ) {
a[ i ].line = i ;
for ( int k = 1 ; k <= 9 ; k++ ) {
cin >> Map[ i ][ k ] ;
if ( Map[ i ][ k ] > 0 ) {
vis[ i ][ k ] = 1 ;
visx[ i ][ Map[ i ][ k ] ] = 1 ;
visy[ i ][ Map[ i ][ k ] ] = 1 ;
g[ pdg( i , k ) ][ Map[ i ][ k ] ] = 1 ;
sum += Map[ i ][ k ] * pdpts( i , k ) ;
}
else if ( Map[ i ][ k ] == 0 ) {
a[ i ].zem++ ;
}
}
}
sort( a + 1 , a + 10 , cmp ) ;
for ( int i = 1 ; i <= 9 ; i++ ) {
for ( int k = 1 ; k <= 9 ; k++ ) {
if ( Map[ a[ i ].line ][ k ] == 0 ) {
cunchu[ pd ][ 0 ] = a[ i ].line ;
cunchu[ pd ][ 1 ] = k ;
cunchu[ pd ][ 2 ] = pdpts( a[ i ].line , k ) ;
cunchu[ pd ][ 3 ] = pdg( a[ i ].line , k ) ;
pd++;
}
}
}
dfs ( 0 , sum ) ;
cout << ans ;
return 0 ;
}