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

count = 0
for i in a:
  for j in range(bisect.bisect(b, i), len(b)):
    count += len(b) - bisect.bisect(c, b[j])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

count = 0
for i in a:
  for j in range(bisect.bisect(b, i), len(b)):
    for k in range(bisect.bisect(c, b[j]), len(c)):
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

count = 0
lenB = len(B)
lenC = len(C)
for a in A:
  startB = bisect.bisect_right(B, a)
  for i in range(startB, lenB):
    count += lenC - bisect.bisect_right(C, B[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

count = 0
lenB = len(B)
lenC = len(C)
for a in A:
  for i in range(bisect.bisect_right(B, a), lenB):
    count += lenC - bisect.bisect_right(C, B[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    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()

    ret = 0
    for a in A:
        ib = bisect_right(B,a)
        for b in B[ib:]:
            ic = bisect_right(C,b)
            ret += N - ic
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import bisect

m=0
for i in a:
    x=bisect.bisect_right(b,i)
    for j in range(x,n):
        y=bisect.bisect_right(c,b[j])
        m+=n-y
print(m)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        a_ind = bisect.bisect_left(a, bi)
        a_oks = a[:a_ind]
        c_ind = bisect.bisect_right(c, bi)
        c_oks = c[c_ind:]
        ans += len(a_oks) * len(c_oks)
    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def is_ok(l, i, key):
    if l[i] > key:
        return True


def binary_seach(l, key):
    left = -1
    right = len(l)

    while right - left > 1:
        mid = left + (right - left) // 2
        if is_ok(l, mid, key):
            right = mid
        else:
            left = mid

    return right


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    # すべてのaに対して条件を満たすbを探索(O(N) * O(log N))
    for ai in a:
        b_ind = binary_seach(b, ai)
        ok_b = b[b_ind:]
       # そのbに対して条件を満たすcを探索(O(log N))
        for bi in ok_b:
            c_ind = binary_seach(c, bi)
            ok_c = c[c_ind:]
            ans += len(ok_c)
    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
def binarySearchLeft(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == 0 or target != nums[mid - 1]:
                return mid
            else:
                high = mid - 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return low

def solve(N, A, B, C):
     A.sort()
     B.sort()
     C.sort()
     ret = 0
     for a in A:
         b_idx = binarySearchLeft(B, a + 1)
         if not (0 <= b_idx < N):
             continue
         for j in range(b_idx, N):
             c_idx = binarySearchLeft(C, B[j] + 1)
             ret += N - c_idx if 0 <= c_idx < N else 0
     print(ret)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    solve(N, A, B, C)

Submission status: Time Limit Exceeded

Solution code:
#ABC077-C
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
ans=0
for i in range(N):
    b=B[i]
    if A[-1]<b:
        a_comb=N
    elif A[0]>=b:
        a_comb=0
    elif A[0]<b and A[1]>=b:
        a_comb=1
    else:
        p=N//2
        while True:
            if A[p]<b and A[p+1]>=b:
                a_comb=p+1
                break
            elif A[p]<b and A[p+1]<b:
                p=(N+p)//2
                continue
            elif A[p]>=b:
                p=(p+1)//2
                continue
    if C[0]>b:
        c_comb=N
    elif C[-1]<=b:
        c_comb=0
    elif C[-1]>b and C[-2]<=b:
        c_comb=1
    else:
        p=N//2
        while True:
            if C[p]>b and C[p-1]<=b:
                c_comb=N-p
                break
            elif C[p]>b and C[p-1]>b:
                p=(p+1)//2
                continue
            elif C[p]<=b:
                p=(N+p)//2
                continue
    ans+=a_comb*c_comb
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N=int(input())
ue=list(map(int,input().split()))
naka=list(map(int,input().split()))
sita=list(map(int,input().split()))
ue.sort(),sita.sort(),naka.sort()
count=0
stop=[0]*N
for i in range(N):
    k=naka[i]
    stop_index=bisect.bisect_right(sita,k)
    if stop_index!=N:
        stop[i]=N-stop_index
for i in range(N):
    k=ue[i]
    a=bisect.bisect_right(naka,k)
    if a!=N:
        count+=sum(stop[a:N])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N=int(input())
ue=list(map(int,input().split()))
naka=list(map(int,input().split()))
sita=list(map(int,input().split()))
ue.sort(),sita.sort(),naka.sort()
count=0
stop=[N]*N
for i in range(N):
    k=naka[i]
    stop_index=bisect.bisect_right(sita,k)
    if stop_index!=N:
        stop[i]=N-stop_index
for i in range(N):
    k=ue[i]
    a=bisect.bisect_right(naka,k)
    if a!=N:
        for j in range(a,N):
            count+=stop[j]
print(count)

Submission status: Time Limit Exceeded

Solution code:
# ABC077C

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

bC=[0 for i in range(N)]
for i in range(N):
    bC[i]=N-bisect.bisect(C,B[i])
    
ans=0
for i in range(N):
    x=bisect.bisect(B,A[i])
    for j in range(x,N):
        ans+=bC[j]
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
    Lists.append(s)
def bin(right,left,i,j):
    global ans
    while(right >= left):
        mid =int(left + (right-left) / 2)
        if(i>=Lists[j][mid]):
            left = mid + 1
        else:
            right = mid - 1
    if(j == 2 and left <= N-1):
        ans += N-left
    elif(left <= N-1):
        for k in range(left,N):
            bin(N-1,0,Lists[j][k],j+1)
for i in Lists[0]:
    bin(N-1,0,i,1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    #N = [list(map(int, input().split())) for i in range(3)]

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

    import bisect
    cnt = 0
    for ai in range(n):
        j = bisect.bisect_right(B, A[ai])

        for bi in range(j, n):
            k = bisect.bisect_right(C, B[bi])
            cnt += n - k
        #print(cnt)

    print(cnt)
    # print(A)
    # print(B)
    # print(C)

resolve()

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

lal = sorted(al,reverse = True)
lbl = sorted(bl,reverse = True)
lcl = sorted(cl,reverse = True)



d =[0]*n

for i in range(n):
    x = lbl[i]
    for j in range(n):
        y = lal[j]
        if x > y:
            d[i] = (n-j)
            break
        
res =0
for i in range(n):
    x = lcl[i]
    for j in range(n):
        y = lbl[j]
        if x >y:            
            res += sum(d[j:])
            break

print(res)

Submission status: Time Limit Exceeded

Solution code:
# C - Snuke Festival
# https://atcoder.jp/contests/abc077/tasks/arc084_a

n = int(input())

a = []
for i in range(3):
    a.append(list(map(int,input().split())))

top = sorted(a[0])
mid = sorted(a[1])
und = sorted(a[2])

c = 0

for m in mid:
    for i in range(n):
        if  top[i] < m:
            for j in range(n):
                if und[j] > m:
                    c += 1
                    
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

cnt = 0
for b in range(N):
    cntab = 0
    for a in range(N):
        if al[a] < bl[b]:
            cntab += 1
    cntbc = 0
    for c in range(N):
        if bl[b] < cl[c]:
            cntbc += 1
    cnt += cntab*cntbc
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

cnt = 0
for a in range(N):
    for b in range(N):
        for c in range(N):
            if al[a] < bl[b] < cl[c]:
                cnt += 1
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())))

from bisect import bisect_left, bisect

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

count = 0
for i in range(n):
    for j in range(n):
        if b[j] < a[i]:
            continue
        for k in range(n):
            if c[k] < b[j]:
                continue
            if a[i] < b[j] < c[k]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
a = []
b = []
c = []

for i in range(3):
    p = input().split()
    if i==0:
        for j in range(n):a.append(int(p[j]))
    elif i==1:
        for j in range(n):b.append(int(p[j]))
    else:
        for j in range(n):c.append(int(p[j]))

count = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i] < b[j] < c[k]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for i in range(len(C)):
    b = bisect.bisect_left(B,C[i])
    if b == 0:
        continue
    for j in range(b):
        a = bisect.bisect_left(A,B[j])
        ans += a
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from collections import defaultdict

N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
num_a = 0
num_c = 0
res = 0
pre_b = -1

dict_C = defaultdict(int)

for b in B:
    dict_C[b] = C.count(b)


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) # a < b となるAの要素数
    pre_num_c = bisect_left(C, b)
    num_c = N - pre_num_c # c > b となるAの要素数
    if pre_num_c != N and C[pre_num_c] == b:
        num_c -= dict_C[b]
    res += num_a * num_c
    pre_b = b
print(res)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from collections import defaultdict

N = int(input())

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

res = 0
pre_b = -1

num_a = defaultdict(int)
pre_num_c = defaultdict(int)
dict_C = defaultdict(int)

for b in B:
    dict_C[b] = C.count(b)
    num_a[b] = bisect_left(A, b)
    pre_num_c[b] = bisect_left(C, b)

for b in B:
    if b == pre_b:
        res += num_a_b * num_c_b
        continue
    num_a_b = num_a[b] # a < b となるAの要素数
    num_c_b = N - pre_num_c[b] # c > b となるAの要素数
    if pre_num_c[b] != N and C[pre_num_c[b]] == b:
        num_c_b -= dict_C[b]
    res += num_a_b * num_c_b
    pre_b = b
print(res)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
num_a = 0
num_c = 0
res = 0
pre_b = -1

for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) # a < b となるAの要素数
    pre_num_c = bisect_left(C, b)
    num_c = N - pre_num_c # c > b となるAの要素数
    if pre_num_c != N and C[pre_num_c] == b:
        num_c -= C.count(b)
    res += num_a * num_c
    pre_b = b
