[Question]
  [
The age-old question - is it better to walk or run? There are two trains of thought. If you run, you cause the rain to effectively hit you from the front, which increases your surface area and basically causes you to run into the raindrops, getting hit with more water. However, if you walk, you spend longer in the rain.
Actually, there is no good answer, because if the rain is about to get worse, you'd better run to get out of it even if you get hit more immediately, because you don't want to get hit by the rain later on.
In fact, if you can't predict the future, you don't actually have a good way to know what the optimal strategy is. However, we are not subject to such constraints, and can take the future as input.
## Specification
You are trying to get somewhere \$N\in\mathbb{Z}\_{\geq1}\$ metres away (\$N\$ will be supplied as input). However, it has started raining. For the next \$N\$ seconds, a certain amount of rain will be falling per second, and will be constant within the span of a 1-second period of time. Specifically, during the \$i\$th second (\$1\leq i\leq N\$), there will be \$a\_i\in\mathbb{Z}\_{\geq0}\$ units of rain. You will also be given \$\{a\_1,a\_2,\dots,a\_N\}\$ as input. It rains the same amount at all locations across that distance, but once you reach your destination, you will no longer get hit by rain.
Now, you want to know how to get rained on the least. During each second, you must either walk or run. On the \$i\$th second, if you walk, you will move 1 metre and get hit by \$a\_i\$ units of rain. If you run, however, you will move 2 metres but get hit by \$2a\_i\$ units of rain. Note that if you are 1 metre from the finish, if you run, it only makes sense to be hit by half of that because you're in the shelter after the first half-second, but since \$\frac{2a\_i}2=a\_i\$, you can just walk instead, so you don't really need to consider this case.
What is the least amount of rain you can get hit by in order to cross those \$N\$ metres?
## I/O Format
You may take \$N\$ as an input if you wish. Since it's the same as the length of the list, you're allowed to exclude it.
You may take \$\{a\_1,a\_2,\dots,a\_N\}\$ as an input if you wish. I'm not sure how you'd solve the problem without it.
You must output a single non-negative integer, the least amount of rain (in units) that you can be hit by in order to cross those \$N\$ metres.
## Example
```
10 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
```
The rain is progressively getting worse. Clearly, every second you spend outside makes the rain worse, so it's better to get hit by double the amount now than wait and get hit by the larger amount later. If you run for 5 seconds, you will move 10 metres and get hit by \$15\times2=30\$ units of rain. In comparison, if you walk for 10 seconds, you get hit by 55 units.
```
6 [1, 0, 1, 0, 1, 0]
```
The rain is acting weird. In this case, if you run for 3 seconds, you get hit by 4 units of rain. However, if you only run during the second and fourth seconds, and walk during the first and third, you still cover 6 metres, but here you only get hit by 2 units since you run during the time when the rain is stopped, and no rain doubled is still no rain.
## Test Cases
```
7 [1, 0, 2, 5, 3, 0, 0]           -> 11
1 [1]                             -> 1
6 [2, 5, 5, 2, 3, 1]              -> 18
1 [5]                             -> 5
3 [3, 3, 5]                       -> 9
9 [1, 0, 3, 1, 1, 1, 3, 2, 3]     -> 9
5 [3, 2, 0, 0, 0]                 -> 5
7 [3, 1, 4, 4, 3, 5, 3]           -> 19
```
You can generate more test cases [here](https://tio.run/##dU/NasMwDD7HTyF6ste0OB27FLJHyGm3rIxAnFUQy8ZxWvb0mdTSLQyGweL700/8yudAz8vSuwF8uDjd45RLSB2SOaoCBxAC6hoswyK5PCcCqwo3rrRqpUm0tSdxTG7FeyR9gKeHDtvfebCDw31mWx1PpvzHU608Rin0MaTMFPXBK@WpBN9BzV/USHwEUpyzNvspjsiVI9czjg7e0iyLNey9h/dSOKJ5giejCmnT/tGstDcwhAQf3Fqin043hi@NSQxTTgx55w2/LQjsbvCdBG92rz/87aqmhM48DGZZKgsv3w); the input accepts the max \$N\$ and the max \$a\_i\$. It's also an ungolfed reference implementation (the `move` function) (I could have probably figured out a DP relation to solve this more efficiently, but I was too lazy, and since it's [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), I don't suppose anyone else will use a more efficient solution either...)
## Scoring
* this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"); since you are writing on your umbrella and have limited space, your code must be as short as possib- wait, you had an umbrella? [...]
* [standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden as usual
* have fun and happy golfing!
  
[Answer]
# [J](http://jsoftware.com/), 44 39 27 bytes
```
#{0,[:<./]+/\@#~1+2#:@i.@^#
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/lasNdKKtbPT0Y7X1YxyU6wy1jZStHDL1HOKU/2typSZn5CsYGirYKqQpGAK16igY6SiY6igYg9kGUHmINJRjAeZBlJmC1QMVQyVNwXKmEI4lmGMMhCgCEGtAemDIGGIKshEQIQMUV1jCZIBaTMDIGOLW/wA "J – Try It Online")
-12 after reading [rak1507's clever idea](https://codegolf.stackexchange.com/a/223785/15469)!
Using 3 3 5 as an example:
* `1+2#:@i.@^#` One plus all binary numbers from `0` to `2^<length>-1`
```
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2
```
* `]...#~` Use each of those as a mask to replicate the input (trailing zeros are just fill):
```
3 3 5 0 0 0
3 3 5 5 0 0
3 3 3 5 0 0
3 3 3 5 5 0
3 3 3 5 0 0
3 3 3 5 5 0
3 3 3 3 5 0
3 3 3 3 5 5
```
* `+/\@` And scan sum each row:
```
3 6 11  0  0  0
3 6 11 16  0  0
3 6  9 14  0  0
3 6  9 14 19  0
3 6  9 14  0  0
3 6  9 14 19  0
3 6  9 12 17  0
3 6  9 12 17 22
```
At this point the problem is essentially solved, because the 3rd column
is "how wet we are after moving 3 meters". All we need to do now is...
* `[:<./` Take the min of all rows and...
* `#{0,` Pluck the 3rd column.
## original approach, 39 bytes
```
[:<./1#.[(*2-~/\0,#<.+/\)"#.1+2#:@i.@^#
```
[Try it online!](https://tio.run/##VY7BCsIwEETvfsXQHGptuk0aAza0UBA8efLa4kUs6sU/8NdjzKZgyQYy@2Yn@/IZ5TN6hxwSCi7cinC8nE9@dB3VWtC43TXVp56UFB2V9VRkgnTZCDc8abgKX2zut8cbWqPHDB1iJBoJK2HiWyXOOIlDVGyz0R/MCdrILIs2ChPOqsHf/GaWMpzyH8EttdqiXUgY2ccyvKv/Ag "J – Try It Online")
Tries all possible combinations.
Using 3 3 5 as an example:
* `1+2#:@i.@^#` One plus all binary numbers from `0` to `2^<length>-1`
```
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2
```
* `+/\` Scan sum each row
```
1 2 3
1 2 4
1 3 4
1 3 5
2 3 4
2 3 5
2 4 5
2 4 6
```
* `#<.` Minimum of each element and input length, 3 in this case:
```
1 2 3
1 2 3
1 3 3
1 3 3
2 3 3
2 3 3
2 3 3
2 3 3
```
* `0,` Append 0:
```
0 1 2 3
0 1 2 3
0 1 3 3
0 1 3 3
0 2 3 3
0 2 3 3
0 2 3 3
0 2 3 3
```
* `2-~/\0` Successive deltas:
```
1 1 1
1 1 1
1 2 0
1 2 0
2 1 0
2 1 0
2 1 0
2 1 0
```
* `*` Multiply each by the input (J dyadic hook):
```
3 3 5
3 3 5
3 6 0
3 6 0
6 3 0
6 3 0
6 3 0
6 3 0
```
* `1#.` Sum rows:
```
11 11 9 9 9 9 9 9
```
* `[:<./` Minimum:
```
9
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 13 bytes
```
▼moΣ↑L¹MṘπL¹2
```
A (sorta) port of my APL solution, just for fun. Husk is certainly an ... interesting ... language.
-2 each from Razetime and Leo
```
▼moΣ↑L¹MṘπL¹2
         πL¹2     cartesian power of [1,2] of length of the list
       MṘ         replicate
 moΣ↑L¹           sum of len(input) take each list
▼                 minimum
```
[Try it online!](https://tio.run/##yygtzv7//9G0Pbn55xY/apvoc2in78OdM843ABlG////jzbWMdQxAUJjHVMd41gA "Husk – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 41 bytes
```
f[a_,b___,c_]=a+Min[b~f~c,a+f@b]
f@a_:0=a
```
[Try it online!](https://tio.run/##RU3LCoMwELz7FQGhF7eQGu0LLPmBQqFHkbCGBj3ooXgT8@tp3LUIy7A7Mzsz4NR9Bpx6iyG4Gg20xhiwpqkwe/Zj3XrnLWDmdNskTqO5ywrD69uPU50eH07rtDn4t8XRz8l8AiFB5CBKEIp2uUCkV2C2JDlqxJUrKLpp5f9V/Y9i/@bLOXOLZV9Bo7gz0pTCHQWRZxAXEFcQt@iXe82OS7KEHw "Wolfram Language (Mathematica) – Try It Online")
Input `f[a1, a2, ..., aN]`.
[Answer]
# [Python 2](https://docs.python.org/2/), 51 bytes
```
f=lambda h=0,*t:t and h+min(f(*t),h+f(*t[:-1]))or h
```
[Try it online!](https://tio.run/##PY7dCoMwDIXv@xS5tJqBtetkgk8ivXA4aaHWIh1jT9/Vhg0Cycn58hM@0ey@S2kd3bw9lhnM2GIdhwizX8A0m/XVWtWRo2nOPA0XoTnfDzDpbax7ghgYeHSj9eEVK84gHNZHyLDjqUeYBEKL0CEoBFnqVjNxGprdciJHFST7gkylWRaTLL0s7v9NJ/MLSVOaKWI72l9O9NTK1LWEpA/0Fw "Python 2 – Try It Online")
Essentially a port of my [Mathematica answer](https://codegolf.stackexchange.com/a/223787/81203).
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 23 bytes
```
{⍺⊃0,⌊⌿+\⍵/⍤1⍨⍉1+⊤⍳2*⍺}
```
Takes the length as ⍺ and the array as ⍵.
```
{⍺⊃0,⌊⌿+\⍵/⍤1⍨⍉1+⊤⍳2*⍺}
              ⍉1+⊤⍳2*⍺   all possible combinations of 1 and 2 of length ⍺
         ⍵/⍤1⍨           replicate ⍵
       +\                cumulative sum
     ⌊⌿                  minimum reduce
 ⍺⊃0,                    take the ⍺-th item (prepend a dummy item so it works with 0 based indexing)
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qG@qp/@jtgkG/6sf9e561NVsoPOop@tRz37tmEe9W/Uf9S4xfNS74lFvp6H2o64lj3o3G2kB1dX@TwPqedTbB9TwqHfNo94th9YbP2qbCDQtOMgZSIZ4eAb/N1dIUzDUUTDQUTDSUTDVUTAGsw24DIHiOoZcZkAKImEKVgGUNgTLmXIZA0ljsIgplyXcFJACGDKGaOEyhag0ghgNMt0cIgJUYwJGxhC7AQ "APL (Dyalog Extended) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 53 bytes
```
f=lambda n,h=0,*t:n>0and h+min(f(n-1,*t),h+f(n-2,*t))
```
[Try it online!](https://tio.run/##PY7dCsIwDIXv@xS5XLcI7WodDuaLjF5M5mihxiEV8elrf1AI9OScL0n3T7AP6mPcJr/cr@sChHYS2IaRLmKhFWx3d9RsDR1kcjnaLus@ax7f1vkbyJGlMT852l@h4Qz2p6MAicPW8zggzBJBIPQIGkEVLQyTOTDslJ6a6IKkXNZQG5aaWRUvNef/psz8StUpw3Rl@7q/nBiqlahjKVV/YL4 "Python 2 – Try It Online")
Uses a kind-of sketchy splatted input format of `f(N, l_1, l_2, ..., l_N)`.
**68 bytes**
```
lambda n,l:min(sum(l[:n-k]+sorted(l[:-k])[:k])for k in range(n/2+1))
```
[Try it online!](https://tio.run/##PU7bCoMwDH3vV@SxxY7ZOicT/JKuDw51ltUoXhj7@q4XNghJz6UnWT77OKN0Q3N3tp0eXQvIbT0ZpNsxUatqPL10ts3r3ncBesRU7dswr/ACg7C2@OwpnmUmGHPv0dgeRE1CTmNwOXbKCCyrwR0G6knmKg5KcMg5SA4lhyK@c01EEDS5@pGUMlq8LpJYauKBKiLnwe2fFDy/KtIvTcrklSk/rqgS5V2XWEW6QH8B "Python 2 – Try It Online")
An efficient solution, unlike the exponential-time solution above. Picks how many seconds `k` to walk, minimizing the sum of first `k` numbers plus the sum of the smallest `n-k` among them which are chosen to be doubled.
Here's a nifty recursive version:
**66 bytes**
```
f=lambda n,l:l and min(sum((l+sorted(l)+[1e999])[:n]),f(n,l[:-1]))
```
[Try it online!](https://tio.run/##PY7dCsMgDIXvfYpcKnVQ27mh0CeRXHS0pYK1pbWMPb2zygaB/JwvJ9k@YV59E@PUuX55DT147rSD3g@wWE@Pc6HUVce6h3GgjlVGjEopZEZ7ZHyiCTf6JpCx@J6tG0Focnl01m9noIzAtlsfIJMsPjkYwaHm0HCQHNpc10jEJSB5pFQUmZGkiyJKJKkxbZ6lRv2dLuYXbdlCIgvbFP984llGibrnaMsH@AU "Python 2 – Try It Online")
[Answer]
# JavaScript (ES6), ~~53~~ 52 bytes
*Saved 1 byte thanks to @l4m2*
Expects `(n)(list)`.
```
f=(n,[k,...a])=>n>0&&Math.min(f(n-1,a),f(n-2,a)+k)+k
```
[Try it online!](https://tio.run/##hZBNDoIwEIX3nqIrQuNQKFiRBdzAExAWDYIi2BohXh9Liz8g0cksZjHfey/vzO@8zW/VtXOEPBR9X8a2gLQGQgjPcJyIxLOsPe9O5FIJu7SFQ4FjGA5fHetabZ9L0cqmII08qpcQUEoBeYB8QAxQoG8vQ3owRq6LKF1NITpA48v3jNCM2SrGWDDtpYw@JEZmt2DE/hixGaOE00DrL5GGiWZM9GphiPXcwATNlhlmfHxT2LuzX9lCwyjtjd7AdD5tO@of "JavaScript (Node.js) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 57 bytes
A direct recursive implementation of the task.
```
f=lambda N,a:N>0and min(f(N-x,a[1:])+x*a[0]for x in[1,2])
```
[Try it online!](https://tio.run/##hZBNboMwEEb3PsW3w26dCkOdFCRyBC6AUOUqQUHix6KkoaenY9M0EVVVywvP6M2bGdvP8dR30TxXWWPat4NBLk2a70PTHdDWHa94vpmkKVRaisfpwRRhWfUDJtRdoWRUivlyqpsjVMooZSX682iRYTCXV4rPIxdP77apRx5gs0cgGHWAIaI1lh8/TCNd3Q8TSChB0Lem7kbunpSxAwWgeahcIMs8Mu9AYyCUiCS0ROzfYYnboa5KMUXcffb3cRzbolhE2htJt65y2IvT6X91msUoYm/5EyYsYcl1CdfveuNlgvKGaW@LlhVXW9413XmMDM/@xsvHrL8k@QI "Python 2 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
2ṗx@"Fṁɗ€§Ṃ
```
A dyadic Link accepting \$N\$ on the left and \$A\$ on the right that yields the smallest amount of rain.
**[Try it online!](https://tio.run/##y0rNyan8/9/o4c7pFQ5Kbg93Np6c/qhpzaHlD3c2/f//3@x/tKGOgQ4UxwIA "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8/9/o4c7pFQ5Kbg93Np6c/qhpzaHlD3c2/T@8XB/I/v8/OtpcRyHaUEfBQEfBSEfBVEfBGMw2iI3l0gGJRxuCWWZAFkTeFKwQqMoQrsQUzAIKgTAQQfiWcINBimHIGKIdrMIUosMIYiPMUnOIKFCtCRgZQ5wFlIsFAA "Jelly – Try It Online").
### How?
```
2ṗx@"Fṁɗ€§Ṃ - Link: integer, N; list (of length N), A
2           - two
 ṗ          - (implicit range of 2 = [1,2]) Cartesian power (N)
        €   - for each (walk/run list, x):
       ɗ    -   last three links as a dyad - f(x, A):
    "       -     zip with:
   @        -       with swapped arguments:
  x         -         repeat elements
     F      -     flatten
      ṁ     -     mould like (A) (i.e. cut to length N)
         §  - sums
          Ṃ - minimum
```
[Answer]
# Vim, 90 bytes
```
"aDqmdd{"cyGO0<esc>Gp:.,$sor n
Go0<esc>ggVGJ0@awwhD:s/ /+/g
0C<c-r>=<c-r>"
,<c-r>b<esc>0"bD"cpG@mq@m0C<c-r>=min([<c-r>b])
```
[Try it online!](https://tio.run/##K/v/XynRpTA3JaVaKbnS3d/AJrU42c69wEpPR6U4v0ghj8s9HyKWnh7m7mXgkFhenuFiVayvoK@tn85l4GyTrFtkZwsmlbh0wHQSWL2BUpKLUnKBu0NuoUMuTF1uZp5GNERRrCbX///mXMZchlwmQGjMZcpl/F@3DAA "V (vim) – Try It Online")
This is vanilla vim (TIO supports V, which is backwards compatible with vim).
Vim doesn't really do branching recursion (at least, I don't know a good way without just writing pure vimscript, and it's possible that would be shorter, but certainly less fun!), so this answer uses a method that's different from most of the existing answers.
**tl;dr**: Takes N followed by the list, one int per line. Finds the minimum over prefices length `n-k` of the sum of that prefix plus its `k` smallest elements.
Long version:
## How?
We observe that, given a list `l` of length `n`, if we choose to run `k` times, we will always choose to run on the `k` smallest elements of the length `n-k` prefix of `l`, and we will avoid the length `k` suffix of `l` entirely. Thus, the solution can be arrived at by concatenating the length `n-k` prefix with the sorted version of itself, and taking the length `n` head of this new list which has length `2*(n-k)`. Once `2*(n-k)` becomes smaller than `n`, we must stop because we can't run more than `n/2` times.
```
"aDqmdd{"cyGO0<esc>Gp:.,$sor n
                                               " input like 3, [2, 1, 5] newline separated
"aD                                            " cut N into register a
   qm                                          " def m:
     dd{                                       " delete current line, go to top
        "cyG                                   " copy file contents into register c
            O0<esc>                            " prepend 0
                   Gp                          " go to end, paste register c below
                     :.,$sor n                 " sort the new copy of l numerically
                                               " -> [0,2,1,5,1,2,5]
Go0<esc>ggVGJ0@awwhD:s/ /+/g
Go0<esc>gg                                     " append a 0 at the end, go back to top
                                               " -> [0,2,1,5,1,2,5,0]
          VGJ                                  " join all the lines by spaces
             0@aw                              " go to the (n+1)th number
                 w                             " go one more and **exit function if we can't**
                                               " note that the prepended and appended 0 were necessary for this magic stopping condition to work
                  hD                           " go left to the preceding space and delete the rest of the line
                                               " -> '0 2 1 5'
                    :s/ /+/g                   " replace all spaces with '+'
                                               " ->'0+2+1+5'
0C<c-r>=<c-r>"                                 " eval the current line and replace it with the result
                                               " -> '8'
,<c-r>b<esc>0"bD"cpG@mq@m0C<c-r>=min([<c-r>b]) 
,<c-r>b<esc>                                   " append a comma followed by the contents of register b
                                               " -> '8,'
            0"bD                               " cut the result of that into b (accumulates)
                "cp                            " write back the original list
                   G@m                         " go to the end and recurse, causing the last element of l to get deleted at the start of m
                      q@m                      " stop defining m, then call it
                                               " now register b contains a comma separated list of the sub-results
                         0C<c-r>=min([<c-r>b]) " take the min of those and replace the current (only) line with the result
```
The next iteration will look like
```
[2,1]
-> [0,2,1,1,2,0]
-> '0 2 1 1 2 0'
-> '0 2 1 1'
-> '0+2+1+1'
-> '4'
-> '4,8,'
```
and finally:
```
[2]
-> [0,2,2,0]
-> '0 2 2 0'
-> **try to go past end of line and exit instead**
```
So after `m` terminates, the final state is
```
buffer: 0 2 2 0
b: 4,8,
```
And so the (only) line in the buffer gets replaced with the evaluation of `min([4,8,])` and we have the desired output: `4`.
A note on the stopping condition `@aww`: In the common case, what we want to do is delete everything from the `n+1`st number onwards, which is achieved by just `@aw` (and no prepending/appending 0s). However, just `@aw` won't cause `m` to exist by error if it moves at all, i.e. even if there are just two numbers ('words') on the line, so we need the second `w` to actually cause `m` to exit, hence the need to prepend 0. (We also can't decrement `N` before reading it because that would fail when N=1--`0w` doesn't move 0 words because `0` isn't a count; it moves to the beginning of the line and then moves 1 word!). The appended `0` is so that we always have something to delete even when there are exactly `n` numbers left, otherwise we would stop without checking the prefix of size `n/2` for even `n`.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 14 bytes
```
Åœʒà3‹}εœ€*}Oß
```
[Try it online!](https://tio.run/##yy9OTMpM/f//cOvRyacmHV5g/KhhZ@25rUcnP2pao1Xrf3j@///mXNHGOgqGOgomYARkmwLJWAA "05AB1E – Try It Online")
Tries all combinations by looking at every permutation of every integer partition of \$N\$ which only consists of 1's and 2's. Porting rak's APL answer will probably be shorter.
[Answer]
# [R](https://www.r-project.org/), ~~68~~ 67 bytes
*Edit: -1 byte thanks to detective work by Giuseppe*
```
f=function(t,r,s=r[1])`if`(t>0,s+min(f(t-1,u<-r[-1]),s+f(t-2,u)),0)
```
[Try it online!](https://tio.run/##jZHNCoMwDIDvPkVhl5al0Np1Tpi@iIwJw4KHdaCVPb7rj0M7FRZ6KGm@fCHtxmer7@/G6Kbvi1EVatAP0740NtBBX3QVv5G6VTU2JYP@aKuxwoZyGK60q6h9tVmXSWEgBBhZNsQZoAfmgBigFJAEJPydEYLmOCBaIs6TJcg9GJWtI4ARd3ZcUEnvtMJVm8Bd1kL5j1BGnHCc8J592nN5xOXzZtyI3yPC0FOnDU5OvjQs8neXu3NmE2cdJ39E@I@Nn8iT8QM "R – Try It Online")
A recursive function that pretty much follows the logic of the explanation.
Note to [R](https://www.r-project.org/) golfers: I thought it should be possible to still save a byte by assigning the twice-used `r[-1]` to a variable at the first use (since `u<-r[-1]` and `u` together are shorter than two `r[-1]`s), but I just [couldn't seem to make it work](https://tio.run/##TYzBCsIwEETvfsWCl106gWxFvJj@SBELpYEcjJBN8PNj9aJzmsc8pvRHyvfXVvNmFnoMseW1pmfmigILZdabLCkuXCcPG3abbYhc3Yh2dWV2@44PK5oIvPwf8gW0soI8aASdQadv9yL0y5HcRKqH/gY). Giuseppe has now managed to to make it run by just swapping the order of the arguments to `min` or by using a different variable name, which is rather wierd and doesn't fill me with unbounded confidence about [R](https://www.r-project.org/) for my real-world work...
[Answer]
# [Julia 0.6](http://julialang.org/), ~~50~~ 44 bytes
```
n<r=n>0&&(!i=r[]i+(n-i<r[2:end]);min(!1,!2))
```
[Try it online!](https://tio.run/##hZDdDoIgGIbPuwpcm8OFGz@hqeiNMA/a6oBmrLG6fkKYZKaLccDB87zfx3t7DepcWKuFaXWH0xQmqjWyVweocyWMpPVVX/qsuSsNE4ISmmX2YZR@DhoSLCSpCW76DKyffd4BhneTUDoeAYwARYAjwPwbz@1RICQKxAmb4R8h8oWQIZr7GW7AUvf8aT6A/x/AI8@EZD530xr5KvLV9ONxlemysFxI@Oa5z6ehmEU3a/uUnneZR39Z6PWn0cq@AQ "Julia 0.6 – Try It Online")
Thanks to MarcMush for -6 bytes.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~39~~ 30 bytes
```
Ｉ⌊ＥΦＥＸ²⊕ＬθΦ⍘ι12μ⁼ΣιＬθΣＥι×Ｉλ§θμ
```
[Try it online!](https://tio.run/##VU7NCoMwDH6V4ilCd9Btp5224UCYILibeCgatNDW2dZtb99l6mUhhC98P0k7CNuOQoVQWmk8XIXzUEgj9ayhEE@4SeXRLrAc34RSznLTWtRoPHZwR9P7AaY4jjnbxBfhsPKU14PkLErSiDj9E2TTLJSDisIlrX/martIlofU6NZfFDFnn5sOPzAtKWudQqjrPWcJZ4elCR9pNk3YvdQX "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
      ²                         Literal 2
     Ｘ                          Raised to power
         θ                      Input array
        Ｌ                       Length
       ⊕                        Incremented
    Ｅ                           Map over implicit range
            ι                   Current index
           ⍘                    Convert to string
             12                 Using digits `12`
          Φ    μ                Remove leading digit
    Φ                            Filter strings where
                   ι             Current string
                  Σ              Digital sum
                 ⁼               Equal to
                     θ           Input array
                    Ｌ            Length
  Ｅ                             Map over strings
                       ι        Current string
                      Ｅ         Map over characters
                          λ     Current character
                         Ｉ      Cast to integer
                        ×       Multiplied by
                            θ   Input array
                           §    Indexed by
                             μ  Current index
                     Σ          Take the sum
 ⌊                              Take the minimum
Ｉ                               Cast to string
                                Implicitly print
```
Previous less brute-forcey 39-byte version:
```
≔⟦υ⟦ω⟧⟧ηＦθ⊞η⁺⁺§η±²2⁺§η±¹1Ｉ⌊Ｅ⊟ηΣＥι×Ｉλ§θμ
```
[Try it online!](https://tio.run/##ZYy9DsIwDIR3nsLqZEthaIGpU8XEUFQJtihDVEITqUl/0gJvH0IpE9bpZJ8/Xa3lWHeyDaHw3jQO@cyAP4VgoCnf3LsRcCCoZq9RM6ja2eNixXRyN/X6hGfVyElhRsQgyRJasX8iXYg0IYrV1WjchEfpJyyNM3a2WMoeq65HHbHLehsGV2OV/5Jt/Px6BwaW1slD4HzHIGWwXxT3Q3QhwvbRvgE "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔⟦υ⟦ω⟧⟧η
```
Start with an (empty) list of ways of walking and running to get to a distance of `-1` and a list of one (empty) way of walking and running to get to a distance of `0`.
```
Ｆθ⊞η⁺⁺§η±²2⁺§η±¹1
```
Build up the ways of walking and running to get to distances of `1`..`N`.
```
Ｉ⌊Ｅ⊟ηΣＥι×Ｉλ§θμ
```
For each way of walking and running to get to a distance of `N`, calculate the amount of rain, and output the minimum.
]