Replace me by the sum of my cyclic successors! I have a simple challenge for you this time. Given an array of positive integers A (or the equivalent in your language), replace each entry Ai with the sum of the next Ai elements of A, cycling back from the beginning if there are not enough items.

As usual, you can compete in any programming language and can take input and provide output through any standard method and in any reasonable format, while taking note that these loopholes are forbidden by default. You may optionally take the size of A as input too. This is code-golf, so the shortest submission (in bytes) for every language wins.

Examples / Test Cases

Given [1,3,4,5], your code should output [3,10,13,14], because 1 is replaced by 3, 3 is replaced by 4+5+1=10 (notice how it wrapped back from the start), 4 by 5+1+3+4=13 and 5 by 1+3+4+5+1=14.

Given [3,2,1,9], your program should produce [12,10,9,33], because we substitute 3 with 2+1+9=12, 2 with 1+9=10, 1 with 9 and 9 with 3+2+1+9+3+2+1+9+3=33 (notice how we wrapped back from the start more than once).

Some more test cases for you to choose from:

[4,3,2,1]                       -&gt; [10,7,5,4]
[3,2,1,9]                       -&gt; [12,10,9,33]
[1,3,4,5]                       -&gt; [3,10,13,14]
[4,4,3,2,2]                     -&gt; [11,11,8,6,8]
[3,5,3,2,1]                     -&gt; [10,14,6,4,3]
[3,2,4,3,2,1,1]                 -&gt; [9,7,7,4,2,1,3]
[7,8,6,5,4,3,2,1,5]             -&gt; [29,33,20,15,11,8,6,5,30]
[28,2,4,2,3,2,3,4,5,3]          -&gt; [137,6,10,5,9,7,12,38,39,34]
[1,2,3,4,5,4,3,2,1,2,3,4,3,2,1] -&gt; [2,7,13,14,12,8,5,3,2,7,9,7,4,2,1]
MATL, 10 9 bytes

"G@:X@+)s


Try it online!

&#9;% implicit input
"&#9;% for loop, iterate over the input array&#32;
G&#9;% push input x
@&#9;% push for loop index, x[i]
:&#9;% range, push [1,...,x[i]]
X@&#9;% push for loop index, i
+&#9;% sum, so stack holds [i+1,...,i+x[i]]
)&#9;% index, modularly, so gets the cyclic successors
s&#9;% sum cyclic successors, leaving the sum on the stack
&#9;% implicit end of for loop
&#9;% implicit output of stack