title: Count Index Pairs Equal Elements Array 1
signature: count_index_pairs_equal_elements_array_1 <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(5L, 11L, 18L, 22L, 40L, 46L, 50L, 51L, 53L, 55L, 64L, 67L, 73L, 78L, 86L), 14L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(14L, -98L, 98L, 58L, -82L, 90L, -80L, -56L, -30L, -36L, -56L, -30L, -58L, 68L, 72L, -76L, 38L, -90L, -72L, 4L, -32L, 32L, -28L, 2L, 12L, -72L, 54L, 2L, 0L, -74L, 8L, 12L, 46L, 72L, -84L, -66L, 70L, 18L, 26L, 72L, -26L, 44L, -8L, 20L, -32L, -56L, 28L), 24L, 
          2L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 13L, 
          56L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(93L, 23L, 62L, 64L, 31L, 78L, 99L), 4L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-94L, -94L, -92L, -86L, -84L, -76L, -76L, -68L, -66L, -56L, -56L, -54L, -50L, -46L, -38L, -34L, -34L, -30L, -26L, -18L, -16L, 2L, 8L, 42L, 52L, 54L, 56L, 64L, 68L, 82L, 82L, 82L, 94L, 96L, 98L), 19L, 
          4L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L), 0L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 18L, 18L, 20L, 21L, 23L, 24L, 27L, 35L, 36L, 38L, 40L, 46L, 50L, 50L, 51L, 52L, 53L, 59L, 61L, 63L, 63L, 65L, 66L, 68L, 68L, 70L, 71L, 74L, 75L, 96L, 98L), 19L, 
          2L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-68L, 40L, 16L, 50L, 36L, 42L, -20L, -46L, -92L, 4L, -18L, -12L, 48L, 0L, -46L, 64L, -74L, -50L, 42L, 44L, -56L, 28L, -10L, 78L, 62L, 70L, -60L, 12L, -44L, -78L), 23L, 
          2L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 30L, 
          211L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(31L, 5L), 1L, 
          0L
      )))
  
  }
  
  main()
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;
  }