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 sys
from bisect import bisect_right as br
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b.sort()
c.sort()
res = 0
bt = [0] * N
for j in range(N):
  y = b[j]
  k = br(c, y)
  bt[j] = N - k
csbt = [0] * (N + 1)
for i in range(N):
  csbt[i + 1] = csbt[i] + bt[i]
for i in range(N):
  x = a[i]
  j = br(b, x)
  if j < N:
    res += csbt[-1] - csbt[j]
print(res)

Submission status: Accepted

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

def fill(D, A, c):
    for a in A:
        if a not in D:
            D[a] = {'A': 0, 'B': 0, 'C': 0}
        D[a][c] += 1


def solve(N: int, A, B, C):
    D = {}
    fill(D, A, 'A')
    fill(D, B, 'B')
    fill(D, C, 'C')
    D = sorted(D.items(), key=lambda x: x[0], reverse=True)

    a = 0
    b = 0
    c = 0
    for k, v in D:
        a += b * v['A']
        b += c * v['B']
        c += v['C']

    print(a)


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

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
BC=[0]*N
for i in range(N):
  id = bisect.bisect_right(C,B[i])
  BC[i]=N-id
sBC=[0]*(N+1)
for i in range(1,N+1):
  sBC[i]=sBC[i-1]+BC[i-1]
for i in range(N):
  id=bisect.bisect_right(B,A[i])
  ans+=sBC[N]-sBC[id]
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()
lenC = len(C)

# Bを止めて,条件を満たすA,Cを数える。足し合わせる。
ans = 0
for b in B:
  idxA = bisect.bisect_left(A, b)
  idxC = lenC - bisect.bisect_right(C, b)
  ans += idxA * idxC
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 i in b:
    ai=bisect.bisect_left(a,i)
    ci=bisect.bisect_right(c,i)
    ans+=ai*(n-ci)
print(ans)

Submission status: Accepted

Solution code:
import math
import copy
import sys
import bisect
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 x in b:
        ans += bisect.bisect_left(a, x) * (n - bisect.bisect_right(c, x))
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import bisect
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
b_ls.sort()
c_ls.sort()
comb_a = []
comb_b = []
len_b = len(b_ls)
len_c = len(c_ls)
for a in a_ls:
    ind = len_b - bisect.bisect_right(b_ls, a)
    comb_a.append(ind)

prod_b = []
res = 0
for b in b_ls[::-1]:
    ind = len_c - bisect.bisect_right(c_ls, b)
    comb_b.append(ind)
    res += ind
    prod_b.append(res)
comb_b = comb_b[::-1]
_sum = 0
for a in comb_a:
    if a <= 0:
        continue
    _sum += prod_b[a-1]
print(_sum)

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):
  ans+=bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))
  
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.sort()
c.sort()
ans = 0

bcb_cum = [0] * (n+1)
for i in range(n):
    bcb_cum[i+1] = bcb_cum[i] + n - bisect_right(c, b[i])
    
for x in a:
    l = bisect_right(b, x)
    ans += bcb_cum[n] - bcb_cum[l]

print(ans)

Submission status: Accepted

Solution code:

import sys
def input():
	return sys.stdin.readline().strip()

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 = []
a = 0
for i in range(N):
	while a < N and A[a] < B[i]:
		a += 1
	if a == N:
		B_num.append(N)
	else:
		B_num.append(a)

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


C_num = []
b = 0
for i in range(N):
	while b < N and B[b] < C[i]:
		b += 1
	if b == N:
		C_num.append(B_num[-1])
	elif b > 0:
		C_num.append(B_num[b - 1])
print(sum(C_num))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

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

ans = 0

#B_iを選んだ時にAの選び方は何通り？
BB = [0] * N
a = 0
for b in range(N):
    while A[a] < B[b] and a <= N-2:
        a += 1
    if a == N-1 and A[a] < B[b]:
        BB[b] = N
    else:
        BB[b] = a
#print(BB)

