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:
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())))
sm=0
for i in range(n):
  b1=bisect.bisect_left(a,b[i])
  c1=n-bisect.bisect_left(c,b[i]+1)
  sm+=b1*c1
print(sm)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	bl = lin()
	cl = lin()
	al.sort()
	bl.sort()
	cl.sort()
	cl_num=bl[:]
	cl_pos=0
	for i, vb in enumerate(bl):
		while cl_pos <n and cl[cl_pos] <= vb:
			cl_pos += 1
		cl_num[i] = n-cl_pos
		
	cl_nokori=[0]*n
	cl_nokori[-1] = cl_num[-1]
	for i, v in enumerate(cl_num[::-1]):
		if i == 0:
			continue
		cl_nokori[n-i-1] = cl_nokori[n-i]+v
	
	ret = 0
	bl_pos=0
	for va in al:
		while bl_pos < n and va >= bl[bl_pos]:
			bl_pos += 1
		if bl_pos == n:
			break
		ret += cl_nokori[bl_pos]
	print(ret)
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST())
b = sorted(LIST())
c = sorted(LIST())

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

Submission status: Accepted

Solution code:
import sys
import bisect

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

A.sort()
B.sort()
C.sort()
# print(A)
# print(B)
# print(C)
ans = 0
for i in range(N):
    mid = B[i]
    top = bisect.bisect_left(A, mid)
    down = bisect.bisect_right(C, mid)
    # print(top, down)
    ans += top * (N - down)

print(ans)

Submission status: Accepted

Solution code:
import bisect
import sys
n = int(input())
up = sorted(list(map(int, input().split())))
mid = sorted(list(map(int, input().split())))
low = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(mid)):
    pre = bisect.bisect_left(up, mid[i])
    over = len(low) - bisect.bisect(low, mid[i])
    ans += pre * over

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int, readline().split())
*a, = map(int, readline().split())
*b, = map(int, readline().split())
*c, = map(int, readline().split())

a.sort()
c.sort()

from bisect import bisect_left, bisect_right

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

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())))
d=0
for t in b:
    d+=bisect.bisect_left(a,t)*(n-bisect.bisect_right(c,t))
print(d)

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:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    ans += a*(N-c)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

N = int(input())

# 二分探索するためにソートしておく
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0

for i in range(N):
    # Bから一つ選ぶ
    b = B[i]
    # bisect_left(ソート済リスト、挿入したい値)
    # leftなので既に値が存在ししていたら既存の左に挿入
    a_ix = bisect_left(A, b)
    # rightも同様
    c_ix = bisect_right(C, b)
    # ex. A = [1, 3, 5], C = [2, 4, 6], b = 5の場合
    # a_ix=2（1と3が可能）, c_ix=2（6が可能）
    # c_ixについては　(全体-ダメな場合の個数)=OKな個数
    ans += a_ix * (N - c_ix)

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

Submission status: Accepted

Solution code:
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    b = [int(i) for i in ipt().split()]
    c = [int(i) for i in ipt().split()]

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

    sb = [0]*n
    na = 0
    for i,bi in enumerate(b):
        for j in range(na,n):
            if a[j] >= bi:
                sb[i] = j
                na = j
                break
            if j == n-1:
                na = n
                break
        if na == n:
            sb[i] = n
    ssb = [0]
    for i in sb:
        ssb.append(ssb[-1]+i)

    ans = 0
    nb = 0
    for i,ci in enumerate(c):
        for j in range(nb,n):
            if b[j] >= ci:
                ans += ssb[j]
                nb = j
                break
            if j == n-1:
                nb = n
                break
        if nb == n:
            ans += ssb[-1]
    print(ans)

    return None

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

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

# for this we will use binary search.
import bisect as bis

BSC = [0]*N
ASB = [0]*N

for i in range (0, N):
	BSC[i] = N-bis.bisect_right(C, B[i])

