#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int s = 0;
for (int i = 1; i <= n; i++)
{
if (i % 7 == 0)
continue;
if (i % 10 == 7)
continue;
if (i / 10 == 7)
continue;
s += i * i;
}
cout << s;
return 0;
}