Bsum = [0] * N
Bsum[0] = BB[0]
for bb in range(1,N):
    Bsum[bb] = Bsum[bb-1] + BB[bb]
#print(Bsum)

ans = 0
b_ = 0
for c in range(N):
    while B[b_] < C[c] and b_ <= N-2:
        b_ += 1
    if b_ == N-1 and B[b_] < C[c]:
        b_ += 1
    b_ -= 1
    if b_ == -1:
        b_ = 0
        continue
    #print(b_)
    ans += Bsum[b_]

print(ans)

Submission status: Accepted

Solution code:
def slove():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = list(map(int, input().rstrip('\n').split()))
    c = list(map(int, input().rstrip('\n').split()))
    a.sort()
    b.sort()
    c.sort()
    t = 0
    for v in b:
        an = bisect.bisect_left(a, v)
        cn = n - bisect.bisect_right(c, v)
        t += (an * cn)
    print(t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
n = int(input())
an = sorted([int(i) for i in input().split()])
bn = sorted([0]+[int(i) for i in input().split()])
cn = sorted([int(i) for i in input().split()])
dpb = [0]*(n+1)
dpc = [0]*n
cnt = 0
for i in range(n+1):
  while cnt < n and bn[i] > an[cnt]:
    cnt += 1
  dpb[i] = cnt
cnt = 0
temp = 0
for i in range(n):
  while cnt < n+1 and cn[i] > bn[cnt]:
    temp += dpb[cnt]
    cnt += 1
  dpc[i] = temp
print(sum(dpc))

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

Submission status: Accepted

Solution code:
import bisect
import numpy as np
N = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
b_bisect = [bisect.bisect_left(a,one) for one in b]
b_cumsum = np.cumsum(b_bisect)
c_bisect = [bisect.bisect_left(b,one) for one in c]

ans = 0
for one in c_bisect:
    if one == 0:
        continue
    else:
        ans += b_cumsum[one-1]
print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
c_list = [int(x) for x in input().split()]

a_list = sorted(a_list)
b_list = sorted(b_list)
c_list = sorted(c_list)

ans = 0

for b_i in b_list:
    a_count_i = bisect.bisect_left(a_list,b_i)
    c_count_i = len(c_list) - bisect.bisect_right(c_list,b_i)
    ans += a_count_i * c_count_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()
B.sort()
C.sort()

BC = {}
for i in range(N):
  rank = N - bisect.bisect_right(C, B[i])
  BC[B[i]] = rank
#print(BC)
BCS = [0 for _ in range(N)]
BCS[N-1] = BC[B[N-1]]
for i in range(N-2,-1,-1):
  BCS[i] =  BCS[i+1] + BC[B[i]]
#print(BCS)

ans = 0
for i in range(N):
  rank = bisect.bisect_right(B, A[i])
  if rank < N:
    ans += BCS[rank]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right


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())))
    l = [0] * n
    for index, i in enumerate(b):
        l[index] = n - bisect_right(c, i)
    s = [l[-1]] * n
    for i in range(n - 2, -1, -1):
        s[i] = s[i + 1] + l[i]
    ans = 0
    for i in a:
        j = bisect_right(b, i)
        if j < n:
            ans += s[j]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect as bi

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()
#print(a)
#print(c)

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

Submission status: Accepted

Solution code:
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()])
import bisect
ans=0
for i in range(n):
  b=B[i]
  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()
C.sort()
LC = len(C)
ans = 0
for b in B:
    na = bisect.bisect_left(A, b)
    nc = LC - bisect.bisect_right(C, b)
    ans += na * nc

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()))
s = 0

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

ia = -1
ic = -1

for b in B:
  while True:
    if ia == N-1 or A[ia+1]>=b: 
      break
    ia += 1
  while True:
    if ic == N-1 or C[ic+1]>b:
      break
    ic += 1
  s += (ia+1)*(N-ic-1)
    
