A Hybrid N-Body-Coagulation Code for Planet Formation