#include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int arr[3][3], present[9] = {}, dup, index_col = 0, index_row = 0, cost1 = 0; for(int i = 0; i < 3; i ++){ for(int j = 0; j < 3; j ++){ cin>>arr[i][j]; present[arr[i][j]]++; } } int i = 0, j = 0; for(i = 0; i < 3; i ++){ int sum = 0; for(j = 0; j < 3; j ++){ sum+=arr[i][j]; } if(sum > 15 || sum < 15){ index_row = i; int k, l; for(k = 0; k <3; k++){ int sum_c = 0; for(l = 0; l <3; l++){ sum_c += arr[k][l]; } if(sum_c > 15 || sum_c < 15){ index_col = l; break; } } } } int index = 0; cost1 = arr[index_row][index_col]; for(int i = index_row; i < 3; i++){ if(present[i] > 1){ for(int j = 0; j < 9; j++){ if(present[i] == 0){ index = i; } } } } arr[index_row][index_col] = ++index; if(cost1 > arr[index_row][index_col]) cout<< cost1-arr[index_row][index_col]; else cout<< arr[index_row][index_col] - cost1; return 0; }