--{-# LANGUAGE OverloadedStrings #-}
--{-# LANGUAGE OverloadedLists   #-}
{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import qualified Data.Vector.Unboxed as V
import Control.Monad
import Control.Monad.State
import Control.Monad.ST
import qualified Data.ByteString.Lazy.Char8 as BS
--import Debug.Trace

type DP s = STUArray s (Bool,Int,Bool,Bool,Bool) Int

modifyArray :: (MArray a e m ,Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray arr i f =  readArray arr i >>= writeArray arr i . f

dp_i :: DP s -> (Int,Int) -> ST s ()
dp_i dparr (i,c) = do
  forM_ [False,True] $ \exist7 ->
    forM_ [False,True] $ \exist5 ->
      forM_ [False,True] $ \exist3 ->
        forM_ [False,True] $ \lower -> if i == 0 && (exist3 || exist5 || exist7 || lower) then return () else do
          a <- readArray dparr (lower,i,exist7,exist5,exist3)
          if a == 0 && i /= 0 then return () else do
            --traceShowM ((lower,i,exist7,exist5,exist3),a)
            let add7T = modifyArray dparr (True,i+1,True,exist5,exist3) (+a)
                add5T = modifyArray dparr (True,i+1,exist7,True,exist3) (+a)
                add3T = modifyArray dparr (True,i+1,exist7,exist5,True) (+a)
                add7F = modifyArray dparr (False,i+1,True,exist5,exist3) (+a)
                add5F = modifyArray dparr (False,i+1,exist7,True,exist3) (+a)
                add3F = modifyArray dparr (False,i+1,exist7,exist5,True) (+a)
                add753T = add7T >> add5T >> add3T
            if lower then add753T
              else if | c > 7  -> add753T
                      | c == 7 -> add7F >> add5T >> add3T
                      | c == 6 -> add5T >> add3T
                      | c == 5 -> add5F >> add3T
                      | c == 4 -> add3T
                      | c == 3 -> add3F
                      | c < 3  -> return ()

solve :: String -> ST s Int
solve n = do
  --添え字　N以下決定,i文字目,7,5,3の存在
  let ln = length n
      ans' k = 3^k - 3*2^k + 3
  dparr <- newArray ((False,0,False,False,False),(True,ln,True,True,True)) 0
  writeArray dparr (False,0,False,False,False) 1
  forM_ (zip [0..ln-1] n) $ \(i,c) -> dp_i dparr (i,(read [c] :: Int))
  ls <- forM [False,True] $ \lower -> readArray dparr (lower,ln,True,True,True)
  --traceShowM ls
  return $ (sum ls) + (sum $ map ans' [3..ln-1])
main :: IO ()
main = do
  s <- getLine
  print $ runST $ solve s

mod' :: Int -> Int
mod' n = if n < 1000000007 then n else mod n 1000000007