for i in range (0, N):
	ASB[i] = bis.bisect_right(B, A[i])
    
for i in range (1, N):
	BSC[N-1-i] += BSC[N-i]

count = 0
for i in range (0, N):
	if ASB[i] ==N:
		continue
	else:
		count+=BSC[ASB[i]]

print(count)

Submission status: Accepted

Solution code:
def main():
    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())))
    
    num_greater_than_b = []
    for b in B:
        num_greater_than_b.append(N-bisect_right(C,b))

    csum = [0]*(N+1)
    for i in range(N-1,-1,-1):
        csum[i] = csum[i+1]+num_greater_than_b[i]
        
    ans = 0
    for i,a in enumerate(A):
        ans += csum[bisect_right(B,a)]
    print(ans)
main()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right  # return index


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

ans = 0

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

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

import bisect

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

Submission status: Accepted

Solution code:
from bisect import *
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:
    temp_a = bisect_left(a, i)
    temp_c = n - bisect_right(c, i)
    res += temp_a*temp_c
print(res)

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

A.append(10**10)
B.append(10**10)
C.append(10**10)

btab=[0 for i in range(n)]

idx=0
for i in range(n):
    while A[idx] < B[i]:
        idx+=1
    btab[i]=idx

idx=0
sow=0
ans=0
for i in range(n):
    while B[idx] < C[i]:
        sow+=btab[idx]
        idx+=1
    ans+=sow

print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    res = 0
    for i in range(n):
        u = bisect_left(A, B[i])
        d = bisect_right(C, B[i])
        res += u * (n - d)
    print(res)


if __name__ == '__main__':
    resolve()

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

Submission status: Accepted

Solution code:
from bisect import bisect_right as br

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
Bc=[]
for i in range(N):
    Bc.append(N-br(C,B[i]))

S=[sum(Bc)]
for j in range(N):
    S.append(S[j]-Bc[j])

for a in A:
    b=br(B,a)
    ans+=S[b]
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split())); a.sort()
b = list(map(int, input().split())); b.sort()
c = list(map(int, input().split())); c.sort()
ab = [0 for i in range(n)]
ans = 0

for i in range(n):
  ab[i] = ab[i-1] + bisect.bisect_left(a, b[i])
for i in range(n):
  tmp = bisect.bisect_left(b, c[i])
  if tmp != 0:
  	ans += ab[tmp-1] 

print(ans)

Submission status: Accepted

Solution code:
def check(arr, mid, maxV):
    if arr[mid] < maxV:
        return True
    else:
        return False


def binSearch(arr, maxV):
    ok = -1
    ng = len(arr)
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(arr, mid, maxV):
            ok = mid
        else:
            ng = mid
    return ok


def resolve():
    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()])
    BoverA = [0 for _ in range(N)]
    sumA = 0
    for i in range(N):
        a = binSearch(A, B[i])
        sumA += (a + 1)
        BoverA[i] = sumA
    sumA = 0
    for i in range(N):
        b = binSearch(B, C[i])
        if b >= 0:
            sumA += 1 * 1 * BoverA[b]
    print(sumA)


resolve()

Submission status: Accepted

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

result = 0
for i in b:
    ta = bisect.bisect_left(a,i)
    tc = bisect.bisect_right(c,i)
    result += ta*(N-tc)
print(result)

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

Submission status: Accepted

Solution code:
import bisect
from itertools import accumulate
n = int(input())
A = sorted(map(int,input().split()))
B = sorted(map(int,input().split()))
C = sorted(map(int,input().split()))
D = [0]*(n+1)
for i in range(n):
    D[i+1] = n-bisect.bisect_right(C,B[i])
