<doocs>0629.K Inverse Pairs Array_1.py
def kInversePairs( n: int, k: int) -> int:
    mod = 1000000007
    dp, pre = [0] * (k + 1), [0] * (k + 2)
    for i in range(1, n + 1):
        dp[0] = 1
    
        for j in range(1, k + 1):
            dp[j] = (pre[j + 1] - pre[max(0, j - i + 1)] + mod) % mod
    
        for j in range(1, k + 2):
            pre[j] = (pre[j - 1] + dp[j - 1]) % mod
    
    return dp[k]
def sample_funcname ( var_0 : int , var_2 : int ) -> int :
    var_4 = 1000000007
    var_7 , var_9 = [ 0 ] * ( var_2 + 1 ) , [ 0 ] * ( var_2 + 2 )
    for var_11 in range ( 1 , var_0 + 1 ) :
        var_7 [ 0 ] = 1
        for var_12 in range ( 1 , var_2 + 1 ) :
            var_7 [ var_12 ] = ( var_9 [ var_12 + 1 ] - var_9 [ max ( 0 , var_12 - var_11 + 1 ) ] + var_4 ) % var_4
        for var_12 in range ( 1 , var_2 + 2 ) :
            var_9 [ var_12 ] = ( var_9 [ var_12 - 1 ] + var_7 [ var_12 - 1 ] ) % var_4
    return var_7 [ var_2 ]
