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
pythonn, T = map(int, input().split()) a = list(map(int, input().split())) def compute_lnds(arr): if not arr: return 0 dp = [1] * len(arr) for i in range(len(arr)): for j in range(i): if arr[j] <= arr[i]: if dp[j] + 1 > dp[i]: dp[i] = dp[j] + 1 return max(dp) if T == 1: print(compute_lnds(a)) else: a2 = a * 2 a3 = a * 3 l1 = compute_lnds(a) l2 = compute_lnds(a2) l3 = compute_lnds(a3) if T <= 3: print([l1, l2, l3][T-1]) else: d = l3 - l2 if l2 - l1 == d: result = l2 + (T - 2) * d else: result = l3 + (T - 3) * d print(result)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.