#include <iostream>
using namespace std;

bool isUnrelevantSeven(int n){
    if(n%7 == 0)return false;
    string s = to_string(n);
    for(int i =0;i<s.length();i++)
        if(s[i]=='7')return false;
    return true;
}

int main() {
    int n;cin>>n;
    int res=0;
    for(int i =1;i<=n;i++)
        if(isUnrelevantSeven(i))res+=i*i;
    cout<<res<<endl;
}
// 64 位输出请用 printf("%lld")

qd