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).

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

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

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  if e<0
  then begin st:=0; exit; end;
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]>6
     then begin
           if (z[i]<>7)
           then begin
                       if i<>kol
                       then rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2)
                       else rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-3)
                end
           else begin
                       if i<>kol
                       then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                       else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  dec(e);
                end;
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then begin
                        if i<>kol
                        then rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                        else rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2);
                      end
                 else begin
                       if i=kol
                       then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                       else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]);
                       dec(e);
                      end;
               end
          else begin
                if i=kol
                then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i])
               end;
          end;
     if (e=0)and(i=1)
     then inc(rez);
     if (e<0)
     then begin
          Break;
          end;
  end;
  m[zz]:=rez;
end;
begin
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to i do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=(kol*a[i2])mod 1000000007;
            Dec(a[i2]);
            kol:=(kol*a[i3])mod 1000000007;
            Dec(a[i3]);
            kol:=(kol*a[i4])mod 1000000007;
            Dec(a[i4]);
            kol:=(kol*a[i5])mod 1000000007;
            Dec(a[i5]);
            kol:=(kol*a[i6])mod 1000000007;
            Dec(a[i6]);
            kol:=(kol*a[i7])mod 1000000007;
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

const md = 1000000007;
var
  f : array[0..15,0..15,0..1] of longint;
  ff : array[0..15,0..15] of longint;
  fk : array[-5..15] of int64;
  w : array[0..15] of int64;
  i,j,n,k,z,q,ii,ss,sum : longint;
  m : ansistring;
  s,s1,s2,ans : int64;
  c,v : char;

  function ch(k,w : int64) : int64;
    var
      ans : int64;
    begin
      if w = 0 then exit(1);
      ans:=1;
      while w > 0 do begin
        ans:=ans*k mod md;
        dec(k);
        dec(w);
      end;
      exit(ans);
    end;
  procedure rec(v : longint);
    var
      sk : int64;
      i : longint;
    begin
      if ss >= sum then exit;
      if v = 6 then begin
        sk:=1;
        for i:=0 to sum do sk:=sk*ch(fk[i],w[i]) mod md;
        ans:=(ans+sk*fk[sum] mod md) mod md;
        exit;
      end;
      for i:=0 to sum do begin
        inc(w[i]);
        ss:=ss+i;
        rec(v+1);
        ss:=ss-i;
        dec(w[i]);
      end;
    end;

begin
  readln(m);
  if m = '7' then begin writeln(0); halt; end;
  for ii:=length(m) downto 1 do begin
    fillchar(f,sizeof(f),0);
    if ii > 1 then f[ii-1,0,1]:=1 else f[ii-1,0,0]:=1;
  for i:=ii-1 to length(m)-1 do
    for k:=0 to 9 do
      for z:=0 to 1 do if (f[i,k,z] > 0) then begin
        if z = 0 then c:=m[i+1] else c:='9';
        if (i = ii-1) then v:='1' else v:='0';
        for c:=v to c do begin
          if (c = '4') or (c = '7') then q:=1 else q:=0;
          f[i+1,k+q,z or ord(ord(c) < ord(m[i+1]))]:=f[i+1,k+q,z or ord(ord(c) < ord(m[i+1]))]+f[i,k,z];
        end;
      end;
    for k:=0 to 9 do ff[length(m)-ii+1,k]:=f[length(m),k,0]+f[length(m),k,1];
  end;
  n:=length(m);
  ans:=1;
  for i:=0 to n do for j:=1 to n do fk[i]:=fk[i]+ff[j,i];
  for sum:=n downto 1 do rec(0);
  //ans:=(ans+fk[1]*ch(fk[0],6)) mod md;
  writeln((ans-1+md) mod md);
end.

const
  base=1000000007;

var
  cr,ct,res,i,j,k,c:longint;
  sn:ansistring;
  n:longint;
  f:array[0..15,0..2,0..15]of longint;
  a,u:array[0..15]of longint;

  procedure rec(t,x:longint);
    var
      i:longint;

    begin
      if (t<=0)then exit;
      if (x=8)then begin
        cr:=1;
        for i:=1 to 7 do begin
          ct:=u[a[i]];
          for j:=1 to i-1 do
            if (a[i]=a[j])then dec(Ct);
          if (ct<=0)then exit;
          cr:=int64(cr)*ct mod base;
        end;
        res:=(res+cr)mod base;
        exit;
      end;
      for i:=0 to 9 do begin
        a[x]:=i;
        rec(t-i,x+1);
      end;
    end;

begin
  read(n);
  str(n,sn);
  fillchar(f,sizeof(F),$0);
  f[1][0][0]:=1;
  for i:=1 to length(sn)do
    for j:=0 to 1 do
      for k:=0 to i do
        if (f[i][j][k]<>0)then begin
          if (j=0)then begin
            for c:=0 to ord(sn[i])-48 do
              inc(f[i+1][ord(c<ord(sn[i])-48)][k+ord((c=4)or(c=7))],f[i][j][k]);
          end else begin
            for c:=0 to 9 do
              inc(f[i+1][1][k+ord((c=4)or(c=7))],f[i][j][k]);
          end;
        end;
  for i:=0 to 9 do u[i]:=f[length(sn)+1][0][i]+f[length(sn)+1][1][i]-ord(i=0);
  res:=0;
  for i:=0 to 9 do begin
    a[1]:=i;
    rec(i,2);
  end;
  writeln(res);
end.

program election;

const
  fi='';
  fo='';
  maxn = 12;
  modulo = trunc(1e9)+7;
var
  m:longint;  len:longint;
  f:array[1..maxn,0..maxn,false..true] of int64;
  c:array[0..maxn] of int64;
  p8,p2,p10:array[0..maxn] of int64;
  cc:array[0..maxn,0..maxn] of int64;
  x:array[0..6] of longint;
  p:array[0..maxn] of longint;
  kq,g:int64;
procedure openfile;
var
  st:string;
begin
  assign(input,fi);reset(input);
  assign(output,fo);rewrite(output);
  readln(m);
  str(m,st);
  len:=length(st);
end;
//---------------
function digitof(n,i:longint):longint;  inline;
begin
  exit((n div p10[i-1]) mod 10);
end;
//--------------
function dp(i,j:longint;small:boolean):int64;
var
  d,lim:longint;
begin
  if j<0 then exit(0);
  if f[i,j,small]<>-1 then exit(f[i,j,small]);
  if i=1 then
    begin
      if j>0 then f[i,j,small]:=0 else f[i,j,small]:=1;
      exit(f[i,j,small]);
    end;
  if small then lim:=9 else lim:=digitof(m,i-1);
  f[i,j,small]:=0;
  if i=len+1 then d:=1 else d:=0;
      for d:=d to lim do
        if (d=4)or(d=7) then f[i,j,small]:=(f[i,j,small]+dp(i-1,j-1,small or (d<digitof(m,i-1)))) mod modulo
        else f[i,j,small]:=(f[i,j,small]+dp(i-1,j,small or (d<digitof(m,i-1)))) mod modulo;
  exit(f[i,j,small]);
end;
//---------------
procedure ghi;
var
  i,j:longint;
  cnt,pp:int64;
begin
  fillchar(p,sizeof(p),0);
  for i:=1 to 6 do inc(p[x[i]]);
  for i:=0 to maxn do
    if p[i]>c[i] then exit;
  cnt:=1;
  pp:=720;
  for i:=0 to maxn do
  if (p[i]>0)and(p[i]<=c[i]) then
    begin
      for j:=0 to p[i]-1 do cnt:=(cnt*(c[i]-j)) mod modulo;
      for j:=1 to p[i] do pp:=pp div j;
    end;
  cnt:=(cnt*pp) mod modulo;
  g:=(g+cnt) mod modulo;
end;
//--------------
procedure dfs(i,r:longint);
var
  j:longint;
begin
  if i=7 then
    begin
      if r=0 then ghi;
      exit;
    end;
  for j:=x[i-1] to r do
    begin
      x[i]:=j;
      dfs(i+1,r-j);
    end;
end;
//---------------
procedure init;
var
  i,j:longint;
  bo:boolean;
begin
  for i:=1 to maxn do
    for j:=0 to maxn do
      for bo:=false to true do f[i,j,bo]:=-1;
end;
//-----------------
procedure process;
var
  i,j:longint;
begin
  fillchar(c,sizeof(c),0);
  p8[0]:=1;
  p2[0]:=1;
  p10[0]:=1;
  for i:=1 to maxn do
    begin
      p8[i]:=p8[i-1]*8;
      if p8[i]>=modulo then p8[i]:=p8[i]-modulo;
      p2[i]:=p2[i-1]*2;
      if p2[i]>=modulo then p2[i]:=p2[i]-modulo;
      p10[i]:=p10[i-1]*10;
    end;
  cc[0,0]:=1;
  for i:=1 to maxn do
    begin
      cc[i,0]:=1;cc[i,i]:=1;
      for j:=1 to i-1 do
        begin
          cc[i,j]:=cc[i-1,j]+cc[i-1,j-1];
          if cc[i,j]>=modulo then cc[i,j]:=cc[i,j]-modulo;
        end;
    end;
  for i:=1 to len-1 do
    begin
      c[0]:=c[0]+7*p8[i-1];
      c[i]:=c[i]+p2[i];
      for j:=1 to i-1 do
        begin
          c[j]:=(c[j]+(((p2[j]*cc[i-1,j]) mod modulo)*((7*p8[i-j-1]) mod modulo)) mod modulo) mod modulo;
          c[j]:=(c[j]+(((p2[j]*cc[i-1,j-1]) mod modulo)*p8[i-j]) mod modulo) mod modulo;
        end;
    end;
  for i:=0 to len do
    begin
      init;
      c[i]:=(c[i]+dp(len+1,i,false)) mod modulo;
    end;
  kq:=0;
  x[0]:=0;
  for len:=1 to len do
    begin
      g:=0;
      for i:=len-1 downto 0 do dfs(1,i);
      kq:=(kq+(g*c[len]) mod modulo) mod modulo;
    end;
  writeln(kq);
end;
//--------------
BEGIN
  openfile;
  process;
END.

const
    md = 1000000007;
var
    cur, res : int64;
    n, i, j, k, l, r, m : longint;
    d : array [0..100001,0..9] of longint;
    a, b, col, c, kol : array [0..100001] of longint;

procedure goes(len, sz, sum : longint);
var
    ans : int64;
    u : longint;
begin
    if (len > 6) then begin
        ans := 1;

//        writeln(sum,' ',sz);
 //       for k := 0 to 9 do write(col[k],' ');
   //     writeln;

        for k := 1 to 6 do
            ans := ans * c[k] mod md;

        res := (res + ans) mod md;

        exit;
    end;
    for u := 0 to sz-1 do
        if (a[u] > col[u]) and (sum+u < sz) then begin
            b[len] := u;
            c[len] := a[u]-col[u];
            col[u] := col[u] + 1;
            goes(len+1, sz, sum+u);
            col[u] := col[u] - 1;
        end;
    end;
function go(x : longint) : longint;
var
    y : longint;
begin
    y := 0;
    while (x > 0) do begin
        if (x mod 10 = 4) or (x mod 10 = 7) then inc(y);
        x := x div 10;
    end;
    go := y;
end;
begin
    read(n); d[0][0] := 1;

    for i := 1 to 99999 do begin
        for j := 0 to 5 do
            d[i][j] := d[i-1][j];
        kol[i] := go(i);
        inc(d[i][kol[i]]);
    end;

    for i := 0 to 99999 do begin
        l := 0; r := 9999; cur := -1;
        while (l <= r) do begin
            m := (l+r) shr 1;
            if (i*10000+m <= n) then begin
                l := m+1;
                cur := m;
            end
            else r := m-1;
        end;
        if (cur <> -1) then
            for j := 0 to 4 do
                inc(a[j+kol[i]], d[cur][j]);
    end;

//    for i := 0 to 9 do write(a[i], ' ');
    if (n = 1000000000) then inc(a[0]);
    dec(a[0]);
    cur := 0;
    for i := 1 to 9 do begin
        res := 0;
        goes(1, i, 0);
//        writeln(res);
        cur := (cur + res*a[i]) mod md;
    end;
    write(cur);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  if e<0
  then begin st:=0; exit; end;
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]>6
     then begin
           if (z[i]<>7)
           then begin
                       if i<>kol
                       then rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2)
                       else rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-3)
                end
           else begin
                       if i<>kol
                       then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                       else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  dec(e);
                end;
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then begin
                        if i<>kol
                        then rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                        else rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2);
                      end
                 else begin
                       if i=kol
                       then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                       else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]);
                       dec(e);
                      end;
               end
          else begin
                if i=kol
                then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i])
               end;
          end;
     if (e=0)and(i=1)
     then inc(rez);
     if (e<0)
     then begin
          Break;
          end;
  end;
  m[zz]:=rez;
end;
begin
//  Assign(input,'input.txt');
//  Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to i do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=(kol*a[i2])mod 1000000007;
            Dec(a[i2]);
            kol:=(kol*a[i3])mod 1000000007;
            Dec(a[i3]);
            kol:=(kol*a[i4])mod 1000000007;
            Dec(a[i4]);
            kol:=(kol*a[i5])mod 1000000007;
            Dec(a[i5]);
            kol:=(kol*a[i6])mod 1000000007;
            Dec(a[i6]);
            kol:=(kol*a[i7])mod 1000000007;
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

{$apptype console}
{$b-}
{$maxstacksize 1000000}
const md=1000000007;
var
  a:array[0..10,0..10] of int64;
  b:array[1..7,0..10] of int64;
  cnk:array[0..10,-11..10] of int64;
  cc:array[0..10] of byte;
  ct,st,error,c,m,k,add,i,j:integer;
  add1,cur,ans:int64;
  s:string;

  Procedure gen(k,r:byte);
  var
   i,j:integer;
  begin
    inc(ct);
    if k>6 then
    begin
      add1:=cur;
      for i := 0 to 10 do if (cc[i]>0) then
          add1:=add1*cnk[i,cc[i]-1] mod md;
       ans:=(ans+add1) mod md;
    end else
    begin
      for j := 0 to r do
        begin
          inc(cc[j]);
          gen(k+1,r-j);
          dec(cc[j]);
        end;
    end;
  end;

begin
 ///reset(input,'input.txt');
// rewrite(output,'output.txt');
 Fillchar(a,sizeof(a),0);
 a[1,1]:=2;
 a[1,0]:=7;
 for i := 2 to 10 do
  for j :=0  to i do
   for k := 0 to 9  do
   begin
     if (k=4) or (k=7) then add:=1 else add:=0;
     a[i,j]:=a[i,j]+a[i-1,j-add];
   end;
   readln(m);
   str(m,s);
   Fillchar(b,sizeof(b),0);
   for i := 0 to 10 do
     for j := 0 to length(s)-1 do
      b[1,i]:=(b[1,i]+a[j,i]) mod md;
 Fillchar(a,sizeof(a),0);

 a[1,1]:=2;
 a[1,0]:=8;
 a[0,0]:=1;
 for i := 2 to 10 do
  for j :=0  to i do
   for k := 0 to 9  do
   begin
     if (k=4) or (k=7) then add:=1 else add:=0;
     a[i,j]:=a[i,j]+a[i-1,j-add];
   end;

  add:=0;
  for i := 1 to length(s) do
  begin
    val(s[i],c,error);
    if (i=1) then st:=1 else st:=0;
    for j := st to c-1 do
    begin
     if (j=4) or (j=7) then inc(add);
     for k := add to length(s) do b[1,k]:=(b[1,k]+a[length(s)-i,k-add]) mod md;
     if (j=4) or (j=7) then dec(add);
    end;
    if (c=4) or (c=7) then inc(add);
    if (i=length(s)) then b[1,add]:=(b[1,add]+1) mod md;
  end;
  ans:=0;
  Fillchar(cc,sizeof(cc),0);
  Fillchar(cnk,sizeof(cnk),0);
  for i := 0 to 10 do cnk[i,0]:=b[1,i];
    for i := 0 to 10 do
      for j := 1 to 10 do cnk[i,j]:=(cnk[i,j-1]*(b[1,i]-j)) mod md;

  {  for j :=0 to 10 do write(b[1,j],' ');
   writeln;
   writeln;

    for i := 0 to 10 do
      begin
        for j := 0 to 10 do write(cnk[i][j],' ');
        writeln;
      end;  }

  for i := 1 to length(s) do
  begin
    cur:=b[1,i];
    gen(1,i-1);
  end;
  writeln(ans);
end.

{$R+,Q+,I+]
{$apptype console}
{$maxstacksize 10000000}
Uses SysUtils;
Var
   i,j,k:Integer;
   m,md,f,t,ans,y:Int64;
   g,p,h,w,a:Array[0..300000] of Int64;
   dp:Array[0..10,-10..10,0..2] of Int64;
Procedure Solve(i,sum,f:Integer);
Var
   j,i1:Integer;
   r,pr:Int64;
Begin
   If f=1 Then Begin
      If sum>=w[1] Then Exit;
   End;
   If i>7 Then Begin
      For j:=0 To y-1 Do h[j]:=0;
      For j:=2 To 7 Do h[w[j]]:=h[w[j]]+1;
      pr:=1;
      For i1:=0 To y-1 Do Begin
         r:=0;
         For j:=1 To h[i1] Do Begin
            pr:=(pr*(p[i1]-r)) mod md;
            r:=r+1;
         End;
      End;
      pr:=(pr*p[w[1]]) mod md;
      ans:=(ans+pr) mod md;
      Exit;
   End;
   For j:=0 To y Do Begin
      w[i]:=j;
      If i<>1 Then Solve(i+1,sum+j,1)
              Else Solve(i+1,sum,1);
   End;
End;
Begin
   Read(m);
   md:=1000000007;
   t:=m;
   i:=0;
   While t>0 Do Begin
      i:=i+1;
      t:=t div 10;
   End;
   y:=i;
   t:=m;
   i:=y;
   While t>0 Do Begin
      g[i]:=t mod 10;
      i:=i-1;
      t:=t div 10;
   End;
   If g[1]<>1 Then dp[1,0,0]:=1
              Else dp[1,0,1]:=1;
   For i:=2 To 9 Do Begin
      f:=0;
      If i=g[1] Then f:=1;
      If i<=g[1] Then Begin
         If (i<>4) and (i<>7) Then dp[1,0,f]:=dp[1,0,f]+1
                              Else dp[1,1,f]:=dp[1,1,f]+1;
      End;
      If i>g[1] Then Begin
         If (i<>4) and (i<>7) Then dp[1,0,2]:=dp[1,0,2]+1
                              Else dp[1,1,2]:=dp[1,1,2]+1;
      End;
   End;
   For i:=2 To y Do
      For j:=0 To y Do Begin
         dp[i,j,0]:=dp[i-1,j,0];
         If g[i]<>0 Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,1];
         dp[i,j,2]:=dp[i-1,j,2];
         If g[i]=0 Then dp[i,j,1]:=dp[i-1,j,1];
         For k:=1 To 9 Do Begin
            If (k<>4) and (k<>7) Then Begin
               dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,0];
               If k<g[i] Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,1];
               dp[i,j,2]:=dp[i,j,2]+dp[i-1,j,2];
               If k>g[i] Then dp[i,j,2]:=dp[i,j,2]+dp[i-1,j,1];
            End
            Else Begin
               dp[i,j,0]:=dp[i,j,0]+dp[i-1,j-1,0];
               If k<g[i] Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j-1,1];
               dp[i,j,2]:=dp[i,j,2]+dp[i-1,j-1,2];
               If k>g[i] Then dp[i,j,2]:=dp[i,j,2]+dp[i-1,j-1,1];
            End;
            If k=g[i] Then Begin
               If (k<>4) and (k<>7) Then dp[i,j,1]:=dp[i-1,j,1]
                                    Else dp[i,j,1]:=dp[i-1,j-1,1];
            End;
         End;
      End;
   For j:=0 To y Do
      For k:=1 To y Do
         If k<>y Then p[j]:=p[j]+dp[k,j,0]+dp[k,j,1]+dp[k,j,2]
                 Else p[j]:=p[j]+dp[k,j,0]+dp[k,j,1];
   ans:=0;
   Solve(1,0,0);
   Write(ans);
End.

const
    f1  = '';//258b.inp';
    f2  = '';//258b.out';
    mxn = 10;
    oo  = round(1e9) + 7;
var
    n   : longint;
    res, tmp    : longint;
    st  : string;
    d   : array [0..mxn, 0..mxn, 0..1] of longint;
    f   : array [0..mxn, 0..mxn] of longint;
    num : array [0..mxn] of longint;

function recur(k, t, ok : longint) : longint;
var tn, okn, p, r   : longint;
        tp  : longint;
