Calculate max frequency and total cells at distance i
for ( j = 0 ; j < Max_element + 1 ; j ++ ) { maximum = Math . Max ( maximum , freq [ i , j ] + freq [ n + m - 2 - i , j ] ) ; total_values += freq [ i , j ] + freq [ n + m - 2 - i , j ] ; }