PROGRAM-ID.                      ABC_102_C.
ENVIRONMENT                      DIVISION.
INPUT-OUTPUT                     SECTION.
FILE-CONTROL.
    SELECT SYSIN ASSIGN TO KEYBOARD ORGANIZATION LINE SEQUENTIAL.

DATA                             DIVISION.
FILE                             SECTION.
    FD  SYSIN.
        01 INDATA PIC X(2200000).

WORKING-STORAGE                  SECTION.
    01 N       PIC 9(6).

    01 INP     PIC X(2200000).

    01 maxlen  PIC 9(7).
    01 cur     PIC 9(7) VALUE 1.
    01 i       PIC 9(18) BINARY VALUE 1.
    01 j       PIC 9(18).
    01 len     PIC 9(7).

    01 B1.
        03 B11 OCCURS 2200000 DEPENDING ON maxlen INDEXED BIX.
            05 B PIC S9(11).

    01 x       PIC S9(11).
    01 t       PIC 9(10).
    01 s       PIC 9(15).

    01 tmp     PIC 9(6).

    01 ans     PIC X(15).

    01 ZS      PIC Z(15)9.
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.
    ACCEPT N.

    OPEN INPUT SYSIN.

    READ SYSIN INTO INP.

    CLOSE SYSIN.

    MOVE N TO maxlen.

    PERFORM maxlen TIMES
        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO x

        SUBTRACT i FROM x

        SET BIX TO i

        MOVE x TO B(BIX)

        COMPUTE cur = j + 1

        ADD 1 TO i
    END-PERFORM.

    SORT B11 ON ASCENDING KEY B.

*> 中央 index
    SUBTRACT 1 FROM N GIVING tmp.

    DIVIDE 2 INTO tmp GIVING tmp.

    ADD 1 TO tmp.

    SET BIX TO tmp.

    MOVE B(BIX) TO x.

    MOVE ZERO TO s.

    MOVE 1 TO i.

    PERFORM maxlen TIMES
        SET BIX TO i

        SUBTRACT B(BIX) FROM x GIVING t

        ADD t TO s

        ADD 1 TO i
    END-PERFORM.

    MOVE s TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.
