Modified p2.cpp according to TA's tips.