def t(n):
    return n * (n + 1) // 2


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


def h(n):
    return n * (2 * n - 1)


def euler_045():
    n_max = 100000
    s = 0

    t_list = [t(n) for n in range(1, n_max + 1)]
    p_set = {p(n) for n in range(1, n_max + 1)}
    h_set = {h(n) for n in range(1, n_max + 1)}

    for n in range(1, n_max + 1):
        if t_list[n - 1] in p_set and t_list[n - 1] in h_set:
            t_ = t_list[n - 1]
            if t_ > 40755:
                s = t_
    return s


if __name__ == "__main__":
    print("e045.py: " + str(euler_045()))
    assert(euler_045() == 1533776805)
