title: Count Index Pairs Equal Elements Array 1
signature: pub fn count_index_pairs_equal_elements_array_1(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([5, 11, 18, 22, 40, 46, 50, 51, 53, 55, 64, 67, 73, 78, 86]), 14, 
        0
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([14, -98, 98, 58, -82, 90, -80, -56, -30, -36, -56, -30, -58, 68, 72, -76, 38, -90, -72, 4, -32, 32, -28, 2, 12, -72, 54, 2, 0, -74, 8, 12, 46, 72, -84, -66, 70, 18, 26, 72, -26, 44, -8, 20, -32, -56, 28]), 24, 
        2
      ));
      
      println!("TEST-2...{}", driver(
        Vec::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]), 13, 
        56
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([93, 23, 62, 64, 31, 78, 99]), 4, 
        0
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-94, -94, -92, -86, -84, -76, -76, -68, -66, -56, -56, -54, -50, -46, -38, -34, -34, -30, -26, -18, -16, 2, 8, 42, 52, 54, 56, 64, 68, 82, 82, 82, 94, 96, 98]), 19, 
        4
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([0]), 0, 
        0
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([3, 18, 18, 20, 21, 23, 24, 27, 35, 36, 38, 40, 46, 50, 50, 51, 52, 53, 59, 61, 63, 63, 65, 66, 68, 68, 70, 71, 74, 75, 96, 98]), 19, 
        2
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([-68, 40, 16, 50, 36, 42, -20, -46, -92, 4, -18, -12, 48, 0, -46, 64, -74, -50, 42, 44, -56, 28, -10, 78, 62, 70, -60, 12, -44, -78]), 23, 
        2
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), 30, 
        211
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([31, 5]), 1, 
        0
      ));
      
  }
source_py: def count_index_pairs_equal_elements_array_1(arr, n):
      mp = dict()
      for i in range(n):
          if (arr[i] in mp.keys()):
              mp[arr[i]] += 1
          else:
              mp[arr[i]] = 1
      ans = 0
      for it in mp:
          count = mp[it]
          ans += ((count * (count - 1)) // 2)
      return ans
source_cpp: int count_index_pairs_equal_elements_array_1(vector<int> arr, int n) {
    unordered_map < int, int > mp;
    for ( int i = 0;
    i < n;
    i ++ ) mp [ arr [ i ] ] ++;
    int ans = 0;
    for ( auto it = mp . begin ( );
    it != mp . end ( );
    it ++ ) {
      int count = it -> second;
      ans += ( count * ( count - 1 ) ) / 2;
    }
    return ans;
  }