-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathTripleSum.py
54 lines (35 loc) · 1 KB
/
TripleSum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the triplets function below.
def triplets(a, b, c):
a = list(sorted(set(a)))
b = list(sorted(set(b)))
c = list(sorted(set(c)))
ai = 0
bi = 0
ci = 0
ans = 0
while bi < len(b):
while ai < len(a) and a[ai] <= b[bi]:
ai += 1
while ci < len(c) and c[ci] <= b[bi]:
ci += 1
ans += ai * ci
bi += 1
return ans
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
lenaLenbLenc = input().split()
lena = int(lenaLenbLenc[0])
lenb = int(lenaLenbLenc[1])
lenc = int(lenaLenbLenc[2])
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)
fptr.write(str(ans) + '\n')
fptr.close()