The law of conservation of energy:
T + U = const
where T=mv22 is kinetic energy, m - mass, v - speed, U=−GmMr is potential energy, r is the distance to the center of second body.
Therefore:
−GM1md2−GM2md2+mv22=0+0+0
v2=4Gd(M1+M2)
v=√4Gd(M1+M2)
v=√4Gd(M1+M2)