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 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 a in range(N):
    for b in range(bisect.bisect_right(B,A[a]),N):
        for c in range(bisect.bisect_right(C,B[b]),N):
            
            if A[a]<B[b]<C[c]:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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()
count = [0]*N
answer = 0
z = 0

for i in range(N):
    if B[0] >= C[N-i-1]:
        break
    z += 1
count[0] = z
for i in range(1, N):
    x = z
    for j in range(z):
        if B[i] < C[N-z+j]:
            break
        else:
            x -= 1
    count[i] = x
y = 0
for i in range(N):
    if A[0] >= B[N-i-1]:
        break
    answer += count[N-i-1]
    y += 1

for i in range(1, N):

    for j in range(y):
        if A[i] >= B[N-j-1]:
            break
        answer += count[N-j-1]
#print(count)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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()
count = [0]*N
answer = 0
for i in range(N):
    x = 0
    for j in range(N):
        if B[i] >= C[N-j-1]:
            break
        x += 1
    count[i] = x

for i in range(N):
    for j in range(N):
        if A[i] >= B[N-j-1]:
            break
        answer += count[N-j-1]
#print(count)
print(answer)

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())) # 大きい

# Cは並び替え不要
A.sort()
B.sort()

total = 0
for c in C:
    b_count = bisect.bisect_left(B, c) # bの数量
    for b in B[:b_count]:
        a_count = bisect.bisect_left(A, b) # aの数量
        total += a_count

print(total)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect
def main():
    n=int(input())
    a,b,c=[sorted(map(int,input().split())) for _ in range(3)]
    ans=0
    for ai in a:
        bidx = bisect(b, ai)
        for bi in b[bidx:]:
            ans += n-bisect(c, bi)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline.rstrip()
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
d = defaultdict(int)
pre = 0
for b in B:
    tmp = bisect.bisect_right(C[pre:],b)
    pre += tmp
    d[b] = n - pre

pre = 0
for a in A:
    tmp = bisect.bisect_right(B[pre:],a)
    pre += tmp
    for b in B[pre:]:
        ans += d[b]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline.rstrip()
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = inpl()
B = sorted(inpl())
C = sorted(inpl())

ans = 0
d = defaultdict(int)
for b in B:
    d[b] = len(C[bisect.bisect_right(C,b):])
for a in A:
    for b in B[bisect.bisect_right(B,a):]:
        ans += d[b]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline.rstrip()
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
d = defaultdict(int)
for b in B:
    d[b] = len(C[bisect.bisect_right(C,b):])
for a in A:
    for b in B[bisect.bisect_right(B,a):]:
        ans += d[b]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline.rstrip()
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
d = defaultdict(int)
for b in B:
    d[b] = len(C[bisect.bisect_right(C,b):])
for a in A:
    for b in B[bisect.bisect_right(B,a):]:
        ans += d[b]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline.rstrip()
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
for a in A:
    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:
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()


def binary_search(lst, value, high):
    l = 0
    r = N - 1
    while l <= r:
        mid = (l + r) // 2
        if lst[mid] < value:
            l = mid + 1
        elif lst[mid] > value:
            r = mid - 1
        else:
            # lstの中にある場合
            if high:
                # 真に大きい
                try:
                    while lst[mid] == value:
                        mid += 1
                except IndexError:
                    return N
                return mid
            else:
                # 真に小さい
                try:
                    while lst[mid] == value:
                        mid -= 1
                except IndexError:
                    return -1
                return mid
    if high:
        return l
    else:
        return r


def main():
    ans = 0
    # Bの値でループしてそれより小さいA、大きいCの個数を求めて掛け合わせる
    for middle in B:
        lower = binary_search(A, middle, False) + 1 # 0-indexedで返るので+1する
        higher = N - binary_search(C, middle, True)
        ans += lower * higher
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = 0
A.sort()
B.sort()
#A_b:a以上のBのパーツ数。ソートしているのでそのままBのindexと対応が付く
A_b = [sum(b > a for b in B) for a in A] 
B_c = [sum(c > b for c in C) for b in B]

