solution of poj.org