#include <iostream> using namespace std; bool divBy7(int x){ if(x % 7 == 0)return true; while(x){ int num; num = x % 10; if(num == 7)return true; x = x / 10; } return false; } int main(){ int n = 0; while(cin >> n){ int sum = 0; for(int i = 0; i <= n; i ++){ if(!divBy7(i)){ sum = sum + i * i; } } cout << sum << endl; } return 0; }