input should be accumulated length, i.e. end-indices not start-indices.
input should be accumulated length, i.e. end-indices not start-indices.