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