Increment frequency of value matrix [ i ] [ j ] at distance i + j
freq [ i + j ] [ matrix [ i ] [ j ] ] ++ ; } } var min_changes_sum = 0 ; for ( var i = 0 ; i < parseInt ( dist / 2 ) ; i ++ ) { var maximum = 0 ; var total_values = 0 ;