#!/usr/bin/env python
# coding=utf-8

# IN PROGRESS #
"""
Problem Definition :

Pentagonal numbers are generated by the formula, Pn=n(3n-1)/2. The first ten pentagonal numbers are:

1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...

It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 - 22 = 48, is not pentagonal.

Find the pair of pentagonal numbers Pj and Pk for which their sum and difference are pentagonal and D = Pk − Pj is minimised what is the value of D?

"""

__author__ = 'vivek'

import time
import math

startTime = time.clock()


def pentagonal(n):
    return n*(3*n - 1)/2


penta_numbers = [pentagonal(x) for x in xrange(1,5000)]

print "Run time...{} secs \n".format(round(time.clock() - startTime, 4))
answers = []

print(penta_numbers[1998])
print(penta_numbers[4998])

for i in xrange(0,1999):
    for j in xrange(i+1,1999):
        number1 = penta_numbers[i]
        number2 = penta_numbers[j]
        if number2+number1 in penta_numbers:# and number2-number1 in penta_numbers:
            answers.append(number1+ number2)
            #print("Found")
            print(number1, number2)
if answers:
    print(min(answers))
    print(len(answers))
else:
    print("Not found")

#print(penta_numbers)

print "Run time...{} secs \n".format(round(time.clock() - startTime, 4))
