Fully optimized euler #39!
from fractions import gcd
def euler39optimized():
sum_count = [0] * 1001
y = 2
while y**2 <= 500:
for z in [x for x in range(y) if gcd(y, x) == 1]:
a = y**2 - z**2
b = 2*y*z
c = y**2 + z**2
for i in range(1, 1001/(a+b+c) + 1):
sum_count[a*i + b*i + c*i] += 1
y += 1
return sum_count.index(max(sum_count))