begin
    if d[k, t, ok] <> -1 then exit( d[k, t, ok] );
    if (k = n) then
        begin
            if (t = 0) then d[k, t, ok] := 1 else d[k, t, ok] := 0;
            exit( d[k, t, ok] );
        end;
    tp := 0;
    if ok = 0 then r := 9
    else r := ord(st[k+1]) - ord('0');

    for p := 0 to r do
        begin
            if (p = 4) or (p = 7) then tn := t - 1 else tn := t;
            if (p = r) and (ok = 1) then okn := 1 else okn := 0;
            if tn >= 0 then
                inc( tp, recur(k+1, tn, okn) );
        end;

    d[k, t, ok] := tp;
    exit( tp );
end;

procedure init;
var i, j    : longint;
begin
    fillchar(d, sizeof(d), 255);
    for i := 0 to n do f[i, 1] := recur(0, i, 1);
    dec( f[0, 1] );
    for i := 0 to n do f[i, 0] := 1;

    for i := 0 to n do
        for j := 2 to 6 do
            f[i, j] := ( int64(f[i, 1] - j + 1) * f[i, j-1] ) mod oo;
end;

procedure check;
var i, j    : longint;
begin
    for i := 0 to n do
        begin
            for j := 0 to 6 do write(f[i, j], ' ');
            writeln;
        end;
end;

procedure count;
var i, s    : longint;
begin
    s := 1;
    for i := 0 to n do
        s := ( int64(s) * f[i, num[i]] ) mod oo;
    tmp := ( tmp + s ) mod oo;
end;

procedure factor(k, t   : longint);
var i   : longint;
begin
    if k = 7 then
        begin
            if t = 0 then count;
            exit;
        end;
    for i := 0 to t do
        begin
            inc(num[i]);
            factor(k+1, t-i);
            dec(num[i]);
        end;
end;

procedure main;
var i   : longint;
begin
    for i := 1 to n do
        if f[i, 1] = 0 then break
        else
            begin
                factor(1, i-1);
                res := ( res + f[i, 1] * int64(tmp) ) mod oo;
            end;
    writeln(res);
end;

begin
    assign(input, f1);  reset(input);
    assign(output, f2); rewrite(output);
    read(st); n := length(st);
    init;
    //check;
    main;
end.

const
    f1  = '258b.inp';
    f2  = '258b.out';
    mxn = 10;
    oo  = round(1e9) + 7;
var
    n   : longint;
    res, tmp    : longint;
    st  : string;
    d   : array [0..mxn, 0..mxn, 0..1] of longint;
    f   : array [0..mxn, 0..mxn] of longint;
    num : array [0..mxn] of longint;

function recur(k, t, ok : longint) : longint;
var tn, okn, p, r   : longint;
        tp  : longint;
begin
    if d[k, t, ok] <> -1 then exit( d[k, t, ok] );
    if (k = n) then
        begin
            if (t = 0) then d[k, t, ok] := 1 else d[k, t, ok] := 0;
            exit( d[k, t, ok] );
        end;
    tp := 0;
    if ok = 0 then r := 9
    else r := ord(st[k+1]) - ord('0');

    for p := 0 to r do
        begin
            if (p = 4) or (p = 7) then tn := t - 1 else tn := t;
            if (p = r) and (ok = 1) then okn := 1 else okn := 0;
            if tn >= 0 then
                inc( tp, recur(k+1, tn, okn) );
        end;

    d[k, t, ok] := tp;
    exit( tp );
end;

procedure init;
var i, j    : longint;
begin
    fillchar(d, sizeof(d), 255);
    for i := 0 to n do f[i, 1] := recur(0, i, 1);
    dec( f[0, 1] );
    for i := 0 to n do f[i, 0] := 1;

    for i := 0 to n do
        for j := 2 to 6 do
            f[i, j] := ( int64(f[i, 1] - j + 1) * f[i, j-1] ) mod oo;
end;

procedure check;
var i, j    : longint;
begin
    for i := 0 to n do
        begin
            for j := 0 to 6 do write(f[i, j], ' ');
            writeln;
        end;
end;

procedure count;
var i, s    : longint;
begin
    s := 1;
    for i := 0 to n do
        s := ( int64(s) * f[i, num[i]] ) mod oo;
    tmp := ( tmp + s ) mod oo;
end;

procedure factor(k, t   : longint);
var i   : longint;
begin
    if k = 7 then
        begin
            if t = 0 then count;
            exit;
        end;
    for i := 0 to t do
        begin
            inc(num[i]);
            factor(k+1, t-i);
            dec(num[i]);
        end;
end;

procedure main;
var i   : longint;
begin
    for i := 1 to n do
        if f[i, 1] = 0 then break
        else
            begin
                factor(1, i-1);
                res := ( res + f[i, 1] * int64(tmp) ) mod oo;
            end;
    writeln(res);
end;

begin
//    assign(input, f1);  reset(input);
//    assign(output, f2); rewrite(output);
    read(st); n := length(st);
    init;
    //check;
    main;
end.

uses math;

const	fi='';//'cf.inp';
		fo='';
      cs=1000000007;
type      ma1=array[0..9]of longint;

var	f,g:text;
		m,n:longint;
      ma:array[0..11,0..11,false..true]of int64;
      kt:array[0..11,0..11,false..true]of boolean;
      l:array[0..7,0..11]of int64;
      d:array[-1..10]of int64;
      c,luck:array[0..11]of longint;
      a:ma1;
      res:int64;

procedure mf;
begin
	assign(f,fi);reset(F);
   assign(g,fo);rewrite(G);
end;

procedure df;
begin
	close(f);close(G);
end;

procedure nhap;
var s:string;i:longint;
begin
	readln(f,s);
   n:=length(s);
   for i:=1 to length(s) do c[i]:=ord(s[i])-48;
   luck[4]:=1;luck[7]:=1;
end;

function tinh(i,j:longint;ok:boolean):int64;
var tg,tam:int64;x,y:longint;
begin
	if ma[i,j,ok]<>-1 then exit(ma[i,j,ok]);
   if i>n then
   begin
   	if j=0 then ma[i,j,ok]:=1 else ma[i,j,ok]:=0;
      kt[i,j,ok]:=false;
      exit(ma[i,j,ok]);
   end;
   ma[i,j,ok]:=0;
   for x:=0 to max(9*ord(ok),c[i]) do
   if not ((luck[x]=1) and (j=0)) then
   begin
   	tam:=ma[i,j,ok];
      ma[i,j,ok]:=(ma[i,j,ok]+tinh(i+1,j-luck[x],ok or (x<c[i])))mod cs;
      kt[i,j,ok]:=kt[i,j,ok]or kt[i+1,j-luck[x],ok or (x<c[i])] or
      (tam+ma[i+1,j-luck[x],ok or (x<c[i])]>=cs);
   end;
   exit(ma[i,j,ok]);
end;

function tim(i,j:longint):int64;
var x:longint;tg,tam:int64;
begin
	tg:=0;
   if i=0 then
   	begin
      	if j=0 then exit(1) else exit(0);
      end;
   for x:=0 to j do
   begin
      if not kt[1,x,false] then
      if a[x]>=ma[1,x,false]-ord(x=0) then continue;
      tam:=(ma[1,x,false]-ord(x=0)-a[x])mod cs;
      a[x]:=a[x]+1;
      tg:=(tg+tam*tim(i-1,j-x)) mod cs;
      a[x]:=a[x]-1;
   end;
   exit(tg);
end;

procedure init;
var i,j,t:longint;x:int64;
begin
	fillchar(ma,sizeof(ma),255);
   for i:=0 to n do
   x:=tinh(1,i,false);
   for i:=0 to n-1 do
   d[i]:=d[i-1]+tim(6,i);
end;

procedure xl;
var i,j:longint;
begin
	init;
   for i:=1 to n do
   begin
   	res:=(res+ma[1,i,false]*d[i-1]) mod cs;
   end;
   writeln(g,res);
end;

BEGIN
	mf;
   nhap;
   xl;
   df;
END.

{$R+}
var
 cc,met:array [0..100] of int64;
 f:array [0..100,-1..100,0..1] of int64;
 md,n,m,k,d,nn:int64;
 c,kol,i,j,i1,i2,i3,i4,i5,i6:longint;
 ans:int64;

 procedure swap(var x,y:int64);
  var
   c:longint;
  begin
  c:=x;
  x:=y;
  y:=c;
  end;

 function add(x1,x2,x3,x4,x5,x6,x7:int64):int64;
  var
   i,j:longint;
   res:int64;
  begin
   res:=1;
   for i:=0 to 11 do
    met[i]:=0;
   inc(met[x1]);  inc(met[x2]); inc(met[x3]); inc(met[x4]); inc(met[x5]);
   inc(met[x6]); inc(met[x7]);
   for i:=0 to 10 do
    begin
      for j:=f[d,i,0]-met[i]+1 to f[d,i,0] do
       begin
         res:=(res*j) mod md;
       end;
       if res=0 then
                        begin
                         add:=0;
                         exit;
                        end;
    end;
    add:=(res mod md);
  end;

begin
 md:=1000000000+7;
 readln(n);
 nn:=n;
 while nn<>0 do
  begin
   inc(d);
   cc[d]:=nn mod 10;
   nn:=nn div 10;
  end;
 for i:=1 to d div 2 do
  swap(cc[i],cc[d-i+1]);

 f[0,0,1]:=1;
 for i:=1 to d do
  begin
   for  kol:=0 to 10 do
    begin
     for c:=0 to 9 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,0]+f[i,kol,0]
         else f[i,kol,0]:=f[i-1,kol,0]+f[i,kol,0];
      end;
     for c:=0 to cc[i]-1 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,1]+f[i,kol,0]
         else f[i,kol,0]:=f[i,kol,0]+f[i-1,kol,1];
      end;
     if (cc[i]=4)or(cc[i]=7) then f[i,kol,1]:=f[i-1,kol-1,1]+f[i,kol,1]
      else f[i,kol,1]:=f[i,kol,1]+f[i-1,kol,1];
    end;
  end;
 for i:=0 to 10 do
  f[d,i,0]:=(f[d,i,0]+f[d,i,1])mod md;
 dec(f[d,0,0]);
 for i:=1 to d do
  begin
   for i1:=0 to i do
    for i2:=0 to i-i1 do
     for i3:=0 to i-i1-i2 do
      for i4:=0 to i-i1-i2-i3 do
       for i5:=0 to i-i1-i2-i3-i4 do
        for i6:=0 to i-i1-i2-i3-i4-i5 do
         begin
          if (i1+i2+i3+i4+i5+i6)>=i then continue;
          ans:=(ans+add(i,i1,i2,i3,i4,i5,i6))mod md;
         end;
  end;
 writeln(ans);
end.

const modulo = 1000000007;
var n:int64;
    f:array[0..33,0..33,0..3] of int64;
    zipher:array[0..33] of int64;
    i,j,k:longint;
    flag,q,cnt,next,flag2,cost,cnt1,cnt2,cnt3,cnt4,cnt5,cnt6,cnt7:longint;
    s:String;
    answer:int64;
    good:array[0..10] of int64;
    mas:array[0..10] of int64;
    qwe:array[0..100] of int64;

function c(a,b:int64):int64;
var i,j:longint;
    cnt,cur:int64;
    answeR:int64;
begin
 answer:=1;
 for i:= b-a+1 to b do
   answer:=(answer*i) mod modulo;
 c:=answer;
end;

function fun(c1,c2,c3,c4,c5,c6,c7:int64):int64;
var answer:int64;
    i:longint;
begin
 fillchar(mas,sizeof(mas),0);
 mas[c1]:=mas[c1]+1;
 mas[c2]:=mas[c2]+1;
 mas[c3]:=mas[c3]+1;
 mas[c4]:=mas[c4]+1;
 mas[c5]:=mas[c5]+1;
 mas[c6]:=mas[c6]+1;
 mas[c7]:=mas[c7]+1;
 answer:=1;
 for i:= 0 to 10 do
 begin
  answer:=(answer*c(mas[i],good[i])) mod modulo;
  if answer = 0 then break;
 end;
 fun:=answer mod modulo;
end;

begin
 readln(n);
 str(n,s);
 for i:= 1 to length(s) do zipher[i]:=ord(s[i])-ord('0');
 fillchar(f,sizeof(f),0);
 for i:= 1 to 9 do
  begin
   if i>zipher[1] then flag:=2 else
   if i=zipher[1] then flag:=1 else
   if i<zipher[1] then flag:=0;
   if (i=4) or (i=7) then q:=1 else q:=0;
   f[1][q][flag]:=f[1][q][flag]+1;
  end;
 for i:= 1 to length(s)-1 do
  for cnt:= 0 to length(s) do
   for flag:= 0 to 2 do
    begin
     if f[i][cnt][flag]=0 then continue;
     for next:= 0 to 9 do
      begin
       if flag = 0 then flag2:=0 else
       if flag = 2 then flag2:=2 else
        begin
         if next=zipher[i+1] then flag2:=1 else
         if next<zipher[i+1] then flag2:=0 else
         if next>zipher[i+1] then flag2:=2;
        end;
       cost:=cnt;
       if (next=4) or (Next=7) then inc(Cost);
       f[i+1][cost][flag2]:=f[i+1][cost][flag2]+f[i][cnt][flag];
      end;
    end;
  answer:=0;
  for i:= 1 to length(s) do
   for j:= 0 to length(s) do
    for k:= 0 to 2 do
     begin
      if (i=lengtH(s)) and (k=2) then continue;
      good[j]:=good[j]+f[i][j][k];
     end;
 answer:=0;
 for cnt1:= 1 to 9 do
  for cnt2:= 0 to cnt1 do
   for cnt3:= 0 to cnt1-cnt2 do
    for cnt4:= 0 to cnt1-cnt2-cnt3 do
     for cnt5:= 0 to cnt1-cnt2-cnt3-cnt4 do
      for cnt6:= 0 to cnt1-cnt2-cnt3-cnt4-cnt5 do
       for cnt7:= 0 to cnt1-cnt2-cnt3-cnt4-cnt5-cnt6 do
       begin
        if cnt1<=cnt2+cnt3+cnt4+cnt5+cnt6+cnt7 then continue;
        answer:=(answer+fun(cnt1,cnt2,cnt3,cnt4,cnt5,cnt6,cnt7)) mod modulo;
       end;
   writeln(answer);
end.

const md = 1000000007;
var
w,ans,s:int64;
fact:array[0..1000]of int64;
p,u,i,j,n,m,t:longint;
dp:array[0..100,0..100]of int64;
a:Array[0..100]of int64;
c1,c2:array[0..100,0..100]of int64;
function st(x,n:int64):int64;
var t:int64;
begin
 if n=0 then st:=1
 else
   begin
    if n mod 2=1 then st:=x*st(x,n-1) mod md
    else
     begin
      t:=st(x,n div 2);
      t:=t*t mod md;
      st:=t;
     end;
   end;
end;
function cnk(n,k:longint):int64;
var i:longint; d:int64;
begin
 d:=1;
 for i:=n-k+1 to n do
  begin
   d:=d*int64(i);
   d:=d mod md;
  end;
 d:=d*st(fact[k],md-2);
 d:=d mod md;
 cnk:=d;
end;
procedure add(var a:int64; b:longint);
begin
 a:=a+b;
 a:=a mod md;
end;
function c(n:longint):int64;
var
d,res:int64;
last,i,j,u:longint;
begin
  fillchar(c1,sizeof(c1),0);
  c1[0,0]:=1;
  for last:=0 to n-1 do
   begin
     fillchar(c2,sizeof(c2),0);
     for i:=0 to n-1 do
       for j:=0 to 6 do
         begin
           for u:=0 to 6-j do
             if (i+u*last<n)and(a[last]>=u) then
              begin
               d:=c1[i,j];
               d:=d*cnk(a[last],u) mod md;
               add(c2[i+u*last,j+u],d);
              end;
         end;
     for i:=0 to n-1 do
      for j:=0 to 6 do
       c1[i,j]:=c2[i,j];
   end;
  res:=0;
  for i:=0 to n-1 do
   res:=(res+c1[i,6]) mod md;
  c:=res;
end;
procedure precalc;
var s:string;
begin
 dp[1,1]:=2;
 dp[1,0]:=8;

 for i:=2 to 9 do
   for j:=0 to i-1 do
     begin
      dp[i,j]:=dp[i,j]+dp[i-1,j]*8;
      dp[i,j+1]:=dp[i,j+1]+dp[i-1,j]*2;
     end;

 str(m,s);
 dp[0,0]:=1;
 for i:=1 to length(s)-1 do
  begin
     for u:=1 to 9 do
      begin
       if (u=4)or(u=7) then t:=1
       else t:=0;
       for j:=0 to i do
        a[j+t]:=a[j+t]+dp[i-1,j];
      end;
  end;
 t:=0;
 for i:=1 to length(s) do
   begin
    p:=1;
    if (i<>1) then p:=0;
    for u:=p to ord(s[i])-49 do
      begin
        if (u=4)or(u=7) then inc(t);
        for j:=0 to 10 do
          a[j+t]:=a[j+t]+dp[length(s)-i,j];
        if (u=4)or(u=7) then dec(t);
      end;
    if (s[i]='4')or(s[i]='7') then inc(t);
   end;
 inc(a[t]);
end;
 begin
  fact[0]:=1;
  for i:=1 to 6 do
   fact[i]:=fact[i-1]*i;
  readln(m);
  w:=1;
  precalc;
  s:=a[0];
  for i:=1 to 10 do
   begin
     ans:=ans+a[i]*c(i);
     ans:=ans mod md;
   end;
  writeln(ans*720 mod md);
 end.

Uses Math;
Const
  Fi            =               '';//ELECTION.INP';
  Fo            =               '';//ELECTION.OUT';
  Base          =               Trunc(1e9)+7;
  Maxcs         =               11;
Type
  M1            =               Array [0..Maxcs] of Longint;
  M2            =               Array [0..Maxcs,-Maxcs..Maxcs,false..true,false..true] of Longint;
Var
  f , g : Text;
  m : Longint;
  res , kq : Int64;
  num : String;
  a , x, dem : M1;
  fx : M2;

Procedure Openfile;
Begin
  Assign(f,fi);
  Reset(f);
  Assign(g,fo);
  Rewrite(g);
End;

Procedure Closefile;
Begin
  Close(f);
  Close(g);
End;

Procedure Doc;
Begin
  Readln(f,m);
End;

Function Tinh(i , j : Longint; ok , ok2 : Boolean) : Longint;
Var
  k , sum : Longint;
Begin
  If fx[i,j,ok,ok2]<>-1 then exit(fx[i,j,ok,ok2]);
  If i>length(num) then
    Begin
      Fx[i,j,ok,ok2]:=ord((j=0) and ok2);
      Exit(fx[i,j,ok,ok2]);
    End;
  Sum:=0;
  For k:=0 to max(ord(num[i])-48,ord(ok)*9) do sum:=sum+tinh(i+1,j-ord((k=4) or (k=7)),ok or (k<ord(num[i])-48),ok2 or (k<>0));
  Fx[i,j,ok,ok2]:=sum;
  Exit(sum);
End;

Procedure Init;
Var
  j : Longint;
Begin
  Str(m,num);
  For j:=0 to length(num) do
    Begin
      Fillchar(fx,sizeof(fx),255);
      a[j]:=tinh(1,j,false,false);
    End;
End;

Procedure Capnhat(sl : Longint);
Var
  i , j : Longint;
  t : Int64;
Begin
  If sl=0 then
    Begin
      t:=1;
      For i:=0 to 9 do
      If dem[i]>0 then
        Begin
          For j:=0 to dem[i]-1 do t:=(t*(a[i]-j)) mod base;
        End;
      Kq:=(kq+t) mod base;
    End;
End;

Procedure Thu(i , j : Longint);
Var
  k : Longint;
Begin
  If i>6 then capnhat(j)
  Else
    For k:=0 to j do
      Begin
        x[i]:=k;
        Inc(dem[k]);
        Thu(i+1,j-k);
        Dec(dem[k]);
      End;
End;

Procedure Solve;
Var
  i , j : Longint;
Begin
  Res:=0;
  For i:=1 to length(num) do
    Begin
      Fillchar(x,sizeof(x),0);
      Fillchar(dem,sizeof(dem),0);
      kq:=0;
      For j:=0 to i-1 do
        Begin
          Thu(1,j);
        End;
      kq:=(kq*a[i]) mod base;
      Res:=(res+kq) mod base;
    End;
End;

Procedure Ghi;
Begin
  If m<=7 then writeln(g,0)
  Else writeln(g,res);
End;

Begin
  Openfile;
  Doc;
  Init;
  Solve;
  Ghi;
  Closefile;
End.

uses math;
const base=1000000000+7;
var m,top,tong:longint;
    st,c:array[0..10]of longint;
    dp:array[0..10,0..10]of longint;
    mang:array[0..10]of longint;
    ans:int64;

function get(x,y:longint):longint;
begin
  get:=(x shr y) and 1;
end;

