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:
def binary_search(sorted_list, item):
    """
    sorted_listのうち，itemより大きくなる最初のindexを求める．
    """
    low = 0
    high = len(sorted_list)

    while low <= high:
        mid = (low + high) // 2
        if(mid >= len(sorted_list) or mid < 0):
            return None

        if sorted_list[mid] > item and mid == 0:
            return mid
        elif sorted_list[mid] > item and sorted_list[mid - 1] <= item:
            return mid
        elif sorted_list[mid] > item and sorted_list[mid - 1] > item:
            high = mid - 1
        else:
            low = mid + 1
    return None


def solve():
    # 標準入力部分
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    # A, B, Cをsort
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for a in A:
        index_b_bigger_a = binary_search(B, a)
        if(index_b_bigger_a is None):
            continue
        for j in range(index_b_bigger_a, N):
            k = binary_search(C, B[j])
            if(k is None):
                continue
            ans += N - k
    print(ans)


if __name__ == "__main__":
    solve()

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(reverse=False)
A.append(float('inf'))
B.sort(reverse=False)

# A > B > Cである組み合わせの数を求める
count = 0
for ic in range(N):
    bottom_a = 0
    for ib in range(N):
        if B[ib] >= C[ic]:
            break
        
        top_a = N
        count_a = 0
        while top_a >= bottom_a:
            middle_a = (top_a + bottom_a) // 2

            if A[middle_a] == B[ib]:
                count_a = middle_a - 1
                break
            if A[middle_a] < B[ib] and B[ib] < A[middle_a + 1]:
                count_a = middle_a
                break
            if A[middle_a] > B[ib]:
                top_a = middle_a
            if A[middle_a] < B[ib]:
                bottom_a = middle_a + 1

        count += count_a + 1
        bottom_a = count_a

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(reverse=False)
A.insert(0, 0)
A.append(float('inf'))
B.sort(reverse=False)

# A > B > Cである組み合わせの数を求める
count = 0
for ic in range(N):
    bottom_a = 0
    for ib in range(N):
        if B[ib] >= C[ic]:
            break
        
        top_a = N
        count_a = 0
        while top_a >= bottom_a:
            middle_a = (top_a + bottom_a) // 2

            if A[middle_a] == B[ib]:
                count_a = middle_a - 1
                break
            if A[middle_a] < B[ib] and B[ib] < A[middle_a + 1]:
                count_a = middle_a
                break
            if A[middle_a] > B[ib]:
                top_a = middle_a
            if A[middle_a] < B[ib]:
                bottom_a = middle_a + 1

        count += count_a
        bottom_a = count_a

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 = sorted(A, reverse=False)
A.insert(0, 0)
A.append(float('inf'))
B = sorted(B, reverse=False)
# A > B > Cである組み合わせの数を求める

count = 0
for ic in range(N):
    bottom_a = 0
    for ib in range(N):
        if B[ib] >= C[ic]:
            break
        
        top_a = N
        count_a = 0
        while top_a >= bottom_a:
            middle_a = (top_a + bottom_a) // 2

            if A[middle_a] == B[ib]:
                count_a = middle_a - 1
                break
            if A[middle_a] < B[ib] and B[ib] < A[middle_a + 1]:
                count_a = middle_a
                break
            if A[middle_a] > B[ib]:
                top_a = middle_a
            if A[middle_a] < B[ib]:
                bottom_a = middle_a + 1

        count += count_a
        bottom_a = count_a

print(count)

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,B,C=map(sorted,(A,B,C))
memo=[-1]*(N+1)

prev_b=0
ans=0
next_b=0
prev_ans=0
for i in range(N):
  if A[i]<next_b:
    ans += prev_ans
    continue
  idx_b = bisect_right(B,A[i],prev_b)
  if idx_b==N:break
  next_b=B[idx_b]
  preb_b=idx_b
  if memo[idx_b] != -1:
    SUM = memo[idx_b]
    prev_ans = SUM
    ans += SUM
    continue
  prev_c=0
  SUM=0
  for j in range(idx_b,N):
    idx_c = bisect_right(C,B[j],prev_c)
    if idx_c==N:break
    preb_c=idx_c
    SUM += N-idx_c
  ans += SUM
  memo[idx_b]=SUM
  prev_ans =SUM

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,B,C=map(sorted,(A,B,C))
memo=[-1]*(N+1)

