Complete poj-1007