  A search for long-lived heavy neutral leptons (HNLs) is presented, which
considers the hadronic final state and coupling scenarios involving all three
lepton generations in the 2-20 GeV HNL mass range for the first time. Events
comprising two leptons (electrons or muons) and jets are analyzed in a data
sample of proton-proton collisions, recorded with the CMS experiment at the
CERN LHC at a centre-of-mass energy of 13 TeV, corresponding to an integrated
luminosity of 138 fb$^{-1}$. A novel jet tagger, based on a deep neural
network, has been developed to identify jets from an HNL decay using various
features of the jet and its constituent particles. The network output can be
used as a powerful discriminating tool to probe a broad range of HNL lifetimes
and masses. Contributions from background processes are determined from data.
No excess of events in data over the expected background is observed. Upper
limits on the HNL production cross section are derived as functions of the HNL
mass and the three coupling strengths $V_{\ell\mathrm{N}}$ to each lepton
generation $\ell$ and presented as exclusion limits in the coupling-mass plane,
as lower limits on the HNL lifetime, and on the HNL mass. In this search, the
most stringent limit on the coupling strength is obtained for pure muon
coupling scenarios; values of $\lvert V_{\mu\mathrm{N}}\rvert^{2}$ $\gt $ 5 (4)
$\times$ 10$^{-7}$ are excluded for Dirac (Majorana) HNLs with a mass of 10 GeV
at a confidence level of 95% that correspond to proper decay lengths of 17 (10)
mm.