prev_b=0
ans=0
for i in range(N):
  idx_b = bisect_right(B,A[i],prev_b)
  if idx_b==N:break
  preb_b=idx_b
  if memo[idx_b] != -1:
    ans += memo[idx_b]
    continue
  prev_c=0
  SUM=0
  for j in range(idx_b,N):
    idx_c = bisect_right(C,B[j],prev_c)
    if idx_c==N:break
    preb_c=idx_c
    SUM += N-idx_c
  ans += SUM
  memo[idx_b]=SUM

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,B,C=map(sorted,(A,B,C))

prev_b=0
ans=0
for i in range(N):
  idx_b = bisect_right(B,A[i],prev_b)
  if idx_b==N:break
  preb_b=idx_b
  prev_c=0
  for j in range(idx_b,N):
    idx_c = bisect_right(C,B[j],prev_c)
    if idx_c==N:break
    preb_c=idx_c
    ans += N-idx_c

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#関数リスト
import sys
from bisect import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    index = 0
    next_i = index
    
    for i in A:
        index = next_i
        for j in range(index, B_len):
            if B[j] <= i:
                next_i = j+1
            else:
                result += C_len - bisect(C,B[j])
    print(result)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#関数リスト
import sys
from bisect import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    for i in A:
        index = bisect(B,i)
        if index == B_len:
            break
        for j in range(index, B_len):
            index2 = bisect(C,B[j])
            if index2 == C_len:
                break
            result += C_len - index2
    print(result)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#関数リスト
import sys
from bisect import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    for i in A:
        index = bisect(B,i)
        for j in range(index, B_len):
            if B[j] > i:
                result += C_len - bisect(C,B[j])
    print(result)

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

def f(X,Y,S):
	i,ret = 0, [0 for _ in range(N)]
	for k,x in enumerate(X):
		while x>=Y[i]:
			i += 1
			if i==N: return ret
		if S is None:	ret[k] = N-i
		else:			ret[k] = sum(S[i:])
	return ret

K = f(B,C,None)
K = f(A,B,K)
print(sum(K))

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())
Ai = sorted(map(int,input().split()))
Bi = sorted(map(int,input().split()))
Ci = sorted(map(int,input().split()))

def f(X,Y,S):
	i,ret = 0, [0 for _ in range(N)]
	for k,x in enumerate(X):
		while x>=Y[i]:
			i += 1
			if i==N: return ret
		ret[k] = sum(S[i:])
	return ret

Ki = f(Bi,Ci,[1]*N)
Hi = f(Ai,Bi,Ki)
print(sum(Hi))

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
ais = map(int, raw_input().split())
bis = map(int, raw_input().split())
cis = map(int, raw_input().split())


count = 0
ais.sort()
bis.sort()
cis.sort()

for a in ais:
	i,j = 0,0
	while(i < len(bis) and not(bis[i] > a)): i+=1
	while(i < len(bis)):
		while(j < len(cis) and not(cis[j] > bis[i])): j +=1
		if j < len(cis):
			count +=  ( n - j)
		i+=1
print count

Submission status: Time Limit Exceeded

Solution code:
#create date: 2020-08-06 09:16

import sys
stdin = sys.stdin
from bisect import bisect_left

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    b = na()
    c = na()
    a.sort()
    b.sort()
    c.sort()
    cnt = 0
    for ci in c:
        i = bisect_left(b, ci)
        if i == 0:
            continue
        for bi in b[:i]:
            j = bisect_left(a, bi)
            cnt += j
    print(cnt)

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)
c.reverse()

ans=0
max1=n-1

for x in range(n):
  maxC=c[x]
  min1=0
  while max1-min1>1:
    zantei=(max1+min1)//2
    if b[zantei]>=maxC:
      max1=zantei
    else:
      min1=zantei
  if b[max1]<maxC:
    ch=max1
  elif b[min1]>=maxC:
    continue
  else:
    
    ch=min1
  
  for y in range(ch+1):
    maxB=b[y]
    max2=n-1
    min2=0
    while max2-min2>1:
      zantei1=(max2+min2)//2
      if a[zantei1]>=maxB:
        max2=zantei1
      else:
        min2=zantei1
    if a[max2]<maxB:
      ch1=max2
    else:
      ch1=min2
      
    ans+=ch1+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()))
a=sorted(a)
b=sorted(b)
c=sorted(c)

ans=0

