This is my exercise on poj just for a record.