Problem: There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.

Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1, 2, ..., m. Each of these 7 parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.

The Little Elephant Political Party members believe in the lucky digits 4 and 7. They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number of lucky digits in the ballot numbers of 6 other parties. 

Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109 + 7).

Input

A single line contains a single positive integer m (7 ≤ m ≤ 109) — the number of possible numbers in the ballot.

Output

In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

7


Output

0


Input

8


Output

1440

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-11;
int n, a[10], k, t;
signed long long m[200][10] = {
    {1048576, 1835008, 1376256, 573440, 143360, 21504, 1792, 64, 0, 0},
    {2097152, 3670016, 2752512, 1146880, 286720, 43008, 3584, 128, 0, 0},
    {3145728, 5505024, 4128768, 1720320, 430080, 64512, 5376, 192, 0, 0},
    {4194304, 7340032, 5505024, 2293760, 573440, 86016, 7168, 256, 0, 0},
    {5242880, 9175040, 6881280, 2867200, 716800, 107520, 8960, 320, 0, 0},
    {6291456, 11010048, 8257536, 3440640, 860160, 129024, 10752, 384, 0, 0},
    {7340032, 12845056, 9633792, 4014080, 1003520, 150528, 12544, 448, 0, 0},
    {8388607, 14680065, 11010048, 4587520, 1146880, 172032, 14336, 512, 0, 0},
    {8388607, 15728641, 12845056, 5963776, 1720320, 315392, 35840, 2304, 64, 0},
    {8388608, 16777216, 14680064, 7340032, 2293760, 458752, 57344, 4096, 128,
     0},
    {9437184, 18612224, 16056320, 7913472, 2437120, 480256, 59136, 4160, 128,
     0},
    {10485760, 20447232, 17432576, 8486912, 2580480, 501760, 60928, 4224, 128,
     0},
    {11534336, 22282240, 18808832, 9060352, 2723840, 523264, 62720, 4288, 128,
     0},
    {12582911, 24117249, 20185088, 9633792, 2867200, 544768, 64512, 4352, 128,
     0},
    {12582911, 25165825, 22020096, 11010048, 3440640, 688128, 86016, 6144, 192,
     0},
    {12582912, 26214400, 23855104, 12386304, 4014080, 831488, 107520, 7936, 256,
     0},
    {13631488, 28049408, 25231360, 12959744, 4157440, 852992, 109312, 8000, 256,
     0},
    {14680064, 29884416, 26607616, 13533184, 4300800, 874496, 111104, 8064, 256,
     0},
    {15728640, 31719424, 27983872, 14106624, 4444160, 896000, 112896, 8128, 256,
     0},
    {16777216, 33554432, 29360128, 14680064, 4587520, 917504, 114688, 8192, 256,
     0},
    {17825792, 35389440, 30736384, 15253504, 4730880, 939008, 116480, 8256, 256,
     0},
    {18874368, 37224448, 32112640, 15826944, 4874240, 960512, 118272, 8320, 256,
     0},
    {19922944, 39059456, 33488896, 16400384, 5017600, 982016, 120064, 8384, 256,
     0},
    {20971520, 40894464, 34865152, 16973824, 5160960, 1003520, 121856, 8448,
     256, 0},
    {22020096, 42729472, 36241408, 17547264, 5304320, 1025024, 123648, 8512,
     256, 0},
    {23068672, 44564480, 37617664, 18120704, 5447680, 1046528, 125440, 8576,
     256, 0},
    {24117248, 46399488, 38993920, 18694144, 5591040, 1068032, 127232, 8640,
     256, 0},
    {25165823, 48234497, 40370176, 19267584, 5734400, 1089536, 129024, 8704,
     256, 0},
    {25165823, 49283073, 42205184, 20643840, 6307840, 1232896, 150528, 10496,
     320, 0},
    {25165824, 50331648, 44040192, 22020096, 6881280, 1376256, 172032, 12288,
     384, 0},
    {26214400, 52166656, 45416448, 22593536, 7024640, 1397760, 173824, 12352,
     384, 0},
    {27262976, 54001664, 46792704, 23166976, 7168000, 1419264, 175616, 12416,
     384, 0},
    {28311552, 55836672, 48168960, 23740416, 7311360, 1440768, 177408, 12480,
     384, 0},
    {29360127, 57671681, 49545216, 24313856, 7454720, 1462272, 179200, 12544,
     384, 0},
    {29360127, 58720257, 51380224, 25690112, 8028160, 1605632, 200704, 14336,
     448, 0},
    {29360128, 59768832, 53215232, 27066368, 8601600, 1748992, 222208, 16128,
     512, 0},
    {30408704, 61603840, 54591488, 27639808, 8744960, 1770496, 224000, 16192,
     512, 0},
    {31457280, 63438848, 55967744, 28213248, 8888320, 1792000, 225792, 16256,
     512, 0},
    {32505856, 65273856, 57344000, 28786688, 9031680, 1813504, 227584, 16320,
     512, 0},
    {33554432, 67108864, 58720256, 29360128, 9175040, 1835008, 229376, 16384,
     512, 0},
    {34603008, 68943872, 60096512, 29933568, 9318400, 1856512, 231168, 16448,
     512, 0},
    {35651584, 70778880, 61472768, 30507008, 9461760, 1878016, 232960, 16512,
     512, 0},
    {36700160, 72613888, 62849024, 31080448, 9605120, 1899520, 234752, 16576,
     512, 0},
    {37748736, 74448896, 64225280, 31653888, 9748480, 1921024, 236544, 16640,
     512, 0},
    {38797312, 76283904, 65601536, 32227328, 9891840, 1942528, 238336, 16704,
     512, 0},
    {39845888, 78118912, 66977792, 32800768, 10035200, 1964032, 240128, 16768,
     512, 0},
    {40894464, 79953920, 68354048, 33374208, 10178560, 1985536, 241920, 16832,
     512, 0},
    {41943039, 81788929, 69730304, 33947648, 10321920, 2007040, 243712, 16896,
     512, 0},
    {41943039, 82837505, 71565312, 35323904, 10895360, 2150400, 265216, 18688,
     576, 0},
    {41943040, 83886080, 73400320, 36700160, 11468800, 2293760, 286720, 20480,
     640, 0},
    {42991616, 85721088, 74776576, 37273600, 11612160, 2315264, 288512, 20544,
     640, 0},
    {44040192, 87556096, 76152832, 37847040, 11755520, 2336768, 290304, 20608,
     640, 0},
    {45088768, 89391104, 77529088, 38420480, 11898880, 2358272, 292096, 20672,
     640, 0},
    {46137343, 91226113, 78905344, 38993920, 12042240, 2379776, 293888, 20736,
     640, 0},
    {46137343, 92274689, 80740352, 40370176, 12615680, 2523136, 315392, 22528,
     704, 0},
    {46137344, 93323264, 82575360, 41746432, 13189120, 2666496, 336896, 24320,
     768, 0},
    {47185920, 95158272, 83951616, 42319872, 13332480, 2688000, 338688, 24384,
     768, 0},
    {48234496, 96993280, 85327872, 42893312, 13475840, 2709504, 340480, 24448,
     768, 0},
    {49283072, 98828288, 86704128, 43466752, 13619200, 2731008, 342272, 24512,
     768, 0},
    {50331648, 100663296, 88080384, 44040192, 13762560, 2752512, 344064, 24576,
     768, 0},
    {51380224, 102498304, 89456640, 44613632, 13905920, 2774016, 345856, 24640,
     768, 0},
    {52428800, 104333312, 90832896, 45187072, 14049280, 2795520, 347648, 24704,
     768, 0},
    {53477376, 106168320, 92209152, 45760512, 14192640, 2817024, 349440, 24768,
     768, 0},
    {54525952, 108003328, 93585408, 46333952, 14336000, 2838528, 351232, 24832,
     768, 0},
    {55574528, 109838336, 94961664, 46907392, 14479360, 2860032, 353024, 24896,
     768, 0},
    {56623104, 111673344, 96337920, 47480832, 14622720, 2881536, 354816, 24960,
     768, 0},
    {57671680, 113508352, 97714176, 48054272, 14766080, 2903040, 356608, 25024,
     768, 0},
    {58720255, 115343361, 99090432, 48627712, 14909440, 2924544, 358400, 25088,
     768, 0},
    {58720255, 116391937, 100925440, 50003968, 15482880, 3067904, 379904, 26880,
     832, 0},
    {58720256, 117440512, 102760448, 51380224, 16056320, 3211264, 401408, 28672,
     896, 0},
    {59768832, 119275520, 104136704, 51953664, 16199680, 3232768, 403200, 28736,
     896, 0},
    {60817408, 121110528, 105512960, 52527104, 16343040, 3254272, 404992, 28800,
     896, 0},
    {61865984, 122945536, 106889216, 53100544, 16486400, 3275776, 406784, 28864,
     896, 0},
    {62914559, 124780545, 108265472, 53673984, 16629760, 3297280, 408576, 28928,
     896, 0},
    {62914559, 125829121, 110100480, 55050240, 17203200, 3440640, 430080, 30720,
     960, 0},
    {62914560, 126877696, 111935488, 56426496, 17776640, 3584000, 451584, 32512,
     1024, 0},
    {63963136, 128712704, 113311744, 56999936, 17920000, 3605504, 453376, 32576,
     1024, 0},
    {65011712, 130547712, 114688000, 57573376, 18063360, 3627008, 455168, 32640,
     1024, 0},
    {66060288, 132382720, 116064256, 58146816, 18206720, 3648512, 456960, 32704,
     1024, 0},
    {67108863, 134217729, 117440512, 58720256, 18350080, 3670016, 458752, 32768,
     1024, 0},
    {67108863, 135266305, 119275520, 60096512, 18923520, 3813376, 480256, 34560,
     1088, 0},
    {67108863, 136314881, 121110528, 61472768, 19496960, 3956736, 501760, 36352,
     1152, 0},
    {67108863, 137363457, 122945536, 62849024, 20070400, 4100096, 523264, 38144,
     1216, 0},
    {67108863, 138412033, 124780544, 64225280, 20643840, 4243456, 544768, 39936,
     1280, 0},
    {67108863, 139460609, 126615552, 65601536, 21217280, 4386816, 566272, 41728,
     1344, 0},
    {67108863, 140509185, 128450560, 66977792, 21790720, 4530176, 587776, 43520,
     1408, 0},
    {67108863, 141557761, 130285568, 68354048, 22364160, 4673536, 609280, 45312,
     1472, 0},
    {67108863, 142606336, 132120577, 69730304, 22937600, 4816896, 630784, 47104,
     1536, 0},
    {67108863, 142606336, 133169153, 71565312, 24313856, 5390336, 774144, 68608,
     3328, 64},
    {67108863, 142606337, 134217728, 73400320, 25690112, 5963776, 917504, 90112,
     5120, 128},
    {67108863, 143654913, 136052736, 74776576, 26263552, 6107136, 939008, 91904,
     5184, 128},
    {67108863, 144703489, 137887744, 76152832, 26836992, 6250496, 960512, 93696,
     5248, 128},
    {67108863, 145752065, 139722752, 77529088, 27410432, 6393856, 982016, 95488,
     5312, 128},
    {67108863, 146800640, 141557761, 78905344, 27983872, 6537216, 1003520,
     97280, 5376, 128},
    {67108863, 146800640, 142606337, 80740352, 29360128, 7110656, 1146880,
     118784, 7168, 192},
    {67108863, 146800641, 143654912, 82575360, 30736384, 7684096, 1290240,
     140288, 8960, 256},
    {67108863, 147849217, 145489920, 83951616, 31309824, 7827456, 1311744,
     142080, 9024, 256},
    {67108863, 148897793, 147324928, 85327872, 31883264, 7970816, 1333248,
     143872, 9088, 256},
    {67108863, 149946369, 149159936, 86704128, 32456704, 8114176, 1354752,
     145664, 9152, 256},
    {67108864, 150994944, 150994944, 88080384, 33030144, 8257536, 1376256,
     147456, 9216, 256},
    {68157440, 152829952, 152371200, 88653824, 33173504, 8279040, 1378048,
     147520, 9216, 256},
    {69206016, 154664960, 153747456, 89227264, 33316864, 8300544, 1379840,
     147584, 9216, 256},
    {70254592, 156499968, 155123712, 89800704, 33460224, 8322048, 1381632,
     147648, 9216, 256},
    {71303168, 158334976, 156499968, 90374144, 33603584, 8343552, 1383424,
     147712, 9216, 256},
    {72351744, 160169984, 157876224, 90947584, 33746944, 8365056, 1385216,
     147776, 9216, 256},
    {73400320, 162004992, 159252480, 91521024, 33890304, 8386560, 1387008,
     147840, 9216, 256},
    {74448896, 163840000, 160628736, 92094464, 34033664, 8408064, 1388800,
     147904, 9216, 256},
    {75497471, 165675009, 162004992, 92667904, 34177024, 8429568, 1390592,
     147968, 9216, 256},
    {75497471, 166723585, 163840000, 94044160, 34750464, 8572928, 1412096,
     149760, 9280, 256},
    {75497472, 167772160, 165675008, 95420416, 35323904, 8716288, 1433600,
     151552, 9344, 256},
    {76546048, 169607168, 167051264, 95993856, 35467264, 8737792, 1435392,
     151616, 9344, 256},
    {77594624, 171442176, 168427520, 96567296, 35610624, 8759296, 1437184,
     151680, 9344, 256},
    {78643200, 173277184, 169803776, 97140736, 35753984, 8780800, 1438976,
     151744, 9344, 256},
    {79691775, 175112193, 171180032, 97714176, 35897344, 8802304, 1440768,
     151808, 9344, 256},
    {79691775, 176160769, 173015040, 99090432, 36470784, 8945664, 1462272,
     153600, 9408, 256},
    {79691776, 177209344, 174850048, 100466688, 37044224, 9089024, 1483776,
     155392, 9472, 256},
    {80740352, 179044352, 176226304, 101040128, 37187584, 9110528, 1485568,
     155456, 9472, 256},
    {81788928, 180879360, 177602560, 101613568, 37330944, 9132032, 1487360,
     155520, 9472, 256},
    {82837504, 182714368, 178978816, 102187008, 37474304, 9153536, 1489152,
     155584, 9472, 256},
    {83886080, 184549376, 180355072, 102760448, 37617664, 9175040, 1490944,
     155648, 9472, 256},
    {84934656, 186384384, 181731328, 103333888, 37761024, 9196544, 1492736,
     155712, 9472, 256},
    {85983232, 188219392, 183107584, 103907328, 37904384, 9218048, 1494528,
     155776, 9472, 256},
    {87031808, 190054400, 184483840, 104480768, 38047744, 9239552, 1496320,
     155840, 9472, 256},
    {88080384, 191889408, 185860096, 105054208, 38191104, 9261056, 1498112,
     155904, 9472, 256},
    {89128960, 193724416, 187236352, 105627648, 38334464, 9282560, 1499904,
     155968, 9472, 256},
    {90177536, 195559424, 188612608, 106201088, 38477824, 9304064, 1501696,
     156032, 9472, 256},
    {91226112, 197394432, 189988864, 106774528, 38621184, 9325568, 1503488,
     156096, 9472, 256},
    {92274687, 199229441, 191365120, 107347968, 38764544, 9347072, 1505280,
     156160, 9472, 256},
    {92274687, 200278017, 193200128, 108724224, 39337984, 9490432, 1526784,
     157952, 9536, 256},
    {92274688, 201326592, 195035136, 110100480, 39911424, 9633792, 1548288,
     159744, 9600, 256},
    {93323264, 203161600, 196411392, 110673920, 40054784, 9655296, 1550080,
     159808, 9600, 256},
    {94371840, 204996608, 197787648, 111247360, 40198144, 9676800, 1551872,
     159872, 9600, 256},
    {95420416, 206831616, 199163904, 111820800, 40341504, 9698304, 1553664,
     159936, 9600, 256},
    {96468991, 208666625, 200540160, 112394240, 40484864, 9719808, 1555456,
     160000, 9600, 256},
    {96468991, 209715201, 202375168, 113770496, 41058304, 9863168, 1576960,
     161792, 9664, 256},
    {96468992, 210763776, 204210176, 115146752, 41631744, 10006528, 1598464,
     163584, 9728, 256},
    {97517568, 212598784, 205586432, 115720192, 41775104, 10028032, 1600256,
     163648, 9728, 256},
    {98566144, 214433792, 206962688, 116293632, 41918464, 10049536, 1602048,
     163712, 9728, 256},
    {99614720, 216268800, 208338944, 116867072, 42061824, 10071040, 1603840,
     163776, 9728, 256},
    {100663295, 218103809, 209715200, 117440512, 42205184, 10092544, 1605632,
     163840, 9728, 256},
    {100663295, 219152385, 211550208, 118816768, 42778624, 10235904, 1627136,
     165632, 9792, 256},
    {100663295, 220200961, 213385216, 120193024, 43352064, 10379264, 1648640,
     167424, 9856, 256},
    {100663295, 221249537, 215220224, 121569280, 43925504, 10522624, 1670144,
     169216, 9920, 256},
    {100663295, 222298113, 217055232, 122945536, 44498944, 10665984, 1691648,
     171008, 9984, 256},
    {100663295, 223346689, 218890240, 124321792, 45072384, 10809344, 1713152,
     172800, 10048, 256},
    {100663295, 224395265, 220725248, 125698048, 45645824, 10952704, 1734656,
     174592, 10112, 256},
    {100663295, 225443841, 222560256, 127074304, 46219264, 11096064, 1756160,
     176384, 10176, 256},
    {100663295, 226492416, 224395265, 128450560, 46792704, 11239424, 1777664,
     178176, 10240, 256},
    {100663295, 226492416, 225443841, 130285568, 48168960, 11812864, 1921024,
     199680, 12032, 320},
    {100663295, 226492417, 226492416, 132120576, 49545216, 12386304, 2064384,
     221184, 13824, 384},
    {100663295, 227540993, 228327424, 133496832, 50118656, 12529664, 2085888,
     222976, 13888, 384},
    {100663295, 228589569, 230162432, 134873088, 50692096, 12673024, 2107392,
     224768, 13952, 384},
    {100663295, 229638145, 231997440, 136249344, 51265536, 12816384, 2128896,
     226560, 14016, 384},
    {100663295, 230686720, 233832449, 137625600, 51838976, 12959744, 2150400,
     228352, 14080, 384},
    {100663295, 230686720, 234881025, 139460608, 53215232, 13533184, 2293760,
     249856, 15872, 448},
    {100663295, 230686721, 235929600, 141295616, 54591488, 14106624, 2437120,
     271360, 17664, 512},
    {100663295, 231735297, 237764608, 142671872, 55164928, 14249984, 2458624,
     273152, 17728, 512},
    {100663295, 232783873, 239599616, 144048128, 55738368, 14393344, 2480128,
     274944, 17792, 512},
    {100663295, 233832449, 241434624, 145424384, 56311808, 14536704, 2501632,
     276736, 17856, 512},
    {100663296, 234881024, 243269632, 146800640, 56885248, 14680064, 2523136,
     278528, 17920, 512},
    {101711872, 236716032, 244645888, 147374080, 57028608, 14701568, 2524928,
     278592, 17920, 512},
    {102760448, 238551040, 246022144, 147947520, 57171968, 14723072, 2526720,
     278656, 17920, 512},
    {103809024, 240386048, 247398400, 148520960, 57315328, 14744576, 2528512,
     278720, 17920, 512},
    {104857600, 242221056, 248774656, 149094400, 57458688, 14766080, 2530304,
     278784, 17920, 512},
    {105906176, 244056064, 250150912, 149667840, 57602048, 14787584, 2532096,
     278848, 17920, 512},
    {106954752, 245891072, 251527168, 150241280, 57745408, 14809088, 2533888,
     278912, 17920, 512},
    {108003328, 247726080, 252903424, 150814720, 57888768, 14830592, 2535680,
     278976, 17920, 512},
    {109051903, 249561089, 254279680, 151388160, 58032128, 14852096, 2537472,
     279040, 17920, 512},
    {109051903, 250609665, 256114688, 152764416, 58605568, 14995456, 2558976,
     280832, 17984, 512},
    {109051904, 251658240, 257949696, 154140672, 59179008, 15138816, 2580480,
     282624, 18048, 512},
    {110100480, 253493248, 259325952, 154714112, 59322368, 15160320, 2582272,
     282688, 18048, 512},
    {111149056, 255328256, 260702208, 155287552, 59465728, 15181824, 2584064,
     282752, 18048, 512},
    {112197632, 257163264, 262078464, 155860992, 59609088, 15203328, 2585856,
     282816, 18048, 512},
    {113246207, 258998273, 263454720, 156434432, 59752448, 15224832, 2587648,
     282880, 18048, 512},
    {113246207, 260046849, 265289728, 157810688, 60325888, 15368192, 2609152,
     284672, 18112, 512},
    {113246208, 261095424, 267124736, 159186944, 60899328, 15511552, 2630656,
     286464, 18176, 512},
    {114294784, 262930432, 268500992, 159760384, 61042688, 15533056, 2632448,
     286528, 18176, 512},
    {115343360, 264765440, 269877248, 160333824, 61186048, 15554560, 2634240,
     286592, 18176, 512},
    {116391936, 266600448, 271253504, 160907264, 61329408, 15576064, 2636032,
     286656, 18176, 512},
    {117440512, 268435456, 272629760, 161480704, 61472768, 15597568, 2637824,
     286720, 18176, 512},
    {118489088, 270270464, 274006016, 162054144, 61616128, 15619072, 2639616,
     286784, 18176, 512},
    {119537664, 272105472, 275382272, 162627584, 61759488, 15640576, 2641408,
     286848, 18176, 512},
    {120586240, 273940480, 276758528, 163201024, 61902848, 15662080, 2643200,
     286912, 18176, 512},
    {121634816, 275775488, 278134784, 163774464, 62046208, 15683584, 2644992,
     286976, 18176, 512},
    {122683392, 277610496, 279511040, 164347904, 62189568, 15705088, 2646784,
     287040, 18176, 512},
    {123731968, 279445504, 280887296, 164921344, 62332928, 15726592, 2648576,
     287104, 18176, 512},
    {124780544, 281280512, 282263552, 165494784, 62476288, 15748096, 2650368,
     287168, 18176, 512},
    {125829119, 283115521, 283639808, 166068224, 62619648, 15769600, 2652160,
     287232, 18176, 512},
    {125829119, 284164097, 285474816, 167444480, 63193088, 15912960, 2673664,
     289024, 18240, 512},
    {125829120, 285212672, 287309824, 168820736, 63766528, 16056320, 2695168,
     290816, 18304, 512},
    {126877696, 287047680, 288686080, 169394176, 63909888, 16077824, 2696960,
     290880, 18304, 512},
    {127926272, 288882688, 290062336, 169967616, 64053248, 16099328, 2698752,
     290944, 18304, 512},
    {128974848, 290717696, 291438592, 170541056, 64196608, 16120832, 2700544,
     291008, 18304, 512},
    {130023423, 292552705, 292814848, 171114496, 64339968, 16142336, 2702336,
     291072, 18304, 512},
    {130023423, 293601281, 294649856, 172490752, 64913408, 16285696, 2723840,
     292864, 18368, 512},
    {130023424, 294649856, 296484864, 173867008, 65486848, 16429056, 2745344,
     294656, 18432, 512},
    {131072000, 296484864, 297861120, 174440448, 65630208, 16450560, 2747136,
     294720, 18432, 512},
    {132120576, 298319872, 299237376, 175013888, 65773568, 16472064, 2748928,
     294784, 18432, 512},
    {133169152, 300154880, 300613632, 175587328, 65916928, 16493568, 2750720,
     294848, 18432, 512},
    {134217728, 301989888, 301989888, 176160768, 66060288, 16515072, 2752512,
     294912, 18432, 512}};
