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())) # Compute DP for first copy dp_prev = [1] * n for i in range(n): for j in range(i): if a[j] <= a[i] and dp_prev[j] + 1 > dp_prev[i]: dp_prev[i] = dp_prev[j] + 1 lengths = [max(dp_prev)] # Compute up to 200 copies or until increments stabilize stable = False for _ in range(1, 200): current_dp = [0] * n for i in range(n): max_prev = 0 for j in range(n): if a[j] <= a[i]: max_prev = max(max_prev, dp_prev[j]) current_max = 1 for j in range(i): if a[j] <= a[i]: current_max = max(current_max, current_dp[j] + 1) current_dp[i] = max(max_prev + 1, current_max) current_len = max(current_dp) lengths.append(current_len) # Check for stabilization of increments if len(lengths) >= 3: inc1 = lengths[-1] - lengths[-2] inc2 = lengths[-2] - lengths[-3] if inc1 == inc2: stable = True break dp_prev = current_dp.copy() if T <= len(lengths): print(lengths[T-1]) else: if len(lengths) < 2: m = lengths[0] else: m = lengths[-1] - lengths[-2] total = lengths[-1] + (T - len(lengths)) * m 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.