Optimizing Box Weights Hackerrank Solution Python