PROGRAM-ID.                      ABC_042_B.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP     PIC X(7).
    01 N       PIC 9(3).
    01 L       PIC 9(3).
    01 S1.
        03 S11 OCCURS 100 DEPENDING ON N.
            05 S PIC X(100).
    01 ans     PIC X(10000).
    01 tmp     PIC X(100).
    01 i       PIC 9(3).
    01 j       PIC 9(3).
    01 st      PIC 9(3).
    01 p       PIC 9(5).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO N L.

    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
        ACCEPT S(i)
    END-PERFORM.

    SORT S11 ON ASCENDING KEY S.

    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
        COMPUTE p = L * (i - 1) + 1

        STRING
            S(i)(1:L)
            INTO ans WITH POINTER p
        END-STRING
    END-PERFORM.

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

    STOP RUN.
