optimal solution, albeit with some rounding errors
optimal solution with some rounding errors
cosmetic changes and fixed optimum solution calc