Iterative Alliterative Additive Array Antics I honestly don't know what the point of this sort of calculation would be, but it should make fun golfing. Shortest code wins.

Input (in no particular order)


An array of integers, a (All elements will be integers less than the length of the array.)
An index therein, i
An iteration count, n


Processing


Store a number x with initial value of 0.
Do the following steps n times:


Add the current value of i to x.
Decrement a[i].
If a[i] is negative, increment it by the length of a.
Set i to a[i].

After the iterations, add the final value of i to x.


Output

After doing the above process, your program should output the final value of x.

Example (n=5)

a                     i   x
2,0,0,5,5,6,7,5,8,5   0   0
1,0,0,5,5,6,7,5,8,5   1   0
1,9,0,5,5,6,7,5,8,5   9   1
1,9,0,5,5,6,7,5,8,4   4   10
1,9,0,5,4,6,7,5,8,4   4   14
1,9,0,5,3,6,7,5,8,4   3   18


The program outputs 21.

Test Case Generator



function newTestCase() {
    var a = Array(Math.floor(Math.random() * 50) + 25).fill(0);
    a = a.map(Math.random).map(e =&gt; e * a.length).map(Math.floor);
    var i = Math.floor(Math.random() * a.length);
    for (var x = 0, n = 0, aa = [...a], ii = i; Math.random() * a.length &gt;= .5;) {
        n++;
        x += ii;
        aa[ii]--;
        if (aa[ii] &lt; 0) aa[ii] += a.length;
        ii = aa[ii];
    }
    return {a, i, n, shouldOutput: x + ii};
}
&lt;button type="button" onclick="console.log(newTestCase());"&gt;Generate&lt;/button&gt;
Python 2, 71 bytes



def f(a,i,n):x=0;exec"x+=i;a[i]+=len(a)*(a[i]&lt;1)-1;i=a[i];"*n;print x+i


Try it online!