You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know…
- User
You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array. Input
The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 300).
Output
Print a single number — the length of a sought sequence.
Examples
Input
4 3 3 1 4 2
Output
5
Note
The array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.
Assistant
import bisect n, T = map(int, input().split()) base = list(map(int, input().split())) max_copies = min(T, 200) L = [] for k in range(1, max_copies + 1): current_array = base * k tails = [] for num in current_array: idx = bisect.bisect_right(tails, num) if idx == len(tails): tails.append(num) else: tails[idx] = num L.append(len(tails)) if T <= max_copies: print(L[T-1]) else: deltas = [L[i+1] - L[i] for i in range(len(L)-1)] found = False for i in range(len(deltas)-1): if deltas[i] == deltas[i+1]: stabilized_delta = deltas[i] stabilized_L = L[i+1] copies_processed = i + 2 # k = i+2 is the number of copies processed total = stabilized_L + (T - copies_processed) * stabilized_delta print(total) found = True break if not found: last_delta = deltas[-1] total = L[-1] + (T - max_copies) * last_delta print(total)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.