Tried to make a macro of distance. Didn't work good.
Unrolling a loop in fill_matrix
Register keyword
Removed if statement in generate_histogram loop.
The report