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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/22
Solved on 2019/3/
@author: shinjisu
"""


# ABC 077 C Festival
import collections
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    B = getIntList()
    d.dmp((B), 'B')
    C = getIntList()
    d.dmp((C), 'C')
    aParts = sorted(A)
    bParts = sorted(B)
    cParts = sorted(C)
    d.dmp((aParts), 'A')
    d.dmp((bParts), 'B')
    d.dmp((cParts), 'C')
    combAB = zeros(N)
    combBC = zeros(N)
    j = 0
    for i in range(N):
        while j < N and bParts[j] <= aParts[i]:
            j += 1
            #d.dmp((i,j),'in while')
        combAB[i] = N-j
        #d.dmp((i,j),'in for')
    d.dmp((combAB), 'combAB')
    j = 0
    for i in range(N):
        while j < N and cParts[j] <= bParts[i]:
            j += 1
        combBC[i] = N-j
    d.dmp((combBC), 'combBC')
    count = 0
    for i in range(N):
        #d.dmp((N-combAB[i]), 'N-combAB[i]')
        count += sum(combBC[N-combAB[i]:])
        #d.dmp((count), 'count')
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/22
Solved on 2019/3/
@author: shinjisu
"""


# ABC 077 C Festival
import collections
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    B = getIntList()
    d.dmp((B), 'B')
    C = getIntList()
    d.dmp((C), 'C')
    aParts = collections.Counter(A)
    bParts = collections.Counter(B)
    cParts = collections.Counter(C)
    d.dmp((aParts), 'A')
    d.dmp((bParts), 'B')
    d.dmp((cParts), 'C')
    count = 0
    prevB = 0
    prevC = 0
    for i in aParts.keys():
        aCount = aParts[i]
        bCount = 0
        for j in bParts.keys():
            cCount = 0
            if j > i:
                bCount = bParts[j]
                prevB = j
                for k in cParts.keys():
                    if k > j:
                        cCount = cParts[k]
                        prevC = k
                        count += aCount*bCount*cCount
