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 = 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 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 = [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_list = []
b_list = []

tmp = n-1
num = 0

for i in range(n):
    while tmp >= 0 and a[n-i-1] < b[tmp]:
        tmp -= 1
        num += 1
    a_list.append(num)
    #num = 0

tmp = n-1
num = 0

for i in range(n):
    while tmp >= 0 and b[n-i-1] < c[tmp]:
        tmp -= 1
        num += 1
    b_list.append(num)
    #num = 0

b_rui = []
tmp = 0

for i in range(n):
    tmp += b_list[i]
    b_rui.append(tmp)

ans = 0

for i in range(n):
    if a_list[i] == 0:
        continue
    ans += b_rui[a_list[i]-1]
    
print(ans)

Submission status: Accepted

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

# B➡Cの対応表を作る
numb = [0]*n
for i,c in enumerate(B):
    numb[i] = n-bisect.bisect_right(C,c)
#print(numb)
for i in range(n-1,0,-1):
    numb[i-1] += numb[i]
#print(numb)
ans = 0
for i in range(n):
    j = bisect.bisect_right(B,A[i])
    if j < n:
        ans += numb[j]
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 x in B:
    ai = bisect.bisect_left(A,x)
    ci = bisect.bisect_right(C,x)
    ans += (ai*(N-ci))
print(ans)

Submission status: Accepted

Solution code:
import bisect


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

ans = 0
for 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 = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

bcount = [0] * (n+1)

bsum = 0
for i in range(n)[::-1]:
        bsum += n - bisect.bisect_right(c, b[i])
        bcount[i] = bsum

result = 0
for i in range(n):
        result += bcount[bisect.bisect_right(b, a[i])]

print(result)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    parts = [[int(a), 0] for a in input().split()]
    parts += [[int(b), 1] for b in input().split()]
    parts += [[int(c), 2] for c in input().split()]
    parts = sorted(parts, key = lambda x: x[0], reverse = True)
    countC = 0
    countBC = 0
    ans = 0
    for i in range(len(parts)):
        if parts[i][1] == 0:
            ans += countBC
        elif parts[i][1] == 1:
            countBC += countC
        else:
            countC += 1
    return ans 

if __name__ == '__main__':
    print(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()))
l=[]
for i in range(N):
    l.append([A[i],3])
    l.append([B[i],2])
    l.append([C[i],1])
l.sort()
a=0
c=N
s=0
for i in range(3*N):
    if l[i][1]==3:
        a+=1
    elif l[i][1]==2:
        s+=a*c
    else:
        c-=1
print(s)

Submission status: Accepted

Solution code:

import bisect

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

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

An = np.array(A)
Bn = np.array(B)
Cn = np.array(C)

An.sort()
Bn.sort()
Cn = -Cn
Cn.sort()

AB = np.searchsorted(An,Bn,side='left')
CB = np.searchsorted(Cn,-Bn,side='left')

print((AB*CB).sum())

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()
total=0
for i in range(N):
    X=bisect.bisect_left(A, B[i])
    Y=len(C)-bisect.bisect_right(C, B[i])
    total+=X*Y
print(total)

Submission status: Accepted

Solution code:

import bisect



def cumsum(inlist):
    s = 0
    outlist = []
    for i in inlist:
        s += i
        outlist.append(s)
    return outlist

n = int(input())
a_list = sorted([ int(v) for v in input().split() ])
b_list = sorted([ int(v) for v in input().split() ])
c_list = sorted([ int(v) for v in input().split() ])
a_b_list = [ bisect.bisect_right(a_list,i-1) for i in b_list]
b_c_list = [ bisect.bisect_right(b_list,i-1) for i in c_list]
a_b_cumsum_list = cumsum(a_b_list)
a_b_c_list = [ a_b_cumsum_list[i-1] for i in b_c_list if i != 0]
print(sum(a_b_c_list))

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort()
C.sort()
ans = sum([bisect_left(A, b) * (N - bisect_right(C, b)) for b in B])
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort()
B.sort()
C.sort()
cnt = [0] * (N + 1)
j = 0
for i, b in enumerate(B):
    while j < N and A[j] < b:
        j += 1
    cnt[i + 1] = j
cnt = list(accumulate(cnt))
ans = 0
j = 0
for i, c in enumerate(C):
    while j < N and B[j] < c:
        j += 1
    ans += cnt[j]
print(ans)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

counts = []
a = 0
for b in range(N):
    while a < N and B[b] > A[a]:
        a += 1
    counts.append(a)

