Looking for variant approach/sketch

Usually optimization is done for sorting algorithms and the like.
Some scale with n, some with n^2, some with nlog(n).
For n=1000 that makes a huge difference.
But here n is small. And the differences found so far are also small. So all of this is just for fun...