A "Sorting" algorithm 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

Here's a neat-o tool to help you score your answers.

Test cases

[1, 2, 4, 5, 3, 6, 6] -&gt; 6
[19, 2] -&gt; 1
[3, 3, 4, 3] -&gt; 3
[10] -&gt; 1
[1, 2, 4, 9] -&gt; 4
[1, 90, 2, 3, 4, 5] -&gt; 5
[1, 90, 91, 2, 3, 4, 5] -&gt; 5
Python 2, length 14 12 10 9



M=max;X=exit;i=input();L=[0]*M(i)
for&#9;a&#9;in&#9;i:L[a-1]=M(L[:a])+1
X(M(L))


Output is via exit code.

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\$.