Solved POJ2956 and POJ 2957