# [Stax](https://github.com/tomtheisen/stax), <s>27</s> 25 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax) äO⌐┤‼èüûGæo♠▲L╛CaëÖ¼M5♪╧! [Run and debug it](https://staxlang.xyz/#p=844fa9b4138a819647916f061e4cbe43618999ac4d350dcf21&i=[1+6+9+4+6+9+7+6+4+4+9+8+7]%0A[10+15+20+10+20+10+10]%0A[9+9+9+9+8+1+8]%0A[1+6+9+4+6+9+7+6+4+4+9+8+7]%0A[1+2+3+2+1]%0A[1]%0A[1+1]&a=1&m=2) Output is separated by newlines. Unpacked, ungolfed, and commented, it looks like this. ``` 0|S Pre- and post-pend a 0 to the input 3B Get all overlapping sub-arrays of length 3 { Begin a new code block for mapping :A Get indices of all maxima {1k Reduce array with block that pushes a literal 1; For singleton arrays this will produce the array element. For multi-element arrays this will produce 1. m Execute the block map. { Begin a block to partition the array via pair-wise predicate Adjacent values will be pushed prior to executing the block; call them a and b *1= a * b == 1 _< a < b + add two conditions; effectively a logical or }) perform block-based partition xs re-tuck the input under the top of the stack m iterate over array using the rest of the program and output implicitly % get length :/ split array into two parts at specified position s|+ sum of the first part ``` [Run this one](https://staxlang.xyz/#c=0%7CS++%09Pre-+and+post-pend+a+0+to+the+input%0A3B+++%09Get+all+overlapping+sub-arrays+of+length+3%0A%7B++++%09Begin+a+new+code+block+for+mapping%0A++%3AA+%09Get+indices+of+all+maxima%0A++%7B1k%09Reduce+array+with+block+that+pushes+a+literal+1%3B%0A+++++%09For+singleton+arrays+this+will+produce+the+array+element.%0A+++++%09For+multi-element+arrays+this+will+produce+1.%0Am++++%09Execute+the+block+map.%0A%7B++++%09Begin+a+block+to+partition+the+array+via+pair-wise+predicate%0A+++++%09Adjacent+values+will+be+pushed+prior+to+executing+the+block%3B+call+them+a+and+b%0A++*1%3D%09a+*+b+%3D%3D+1%0A++_%3C+%09a+%3C+b%0A++%2B++%09add+two+conditions%3B+effectively+a+logical+or%0A%7D%29+++%09perform+block-based+partition%0Axs+++%09re-tuck+the+input+under+the+top+of+the+stack%0Am++++%09iterate+over+array+using+the+rest+of+the+program+and+output+implicitly%0A++%25++%09get+length%0A++%3A%2F+%09split+array+into+two+parts+at+specified+position%0A++s%7C%2B%09sum+of+the+first+part&i=[1+6+9+4+6+9+7+6+4+4+9+8+7]%0A[10+15+20+10+20+10+10]%0A[9+9+9+9+8+1+8]%0A[1+6+9+4+6+9+7+6+4+4+9+8+7]%0A[1+2+3+2+1]%0A[1]%0A[1+1]&m=2)