[Question]
  [
Consider a piece of string (as in "rope", not as in "a bunch of characters"), which is folded back and forth on the real line. We can describe the shape of the string with a list of points it passes through (in order). For simplicity, we'll assume all of those points are integers. 
Take as an example `[-1, 3, 1, -2, 5, 2, 3, 4]` (note that not each entry implies a fold):
![enter image description here](https://i.stack.imgur.com/tLyo8.png)
The string extending along the vertical direction is only for visualisation purposes. Imagine the string all flattened onto the real line.
Now here is the question: what is the greatest number of pieces this string can be cut into with a single cut (which would have to be vertical in the above picture). In this case, the answer is *6* with a cut anywhere between `2` and `3`:
![enter image description here](https://i.stack.imgur.com/n640M.png)
To avoid ambiguities, the cut *has* to be performed at a non-integer position.
## The Challenge
Given a list of integer positions a string is folded through, you're to determine the greatest number of pieces the string can be cut into with a single cut at a non-integer position.
You may write a full program or a function. You may take input via STDIN, command-line argument, prompt or function parameter. You may write output to STDOUT, display it in a dialog box or return it from the function.
You may assume that the list is in any convenient list or string format.
The list will contain at least **2** and no more than **100** entries. The entries will be integers, each in the range **-231 ≤ pi < 231**. You may assume that no two consecutive entries are identical.
Your code must process any such input (including the test cases below) in less than 10 seconds on a reasonable desktop PC.
## Test Cases
All test cases are simply input followed by output.
```
[0, 1]
2
[2147483647, -2147483648]
2
[0, 1, -1]
3
[1, 0, -1]
2
[-1, 3, 1, -2, 5, 2, 3, 4]
6
[-1122432493, -1297520062, 1893305528, 1165360246, -1888929223, 385040723, -80352673, 1372936505, 2115121074, -1856246962, 1501350808, -183583125, 2134014610, 720827868,  -1915801069, -829434432, 444418495, -207928085, -764106377, -180766255, 429579526,  -1887092002, -1139248992, -1967220622, -541417291, -1617463896, 517511661, -1781260846,  -804604982, 834431625, 1800360467, 603678316, 557395424, -763031007, -1336769888,  -1871888929, 1594598244, 1789292665, 962604079, -1185224024, 199953143, -1078097556, 1286821852, -1441858782, -1050367058, 956106641, -1792710927, -417329507, 1298074488,  -2081642949, -1142130252, 2069006433, -889029611, 2083629927, 1621142867, -1340561463,  676558478, 78265900, -1317128172, 1763225513, 1783160195, 483383997, -1548533202,  2122113423, -1197641704, 319428736, -116274800, -888049925, -798148170, 1768740405,  473572890, -1931167061, -298056529, 1602950715, -412370479, -2044658831, -1165885212,  -865307089, -969908936, 203868919, 278855174, -729662598, -1950547957, 679003141,  1423171080, 1870799802, 1978532600, 107162612, -1482878754, -1512232885, 1595639326,  1848766908, -321446009, -1491438272, 1619109855, 351277170, 1034981600, 421097157,  1072577364, -538901064]
53
[-2142140080, -2066313811, -2015945568, -2013211927, -1988504811, -1884073403, -1860777718,  -1852780618, -1829202121, -1754543670, -1589422902, -1557970039, -1507704627, -1410033893,  -1313864752, -1191655050, -1183729403, -1155076106, -1150685547, -1148162179, -1143013543,  -1012615847, -914543424, -898063429, -831941836, -808337369, -807593292, -775755312, -682786953, -679343381, -657346098, -616936747, -545017823, -522339238, -501194053,  -473081322, -376141541, -350526016, -344380659, -341195356, -303406389, -285611307, -282860017, -156809093, -127312384, -24161190, -420036, 50190256, 74000721, 84358785,  102958758, 124538981, 131053395, 280688418, 281444103, 303002802, 309255004, 360083648,  400920491, 429956579, 478710051, 500159683, 518335017, 559645553, 560041153, 638459051,  640161676, 643850364, 671996492, 733068514, 743285502, 1027514169, 1142193844, 1145750868,  1187862077, 1219366484, 1347996225, 1357239296, 1384342636, 1387532909, 1408330157,  1490584236, 1496234950, 1515355210, 1567464831, 1790076258, 1829519996, 1889752281,  1903484827, 1904323014, 1912488777, 1939200260, 2061174784, 2074677533, 2080731335, 2111876929, 2115658011, 2118089950, 2127342676, 2145430585]
2
```
  
[Answer]
# APL, ~~16~~ 14 bytes
```
1+⌈/+/2≠/∘.≤⍨⎕
```
Thanks to @ngn for saving 2 bytes.
The `⎕` is actually a box character, not a missing-font error. You can try the program at [tryapl.org](http://tryapl.org/), but since `⎕` is not fully supported there, you have to replace it by the input value:
```
    1+⌈/+/2≠/∘.≤⍨ ¯1 3 1 ¯2 5 2 3 4
6
```
### Explanation
The program is best explained with the example input `s = ¯1 3 1 ¯2 5 2 3 4`, which is taken from STDIN by `⎕`. First, we compute the `≤`-outer product of `s` with itself using `∘.≤⍨`. This results in a Boolean matrix whose `i`th row tells which elements of `s` are less than or equal to `s[i]`:
```
1 1 1 0 1 1 1 1
0 1 0 0 1 0 1 1
0 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1
0 0 0 0 1 0 0 0
0 1 0 0 1 1 1 1
0 1 0 0 1 0 1 1
0 0 0 0 1 0 0 1
```
The occurrences of `0 1` and `1 0` on row `i` mark places where the string passes over the point `s[i] + 0.5`. We match on these on every row using `2≠/`, "reduce 2-sublists by `≠`":
```
0 0 1 1 0 0 0
1 1 0 1 1 1 0
1 0 1 1 0 0 0
0 0 0 0 0 0 0
0 0 0 1 1 0 0
1 1 0 1 0 0 0
1 1 0 1 1 1 0
0 0 0 1 1 0 1
```
What remains is to take the sums of the rows with `+/`
```
2 5 3 0 2 3 5 3
```
and one plus the maximum of these with `1+⌈/`:
```
6
```
The result is automatically printed to STDOUT in most APL implementations.
[Answer]
# Python, ~~88~~ ~~75~~ 73 bytes
```
lambda x:max(sum((a+.5-m)*(a+.5-n)<0for m,n in zip(x,x[1:]))for a in x)+1
```
Just a straightforward lambda
---
Just to show another approach:
# Pyth, ~~28~~ 27 bytes
```
heSmsmq@S+k(d)1dC,QtQm+b.5Q
```
This one's roughly equivalent to
```
lambda x:max(sum(a+.5==sorted(n+(a+.5,))[1]for n in zip(x,x[1:]))for a in x)+1
```
applied to the input list from STDIN. Try it on the [online interpreter](https://pyth.herokuapp.com/).
[Answer]
# [Pyth](https://github.com/isaacg1/pyth): ~~31~~ ~~30~~ ~~29~~ ~~28~~ ~~24~~ 23 character (Python 68 chars)
```
heSmsm&<hSkdgeSkdC,tQQQ
```
Try it here: [Pyth Compiler/Executor](https://pyth.herokuapp.com/)
It expects a list of integers as input 
`[-1, 3, 1, -2, 5, 2, 3, 4]`
It's a straightforward translation of my Python program:
```
lambda s:1+max(sum(min(a)<i<=max(a)for a in zip(s,s[1:]))for i in s)
```
## Old solution: Pyth 28 char
Just for archiving reasons. 
```
heSmsm<*-dhk-dek0C,tQQm+b.5Q
```
A corresponding Python code would be:
```
f=lambda x:1+max(sum((i-a)*(i-b)<0for a,b in zip(x,x[1:]))for i in [j+.5 for j in x])
```
[Answer]
# CJam, ~~36 34 33~~ 30 bytes
```
q~[__(+]zW<f{f{1$+$#1=}1b}$W=)
```
I believe that there is a better algorithm out there in the wild. Still, this works under the limit required for all test cases (even on the online compiler)
Input is like
```
[-2142140080 -2066313811 -2015945568 -2013211927 -1988504811 -1884073403 -1860777718  -1852780618 -1829202121 -1754543670 -1589422902 -1557970039 -1507704627 -1410033893  -1313864752 -1191655050 -1183729403 -1155076106 -1150685547 -1148162179 -1143013543  -1012615847 -914543424 -898063429 -831941836 -808337369 -807593292 -775755312 -682786953 -679343381 -657346098 -616936747 -545017823 -522339238 -501194053  -473081322 -376141541 -350526016 -344380659 -341195356 -303406389 -285611307 -282860017 -156809093 -127312384 -24161190 -420036 50190256 74000721 84358785  102958758 124538981 131053395 280688418 281444103 303002802 309255004 360083648  400920491 429956579 478710051 500159683 518335017 559645553 560041153 638459051  640161676 643850364 671996492 733068514 743285502 1027514169 1142193844 1145750868  1187862077 1219366484 1347996225 1357239296 1384342636 1387532909 1408330157  1490584236 1496234950 1515355210 1567464831 1790076258 1829519996 1889752281  1903484827 1904323014 1912488777 1939200260 2061174784 2074677533 2080731335 2111876929 2115658011 2118089950 2127342676 2145430585]
```
Output (for above case) is
```
2
```
**How it works**
```
q~[__(+]zW<f{f{1$+$#1=}1b}$W=)
q~                                "Evaluate input string as array";
  [__                             "Put two copies of it in an array";
     (+]                          "Shift first element of second copy to its end";
        z                         "Zip together the two arrays. This creates";
                                  "pair of adjacent elements of the input.";
         W<                       "Remove the last pair";
           f{            }        "For each element of input array, take the zipped";
                                  "array and run the code block";
             f{       }           "For each element of the zipped array along with";
                                  "the current element from input array, run this block";
               1$+                "Copy the current number and add it to the pair";
                  $#              "Sort the pair and find index of current number";;
                    1=            "check if index == 1 for a < I <= b check";
                       1b         "Get how many pairs have this number inside of them";
                          $W=)    "Get the maximum parts the rope can be cut into";
```
Now suppose the input array is `[-1 3 1 -2 5 2 3 4]`, the zipping steps look like:
```
[-1 3 1 -2 5 2 3 4] [[-1 3 1 -2 5 2 3 4] [-1 3 1 -2 5 2 3 4]
[-1 3 1 -2 5 2 3 4] [[-1 3 1 -2 5 2 3 4] [3 1 -2 5 2 3 4 -1]
[-1 3 1 -2 5 2 3 4] [[-1 3] [3 1] [1 -2] [-2 5] [5 2] [2 3] [3 4]]]
```
The second array on the last line is the folds of the string.
Now we iterate over `[-1 3 1 -2 5 2 3 4]` and calculate the number of sets each of them lie in. Get the maximum out of that number, increment it and we have our answer.
[Try it online here](http://cjam.aditsu.net/)
[Answer]
# Matlab (123)(97)(85)
Yay, finally a use for *XNOR*=) I am sure it can be golfed down way more.
But honestly I am a little embarassed that MatLab is becoming the language I know best =/
Approximate runtime is `O(n^2)`.
**EDIT2:**
```
a=input();v=2:nnz(a);disp(max(arrayfun(@(e)sum(~xor(a(v-1)<e,e<a(v))),sort(a)-.5))+1)
```
**EDIT:** New more golfed version (including hints from @DennisJaheruddin, thanks!)
```
a=input();c=sort(a)-.5;n=0;v=2:nnz(c);for e=c;n=[n,sum(~xor(a(v-1)<e,e<a(v)))];end;disp(max(n)+1)
```
Old version:
```
a=input();
c=conv(sort(a),[.5,.5],'valid');' %find all cutting positions by taking the mean of two successive points
k=numel(c);
for e=1:k %iterate over all 'cuts'
    n(e)=sum(~xor(a(1:k)<c(e),c(e)<a(2:k+1)));%find the number of threads the cut cuts
end
disp(max(n)+1) %output the max
```
@MartinBüttner: I really enjoy your nice little just-before-I-go-to-bed-challenges!
[Answer]
# Mathematica ~~134 133~~ 104
Fun to solve, despite the size of the code.
Further golfing can still be achieved by replacing the idea of `IntervalMemberQ[Interval[a,b],n]` with `a<n<b`.
```
n_~f~i_:=Count[IntervalMemberQ[#,n]&/@i,1>0];
g@l_:=Max[f[#,Interval/@Partition[l,2,1]]&/@(Union@l+.5)]+1
```
---
```
g[{-1, 3, 1, -2, 5, 2, 3, 4}]
```
> 
> 6
> 
> 
> 
---
## Explanation
`list1` is the given list of points
`list2` is a shortened list that removes numbers that were not at folds; they are irrelevant. It's not necessary to do this, but it leads to a clearer and more efficient solution.
```
list1 = {-1, 3, 1, -2, 5, 2, 3, 4};
list2 = {-1, 3, 1, -2, 5,2, 3, 4} //. {beg___, a_, b_, c_, end___} /; (a <= b <= c) 
 \[Or] (a >= b >= c) :> {beg, a, c, end}
```
The intervals in `list1` and `list2` are shown in the plots below:
```
NumberLinePlot[Interval /@ Partition[list1, 2, 1]]
NumberLinePlot[intervalsArrangedVertically = Interval /@ Partition[list2, 2, 1]]
```
![intervals](https://i.stack.imgur.com/65e42.png)
---
We only need to test a single line in each interval determined by the fold points.
The test lines are the dashed vertical lines in the plot.
```
delimitersLeftToRight = Union[list2]
testLines = delimitersLeftToRight + .5
NumberLinePlot[
 intervalsArrangedVertically = Interval /@ Partition[list2, 2, 1], 
 GridLines -> {testLines, {}}, 
 GridLinesStyle -> Directive[Gray, Dashed]]
```
![test lines](https://i.stack.imgur.com/3Fj60.png)
---
`f` finds the number of cuts or crossings of each test line.
The line at x= 2.5 makes 5 crossings.
That leaves 5 + 1 pieces of string.
```
f[num_, ints_] := Count[IntervalMemberQ[#, num] & /@ ints, True]
f[#, intervalsArrangedVertically] & /@ testLines
Max[%] + 1
```
> 
> {2, 3, 5, 3, 2, 0}  
> 
> 6
> 
> 
> 
[Answer]
# Pyth, 21 bytes
```
heSmsmq1xS+dSkdC,tQQQ
```
[Try it here.](https://pyth.herokuapp.com/)
Give input as Python-style list, e.g. `[-1, 3, 1, -2, 5, 2, 3, 4]`
Closely based off of @jakube's program, but with an improved central algorithm. Instead of doing a `>` check and a `>=` check, I do a `.index()` on the three numbers combined and make sure the index is 1, meaning it's greater than minimum and less than or equal to the maximum.
[Answer]
## R, ~~86~~ 83
Was working through this and then realised that I had essentially come up with the same solution as Optimizer and others I suspect.
Anyway here it is as a function that takes a vector
```
f=function(l)max(colSums(mapply(function(n)c(l[-1],NA,l)<=n&c(l,l[-1],NA)>=n,l),T))
```
[Answer]
## GolfScript (43 bytes)
```
~[.(;]zip);{$}%:x{0=:y;x{{y>}%2,=},,}%$-1=)
```
In terms of efficiency, this is O(n^2) assuming that comparisons take O(1) time. It breaks the input into line segments and for each starting point it counts the half-open line segments which cross it.
[Online demo](http://golfscript.apphb.com/?c=OydbLTEgMyAxIC0yIDUgMiAzIDRdJwoKCn5bLig7XXppcCk7eyR9JTp4ezA9Onk7eHt7eT59JTIsPX0sLH0lJC0xPSk%3D)
[Answer]
# Python - 161
This can probably be golfed more. gnibbler helped golf this a lot.
```
l=input()
d={}
for i in zip(l,l[1:]):d[sum(i)/2.]=0
for i,k in zip(l,l[1:]):
 for j in[m for m in d.keys()if min(i,k)<m<max(i,k)]:d[j]+=1
print max(d.values())+1
```
[Answer]
# Ruby, 63
Similar to the Python solutions in concept.
```
->a{a.map{|x|a.each_cons(2).count{|v|v.min<x&&x<=v.max}}.max+1}
```
Add 2 chars before the code e.g. `f=` if you want a named function. Thx to [MarkReed](https://codegolf.stackexchange.com/users/4133/mark-reed).
[Answer]
# C#, ~~73~~ 65 bytes
```
N=>1+N.Max(i=>N.Zip(N.Skip(1),(f,s)=>f<i+.5==i+.5<s).Count(b=>b))
```
Reading the rules I thought a C# lambda should do pretty well.
Edit: just found `Count` has a useful overload for filtering!
You can test this by defining the appropriate `delegate` type:
```
delegate int solver(int[] l);
```
And then
```
var l = new int[] { -1, 3, 1, -2, 5, 2, 3, 4 };
solver s = N=>1+N.Max(i=>N.Zip(N.Skip(1),(f,s)=>f<i+.5==i+.5<s).Count(b=>b));
Console.WriteLine(s(l));
```
[Answer]
# Matlab (63 43)
Input is given as a row vector passed to the function `f`. So for example `f([-1, 3, 1, -2, 5, 2, 3, 4])` returns `6`.
```
f=@(x)max(sum(diff(bsxfun(@le,2*x',x(1:end-1)+x(2:end)))~=0))+1
```
Shorter version:
```
f=@(x)max(sum(diff(bsxfun(@lt,x',x))~=0))+1
```
# Octave (31)
In Octave `bsxfun` can be removed thanks to automatic broadcasting:
```
f=@(x)max(sum(diff(x'<x)~=0))+1
```
[Answer]
# [K (ngn/k)](https://bitbucket.org/ngn/k), 17 bytes
```
{|/+/'~~':'x>/:x}
```
[Try it online!](https://tio.run/##PZY7jh5HDIRznWIyBdZCfDTZzRXgiwhK5cCAIgUGbOvq669aghcbEDM9TbJYVfz/fPn2x7e3t6@vf//z8beP73/8eP/6/q/fP77@9e/b18/2@Jd3Xz@Hr71O9trPy//x0RsOPC/3jD/2K3rxJ/U4nnqCcH159@67v764R6yMNcnBmF1h1vH4mUyrivO4d2VbrObEOWdiIvLJU7ZsE70cy4re3J87JruMHO7l4baXvqrm89G9ZZ5lx44eZ5300OFc5qvdnh12Yp/W@/E65tZDipiVi0KfxZ@fNUUvtie4inD34mDurWttd0fVs2JqD6XdwrcNvQWx58Q6M4qndwQdE9fy5TQg8Nr36jzTT/kuIGg93cej7QiJY6ttzYnnqC4nIaCZgdTq/TTBpjm@r51TK5aKTEs3U5HJ@x7gVG37F67AM6u4dK2HZEK6ux6Aa2E9qv0UA2Maj89MpS8NzvYxZlf9eIBd6BSPhVSdfRRbqSSr80wBdAOYOprYDjCURO8JYFQHD8BwLRXHOLwBct3ki0lZcDeQDURZqfGfsZh25ykcjNF1AKLjp2@zy8gJoA9NV521z0NVXdyh174pG@hpujMYnecn2Pnh1S@G5kwbeufJGd1X61RmMMyAvsxziYbuIxpsW0/6kHunJk8laEOJAJmRTYgvc3yR0pTy7AW8pNhZO@hGvEg@3KaxC43q0niQgRDyElyRpNJQwtbqOpR60xEVdZEP4di2w5HpGQIKCksmND4PND@0KoXAOlF2LuuRD9cWJNrgw4T9AUmBhG4g2YYJlARas8EBbvCUomCJ36kfWj@7pDw0GBnkEbWqczjOFesgkZEIE@uAyabxroFNqI@bG/HZUN6TXLH3RcoSwrvSwQP45tRI4qgN0mQrBCO9rk8YzneXw8SrvIl/U@0g1Z2exwWrXbZXX5Y5hfjloaMKrOWeQRfwHvpovKdt8@dXMgV6TOfGyMQA/PK5Vi3xXL0fSBBzJY8KZwOm2mSADK5vLlzD4NV1PxWGm17l0D5ERTNXcrK1nzVwEe5Cjze2BiH5r4tMMP6nRFfK5H4KE8NwER4KuEq7RnAYXxPK2ERVMlxLgeIgqae2i1HJofYuhJ2abF9nRPSEexLxHXpuDIYJijvtDcW2soGDoR7pAsNIHC85wDPSmW6A7Eg7ZXxJRwtRcRnejF8avvUiW6PMGoV8Vll6CglMzsjQsHW0JzsLKAcv/Iqz8SL7uU82deeh41hQyqWsFTLJh0qYDDeiPRyR4Z2V8iqYKpHBX1ZPLHGKLhkOVWOkD4bfsILJYxnaBcyFonB2SSLxMkYkC6CeuxEfEkAQyK2FgAigAu4SH16xITRl5VQjMvZJ7J4hCDqMexp6glVxFQgQ0Tj@rC@ahQXcu4m0CiWA3nhyL6a2WZ5wwxftIT8qCrXFJgEHfESSGO5aCpmvaeFBNMbLUpMD8xqLBjrMDbmzoABG9sQk2UpQVVzqvOHGBYAcmxCF7OpyUebBNlphB9KFzPgBY8SdFEIUMmBaLp/Z@A81IKbSZpFLHP0cCKE/TB3TkK@P0RE5tICYD3tV9U7e5dqmzeB42qZ0WmEXUlxqM6Bjtt79ZUCjrXWnHwmtHe8K4f@oyBBv6A1s42qGRupaSnx5@w8 "K (ngn/k) – Try It Online")
Modeled after [Zgarb's APL answer](https://codegolf.stackexchange.com/a/44562/98547).
* `x>/:x` build matrix storing whether or not each value of x is larger than each other value of x
* `~~':'` for each "row", determine where the values change (i.e. `differ each`)
* `+/'` take the sum of each row
* `|/` take/return the maximum sum
[Answer]
# JavaScript (ES6) 80 ~~82~~
See comments - byte count does not include assign to F (that's still needed to test)
```
F=l=>Math.max(...l.map(v=>l.map(t=>(n+=t>u?v<t&v>=u:v>=t&v<u,u=t),n=1,u=l[0])&&n))
```
**Test** In FireFox/FireBug console
```
;[
 F([0, 1])
,F([2147483647, -2147483648])
,F([0, 1, -1])
,F([1, 0, -1])
,F([-1, 3, 1, -2, 5, 2, 3, 4])  
,F([-1122432493, -1297520062, 1893305528, 1165360246, -1888929223, 385040723, -80352673, 1372936505, 2115121074, -1856246962, 1501350808, -183583125, 2134014610, 720827868, -1915801069, -829434432, 444418495, -207928085, -764106377, -180766255, 429579526, -1887092002, -1139248992, -1967220622, -541417291, -1617463896, 517511661, -1781260846, -804604982, 834431625, 1800360467, 603678316, 557395424, -763031007, -1336769888, -1871888929, 1594598244, 1789292665, 962604079, -1185224024, 199953143, -1078097556, 1286821852, -1441858782, -1050367058, 956106641, -1792710927, -417329507, 1298074488, -2081642949, -1142130252, 2069006433, -889029611, 2083629927, 1621142867, -1340561463, 676558478, 78265900, -1317128172, 1763225513, 1783160195, 483383997, -1548533202, 2122113423, -1197641704, 319428736, -116274800, -888049925, -798148170, 1768740405,  473572890, -1931167061, -298056529, 1602950715, -412370479, -2044658831, -1165885212, -865307089, -969908936, 203868919, 278855174, -729662598, -1950547957, 679003141,  1423171080, 1870799802, 1978532600, 107162612, -1482878754, -1512232885, 1595639326, 1848766908, -321446009, -1491438272, 1619109855, 351277170, 1034981600, 421097157, 1072577364, -538901064])
,F([-2142140080, -2066313811, -2015945568, -2013211927, -1988504811, -1884073403, -1860777718, -1852780618, -1829202121, -1754543670, -1589422902, -1557970039, -1507704627, -1410033893,  -1313864752, -1191655050, -1183729403, -1155076106, -1150685547, -1148162179, -1143013543,  -1012615847, -914543424, -898063429, -831941836, -808337369, -807593292, -775755312, -682786953, -679343381, -657346098, -616936747, -545017823, -522339238, -501194053,  -473081322, -376141541, -350526016, -344380659, -341195356, -303406389, -285611307, -282860017, -156809093, -127312384, -24161190, -420036, 50190256, 74000721, 84358785,  102958758, 124538981, 131053395, 280688418, 281444103, 303002802, 309255004, 360083648,  400920491, 429956579, 478710051, 500159683, 518335017, 559645553, 560041153, 638459051,  640161676, 643850364, 671996492, 733068514, 743285502, 1027514169, 1142193844, 1145750868,  1187862077, 1219366484, 1347996225, 1357239296, 1384342636, 1387532909, 1408330157,  1490584236, 1496234950, 1515355210, 1567464831, 1790076258, 1829519996, 1889752281,  1903484827, 1904323014, 1912488777, 1939200260, 2061174784, 2074677533, 2080731335, 2111876929, 2115658011, 2118089950, 2127342676, 2145430585])
]
```
*Output*
> 
> [2, 2, 3, 2, 6, 53, 2]
> 
> 
> 
[Answer]
# [Python 2](https://docs.python.org/2/), 63 bytes
```
lambda x:max(sum(a-m^a-n<0for m,n in zip(x,x[1:]))for a in x)+1
```
[Try it online!](https://tio.run/##PZbdbh1HDoTv9ynOpYSVALL5000jeRKvA2ixa0RApBiOjSj78t6PHCG6UU@fniZZrCrOl7@@/fr76/rx@ed//fjt6eXf/3m6vX14eXq7@@P7y93T48svT4@vP8nn37/eXh5eb8@vt/89f7l7e3j7qB8@3d/3/lPvvt3/U3/8@evzb/@96YcvX59fv90@3z2/fvn@7e7@/sdHebjpp398XOrbj6Xvh9vj3w@HX/oAe32I//K@fGRt1y/r4RYPtzXPPj/pWm7Ly/rwqh1LJDmgp8wkYh3WmmEpy7MPnXNq1Vq8YSfEZffy8YjFyt2BbK@yDOlQqqFLZfu8GsklNfeHqIUcOfODxTFd84K5qKeS/V5y1j7JEc6UxhGVrA62ys1JnDL40@MVXZ7sWlzZ653OYdt77peduYJ9XxW7yHTuPGdLUfHqQ2q1/FTNQ@VeCyT6IVxdqWmwTd2edooLQneATc7@PrpSjs/FRzzF6/D26Tw1uzbSEHD0JKdktam5r4ltFb58sjYxFZmsjSNZ4H3lut@hb/DKg9udVwjc7cgkAMhmN6SmnBP0Vvparaow9Wmy7CP0OYisC3BXH@wfGsc4@8yDRCcoQewKupHAOWXW2gpmnSCgGHB2slAHjN2vXOmbJkj7lYjTVFkdBEQLfrkNY07JqlTtfSi8aq4Fq37l5IWBC@FBnHtBI@L4JgZZZnDVHNFNITSowUhb9FltgAFe0WYGCrFjVXNl@Amz1U2Hboto5kNh1WrWbAEy0yKHbUN5UkJkE40W0NhaQ7E66gSWCXy2gz37N98We1HdEMl4fcuQpEGKjGkhemroNAbIZUSdvi1xzzjkfkVmGWQ5rEKGsuX0scoqVp3fEqONpWyjlkP1ozYI25yvERihgvujmbfBDTJw/w2cGz1k2OzcMIcMG8faYASZep8k4ZVeHDmAcnaMnFH2snVabjAy0spGV8jxoLcabRsOhRhkqOAFCdF0h0gULXValMZNe19AiqEbncjwBqZqJ91ZrNj0oyMH@msrGAtbzS@XqQH0Mk3t6MAtI5RoA@kHUtGLuYqqsK7rGLJCMxBtOHBSNn/6LroAUpp3uRQ6E3pxCSE8vCUySBzYsuryEfRcG4inYlpMZ/OKiiMJRGyzHd7SN9@X@AADcqO6S7ptoe8JcR/uRbXXgySQjfVrkw@xvMvdrR3Vr7sFM9LWSlNFO9PLXw79TdZjos1xQuW4NwoB3dmXHXRyfHDvwCpsmp9jxhhJr3cZKj4NReJfdHiIlppwck9cABJEONLCigx7tT7DLoElJlO0glnY@KxRpiPPvpTZgElL@@NjOyhpR82al8Ni9uGKtBd3e5ktCHmMc0FSCKSX2hO7k/f5tqnETgOxHALqSNRX2zI@jFdgU6xQMhbcfT5ubYkxDESwUL8H4vKmYFdPF6nE2mSYPAmVmivYUY@lbiBJMl9GVYZv0syxF/Kbqd12IT2DvMcLjUFH0R3F5hCmhHZiTeQ81iOHPsWUFmxB7oYxuA1cegkcjIZ57ZZMUhqyqQjLPe3o3vpnHKR3ezcjHjqpd8komeRambKYa@DTNtXiKu70WUMGueYxHIUMDNwxf44wIBpYvBQTYW62KbQN0vWelXC9OZh2rTfuUu0JKJeK5F3kTuYHT@pDzi14QSsCp6Hl2OCsoRex2h@1rWxjct0T1Bk96PpdRgu6Wmc8rqAJjjSzpYQ6CTdDkTbyATAVlM1nQMrMKMVBd1dDfUxrkrWZUbgEQ/n6rKH@nGHcnzjZnyY6a5RUk/RqulFxw79GgtQWn/4P "Python 2 – Try It Online")
I'm back 6 years in the future to golf the Python answers by [Sp3000](https://codegolf.stackexchange.com/a/44545/20260) and [Jakube](https://codegolf.stackexchange.com/a/44547/20260)!
The improvement is shorten the core expression of `(a+.5-m)*(a+.5-n)<0` or `min(t)<a<=max(t)` with `t` for `m,n` to:
```
a-m^a-n<0
```
This is parsed as `(a-m)^(a-n)<0`. Due the how XOR acts on the Python's bit representations of negative numbers, two the XOR of two numbers is negative if and only if exactly one of them is negative. So, this expression is equivalent to `(a-m<0)^(a-n<0)` or `(a<m)^(a<n)`. This expresses that exactly one of `m,n` is smaller than `a` while the other one isn't, which is equivalent to `min(m,n)<a<=max(m,n)`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
>þ`^ƝS$€Ṁ‘
```
[Try it online!](https://tio.run/##RZY9si1FDoR9VnEMzPsi9F8lh02MSTxinHEm2MB4BA5bGGd2wAZwcF4E@xg2cvmkvsCxqutUl6RUZqr//a/vv//P@/s3X37953e//e8fX//@48///@WH33/47/uXn1i/v3/71ev1rby99PPbrEzjxPWK8/b69NfDff6cY2x/HGUpfz994tGf/@3tlW8v2@f48181C7don1esT5pIcUZvu0umXdZa6SUWNYfuvW1txht@U0LOLD9d8bQ6E8uPtVfKRFNNNZUT@2oWl/Ten6KecuXuH57X1fYFD9EopYZjcu3c4ghnWvOKSvUEsw4PEqcSfnqjcyqU08aVsz4VHPZz9n45VZbsh3WeJtO9894jTcU2h9Tb4nbvQ9cxA4l5yNBQalqQS0@U3@aC1JNgU7t/rlrJjb34SpREX96@k6fW1EYaAo5R5FSsDjXPNXm8Myw2axdXkc3aOVIN3k@u5wP6Aa8juT14hcDTjioCgGxNQ3rLuUlvZa7V7k7X2CbLuUKfk8hqgGtzcP4YHPOeuw@Sk6AksTvpRgHnltl2FMwmQUBx4JxkoQ4YRzy50jctkI4nkaCpYhMERBt@hS9jbot1qc4@dLbea8FqXrn1YBBCeBDnXtDIvHGIQZaVXLVH9FAIDRowyo0@qy8wwCs6zEAtfr17r8y46W7TdOhmRPNYCqv2sOYIkLk2ORxfypMSgttotIDGti3F@moQWDbwPQH27L/ieB6juiWS8/qRJcmAlJXbQvQ00GkukOZE3b6ZRFRecn8is0yyXFYhQzly51hXN6vJz8RpYyvbqOVS/aoNwg7newVGqOT@HOYdcIMM3P8C50EPGQ47D8whw8GxDxhBptknSXilD0cuoNyTK2eUbW535AYjs7x9dYUcL3rr1bbjVohBlgrRkBBNT4hC0dJ3ROncdM4DpDi60Y0Mb2CqTtKTheWhHxM50d9YwZ8uZkOxkC0DAKtc/eoiLquVHA@ZB7LRh7yKsHCv5xjKQjZwbWlwSw4//dBdgir9e4wKqQnteLSQkTEqWTAuhLF@rARJ9wHlLZou09x6omJKAhfHb5e6tC7Ooz/wgN8I71HvuOhHQtyHgVHw8yAFajsJdPiHXj4UHz6mGs/dgh/pyGXYopPpYzGXFhfr9dGhOaFqDRyRAPDuy0mauVZ4TuIWvv2v9WO8ZNanHSHfgaKwMJq8XCstaHk2LgAJOlx14UaOw/qcYZfAkpspcsEvfK3WKTNQ6FzKeMCnZSzy05goaWfvmpfTc/ehi4wdT3sZL2h5vdPgKRzSR/CF48nHiDtU4neAsICDuioNG2fGirELnIoVYsaFp883fFwxl4RoFvbPTLQYFk71dJFKfHyG4VNQabiCI81kmgaSJCNmheVYJ81chyG/HeLjGDJjKGbC0BiklNNRnA5tSuokNkSu6zN16FNuackW5B4Yk9vAZZbAwXTY117FMKUhh4pw3TumHmMBTISKae9hykMnjSkZMZPciFOM0QY@41QjrubO2DVkkGckw1HIwMxd/@cIM2KAxU7xEUbn@MI4IV2fcQnXh4Plz/pgMD22gHKpSD50HmR@saU5FNyCHYwiMBtajhPuGnoRayxSx80OPjc9QZ05s27eZbqgK7trcw1NMKUdLy3USbidi7SRb4CtoH2/BEp2TCkmeqYa6mNgk6zvmMIlmMvPlw31187j@cqp@TrRXaOk3qRt6EbFA7@tBKktP3/1@Q8 "Jelly – Try It Online")
## How it works
```
>þ`^ƝS$€Ṁ‘ - Main link. 1 argument        e.g.   [1, 0, -1]
>þ`        - Greater than outer product          [[0, 0, 0], [1, 0, 0], [1, 1, 0]]
      $€   - Over each sublist:           e.g.   [1, 1, 0]
    Ɲ      -   Over each overlapping pair e.g.   [1, 0]
   ^       -     Perform XOR                     1
     S     -   Take the sums                     [0, 1, 1]
        Ṁ  - Take the maximum                    1
         ‘ - Increment                           2
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
ε@Ôg}à
```
[Try it online!](https://tio.run/##LVS9jZxZDGtlCpgF9C8xcx@GAx9wOFzkwLG7cAFuwhU4d0trSuON3rxPj6Qoar98/fzP//@@v//@@eHX9/@@/frx/v7xTdUs3AL@fLypodNEyp4PHbhLpg3PWuklFrVFMwODGV/4pIT0Ht9GPK2aR/U2eKXk82GqqabScU@zCILDT1FPGZn74Dmudg88RKNUno82GesplrAGmiMqhSUzhAeFPx/BP50A376ZNIyQe@4KFnv34UtXWfI@DNmg0sOcaQE7ti1Sh8UA9wPVZnRif2RoKHvS/VDaUT4gQGonvam771ErmTjgkSgJDF/P6tTa3ihD6GMUNRVPzZ4XJtuRYXGqXVxFTrWzpEC/X1r7r/VrHiKJHnxC4h1HFQnobO1AcO1McraysAogXeOGLD3COSeZ1WiubeF@WB9zeu6H5AqUJDeS0yjaeW3CWunZCqQpTjtXLKNDjyNeWjk3LTodLyHBoYotCR0F8xV@iRmIoVT3frwMB0uv9snUy4MQ0tNx4tKNzIkmB1VWEupKtNkIB7RmlBvnrH7G0F7RTUaM@zhwkBmT7rZDZ9yMbB4XYVVsalpomSuoof0iT0kdc2wcAQcLu4hhNEgsRzwd9J73j2jPNnZ3QXI@b7mQrElZeSPkPq11mmekOVlvbiYRlUPtL2YekyovVVxDaZktQwE8rT4T5xihvOa2DLu/bWNgN/O4BSNVEj83eU3fGAbiP@jzusc13HQ2k0OF6yOaHjFMe0@RzJW@MjI0ZTpvnbnZ5ja7bkxklsNvr7iOw33D7bYbg0Wgi0KAIeROL0VxowWzS@lE6n4ZKc690WNmbphUXdGrwrI5j2VO7t/@K4hPfwA "05AB1E – Try It Online")
Explanation:
```
ε   }    # for each element of the input
 @       # is each element >= this one? (returns list of booleans)
  Ô      # connected uniquified
   g     # length
     à   # maximum
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 71 bytes
```
a=>Math.max(...a.map(t=>a.map(u=>s+=(a[i++]-t-.5)*(u-t-.5)<0,s=i=1)|s))
```
[Try it online!](https://tio.run/##TZbNbl03DIT3eYq7tBvbIMUfSWhvltn1CQIvLtKgdZHGQe0UXfTd3Y88TlGvJFlHJIczw/v75a/L08c/H74@3355/OXTy/vzy@X87ufL8293f1z@vrq7u7uw@Hr1fH53LL6d3z29PV9dPjy8fXt/@3x7F9c/XH07Fj/JzdP54azX/zxdX7/8@PHxy9Pj5093nx9/vfrw5vT@6oPcnPT@@s0Ny6E@fVn6vDnd/rdZr/@ti5x/v8xa/re9ZW/HjXFzipvT6L3fX59Orxd0DLfh2@qzsWcMkeSarm0mEWOx1gxLGZ51aa21xx6DL2yFuMxa3i6xGDkrnM2xLUMqoGroUJnen0byyO73Q9RClqz@h8UyHf2BuainUsccssZc2Ve2xhKV3BVrbDcnb2rhT5fvqBpl7sGLtZ7pXLY5@3mZmSM497FjbhI9KpmyqXfURm0PX3v3ZuccAxxqE66uVNQ4p05PW5vvQ2eATPb5XDpSViO0xFN8Lz5elaVmFUYSAoieZJSsJgXXKzFthw/vnE1MRTpn40puwO5M5yvsBdz24HHnC8JWKzJ5H1SzmrG7mBX0VepV3XuHqXeDZS6hx0FgHQA76mL9o0CMNVdvJCo/CULvoBMJll3kHlNBrPIDEgPLyhXaALB7p0rLNEHZjzycfsqoGMC5oZZbk2VtGTtV6xw@j92vglR9svJAwIXowA1gMyOWTyKQYwYv9Q2dlEFzCoq0QYvVGhawFS1SoBZbtne/GL7CbFTDB8Sn597cVd3FlyngZbrJYFozhITQWwcDf5q6R5NrL3XiSsdd0wGe85NPizmorTlkfD6l@VEIRUb3DyEVbhqN4jCidtOGuGcsUj8iswyyrNDIT6asurVzb1aV3hCjhVs5RiWL2ltlULXIvg/VoEKejyLdBDWIwPMnQC7skF8Rc8IaEiwU9wQhiFTn5Ain9ODHApM1o2WMooeNVTqDjZG2rQSFDBc62y1pw6qQgTQNfMM/pFwREiXLXiVG46E5DxjFUIx2YDgDSbVyJocRk2ZU3EB35QD@3d1G0culqwC@TFNb2nhLyyTyoKSSjR68VSSFaR3XEBWKgWdNgpUy@dNDcQGmNO/YIDKhF4cKwsNLHw3Fgi1jHxaClvcE466ZFtPZPILiRQIPy2WbtjTO56E84IDbSO7QbXnnaz68h29R8LGRBLSeAlrkQyqvWncrK/XjbcGHtKRSXNHK9PCWRYOTddtncZxQh1khEADuc5lBK9sC5wx8wrr72S6Mi9R6bkPDq6BIvIseN9NSE1LOjgtAggZbWviQ4axWdzglsERnilawCmuLNcp01FmPMhSwZylvvC33JO3YvebjsOhz2CJlw9VdhgpCbtMcsBQK6SH2xOvkdbBNKrFVQAyHgtoS9VGWjAdjFZgUK5SM/Vafl1v5YalaS7Bwvybh8GJhVU8XqcTKY5g5CZOKK7hRDaRqIEkyWlpWhmnSzLYX8usBXnYhNX68JguNQUhRHcXlUKaEVmLF41xW04Y@RZcWHMHtgjF4DVxqCRzMhf7slIxQGjKpCMNdZedeBsAsSK/2TmY7dFKvkpEyyZU2ZTDSwKdsqrS1edN7DRmkBzEbYElGbTs/V5gOBSxeioswMssVygbpeo1JuF4cTDvWE3vZ5QoIl4qkZc6GzBemVJecV3CDUgRWQ8uxwV5DL2KVP2p52cTlqieoM2rKtQWt@gkzVpvchiZ4Uk@WLdRJuJ6ItJHZ3xVs618AKT2hFAudVQ31MalJ1npCYRIM5OP3DPVnT@L6bZP1o0R7jZJ2Jz2KblRc8I@WILUFpnV//fIv "JavaScript (Node.js) – Try It Online")
[Answer]
# [Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), 27 bytes
```
D,w,@@,VbUG€<ÑBxs
L~,A€wM1+
```
[Try it online!](https://tio.run/##S0xJKSj4/99Fp1zHwUEnLCnU/VHTGpvDE50qirl86nQcgbxyX0NtoIISHQcrHcNYLi6VErtoAwVDBSMF41hOTk5rBSOwkK6hgjFQVNdIwRQkpWASC5IzA8sZKhgo6BpCVf8HAA "Add++ – Try It Online")
Approach thanks to Zgarb for their [APL answer](https://codegolf.stackexchange.com/a/44562)
The key part of this challenge is implementing an outer product command. Unfortunately, Add++ doesn't have a builtin to do so, not does it have any way of defining functions that take other functions as arguments. However, we can still make a generalised outer product function nonetheless. As the only way for a function to be accessed inside another function is via referencing an existing function, user defined or builtin, we have to create a 'builtin' that references such a function.
A generalised "table" function would look something like this:
```
D,func,@@,+
D,iter,@@*, VbUG €{func}
D,table,@@, $ bRbU @ €{iter} B]
```
[Try it online!](https://tio.run/##S0xJKSj4/99FJ600L1nHwUFHm4vLRSezJLUIyNHSUQhLCnVXeNS0phokXwuUKklMykkFKVRQUUgKSgpVcABLg3TUKjjF/lcBK7Czt7Pn8v//P9pQwUjBWMEk9n@0qYKZgrmCRSwA "Add++ – Try It Online")
where `func` is a dyadic function that contains our operand. You can see faint similarities of this structure in the original submission, at the start of the **w** function, but here we want, primarily, a *monadic* outer product function - an outer product function that takes the same argument on both sides.
The general **table** function takes advantage of how the `€`ach quick approaches dyadic functions. If the stack looks like
```
 [a b c d e]
```
when `€{func}` is encountered, the `€` pops `e`, binds that as the left argument to the dyad, and maps that partial function over `a, b, c, d`. However, the `€` quick maps over the entire stack, rather than over lists. So we need to flatten the arrays passed as arguments first.
The **table** function works overall like this
```
D,func,@@,+
D,iter,		; Define our helper function **iter**
		;   This takes an array as its left argument
		;   And a single integer as its right argument
	@@	; Dyadic arguments - take two arguments and push to the stack
	*,	; After execution, return the entire stack, rather then just the top element
		;
		; Example arguments:	[5 6 7 8] 1
		; 
	VbUG	; Unpack the array;	[5 6 7 8 1]
		;
	€{func}	; Map **func** over the stack
		; As **func** is dyadic, this pops the right argument
		;   and binds that to a monadic **func**
		; This then maps the remaining elements, [5 6 7 8]
		;   over the monadic call of **func**, yielding [6 7 8 9]
		; Now, as the **\*** flag was defined, we return the entire array
		;   rather than just the last element.
		; We'd achieve the same behaviour by removing the flag and appending **B]**
D,table,	; Define the main **table** function
		;   This takes two arrays as arguments
		;   Returns a single 2D array representing their outer product with **func**
	@@,	; Take the two arrays and push to the stack
		; 
		; Example arguments:	[[1 2 3 4] [5 6 7 8]]
		;
	$	; Swap;		STACK = [[5 6 7 8] [1 2 3 4]]
	bR	; Reverse last;	STACK = [[5 6 7 8] [4 3 2 1]]
	bU	; Unpack;	STACK = [[5 6 7 8] 4 3 2 1]
	@	; Reverse;	STACK = [1 2 3 4 [5 6 7 8]]
		; 
		; This allows us to place the stack so that each element of
		;   the first array is iterated over with the second array
		;
	€{iter}	; Map **iter**;	STACK = [[6 7 8 9] [7 8 9 10] [8 9 10 11] [9 10 11 12]]
		;
	B]	; Return the whole stack;
$table>?>?
O
```
However, we can shorten this by quite a lot due to the fact that we need our outer table to be *monadic*, and only needs to apply to the argument passed. The `A` command pushes each argument to the stack individually, so we don't need to mess around with any stack manipulation. In short, if our argument is the array `[a b c d]`, we need to make the stack into
```
[a b c d [a b c d]]
```
The top value is, of course, the argument.You may have noticed from the general example that `bU` is the **unpack** command i.e. it splats the top array to the stack. So to make the above configuration, we can use the code
```
L,bUA
```
[Try it online!](https://tio.run/##S0xJKSj4/99HJynU8T@nUyyntYJHalGqQkm@QnFGfrlCSUaqQnFJYnI2F5dKTmJuUkqigqGdPZf////RhgpGCsYKJrEA "Add++ – Try It Online")
However, this can be shortened by a byte. As an alias for `L,bU`, we can use the `~` flag, to splat the arguments to the stack beforehand, making our configuration example into
```
L~,A
```
[Try it online!](https://tio.run/##S0xJKSj4/9@nTsfxP6dTLKe1gkdqUapCSb5CcUZ@uUJJRqpCcUlicjYXl0pOYm5SSqKCoZ09l////9GGCkYKxgomsQA "Add++ – Try It Online")
which is the start of the second line in the program. Now we've implemented monadic outer product, we just need to implement the rest of the algorithm. Once retrieving the result of **table** with `<` (less than), and count the number of `[0 1]` and `[1 0]` pairs in each row. Finally, we take the maximum of these counts, and increment it.
The complete step for step walk through is
```
D,w,		; Define a function **w**
		;   This takes an array and an integer as arguments
		;   First, it produces the outer product with less than
		;   Then reduce overlapping pairs by XOR
		;   Finally, sum the rows
	@@,	; Take two arguments
		;
		; Example arguments:		[[0 1 2 3] 0]
		;
	VbUG€<	; Map **<** over the array;	STACK = [0 1 1 1]
	ÑBx	; Equals [1 0];		STACK = [1 0 0]
	s	; Sum;			STACK = [1]
L		; Define a lambda function
		;   This takes one argument, an array
	~,	;   Splat the array to the stack before doing anything
		;
		; Example argument:		[0 1 2 3]
		;
	A€w	; Map with **w**;		STACK = [1 1 1 0]
	M	; Maximum;		STACK = [1]
	1+	; Increment;		STACK = [2]
```
]