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: Accepted

Solution code:
def upper_bound(ar, val):
    low = 0
    high = len(ar)
    while low < high:
        mid = (low + high) >> 1
        if val >= ar[mid]:
            low = mid + 1
        else:
            high = mid
    return low


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] * n
greater_a = [0] * n
for i in range(n):
    greater_a[i] = upper_bound(b, a[i])
    count[i] = n - upper_bound(c, b[i])
prefix = [0] * n
prefix[n - 1] = count[n - 1]
for k in range(n - 2, -1, -1):
    prefix[k] = prefix[k + 1] + count[k]
total = 0
for k in range(n):
    if greater_a[k] < n:
        total += prefix[greater_a[k]]
print(total)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
list_a.sort()
list_b.sort()
list_c.sort()
len_c = len(list_c)
result = 0
for one_b in list_b:
  place_a = bisect.bisect_left(list_a, one_b)
  place_c = bisect.bisect_right(list_c, one_b)
  result += place_a * (len_c - place_c)
print(result)

Submission status: Accepted

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


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()
    C.sort()

    ans = 0
    for b in B:
        cnt_a = bisect.bisect_left(A, b)
        cnt_c = N - bisect.bisect_right(C, b)
        ans += cnt_a * cnt_c
        # print(str(cnt_a) + "*" + str(cnt_c))
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def test():
    n = int(input())
    A,B,C = [list(sorted(map(int,input().split()))) for i in range(3)]
    ans = 0

    for b in B:
        ans += low_left(A,b) * (n-high_right(C,b))
    print(ans) 


def low_left(ls,t):
    low,high = 0,len(ls)
    while low<high:
        mid = (low+high)//2
        if ls[mid] < t:
            low = mid + 1
        else:
            high = mid
    return low


def high_right(ls,t):
    low,high = 0,len(ls)
    while low<high:
        mid = (low+high)//2
        if ls[mid] > t:
            high = mid
        else:
            low = mid + 1
    return low


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
import bisect
N=int(input())
A=sorted(map(int,input().split()))
B=map(int,input().split())
C=sorted(map(int,input().split()))
ans=0
for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    ans+=a*c
print(ans)

Submission status: Accepted

Solution code:
import bisect
def main():
    n=int(input())
    a=sorted(list(map(int,input().split(' '))))
    b=sorted(list(map(int,input().split(' '))))
    c=sorted(list(map(int,input().split(' '))))
    c_len=len(c)
    ans = 0
    for i in b:
        ans_a=bisect.bisect_left(a,i)
        ans_c=c_len-bisect.bisect_right(c,i)
        ans += ans_a*ans_c
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

result = 0
for i in range(n):
    x = bisect.bisect_left(a, b[i])
    y = n - bisect.bisect_right(c, b[i])
    result += x*y


print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    C.sort()
    answer = 0
    for i in range(N):
        A_index = bisect.bisect_left(A,B[i])
        C_index = bisect.bisect_left(C,B[i]+1) 
        answer += (N-C_index)*A_index
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    B.sort()
    C.sort()
    answer = 0
    for i in range(N):
        A_index = bisect.bisect_left(A,B[i])
        C_index = bisect.bisect_left(C,B[i]+1) 
        answer += (N-C_index)*A_index
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Submission status: Accepted

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 Bi in B:
    a=bi.bisect_left(A,Bi)
    c=N-bi.bisect_right(C,Bi)
    ans+=a*c

print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
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()
Bsum=[0]*(N+1)
for i in range(N):
  Bsum[i+1] = N-bisect.bisect_right(C,B[i])
Bsum=list(accumulate(Bsum))
ans = 0
for i in range(N):
  a = bisect.bisect_right(B,A[i])
  ans += Bsum[-1]-Bsum[a]
print(ans)

Submission status: Accepted

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()
ans=0 
from bisect import bisect_left as bl,bisect_right as br 
for i in b: 
    left=bl(a,i)
    right=n-br(c,i)
    ans+=left*right 
print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right
inout = sys.stdin.readline

