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

sum=0
for bb in b:
    x=bisect.bisect_left(a,bb)
    y=bisect.bisect_right(c,bb)
    sum+=x*(n-y)
print(sum)

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

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

    okb[i] = k

ans = 0
okc = 0

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

    ans += okc
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

b_a = [0]
for i in range(n):
    bsct = bisect.bisect_left(a,b[i])
    b_a.append(bsct)
b_a_sum = [0]
sm = 0
for i in range(1,n+1):
    sm += b_a[i]
    b_a_sum.append(sm)
ans = 0
for i in range(n):
    mid =  bisect.bisect_left(b,c[i])
    ans += b_a_sum[mid] 
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
lists1=sorted(list(map(int,input().split())))+[10**9+1]

lists2=sorted(list(map(int,input().split())))+[10**9+2]
lists3=sorted(list(map(int,input().split())))+[10**9+3]
lists_small=[0]*(n+1)
lists_big=[0]*(n+1)

numbers=0
for x in range(n):
    while lists1[numbers]<lists2[x]:
        numbers+=1
    lists_small[x]=numbers


numberss=0
for y in range(n):
    while lists3[numberss]<=lists2[y]:
        numberss+=1
    changes=n-numberss
    lists_big[y]=changes



ans=0
for xy in range(n):
    ans+=lists_big[xy]*lists_small[xy]
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
from collections import deque

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 = [-i for i in A]
B = [-i for i in B]
C = [-i for i in C]
BD = [i for i in B]

heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)
heapq.heapify(BD)

ai = [0]*N
bi = [0]*N
ci = [1]*N

def compete_cal(N, B, C, bi, ci):
    ciq = deque(ci)
    for i in range(N):
        b=-heapq.heappop(B)
        while len(C)>0:
          c=-heapq.heappop(C)
          if c>b:
              bi[i]+=ciq.popleft()
          else:
              heapq.heappush(C, -c)
              break

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

    return bi   

bi = compete_cal(N, B, C, bi, ci)

ai = compete_cal(N, A, BD, ai, bi)
    
print(sum(ai))

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 sys
import heapq
from collections import deque

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 = [-i for i in A]
B = [-i for i in B]
C = [-i for i in C]
BD = [i for i in B]


heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)
heapq.heapify(BD)

ai = [0]*N
bi = [0]*N
ci = [1]*N


for i in range(N):
    b=-heapq.heappop(B)
    cnt=False
    while not cnt:
        if len(C)==0:
            cnt=True
            break
        else:
            c=-heapq.heappop(C)
            if c>b:
                bi[i]+=1
            else:
                cnt=True
                heapq.heappush(C, -c)

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

bi = deque(bi)   
    
for i in range(N):
    a=-heapq.heappop(A)
    while len(BD)>0:
        b=-heapq.heappop(BD)
        if b>a:
            ai[i]+=bi.popleft()
        else:
            heapq.heappush(BD, -b)
            break
        
         
for i in range(1,N):
    ai[i]+=ai[i-1]
    
print(sum(ai))

Submission status: Accepted

Solution code:
import bisect

#データの代入
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

#昇順にソート
A.sort()
B.sort()
C.sort()
 
#方針
#適当にBを決める
#当てはまるAとCのパターン数を求める
#A×C
#これをすべてのBで繰り返す

pattern = 0
minA = min(A)
maxC = max(C)

for i in B:
        if minA < i and maxC > i:
                #あてはまるA,Cが存在
                index = bisect.bisect_left(A, i)
                index2 = bisect.bisect_right(C, i)

                #挿入できる個数
                canA = index
                canC = N - index2

                pattern += canA * canC
        
print(pattern)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    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:
        i=bisect.bisect_left(A,b)
        j=bisect.bisect_right(C,b)
        ans+=i*(n-j)
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
cnt = 0
for b in B:
  pos_a = bisect.bisect_left(A, b)
  pos_c = bisect.bisect_right(C, b)
  cnt += pos_a * (N-pos_c)
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left
from bisect import bisect_right

N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
j = bisect_left(C, B[0])
ansBC = [N - j] + [0] * (N-1)

for i in range(1, N):
    while j < N and B[i] >= C[j]:
        j += 1
    if j == N:
        break
    ansBC[i] = N - j

