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 search(key, L):
    inc = -1
    exc = N
    while abs(inc-exc) > 1:
        mid = (inc+exc) // 2
        if True if L[mid] <= key else False:
            inc = mid
        else:
            exc = mid
    return exc


def main():
    ans = 0
    for a in A:
        for i in range(search(a, B), N):
            ans += N - search(B[i], C)
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A = [int(a) for a in input().split()]
    B = sorted([int(b) for b in input().split()])
    C = sorted([int(c) for c in input().split()])
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect
def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    b.sort()
    c.sort()
    r = 0
    a_index_inB = [bisect(b, ea) for ea in a]
    b_larger_inC = [n - bisect(c, eb) for eb in b]
    for aiie in a_index_inB:
        r += sum(b_larger_inC[aiie:])

    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A.sort()
B.sort()
C.sort()
length = len(A)
#A<B<Cの組み合わせの数が答え
for i in range(length):
    #Aを1つ決めた時、BがA以下の値
    A_miman = bisect.bisect_right(B,A[i])
    for j in range(A_miman,N):
        #Bを1つ決めた時、CがBより大きい値の数をansに足す
        ans += N - bisect.bisect_right(C, B[j])
        


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A.sort()
B.sort()
C.sort()
#A<B<Cの組み合わせの数が答え
for i in range(len(A)):
    #Aを1つ決めた時、BがA以下の値
    A_miman = bisect.bisect_right(B,A[i])
    for j in range(A_miman,N):
        #Bを1つ決めた時、CがBより大きい値の数をansに足す
        ans += N - bisect.bisect_right(C, B[j])
        


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

for i in range(len(A)):
    #Aを1つ決めた時、BがA以下の値
    A_miman = bisect.bisect_right(B,A[i])
    for j in range(A_miman,N):
        #Bを1つ決めた時、CがBより大きい値
        ans += N - bisect.bisect_right(C, B[j])
        


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

for i in range(len(A)):
    #Aを1つ決めた時、BがA以下の値
    A_miman = bisect.bisect_right(B,A[i])
    for j in range(A_miman,N):
        #Bを1つ決めた時、CがB以上の値
        over_B = N - bisect.bisect_right(C, B[j])
        ans += over_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.append(10 ** 10)
B.append(10 ** 10)
C.append(10 ** 10)

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

i, j, k = 0, 0, 0
count = 0
total = []
result = 0

while i < N:
    while C[i] > B[j] and j < N:
        while B[j] > A[k] and k < N:
            count += 1
            k += 1
        total.append(count)
        j += 1
    result += sum(total)
    i += 1

print(result)

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 find(num, lst):
    lst2 = [0]+lst
    left = 0
    right = len(lst2)
    while left+1<right:
        mid = (left+right)//2
        if lst2[mid]<=num:
            left = mid
        else:
            right = mid
    return right-1

ans = 0

for a in A:
    minB = find(a, B)
    for b in B[minB:]:
        minC = find(b, C)
        ans += (n-minC)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from bisect import bisect
    import sys
    sys.setrecursionlimit(200000)

    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:
        bIdx = bisect(B,a)
        if N - bIdx > 0:
            for j in range(bIdx,N):
                b = B[j]
                cIdx = bisect(C,b)
                if N - cIdx > 0:
                    ans += N-cIdx

    print(ans)
main()

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())))
ans = 0
for a in A:
    bIdx = bisect(B,a)
    if N - bIdx > 0:
        for j in range(bIdx,N):
            b = B[j]
            cIdx = bisect(C,b)
            if N - cIdx > 0:
                ans += N-cIdx

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()))
AB = []
total = 0
for i in range(len(B)):
  count = 0
  for j in range(len(A)):
    if A[j]<B[i]:
      count+=1
  AB.append(count)
for i in range(len(C)):
  for j in range(len(B)):
    if B[j]<C[i]:
      total+=AB[j]
print(total)

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

Clen = len(C)

total = 0

for i in A:
    Bmin = bisect.bisect_right(B, i)
    for j in B[Bmin :]:
        total += Clen - bisect.bisect_right(C, j)

print(total)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

N = int(readline())
tmp = list(map(int,input().split()))
A = []  
[bisect.insort_right(A, x) for x in tmp]
B = list(map(int,readline().rstrip().split()))
#B = []
#[bisect.insort_right(B,x) for x in tmp ]
C = list(map(int,readline().rstrip().split()))
#C = []
#[bisect.insort_right(C,x) for x in tmp]

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