def main():
    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 Bi in B:
        Ai = bisect_left(A, Bi)
        Ci = N - bisect_right(C, Bi)
        ans += (Ai*Ci)

    print(ans)


if __name__ == '__main__': main()

Submission status: Accepted

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
b_li = [0 for i in range(n)]

for b in range(n):    
    index = bisect.bisect_left(C, B[b]+1)
    b_li[b] = n-index

for b in range(n-2,-1,-1):
    b_li[b] += b_li[b+1]
b_li.append(0)

for a in range(n):    
    index = bisect.bisect_left(B, A[a]+1)

    ans += b_li[index]
    
        
    

print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right
inout = sys.stdin.readline

def main():
    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 Bi in B:
        Ai = bisect_left(A, Bi)
        Ci = N - bisect_right(C, Bi)
        ans += (Ai*Ci)

    print(ans)


if __name__ == '__main__': main()

Submission status: Accepted

Solution code:
import bisect

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    ans += bisect.bisect_left(A,b) * (len(C) - bisect.bisect(C,b))

print(ans)

Submission status: Accepted

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

import sys
from bisect import bisect_right
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = sorted(LIST())
B = sorted(LIST())
C = sorted(LIST())

dp1 = [1] * (N+1)
dp2 = [0] * (N+1)
dp3 = [0] * (N+1)

for i1, a in enumerate(A):
    i2 = bisect_right(B, a)
    dp2[i2] += dp1[i1]
dp2 = list(accumulate(dp2))
for i2, b in enumerate(B):
    i3 = bisect_right(C, b)
    dp3[i3] += dp2[i2]
dp3 = list(accumulate(dp3))
print(sum(dp3[:N]))

Submission status: Accepted

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
#初めから、どこに挿入されるのかを考えておく
Bcount = [0 for i in range(n+1)]
for i in range(1,n+1):
    Bcount[i] = bisect.bisect_left(a, b[i-1]) + Bcount[i - 1]

for i in range(n):
    index = bisect.bisect_left(b,c[i])

    ans += Bcount[index]
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
list1 = [list(map(int,input().split())) for i in range(3) ]

for i in range(3):
	list1[i].sort()

count = 0

for i in range(n):
	a = bisect.bisect_left(list1[0],list1[1][i])
	c = bisect.bisect_right(list1[2],list1[1][i])
	count += a*(n-c)
print(count)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    N = int(inputs[0])
    A = string_to_int(inputs[1])
    B = string_to_int(inputs[2])
    C = string_to_int(inputs[3])
    A.sort()
    B.sort()
    C.sort()

    patterns = 0

    for b in B:
        ai = bisect.bisect_left(A, b)
        ci = bisect.bisect_right(C, b)
        patterns += ai * (N-ci)

    return patterns


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(4))
    print(ret)

Submission status: Accepted

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())))
ans=0
for b in B:
    ans+=(bisect.bisect_left(A,b)*(n-bisect.bisect_right(C,b)))

print(ans)

Submission status: Accepted

Solution code:
import bisect as bis

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_e in b:
    n_top = bis.bisect_left(a, b_e)
    n_bottom = n - bis.bisect_right(c, b_e)
    ans += n_top * n_bottom

print(ans)

Submission status: Accepted

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:
    mid = bisect.bisect_left(A, b)
    bottom = n - bisect.bisect_right(C, b)
    cnt += mid*bottom

print(cnt)

Submission status: Accepted

Solution code:
import bisect
n = int(input())

A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

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

res = 0
for i in range(n):
    i1 = bisect.bisect_left(A,B[i])
    i2 = bisect.bisect_right(C,B[i])
    res += i1 * (n - i2)

print(res)

Submission status: Accepted

