Simple approach | Python 3
ApproachSort the array, then we can observe tha each element is max for its left side and min for its right side.
So chooses rest of elements from either side;
# Approach
<!-- Describe your approach to solving the problem. -->
Sort the array, then we can observe tha each element is max for its left side and min for its right side.
So chooses rest of elements from either side; atmost $k - 1$ elements.
let's say maximum length of subsequnce is $L$ from $m$ elements.
hence total count is equal to
`mC0 + mC1 + ... + mCL`
`1   + m / 1  + m / 1 * (m - 1) / 2 + m / 1 * (m - 1) / 2 * (m - 2) / 3 + ...`
Loop from $0$ to $L - 1$, then update by multiply the previous term with $(m - j) / (j + 1)$. This way dont need to calculate each comibination seperately.

# Note
- Caching each result, since same value is used later. ie, $i$ and $n - 1 - i$.
- In C++, there is a limtation to this approach, due to 64-bit limit on `long long`. Taking modulo of each term gives wrong answer. Give suggestions.



# Complexity
- Time complexity: $$O(n + k)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->


- Space complexity: $$O(n)$$  for caching
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def minMaxSums(self, nums: List[int], k: int) -> int:
        mod = 10**9 + 7
        @lru_cache(None)
        def total(N: int):
            max_len = min(N, k - 1)
            res, prev = 1, 1
            for j in range(max_len):
                prev = (N - j) * prev // (j + 1)
                res = (res + prev)
            return res

        nums.sort()
        n = len(nums)
        res = 0
        for i in range(n):
            res = (res + (total(n - i - 1) + total(i)) * nums[i]) % mod
        return res
        
```
['Math', 'Python3']