Hello! I do not understand the math that was used to solve this problem. In the official editorial`, I understand everything until the last 2 sentences, which are " Thus, we have to group all prefix by value pi−i for i from 0 to n. And if the have x prefix with same value of pi−i then we have to add x(x−1)/2 to the answer."
Would anyone be able to explain this concept to me? Thanks!