Extension of SCF and DFT versions of chemical Hamiltonian approach to N interacting subsystems and an algorithm for their efficient implementation