ans = sum(sum(B_c[N-x:]) for x in A_b) 
#aはB[i](i>N-x)の上に乗せられる。
#B[i]を乗せられるCのパーツ数はリストB_cにまとめてある。
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = 0
Sum = 0
A.sort(reverse=True)
B.sort(reverse=True)
#A_b:a以上のBのパーツ数。ソートしているのでそのままBのindexと対応が付く
A_b = [sum(b > a for b in B) for a in A] 
B_c = [sum(c > b for c in C) for b in B]

ans = sum(sum(B_c[:x]) for x in A_b) 
#aはB[i](i<x)の上に乗せられる。
#B[i]を乗せられるCのパーツ数はリストB_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()))

B.sort()
C.sort()


def binary_search(lst, value):
    l = 0
    r = N - 1
    while l <= r:
        mid = (l + r) // 2
        if lst[mid] < value:
            l = mid + 1
        elif lst[mid] > value:
            r = mid - 1
        else:
            return mid, 1
    return l, 0


def main():
    ans = 0
    for upper in A:
        i, is_in_B = binary_search(B, upper)
        i += is_in_B
        for middle in B[i:]:
            j, is_in_C = binary_search(C, middle)
            ans += N - j - is_in_C
    
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


def binary_search_min_c_index(b, begin, end):
  if C[begin] <= b: return begin-1
  elif C[end] >  b: return end
  elif end == begin + 1: return begin
  
  # if end - begin > 1:
  index = (begin + end) // 2
  if C[index] > b:
    if C[index+1] <= b:
      return index
    else:
      return binary_search_min_c_index(b, index+1, end)
    
  else:
    if C[index-1] > b:
      return index-1
    else:
      return binary_search_min_c_index(b, begin, index)


def enum_bc_combination(a, start_index, c_cache):
  if start_index == len(B):
    return start_index, c_cache, 0
  
  bc_count = 0
  for j in range(len(B[start_index:])):
    if B[start_index + j] <= a: return start_index + j - 1, c_cache, bc_count
    
    c_cache = binary_search_min_c_index(B[start_index + j], begin=c_cache, end=N-1)
    bc_count += c_cache + 1
    c_cache = max(0, c_cache)
    
  return N-1, c_cache, bc_count


total_count = 0
b_cache, c_cache, cache_count = -1, 0, 0
for i in range(N):
  if b_cache == N-1:
    total_count += cache_count * (N - i)
    break
    
  b_cache, c_cache, count = enum_bc_combination(A[i], b_cache+1, c_cache)
  total_count += cache_count + count
  cache_count += count
  
print(total_count)

Submission status: Time Limit Exceeded

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


def binary_search_min_c_index(b, begin, end):
  if C[begin] <= b: return begin-1
  elif C[end] >  b: return end
  elif end == begin + 1: return begin
  
  # if end - begin > 1:
  index = (begin + end) // 2
  if C[index] > b:
    if C[index+1] <= b:
      return index
    else:
      return binary_search_min_c_index(b, index+1, end)
    
  else:
    if C[index-1] > b:
      return index-1
    else:
      return binary_search_min_c_index(b, begin, index)
 
    
def enum_bc_combination(a):
  count_bc = 0
  prev_index = 0
  for b in B:
    if b <= a: return count_bc
    prev_index = binary_search_min_c_index(b, begin=prev_index, end=N-1)
    count_bc += prev_index + 1
    prev_index = max(0, prev_index)
  return count_bc
 
 
 
total_count = 0
for a in A:
  count_with_a = enum_bc_combination(a)
  if count_with_a:
    total_count += count_with_a
  else: break
print(total_count)

Submission status: Time Limit Exceeded

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


def binary_search_min_c_index(b, begin, end):
  if C[begin] <= b: return begin-1
  elif C[end] >  b: return end
  elif end == begin + 1: return begin
  
  # if end - begin > 1:
  index = (begin + end) // 2
  if C[index] > b:
    if C[index+1] <= b:
      return index
    else:
      return binary_search_min_c_index(b, index+1, end)
    
  else:
    if C[index-1] > b:
      return index-1
    else:
      return binary_search_min_c_index(b, begin, index)

    
def enum_bc_combination(a):
  count_bc = 0
  for b in B:
    if b <= a: return count_bc
    count_bc += binary_search_min_c_index(b, begin=0, end=N-1) + 1
  return count_bc



total_count = 0
for a in A:
  count_with_a = enum_bc_combination(a)
  if count_with_a:
    total_count += count_with_a
  else: break
