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
n, T = map(int, input().split()) a = list(map(int, input().split())) max_val = 300 dp = [0] * (max_val + 1) lengths = [0] for _ in range(min(T, 300)): new_dp = dp.copy() for num in a: prefix_max = 0 for v in range(num + 1): if dp[v] > prefix_max: prefix_max = dp[v] if new_dp[num] < prefix_max + 1: new_dp[num] = prefix_max + 1 dp = new_dp current_max = max(dp) lengths.append(current_max) if len(lengths) >= 3: inc_prev = lengths[-1] - lengths[-2] inc_prev_prev = lengths[-2] - lengths[-3] if inc_prev == inc_prev_prev: total_reps = len(lengths) - 1 remaining = T - total_reps print(lengths[-1] + remaining * inc_prev) exit() if T <= len(lengths) - 1: print(lengths[T]) else: last_inc = lengths[-1] - lengths[-2] remaining = T - (len(lengths) - 1) print(lengths[-1] + remaining * last_inc)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.