Subtract the count of 0 from the required number of zeroes
cnt_0 = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT if ( S [ i ] == '0' ) : NEW_LINE INDENT cnt_0 += 1 NEW_LINE DEDENT DEDENT a = a - cnt_0 NEW_LINE