j = N-1
ans = 0
for i in range(N):
    while j >= 0 and A[i] < B[j]:
        ans += ansBC[j] * (N - i)
        j -= 1
    if j == -1:
        break
    
print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
ls = [sorted(map(int, input().split())) for _ in range(3)]
res = 0
for i in range(n):
    b = ls[1][i]
    x = bisect.bisect_right(ls[0], b - 1)
    y = bisect.bisect_left(ls[2], b + 1)
    res += x * (n - y)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left
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()))
A.sort()
B.sort()
C.sort()
ans = 0
for j in range(N):
    b = B[j]
    i = bisect_left(A, b)
    k = bisect_right(C, b)
    ans += i * (N - k)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()



small = sorted(LI())
middle = sorted(LI())
big = sorted(LI())


ans = 0
for i in range(n):
    ans += bisect_left(small, middle[i]) * (n - bisect_right(big, middle[i]))



print(ans)

Submission status: Accepted

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

import bisect

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

cnt = 0
for j in range(N):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect_right(C, B[j])
    cnt += i *(N-k)

print(cnt)

Submission status: Accepted

Solution code:
def main():
    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()))
    
    A = sorted(A) + [float("inf")]
    B = sorted(B) + [float("inf")]
    C = sorted(C) + [float("inf")]
    
    b, c = 0, 0
    BC = []
    while b < N:
        if B[b] < C[c] or c == N:
            BC.append(N-c)
            b += 1
        else:
            c += 1
    for i in range(N-1):
        BC[N-2-i] += BC[N-1-i]
    
    a, b = 0, 0
    AB = []
    while a < N:
        if b == N:
            AB.append(N)
            a += 1
        elif A[a] < B[b]:
            AB.append(b)
            a += 1
        else:
            b += 1
            
    ans = 0
    BC += [0]
    for i in range(N):
        ans += BC[AB[i]]
    #print(AB,BC)
    print(ans)

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

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


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

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

import bisect

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

print(ans)

Submission status: Accepted

Solution code:
# TODO: unknown
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()
a.append(10 ** 9 + 1)
b.append(10 ** 9 + 2)
c.append(10 ** 9 + 3)

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

k = 0
bc = [0] * (n + 1)
for j in range(n + 1):
    while c[k] <= b[j]:
        k += 1
    bc[j] = k

bc_acc = [0] * (n + 1)
bc_acc[n] = 0
for j in range(n-1, -1, -1):
    bc_acc[j] = bc_acc[j+1] + n - bc[j]

ans = 0
for i in range(n):
    ans += bc_acc[ab[i]]

print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())

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

ans = 0
mem_idx_a = {}
for idx_b in range(N):
  idx_c = bisect.bisect_right(C,B[idx_b])
  idx_a = bisect.bisect_left(A,B[idx_b])
  ans += (N-idx_c)*idx_a
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
D = [0]*N
E = [0]*(N+1)
for i, b in enumerate(B) :
    D[i] = N - bisect(C, b)
for i, d in enumerate(D[::-1]) :
    E[N-i-1] = E[N-i] + d
c = 0
for a in A:
    c += E[bisect(B, a)]
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_right, bisect_left


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans  = 0
    A.sort()
    B.sort()
    C.sort()
    for i in range(N):
        ai = bisect_left(A, B[i])
        ci = bisect_right(C, B[i])
        ans += (ai) * (N-ci)

    print(ans)

    return


# Generated by 1.1.5 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 sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from bisect import bisect_left

N = I()
A = III()
B = III()
C = III()

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

memo = [0]*N
for i in range(N):
    x = bisect_left(A,B[i])
    if i==0:
        memo[i] = x
    else:
        memo[i] = memo[i-1]+x

ans = 0
for i in range(N):
    y = bisect_left(B,C[i])
    if y==0:
        continue
    else:
        ans += memo[y-1]

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

Submission status: Accepted

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

import bisect

def main(N,A,B,C):
    A.sort()
    C.sort()
    ans = 0
    for i in B:
        cnt_small = bisect.bisect_left(A,i)
        cnt_large = N - bisect.bisect_right(C,i)
        ans += cnt_small*cnt_large
    print(ans)
        
if __name__ == '__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()]
    main(N,A,B,C)

