The joint optimization of the input flow and the size of the storehouse