#                        d.dmp((i,j,k),'i,j,k')
 #                       d.dmp((aCount,bCount,cCount),'aCount,bCount,cCount')
  #                      d.dmp(count,'count')
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
ans = 0
n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))
for i in range(n):
    ans += np.sum(a < b[i]) * np.sum(c > b[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array([sorted(list(map(int, input().split()))) for _ in range(3)])
ans = 0
for i in range(n):
    ans += np.sum(a[0] < a[1][i]) * np.sum(a[2] > a[1][i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
As = sorted(list(map(int,input().split())))
Bs = sorted(list(map(int,input().split())))
Cs = sorted(list(map(int,input().split())))
ans = 0
for a in As:
    bindex = bisect.bisect_right(Bs, a)
    Bkouho = Bs[bindex:]
    for b in Bkouho:
        cindex = bisect.bisect_right(Cs, b)
        ans += len(Cs)-cindex
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect

def main():
    input = sys.stdin.readline
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    Bn = [0] * N
    for i in range(N):
        b = B[i]
        m = bisect(C, b)
        Bn[i] = (N - m)

    ans = 0
    for i in range(N):
        a = A[i]
        m = bisect(B, a)
        ans += sum(Bn[m:])

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect

def main():
    input = sys.stdin.readline
    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:
        n = bisect(B, a)
        for b in B[n:]:
            m = bisect(C, b)
            ans += (N - m)

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect

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

    ans = 0
    for a in A:
        for b in B:
            for c in C:
                if a < b < c:
                    ans += 1

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [list(map(int,input().split())) for i in range(3)]
c = 0

for i in range(n):
        t = sum(x < s[1][i] for x in s[0])
        h = sum(x > s[1][i] for x in s[2])
        c = c + t * h

print(c)

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):
    b_idx = bisect.bisect_right(B, A[i])
    for j in range(b_idx, N):
        c_idx = bisect.bisect_right(C, B[j])
        count += N - c_idx

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect as bs
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:
    _b = bs.bisect_right(B, a)
    for b in range(_b, N):
        ans += N - bs.bisect(C, B[b])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(s) for s in input().split()]
    b = [int(s) for s in input().split()]
    c = [int(s) for s in input().split()]
    print(solve(n, a, b, c))

def solve(n, a, b, c):
    d = [c, b, a]
    dp = []
    dp.append([1 for _ in range(n)])
    dp.append([0 for _ in range(n)])
    dp.append([0 for _ in range(n)])

    for i in range(1, 3):
        for j in range(n):
            dp[i][j] = sum(dp[i-1][k] for k in range(n) if d[i-1][k] > d[i][j])

    return sum(dp[2])


def ilen(it):
    c = 0
    for _ in it:
        c += 1
    return c

main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import bisect as bs
import sys
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()

second = [N - bs.bisect_right(C,B[i]) for i in range(N)]

ans = 0
for i in range(N):
    ans += np.sum(second[bs.bisect_right(B,A[i]):])

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import bisect as bs

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

first = [N - bs.bisect_right(B,A[i]) for i in range(N)]
second = [N - bs.bisect_right(C,B[i]) for i in range(N)]

ans = 0
for i in range(N):
    ans += np.sum(second[N - first[i]:])

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0
for j in range(len(B)):
    axb = bisect.bisect_left(A, B[j])
    bxc = len(C) - len(C[:bisect.bisect(C, B[j])])
    ans += axb * bxc
print(ans)

Submission status: Time Limit Exceeded

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

result = 0
for c in C:
    B_sub = B[:bisect.bisect_left(B,c)]
    for b in B_sub:
        result += bisect.bisect_left(A,b)

print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

cache = []
result = 0
doneb = 0
donea = 0
for c in Clist:
    idxc = bisect.bisect_left(Blist, c)
    for i in range(0, idxc):
        b = Blist[i]
        idxb = bisect.bisect_left(Alist, b)
        result += idxb

print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

    counter = 0
    for c in C:
        b_count = bisect.bisect_left(B, c)
        for b in B[0:b_count]:
            a_count = bisect.bisect_left(A, b)
            counter += a_count

    print(counter)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

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

print( ans )

Submission status: Time Limit Exceeded

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

ans = 0
for b in B:
    a_num = 0
    c_num = 0
    for a in A:
        if a < b:
            a_num += 1
        else:
            break
    for c in C:
        if b < c:
            c_num += 1
        else:
            break
    ans += a_num * c_num

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for b in B:
    a_ = len(list(filter(lambda x:x < b, A)))
    c_ = len(list(filter(lambda x:x > b, C)))
    ans += a_ * c_

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
asort = sorted(a)
bsort = sorted(b)
csort = sorted(c)
res = 0
for ai in a:
    bindex = bisect.bisect_right(bsort, ai)
    if bindex == n:
        continue
    for bi in bsort[bindex:]:
        cindex = bisect.bisect_right(csort, bi)
        if cindex == n:
            continue
        res += n-cindex
print(res)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

cnt = 0
for i in range(N):
    x = bisect.bisect_right(B, A[i])
    for j in B[x:]:
        y = bisect.bisect_right(C, j)
        cnt += len(C[y:])
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect as bi
n = int(input())
kariA = list(map(int,input().split()))
kariB = list(map(int,input().split()))
kariC = list(map(int,input().split()))
A = sorted(kariA)
B = sorted(kariB)
C = sorted(kariC)
count = 0
for c in C:
    for b in B[:bi.bisect_left(B,c)]:
            count += bi.bisect_left(A,b)
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
b.sort()
c=[int(i) for i in input().split()]
c.sort()
#print(n,a,b,c)

ans=0
for j in range(n):
    aa=bisect.bisect_right(b, a[j])
    if aa < n:
        for i in range(aa,n):
            ans+=n-bisect.bisect_right(c, b[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
b=[int(i) for i in input().split()]
b.sort()
c=[int(i) for i in input().split()]
c.sort()
#print(n,a,b,c)

ans=0
for j in range(n):
    aa=bisect.bisect_right(b, a[j])
    if aa < n:
        for i in range(aa,n):
            bb=bisect.bisect_right(c, b[i])
            ans+=n-bb

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
b=[int(i) for i in input().split()]
b.sort()
c=[int(i) for i in input().split()]
c.sort()
#print(n,a,b,c)

ans=0
for j in range(n):
    aa=bisect.bisect_right(b, a[j])
    if aa < n:
        for i in range(aa,n):
            bb=bisect.bisect_right(c, b[i])
            ans+=n-bb

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

cache = []
result = 0
doneb = 0
donea = 0
for i in range(0, len(Clist)):
    c = Clist[i]
    for j in range(doneb, len(Blist)):
        b = Blist[j]
        if b >= c:
            break
        doneb += 1
        acount = donea
        for k in range(donea, len(Alist)):
            a = Alist[k]
            if a >= b:
                break
            acount += 1
            donea += 1
        cache.append(acount)
    result += sum(cache)

print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect as bi
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(len(c)):
    for j in range(bi.bisect_left(b,c[i])):
        ans += bi.bisect_left(a,b[j])
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()]


ans = 0
for i in b:
    count_a = 0
    count_c = 0
    for j in range(n):
        if i > a[j]:
            count_a += 1
        if i < c[j]:
            count_c += 1
    ans += count_a * count_c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def comp(i,j):
    # i < j <-> 1
    # i > j <-> -1
    # i == j <-> 0
    if len(i) < len(j):
        return 1
    elif len(i) > len(j):
        return -1
    for x in range(len(i)):
        if i[x] == j[x]:
            continue
        elif i[x] > j[x]:
            return -1
        else:
            return 1
    return 0



def bisect_left(array, i):
    __bisect_array = array
    def _bisect_left(i, left, right):
        n = right - left + 1
        mid = (left+right) // 2
        if n == 1:
            if comp(__bisect_array[mid],i) == 1:
                return 1
            else:
                return 0
        if comp(i, __bisect_array[mid]) >= 0:
            return _bisect_left(i,left,mid)
        else:
            return (mid-left+1) + _bisect_left(i,mid+1,right)
    return _bisect_left(i, 0, len(array)-1)

def bisect_right(array, i):
    __bisect_array = array
    def _bisect_right(i, left, right):
        n = right - left + 1
        mid = (right+left) // 2
        if n == 1:
            if comp(i, __bisect_array[mid]) == 1:
                return 0
            else:
                return 1
        if comp(__bisect_array[mid] ,i) >= 0:
            return  (mid-left+1) + _bisect_right(i,mid+1,right)
        else:
           return _bisect_right(i,left,mid)
    return _bisect_right(i, 0, len(array)-1)

N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    l = list(map(str,sorted(l)))
    L.append(l)
ans = 0
for x in L[1]:
    n = bisect_left(L[0],x)
    m = bisect_right(L[2],x)
    m = N - m
    ans += n*m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def bisect_left(array, i):
    __bisect_array = array
    def _bisect_left(i, left, right):
        n = right - left + 1
        mid = (left+right) // 2
        if n == 1:
            if __bisect_array[mid] < i:
                return 1
            else:
                return 0
        if i <= __bisect_array[mid]:
            return _bisect_left(i,left,mid)
        else:
            return (mid-left+1) + _bisect_left(i,mid+1,right)
    return _bisect_left(i, 0, len(array)-1)

def bisect_right(array, i):
    __bisect_array = array
    def _bisect_right(i, left, right):
        n = right - left + 1
        mid = (right+left) // 2
        if n == 1:
            if i < __bisect_array[mid] :
                return 0
            else:
                return 1
        if __bisect_array[mid] <= i:
            return  (mid-left+1) + _bisect_right(i,mid+1,right)
        else:
           return _bisect_right(i,left,mid)
    return _bisect_right(i, 0, len(array)-1)

N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    L.append(sorted(l))
ans = 0
for x in L[1]:
    n = bisect_left(L[0],x)
    m = bisect_right(L[2],x)
    m = N - m
    ans += n*m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def bisect_left(array, i, left, right):
    n = right - left + 1
    mid = (left+right) // 2
    if n == 1:
        if array[mid] < i:
            return 1
        else:
            return 0
    if i <= array[mid]:
        return bisect_left(array,i,left,mid)
    else:
        return (mid-left+1) + bisect_left(array,i,mid+1,right)

def bisect_right(array, i, left, right):
    n = right - left + 1
    mid = (right+left) // 2
    if n == 1:
        if i < array[mid] :
            return 0
        else:
            return 1
    if array[mid] <= i:
        return  (mid-left+1) + bisect_right(array,i,mid+1,right)
    else:
        return bisect_right(array,i,left,mid)

N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    L.append(sorted(l))
ans = 0
for x in L[1]:
    n = bisect_left(L[0],x,0,N-1)
    m = bisect_right(L[2],x,0,N-1)
    m = N - m
    ans += n*m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def bisect_left(array, i):
    n = len(array)
    mid = n // 2
    if n == 1:
        if array[0] < i:
            return 1
        else:
            return 0
    if i <= array[mid]:
        return bisect_left(array[:mid],i)
    else:
        return mid + bisect_left(array[mid:],i)

def bisect_right(array, i):
    n = len(array)
    mid = n // 2
    if n == 1:
        if i < array[0] :
            return 0
        else:
            return 1
    if array[mid] <= i:
        return  mid + bisect_right(array[mid:],i)
    else:
        return bisect_right(array[0:mid],i)

N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    L.append(sorted(l))
ans = 0
for x in L[1]:
    n = bisect_left(L[0],x)
    m = bisect_right(L[2],x)
    m = N - m
    ans += n*m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A = sorted(IL())
B = sorted(IL())
C = sorted(IL())

dp = [0]*N 

ans = 0
for i in range(N):
	dp[i] = bisect.bisect_left(A,B[i])
for i in range(N):
	ans += sum(dp[:bisect.bisect_left(B,C[i])])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N):
  l, r = 0, 0
  for j in range(N):
    k = i - j
    if(A[j] < B[i]):
      l += 1
    if(B[i] < C[k]):
      r += 1
  cnt += l*r
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())))
a_n = [0] * n
b_n = [0] * n
for i in range(n):
    a_n[i] = bisect.bisect_right(b, a[i])
