## fizzbuzzer.com

### Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

# Triple Sum

Sharing is caring!

Problem Statement
Given $3$ arrays $a, b, c$ of different sizes, find the number of distinct triplets $(p, q, r)$ where $p$ is an element of $a$, written as $p \in a$, $q \in b$, and $r \in c$, satisfying the criteria: $p \le q$ and $q \ge r$

For example, given $a=\left[3,5,7\right]$ $b=\left[3,6\right]$ and $c=\left[4,6,9\right]$ we find four distinct triplets: $latex(3,6,4), (3,6,6), (5,6,4), (5,6,6)$

Function Description
Complete the triplets function in the editor below. It must return the number of distinct triplets that can be formed from the given arrays.

triplets has the following parameter(s):
a, b, c: three arrays of integers.

Input Format
The first line contains $3$ integers $len_a, len_b, len_c$, the sizes of the three arrays.
The next $3$ lines contain space-separated integers numbering $len_a, len_b, len_c$ respectively.

Constraints
$1 \le len_a, len_b, len_c \le 10^5$
$1 \le all\ elements\ in\ a,b,c \le 10^8$

Output Format
Print an integer representing the number of distinct triplets.

Sample Input 0

Sample Output 0

Explanation 0
The special triplets are $(1,2,1), (1,2,2), (1,3,1), (1,3,2), (1,3,3), (3,3,1), (3,3,2), (3,3,3)$.

Solution