cs = list(itertools.accumulate(counts))
s = sum(counts)
ans = 0
b = 0
for c in range(N):
    while b < N and C[c] > B[b]:
        b += 1

    ans += cs[b - 1] if b - 1 >= 0 else 0
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, B, C = sorted(A), sorted(B), sorted(C)

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = n - bisect.bisect_right(C, b)
    if a > 0 and c > 0:
        ans += a*c

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):
    b = B[i]
    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 = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))
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 = list(map(int, input().split()))
a.sort()
b = list(map(int, input().split()))
c = list(map(int, input().split()))
c.sort()
cnt = 0
for i in b:
    cnt += bisect.bisect_left(a, i) * (n - bisect.bisect_right(c, i))
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left
from collections import defaultdict

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

AB = defaultdict(int)

for b in B:
    AB[b] = bisect_left(A, b)

sumAB = defaultdict(int)
sumAB[0] = 0
s = 0
for b in B:
    s += AB[b]
    sumAB[b] = s

B.insert(0, 0)
ans = 0
for c in C:
    r = bisect_left(B, c)
    ans += sumAB[B[r - 1]]

print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
X = [sorted(list(map(int,input().split()))) for i in range(3)]
def nmb(i):
	left = bisect.bisect_left(X[0],i)
	right = bisect.bisect_right(X[2],i)
	return left*(len(X[2])-right)

ans = 0
for i in X[1]:
	ans += nmb(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 for i in range(n)]
buf = [0 for i in range(n)]

a.reverse()
b.reverse()
c.reverse()
#
# print(a)
# print(b)
# print(c)


ind = 0
for i in range(n):
    buf[i]=buf[i-1]
    if ind > n - 1:
        continue
    while(True):
        if b[i] < c[ind]:
            buf[i] += 1
            ind += 1
            if ind > n-1:
                break
        else:
            break
# print(buf)


ind = 0
for i in range(n):
    ans[i]=ans[i-1]
    if ind > n - 1:
        continue
    while True:
        if a[i] < b[ind]:
            ans[i] += buf[ind]
            ind += 1
            if ind > n-1:
                break
        else:
            break

# print(ans)
print(sum(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()

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

Submission status: Accepted

Solution code:
import bisect

N = int(input())

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

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

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:
    ri = bisect.bisect_left(A, i)
    li = N - bisect.bisect_right(C, i)
    ans += ri*li

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()
bans = []
for bi in range(n):
  bnow = b[bi]
  here = bisect.bisect_right(c,bnow)
  bans.append([bnow,n-here])
bsun = 0
for bi in range(n):
  bsun += bans[n-1-bi][1]
  bans[n-1-bi].append(bsun)
ans = 0
for ai in range(n):
  anow = a[ai]
  here = bisect.bisect_right(b,anow)
  if here != n:
    ans += bans[here][2]
#print(bans)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect
from itertools import accumulate
n,*l = map(int,open(0).read().split())
s = sorted
a,b,c = s(l[:n]),s(l[n:2*n]),s(l[2*n:])
ref=[]
for i in b:
	ref.append(n-bisect(c,i))
ref = list(accumulate(ref[::-1]))[::-1] + [0]
ans=0
for i in a:
	ans += ref[bisect(b,i)]
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()))
C = list(map(int, input().split()))
C.sort()

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())

lista=np.array(list(map(int,input().rstrip().split())))
listb=np.array(list(map(int,input().rstrip().split())))
listc=np.array(list(map(int,input().rstrip().split())))
lista=np.sort(lista)
listc=np.sort(listc)

cont=0

for naka in listb:
	ueikeruyatsu=np.searchsorted(lista,naka,side='left')
	shitaikeruyatsu=n - np.searchsorted(listc,naka,side='right')
	cont += ueikeruyatsu * shitaikeruyatsu


print(cont)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, bisect


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)

    counter = 0
    for j in range(N):
        b = B[j]
        ba = bisect.bisect_left(A, b)
        cb = N - bisect.bisect_right(C, b)
        counter += ba*cb
    
    print(counter)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

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

lenC = len(C)

cnt = 0

for b in B:
    ind_a = bisect.bisect_left(A, b)
    ind_c = bisect.bisect_right(C, b)
    cnt += ind_a * (lenC - ind_c)

print(cnt)

Submission status: Accepted

Solution code:
import bisect

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

    sort_A = sorted(A)
    sort_B = sorted(B)
    sort_C = sorted(C)
    cnt = 0
    for b in sort_B:
        a = bisect.bisect_left(sort_A, b)
        c = N - bisect.bisect_right(sort_C, b)
        cnt += a * c

    print(cnt)

main()

Submission status: Accepted

Solution code:

