Increasing the Efficiency of Terahertz Generation during the Current Flow through Magnetic Junctions Formed by Inhomogeneous Ultrathin Films of a Ferromagnetic Metal