Problem:


Score : 300 points

Problem Statement

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.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9(1\leq i\leq N)

1 \leq B_i \leq 10^9(1\leq i\leq N)

1 \leq C_i \leq 10^9(1\leq i\leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

Upper: 1-st part, Middle: 1-st part, Lower: 1-st part

Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part

Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87



Sample input:
2
1 5
2 4
3 6


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = sorted(list(map(int, input().split(" "))))
bottoms = sorted(list(map(int, input().split(" "))))


def binary_search(check_list, num, left, right):
    if left > right:
        return left
    mid = (left + right) // 2
    if check_list[mid] > num:
        return binary_search(check_list, num, left, mid - 1)
    elif check_list[mid] == num:
        return mid
    else:
        return binary_search(check_list, num, mid + 1, right)


total_count = 0
for bottom in bottoms:
    mid_insert_index = binary_search(mids, bottom, 0, N - 1)

    for mid in mids[0:mid_insert_index]:
        top_insert_index = binary_search(tops, mid, 0, N - 1)
        total_count += top_insert_index
print(total_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = sorted(list(map(int, input().split(" "))))
bottoms = sorted(list(map(int, input().split(" "))))


def binary_search(check_list, num, left, right):
    if left > right:
        return left
    mid = (left + right) // 2
    if check_list[mid] > num:
        return binary_search(check_list, num, left, mid - 1)
    elif check_list[mid] == num:
        return mid
    else:
        return binary_search(check_list, num, mid + 1, right)


total_count = 0
for bottom in bottoms:
    mid_insert_index = binary_search(mids, bottom, 0, N - 1)

    for mid in mids[0:mid_insert_index]:
        top_insert_index = binary_search(tops, mid, 0, N - 1)
        total_count += len(tops[0:top_insert_index])
print(total_count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a,b,c=sorted(a),sorted(b),sorted(c)

la=[]
for i in range(n):
    p=[0,n-1]
    for j in range(n):
        if p[1]-p[0]==1 and n>2:
            break
        else:
            if a[i]<b[0]:
                p[1]=0
                break
            elif b[n-1]<=a[i]:
                p[1]=n
                break
            elif a[i]<b[(p[0]+p[1])//2]:
                p[1]=(p[0]+p[1])//2
            else:
                p[0]=(p[0]+p[1])//2
    la.append(n-p[1])

lb=[]
for i in range(n):
    p=[0,n-1]
    for j in range(n):
        if p[1]-p[0]==1 and n>2:
            break
        else:
            if b[i]<c[0]:
                p[1]=0
                break
            elif c[n-1]<=b[i]:
                p[1]=n
                break
            elif b[i]<c[(p[0]+p[1])//2]:
                p[1]=(p[0]+p[1])//2
            else:
                p[0]=(p[0]+p[1])//2
    lb.append(n-p[1])

m=0
for i in range(n):
    m+=sum(lb[n-la[i]:n])
print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = sorted([int(i) for i in input().split()])

import bisect

ans = 0
for i in range(N):
    leftb = bisect.bisect_right(b, a[i])
    for j in range(leftb, N):
        leftc = bisect.bisect_right(c, b[j])
        leftctmp = N - leftc
        ans += leftctmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = sorted(list(map(int, input().split())))
l_b = len(B)
C = sorted(list(map(int, input().split())))
l_c = len(C)
ans = 0
for a in A:
    i = bisect.bisect_right(B, a)
    for j in range(i, l_b):
        num = bisect.bisect_right(C, B[j])
        ans += l_c - num
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
l_c = len(C)
ans = 0
for a in A:
    i = bisect.bisect_right(B, a)
    for b in B[i:]:
        j = bisect.bisect_right(C, b)
        ans += l_c - j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
l_c = len(C)
ans = 0
for a in A:
    i = bisect.bisect_right(B, a)
    for b in B[i:]:
        j = bisect.bisect_right(C, b)
        ans += l_c - j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
A = sorted(list(map(int, input().split(" "))))
B = sorted(list(map(int, input().split(" "))))
C = sorted((map(int, input().split(" "))))

count = 0
for a in A:
    for b in B:
        if b <= a:
            continue
        insert_index = bisect_left(C, b)
        if not insert_index > len(C) - 1:
            if C[insert_index] == b:
                count += len(C) - insert_index - 1
            else:
                count += len(C) - insert_index

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect as bi

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for a in A:
    Bi = bi.bisect_right(B,a)
    if N-Bi == 0:
        break
    for b in B[Bi:]:
        Ci = bi.bisect_right(C,b)
        if N-Ci == 0:
            break
        ans += (N-Ci)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort()
b.sort()
c.sort()

ans=0

for i in a:
  p=0
  q=0
  r=0
  r=bisect.bisect_right(b,i)
  #print("r",r)
  for j in range(r,n):
    p=n-i
    if j<n:
      q=n-bisect.bisect_right(c,b[j])
      ans+=q
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
C = list(map(int, input().strip().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for a in A:
    i = bisect_right(B, a)
    for b in B[i:]:
        j = bisect_right(C, b)
        ans += len(C[j:])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

a.sort()
b.sort()
c.sort()

b_ans_list = [0 for _ in range(n)]
for i in range(n):
    # b[i]における選択可能なcの個数
    b_ans_list[i] = n - bisect.bisect_right(c, b[i])

ans = 0

for i in range(n):
    b_index = bisect.bisect_right(b, a[i])
    ans += sum(b_ans_list[b_index::])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

a.sort()
b.sort()
c.sort()

ans = 0

for i in range(n):
    b_index = bisect.bisect_right(b, a[i])
    for j in range(b_index, n):
        ans += n - bisect.bisect_right(c, b[j])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def abstract_bisect(l:list,evaluate_function:callable):
    left_bool=evaluate_function(l[0])
    if left_bool==True:
        return -1
    def evaluate_number(i):
        return evaluate_function(l[i])

    def bis(begin_num:int,end_num:int):
        if end_num-begin_num<=1:
            if evaluate_number(end_num)==left_bool:
                return end_num
            else:
                return begin_num
        else:
            center_num=int((begin_num+end_num)//2)
            centere_bool=evaluate_number(center_num)
            if not centere_bool==left_bool:
                return bis(begin_num=begin_num,end_num=center_num)
            else:
                return bis(begin_num=center_num,end_num=end_num)
    return bis(0,len(l)-1)
def input_int_list():
    return [int(thing) for thing in input().split(" ")]


N=int(input())
A_list=sorted(input_int_list())
B_list=sorted(input_int_list())
C_list=sorted(input_int_list())

B_C=[]
ans=0
for i in B_list:
    imp=abstract_bisect(C_list,lambda x:x>i)+1
    B_C.append(N-imp)

for i in range(N):
    a=A_list[i]
    ind=abstract_bisect(B_list,lambda x:x>a)+1
    if ind==N:
        continue
    else:
        ans=ans+sum(B_C[ind:])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

L = list(itertools.product(A,B,C,repeat=1))
cnt = 0
for i,j,k in L:
    if i<j<k:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a, b, c = sorted(a), sorted(b), sorted(c)

ans = 0
for i in b:
    up_index = bisect.bisect_left(a,i)
    down_index = bisect.bisect_right(c,i)
    ans += len(a[:up_index])*len(c[down_index:])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = list(map(int, input().split()))

    ans = 0

    b_list.sort()
    c_list.sort()

    for i in range(n):
        tob_insert_num = a_list[i]
        tob_insert_index = bisect.bisect_right(b_list, tob_insert_num)
        for j in range(tob_insert_index,n):
            toc_insert_num = b_list[j]
            toc_insert_index = bisect.bisect_right(c_list, toc_insert_num)
            ans += n - toc_insert_index

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
ans = 0
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
lis_B = [0] * N
for i in range(N):
  tmp = bisect.bisect_right(C, B[i])
  if tmp  == N:
    break
  lis_B[i] = N - tmp
for i in range(N):
  tmp = bisect.bisect_right(B, A[i])
  if tmp == N:
    break
  ans += sum(lis_B[tmp:N])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for i in range(n):
    a = A[i]
    for b in B[bisect.bisect_right(B, a):]:
        ans += len(C[bisect.bisect_right(C, b):])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

a_num = np.zeros(n)
b_num = np.zeros(n)

left = 0
right = 0
while left <= n-1 and right <= n-1:
    if a[left] < b[right]:
        a_num[left:] += 1
        right += 1
    else:
        left += 1

left = 0
right = 0
while left <= n-1 and right <= n-1:
    if b[left] < c[right]:
        b_num[left:] += 1
        right += 1
    else:
        left += 1

ans = 0
for i in a_num:
    i = int(i)
    ans += sum(b_num[:i])
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, input().split()))
n=s[0]
a=[]
b=[]
c=[]
s = list(map(int, input().split()))
for i in range(n):
    a.append(s[i])
s = list(map(int, input().split()))
for i in range(n):
    b.append(s[i])
s = list(map(int, input().split()))
for i in range(n):
    c.append(s[i])
count=0
a.sort()
c.sort()

for i in b:
    count_a = 0
    count_c = 0
    for j in a:
        if i<=j:
            break
        count_a+=1
    for j in c[::-1]:
        if i>=j:
            break
        count_c+=1
    count+=count_a*count_c
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, input().split()))
n=s[0]
a=[]
b=[]
c=[]
s = list(map(int, input().split()))
for i in range(n):
    a.append(s[i])
s = list(map(int, input().split()))
for i in range(n):
    b.append(s[i])
s = list(map(int, input().split()))
for i in range(n):
    c.append(s[i])
count=0
for i in a:
    for j in b:
        if i<j:
            for k in c:
                if j<k:
                    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4100000)
input=sys.stdin.readline
# coding: utf-8
# Your code here!

n=int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()
"""
print(a[0])
print(a[1])
print(a[2])
"""
def bin_lower(b):
    if a[0][0]>=b:
        return 0
    pl=0
    pr=n-1
    
    while True:
        pc=(pl+pr)//2
        if a[0][pc]>=b and a[0][pc-1]<b:
            return pc
        elif a[0][pc]<b:
            pl=pc+1
            if pl>n-1:
                return n
        """
        else:
            pr=pc-1
            if pr<0:
                return 0
        """
                
def bin_upper(b):    
    if a[2][n-1]<=b:
        return 0
    pl=0
    pr=n-1
    
    while True:
        pc=(pl+pr)//2
        if a[2][pc]<=b and a[2][pc+1]>b:
            return n-1-pc
        elif a[2][pc]>b:
            pr=pc-1
            if pr<0:
                return n
        """
        else:
            pl=pc+1
            if pl>n-1:
                return 0
        """
"""
print(bin_upper(a[1][0]))
print(bin_lower(a[1][0]))
print(bin_upper(a[1][1]))
print(bin_lower(a[1][1]))
print(bin_upper(a[1][2]))
print(bin_lower(a[1][2]))
"""

cnt=0
for i in range(n):
    cnt+=bin_lower(a[1][i])*bin_upper(a[1][i])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for i in range(N):
    a = A[i]
    b_idx = bisect_right(B, a)
    if b_idx == N:
        break
    b = B[b_idx]
    for j in range(b_idx, N):
        c_idx = bisect_right(C, B[j])
        ans += N - c_idx
        # if C[c_idx] == B[j]:
        #     ans -= 1
print(ans)
# print(*A)
# print(*B)
# print(*C)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0
Cb=[0]*(N+1)
prebr=0
for i in range(N):
  prebr+=bisect_right(C[prebr:],B[i])
  Cb[i]=N-prebr
for i in range(N-1,-1,-1):
  Cb[i]+=Cb[i+1]
for a in A:
  bi=bisect_right(B,a)
  ret+=Cb[bi]
print(ret)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0

Cb=[0]*N
for i in range(N):
  Cb[i]=N-bisect_right(C,B[i])
for a in A:
  bi=bisect_right(B,a)
  for bii in range(bi,N):
    ret+=Cb[bii]
print(ret)

Submission status: Time Limit Exceeded

Solution code:
def sup(A, j):
	A = sorted(A)
	if A[0] >= j:
		return 0
	l = 0
	r = len(A) - 1
	while True:
		i = (l+r) // 2
		if i == len(A) - 1 and A[i] < j:
			return len(A)
		elif A[i]<j and A[i+1]>=j:
			return i+1
		else:
			if A[i] >= j:
				r = i-1
			else: # A[i+1] < j
				l = i+1		

def inf(A, j): 
    A = sorted(A)
    if A[-1] <= j:
        return 0
    l = 0
    r = len(A) - 1
    while True:
        i = (l+r) // 2
        if i == 0 and A[i]>j:
            return len(A)
        elif A[i]>j and A[i-1]<=j:
            return len(A)-i
        else:
            if A[i] <= j:
                l = i+1
            else: # A[i-1] > j
                r = i-1		

N = int(input())
[A, B, C] = [[int(i) for i in input().split()] for j in range(3)]
ans = 0
for j in B:
	ans += sup(A, j) * inf(C, j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ab = [bisect(b, ai) for ai in a]
bc = [bisect(c, bi) for bi in b]
cnt = 0
for bi in ab:
    if bi == n:
        continue
    for i in range(bi, n):
        if bc[i] == n:
            continue
        cnt += n - bc[i]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0

for i in range(n):
    bi = bisect(b, a[i])
    if bi >= n:
        continue
    for j in range(bi, n):
        cj = bisect(c, b[j])
        if cj >= n:
            continue
        cnt += n - cj
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
count=0
for i in range(n):
	for j in range(n):
		if a[i]<b[j]:
			for k in range(n):
				if b[j]<c[k]:
					count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
count=0
for i in range(n):
	for j in range(n):
		for k in range(n):
			if a[i]<b[j] and b[j]<c[k]:
				count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

_ = input()

heads = list(sorted(map(int,input().split())))
bodies = list(map(int,input().split()))
legs = list(sorted(map(int,input().split())))


cnt = 0
for body in bodies:
    #  頭は、体より小さくなければならない
    head_idx = bisect.bisect_left(heads, body)
    head_cnt = len(heads[:head_idx])

    #  足は、体より大きくなければならない
    leg_idx = bisect.bisect_right(legs, body)
    leg_cnt = len(legs[leg_idx:])

    cnt += head_cnt * leg_cnt # 組み合わせの掛け算

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

_ = input()

heads = list(map(int,input().split()))
bodies = list(map(int,input().split()))
legs = list(map(int,input().split()))


cnt = 0
sorted_heads = list(sorted(heads))
sorted_legs = list(sorted(legs))

for body in bodies:
    #  頭は、体より小さくなければならない
    head_idx = bisect.bisect_left(sorted_heads, body)
    head_cnt = len(sorted_heads[:head_idx])

    #  足は、体より大きくなければならない
    leg_idx = bisect.bisect_right(sorted_legs, body)
    leg_cnt = len(sorted_legs[leg_idx:])

    cnt += head_cnt * leg_cnt # 組み合わせの掛け算

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x2 = bisect_right(c, b[i])
    bn.append(n-x2)
for i in range(n):
    x1 = bisect_right(b, a[i])
    cnt += sum(bn[x1:])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
for i in range(n):
    x1 = bisect_right(b, a[i])
    for j in range(x1, n):
        cnt += (n-bisect_right(c, b[j]))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)
from collections import defaultdict
# d = defaultdict(list)

from itertools import combinations
# comb = combinations(range(N), 2)


def C(x, ub):
    return x < ub


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    a_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    b_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    c_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    a_list = sorted(a_list, reverse=True)
    b_list = sorted(b_list, reverse=True)
    c_list = sorted(c_list, reverse=True)

    total_count = 0
    count_b_dict = dict()
    i_b_upper = -1
    i_a_upper = -1
    for c in c_list:
        if b_list[-1] >= c or a_list[-1] >= c:
            break
        i_b_lower = N

        while (i_b_lower - i_b_upper > 1):
            i_b_middle = (i_b_lower + i_b_upper) // 2
            if C(b_list[i_b_middle], c):
                i_b_lower = i_b_middle
            else:
                i_b_upper = i_b_middle

        for i in range(i_b_lower, N):
            b_count = count_b_dict.get(i, None)
            if b_count is not None:
                total_count += b_count
                continue

            b = b_list[i]
            if a_list[-1] >= b:
                break
            i_a_lower = N

            while (i_a_lower - i_a_upper > 1):
                i_a_middle = (i_a_lower + i_a_upper) // 2
                if C(a_list[i_a_middle], b):
                    i_a_lower = i_a_middle
                else:
                    i_a_upper = i_a_middle

            count_b_dict[i] = N - i_a_lower

            total_count += (N - i_a_lower)

    print(total_count)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 5
2 4
3 6"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
1 1 1
2 2 2
3 3 3"""
        output = """27"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288"""
        output = """87"""
        self.assertIO(input, output)


if __name__ == "__main__":
    unittest.main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
*a, = sorted(map(int, input().split()))
*b, = sorted(map(int, input().split()))
*c, = sorted(map(int, input().split()))

ans = 0
for _c in c:
    i = bisect.bisect_left(b, _c)
    for j in range(i):
        ans += bisect.bisect_left(a, b[j])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

# print(a, b, c)

ans = 0
for i in range(n):
    idx_b = bisect_right(b, a[i])
    # select_b = n - idx_b
    for j in range(idx_b, n):
        idx_c = bisect_right(c, b[j])
        select_c = n - idx_c
        ans += select_c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

import numpy as np

A = np.sort(np.array(A))
B = np.sort(np.array(B))
C = np.sort(np.array(C))

#print(A,B,C)

sm=0

for a in A:
    for b in B:
#        print(a,b)
        if a>=b:
            continue
        for c in C:
            if b<c:
 #               print(a,b,c)
                sm+=1

print(sm)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
N=int(input())
A=sorted(list(map(int, input().split())), reverse=True)
B=sorted(list(map(int, input().split())), reverse=True)
C=sorted(list(map(int, input().split())), reverse=True)

ret = 0
for i in C:
    small_b = [b for b in B if b < i]
    for j in small_b:
        small_a = [a for a in A if a < j]
        ret += len(small_a)

print(ret)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for i in range(N):
    b_min = bisect.bisect_right(B, A[i])
    for k in range(b_min, N):
        c_min = bisect.bisect_right(C, B[k])
        ans += N - c_min
        ##print(i, k, ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 愚直に全探索する場合（計算量はn^3）
n = int(input())
A = list(int(i) for i in input().split())  
B = list(int(i) for i in input().split())  
C = list(int(i) for i in input().split())

count = 0
for a in A:
    for b in B:
        for c in C:
            if (a < b and b < c): 
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# ABC77 C - Snuke Festival
from bisect import bisect_left
from bisect import bisect_right
import numpy as np

N = int(input())
A = np.array(sorted(list(map(int, input().split()))))
B = np.array(sorted(list(map(int, input().split()))))
C = np.array(sorted(list(map(int, input().split()))))

ans = 0
for i in range(N):
#    ans += bisect_left(A, B[i]) * (N - bisect_right(C, B[i]))
    ans += np.count_nonzero(A < B[i]) * np.count_nonzero(C > B[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right


def solve():
    N, *ABC = map(int, open(0).read().split())
    A = ABC[:N]
    B = ABC[N:2*N]
    C = ABC[2*N:]
    B.sort()
    C.sort()
    
    ans = 0
    for i in range(N):
        index = bisect_right(B, A[i])
        for j in range(index, N):
            ans += N - bisect_right(C, B[j])
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

count = 0

for i in range(N):
    index_b = bisect.bisect_right(B, A[i])
    for j in range(index_b, N):
        index_c = bisect.bisect_right(C, B[j])
        count += N - index_c

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

def bis(x,vec):
   left_index_NG=-1
   right_index_OK=len(vec)
   while(left_index_NG<right_index_OK-1):
      mid=int((left_index_NG+right_index_OK)/2)
      if x < vec[mid]:
         right_index_OK=mid
      else:
         left_index_NG=mid
   return right_index_OK

alltypes=0
for i in range(N):
   a=A[i]
   for j in range(N):
      if(A[i]>=B[j]):
         continue
      else:
         b=B[j]
         alltypes+=len(C)-bis(b,C)

print(alltypes)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array(sorted([int(i) for i in input().split()]))
b = np.array(sorted([int(i) for i in input().split()]))
c = np.array(sorted([int(i) for i in input().split()]))
cnt = 0
for ai in a:
  for bi in b:
    if bi <= ai:
      continue
    cnt += len(c[c > bi])
    # print(ai, bi, c[c > bi])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import *
n=int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
ans=0
for i in range(n):
  for j in range(bisect_right(b,a[i]),n):
    ans+=n-bisect_right(c,b[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

def main():
    N = int(input())

    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # print(A,B,C)

    A.sort()
    B.sort()
    C.sort()

    def f(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for ai in A:
        for bi in B:
            if bi <= ai:
                continue
            x = f(bi)
            cnt += x

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    N = int(input())

    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # print(A,B,C)

    A.sort()
    B.sort()
    C.sort()

    cnt = 0
    for ai in A:
        for bi in B:
            if bi <= ai:
                continue
            for ci in C:
                if ci <= bi:
                    continue
                # print(ai, bi, ci)
                cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()
B = MAP()
C = MAP()

A.sort()
B.sort()
C.sort()

cand_a = [0] * N
for i,a in enumerate(A):
	cand_a[i] = N - bisect.bisect_right(B, a)

cand_b = [0] * N
for i,b in enumerate(B):
	cand_b[i] = N - bisect.bisect_right(C, b)

cand_c = [0] * N
for i,b in enumerate(cand_b):
	cand_c[i] = sum(cand_b[i:])

ans = sum([cand_c[N-a] for a in cand_a if a])
print(ans)