IDENTIFICATION DIVISION.
PROGRAM-ID. A-BEGINNER.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP     PIC X(501).
01 IN-DATA.
   03 DT-X1 PIC X(10).
01 IN-LEN.
   03 DT-L1 PIC 9(2).
01 IN-N     PIC 9(6).
01 IN-TABLE.
   03 I-STR PIC X(10) OCCURS 200000.
   03 I-MAX PIC X(10) OCCURS 200000.
01 W-STR    PIC X(10).
01 I        PIC 9(6).
01 J        PIC 9(6).
01 K        PIC 9(6).
01 L        PIC 9(6).
01 MAX      PIC 9(6).
01 CNT-MAX  PIC 9(6).
 
PROCEDURE DIVISION.
MAIN-001.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO DT-X1 COUNT IN DT-L1.
  MOVE DT-X1(1:DT-L1) TO IN-N.
 
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > IN-N
    ACCEPT I-STR(I)
  END-PERFORM.

  IF (IN-N > 1)
    COMPUTE I = IN-N / 2
    PERFORM UNTIL (I <= 0)
      COMPUTE L = IN-N - I
      MOVE 1 TO K
      PERFORM UNTIL (K > L)
        MOVE K TO J
        PERFORM UNTIL (J <= 0)
          IF (I-STR(J) > I-STR(J + I))
            MOVE I-STR(J)     TO W-STR
            MOVE I-STR(J + I) TO I-STR(J)
            MOVE W-STR        TO I-STR(J + I)
            COMPUTE J = J - I
          ELSE
            MOVE 0 TO J
          END-IF
        END-PERFORM
        ADD 1 TO K
      END-PERFORM
      COMPUTE I = I / 2
    END-PERFORM
  END-IF.

  MOVE 0 TO MAX.
  MOVE 1 TO I.
  PERFORM UNTIL I > IN-N
    PERFORM VARYING J FROM I BY 1 
              UNTIL (J > IN-N) OR (I-STR(J) NOT = I-STR(I))
    END-PERFORM
    IF (J - I > MAX)
      COMPUTE MAX = J - I
      MOVE 1 TO CNT-MAX
      MOVE I-STR(I) TO I-MAX(CNT-MAX)
    ELSE 
      IF (J - I = MAX)
        ADD  1 TO CNT-MAX
        MOVE I-STR(I) TO I-MAX(CNT-MAX)
      END-IF
    END-IF
    MOVE J TO I
  END-PERFORM.

  PERFORM VARYING I FROM 1 BY 1 UNTIL I > CNT-MAX
    DISPLAY I-MAX(I)
  END-PERFORM.

MAIN-EXIT.
  STOP RUN.
