Solves P4 with nested loops & conditionals