solve P39, P40