procedure nhap;
var m2:longint;
begin
  assign(input,'');  reset(input);
  fillchar(dp,sizeof(dp),0);
  readln(m);  top:=0;
  while m<>0 do begin
    inc(top);  st[top]:=m mod 10;  m:=m div 10;
  end;
end;

procedure solve;
var i,j,count,ans,t:longint;
begin
  dp[0,0]:=1;
  for i:=1 to min(9,top) do begin
    for j:=0 to (1 shl i)-1 do begin
      count:=0;  ans:=1;
      for t:=1 to i do if get(j,t-1)=1 then begin
        inc(count);  ans:=ans*2;
      end
      else ans:=ans*8;
      dp[i,count]:=dp[i,count]+ans;
    end;
  end;
end;

function combi(p,x:longint):int64;
var i:longint;
    combix:int64;
begin
  combix:=1;
  for i:=0 to x-1 do combix:=(combix*(p-i))mod base;
  combi:=combix;
end;

procedure update(lab:longint);
var sum:int64;
    i:longint;
begin
  sum:=1;
  for i:=0 to 9 do begin
    sum:=(sum*combi(mang[i],c[i]))mod base;
  end;
  sum:=(sum*mang[lab])mod base;
  ans:=(ans+sum)mod base;
end;

procedure pick(k,lab:longint);
var i:longint;
begin
  for i:=0 to 9 do begin
    if tong+i>=lab then exit;
    tong:=tong+i;
    inc(c[i]);
    if k=6 then update(lab) else pick(k+1,lab);
    dec(c[i]);
    tong:=tong-i;
  end;
end;

procedure print;
var i,j,t,v,count,i1,i2,i3,i4,i5,i6:longint;
begin
  fillchar(mang,sizeof(mang),0);  ans:=0;  count:=0;
  for i:=top downto 1 do begin
    for j:=st[i]-1 downto 0 do begin
      if (j=4)or(j=7) then inc(count);
      for t:=0 to 9 do if (t+count<=9)
        then mang[t+count]:=mang[t+count]+dp[i-1,t];
      if (j=4)or(j=7) then dec(count);
    end;
    if (st[i]=4)or(st[i]=7) then inc(count);
  end;
  inc(mang[count]);  dec(mang[0]);
  for i:=0 to 9 do begin
    tong:=0;  fillchar(c,sizeof(c),0);
    pick(1,i);
  end;
  writeln(ans);
end;

begin
  nhap;
  solve;
  print;
end.

const md=1000000000+7;
Var ans,tt,sum,n,x,res:int64;
    f:array[0..12,0..12,boolean]of int64;
    i,j,len,u,d,mx:longint;
    s:string;
    g,fact,rev,q:array[0..1234]of int64;
    w:boolean;
 function pow(a,b:int64):int64;
   begin
     if b=0 then exit(1);
     if b mod 2=1 then pow:=pow(a,b-1)*a mod md
     else begin a:=a*a mod md;pow:=pow(a,b div 2);end;
   end;
  procedure rec(x,sum:longint;tmp:int64;pp:longint);
    var i:longint;
      begin
       if sum>len then exit;
        if x=len then
          begin
            if pp<>6 then exit;
            for i:=sum+1 to len do
              ans:=(ans+tmp*g[i])mod md;
             exit;
          end;
        for i:=0 to 6-pp do
         if g[x]>=i then
          begin
            tt:=tmp;
            for j:=g[x] downto g[x]-i+1 do
              tt:=(tt*int64(j)) mod md;
            tt:=tt*rev[fact[i]] mod md;
            rec(x+1,sum+i*x,tt,pp+i);
          end;
      end;
  begin
    read(n);
    rev[0]:=1;
    for i:=1 to 1000 do
      rev[i]:=pow(i,md-2);
    fact[0]:=1;
    for i:=1 to 7 do
      fact[i]:=fact[i-1]*i;

    str(n+1,s);
    len:=length(s);
    f[0,0,false]:=1;
    for i:=1 to len do
      for j:=0 to len do
        for w:=false to true do
          begin
            if w  then mx:=9
            else mx:=ord(s[i])-48;
            for d:=0 to mx do
              f[i,j+ord((d=4)or(d=7)),w or (d<ord(s[i])-48)]:=(
              f[i,j+ord((d=4)or(d=7)),w or (d<ord(s[i])-48)]+f[i-1,j,w]);
          end;
    for i:=0 to len do
      g[i]:=f[len,i,true];
    dec(g[0]);
    ans:=0;
    rec(0,0,720,0);
//    ans:=ans*int64(720) mod md;
    Writeln(ans);
  end.

const
   finp='';//258B.inp';
   fout='';//258B.out';
   base=1000000007;

var
   fi,fo:text;
   f:array[0..10,-1..10] of int64;
   a,s,gt,val:array[0..10] of longint;
   m,n,sum,kq:longint;

procedure openfile;
begin
   assign(fi,finp);
   reset(fi);
   assign(fo,fout);
   rewrite(fo);
end;

procedure closefile;
begin
   close(fi);
   close(fo);
end;

procedure enter;
begin
   readln(fi,n);
end;

procedure slcs(x:longint);
begin
   m:=0;
   while x>0 do
   begin
      inc(m); a[m]:=x mod 10;
      x:=x div 10;
   end;
end;

function mu(x,k:longint):longint;
var t:int64;
begin
   if (k=1) then exit(x);
   t:=mu(x,k div 2);
   t:=t*t mod base;
   if odd(k) then t:=t*x mod base;
   exit(t);
end;

procedure prepare;
var i,j,k,t,dem,x,y:longint;
begin
   f[1,0]:=7;
   f[1,1]:=2;
   f[0,0]:=1;
   slcs(n);
   for i:=2 to m-1 do
   for j:=0 to i do
   begin
      x:=int64(f[i-1,j-1])*2;
      y:=int64(8)*f[i-1,j];
      f[i,j]:=x+y;
      n:=n;
   end;
   for i:=1 to m-1 do
   for j:=0 to i do s[j]:=s[j]+f[i,j];
   dem:=0;
   for i:=m downto 1 do
   begin
      if i=m then x:=1 else x:=0;
      for j:=x to a[i]-1 do
      if (j=4) or (j=7) then
      begin
         for k:=dem+1 to 9 do
         for t:=0 to i-1 do s[k]:=s[k]+f[t,k-dem-1];
      end else
      begin
         for k:=dem to 9 do //s[k]:=s[k]+f[i-1,k-dem];
         for t:=0 to i-1 do s[k]:=s[k]+f[t,k-dem];
      end;
      if (a[i]=4) or (a[i]=7) then inc(dem);
   end;
   inc(s[dem]);
   gt[0]:=1;  val[0]:=1;
   for i:=1 to 6 do gt[i]:=int64(gt[i-1])*i mod base;
   for i:=1 to 6 do val[i]:=mu(gt[i],base-2);
end;

function c(n,k:longint):longint;
var i,s:longint;
begin
   s:=1;
   for i:=n-k+1 to n do s:=int64(s)*i mod base;
   s:=int64(s)*val[k] mod base;
   exit(s);
end;

procedure update(x:longint);
var i,j:longint;
begin
   j:=0;
   for i:=0 to x-1 do j:=j+a[i];
   if (j<>6) then exit;
   j:=0;
   for i:=0 to x-1 do j:=j+int64(a[i])*i;
   if j>=x then exit;
   j:=1;
   for i:=0 to x-1 do j:=int64(j)*c(s[i],a[i]) mod base;
   j:=int64(j)*gt[6] mod base;
   sum:=(sum+j) mod base;
end;

procedure trying(i,x,k:longint);
var j:longint;
begin
   if (i>x-1) then
   begin
      update(x);
      exit;
   end;
   //if i=0 then k:=6 else k:=x-1;
   for j:=0 to k do
   begin
      a[i]:=j;
      trying(i+1,x,k-j);
      a[i]:=0;
   end;
end;

procedure lam(x:longint);
var i,j,k:longint;
begin
  sum:=0;
  trying(0,x,6);
  kq:=(kq+int64(s[x])*sum mod base) mod base
end;

procedure process;
var i:longint;
begin
   for i:=1 to m do
   if s[i]>0 then lam(i);
   writeln(kq);
end;

procedure check;
var i,j,dem:longint;
begin
   for i:=0 to m do write(s[i],' '); writeln;
   fillchar(s,sizeof(s),0);
   for i:=1 to n do
   begin
      j:=i; dem:=0;
      while j>0 do
      begin
         if (j mod 10=4) or (j mod 10=7) then inc(dem);
         j:=j div 10;
      end;
      inc(s[dem]);
      //if dem=0 then writeln('g','  ',i);
   end;
   for i:=0 to m do write(s[i],' '); writeln;
end;

BEGIN
   openfile;
   enter;
   prepare;
   process;
   //check;
   closefile;
END.

uses math;
const
        nmax    =       100;
        modul   =       1000000007;
var
        n,m:longint;
        a:string;
        kq,f:Array[0..10,0..1,0..10 ]of longint;
        sl,s:array[0..10] of longint;
        Sol,Res:int64;
function Cal(i,ok,j:longint):longint;
var cs,bd,kt,ok1:longint;
x:longint;
begin
        if i>length(a) then  exit(ord(j=0));
        if kq[i][ok][j]=n then exit(f[i][ok][j]);
        bd:=0;
        x:=0;
        if ok=0 then kt:=ord(a[i])-48 else kt:=9;
        for cs:=bd to kt do
          if (cs<>4)and(cs<>7) then
           begin
             if (ok=0)and(cs=ord(a[i])-48) then ok1:=0 else ok1:=1;
             x:=x+Cal(i+1,ok1,j);
           end else if j>0 then
             begin
               if (ok=0)and(cs=ord(a[i])-48) then ok1:=0 else ok1:=1;
               x:=x+Cal(i+1,ok1,j-1);
             end;
        kq[i][ok][j]:=n;
        f[i][ok][j]:=x;
        exit(x);
end;
procedure perfect(t:longint);
var i,j:longint;
begin
        res:=0;
        for i:=t+1 to length(a) do res:=res+sl[i];
        for i:=0 to length(a) do
          for j:=1 to s[i] do
            res:=(res*(sl[i]-j+1))mod modul;
        Sol:=(Sol+Res)mod modul;
end;
procedure DFS(i,t:longint);
var j:longint;
begin
        if t>=length(a) then exit;
        if i>6 then
          begin
            perfect(t);
            exit;
          end;
        for j:=0 to length(a) do if s[j]<sl[j] then
          begin
            inc(s[j]);
            DFS(i+1,t+j);
            dec(s[j]);
          end;
end;
procedure progress;
var i,j,u,v:longint;
begin
        read(m);str(m,a);
        for i:=0 to length(a) do
         begin
          inc(n);
          sl[i]:=Cal(1,0,i);
         end;
        dec(sl[0]);
        DFS(1,0);
        writeln(Sol);
end;
begin
        assign(input,'');reset(input);
        assign(output,'');rewrite(output);
          progress;
        close(input);
        close(output);
end.

const md:int64=1000000007;

var s:string;
    p:integer;
    ff,ans:int64;
    i,j,k,l,n,t,x,y:longint;
    a:array[0..15] of longint;
    f,w:array[0..1001] of int64;
    v:array[0..15,0..1,0..15] of int64;

function ll(x,y:int64):int64;
 begin
  if y=0 then ll:=1
         else begin
               if y mod 2=1 then ll:=x*ll(x,y-1) mod md
                            else begin
                                  x:=ll(x,y div 2);
                                  ll:=x*x mod md;
                                 end;
              end;
 end;

function pp(x,y:int64):int64;
var p:int64;
 begin
  p:=1;
  for i:=x-y+1 to x do
   p:=(p*int64(i)) mod md;
  pp:=p;
 end;

procedure tt(j,k,t,p:int64);
var lp:int64;
    i:longint;
 begin
  if k>6 then exit;
  if j>l then exit;

  if k=6 then begin
               for i:=1 to 6 do
                p:=p*int64(i) mod md;

               for i:=t+1 to l do
                ans:=(ans+w[i]*p) mod md;
               exit;
              end;

  for i:=0 to 6-k do
   begin
    if i<=w[j] then begin
                     tt(j+1,k+i,t+i*j,(p*pp(w[j],i) mod md)*f[i] mod md);
                    end
               else break;
   end;

 end;

 begin
  read(n);
  str(n,s);
  l:=length(s);
  for i:=1 to l do
   val(s[i],a[i],p);

  v[0,0,0]:=1;
  for i:=1 to l do
   for j:=0 to 1 do
    for k:=0 to l do
     begin
      if v[i-1,j,k]=0 then continue;

      if j=1 then x:=9
             else x:=a[i];

      for y:=0 to x do
       begin
        if (y<>4) and
           (y<>7) then t:=k
                  else t:=k+1;

        if (y<x) or
           (j=1) then v[i,1,t]:=(v[i,1,t]+v[i-1,j,k]) mod md
                 else v[i,0,t]:=(v[i,0,t]+v[i-1,j,k]) mod md;
       end;
     end;

  for i:=0 to l do
   begin
    w[i]:=v[l,0,i]+v[l,1,i];
    if i=0 then dec(w[i]);
   end;

  ff:=1;
  f[0]:=1;
  for i:=1 to 6 do
   begin
    ff:=ff*i;
    f[i]:=ll(ff,md-2);
   end;

  ans:=0;
  tt(0,0,0,1);

  writeln(ans);
 end.

const
  md=round(1e9)+7;
var
  dp:array[0..10,0..10,0..1] of int64;
  cnt,res,a:array[0..10] of int64;
  ans,m,i,j,k,x,next,ni,nx,nj:longint;

procedure solve(nom,k,sum:longint;num:int64);
var
  i:longint;
begin
  if (nom=7) then
  begin
    res[k]:=res[k]+num;
    if (res[k]>=md) then res[k]:=res[k]-md;
    exit;
  end;
  for i:=0 to 9 do if (cnt[i]<>0) then
  begin
    if (sum+i>=k) then break;
    dec(cnt[i]);
    solve(nom+1,k,sum+i,(num*(cnt[i]+1)) mod md);
    inc(cnt[i]);
  end;
end;

begin
  readln(m);
  for k:=1 to 10 do
  begin
    a[k]:=m mod 10;
    m:=m div 10;
    if (m=0) then break;
  end;
  for i:=1 to k do
  begin
    j:=k-i+1;
    if (i>j) then break;
    x:=a[i]; a[i]:=a[j]; a[j]:=x;
  end;
  dp[0,0,0]:=1;
  for i:=0 to k-1 do for j:=0 to k do for x:=0 to 1 do
  begin
    if (dp[i,j,x]=0) then continue;
    ni:=i+1;
    for next:=0 to 9 do
    begin
      if (x=1) then nx:=1 else
      begin
        if (next<a[ni]) then nx:=1;
        if (next=a[ni]) then nx:=0;
        if (next>a[ni]) then continue;
      end;
      nj:=j;
      if (next=4) or (next=7) then inc(nj);
      dp[ni,nj,nx]:=dp[ni,nj,nx]+dp[i,j,x];
      if (dp[ni,nj,nx]>=md) then dp[ni,nj,nx]:=dp[ni,nj,nx]-md;
    end;
  end;
  for j:=0 to k do for x:=0 to 1 do cnt[j]:=(cnt[j]+dp[k,j,x]) mod md;
  dec(cnt[0]);
  for i:=0 to 9 do
  begin
    if (cnt[i]=0) then continue;
    dec(cnt[i]);
    solve(1,i,0,1);
    inc(cnt[i]);
  end;
  for i:=0 to 9 do ans:=(ans+cnt[i]*res[i]) mod md;
  writeln(ans);
end.

program problem2;

const	md =	1000000007;

var	rev: array[ 1..10 ] of longInt;

function pow( a, p: longInt ): longInt;
var	res: longInt;
begin
	res := 1;
	while ( p > 0 ) do
	begin
		if ( odd(p) ) then
			res := ( res * int64(a) ) mod md;

		a := ( a * int64(a) ) mod md;
		p := p div 2;
	end;

	exit( res );
end;

function c( n, k: longInt ): longInt;
var	i: longInt;
	res: int64;
begin
	res := 1;
	for i := 1 to k do
		res := ( ( ( res * (n-i+1) ) mod md ) * rev[i] ) mod md;

	exit( res );
end;

var	i, j, k, l, ans, j1, k1, l1: longInt;
	cnt: array[ 0..10 ] of longInt;
	dp: array[ 1..10, 0..6, 0..10, -1..10 ] of int64;
	pow8: array[ 0..10 ] of longInt;
	m: ansistring;

begin
	fillchar( cnt, sizeOf(cnt), 0 );
	fillchar( dp, sizeOf(dp), 0 );

	for i := 1 to 10 do
		rev[i] := pow( i, ( md - 2 ) );

	pow8[0] := 1;
	for i := 1 to 9 do
		pow8[i] := pow8[i-1] * 8;

	readln( m );

	l := 0;
	for i := 1 to length( m ) do
	begin
		for j := 0 to ( ord( m[i] ) - ord( '0' ) - 1 ) do
			for k := 0 to ( length(m) - i ) do
				if ( j = 4 ) or ( j = 7 ) then
					inc( cnt[l+k+1], ( c( ( length(m) - i ), k ) * ( 1 shl k ) * pow8[ length(m) - i - k ] ) )
				else
					inc( cnt[l+k], ( c( ( length(m) - i ), k ) * ( 1 shl k ) * pow8[ length(m) - i - k ] ) );

		if ( m[i] = '4' ) or ( m[i] = '7' ) then
			inc( l );
	end;
	inc( cnt[l] );
	dec( cnt[0] );
{
	for i := 0 to 10 do
		writeln( i, ': ', cnt[i] );
}
	for i := 1 to 10 do
	begin
		dp[i][0][0][-1] := cnt[i];
		for j := 0 to 6 do
			for k := 0 to (i-1) do
				for l := 0 to 10 do
					for j1 := 0 to j do
						if ( k >= ( j1 * l ) ) then
							dp[i][j][k][l] := ( dp[i][j][k][l] + ( dp[i][j-j1][ k - (j1*l) ][l-1] * c( cnt[l], j1 ) ) ) mod md;
	end;

	ans := 0;
	for i := 1 to 10 do
		for k := 0 to (i-1) do
			ans := ( ans + dp[i][6][k][10] ) mod md;

	ans := ( ans * int64(720) ) mod md;

	writeln( ans );
end.

{$R-,S-,Q-,I-,O+}
{$M 32000000}

{$APPTYPE CONSOLE}

uses Math;
const
inf = round(1e9);
maxn = round(1e5)+200;
md = round(1e9)+7;
var
m,i,j,k,l,lenm : longint;
dp : array [1..11,0..11,0..2] of int64;
cnt : array [0..11] of int64;
a : array [1..11] of longint;
ans : int64;

function lucky (x : longint) : boolean;
begin
 lucky:=(x=4) or (x=7);
end;

function go(sum,len : longint) : int64;
var
i : longint;
res : int64;
begin
 if len=6 then
 begin
  go:=1;
  exit;
 end;
 res:=0;
 for i:=0 to sum-1 do
 begin
  dec(cnt[i]);
  res:=res+((cnt[i]+1)*go(sum-i,len+1))mod md;
  inc(cnt[i]);
 end;
 go:=res;
end;

begin
 //reset (input,'input.txt');
 //rewrite (output,'output.txt');
 readln(m);
 lenm:=0;
 while m>0 do
 begin
  inc(lenm);
  a[lenm]:=m mod 10;
  m:=m div 10;
 end;
 for i:=1 to lenm shr 1 do
 begin
  l:=a[i]; a[i]:=a[lenm-i+1]; a[lenm-i+1]:=l;
 end;

 fillchar(dp,sizeof(dp),0);
 for i:=1 to 9 do
 begin
  if (i<a[1]) and not lucky(i) then inc(dp[1,0,0]);
  if (i=a[1]) and not lucky(i) then inc(dp[1,0,1]);
  if (i>a[1]) and not lucky(i) then inc(dp[1,0,2]);
  if (i<a[1]) and lucky(i) then inc(dp[1,1,0]);
  if (i=a[1]) and lucky(i) then inc(dp[1,1,1]);
  if (i>a[1]) and lucky(i) then inc(dp[1,1,2]);
 end;
 for i:=1 to lenm-1 do
  for j:=0 to i do
   for k:=0 to 2 do
   if dp[i,j,k]>0 then
    for l:=0 to 9 do
    begin
     if k=0 then
     begin
      if lucky(l) then dp[i+1,j+1,k]:=dp[i+1,j+1,k] + dp[i,j,k];
      if not lucky(l) then dp[i+1,j,k]:=dp[i+1,j,k] + dp[i,j,k];
     end;

     if k=1 then
     begin
      if l<a[i+1] then
      begin
       if lucky(l) then dp[i+1,j+1,0]:=dp[i+1,j+1,0] + dp[i,j,k];
       if not lucky(l) then dp[i+1,j,0]:=dp[i+1,j,0] + dp[i,j,k];
      end;
      if l=a[i+1] then
      begin
       if lucky(l) then dp[i+1,j+1,1]:=dp[i+1,j+1,1] + dp[i,j,k];
       if not lucky(l) then dp[i+1,j,1]:=dp[i+1,j,1] + dp[i,j,k];
      end;
      if l>a[i+1] then
      begin
       if lucky(l) then dp[i+1,j+1,2]:=dp[i+1,j+1,2] + dp[i,j,k];
       if not lucky(l) then dp[i+1,j,2]:=dp[i+1,j,2] + dp[i,j,k];
      end;
     end;

     if k=2 then
     begin
      if lucky(l) then dp[i+1,j+1,k]:=dp[i+1,j+1,k] + dp[i,j,k];
      if not lucky(l) then dp[i+1,j,k]:=dp[i+1,j,k] + dp[i,j,k];
     end;
    end;
 fillchar(cnt,sizeof(cnt),0);
 for i:=1 to lenm-1 do
  for j:=0 to i do
   for k:=0 to 2 do cnt[j]:=(cnt[j]+dp[i,j,k])mod md;
 for j:=0 to lenm do
  for k:=0 to 1 do cnt[j]:=(cnt[j]+dp[lenm,j,k]) mod md;

 ans:=0;
 for i:=1 to lenm do ans:=(ans+cnt[i]*go(i,0))mod md;
 writeln(ans);
