solution for poj.org