print(s)

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

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

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()
B.sort()
C.sort()
ans = 0
for b in B:
    ia = min(bisect.bisect_left(A,b),N-1)
    ic = min(bisect.bisect_right(C,b),N-1)
    a = ia if A[ia]>=b else ia+1
    c = N-ic-1 if C[ic]<=b else N-ic
    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 = 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:
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()
count1=0
count2=0
ans=0

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

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()))
ad=sorted(a)
bd=sorted(b)
cd=sorted(c)
#print(ad)
#print(bd)
#print(cd)
count=0
for i in range(n):
  al=bisect.bisect_left(ad,bd[i])
  cl=bisect.bisect_right(cd,bd[i])
  sum=al * ( n - cl )
  #print(str(al) + " " + str(cl) + " " + str(sum))
  count=count+( al * ( n - cl ) )
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()
y=[]
import bisect
for i in range(n):
	y.append(bisect.bisect_left(a,b[i]))
ans=0
q=[]
for i in range(n):
	p=bisect.bisect_left(b,c[i])
	q.append(p)
k=sum(y[0:q[0]])
for i in range(n-1):
	ans+=k
	if q[i+1]!=q[i]:
		k+=sum(y[q[i]:q[i+1]])
ans+=k
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())))
t = 0
for i in b:
    t += (bisect.bisect_left(a, i) * (n - bisect.bisect_right(c, i)))
print(t)

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
from bisect import bisect_left
from bisect import bisect_right

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


X = [bisect_left(A ,B[i]) for i in range(N)]
Y = [N - bisect_right(C ,B[i]) for i in range(N)]

total = 0

for x,y in zip(X, Y):
    total += x * y

print(total)

Submission status: Accepted

Solution code:
# 2019/08/07
# Bのソートは不要！！

from bisect import bisect_left,bisect_right

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):
    bc=n-bisect_right(c,b[i])
    ba=bisect_left(a,b[i])
    ans+=bc*ba    

print(ans)

Submission status: Accepted

Solution code:
# 2019/08/07

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):
    bc=n-bisect_right(c,b[i])
    ba=bisect_left(a,b[i])
    ans+=bc*ba    

print(ans)

Submission status: Accepted

Solution code:
import bisect

a = int(input())
b = list(map(int, input().split()))
b.sort()
c = list(map(int, input().split()))
d = list(map(int, input().split()))
d.sort()
e = 0
for i in c:
    e += bisect.bisect_left(b, i) * (a - bisect.bisect_right(d, i))
print(e)

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
i = 0
j = 0
for b in B:
    while i < N and A[i] < b:
        i += 1
    while j < N and C[j] <= b:
        j += 1
    ans += i * (N-j)

print(ans)

Submission status: Accepted

Solution code:
import bisect
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = list(map(int, input().split()))
d = list(map(int, input().split()))
d.sort()
ans = 0
for i in range(a):
    ans += bisect.bisect_left(b, c[i]) * (a - bisect.bisect_right(d, c[i]))
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())))
s=0
for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    s+=a*c
print(s)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = sorted([int(i) for i in input().split()])
ans = 0
for i in b:
    ans += bisect.bisect_left(a, i) * (n - bisect.bisect(c, i))
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect
n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
ans=0
for i in lb:
    ans+=bisect_left(la,i)*(len(lc)-bisect(lc,i))
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect

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

b_cost = [0]

for i,b in enumerate(bb):
  b_cost.append(N-bisect(cc, b)+b_cost[i])

ans = 0
for a in aa:
  idx = bisect(bb, a)
  ans += b_cost[-1]-b_cost[idx]
print(ans)

Submission status: Accepted

Solution code:
# ABC 84, C - sunuke festival
import bisect

