Final solution of ps6