print(res)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
num_a = 0
num_c = 0
res = 0

for b in B:
    num_a = bisect_left(A, b) # a < b となるAの要素数
    pre_num_c = bisect_left(C, b)
    num_c = N - pre_num_c # c > b となるAの要素数
    if pre_num_c != N and C[pre_num_c] == b:
        num_c -= C.count(b)
    res += num_a * num_c
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
S = [sorted(li()) for _ in range(3)]
rec = [[0]*N for i in range(2)]

for i in range(N):
    for j in range(2):
        rec[j][i] = bisect.bisect_right(S[j+1], S[j][i])

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

print(ans)

Submission status: Time Limit Exceeded

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

a = [A,B,C]
permutation = list(itertools.product(*a))

cnt = 0
for i in permutation:
    if i[0] < i[1] < i[2]:
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(len(b)):
    al = 0
    ar = n-1
    while True:
        if a[-1] < b[i]:
            an = n
            break
        if a[0] >= b[i]:
            an = 0
            break
        am = (al+ar)//2
        if a[am] < b[i]:
            al = am
        else:
            ar = am
        an = al + 1
        if al+1 == ar:
            break
    cl = 0
    cr = n-1
    while True:
        if c[0] > b[i]:
            cn = n
            break
        if c[-1] <= b[i]:
            cn = 0
            break
        cm = (cl+cr)//2
        if c[cm] <= b[i]:
            cl = cm
        else:
            cr = cm
        cn = n - cr
        if cl+1 == cr:
            break
    ans += an*cn
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#ABC077C
def main():
    import sys, bisect
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    C = list(map(int, sys.stdin.readline().split()))
    
    A.sort()
    B.sort()
    C.sort()
    #print(A, B, C)
    ans = 0
    for i in range(N):
        idxB = bisect.bisect_right(B, A[i])
        for j in range(idxB, N):
            idxC = bisect.bisect_right(C, B[j])
            #print(A[i],B[j], (N-idxC))
            ans +=(N-idxC)
    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()))

