Fast triangular factorization of the sum of quasi-Toeplitz and quasi-Hankel matrices