[Question]
  [
There is a "sorting algorithm" sometimes called Stalin sort in which in order to sort a list you simply remove elements from the list until it is sorted in increasing order. For example the list
```
[1, 2, 4, 5, 3, 6, 6]
```
When "sorted" using Stalin sort becomes
```
[1, 2, 4, 5, 6, 6]
```
The three was removed because it was out of order.
Now obviously there are many ways to remove elements to sort a list. For example any list with less than two elements must be sorted so by just removing enough elements blindly we can always sort a list. Since this is the case we only care about the *longest* possible result from a Stalin sort.
Your task will be to take a list of positive integers and output the length of the longest sorted (increasing) list that can be arrived at by removing elements from the original list. That is find the length of the longest sorted (possibly non-contiguous) sub-list.
Sorted lists can have the same element more than once in a row. You do not need to support the empty list unless your program itself is empty.
# Scoring
Your answer will be scored by the length of its own longest possible Stalin sort. Programs will be interpreted as a sequence of bytes rather than characters, and their order will be the natural one that arises by interpreting the bytes as numbers. Lower scores are better.
# *This is not [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'")*
Here's [a neat-o tool](https://ptpb.pw/SVSt.html) to help you score your answers.
# Test cases
```
[1, 2, 4, 5, 3, 6, 6] -> 6
[19, 2] -> 1
[3, 3, 4, 3] -> 3
[10] -> 1
[1, 2, 4, 9] -> 4
[1, 90, 2, 3, 4, 5] -> 5
[1, 90, 91, 2, 3, 4, 5] -> 5
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), length ~~14~~ ~~12~~ ~~10~~ 9
```
M=max;X=exit;i=input();L=[0]*M(i)
for	a	in	i:L[a-1]=M(L[:a])+1
X(M(L))
```
Output is via exit code.
[Try it online!](https://tio.run/##XY9da4MwFIavza84lA6TTsXoOvCru9qdhbLddGReZJpiYEvEOtZC/7uLOvcFIeE87znnffPCj3Vf8g7SFDy4QC14BW4JLoUNlLoSXnPut9kbPyX7TJxkl8hMqua9wyTJM@YXqy2WBB10a3FLKkvGOeMuLbItzlnMC3JN0R6bgpDeQ@ijlq8CWmOSQKWR1bRSdQewr9wgPIK7ARsWy4f7Xf60MOK5q7UK5hgmYvpLFWWtYXmHKq0EQvOiZ/VY6lbEYKNpPBx@Y48yZivdCIV94g0JMPGEGnZjUhAb0m@fC/xzRl9ePaMOBA7cOLB2IHTg1pwCMRoZbN5whEYNB@gP19wfTUXkj2DqWv@wiP7lnw "Bash – Try It Online")
### How it works
At all times, the array \$L\$ keeps track of the longest sorted subarrays encountered so far; \$L[a-1]\$ is the length of longest one that ends with \$a\$.
Initially, we haven't processed an array elements, so \$L\$ consists entirely of zeroes.
When processing the array element \$a\$, we first take the maximum of \$[L[0], \dots, L[a-1]]\$, which is length of the longest sorted subarray encountered so far that ends with \$a\$ or a smaller integer. Appending \$a\$ to such an array will keep it sorted, so the longest sorted subarray ending in \$a\$ is one element longer than that maximum. We update \$L[a-1]\$ with the computed value.
The final result is the maximum of \$L\$.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), score 9
```
Length@*LongestOrderedSequence
```
[Try it online!](https://tio.run/##ZZBRS8MwEMff8ylCBFHJcF23Qa0ZhakgDBS6t9iH0l7boEtqmsFgbF@93jJWFCEv9/vd/bnLJncNbHKniryvOmdF6qzS9Tr/BMn6FejaNcndyugaOvdmS7BQpvC9BV1Az/h@wkeTQ0YqsTbPu9ZC1ymjk1MSITdkrzQ3W3cQV8dzbtp@KXdkdLSgLCZK/xmTbKU6xx4XSmcxjokXazZPqlauS7CMyTtGOMledbt1VFDGMZ5xiu4CquSMYNdC4aD0EP2JFcZahEOfEAJNFpPb6/vk13qSyYDTCadTTmechpzO8WWnnedEBhE6XwREhl5jX@hJiHp8cUNG5MnUk2js6Xlo5sVsEFHwXzLOPjTLyOX2FK@AB3/B2iyb3OZ4pl2aEvynZ/0P "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), length ~~4~~ 2
```
ṢƑƇZLƲ}ŒP
```
[Try it online!](https://tio.run/##y0rNyan8///hzkXHJh5rj/I5tqn26KSA/4fbHzWtUXi4c7GBgvv//xpcCrmJBRrJ@Smp8QWJ6al6aZl5KToK6mi61DV1FKJjdRSUFYqT84tSuRSiDXUUjHQUTHQUTHUUjHUUzIAoVgckbgmUALOMwRJAFcYQCQMIBdNnCeNaGoCFIGpNkUUtDdFkNAE "Jelly – Try It Online")
### Bytes in [Jelly's code page](https://github.com/DennisMitchell/jellylanguage/wiki/Code-page "Code page · DennisMitchell/jellylanguage Wiki")
```
183 146 144 90 76 169 125 19 80
```
### How it works
```
ṢƑƇZLƲ}ŒP  Main link. Argument: A (array)
       ŒP  Powerset; yield P, the array of all sub-arrays of A.
     Ʋ     Vier; combine the preceding four links into a monadic chain...
      }    and apply the chain to the right argument (P).
  Ƈ            Comb; only keep arrays for which the link to the left returns 1.
