IDENTIFICATION DIVISION.
PROGRAM-ID. 160D.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC  X(15).
01 N          PIC  9(4) COMP.
01 X          PIC  9(4) COMP.
01 Y          PIC  9(4) COMP.
01 I          PIC  9(4) COMP.
01 J          PIC  9(4) COMP.
01 D-TBL.
   03 D       PIC  9(4) COMP OCCURS 2000.
01 D1         PIC  9(4) COMP.
01 D2         PIC  9(4) COMP. 
01 CNT        PIC  9(4) COMP.
01 OUT        PIC  ZZZ9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N X Y. 
*>
  PERFORM VARYING I FROM 2 BY 1 UNTIL I > 2000
    MOVE 0 TO D(I)
  END-PERFORM.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N - 1
    COMPUTE J = I + 1
    PERFORM VARYING J FROM J BY 1 UNTIL J > N
      EVALUATE TRUE
        WHEN (I <= X) AND (J <= X)
        WHEN (I >= Y) AND (J >= Y)
          ADD 1 TO D(J - I)
        WHEN (I <= X) AND (J >= Y)
          ADD 1 TO D(X - I + J - Y + 1)
        WHEN (I >= X) AND (J <= Y)
          COMPUTE D1 = J - I
          COMPUTE D2 = I - X + Y - J + 1
          ADD 1 TO D(FUNCTION MIN(D1, D2))
        WHEN (I <= X) AND (J <= Y)
          COMPUTE D1 = J - I
          COMPUTE D2 = X - I + Y - J + 1
          ADD 1 TO D(FUNCTION MIN(D1, D2))
        WHEN (I >= X) AND (J >= Y)
          COMPUTE D1 = J - I
          COMPUTE D2 = I - X + J - Y + 1
          ADD 1 TO D(FUNCTION MIN(D1, D2))
      END-EVALUATE
    END-PERFORM
  END-PERFORM.  
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I >= N
    MOVE D(I) TO OUT
    DISPLAY FUNCTION TRIM(OUT)
  END-PERFORM.
*>
  STOP RUN.
