Solved for all problems 26-50. Requires optimisation