ans = 0
for c in C:
    for b in B:
        for a in A:
            if c > b & b > a:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

def binary_search(ys,target,low,high,reverse=True):
    xs = sorted(ys)
    maxlen = len(xs)

    middle = 0
    #print("array => %s, target => %d" %(xs,target))
    while(low <= high):
        middle = (low + high) // 2
        #print("target %d, low %d, mid %d, high %d" %(target,low,middle,high))
        if xs[middle] == target:
             #print("find ",middle)
            if reverse == False:
                return middle
            else:
                return middle+1
        if xs[middle] > target:
            high = middle - 1
        elif xs[middle] < target:
            low = middle + 1

    middle = (low + high) // 2 +1
   # print("target %d, low %d, mid %d, high %d" %(target,low,middle,high))
    return middle
    


def snuke_festival(a,b,c):
    count = 0
    b_sorted = sorted(b)
    high = len(b)-1
    low = 0
    ab = 0
    bc = 0
    mid_a = 0
    mid_b = 0
    maxlen=len(b)
    for n in range(maxlen):
        mid_a = binary_search(a,b_sorted[n],mid_a,high,False)
        ab = mid_a
        mid_b = binary_search(c,b_sorted[n],low,mid_b,True)
        bc = maxlen - mid_b
        count += ab * bc
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(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(" "))))

count = 0
for i in b:
  #print((a[:bisect.bisect(a, i - 1)]), i, c[bisect.bisect_left(c, i + 1):]) 
  count += len(a[:bisect.bisect(a, i - 1):]) * len(a[bisect.bisect_right(c, i):]) 
print(count)

Submission status: Time Limit Exceeded

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

def binary_search(ys,target,reverse=True):
    xs = sorted(ys)
    low = 0
    maxlen = len(xs)
    high = len(xs)-1
    middle = 0
    #print("array => %s, target => %d" %(xs,target))
    while(low <= high):
        middle = (low + high) // 2

        if xs[middle] == target:
            #print("find ",middle)
            if reverse == False:
                return middle
            else:
                return maxlen - middle - 1
        elif xs[middle] > target:
            high = middle - 1
        elif xs[middle] < target:
            low = middle + 1

    middle = (low + high) // 2
    if reverse == False:
        return middle + 1
    else:
        return maxlen - middle - 1


