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 X          PIC 9(18).
01 Y          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.
    
  COMPUTE CNT = N / (A + B)
 
  EVALUATE TRUE
    WHEN A = 0 
      MOVE 0 to OUT-CNT
    WHEN B = 0
      MOVE N TO OUT-CNT
    WHEN OTHER
      COMPUTE SUM-A = A * CNT
      COMPUTE SUM-B = B * CNT

      PERFORM UNTIL (N <= SUM-A + SUM-B)
        COMPUTE SUM-A = SUM-A + A
        COMPUTE SUM-B = SUM-B + B
      END-PERFORM

      COMPUTE BK-CNT = SUM-A + SUM-B - N
      IF (BK-CNT <= B)
        MOVE SUM-A TO OUT-CNT 
      ELSE
        COMPUTE OUT-CNT = SUM-A - (BK-CNT - B)
      END-IF
  END-EVALUATE.
      
  DISPLAY OUT-CNT.
 
MAIN-EXIT.
  STOP RUN.
