How to optimize this Python script?
<p>There are numerous solutions (a, b, c) for an integer right triangle with perimeter p, and for all these solutions a+b+c == p and the Pythagorean theorem also applies. I am writing a Python script to calculate the maximum number of solutions possible for a triangle with perimeter &lt;= 1000. </p>

<p>My script is correct, however it takes forever to run. I'm sure it would take more than 30 minutes even with my i7 processor, so I need to optimize it. Can someone help me? (This is a problem on Project Euler, in case anyone is wondering)</p>

<pre><code>def solutions(p):
    result = []

    for a in range(1, p + 1):
        for b in range(1, p - a + 1):
            for c in range(1, p - a - b + 1):
                if a + b + c == p and a &lt; b and b &lt; c:
                    d = a ** 2
                    e = b ** 2
                    f = c ** 2

                    if (d + e == f) or (e + f == d) or (f + d == e):
                        result.append((a, b, c))
    return len(result)


max_p = 0
max_solutions = 0

for p in range(3, 1001):
    print("Processing %d" % p)
    s = solutions(p)

    if s &gt; max_solutions:
        max_solutions = s
        max_p = p

print("%d has %d solutions" % (max_p, max_solutions))
</code></pre>
