solve the poj1024 problem