COMBINATORICS || Helpful solution  
IntuitionThink about how much elements are greater and smaller than current element, and how can sorting help. now think about in how much of such subsequences
# Intuition
Think about how much elements are greater and smaller than current element, and how can sorting help. now think about in how much of such subsequences you can have this element as maximum or minimum 

now think about how to precompute factorials to increase time complexity 


I am leaving the part of finding tc and sc to you so you can understand it better 

happy coding 

Ps - Yes, this is my alternative account, I am knight level coder , so do not feel demotivated that a random stupid 1700 kid solves this , this question was genuienly hard , and I got stucked with applying dp approach at first 
# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```cpp []
class Solution {
public:
    int mod = 1e9 + 7;

    vector<long long> fact, invFact;

    void precomputeFactorials(int n) {
        fact.resize(n + 1, 1);
        invFact.resize(n + 1, 1);

        for (int i = 2; i <= n; i++) {
            fact[i] = (fact[i - 1] * i) % mod;
        }

        invFact[n] = modExp(fact[n], mod - 2);
        for (int i = n - 1; i >= 0; i--) {
            invFact[i] = (invFact[i + 1] * (i + 1)) % mod;
        }
    }

    long long modExp(long long x, long long y) {
        long long res = 1;
        x = x % mod;
        while (y > 0) {
            if (y & 1) {
                res = (res * x) % mod;
            }
            x = (x * x) % mod;
            y >>= 1;
        }
        return res;
    }

    long long combination(int n, int r) {
        if (r > n || r < 0) return 0;
        return (((fact[n] * invFact[r]) % mod) * invFact[n - r]) % mod;
    }

    int minMaxSums(vector<int>& nums, int k) {
        int n = nums.size();
        precomputeFactorials(n);  // Precompute factorials and inverses

        int res = 0;
        sort(nums.begin(), nums.end());

        for (int i = 0; i < n; i++) {
            int ele = nums[i], mini = i, maxi = n - i - 1;
            long long possible = 2;

            for (int j = 2; j <= min(k, n); j++) {
                int need = maxi - (j - 1);
                if (need >= 0) {
                    possible = (possible + combination(maxi, need)) % mod;
                } else {
                    break;
                }
            }

            for (int j = 2; j <= min(k, n); j++) {
                int need = mini - (j - 1);
                if (need >= 0) {
                    possible = (possible + combination(mini, need)) % mod;
                } else {
                    break;
                }
            }

            res = (res + ele * possible) % mod;
        }
        return res;
    }
};

```
['Combinatorics', 'C++']