Working on TOJ - Problem 1293