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

from bisect import *

ans = 0
for b in B:
    a = bisect_right(A, -b)
    c = bisect_right(C, b)
    ans += (len(A) - a) * (len(C) - c)
print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort()
C.sort()
count = 0
for Bi in B:
    a = bisect.bisect_left(A, Bi)
    c = bisect.bisect_right(C, Bi)
    count += a * (len(C) - c)
print(count)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
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()])
# N = 6
# A = sorted([int(i) for i in '3 14 159 2 6 53'.split()])
# B = sorted([int(i) for i in '58 9 79 323 84 6'.split()])
# C = sorted([int(i) for i in '2643 383 2 79 50 288'.split()])
res = 0
for b in B:
    res += bisect_left(A, b) * (N -bisect_right(C, b))
print(res)

Submission status: Accepted

Solution code:
"""
atcoder workspace
"""
from bisect import bisect_left, bisect_right

N = int(input())

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

A.sort()
C.sort()

ans = int()
for i in B:
    x = bisect_left(A, i)
    y = bisect_right(C, i)
    ans += x * (N-y)

"""
 A = [1,2,2,3,4]
 B = [1,1,2,4,5]
 C = [1,1,2,2,3]
 A < B < C
 when i+2(B = 2),
 x = 1, y = 3
 N_A = 1 (A=1), N_C = 1 (C=3)
"""

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

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

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

Submission status: Accepted

Solution code:
import itertools

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)

ab = []
pivot_a = pivot_b = 0
while pivot_b<n:
    while pivot_a<n and a[pivot_a]<b[pivot_b]:
        pivot_a += 1
    ab.append(pivot_a)
    pivot_b += 1
#print(ab)
ab_sum = list(itertools.accumulate(ab))

bc = []
pivot_a = pivot_b = 0
while pivot_b<n:
    while pivot_a<n and b[pivot_a]<c[pivot_b]:
        pivot_a += 1
    bc.append(pivot_a)
    pivot_b += 1
#print(bc)

res = 0
for i in bc:
    if i!=0:
        res += ab_sum[i-1]
print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
bb = inpl()
cc = inpl()
aa.sort()
bb.sort()
cc.sort()
Sc = len(cc)

ans = 0
for b in bb:
	na = bisect.bisect_left(aa,b)
	nc = Sc - bisect.bisect_right(cc,b)
	ans += na*nc
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()
b.sort()
c.sort()

d = []
e = []

for i in range(n):
    k = bisect.bisect_left(a,b[i])
    d.append(k)

for i in range(n):
    k = bisect.bisect_right(c,b[i])
    e.append(n-k)
    
#print(d)
#print(e)

ass = 0
for i in range(n):
    ass += d[i]*e[i]

print(ass)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
abc = [tuple(map(int, input().split(" "))) for i in range(3)]
# n = 100000
# abc = [tuple(range(n)) for i in range(3)]

a, b, c = [sorted(abc_i) for abc_i in abc]

print(sum(bisect.bisect_left(a, b_i) * (n-bisect.bisect_right(c, b_i)) for b_i in b))

Submission status: Accepted

Solution code:
import bisect

n = int(input())
abc = [tuple(map(int, input().split(" "))) for i in range(3)]
# n = 100000
# abc = [tuple(range(n)) for i in range(3)]

a, b, c = [sorted(abc_i) for abc_i in abc]

print(sum(bisect.bisect_left(a, b_i) * (n-bisect.bisect(c, b_i)) for b_i in b))

Submission status: Accepted

Solution code:
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_s, b_s, c_s = sorted(a), sorted(b), sorted(c)

a_idx, c_idx = 0, 0
small_at, big_at = [], []
small_cnt, big_cnt = 0, 0

for i in b_s :
    while a_idx < N and a_s[a_idx] < i :
        a_idx += 1
        small_cnt += 1
        
    while c_idx < N and c_s[c_idx] <= i :
        c_idx += 1
        big_cnt += 1
        
    small_at.append(small_cnt)
    big_at.append(big_cnt)
    
