def max_sum_increasing_subseq(a, n, index, k):
    dp = [0] * n
    for i in range(n):
        dp[i] = a[i]
    
    for i in range(1, n):
        for j in range(i):
            if a[i] > a[j] and dp[i] < dp[j] + a[i]:
                dp[i] = dp[j] + a[i]
    
    # Now find max sum of increasing subsequence ending at index 'index'
    # that can be extended to include a[k]
    # We need subsequences from prefix till index that end with value < a[k]
    # and include element at position index
    
    # Recompute: dp[i] = max sum increasing subsequence ending at i
    # We want dp[index] where the subsequence ends at 'index' and a[index] < a[k]
    
    if a[index] >= a[k]:
        return 0
    
    return dp[index] + a[k]