For all the possible sets Calculate max ( S ) and min ( S )
for i in range ( n ) : NEW_LINE INDENT x = n - i - 1 NEW_LINE if ( x >= k ) : NEW_LINE INDENT ans -= ( binomial ( x , k ) * a [ i ] ) % mod NEW_LINE DEDENT y = i NEW_LINE if ( y >= k ) : NEW_LINE INDENT ans += ( binomial ( y , k ) * a [ i ] ) % mod NEW_LINE DEDENT ans = ( ans + mod ) % mod NEW_LINE DEDENT return ans NEW_LINE