import Control.Monad
import Control.Monad.State
import Data.Maybe
import qualified Data.Map as Map

main :: IO ()
main = do
  n <- readLn :: IO Integer
  print $ (`evalState` Map.empty) $ do
    forM_ [1..n] $ \i -> do
      let x = show i
          key = (head x, last x)
      res <- gets (Map.lookup key)
      modify $ case res of
        Just value -> Map.insert key (value + 1)
        Nothing -> Map.insert key 1
    
    sum . catMaybes <$> do
      forM [1..n] $ \i -> do
        let x = show i
            key = (last x, head x)
        gets (Map.lookup key)