solve poj problem