I put my example code as follows. I think it is too inefficient.
For the example, I have a long text and a long array of indices of positions on the text.
And