#include #include #include #include #include #include using namespace std; int res=INT_MAX; int testmat[3][3]; int mod(int a,int b) { return a>=b?a-b:b-a; } int find(int mat[3][3]) { int cost=0; for(int i=0;i<3;i++) for(int j=0;j<3;j++) if(testmat[i][j]!=mat[i][j]) cost+= mod(testmat[i][j],mat[i][j]); return cost; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int ansmat1[3][3]={4,9,2,3,5,7,8,1,6}; int ansmat2[3][3]={8,3,4,1,5,9,6,7,2}; int ansmat3[3][3]={6,1,8,7,5,3,2,9,4}; int ansmat4[3][3]={2,7,6,9,5,1,4,3,8}; int ansmat5[3][3]={8,1,6,3,5,7,4,9,2}; int ansmat6[3][3]={4,3,8,9,5,1,2,7,6}; int ansmat7[3][3]={2,9,4,7,5,3,6,1,8}; int ansmat8[3][3]={6,7,2,1,5,9,8,3,4}; int count=0; for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin>>testmat[i][j]; res=min(find(ansmat1),res); res=min(find(ansmat2),res); res=min(find(ansmat3),res); res=min(find(ansmat4),res); res=min(find(ansmat5),res); res=min(find(ansmat6),res); res=min(find(ansmat7),res); res=min(find(ansmat8),res); cout<