PSX gains 245 points, closing at 40,077 points