#include<cstdio>
#include<iostream>
#define M 10
using namespace std;
int fen[M][M]={{0,0,0,0,0,0,0,0,0,0},
{0,6,6,6,6,6,6,6,6,6},
{0,6,7,7,7,7,7,7,7,6},
{0,6,7,8,8,8,8,8,7,6},
{0,6,7,8,9,9,9,8,7,6},
{0,6,7,8,9,10,9,8,7,6},
{0,6,7,8,9,9,9,8,7,6},
{0,6,7,8,8,8,8,8,7,6},
{0,6,7,7,7,7,7,7,7,6},
{0,6,6,6,6,6,6,6,6,6}};
int map[M][M],f[M][M],vish[M][M],visl[M][M],visg[4][4][M],ans=0;
void init(int x,int y,int v)
{
vish[x][v]=1;
visl[y][v]=1;
visg[(x+2)/3][(y+2)/3][v]=1;
}
void init2(int x,int y,int v)
{
vish[x][v]=0;
visl[y][v]=0;
visg[(x+2)/3][(y+2)/3][v]=0;
}
int ok()
{
for(int i=1;i<=9;i++)
for(int j=1;j<=9;j++)
if(!map[i][j])return 0;
return 1;
}
void dfs(int x,int y,int t)
{
if(map[x][y])return;
if(ok())
{
ans=max(t,ans);
return;
}
for(int k=1;k<=9;k++)
{
if(!vish[x][k]&!visl[y][k]&&!visg[(x+2)/3][(y+2)/3][k])
{
map[x][y]=k;//赋值
init(x,y,k);//标志
t+=fen[x][y]*k;//累加分数
int ff=0;
for(int i=x;i<=9;i++)
{
for(int j=y;j<=9;j++)
if(!f[i][j])
{
dfs(i,j,t);//递归下一个数
map[x][y]=0;
init2(x,y,k);//回溯
ff=1;
break;
}
if(ff)break;
}
}
}
}
int main()
{
freopen("jh.in","r",stdin);
int tot=0;
for(int i=1;i<=9;i++)
for(int j=1;j<=9;j++)
{
scanf("%d",&map[i][j]);
if(map[i][j])f[i][j]=1;
tot+=map[i][j]*fen[i][j];
init(i,j,map[i][j]);
}
int flag=0;
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
if(!f[i][j])
{
flag=1;
dfs(i,j,tot);
break;
}
if(flag)break;
}
printf("%d",ans);
return 0;
}