program handstand2
  implicit none
  integer :: n, i, a, b
  integer(8) :: c(9,9) = 0, x = 0
  read(*,*) n
  do i = 1, n
    a = mod(i,10)
    if (a == 0) cycle
    b = i
    do while (b >= 10)
      b = b/10
    end do
    c(a,b) = c(a,b)+1
  end do
  do a = 1, 9
    do b = 1, 9
      x = x+c(a,b)*c(b,a)
    end do
  end do
  write(*,'(i0)') x
end program handstand2