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:
import math
import sys
import queue
import copy
import bisect#2分探索

def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())
def inputl():
    return list(map(int, input().split()))
def printl(li):
    print(*li, sep="\n")
def argsort(s):
    return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

N = inputi()
#N, K = inputl()
#L = [int(input()) for i in range(N)]
A = inputl()
B = inputl()
C = inputl()
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から最も左の4位置を返す。
#bisect.insort_left(a, 4)#挿入
A.sort(reverse=True)
B.sort()
C.sort()
tot=0
cut=N

for a in A:
    cut=bisect.bisect_right(B[0:cut], a)
    cut2=N
    for i in reversed(range(cut,N)):
        b=B[i]
        cut2=bisect.bisect_right(C[0:cut2], b)
        tot+=N-cut2
print(tot)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import queue
import copy
import bisect#2分探索

def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())
def inputl():
    return list(map(int, input().split()))
def printl(li):
    print(*li, sep="\n")
def argsort(s):
    return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

N = inputi()
#N, K = inputl()
#L = [int(input()) for i in range(N)]
A = inputl()
B = inputl()
C = inputl()
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から最も左の4位置を返す。
#bisect.insort_left(a, 4)#挿入

B.sort()
C.sort()
tot=0
for a in A:
    cut=bisect.bisect_right(B, a)
    for i in range(cut,N):
        b=B[i]
        cut2=bisect.bisect_right(C, b)
        tot+=N-cut2
print(tot)

Submission status: Time Limit Exceeded

Solution code:
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 ic in c:
  for ib in b:
    if ib>=ic:break
    for ia in a:
      if ia>=ib:break
      ans+=1
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()))
ans=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      if a[i]<b[j]<c[k]:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
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()
p = 0
c.sort()
q = 0
count = 0
x = 0
for i in range(n):
    p = 0
    q = 0
    while p<n:
        if (b[p] > a[i]):
            while q<n:
                if (c[q] > b[p]):
                    count += (n-q)
                    
                    p += 1
                    break
                else:
                    q += 1
        else:
            p += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def isOK(array, index, key):
    if array[index] > key:
        return True
    else:
        return False

def binary_serch(array, key):
    ng = -1
    ok = len(array)

    while (abs(ok - ng) > 1):
        mid = (ok + ng)//2

        if isOK(array, mid, key):
            ok = mid
        else:
            ng = mid
    return ok
n = int(input())
array1 = list(map(int,input().split()))
array2 = list(map(int,input().split()))
array3 = list(map(int,input().split()))

# array1 = sorted(array1)
array2 = sorted(array2)
array3 = sorted(array3)

# a = binary_serch(array2, 5)
count=0
for array1_index in range(n):
    start_array2_index = binary_serch(array2, array1[array1_index])
    #print(array1[array1_index])
    for cor_array2_index in range(start_array2_index, n):
        #print(array2[cor_array2_index])
        start_array3_index = binary_serch(array3, array2[cor_array2_index])
        # for k in range(start_array3_index,n):
        #     print(array3)
        count+=abs(start_array3_index - n)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import sys
inf = 10**9+7
mod = 10**9+7
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b.sort()
c.sort()
b_len = len(b)
c_len = len(c)
count = 0
b_list = [0 for i in range(b_len)]

for i,num in enumerate(b):
    ind_c = bisect.bisect_left(c, num)
    if c_len == ind_c:
        continue
    else:
        if c[ind_c] == num:
            while ind_c != c_len and c[ind_c] == num:
                ind_c+=1
            if ind_c != c_len:
                b_list[i] = c_len-ind_c
        else:
            b_list[i] = c_len-ind_c

# 累積和
a2 = [0]
for i in b_list:a2.append(a2[-1]+i)
def SumArea(l, r):
    return a2[r]-a2[l]


for num in a:
    ind_b = bisect.bisect_left(b, num)
    if b_len == ind_b:
        continue
    else:
        if b[ind_b] == num:
            while ind_b != b_len and b[ind_b] == num:
                ind_b += 1
            if ind_b != b_len:
                count += SumArea(ind_b, b_len)
        else:
            count += SumArea(ind_b, b_len)
