module ABC139

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  type coordinate
    real(REAL64), public :: x
    real(REAL64), public :: y
    real(REAL64), public :: distance
  end type coordinate

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_F

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_F

    ! variables for this <subroutine>
    integer(INT32)   :: num_engines
    real(REAL64)     :: x_max, x_read, x_trial
    real(REAL64)     :: y_max, y_read, y_trial
    real(REAL64)     :: distance_max
    real(REAL64)     :: distance_trial

    ! support variables for this <subroutine>
    integer(INT32) :: itr

    ! STEP.01
    ! read out the given data (the number of engines)
    read(unit=INPUT_UNIT, fmt=*) num_engines

    ! STEP.02
    ! initialize the variables for this <subroutine>
    distance_max = 0.0_REAL64
    x_max        = 0.0_REAL64
    y_max        = 0.0_REAL64
    x_trial      = 0.0_REAL64
    y_trial      = 0.0_REAL64

    ! STEP.03
    ! calculate the answer of this task
    do itr = 1, num_engines, 1

      ! read out the given data (the movement by the each engine)
      read(unit=INPUT_UNIT, fmt=*) x_read, y_read

      x_trial        = x_trial + x_read
      y_trial        = y_trial + y_read
      distance_trial = sqrt(x_trial * x_trial + y_trial * y_trial)

      if (distance_trial .gt. distance_max) then
        x_max        = x_trial
        y_max        = y_trial
        distance_max = distance_trial
      end if

    end do

    ! STEP.04
    ! output the answer of this task
    write(unit=OUTPUT_UNIT, fmt='(ES23.15e3)', advance='yes') distance_max

    ! STEP.END
    return

  end subroutine task_F

end module ABC139

program main

  ! <module>s to import
  use, non_intrinsic :: ABC139

  ! require all variables to be explicitly declared
  implicit none

  call task_F

end program main