input: from typing import List
  
  def sum_of_powers(nums: List[int], k: int) -> int:
      """
      You are given an integer array nums of length n, and a positive integer k.
  
      The power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence.
  
      Return the sum of powers of all subsequences of nums which have length equal to k.
  
      Since the answer may be large, return it modulo 10^9 + 7.
  
      Examples:
      >>> nums = [1,2,3,4], k = 3
      4
      >>> nums = [2,2], k = 2
      0
      >>> nums = [4,3,-1], k = 2
      10
  
      Constraints:
      2 <= n == nums.length <= 50
      -10^8 <= nums[i] <= 10^8 
      2 <= k <= n
      """
  
output: 
      MOD = 10**9 + 7
      n = len(nums)
      nums.sort()
      
      def power(subseq):
          return min(abs(subseq[i] - subseq[i-1]) for i in range(1, len(subseq)))
      
      def combinations(arr, k):
          if k == 0:
              return [[]]
          if not arr:
              return []
          return [[arr[0]] + c for c in combinations(arr[1:], k-1)] + combinations(arr[1:], k)
      
      all_subseqs = combinations(nums, k)
      result = sum(power(subseq) for subseq in all_subseqs) % MOD
      
      return result
  