IDENTIFICATION DIVISION.
PROGRAM-ID. 100C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(2200000).
*>
WORKING-STORAGE SECTION.
01 N          PIC  9(07) COMP.
01 I          PIC  9(06) COMP.
01 W          PIC S9(10) COMP.
01 S          PIC  9(10) COMP.
01 AMR        PIC  9(01) COMP. 
01 P1         PIC  9(7) COMP.
01 P2         PIC  9(7) COMP.
01 TBL1.
   03 A       PIC  9(10) OCCURS 200000 DEPENDING ON N.
01 TBL-SA.
   03 SA      PIC S9(10) OCCURS 200000 DEPENDING ON N.
01 CNT        PIC 9(15) COMP.
01 OUT        PIC Z(14)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.         
  CLOSE STDIO.
*>
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO A(I)
    COMPUTE SA(I) = A(I) - I
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  SORT SA ASCENDING KEY SA.
  DIVIDE N BY 2 GIVING S REMAINDER AMR.
  IF (AMR = 1)
    MOVE SA(S) TO W
  ELSE
    COMPUTE W ROUNDED = (SA(S) + SA(S + 1)) / 2
  END-IF
*>
  MOVE 0 TO CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    COMPUTE S = A(I) - (W + I)
    COMPUTE CNT = CNT + S  
  END-PERFORM.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