print(count)

Submission status: Time Limit Exceeded

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

def binarySearch(i,lst):
	#(lb,ub]で持って、条件式を実現する最小のdを求める
	lb=-1
	ub=n-1
	if lst[ub]<=i:
		return n
	while ub-lb>1:
		mid=(lb+ub)//2
		if lst[mid]>i:
			ub=mid
		else:
			lb=mid
	return ub

ans=0
for i in range(n):
	b_minindex=binarySearch(a[i],b)
	for j in range(b_minindex,n):
		if b_minindex==n:
			break
		c_minindex=binarySearch(b[j],c)
		ans+=n-c_minindex
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    la = list(map(int, input().split()))
    lb = list(map(int, input().split()))
    lc = list(map(int, input().split()))
    
    la.sort()
    lb.sort()
    lc.sort()

    ans = 0
    for a in la:
        if a < lb[-1]:
            idxb = bisect.bisect_right(lb, a)
            for b in lb[idxb:]:
                if b < lc[-1]:
                    idxc = bisect.bisect_right(lc, b)
                    ans += (n - idxc)
    print(ans) 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(n - sum(x > a[i] for x in b), n):
        ans += sum(x > b[j] for x in c)

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 C:
    index = bisect.bisect_left(B,i)
    for j in range(index):
        index2 = bisect.bisect_left(A,B[j])
        ans += index2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ABC = [sorted(list(map(int,input().split()))) for i in range(3)]

ans = 0
for i in range(N):
  for j in range(N):
    if ABC[0][i]>=ABC[1][j]:
      continue
    else:
      for k in range(N):
        if ABC[1][j]>=ABC[2][k]:
          continue
        else:
          ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ABC = [list(map(int,input().split())) for i in range(3)]

ans = 0
ans_line = 0

for i in range(N):
  for j in range(N):
    if ABC[0][i]<ABC[1][j]:
      for k in range(N):
        if ABC[1][j]<ABC[2][k]:
          ans += 1

for i in range(N):
  if ABC[0][i]<ABC[1][i] and ABC[1][i]<ABC[2][i]:
    ans_line += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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


"""
minnum以上で最小の数のindexを返す。無いときはlen(List)を返す
計算量log(len(List))
"""
def bts(List,minnum,under=0):
    if List[0]>=minnum:
        return under
    if List[-1]<minnum:
        return len(List)+under
    i = int(len(List)/2)
    if List[i]>=minnum and List[i-1]<minnum:
        return i + under
    if List[i]<minnum:
        return bts(List[i+1:],minnum,under+i+1)
    return bts(List[:i],minnum,under)


res = 0
for i in range(N):
    b = B[i]
    a = bts(A,b)
    c = N - bts(C,b+1)
    res += a*c

print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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


"""
minnum以上で最小の数のindexを返す。無いときはlen(List)を返す
計算量log(len(List))
"""
def bts(List,minnum,under=0):
    if List[0]>=minnum:
        return under
    if List[-1]<minnum:
        return len(List)+under
    i = int(len(List)/2)
    if List[i]>=minnum and List[i-1]<minnum:
        return i + under
    if List[i]<minnum:
        return bts(List[i+1:],minnum,under+i+1)
    return bts(List[:i],minnum,under)





#各Bの下に置けるCの数を保存
Bcounter = [0]*N

for i in range(N):
    Bcounter[i] = N - bts(C,B[i]+1,0)

for i in range(1,N):
    Bcounter[i] = Bcounter[i-1] + Bcounter[i]
Bcounter=[0]+Bcounter


res = 0
for i in range(N):
    a = A[i]
    #a以上で最小のb
    minb = bts(B,a+1)
    #本来なら、最小のb以降のBを一つ一つ足し上げていく
    res += Bcounter[-1] - Bcounter[minb]

print(res)

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()))
B.sort()
C.sort()

cnt = 0
tmp = N
while tmp != 0:
  cnt += 1
  tmp //= 2

