IDENTIFICATION DIVISION.
PROGRAM-ID. 131B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP  PIC X(60).
01 N    PIC 9(3).
01 L    PIC S9(3).
01 A    PIC S9(3).
01 AP   PIC 9(3).
01 TL   PIC S9(5).
01 I    PIC 9(3).
01 MIN  PIC 9(3).
01 MIS  PIC S9(3). 
01 OUT  PIC -(5)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N L.
*>
  MOVE 999 TO MIN.
  MOVE 0   TO TL.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    COMPUTE A =  L + I - 1
    MOVE A TO AP
    IF (AP < MIN)
      MOVE AP TO MIN
      MOVE A  TO MIS
    END-IF
*>
    ADD A  TO TL 
  END-PERFORM.
*>
  COMPUTE OUT = TL - MIS.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.