Solution code:
# a, b, cで大きいサイズのものから数えていき、あるa, bのパーツに関してその下のパーツの組み合わせがいくつあるか数える。O(N)
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    # 番兵
    as_ = [0] + sorted(list(map(int, input().split())))
    bs_ = [0] + sorted(list(map(int, input().split())))
    cs_ = [0] + sorted(list(map(int, input().split())))

    # その時点で成り立つ組み合わせの数
    n_combs = [0] * 3
    is_ = [n] * 3
    while is_[0] >= 1:
        # print((as_[is_[0]], 0), (bs_[is_[1]], 1), (cs_[is_[2]], 2))
        # 同じ数字の時、上のパーツが選ばれて欲しいため2つめに以下のような数字を入れている
        max_value = max((as_[is_[0]], 0, 0), (bs_[is_[1]], -1, 1), (cs_[is_[2]], -2, 2))
        posi = max_value[2]
        if posi == 2:
            n_combs[2] += 1
        else:
            n_combs[posi] += n_combs[posi + 1]
        is_[posi] -= 1
        
    print(n_combs[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

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 = sorted(a)
b = sorted(b)
c = sorted(c)
ans = 0
for i in range(n):
    at = bisect.bisect_left(a, b[i])
    ct = max(len(c) - bisect.bisect_right(c, b[i]), 0)
    ans += at * ct
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))
CList = list(map(int,input().split()))
AList.sort()
BList.sort()
CList.sort()
#Bより真に小さいAの数
Bx  = []
#Bxの累積和
Bx2 = []
#Cより真に小さいBの数
Cx = []

bnum = 0
for b in BList:
    while bnum < N and AList[bnum] < b:
        bnum += 1
    Bx.append(bnum)

for i in range(N):
    if i != 0:
        Bx2.append(Bx2[i-1]+Bx[i])
    else:
        Bx2.append(Bx[i])

cnum = 0
for c in CList:
    while cnum < N and BList[cnum] < c:
        cnum += 1
    Cx.append(cnum)

ans = 0
for sc in Cx:
    if sc > 0:
        ans += Bx2[sc-1]
print(ans)

Submission status: Accepted

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

ans = 0
for mid in B:
    n_bottom = N - bisect.bisect_right(C,mid)
    n_top = bisect.bisect_left(A,mid)
    ans += n_bottom * n_top

print(ans)

Submission status: Accepted

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

ans=0
for i in range(n):
    ida=bisect.bisect_left(a,b[i])
    idc=bisect.bisect_right(c,b[i])
    ans+=(ida*(n-idc))
print(ans)

Submission status: Accepted

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_accum = [0 for _ in range(n)]
c_accum = [0 for _ in range(n)]
a.sort()
b.sort()
c.sort()
for i in range(n):
    index = bisect_right(b, a[i])
    try:
        b_accum[index] += 1
    except IndexError:
        pass
for i in range(1, n):
    b_accum[i] += b_accum[i-1]
for i in range(n):
    index = bisect_right(c, b[i])
    try:
        c_accum[index] += b_accum[i]
    except IndexError:
        pass
for i in range(1, n):
    c_accum[i] += c_accum[i-1]
for i in range(1, n):
    c_accum[i] += c_accum[i-1]
print(c_accum[n-1])

Submission status: Accepted

Solution code:
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
for i in range(n):
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)

Submission status: Accepted

Solution code:
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)

Submission status: Accepted

Solution code:
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
for i in range(n):
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)

Submission status: Accepted

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())))
GB = [0 for _ in range(N)]
for i in range(N):
    ind = bisect.bisect_right(C,B[i])
    GB[i] = N-ind
SB = [0 for _ in range(N)]
SB[N-1] = GB[N-1]
for i in range(N-2,-1,-1):
    SB[i] = SB[i+1]+GB[i]
cnt = 0
for i in range(N):
    a = A[i]
    ind = bisect.bisect_right(B,a)
    if ind<N:
        cnt += SB[ind]
print(cnt)

Submission status: Accepted

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()
#print(a,b,c)
ans=0
for i in range(n):
    x=bisect.bisect_left(a,b[i])
    y=bisect.bisect_right(c,b[i])
    #print(x,y)
    ans+=x*(n-y)
print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())))
ans = 0
for i in range(N):
  ans += bisect.bisect_left(A,B[i]) * (N - bisect.bisect_right(C,B[i]))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])

