The missing number P=23265.
Let each term be represented by f(x) where f denotes a quadratic function and x is the order of the terms: 0, 1, 2, 3, where P=f(1).
f(0)=ax^2+bx+c=40316 when x=0, so c=40316.
f(2)=12650=4a+2b+40316, so 4a+2b=-27666, or 2a+b=-13833 and b=-(2a+13833).
f(3)=8471=9a+3b+40316, so 9a+3b=-31845, or 3a+b=-10615
Substituting for b: 3a-2a-13833=-10615, so a=3218, b=-20269.
P=f(1)=23265.