for x in range(n):
  maxC=c[x]
  min1=0
  max1=n-1
  while max1-min1>1:
    zantei=(max1+min1)//2
    if b[zantei]>=maxC:
      max1=zantei
    else:
      min1=zantei
  if b[max1]<maxC:
    ch=max1
  elif b[min1]>=maxC:
    continue
  else:
    
    ch=min1
  
  for y in range(ch+1):
    maxB=b[y]
    max2=n-1
    min2=0
    while max2-min2>1:
      zantei1=(max2+min2)//2
      if a[zantei1]>=maxB:
        max2=zantei1
      else:
        min2=zantei1
    if a[max2]<maxB:
      ch1=max2
    else:
      ch1=min2
      
    ans+=ch1+1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

def isOK(index,key,li):
    if li[index] >= key:
        #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、
        #ここの不等号にイコールを入れると
        #okはliの中でkey未満の数字がいくつあるかを表すようになる
        return True
    else:
        return False
def binary_search(key,li):
    ng = -1
    ok = len(li)
    while abs(ok - ng) > 1:
        mid = ok + ng //2
        if isOK(mid,key,li):
            ok = mid
        else:
            ng = mid
    return ok
    #liはsortしておくことに注意


def isOK2(index,key,li):
    if li[index] > key:
        #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、
        #ここの不等号にイコールを入れると
        #okはliの中でkey未満の数字がいくつあるかを表すようになる
        return True
    else:
        return False
def binary_search2(key,li):
    ng = -1
    ok = len(li)
    while abs(ok - ng) > 1:
        mid = ok + ng //2
        if isOK2(mid,key,li):
            ok = mid
        else:
            ng = mid
    return ok
    #liはsortしておくことに注意
n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
ans = 0
for i in range(n):
    B = b_li[i]
    k = n - binary_search2(B,c_li)
    l = binary_search(B,a_li)
    ans += k*l
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

def isOK(index,key,li):
    if li[index] >= key:
        #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、
        #ここの不等号にイコールを入れると
        #okはliの中でkey未満の数字がいくつあるかを表すようになる
        return True
    else:
        return False
def binary_search(key,li):
    ng = -1
    ok = len(li)
    while abs(ok - ng) > 1:
        mid = ok + ng //2
        if isOK(mid,key,li):
            ok = mid
        else:
            ng = mid
    return ok
    #liはsortしておくことに注意


def isOK2(index,key,li):
    if li[index] > key:
        #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、
        #ここの不等号にイコールを入れると
        #okはliの中でkey未満の数字がいくつあるかを表すようになる
        return True
    else:
        return False
def binary_search2(key,li):
    ng = -1
    ok = len(li)
    while abs(ok - ng) > 1:
        mid = ok + ng //2
        if isOK2(mid,key,li):
            ok = mid
        else:
            ng = mid
    return ok
    #liはsortしておくことに注意
n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
p = len(c_li)
ans = 0
for i in range(n):
    B = b_li[i]
    k = p - binary_search2(B,c_li)
    l = binary_search(B,a_li)
    ans += k*l
print(ans)

Submission status: Time Limit Exceeded

Solution code:

def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

def isOK(index,key,li):
    if li[index] >= key:
        #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、
        #ここの不等号にイコールを入れると
        #okはliの中でkey未満の数字がいくつあるかを表すようになる
        return True
    else:
        return False
def binary_search(key,li):
    ng = -1
    ok = len(li)
    while abs(ok - ng) > 1:
        mid = ok + ng //2
        if isOK(mid,key,li):
            ok = mid
        else:
            ng = mid
    return ok
    #liはsortしておくことに注意


n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
ans = 0
for i in range(n):
    C = c_li[i]
    k = binary_search(C,b_li)
    for j in range(k):
        B = b_li[j]
        l = binary_search(B,a_li)
        ans += l
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

def isOK(index,key,li):
    if li[index] >= key:
        #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、
        #ここの不等号にイコールを入れると
        #okはliの中でkey未満の数字がいくつあるかを表すようになる
        return True
    else:
        return False
def binary_search(key,li):
    ng = -1
    ok = len(li)
    while abs(ok - ng) > 1:
        mid = ok + ng //2
        if isOK(mid,key,li):
            ok = mid
        else:
            ng = mid
    return ok
    #liはsortしておくことに注意


n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
ans = 0
for i in range(n):
    C = c_li[i]
    k = binary_search(C,b_li)
    for j in range(k):
        B = b_li[j]
        l = binary_search(B,a_li)
        ans += l
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect as bs

n = int(input())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
c_l = list(map(int, input().split()))

a_l.sort()
b_l.sort()
c_l.sort()

ans = 0
for i in range(n):
    index_1 = bs.bisect_right(b_l,a_l[i])
    for j in range(index_1,n):
        index_2 = bs.bisect_right(c_l,b_l[j])
        ans += (n-index_2)
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())))

