IDENTIFICATION DIVISION.
PROGRAM-ID. 096C.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 INP     PIC  X(30).
01 A       PIC  9(4) COMP.
01 B       PIC  9(4) COMP.
01 C       PIC  9(4) COMP.
01 X       PIC  9(6) COMP.
01 Y       PIC  9(6) COMP.
01 SA      PIC  9(6) COMP.
01 BIG     PIC  9(4) COMP.
01 MAX     PIC  9(9) COMP.
01 CNT     PIC  9(9) COMP.
01 OUT     PIC  Z(8)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO A B C X Y. 
*>
  COMPUTE MAX = A * X + B * Y.
  IF (X >= Y)
    MOVE A TO BIG
    COMPUTE SA = X - Y
  ELSE
    MOVE B TO BIG
    COMPUTE SA = Y - X
  END-IF
*>
  IF (A + B <= C * 2)
    MOVE MAX TO CNT
  ELSE
    COMPUTE CNT = MAX - (A + B - C * 2) * FUNCTION MIN(X, Y)
  *> 
    IF (BIG > C * 2)
      COMPUTE CNT = CNT - (BIG - C * 2) * SA
    END-IF 
  END-IF. 
*>---
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
