title: Count Subarrays Equal Number 1S 0S
signature: pub fn count_subarrays_equal_number_1s_0s(arr: Vec<i32>, n: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(arr: Vec<i32>, n: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-2...{}", driver(
        Vec::from([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]), 11, 
        3
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-98, -62, -60, 16, 78, 82]), 5, 
        0
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([1, 0, 1]), 2, 
        1
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([2, 31, 34, 64]), 2, 
        0
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([1, 1, 1]), 1, 
        0
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([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
      ));
      
  }
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;
  }