[Question]
  [
[hgl](https://gitlab.com/WheatWizard/haskell-golfing-library/-/blob/master/src/P.hs) has a "scan" function called `sc`. What it does in general is a little bit abstract, so we will just talk about one specific way you can use it.
If we want to take a list of integers and get the partial sums of every prefix we can scan with `+` for sums and `0` as a starting value:
```
ghci> sc (+) 0 [1,2,3,4,5,6]
[1,3,6,10,15,21]
```
This moves left to right adding each value of the list to the accumulator and replacing it with the sum.
We can also scan things other than lists. We can scan all sorts of trees and list-like things. hgl more or less builds the scan function based on the type we give it.
One weirder example is ragged lists. These are lists that contain a mixture of values and other ragged lists. For example:
```
[1,2,3,[2,3,4],[],2,1,[4,8,[6],5],2]
```
The compiler has dreamed up a rather weird way to scan these. When the list contains values it behaves normally:
```
ghci> sc (+) 0 [1,2,3,[2,3,4],[],2,1,[4,8,[6],5],2]
[1,2,3,[2,3,4],[],2,1,[4,8,[6],5],2]
 ^1
[1,3,3,[2,3,4],[],2,1,[4,8,[6],5],2]
   ^3
[1,3,6,[2,3,4],[],2,1,[4,8,[6],5],2]
     ^6
```
but when it hits a list it splits the read head in two. One goes down that list and scans it, the other skips it and scans the rest of the outer list.
```
[1,3,6,[8,3,4],[],2,1,[4,8,[6],5],2]
       ^6
[1,3,6,[8,3,4],[],2,1,[4,8,[6],5],2]
        ^8     ^6
[1,3,6,[8,11,4],[],8,1,[4,8,[6],5],2]
          ^11      ^8
[1,3,6,[8,11,15],[],8,9,[4,8,[6],5],2]
             ^15      ^9
[1,3,6,[8,11,15],[],8,9,[4,8,[6],5],2]
                        ^9
[1,3,6,[8,11,15],[],8,9,[13,8,[6],5],11]
                         ^13         ^11
[1,3,6,[8,11,15],[],8,9,[13,21,[6],5],11]
                            ^21
[1,3,6,[8,11,15],[],8,9,[13,21,[6],5],11]
                               ^21
[1,3,6,[8,11,15],[],8,9,[13,21,[27],26],11]
                                ^27 ^26
[1,3,6,[8,11,15],[],8,9,[13,21,[27],26],11]
```
This treats a ragged list as a sort of tree, where the main list forms a spine and each nested list is an offshoot from that spine.
## Task
Take a ragged list of positive integers as input and perform the scan shown above (`sc (+) 0`) returning the scanned list.
You may take and output a ragged list in any reasonable format.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so answers will be scored in bytes with minimizing the source size being the goal.
## Test cases
```
[] -> []
[8] -> [8]
[1,2,3] -> [1,3,6]
[1,1,1,1,1] -> [1,2,3,4,5]
[[1],[1],[1]] -> [[1],[1],[1]]
[1,[1],[1],[1]] -> [1,[2],[2],[2]]
[1,2,3,[2,3,4],[],2,1,[4,8,[6],5],2] -> [1,3,6,[8,11,15],[],8,9,[13,21,[27],26],11]
[[1,2,3,4],[1,2,3],[1,2,3]] -> [[1,3,6,10],[1,3,6],[1,3,6]]
```
  
[Answer]
# [Python](https://www.python.org), ~~57~~ ~~54~~ 53 bytes
```
f=lambda x,a=0:[i*0==0and(a:=a+i)or f(i,a)for i in x]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3TdNscxJzk1ISFSp0Em0NrKIztQxsbQ0S81I0Eq1sE7UzNfOLFNI0MnUSNdOArEyFzDyFilioZuuCosy8Eo00jWhDHQUjHQVjHYVoCGUSC2TGggWBUtEmOgoWQMoMKGIKEo3V1IQYAXMHAA)
Thanks to @ovs for -3 bytes.
# [Whython](https://github.com/pxeger/whython), 42 bytes
```
f=lambda x,a=0:[(a:=a+i)?f(i,a)for i in x]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728PKOyJCM_b8GCpaUlaboWN7XSbHMSc5NSEhUqdBJtDayiNRKtbBO1MzXt0zQydRI10_KLFDIVMvMUKmKhOqwLijLzSjTSNKINdRSMdBSMdRSiIZRJLJAZCxYESkWb6ChYACkzoIgpSDRWUxNiBMxyAA)
Uses the `?` operator to catch `TypeError: unsupported operand type(s) for +: 'int' and 'list'` and recurse in that case.
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 34 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
{√ó‚â†ùï©?(‚äëùï©)ùï§{=ùï®?ùï©‚àæÀú‚ãàùîΩùï®;ùï®+0‚àæùï©}ùïä1‚Üìùï©;ùï©}
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RuKGkHvDl+KJoPCdlak/KOKKkfCdlakp8J2VpHs98J2VqD/wnZWp4oi+y5zii4jwnZS98J2VqDvwnZWoKzDiiL7wnZWpffCdlYox4oaT8J2VqTvwnZWpfQoKCj7ii4jiiJhG4oiY4oCiSnPCqOKfqCJbOF0iCiJbMSwyLDNdIgoiWzEsMSwxLDEsMV0iCiJbWzFdLFsxXSxbMV1dIgoiWzEsWzFdLFsxXSxbMV1dIgoiWzEsMiwzLFsyLDMsNF0sW10sMiwxLFs0LDgsWzZdLDVdLDJdIgoiW1sxLDIsMyw0XSxbMSwyLDNdLFsxLDIsM11dIuKfqQ==)
```
{√ó‚â†ùï©?(‚äëùï©)ùï§{=ùï®?ùï©‚àæÀú‚ãàùîΩùï®;ùï®+0‚àæùï©}ùïä1‚Üìùï©;ùï©} # Function taking a nested list as ùï©
 √ó‚â†ùï©?                          ;ùï©  # If the list is empty, return it
                            1‚Üìùï©    # Tail of ùï©
                           ùïä       # Recursive call on the tail
                                   # If that fails, return the tail (for the base case)
      ‚äëùï©                           # The first element of the list
        ùï§{      ...      }         # Call the inner function with parameters
                                   #  - ùï©: result of recursive call
                                   #  - ùï®: first element
                                   #  - ùîΩ: a reference to the outer function
          =ùï®?<list>;<int>          #   Conditional, the rank of ùï® is 0 for ints and 1 for lists
                 ùîΩùï®                #   If ùï® is a list, call ùîΩ on that 
             ùï©‚àæÀú‚ãà                  #   And insert the result in the front of ùï©
                      0‚àæùï©          #   If ùï® is an integer, prepend 0 to the list ùï©
                    ùï®+             #   And add ùï® to each integer in the resulting nested list
```
I tried to handle the base case with `‚éä` (Catch) instead of an explicit conditional, but couldn't get it to work properly. See [the revision history](https://codegolf.stackexchange.com/revisions/240620/2) for my failed attempts.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 39 bytes
```
a_~f~b___:=Join[{f@@a},0&@@a+f@b]
_f={}
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78/z8xvi6tLik@Pt7K1is/My@6Os3BIbFWx0ANSGmnOSTFcsWn2VbX/g8oyswriVbWtQPKK8eq1QUnJ@bVVXNV1@pwVVuACEMdIx1jCAMKQZxqIAnFEDkMAaAunWoQYQIUrAVygWpMdCx0qs1qdUyBfIgpOjAVUGugdC1X7X8A "Wolfram Language (Mathematica) ‚Äì Try It Online")
Input `[list...]`. Inputting `[list]` works, but returns inside an extra layer of `{}`.
```
a_~f~b___:=                         when input is nonempty:
                 f@@a                 recurse on first element
                                      (do nothing if it's an integer)
           Join[{    },      f@b]     followed by recursion on remainder
                           a+           with first element added
                       0&@@             (or 0 if it's a list)
_f={}                               otherwise return empty list
```
---
### [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 40 bytes
```
f=#/.{a_,b___}:>Join[{f@a},0&@@a+f@{b}]&
```
[Try it online!](https://tio.run/##ZU1NC8IwDL33bxR6MX5PGYKjZ0@CxzFKNiz2sArSW8j@em1pPUnIS97LSzJjeD1nDG7CGO1VbjeEBkZjDF@629v5nqxGhp3SGldW08iDiveP86GX685qOajlMaFfSBCDoDbDHg5wLE2NTChhzTL7E9IWUIYmiZxo8jTQAp0ZTomXK/Bz1De1suD4BQ "Wolfram Language (Mathematica) ‚Äì Try It Online")
Input `[list]`.
[Answer]
# [R](https://www.r-project.org/), ~~111~~ ~~107~~ ~~103~~ 98 bytes
*Edit: -5 bytes each thanks to pajonk and Giuseppe*
```
`~`=function(x,t=0)`if`(length(x),`if`(is.list(y<-el(x)),c(list(y~t),x[-1]~t),c(y+t,x[-1]~y+t)),x)
```
[Try it online!](https://tio.run/##ZU5BDoIwELz7ChIv3bgYWxBqIn7EGDENKglBQ5cELnwdS1uNymlnZ3Zmpxm1utTnZ9XqbMyHPLu2taLyUbMOKdtAXl5zVhX1je6sA7RrqddVqYn1@7CoDAuomCMGAuyOIT9NQLF@RX41yJx1MJLimb2FhaaGfZ4zIwAsSAkny7kurJ44naMb8D/nvsT60rdPYORuJxB7HxjaR8YoHUgAt4aHYBmEh8C7I0ycKpFz5NuPX@LOV4hQ@CiRGr@J4XzeKrWtpGv1Ve3dyG4/eJ4hAcYX "R ‚Äì Try It Online")
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-xp`, 27 bytes
```
b|:0FdacPB:xNd?b+:d(fdb)c|l
```
Recursive main program, takes the list as a command-line argument. [Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgebSSbkWBUuyCpaUlaboWu5NqrAzcUhKTA5ysKvxS7JO0rVI00lKSNJNrciAqoApvakQrRRtaG1kbW0eDCJNY6-hYINfQOtrE2sI62izW2hTIj4WbDAA)
### Explanation
```
b|:0FdacPB:xNd?b+:d(fdb)c|l
                             a (1st arg) is the input list; b (2nd arg) is the starting
                             number for the scan
                             When the function is called as the main program, b is not
                             specified, so it is nil
b|:0                         If b is falsey (nil or 0), set it to 0 instead
                             c and d are also local variables which are nil b/c 3rd and
                             4th arguments are not given
    Fda                      For each element d in the input list:
           xNd                 Does d contain x (empty string)?
              ?                If so, it's an integer:
               b+:d              Add it to b in-place
                               If not, it's a list of integers:
                   (f  )         Make a recursive call
                     d           using d as the new list
                      b          and the current value of b as the new starting point
       cPB:                    Take that result and push it onto the end of c
                               (Pushing an element to a nil variable makes it a list)
                        c    After the loop, return c...
                         |   except if c is falsey, it's still nil...
                          l  so return empty list instead
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 39 bytes
```
f=->d,t=0{d.map{|x|x*0==0?t+=x:f[x,t]}}
```
[Try it online!](https://tio.run/##XU/RasMwDHz3V5jubbuWOGk7b@DtQ1Q9dGvCBmsoqQseSb49kxMnlGFk6U7nk9zcPn6HoXLrtxO8y9rT5ny8tF3owmPmXPbun1x4rSjAc98PRMTQxAyliWysbQIGOYpIGBTYL2Q6U0MU2GKXmiRsiti@h/PrfxIhcp7jfq7gaC08CxTZFha0Z5mFfFkKZGFkmd2os3gR3wJ5dH0WnciNWXbD7Jg@lvK06ehmspGNv50zs@JNefz8ajtfXj2a8nr78Z3SwVUUGVb6omMRc5Cr@a69Xj20wblJ3B/qQ71SWqleDX8 "Ruby ‚Äì Try It Online")
Ruby has the same operator `*` for Integer and Array which takes the same right operand type(number).  
If we multiply a number by 0 we get 0, if an Array we get an empty Array.
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), ~~116~~ ~~108~~ 96 bytes
```
(d S(q((L A)(i L(i(a(h L)1)(c(a(h L)A)(S(t L)(a(h L)A)))(c(S(h L)A)(S(t L)A)))L
(d f(q((L)(S L 0
```
[Try it online!](https://tio.run/##XYyxCsMwDER3f8WNpy1O0tC1uzZ/QWkpNZSSUC/9ekU2ptAgJO7diSv5/X3lz2rGOxI3UnERZigzr3xCJQpvXXqSWFz8WGqY/sPqavC@R@tzG4rBWDGiT2jIKDhs6H8jJrCe2W1xjOCMM7gITs62Aw "tinylisp ‚Äì Try It Online")
-8 bytes by removing `(load library` thanks to chunes [in chat](https://chat.stackexchange.com/transcript/message/60327802#60327802). -12 bytes thanks to some [type abuse](https://codegolf.stackexchange.com/a/242255/67312).
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 37 bytes
```
f=(v,a=0)=>v.map(z=>z.at?f(z,a):a+=z)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bVFLDoIwEI1bT-HGpI1PtKBYNdWDNF00Cm5QTPwsuIobF3ooPY0DWIJCmsmk896b7-1xSLfR_f68nOOhfPVjxa6waszV6urt7ZFlapV59ryOWQbLF3agMl6S353bJj2c0iTyknTHYqYN58veaNTTpvuHyAqSDUzAR1DhAgHCFs731XikwgTTBlcLg69V7HqsmbtNQVHfOGvvmZC8BWIY-pJgAgkdGuoJ_u9A0BKC2p8WZIk51Qrg50VmRCaNEC2DwBUod-R8bawiuRgXUL445015I3fYDw)
Port of several of the other answers.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~25~~ 12 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
[emanresu's solution](https://codegolf.stackexchange.com/a/256309/58974) made me realise that, although I had the right method, my approach to it was *all* wrong - I honestly don't know *what* I was thinking!- so please upvote them if you're upvoting this.
```
√ã¬∂√î?√üD√îV:V¬±D
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=y7bUP99E1FY6VrFE&input=WzEsMiwzLFsyLDMsNF0sW10sMiwxLFs0LDgsWzZdLDVdLDJdCi1R)
```
√ã¬∂√î?√üD√îV:V¬±D     :Implicit input of array U, with second input variable V defaulting to 0
√ã                :Map each D in U
 ¬∂               :  Is D strictly equal to
  √î              :  Its reverse, if it's an array, or maximum, if it's an integer (see more detailed explanation below)
   ?             :  If true
    √ü            :    Recursive call with arguments
     D√î          :    U = D reversed (because reversing an array in JS mutates the original), and
       V         :    Current value of V
        :        :  Else
         V¬±D     :    Increment V by D
```
---
To (try to) explain how the `√î` (which is a shortcut for the `w` method, without any arguments) allows us to differentiate between arrays & numbers by testing for strict equality:
While it's true that in JavaScript 2 arrays containing the exact same elements are [not strictly equal](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubyg&code=WzEsIDIsIDNdID09PSBbMSwgMiwgM10&footer=KSQ) as they are 2 distinct objects, an array assigned to a variable is, of course, [equal to itself](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubygo&code=VSA9IFsxLCAyLCAzXSwKVSA9PT0gVQ&footer=KSQ). Add to that that the `reverse` method for arrays (`w` in Japt) [mutates the original array](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubyhb&code=VSA9IFsxLCAyLCAzXSwKVS53KCk&footer=XS5xKFIpKSQ) and that explains how an array assigned to a variable (`D` in this case) can be [strictly equal to its reverse](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubygo&code=VSA9IFsxLCAyLCAzXSwKVSA9PT0gVS53KCk&footer=KSkk).
As to why a number does not equal its maximum, that's down to a peculiarity of Japt. Firstly, when applied to a number, Japt's `w` method [returns the maximum](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubygo&code=VSA9IDgsClUudyg0LCAxMik&footer=KSkk) of that number and the arguments passed to the method, [as a `Number`](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubygo&code=VSA9IDgsCnR5cGVvZiBVLncoNCwgMTIp&footer=KSkk). However, if *no* arguments are passed to the `w` method then the number it's applied to is [returned as excpected](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubygo&code=VSA9IDgsClUudygp&footer=KSkk) but, [for some reason](https://github.com/ETHproductions/japt/blob/master/src/japt-interpreter.js#L220), Japt [converts the returned value to an `Object`](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubygo&code=VSA9IDgsCnR5cGVvZiBVLncoKQ&footer=KSkk) and a `Number` cannot be [strictly equal to](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=JE8ubygo&code=VSA9IDgsClUgPT09IFUudygp&footer=KSkk) an `Object`
---
## Original, 25 bytes
Preserving this version as Conor O'Brien awarded it an unexpected boubty.
```
W=Uv)?[W¬∂√î?√üW√î:V¬±W]c√üUV:U
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Vz1Vdik/W1e21D/fV9Q6VrFXXWPfVVY6VQ&input=WzEsMiwzLFsyLDMsNF0sW10sMiwxLFs0LDgsWzZdLDVdLDJdCi1R)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~30~~ 29 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
0U"ŒµdiXƒáy+≈°¬¨√´XD¬¨≈°Uy¬Æ.V}sU"¬©.V
```
[Try it online](https://tio.run/##yy9OTMpM/f/fIFTp3NaUzIgj7ZXaRxceWnN4dYTLoTVHF4ZWHlqnF1ZbHKp0aKVe2P//0YY6RjrGOtEgwiRWJzoWyDXUiTbRsdCJNovVMQXyY//r6ubl6@YkVlUCAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeV/g1Clc1tTMiOOtFdqH114aM3h1REuh9YcXRhaeWidXlhtcajSoZV6Yf91/kdHx@ooRFuACEMdIx1jCAMKQZxoIAnFEDkMAaAunWgQYQIUjAVygWpMdCx0os1idUyBfIgpOjAVUGugdGzsf13dvHzdnMSqSgA).
**Explanation:**
Unfortunately 05AB1E lacks recursive methods. We can however mimic this behavior by using `"recursive_function_here¬Æ.V"¬©.V`. One big disadvantage about this however, is that the variables will always be in the scope of the full program, rather than this recursive function. So instead, we use and modify a list as variable.
```
0U         # Start with X=[0] (or actually X=0, but it behaves as [0])
  "..."    # Push a string with the recursive function explained below
       ¬©   # Store this string in variable `¬Æ` (without popping)
        .V # Evaluate it as 05AB1E code
           # (after which the result is output implicitly)
Œµ          # Map each item `y` to:
 di        #  If `y` is a (non-negative) integer:
   X       #   Push list X
    ƒá      #   Extract its head; pop and push remainder-list and first item
           #   separated to the stack
     y+    #   Add the current integer `y` to this head
       ≈°   #   Prepend it back to the remainder-list
        ¬¨  #   Push this prepended head again (without popping the list)
  √´        #  Else (`y` is an inner list instead):
   X       #   Push `X`
    D      #   Push `X` again by duplicating
     ¬¨≈°    #   In this second `X`, prepend its own head
       U   #   Pop and replace `X` with this modified list
   y       #   Push the current list `y`
    ¬Æ.V    #   Do a recursive call with it
  }        #  After the if-else statement:
   s       #   Swap so the (potentially modified) `X` is at the top of the stack
    U      #   Pop and replace `X` with this modified list
```
[Answer]
# Python3, 74 bytes:
```
f=lambda x,h=0:x and[int==type(x[0])and(h:=h+x[0])or f(x[0],h)]+f(x[1:],h)
```
[Try it online!](https://tio.run/##dY5NCsMgEIX3PUWWSmYRmx@C4EmGWaSkYqFNRLJITm9H2yySUkSc9703M/ptcfNU9z7EaM1zeN3GoVjBmUqvxTCN@JgWY5bN38WKFUlGwmnjyqzmUNjMwUkqU6l0qqMP3CesQAVXqKGBFjqS8nLimE0CJJYKsIEesCNoWR/iB9H/TjqR7zlQVLznc0/pf87@@eTkJfvLqfgG)
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 44 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
0‚ä∏{0=‚â†ùï©?ùï©;√ó‚â°‚äëùï©?(‚ãàùï®ùïä‚äëùï©)‚àæùï®ùïä1‚Üìùï©;a‚àæ(a‚Üêùï®+‚äëùï©)ùïä1‚Üìùï©}
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgMOKKuHswPeKJoPCdlak/8J2VqTvDl+KJoeKKkfCdlak/KOKLiPCdlajwnZWK4oqR8J2VqSniiL7wnZWo8J2VijHihpPwnZWpO2HiiL4oYeKGkPCdlagr4oqR8J2VqSnwnZWKMeKGk/Cdlal9Cgo+KOKLiCBGKcKo4p+o4oCiSnMiW10iCuKAokpzIls4XSIK4oCiSnMiWzEsMiwzXSIK4oCiSnMiWzEsMSwxLDEsMV0iCuKAokpzIltbMV0sWzFdLFsxXV0iCuKAokpzIlsxLFsxXSxbMV0sWzFdXSIK4oCiSnMiWzEsMiwzLFsyLDMsNF0sW10sMiwxLFs0LDgsWzZdLDVdLDJdIgrigKJKcyJbWzEsMiwzLDRdLFsxLDIsM10sWzEsMiwzXV0i4p+p)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 51 bytes
```
‚äûœÖ‚äûÔºØŒ∏‚Å∞Ôº¶œÖ¬´‚âî‚äüŒπŒ∑Ôº¶Ôº¨Œπ¬´‚âî¬ßŒπŒ∫Œ∂¬ø‚ÅºŒ∂‚Å∫Œ∂‚ü¶‚üß‚äûœÖ‚äûÔºØŒ∂Œ∑¬´‚âß‚Å∫Œ∂Œ∑¬ß‚âîŒπŒ∫Œ∑¬ª¬ª¬ª‚≠Ü¬πŒ∏
```
[Try it online!](https://tio.run/##bY7LSgQxEEXX3V@RZQVKsHUUYVazcCEoNroMWYQx0wmGfuQh0jLfHivRBhdCSFF1b91TR6P8cVIu5z4FAwlZqc@z9ipOHhZkl5zv29PkGSTOvtrmEIIdRuinGSxHZkhtqvyoxyEaGlbb5jvEh/FNf4JF9k72tdgbe2JwvyTlAqxEdKlWITnt/nvHWkB1Vbuga37zpOYfxosdTISSQvm/F238v/hNOrf0zm3v7RjhNVIZKAs6ZAsxchaiwyu8RlG@nUQhqe1Q7PAOxa3EG@qlzBcf7hs "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
‚äûœÖ‚äûÔºØŒ∏‚Å∞
```
Temporarily push the initial accumulator to the list and push that list to the list of lists.
```
Ôº¶œÖ¬´
```
Loop over all of the lists.
```
‚âî‚äüŒπŒ∑
```
Remove the accumulator from the list.
```
Ôº¶Ôº¨Œπ¬´
```
Loop over the elements of the list.
```
‚âî¬ßŒπŒ∫Œ∂
```
Get the current element.
```
¬ø‚ÅºŒ∂‚Å∫Œ∂‚ü¶‚üß
```
Check whether it's a list. Adding an empty list to a list produces the original list, but adding it to an integer vectorises therefore producing the empty list rather than an integer.
```
‚äûœÖ‚äûÔºØŒ∂Œ∑
```
If it's a sublist then temporarily push the accumulator to the sublist and push the sublist to the list of lists.
```
¬´‚âß‚Å∫Œ∂Œ∑¬ß‚âîŒπŒ∫Œ∑
```
Otherwise add the value to the accumulator and replace the value with the total.
```
¬ª¬ª¬ª‚≠Ü¬πŒ∏
```
Pretty-print the result as the default output format doesn't handle ragged lists very well.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 52 bytes
```
f=([h,...t],v=0)=>h?[h+0>h?f(h,v):v+=h,...f(t,v)]:[]
```
[Try it online!](https://tio.run/##bVDRDoIwDHz3K3wc4QQGihODfsjSB6PiNEaMkP3@LCgEhSxN095de93tYA/V8XV91otHeTo7V@RCGwRBUBNsHnn5zuy18SNOhTCwXmb9vCUUouaSMk3uWD6q8n4O7uVFFEKT523nYTjXNPtDVA@pESYRI@lxiQTpBOf7BjxWYYnViKsl4Rs9e9gbz55ScDemLqY9M9JYYAZxyYIlFHRK7Anx70HQCpLtr1qywoZ3JYibJWsms0bKiUPQLfj8UZcHZ7XDZdRCzcd1mdwb "JavaScript (Node.js) ‚Äì Try It Online")
]