N=10**12
M=10**6
c=[0]*M
b=[0]*6
for i in range(M):
b[0]=(9*i*i-i)%M
b[1]=(9*i*i+3*i+1)%M
b[2]=(9*i*i+6*i+2)%M
b[3]=(9*i*i+7*i+2)%M
b[4]=(9*i*i+13*i+5)%M
b[5]=(9*i*i+14*i+5)%M
for j in range(6):
c[b[j]]+=(N-j-6*i+6*M)/(6*M)
print sum(c[i]*(c[i]-1)/2 for i in range(M))