while True:
try:
res = 0
for i in range(1, int(input()) + 1):
if "7" not in str(i) and i % 7 != 0:
res += i ** 2
print(res)
except:
break
while True:
try:
res = 0
for i in range(1, int(input()) + 1):
if "7" not in str(i) and i % 7 != 0:
res += i ** 2
print(res)
except:
break