       IDENTIFICATION DIVISION.
       PROGRAM-ID. AOC-2020-06-1.
       AUTHOR. ANNA KOSIERADZKA.
      
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT INPUTFILE ASSIGN TO "d6.input"
           ORGANIZATION IS LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
         FD INPUTFILE
         RECORD IS VARYING IN SIZE FROM 1 to 99
         DEPENDING ON REC-LEN.
         01 INPUTRECORD PIC X(99).
       WORKING-STORAGE SECTION.
         01 FILE-STATUS PIC 9 VALUE 0.
         01 REC-LEN PIC 9(2) COMP.
         01 WS-GROUP-ANSWERS PIC X OCCURS 26 TIMES.
         01 WS-CHAR PIC X.

       LOCAL-STORAGE SECTION.
         01 I UNSIGNED-INT VALUE 1.
         01 C UNSIGNED-INT VALUE 1.
         01 GROUP-TOTAL UNSIGNED-INT VALUE 0.
         01 TOTAL UNSIGNED-INT VALUE 0.

       PROCEDURE DIVISION.
       001-MAIN.
           PERFORM 004-NEXT-GROUP.
           OPEN INPUT INPUTFILE.
           PERFORM 002-READ UNTIL FILE-STATUS = 1.
           CLOSE INPUTFILE.
           PERFORM 004-NEXT-GROUP.
           DISPLAY TOTAL.
           STOP RUN.

       002-READ.
            READ INPUTFILE
                AT END MOVE 1 TO FILE-STATUS
                NOT AT END PERFORM 003-PROCESS-RECORD
            END-READ.
       
       003-PROCESS-RECORD.
           IF REC-LEN = 0 THEN
              PERFORM 004-NEXT-GROUP
           ELSE 
              PERFORM 005-PROCESS-ROW
           END-IF.
          
       004-NEXT-GROUP.
           ADD GROUP-TOTAL TO TOTAL.
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 26
              MOVE 0 TO WS-GROUP-ANSWERS(I)
           END-PERFORM.
           MOVE 0 TO GROUP-TOTAL.
           
       005-PROCESS-ROW.
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > REC-LEN
              MOVE INPUTRECORD(I:1) TO WS-CHAR
              COMPUTE C = FUNCTION ORD(WS-CHAR)
              IF WS-GROUP-ANSWERS(C - 97) = 0 THEN 
                 MOVE 1 TO WS-GROUP-ANSWERS(C - 97) 
                 ADD 1 TO GROUP-TOTAL
              END-IF 
           END-PERFORM.
