#include <bits/stdc++.h>   long long nmax[11] = {0,      9,       99,       999,       9999,        99999,                         999999, 9999999, 99999999, 999999999, 9999999999LL};   long long P[11][11];   long long cnt[11][11][11], C[11][11], totalcnt[11][11], tmp;   long long nsel[11][11][11][11][11], fact[11], nways;   int N, x, y, len, i, j, jstart, nx, ny, cnx, cny, difx, dify, nextx, nexty;   void ComputeComb() {     int i, j;     C[0][0] = 1;     for (i = 1; i < 11; i++) {       C[i][0] = 1;       for (j = 1; j <= i; j++) {         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;       }     }   }   inline int extended_gcd(long long A, long long B, long long &X, long long &Y) {     if (B == 0) {       X = 1;       Y = 0;       return A;     }     long long X0, Y0, D;     D = extended_gcd(B, A % B, X0, Y0);     X = Y0;     Y = X0 - (A / B) * Y0;     return D;   }   long long inv[11];   void ComputeInv() {     long long garbage;     for (int i = 1; i < 11; i++) {       extended_gcd(i, 1000000007, inv[i], garbage);       inv[i] %= 1000000007;       while (inv[i] < 0) inv[i] += 1000000007;     }   }   void ComputeFact() {     fact[0] = 1;     for (int i = 1; i < 11; i++) {       fact[i] = (fact[i - 1] * i) % 1000000007;     }   }   void ComputeP() {     int i, j;     for (i = 0; i < 11; i++) {       P[i][0] = 1;       for (j = 1; j < 11; j++) P[i][j] = (P[i][j - 1] * i) % 1000000007;     }   }   int digits[11], ndigits;   void GetN(int N) {     ndigits = 0;     while (N > 0) {       digits[ndigits] = N % 10;       N /= 10;       ndigits++;     }   }   long long totalcnt2[11][11];   void TestBruteForce() {     int x, y, i, j;     for (i = 1; i <= N; i++) {       x = y = 0;       j = i;       while (j > 0) {         if (j % 10 == 4)           x++;         else if (j % 10 == 7)           y++;         j /= 10;       }       totalcnt2[x][y]++;     }     for (x = 0; x < 11; x++)       for (y = 0; y < 11; y++)         if (totalcnt[x][y] != totalcnt2[x][y]) {           fprintf(stderr,  !!! x=%d y=%d: %I64d %I64d n , x, y, totalcnt[x][y],                   totalcnt2[x][y]);         }   }   int main() {     ComputeComb();     ComputeInv();     ComputeFact();     ComputeP();     scanf( %d , &N);     GetN(N);     for (len = 1; len < 11; len++)       for (x = 0; x < 11 && x <= len; x++)         for (y = 0; y < 11 && x + y <= len; y++) {           cnt[len][x][y] = 0;           if (len < ndigits) {             if (x == 0 && y == 0)               tmp = P[8][len] % 1000000007;             else {               tmp = (C[len][x] * C[len - x][y]);               tmp = (tmp * P[8][len - x - y]);             }             cnt[len][x][y] = tmp;           } else if (len == ndigits) {             nx = ny = 0;             for (i = ndigits - 1; i >= 0; i--) {               if (i == ndigits - 1)                 jstart = 1;               else                 jstart = 0;               for (j = jstart; j < digits[i]; j++) {                 cnx = nx;                 cny = ny;                 if (j == 4)                   cnx++;                 else if (j == 7)                   cny++;                 if (cnx <= x && cny <= y) {                   difx = x - cnx;                   dify = y - cny;                   if (difx == 0 && dify == 0)                     cnt[len][x][y] = (cnt[len][x][y] + P[8][i]);                   else                     cnt[len][x][y] = (cnt[len][x][y] + cnt[i][difx][dify]);                 }               }               if (digits[i] == 4)                 nx++;               else if (digits[i] == 7)                 ny++;             }             if (nx == x && ny == y) cnt[len][x][y]++;           }           if (len >= ndigits - 1) {             totalcnt[x][y] += cnt[len][x][y];             if (x == 0 && y == 0 && len == ndigits - 1) totalcnt[x][y]--;           }         }     for (x = 0; x < 11; x++)       for (y = 0; y < 11; y++)         if (totalcnt[x][y] > 0) {         }     nways = 1;     for (i = 0; i <= 6; i++) {       if (i > 0) {         nways = (nways * (totalcnt[0][0] - i + 1)) % 1000000007;         nways = (nways * inv[i]) % 1000000007;       }       nsel[0][0][0][0][i] = nways;     }     for (x = 0; x < 11; x++)       for (y = 0; y < 11; y++)         for (nx = 0; nx < 11; nx++)           for (ny = 0; ny < 11; ny++)             for (i = 0; i <= 6; i++)               if (nsel[x][y][nx][ny][i] > 0) {                 cnx = x;                 cny = y + 1;                 if (cny >= 11) {                   cnx++;                   cny = 0;                 }                 if (cnx >= 11) break;                 nways = 1;                 for (j = 0; j <= 6; j++) {                   nextx = nx + j * cnx;                   nexty = ny + j * cny;                   if (nextx >= 11 || nexty >= 11 || i + j > 6) break;                   if (j > 0) {                     nways = (nways * (totalcnt[cnx][cny] - j + 1)) % 1000000007;                     nways = (nways * inv[j]) % 1000000007;                   }                   tmp = (nways * nsel[x][y][nx][ny][i]) % 1000000007;                   nsel[cnx][cny][nextx][nexty][i + j] =                       (nsel[cnx][cny][nextx][nexty][i + j] + tmp) % 1000000007;                 }               }     long long answer = 0;     for (x = 0; x < 11; x++)       for (y = 0; y < 11; y++)         for (nx = 0; nx < 11; nx++)           for (ny = 0; ny < 11; ny++)             if (nx + ny < x + y) {               tmp = totalcnt[x][y];               tmp = (tmp * nsel[11 - 1][11 - 1][nx][ny][6]) % 1000000007;               answer = (answer + tmp) % 1000000007;             }     printf( %I64d n , (answer * fact[6]) % 1000000007);     return 0;   }