Submission status: Accepted

Solution code:
# 2019/09/07

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

cnt=0
for bb in b:
    aa=bisect_left(a,bb)
    cc=n-bisect_right(c,bb)
    cnt+=aa*cc
print(cnt)

Submission status: Accepted

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

#各BがCのどこに挿入できるか
BtoC = [0]*N
for i in range(N):
    BtoC[i] = N - bisect.bisect_right(C,B[i])

#累積和
s = [0]*N
for i in range(N):
    i = N-1-i
    if i == N-1:
        s[i] = BtoC[i]
        continue
    s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
    ind = bisect.bisect_right(B,a)
    res += s[ind] if ind <= N-1 else 0
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()

BtoC = [0]*N
for i in range(N):
    BtoC[i] = N - bisect.bisect_right(C,B[i])
s = [0]*N
for i in range(N):
    i = N-1-i
    if i == N-1:
        s[i] = BtoC[i]
        continue
    s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
    ind = bisect.bisect_right(B,a)
    res += s[ind] if ind <= N-1 else 0
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()

BtoC = [0]*N
for i in range(N):
    BtoC[i] = N - bisect.bisect_right(C,B[i])
s = [0]*N
for i in range(N):
    i = N-1-i
    if i == N-1:
        s[i] = BtoC[i]
        continue
    s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
    ind = bisect.bisect_right(B,a)
    if ind >= N:
        break
    res += s[ind]
print(res)

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())))
BB=[0]*(n+1)
for i in A:
  BB[bisect.bisect_right(B,i)]+=1
BB=BB[:-1]
for j in range(n-1):
  BB[j+1]+=BB[j]
ans=0
for k,l in zip(B,BB):
  ans+=l*(n-bisect.bisect_right(C,k))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = sorted([int(_) for _ in input().split()])
B = sorted([int(_) for _ in input().split()])
C = sorted([int(_) for _ in input().split()])


def f(_A, _B):
    bcnt = [0] * n
    j = 0
    for i in range(n):
        if i > 0: bcnt[i] = bcnt[i - 1]
        while j < n:
            if _B[i] > _A[j]:
                bcnt[i] += 1
                j += 1
            else:
                break
    return bcnt


spam = f(A, B)
for i in range(1, n):
    spam[i] += spam[i - 1]

ham = f(B, C)
ans = 0
for i in range(n):
    if ham[i] <= 0: continue
    ans += spam[ham[i] - 1]
print(ans)

Submission status: Accepted

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

def main():
    N = int(input())
    a = sorted(list(map(int, input().split())))
    b = sorted(list(map(int, input().split())))
    c = sorted(list(map(int, input().split())))

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect


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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import bisect, sys
from itertools import accumulate
input = sys.stdin.readline
n = int(input())
a = sorted(map(int,input().split()))
b = sorted(map(int,input().split()))
c = sorted(map(int,input().split()))

ans = 0
b_sect = [0]
for i in range(n)[::-1]:
    b_sect.append(n-bisect.bisect_right(c,b[i]))
acc = list(accumulate(b_sect))[::-1]

for i in a:
    t = bisect.bisect_right(b,i)
    ans += acc[t]
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()))

ans = 0
b_sect = [0]
for i in range(n)[::-1]:
    b_sect.append(n-bisect.bisect_right(c,b[i]))
acc = list(accumulate(b_sect))[::-1]

for i in a:
    t = bisect.bisect_right(b,i)
    ans += acc[t]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

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

s = [0] * N
for i in range(N) :
    s[i] = N - bisect_right(C, B[i])
for i in range(N-2, -1, -1) :
    s[i] += s[i+1]

ret = 0
for i in range(N) :
    a = bisect_right(B, A[i])
    if a < N :
        ret += s[a]
print(ret)

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from heapq import *
from itertools import *
from operator import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    AS = list(map(int, input().split()))
    BS = list(map(int, input().split()))
    CS = list(map(int, input().split()))
    AS.sort()
    BS.sort()
    CS.sort()

    ans = 0
    for b in BS:
        a_idx = bisect_left(AS, b)
        c_idx = bisect_right(CS, b)
        if a_idx == 0 or c_idx == N: continue
        ans += a_idx*(N-c_idx)

    print(ans)

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()))
# cから自分よりも小さいパーツの数を数えていく
a.sort()
b.sort()
c.sort()
from bisect import bisect_left
from bisect import bisect_right
ans = 0
for j in range(n):
    key = b[j]
    i = bisect_left(a, key)
    k = n - bisect_right(c, key)
    ans += i * k
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

