#include<cstdio>
int main()
{
int n,p;
int sum;
sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
if(i/10 != 7)
{
if(i%10 != 7)
{
if(i%7 != 0)
{
sum += i*i;
}
}
}
}
printf("%d",sum);
}