print(total_count)

Submission status: Time Limit Exceeded

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

def enum_bc_combination(a):
  count = 0
  for b in B:
    if b <= a: return count
    for c in C:
      if c <= b: break
      count += 1
  return count

total_count = 0
for a in A:
  total_count += enum_bc_combination(a)
print(total_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split(" ")]
B = [int(b) for b in input().split(" ")]
C = [int(c) for c in input().split(" ")]

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

combiBC = [0] * len(B)
# combiBC[i] : number of combination of B, C when B[i] is selected

ic = 0
lc = len(C)
for ib in range(len(B)):
	b = B[ib]
	while ic < lc:
		c = C[ic]
		if b >= c:
			ic += 1
		else:
			combiBC[ib] = lc - ic
			break

cnt = 0
ib = 0
for ia in range(len(A)):
	a = A[ia]
	while ib < len(B):
		b = B[ib]
		if a >= b:
			ib += 1
		else:
			cnt += sum(combiBC[ib:])
			break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split(" ")]
B = [int(b) for b in input().split(" ")]
C = [int(c) for c in input().split(" ")]

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

ib = 0
ic = 0
lc = len(C)
sb_flag, sc_flag = [False, False]
sb, sc = [0, 0]
cnt = 0

for ia in range(len(A)):
	a = A[ia]
	while ib < len(B):
		b = B[ib]
		if a >= b:
			ib += 1
		else: # a < b
			if not sb_flag:
				sb = ib
				sb_flag = True
			while ic < lc:
				c = C[ic]
				if b >= c:
					ic += 1
				else: # b < c
					if not sc_flag:
						sc = ic
						sc_flag = True
					cnt += lc - ic
					break
			ib += 1

	ib = sb
	ic = sc
	sb_flag = False
	sc_flag = False

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect

def main():
    input = sys.stdin.buffer.readline
    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()
    A_count = [0] * len(A)
    B_count = [0] * len(B)
    for i in range(len(B)):
        B_count[i] = len(C) - bisect(C, B[i])
    for i in range(len(A)):
        A_count[i] = sum(B_count[bisect(B, A[i]):])
    print(sum(A_count))

if __name__ == '__main__':
    main()

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 = i = j = 0

import bisect

for b in B:
    if b in A:
        b -= 1
    i = len(A[:bisect.bisect_left(A,b)])
    if b in C:
        b += 1
    j = len(C[bisect.bisect_left(C,b):])

    ans += i * j

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

ans = i = j = 0

