complete 1002.cpp