 def issumofsqcube(n, count=0, b=2):
     while count <= 5 and (b in range(2, 1 + int(pow(n - 4, 1.0/3)))):
         if sqrt(n - pow(b, 3))%1 == 0:
             count = count + 1
             b = b + 1
         else:
             b = b + 1
     return count == 4
 
 def nextpal(n):
     while True:
         n = n+1
         r = str(n)[::-1]
         if int(r) == n:
             return int(r)
 
 def sumofpal(n, count=0, s=0, i=11):
     while count <= n:
         if issumofsqcube(i):
             s = s + i
             count += 1
             i = nextpal(i)
         else:
             i = nextpal(i)
     return s
 
 print(sumofpal(1))