Company: DeShaw_24july
Difficulty: medium
Cost of Lineups Problem Description In a sports league, each player is assigned a rank from 1 to k. You are analyzing all possible ways to arrange n players in a lineup, where each player's rank is an integer from 1 to k. A team is defined as a group of k consecutive players (a contiguous subarray of length k). A team is considered perfect if it contains every rank from 1 to k exactly once (the team is a permutation of {1, 2, ..., k}). The cost of a lineup is the maximum number of non-overlapping perfect teams that can be selected from it. Each player can belong to at most one perfect team. For example, suppose n = 10, k = 3, and the array is [1, 2, 1, 3, 2, 3, 1, 2, 3, 1]. In that case, its cost is 2 because, for example, we can choose the subarray from the 2nd element to the 4th element and from the 7th element to the 9th element, and we can show that it's impossible to choose more than 2 subarrays. Calculate the sum of costs over all possible lineups of length n (all arrays of lengt