Submission status: Accepted

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

n=int(input())
a=[]
for i in range(3):
   a.append(list(map(int,input().split())))

for j in range(3):
    a[j].sort()
ans=0
for l in a[1]:
    aa=bisect.bisect_left(a[0],l)
    bb=(n-bisect.bisect_right(a[2],l))
    ans+=aa*bb
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# C - Snuke Festival
import bisect

N = int(input().split()[0])
a_list = sorted(list(map(int, input().split())))
b_list = sorted(list(map(int, input().split())))
c_list = sorted(list(map(int, input().split())))

comb_n = 0
comb_n_list = []

# 自分より大きい個数
start_c_index = 0
start_a_index = 0

for i in range(N):  # 10 ** 5
    b = b_list[i]
    a_n = bisect.bisect_left(a_list, b)
    c_n = N - bisect.bisect_right(c_list, b)
    comb_n += a_n * c_n
ans = comb_n
print(ans)

Submission status: Accepted

Solution code:
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
aaa = na()
bbb = na()
ccc = na()
aaa.sort()
ccc.sort()
l = 0
r = 0
ct = 0
ct = 0
for i in range(n):
    l = bisect.bisect_left(aaa, bbb[i])
    r = bisect.bisect_right(ccc, bbb[i])
    ct += l * (n - r)

print(ct)

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

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):
    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:
import bisect
n = int(input())
ans = 0
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
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:
import bisect
n = int(input())
bb = [0] * (n+1)
ans = 0
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()

for i in range(1,n+1):
    bb[i] = bisect.bisect_left(a,b[i-1]) + bb[i-1]

for i in range(n):
    ans += bb[bisect.bisect_left(b,c[i])]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

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

    print(ans)

sol()

Submission status: Accepted

Solution code:
N = int(input())
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

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

dataa = []
datab = []
memo = 0
#print(a)
for i in range(N):
    flag = 0
    for j in range(memo, N):
        #print(a[0][i], a[1][j])
        if a[0][i] < a[1][j]:
            memo = j
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            dataa.append(0)
        break
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[1][i] < a[2][j]:
            memo = j
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            datab.append(0)
        break
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)

Submission status: Accepted

Solution code:
import bisect

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

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:

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

A.append(10 ** 9 + 2)

ap = 0

Bnum = []

ans = 0

for i in range(N):

    b = B[i]

    while True:

        if A[ap] < b:

            ap += 1

        else:

            break

    if i == 0:
        Bnum.append(ap)

    else:
        Bnum.append(ap + Bnum[-1])

bp = 0
B.append(10 ** 9 + 2)

for i in range(N):

    c = C[i]

    while True:

        if B[bp] < c:

            bp += 1

        else:

            break

    if bp != 0:
        ans += Bnum[bp-1]

print (ans)

Submission status: Accepted

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

b_num = [0 for _ in range(n)]
for b_i in range(n):
    c_i = bisect.bisect_right(c, b[b_i])
    b_num[b_i] = n - c_i

for i in range(1, len(b_num)):
    b_num[len(b_num) - 1 - i] += b_num[len(b_num) - i]

ans = 0
for a_i in range(len(a)):
    b_i = bisect.bisect_right(b, a[a_i])
    if b_i >= n:
        continue
    ans += b_num[b_i]
print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
As.sort()
Bs.sort()
Cs.sort()
#print(As)
#print(Bs)
#print(Cs)
NsB = []
for i in range(N):
  B = Bs[i]
  j = bisect.bisect_left(Cs, B+1)#Cs>B
  NsB.append(N-j)
#print(NsB)
CSNsB = []
r = 0
for i in reversed(range(N)):
  r += NsB[i]
  CSNsB.append(r)
CSNsB.reverse()
#print(CSNsB)
r = 0
for i in range(N):
  A = As[i]
  j = bisect.bisect_left(Bs, A+1)
  if j < N:
    r += CSNsB[j]
print(r)