n = int(input())
A = sorted([int(el) for el in input().split(' ')])
B = [int(el) for el in input().split(' ')]
C = sorted([int(el) for el in input().split(' ')])

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(_) for _ in input().split()])
b=[int(_) for _ in input().split()]
c=sorted([int(_) for _ in input().split()])
x=0
for i in range(n):
    oa=-1
    na=n
    while na-oa>1:
        ma=(oa+na)//2
        if a[ma]<b[i]:oa=ma
        else:na=ma
    ob=n
    nb=-1
    while ob-nb>1:
        mb=(ob+nb)//2
        if c[mb]>b[i]:ob=mb
        else:nb=mb
    x+=(oa+1)*(n-ob)
print(x)

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:
# ARC084C - Snuke Festival
import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right

def main():
    n = int(input())
    A, B, C = [sorted(map(int, input().rstrip().split())) for _ in range(3)]
    l, ans = len(C), 0
    for i in B:
        ans += bisect_left(A, i) * (l - bisect_right(C, i))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ARC084C - Snuke Festival
from bisect import bisect_left, bisect_right

def main():
    n = int(input())
    A, B, C = [sorted(tuple(map(int, input().rstrip().split()))) for _ in range(3)]
    l, ans = len(C), 0
    for i in B:
        ans += bisect_left(A, i) * (l - bisect_right(C, i))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
dat_a = list(map(int, input().split()))
dat_b = list(map(int, input().split()))
dat_c = list(map(int, input().split()))
dat_a.sort()
dat_b.sort()
dat_c.sort()

import bisect
res = 0
for i in range(n):
    x = bisect.bisect_left(dat_a, dat_b[i])
    y = bisect.bisect_right(dat_c, dat_b[i])
    res += x * (n - y)
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()

def func(x, y):
    i = 0
    j = 0
    cnt = 0
    s = [0 for i in range(n)]
    while j < n and i < n:
        if y[j] > x[i]:
            cnt += 1
            i += 1
        else:
            s[j] = cnt
            j += 1
    if i == n:
        for k in range(j,n):
            s[k] = cnt
    return s

s1 = func(a, b)
for i in range(1, n):
    s1[i] += s1[i-1]
s2 = func(b, c)
cnt = 0
for i in range(n):
    if s2[i] != 0:
        cnt += s1[s2[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())))
ans=0
for i in range(n):
  d=bisect.bisect_left(a,b[i])
  e=bisect.bisect_right(c,b[i])
  ans+=d*(n-e)
print(ans)

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

from bisect import bisect_left,bisect_right
cnt = 0
for i in b:
    cnt += bisect_left(a,i)*(n-bisect_right(c,i))

print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N-bisect_right(C, 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())))
cnt = 0
for bb in b:
    anum = bisect.bisect_left(a, bb)
    cnum = n - bisect.bisect_right(c, bb)
    cnt += (anum * cnum)
print(cnt)

Submission status: Accepted

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

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = 0
a.sort()
c.sort()
for i in range(n):
    cnt += (bisect.bisect_left(a, b[i])) * (n-bisect.bisect_right(c, b[i]))
print(cnt)

Submission status: Accepted

Solution code:
import bisect
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
B = [int(_) for _ in stdin.readline().rstrip().split()]
C = [int(_) for _ in stdin.readline().rstrip().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:
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

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

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

for i in range(len(B) - 2, -1, -1):
	bt[i] += bt[i + 1]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += bt[bif]

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()))
ans=0
a.sort()
b.sort()
c.sort()
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 = 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
j = 0
k = 0


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

    ans += j*(n-k)


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

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())))
cnt=0
x=[]
i=0
b__=b.copy()
rev=0
while(b__):
     b_=b__.pop()
     while(1):
          try:
               c_=c.pop()
          except:
               rev+=cnt
               x.append(rev)
               cnt=0
               break
          if c_>b_:
               cnt+=1
          else:
               rev+=cnt
               x.append(rev)
               cnt=0
               c.append(c_)
               break
cnt=0
i=n-1
rev=0
ans=0
while(a):
     a_=a.pop()
     while(1):
          try:
               b_=b.pop()
          except:
               rev+=cnt
               ans+=rev
               cnt=0
               break
          if b_>a_:
               cnt+=x.pop(0)
          else:
               rev+=cnt
               ans+=rev
               cnt=0
               b.append(b_)
               break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC084C - Snuke Festival
