title: Count Pairs Two Sorted Arrays Whose Sum Equal Given Value X 2
signature: count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_2 <- function(arr1, arr2, m, n, x) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr1, arr2, m, n, x, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr1, arr2, m, n, x), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(5L, 5L, 7L, 10L, 14L, 14L, 17L, 21L, 32L, 34L, 37L, 40L, 40L, 40L, 46L, 46L, 50L, 50L, 51L, 55L, 57L, 62L, 65L, 67L, 67L, 69L, 70L, 70L, 72L, 73L, 76L, 77L, 77L, 78L, 84L, 85L, 85L, 86L, 87L, 88L, 88L, 89L, 89L, 90L, 93L, 99L), list(2L, 5L, 8L, 8L, 10L, 12L, 13L, 15L, 17L, 18L, 20L, 20L, 21L, 27L, 28L, 31L, 34L, 37L, 40L, 46L, 48L, 52L, 53L, 54L, 54L, 58L, 59L, 60L, 66L, 68L, 68L, 69L, 70L, 71L, 72L, 73L, 77L, 77L, 80L, 84L, 84L, 92L, 92L, 95L, 97L, 97L), 28L, 29L, 23L, 
          3L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-84L, 52L, -34L, 96L, 16L, 92L, -64L, -74L), list(-22L, 26L, -12L, -54L, 66L, 86L, 38L, 76L), 6L, 5L, 7L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 37L, 26L, 42L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(60L, 92L, 42L, 83L, 55L, 76L, 29L, 62L), list(71L, 2L, 74L, 42L, 80L, 71L, 26L, 76L), 4L, 7L, 7L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-94L, -94L, -58L, -40L, -40L, -26L, -24L, -22L, -22L, -22L, -2L, 0L, 4L, 8L, 12L, 16L, 16L, 18L, 22L, 32L, 42L, 44L, 50L, 58L, 64L, 78L, 80L, 90L), list(-86L, -84L, -78L, -76L, -72L, -70L, -62L, -58L, -54L, -54L, -50L, -46L, -44L, -40L, -30L, -28L, -16L, -10L, 10L, 36L, 36L, 48L, 70L, 84L, 84L, 90L, 94L, 98L), 17L, 27L, 17L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L), list(1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L), 5L, 8L, 9L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(1L, 5L, 7L, 7L, 7L, 14L, 15L, 16L, 17L, 18L, 18L, 19L, 20L, 25L, 27L, 31L, 36L, 42L, 47L, 51L, 56L, 56L, 56L, 58L, 58L, 59L, 63L, 63L, 63L, 65L, 66L, 67L, 76L, 83L, 93L, 94L, 97L), list(2L, 3L, 7L, 8L, 9L, 10L, 17L, 18L, 21L, 28L, 29L, 29L, 33L, 35L, 46L, 47L, 47L, 49L, 49L, 49L, 53L, 56L, 58L, 59L, 59L, 60L, 65L, 67L, 70L, 78L, 81L, 85L, 85L, 87L, 90L, 92L, 96L), 28L, 34L, 31L, 
          1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(78L, -74L, 52L, 56L, -8L, 92L, 14L, 56L, -72L, -92L, 32L, -94L, -26L, -8L, -66L, 72L, -24L, 36L, -84L, -4L, -68L, 14L, 78L, 40L, -82L, -10L, 16L, 56L, 6L, -16L, 30L, 24L, -32L), list(-74L, 22L, -14L, -2L, 36L, 86L, -70L, -20L, -76L, -84L, -40L, -36L, 42L, 22L, -60L, -94L, -18L, 8L, -14L, -42L, -68L, 62L, -60L, 2L, 40L, -66L, 68L, 96L, 70L, 98L, -38L, -74L, -92L), 16L, 30L, 24L, 
          1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 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), list(0L, 0L, 0L, 0L, 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), 25L, 33L, 33L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(17L, 50L, 65L, 4L, 19L, 10L, 45L, 70L, 76L, 81L, 28L, 97L, 55L, 70L, 38L, 2L, 40L, 67L, 36L, 33L, 6L, 85L, 25L), list(78L, 92L, 65L, 23L, 7L, 94L, 18L, 4L, 2L, 53L, 31L, 58L, 98L, 18L, 46L, 16L, 17L, 92L, 80L, 92L, 43L, 70L, 50L), 16L, 22L, 22L, 
          0L
      )))
  
  }
  
  main()
source_py: def count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_2(arr1, arr2, m, n, x):
      (count, l, r) = (0, 0, (n - 1))
      while ((l < m) and (r >= 0)):
          if ((arr1[l] + arr2[r]) == x):
              l += 1
              r -= 1
              count += 1
          elif ((arr1[l] + arr2[r]) < x):
              l += 1
          else:
              r -= 1
      return count
source_cpp: int count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_2(vector<int> arr1, vector<int> arr2, int m, int n, int x) {
    int count = 0;
    int l = 0, r = n - 1;
    while ( l < m && r >= 0 ) {
      if ( ( arr1 [ l ] + arr2 [ r ] ) == x ) {
        l ++;
        r --;
        count ++;
      }
      else if ( ( arr1 [ l ] + arr2 [ r ] ) < x ) l ++;
      else r --;
    }
    return count;
  }