def row_idx_from_mat_coords(n: int, i: int, j: int) ->int:
    """Vector index corresponding to the matrix upper triangle coordinates."""
    if i <= j:
        return int(i * n - (i - 1) * i / 2 + j - i)
    else:
        return int(j * n - (j - 1) * j / 2 + i - j)
