title: Number Of Pairs In An Array Having Sum Equal To Product
signature: fun numberOfPairsInAnArrayHavingSumEqualToProduct(a: ArrayList<Int>, n: Int): Int {
test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(a: ArrayList<Int>, n: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(a, n), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(9, 10, 20, 26, 26, 28, 31, 34, 35, 36, 36, 37, 39, 43, 44, 44, 46, 49, 54, 57, 58, 63, 64, 64, 65, 67, 70, 70, 74, 75, 77, 78, 79, 81, 82, 83, 84, 86, 95), 31, 0)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(0, -10, 10, 0, 68, 4, -6, -14, 74, -80, 56, -4, 36, 56, 10, -16, 90, 84, -38, -40, 40, -86, -36, -16, -48, -76, -72, -18, -14, -40, -82, 56, -60), 19, 1)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(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), 22, 21)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(88, 20, 53, 21, 29, 73, 62, 91, 72, 34, 47, 42, 98, 9, 79, 80, 94, 36, 7, 67, 96, 34, 99, 56, 37, 70, 55, 36, 10, 77, 41, 51, 5, 37, 57, 29, 56, 74, 97, 31, 96, 52, 13, 29, 87, 58, 28, 31), 38, 0)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(20), 0, 0)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1), 21, 15)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(2, 4, 9, 16, 22, 23, 25, 33, 33, 36, 39, 48, 49, 52, 53, 60, 67, 68, 76, 77, 79, 84, 84, 86, 89), 24, 0)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(-62, 42, -88, -44, 90, 30, 52, 54, 56, -72, -76, 90, 18, 42, 62, -84, 56, -80, 72), 13, 0)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 15, 15)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(22, 15, 28, 29, 32, 16, 33, 83), 7, 0)
      println("TEST-9...${result}")
      
          
  }
  
  main()
source_py: def number_of_pairs_in_an_array_having_sum_equal_to_product(a, n):
      zero = 0
      two = 0
      for i in range(n):
          if (a[i] == 0):
              zero += 1
          if (a[i] == 2):
              two += 1
      cnt = (((zero * (zero - 1)) // 2) + ((two * (two - 1)) // 2))
      return cnt
source_cpp: int number_of_pairs_in_an_array_having_sum_equal_to_product(vector<int> a, int n) {
    int zero = 0, two = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( a [ i ] == 0 ) {
        zero ++;
      }
      if ( a [ i ] == 2 ) {
        two ++;
      }
    }
    int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2;
    return cnt;
  }