Solution from CareerCup 150