#include int main(){ int n; while(scanf("%d",&n)!=EOF){ int answer=0; for(int i=1;i<=n;i++){ if(i%7==0||i%10==7||i/10==7){ continue; } answer+=i*i; } printf("%d\n",answer); } return 0; }