D = tuple(accumulate(D))
ans = 0
for i in range(n):
    j = bisect.bisect_right(B,A[i])
    ans += D[-1]-D[j]
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()))
lenc = len(c)
a.sort()
c.sort()
ans = 0
for i in b:
	atmp = bisect.bisect_left(a, i)
	ctmp = lenc - bisect.bisect_right(c, i)
	ans += atmp * ctmp
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right,bisect_left
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 b:ans+=bisect_left(a,i)*(n-bisect_right(c,i))
print(ans)

Submission status: Accepted

Solution code:
def Binary_Search(A,x):
    L=0
    R=len(A)
    while R-L>1:
        C=(R+L-1)//2
        
        if A[C]<=x:
            L=C+1
        else:
            R=C+1
    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()
A.append(A[-1]+1)
B.sort()
C.sort()
C=[0]+C
C=[-c for c in C[::-1]]

S=0
for b in B:
    S+=Binary_Search(A,b-1)*Binary_Search(C,-(b+1))
print(S)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left

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

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

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

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(reverse=True)
c = [-x for x in c]

ans = 0
for x in b:
    ans += bisect.bisect_left(a, x) * (bisect.bisect_left(c, -x))

print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
ans = 0
L = [0] * n
for i in range(n):
    a = bisect.bisect_left(A, B[i])
    L[i] = a
cum = [0] * (n + 1)
for i in range(n):
    cum[i+1] = cum[i] + L[i]
for i in range(n):
    b = bisect.bisect_left(B, C[i])
    ans += cum[b]
print(ans)

Submission status: Accepted

Solution code:
import bisect

def main():
    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 b in B:
        indexa = bisect.bisect_left(A, b)
        indexc = bisect.bisect_right(C, b)
        ans += indexa * (N - indexc)
    print(ans)

if __name__ == '__main__':
    main()

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())))
    # print(N, A, B, C)
    # print(A)
    # print(B)
    # print(C)
    B1 = [0]*N
    for i in range(N):
        b = B[i]
        B1[i] = N - bisect.bisect_right(C, b)
        if i != 0:
            B1[i] += B1[i - 1]
    A1 = [0]*N
    for i in range(N):
        a = A[i]
        index = bisect.bisect_right(B, a)
        if index == 0:
            A1[i] = B1[-1]
        elif index < N:
            A1[i] = B1[-1] - B1[index - 1]
    ans = sum(A1)
    # print(B1, A1)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left

input = sys.stdin.buffer.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())))

cumsum = [0]
for i in range(len(B)):
    b = B[i]
    a_idx = bisect_left(A, b)
    cumsum.append(cumsum[i] + a_idx)
# print('cumsum', cumsum)

ans = 0
for i in range(len(C)):
    c = C[i]
    b_idx = bisect_left(B, c)
    ans += cumsum[b_idx]
print(ans)

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

AB = [0]*N
sAB = [0]*N
rlt = 0

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

for i in range(N):
  AB[i] = bisect_left(A, B[i])

sAB[0] = AB[0]
for i in range(N-1):
  sAB[i+1] = sAB[i] + AB[i+1]

for i in range(N):
  j = bisect_left(B, C[i])
  if j == 0:
    continue
  else:
    rlt += sAB[j-1]
  
print(rlt)

Submission status: Accepted

Solution code:
n=int(input())
from bisect import bisect_left as bl,bisect_right as br
a,b,c=[list(map(int,input().split())) for i in range(3)]
a.sort()
c.sort()
print(sum(bl(a,i)*(n-br(c,i))for i in b))

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()
from bisect import bisect_left
from bisect import bisect_right
count = 0
for bi in range(n):
  c_right = bisect_right(c, b[bi])
  a_left = bisect_left(a, b[bi])
  count += (n-c_right) * a_left
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()


Bnum=[]
a=0
for i in range(n):
    while a!=n and B[i]>A[a] :
        a+=1
    Bnum.append(a)

Cnum=[]
b=0
s=0
for i in range(n):
    while b!=n and C[i]>B[b]:
        s+=Bnum[b]
        b+=1
    Cnum.append(s)

