P019: improved solution