ṢƑ             Sort fixed; yield 1 if sorting doesn't alter the array.
   Z           Zip; read the filtered powerset by columns.
    L          Take the length.
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), score 9
```
*.combinations.map({@^a*[<=] @a}).max
```
[Try it online!](https://tio.run/##jVFha4MwEP1cf8WjhFVtGrSuBecU/4fE4pxuKbMWHWVF/O3uEldovw0Cl/cu9@7d5Vx1X/upueKpRjy5omybN3UqvlV76kVTnO0hzQs3e40l0mJ0iPqZIqsvrqhtdnBQt51l@xxbjmeOHUfAsafjcKJD4vUlMDTlA0N73IRbUfiHQs8w88vdHRn6D4nIsgZrQZbTPjKRNYjBDhufYNpnrJGENSBzmt8KITxsEjAFqjQlF3pixrNFxvKjTGKKSjquFjjKkTOVC5GvaUY9M9ZG0MgrLc8uGs6dFVStFZMYc3tKjdZCL2nZl21XvWCYE@MymnmRkWuOAdT81kiKj64iRw@G5pXbpv5ACCNomhxe4kKK8rOjHYz26l8ftxJt99470y8 "Perl 6 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), Score ~~8~~ 7, 48 bytes
```
(l:k)%d|d>l=k%d|3>2=max(1+k%l)(k%d)
c%b=0
a=(%0)
```
[Try it online!](https://tio.run/##jY5BasMwEEX3OsUQ2zBDQ7GTnWG0aW6RdDGSTSwsy0ZRIAvd3RVtD5DVvHn8xZvkMY/e727Z1pjgIkk@vyaJO/p@pmbIg/Y8l3vWJ17khd3H3HjCokjZxnCrhLFpaX@CgMl@DPc0FdTwjwa4vBk63RYySio0vaUs2rBUNhfPT5TeVJawCCoLw1f5Vo4Pb1Tcwm/GLfx1HNQiLvAWXUg1JnG@RjtFaKlyR6kX2WCNAzjafwA "Haskell – Try It Online")
The longest sorted sublist is
```
%%%%%%)
```
[Answer]
# Pyth, score ~~3~~ 2 (~~7~~ bytes)
```
leSI#y
```
Saved a point thanks to Anders Kaseorg.  
[Try it here](http://pyth.herokuapp.com/?code=leSI%23y&input=%22leSI%23y%22&debug=0)
### Explanation
```
leSI#y
     yQ    Take the power set of the (implicit) input (preserving order).
  SI#      Get the ones that are sorted.
 e         Take the last (longest).
l          Get the length.
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 4 maximal length stalin sort
```
S{:^fF%|M
```
[Run and debug it](https://staxlang.xyz/#c=S%7B%3A%5EfF%25%7CM&i=%22S%7B%3A%5EfF%25%7CM%22%0A[1,+2,+4,+5,+3,+6,+6]+%0A[19,+2]+%0A[3,+3,+4,+3]+%0A[10]+%0A[1,+2,+4,+9]+%0A[1,+90,+2,+3,+4,+5]+%0A[1,+90,+91,+2,+3,+4,+5]%0A&a=1&m=2)
It works like this.
```
S       powerset of input
{:^f    filter by non-descending sequences
F%|M    take the maximum length remaining
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), length 2 (4 bytes)
```
⊇≤₁l
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3w/1FX@6POJY@aGnP@/4@ONtRRMNJRMNFRMNVRMNZRMAOiWB2FaEtLHTMdI2MQ0wIsYWgEpA0NLGJjAQ "Brachylog – Try It Online")
An answer which makes up for being so concise by not being that much shorter sorted.
(`08 03 80 6C` in Brachylog's code page)
```
        Output
   l    the length of
 ≤₁     a non-decreasing
⊇       sublist of
        the input.
        (maximizing the size of the sublist)
```
[Answer]
# [R](https://www.r-project.org/), Score ~~15~~ 11, ~~72~~ 62 bytes
```
function(L,M=max,A=1:M(L)*0){for(Y in L)A[Y]=M(A[1:Y])+1;M(A)}
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/T8NHx9c2N7FCx9HW0MpXw0dTy0CzOi2/SCNSITNPwUfTMToy1tZXwzHa0CoyVlPb0BrI1qz9n6aRrGGsY6xjomOsqckF4hnqGAF5lnCepYGOJUgMpMYULFpakmYRku@ZV6KhRJntSpqaCsoKJZm5qcUK@aUl/wE "R – Try It Online")
Ports [Dennis' Python answer](https://codegolf.stackexchange.com/a/174994/67312) to R.
]