#include<cstdio>
int Judge7(int n){
    int a,b,c;
    int x=n;
    c=n%10;
    n=n/10;
    b=n%10;
    n=n/10;
    a=n%10;
    if(0==x%7 || 7==a || 7==b || 7==c ){
        return 0;
    }
    else return x;

}
int main(){
    int i,sum=0;
    scanf("%d",&i);
    for(int j=0;j<=i;++j){
      sum= sum+Judge7(j)* Judge7(j);
    }
    printf("%d\n",sum);
}