end.

const md = 1000000007;
var
  f : array[0..15,0..15,0..1] of longint;
  ff : array[0..15,0..15] of longint;
  fk : array[-5..15] of int64;
  w : array[0..15] of int64;
  i,j,n,k,z,q,ii : longint;
  m : ansistring;
  s,s1,s2,ans : int64;
  c,v : char;

  function chk(s : int64) : int64;
    var
      q,i : longint;
      ans,e : int64;
    begin
      i:=1;
      ans:=1;
      while i <= 5 do begin
        e:=s;
        ans:=ans*e mod md;
        dec(s);
        inc(i);
      end;
      exit(ans);
    end;

begin
  readln(m);
  if m = '7' then begin writeln(0); halt; end;
  for ii:=length(m) downto 1 do begin
    fillchar(f,sizeof(f),0);
    if ii > 1 then f[ii-1,0,1]:=1 else f[ii-1,0,0]:=1;
  for i:=ii-1 to length(m)-1 do
    for k:=0 to 9 do
      for z:=0 to 1 do if (f[i,k,z] > 0) then begin
        if z = 0 then c:=m[i+1] else c:='9';
        if (i = 0) then v:='1' else v:='0';
        for c:=v to c do begin
          if (c = '4') or (c = '7') then q:=1 else q:=0;
          f[i+1,k+q,z or ord(ord(c) < ord(m[i+1]))]:=f[i+1,k+q,z or ord(ord(c) < ord(m[i+1]))]+f[i,k,z];
        end;
      end;
    for k:=0 to 9 do ff[length(m),k]:=f[length(m),k,0]+f[length(m),k,1];
  end;
  for i:=0 to length(m) do begin
    s:=0;
    for j:=1 to length(m) do s:=(s+int64(ff[j,i])) mod md;
    fk[i]:=(fk[i-1]+s) mod md;
  end;
  for i:=length(m) downto 1 do begin
    s1:=fk[i]-fk[i-1];
    ans:=(ans+((chk(fk[i-1])*s1)) mod md) mod md;
  end;
  writeln(ans mod md);
end.

program election;

const
  fi='';
  fo='';
  maxn = 12;
  modulo = trunc(1e9)+7;
var
  m:longint;  len:longint;
  f:array[1..maxn,0..maxn,false..true,false..true] of int64;
  c:array[0..maxn] of int64;
  p8,p2,p10:array[0..maxn] of int64;
  cc:array[0..maxn,0..maxn] of int64;
  x:array[1..6] of longint;
  p:array[0..maxn] of longint;
  kq,g:int64;
procedure openfile;
var
  st:string;
begin
  assign(input,fi);reset(input);
  assign(output,fo);rewrite(output);
  readln(m);
  str(m,st);
  len:=length(st);
end;
//---------------
function digitof(n,i:longint):longint;  inline;
begin
  exit((n div p10[i-1]) mod 10);
end;
//--------------
function dp(i,j:longint;small,posi:boolean):int64;
var
  d,lim:longint;
begin
  if j<0 then exit(0);
  if f[i,j,small,posi]>0 then exit(f[i,j,small,posi]);
  if i=1 then
    begin
      if j>0 then f[i,j,small,posi]:=0 else f[i,j,small,posi]:=1;
      exit(f[i,j,small,posi]);
    end;
  if small then lim:=9 else lim:=digitof(m,i-1);
  f[i,j,small,posi]:=0;
  if posi then
    begin
      for d:=1 to lim do
        if (d=4)or(d=7) then f[i,j,small,posi]:=(f[i,j,small,posi]+dp(i-1,j-1,small or (d<digitof(m,i-1)),posi or (d>0))) mod modulo
        else f[i,j,small,posi]:=(f[i,j,small,posi]+dp(i-1,j,small or (d<digitof(m,i-1)),posi or (d>0))) mod modulo;
    end
  else
    begin
      for d:=1 to lim do
        if (d=4)or(d=7) then f[i,j,small,posi]:=(f[i,j,small,posi]+dp(i-1,j-1,small or (d<digitof(m,i-1)),posi or (d>0))) mod modulo
        else f[i,j,small,posi]:=(f[i,j,small,posi]+dp(i-1,j,small or (d<digitof(m,i-1)),posi or (d>0))) mod modulo;
    end;
  exit(f[i,j,small,posi]);
end;
//---------------
procedure ghi;
var
  i,j:longint;
  cnt:int64;
begin
  fillchar(p,sizeof(p),0);
  for i:=1 to 6 do inc(p[x[i]]);
  for i:=0 to maxn do
    if p[i]>c[i] then exit;
  for i:=0 to maxn do
  if (p[i]>0)and(p[i]<=c[i]) then
    begin
      cnt:=1;
      for j:=0 to p[i]-1 do cnt:=(cnt*(c[i]-j)) mod modulo;
      g:=(g+cnt) mod modulo;
    end;
end;
//--------------
procedure dfs(i,r:longint);
var
  j:longint;
begin
  if i=7 then
    begin
      if r=0 then ghi;
      exit;
    end;
  for j:=0 to r do
    begin
      x[i]:=j;
      dfs(i+1,r-j);
    end;
end;
//---------------
procedure process;
var
  i,j:longint;
begin
  fillchar(c,sizeof(c),0);
  p8[0]:=1;
  p2[0]:=1;
  p10[0]:=1;
  for i:=1 to maxn do
    begin
      p8[i]:=p8[i-1]*8;
      if p8[i]>=modulo then p8[i]:=p8[i]-modulo;
      p2[i]:=p2[i-1]*2;
      if p2[i]>=modulo then p2[i]:=p2[i]-modulo;
      p10[i]:=p10[i-1]*10;
    end;
  cc[0,0]:=1;
  for i:=1 to maxn do
    begin
      cc[i,0]:=1;cc[i,i]:=1;
      for j:=1 to i-1 do
        begin
          cc[i,j]:=cc[i-1,j]+cc[i-1,j-1];
          if cc[i,j]>=modulo then cc[i,j]:=cc[i,j]-modulo;
        end;
    end;
  for i:=1 to len-1 do
    begin
      c[0]:=c[0]+7*p8[i-1];
      c[i]:=c[i]+p2[i];
      for j:=1 to i-1 do
        begin
          c[j]:=(c[j]+(((p2[j]*cc[i-1,j]) mod modulo)*((7*p8[i-j-1]) mod modulo)) mod modulo) mod modulo;
          c[j]:=(c[j]+(((p2[j]*cc[i-1,j-1]) mod modulo)*p8[i-j]) mod modulo) mod modulo;
        end;
    end;
  for i:=0 to len do
    begin
      fillchar(f,sizeof(f),0);
      c[i]:=(c[i]+dp(len+1,i,false,false)) mod modulo;
    end;
  fillchar(x,sizeof(x),0);
  kq:=0;
  for len:=1 to len do
    begin
      g:=0;
      for i:=len-1 downto 0 do dfs(1,i);
      kq:=(kq+(g*c[len]) mod modulo) mod modulo;
    end;
  writeln(kq);
end;
//--------------
BEGIN
  openfile;
  process;
END.

program election;

const
  fi='';
  fo='';
  maxn = 12;
  modulo = trunc(1e9)+7;
var
  m:longint;  len:longint;
  f:array[1..maxn,0..maxn,false..true,false..true] of int64;
  c:array[0..maxn] of int64;
  p8,p2,p10:array[0..maxn] of int64;
  cc:array[0..maxn,0..maxn] of int64;
  x:array[1..6] of longint;
  p:array[0..maxn] of longint;
  kq,g:int64;
procedure openfile;
var
  st:string;
begin
  assign(input,fi);reset(input);
  assign(output,fo);rewrite(output);
  readln(m);
  str(m,st);
  len:=length(st);
end;
//---------------
function digitof(n,i:longint):longint;  inline;
begin
  exit((n div p10[i-1]) mod 10);
end;
//--------------
function dp(i,j:longint;small,posi:boolean):int64;
var
  d,lim:longint;
begin
  if j<0 then exit(0);
  if f[i,j,small,posi]>0 then exit(f[i,j,small,posi]);
  if i=1 then
    begin
      if j>0 then f[i,j,small,posi]:=0 else f[i,j,small,posi]:=1;
      exit(f[i,j,small,posi]);
    end;
  if small then lim:=9 else lim:=digitof(m,i-1);
  f[i,j,small,posi]:=0;
  if posi then
    begin
      for d:=0 to lim do
        if (d=4)or(d=7) then f[i,j,small,posi]:=(f[i,j,small,posi]+dp(i-1,j-1,small or (d<digitof(m,i-1)),posi or (d>0))) mod modulo
        else f[i,j,small,posi]:=(f[i,j,small,posi]+dp(i-1,j,small or (d<digitof(m,i-1)),posi or (d>0))) mod modulo;
    end
  else
    begin
      if i=2 then d:=1 else d:=0;
      for d:=d to lim do
        if (d=4)or(d=7) then f[i,j,small,posi]:=(f[i,j,small,posi]+dp(i-1,j-1,small or (d<digitof(m,i-1)),posi or (d>0))) mod modulo
        else f[i,j,small,posi]:=(f[i,j,small,posi]+dp(i-1,j,small or (d<digitof(m,i-1)),posi or (d>0))) mod modulo;
    end;
  exit(f[i,j,small,posi]);
end;
//---------------
procedure ghi;
var
  i,j:longint;
  cnt:int64;
begin
  fillchar(p,sizeof(p),0);
  for i:=1 to 6 do inc(p[x[i]]);
  for i:=0 to maxn do
    if p[i]>c[i] then exit;
  for i:=0 to maxn do
  if (p[i]>0)and(p[i]<=c[i]) then
    begin
      cnt:=1;
      for j:=0 to p[i]-1 do cnt:=(cnt*(c[i]-j)) mod modulo;
      g:=(g+cnt) mod modulo;
    end;
end;
//--------------
procedure dfs(i,r:longint);
var
  j:longint;
begin
  if i=7 then
    begin
      if r=0 then ghi;
      exit;
    end;
  for j:=0 to r do
    begin
      x[i]:=j;
      dfs(i+1,r-j);
    end;
end;
//---------------
procedure process;
var
  i,j:longint;
begin
  fillchar(c,sizeof(c),0);
  p8[0]:=1;
  p2[0]:=1;
  p10[0]:=1;
  for i:=1 to maxn do
    begin
      p8[i]:=p8[i-1]*8;
      if p8[i]>=modulo then p8[i]:=p8[i]-modulo;
      p2[i]:=p2[i-1]*2;
      if p2[i]>=modulo then p2[i]:=p2[i]-modulo;
      p10[i]:=p10[i-1]*10;
    end;
  cc[0,0]:=1;
  for i:=1 to maxn do
    begin
      cc[i,0]:=1;cc[i,i]:=1;
      for j:=1 to i-1 do
        begin
          cc[i,j]:=cc[i-1,j]+cc[i-1,j-1];
          if cc[i,j]>=modulo then cc[i,j]:=cc[i,j]-modulo;
        end;
    end;
  for i:=1 to len-1 do
    begin
      c[0]:=c[0]+7*p8[i-1];
      c[i]:=c[i]+p2[i];
      for j:=1 to i-1 do
        begin
          c[j]:=(c[j]+(((p2[j]*cc[i-1,j]) mod modulo)*((7*p8[i-j-1]) mod modulo)) mod modulo) mod modulo;
          c[j]:=(c[j]+(((p2[j]*cc[i-1,j-1]) mod modulo)*p8[i-j]) mod modulo) mod modulo;
        end;
    end;
  for i:=0 to len do
    begin
      fillchar(f,sizeof(f),0);
      c[i]:=(c[i]+dp(3,i,false,false)) mod modulo;
    end;
  fillchar(x,sizeof(x),0);
  kq:=0;
  for len:=1 to len do
    begin
      g:=0;
      for i:=len-1 downto 0 do dfs(1,i);
      kq:=(kq+(g*c[len]) mod modulo) mod modulo;
    end;
  writeln(kq);
end;
//--------------
BEGIN
  openfile;
  process;
END.

program election;

const
  fi='';
  fo='';
  maxn = 12;
  modulo = trunc(1e9)+7;
var
  m:longint;  len:longint;
  f:array[1..maxn,0..maxn,false..true] of int64;
  c:array[0..maxn] of int64;
  p8,p2,p10:array[0..maxn] of int64;
  cc:array[0..maxn,0..maxn] of int64;
  x:array[0..6] of longint;
  p:array[0..maxn] of longint;
  kq,g:int64;
procedure openfile;
var
  st:string;
begin
  assign(input,fi);reset(input);
  assign(output,fo);rewrite(output);
  readln(m);
  str(m,st);
  len:=length(st);
end;
//---------------
function digitof(n,i:longint):longint;  inline;
begin
  exit((n div p10[i-1]) mod 10);
end;
//--------------
function dp(i,j:longint;small:boolean):int64;
var
  d,lim:longint;
begin
  if j<0 then exit(0);
  if f[i,j,small]>0 then exit(f[i,j,small]);
  if i=1 then
    begin
      if j>0 then f[i,j,small]:=0 else f[i,j,small]:=1;
      exit(f[i,j,small]);
    end;
  if small then lim:=9 else lim:=digitof(m,i-1);
  f[i,j,small]:=0;
  if i=len+1 then d:=1 else d:=0;
      for d:=d to lim do
        if (d=4)or(d=7) then f[i,j,small]:=(f[i,j,small]+dp(i-1,j-1,small or (d<digitof(m,i-1)))) mod modulo
        else f[i,j,small]:=(f[i,j,small]+dp(i-1,j,small or (d<digitof(m,i-1)))) mod modulo;
  exit(f[i,j,small]);
end;
//---------------
procedure ghi;
var
  i,j:longint;
  cnt:int64;
begin
  fillchar(p,sizeof(p),0);
  for i:=1 to 6 do inc(p[x[i]]);
  for i:=0 to maxn do
    if p[i]>c[i] then exit;
  cnt:=1;
  for i:=0 to maxn do
  if (p[i]>0)and(p[i]<=c[i]) then
    begin
      for j:=0 to p[i]-1 do cnt:=(cnt*(c[i]-j)) mod modulo;
      for j:=1 to p[i] do cnt:=cnt div j;
    end;
  cnt:=(cnt*720) mod modulo;
  g:=(g+cnt) mod modulo;
end;
//--------------
procedure dfs(i,r:longint);
var
  j:longint;
begin
  if i=7 then
    begin
      if r=0 then ghi;
      exit;
    end;
  for j:=x[i-1] to r do
    begin
      x[i]:=j;
      dfs(i+1,r-j);
    end;
end;
//---------------
procedure process;
var
  i,j:longint;
begin
  fillchar(c,sizeof(c),0);
  p8[0]:=1;
  p2[0]:=1;
  p10[0]:=1;
  for i:=1 to maxn do
    begin
      p8[i]:=p8[i-1]*8;
      if p8[i]>=modulo then p8[i]:=p8[i]-modulo;
      p2[i]:=p2[i-1]*2;
      if p2[i]>=modulo then p2[i]:=p2[i]-modulo;
      p10[i]:=p10[i-1]*10;
    end;
  cc[0,0]:=1;
  for i:=1 to maxn do
    begin
      cc[i,0]:=1;cc[i,i]:=1;
      for j:=1 to i-1 do
        begin
          cc[i,j]:=cc[i-1,j]+cc[i-1,j-1];
          if cc[i,j]>=modulo then cc[i,j]:=cc[i,j]-modulo;
        end;
    end;
  for i:=1 to len-1 do
    begin
      c[0]:=c[0]+7*p8[i-1];
      c[i]:=c[i]+p2[i];
      for j:=1 to i-1 do
        begin
          c[j]:=(c[j]+(((p2[j]*cc[i-1,j]) mod modulo)*((7*p8[i-j-1]) mod modulo)) mod modulo) mod modulo;
          c[j]:=(c[j]+(((p2[j]*cc[i-1,j-1]) mod modulo)*p8[i-j]) mod modulo) mod modulo;
        end;
    end;
  for i:=0 to len do
    begin
      fillchar(f,sizeof(f),0);
      c[i]:=(c[i]+dp(len+1,i,false)) mod modulo;
    end;
  kq:=0;
  x[0]:=0;
  for len:=1 to len do
    begin
      g:=0;
      for i:=len-1 downto 0 do dfs(1,i);
      kq:=(kq+(g*c[len]) mod modulo) mod modulo;
    end;
  writeln(kq);
end;
//--------------
BEGIN
  openfile;
  process;
END.

const
    md = 1000000007;
var
    cur, res : int64;
    n, i, j, k, l, r, m : longint;
    d : array [0..10001,0..9] of longint;
    a, b, col, c, kol : array [0..10001] of longint;

procedure goes(len, sz, sum : longint);
var
    ans : int64;
    u : longint;
begin
    if (len > 6) then begin
        ans := 1;

//        writeln(sum,' ',sz);
 //       for k := 0 to 9 do write(col[k],' ');
   //     writeln;

        for k := 1 to 6 do
            ans := ans * c[k] mod md;

        res := (res + ans) mod md;

        exit;
    end;
    for u := 0 to sz-1 do
        if (a[u] > col[u]) and (sum+u < sz) then begin
            b[len] := u;
            c[len] := a[u]-col[u];
            col[u] := col[u] + 1;
            goes(len+1, sz, sum+u);
            col[u] := col[u] - 1;
        end;
    end;
function go(x : longint) : longint;
var
    y : longint;
begin
    y := 0;
    while (x > 0) do begin
        if (x mod 10 = 4) or (x mod 10 = 7) then inc(y);
        x := x div 10;
    end;
    go := y;
end;
begin
    read(n); d[0][0] := 1;

    for i := 1 to 9999 do begin
        for j := 0 to 4 do
            d[i][j] := d[i-1][j];
        kol[i] := go(i);
        inc(d[i][kol[i]]);
    end;

    for i := 0 to 9999 do begin
        l := 0; r := 9999; cur := -1;
        while (l <= r) do begin
            m := (l+r) shr 1;
            if (i*10000+m <= n) then begin
                l := m+1;
                cur := m;
            end
            else r := m-1;
        end;
        if (cur <> -1) then
            for j := 0 to 4 do
                inc(a[j+kol[i]], d[cur][j]);
    end;

//    for i := 0 to 9 do write(a[i], ' ');
    if (n = 1000000000) then inc(a[0]);
    dec(a[0]);
    cur := 0;
    for i := 1 to 9 do begin
        res := 0;
        goes(1, i, 0);
//        writeln(res);
        cur := (cur + res*a[i]) mod md;
    end;

    write(cur);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>6
     then begin
           if (z[i]<>7)or(i=1)
           then rez:=rez+2*p(i-1,e-1)*st(i-2-e)+p(i-1,e)*st(i-e-1)*(z[i]-2)
           else rez:=rez+p(i-1,e-1)*st(i-2-e)+p(i-1,e)*st(i-e-1)*(z[i]-2);
           dec(e);
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then rez:=rez+p(i-1,e-1)*st(i-2-e)+p(i-1,e)*st(i-e-1)*(z[i]-1)
                 else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
                 dec(e);
               end
          else begin
                rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
               end;
          end;
     if e<0
     then begin inc(rez); break; end;
  end;
  m[zz]:=rez;
