Problem:
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.  He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.  To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.  How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Incorrect submission (verdict: Wrong Answer):
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    A = NLI()
    B = NLI()
    C = NLI()
    
    A = sorted(A)
    C = sorted(C)
    
    ans = 0
    
    for b in B:
        

        A_ng = 0       
        A_ok = len(A)  

        while (abs(A_ok - A_ng) > 1):
            A_mid = (A_ok + A_ng) // 2

            if A[A_mid] >= b:
                A_ok = A_mid
            else:
                A_ng = A_mid
                
        C_ng = 0       
        C_ok = len(C)  

        while (abs(C_ok - C_ng) > 1):
            C_mid = (C_ok + C_ng) // 2

            if C[C_mid] > b:
                C_ok = C_mid
            else:
                C_ng = C_mid
                
                
        len_C = len(C)
        
        ans += A_ok * (len_C-C_ok)
        
    print(ans)
if __name__ == '__main__':
    main()

Fixed, accepted submission:
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    A = NLI()
    B = NLI()
    C = NLI()
    
    A = sorted(A)
    C = sorted(C)
    
    ans = 0
    
    for b in B:
        

        A_ng = -1       
        A_ok = len(A)  

        while (abs(A_ok - A_ng) > 1):
            A_mid = (A_ok + A_ng) // 2

            if A[A_mid] >= b:
                A_ok = A_mid
            else:
                A_ng = A_mid
                
        C_ng = -1      
        C_ok = len(C)  

        while (abs(C_ok - C_ng) > 1):
            C_mid = (C_ok + C_ng) // 2

            if C[C_mid] > b:
                C_ok = C_mid
            else:
                C_ng = C_mid
                
                
        len_C = len(C)
        
        ans += A_ok * (len_C-C_ok)
        
    print(ans)
if __name__ == '__main__':
    main()