Problem 5

A little ugly but it works