end;
begin
//  Assign(input,'input.txt');
//  Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to 9 do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=kol*a[i2];
            Dec(a[i2]);
            kol:=kol*a[i3];
            Dec(a[i3]);
            kol:=kol*a[i4];
            Dec(a[i4]);
            kol:=kol*a[i5];
            Dec(a[i5]);
            kol:=kol*a[i6];
            Dec(a[i6]);
            kol:=kol*a[i7];
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e);
  for i:=kol downto 1 do
  begin
     if z[i]>4
     then begin
           rez:=rez+2*p(kol-1,e-1);
           dec(e);
          end
     else begin
           rez:=rez+dp[kol-1,e-1];
           dec(e);
          end;
     if e=0
     then break;
  end;
  m[zz]:=rez;
end;
begin
 // Assign(input,'input.txt');
 // Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to 9 do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=kol*a[i2];
            Dec(a[i2]);
            kol:=kol*a[i3];
            Dec(a[i3]);
            kol:=kol*a[i4];
            Dec(a[i4]);
            kol:=kol*a[i5];
            Dec(a[i5]);
            kol:=kol*a[i6];
            Dec(a[i6]);
            kol:=kol*a[i7];
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>6
     then begin
           if (z[i]<>7)or(i=1)
           then begin
                       if i<>kol
                       then inc(z[i]);

                rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2);
                end
           else begin
                       if i<>kol
                       then inc(z[i]);
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                end;
           dec(e);
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then begin
                        if i<>kol
                        then Inc(z[i]);
                        rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                      end
                 else begin
                       if i<>kol
                       then inc(z[i]);
                       rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
                      end;
                 dec(e);
               end
          else begin
                if i=kol
                then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i])
               end;
          end;
     if e<0
     then begin
{           if i=1
           then inc(rez);}
          Break;
          end;
  end;
  m[zz]:=rez;
end;
begin
  //Assign(input,'input.txt');
  //Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to 9 do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=(kol*a[i2])mod 1000000007;
            Dec(a[i2]);
            kol:=(kol*a[i3])mod 1000000007;
            Dec(a[i3]);
            kol:=(kol*a[i4])mod 1000000007;
            Dec(a[i4]);
            kol:=(kol*a[i5])mod 1000000007;
            Dec(a[i5]);
            kol:=(kol*a[i6])mod 1000000007;
            Dec(a[i6]);
            kol:=(kol*a[i7])mod 1000000007;
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>6
     then begin
           if (z[i]<>7)or(i=1)
           then begin
                rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2);
                            if i<>kol
                       then inc(z[i]);
                end
           else begin
                       if i<>kol
                       then inc(z[i]);
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                end;
           dec(e);
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then begin
                        if i<>kol
                        then Inc(z[i]);
                        rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                      end
                 else begin
                       if i<>kol
                       then inc(z[i]);
                       rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
                      end;
                 dec(e);
               end
          else begin
                if i=kol
                then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i])
               end;
          end;
     if e<0
     then begin{ inc(rez);} break; end;
  end;
  m[zz]:=rez;
end;
begin
  //Assign(input,'input.txt');
 // Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to 9 do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=kol*a[i2];
            Dec(a[i2]);
            kol:=kol*a[i3];
            Dec(a[i3]);
            kol:=kol*a[i4];
            Dec(a[i4]);
            kol:=kol*a[i5];
            Dec(a[i5]);
            kol:=kol*a[i6];
            Dec(a[i6]);
            kol:=kol*a[i7];
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>4
     then begin
           if (z[i]<>7)or(i=1)
           then rez:=rez+2*p(i-1,e-1)*st(i-2-e)+p(i-1,e)*st(i-e-1)*(z[i]-2)
           else rez:=rez+p(i-1,e-1)*st(i-2-e)+p(i-1,e)*st(i-e-1)*(z[i]-2);
           dec(e);
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then rez:=rez+p(i-1,e-1)*st(i-2-e)+p(i-1,e)*st(i-e-1)*(z[i]-1)
                 else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
                 dec(e);
               end
          else begin
                rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
               end;
          end;
     if e<0
     then begin inc(rez); break; end;
  end;
  m[zz]:=rez;
end;
begin
 // Assign(input,'input.txt');
 // Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to 9 do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=kol*a[i2];
            Dec(a[i2]);
            kol:=kol*a[i3];
            Dec(a[i3]);
            kol:=kol*a[i4];
            Dec(a[i4]);
            kol:=kol*a[i5];
            Dec(a[i5]);
            kol:=kol*a[i6];
            Dec(a[i6]);
            kol:=kol*a[i7];
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>6
     then begin
           if (z[i]<>7)
           then begin
                       if i<>kol
                       then rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2)
                       else rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-3)
                end
           else begin
                       if i<>kol
                       then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                       else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  dec(e);
                end;
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then begin
                        if i<>kol
                        then rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                        else rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2);
                      end
                 else begin
                       if i=kol
                       then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                       else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]);
                       dec(e);
                      end;
               end
          else begin
                if i=kol
                then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i])
               end;
          end;
     if e=0
     then Inc(rez);
     if (e<=0)
     then begin
{           if i=1
           then inc(rez);}
          Break;
          end;
  end;
  m[zz]:=rez;
end;
begin
//  Assign(input,'input.txt');
//  Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to i do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=(kol*a[i2])mod 1000000007;
            Dec(a[i2]);
            kol:=(kol*a[i3])mod 1000000007;
            Dec(a[i3]);
            kol:=(kol*a[i4])mod 1000000007;
            Dec(a[i4]);
            kol:=(kol*a[i5])mod 1000000007;
            Dec(a[i5]);
            kol:=(kol*a[i6])mod 1000000007;
            Dec(a[i6]);
            kol:=(kol*a[i7])mod 1000000007;
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>6
     then begin
           if (z[i]<>7)
           then begin
                       if i<>kol
                       then rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2)
                       else rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-3)
                end
           else begin
                       if i<>kol
                       then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                       else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  dec(e);
                end;
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then begin
                        if i<>kol
                        then rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                        else rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2);
                      end
                 else begin
                       if i=kol
                       then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                       else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]);
                       dec(e);
                      end;
               end
          else begin
                if i=kol
                then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i])
               end;
          end;
     if (i=1)and(e=0)
     then Inc(rez);
     if (e<0)
     then begin
{           if i=1
           then inc(rez);}
          Break;
          end;
  end;
  m[zz]:=rez;
end;
begin
 // Assign(input,'input.txt');
 // Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to i do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=(kol*a[i2])mod 1000000007;
            Dec(a[i2]);
            kol:=(kol*a[i3])mod 1000000007;
            Dec(a[i3]);
            kol:=(kol*a[i4])mod 1000000007;
            Dec(a[i4]);
            kol:=(kol*a[i5])mod 1000000007;
            Dec(a[i5]);
            kol:=(kol*a[i6])mod 1000000007;
            Dec(a[i6]);
            kol:=(kol*a[i7])mod 1000000007;
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>6
     then begin
           if (z[i]<>7)or(i=1)
           then begin
                       if i<>kol
                       then inc(z[i]);

                rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2);
                end
           else begin
                       if i<>kol
                       then inc(z[i]);
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                end;
           dec(e);
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then begin
                        if i<>kol
                        then Inc(z[i]);
                        rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                      end
                 else begin
                       if i<>kol
                       then inc(z[i]);
                       rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
                      end;
                 dec(e);
               end
          else begin
                if i=kol
                then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i])
               end;
          end;
     if e<0
     then begin
{           if i=1
           then inc(rez);}
           break;
          end;
  end;
  m[zz]:=rez;
end;
begin
 // Assign(input,'input.txt');
 // Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to 9 do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=kol*a[i2];
            Dec(a[i2]);
            kol:=kol*a[i3];
            Dec(a[i3]);
            kol:=kol*a[i4];
            Dec(a[i4]);
            kol:=kol*a[i5];
            Dec(a[i5]);
            kol:=kol*a[i6];
            Dec(a[i6]);
            kol:=kol*a[i7];
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>6
     then begin
           if (z[i]<>7)or(i=1)
           then rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2)
           else begin
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                end;
           dec(e);
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                 else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
                 dec(e);
               end
          else begin
                rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
               end;
          end;
     if e<0
     then begin inc(rez); break; end;
  end;
  m[zz]:=rez;
end;
begin
 // Assign(input,'input.txt');
 // Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to 9 do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=kol*a[i2];
            Dec(a[i2]);
            kol:=kol*a[i3];
            Dec(a[i3]);
            kol:=kol*a[i4];
            Dec(a[i4]);
            kol:=kol*a[i5];
            Dec(a[i5]);
            kol:=kol*a[i6];
            Dec(a[i6]);
            kol:=kol*a[i7];
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

Var i,j,i1,i2,i3,i4,i5,i6,i7,n:Integer;
a,m:array [0..9] of int64;
kol,rez:int64;
dp:array [0..10,0..10] of LongInt;
function stepen(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*2;
  stepen:=rez;
end;
function st(e:longint):longint;
Var i,rez:longint;
begin
  rez:=1;
  for i:=1 to e do
  rez:=rez*8;
  st:=rez;
end;
function p(n,e:longint):longint;
begin
  p:=dp[n,e]*stepen(e);
end;
procedure podchet(n,e:longint);
var zz,kol,i,rez:LongInt;
z:array [1..10] of longint;
begin
  rez:=0;
  zz:=e;
  kol:=0;
  while n<>0 do
  begin
    inc(kol);
    z[kol]:=n mod 10;
    n:=n div 10;
  end;
  rez:=rez+p(kol-1,e)*st(kol-e-1);
  for i:=kol downto 1 do
  begin
     if z[i]=0
     then Continue;
     if z[i]>6
     then begin
           if (z[i]<>7)or(i=1)
           then begin
                rez:=rez+2*p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-2);
                            if i<>kol
                       then inc(z[i]);
                end
           else begin
                       if i<>kol
                       then inc(z[i]);
                  rez:=rez+p(i-1,e-1)*st(i-1-(e-1));
                  rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-2);
                end;
           dec(e);
          end
     else begin
          if (z[i]>3)
          then begin
                 if (z[i]<>4)or(i=1)
                 then begin
                        if i<>kol
                        then Inc(z[i]);
                        rez:=rez+p(i-1,e-1)*st(i-1-(e-1))+p(i-1,e)*st(i-e-1)*(z[i]-1)
                      end
                 else begin
                       if i<>kol
                       then inc(z[i]);
                       rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1);
                      end;
                 dec(e);
               end
          else begin
                if i=kol
                then rez:=rez+p(i-1,e)*st(i-e-1)*(z[i]-1)
                else rez:=rez+p(i-1,e)*st(i-e-1)*(z[i])
               end;
          end;
     if e<0
     then begin inc(rez); break; end;
  end;
  m[zz]:=rez;
end;
begin
  //Assign(input,'input.txt');
  //Assign(output,'output.txt');
  readln(n);
  dp[0,0]:=1;
  for i:=1 to 9 do
  begin
    dp[i,0]:=1;
    for j:=1 to 9 do
    dp[i,j]:=dp[i-1,j-1]+dp[i-1,j];
  end;
  for i:=1 to 9 do
  podchet(n,i);
  m[0]:=n-m[1]-m[2]-m[3]-m[4]-m[5]-m[6]-m[7]-m[8]-m[9];
  rez:=0;
  for i1:=1 to 9 do
  begin
    for i2:=0 to 9 do
    for i3:=0 to 9 do
    for i4:=0 to 9 do
    for i5:=0 to 9 do
    for i6:=0 to 9 do
    for i7:=0 to 9 do
    begin
      if i2+i3+i4+i5+i6+i7<i1
      then begin
            a:=m;
            kol:=m[i1];
            kol:=kol*a[i2];
            Dec(a[i2]);
            kol:=kol*a[i3];
            Dec(a[i3]);
            kol:=kol*a[i4];
            Dec(a[i4]);
            kol:=kol*a[i5];
            Dec(a[i5]);
            kol:=kol*a[i6];
            Dec(a[i6]);
            kol:=kol*a[i7];
            Dec(a[i7]);
            rez:=rez+kol;
            rez:=rez mod 1000000007
           end;
    end;
  end;
  Writeln(rez);
end.

const
    f1  = '258b.inp';
    f2  = '258b.out';
    mxn = 10;
    oo  = round(1e9) + 7;
var
    n   : longint;
    res, tmp    : longint;
    st  : string;
    d   : array [0..mxn, 0..mxn, 0..1] of longint;
    f   : array [0..mxn, 0..mxn] of longint;
    num : array [0..mxn] of longint;

function recur(k, t, ok : longint) : longint;
var tn, okn, p, r   : longint;
        tp  : longint;
begin
    if d[k, t, ok] <> -1 then exit( d[k, t, ok] );
    if (k = n) then
        begin
            if (t = 0) then d[k, t, ok] := 1 else d[k, t, ok] := 0;
            exit( d[k, t, ok] );
        end;
    tp := 0;
    if ok = 0 then r := 9
    else r := ord(st[k+1]) - ord('0');

    for p := 0 to r do
        begin
            if (p = 4) or (p = 7) then tn := t - 1 else tn := t;
            if (p = r) and (ok = 1) then okn := 1 else okn := 0;
            if tn >= 0 then
                inc( tp, recur(k+1, tn, okn) );
        end;

    d[k, t, ok] := tp;
    exit( tp );
end;

procedure init;
var i, j    : longint;
begin
    fillchar(d, sizeof(d), 255);
    for i := 0 to n do f[i, 1] := recur(0, i, 1);
    dec( f[0, 1] );
    for i := 0 to n do f[i, 0] := 1;

    for i := 0 to n do
        for j := 2 to 6 do
            f[i, j] := ( int64(f[i, 1] - j + 1) * f[i, j-1] ) mod oo;
end;

procedure check;
var i, j    : longint;
begin
    for i := 0 to n do
        begin
            for j := 0 to 6 do write(f[i, j], ' ');
            writeln;
        end;
end;

procedure count;
var i, s    : longint;
begin
    s := 1;
    for i := 0 to n do
        s := ( int64(s) * f[i, num[i]] ) mod oo;
    tmp := tmp + s;
end;

procedure factor(k, t   : longint);
var i   : longint;
begin
    if k = 7 then
        begin
            if t = 0 then count;
            exit;
        end;
    for i := 0 to t do
        begin
            inc(num[i]);
            factor(k+1, t-i);
            dec(num[i]);
        end;
end;

procedure main;
var i   : longint;
begin
    for i := 1 to n do
        if f[i, 1] = 0 then break
        else
            begin
                factor(1, i-1);
                res := ( res + f[i, 1] * int64(tmp) ) mod oo;
            end;
    writeln(res);
end;

begin
//    assign(input, f1);  reset(input);
//    assign(output, f2); rewrite(output);
    read(st); n := length(st);
    init;
    //check;
    main;
end.

{$R+}
var
 cc,met:array [0..10] of int64;
 f:array [0..10,-1..10,0..1] of int64;
 md,i,j,n,m,k,i1,i2,i3,i4,i5,i6,d,nn,kol,c:longint;
 ans:int64;

 procedure swap(var x,y:int64);
  var
   c:longint;
  begin
  c:=x;
  x:=y;
  y:=c;
  end;

 function add(x1,x2,x3,x4,x5,x6,x7:longint):int64;
  var
   i:longint;
   res:int64;
  begin
   res:=1;
   for i:=0 to 10 do
    met[i]:=0;
   inc(met[x1]); inc(met[x2]); inc(met[x3]); inc(met[x4]); inc(met[x5]);
   inc(met[x6]); inc(met[x7]);
   for i:=0 to 9 do
    begin
      for j:=f[d,i,0]-met[i]+1to f[d,i,0] do
       begin
         res:=(res*j) mod md;
       end;
       if res=0 then exit(0);
    end;
    exit(res mod md);
  end;

begin
 md:=1000000000+7;
 readln(n);
 nn:=n;
 while nn<>0 do
  begin
   inc(d);
   cc[d]:=nn mod 10;
   nn:=nn div 10;
  end;
 for i:=1 to d div 2 do
  swap(cc[i],cc[d-i+1]);

 f[0,0,1]:=1;
 for i:=1 to d do
  begin
   for  kol:=0 to 10 do
    begin
     for c:=0 to 9 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,0]+f[i,kol,0]
         else f[i,kol,0]:=f[i-1,kol,0]+f[i,kol,0];
      end;
     for c:=0 to cc[i]-1 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,1]+f[i,kol,0]
         else f[i,kol,0]:=f[i,kol,0]+f[i-1,kol,1];
      end;
     if (cc[i]=4)or(cc[i]=7) then f[i,kol,1]:=f[i-1,kol-1,1]+f[i,kol,1]
      else f[i,kol,1]:=f[i,kol,1]+f[i-1,kol,1];
    end;
  end;
 for i:=0 to 10 do
  f[d,i,0]:=f[d,i,0]+f[d,i,1];
 dec(f[d,0,0]);
 for i:=1 to d do
  begin
   for i1:=0 to i do
    for i2:=0 to i-i1 do
     for i3:=0 to i-i1-i2 do
      for i4:=0 to i-i1-i2-i3 do
       for i5:=0 to i-i1-i2-i3-i4 do
        for i6:=0 to i-i1-i2-i3-i4-i5 do
         begin
          if (i1+i2+i3+i4+i5+i6)>=i then continue;
          ans:=(ans+add(i,i1,i2,i3,i4,i5,i6))mod md;
         end;
  end;
 writeln(ans);
end.

{$R+}
var
 cc,met:array [0..100] of int64;
 f:array [0..100,-1..100,0..1] of int64;
 md,n,m,k,d,nn:int64;
 c,kol,i,j,i1,i2,i3,i4,i5,i6:longint;
 ans:int64;

 procedure swap(var x,y:int64);
  var
   c:longint;
  begin
  c:=x;
  x:=y;
  y:=c;
  end;

 function add(x1,x2,x3,x4,x5,x6,x7:int64):int64;
  var
   i,j:longint;
   res:int64;
  begin
   res:=1;
   for i:=0 to 11 do
    met[i]:=0;
   inc(met[x1]);  inc(met[x2]); inc(met[x3]); inc(met[x4]); inc(met[x5]);
   inc(met[x6]); inc(met[x7]);
   for i:=0 to 9 do
    begin
      for j:=f[d,i,0]-met[i]+1 to f[d,i,0] do
       begin
         res:=(res*j) mod md;
       end;
       if res=0 then
                        begin
                         add:=0;
                         exit;
                        end;
    end;
    add:=(res mod md);
  end;

begin
 md:=1000000000+7;
 readln(n);
 nn:=n;
 while nn<>0 do
  begin
   inc(d);
   cc[d]:=nn mod 10;
   nn:=nn div 10;
  end;
 for i:=1 to d div 2 do
  swap(cc[i],cc[d-i+1]);

 f[0,0,1]:=1;
 for i:=1 to d do
  begin
   for  kol:=0 to 10 do
    begin
     for c:=0 to 9 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,0]+f[i,kol,0]
         else f[i,kol,0]:=f[i-1,kol,0]+f[i,kol,0];
      end;
     for c:=0 to cc[i]-1 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,1]+f[i,kol,0]
         else f[i,kol,0]:=f[i,kol,0]+f[i-1,kol,1];
      end;
     if (cc[i]=4)or(cc[i]=7) then f[i,kol,1]:=f[i-1,kol-1,1]+f[i,kol,1]
      else f[i,kol,1]:=f[i,kol,1]+f[i-1,kol,1];
    end;
  end;
 for i:=0 to 10 do
  f[d,i,0]:=(f[d,i,0]+f[d,i,1])mod md;
 dec(f[d,0,0]);
 for i:=1 to d do
  begin
   for i1:=0 to i do
    for i2:=0 to i-i1 do
     for i3:=0 to i-i1-i2 do
      for i4:=0 to i-i1-i2-i3 do
       for i5:=0 to i-i1-i2-i3-i4 do
        for i6:=0 to i-i1-i2-i3-i4-i5 do
         begin
          if (i1+i2+i3+i4+i5+i6)>=i then continue;
          ans:=(ans+add(i,i1,i2,i3,i4,i5,i6))mod md;
         end;
  end;
 writeln(ans);
end.

var
 cc,met:array [0..10] of longint;
 f:array [0..10,-1..10,0..1] of longint;
 md,i,j,n,m,k,ans,i1,i2,i3,i4,i5,i6,d,nn,kol,c:longint;

 procedure swap(var x,y:longint);
  var
   c:longint;
  begin
  c:=x;
  x:=y;
  y:=c;
  end;

 function add(x1,x2,x3,x4,x5,x6,x7:longint):int64;
  var
   i:longint;
   res:int64;
  begin
   res:=1;
   for i:=0 to 10 do
    met[i]:=0;
   inc(met[x1]); inc(met[x2]); inc(met[x3]); inc(met[x4]); inc(met[x5]);
   inc(met[x6]); inc(met[x7]);
   for i:=0 to 9 do
    begin
      for j:=f[d,i,0]-met[i]+1to f[d,i,0] do
       begin
         res:=res*j mod md;
       end;
       if res=0 then exit(0);
    end;
    exit(res);
  end;