print(sum(Cnum))

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left

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 B in Bs:
    A_idx = bisect_left(As, B)
    C_idx = bisect_right(Cs, B)
    ans += A_idx * (N - C_idx)

print(ans)

Submission status: Accepted

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

a_list.sort()
b_list.sort()
c_list.sort()
n_b = []
current = 0
for i in range(n):
    a = a_list[i]
    while current <= n-1 and b_list[current] <= a:
        current += 1
    n_b.append(n-current)
n_c = []
current = 0
for i in range(n):
    b = b_list[i]
    while current <= n-1 and c_list[current] <= b:
        current += 1
    n_c.append(n-current)
cum_nc = [0]*n
cum_nc[0] = n_c[n-1]
for i in range(1, n):
    cum_nc[i] = cum_nc[i-1] + n_c[n-1-i]
ans = 0

for i in n_b:
    if i > 0:
        ans += cum_nc[i-1]
print(ans)

Submission status: Accepted

Solution code:
import bisect

n, *lst = map(int, open(0).read().split())
alst = sorted(lst[:n])
blst = lst[n:2*n]
clst = sorted(lst[2*n:])
res = 0
for i in blst:
  a = bisect.bisect_left(alst, i)
  c = n - bisect.bisect_right(clst, i)
  res += a * c
print(res)

Submission status: Accepted

Solution code:
import bisect

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 range(n):
    num1 = bisect.bisect_left(a,b[i])
    num2 = n - bisect.bisect(c,b[i])
    ans += num1*num2

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

li = []
i = 0
for bb in b:
    while i<n and a[i]<bb:
        i += 1
    li.append(i)
li2 = [0]
accu = 0
for i in li:
    accu += i
    li2.append(accu)
ans = 0
i = 0
for cc in c:
    while i<n and b[i]<cc:
        i += 1
    ans += li2[i]
print(ans)

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from bisect import bisect_left, bisect_right
#======================================================#
def main():
    n = II()
    aa = MII(); bb = MII(); cc = MII()
    aa.sort();  bb.sort();  cc.sort()
    cnt = 0
    for b in bb:
        a = bisect_left(aa, b)
        c = bisect_right(cc, b)
        cnt += (a)*(n-c)
    print(cnt)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import bisect

readline = sys.stdin.readline

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

    A.sort()
    C.sort()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import bisect
n = inn()
a = inl()
a.sort()
a.append(10**9+1)
b = inl()
b.sort()
b.append(10**9+1)
c = inl()
c.sort()
c.append(10**9+1)
sm = 0
for i in range(n):
    p = bisect.bisect_left(a,b[i])
    q = bisect.bisect_right(c,b[i])
    sm += p*(n-q)
print(sm)

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())))
result = 0
for b in B:
    #print(search(A, b-1, True) + 1, N - search(C, b+1, False))
    result += bisect.bisect_right(A, b - 1) * (N-bisect.bisect_left(C, b + 1))
print(result)

Submission status: Accepted

Solution code:
from bisect import *
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
c = sorted(c)

rec = 0
for i in range(n):
    temp = b[i]
    l = bisect_left(a, temp)
    r = bisect_right(c, temp)
    rec += l * (n - r)
print(rec)

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()))
B_ans = [0]*N
A.sort()
B.sort()
C.sort()
ans = 0

for i, b in enumerate(B):
    bi = bisect.bisect_left(A, b)
    B_ans[i] = B_ans[i-1] + bi
for j, c in enumerate(C):
    ci = bisect.bisect_left(B, c)
    if ci == 0:
        continue

    ans += B_ans[ci-1]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left
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 b in B:
    a_id = bisect_left(A, b)
    c_id = bisect_right(C, b)
    ans += a_id * (len(C) - c_id)

print(ans)

Submission status: Accepted

Solution code:
import bisect


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

s = [0] * (N + 1)
for i, bi in enumerate(B):
    s[i + 1] = s[i] + N - bisect.bisect_right(C, bi)

