program infinite_sequence
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8) :: dp(0:1000000) = 0_8, m, s = 1_8
  integer :: n, i
  dp(1) = 1_8
  read(*,*) n
  m = mod(int(n-1,8)*int(n-1,8),md)
  do i = 2, n
    dp(i) = modulo(m+s+int(n-i+2,8)-dp(i-2),md)
    s = mod(s+dp(i),md)
  end do
  write(*,'(i0)') dp(n)
end program infinite_sequence