def binary_search(v, L):
  if max(L) <= v:
    return 0
  elif min(L) > v:
    return N
  else:
    l, r = 0, N
    d = (l + r) // 2
    for _ in range(cnt+2):
      if L[d] <= v:
        l = d + 1
        d = (l + r) // 2
      else:
        r = d
        d = (l + r) // 2
    return N - d

LB = [binary_search(B[_], C) for _ in range(N)]
for i in range(N-1, 0, -1):
  LB[i-1] += LB[i]
S = 0
for i in range(N):
  X = N - binary_search(A[i], B)
  if X != N:
    S += LB[X]
print(S)

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()

cnt = 0
tmp = N
while tmp != 0:
  cnt += 1
  tmp //= 2

def binary_search(v, L):
  if max(L) <= v:
    return 0
  elif min(L) > v:
    return N
  else:
    l, r = 0, N
    d = (l + r) // 2
    for _ in range(cnt+2):
      if L[d] <= v:
        l = d + 1
        d = (l + r) // 2
      else:
        r = d
        d = (l + r) // 2
    return N - d

LB = [binary_search(B[_], C) for _ in range(N)]
for i in range(N-1, 0, -1):
  LB[i-1] += LB[i]
S = 0
for i in range(N):
  X = N - binary_search(A[i], B)
  if X == N:
    break
  else:
    S += LB[X]
print(S)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N = int(input())
upper = sorted(list(map(int, input().split())))
middle = sorted(list(map(int, input().split())))
lower = list(map(int, input().split()))

ans = 0
for l in lower:
    idx = bisect_left(middle, l)
    if idx>=1:
        for m in middle[:idx]:
            idx2 = bisect_left(upper, m)
            ans += idx2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    c = [int(i) for i in input().split()]
    a.sort()
    b.sort()
    c.sort()

    cnt = 0
    for i in range(n):
        v = a[i]  
        idx_b = bisect_right(b, v) 
        for j in range(idx_b, n):
            u = b[j]
            idx_c = bisect_right(c, u)
            cnt += n-idx_c     
    print(cnt)
main()

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 isOK(A,mid,target):
    #条件を満たす領域とそうでない領域の境目！
    return target<A[mid]   #条件を満たす中で最小
    #return A[mid]<=target  #条件を満たす中で最大
def aa(A,target):
    ng=-1 ; ok=n  #okはその条件を満たしていることが大前提
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if isOK(A,mid,target): ok=mid
        else: ng=mid
    return ok

ans=0

for i in A:
    t=aa(B,i) 
    for q in range(t,n):
        ans+=n-aa(C,B[q])
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
A=Counter(input().split())
B=Counter(input().split())
C=Counter(input().split())
ans=0
for a_key,a_count in A.most_common():
    for b_key,b_count in B.most_common():
        for c_key,c_count in C.most_common():
            a_key,b_key,c_key=int(a_key),int(b_key),int(c_key)
            if a_key<b_key and b_key<c_key:
                ans+=a_count*b_count*c_count
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 range(n):
  canB = bisect.bisect_right(B, A[i])
  if canB == n:
    continue
  else:
    for j in range(canB, n):
      canC = bisect.bisect_right(C, B[j])
      ans += (n - canC)
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())))
ansum = 0
def stat(array,par):
    return bisect.bisect_right(array,par)

for A in a:
    index = stat(b,A)
    for B in b[index:]:
        indexC = stat(c,B)
        ansum += max(0,n-indexC)
print(ansum)

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()

from fractions import gcd
from math import ceil
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

ans = 0
ind = bisect_right(B,A[0])
for a in A:
    if a >= B[-1]:
        continue
    while a >= B[ind]:
        ind += 1
    for b in B[ind:]:
        indc = bisect_right(C,b)
        ans += N-indc

        

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()))

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

from fractions import gcd
from math import ceil
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

