Problem :

https://www.hackerrank.com/challenges/triple-sum/problem


My Solution :

#!/usr/bin/env python3


def triplets(a, b, c):
    a = sorted(set(a))
    b = sorted(set(b))
    c = sorted(set(c))
    result, i, j, p, r = 0, 0, 0, 0, 0
    for q in b:
        while i < len(a) and a[i] <= q:
            p += 1
            i += 1
        while j < len(c) and c[j] <= q:
            r += 1
            j += 1
        result += p * r
    return result


la, lb, lc = map(int, input().split())
arra = list(map(int, input().rstrip().split()))
arrb = list(map(int, input().rstrip().split()))
arrc = list(map(int, input().rstrip().split()))
ans = triplets(arra, arrb, arrc)
print(ans)