#include #include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ string a[9]; string temp[]=""; int initial[9]={0}; for(int i=0;i<9;i++){ cin>>a[i]; initial[i]=stoi(a[i]); *temp= *temp+a[i]; } long int num=stoi(*temp); vector sum(8); long int a1[9]={8,1,6,3,5,7,4,9,2}; long int a2[9]={6,1,8,7,5,3,2,9,4}; long int a3[9]={4,9,2,3,5,7,8,1,6}; long int a4[9]={2,9,4,7,5,3,6,1,8}; long int a5[9]={8,3,4,1,5,9,6,7,2}; long int a6[9]={4,3,8,9,5,1,2,7,6}; long int a7[9]={6,7,2,1,5,9,8,3,4}; long int a8[9]={2,7,6,9,5,1,4,3,8}; for(int i=0;i<9;i++){ sum[0]=sum[0]+abs(a1[i]-initial[i]); sum[1]=sum[1]+abs(a2[i]-initial[i]); sum[2]=sum[2]+abs(a3[i]-initial[i]); sum[3]=sum[3]+abs(a4[i]-initial[i]); sum[4]=sum[4]+abs(a5[i]-initial[i]); sum[5]=sum[5]+abs(a6[i]-initial[i]); sum[6]=sum[6]+abs(a7[i]-initial[i]); sum[7]=sum[7]+abs(a8[i]-initial[i]); } cout<<*std::min_element(sum.begin(), sum.end()); return 0; }