  Program Main

    Implicit None
    Integer*8            :: N, A, B, ball

    N = 0 ; A = 0 ; B = 0 ; ball = 0
    Read(*,*) N,A,B

    Loop:Do 
            N = N - A
            If (N > 0) then
               ball = ball + A
            Else
               ball = ball + N + A
               Exit Loop
            Endif

            N = N - B
            If (N <= 0) Exit Loop

         Enddo Loop
 
    Write(*,"(I0)") ball

  End Program