for i in range(n):
    b_n[i] = n - bisect.bisect_right(c, b[i])
ans = 0
for i in a_n:
    ans += sum(b_n[i:])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
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()))
# main
cnt = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i] < b[j] and b[j] < c[k]:
                cnt += 1
print(cnt)

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_check = [n] * n
c_check = [0] * n
for i,j in enumerate(sorted(b)):
    for k,l in enumerate(sorted(c)):
        if l > j:
            c_check[i] = n - k
            break
    for k,l in enumerate(sorted(a)):
        if l >= j:
            a_check[i] = k
            break
ans = 0
for i in range(n):
    ans += a_check[i] * c_check[i]
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()]

b_check = [0] * n
for i,j in enumerate(sorted(b)):
    for k,l in enumerate(sorted(c)):
        if l > j:
            b_check[i] = n - k
            break
            
ans = 0
for i,j in enumerate(sorted(a)):
    for k,l in enumerate(sorted(b)):
        if l > j:
            ans += sum(b_check[k:n])
            break
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):
    a = A[i]
    for j in range(N):
        if B[j] > a:
            b = B[j]
            for k in range(N):
                if C[k] > b:
                    count+=(N-k)
                    break
                else:
                    pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
from operator import itemgetter

# N, K = map(int, input().split())
# h = list(map(int, input().split()))
# S = [input() for _ in range(H)]
# X = [[0 for j in range(100)] for i in range(200)]


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

