Increment frequency of value matrix [ i ] [ j ] at distance i + j
freq [ i + j ] [ matrix [ i ] [ j ] ] += 1 NEW_LINE min_changes_sum = 0 NEW_LINE for i in range ( dist // 2 ) : NEW_LINE maximum = 0 NEW_LINE total_values = 0 NEW_LINE