Let M = Mass of the sun
M' = Mass of Mars
R = Radius of the orbit of the Mars
m = mass of the spaceship
The P.E. of spaceship due to gravitional attraction of the sun = -GMm/R
P.E. of the spaceship due to gravitational attraction of Mars = -GM'm/R'
Since, K.E. of the spaceship = 0
Total energy of the spaceship
= -GMm/R - GM'm/R' = -Gm[M/R + M'R']
The energy required to rocket out the spaceship from the solar system,
= -(total energy of spacesh)