Search for high-mass Z gamma resonances in e+ e- gamma and mu+ mu- gamma final states in proton-proton collisions at sqrt(s) = 8 and 13 TeV