sum_comb = 0 
for i in range(N) :
    sum_comb += small_at[i] * (N - big_at[i])

print(sum_comb)

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

import bisect
print(sum(bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) for b in B))

Submission status: Accepted

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

def main():

    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = list(map(int, input().split()))

    a_list.sort()
    b_list.sort()
    c_list.sort()

    cnt = 0
    
    for b in b_list:
        i = bisect.bisect_left(a_list, b)
        j = n - bisect.bisect_right(c_list, b)
        cnt += i * j
    
    print(cnt)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

N = int(input())

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

A.sort()
C.sort()

count=0
i=0
for i in range(N):
    countA = bisect.bisect_left(A, B[i])
    #print(bisect.bisect_left(A, B[i]))

    countB = N - bisect.bisect_right(C, B[i])
    #print(bisect.bisect_right(C, B[i]))

    count += countA * countB

print(count)

Submission status: Accepted

Solution code:
import bisect, functools, sys
sys.setrecursionlimit(10**6)
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())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

b_cache = [0] * (N + 1)
b_cached = [False] * (N + 1)
def b_i(i):
    global b_cache, b_cached
    if i >= 1:
        if not b_cached[i - 1]: b_i(i - 1)
        t = b_cache[i - 1] + a(B[i - 1])
        b_cache[i] = t
        b_cached[i] = True
        return t
    return 0

@functools.lru_cache(maxsize=None)
def b(n):
    return b_i(min(N, bisect.bisect_left(B, n)))

def c():
    return sum(b(x) for x in C)

print(c())

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

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

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
A.sort()
B.sort()
C.sort()
count = 0
for Bi in B:
    idx_A = bisect.bisect_left(A, Bi)
    idx_C = bisect.bisect_right(C, Bi)
    count += (idx_A) * (len(C) - idx_C)
print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]


N = int(input())
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = list(map(int,input().split()))

aa.sort()
bb.sort()
cc.sort()

ans = 0
for b in bb:
	an = bisect.bisect_left(aa,b)
	cn = N-bisect.bisect_right(cc,b)
	ans += an*cn

print(ans)

Submission status: Accepted

Solution code:
'''
https://beta.atcoder.jp/contests/abc077/submissions/2532572
'''
from bisect import bisect_left, bisect_right

def inpl():
    return list(map(int, input().split()))

n = int(input())
a = sorted(inpl())
b = sorted(inpl())
c = sorted(inpl())

ans = 0
for v in b:
    ans += bisect_left(a, v) * (n - bisect_right(c, v))
print(ans)

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())))
bina = 0
binc = 0
count = 0
for b_tree in b:
    while bina < N and a[bina] < b_tree:
        bina += 1
    while binc < N and c[binc] <= b_tree:
        binc += 1
    count += bina * (N-binc)
print(count)

Submission status: Accepted

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

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:
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()))
ans = 0
A.sort()
C.sort()
for b in B:
	a_cand = bisect_left(A, b)
	c_cand = N - bisect_right(C, b)
	ans += a_cand * c_cand
print(ans)

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()))
A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)
A2.append(2000000000)
B2.append(2000000000)
def numadd(up, down):
    array = []
    count = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
        array.append(count)
    return array

B3 = numadd(A2,B2)
C3 = numadd(B2,C2)
B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])
ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]
print(ans)

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


A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)

A2.append(2000000000)
B2.append(2000000000)

def numadd(up, down):
    array = []
    count = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            
        array.append(count) #+ last)
    return array

B3 = numadd(A2,B2)
C3 = numadd(B2,C2)

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

print(ans)

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


#A2 = sorted(A)
#B2 = sorted(B)
#C2 = sorted(C)


def numadd(up, down):
    array = []
    count = 0
    last = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            if count == N:
                count = count - 1
                last = 1
                break
        array.append(count + last)
    return array