comb = 0
top_start = 0

while top_start < N:
    top_value = A[top_start]
    top_end = bisect.bisect_right(A,top_value)
    top_num = top_end - top_start
    mid_start = bisect.bisect_right(B,top_value)
    while mid_start < N:
        mid_value = B[mid_start]
        mid_end = bisect.bisect_right(B,mid_value)
        mid_num = mid_end - mid_start
        bottom_end = bisect.bisect_right(C,mid_value)
        bottom_num = N - bottom_end

        if bottom_num == 0: break

        comb += top_num * mid_num * bottom_num
        mid_start = mid_end
    top_start = top_end

print(comb)

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()))
from bisect import *

cnt=0
for a in A:
    in_b = bisect_right(B, a)
    for b in B[in_b:]:
        in_c = bisect_right(C, b)
        for c in C[in_c:]:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = [int(x) for x in input().split()]
b.sort()
c = [int(x) for x in input().split()]
c.sort()
l = [[a[i], b[i], c[i]] for i in range(n)]

def solve(value: int, key: int) -> bool:
    return value >= key

def binary_search(l, key: int) -> int:
    ng = -1
    ok = len(l)

    while abs(ok - ng) > 1:
        mid = int((ok + ng) / 2)
        if solve(l[mid], key):
            ok = mid
        else:
            ng = mid
    return ok

result = 0

for c_elem in c:
    cases = binary_search(b, c_elem)
    for b_elem in b[:cases]:
        tmp = binary_search(a, b_elem)
        result += tmp

print(result)

Submission status: Time Limit Exceeded

Solution code:
import copy
n =int(input())
a=[]
b=[]
c=[]
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))

c.sort()
c2 = copy.copy(c)
b_limit = 0
c_limit =0
count =0
c_count =0
b_score =[0]*n
for i in a:
    c_count =0
    c = copy.copy(c2)
    if b_limit == 1:
        break
    for j in  reversed(range(len(b))):
        if b[j] <= i:
            if b[j] == max(b):
                b_limit +=1
            break
        else:
            if not b_score[j] == 0:
                count += b_score[j]
                continue
            if len(c) ==0:
                count +=c_count
                if b_score[j] ==0:
                    b_score[j] = c_count
                continue
        for k in reversed(range(len(c))):
            if c[k] <= b[j]:
                count += c_count
                if b_score[j] ==0:
                    b_score[j] = c_count
                break
            c.pop(k)
            c_count +=1
            if k == 0:
                count +=c_count
                if b_score[j] ==0:
                    b_score[j] = c_count
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
n =int(input())
a=[]
b=[]
c=[]
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))

c.sort()
c2 = copy.copy(c)
b_limit = 0
c_limit =0
count =0
c_count =0
b_score =[0]*n
for i in a:
    c_count =0
    c = copy.copy(c2)
    if b_limit == 1:
        break
    for j in  reversed(range(len(b))):
        if b[j] <= i:
            if b[j] == max(b):
                b_limit +=1
            break
        else:
            if not b_score[j] == 0:
                count += b_score
                continue
            if len(c) ==0:
                count +=c_count
                if b_score[j] ==0:
                    b_score[j] == c_count
                continue
        for k in reversed(range(len(c))):
            if c[k] <= b[j]:
                count += c_count
                if b_score[j] ==0:
                    b_score[j] == c_count
                break
            c.pop(k)
            c_count +=1
            if k == 0:
                count +=c_count
                if b_score[j] ==0:
                    b_score[j] == c_count


print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
n =int(input())
a=[]
b=[]
c=[]
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))

c.sort()
c2 = copy.copy(c)
b_limit = 0
c_limit =0
count =0
c_count =0

for i in a:
    c_count =0
    c = copy.copy(c2)
    if b_limit == 1:
        break
    for j in  reversed(range(len(b))):
        if b[j] <= i:
            if b[j] == max(b):
                b_limit +=1
            break
        else:
            if len(c) ==0:
                count +=c_count
                continue
        for k in reversed(range(len(c))):
            if c[k] <= b[j]:
                count += c_count
                break
            c.pop(k)
            c_count +=1
            if k == 0:
                count +=c_count


print(count)

Submission status: Time Limit Exceeded

Solution code:
n =int(input())
a=[]
b=[]
c=[]
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))
c.sort()
b_limit = 0
c_limit =0
count =0

for i in a:
    if b_limit == 1:
        break
    for j in  reversed(b):
        if j <= i:
            if j == max(b):
                b_limit +=1
            break
        for k in reversed(c):
            if k <= j:
                break
            count +=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

