Working on TOJ - Problem 1000