put P1 and P4's solutions together