b_li.sort()
c_li.sort()

check_li = [0]*(n+10)

for i in range(len(b_li)):
    s = bisect.bisect_right(c_li, b_li[i])
    check_li[i] = len(c_li[s:])

tmp = 0
for i in range(1, n+11):
    check_li[-i] = check_li[-i] + tmp
    tmp = check_li[-i]

ans = 0

for i in a_li:
    s = bisect.bisect_right(b_li, i)
    ans += check_li[s]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

b_li.sort()
c_li.sort()

check_li = [0]*(n+10)

for i in range(len(b_li)):
    s = bisect.bisect_right(c_li, b_li[i])
    check_li[i] = len(c_li[s:])
    

ans = 0

for i in a_li:
    s = bisect.bisect_right(b_li, i)
    ans += sum(check_li[s:])
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

b_li.sort()
c_li.sort()

ans = 0

for i in a_li:
    s = bisect.bisect(b_li, i)
    
    for j in b_li[s:]:
        t = bisect.bisect(c_li, j)
        ans += n-t
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

b_li.sort()
c_li.sort()

ans = 0

for i in a_li:
    s = bisect.bisect_right(b_li, i)
    
    for j in b_li[s:]:
        t = bisect.bisect_right(c_li, j)
        ans += n-t
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

a_li.sort()
b_li.sort()
c_li.sort()

ans = 0

for i in a_li:
    s = bisect.bisect_right(b_li, i)
    
    for j in b_li[s:]:
        t = bisect.bisect_right(c_li, j)
        ans += n-t
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

a_li.sort()
b_li.sort()
c_li.sort()

if a_li[0] >= b_li[-1]:
    print(0)
    exit()
    
ans = 0

for i in a_li:
    s = bisect.bisect_right(b_li, i)
    
    for j in b_li[s:]:
        t = bisect.bisect_right(c_li, j)
        ans += len(c_li[t:])
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
ans=0

N,a,b,c=open(0).read().rstrip().split('\n')
N=int(N)
A=[int(i) for i in a.split()]
B=[int(i) for i in b.split()]
C=[int(i) for i in c.split()]
A.sort()
B.sort()
C.sort()

for i in A:
    if i>=B[-1]:
        break
    b_index=bisect.bisect_right(B,i)
    for j in B[b_index:]:
        if j>=C[-1]:
            break
        c_index=bisect.bisect_right(C,j)
        ans+=N-c_index
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
INF=10**100
ans=0

N,a,b,c=open(0).read().rstrip().split('\n')
N=int(N)
A=[int(i) for i in a.split()]
B=[int(i) for i in b.split()]
C=[int(i) for i in c.split()]
A.sort()
B.sort()
C.sort()

for i in A:
    if i>=B[-1]:
        break
    b_index=bisect.bisect_right(B,i)
    for j in B[b_index:]:
        if j>=C[-1]:
            break
        c_index=bisect.bisect_right(C,j)
        ans+=len(C[c_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()
B.sort()
C.sort()

ans = 0
for b in B:
    a_index = bisect.bisect_left(A, b)
    c_index = bisect.bisect_right(C, b)
    ans += len(A[:a_index])*len(C[c_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()
B.sort()
C.sort()

ans = 0
for a in A:
    b_index = bisect.bisect_right(B, a)
    for b in B[b_index:]:
        ans += len(C[bisect.bisect_right(C,b):])
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 l in a:
    m_idx = bisect.bisect_right(b, l)
    if m_idx == n:
        break
    for m in b[m_idx:]:
        l_idx = bisect.bisect_right(c, m)
        if l_idx == n:
            break
        ans += n - l_idx

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect

n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
b = list(map(int, sys.stdin.buffer.readline().split()))
c = list(map(int, sys.stdin.buffer.readline().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in a:
    for j in range(bisect(b, i), n):
        ans += n - bisect(c, b[j])
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()
cnt = 0
for i in range(n):
    for j in range(bisect.bisect_right(b, a[i]), n):
        cnt += n - bisect.bisect_right(c, b[j])

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect, bisect_left

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

for l in [a, b, c]:
    l.sort()

ans = 0
for b_item in b:
    l = bisect_left(a, b_item)
    r = bisect(c, b_item)
    ans += len(a[:l]) * len(c[r:])
print(ans)

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

for l in [a, b, c]:
    l.sort()

ans = 0
for a_item in a:
    l = bisect(b, a_item)
    for b_item in b[l:]:
        r = bisect(c, b_item)
        ans += len(c[r:])
print(ans)