Triangular Square Numbers Square numbers are those that take the form of \$n^2\$ where \$n\$ is an integer. These are also called perfect squares, because when you take their square root you get an integer.
The first 10 square numbers are: (OEIS)
0, 1, 4, 9, 16, 25, 36, 49, 64, 81

Triangular numbers are numbers that can form an equilateral triangle. The n-th triangle number is equal to the sum of all natural numbers from 1 to n.
The first 10 triangular numbers are: (OEIS)
0, 1, 3, 6, 10, 15, 21, 28, 36, 45

Square triangular numbers are numbers that are both square and triangular.
The first 10 square triangular numbers are: (OEIS)
0, 1, 36, 1225, 41616, 1413721, 48024900, 1631432881, 55420693056, 1882672131025, 63955431761796

There is an infinite number of square numbers, triangle numbers, and square triangular numbers.
Write a program or named function that given an input (parameter or stdin) number \$n\$, calculates the \$n\$th square triangular number and outputs/returns it, where n is a positive nonzero number. (For \$n=1\$ return 0)
For the program/function to be a valid submission it should be able to return at least all square triangle numbers smaller than \$2^{31}-1\$.
Bonus
-4 bytes for being able to output all square triangular numbers less than 2^63-1
-4 bytes for being able to theoretically output square triangular numbers of any size.
+8 byte penalty for solutions that take nonpolynomial time.
Bonuses stack.
This is code-golf challenge, so the answer with the fewest bytes wins.
Python 2, 45 - 4 - 4 = 37



a=1;b=0
exec"a,b=b,34*b-a+2;"*input()
print a


Iterates using the reccurence

f(0) = 1
f(1) = 0
f(k) = 34*f(k-1)-f(k-2)+2


In theory, this supports numbers of any size, but runs in exponential time, so it shouldn't qualify for the bonuses. Should work for numbers of any size. For example, for 100, gives

1185827220993342542557325920096705939276583904852110550753333094088280194260929920844987597980616456388639477930416411849864965254621398934978872054025


A recursive solution uses 41 chars, but shouldn't qualify because it takes exponential time.

f=lambda k:k&gt;2and 34*f(k-1)-f(k-2)+2or~-k