B3 = numadd(sorted(A),sorted(B))
C3 = numadd(sorted(B),sorted(C))

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

print(ans)

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


A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)


def numadd(up, down):
    array = []
    count = 0
    last = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            if count == N:
                count = count - 1
                last = 1
                break
        array.append(count + last)
    return array

B3 = numadd(A2,B2)
C3 = numadd(B2,C2)

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

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

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

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

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

Submission status: Accepted

Solution code:
import bisect
N=int(input())
s=[list(sorted(map(int,input().split()))) for i in range(3)]
t=[]
q=0
for i in s[1]:
    t.append(N-bisect.bisect_right(s[2],i))
for i in range(N):
    q+=bisect.bisect_left(s[0],s[1][i])*t[i]
print(q)

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)
z = [0] * N
ans = 0
for i in range(N-1,-1,-1):
  e = b[i]
  cin =  bisect.bisect_right(c,e)
  if i + 1 == N:
    z[i] = N-cin
  else:
    z[i] = z[i+1] + N-cin
for i in range(N):
  d = a[i]
  bind =  bisect.bisect_right(b,d)
  if bind == N:
    continue
  ans += z[bind]
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()

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

Submission status: Accepted

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

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

B_num = []
for i in range(N):
    if i == 0:
        B_num.append(bisect.bisect_left(A, B[i]))
    else:
        B_num.append(bisect.bisect_left(A, B[i]) + B_num[i-1])

count = 0
for i in range(N):
    idx = bisect.bisect_left(B, C[i])
    if idx == 0:
        continue
    else:
        count += B_num[idx - 1]

print(count)

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

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

ab=[0]*N
count=0

for i in range(N):
    while count<N and A[count]<B[i]:
        count+=1
    ab[i]=count

count=0
ans=0
bc=[0]*N

for i in range(N-1,-1,-1):
    while count<N and C[count]>B[i]:
        count+=1
    #bc[i]=count
    ans+=count*ab[i]

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()
ans = 0
def find_lt(a, x):
    'Find rightmost value less than x'
    i = bisect.bisect_left(a, x)
    if i:
        return i
    return 0
def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect.bisect_right(a, x)
    if i != len(a):
        return len(a)-i
    return 0
for bs in b:
  ans += find_lt(a, bs)*find_gt(c,bs)
print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
A = sorted([int(x) for x in input().split()])
B = [int(x) for x in input().split()]
C = sorted([int(x) for x in input().split()])

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

Submission status: Accepted

Solution code:
import bisect as bi

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

A.sort()
B.sort()
C.sort()
ans = 0

for b in B:
    i = bi.bisect_left(A, b) # A[0],...,A[i - 1] < b
    k = bi.bisect_right(C, b) # b < C[k],...C[N-1]
    ans += i * (N - k)

print(ans)

Submission status: Accepted

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

# 2分検索ライブラリを使う
import bisect

N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

# 昇順ソート
A_list.sort()
C_list.sort()

ans = 0
for i in range(N):
    # 同じ値があった時に、leftは先頭、rightは最後尾のindexを返す
    ab = bisect.bisect_left(A_list, B_list[i])
    bc = N - bisect.bisect_right(C_list, B_list[i])
    # 返されたindexから、候補となるABとBCの数が分かるので、合計していく
    ans += ab * bc
print(ans)

Submission status: Accepted

Solution code:
N=int(input().strip())
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,reverse=True)
def binsearch_int(func, min_x, max_x):
    """func(x) == Trueとなる最大のxを返す
    """
    if func(max_x):
        return max_x
    if not func(min_x):
        return -1
    left,right=min_x,max_x
    while left+1<right:
        mid=(left+right)//2
        if func(mid):
            left=mid
        else:
            right=mid
    return left
