#include #include #include #include #define every(iter,iterable) for(typeof((iterable).begin()) iter =iterable.begin();iter!=iterable.end();iter++) #include #include using namespace std; int cost(int [3][3],int [3][3]); int cost(int a[3][3],int b[3][3]) { int z=0; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { z=z+abs(a[i][j]-b[i][j]); } } return z; } int main() { int a[3][3]; int r[4]; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { cin>>a[i][j]; } } int a1[3][3]={4,9,2,3,5,7,8,1,6}; int a2[3][3]={4,3,8,9,5,1,2,7,6}; int a3[3][3]={6,7,2,1,5,9,8,3,4}; int a4[3][3]={6,1,8,7,5,3,2,9,4}; int a5[3][3]={8,3,4,1,5,9,6,7,2}; int a6[3][3]={8,1,6,3,5,7,4,9,2}; int a7[3][3]={2,9,4,7,5,3,6,1,8}; int a8[3][3]={2,7,6,9,5,1,4,3,8}; int z[8]; z[0]=cost(a,a1); z[1]=cost(a,a2); z[2]=cost(a,a3); z[3]=cost(a,a4); z[4]=cost(a,a5); z[5]=cost(a,a6); z[6]=cost(a,a7); z[7]=cost(a,a8); int m=z[0]; for(int i=0;i<8;i++) { if(z[i]