begin
 md:=1000000000+7;
 readln(n);
 nn:=n;
 while nn<>0 do
  begin
   inc(d);
   cc[d]:=nn mod 10;
   nn:=nn div 10;
  end;
 for i:=1 to d div 2 do
  swap(cc[i],cc[d-i+1]);

 f[0,0,1]:=1;
 for i:=1 to d do
  begin
   for  kol:=0 to 10 do
    begin
     for c:=0 to 9 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,0]+f[i,kol,0]
         else f[i,kol,0]:=f[i-1,kol,0]+f[i,kol,0];
      end;
     for c:=0 to cc[i]-1 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,1]+f[i,kol,0]
         else f[i,kol,0]:=f[i,kol,0]+f[i-1,kol,1];
      end;
     if (cc[i]=4)or(cc[i]=7) then f[i,kol,1]:=f[i-1,kol-1,1]+f[i,kol,1]
      else f[i,kol,1]:=f[i,kol,1]+f[i-1,kol,1];
    end;
  end;
 for i:=0 to 10 do
  f[d,i,0]:=f[d,i,0]+f[d,i,1];
 dec(f[d,0,0]);
 for i:=1 to d do
  begin
   for i1:=0 to i do
    for i2:=0 to i-i1 do
     for i3:=0 to i-i1-i2 do
      for i4:=0 to i-i1-i2-i3 do
       for i5:=0 to i-i1-i2-i3-i4 do
        for i6:=0 to i-i1-i2-i3-i4-i5 do
         begin
          if (i1+i2+i3+i4+i5+i6)>=i then continue;
          ans:=(ans+add(i,i1,i2,i3,i4,i5,i6))mod md;
         end;
  end;
 writeln(ans);
end.

var
 cc,met:array [0..10] of longint;
 f:array [0..10,-1..10,0..1] of longint;
 md,i,j,n,m,k,i1,i2,i3,i4,i5,i6,d,nn,kol,c:longint;
 ans:int64;

 procedure swap(var x,y:longint);
  var
   c:longint;
  begin
  c:=x;
  x:=y;
  y:=c;
  end;

 function add(x1,x2,x3,x4,x5,x6,x7:longint):int64;
  var
   i:longint;
   res:int64;
  begin
   res:=1;
   for i:=0 to 10 do
    met[i]:=0;
   inc(met[x1]); inc(met[x2]); inc(met[x3]); inc(met[x4]); inc(met[x5]);
   inc(met[x6]); inc(met[x7]);
   for i:=0 to 9 do
    begin
      for j:=f[d,i,0]-met[i]+1to f[d,i,0] do
       begin
         res:=res*j mod md;
       end;
       if res=0 then exit(0);
    end;
    exit(res);
  end;

begin
 md:=1000000000+7;
 readln(n);
 nn:=n;
 while nn<>0 do
  begin
   inc(d);
   cc[d]:=nn mod 10;
   nn:=nn div 10;
  end;
 for i:=1 to d div 2 do
  swap(cc[i],cc[d-i+1]);

 f[0,0,1]:=1;
 for i:=1 to d do
  begin
   for  kol:=0 to 10 do
    begin
     for c:=0 to 9 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,0]+f[i,kol,0]
         else f[i,kol,0]:=f[i-1,kol,0]+f[i,kol,0];
      end;
     for c:=0 to cc[i]-1 do
      begin
        if (c=4)or(c=7) then f[i,kol,0]:=f[i-1,kol-1,1]+f[i,kol,0]
         else f[i,kol,0]:=f[i,kol,0]+f[i-1,kol,1];
      end;
     if (cc[i]=4)or(cc[i]=7) then f[i,kol,1]:=f[i-1,kol-1,1]+f[i,kol,1]
      else f[i,kol,1]:=f[i,kol,1]+f[i-1,kol,1];
    end;
  end;
 for i:=0 to 10 do
  f[d,i,0]:=f[d,i,0]+f[d,i,1];
 dec(f[d,0,0]);
 for i:=1 to d do
  begin
   for i1:=0 to i do
    for i2:=0 to i-i1 do
     for i3:=0 to i-i1-i2 do
      for i4:=0 to i-i1-i2-i3 do
       for i5:=0 to i-i1-i2-i3-i4 do
        for i6:=0 to i-i1-i2-i3-i4-i5 do
         begin
          if (i1+i2+i3+i4+i5+i6)>=i then continue;
          ans:=(ans+add(i,i1,i2,i3,i4,i5,i6))mod md;
         end;
  end;
 writeln(ans);
end.

const md = 1000000007;
var
w,ans,s:int64;
fact:array[0..1000]of int64;
p,u,i,j,n,m,t:longint;
dp:array[0..100,0..100]of int64;
a:Array[0..100]of int64;
c1,c2:array[0..100,0..100]of int64;
function st(x,n:int64):int64;
var t:int64;
begin
 if n=0 then st:=1
 else
   begin
    if n mod 2=1 then st:=x*st(x,n-1) mod md
    else
     begin
      t:=st(x,n div 2);
      t:=t*t mod md;
      st:=t;
     end;
   end;
end;
function cnk(n,k:longint):int64;
var i:longint; d:int64;
begin
 d:=1;
 for i:=n-k+1 to n do
  begin
   d:=d*int64(i);
   d:=d mod md;
  end;
 d:=d*st(fact[k],md-2);
 d:=d mod md;
 cnk:=d;
end;
procedure add(var a:int64; b:longint);
begin
 a:=a+b;
 if a>=md then a:=a-md;
end;
function c(n:longint):int64;
var
d,res:int64;
last,i,j,u:longint;
begin
  c1[0,0]:=1;
  for last:=0 to n-1 do
   begin
     fillchar(c2,sizeof(c2),0);
     for i:=0 to n-1 do
       for j:=0 to 6 do
         begin
           add(c2[i,j],c1[i,j]);
           for u:=1 to 6-j do
             if (i+u*last<n)and(a[last]>=u) then
              begin
               d:=c1[i,j];
               d:=d*cnk(a[last],u) mod md;
               add(c2[i+u*last,j+u],d);
              end;
         end;
     for i:=0 to n-1 do
      for j:=0 to 6 do
       c1[i,j]:=c2[i,j];
   end;
  res:=0;
  for i:=0 to n-1 do
   res:=(res+c1[i,6]) mod md;
  c:=res;
end;
procedure precalc;
var s:string;
begin
 dp[1,1]:=2;
 dp[1,0]:=8;

 for i:=2 to 9 do
   for j:=0 to i-1 do
     begin
      dp[i,j]:=dp[i,j]+dp[i-1,j]*8;
      dp[i,j+1]:=dp[i,j+1]+dp[i-1,j]*2;
     end;

 str(m,s);
 dp[0,0]:=1;
 for i:=1 to length(s)-1 do
  begin
     for u:=1 to 9 do
      begin
       if (u=4)or(u=7) then t:=1
       else t:=0;
       for j:=0 to i do
        a[j+t]:=a[j+t]+dp[i-1,j];
      end;
  end;
 t:=0;
 for i:=1 to length(s) do
   begin
    p:=1;
    if (i<>1) then p:=0;
    for u:=p to ord(s[i])-49 do
      begin
        if (u=4)or(u=7) then inc(t);
        for j:=0 to 10 do
          a[j+t]:=a[j+t]+dp[length(s)-i,j];
        if (u=4)or(u=7) then dec(t);
      end;
    if (s[i]='4')or(s[i]='7') then inc(t);
   end;
 inc(a[t]);
end;
 begin
  fact[0]:=1;
  for i:=1 to 6 do
   fact[i]:=fact[i-1]*i;
  readln(m);
  w:=1;
  precalc;
  s:=a[0];
  for i:=1 to 10 do
   begin
     ans:=ans+a[i]*c(i);
     ans:=ans mod md;
   end;
  writeln(ans*720 mod md);
 end.

const md = 1000000007;
var
w,ans,s:int64;
p,u,i,j,n,m,t:longint;
dp:array[0..100,0..100]of int64;
a:Array[0..100]of int64;
function st(x,n:int64):int64;
var t:int64;
begin
 if n=0 then st:=1
 else
   begin
    if n mod 2=1 then st:=x*st(x,n-1) mod md
    else
     begin
      t:=st(x,n div 2);
      t:=t*t mod md;
      st:=t;
     end;
   end;
end;
function c(n,k:longint):int64;
var d:int64;
    i:longint;
begin
 d:=1;
 for i:=n-k+1 to n do
  d:=d*int64(i) mod md;
 d:=d*w mod md;
 c:=d;
end;
procedure precalc;
var s:string;
begin
 dp[1,1]:=2;
 dp[1,0]:=8;

 for i:=2 to 9 do
   for j:=0 to i-1 do
     begin
      dp[i,j]:=dp[i,j]+dp[i-1,j]*8;
      dp[i,j+1]:=dp[i,j+1]+dp[i-1,j]*2;
     end;

 str(m,s);
 dp[0,0]:=1;
 for i:=1 to length(s)-1 do
  begin
     for u:=1 to 9 do
      begin
       if (u=4)or(u=7) then t:=1
       else t:=0;
       for j:=0 to i do
        a[j+t]:=a[j+t]+dp[i-1,j];
      end;
  end;
 t:=0;
 for i:=1 to length(s) do
   begin
    p:=1;
    if (i<>1) then p:=0;
    for u:=p to ord(s[i])-49 do
      begin
        if (u=4)or(u=7) then inc(t);
        for j:=0 to 10 do
          a[j+t]:=a[j+t]+dp[length(s)-i,j];
        if (u=4)or(u=7) then dec(t);
      end;
    if (s[i]='4')or(s[i]='7') then inc(t);
   end;
 inc(a[t]);
end;
 begin
  readln(m);
  w:=1;
  precalc;
  s:=a[0];
  for i:=1 to 10 do
   begin
     ans:=ans+a[i]*c(s,6);
     ans:=ans mod md;
   end;
  writeln(ans);
 end.

Uses Math;
Const
  Fi            =               '';//ELECTION.INP';
  Fo            =               '';//ELECTION.OUT';
  Base          =               Trunc(1e9)+7;
  Maxcs         =               11;
Type
  M1            =               Array [0..Maxcs] of Longint;
  M2            =               Array [0..Maxcs,-Maxcs..Maxcs,false..true,false..true] of Longint;
Var
  f , g : Text;
  m : Longint;
  res , kq : Int64;
  num : String;
  a , x, dem : M1;
  fx : M2;

Procedure Openfile;
Begin
  Assign(f,fi);
  Reset(f);
  Assign(g,fo);
  Rewrite(g);
End;

Procedure Closefile;
Begin
  Close(f);
  Close(g);
End;

Procedure Doc;
Begin
  Readln(f,m);
End;

Function Tinh(i , j : Longint; ok , ok2 : Boolean) : Longint;
Var
  k , sum : Longint;
Begin
  If fx[i,j,ok,ok2]<>-1 then exit(fx[i,j,ok,ok2]);
  If i>length(num) then
    Begin
      Fx[i,j,ok,ok2]:=ord((j=0) and ok2);
      Exit(fx[i,j,ok,ok2]);
    End;
  Sum:=0;
  For k:=0 to max(ord(num[i])-48,ord(ok)*9) do sum:=sum+tinh(i+1,j-ord((k=4) or (k=7)),ok or (k<ord(num[i])-48),ok2 or (k<>0));
  Fx[i,j,ok,ok2]:=sum;
  Exit(sum);
End;

Procedure Init;
Var
  j : Longint;
Begin
  Str(m,num);
  For j:=0 to length(num) do
    Begin
      Fillchar(fx,sizeof(fx),255);
      a[j]:=tinh(1,j,false,false);
    End;
End;

Procedure Capnhat;
Var
  i , j : Longint;
  t : Int64;
Begin
  t:=1;
  For i:=0 to 9 do
  If dem[i]>0 then
    Begin
      For j:=0 to dem[i]-1 do t:=(t*(a[i]-j)) mod base;
    End;
  Kq:=(kq+t) mod base;
End;

Procedure Thu(i , j : Longint);
Var
  k : Longint;
Begin
  For k:=0 to j do
    Begin
      Inc(dem[k]);
      If i<6 then thu(i+1,j-k)
      Else capnhat;
      Dec(dem[k]);
    End;
End;

Procedure Solve;
Var
  i , j : Longint;
Begin
  Res:=0;
  For i:=1 to length(num) do
    Begin
      //Fillchar(x,sizeof(x),0);
      Fillchar(dem,sizeof(dem),0);
      kq:=0;
      For j:=0 to i-1 do thu(i,j);
      kq:=(kq*a[i]) mod base;
      Res:=(res+kq) mod base;
    End;
End;

Procedure Ghi;
Begin
  If m<=7 then writeln(g,0)
  Else writeln(g,res);
End;

Begin
  Openfile;
  Doc;
  Init;
  Solve;
  Ghi;
  Closefile;
End.

uses math;
const base=1000000000+7;
var m,top,tong:longint;
    st,c:array[0..10]of longint;
    dp:array[0..10,0..10]of longint;
    mang:array[0..10]of longint;
    ans:int64;

function get(x,y:longint):longint;
begin
  get:=(x shr y) and 1;
end;

procedure nhap;
var m2:longint;
begin
  assign(input,'');  reset(input);
  fillchar(dp,sizeof(dp),0);
  readln(m);  top:=0;
  while m<>0 do begin
    inc(top);  st[top]:=m mod 10;  m:=m div 10;
  end;
end;

procedure solve;
var i,j,count,ans,t:longint;
begin
  dp[0,0]:=1;
  for i:=1 to min(9,top) do begin
    for j:=0 to (1 shl i)-1 do begin
      count:=0;  ans:=1;
      for t:=1 to i do if get(j,t-1)=1 then begin
        inc(count);  ans:=ans*2;
      end
      else ans:=ans*8;
      dp[i,count]:=dp[i,count]+ans;
    end;
  end;
end;

function combi(p,x:longint):int64;
var i:longint;
    combix:int64;
begin
  combix:=1;
  for i:=0 to x-1 do combix:=(combix*(p-i))mod base;
  combi:=combix;
end;

procedure update(lab:longint);
var sum:int64;
    i:longint;
begin
  sum:=1;
  for i:=0 to 9 do begin
    sum:=sum*combi(mang[i],c[i]);
  end;
  sum:=sum*mang[lab];
  ans:=ans+sum;
end;

procedure pick(k,lab:longint);
var i:longint;
begin
  for i:=0 to 9 do begin
    if tong+i>=lab then exit;
    tong:=tong+i;
    inc(c[i]);
    if k=6 then update(lab) else pick(k+1,lab);
    dec(c[i]);
    tong:=tong-i;
  end;
end;

procedure print;
var i,j,t,v,count,i1,i2,i3,i4,i5,i6:longint;
begin
  fillchar(mang,sizeof(mang),0);  ans:=0;  count:=0;
  for i:=top downto 1 do begin
    for j:=st[i]-1 downto 0 do begin
      if (j=4)or(j=7) then inc(count);
      for t:=0 to 9 do if (t+count<=9)
        then mang[t+count]:=mang[t+count]+dp[i-1,t];
      if (j=4)or(j=7) then dec(count);
    end;
    if (st[i]=4)or(st[i]=7) then inc(count);
  end;
  inc(mang[count]);  dec(mang[0]);
  for i:=0 to 9 do begin
    tong:=0;  fillchar(c,sizeof(c),0);
    pick(1,i);
  end;
  writeln(ans);
end;

begin
  nhap;
  solve;
  print;
end.

uses math;
const base=1000000000+7;
var m,top:longint;
    st:array[1..10]of longint;
    dp:array[0..10,0..10]of longint;
    mang:array[0..10]of longint;

function get(x,y:longint):longint;
begin
  get:=(x shr y) and 1;
end;

procedure nhap;
var m2:longint;
begin
  assign(input,'');  reset(input);
  fillchar(dp,sizeof(dp),0);
  readln(m);  top:=0;
  while m<>0 do begin
    inc(top);  st[top]:=m mod 10;  m:=m div 10;
  end;
end;

procedure solve;
var i,j,count,ans,t:longint;
begin
  dp[0,0]:=1;
  for i:=1 to min(9,top) do begin
    for j:=0 to (1 shl i)-1 do begin
      count:=0;  ans:=1;
      for t:=1 to i do if get(j,t-1)=1 then begin
        inc(count);  ans:=ans*2;
      end
      else ans:=ans*8;
      dp[i,count]:=dp[i,count]+ans;
    end;
  end;
end;

function combi(p:longint):int64;
var i:longint;
    combix:int64;
begin
  combix:=1;
  for i:=0 to 5 do combix:=(combix*(p-i))mod base;
  combi:=combix;
end;

procedure print;
var ans,i,j,t,v,sum,count:longint;
begin
  fillchar(mang,sizeof(mang),0);  ans:=0;  count:=0;
  for i:=top downto 1 do begin
    for j:=st[i]-1 downto 0 do begin
      if (j=4)or(j=7) then inc(count);
      for t:=0 to 9 do if (t+count<=9)
        then mang[t+count]:=mang[t+count]+dp[i-1,t];
      if (j=4)or(j=7) then dec(count);
    end;
    if (st[i]=4)or(st[i]=7) then inc(count);
  end;
  inc(mang[count]);  dec(mang[0]);
  for i:=0 to 9 do begin
    sum:=0;
    for j:=0 to i-1 do sum:=sum+mang[j];
    ans:=(ans+(combi(sum)*mang[i])mod base)mod base;
  end;
  writeln(ans);
end;

begin
  nhap;
  solve;
  print;
end.

const md=1000000000+7;
Var ans,sum,n,x,res:int64;
    f:array[0..12,0..12,boolean]of int64;
    i,j,len,u,d,mx:longint;
    s:string;
    w:boolean;
{ function pow(a,b:int64):int64;
   begin
     if b=0 then exit(1);
     if b mod 2=1 then pow:=pow(a,b-1)*a mod md
     else begin a:=a*a mod md;pow:=pow(a,b div 2);end;
   end;
 } begin
    read(n);
    str(n+1,s);
    len:=length(s);
    f[0,0,false]:=1;
    for i:=1 to len do
      for j:=0 to len do
        for w:=false to true do
          begin
            if w  then mx:=9
            else mx:=ord(s[i])-48;
            for d:=0 to mx do
              f[i,j+ord((d=4)or(d=7)),w or (d<ord(s[i])-48)]:=(
              f[i,j+ord((d=4)or(d=7)),w or (d<ord(s[i])-48)]+f[i-1,j,w]);
          end;
    ans:=0;
    sum:=-1;
//    dd:=pow(720,md-2);
    for i:=0 to len do
      begin
        x:=f[len,i,true];
        if i>0 then
        begin
        res:=1;
        for j:=sum downto sum-5 do
          res:=res*int64(j) mod md;
          end else res:=0;
        ans:=(ans+res*x)mod md;
        sum:=sum+x;
      end;
    Writeln(ans);
  end.

const md=1000000000+7;
Var ans,sum,n,x,res:int64;
    f:array[0..12,0..12,boolean]of int64;
    i,j,len,u,d,mx:longint;
    s:string;
    g,fact,rev,q:array[0..1234]of int64;
    w:boolean;
 function pow(a,b:int64):int64;
   begin
     if b=0 then exit(1);
     if b mod 2=1 then pow:=pow(a,b-1)*a mod md
     else begin a:=a*a mod md;pow:=pow(a,b div 2);end;
   end;

  procedure rec(x,sum:longint;tmp:int64);
    var i:longint;
      begin
        if sum>=len then exit;
        if x=7 then
          begin
            for i:=0 to len do
              tmp:=tmp*rev[fact[q[i]]] mod md;
            for i:=sum+1 to len do
               ans:=(ans+tmp*g[i])mod md;
            exit;
          end;
        for i:=0 to len-1 do
          if g[i]>0 then
            begin
              dec(g[i]);
              inc(q[i]);
              rec(x+1,sum+i,tmp*g[i] mod md);
              inc(g[i]);
              dec(q[i]);
            end;
      end;
  begin
    read(n);
    rev[0]:=1;
    for i:=1 to 1000 do
      rev[i]:=pow(i,md-2);
    fact[0]:=1;
    for i:=1 to 7 do
      fact[i]:=fact[i-1]*i;
    str(n+1,s);
    len:=length(s);
    f[0,0,false]:=1;
    for i:=1 to len do
      for j:=0 to len do
        for w:=false to true do
          begin
            if w  then mx:=9
            else mx:=ord(s[i])-48;
            for d:=0 to mx do
              f[i,j+ord((d=4)or(d=7)),w or (d<ord(s[i])-48)]:=(
              f[i,j+ord((d=4)or(d=7)),w or (d<ord(s[i])-48)]+f[i-1,j,w]);
          end;
    for i:=0 to len do
      g[i]:=f[len,i,true];
    ans:=0;
    rec(1,0,1);
    ans:=ans*int64(720) mod md;
    Writeln(ans);
  end.

