Leading neutron energy and p(T) distributions in deep inelastic scattering and photoproduction at HERA