IDENTIFICATION DIVISION. PROGRAM-ID. D1. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "INPUT1.TXT" ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD INPUT-FILE. 01 INPUT-LINE. 05 LEFT-NO PIC 9(5). 05 FILLER PIC X(3). 05 RIGHT-NO PIC 9(5). WORKING-STORAGE SECTION. 01 LEFT-NOS OCCURS 1000 INDEXED BY LEFT-IDX. 05 LEFT-NO-ELT PIC 9(5). 01 RIGHT-NOS OCCURS 1000 INDEXED BY RIGHT-IDX. 05 RIGHT-NO-ELT PIC 9(5). 01 IDX PIC 9(5). 01 ANSWER PIC 9(9). 01 EOF PIC X VALUE "N". PROCEDURE DIVISION. OPEN INPUT INPUT-FILE. PERFORM READ-LINE UNTIL EOF = "Y". PERFORM SORT-TABLES. PERFORM PART-1. DISPLAY ANSWER. CLOSE INPUT-FILE. STOP RUN. READ-LINE. READ INPUT-FILE AT END MOVE "Y" TO EOF NOT AT END PERFORM PARSE-LINE END-READ. PARSE-LINE. MOVE LEFT-NO TO LEFT-NOS(LEFT-IDX). MOVE RIGHT-NO TO RIGHT-NOS(RIGHT-IDX). ADD 1 TO LEFT-IDX RIGHT-IDX. SORT-TABLES. SORT LEFT-NOS ON ASCENDING KEY LEFT-NO-ELT. SORT RIGHT-NOS ON ASCENDING KEY RIGHT-NO-ELT. PART-1. PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > 1000 COMPUTE ANSWER = ANSWER + FUNCTION ABS(LEFT-NO-ELT(IDX) - RIGHT-NO-ELT(IDX)) END-PERFORM. DBG-TBLS. PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > 1000 DISPLAY 'LEFT: ' LEFT-NOS(IDX) ', RIGHT: ' RIGHT-NOS(IDX) END-PERFORM.