IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_087_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 i      PIC 9(2).
    01 j      PIC 9(2).
    01 k      PIC 9(2).
    01 A      PIC 9(2).
    01 B      PIC 9(2).
    01 C      PIC 9(2).
    01 X      PIC 9(5).
    01 cnt    PIC 9(5) VALUE 0.
    01 ZS     PIC Z(4)9.
    01 ans    PIC X(4).
    01 val    PIC 9(5).
    01 DUMMY  PIC X(1).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT A.
    ACCEPT B.
    ACCEPT C.
    ACCEPT X.

    PERFORM VARYING i FROM 0 BY 1 UNTIL A < i
        PERFORM VARYING j FROM 0 BY 1 UNTIL B < j
            PERFORM VARYING k FROM 0 BY 1 UNTIL C < k
                COMPUTE val = 500 * i + 100 * j + 50 * k
                IF val = X THEN
                    ADD 1 TO cnt
                END-IF
            END-PERFORM
        END-PERFORM
    END-PERFORM.

    MOVE cnt TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.