listb = []
for i , b in enumerate(B[::-1]):
    if i == 0:
        listb.append(N - bisect.bisect_right(C,b))
    else:
        listb.append(N - bisect.bisect_right(C,b) + listb[i-1])

ans = 0
for a in A :
    indexb = bisect.bisect_right(B,a)
    if indexb == N :
        break
    ans += listb[N-1 - indexb]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def binary_search1(key, a):
    left = -1 # index = 0 が条件を満たすこともあるので初期値は−１
    right = len(a) # index = len(a) -1 が条件満たさないこともある

    # どんな二分探索でもここの書き方を変えずにできる
    while right - left > 1 :
        mid = left + ((right - left + 1) // 2)
        if a[mid] >= key: 
            right = mid
        else:
            left = mid
    return right

def binary_search2(key, a):
    left = -1 # index = 0 が条件を満たすこともあるので初期値は−１
    right = len(a) # index = len(a) -1 が条件満たさないこともある

    # どんな二分探索でもここの書き方を変えずにできる
    while right - left > 1 :
        mid = left + ((right - left + 1) // 2)
        if a[mid] > key:
            right = mid
        else:
            left = mid
    return right

import sys

def main():

    _ = input()
    a_l = sorted(list(map(int, sys.stdin.readline().strip().split())))
    b_l = sorted(list(map(int, sys.stdin.readline().strip().split())))
    c_l = sorted(list(map(int, sys.stdin.readline().strip().split())))
    cnt = 0
    for b in b_l:
        a_under_b_idx = binary_search1(b, a_l)
        c_upper_b_idx = binary_search2(b, c_l)
        cnt += len(a_l[:a_under_b_idx])*len(c_l[c_upper_b_idx:])
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

N = int(readline())
tmp = list(map(int,input().split()))
A = []  
[bisect.insort_right(A, x) for x in tmp]
tmp = list(map(int,readline().rstrip().split()))
B = []
[bisect.insort_right(B,x) for x in tmp ]
tmp = list(map(int,readline().rstrip().split()))
C = []
[bisect.insort_right(C,x) for x in tmp]

ans = 0
for b in B :
    indA = bisect.bisect_left(A,b)
    indC = bisect.bisect_right(C,b)
    ans += indA * (N-indC)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

N = int(readline())
tmp = list(map(int,input().split()))
A = []  
[bisect.insort_right(A, x) for x in tmp]
tmp = list(map(int,readline().rstrip().split()))
B = []
[bisect.insort_right(B,x) for x in tmp ]
tmp = list(map(int,readline().rstrip().split()))
C = []
[bisect.insort_right(C,x) for x in tmp]

listb = []
for i , b in enumerate(B[::-1]):
    if i == 0:
        listb.append(N - bisect.bisect_right(C,b))
    else:
        listb.append(N - bisect.bisect_right(C,b) + listb[i-1])

ans = 0
for a in A :
    indexb = bisect.bisect_right(B,a)
    if indexb == N :
        break
    ans += listb[N-1 - indexb]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

N = int(readline())
tmp = list(map(int,input().split()))
A = []  
[bisect.insort_right(A, x) for x in tmp]
tmp = list(map(int,readline().rstrip().split()))
B = []
[bisect.insort_right(B,x) for x in tmp ]
tmp = list(map(int,readline().rstrip().split()))
C = []
[bisect.insort_right(C,x) for x in tmp]

ans = 0
for a in A :
    indexb = bisect.bisect_right(B,a)
    if indexb == N :
        break
    for ib in range( indexb , N):
        indexc = bisect.bisect_right(C,B[ib])
        if indexc == N :
            break
        ans += (N-indexc)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# index が条件をみたかどうか
def isLess(index, key, a):
	if a[index] >= key:
		return True
	else: 
		return False
      
def isUpper(index, key, a):
	if a[index] > key:
		return True
	else: 
		return False
      
def binary_search(key, a, upper=True):
    left = -1 # index = 0 が条件を満たすこともあるので初期値は−１
    right= len(a) # index = len(a) -1 が条件満たさないこともある
 
    # どんな二分探索でもここの書き方を変えずにできる
    while right - left > 1 :
        mid = left + ((right - left + 1) // 2)
        if upper:
            if isUpper(mid, key, a): # isOKの名前でこの関数内の条件判定変えれば色々できそう
                right = mid
            else:
                left = mid
        else:
            if isLess(mid, key, a): # isOKの名前でこの関数内の条件判定変えれば色々できそう
                right = mid
            else:
                left = mid
    return right

import sys

def main():
    n = int(input())
    a_l = sorted(list(map(int, sys.stdin.readline().strip().split())))
    b_l = sorted(list(map(int, sys.stdin.readline().strip().split())))
    c_l = sorted(list(map(int, sys.stdin.readline().strip().split())))
    cnt = 0
    for b in b_l:
        a_under_b_idx = binary_search(b, a_l, upper=False)
        c_upper_b_idx = binary_search(b, c_l)
        cnt += len(a_l[:a_under_b_idx])*len(c_l[c_upper_b_idx:])
    print(cnt)
    
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
 
# index が条件をみたかどうか
def isLess(index, key, a):
	if a[index] >= key:
		return True
	else: 
		return False
      
def isUpper(index, key, a):
	if a[index] > key:
		return True
	else: 
		return False
      
def binary_search(key, a, upper=True):
    left = -1 # index = 0 が条件を満たすこともあるので初期値は−１
    right= len(a) # index = len(a) -1 が条件満たさないこともある
 
    # どんな二分探索でもここの書き方を変えずにできる
    while right - left > 1 :
        mid = left + ((right - left + 1) // 2)
        if upper:
            if isUpper(mid, key, a): # isOKの名前でこの関数内の条件判定変えれば色々できそう
                right = mid
            else:
                left = mid
        else:
            if isLess(mid, key, a): # isOKの名前でこの関数内の条件判定変えれば色々できそう
                right = mid
            else:
                left = mid
    return right
  
def main():
    n = int(input())
    a_l = sorted(list(map(int, input().split())))
    b_l = sorted(list(map(int, input().split())))
    c_l = sorted(list(map(int, input().split())))
    cnt = 0
    for b in b_l:
        a_under_b_idx = binary_search(b, a_l, upper=False)
        c_upper_b_idx = binary_search(b, c_l)
        cnt += len(a_l[:a_under_b_idx])*len(c_l[c_upper_b_idx:])
    print(cnt)
    
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a_l = sorted(list(map(int, input().split())))
    b_l = sorted(list(map(int, input().split())))
    c_l = sorted(list(map(int, input().split())))
    cnt = 0
    for a in a_l:
        for b in b_l:
            if b <= a: continue
            for c in c_l:
                if b >= c: continue
                cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
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()

import bisect
ans = 0

B_list = []
for b in B:
    B_list.append(bisect.bisect_left(A,b))

for c in C:
    b_bisect = bisect.bisect_left(B, c)
    for i, b in enumerate(B[:b_bisect]):
        #a_bisect = bisect.bisect_left(A,b)
        #の代わり
        a_bisect = B_list[i]
        ans += a_bisect 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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()

import bisect
ans = 0
for c in C:
    b_bisect = bisect.bisect_left(B, c)
    for b in B[:b_bisect]:
        a_bisect = bisect.bisect_left(A,b)
        ans += a_bisect 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

up_mid = [N - bisect.bisect_right(B, x) for x in A]
mid_down = [N - bisect.bisect_right(C, x) for x in B]

ans = 0
for i in up_mid:
    ans += sum(mid_down[::-1][:i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Beginner Contest 077 C - Snuke Festival　

import sys

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
B = list(map(int, sys.stdin.readline().strip().split()))
C = list(map(int, sys.stdin.readline().strip().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)


def search(i, S):  # i : search する数値  S: search対象の数列
    if S[0] > i:
        return len(S)
    if S[-1] <= i:
        return 0

    left = 0
    right = len(S) - 1

    while right - left != 1:
        # print(f'right:{right}, left:{left}')
        mid = int((left + right) / 2)
        if S[mid] <= i:
            left = mid
        else:
            right = mid

    return len(S) - (left + 1)


ans = 0
for a in A:
    b_num = search(a, B)
    if b_num == 0:
        continue
    for b in B[-b_num:]:
        # print(f'a: {a}, b: {b}')
        c_num = search(b, C)
        # print(f'c_num: {c_num}')
        # print(a, b, C[-c_num])
        ans += c_num

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

count = 0
for i in range(n):
    for j in range(bisect.bisect(B, A[i]), n):
        k = bisect.bisect(C, B[j])
        if k < n:
            count += (n - k)

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

q = deque()
for i in a:
    q.append([i])

ans = 0
while q:
    now = q.popleft()
    n = len(now)
    if n == 3:
        ans += 1
    elif n == 2:
        for x in c:
            if now[-1] < x:
                q.append(now + [x])
    elif n == 1:
        for y in b:
            if now[-1] < y:
                q.append(now + [y])

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())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)


def dfs(parts):
    global ans
    n = len(parts)
    if n == 3:
        ans += 1
    elif n == 2:
        for i in c:
            if parts[1] < i:
                dfs(parts + [i])
            else:
                break
    elif n == 1:
        for j in b:
            if parts[0] < j:
                dfs(parts + [j])
            else:
                break


ans = 0
for i in a:
    dfs([i])

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


def dfs(parts):
    global ans
    n = len(parts)
    if n == 3:
        ans += 1
    elif n == 2:
        for i in c:
            if parts[1] < i:
                dfs(parts + [i])
    elif n == 1:
        for j in b:
            if parts[0] < j:
                dfs(parts + [j])


ans = 0
for i in a:
    dfs([i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
a = LI()
a.sort()
b = LI()
b.sort()
c = LI()
c.sort()

def bsearch(p, x):
    left = 0
    right = len(p)-1
    while(left <= right):
        mid = (left + right) // 2
        if(p[mid] == x):
            return mid + 1
        elif(p[mid] < x):
            left = mid + 1
        else:
            right = mid - 1
    return left

count = 0
for i in a:
    x = bsearch(b,i)
    for j in range(x,n):
        y = bsearch(c,b[j])
        count += n - y

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

import bisect
a.sort()
b.sort()
c.sort()
ans = 0

comb = []
for i in range(len(b)):
    key = bisect.bisect_left(c,b[i]+1)
    comb.append(len(c) -key)
comb.append(0)
combsum = []
for i in range(len(comb)):
    x = sum(comb[i:])
    combsum.append(x)
for A in a:
    key_b = bisect.bisect_left(b,A+1)
    ans += combsum[key_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()))

import bisect
a.sort()
b.sort()
c.sort()
ans = 0

comb = []
for i in range(len(b)):
    key = bisect.bisect_left(c,b[i]+1)
    comb.append(len(c) -key)
comb.append(0)
for A in a:
    key_b = bisect.bisect_left(b,A+1)
    ans += sum(comb[key_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()))

import bisect
a.sort()
b.sort()
c.sort()
ans = 0
for A in a:
    key_b = bisect.bisect_left(b,A+1)
    if key_b == len(b):
        continue
    for i in range(key_b,len(b)):
        key_c = bisect.bisect_left(c,b[i]+1)
        ans += len(c) - key_c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
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())))
cnt=0

for i in range(0,len(c)):
    b_index=bisect.bisect_left(b,c[-i-1])
    for u in range(b_index):
        cnt+=bisect.bisect_left(a,b[b_index-1-u])
    
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()))

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

ans = 0
ai= 0
ci = n-1
for b_ in b:
    ai= 0
    ci = n-1
    while ai < n and a[ai] < b_:
        ai += 1
    while ci >= 0  and c[ci] > b_:
        ci -= 1
    ans += ai * (n-1-ci)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

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

ans = 0
y_low = {}
i = 0
for x in A:
    y_low[i] = bisect_right(B, x)
    i += 1
for y_lowi in y_low.values():
    for y in B[y_lowi:]:
        z_low = bisect_right(C, y)
        ans += N - z_low
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

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
y_low = 0
z_low = 0
for x in A:
    y_low = bisect_right(B, x)
    for y in B[y_low:]:
        z_low = bisect_right(C, y)
        ans += N - z_low
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

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 x in A:
    y_low = bisect_right(B, x)
    for y in B[y_low:]:
        z_low = bisect_right(C, y)
        ans += N - z_low
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
def find_ge(a, x):
    i = bisect.bisect_right(a,x)
    return i
    
def solve(n, a, b, c):

    b_count = [0]*len(b)
    for i, x in enumerate(b):
        b_count[i] = len(c) - find_ge(c, x)

    ans = 0
    for i in a:
        x = find_ge(b, i)
        ans += sum(b_count[x:])
        
    return ans

if __name__ == "__main__":
    n = int(input())
    a = sorted([int(i) for i in input().split()])
    b = sorted([int(i) for i in input().split()])
    c = sorted([int(i) for i in input().split()])
    print(solve(n, a, b, c))

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

cnt = 0


for b in B :
    a_cnt = len(A[:bisect.bisect_left(A,b)])
    c_cnt = len(C[bisect.bisect_right(C,b):])
    cnt += a_cnt * c_cnt
    
print(cnt)

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

cnt = 0

for a in A:
    for b in B[bisect.bisect_right(B,a):]:
        cnt += len(C[bisect.bisect_right(C,b):])
        #for c in C [bisect.bisect_left(C,b):]:
            #if a < b < c :
                #cnt += 1

print(cnt)

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

cnt = 0

for a in A:
    for b in B[bisect.bisect_left(B,a):]:
        for c in C [bisect.bisect_left(C,b):]:
            if a < b < c :
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
input = sys.stdin.readline
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:
  x=bisect.bisect_left(b,i)
  for j in range(x):
    y=bisect.bisect_left(a,b[j])
    ans+=y
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()))

