Dynamic Programming and Bitwise Manipulation for Efficient Subsequence Sum Calculation 
IntuitionApproachsorting the Array:
First, let's sort given array nums, so it'll be easier to get subsequences numbers.Combinations (n choose r):Dynamically mak
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
sorting the Array:
First, let's sort given array nums, so it'll be easier to get subsequences numbers.

Combinations (n choose r):

Dynamically make a 2D list, ncr in which combinations(n choose r) values will be stored, compute them modulo:
1
0
9+
7

Over the Sorted Array:

For each element in the sorted array, take the number of subsequences it can be done with this and all the previous elements.

For each element, update the answer by adding the product of the element (as either maximum or minimum) and the number of subsequences it can be part of. Make sure to take this sum modulo
1
0
9
+
7
.

Return the Result:

After iterating through all elements in the array, return the final calculated sum modulo
1
0
9

# Complexity
Time Complexity: 
o(𝑛log𝑛+𝑛×𝑘)

Space Complexity: 
𝑂(𝑛×𝑘)

# Code
```python3 []
from typing import List

class Solution:
    def minMaxSums(self, nums: List[int], k: int) -> int:
        nums.sort()
        ans = 0
        MOD = 10**9 + 7
        n = len(nums)
        
        ncr = [[0] * (k + 1) for _ in range(n + 1)]
        ncr[0][0] = 1
        for i in range(1, n + 1):
            ncr[i][0] = 1
            for j in range(1, k + 1):
                ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % MOD

        for i in range(n):
            numberOfSubsequences = 0
            for j in range(k):
                if i >= j:
                    numberOfSubsequences = (numberOfSubsequences + ncr[i][j]) % MOD
            ans = (ans + (nums[i] + nums[n - i - 1]) * numberOfSubsequences) % MOD
        
        return ans

```
['Python3']