ans = 0
for a in A:
    indb = bisect_right(B, a)
    for b in B[indb:]:
        indc = bisect_right(C,b)
        ans += N-indc

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())))
bnum = [n - bisect.bisect_right(c, b[i]) for i in range(n)]
ans = 0
for i in range(n):
  ai = a[i]
  ans += sum(bnum[bisect.bisect_right(b, ai):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):
  ai = a[i]
  for j in range(bisect.bisect_right(b, ai), n):
    bj = b[j]
    ans += n - bisect.bisect_right(c, bj)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
import bisect

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

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

ans = 0
# for ai in A:
#     i = bisect.bisect_right(B, ai)
#     for bi in B[i:]:
#         j = bisect.bisect_right(C, bi)
#         ans += len(C[j:])

for bi in B:
    i = bisect.bisect_left(A, bi)
    j = bisect.bisect_right(C, bi)
    ans += len(A[:i]) * len(C[j:])


print(ans)

Submission status: Time Limit Exceeded

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
import bisect

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

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

ans = 0
for ai in A:
    i = bisect.bisect_right(B, ai)
    for bi in B[i:]:
        j = bisect.bisect_right(C, bi)
        ans += len(C[j:])

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()))
A.sort()
B.sort()
C.sort()

def binsearch(threshold, lst):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (left + right) // 2
        if lst[mid] > threshold:
            right = mid
        else:
            left = mid
    return right

ans = 0
for a in A:
    b_min_index = binsearch(a, B)
    for i in range(b_min_index, N):
        c_min_index = binsearch(B[i], C)
        ans += N - c_min_index
        #print(a, B[b_min_index], C[c_min_index])
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()
c.sort()

ans = 0
for i in range(len(b)):
    a_idx = bisect.bisect_left(a, b[i])
    c_idx = bisect.bisect_right(c, b[i])
    l = len(c[c_idx:])
    ans += a_idx * (n - c_idx)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def binSearch(array, num):
    n = len(array)
    l = -1
    r = n

    while l + 1 < r:
        m = (l + r) // 2
        if num <= array[m]:
            r = m
        else:
            l = m

    return r


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(len(b)):
    a_idx = binSearch(a, b[i])
    c_idx = binSearch(c, b[i] + 1)
    l = len(c[c_idx:])
    ans += a_idx * (n - c_idx)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def binSearch(array, num):
    n = len(array)
    l = -1
    r = n

    while l + 1 < r:
        m = (l + r) // 2
        if num <= array[m]:
            r = m
        else:
            l = m

    return r


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(len(b)):
    a_idx = binSearch(a, b[i])
    k = len(a[0:a_idx])
    c_idx = binSearch(c, b[i] + 1)
    l = len(c[c_idx:])
    ans += k * l
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
a = getInputIntList()
b = getInputIntList()
c = getInputIntList()

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

ans = 0
for i in range(n):
    x = bisect.bisect_left(b, c[i])
    for j in range(x-1, -1, -1):
        y = bisect.bisect_left(a, b[j])
        ans += y

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect 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())))
count = 0
for i in range(N):
    minb = bisect(B, A[i])
    if minb == N:
        break
    for j in range(minb, N):
        if B[j] == A[i]:
            continue
        minc = bisect(C, B[j])
        if minc == N:
            break
        count += N - minc
print(count)

Submission status: Time Limit Exceeded

Solution code:
from bisect 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):
    minb = bisect(B, A[i])
    if minb == N:
        break
    for j in range(minb, N):
        if B[j] == A[i]:
            continue
        minc = bisect(C, B[j])
        if minc == N:
            break
        count += N - minc
print(count)

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()
C.sort()

ans = 0

for b in B:
    indexA = bisect.bisect_left(A, b)
    indexC = bisect.bisect_right(C, b)

    #print(indexA)
    #print(indexC)

    #if indexA != N-1 or indexC != 0:
    ans += len(A[0:indexA]) * len(C[indexC:N+1])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    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 binSearch(a, x):
        l = -1
        r = len(a)
        while r-l>1:
            m = (l+r)//2
            if x<a[m]:
                r = m
            else:
                l = m
        return r

    ans = 0
    for a in A:
        b_l = binSearch(B, a)
        for b in B[b_l:]:
            c_l = binSearch(C, b)
            ans += N - c_l

    print(ans)

