В задаче есть логика
import math
order=50
box=[0, 0, 0]
box[2]=box[2]+order//18*2
order%=18
qty_box=[math.ceil(order/3), math.ceil(order/6), math.ceil(order/9)]
min_qty_box=min(qty_box)
index_min_qty_box=qty_box.index(min_qty_box)
free_place=[(min_qty_box*3-order), (min_qty_box*6-order),(min_qty_box*9-order)]
min_free_place=min(free_place[index_min_qty_box:])
box[free_place.index(min_free_place)]+=min_qty_box
print(box)