P042: improved solution