Comments

There is no assignment of 0 when defining P in your code. I think it may be an error here.

A nice round, thanks for the fast editoria!!!