def main():
    from bisect import bisect_right
    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())

    b2c = [0] * (N+1)
    for i in range(N):
        b = B[i]
        j = bisect_right(C, b)
        b2c[i] = N - j
        #print("B[%d]=%5d"%(i,b), "C[%d]=%5d"%(j, C[j]), "bc=%d"%(N-j))

    for i in range(N-1)[::-1]:
        b2c[i] += b2c[i+1]
        pass
    #print(b2c)

    total = 0
    for i in range(N):
        a = A[i]
        a2b = bisect_right(B, a)
        t = b2c[a2b]
        #print("%d:t=%d"%(i, t),a2b)
        total+=t

    print(total)
        
main()

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

b2c = [0] * (N+1)
for i in range(N):
    b = B[i]
    j = bisect_right(C, b)
    b2c[i] = N - j
    #print("B[%d]=%5d"%(i,b), "C[%d]=%5d"%(j, C[j]), "bc=%d"%(N-j))

for i in range(N-1)[::-1]:
    b2c[i] += b2c[i+1]
    pass
#print(b2c)

total = 0
for i in range(N):
    a = A[i]
    a2b = bisect_right(B, a)
    t = b2c[a2b]
    #print("%d:t=%d"%(i, t),a2b)
    total+=t

print(total)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0

for b in B:
  num_a = bisect.bisect_left(A, b)
  num_c = n - bisect.bisect_right(C, b)
  ans += num_a * num_c
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 b in B:
    lower_A = bisect.bisect_left(A, b)  # b以上の値が初めて現れるインデックスが得られる
    upper_C = bisect.bisect_right(C, b)  # bより真に大きい値が初めて現れるインデックスが得られる
    ans += lower_A * (N-upper_C)

print(ans)

Submission status: Accepted

Solution code:

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

A.sort()
C.sort()

def bin_search_withR(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

def bin_search_withL(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] > targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

total = 0
for b in B:
    a_ub, a_lb = bin_search_withR(A, b)
    c_ub, c_lb = bin_search_withL(C, b)
    total += a_ub * (N - c_ub)

print(total)

Submission status: Accepted

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

import bisect
upper_condition = [bisect.bisect_left(A, b) for b in B]
lower_condition = [N - bisect.bisect_right(C, b) for b in B]

print(sum(map(lambda x: x[0]*x[1], zip(upper_condition, lower_condition))))

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

print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    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, bisect_left

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

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

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

    ans += p * q

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

nums = []
for idx in range(N):
  nums.append((1, A[idx]))
  nums.append((2, B[idx]))
  nums.append((3, C[idx]))
nums.sort(key=lambda x:(x[1], -x[0]))
sum_a = 0
sum_b = 0
sum_c = 0
for idx in range(3*N):
  if nums[idx][0] == 1:
    sum_a += 1
  elif nums[idx][0] == 2:
    sum_b += sum_a
  elif nums[idx][0] == 3:
    sum_c += sum_b
print(sum_c)

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())))
B=[0]*n
j=0
for i in range(n):
    while b[i]>=c[j] and j<n-1:j+=1
    if b[i]<c[j]:B[i]=n-j
ans=0
s=sum(B)
j=0
for i in range(n):
    while a[i]>=b[j] and j<n-1:s-=B[j];j+=1
    if a[i]<b[j]:ans+=s
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import bisect



def main():
    num = int(input())
    data_a = list(map(int, input().split()))
    data_a.sort()
    data_b = list(map(int, input().split()))
    data_b.sort()
    data_c = list(map(int, input().split()))
    data_c.sort()

    ans = 0
    for ele in data_b:
        aaa = bisect.bisect_left(data_a, ele)
        bbb = bisect.bisect_right(data_c, ele)
        bbb = num - bbb
        ans += aaa * bbb
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    while a<N and A[a]<i:
        a+=1
    while c<N and C[c]<=i:
        c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    B = inputList()
    C = inputList()
    
    A.sort()
    B.sort()
    C.sort()
    
    tmplist = []
    for i,val in enumerate(B):
        target1 = bisect_left(C, val+1)
        tmp = N - target1
        tmplist.append(tmp)
            
    for i in range(N-2, -1, -1):
        tmplist[i] = tmplist[i] + tmplist[i+1]
        
    #print(tmplist)
    
    ans = 0
    for i,val in enumerate(A):
        target1 = bisect_left(B, val+1)
        if target1 == N:
            continue
        ans += tmplist[target1]
        
    print(ans)
    
    
            	
if __name__ == "__main__":
	main()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_left
INF = float("inf")


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    B.sort()
    C.sort()
    count = 0
    for b in B:
        countA = bisect_left(A, b)
        countC = N-bisect_left(C, b+1)
        count += countA*countC
    print(count)

    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