def binary_search(l, p, low):
    if low:
        if len(l) == 1:
            if l[0] < p:
                return 1
            else:
                return 0
        elif l[len(l)//2] < p:
            return len(l[:len(l)//2:]) + binary_search(l[len(l)//2::], p, low)
        else:
            return binary_search(l[:len(l)//2:], p, low) + binary_search(l[len(l)//2::], p, low)
    else:
        if len(l) == 1:
            if l[0] > p:
                return 1
            else:
                return 0
        elif l[len(l)//2] > p:
            return len(l[len(l)//2::]) + binary_search(l[:len(l)//2:], p, low)
        else:
            return binary_search(l[:len(l)//2:], p, low) + binary_search(l[len(l)//2::], p, low)

for b in B:
    i = binary_search(A,b,True)
    j = binary_search(C,b,False)
    ans += i * j

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())))
ans = 0
for a in A:
    for b in B:
        if a >= b:
            continue
        for c in C:
            if b >= c:
                continue
            else:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    index_mid = 0
    index_low = 0

    for i in range(N):
        len_up = upper[i]
        index_mid = index_mid + bisect.bisect_right(middle[index_mid:], len_up)

        if (index_mid >= N):
            break

        index_low = index_low + bisect.bisect_right(lower[index_low:], middle[index_mid])

        tmp_mid = index_mid
        tmp_low = index_low        

        while (tmp_mid < N):
            len_mid = middle[tmp_mid]
            tmp_low = tmp_low + bisect.bisect_right(lower[tmp_low:], len_mid)

            if (tmp_low < N):
                cnt += N - tmp_low
                tmp_mid += 1

            else:
                break

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    for i in range(N):
        len_up = upper[i]
        
        index_mid = bisect.bisect_right(middle, len_up)

        while (index_mid < N):
            len_mid = middle[index_mid]
            index_low = bisect.bisect_right(lower, len_mid)

            if (index_low < N):
                cnt += N - index_low
                index_mid += 1
            
            else:
                break

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
import math
import time
import statistics
import math
import itertools
import bisect

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()

    a_list = get_int_list()
    b_list = get_int_list()
    c_list = get_int_list()

    a_list.sort()
    b_list.sort()
    c_list.sort()

    a_count = []
    b_count = []

    idx = 0
    for a in a_list:
        idx = bisect.bisect_right(b_list, a, idx)
        a_count.append(idx)

    idx = 0
    for b in b_list:
        idx = bisect.bisect_right(c_list, b, idx)
        b_count.append(idx)

    ans = 0
    for a in a_count:
        if a == n:
            continue
        for i in range(a, n):
            ans += n - b_count[i]

    print(ans)
    #print(time.time() - start)

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 = sorted(a)
b = sorted(b)
c = sorted(c)

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(100):
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
import math
import time
import statistics
import math
import itertools
import bisect

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()

    a_list = get_int_list()
    b_list = get_int_list()
    c_list = get_int_list()

    a_list.sort()
    b_list.sort()
    c_list.sort()

    ans = 0
    for a in a_list:
        idx = bisect.bisect_right(b_list, a)
        for i in range(idx, n):
            idx2 = bisect.bisect_right(c_list, b_list[i])
            ans += n - idx2

    print(ans)

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=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ物は一個下げる
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    return r+1

#二分探索(x以下の最大値)
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    return r

#個数をカウント
count=0
for i in range(n):
    if min(a)>=b[i] or max(c)<=b[i]:
        count=0
    else:
        a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
        c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
        count+=a_count*(len(c)-c_count+1)
        #print(upper_bound(a,b[i]),lower_bound(c,b[i]))
        #print(a_count,len(c),c_count,len(c)-c_count+1)
        #print(count)

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()))
out=0
a.sort()
b.sort()
c.sort()
for i in range(n):
    for j in range(n):
        if b[j] > a[i]:
            for k in range(n):
                if c[k] > b[j]:
                    out+=(n-k)
                    break
print(out)

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()))
out=0
for i in a:
    for j in b:
        for k in c:
            if k > j and j > i:
                out+=1
print(out)

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
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]:
                    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
A_list = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
cnt = 0

def is_ok(arg):
    return B_list[arg] > A_list[i]

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(arg):
    return C_list[arg] > B_list[j]

def bisect2(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid):
            ok = mid
        else:
            ng = mid
    return ok

for i in range(n): #Aを決定
    #Aより大きいBを探す
    B_key = bisect(-1, len(B_list)-1)
    if A_list[i] < B_list[B_key]:
        for j in range(B_key, n):
            #Bより大きいCを探す
            C_key = bisect2(-1, len(C_list)-1)
            if B_list[j] < C_list[C_key]:
                cnt += n-C_key
            else:
                break
    else:
        break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
A_list = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
cnt = 0

def is_ok(arg):
    return B_list[arg] > A_list[i]

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(arg):
    return C_list[arg] > B_list[j]

def bisect2(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid):
            ok = mid
        else:
            ng = mid
    return ok

for i in range(n): #Aを決定
    #Aより大きいBを探す
    B_key = bisect(-1, len(B_list)-1)
    if A_list[i] < B_list[B_key]:
        for j in range(B_key, n):
            #Bより大きいCを探す
            C_key = bisect2(-1, len(C_list)-1)
            if B_list[j] < C_list[C_key]:
                cnt += n-C_key

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def solve():
    # 標準入力部分
    N = int(input())
    A = np.array(input().split(), dtype=np.int32)
    B = np.array(input().split(), dtype=np.int32)
    C = np.array(input().split(), dtype=np.int32)
    # A, B, Cをsort
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for a in A:
        index_b_bigger_a = np.searchsorted(B, a, 'right')
        if(index_b_bigger_a == N):
            continue
        for j in range(index_b_bigger_a, N):
            k = np.searchsorted(C, B[j], 'right')
            if(k == N):
                continue
            ans += N - k
    print(ans)


if __name__ == "__main__":
    solve()