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