The KPZ equation with flat initial condition and the directed polymer with one free end