const md=1000000000+7;
Var ans,sum,n,x,res:int64;
    f:array[0..12,0..12,boolean]of int64;
    i,j,len,u,d,mx:longint;
    s:string;
    w:boolean;
{ function pow(a,b:int64):int64;
   begin
     if b=0 then exit(1);
     if b mod 2=1 then pow:=pow(a,b-1)*a mod md
     else begin a:=a*a mod md;pow:=pow(a,b div 2);end;
   end;
 } begin
    read(n);
    str(n+1,s);
    len:=length(s);
    f[0,0,false]:=1;
    for i:=1 to len do
      for j:=0 to len do
        for w:=false to true do
          begin
            if w  then mx:=9
            else mx:=ord(s[i])-48;
            for d:=0 to 9 do
              f[i,j+ord((d=4)or(d=7)),w or (d<ord(s[i])-48)]:=(
              f[i,j+ord((d=4)or(d=7)),w or (d<ord(s[i])-48)]+f[i-1,j,w]);
          end;
    ans:=0;
    sum:=-1;
//    dd:=pow(720,md-2);
    for i:=0 to len do
      begin
        x:=f[len,i,true];
        if sum>5 then
        begin
        res:=1;
        for j:=sum downto sum-5 do
          res:=res*int64(j) mod md;
          end else res:=0;
        ans:=(ans+res*x)mod md;
        sum:=sum+x;
      end;
    Writeln(ans);
  end.

const
   finp='';//258B.inp';
   fout='';//258B.out';
   base=1000000007;

var
   fi,fo:text;
   f:array[0..10,-1..10] of longint;
   a,s,gt,val:array[0..10] of longint;
   m,n,sum,kq:longint;

procedure openfile;
begin
   assign(fi,finp);
   reset(fi);
   assign(fo,fout);
   rewrite(fo);
end;

procedure closefile;
begin
   close(fi);
   close(fo);
end;

procedure enter;
begin
   readln(fi,n);
end;

procedure slcs(x:longint);
begin
   m:=0;
   while x>0 do
   begin
      inc(m); a[m]:=x mod 10;
      x:=x div 10;
   end;
end;

function mu(x,k:longint):longint;
var t:int64;
begin
   if (k=1) then exit(x);
   t:=mu(x,k div 2);
   t:=t*t mod base;
   if odd(k) then t:=t*x mod base;
   exit(t);
end;

procedure prepare;
var i,j,k,dem,x,y:longint;
begin
   f[1,0]:=7;
   f[1,1]:=2;
   f[0,0]:=1;
   slcs(n);
   for i:=2 to m do
   for j:=0 to i do
   begin
      x:=int64(f[i-1,j-1])*2;
      y:=int64(8)*f[i-1,j];
      f[i,j]:=x+y;
      n:=n;
   end;
   for i:=1 to m-1 do
   for j:=0 to i do s[j]:=s[j]+f[i,j];
   dem:=0;
   for i:=m downto 1 do
   begin
      for j:=1 to a[i]-1 do
      if (j=4) or (j=7) then
      begin
         for k:=dem+1 to 9 do s[k]:=s[k]+f[m-i,k-dem-1];
      end else
      begin
         for k:=dem to 9 do s[k]:=s[k]+f[m-i,k-dem];
      end;
      if (a[i]=4) or (a[i]=7) then inc(dem);
   end;
   inc(s[dem]);
   gt[0]:=1;  val[0]:=1;
   for i:=1 to 6 do gt[i]:=int64(gt[i-1])*i mod base;
   for i:=1 to 6 do val[i]:=mu(gt[i],base-2);
end;

function c(n,k:longint):longint;
var i,s:longint;
begin
   s:=1;
   for i:=n-k+1 to n do s:=int64(s)*i mod base;
   s:=int64(s)*val[k] mod base;
   exit(s);
end;

procedure update(x:longint);
var i,j:longint;
begin
   j:=0;
   for i:=0 to x-1 do j:=j+a[i];
   if (j<>6) then exit;
   if (j-a[0]>=x) then exit;
   j:=1;
   for i:=0 to x-1 do j:=int64(j)*c(s[i],a[i]) mod base;
   j:=int64(j)*gt[6] mod base;
   sum:=(sum+j) mod base
end;

procedure trying(i,x:longint);
var j,k:longint;
begin
   if (i>x-1) then
   begin
      update(x);
      exit;
   end;
   if i=0 then k:=6 else k:=x-1;
   for j:=0 to k do
   begin
      a[i]:=j;
      trying(i+1,x);
      a[i]:=0;
   end;
end;

procedure lam(x:longint);
var i,j,k:longint;
begin
  sum:=0;
  trying(0,x);
  kq:=(kq+int64(s[x])*sum mod base) mod base
end;

procedure process;
var i:longint;
begin
   for i:=1 to m do
   if s[i]>0 then lam(i);
   writeln(kq);
end;

BEGIN
   openfile;
   enter;
   prepare;
   process;
   closefile;
END.

const
   finp='';//258B.inp';
   fout='';//258B.out';
   base=1000000007;

var
   fi,fo:text;
   f:array[0..10,-1..10] of int64;
   a,s,gt,val:array[0..10] of longint;
   m,n,sum,kq:longint;

procedure openfile;
begin
   assign(fi,finp);
   reset(fi);
   assign(fo,fout);
   rewrite(fo);
end;

procedure closefile;
begin
   close(fi);
   close(fo);
end;

procedure enter;
begin
   readln(fi,n);
end;

procedure slcs(x:longint);
begin
   m:=0;
   while x>0 do
   begin
      inc(m); a[m]:=x mod 10;
      x:=x div 10;
   end;
end;

function mu(x,k:longint):longint;
var t:int64;
begin
   if (k=1) then exit(x);
   t:=mu(x,k div 2);
   t:=t*t mod base;
   if odd(k) then t:=t*x mod base;
   exit(t);
end;

procedure prepare;
var i,j,k,dem,x,y:longint;
begin
   f[1,0]:=7;
   f[1,1]:=2;
   f[0,0]:=1;
   slcs(n);
   for i:=2 to m-1 do
   for j:=0 to i do
   begin
      x:=int64(f[i-1,j-1])*2;
      y:=int64(8)*f[i-1,j];
      f[i,j]:=x+y;
      n:=n;
   end;
   for i:=1 to m-1 do
   for j:=0 to i do s[j]:=s[j]+f[i,j];
   dem:=0; f[1,0]:=8;
   for i:=m downto 1 do
   begin
      if i=m then x:=1 else x:=0;
      for j:=x to a[i]-1 do
      if (j=4) or (j=7) then
      begin
         for k:=dem+1 to 9 do s[k]:=s[k]+f[i-1,k-dem-1];
      end else
      begin
         for k:=dem to 9 do s[k]:=s[k]+f[i-1,k-dem];
      end;
      if (a[i]=4) or (a[i]=7) then inc(dem);
   end;
   inc(s[dem]);
   gt[0]:=1;  val[0]:=1;
   for i:=1 to 6 do gt[i]:=int64(gt[i-1])*i mod base;
   for i:=1 to 6 do val[i]:=mu(gt[i],base-2);
end;

function c(n,k:longint):longint;
var i,s:longint;
begin
   s:=1;
   for i:=n-k+1 to n do s:=int64(s)*i mod base;
   s:=int64(s)*val[k] mod base;
   exit(s);
end;

procedure update(x:longint);
var i,j:longint;
begin
   j:=0;
   for i:=0 to x-1 do j:=j+a[i];
   if (j<>6) then exit;
   if (j-a[0]>=x) then exit;
   j:=1;
   for i:=0 to x-1 do j:=int64(j)*c(s[i],a[i]) mod base;
   j:=int64(j)*gt[6] mod base;
   sum:=(sum+j) mod base;
end;

procedure trying(i,x,k:longint);
var j:longint;
begin
   if (i>x-1) then
   begin
      update(x);
      exit;
   end;
   //if i=0 then k:=6 else k:=x-1;
   for j:=0 to k do
   begin
      a[i]:=j;
      trying(i+1,x,k-j);
      a[i]:=0;
   end;
end;

procedure lam(x:longint);
var i,j,k:longint;
begin
  sum:=0;
  trying(0,x,6);
  kq:=(kq+int64(s[x])*sum mod base) mod base
end;

procedure process;
var i:longint;
begin
   for i:=1 to m do
   if s[i]>0 then lam(i);
   writeln(kq);
end;

procedure check;
var i,j,dem:longint;
begin
   for i:=0 to m do write(s[i],' '); writeln;
   fillchar(s,sizeof(s),0);
   for i:=1 to n do
   begin
      j:=i; dem:=0;
      while j>0 do
      begin
         if (j mod 10=4) or (j mod 10=7) then inc(dem);
         j:=j div 10;
      end;
      inc(s[dem]);
      //if dem=0 then writeln('g','  ',i);
   end;
   for i:=0 to m do write(s[i],' '); writeln;
end;

BEGIN
   openfile;
   enter;
   prepare;
   process;
   //check;
   closefile;
END.

const
   finp='';//258B.inp';
   fout='';//258B.out';
   base=1000000007;

var
   fi,fo:text;
   f:array[0..10,-1..10] of int64;
   a,s,gt,val:array[0..10] of longint;
   m,n,sum,kq:longint;

procedure openfile;
begin
   assign(fi,finp);
   reset(fi);
   assign(fo,fout);
   rewrite(fo);
end;

procedure closefile;
begin
   close(fi);
   close(fo);
end;

procedure enter;
begin
   readln(fi,n);
end;

procedure slcs(x:longint);
begin
   m:=0;
   while x>0 do
   begin
      inc(m); a[m]:=x mod 10;
      x:=x div 10;
   end;
end;

function mu(x,k:longint):longint;
var t:int64;
begin
   if (k=1) then exit(x);
   t:=mu(x,k div 2);
   t:=t*t mod base;
   if odd(k) then t:=t*x mod base;
   exit(t);
end;

procedure prepare;
var i,j,k,t,dem,x,y:longint;
begin
   f[1,0]:=7;
   f[1,1]:=2;
   f[0,0]:=1;
   slcs(n);
   for i:=2 to m-1 do
   for j:=0 to i do
   begin
      x:=int64(f[i-1,j-1])*2;
      y:=int64(8)*f[i-1,j];
      f[i,j]:=x+y;
      n:=n;
   end;
   for i:=1 to m-1 do
   for j:=0 to i do s[j]:=s[j]+f[i,j];
   dem:=0;
   for i:=m downto 1 do
   begin
      if i=m then x:=1 else x:=0;
      for j:=x to a[i]-1 do
      if (j=4) or (j=7) then
      begin
         for k:=dem+1 to 9 do
         for t:=0 to i-1 do s[k]:=s[k]+f[t,k-dem-1];
      end else
      begin
         for k:=dem to 9 do //s[k]:=s[k]+f[i-1,k-dem];
         for t:=0 to i-1 do s[k]:=s[k]+f[t,k-dem];
      end;
      if (a[i]=4) or (a[i]=7) then inc(dem);
   end;
   inc(s[dem]);
   gt[0]:=1;  val[0]:=1;
   for i:=1 to 6 do gt[i]:=int64(gt[i-1])*i mod base;
   for i:=1 to 6 do val[i]:=mu(gt[i],base-2);
end;

function c(n,k:longint):longint;
var i,s:longint;
begin
   s:=1;
   for i:=n-k+1 to n do s:=int64(s)*i mod base;
   s:=int64(s)*val[k] mod base;
   exit(s);
end;

procedure update(x:longint);
var i,j:longint;
begin
   j:=0;
   for i:=0 to x-1 do j:=j+a[i];
   if (j<>6) then exit;
   if (j-a[0]>=x) then exit;
   j:=1;
   for i:=0 to x-1 do j:=int64(j)*c(s[i],a[i]) mod base;
   j:=int64(j)*gt[6] mod base;
   sum:=(sum+j) mod base;
end;

procedure trying(i,x,k:longint);
var j:longint;
begin
   if (i>x-1) then
   begin
      update(x);
      exit;
   end;
   //if i=0 then k:=6 else k:=x-1;
   for j:=0 to k do
   begin
      a[i]:=j;
      trying(i+1,x,k-j);
      a[i]:=0;
   end;
end;

procedure lam(x:longint);
var i,j,k:longint;
begin
  sum:=0;
  trying(0,x,6);
  kq:=(kq+int64(s[x])*sum mod base) mod base
end;

procedure process;
var i:longint;
begin
   for i:=1 to m do
   if s[i]>0 then lam(i);
   writeln(kq);
end;

procedure check;
var i,j,dem:longint;
begin
   for i:=0 to m do write(s[i],' '); writeln;
   fillchar(s,sizeof(s),0);
   for i:=1 to n do
   begin
      j:=i; dem:=0;
      while j>0 do
      begin
         if (j mod 10=4) or (j mod 10=7) then inc(dem);
         j:=j div 10;
      end;
      inc(s[dem]);
      //if dem=0 then writeln('g','  ',i);
   end;
   for i:=0 to m do write(s[i],' '); writeln;
end;

BEGIN
   openfile;
   enter;
   prepare;
   process;
   //check;
   closefile;
END.

const md:int64=1000000007;

var s:string;
    p:integer;
    ans,t:int64;
    i,j,k,l,n,x,y,i1,i2,i3,i4,i5,i6:longint;
    a,u,w:array[0..21] of int64;
    v,f:array[0..21,0..21,0..21] of int64;

function tt(x:int64):int64;
var s:int64;
    i:longint;
 begin
  s:=1;
  for i:=x-5 to x do
   s:=s*int64(i) mod md;
  tt:=s;
 end;

 begin
  read(n);
  str(n,s);
  l:=length(s);
  for i:=1 to l do
   val(s[i],a[i],p);

  v[0,1,0]:=1;
  for i:=1 to l do
   for j:=0 to 1 do
    for k:=0 to l do
     begin
      if v[i-1,j,k]=0 then continue;

      if j=0 then x:=9
             else x:=a[i];

      for y:=0 to x do
       begin
        if (y=0) and (i=1) then continue;

        if (y=4) or
           (y=7) then t:=k+1
                 else t:=k;

        if (j=0) or
          ((j=1) and (y<x)) then v[i,0,t]:=(v[i,0,t]+v[i-1,j,k]) mod md
                            else v[i,1,t]:=(v[i,1,t]+v[i-1,j,k]) mod md;

       end;

     end;

  for i:=0 to l do
   w[i]:=w[i]+v[l,0,i]+v[l,1,i];

  f[0,0,0]:=1;
  for i:=1 to l do
   for j:=0 to l do
    for x:=0 to 9 do
     begin
      for y:=0 to 9 do
       begin
        if (y=4) or
           (y=7) then t:=j+1
                 else t:=j;

        f[i,t,y]:=(f[i,t,y]+f[i-1,j,x]) mod md;
       end;

     end;

  for i:=1 to l-1 do
   for j:=0 to l-1 do
    for x:=1 to 9 do
     w[j]:=(w[j]+f[i,j,x]);

  for i1:=0 to l do
   for i2:=0 to l do
    for i3:=0 to l do
     for i4:=0 to l do
      for i5:=0 to l do
       for i6:=0 to l do
        begin
         if (i1+i2+i3+i4+i5+i6>l) then continue;

         u[i1+i2+i3+i4+i5+i6]:=w[i1];
         if (i1<>i2) then inc(u[i1+i2+i3+i4+i5+i6],w[i2]);
         if (i1<>i3) and
            (i2<>i3) then inc(u[i1+i2+i3+i4+i5+i6],w[i3]);
         if (i1<>i4) and
            (i2<>i4) and
            (i3<>i4) then inc(u[i1+i2+i3+i4+i5+i6],w[i4]);
         if (i1<>i5) and
            (i2<>i5) and
            (i3<>i5) and
            (i4<>i5) then inc(u[i1+i2+i3+i4+i5+i6],w[i5]);

         if (i1<>i6) and
            (i2<>i6) and
            (i3<>i6) and
            (i4<>i6) and
            (i5<>i6) then inc(u[i1+i2+i3+i4+i5+i6],w[i6]);

        end;

  ans:=0;
  for i:=1 to l do
   begin
    t:=w[i];
    for k:=0 to j-1 do
     ans:=(ans+t*tt(u[k])) mod md;
   end;

  writeln(ans);
 end.

const md:int64=1000000007;

var s:string;
    p:integer;
    ans,t:int64;
    i,j,k,l,n,x,y:longint;
    a,w:array[0..21] of int64;
    lw:array[0..21] of boolean;
    v,f:array[0..21,0..21,0..21] of int64;

function tt(x:int64):int64;
var s:int64;
    i:longint;
 begin
  s:=1;
  for i:=x-5 to x do
   s:=s*int64(i) mod md;
  tt:=s;
 end;

 begin
  read(n);
  str(n,s);
  l:=length(s);
  for i:=1 to l do
   val(s[i],a[i],p);

  v[0,1,0]:=1;
  for i:=1 to l do
   for j:=0 to 1 do
    for k:=0 to l do
     begin
      if v[i-1,j,k]=0 then continue;

      if j=0 then x:=9
             else x:=a[i];

      for y:=0 to x do
       begin

        if (y=4) or
           (y=7) then t:=k+1
                 else t:=k;

        if (j=0) or
          ((j=1) and (y<x)) then v[i,0,t]:=(v[i,0,t]+v[i-1,j,k]) mod md
                            else v[i,1,t]:=(v[i,1,t]+v[i-1,j,k]) mod md;

       end;

     end;

  for i:=0 to l do
   w[i]:=w[i]+v[l,0,i]+v[l,1,i];

  f[0,0,0]:=1;
  for i:=1 to l do
   for j:=0 to l do
    for x:=0 to 9 do
     begin
      for y:=0 to 9 do
       begin
        if (y=4) or
           (y=7) then t:=j+1
                 else t:=j;

        f[i,t,y]:=(f[i,t,y]+f[i-1,j,x]) mod md;
       end;

     end;

  for i:=1 to l-1 do
   for j:=0 to l-1 do
    for x:=1 to 9 do
     w[j]:=(w[j]+f[i,j,x]);

  ans:=0;
  for i:=1 to l do
   begin
    t:=w[i];
    for k:=0 to j-1 do
     ans:=(ans+t*tt(w[k]-1)) mod md;
   end;

  writeln(ans);
 end.

const md:int64=1000000007;

var s:string;
    p:integer;
    ans,t:int64;
    i,j,k,l,n,x,y,i1,i2,i3,i4,i5,i6:longint;
    a,u,w:array[0..21] of int64;
    v,f:array[0..21,0..21,0..21] of int64;

