s=[n*(n+1)*(2*n+1)/6 for n in range(7072)] print sum(set(k for i in range(7070) for j in range(i+2,7072) for k in [s[j]-s[i]] if k < 100000000 and k==int(str(k)[::-1])))