Fix bug in add topic pages

range(from, to, step), the index to is not covered.
for i in range(n - 1, -1, -1) will cover n -1, n -2, ..., 0