Optimizing Box Weights Hackerrank