CI = []
for b in B:
    ci = bisect_right(C, b)
    CI.append(N-ci)

CII = CI[::-1]
D = []
d = 0
for cii in CII:
    d += cii
    D.append(d)

D = D[::-1]

ans = 0
for a in A:
    bi = bisect_right(B, a)
    if bi == N:
        continue
    ans += D[bi]
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
k = []
for _ in range(3):
    a = [int(i) for i in input().split()]
    a.sort()
    k.append(a)
count = 0
for i in k[1]:
    b = bisect.bisect_left(k[0],i)
    c = bisect.bisect_right(k[2],i)
    count += b*(n-c)
print(count)

Submission status: Accepted

Solution code:
import bisect

N=int(input())
A=[]
for _ in range(3):
    lst=list(map(int,input().split()))
    lst.sort()
    A.append(lst)
cnt=0
for i in range(N):
    numl=bisect.bisect_left(A[0],A[1][i])
    numr=(N-bisect.bisect_right(A[2],A[1][i]))
    cnt+=numl*numr
print(cnt)

Submission status: Accepted

Solution code:
import bisect

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

a.sort()
c.sort()

ans = 0

for i in b:
	ans += (bisect.bisect_left(a,i)) * (len(c) - bisect.bisect_right(c,i))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split()])
B = [int(b) for b in input().split()]
C = sorted([int(c) for c in input().split()])
ans = 0

import bisect
for i in range(N):
  b = B[i]
  end_A = bisect.bisect_left(A, b)
  start_C = bisect.bisect_right(C, b)
  ans += end_A * (N - start_C)

print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
ABC = [list(map(int,input().split())) for i in range(3)]
ABC[0].sort()
ABC[2].sort()

ans = 0
for i in range(N):
    B_hi = bisect.bisect_left(ABC[0],ABC[1][i])
    B_lo =N - bisect.bisect_right(ABC[2],ABC[1][i])
    ans += B_hi * B_lo

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 b in B:
    countA = bisect.bisect_left(A, b)
    countC = len(C) - bisect.bisect(C, b)
    ans += countA * countC

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
import bisect
import numpy as np
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_b=np.zeros(n,dtype=np.int64)
def lower_elements(A, b):
    ''' リストAの要素のうち，b未満のものの個数を返す関数 '''
    lower_bound = -1
    upper_bound = len(A)
    while upper_bound - lower_bound > 1:
        middle = (lower_bound + upper_bound) // 2
        if A[middle] < b:
            lower_bound = middle
        else:
            upper_bound = middle
    return lower_bound + 1
 
 
def upper_elements(C, b):
    ''' リストCの要素のうち，cより大きいものの個数を返す関数 '''
    i = -1
    j = len(C)
    while j - i > 1:
        m = (i + j) // 2
        if C[m] > b:
            j = m
        else:
            i = m
    return len(C) - j

for i in range(n):
    count_b[n-1-i]=upper_elements(c,b[i])
count=np.cumsum(count_b)
ans=0
for i in range(n):
    x=upper_elements(b,a[i])
    if x!=0:
        ans+=count[x-1]
print(ans)

Submission status: Accepted

Solution code:
import bisect


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

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

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()
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:
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:
#!/usr/bin/env python3
#ABC77 C

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

Submission status: Accepted

Solution code:
n=int(input())
a,b,c=[list(map(int,input().split())) for _ in [0]*3]
from itertools import accumulate
a.sort()
b.sort()
c.sort()
a+=[10**20]
b+=[10**20]
 
p,q=0,0
cnt=0
ans=[0]*n
for i in range(n):
    for j in range(p,n+1):
        if b[i]>a[j]:
            pass
        else:
            break
    ans[i]=j
    p=j
ans=[0]+list(accumulate(ans))

for i in range(n):
    for j in range(q,n+1):
        if c[i]>b[j]:
            pass
        else:
            break
    q=j
    cnt+=ans[j]
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())))
print(sum(bisect.bisect_left(a,b)*(N-bisect.bisect_right(c,b)) for b in B))

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

print(ans)

Submission status: Accepted

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

a_big_b = [0] * len(a)
for i,p in enumerate(a):
    j = bisect.bisect_right(b, p)
    a_big_b[i] = j

b_big_c = [0] * len(b)
for i in range(len(b)-1,-1,-1):
    k = len(c) - bisect.bisect_right(c, b[i])
    if i==len(b)-1:b_big_c[i] = k
    else:b_big_c[i] = k + b_big_c[i+1]

g=0
for aa in a_big_b:
    if aa == len(b_big_c):pass
    else:g += b_big_c[aa]
print(g)