function tt(x:int64):int64;
var s:int64;
    i:longint;
 begin
  s:=1;
  for i:=x-5 to x do
   s:=s*int64(i) mod md;
  tt:=s;
 end;

 begin
  read(n);
  str(n,s);
  l:=length(s);
  for i:=1 to l do
   val(s[i],a[i],p);

  v[0,1,0]:=1;
  for i:=1 to l do
   for j:=0 to 1 do
    for k:=0 to l do
     begin
      if v[i-1,j,k]=0 then continue;

      if j=0 then x:=9
             else x:=a[i];

      for y:=0 to x do
       begin
        if (y=0) and (i=1) then continue;

        if (y=4) or
           (y=7) then t:=k+1
                 else t:=k;

        if (j=0) or
          ((j=1) and (y<x)) then v[i,0,t]:=(v[i,0,t]+v[i-1,j,k]) mod md
                            else v[i,1,t]:=(v[i,1,t]+v[i-1,j,k]) mod md;

       end;

     end;

  for i:=0 to l do
   w[i]:=w[i]+v[l,0,i]+v[l,1,i];

  f[0,0,0]:=1;
  for i:=1 to l do
   for j:=0 to l do
    for x:=0 to 9 do
     begin
      for y:=0 to 9 do
       begin
        if (y=4) or
           (y=7) then t:=j+1
                 else t:=j;

        f[i,t,y]:=(f[i,t,y]+f[i-1,j,x]) mod md;
       end;

     end;

  for i:=1 to l-1 do
   for j:=0 to l-1 do
    for x:=1 to 9 do
     w[j]:=(w[j]+f[i,j,x]);

  for i1:=0 to l do
   for i2:=0 to l do
    for i3:=0 to l do
     for i4:=0 to l do
      for i5:=0 to l do
       for i6:=0 to l do
        begin
         if (i1+i2+i3+i4+i5+i6>l) then continue;

         t:=0;
         if (i1=i1) then inc(t);
         if (i1=i2) then inc(t);
         if (i1=i3) then inc(t);
         if (i1=i4) then inc(t);
         if (i1=i5) then inc(t);
         if (i1=i6) then inc(t);
         if t>w[i1] then continue;

         t:=0;
         if (i2=i1) then inc(t);
         if (i2=i2) then inc(t);
         if (i2=i3) then inc(t);
         if (i2=i4) then inc(t);
         if (i2=i5) then inc(t);
         if (i2=i6) then inc(t);
         if t>w[i2] then continue;

         t:=0;
         if (i3=i1) then inc(t);
         if (i3=i2) then inc(t);
         if (i3=i3) then inc(t);
         if (i3=i4) then inc(t);
         if (i3=i5) then inc(t);
         if (i3=i6) then inc(t);
         if t>w[i3] then continue;

         t:=0;
         if (i4=i1) then inc(t);
         if (i4=i2) then inc(t);
         if (i4=i3) then inc(t);
         if (i4=i4) then inc(t);
         if (i4=i5) then inc(t);
         if (i4=i6) then inc(t);
         if t>w[i4] then continue;

         t:=0;
         if (i5=i1) then inc(t);
         if (i5=i2) then inc(t);
         if (i5=i3) then inc(t);
         if (i5=i4) then inc(t);
         if (i5=i5) then inc(t);
         if (i5=i6) then inc(t);
         if t>w[i5] then continue;

         t:=0;
         if (i6=i1) then inc(t);
         if (i6=i2) then inc(t);
         if (i6=i3) then inc(t);
         if (i6=i4) then inc(t);
         if (i6=i5) then inc(t);
         if (i6=i6) then inc(t);
         if t>w[i6] then continue;

         u[i1+i2+i3+i4+i5+i6]:=w[i1];

         if (i1<>i2) then inc(u[i1+i2+i3+i4+i5+i6],w[i2]);

         if (i1<>i3) and
            (i2<>i3) then inc(u[i1+i2+i3+i4+i5+i6],w[i3]);

         if (i1<>i4) and
            (i2<>i4) and
            (i3<>i4) then inc(u[i1+i2+i3+i4+i5+i6],w[i4]);

         if (i1<>i5) and
            (i2<>i5) and
            (i3<>i5) and
            (i4<>i5) then inc(u[i1+i2+i3+i4+i5+i6],w[i5]);

         if (i1<>i6) and
            (i2<>i6) and
            (i3<>i6) and
            (i4<>i6) and
            (i5<>i6) then inc(u[i1+i2+i3+i4+i5+i6],w[i6]);

        end;

  ans:=0;
  for i:=1 to l do
   begin
    t:=w[i];
    for k:=0 to j-1 do
     ans:=(ans+t*tt(u[k])) mod md;
   end;

  writeln(ans);
 end.

{$apptype console}
{$b-}
{$maxstacksize 1000000}
const md=1000000007;
var
  a:array[0..10,0..10] of int64;
  b:array[1..7,0..10] of int64;
  cnk:array[0..10,-11..10] of int64;
  cc:array[0..10] of byte;
  ct,st,error,c,m,k,add,i,j:integer;
  add1,cur,ans:int64;
  s:string;

  Procedure gen(k,r:byte);
  var
   i,j:integer;
  begin
    inc(ct);
    if k>6 then
    begin
      add1:=cur;
     // for i := 0 to 10 do write(cc[i],'! ');
     // writeln;
      for i := 0 to 10 do if (cc[i]>0) then
          add1:=add1*cnk[i,cc[i]-1];
       ans:=(ans+add1) mod md;
    end else
    begin
      for j := 0 to r do
        begin
          inc(cc[j]);
          gen(k+1,r-j);
          dec(cc[j]);
        end;
    end;
  end;

begin
// reset(input,'input.txt');
// rewrite(output,'output.txt');
 Fillchar(a,sizeof(a),0);
 a[1,1]:=2;
 a[1,0]:=7;
 for i := 2 to 10 do
  for j :=0  to i do
   for k := 0 to 9  do
   begin
     if (k=4) or (k=7) then add:=1 else add:=0;
     a[i,j]:=a[i,j]+a[i-1,j-add];
   end;
   readln(m);
   str(m,s);
   Fillchar(b,sizeof(b),0);
   for i := 0 to 10 do
     for j := 0 to length(s)-1 do
      b[1,i]:=(b[1,i]+a[j,i]) mod md;
 Fillchar(a,sizeof(a),0);

 a[1,1]:=2;
 a[1,0]:=8;
 a[0,0]:=1;
 for i := 2 to 10 do
  for j :=0  to i do
   for k := 0 to 9  do
   begin
     if (k=4) or (k=7) then add:=1 else add:=0;
     a[i,j]:=a[i,j]+a[i-1,j-add];
   end;

  add:=0;
  for i := 1 to length(s) do
  begin
    val(s[i],c,error);
    if (i=1) then st:=1 else st:=0;
    for j := st to c-1 do
    begin
     if (j=4) or (j=7) then inc(add);
     for k := add to length(s) do b[1,k]:=(b[1,k]+a[length(s)-i,k-add]) mod md;
     if (j=4) or (j=7) then dec(add);
    end;
    if (c=4) or (c=7) then inc(add);
    if (i=length(s)) then b[1,add]:=(b[1,add]+1) mod md;
  end;
  ans:=0;
  Fillchar(cc,sizeof(cc),0);
  Fillchar(cnk,sizeof(cnk),0);
  for i := 0 to 10 do cnk[i,0]:=b[1,i];
    for i := 0 to 10 do
      for j := 1 to 10 do cnk[i,j]:=(cnk[i,j-1]*(b[1,i]-j)) mod md;

  {  for j :=0 to 10 do write(b[1,j],' ');
   writeln;
   writeln;

    for i := 0 to 10 do
      begin
        for j := 0 to 10 do write(cnk[i][j],' ');
        writeln;
      end;  }

  for i := 1 to length(s) do
  begin
    cur:=b[1,i];
    gen(1,i-1);
  end;
  writeln(ans);
end.

{$apptype console}
{$b-}
{$maxstacksize 1000000}
const md=1000000007;
var
  a:array[0..10,0..10] of int64;
  b:array[1..7,0..10] of int64;
  cnk:array[0..10,-11..10] of int64;
  cc:array[0..10] of byte;
  ct,st,error,c,m,k,add,i,j:integer;
  add1,cur,ans:int64;
  s:string;

  Procedure gen(k,r:byte);
  var
   i,j:integer;
  begin
    inc(ct);
    if k>6 then
    begin
      add1:=cur;
      for i := 0 to 10 do if (cc[i]>0) then
          add1:=add1*cnk[i,cc[i]-1];
       ans:=(ans+add1) mod md;
    end else
    begin
      for j := 0 to r do
        begin
          inc(cc[j]);
          gen(k+1,r-j);
          dec(cc[r]);
        end;
    end;
  end;

begin
 //reset(input,'input.txt');
 //rewrite(output,'output.txt');
 Fillchar(a,sizeof(a),0);
 a[1,1]:=2;
 a[1,0]:=7;
 for i := 2 to 10 do
  for j :=0  to i do
   for k := 0 to 9  do
   begin
     if (k=4) or (k=7) then add:=1 else add:=0;
     a[i,j]:=a[i,j]+a[i-1,j-add];
   end;
   readln(m);
   str(m,s);
   Fillchar(b,sizeof(b),0);
   for i := 0 to 10 do
     for j := 0 to length(s)-1 do
      b[1,i]:=(b[1,i]+a[j,i]) mod md;
 Fillchar(a,sizeof(a),0);

 a[1,1]:=2;
 a[1,0]:=8;
 a[0,0]:=1;
 for i := 2 to 10 do
  for j :=0  to i do
   for k := 0 to 9  do
   begin
     if (k=4) or (k=7) then add:=1 else add:=0;
     a[i,j]:=a[i,j]+a[i-1,j-add];
   end;

  add:=0;
  for i := 1 to length(s) do
  begin
    val(s[i],c,error);
    if (i=1) then st:=1 else st:=0;
    for j := st to c-1 do
    begin
     if (j=4) or (j=7) then inc(add);
     for k := add to length(s) do b[1,k]:=(b[1,k]+a[length(s)-i,k-add]) mod md;
     if (j=4) or (j=7) then dec(add);
    end;
    if (c=4) or (c=7) then inc(add);
    if (i=length(s)) then b[1,add]:=(b[1,add]+1) mod md;
  end;
  ans:=0;
  Fillchar(cc,sizeof(cc),0);
  Fillchar(cnk,sizeof(cnk),0);
  for i := 0 to 10 do cnk[i,0]:=b[1,i];
    for i := 0 to 10 do
      for j := 1 to 10 do cnk[i,j]:=(cnk[i,j-1]*(b[1,i]-j)) mod md;

  for i := 1 to length(s) do
  begin
    cur:=b[1,i];
    gen(1,i-1);
  end;
  writeln(ans);
end.

{$R+,Q+,I+]
{$apptype console}
{$maxstacksize 10000000}
Uses SysUtils;
Var
   i,j,k,n:Integer;
   m,md,f,t,ans,y,r,k1:Int64;
   g,p,h,w,l,a:Array[0..300000] of Int64;
   dp:Array[0..10,-10..10,0..2] of Int64;
Procedure Solve(i,sum:Integer);
Var
   j,i1:Integer;
   r,pr:Int64;
Begin
   If sum>=y Then Exit;
   If i>6 Then Begin
      For j:=0 To y-1 Do h[j]:=0;
      For j:=1 To 6 Do h[w[j]]:=h[w[j]]+1;
      pr:=1;
      For i1:=0 To y-1 Do Begin
         r:=0;
         For j:=1 To h[i1] Do Begin
            pr:=(pr*(p[i1]-r)) mod md;
            r:=r+1;
         End;
         l[sum]:=(l[sum]+pr) mod md;
      End;
      Exit;
   End;
   For j:=0 To y-1 Do Begin
      w[i]:=j;
      Solve(i+1,sum+j);
   End;
End;
Procedure Get(x:Int64);
Begin
   If x>m Then Exit;
   n:=n+1;
   a[n]:=x;
   Get(10*x+4);
   Get(10*x+7);
End;
Begin
   Read(m);
   md:=1000000007;
   t:=m;
   i:=0;
   While t>0 Do Begin
      i:=i+1;
      t:=t div 10;
   End;
   y:=i;
   t:=m;
   i:=y;
   While t>0 Do Begin
      g[i]:=t mod 10;
      i:=i-1;
      t:=t div 10;
   End;
   If g[1]<>1 Then dp[1,0,0]:=1
              Else dp[1,0,1]:=1;
   For i:=2 To 9 Do Begin
      f:=0;
      If i=g[1] Then f:=1;
      If i<=g[1] Then Begin
         If (i<>4) and (i<>7) Then dp[1,0,f]:=dp[1,0,f]+1
                              Else dp[1,1,f]:=dp[1,1,f]+1;
      End;
      If i>g[1] Then Begin
         If (i<>4) and (i<>7) Then dp[1,0,2]:=dp[1,0,2]+1
                              Else dp[1,1,2]:=dp[1,1,2]+1;
      End;
   End;
   For i:=2 To y Do
      For j:=0 To y Do Begin
         dp[i,j,0]:=dp[i-1,j,0];
         If g[i]<>0 Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,1];
         dp[i,j,2]:=dp[i-1,j,2];
         If g[i]=0 Then dp[i,j,1]:=dp[i-1,j,1];
         For k:=1 To 9 Do Begin
            If (k<>4) and (k<>7) Then Begin
               dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,0];
               If k<g[i] Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,1];
               dp[i,j,2]:=dp[i,j,2]+dp[i-1,j,2];
               If k>g[i] Then dp[i,j,2]:=dp[i,j,2]+dp[i-1,j,1];
            End
            Else Begin
               dp[i,j,0]:=dp[i,j,0]+dp[i-1,j-1,0];
               If k<g[i] Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j-1,1];
               dp[i,j,2]:=dp[i,j,2]+dp[i-1,j-1,2];
               If k>g[i] Then dp[i,j,2]:=dp[i,j,2]+dp[i-1,j-1,1];
            End;
            If k=g[i] Then Begin
               If (k<>4) and (k<>7) Then dp[i,j,1]:=dp[i-1,j,1]
                                    Else dp[i,j,1]:=dp[i-1,j-1,1];
            End;
         End;
      End;
   For j:=0 To y Do
      For k:=1 To y Do
         If k<>y Then p[j]:=p[j]+dp[k,j,0]+dp[k,j,1]+dp[k,j,2]
                 Else p[j]:=p[j]+dp[k,j,0]+dp[k,j,1];
   ans:=0;
   Solve(1,0);
   n:=0;
   Get(4);
   Get(7);
   k1:=0;
   For i:=1 To 20 Do Begin
      t:=i;
      r:=0;
      While t>0 Do Begin
         If (t mod 10=4) or (t mod 10=7) Then r:=r+1;
         t:=t div 10;
      End;
      If r=1 Then k1:=k1+1;
   End;
   For i:=1 To n Do Begin
      t:=a[i];
      r:=0;
      While t>0 Do Begin
         If (t mod 10=4) or (t mod 10=7) Then r:=r+1;
         t:=t div 10;
      End;
      For j:=0 To r-1 Do ans:=(ans+l[j]) mod md;
   End;
   Write(ans);
End.

{$R+,Q+,I+]
{$apptype console}
{$maxstacksize 10000000}
Uses SysUtils;
Var
   i,j,k,n:Integer;
   m,md,f,t,ans,y,r:Int64;
   g,p,h,w,l,a:Array[0..300000] of Int64;
   dp:Array[0..10,-10..10,0..1] of Int64;
Procedure Solve(i,sum:Integer);
Var
   j,i1:Integer;
   r,pr:Int64;
Begin
   If sum>=y Then Exit;
   If i>6 Then Begin
      For j:=0 To y-1 Do h[j]:=0;
      For j:=1 To 6 Do h[w[j]]:=h[w[j]]+1;
      pr:=1;
      For i1:=0 To y-1 Do Begin
         r:=0;
         For j:=1 To h[i1] Do Begin
            pr:=(pr*(p[i1]-r)) mod md;
            r:=r+1;
         End;
         l[sum]:=(l[sum]+pr) mod md;
      End;
      Exit;
   End;
   For j:=0 To y-1 Do Begin
      w[i]:=j;
      Solve(i+1,sum+j);
   End;
End;
Procedure Get(x:Int64);
Begin
   If x>m Then Exit;
   n:=n+1;
   a[n]:=x;
   Get(10*x+4);
   Get(10*x+7);
End;
Begin
   Read(m);
   md:=1000000007;
   t:=m;
   i:=0;
   While t>0 Do Begin
      i:=i+1;
      t:=t div 10;
   End;
   y:=i;
   t:=m;
   i:=y;
   While t>0 Do Begin
      g[i]:=t mod 10;
      i:=i-1;
      t:=t div 10;
   End;
   If g[1]<>1 Then dp[1,0,0]:=1
              Else dp[1,0,1]:=1;
   For i:=2 To g[1] Do Begin
      f:=0;
      If i=g[1] Then f:=1;
      If (i<>4) and (i<>7) Then dp[1,0,f]:=dp[1,0,f]+1
                           Else dp[1,1,f]:=dp[1,1,f]+1;
   End;
   For i:=2 To y Do
      For j:=0 To y Do Begin
         dp[i,j,0]:=dp[i-1,j,0];
         If g[i]<>0 Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,1];
         For k:=1 To 9 Do Begin
            If (k<>4) and (k<>7) Then Begin
               dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,0];
               If k<g[i] Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,1]
            End
            Else Begin
               dp[i,j,0]:=dp[i,j,0]+dp[i-1,j-1,0];
               If k<g[i] Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j-1,1];
            End;
            If k=g[i] Then Begin
               If (k<>4) and (k<>7) Then dp[i,j,1]:=dp[i-1,j,1]
                                    Else dp[i,j,1]:=dp[i-1,j-1,1];
            End;
         End;
      End;
   For j:=0 To y Do p[j]:=dp[y,j,0]+dp[y,j,1];
   ans:=0;
   Solve(1,0);
   n:=0;
   Get(4);
   Get(7);
   For i:=1 To n Do Begin
      t:=a[i];
      r:=0;
      While t>0 Do Begin
         If (t mod 10=4) or (t mod 10=7) Then r:=r+1;
         t:=t div 10;
      End;
      For j:=0 To r-1 Do ans:=(ans+l[j]) mod md;
   End;
   Write(ans);
End.

{$R+,Q+,I+]
{$apptype console}
{$maxstacksize 10000000}
Uses SysUtils;
Var
   i,j,k,n:Integer;
   m,md,f,t,ans,y,r,k1:Int64;
   g,p,h,w,l,a:Array[0..300000] of Int64;
   dp:Array[0..10,-10..10,0..2] of Int64;
Procedure Solve(i,sum:Integer);
Var
   j,i1:Integer;
   r,pr:Int64;
Begin
   If sum>=y Then Exit;
   If i>6 Then Begin
      For j:=0 To y-1 Do h[j]:=0;
      For j:=1 To 6 Do h[w[j]]:=h[w[j]]+1;
      pr:=1;
      For i1:=0 To y-1 Do Begin
         r:=0;
         For j:=1 To h[i1] Do Begin
            pr:=(pr*(p[i1]-r)) mod md;
            r:=r+1;
         End;
      End;
      l[sum]:=(l[sum]+pr) mod md;
      Exit;
   End;
   For j:=0 To y-1 Do Begin
      w[i]:=j;
      Solve(i+1,sum+j);
   End;
End;
Procedure Get(x:Int64);
Begin
   If x>m Then Exit;
   n:=n+1;
   a[n]:=x;
   Get(10*x+4);
   Get(10*x+7);
End;
Begin
   Read(m);
   md:=1000000007;
   t:=m;
   i:=0;
   While t>0 Do Begin
      i:=i+1;
      t:=t div 10;
   End;
   y:=i;
   t:=m;
   i:=y;
   While t>0 Do Begin
      g[i]:=t mod 10;
      i:=i-1;
      t:=t div 10;
   End;
   If g[1]<>1 Then dp[1,0,0]:=1
              Else dp[1,0,1]:=1;
   For i:=2 To 9 Do Begin
      f:=0;
      If i=g[1] Then f:=1;
      If i<=g[1] Then Begin
         If (i<>4) and (i<>7) Then dp[1,0,f]:=dp[1,0,f]+1
                              Else dp[1,1,f]:=dp[1,1,f]+1;
      End;
      If i>g[1] Then Begin
         If (i<>4) and (i<>7) Then dp[1,0,2]:=dp[1,0,2]+1
                              Else dp[1,1,2]:=dp[1,1,2]+1;
      End;
   End;
   For i:=2 To y Do
      For j:=0 To y Do Begin
         dp[i,j,0]:=dp[i-1,j,0];
         If g[i]<>0 Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,1];
         dp[i,j,2]:=dp[i-1,j,2];
         If g[i]=0 Then dp[i,j,1]:=dp[i-1,j,1];
         For k:=1 To 9 Do Begin
            If (k<>4) and (k<>7) Then Begin
               dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,0];
               If k<g[i] Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j,1];
               dp[i,j,2]:=dp[i,j,2]+dp[i-1,j,2];
               If k>g[i] Then dp[i,j,2]:=dp[i,j,2]+dp[i-1,j,1];
            End
            Else Begin
               dp[i,j,0]:=dp[i,j,0]+dp[i-1,j-1,0];
               If k<g[i] Then dp[i,j,0]:=dp[i,j,0]+dp[i-1,j-1,1];
               dp[i,j,2]:=dp[i,j,2]+dp[i-1,j-1,2];
               If k>g[i] Then dp[i,j,2]:=dp[i,j,2]+dp[i-1,j-1,1];
            End;
            If k=g[i] Then Begin
               If (k<>4) and (k<>7) Then dp[i,j,1]:=dp[i-1,j,1]
                                    Else dp[i,j,1]:=dp[i-1,j-1,1];
            End;
         End;
      End;
   For j:=0 To y Do
      For k:=1 To y Do
         If k<>y Then p[j]:=p[j]+dp[k,j,0]+dp[k,j,1]+dp[k,j,2]
                 Else p[j]:=p[j]+dp[k,j,0]+dp[k,j,1];
   ans:=0;
   Solve(1,0);
   n:=0;
   Get(4);
   Get(7);
   k1:=0;
   For i:=1 To m Do Begin
      t:=i;
      r:=0;
      While t>0 Do Begin
         If (t mod 10=4) or (t mod 10=7) Then r:=r+1;
         t:=t div 10;
      End;
      If r=4 Then k1:=k1+1;
   End;
   For i:=1 To n Do Begin
      t:=a[i];
      r:=0;
      While t>0 Do Begin
         If (t mod 10=4) or (t mod 10=7) Then r:=r+1;
         t:=t div 10;
      End;
      For j:=0 To r-1 Do ans:=(ans+l[j]) mod md;
   End;
   Write(ans);
End.