Added beautiful solution for hamm problem