smaller=[binsearch_int(lambda x: A[x]<i,0,N-1)+1 for i in B]
bigger=[binsearch_int(lambda x: C[x]>i,0,N-1)+1 for i in B]
print(sum(a*c for a,c in zip(smaller, bigger)))

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 i in B:
    res += bisect.bisect_left(A, i) * (N - bisect.bisect_right(C, i))
    
print(res)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

result = 0

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

print(result)

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


def hoge():
    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai < N - 1:
            while A[Ai + 1] < B[i]:
                Ai += 1
                if Ai == N - 1:
                    break
        if Ci < N - 1:
            while C[Ci + 1] <= B[i]:
                Ci += 1
                if Ci == N - 1:
                    break
        count += (Ai + 1) * (N - (Ci + 1))
    return count


print(hoge())

Submission status: Accepted

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

    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai<N-1:
            while A[Ai+1]<B[i]:
                Ai += 1
                if Ai == N-1:
                    break
        if Ci<N-1:
            while C[Ci+1]<=B[i]:
                Ci += 1
                if Ci==N-1:
                    break
        count += (Ai+1) * (N-(Ci+1))

    return count

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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


def higher_search(list, key):
    l = -1
    r = len(list)

    while r - l > 1:
        mid = l + (r - l) // 2
        if list[mid] > key:
            r = mid
        else:
            l = mid

    if r == len(list):
        return -1
    else:
        return r


def lower_search(list, key):
    l = -1
    r = len(list)

    while r - l > 1:
        mid = r - (r - l) // 2
        if list[mid] < key:
            l = mid
        else:
            r = mid

    if l == -1:
        return -1
    else:
        return l


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

ans = 0
for b in B:
    a_index = lower_search(A, b)
    c_index = higher_search(C, b)
    if c_index == -1:
        c_index = n
    ans += (a_index + 1) * (n - c_index)

print(ans)

Submission status: Accepted

Solution code:
import bisect as bi

# input
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 b in B:
    i = bi.bisect_left(A, b) # A[0],...,A[i - 1] < b
    k = bi.bisect_right(C, b) # b < C[k],...C[N-1]
    count += i * (N - k)

print(count)

Submission status: Accepted

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

count = 0

for b in B:
    i = bisect_left(A, b)
    k = bisect_right(C, b)
    count += i * (N-k)

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

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()))
a = sorted(a)
b = sorted(b)
c = sorted(c)
num = 0
p, q = 0, 0
for i in range(n):
    while p < n and a[p] < b[i]:
        p += 1
    while q < n and c[q] <= b[i]:
        q += 1
    num += p * (n - q)

print(num)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
one = list(map(int, input().split()))
second = list(map(int, input().split()))
third = list(map(int, input().split()))

one.sort()
second.sort()
third.sort()

c = 0
for second_v in second:
    one_n = bisect.bisect_left(one, second_v)
    third_n = len(third) - bisect.bisect_right(third, second_v)
    c += one_n * third_n
print(c)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
a = sorted([int(i) for i in input().split()])
b = [int(i) for i in input().split()]
c = sorted([int(i) for i in input().split()])

total = 0

for middle in b:

    total += bisect.bisect_left(a,middle) * (n-bisect.bisect_right(c,middle))

print(total)

Submission status: Accepted

Solution code:
import bisect
def inpl(): return list(map(int, input().split()))
N = int(input())
a, b, c = sorted(inpl()), sorted(inpl()), sorted(inpl())

ans = 0
for j in b:
    ans += bisect.bisect_left(a, j)*(N-bisect.bisect_right(c, j))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [sorted(list(map(int, input().split()))) for _ in range(3)]
ans = [[1]*(N) for _ in range(3)]

for i in range(2):

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

    last = -1
    for j in range(N):
        target = s[i+1][j]
        lo = last
        hi = N-1
        while hi - lo > 1:
            m = (hi+lo)//2
            if s[i][m] < target:
                lo = m
            else:
                hi = m
        if s[i][hi] < target:
            last = hi
        elif s[i][lo] < target:
            last = lo
        if last >= 0:
            ans[i+1][j] = ans[i][last]
        else:
            ans[i+1][j] = 0