res = 0
res_b = 0
cnt = 0
i, j = 0, 0
for c_ in c:
    while i <= n-1 and c_ > b[i]:
        while j <= n-1 and b[i] > a[j]:
            cnt += 1
            j += 1
        res_b += cnt
        i += 1
    res += res_b

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])

def func1(list_1, list_2):
    res = []
    cnt = 0
    i = 0
    for x in list_2:
        while i <= n-1 and list_1[i] < x:
            cnt += 1
            i += 1
        res.append((x, cnt))
    return res

def func2(list_res, list_3):
    res = 0
    cnt = 0
    i = 0
    for x in list_3:
        while i <= n-1 and list_res[i][0] < x:
            cnt += list_res[i][1]
            i += 1
        res += cnt
    return res

ans = func2(func1(a, b), c)

print(ans)

Submission status: Accepted

Solution code:
def lowerBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>=n: high = mid
        else: low = mid
    return high

def upperBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>n: high = mid
        else: low = mid
    return low+1

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

ans = 0
for i in b:
    cnt_a = lowerBound(a, i)
    cnt_b = n - upperBound(c,i)
    ans += cnt_a * cnt_b
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):
    upper = bisect.bisect_left(A, B[i])
    downer = bisect.bisect_right(C, B[i])
    ans += upper*(len(C)-downer)
print(ans)

Submission status: Accepted

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

res = 0

for sb in b:
    resa = bisect.bisect_left(a,sb)
    resc = n - bisect.bisect_right(c,sb)
    res += resa*resc

print(res)

Submission status: Accepted

Solution code:
from  bisect import bisect_left, bisect_right

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

cnt = 0
for b in B:
    a_cnt = bisect_left(A, b)
    c_cnt = N - bisect_right(C, b)
    cnt += a_cnt * c_cnt
print(cnt)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
ary = [sorted(map(int,input().split())) for _ in range(3)]
ans = 0
for i in range(n):
    a = bisect.bisect_left(ary[0],ary[1][i])
    b = n - bisect.bisect_right(ary[2],ary[1][i])
    ans += a*b
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

answer = 0
CL = len(C)
for b in B:
    ai = bisect_left(A, b)
    ci = bisect_right(C, b)
    answer += ai * (CL - ci)
print(answer)

Submission status: Accepted

Solution code:
# C
import bisect
n = int(input())
al = map(int, input().split())
bl = map(int, input().split())
cl = map(int, input().split())
al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)

total = 0
for blnum in bl:
    alcnt = bisect.bisect_left(al, blnum)
    clcnt = n - bisect.bisect_right(cl, blnum)
    total += alcnt*clcnt
print(total)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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=[]
count=0

def binary (l,num):#自分で実装しててえらいと思う
    high=len(l)-1
    low=0
    
    if num<=l[0]:
        return 0
    elif num>l[-1]:
        return len(l)
        
    while True:
        #print(high,low)
        mid=int((high+low))//2
        if l[mid]<num:
            if l[mid+1]>=num:
                return mid+1
            else:
                #print("a")
                low=mid
        elif l[mid]>=num:
            if l[mid-1]<num:
                return (mid-1)+1
            else:
                #print("b")
                high=mid
                
for i in range(len(B)):
    if i==0:
        ans.append(binary(A,B[i]))
    else:
        ans.append(binary(A,B[i])+ans[i-1])

for item in C:
    z=binary(B,item)
    if z==0:
        continue
    else:
        count+=ans[binary(B,item)-1]

print(count)

Submission status: Accepted

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

bc = []
idx = 0
for i in range(n):
    while True:
        if b[i] >= c[-1]:
            bc.append(0)
            break
        elif c[idx] <= b[i]:
            idx += 1
        else:
            bc.append(n-idx)
            break

bc2 = bc[::-1]
ab2 = []
absum = 0
for i in range(n):
    absum += bc2[i]
    ab2.append(absum)
ab = ab2[::-1]

res = 0
idx = 0
for i in range(n):
    while True:
        if a[i] >= b[-1]:
            break
        elif b[idx] <= a[i]:
            idx += 1
        else:
            res += ab[idx]
            break
print(res)

Submission status: Accepted

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

for x in [A, B, C]:
    x.sort()