# Binary search
from bisect import bisect_left, bisect_right

n = int(input())
A, B, C = [sorted(list(map(int, input().rstrip().split()))) for _ in range(3)]
lgth = len(C)
ans = 0
for i in B:
    ans += bisect_left(A, i) * (lgth - bisect_right(C, i))
print(ans)

Submission status: Accepted

Solution code:
# ABC084C - Snuke Festival
from bisect import bisect_left, bisect_right

n = int(input())
lst_a = sorted(list(map(int, input().rstrip().split())))
lst_b = sorted(list(map(int, input().rstrip().split())))
lst_c = sorted(list(map(int, input().rstrip().split())))
lgth = len(lst_c)
ans = 0
for i in lst_b:
    ans += bisect_left(lst_a, i) * (lgth - bisect_right(lst_c, i))
print(ans)

Submission status: Accepted

Solution code:
# ABC084C - Snuke Festival
from bisect import bisect_left, bisect_right

n = int(input())
lst_a = sorted(list(map(int, input().rstrip().split())))
lst_b = list(map(int, input().rstrip().split()))
lst_c = sorted(list(map(int, input().rstrip().split())))
lgth = len(lst_c)
ans = 0
for i in lst_b:
    ans += bisect_left(lst_a, i) * (lgth - bisect_right(lst_c, 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()
B.sort()
C.sort()

count = 0

for i in range(len(B)):
    a_b = bisect.bisect_left(A,B[i])
    c_b = bisect.bisect_right(C,B[i])
    count += a_b * (N - c_b)

print(count)

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

sum = 0
for i in range(len(b)):
    ai = bisect.bisect_left(a, b[i])
    ci = bisect.bisect_right(c, b[i])
    sum += ai * (n - ci)

print(sum)

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

cur_l = 0
cur_r = 0
p = 0
for cur_mid in B:
    while cur_l < len(A):
        if A[cur_l] >= cur_mid:
            break
        cur_l += 1
    while cur_r < len(C):
        if cur_mid < C[cur_r]:
            break
        cur_r += 1
    p += cur_l * (len(C) - cur_r)

print(p)

Submission status: Accepted

Solution code:
N = int(input())

L = []
L.extend(((int(x), 3)  for x in input().split()))
L.extend(((int(x), 2)  for x in input().split()))
L.extend(((int(x), 1)  for x in input().split()))

L = sorted(L, reverse=True)

cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
    if i == 1:
        cnt_C += 1
    elif i == 2:
        cnt_B += cnt_C
    elif i == 3:
        cnt_A += cnt_B

print(cnt_A)

Submission status: Accepted

Solution code:
N = int(input())

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

L = []
L.extend(((x, 3)  for x in A))
L.extend(((x, 2)  for x in B))
L.extend(((x, 1)  for x in C))

L = sorted(L, reverse=True)

cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
    if i == 1:
        cnt_C += 1
    elif i == 2:
        cnt_B += cnt_C
    elif i == 3:
        cnt_A += cnt_B

print(cnt_A)

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

numpattern = 0

for i in range(N):
    numsmallerA = bisect.bisect_left(A,B[i])
    numbiggerC = N - bisect.bisect_right(C,B[i])
    numpattern += numsmallerA * numbiggerC

print(numpattern)

Submission status: Accepted

Solution code:
from bisect import bisect_left as bisect
from numpy import cumsum
N=int(input())
A,B,C=[sorted([int(_) for _ in input().split()]) for __ in range(3)]
ableAonB=[]
ableBonC=[]
ans=0
for b in B:
    ableAonB.append(bisect(A,b))
sumAonB=(cumsum(ableAonB))
for c in C:
    ableBonC.append(bisect(B,c))
for c in ableBonC:
    if c==0:continue
    ans+=sumAonB[c-1]
print(ans)