program Handstand2

  implicit none

  integer N
  integer a, b
  real logA,logB
  ! integer intLogA, intLogB
  integer a1, a2, b1, b2
  integer :: count = 0
  integer Pa1(10), Pa2(10), Pb1(10), Pb2(10)
  integer i, j
  read *, N
  Pa1 = 0
  Pa2 = 0
  Pb1 =0
  Pb2 = 0
  do a = 1, N
    logA = real(10 ** int(log10(real(a))))
    a1 = a / logA
    a2 = mod(a,10)
    do i = 1, 9
      if ( i == a1 ) then
        Pa1(i) = Pa1(i) + 1
      else
        Pa1(10) = Pa1(10) + 1
      end if
    end do

    do i = 1, 9
      if ( i == a2 ) then
        Pa2(i) = Pa2(i) + 1
      else
        Pa2(10) = Pa2(10) + 1
      end if
    end do
    ! Pa1(a) = a1
    ! Pa2(a) = a2
  end do
  do b = 1, N
    ! logA = log10(real(a))
    ! logB = log10(real(b))
    ! intLogA = 10 ** int(log10(real(a)))
    ! intLogB = 10 ** int(logB)
    logB = real(10 ** int(log10(real(b))))
    b1 = b / logB
    b2 = mod(b,10)
    do i = 1, 9
      if ( i == b1 ) then
        Pb1(i) = Pb1(i) + 1
      else
        Pb1(10) = Pb1(10) + 1
      end if
    end do

    do i = 1, 9
      if ( i == b2 ) then
        Pb2(i) = Pb2(i) + 1
      else
        Pb2(10) = Pb2(10) + 1
      end if
    end do
    ! Pb1(b) = b1
    ! Pb2(b) = b2
  end do

  ! print *, Pa1
  ! print *, Pa2
  ! print *, Pb1
  ! print *, Pb2

do i = 1, 10
  do j = 1, 10
    count = count + Pa1(i) * Pb2(j)
    count = count + Pa2(i) + Pb1(j)
  end do
end do

  print '(i0)', count

end program