i = -1
j = 0
result = 0
for b in B:
    while i < N - 1 and A[i + 1] < b:
        i += 1
    while j < N and C[j] <= b:
        j += 1
    result += (i+1) * (N - j)
print(result)

Submission status: Accepted

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

for x in [A, B, C]:
    x.sort()

result = 0
for b in B:
    a = bisect_left(A, b)
    c = N - bisect_right(C, b)
    result += a * c
print(result)

Submission status: Accepted

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

for x in [A, B, C]:
    x.sort()

t = [0] * (N + 1)  # 中部のパーツのサイズが Bi 以上のときの B と C の組み合わせの数
j = 0
for i in range(N):
    while j < N and C[j] <= B[i]:
        j += 1
    t[i] = N - j
for i in range(N - 1, -1, -1):
    t[i] += t[i + 1]

result = 0
i = 0
for a in A:
    while i < N and B[i] <= a:
        i += 1
    result += t[i]
print(result)

Submission status: Accepted

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

for x in [A, B, C]:
    x.sort()

t = [0] * (N + 1)  # 中部のパーツのサイズが Bi 以上のときの B と C の組み合わせの数
for i in range(N):
    t[i] = N - bisect_right(C, B[i])
for i in range(N - 1, -1, -1):
    t[i] += t[i + 1]

result = 0
for a in A:
    result += t[bisect_right(B, a)]
print(result)

Submission status: Accepted

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):
    a = bisect.bisect_left(A,B[i])
    c = bisect.bisect_right(C,B[i])
    count += a*(n-c)
    
print(count)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    i = bisect.bisect_left(A, b)
    j = bisect.bisect_right(C, b)
    ans += i * (N - j)
print(ans)

Submission status: Accepted

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()))
r=0
for b in B:
    i=bisect.bisect_left(A,b)
    j=n-bisect.bisect_right(C,b)
    r+=i*j
print(r)

Submission status: Accepted

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()
c_len = len(C)

cnt = 0
for b in B:
    a_cnt = bisect.bisect_left(A,b)
    c_cnt = c_len - bisect.bisect_right(C,b)
    cnt +=  a_cnt * c_cnt

print(cnt)

Submission status: Accepted

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

total = 0
for b in B:
  total += bisect_left(A, b) * (n - bisect_right(C, b))
print(total)

Submission status: Accepted

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

answer = 0
for b in B:
    ai = bisect.bisect_left(A, b)
    ci = bisect.bisect_right(C, b)
    answer += ai * (N - ci)

print(answer)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    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 x in b:
        cnt += bisect_left(a, x)*(n-bisect_right(c, x))
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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





bc_val = [0] * N
for i in range(N):
    b = B[i]
    c_idx = bisect.bisect_right(C,b)
    bc_val[i] = (N-c_idx)
    
bc_ruiseki = [0] * N
tmp = bc_val[N-1]
bc_ruiseki[N-1] = tmp
for i in reversed(range(N-1)):
    tmp += bc_val[i]
    bc_ruiseki[i] = tmp
 

ans = 0
ib = 0
b = B[0]
flag = True
for ia in range(N):
    a = A[ia]
    while b <= a:
        if ib == N-1:
            flag = False
            break
        ib += 1
        b = B[ib]
    if flag:
        ans += bc_ruiseki[ib]
    else:
        break
    
print(ans)

Submission status: Accepted

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

bl = [bisect.bisect_left(A, b) for b in B]
for i in range(1, N):
    bl[i] += bl[i-1]
cl = [bisect.bisect_left(B, c) for c in C]

ans = 0
for c in cl:
    if c < 1:
        continue
    ans += bl[c-1]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

a = np.searchsorted(A, B, side='left')
c = np.searchsorted(C, -B, side='left')

print((a * c).sum())

Submission status: Accepted

Solution code:
import numpy as np

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

A.sort()
B.sort()

a = np.searchsorted(A, B, side='left')

B = sorted(B * (-1))
C = sorted(C * (-1))

c = np.searchsorted(C, B, side='left')
c = np.fliplr([c])[0]


print((a * c).sum())