Problem D - k-monotonic sequences -------------------------------- Monotonically increasing (or just monotonic) sequences are lists of numbers which, when sorted in ascending order, results in a list in which every number is strictly bigger than all the previous numbers in that list. We can generalize this to call a sequence k-monotonic if after sorting the sequence in ascending order, we get a list in which the the first k numbers form a monotonic sequence but the first k+1 numbers do not. In this problem you are given a list of at most 10000 integers between 0 and 100000 (both inclusive) and asked to determine the value of k. Note that k is defined for every sequence. Input ----- Input consists of multiple cases. Each case starts with a line containing 1 positive integer N (0 <= N < 10001) that indicates the number of cases. The next line consists of N non-negative integers separated by spaces. Input is terminated by a line containing a single zero, with no following lines. This line should not produce any k value. Output ------ For each instance produce one line of output containing the value of k. Sample Input ------------ 3 5 5 5 4 4 3 1 2 0 Output for Sample Input ----------------------- 1 4