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 IDX          PIC 9(5) VALUE ZERO.
      
PROCEDURE DIVISION.
    ACCEPT S
    PERFORM VARYING IDX FROM 0 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 O_ANS
    DISPLAY O_ANS
    STOP RUN.
