IDENTIFICATION DIVISION.
PROGRAM-ID. 0303A.

ENVIRONMENT DIVISION.

DATA DIVISION.
WORKING-STORAGE SECTION.

01 S.
    02 S-O      OCCURS 10000.
        03 SA   PIC X(1) VALUE SPACE.
01 RCNT         PIC 9(5) VALUE ZERO.
01 BCNT         PIC 9(5) VALUE ZERO.
01 LEN          PIC 9(5) VALUE ZERO.
01 ANS          PIC 9(5) VALUE ZERO.
01 O_ANS		PIC ZZZZ9.
01 X_ANS.
    02 X_ANS_O  PIC X(1) OCCURS 5.
01 L_ANS.
    02 L_ANS_O  PIC X(1) OCCURS 5.
01 IDX          PIC 9(5) VALUE ZERO.
01 IDX2         PIC 9(5) VALUE ZERO.      
      
PROCEDURE DIVISION.
    ACCEPT S
    PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > 10000         
        IF SA(IDX) = "0" THEN
            COMPUTE RCNT = RCNT + 1
        ELSE IF SA(IDX) = "1" THEN
            COMPUTE BCNT = BCNT + 1
        ELSE IF SA(IDX) = SPACE THEN
            COMPUTE LEN = IDX - 1
            MOVE 10000 TO IDX
        END-IF
    END-PERFORM
    IF RCNT > BCNT THEN
        COMPUTE ANS = LEN - (RCNT - BCNT)
    ELSE
        COMPUTE ANS = LEN - (BCNT - RCNT)
    END-IF
    MOVE ANS TO X_ANS
    EVALUATE ANS
        WHEN 00000 THRU 00009
            MOVE X_ANS_O(5) TO L_ANS_O(1)
        WHEN 00010 THRU 00099
            MOVE X_ANS_O(4) TO L_ANS_O(1)
            MOVE X_ANS_O(5) TO L_ANS_O(2)
        WHEN 00100 THRU 00999
            MOVE X_ANS_O(3) TO L_ANS_O(1)
            MOVE X_ANS_O(4) TO L_ANS_O(2)
            MOVE X_ANS_O(5) TO L_ANS_O(3)
        WHEN 01000 THRU 09999
            MOVE X_ANS_O(2) TO L_ANS_O(1)
            MOVE X_ANS_O(3) TO L_ANS_O(2)
            MOVE X_ANS_O(4) TO L_ANS_O(3)
            MOVE X_ANS_O(5) TO L_ANS_O(4)
        WHEN 10000
            MOVE X_ANS TO L_ANS
    END-EVALUATE
    DISPLAY L_ANS
    STOP RUN.
