[Question]
  [
Part of [**Code Golf Advent Calendar 2022**](https://codegolf.meta.stackexchange.com/questions/25251/announcing-code-golf-advent-calendar-2022-event-challenge-sandbox) event. See the linked meta post for details.
---
Fen is a magician Elf. He can cast spells on an array of numbers to produce another number or array of numbers.
One of his inventions is the Wick spell. He loves to use this spell because "once this spell is applied, [a combination of `prefix sum` spells and `change number` spells becomes magically cheaper](https://codegolf.stackexchange.com/q/225634/78410)".
## Task
Implement Fen's Wick spell.
* Given an array of positive integers `A` of length `n`,
* Replace each item at 1-based index `i` with the sum of last `j` elements, where `j == 2 ** (trailing zeros of i in binary)`.
For example, if the given array is `A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]`,
```
Wick(A) = [
    1,      # 1
    3,      # 1+2
    3,      #     3
    10,     # 1+2+3+4
    5,      #         5
    11,     #         5+6
    7,      #             7
    36,     # 1+2+3+4+5+6+7+8
    9,      #                 9
    10,     #                 9+1
]
```
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply. The shortest code in bytes wins.
## Test cases
```
[] -> []
[999] -> [999]
[3,1,4] -> [3,4,4]
[3,1,4,1,5,9,2,6] -> [3,4,4,9,5,14,2,31]
```
  
[Answer]
# [Python 3.8](https://docs.python.org/3.8/), 45 bytes
```
lambda l,i=0:[sum(l[i&(i:=i+1):i])for _ in l]
```
[Try it online!](https://tio.run/##NcVBDsIgEEDRPaeYlYE4C7FqhISTIDEYSzrJlBKkGk@P3bj475dvm5Y8XEvtyd06x/nxjMBI7mD9a50le9pJso72WlkKKi0V7kAZOPTPRDyCtgLYje/IknJZm1RKQKmUm0ySleo@CG@M2RxQ4@n/rTMaPOIl/AA "Python 3.8 (pre-release) – Try It Online")
The start index for the sum at one-indexed position `i` is `i&i-1`, which is obtained from the binary representation of `i` by setting the rightmost 1 bit to 0.
[Answer]
# [Python](https://www.python.org) NumPy, 42 bytes
```
def f(a):b=a[1::2];b+=a[:-1:2];b@b>0!=f(b)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY47DsIwEETr-BRL58AmIvyEjYK4R5RiDVikiG0Zp_BZaNLAnbgNBpFiZ14zevt4uRhu1ozjcwi62L_nl6sGzSmXqqamknLVHtQioSyqH5_UcTmrNVf5f2G73lkfwAy9i0B3MI4xbT0QdAaaFhshRMo1VriZOt0WBa5w10qWEdRpVZL3FJOaZcldnq2LPPFXxTLnOxM44aSdHv4A)
### [Python](https://www.python.org) NumPy, 44 bytes
```
def f(a):a[1::2]+=a[:-1:2];a@a>0!=f(a[1::2])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NU5LDoIwFFzTUzx3JT6I4Ce2psZ7NCweaiML2qbComdxw0bv5G1sIizmk0wmM6-Pj8PD2Wl6j4Mpjl-83Q0YTrkkXUlZN2tFWhZVcie60HmzUin9R_nccV3vXRjAjr2PQE-wnjHjAhB0FnSDWgiReIsV7hZN2KPAGg-NZBmBSq2SQqCYxlnWKiqvzkeevOFtYh86O3DCdp5dLv8A)
Takes a NumPy array and modifies it in-place.
### How?
Simple recursion best explained by example:
```
a1
   a2
      a3
         a4
            a5
               a6
                  a7
                     a8
                        a9
    ==>
a1
a1+a2
      a3
      a3+a4
            a5
            a5+a6
                  a7
                  a7+a8
                        a9
   ==>
a1
a1+a2
      a3
a1+a2+a3+a4
            a5
            a5+a6
                  a7
            a5+a6+a7+a8
                        a9
   ==>
a1
a1+a2
      a3
a1+a2+a3+a4
            a5
            a5+a6
                  a7
a1+a2+a3+a4+a5+a6+a7+a8
                        a9
```
[Answer]
# [Rust](https://www.rust-lang.org), 64 bytes
```
|x:&[_]|(0..x.len()).map(|i|x[i&i+1..=i].iter().sum()).collect()
```
[Attempt This Online!](https://ato.pxeger.com/run?1=LcxPCoJAHIbhvaeYXMgM_RrS_plmdYhoIyIiIwyMJjoDkuNJ2rioC3SbblNqq48PHt7Hs1K17N9ZgfKEF5igVjCJMhS8lMwW7uesG88K40jjJaUNFexnCM2TEmuum5BbfG5TGvCIcskqTGit8kGkNyFYKjH5dy6-MYRj78rSg6r5nR1RgDJshfb4wImIbxhlxQspihk2W-_UmTACcGAFa9jAFnbgwh7siAy4m9p9P-0X)
Uses XNOR's trick. Also uses blatant abuse of type annotations outside the code.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 12 bytes
```
ＩＥθΣ✂θ＆κ⊕κ⊕κ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzexQKNQRyG4NFcjOCczORXEccosKc8sTnXMS9HI1lHwzEsuSs1NzStJBXI1NTEEQMD6///oaGMdQx0TIDbVsdQx0jGLjf2vW5YDAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  θ             Input array
 Ｅ              Map over elements
     θ          Input array
    ✂           Sliced from
       κ        Current index
      ＆         Bitwise And
         κ      Current index
        ⊕       Incremented
           κ    To current index
          ⊕     Incremented
   Σ            Take the sum
Ｉ               Cast to string
                Implicitly print
```
Due to Charcoal being 0-indexed, the length of the slice is `(k+1&-(k+1))` and the start position is therefore `k+1-(k+1&-(k+1))`. However `-(k+1)` is the same as `~k` so that simplifies to `k+1-(k+1&~k)`. Writing `k+1` as `(k+1&k)|(k+1&~k)` (which have no bits in common) we see that the `k+1&~k`s cancel, leaving `k+1&k`, at which point this degenerates into a port of @xnor's Python answer.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), ~~13~~ 7 bytes
```
ẏD›⋏ṡİṠ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLhuo9E4oC64ouP4bmhxLDhuaAiLCIiLCJbMywxLDQsMSw1LDksMiw2XSJd)
Half porting python. TIL `ṡ` vectorises zip-wise between two lists.
## Explained
```
ẏD›⋏ṡİṠ
ẏ       # The range [0, len(input))
 D      # pushed three times to the stack
  ›     # increment the top copy
   ⋏    # and get the bitwise-and of each pair of n and n-1 in each list
# At this point the stack is: [[0, 1, 2, ..., len(input) - 1], [1 bitand 0, 2 bitand 3, 3 bitand 4, ..., len(input) bitand len(input - 1)]
    ṡ   # create the range [x, y] for each x and y pair in the top two stack items: [[0], [1, 0], [2], [3, 2, 1, 0], ...]
     İ  # get the nth item in the input at each atomic index in the above list: [[input[0]], [input[1], input[0]], ...]
      Ṡ # sum each sublist and implicitly print
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-p`, ~~34~~ ~~27~~ ~~22~~ 18 bytes
```
$+g@(_BA_+1\,_)MEg
```
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCIkK2dAKF9CQV8rMVxcLF8pTUVnIiwiIiwiMyAxIDQgMSA1IDkgMiA2IiwiLXAiXQ==)
Port of @xnor's answer. Started with a port of my own python answer, but @xnor's was much shorter
~~-7~~ -12 bytes thanks to @AidenChow and @DLosc  
-4 bytes thanks to @DLosc
[Answer]
# [Python](https://www.python.org), 82 bytes
```
lambda A:[sum(A[i-2**len(bin(i)[2:].split("1")[-1]):i])for i in range(1,len(A)+1)]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=ZY9BTsMwEEX3OYXVlV0mqJOkoYmURa7A1ljIpQlYct0odoXgKmwiIbgTF-AcjEmABbJGMx7_eZ7_8j48hYeTm1775ubtHPp093Ft9XF_0KytpT8feStNmq3XtnN8bxw3Qma1uvSDNYGvcCVkikrURon-NDLDjGOjdvcdR4gjrbhAoRbyZ-h8uL3TvvONTCRCBjkUsIUSrmAHFaCCRMaoqiqmHBCK34JiS6IMSmqpJNHOP3bjgsrp4IYEiATLy0jb_MMVPzgqSEHqIi6B38BhNC5wbS2XPY-riqaZ_2DRW-zAcieXz2bgf36WBy-UELPbaZrzFw)
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 41 bytes
```
a->a*matrix(#a,,j,i,i-j<gcd(i,2^i)&&j<=i)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PY1dCsIwEISvEiqURCYPbe1PoO1FStVFadmgEkoFPYsvBRHP5G1MsfiwM9_OMuzj7WjgXe-mZyeq13XsdPFRpGtan2kc-CZXBFgwWNuyPxwlI96yCkNbVqyWwp6cO90lCV0LN_Bl9BjMSyA6SUpBNE3rxRgzW4IImz_4SWEQI5ujyEPiwxQZchT-ELXt8meafv4F)
---
# [PARI/GP](https://pari.math.u-bordeaux.fr), 42 bytes
```
a->a*matrix(#a,,j,i,j>bitand(i,i-1)&&j<=i)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PY1hCoJAEIWvshjIrrz9sZnmQnoRkZoIY8RkkQ3qLP0RIjpTt2kl6ce8980bHvN4Oxp5f3bTsxXl6-pbXXwS0hUlF_Ij3-SKgA6Mrjqyp-EkGayNiuNuV7JaGgdyrr9LEroSbuTBB4zmJRKtJKUg6roJYq2dLYXB5g9hMliskc-RCZCGMEOOLYpwME2z_Jmmn38B)
A port of [@xnor's Python answer](https://codegolf.stackexchange.com/a/255276/9288).
[Answer]
# JavaScript (ES6), 48 bytes
Isolates the least significant non-zero bit of the 1-based index and uses it as a counter to recursively add previous values to the current one.
```
a=>a.map((_,i)=>(g=j=>j&&a[--i]+g(j-1))(++i&-i))
```
[Try it online!](https://tio.run/##bcpBCoMwEIXhfU@RlczgREnVQhbJRSSUwaokWCO19Ppp6EraPnibny/wi/fh4benXONtTJNJbCxXd94AruTRWJhNMDYUBfdSelfOEKRChLL0hfSIaYjrHpexWuIME/RaaycOQxR1LT759EUbUtS6H9pQm/NfnN@RpjNd3BHn1JFqc2@US28 "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), 47 bytes
Porting [xnor's approach](https://codegolf.stackexchange.com/a/255276/58563) is 1 byte shorter.
```
a=>a.map((_,i)=>eval(a.slice(i&++i,i).join`+`))
```
[Try it online!](https://tio.run/##bcpBCsIwEIXhvafISiZkTKlphSzai0iwQ0wlJU2KlV4/BldFffA2H/9EG6326ZfXKaa7y2OXqetJzrQA3NDzrncbBSC5Bm8d@KMQvrCcko@DGDjPNsU1BSdDesAIV621YbtxzqqKffjwlSqssTE/qcKm8N@4vEWNZ7yYfVyoxboprmqT3w "JavaScript (Node.js) – Try It Online")
[Answer]
# Excel (ms365), 119 bytes
[![enter image description here](https://i.stack.imgur.com/RRWAe.png)](https://i.stack.imgur.com/RRWAe.png)
Formula in `B1`:
```
=IFERROR(MAP(SEQUENCE(COUNT(A:A)),LAMBDA(z,SUM(OFFSET(A1,z-1,,-BIN2DEC(TEXTAFTER(0&BASE(z,2),1,-2,,,BASE(z,2))))))),"")
```
I've no doubt this can be further shortened.
[Answer]
# [Desmos](https://desmos.com/calculator), 95 bytes
```
f(l)=[l[i-2^{[0...i][mod(floor(i/2^{[0...i]}),2)=1].min}+1...i].totalfori=[0...l.length][2...]]
```
[Try It On Desmos!](https://www.desmos.com/calculator/da5t11smix)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/04vd8aqoaw)
Desmos doesn't have any binary functionalities like converting to binary or bitwise anding, so basically around half the code is dedicated to converting to binary and finding the number of trailing zeroes.
Also, in case you were wondering, I can't simply do `[1...l.length]` instead of `[0...l.length][2...]` because `f([])` (empty list input) gives an error for `[1...l.length]`: "Ranges must be arithmetic sequences."
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 7.5 bytes (15 nibbles)
```
.,,$+>`&-$~$<$@
```
```
.,,$+>`&-$~$<$@
.                   # map over each i in
 ,                  # range from 1..
  ,                 # length of 
   $                # input,
    +               #   get the sum of:
     >              #     drop the first j elements, where j is
      `&            #       bitwise AND of
        -$~         #         i-1 and
           $        #         i, 
            <$      #     from the first i elements of
              @     #     input     
```
[![enter image description here](https://i.stack.imgur.com/lvVhX.png)](https://i.stack.imgur.com/lvVhX.png)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~9~~ 8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
āεN&NŸèO
```
[Try it online](https://tio.run/##yy9OTMpM/f//SOO5rX5qfkd3HF7h//9/tKGOkY6xjomOqY6ZjrmOhY6ljmEsAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeWhlf@PNJ7b6qfmd3THoXXFh1f4/6/V@R8dbahjpGOsY6JjqmOmY65joWOpYxirEw1ElpaWQNJYx1DHBEYDsSlQgZGOWWwsAA).
**Explanation:**
```
ā         # Push a list in the range [1, (implicit) input-length]
 ε        # Map over each of these 1-based indices `y`:
  N       #  Push the 0-based map index `N`
   &      #  Bitwise-AND the 1-based index `y` and 0-based index `N` together
    NŸ    #  Pop and push a list in the range [y&N,N]
      è   #  Index each into the (implicit) input-list
       O  #  Sum this list together
          # (after which the list is output implicitly as result)
```
[Answer]
# [C (clang)](http://clang.llvm.org/), 49 bytes
```
i;f(*a,n){for(;n;)for(i=n&--n;i<n;)a[n]+=a[i++];}
```
[Try it online!](https://tio.run/##rVTbjpswEH3frxghZcXFaEOAtNRL@1D1KxIeEDFb1K0TLlWjRvx66WBjbG/60IdGhLHnzMw5MwaqsHot@cs0NbR2/ZJw71afO5dy6s22yfljGHLaPKOjPPAiyMtDEwQFHaeGD/C9bLjrwe0B8Dc7BtYP0aGAHG4RgR2BmEBCICWwJ/COwHsCGYFopGv0TkYbnlh6siwznIl0YjmsmxhAagHingoSJN@PdFXGrhdWDeyk1cXiirYiIYqEvngvBW4XBpVlq1TeO6UK0GoTrVaBqQUKvllAIucVGZrn/riM7ptf7Fy7Yr7e07Lz5ZaAge5sdGejsY3GNprYaGKjqY2mnlbqC6m9lCpEEXm40sTSJNKkZp4aikxdD4noyetlrJeJXqpy1Zn3A1Rfy87HO6u@sU4WdY7XL7vjNfuM/9QhYO5jZ8nGpx3ceeYNP7Erpm3psnxWM1CEHjwpl7/6KASBiFdvg54MFpPTEXhBTRj4gvI79NIhXrvOzfG0c5XZSoktyuMzd2vymumbfnPCplv4BHPv8AEctMOhLYyy4x3rCOFHsKndAT8P1G6OoYz1CP/W36Xse4yJ/qmFNeZNK3ONx1yIhhwJ0dL/2@ymP3KMVM/NzKhSZHjHhh8dR70P4/S7ql/Ll34Kf/4B "C (clang) – Try It Online")
*Uses [xnor](https://codegolf.stackexchange.com/users/20260/xnor)'s idea from his [Python answer](https://codegolf.stackexchange.com/a/255276/9481)*
Inputs a pointer to an array of integers and its length (because pointers in C carry no length info).  
Returns the Fen Wicked array through the input pointer.
[Answer]
# [Python](https://www.python.org), ~~84~~ ~~83~~ 77 bytes
There's probably room for improvement here. Takes both the array and the length of the array, and returns a map.
```
lambda a,n:[sum(a[u-2**len(bin(u+1).split("1")[-1])+1:u+1])for u in range(n)]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY5NCsIwEIWvEoqLmToRUn-oBe8hhCxSbDWQjiFNFp7FTTd6J29jF-3iLR7f4-O9v-GVHk-epk9Ovax_115chLdDe7PCEjeDDbDU3Ix5AKuzhKosfcfQOoa8VbiLY_AuQaEK1FIZlAqbGRikaPneASMu_k2IjhN4NyboQe9J0WHOkc5U0cmQqHHdrp_-)
[Answer]
# Java 8, 89 bytes
```
a->{int l=a.length,r[]=new int[l],i;for(;l-->0;)for(i=l&l+1;i<=l;)r[l]+=a[i++];return r;}
```
[Try it online.](https://tio.run/##dVDLbsIwELzzFSsOVaw4VlMKbXCDVPVcLhwjH7bBUFPjIMehQlG@Pd3wEKcevLMejWZGu8MjJrv1T19arGv4ROPaEYBxQfsNlhqWw/dMFArK6ILIJLHdiEYdMJgSluAg7zFZtKQAm6Ow2m3DN/eFyp3@PRtYxY3cVD6SNkkWj5INu8ntg41Tad5yK5knUZxjYeJYSa9D4x142fVyyDo0X5ayrpHHyqxhT4WjVfDGbQuF7FJ2sD2ih6Dr8IG1hjncKqhCtW3H2yzLaE54yp9vSG/KM/7EZ8SkhBPipnzGX/gr8WnXsbM7wOpUB70XVRPEgZKDddGO7iiaYKx49x5PtQjVpVV0K8Hi8RzG8f9CJ8q7mF0v3PV/)
**Explanation:**
```
a->{                  // Method with integer-array as both parameter and return-type
  int l=a.length,     //  Length of the input-array
      r[]=new int[l], //  Result-array, starting with this length amount of 0s
      i;              //  Index-integer, uninitialized
  for(;l-->0;)        //  Loop `l` in the range (length,0]:
    for(i=l&l+1;      //   Set `i` to `l` bitwise-AND-ed by `l+1`
        i<=l;)        //   Inner loop `i` in the range [i&i+1,l]:
      r[l]+=          //    Add to the `l`'th value of the result-array:
        a[i++];       //     The `i`'th value of the input-array
  return r;}          //  After the nested loop, return the resulting array
```
[Answer]
# [Factor](https://factorcode.org), 90 bytes
```
[ dup length [0,b) [ dup dup 1 + bitand swap 1 + rot [ <slice> ] keep swap sum ] map nip ]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=dY69TgMxEIT7e4ppERAR_u9AKWhQJAhFlAJOKTbO5rDi8xnbJxQhnoTmmvBOeRs28lUgipVnvh1r9ut7RSo2vtutZ9Px5L7Amr1lg8BvLVvFATXF14EnW4m2VHNwtMfOc4wb57WNMI0ik5Ig72kTcJONJwVURSqbPj_ePT0kc5WVhuO2javj691LiWXrYNhW8rE8OVocIKH9DHGIhY5klwjvlLxvoiRug9GKR5jLsezSNrS1-FqU1Q7zvkEXo772A_hMEnKrwUBInud_4ZkUnf-Hh7hAjlNc_g70hV2X3h8)
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 9 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
£sY°&YY x
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=o3NZsCZZWSB4&input=WzEsIDIsIDMsIDQsIDUsIDYsIDcsIDgsIDksIDFd)
[Answer]
# [Ruby](https://www.ruby-lang.org/), 35 bytes
Port of [xnor's approach](https://codegolf.stackexchange.com/a/255276/11261) via [Arnauld's](https://codegolf.stackexchange.com/a/255279/11261).
```
->a{i=0
a.map{eval a[i&i+=1,i]*?+}}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhY3lXXtEqszbQ24EvVyEwuqU8sScxQSozPVMrVtDXUyY7XstWtroUrNChTcoqNjY7nAtKWlJYxprGOoY4LCAWJTHUsdIx2z2FiI7gULIDQA)
[Answer]
# x86-64 machine code, 23 bytes
```
31 C9 8B 04 8F 89 CA FF C1 09 CA 39 F2 73 03 01 04 97 39 F1 72 EC C3
```
[Try it online!](https://tio.run/##TVLLbsIwEDzHX7FNheQkpqVAkRqaXnrupadKkIOxHXCVOMgGGor49abr8BAHex@zO7NrWfSXQrQtdxVQ@AwpKdKgqS0o0TB/EZsGVb0DxTGeWakhgXFsRZOTU16e6wJtxMnx3desqNbnyGkSfHMFjgRcyhsu2eTM8xOXnsrFtXwBlgRWbUgURlOyq7WEgmqzgZgz8NZg@h6Vy61U8Oo2UtcPqzdCPFZxbbpibpeCgVhxC3GMwS4iBz8vIrMcMjiM2BMb43lmL2zIJsfpCS0Rc/pX1QXl0ePZizlKBphhUHYertupaKweTNHcZVCiTZII1haRgoY9DSFDNZ37lkt2bubmg4uVNgpELVXql@yUG8/FYI@hrOFwaYDeYPiFRPuM0q1xemmU7PaKoyKaNUmC9Ef4WelSAd37QQbN@@hWEiiOsthvlIvmBpkaD@IDb63B4cmxbf9EUfKla/vVZIwXfowMW1X5Dw "C (gcc) – Try It Online")
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes the address of an array of 32-bit integers in RDI and its length in ESI, and modifies the array in place.
---
Go through each position in ascending order, and add its value to the value at the position that should immediately contain it, if that position exists within the array's bounds.
```
―――――――7
   ↑ ↑↑
―――3 ||
 ↑↑  ||
―1| ―5| ―9
↑ | ↑ | ↑
0 2 4 6 8
```
With 0-indexing, if the current position is `n`, the containing position is `n OR n+1`.
---
Assembly:
```
f:  xor ecx, ecx            # Set ECX to 0.
r:  mov eax, [rdi + 4*rcx]  # Load the value at index ECX into EAX.
    mov edx, ecx            # Set EDX to the value of ECX.
    inc ecx                 # Increase the value of ECX by 1.
    or edx, ecx             # Set EDX to its bitwise OR with ECX.
    cmp edx, esi            # Compare that value to the the length.
    jae s                   # Jump if it's greater than or equal to the length.
    add [rdi + 4*rdx], eax  # (If it's less) Add EAX to the value at index EDX.
s:  cmp ecx, esi            # Compare ECX to the length.
    jb r                    # Jump back, to repeat, if it's lesser.
    ret                     # Return.
```
[Answer]
# [Halfwit](https://github.com/chunkybanana/halfwit/), 38 bytes
```
>[<?(>M<+;M>M<N+JM>{<b(n};W;R*;(n};W>{<b:Nn+(:n+?i$;_WR+
```
[Try It Online!](https://dso.surge.sh/#@WyJoYWxmd2l0IiwiIiwiPls8Pyg+TTwrO00+TTxOK0pNPns8YihufTtXO1IqOyhufTtXPns8YjpObisoOm4rP2kkO19XUisiLCIiLCJbWzNuLDFuLDRuLDFuLDVuLDluLDJuLDZuXV0iLCIiXQ==)
Why did I create this language again? Doesn't help that several builtins that would've been useful for this are buggy or just unimplemented.
Uses xnor's trick.
```
== range generation ==
>[<?(>M<+; # Get the length of the input (oof)
>[<        # Push 0
   ?(    ; # Over every item of the input...
     >M<+  # Increment
== The binary bit ==
M>M<N+JM>{<b(n};W;R*;(n};W>{<b # For each index, calculate i & i-1
M                              # Over each integer from the previous...
 >M<N+                         # Decrement
      J                        # Pair with the decremented version
       M         ;             # Over each...
           b                   # Convert to base...     
        >{<                    # 2
            (  ;               # Over each binary digit
             n}                # Push it to the bottom of the stack
                W              # Get all elements of the stack i.e. the reversed binary representation
                  R*;          # Reduce by multiplication i.e. & for single bits
                     (n};W     # Reverse again (see above)
                          >{<b # Convert back from binary
== Index into input and sum ==   
:Nn+(:n+?i$;_WR+ # For each number from i&i-1 to i, get that index in the input, and sum
:Nn              # Make the stack [i&i-1,i&i-1,-(i&i-1), i]
   +             # i - (i&i-1)
    (      ;     # That many times...
     :           # Duplicate the i&i-1 kept on top of the stack.
      n+         # Add that to the current index
        ?i       # Index into the input
          $      # Push under the i&i-1
            _W   # Pop the i&i-1 and wrap the stack
              R+ # Sum
```
[Answer]
# [Ohm v2](https://github.com/nickbclifford/Ohm), 13 bytes
```
l@€^à^G€³s®;Σ
```
[Try it online!](https://tio.run/##y8/INfr/P8fhUdOauMML4tyB9KHNxYfWWZ9b/P9/tLGOoY4JEJvqWOoY6ZjFAgA "Ohm v2 – Try It Online")
Simple port of 05AB1E for the hats :p
## Explained
```
l@€^à^G€³s®;Σ
l@             # the range [1, len(input)]
  €----------  # to each number:
   ^à          #   bit-and with number - 1
     ^G        #   the range [number, ^]
       €---;   #   to each:
        ³s®    #     input[^]
            Σ  #   sum
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 45 bytes
```
a=>a.map((_,i)=>(g=j=>j&~i?0:a[j]+g(j-1))(i))
```
[Try it online!](https://tio.run/##bcpBCsIwEIXhvafISmZw2hqTChESD1KChNqWhNoUKy69egyuivrgbX6@4J5uae9@fhRTvHap18lp48qbmwEu5FEbGHTQJmxf/rw/uSbY3QCh4IjgEVMbpyWOXTnGAXpolFKWrYbIqop98uaLCuIk7Q8VJHP@i/NrUnSgo13jnGriMnfBbXoD "JavaScript (Node.js) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
J&’‘rƲị⁸§
```
A monadic Link that accepts a list of positive integers and yields another.
**[Try it online!](https://tio.run/##ATIAzf9qZWxsef//SibigJnigJhyxrLhu4vigbjCp////1sxLDIsMyw0LDUsNiw3LDgsOSwxXQ "Jelly – Try It Online")**
### How?
Much like many others, uses the same bitwise trick that [xnor used](https://codegolf.stackexchange.com/a/255276/53748).
```
J&’‘rƲị⁸§ - Link: list of positive integers, A
J         - range of length (A) -> [1..length(A)]
     Ʋ    - last four links as a monad - f(X=that):
  ’       -   decrement (X)
 &        -   (X) bitwise AND (that)
   ‘      -   increment (that)
    r     -   inclusive range -> [[startIndexForSum, endIndexForSum] for each element]
       ⁸  - chain's left argument -> A
      ị   - (ranges) index into (A)
        § - sums
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 11 bytes
```
.es:Q.&hkkh
```
[Try it online!](https://tio.run/##K6gsyfj/Xy@12CpQTy0jOxvIiTbWMdQxAWJTHUsdIx2zWAA "Pyth – Try It Online")
Uses [xnor's](https://codegolf.stackexchange.com/a/255276/58563) trick.
### Explanation
```
.es:Q.&hkkhkQ    # implicit k and Q added
                 # Q = eval(input()) implicitly
.e          Q    # enumerate k over the indices of Q
  s              # sum of
   :Q            # index Q from
     .&hkk       # k & (k+1)
          hk     # to k+1
```
]