print(sum(ans[2]))

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

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(" ")))
#アルゴリズムわからないけどN log N?
a.sort()
b.sort()
c.sort()
 
#O(N)?
i,j,k = 0,0,0
ans = 0
while j < N:
  while i < N and a[i]<b[j] :
    i += 1
  while k < N and c[k]<=b[j]:
    k += 1
  ans += i * (N - k)
  j += 1
 

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

ans = 0
for i in B:
    ins_a = bisect.bisect_left(A,i)
    ins_c = bisect.bisect_right(C,i)
    ans+=ins_a*(N-ins_c)

print(ans)

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

bmul = [0]*(n+1)
ci = 0

for bi in range(n):
    while ci != n and c[ci] <= b[bi]:
        ci += 1
    bmul[bi] = n-ci
for i in range(n):
    bmul[n-i-1] += bmul[n-i]
bi = 0
ai = 0
ret = 0
for ai in range(n):
    while bi != n and b[bi] <= a[ai]:
        bi += 1
    ret += bmul[bi]
print(ret)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

B2 = [0 for i in range(N)]
for i,b in enumerate(B):
	idx = bisect_left(C,b+1)
	B2[i] = N - idx

B2sum = [0 for i in range(N+1)]
for i in range(N)[::-1]:
	B2sum[i] = B2sum[i+1] + B2[i]


ans = 0
for a in A:
	idx = bisect_left(B,a+1)
	ans += B2sum[idx]

print(ans)

Submission status: Accepted

Solution code:
import bisect

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
for bb in b:
    b_res = bisect.bisect_left(a, bb)
    c_res = len(c) - bisect.bisect_right(c, bb)
    res += (b_res*c_res)

print(res)

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

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

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()
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:
def someone_ans():
    def binary_search(L, key, mode):
        low, high = 0, len(L)
        mid = len(L) // 2
        while low <= high - 1:
            if L[mid] < key and mode == 0 or L[mid] <= key and mode == 1:
                low = mid + 1
            else:
                high = mid
            mid = (low + high) // 2
        return high

    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 i in B:
        Ai = binary_search(A, i, 0)
        Ci = len(C) - binary_search(C, i, 1)
        ans += Ai*Ci
    return ans


# print(m())
print(someone_ans())

Submission status: Accepted

Solution code:
def BinarySearch(L, key, mode):
    left, right = 0, len(L)
    mid = len(L)//2
    while  left <= right-1:
        if L[mid] < key and mode == 0 or L[mid] <= key and mode == 1:
            left = mid+1
        else:
            right = mid
        mid =  (left+right)//2
    return right

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()
C.sort()
ans = 0
for i in B:
    Ai = BinarySearch(A, i, 0)
    Ci = len(C)-BinarySearch(C, i, 1)
    ans += Ai*Ci
print(ans)

Submission status: Accepted

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

lis = [0] * n
j = 0
for i in range(n):
    while j < n and a[j] < b[i]:
        j += 1
    lis[i] = j

li = [0] * n
m = 0
j = 0
for i in range(n):
    while j < n and b[j] < c[i]:
        m += lis[j]
        j += 1
    li[i] = m
print(sum(li))

Submission status: Accepted

Solution code:
def binary_search(lst, e, mode):
    l, u = 0, len(lst)
    mid = len(lst) // 2

    while l <= u-1:
        if lst[mid] < e and mode == "l" or lst[mid] <= e and mode == "u":
            l = mid + 1
        else:
            u = mid
        mid = (l+u) // 2

    return u


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

com = 0

for i in b:
    j = binary_search(a, i, "l")
    k = len(c) - binary_search(c, i, "u")
    com += j * k

print(com)