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