IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 i          PIC 9(10) VALUE 1 COMP.
01 N          PIC 9(10).
01 num        PIC 9(10) VALUE 4.
01 ans        PIC X(12).
01 zs         PIC Z(9)9.
01 S          PIC X(3).
01 C1.
   03 C11 OCCURS 4 DEPENDING num.
      05 C    PIC 9(10) VALUE 0 COMP.
01 j1         PIC X(12) VALUE "AC WA TLERE".
01 REDEFINES j1.
  03 j        PIC X(3) OCCURS 4 INDEXED BY ix.
01 mul        PIC X(3) VALUE " x ".

PROCEDURE DIVISION.
  ACCEPT N.
  PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
    ACCEPT S
    SET ix TO 1
    PERFORM UNTIL 4 < ix
      SEARCH j VARYING ix
        AT END
          CONTINUE
        WHEN S = j(ix)
          ADD 1 TO C(ix)
          SET ix UP BY 1
      END-SEARCH
    END-PERFORM
  END-PERFORM.
  PERFORM VARYING i FROM 1 BY 1 UNTIL num < i
    MOVE SPACE TO ans
    MOVE C(i) TO zs
    STRING FUNCTION TRIM(j(i)) mul FUNCTION TRIM(zs) INTO ans
    DISPLAY FUNCTION TRIM(ans)
  END-PERFORM.
  STOP RUN.
