IDENTIFICATION DIVISION.
PROGRAM-ID. 160E.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(1100000).
*>
WORKING-STORAGE SECTION.
01 S          PIC  X(100).
01 X          PIC  9(6).
01 Y          PIC  9(6).
01 A          PIC  9(6).
01 B          PIC  9(6).
01 C          PIC  9(6).
01 A-TBL.
   03 PA      PIC  9(10) OCCURS 100000 DEPENDING ON A.
01 B-TBL.
   03 PB      PIC  9(10) OCCURS 100000 DEPENDING ON B.
01 C-TBL.
   03 PC      PIC  9(10) OCCURS 100000 DEPENDING ON C.
01 P1         PIC  9(7) COMP.
01 P2         PIC  9(7) COMP.
01 I          PIC  9(6) COMP.
01 J          PIC  9(6) COMP.
01 K          PIC  9(6) COMP.
01 PX         PIC  9(6).
01 PY         PIC  9(6).
01 CNT        PIC  9(16) COMP.
01 OUT        PIC  Z(15)9.
*> 
PROCEDURE DIVISION.
  ACCEPT S.
  UNSTRING S DELIMITED BY ' '
      INTO X Y A B C.
*>
  OPEN INPUT STDIO.
  READ STDIO.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > A
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO PA(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  READ STDIO.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > B
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO PB(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  READ STDIO.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > C
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO PC(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  CLOSE STDIO.
*>
  SORT PA DESCENDING KEY PA.
  SORT PB DESCENDING KEY PB.
  SORT PC DESCENDING KEY PC.
*>
  MOVE 1 TO I J K.
  MOVE 0 TO PX PY CNT.
  PERFORM UNTIL PX >= X AND PY >= Y
    EVALUATE TRUE
      WHEN PX < X AND PA(I) >= PC(K)
        ADD PA(I) TO CNT
        ADD 1     TO I PX
      WHEN PY < Y AND PB(J) >= PC(K)
        ADD PB(J) TO CNT
        ADD 1     TO J PY
      WHEN PX < X AND PA(I) < PC(K)
        ADD PC(K) TO CNT
        ADD 1     TO K PX
      WHEN PY < Y AND PB(J) < PC(K)
        ADD PC(K) TO CNT
        ADD 1     TO K PY
    END-EVALUATE
  END-PERFORM.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