if __name__ == '__main__':
    resolve()

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 up in a:
    tmp1 = bisect.bisect_right(b, up)
    for middle in b[tmp1:]:
        down = bisect.bisect_right(c, middle)
        ans += (n - down)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right


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

    A_map = {}
    for a in A:
        i = bisect_right(B, a)
        B_ = B[i:]
        A_map[a] = B_
    
    B_map = {}
    for b in B:
        i = bisect_right(C, b)
        c_num = len(C) - i
        B_map[b] = c_num

    count = 0
    for a in A:
        for b in A_map[a]:
            count += B_map[b]
    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right


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

    count = 0
    for a in A:
        i = bisect_right(B, a)
        B_ = B[i:]

        for b in B_:
            i = bisect_right(C, b)
            c_num = len(C) - i
            count += c_num

    print(count)


if __name__ == "__main__":
    main()

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 f(l, s, mn):
    ng = s - 1
    ok = len(l)
    while abs(ng - ok) > 1:
        i = (ok + ng) // 2
        x = l[i]
        if mn < x:
            ok = i
        else:
            ng = i
    return ok

ans = 0
bs = 0
for a in A:
    cs = 0
    bs = f(B, bs, a)
    for bi in range(bs, N):
        cs = f(C, cs, B[bi])
        ans += N - cs

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()))
B.sort()
C.sort()

def f(l, mn):
    ng = -1
    ok = len(l)
    while abs(ng - ok) > 1:
        i = (ok + ng) // 2
        x = l[i]
        if mn < x:
            ok = i
        else:
            ng = i
    return ok

ans = 0
for a in A:
    for bi in range(f(B, a), N):
        b = B[bi]
        ans += N - f(C, b)
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()))

cnt = 0
for i in range(N): #中段について 
        for j in range(N): #上段について
            for k in range(N): #下段について 
                if A[j] < B[i] < C[k]:
                    cnt += 1
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()))

cnt = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if A[i] <B[j]:
                if B[j] < C[k]:
                    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#二分探索
from bisect import bisect_left
#input
N = int(input())
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()
Bis_B = []
for i in range(N):
    Bis_B.append(bisect_left(A,B[i]))

#print(Bis_B)

ans = 0
for i in range(N):
    M = bisect_left(B, C[i])
    if M == 0: #この文で余分な動作を少し減らせる
        continue
    ans += sum(Bis_B[:M]) #この探索を複数回やってしまっている？
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#二分探索
from bisect import bisect_left
#input
N = int(input())
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()

#3重を考えるとC<B<A
ans = 0
for i in range(N):
    M = bisect_left(B, C[i])
    if M == 0:
        continue
    for j in range(M):
        ans += bisect_left(A,B[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#二分探索
from bisect import bisect_left
#input
N = int(input())
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()

#3重を考えるとC<B<A
ans = 0
for i in range(N):
    M = bisect_left(B, C[i])

    #ans += M
    for j in range(M):
        ans += bisect_left(A,B[j])


print(ans)

Submission status: Time Limit Exceeded

Solution code:
#二分探索
from bisect import bisect_left
#input
N = int(input())
#print(N)

A = list(map(int, input().split())) #この表記について...
B = list(map(int, input().split()))
C = list(map(int, input().split()))
#print(A,B,C)

#sort 昇順に並び替え
A.sort()
B.sort()
C.sort()

#3重を考えるとC<B<A
ans = 0
for i in range(N):
    M = bisect_left(B, C[i]) 
    #ans += M
    for j in range(M):
        ans += bisect_left(A,B[j])


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()))
A.sort()
B.sort()
C.sort()

def f(l, mn):
    ng = -1
    ok = len(l)
    while abs(ng - ok) > 1:
        i = (ok + ng) // 2
        x = l[i]
        if mn < x:
            ok = i
        else:
            ng = i
    return l[ok:]

ans = 0
for a in A:
    for b in f(B, a):
        ans += len(f(C, b))
print(ans)

Submission status: Time Limit Exceeded

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

#print(N,A,B,C)

count=0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if A[i]<B[j]<C[k]:
                count+=1
print(count)
#do binary search