title: Count Subarrays Equal Number 1S 0S
signature: def count_subarrays_equal_number_1s_0s(arr, n):
source_py: def count_subarrays_equal_number_1s_0s(arr, n):
      um = dict()
      curr_sum = 0
      for i in range(n):
          curr_sum += ((- 1) if (arr[i] == 0) else arr[i])
          if um.get(curr_sum):
              um[curr_sum] += 1
          else:
              um[curr_sum] = 1
      count = 0
      for itr in um:
          if (um[itr] > 1):
              count += ((um[itr] * int((um[itr] - 1))) / 2)
      if um.get(0):
          count += um[0]
      return int(count)
source_cpp: int count_subarrays_equal_number_1s_0s(vector<int> arr, int n) {
    unordered_map < int, int > um;
    int curr_sum = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      curr_sum += ( arr [ i ] == 0 ) ? - 1 : arr [ i ];
      um [ curr_sum ] ++;
    }
    int count = 0;
    for ( auto itr = um . begin ( );
    itr != um . end ( );
    itr ++ ) {
      if ( itr -> second > 1 ) count += ( ( itr -> second * ( itr -> second - 1 ) ) / 2 );
    }
    if ( um . find ( 0 ) != um . end ( ) ) count += um [ 0 ];
    return count;
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(arr, n, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              arr, n),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver([2, 12, 18, 19, 19, 20, 20, 21, 25, 29, 38, 54, 54, 71, 72, 72, 74, 75, 77, 78, 80, 80, 81, 84, 97, 97], 24, 0)
      print(f"TEST-0...{result}")
  
      result = driver([10, 70, 24, -38, 32, -68, 88, -28, -24, -70, -64, 50, -30, 64, 54, -6, 18, -30, -30, -62, -10, 94, -54, -22, -88, 96, 22, 26, -92, -40, -76, 46, 36, 30, 24, -52, 0], 24, 1)
      print(f"TEST-1...{result}")
  
      result = driver([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], 11, 3)
      print(f"TEST-2...{result}")
  
      result = driver([66, 50, 17, 15, 86, 84, 87, 24, 81, 23, 71, 31, 13, 72, 58, 19, 29, 28, 40, 14, 48, 48, 81, 4, 52, 88, 54, 56, 10, 12, 58, 55, 7, 66, 15, 73, 22, 2, 20, 27, 57, 56, 56, 31, 9, 55], 40, 0)
      print(f"TEST-3...{result}")
  
      result = driver([-98, -62, -60, 16, 78, 82], 5, 0)
      print(f"TEST-4...{result}")
  
      result = driver([1, 0, 1], 2, 1)
      print(f"TEST-5...{result}")
  
      result = driver([2, 31, 34, 64], 2, 0)
      print(f"TEST-6...{result}")
  
      result = driver([-70, 90, -10, -64, -76, -74, -12, -44, -48, -54, 76, -78, 8, 0, 0, 78, -28, 6, 98, -84, 60, 60, 2, 48, -96, -28, -78, -76, -56, -26, -60, 50, 44, 34, -90, 80, -30, -98, 62, 36, -46, -72], 25, 2)
      print(f"TEST-7...{result}")
  
      result = driver([1, 1, 1], 1, 0)
      print(f"TEST-8...{result}")
  
      result = driver([37, 70, 80, 61, 86, 10, 17, 98, 54, 89, 87, 84, 11, 55, 3, 52, 4, 90, 98, 31, 20, 62, 71, 58, 58, 6, 92, 5, 99, 99, 72, 40, 82, 54, 23, 19, 85, 91, 62, 98, 62, 72, 93, 74], 27, 0)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: count_subarrays_equal_number_1s_0s
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"arr": [2, 12, 18, 19, 19, 20, 20, 21, 25, 29, 38, 54, 54, 71, 72, 72, 74, 75, 77, 78, 80, 80, 81, 84, 97, 97], "n": 24}}, {"idx": 1, "outputs": 1, "inputs": {"arr": [10, 70, 24, -38, 32, -68, 88, -28, -24, -70, -64, 50, -30, 64, 54, -6, 18, -30, -30, -62, -10, 94, -54, -22, -88, 96, 22, 26, -92, -40, -76, 46, 36, 30, 24, -52, 0], "n": 24}}, {"idx": 2, "outputs": 3, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], "n": 11}}, {"idx": 3, "outputs": 0, "inputs": {"arr": [66, 50, 17, 15, 86, 84, 87, 24, 81, 23, 71, 31, 13, 72, 58, 19, 29, 28, 40, 14, 48, 48, 81, 4, 52, 88, 54, 56, 10, 12, 58, 55, 7, 66, 15, 73, 22, 2, 20, 27, 57, 56, 56, 31, 9, 55], "n": 40}}, {"idx": 4, "outputs": 0, "inputs": {"arr": [-98, -62, -60, 16, 78, 82], "n": 5}}, {"idx": 5, "outputs": 1, "inputs": {"arr": [1, 0, 1], "n": 2}}, {"idx": 6, "outputs": 0, "inputs": {"arr": [2, 31, 34, 64], "n": 2}}, {"idx": 7, "outputs": 2, "inputs": {"arr": [-70, 90, -10, -64, -76, -74, -12, -44, -48, -54, 76, -78, 8, 0, 0, 78, -28, 6, 98, -84, 60, 60, 2, 48, -96, -28, -78, -76, -56, -26, -60, 50, 44, 34, -90, 80, -30, -98, 62, 36, -46, -72], "n": 25}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [1, 1, 1], "n": 1}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [37, 70, 80, 61, 86, 10, 17, 98, 54, 89, 87, 84, 11, 55, 3, 52, 4, 90, 98, 31, 20, 62, 71, 58, 58, 6, 92, 5, 99, 99, 72, 40, 82, 54, 23, 19, 85, 91, 62, 98, 62, 72, 93, 74], "n": 27}}]
question_info.entry_cls_name: Solution