#include using namespace std; int main(){ int a[3][3] = {4,9,2,3,5,7,8,1,6}; int b[3][3] = {2,7,6,9,5,1,4,3,8}; int c[3][3] = {6,1,8,7,5,3,2,9,4}; int d[3][3] = {8,3,4,1,5,9,6,7,2}; int e[3][3] = {2,9,4,7,5,3,6,1,8}; int f[3][3] = {6,7,2,1,5,9,8,3,4}; int g[3][3] = {8,1,6,3,5,7,4,9,2}; int h[3][3] = {4,3,8,9,5,1,2,7,6}; int v[3][3]; int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0; for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ cin>>v[i][j]; } } for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ if(v[i][j]!=a[i][j]){ A += abs(v[i][j]-a[i][j]); } } } for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ if(v[i][j]!=b[i][j]){ B += abs(v[i][j]-b[i][j]); } } } for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ if(v[i][j]!=c[i][j]){ C += abs(v[i][j]-c[i][j]); } } } for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ if(v[i][j]!=d[i][j]){ D += abs(v[i][j]-d[i][j]); } } } for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ if(v[i][j]!=e[i][j]){ E += abs(v[i][j]-e[i][j]); } } } for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ if(v[i][j]!=f[i][j]){ F += abs(v[i][j]-f[i][j]); } } } for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ if(v[i][j]!=g[i][j]){ G += abs(v[i][j]-g[i][j]); } } } for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ if(v[i][j]!=h[i][j]){ H += abs(v[i][j]-h[i][j]); } } } priority_queue pq; pq.push(-A); pq.push(-B); pq.push(-C); pq.push(-D); pq.push(-E); pq.push(-F); pq.push(-G); pq.push(-H); cout<<-pq.top()<