## solve
ans = 0
for a in A:
	for b in B:
		for c in C:
			if a < b < c:
				ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve(N, As, Bs, Cs):
    # print(As, Bs, Cs)
    ans = 0
    As.sort()
    Bs.sort()
    Cs.sort()
    
    memo = {}
    for b in Bs:
        bans = 0
        for i, c in enumerate(Cs):
            if b < c:
                bans += N - i
                break
        memo[b] = bans

    for a in As:
        for b in Bs:
            if b > a and b in memo:
                ans += memo[b]

    return ans

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    Bs = list(map(int, input().split(" ")))
    Cs = list(map(int, input().split(" ")))
    print(solve(N, As, Bs, Cs))

Submission status: Time Limit Exceeded

Solution code:
def solve(N, As, Bs, Cs):
    # print(As, Bs, Cs)
    ans = 0
    As.sort()
    Bs.sort()
    Cs.sort()
    memo = {}
    for a in As:
        for b in Bs:
            if b <= a:
                continue
            if b in memo:
                ans += memo[b]
                continue
            bans = 0
            for i, c in enumerate(Cs):
                if b < c:
                    bans += N - i
                    break
            memo[b] = bans
            ans += bans
    return ans


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    Bs = list(map(int, input().split(" ")))
    Cs = list(map(int, input().split(" ")))
    print(solve(N, As, Bs, Cs))

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=True)
# B.sort(reverse=True)
# C.sort(reverse=True)
# C.append(-1)
a_count = [0 for i in range(N)]
b_count = [0 for i in range(N)]
# i, j = 0, 0
# while i < N:
#     if B[i] >= C[j]:
#         b_count[i] = j
#         i += 1
#     else:
#         j += 1
for i in range(N):
    for j in range(N):
        if B[i] < C[j]:
            b_count[i] += 1
