IDENTIFICATION DIVISION.
PROGRAM-ID. 158B.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC X(100).
01 N          PIC 9(19).
01 A          PIC 9(18).
01 B          PIC 9(18).
01 SUM-A      PIC 9(19).
01 SUM-B      PIC 9(19).
01 CNT        PIC 9(18).
01 BK-CNT     PIC 9(19).

01 OUT-CNT    PIC Z(18)9.
 
PROCEDURE DIVISION.
MAIN-001.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO N A B.
    
  EVALUATE TRUE
    WHEN A = 0
      MOVE 0 TO OUT-CNT
    WHEN B = 0
      MOVE N TO OUT-CNT
    WHEN OTHER
      COMPUTE CNT = N / (A + B) 
      EVALUATE TRUE
        WHEN (N - (A + B) * CNT = 0)
          COMPUTE OUT-CNT = A * CNT
        WHEN (N - (A + B) * CNT >= A)
          COMPUTE OUT-CNT = A * CNT + A
        WHEN OTHER
          COMPUTE OUT-CNT = N - B * CNT
      END-EVALUATE
  END-EVALUATE.

  DISPLAY OUT-CNT.
 
MAIN-EXIT.
  STOP RUN.