int sd = 5000000;
signed long long ans = 0, tans = 1;
signed long long res[7];
int p[7], d;
signed long long MOD = 1000000007;
int main() {
  cin >> n;
  int nn = sd, d = 0;
  while (nn <= n) {
    d++;
    nn += sd;
  }
  d--;
  nn -= sd;
  if (d > -1)
    for (int i = 0; i < 10; i++) a[i] = m[d][i];
  for (int i = nn + 1; i <= n; i++) {
    k = i;
    t = 0;
    while (k > 0) {
      if ((k % 10 == 4) || (k % 10 == 7)) t++;
      k /= 10;
    }
    a[t]++;
  }
  for (p[0] = 1; p[0] < 10; p[0]++)
    for (p[1] = 0; p[1] < 10; p[1]++)
      for (p[2] = 0; p[2] < 10; p[2]++)
        for (p[3] = 0; p[3] < 10; p[3]++)
          for (p[4] = 0; p[4] < 10; p[4]++)
            for (p[5] = 0; p[5] < 10; p[5]++)
              for (p[6] = 0; p[6] < 10; p[6]++)
                if (p[0] > p[1] + p[2] + p[3] + p[4] + p[5] + p[6]) {
                  tans = 1;
                  for (int i = 0; i < (7); i++) {
                    d = 0;
                    for (int j = 0; j < (i); j++)
                      if (p[i] == p[j]) d++;
                    res[i] = a[p[i]] - d;
                    if (res[i] < 0) res[i] = 0;
                    tans = (tans * res[i]) % MOD;
                  }
                  ans = (ans + tans) % MOD;
                }
  cout << ans;
  return 0;
}