[Question]
  [
## Introduction:
Inspired by these two SO questions (no doubt from the same class): [print the elements in the subarray of maximum sum without adjacent elements java](https://stackoverflow.com/q/55691215/1682559) and [Maximum sum of non adjacent elements of an array, to be printed](https://stackoverflow.com/q/55688939/1682559).
## Challenge:
Given a list of integers, output a subsequence consisting of non-adjacent elements that have the highest sum. Here some examples:
* `[1,2,3,-1,-3,2,5]` would result in `[1,3,5]` (with a sum of `9`) at the 0-based indices `[0,2,6]`.
* `[4,5,4,3]` would result in either `[4,4]` (with a sum of `8`) at the 0-based indices `[0,2]` or `[5,3]` (also with a sum of `8`) at the 0-based indices `[1,3]`.
* `[5,5,10,100,10,5]` would result in `[5,100,5]` (with a sum of `110`) at either the 0-based indices `[0,3,5]` or `[1,3,5]`.
What's most important about these examples above, the indices containing the elements are at least 2 apart from each other. If we look at the example `[5,5,10,100,10,5]` more in depth: we have the following potential subsequence containing non-adjacent items; with their indices below it; with their sums below that:
```
[[5],[10],[100],[10],[5],[5],[100,5],[10,5],[10,10],[5,5],[5,10],[5,100],[5,5],[5,10],[5,100],[5,10],[5,100,5],[5,100,5],[5,10,5],[5,10,10]]   // non-adjacent subsequences
[[5],[ 4],[  3],[ 2],[1],[0],[  3,5],[ 2,5],[ 2, 4],[1,5],[1, 4],[1,  3],[0,5],[0, 4],[0,  3],[0, 2],[1,  3,5],[0,  3,5],[0, 2,5],[0, 2, 4]]   // at these 0-based indices
[  5,  10,  100,  10,  5,  5,    105,    15,     20,   10,    15,    105,   10,    15,    105,    15,      110,      110,      20,       25]   // with these sums
                                                                                                            ^         ^                        // and these two maximums
```
Since the maximum sums are `110`, we output `[5,100,5]` as result.
## Challenge rules:
* You are allowed to output key-value pairs of the index + value. So instead of `[5,100,5]` you can output `[[0,5],[3,100],[5,5]]` or `[[1,5],[3,100],[5,5]]` as result (or `[[1,5],[4,100],[6,5]]`/`[[2,5],[4,100],[6,5]]` when 1-based indexing is used instead of 0-based).
	+ If you use key-value pairs, they can also be in reverse or random order, since it's clear which values are meant due to the paired index.
	+ Outputting just the indices without values isn't allowed. It should either output the values, or the values/indices as key-value pairs (or two separated lists for 'keys' and 'values' of the same size if key-value pairs are not possible in your language of choice).
* You are allowed to output all possible subsequences with the maximum sum instead of just one.
* As you can see from the examples, the input-list can contain negative and duplicated values as well. You can assume the input-integers are within the range \$[-999,999]\$.
* The output-list cannot be empty and must always contain at least one element (if a list would only contain negative values, a list containing the single lowest negative value would then be output as result - see last two test cases).
* If there is one possible output but for multiple different indices, it's allowed to output both of them even though they might look duplicates. (i.e. the example above, may output `[[5,100,5],[5,100,5]]` for both possible index-combinations).
## Test cases:
```
Input:                   Possible outputs:       At 0-based indices:     With sum:
[1,2,3,-1,-3,2,5]        [1,3,5]                 [0,2,6]                 9
[4,5,4,3]                [4,4]/[5,3]             [0,2]/[1,3]             8
[5,5,10,100,10,5]        [5,100,5]               [0,3,5]/[1,3,5]         110
[10]                     [10]                    [0]                     10
[1,1,1]                  [1,1]                   [0,2]                   2
[-3,7,4,-2,4]            [7,4]                   [1,4]                   11
[1,7,4,-2]               [7]                     [1]                     7
[1,2,-3,-4,5,6,-7]       [2,6]                   [1,5]                   8
[800,-31,0,0,421,726]    [800,726]/[800,0,726]   [0,5]/[0,3,5]/[0,2,5]   1526
[-1,7,8,-5,40,40]        [8,40]                  [2,4]/[2,5]             48
[-5,-18,-3,-1,-10]       [-1]                    [3]                     -1
[0,-3,-41,0,-99,-2,0]    [0]/[0,0]/[0,0,0]       [0]/[3]/[6]/[0,3]/
                                                  [0,6],[3,6]/[0,3,6]    0
```
  
[Answer]
# [Husk](https://github.com/barbuz/Husk), 11 bytes
```
►Σ†!¹mü≈tṖŀ
```
[Try it online!](https://tio.run/##yygtzv7//9G0XecWP2pYoHhoZ@7hPY86O0oe7px2tOH////RFgYGOrrGhjoGQGhiZKhjbmQWCwA "Husk – Try It Online")
## Explanation
```
►Σ†!¹mü≈tṖŀ  Implicit input, say L=[4,5,3,4].
          ŀ  Indices: [1,2,3,4]
         Ṗ   Powerset: [[],[1],[2],[1,2],..,[1,2,3,4]]
        t    Tail (remove the empty list): [[1],[2],[1,2],..,[1,2,3,4]]
     m       For each,
      ü      de-duplicate by
       ≈     differing by at most 1.
             For example, [1,2,4] becomes [1,4].
  †          Deep map
   !¹        indexing into L: [[4],[5],[4],..,[5,4],[4,3]]
►            Maximum by
 Σ           sum: [5,4]
```
[Answer]
# [Haskell](https://www.haskell.org/), 60 bytes
```
snd.([]%)
r%(h:t)=max(r%t)$(r++[h])%drop 1t
r%_=(sum r<$r,r)
```
[Try it online!](https://tio.run/##LY5tboMwDIb/c4r8KFKi2lUSoKXTOMJOQKMqakupBiwKTNrplzoEOZFffz12b@fvxzCErrmEebofeGtykfmc9x@LaEb7x32@iB33@33bG5Hf/Y9jaqGOa8Pn35H5z50HL8JoXxNr2Gjd15Vx51/Twg6sE6zNWKtAQwGoAAtSlQHKlVBBCcWqK9JK0ot/qyuZHJCtimZPNIEayq2Swi3QEY6RegQ8rcmaeFgokGSlpn59TKQ4WgPSAVRIeyhAVa8MOnNbLhMzEvB8jqulMVn4v3WDfc4Bb869AQ "Haskell – Try It Online")
The helper function `%` recursively branches on choosing whether the include the first element and drop the second, or to skip the first element. It takes the maximum of all outcomes, which are tuples whose first element is the sum, and whose second element is the corresponding list which is extracted for the output.
To handle the rule that the empty list is disallowed even if it would have the smallest trick, we do a cute trick of writing `sum r<$r` rather than `sum r`.This makes a list whose elements all are `sum r` and whose length is that of `r`. That way, when we choose the maximum, we prioritize any list over an empty `r`, but otherwise comparisons depend on the first element which is `sum r` .
[Answer]
# [R](https://www.r-project.org/), ~~136~~ 125 bytes
```
function(l,G=unlist(Map(combn,list(y<-seq(a=l)),y,c(function(x)'if'(all(diff(x)>1),l[x],-Inf)),F),F))G[which.max(Map(sum,G))]
```
[Try it online!](https://tio.run/##PU7BboMwDL3vK3arIz1PBMJGpXbHoR32BVUPLFvUSCFdS9Ho1zOHAbIt@fk9P/s6uscdj66P9ubPkQLqfR@D72700fyQPbefERO877j7vlCzD0rhDkvrzqA23m2oCYG@vHOCX7VCOAxH8Ht0In9LqerD78nb01PbDJN517eolTqOjixp5CjAGlxIVyr1kKYGJQyKGZWCdCaZatXobGkgMffi8iKbnMOs7P9ghpWYcKGRSZhcyPx5WU3KCiyXhVrMBbKu0nfpx/VmNk1M8uHtNt0TZvwD "R – Try It Online")
*-6 bytes thanks to [digEmAll](https://codegolf.stackexchange.com/users/41725/digemall)*, who incidentally also [outgolfed me](https://codegolf.stackexchange.com/a/183541/67312).
Returns the shortest subsequence as a `list`, breaking ties on lexicographically first by indices.
Brute-force generates all index subsequences, then `Filter`s for those that are non-adjacent, i.e., where `all(diff(x)>1)`. Then subsets `[` into `l` using these indices, selecting `[[` the first one where the sum is the max (`which.max`).
~~I'm pretty sure this is the first R answer I've ever written that uses `Filter`!~~ sad, `Filter` is ungolfy, no wonder I've never used it...
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 14 bytes
Saved 1 byte thanks to *Kevin Cruijssen*
```
ā<æʒĆ¥≠W}èΣO}θ
```
[Try it online!](https://tio.run/##yy9OTMpM/f//SKPN4WWnJh1pO7T0UeeC8NrDK84t9q89t@P//2gLAwMdXWNDHQMgNDEy1DE3MosFAA "05AB1E – Try It Online")
or as a [Test Suite](https://tio.run/##JU67CsJAEOz9ll24vUdyAUuxtRKLkELBwsrCOoWNYJsvEETxE6xNKot8hD9yzl7Ye8zN7szc8bTdHfZJ7HKxTsN53j@/3XD5PH7X26btX@N91Y7vRKkWsuSIhdgBhWZWewrkyQEFIDFYunNPjB6Ewg1FiUm25DM7PTK0asfqVBCXoCI82AkZlLeYtYU6qCgSIxC0egOyxKzGl3KcmbxUy1Wlcab5Aw)
**Explanation**
```
ā<               # push [0 ... len(input)-1]
  æ              # compute powerset
   ʒ    }        # filter, keep lists where:
      ≠W         # no element is 1 in the
     ¥           # deltas
    Ć            # of the list with the head appended
         è       # index into the input with each
          ΣO}    # sort by sum
             θ   # take the last element
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog) (v2), 14 bytes
```
{~ba~c∋₁ᵐ}ᶠ+ᵒt
```
[Try it online!](https://tio.run/##ATUAyv9icmFjaHlsb2cy//97fmJhfmPiiIvigoHhtZB94bagK@G1knT//1sxLDIsXzEsXzMsNV3/Wg "Brachylog – Try It Online")
Function submission; input from the left, output from the right, as usual. Very slow; a five-element list is probably the maximum for testing on TIO.
```
{~ba~c∋₁ᵐ}ᶠ+ᵒt
 ~b              Prepend an arbitrary element to the input
   a             Take a prefix or suffix of the resulting list
    ~c           Ordered partition into contiguous sublists
      ∋₁         Take the second element
        ᵐ          of each sublist
{        }ᶠ      Find all possible ways to do this
           +ᵒ    Sort by sum
             t   Take the greatest
```
The results we get from prefixes aren't incorrect, but also aren't interesting; all possible results are generated via taking a suffix (which is possibly the list itself, but cannot be empty), but "suffix" is more verbose in Brachylog than "prefix or suffix", so I went with the version that's terser (and less efficient but still correct). The basic idea is that for each element we want in the output list, the partition into contiguous sublists needs to place that element and the element before into the same sublist (because the element is the *second* element of the sublist), so two consecutive elements can't appear in the result. On the other hand, it's fairly clear that any list without two consecutive elements can appear in the result. So once we have all possible candidate lists, we can just take the sums of all of them and see which one is largest.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
ŒPm€2SÞṪ
```
[Try it online!](https://tio.run/##y0rNyan8///opIDcR01rjIIPz3u4c9X///@jDXWMdIx1dA11dI2BLNNYAA "Jelly – Try It Online")
This is a function submission (it's almost usable as a full program, which is what the TIO link does, but the output format is a little weird; when used as a function, though, it just outputs the list of elements from the subsequence).
## Explanation
I found a much terser algorithm (loosely inspired by my previous Brachylog answer), saving 6 bytes over the Jelly and Brachylog answers and 3 bytes over the current leading answer.
```
ŒPm€2SÞṪ
ŒP         On the set of all subsequences of {the input},
  m 2        remove every second element of
   €         each subsequence,
      ÞṪ     then {return} the resulting subsequence with the maximal
     S       sum
```
The basic idea is that we don't look for the subsequence we want directly; rather, we find a subsequence with an additional element inserted in between each of the elements we want. This is always possible if the elements of the subsequence we want are not adjacent in the original list (because there'll always be at least one in between to insert), and never possible if the elements of the subsequence we want are adjacent in the original list. So all we have to do is look at all the subsequences of the input, then take alternating elements from them, to get a list of all the non-adjacent-item subsequences of the input.
This algorithm will return many of the non-adjacent-item subsequences more than once, but that doesn't matter, because we're just looking for a maximal element, and repeating elements of the set we're taking a maximum of has no influence on the maximum.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~16~~ 14 bytes
```
JŒPḊf’$ÐḟịµSÞṪ
```
[Try it online!](https://tio.run/##JY6/CsIwEMb3PkWHjneQpH9dfAAnwUlKRx2kL@BWXAq6SCcF/@ziKrS4Gfog6YvEu4RLwi9f7r4vu01d761djN3S9Mft1FwjfTb903xPv89KP8zwsmNnhgtMzS3EeTg1d9Ctk6JAt9Phvba2DEoJCmJACRgTpRUEZQIpJBAzpoRS0OLtX6VwJ1Ax0FhO3agg8bq/eVbsiuyXAeasFeSEsQRBlSjqVplz4bkCkIJJdwnEKAtnQJ/zqcL78TjOZhwqqqD6Aw "Jelly – Try It Online")
Thanks to @EriktheOutgolfer for saving 2 bytes!
[Answer]
# JavaScript (ES6), ~~138 132 130 129~~ 126 bytes
Outputs key-value pairs.
```
a=>a.reduce((a,x,i)=>[...a,...a.map(y=>[[x,i],...y])],[[]]).map(m=a=>a.some(s=p=([v,i])=>p-(s=~~s+v,p=i)<2)|s<m||(r=a,m=s))&&r
```
[Try it online!](https://tio.run/##bVHRjoIwEHy/r/DJtLktlAKKifVHSB8a5S5eRAi9M2di/HVuCppTaktLuzO7O7v9sifrtt2@/RbHZlf1H7q3emOjrtr9bCvGLP3SnutNGUWRJb9FtW3ZGZYSiPGms@GGytIYPmC1HiK4pq6Y061m5QlExGgF7terez9Rq/d8rfjFrevLhXXaUq0d5/N512@bo2sOVXRoPtkHKxNSlJJISKQ45WaGwfksjmeAUhjeJg4Z5ZRROhDv4@aQUWbiMgc4dcrhlEh8fj1nyQdrmCeRTyke8wAK2IRpXrMBTOkodokqhILiCR32F9FHtgmjL1@QlW@m8I1akFiaf7KiRUAvUL1IE5KYmUImtTA3uof8NR5O4zmoxGsrSOBR4C8fO1v4e8DP8djFIBBvPjb5xhdhn@RYiVcnVivfL3kXJyELosYd//4P "JavaScript (Node.js) – Try It Online")
### Step 1
We first compute the powerset of the input with \$[value, index]\$ pairs.
```
a.reduce((a, x, i) => // for each value x at position i:
  [                   //   update a[] to a new array consisting of:
    ...a,             //     all previous entries
    ...a.map(y =>     //     for each value y in a[]:
      [[x, i], ...y]  //       append [x, i], followed by all original entries
    )                 //     end of map()
  ],                  //   end of new array
  [[]]                //   start with a = [[]]
)                     // end of reduce()
```
### Step 2
We then look for the maximum sum \$m\$ among these sets, discarding sets with at least two adjacent elements. The best set is stored in \$r\$.
```
.map(m =              // initialize m to a non-numeric value
  a =>                // for each entry a[] in the powerset:
  a.some(s = p =      //   initialize s and p to non numeric values
    ([v, i]) =>       //   for each value v and each index i in a[]:
    p - (             //     compute p - i
      s = ~~s + v,    //     add v to s
      p = i           //     update p to i
    ) < 2             //     if p - i is less than 2, yield true
  ) |                 //   end of some()
  s < m ||            //   unless some() was truthy or s is less than m,
  (r = a, m = s)      //   save a[] in r[] and update m to s
) && r                // end of map(); return r[]
```
[Answer]
## Haskell, ~~81~~ 80 bytes
```
snd.maximum.map((,)=<<sum).tail.f
f(a:b:c)=f(b:c)++map(a:)(f c)
f a=[]:map(:[])a
```
[Try it online!](https://tio.run/##LU5RbsMgDP3PKfgE1Y6AJG2KyhF2giyaWDa6aCFCSyvt9GMmRAb5@T372V9u@/5clhTta9rWjzq43zk8A@XIOQh7u23PIOqHm5faV547824mYT3P6XTKbc4I7tkkKs@cHUaTOTOMwqXg5pVZRsTLG@PxZ14frGZRsKFigwINDaACbAh1IxDXQgctNDvuCCtJL/9DV7IkoNgRzV5oAjW0h1LKo9DZHLPrGfCykz35YaNAUrSa@vW5OOXRHpAOIKHsoQJVv3vQmcdyWTyzA16vebUcxyr9TX5x9y3hFOM/ "Haskell – Try It Online")
`f` builds all valid subsequences by either skipping the next element (`f(b:c)`) or using it and skipping the next (`map(a:)(f c)`) and recursively work on the rest. For the result, build all subsequences (`f`), drop the empty subsequence (which occurs first in the list: `tail`), make pairs `(<sum>,<subsequence>)` (`map((,)=<<sum)`), find the maximum (pairs are compared in lexicographical order) -> `maximum`) and drop the sum (`snd`).
Edit: -1 byte thanks to @Lynn. 
[Answer]
# [J](http://jsoftware.com/), 47 bytes
```
>@{:@(<@#~/:+/@#~)1(-#~0=1 1+/@E."1-)[:i.&.#.=~
```
[Try it online!](https://tio.run/##RVDLTsMwELz7K0a1RBNBXK9jN6lFUASCE@LAtVJ9qKgoFz4AkV8P65eIFXl2xrsz9te6UdsLJo8t7qDh@e8Unt5fX9aH@cfPzf0sl52/3fHWUtPJRU8E4vpZbahrj/6qbpRU07K2Qrw9KnycP7/RHL3086@ar8qcZAtCDydE0hJG53FhaLgIhNAzcll3TCXVMrToK0ta1z6XysTwVvoYTXGmrjZUTXhlbuB5iWO/iIOBrUrqrWz@smSw/0/LjSHm2iMMWR45xGDKkViEnvgVNayhKJRTsLpYR5MRwUXGlrBMRn8mA43JhN@k3iTfS2fvODscDjGkFusf "J – Try It Online")
*-7 bytes thanks to FrownyFrog*
# original
# [J](http://jsoftware.com/), 54 bytes
```
[:(>@{:@/:+/&>)]<@#~"1[:(#~0=1 1+/@E."1])[:#:@}[[email protected]](/cdn-cgi/l/email-protection)^#
```
[Try it online!](https://tio.run/##VVBBTsMwELznFaNEoo1KHa9jN6lFKgsEJ8SBa1V8QFTAhQcg@vWwa8dCZBV5d2bHM8nnXKvVGZPHCtfQ8PxuFe6eHx/mo18fwrcPnd90V4f2dBOaS02MNhc9EWjThXtV06k9@saHHxU@lHlp5raqnm4V3l7fv7D@R7Ug9HBVlbjUY@tx5tbwEAmx585l3nIl1vKaRZ9RB9K66FwaE8LHouNukjt1saFiwpWxoVzNftJHA1uYpC1ofjJlsPtLy8IouXaIQ6ZHDqExmGVJxtgTBLSGhFj2YPViLjYjohPELnEZlAQMRhqTDf@V8i06VRLrHEEM4n4vWXU1/wI "J – Try It Online")
[Answer]
# T-SQL, ~~122~~ ~~119~~ 118 bytes
Input is a table variable.
This query picks all elements from the table variable, combining these with all non-adjacent elements with higher position values and show the text generated for the highest sum of these values.
```
WITH C(y,j,v)as(SELECT*,x*1FROM @
UNION ALL
SELECT y+','+x,i,v+x
FROM @ JOIN C ON~-i>j)SELECT
TOP 1y FROM C ORDER BY-v
```
**[Try it online](https://data.stackexchange.com/stackoverflow/query/1032334/maximum-summed-powersets-with-non-adjacent-items)** ungolfed
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 144 bytes
```
If[Max[a=#]>(d=Max[m=Tr/@(g=a[[#]]&/@Select[Subsets[Range[x=Length@#],{2,x}]&@#,FreeQ[Differences@#,1]&]&@a)]),{Max@a},g[[#]]&@@@Position[m,d]]&
```
[Try it online!](https://tio.run/##XZBRa4MwEMff/RQFQVq4UBO1tQ8ZeRiDwQbd2reQh8xGK0wLmoEgfnZ3mS8zXAKX313@908abe@m0bYu9Fzy@bWU73qQmofqaXvjLm/4tduLbcW1lKFS0V5czLcprLz8fPXG9vJTt5WRA38zbWXvIlQwMhgmFYkQXjpjPuRzXZamM21hemRURVjTO7WDEQcIPUG1SAshzo@@tvWjlQ3ckMznrm7tRmxKOVJgkAChQBLMskkF/4opZJBCsoYZQhrjctu/QWPvDBhrhIOOqEoYpH7vwn3KnDfivByAHNfVHF2QhEKMkTJUYAdvmlPNgeBDsMNzh5TQ/E8eP8D3Hi9znTg5nZxh1xAE8/wL "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# Pyth, 19 bytes
```
esDm@LQdtf!q#1.+TyU
```
Try it online [here](https://pyth.herokuapp.com/?code=esDm%40LQdtf%21q%231.%2BTyU&input=%5B800%2C-31%2C0%2C0%2C421%2C726%5D&debug=0), or verify all the test cases at once [here](https://pyth.herokuapp.com/?code=esDm%40LQdtf%21q%231.%2BTyU&test_suite=1&test_suite_input=%5B1%2C2%2C3%2C-1%2C-3%2C2%2C5%5D%0A%5B4%2C5%2C4%2C3%5D%0A%5B5%2C5%2C10%2C100%2C10%2C5%5D%0A%5B10%5D%0A%5B1%2C1%2C1%5D%0A%5B-3%2C7%2C4%2C-2%2C4%5D%0A%5B1%2C7%2C4%2C-2%5D%0A%5B1%2C2%2C-3%2C-4%2C5%2C6%2C-7%5D%0A%5B800%2C-31%2C0%2C0%2C421%2C726%5D%0A%5B-1%2C7%2C8%2C-5%2C40%2C40%5D%0A%5B-5%2C-18%2C-3%2C-1%2C-10%5D%0A%5B0%2C-3%2C-41%2C0%2C-99%2C-2%2C0%5D&debug=0).
```
esDm@LQdtf!q#1.+TyUQ   Implicit: Q=eval(input())
                       Trailing Q inferred
                  UQ   Generate range [0-len(Q))
                 y     Take the powerset of the above
         f             Filter keep elements of the above, as T, using:
              .+T        Take differences of consecutive elements of T
           q#1           Keep those differences equal to 1
          !              Logical NOT - empty lists evaluate to true, populated ones to false
                       Result of the filter is those sets without consecutive numbers
        t              Drop the first element (empty set)
   m                   Map the remaining sets, as d, using:
     L d                 For each element of d...
    @ Q                  ... get the element in Q with that index
 sD                    Order the sets by their sum
e                      Take the last element, implicit print
```
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 24 bytes
```
e:w;ċz⟨ọ1>¦ẏ⟩⁇‼⁇E‡ev2%Σ⌠
```
[Try it online!](https://tio.run/##S0/MTPz/P9Wq3PpId9Wj@Sse7u41tDu07OGu/kfzVz5qbH/UsAdIuj5qWJhaZqR6bvGjngX//0cbKhgpGCvoGiroGgNZprEA "Gaia – Try It Online")
Ugh, `E‡` does some weird stuff...according to the documentation, it *should* do something like "given length `i` set of lists `X` and length `j` set of indices `Y`, return `X[i][Y[j]]`", but instead returns `[X[i][Y[j]] X[i][Y[-j]]` where negative indexing represents the complement, so we have to do `ev2%` to extract only the ones we want.
```
e				| eval as a list l
 :				| dup
  w				| wrap as a list
   ;				| push l again
    ċ				| push [1..len(l)]
     z				| push all subsets of [1..len(l)] -- index powerset.
      ⟨      ⟩⁇			| filter this for:
       ọ			| deltas
        1>¦			| are greater than 1
           ẏ			| all (all deltas greater than 1)
	       ‼⁇		| filter for non-empty lists
		 E‡		| table extract elements. Given l and index set i, this pushes
				| [l[i] l[setdiff(1..l,i)]] for some reason
		   ev2%		| get the l[i] only by unlisting, reversing, and taking every other element
		       Σ⌠	| Get the one with the maximum sum
```
[Answer]
# [R](https://www.r-project.org/), ~~108~~ 107 bytes
```
function(v,M=-Inf){for(j in J<-seq(a=v))for(i in combn(J,j,,F))if(all(diff(i)>1)&sum(v[i])>sum(M))M=v[i]
M}
```
[Try it online!](https://tio.run/##lZLfa8IwEMff/SsCwkjgwpL@0AqrDwMHyrrJqk@SB@cWiGhlOn0Z@9u7u1Y7Z@3DkrYkl376/d5dt7mNc7vPFp9uk/EDJLEcZlZ82c2WL5nL2OhO7t4/@Dw@CEFBR8HFZv2a8REsAR6EcJbPVyv@5qzlTvS1uNnt1/wwc0b0aZUIkcS0bSXfeZsNn8bTCbs@xs9pOrx/HLCXQTp9nKSttvzXaFm@4Bo88EFqkD6uQiHKb7cZm2k8CE1NtsACCCEA//T6aRAWQGBuZyH4po6FiGmFF91/1cIiWtMrTapLoV@TylyrzTE3nHWyzE2bJgwr0cXkpAfBOUwYxk2zWkldCBbYVY@sagAqSqpoB2T3iBPmQadRLcJiSV@Dwhl4qO11iCSMjnCLTaBVua5yI5cRSOwecuq8ARHuTVNJQvxFosIn/ilVOwiTurkBqsyMXMpejyqqTiYV2kNz5RMq4fwH "R – Try It Online")
-1 thanks to @Giuseppe
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~70~~ 63 bytes
```
MaximalBy[Select[q=Rest@Subsets@#,!FreeQ[q,#~Riffle~_]&],Tr,1]&
```
[Try it online!](https://tio.run/##JU/LasMwELz7L0oghzJLJdlOnIPB5NBboU16M6YoQaYGOxBbhRbj/Lq7K7GSGO3OQxqs/3aD9d3Vrm25vtnfbrD98a8@u95dfX0vT27y1fnnMjk/VRs8vY7OfdR3bB6nrm179/hqtg0@R@hmu3omT@WczBoGKUiDUkb5gmTOkCNDKjBnqBUv2XGqVTjBJYBle2aTQRb78RaxEVcSvx1oL72CnSjVUFyZYbbZBRfRFSAO5n5IYEy6CAb8uJiqop/I6XCQULUkS/I@djdfPbcvVfjW@g8 "Wolfram Language (Mathematica) – Try It Online")
High-level search
```
          Select[q=Rest@Subsets@#,                     ]        (*choose nonempty subsets of the input such that*)
                                  !FreeQ[q,          ]&         (*there exists a subset of the input which matches*)
                                           #~Riffle~_           (*this list, with an item inserted between adjacent elements*)
MaximalBy[                                              ,Tr,1]& (*and return one with the greatest total*)
```
`,1` is required so as not to inadvertently return invalid sets (otherwise, for example, an input of `{1,1,1}` would result in an output of `{{1,1},{1,1},{1,1}}`)
[Answer]
# [Haskell](https://www.haskell.org/), ~~300~~ 168 bytes
```
import Data.List
h[]=1>2
h(x:y)=fst$foldl(\a c->((fst a)&&(c-snd a>1),c))(1<2,x)y
z=snd.last.sortOn fst.map((,)=<<sum.snd).filter(h.fst).map unzip.subsequences.zip[0..]
```
[Try it online!](https://tio.run/##FYzBboMwEETvfMUeomhXMitMq6aqMKceK/UDKAeXGGHVOJQ1UsLPU1dze/NmJis/LoTj8PNyWxO822T5w0sqpq43uq2LCe9vDzKjpNN4C9eAXxaGskXMBCydzziUEq9gW01qIELd1OpOj2I3GXOwkljy9WeEvODZLoiKTNPINnM2iEcfkltx4tzTvwBb3P3Csn2L@91cHJxwBl3F3B@z9REMLKuPCU6wQ/daVap80qrKea61utQv/fEH "Haskell – Try It Online")
-132 bytes thanks to all the feedback from [@nimi](https://codegolf.stackexchange.com/users/34531/nimi) :)
---
[Original](https://tio.run/##TY/BboMwEETv/oo9WJGtmgholVZR4VBVPfUPCFI2xIATYyh2JMPPU5NIVbWX1cybHW2L9iq1XhbVDf3o4BMdbr@VdeS/8HUzlVO9IXVRZkVJavDZrAbwRbzdamka14IvSfNwG@b3E89YhwPU1oEX62bNGTzfNzCRNnBJnpL2AQaG1r0@a3ZAqKKcsTWFfLNhVbTGME@4qDhnyXsqPJ/IJfTXSjs5sgNDceJR3sKJe3INRij7U9n9bsKeOIq7xAOkAxTOUo2h2IYnPyZW9d2Aozz25hjKAzQDZppe6YU21N5OVv7cpKmkpTXg0qEykMEwKuOAwgzFWxyL6DkRcZiXNBGv6a5cfgE "Haskell – Try It Online")
### Ungolfed (original)
```
import Data.List
import Data.Function
f :: [Int] -> [(Int, Int)] -- attach indices for later use
f [] = []
f xs = zip xs [0..length xs]
g :: [[(Int, Int)]] -> [([Int], [Int])] -- rearrange into list of tuples
g [] = []
g (x:xs) = (map fst x, map snd x) : g xs
h :: [Int] -> Bool -- predicate that checks if the indices are at least 2 apart from each other
h [] = False
h (x:xs) = fst $ foldl (\acc curr -> ((fst acc) && (curr - snd acc > 1), curr)) (True, x) xs
j :: [([Int], [Int])] -> [([Int], [Int])] -- remove sets that don't satisfy the condition
j xs = filter (\(elements, indices) -> h indices) xs
k :: [([Int], [Int])] -> [(Int, ([Int], [Int]))] -- calculate some of elements
k xs = map (\(elements, indices) -> (foldl1 (+) elements, (elements, indices))) xs
l :: [(Int, ([Int], [Int]))] -> ([Int], [Int]) -- grab max
l xs = snd $ last $ sortBy (compare `on` fst) xs
z -- put things together
```
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 46 bytes
```
≔⟦υ⟧ηＦθ«≔υζ≔Ｅη⁺κ⟦ι⟧υ≔⁺ζηη»≔Φ⁺υηιη≔ＥηΣιζＩ§η⌕ζ⌈ζ
```
[Try it online!](https://tio.run/##VY1NC4JAEEDP@Sv2uAvjwaSTpwiEDoLQcdnDopZDutZ@hBj99s1Ng5rTDO/xpmqlrgbZeb83Bi@KcieAtCyLzoMm9M7IM9qsyAGZZvA9C3mjLZCyc4ZegXAUjAFxP8YHTSG3JF/RCnLsbKMX7haOq/MfP7meYsiGx6VGZelBGkv39qjqZgxKjqoOTwo5Yj/rEwuTec95AltIIU4gTudtJ4SPH90b "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔⟦υ⟧η
```
The variable `u` is predefined with an empty list. This is put in a list which is assigned to `h`. These variables act as accumulators. `u` contains the sublists that include the latest element of the input `q` while `h` contains the sublists that do not (and therefore are suitable for appending the next element of the input).
```
Ｆθ«
```
Loop over the elements of the input.
```
≔υζ
```
Save the list of sublists that contain the previous element.
```
≔Ｅη⁺κ⟦ι⟧υ
```
Take all of the sublists that do not contain the previous element, append the current element, and save the result as the list of sublists that contain the current element. (I don't use `Push` here as I need to clone the list.)
```
≔⁺ζηη»
```
Concatenate both previous sublists into the new list of sublists that do not contain the current element.
```
≔Φ⁺υηιη
```
Concatenate the sublists one last time and remove the original empty list (which Charcoal can't sum anyway).
```
≔ＥηΣιζ
```
Compute the sums of all of the sublists.
```
Ｉ§η⌕ζ⌈ζ
```
Find an index of the greatest sum and output the corresponding sublist.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-h`](https://codegolf.meta.stackexchange.com/a/14339/), 22 bytes
```
Êo à k_mÄ øZÃm!gU
fÊñx
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVFo&code=ym8g4CBrX23EIPhaw20hZ1UKZsrxeA&input=Wy01LC0yLC0xLC02LC05XQ)
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-h`](https://codegolf.meta.stackexchange.com/a/14339/), 21 bytes
Ever have one of those challenges where you completely forget how to golf?!
```
ð¤à fÊk_än ø1Ã®mgUÃñx
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWg&code=8KTgIGbKa1/kbiD4McOubWdVw/F4&input=Wy01LC0xOCwtMywtMSwtMTBdCi1R)
```
ð¤à fÊk_än ø1Ã®mgUÃñx     :Implicit input of array U
ð                         :Indices of elements that return true when
 ¤                        :  Converted to a base-2 string (to account for 0s)
  à                       :Combinations
    f                     :Filter by
     Ê                    :  Length (to remove the empty combination)
      k_                  :Remove elements that return true
        än                :  Deltas
           ø1             :  Contains 1
             Ã            :End remove
              ®           :Map
               m          :  Map
                gU        :    Index into U
                  Ã       :End map
                   ñ      :Sort by
                    x     :  Sum
                          :Implicit output of last element
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~63~~ ~~70~~ 65 bytes
```
f=lambda a:a and max([a[:1],a[:1]+f(a[2:]),f(a[1:])],key=sum)or a
```
[Try it online!](https://tio.run/##XVBda8MwDHxef4UeEyaD7TgfDfSXGD94dGFlS1raDtZfn@rkZQ8DW5zOp5Osy@P@cV78uk6Hrzy/HTPlUe5ypDn/VDHH0SXW@DpVOfox1QzgBCT@fH8cbt9zfb5SXidEphudFopVdNxzSEx9zYSMPFPDZASZRrNWXvf6GiRhktgINSjVKuUsri0Aeuds8bNI7OaNI4TXHPa92hnpErRqE278v8FQYsoUnaD@b4wBzU0jKqsneJj4Dqat70q/4juIEL@ACtOF4gDOuOG3B36vsxtXp3H3crmeljvWJksVuSyzAgJcnw "Python 2 – Try It Online")
5 bytes thx to [ArBo](https://codegolf.stackexchange.com/users/82577/arbo)
]