Working on TOJ - Problem 1001