[Question]
  [
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](https://codegolf.meta.stackexchange.com/a/2073/59487) and can take input and provide output through any [standard method](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) and in any reasonable format, while taking note that [these loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden by default. You may optionally take the size of **A** as input too. This is [code-golf](/questions/tagged/code-golf "show questions tagged '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]                       -> [10,7,5,4]
[3,2,1,9]                       -> [12,10,9,33]
[1,3,4,5]                       -> [3,10,13,14]
[4,4,3,2,2]                     -> [11,11,8,6,8]
[3,5,3,2,1]                     -> [10,14,6,4,3]
[3,2,4,3,2,1,1]                 -> [9,7,7,4,2,1,3]
[7,8,6,5,4,3,2,1,5]             -> [29,33,20,15,11,8,6,5,30]
[28,2,4,2,3,2,3,4,5,3]          -> [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] -> [2,7,13,14,12,8,5,3,2,7,9,7,4,2,1]
```
  
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~10~~ 9 bytes
```
"G@:X@+)s
```
[Try it online!](https://tio.run/##y00syfn/X8ndwSrCQVuz@P//aEMdYx0THdNYAA "MATL – Try It Online")
```
	% implicit input
"	% for loop, iterate over the input array 
G	% push input x
@	% push for loop index, x[i]
:	% range, push [1,...,x[i]]
X@	% push for loop index, i
+	% sum, so stack holds [i+1,...,i+x[i]]
)	% index, modularly, so gets the cyclic successors
s	% sum cyclic successors, leaving the sum on the stack
	% implicit end of for loop
	% implicit output of stack
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
ṙJṁS¥"
```
[Try it online!](https://tio.run/##y0rNyan8///hzpleD3c2Bh9aqvT/cPvRSQ93zvj/P9pQx0jHWMdExxSIjYFsGB/MjgUA "Jelly – Try It Online")
[Answer]
# [Python](https://docs.python.org), 55 bytes
```
lambda a:[sum((-~v*a)[i:i+v])for i,v in enumerate(a,1)]
```
**[Try it online!](https://tio.run/##VY7BDoIwEETvfsXe2upyoKAiif5I4VBjiU2kECgkXvx1bBc52Ev3zcxOtn/7Z@eypblWy0u394cGXapxajlPPvNeC2VLe5hr0XQDWJzBOjBuas2gveEaU1Ev0fJm9NHjKscMJaY1KvrxEqY0aDkew5Tj6kvyj3/Z3ybxGQs8BX/T4q4sKCRJokLMqHyjLbzyWi3KHYTXD9Z5zgAY0q0IrHLJLVDDIwsSmFi@ "Python 3 – Try It Online")**
[Answer]
# J, 33 bytes
```
[:({.+/@{.}.)"1 i.@#|."{($~>./*#)
```
## ungolfed
```
[: ({. +/@{. }.)"1 i.@# |."0 _ ($~ (>./ * #))
```
## explanation
[![enter image description here](https://i.stack.imgur.com/5lY8N.png)](https://i.stack.imgur.com/5lY8N.png)
[Try it online!](https://tio.run/##fZDNasJAFIX3eYpDLJjROmb@nElAEYSuunLrUirVjQ@Qtq@e3jv5MYomJAOB@c797rnUqZyesC4xxTtylPQtJHb7z4/6UGaVnC@3lfyVIlU4y@3kR6ZV9va3kcvZRNQiSb6O31dkJ1gYaCiB58@ihMrh4WB7JAIoxhDNVAFjekgRZuFGIMOMotMO5Bo9LV5OUvwGrBAGfm5sqWYlZYmh9Lut2jKekUQV1IOnO3zjxvk43fXsw4rEaS4Cmma6TpYE8z5Bhzhax4DYEoy49zWeILJ2UYLqNQGGYu2g347tRJr/tgjWYJLrZT60HfkYGHdK6n8 "J – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~86~~ 85 bytes
* Saved a byte thanks to [Jakob](https://codegolf.stackexchange.com/users/44945/jakob).
```
C(y,c,l,i,k)int*y;{for(l=~0;++l<c;printf("%d,",k))for(k=i=0;i++<y[l];k+=y[(l+i)%c]);}
```
[Try it online!](https://tio.run/##jZLbaoQwEIav26dYhIWkzkKOqxLtzT6G60WxbBGtLUtvROyr20k83GwoERVNJt8/88/Up4@6nucLGaCGDhpoadP/vAxmvH3dSVf8MhPHXV6b7zuu30h0fIcIg6jdboumYKaJ43wou8q0cTGUpIsbeqwraqb5863pCR2fn7bDB7zKiJoLIbhQVnTkE3C6w6trn59eDyUH/Lr2GPnfWQUSBCBBeQgMEtCggkAOA5kfhFsMMpAyCMUxJwXai5KWxPGtAstbChQTaE9eHPBO4YxPWI16s0t77cKszk4x1LHVfktMHokZ@p9gjI0IYyauGr1z0cTskStcKwTmqzcDsDAWpCBSl7ZwAq5PIHH@mMcPmSAYXdFgC8EhkClIlFaBU7Dxt2KW/7UB3NMBYWXcbKBYujYrceqLibvuNP8B "C (gcc) – Try It Online")
[Answer]
## Haskell, ~~50~~ ~~47~~ 44 bytes
```
zipWith((sum.).take)<*>scanr(:)[].tail.cycle
```
[Try it online!](https://tio.run/##dY7NDoIwEITvPsUePIBZSSigaMTX8IA9NJWfhoINxYM@vJW0chDicWd2vpma6aaQ0pQZXM1LqIsYas/Tjzbwg4E1hX/anDVnXe8d/ZyOkpABf3JZmJaJDjK43VcAqhfdAGsoIY8xQoIh/VWthoeZGo6/MSZ0TnAMsmAkf9nf1oW3xxR3Y27y510ktWFibTsGo8XIyZkg7nZTzJuXklXabLlSHw "Haskell – Try It Online")
```
                    -- <*> in function context is Haskell's S combinator, i.e.
                    --     (zipWith ... <*> scanr ...) arg
                    -- resovles to
                    --     zipWith ... arg (scanr ... arg)
zipWith             -- so we zip
                    --   the input list and
 scanr(:)[]         --   the tails (tails of [1,2,3] are [[1,2,3],[2,3],[3],[]])
      tail          --   of the tail of
          cycle     --   and infinite cycle of the input list
                    -- with the function
 (sum.).take        --   take that many elements given by the element
                    --   of the input list from the list given by the inits
                    --   and sum it   
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~8~~ 7 bytes
```
εL¾+èO¼
```
[Try it online!](https://tio.run/##MzBNTDJM/f//3FafQ/u0D6/wP7Tn//9oIwsdIx0TIDYGYxMdUx3jWAA "05AB1E – Try It Online")
**Explanation**
```
ε        # apply to each element x of the input
 L       # push range [1 ... x]
  ¾+     # add counter to each (initially 0)
    è    # cyclically index into input with each
     O   # sum
      ¼  # increment counter
```
[Answer]
# [K4](http://kx.com/download/) / [K (oK)](https://github.com/JohnEarnest/ok), ~~20~~ 19 bytes
**Solution:**
```
+/'x#'1_(1+2##x)#x:
```
[Try it online!](https://tio.run/##y9bNz/7/X1tfvUJZ3TBew1DbSFm5QlO5wspQwVjBRMH0/38A "K (oK) – Try It Online")
**Examples:**
```
q)k)+/'x#'1_(1+2##x)#x:1 3 4 5
3 10 13 14
q)k)+/'x#'1_(1+2##x)#x:4 3 2 1
10 7 5 4
q)k)+/'x#'1_(1+2##x)#x:3 2 4 3 2 1 1
9 7 7 4 2 1 3
q)k)+/'x#'1_(1+2##x)#x:1 2 3 4 5 4 3 2 1 2 3 4 3 2 1
2 7 13 14 12 8 5 3 2 7 9 7 4 2 1
```
**Explanation:**
Reshape input, drop first, take x length of each, sum up.
```
+/'x#'1_(1+2##x)#x: / the solution
                 x: / store input as x
                #   / reshape
        (      )    / do this together
             #x     / count x
           2#       / duplicate (2-take)
         1+         / add 1
      1_            / 1 drop (_), remove first element
   x#'              / x take each-both
+/'                 / sum (+/) each
```
[Answer]
# [R](https://www.r-project.org/), ~~62~~ 58 bytes
```
function(a,l)diag(diffinv(matrix(a,max(a)*l+1,l))[a+2,])-a
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNRJ0czJTMxXSMlMy0tM69MIzexpCizAiiemwgkNbVytA2BSjSjE7WNdGI1dRP/p2kkaxjrGOkY6lhq6pho/gcA "R – Try It Online")
An alternative to the [other R solution](https://codegolf.stackexchange.com/a/166945/67312). In the comments [JayCe made a mention of `cumsum`](https://codegolf.stackexchange.com/questions/166920/replace-me-by-the-sum-of-my-cyclic-successors/166929#comment403701_166945) which triggered something in my brain to use `diffinv` and matrix recycling instead of `rep`.
### Explanation:
Given input array `a`, let `M=max(a)` and `l=length(a)`.
Observe that `M+l` is the maximum possible index we'd need to access, and that `M+l<=M*l+1`, since if `M,l>1`,`M+l<=M*l` (with equality only when `M=l=2`) and if `l==1` or `M==1`, then `M+l==M*l+1`.
By way of example, let `a=c(4,3,2,1)`. Then `M=l=4`.
We construct the `M*l+1 x l` matrix in R by `matrix(a,max(a)*l+1,l)`. Because R recycles `a` in column-major order, we end up with a matrix repeating the elements of `a` as such:
```
      [,1] [,2] [,3] [,4]
 [1,]    4    3    2    1
 [2,]    3    2    1    4
 [3,]    2    1    4    3
 [4,]    1    4    3    2
 [5,]    4    3    2    1
 [6,]    3    2    1    4
 [7,]    2    1    4    3
 [8,]    1    4    3    2
 [9,]    4    3    2    1
[10,]    3    2    1    4
[11,]    2    1    4    3
[12,]    1    4    3    2
[13,]    4    3    2    1
[14,]    3    2    1    4
[15,]    2    1    4    3
[16,]    1    4    3    2
[17,]    4    3    2    1
```
Each column is the cyclic successors of each element of `a`, with `a` across the first row; this is due to the way that R recycles its arguments in a matrix.
Next, we take the inverse "derivative" with `diffinv`, essentially the cumulative sum of each column with an additional `0` as the first row, generating the matrix
```
      [,1] [,2] [,3] [,4]
 [1,]    0    0    0    0
 [2,]    4    3    2    1
 [3,]    7    5    3    5
 [4,]    9    6    7    8
 [5,]   10   10   10   10
 [6,]   14   13   12   11
 [7,]   17   15   13   15
 [8,]   19   16   17   18
 [9,]   20   20   20   20
[10,]   24   23   22   21
[11,]   27   25   23   25
[12,]   29   26   27   28
[13,]   30   30   30   30
[14,]   34   33   32   31
[15,]   37   35   33   35
[16,]   39   36   37   38
[17,]   40   40   40   40
[18,]   44   43   42   41
```
In the first column, entry `6=4+2` is equal to `14=4 + (3+2+1+4)`, which is the cyclic successor sum (CSS) plus a leading `4`. Similarly, in the second column, entry `5=3+2` is equal to `10=3 + (4+1+2)`, and so forth.
So in column `i`, the `a[i]+2`nd entry is equal to `CSS(i)+a[i]`. Hence, we take rows indexed by `a+2`, yielding a square matrix:
```
     [,1] [,2] [,3] [,4]
[1,]   14   13   12   11
[2,]   10   10   10   10
[3,]    9    6    7    8
[4,]    7    5    3    5
```
The entries along the diagonal are equal to the cyclic successor sums plus `a`, so we extract the diagonal and subtract `a`, returning the result as the cyclic successor sums.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
R+"Jị⁸§
```
**[Try it online!](https://tio.run/##y0rNyan8/z9IW8nr4e7uR407Di3///9/tKGOsY6JjmksAA "Jelly – Try It Online")**
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 26 bytes
```
{Sum=>_[(_2+1:_)%#_]}#Iota
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBl@786uDTX1i4@WiPeSNvQKl5TVTk@tlbZM78k8b9fampKcbRKQUFyeixXQFFmXklIanGJc2JxanF0mo5CNJeCgoKJurG6kbqhDogNZqlbgtmGQHETdVMdiBqIKiOoKlM0PVAzoCLm6hbqZkA1MFGIGUYWYIVGYEGw0erGUItgfJgGCB/M5oqN/Q8A "Attache – Try It Online")
## Explanation
This is a fork of two functions:
* `{Sum=>_[(_2+1:_)%#_]}`
* `Iota`
What this means is, the right tine `Iota` is applied to the argument `x` and is passed as the second argument to the center tine (the first function). So this becomes, for input `x`:
```
{Sum=>_[(_2+1:_)%#_]}[x, Iota[x]]
```
Replacing those in for `_` and `_2`:
```
Sum => x[(Iota[x] + 1:x) % #x]
```
`Iota[x]` returns an array of the indices of `x`. It's equivalent to `0...#x`. `#x` is a short way of saying the size of `x`, or `Size[x]`. In essence, this function is mapping the `Sum` function over the second expression:
```
x[(Iota[x] + 1:x) % #x]
```
The outer `x[...]` bit means that `...` will generate a series of indices to be selected from `x`. The most important part of generating the indices is this:
```
Iota[x] + 1:x
```
This expression uses a bit of vectorization. To visualize this, let's suppose the input is `x := [1, 3, 4, 5]`. Then, this expression is equivalent to:
```
Iota[[1, 3, 4, 5]] + 1:[1, 3, 4, 5]
[0, 1, 2, 3] + [1:1, 1:3, 1:4, 1:5]
[0, 1, 2, 3] + [[1], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5]]
[0 + [1], 1 + [1, 2, 3], 2 + [1, 2, 3, 4], 3 + [1, 2, 3, 4, 5]]
[[0 + 1], [1 + 1, 1 + 2, 1 + 3], [2 + 1, 2 + 2, 2 + 3, 2 + 4], [3 + 1, 3 + 2, 3 + 3, 3 + 4, 3 + 5]]
[[1], [2, 3, 4], [3, 4, 5, 6], [4, 5, 6, 7, 8]]
```
This is a list of indices which represent the indices next `N` elements in `x` mod `#x`. To make them safe for retrieval, we take this array mod `#x`:
```
(Iota[x] + 1:x) % #x
```
This gives us the proper indices, which are then obtained from `x` and each array is summed, giving the proper results.
## Other attempts
**36 bytes:** `{Sum@_&Get=>((_2+1.._2+_)%#_)}#Iota` - I forgot `x[...]` fully vectorizes, so that becomes:
**30 bytes:** `{Sum=>_[(_2+1.._2+_)%#_]}#Iota` - but then I realized the `_2+` in the inner range could be factored out, which means we could save parentheses by using `:` instead of `..`, giving us the current version.
[Answer]
# [R](https://www.r-project.org/), ~~89~~ 64 bytes
```
j=rep(x<-scan(),max(x));Map(function(u,v)sum(j[v+1:u]),x,seq(x))
```
[Try it online!](https://tio.run/##K/r/P8u2KLVAo8JGtzg5MU9DUyc3sUKjQlPT2jexQCOtNC@5JDM/T6NUp0yzuDRXIyu6TNvQqjRWU6dCpzi1EKTwv7GCkYKhguV/AA "R – Try It Online")
Main idea to to generate a way-long-enough cycling index vector you can use to get the needed elements from the input vector.
Original version:
```
function(x,i=seq(x),j=rep(i,max(x))){for(k in i){T=c(T,sum(x[j[(k+1):(k+x[k])]]))};T[-1]}
```
[Try it online!](https://tio.run/##JcmxCsIwGATg3afo@B/@DrE6qOQtsoUMJTSQhqaaWgiUPntM7XDHfVwqTha3RPv1U6TMXs79hzJ4kKl/k@exy5XA6qZEofGx8ViVtKR4XkbKetAUzgLP2lkHA2OA7aX0RZitOLLU8pUFP4DTLlHV8o3vNcdz@L@B8gM "R – Try It Online")
[Answer]
# Pyth, ~~13~~ 11 bytes
```
.esm@Q+dkSb
```
Saved 2 bytes thanks to Mr. Xcoder.  
[Try it here](https://pyth.herokuapp.com/?code=.es%3C%3E%2ahsQQhkb&input=%5B1%2C2%2C3%2C4%2C5%2C4%2C3%2C2%2C1%2C2%2C3%2C4%2C3%2C2%2C1%5D%0A&debug=0)
### Explanation
```
.esm@Q+dkSb
.e         Q   For each index k and value b in (implicit) input...
         Sb    ... get the list [1, ..., b]...
   m  +dk      ... add k to each...
    @Q         ... and index into the input...
  s            ... then take the sum.
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 12 bytes
```
ＩＥθΣＥι§θ⊕⁺κλ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzexQKNQRyG4NBfMzNRRcCzxzEtJrQCJeuYlF6XmpuaVpKZoBOSUFmtk6yjkaEKB9f//0dHmOhY6ZjqmOiY6xjpGOoY6prGx/3XLcgA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  θ             Input array
 Ｅ              Map over elements
     ι          Current element
    Ｅ           Map over implicit range
           λ    Inner index
          κ     Outer index
         ⁺      Sum
        ⊕       Increment
       θ        Input array
      §         Cyclically index
   Σ            Sum
Ｉ               Cast to string
                Implicitly print on separate lines
```
[Answer]
# JavaScript ES6, 65 bytes
```
a=>a.map((x,y)=>{for(s=0,i=y;i<y+x;)s+=a[++i%a.length];return s})
```
Straightforward solution. Ungolfed:
```
a => a.map((x,y) => {
    var s = 0;
    for (i = y; i < y + x; i++) {
        s += a[i % a.length];
    }
    return s;
});
```
JavaScript's `map()` function is perfect for the job, it runs the given callback against each element and replaced it by the result of the callback. The callback receives two parameters, the first `x` is the value and the second `y` is the index. By taking the modulus `i % a.length` we can easily loop over the array, multiple times if needed.
### Test snippet
(Put the input as JSON notation)
```
let f = a=>a.map((x,y)=>{for(s=0,i=y;i<y+x;)s+=a[++i%a.length];return s})
```
```
<input id=I type="text" size=70 value="[4,3,2,1]"><button onclick="console.log(f(JSON.parse(I.value)))">Run</button>
```
[Answer]
# Java 8, 87 bytes
A curried void lambda taking an `int[]` list and `int` length.
```
l->s->{for(int i=-1,j,t;++i<s;System.out.println(t))for(j=t=0;j++<l[i];)t+=l[(i+j)%s];}
```
[Try It Online](https://tio.run/##rVJLa@MwED7Hv0KXgowdsUmbkx@wLCwUGnahx5CDKstBriIZaZwlBP/2rCzbrdsmFEpPFjPffI/xVPRA57rmqiqez3XzJAVDTFJr0ZoKhU7BbChaoOA@pVBUospNkQaEJGWjGAityO/hkQoFm218CfJLK9vsuUnvFfAdN3mOSpQFZznP7Tw/ldpgN4xENl/EVQxJFInUJo9HC3xPdAOkNq4vFYYw7MBVBtmPpIqiVG7ENgkhyuQGi6gKb@w2ac/BLAmcf6OBM@DFGKGP19N2Aa8h1po9/@0UH8Fw2kMn2NeAD8JC@uepcvUcGc64OLh@hhT/N0H9NIYePTTHYWdsNq72oEWBxmw9D9Jhrzcb@QgtCqzdoKu10@krPpjk1OCR5apZcD5HieSN4GcBeiw0RnU0g6/B26Wbeb9O90MHiXcdT97RvGXxW9q7o8QOJtRus0XU7GyfsCS0ruURd3T@ANHpLka3MVrGaNGGhDLGa8B33rePJKnakQu3NSkNK/QzlwVeNJavGqvv1Fh49luvtJroTesfUi6@bKEN2uD8Hw). Note that I've shadowed `System.out` in this program in order to grab results for prettier printing.
[Answer]
# [Julia 0.6](http://julialang.org/), 63 55 53 bytes
```
A->[sum(repmat(A,v+1)[i+1:i+v])for(i,v)=enumerate(A)]
```
[Try it online!](https://tio.run/##HYjLCsMgEAB/pcdd3BzU9EEhAb9DPCzBgiXaYNTft7aHGZh51z3wrW9LN9Nqzxoh@yNyAUNNSLRByGcQzeHrkyFQw8WnGn3m4sGg65EP4Gk9ckhlT7ABI9IFrCTlyCqSw5I03Un/@kGK5oH@M9N1bMT@BQ "Julia 0.6 – Try It Online")
---
Older solution:
# [Julia 0.6](http://julialang.org/), 65 bytes
```
A->(l=length(A);[sum(A[mod1(j,l)]for j∈i+1:i+A[i])for i∈1:l])
```
[Try it online!](https://tio.run/##LYpLCoQwEESv4rIb20Wb@eGgkHOELILzS0iiOHoHzzkXySTgoop6j3Kbt@aSxj7JZgDf@2d8rx@QeFffLYBUYXowOPKoX9NSud@@25o7W0tlNRZls@LOa0zBzGCaYV5sXH2EEQwiVaCYWhI5TKypUO722IKuJArf8uF0HEVe56wR0x8 "Julia 0.6 – Try It Online")
---
Another solution. Not great by bytecount, but I like it, and it's probably more efficient than the other two, especially if the input has big numbers. 
# [Julia 0.6](http://julialang.org/), 69 bytes
```
A->(l=length(A);[sum([A;A][i+1:i+A[i]%l])+A[i]÷l*sum(A)for i∈1:l])
```
[Try it online!](https://tio.run/##yyrNyUw0@59s@99R104jxzYnNS@9JEPDUdM6urg0VyPa0doxNjpT29AqU9sxOjNWNSdWE8w4vD1HC6TAUTMtv0gh81FHh6EVUO5/bmKBRqKuXUFRZl5JTp5GskaipqaOgka0oY6RjjEQG@oYxuqAeEDSCMo21jHXMQbxLYAKTKAKjYEsU6CwpuZ/AA "Julia 0.6 – Try It Online")
[Answer]
# [Canvas](https://github.com/dzaima/Canvas), 10 [bytes](https://github.com/dzaima/Canvas/blob/master/files/chartable.md)
```
²Ｘ｛ｘ＋⁸＠］∑］
```
[Try it here!](https://dzaima.github.io/Canvas/?u=JUIyJXVGRjM4JXVGRjVCJXVGRjU4JXVGRjBCJXUyMDc4JXVGRjIwJXVGRjNEJXUyMjExJXVGRjNE,i=JTVCNCUyQzQlMkMzJTJDMiUyQzIlNUQ_,v=3)
Explanation:
```
{         ] map over the items in the input
 ²X           save this loops counter on X (because of a bad design choice..)
   {    ]     map over 1..current item
    x+          add to it X
      ⁸@        and index in the input using that
         ∑    sum the map
```
[Answer]
# [QBasic 1.1](http://www.qbasic.net/), 115 bytes
```
INPUT L
DIM A(L)
FOR I=0TO L-1
INPUT C
A(I)=C
NEXT
FOR I=0TO L-1
S=0
FOR C=I+1TO I+A(I)
S=S+A(C MOD L)
NEXT
?S
NEXT
```
First input is the length **L**, then **L** subsequent inputs are the elements in order. **L** outputs represent the resulting array, with the elements in the order they're presented.
[Answer]
# Japt, 7 bytes
```
ËÆg°EÃx
```
[Try it here](https://ethproductions.github.io/japt/?v=1.4.5&code=y8ZnsEXDeA==&input=WzMsMiwxLDld)
[Answer]
# JavaScript, 46 bytes
```
a=>a.map(g=(x,y)=>x--&&a[++y%a.length]+g(x,y))
```
[Try it online](https://tio.run/##HclLCoAgFADA0ySGH6hWLfQi4uJhaoWpZISd3qLZzg43FHNu@WIxLbY50UBI4Adk7AWu9OmFrIwhBIqQpwMebPTXqon/s28mxZKC5SF57LCa6EgHOutvXg)
[Answer]
# APL+WIN, 37 bytes
Prompts for input:
```
+/¨v↑¨⊂[2](⍳⍴v)⌽((⍴v),⍴n)⍴n←(+/v)⍴v←⎕
```
[Try it online! Courtesy of Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcjzra0/5r6x9aUfaobeKhFY@6mqKNYjUe9W5@1LulTPNRz14NDTBLB0jmaYIIoDYNbf0yEBuoZwLQqP9AQ/6ncRlZKBgpmACxMRibKJgqGHOlcRnCeSZgGRgfzAYA "APL (Dyalog Classic) – Try It Online")
Explanation:
```
n←(+/v)⍴v←⎕ prompts for input and creates a repeating vector of length max v
((⍴v),⍴n)⍴n converts n to a matrix of length v x length n
(⍳⍴v)⌽ rotates each row of n by the size of each element of v
⊂[2] converts each row of m to an element in a nested vector
+/¨v↑¨ selects the number of elements from each element of the nested vector according to v and sums
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 38 bytes
```
->a{w=0;a.map{|x|(a*-~x)[w+=1,x].sum}}
```
[Try it online!](https://tio.run/##VY7NDsIgEITvPgVHf7aNUKo1Bl@EcMBDT23S2DTFAL46ll05eJuZfDO7r@X5Tr1K1cP6VZ3vth7t5IMLe3usPu6g15Pi4Ew9L2OMSWsJDQjgBnYaBdyy5Fsqoc1SAiGCkPaf/9UpuEIHl40oIfZFh5jADFehoRPFFpw8zZv8N/NhCGxivR5MTF8 "Ruby – Try It Online")
[Answer]
# **JavaScript, 65 bytes 3̶0̶0̶ ̶b̶y̶t̶e̶s̶**
golfed
```
n=>n.map((z,x)=>{for(s=0,i=x;i<z+x;)s+=n[++i%n.length];return s})
```
ungolfed
```
     f = n=>n.map((z,x)=>{
            for(s=0,i=x;i<z+x;)s+=n[++i%n.length];
            return s
            }
        );
console.log(f(process.argv[2].slice(1, -1).split(", ").map(x=>+x)))
```
[Try it online!](https://tio.run/##Hc3RCsIgFADQX5Eg8KKTbU/Bcj8y9iDLLcOu4rUhi77dovcD52F2Q0tyMTcYbrauuqIeUT1N5PyQBfT4XkPipFvpdBnc9RBlABIaJyHcGZW3uOX7PCSbXwkZfaAuASl4q3zY@MpjCoslUiZt@9TPirxbLO8kazpQFL3L/CTZCf5n0aMoAFDr1EvWSvZzl/kL "JavaScript (Node.js) – Try It Online")
(ungolfed version above)
I'm new to this codegolf thing!
---
\*updated! thanks to the useful links provided in comments, I managed to reduce the size to 65 bytes!
[Answer]
## [Perl 5](https://www.perl.org/) with `-M5.010`, 42 bytes
```
say sum+((@F,@F)x$_)[++$-..($-+$_-1)]for@F
```
[Try it online!](https://tio.run/##TY/BbsIwEETv@QqL@pDI65CEuKWgSjnlBEdOCKEgbSWraYLsrYCfr7s1ROKyO7PzPJLP6HoTpP4o1uJFOPRI4nN0gtCT8D@WMPjuxupbpWnTQtNmV3nM9kpJneep1EoedZkd@E3ThjWzs9l/E17JdaK3A4qTw@5LnJAuiEMs9qGGBVRQJnHCe1Kyr8EkNdyTihPzxDx4dm@whFfOpotJqmUEqniINbDgwklP4N1H/TueyY6DD3ro2jnMg96avCgL3hvrabXake1Vyp/O/gA "Perl 5 – Try It Online")
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-rn`, 14 bytes
```
$+g@(_+\,B)MEg
```
Takes input numbers on successive lines of stdin; gives output numbers on successive lines of stdout. [Try it online!](https://tio.run/##K8gs@P9fRTvdQSNeO0bHSdPXNf3/f0MuYy4TLtP/ukV5AA "Pip – Try It Online")
### Explanation
```
             g  List of lines of stdin (from -r flag)
           ME   Enumerate and map this function to the (index, value) pairs:
       \,B       One-based range(value)
     _+          To each element, add the index of that value
  g@(     )      Use the resulting range to slice into the original list g
                 (cyclical indexing is built in)
$+               Sum the numbers in the slice
                Output the list of results one per line (from -n flag)
```
Or, using a worked example:
```
             g  [1 3 4 5]
           ME   
       \,B      [(1,2) (1,4) (1,5) (1,6)]
     _+         [(1,2) (2,5) (3,7) (4,9)]
  g@(     )     [[3] [4 5 1] [5 1 3 4] [1 3 4 5 1]]
$+              [3 10 13 14]
```
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 12 bytes
```
+/¨⊢⍴¨⍳∘≢⌽¨⊂
```
[Try it online!](https://tio.run/##fZDNSsNAFIX38xR3l0Updv6ciW8TKpFgINJ2U6SbImKtETeCW7tyr24ENz7KfZF4ZqYRlMYQJpOZ755z7i0u6vHpsqibs/G0Lubzatrx/WPV8PWD7Eqso6OvF77dcfuGb/vKN0@82fHdZzhdd90CyCW377x5nmFbcvtxkjXnGW@vsrKo6gwHuJ6thCFNiiQdfhYkJ@TIkhEJy4dBFdictBYSmgZFQ6gOpMRqYJ8CqCFVGV5Px@SRwP4TNkaVBiQUY9q@NXmAzdGVAxHutXDRwf5U2D@0Cm2Rgr7t4yDKRCgfbVQsSz3rX4m0A4pcNhpiRNqThpjBjPqK3jT9pz0sAx9GFKr8vnMXZWLqbw "APL (Dyalog Classic) – Try It Online")
uses `⎕io←1`
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~50~~ 32 bytes
```
{$_>>.&{.[++$+ ^$^a X%+$_].sum}}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WiXezk5PrVovWltbRVshTiUuUSFCVVslPlavuDS3tva/dXEiSKlGtImOsY6RjmGspjUXTAgsoGOJLGQIVGWiY4osZKID0WqEqtUUu3lQa1AlzHUsdMyAOmCSKOYbWYC1GYHlwLbrGKM6CSYM0w7hw6z/DwA "Perl 6 – Try It Online")
~~I'm new to golfing in Perl 6, so I'm sure this can be shorter.~~ Not new anymore, and back to golf this!
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 6 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
ıRṅ+iS
```
[Try it online!](https://Not-Thonnu.github.io/run#aGVhZGVyPSZjb2RlPSVDNCVCMVIlRTElQjklODUlMkJpUyZmb290ZXI9JmlucHV0PSU1QjQlMkMzJTJDMiUyQzElNUQlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAtJTNFJTIwJTVCMTAlMkM3JTJDNSUyQzQlNUQlMEElNUIzJTJDMiUyQzElMkM5JTVEJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwLSUzRSUyMCU1QjEyJTJDMTAlMkM5JTJDMzMlNUQlMEElNUIxJTJDMyUyQzQlMkM1JTVEJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwLSUzRSUyMCU1QjMlMkMxMCUyQzEzJTJDMTQlNUQlMEElNUI0JTJDNCUyQzMlMkMyJTJDMiU1RCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMC0lM0UlMjAlNUIxMSUyQzExJTJDOCUyQzYlMkM4JTVEJTBBJTVCMyUyQzUlMkMzJTJDMiUyQzElNUQlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAtJTNFJTIwJTVCMTAlMkMxNCUyQzYlMkM0JTJDMyU1RCUwQSU1QjMlMkMyJTJDNCUyQzMlMkMyJTJDMSUyQzElNUQlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAtJTNFJTIwJTVCOSUyQzclMkM3JTJDNCUyQzIlMkMxJTJDMyU1RCUwQSU1QjclMkM4JTJDNiUyQzUlMkM0JTJDMyUyQzIlMkMxJTJDNSU1RCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMC0lM0UlMjAlNUIyOSUyQzMzJTJDMjAlMkMxNSUyQzExJTJDOCUyQzYlMkM1JTJDMzAlNUQlMEElNUIyOCUyQzIlMkM0JTJDMiUyQzMlMkMyJTJDMyUyQzQlMkM1JTJDMyU1RCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMC0lM0UlMjAlNUIxMzclMkM2JTJDMTAlMkM1JTJDOSUyQzclMkMxMiUyQzM4JTJDMzklMkMzNCU1RCUwQSU1QjElMkMyJTJDMyUyQzQlMkM1JTJDNCUyQzMlMkMyJTJDMSUyQzIlMkMzJTJDNCUyQzMlMkMyJTJDMSU1RCUyMC0lM0UlMjAlNUIyJTJDNyUyQzEzJTJDMTQlMkMxMiUyQzglMkM1JTJDMyUyQzIlMkM3JTJDOSUyQzclMkM0JTJDMiUyQzElNUQmZmxhZ3M9Qw==)
#### Explanation
```
ıRṅ+iS  # Implicit input
ı       # Map over the input:
 R      #  [1..item]
  ṅ+    #  Plus 0-based index
    i   #  Index into input
     S  #  Sum the list
        # Implicit output
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 10 bytes
```
ėƛ÷$?$›ǓẎ∑
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyJ+UCIsIiIsIsSXxpvDtyQ/JOKAuseT4bqO4oiRIiwiIiwiWzQsMywyLDFdICAgICAgICAgICAgICAgICAgICAgICAtPiBbMTAsNyw1LDRdXG5bMywyLDEsOV0gICAgICAgICAgICAgICAgICAgICAgIC0+IFsxMiwxMCw5LDMzXVxuWzEsMyw0LDVdICAgICAgICAgICAgICAgICAgICAgICAtPiBbMywxMCwxMywxNF1cbls0LDQsMywyLDJdICAgICAgICAgICAgICAgICAgICAgLT4gWzExLDExLDgsNiw4XVxuWzMsNSwzLDIsMV0gICAgICAgICAgICAgICAgICAgICAtPiBbMTAsMTQsNiw0LDNdXG5bMywyLDQsMywyLDEsMV0gICAgICAgICAgICAgICAgIC0+IFs5LDcsNyw0LDIsMSwzXVxuWzcsOCw2LDUsNCwzLDIsMSw1XSAgICAgICAgICAgICAtPiBbMjksMzMsMjAsMTUsMTEsOCw2LDUsMzBdXG5bMjgsMiw0LDIsMywyLDMsNCw1LDNdICAgICAgICAgIC0+IFsxMzcsNiwxMCw1LDksNywxMiwzOCwzOSwzNF1cblsxLDIsMyw0LDUsNCwzLDIsMSwyLDMsNCwzLDIsMV0gLT4gWzIsNywxMywxNCwxMiw4LDUsMywyLDcsOSw3LDQsMiwxXSJd)
#### Explanation
```
ėƛ÷$?$›ǓẎ∑  # Implicit input
ėƛ          # Enumerate (index, item) and map over:
  ÷$        #  Dump onto stack and swap
    ?$›Ǔ    #  Rotate input left by (index + 1)
        Ẏ∑  #  Take the first (item) elements and sum
            # Implicit output
```
]