c.sort()

### 二分探索
ans = 0
for i in range(n):
    for j in range(n):
        if a[i] < b[j]:
            for k in range(len(c)):
                low = 0
                high = len(c) - 1
                item = c[k]

                while low <= high:
                    mid = (low + high) //2
                    guess = c[mid]
                    if guess == item:
                        break
                    if guess > item:
                        high = mid -1
                    else:
                        low = mid + 1

                if c[mid] > b[j]:
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left,bisect_right
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
    for j in range(n):
        if a[i]>=b[j]:
            continue
        else:
            ans+=n-bisect_left(c,b[j]+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left,bisect_right
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for A in a:
    indexB=bisect_left(b,A+1)
    for B in b[indexB:]:
        indexC=bisect_left(c,B+1)
        for C in c[indexC:]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

n = int(readline())
a = np.array(readline().split(), dtype=np.int64)
b = np.array(readline().split(), dtype=np.int64)
c = np.array(readline().split(), dtype=np.int64)

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

cnt=0
for i in range(n):
  B=b[i]
  AA=np.searchsorted(a, B-0.1, side='right')
  CC=n-np.searchsorted(c, B+0.1)
  cnt+=AA*CC
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=np.array(sorted(list(map(int,input().split()))))
b=sorted(list(map(int,input().split())))
c=np.array(sorted(list(map(int,input().split()))))
#cnt=0
#for i in range(n):
 # B=b[i]
  #A=[a[i] for i in range(n) if a[i]<B]
  #C=[c[i] for i in range(n) if c[i]>B]
  #cnt+=len(A)*len(C)
#print(cnt)

cnt=0
for i in range(n):
  B=b[i]
  AA=np.searchsorted(a, B-0.1, side='right')
  CC=n-np.searchsorted(c, B+0.1)
  cnt+=AA*CC
print(cnt)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(n):
  B=b[i]
  AA=np.searchsorted(a, B-0.1, side='right')
  CC=n-np.searchsorted(c, B+0.1)
  cnt+=AA*CC
print(cnt)

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

import bisect

count_B = {}
count_C = {}


for b in B:
    count_C[b] = N - bisect.bisect_right(C, b)

count = 0
for a in A:
    for b in B[bisect.bisect_right(B, a):]:
        count += count_C[b]
        # print(a, b)
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from bisect import bisect_left
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in c:
        j = bisect_left(b, i)
        for k in b[:j]:
            l = bisect_left(a, k)
            ans += l

    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.sort()
B.sort()
C.sort()
ans = 0
def func(array, value):
  ng = -1
  ok = len(array)
  #if value
  while ok - ng > 1:
    mid = (ok + ng)//2
    if array[mid] < value:
      ng = mid
    elif array[mid] >= value:
      ok = mid
  return ok
for a in A:
  b_idx = func(B, a + 1)
  if b_idx == len(B):
    break
  #print('a', a)
  #print('B[b_idx:]',B[b_idx:])
  for b in B[b_idx:]:
    c_idx = func(C, b + 1)
    #print('b',b)
    #print('C[c_idx:]',C[c_idx:])
    if c_idx == len(C):
      break
    #print(a, b_idx, c_idx)
    ans += len(C) - c_idx
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()
ans = 0
def func(array, value):
  ng = -1
  ok = len(array)
  #if value
  while ok - ng > 1:
    mid = (ok + ng)//2
    if array[mid] < value:
      ng = mid
    elif array[mid] >= value:
      ok = mid
  return ok
for a in A:
  b_idx = func(B, a + 1)
  if b_idx == len(B):
    continue
  #print('a', a)
  #print('B[b_idx:]',B[b_idx:])
  for b in B[b_idx:]:
    c_idx = func(C, b + 1)
    #print('b',b)
    #print('C[c_idx:]',C[c_idx:])
    if c_idx == len(C):
      continue
    #print(a, b_idx, c_idx)
    ans += len(C) - c_idx
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
alis = sorted(list(map(int, input().split())))
blis = sorted(list(map(int, input().split())))
clis = sorted(list(map(int, input().split())))
bc = [0]*n
for i in range(n):
    bc[i] = n - bisect.bisect_right(clis, blis[i])
ans = 0
for i in range(n):
    index = bisect.bisect_right(blis, alis[i])
    ans += sum(bc[index:])
print(ans)