def nCkModp(n, k, p):  
    """
    Returns nCk % p
    
    Parameters
    ----------
    n : int
        denotes n in nCk%p
    k : int
        denotes k in nCk%p
    p : int
        denotes p in nCk%p
    return : int
        returns an integer

    """
    if (k > n- k): 
        k = n - k    
    Coef = [0 for i in range(k + 1)] 
  
    Coef[0] = 1
    for i in range(1, n + 1):  
        for j in range(min(i, k), 0, -1):  
            Coef[j] = (Coef[j] + Coef[j-1]) % p 
    return Coef[k]