title: Count Index Pairs Equal Elements Array 1
signature: countIndexPairsEqualElementsArray1 :: [Integer] -> Integer -> Integer
  countIndexPairsEqualElementsArray1 arr n = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: Integer -> Integer -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: [Integer] -> Integer -> Integer -> String
  driver arr n expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME arr n) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver ([5, 11, 18, 22, 40, 46, 50, 51, 53, 55, 64, 67, 73, 78, 86]) (14) (0) )
  
      printf "TEST-1...%s\n" (driver ([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) )
  
      printf "TEST-2...%s\n" (driver ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]) (13) (56) )
  
      printf "TEST-3...%s\n" (driver ([93, 23, 62, 64, 31, 78, 99]) (4) (0) )
  
      printf "TEST-4...%s\n" (driver ([-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) )
  
      printf "TEST-5...%s\n" (driver ([0]) (0) (0) )
  
      printf "TEST-6...%s\n" (driver ([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) )
  
      printf "TEST-7...%s\n" (driver ([-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) )
  
      printf "TEST-8...%s\n" (driver ([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) )
  
      printf "TEST-9...%s\n" (driver ([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;
  }