def fun(n): flag = 0 if n % 7 == 0: return 0 while n: t = n % 10 n = n / 10 if t == 7: return 0 return 1 def shu(n): arr = [] for i in range(1, n+1): if fun(i): arr.append(i**2) return sum(arr) while True: try: n = int(input()) print(shu(n)) except: break