import math


def row_index(k, n):
    """
    See Also:
        https://stackoverflow.com/questions/13079563/how-does-condensed-distance-matrix-work-pdist

    Args:
        k: Condensed index.
        n: Dimension of distance matrix.

    Returns:
        Row index.
    """
    return int(math.ceil((1 / 2.) * (- (-8 * k + 4 * n ** 2 - 4 * n - 7) ** 0.5 + 2 * n - 1) - 1))