print(sum(s[N] - s[bisect.bisect_right(B, ai)] for ai in A))

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)
count = 0
import bisect
for i in range(n):
    A = bisect.bisect_right(a,b[i]-1)
    C = bisect.bisect_left(c,b[i]+1)
    count += A*(n-C)
print(count)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from bisect import *

n = ni()
a = na()
b = na()
c = na()
a.sort()
c.sort()

ans = 0
for j in range(n):
    ap = bisect_left(a, b[j])
    cp = bisect_right(c, b[j])
    ans += ap * (n - cp)

print(ans)

Submission status: Accepted

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

    #B[i]の上に何種類乗るか調べる
    #res[i]:B[i]の上に乗るAの数
    res = [0]*(n)
    j = 0
    res2=[0]*(n)
    for i in range(n):
        res[i]=bisect.bisect_left(A, B[i])
        res2[i]=n-bisect.bisect_right(C, B[i])

    ans = 0

    for i in range(n):
        ans+=(res[i]*res2[i])
    return ans
if __name__ == '__main__':
    print(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:
    idx_a = bisect.bisect_left(A,b)
    idx_c = bisect.bisect_right(C,b)
    ans += idx_a * (N - idx_c)

print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
bl.sort()
cl.sort()
ans = 0
tmp1 = [n]*n
tmp2 = [n]*n
for i in range(n):
    j = bisect.bisect_left(al, bl[i])
    tmp1[i] = j
for i in range(n):
    j = bisect.bisect_right(cl, bl[i])
    tmp2[i] = n-j
for i in range(n):
    ans += tmp1[i]*tmp2[i]
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 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:
from bisect import bisect_left,bisect_right
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

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

Submission status: Accepted

Solution code:
def main(n,a,b,c):
  import bisect
  ans=0
  for i in range(n):
    na=bisect.bisect_left(a,b[i])
    nc=n-bisect.bisect_right(c,b[i])
    ans+=na*nc
  print(ans)
if __name__=='__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())))
  main(n,a,b,c)

Submission status: Accepted

Solution code:
#!python3

import numpy as np


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


def main():
    a = np.array(sorted(A))
    b = np.array(sorted(B))
    c = np.array(sorted(C))
    
    w = [None] * N
    for i in range(N):
        w[i] = N - np.searchsorted(c, b[i], side="right")
    
    wsum = [0] * (N + 1)
    for i in range(N - 1, -1, -1):
        wsum[i] = w[i] + wsum[i + 1]
    
    ans = 0
    for i in range(N):
        ans += wsum[np.searchsorted(b, a[i], side="right")]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import bisect

readline = sys.stdin.readline
bileft = bisect.bisect_left
biright = bisect.bisect_right

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort(); C.sort()
    minA = min(A); maxA = max(A)
    minC = min(C); maxC = max(C)
    ans = 0
    for b in B:
        L = minA; R = maxA + 1
        mid = (L + R) // 2
        if b >= R:
            L = R
        else:
            while L + 1 < R:
                if mid <= b:
                    L = mid
                else:
                    R = mid
                mid = (L + R) // 2
        #print('L:{}, b:{}, R:{}'.format(L, b, R))
        a = bileft(A, L)
        #print(a, A)

        L = minC; R = maxC + 1
        mid = (L + R) // 2
        if b <= L-1:
            L = L-1
        else:
            while L + 1 < R:
                if mid <= b:
                    L = mid
                else:
                    R = mid
                mid = (L + R) // 2   
        #print('L:{}, b:{}, R:{}'.format(L, b, R))
        c = len(C) - biright(C, L)
        #print(c, C)
        #print('------')

        ans += a*c

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

count = 0

for i in range(N):
  a = bisect_left(A, B[i])
  c = bisect(C, B[i])
  c = N - c
  count += (a*c)

print(count)