input = open('data4.txt','r')
output = open('out4.txt','w')

dictionary = []
total = 0
sum = 0
for x in range(0,50000):
	temp = str(x)
	for y in range(0,len(temp)):
		sum = sum + int(temp[y])
	dictionary.append(str((x*sum) % 99999))
	sum = 0

for x in input.readlines():
	temp = x.split()
	for y in range(0,len(dictionary)):
		dic = str(dictionary[y])
		if (int(temp[0]) == int(dic[0:len(temp[0])])):
			total = total + 1
	#print total
	output.write(str(total) + '\n')
	total = 0
output.close()