def snuke_festival(a,b,c):
    count = 0
    b_sorted = sorted(b)
    for n in b_sorted:
        ab = 0
        bc = 0
        ab = binary_search(a,n,False)
        bc = binary_search(c,n,True)
        count += ab * bc
        #print("%d * %d = %d, count = %d" %(ab, bc,ab*bc,count))
        #print("")
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(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(" "))))

count = 0
for i in a:
  for j in b[bisect.bisect_left(b, i + 1):]:
    #for k in c[bisect.bisect_left(c, j):]:
    #print(i, j, c[bisect.bisect_left(c, j + 1):])
    count += len(c[bisect.bisect_left(c, j + 1):])
print(count)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
import numpy as np

n = int(input())

top = map(int, input().split())
mid = map(int, input().split())
bot = map(int, input().split())
top = np.array(sorted(top))
mid = np.array(sorted(mid))
bot = np.array(sorted(bot))

ans = 0
for i in top:
    for j in mid[bisect_right(mid,i):]:
        ans += len(bot[bisect_right(bot,j):])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
count=0
import bisect
for i in range(0,n):
  tempb=bisect.bisect_right(b,a[i])
  if tempb!=len(b):
    for j in range(tempb,n):
      tempc=bisect.bisect_right(c,b[j])
      tempcl=n-tempc
      count=count+tempcl
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
BC,ans=[0 for _ in range(n)],0
C=list(map(int,input().split()))
C.sort()

for i in range(n):
  left,right=-1,n
  
  while right - left > 1:
    mid = (left + right) // 2
    
    if B[mid] > A[i]:
      right = mid
    else:
      left = mid
  k = right
  
  for j in range(k,n):
    if BC[j]:
      ans += BC[j]
      continue
    
    left,right=-1,n
    
    while right - left > 1:
      mid = (left + right) // 2
      
      if C[mid] > B[j]:
        right = mid
      else:
        left = mid
        
    ans += (n - right)
    BC[j] = n - right
    
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()))

B.sort()
C.sort()
ans = 0
for a in A:
    b_index = bisect_right(B, a)
    if b_index == len(B):
        continue
    b_cnt = len(B)-b_index

    for b in B[b_index:]:
        c_index = bisect_right(C, b)
        if c_index == len(C):
            continue
        c_cnt = len(C)-c_index

        ans += c_cnt
print(ans)

Submission status: Time Limit Exceeded

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

def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    c_sorted = sorted(c)

    for n in b:
        ab = 0
        bc = 0
        for i in a_sorted:
            if n > i:
                ab += 1

        for i in c_sorted:
            if n < i:
                bc += 1

        count += ab * bc
    return count
        
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

Submission status: Time Limit Exceeded

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

def is_saidan(parts):
    tmp = 0
    for j in parts:
        if j > tmp:
            tmp = j
        else:
            break
    else:
        return True
    return False

def snuke_festival(a,b,c):
    comb = list(itertools.product(a,b,c))
    count = 0
    for i in comb:
        if is_saidan(i):
            count += 1
    return count
        
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

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() ) )
# print(d,n,m)
# print(A_list)
# print(B_list)
# print(C_list)

import numpy as np

A_np = np.array(A_list)
C_np = np.array(C_list)

sum_conbi = 0
for B in B_list:
    sum_conbi += np.count_nonzero(A_np < B) * np.count_nonzero(C_np > B)

print(sum_conbi)

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() ) )
# print(d,n,m)
# print(A_list)
# print(B_list)
# print(C_list)

A_sort = sorted(A_list)
C_sort = sorted(C_list)
# print(A_sort)
# print(C_sort)

import numpy as np

A_np = np.array(A_sort)
C_np = np.array(C_sort)

sum_conbi = 0
for B in B_list:
    a_result = A_np[A_np < B]
    c_result = C_np[C_np > B]

    # print(a_result)
    # print(c_result)

    sum_conbi += len(a_result) * len(c_result)

print(sum_conbi)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
X = []
for b in B:
    X.append(len(C[bisect_right(C, b):]))
X.reverse()
Acc = list(accumulate(X))
Acc.reverse()
for a in A:
    tmp = bisect_right(B, a)
    if tmp < len(Acc):
        ans += Acc[tmp]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for a in A:
    for b in B[bisect_right(B, a):]:
        ans += len(C[bisect_right(C, b):])
print(ans)