def idx(i, j, n):
    """Let A[:, :] be a symmetric matrix (squareform) of size n by n with zeros on the diagonal
    Let L[:] be the longform of A. Then for i < j, we have A[i, j] = L[idx(i, j, n)]"""
    return n * (n - 1) // 2 - (n - i) * (n - i - 1) // 2 + j - i - 1