Michael's solution for Set 1