for i in range(N):
    for j in range(N):
        if A[i] < B[j]:
            a_count[i] += b_count[j]
print(sum(a_count))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
u = list(map(int,input().split()))
m = list(map(int,input().split()))
d = list(map(int,input().split()))
u.sort()
m.sort()
d.sort()

cnt = 0
a = []
for i in range(n):
    for j in range(cnt,n):
        if u[j] < m[i]:
            cnt += 1
        else:
            a.append(cnt)
            break
    else:
        a.append(cnt)

cnt = 0
ans = 0
for i in range(n):
    for j in range(cnt,n):
        if d[i] > m[j]:
            cnt += 1
        else:
            break
    ans += sum(a[:cnt])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
u = list(map(int,input().split()))
m = list(map(int,input().split()))
d = list(map(int,input().split()))

cnt = 0
for i in range(n):
    for j in range(n):
        if m[j] < d[i]:
            for k in range(n):
                if u[k] < m[j]:
                    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())))

ans = 0
for a in A:
    B2 = [i for i in B if i > a]
    for b in B2:
        ans += len([j for j in C if j > b])
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
al = [int(a) for a in input().split()]
bl = [int(b) for b in input().split()]
cl = [int(c) for c in input().split()]

al.sort()
bl.sort()
cl.sort()

k = 0
for a in al:
    for b in bl[bisect.bisect_right(bl, a):]:
        k += n - bisect.bisect_right(cl, b)
print(k)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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


Ac, Cc = [0]*n, [0]*n
Ap, Cp = 0, 0

for i in range(n):
    index = bisect.bisect_left(A[Ap:], B[i])
    Ac[i], Ap = index + Ap, index + Ap
    index = bisect.bisect_right(C[Cp:], B[i])
    Cc[i], Cp = n - index - Cp, index + Cp


count = 0
for i in range(n):
    count += Ac[i]*Cc[i]

print(count)