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:
from bisect import bisect_right

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

ca = [0] * N
cb = [0] * N

for i in range(N):
  ca[i] = bisect_right(B, A[i])
  cb[i] = N - bisect_right(C, B[i])

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

print(sum([cb[i] for i in ca]))

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

Submission status: Accepted

Solution code:
import bisect

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

ans = 0
for _b in b:
    aNum = bisect.bisect_left(a, _b)
    cNum = len(c) - bisect.bisect_right(c, _b)
    ans += aNum*cNum

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 i in range(N):
    b = B[i]
    x = bisect.bisect_left(A,b)
    y = N - bisect.bisect_right(C,b)
    ans += x*y
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:
    idx_a = bisect.bisect_left(A, b)
    idx_c = bisect.bisect(C, b)
    ans += idx_a * (N - idx_c)
print(ans)

Submission status: Accepted

Solution code:
import sys
import bisect

input = sys.stdin.readline


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

    A.sort()
    B.sort()
    C.sort()
    B_ruiseki = [0]

    for i, b in enumerate(B):
        B_ruiseki.append(bisect.bisect_left(A, b) + B_ruiseki[i])

    ans = 0
    for i, c in enumerate(C):
        ans += B_ruiseki[bisect.bisect_left(B, c)]

    print(ans)




    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

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

# print(a, b, c)

ans = 0

for i in range(n):
    idx_a = bisect_left(a, b[i])
    select_b = idx_a

    idx_c = bisect_right(c, b[i])
    select_c = n - idx_c
    ans += select_b * select_c

# for i in range(n):
#     idx_b = bisect_right(b, a[i])
#     # select_b = n - idx_b
#     for j in range(idx_b, n):
#         idx_c = bisect_right(c, b[j])
#         select_c = n - idx_c
#         ans += select_c
print(ans)

Submission status: Accepted

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

a_b = 0
b_c = 0
count = 0
for b_item in b:
    while a_b < N and a[a_b] < b_item:
        a_b += 1
    while b_c < N and c[b_c] <= b_item:
        b_c += 1
    count += (a_b * (N - b_c))

print(count)

Submission status: Accepted

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

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):
    b = B[i]
    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 math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
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):
    a_num = bisect.bisect_right(A,B[i]-1)
    c_num = N-bisect.bisect_left(C,B[i]+1)
    ans += a_num * c_num

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

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_left
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
I = [0] * (N+1)
J = [0] * (N+1)
for i in range(N): I[bisect_left(B, A[i]+1)] += 1
I = list(accumulate(I))
for i in range(N): J[bisect_left(C, B[i]+1)] += I[i]
print(sum(accumulate(J[:-1])))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
N=int(input())
A=sorted(list(map(int, input().split())))
B=sorted(list(map(int, input().split())))
C=sorted(list(map(int, input().split())))


ret = 0
for i in range(N):
    # 中段を決めた時、その値より小さくなる上段を探す
    new_A = bisect_left(A, B[i])
    # 中段を決めた時、その値より大きくなる下段を探す
    new_C = bisect_right(C, B[i])
    # 組み合わせ
    ret += new_A * (N - new_C)

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

n = int(input())
lstA = sorted(list(map(int,input().split())))
lstB = sorted(list(map(int,input().split())))
lstC = sorted(list(map(int,input().split())))

ans = 0
for i in range(n):
    num = lstB[i]
    top = bisect.bisect_left(lstA, num)
    btm = n - bisect.bisect_right(lstC, num)
    ans += top*btm
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

N = int(input())

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

ans = 0
for i in range(N):
  len_a = bisect_left(A, B[i])
  c_index = bisect_right(C, B[i])
  len_c = N - c_index
  ans += len_a * len_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()
C.sort()
ans = 0
for b in B:
    a_max = bisect.bisect_left(A, b)
    c_min = bisect.bisect_right(C, b)
    ans += a_max * (N - c_min)
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())))
count = 0
for i in range(N):
    b = B[i]
    cind = bisect.bisect_right(C,b)
    aind = bisect.bisect_left(A,b)
    count+=(N-cind)*aind
print(count)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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


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

Submission status: Accepted

Solution code:
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()
num=[[0]*n for _ in range(3)]
from bisect import bisect_right as bl

for i in range(n):
    t=bl(b,a[i])
    if t==n:
        continue
    num[0][t]+=1
#print(num)
for i in range(1,n):
    num[0][i]+=num[0][i-1]
#print(num[0])
for i in range(n):
    t=bl(c,b[i])
    if t==n:
        continue
    num[1][t]+=num[0][i]

#print(num)
for i in range(1,n):
    num[1][i]+=num[1][i-1]
#print(num)
"""
for i in range(1,n):
    num[1][i]+=num[1][i-1]"""
#print(num[1])
print(sum(num[1]))

Submission status: Accepted

Solution code:
import bisect

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

B.sort()
C.sort()

BtoC = [0 for i in range(N)]

for i in range(N-1,-1,-1):
    x = bisect.bisect_right(C,B[i])
    if i == N-1:
        BtoC[i] = N-x
    else:
        BtoC[i] = BtoC[i+1]+N-x

#print(BtoC)

ans = 0

for a in A:
    y = bisect.bisect_right(B,a)
    if y != N:
        ans += BtoC[y]

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:
    la = bisect.bisect_left(A,b)
    rc = N - bisect.bisect_right(C,b)
    ans += la*rc
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):
    l = bisect.bisect_left(A, B[i])
    r = N - bisect.bisect_right(C, B[i])
    ans += l * r

print(ans)

Submission status: Accepted

Solution code:
# 二分探索法を利用する場合
from bisect import bisect_left, bisect_right

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

# sortの計算量はO(nlogn)
A.sort()
B.sort()
C.sort()

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

ans = 0
# bisect_ リストの挿入できるインデックスを出力
for b in B:
  # 各bに対して使えるaの個数
  left = bisect_left(A, b)
  # 各bに対して使えないcの個数 同じ値がある場合
  right = bisect_right(C, b)
  # left * 各bに対して使えるcの個数
  ans += left*(N-right)
  
print(ans)

Submission status: Accepted

Solution code:
# ABC77 C - Snuke Festival
from bisect import bisect_left
from bisect import bisect_right
from bisect 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_left(A, B[i]) * (N - 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()))
A.sort()
B.sort()
C.sort()
ans = 0
#A to B
AtoB = []
for e in A:
    b_search = bisect_right(B,e)
    b_pattern = N-b_search
    AtoB.append(b_pattern)
BtoC = []
for e in B:
    c_search = bisect_right(C,e)
    c_pattern = N-c_search
    BtoC.append(c_pattern)
cs = [0]
for e in reversed(BtoC):
    cs.append(e+cs[-1])
cs = cs[1:]
for e in AtoB:
    if e == 0:
        continue
    ans += cs[e-1]
print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())

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

A_B = [0]*N
B_C = [0]*N

for i in range(N):
    index = bisect.bisect_left(A,B[i])
    A_B[i] = index 

for i in range(N):
    index = bisect.bisect_right(C,B[i])
    B_C[i] = len(C)-index

sum = 0
for i in range(N):
    sum = sum + B_C[i]*A_B[i]

print(sum)

Submission status: Accepted

Solution code:
n = int(input())
al = sorted(list(map(int,input().split())))
bl = sorted(list(map(int,input().split())))
cl = sorted(list(map(int,input().split())))

import bisect
bbl = []
import bisect

for b in bl:
   idx = bisect.bisect_right(cl,b)
   bbl.append(n-idx)
aal = []
for a in al:
   idx = bisect.bisect_right(bl,a)
   aal.append(idx)
import itertools
bbl = list(itertools.accumulate(bbl[::-1]))[::-1]
bbl.append(0)
ans = 0
for a in aal:
   ans += bbl[a] 
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right


def solve():
    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):
        cnt_a = bisect_left(A, B[i])
        cnt_b = N - bisect_right(C, B[i])
        ans += cnt_a * cnt_b
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = sorted(LI())
    B = sorted(LI())
    C = sorted(LI())
    cnt = 0
    B_lt_A = [0] * N
    C_lt_B = [0] * N

    b_ix = 0
    for a_ix, a in enumerate(A):
        while b_ix < N and a >= B[b_ix]:
            b_ix += 1
        B_lt_A[a_ix] = N - b_ix

    c_ix = 0
    for b_ix, b in enumerate(B):
        while c_ix < N and b >= C[c_ix]:
            c_ix += 1
        C_lt_B[b_ix] = N - c_ix
    cumsum = [0] * (N+1)
    for i in range(N):
        cumsum[i+1] = cumsum[i] + C_lt_B[i]

    for i in range(N):
        B_lt_A[i] = N - B_lt_A[i]
    for c_ix in B_lt_A:
        cnt += (cumsum[-1] - cumsum[c_ix])

    print(cnt)
main()

Submission status: Accepted

Solution code:
from sys import stdin
import bisect
n = int(stdin.readline().rstrip())
top = sorted(list(map(int, stdin.readline().rstrip().split())))
middle = sorted(list(map(int, stdin.readline().rstrip().split())))
bottom = sorted(list(map(int, stdin.readline().rstrip().split())))

res = 0

for j in middle:
    res += bisect.bisect_left(top, j) * (n - bisect.bisect_right(bottom, j))

print(res)

Submission status: Accepted

Solution code:
import bisect

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

A.sort()
C.sort()

count = 0

for b in B:
    index_b = bisect.bisect_left(A, b)
    index_c = bisect.bisect_right(C, b)
    count += (N - index_c) * index_b

print(count)

Submission status: Accepted

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

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

def bisA(x,vec):
   left_index_OK=-1
   right_index_NG=len(vec)
   while(left_index_OK<right_index_NG-1):
      mid=int((left_index_OK+right_index_NG)/2)
      if x > vec[mid]:
         left_index_OK=mid
      else:
         right_index_NG=mid
   #print(vec[left_index_OK])
   return left_index_OK

def bisC(x,vec):
   left_index_NG=-1
   right_index_OK=len(vec)
   while(left_index_NG<right_index_OK-1):
      mid=int((left_index_NG+right_index_OK)/2)
      if x < vec[mid]:
         right_index_OK=mid
      else:
         left_index_NG=mid
   #print(vec[right_index_OK])
   return right_index_OK

alltypes=0
atypes=0
ctypes=0
for i in range(N):
   b=B[i]
   if b<=A[0]:
      continue
   else:
      atypes=bisA(b,A)+1
      ctypes=len(C)-bisC(b,C)
      alltypes+=atypes*ctypes

print(alltypes)

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()
AB=[0]*N
BC=[0]*N

i=0
j=0
while j<N:
  while i<N and A[i]<B[j]:
    i+=1
  AB[j]=i
  j+=1
  
ABs=[0]*(N+1)
for i in range(1, N+1):
  ABs[i]=ABs[i-1]+AB[i-1]
  
i=0
j=0
out=0
while j<N:
  while i<N and B[i]<C[j]:
    i+=1
  BC[j]=ABs[i]
  j+=1
  
print(sum(BC))

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r

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

def main():
    a.sort()
    b.sort()
    c.sort()
    res = 0
    for i in b:
        cnt_a = bi_l(a, i)
        cnt_c = n - bi_r(c, i)
        res += cnt_a * cnt_c
 
    return res
    
if __name__ == '__main__':
    ans = main()
    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()

ans = 0

def bisect(array, threshold, equal=False):
    OK = -1
    NG = N
    while NG - OK > 1:
        mid = (OK + NG) // 2
        if array[mid] < threshold:
            OK = mid
        elif equal == True and array[mid] == threshold:
            OK = mid
        else:
            NG = mid
    return OK + 1

for i in B:
    ans += bisect(A, i) * (N - bisect(C, i, True))

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

ans = 0

for i in B:
    OK = -1
    NG = N
    while NG - OK > 1:
        mid = (OK + NG) // 2
        if A[mid] < i:
            OK = mid
        else:
            NG = mid
    countA = OK + 1
    
    OK = N
    NG = -1
    while OK - NG > 1:
        mid = (OK + NG) // 2
        if C[mid] > i:
            OK = mid
        else:
            NG = mid
    countC = N - NG - 1
    ans += countA * countC

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

Submission status: Accepted

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

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

    # print(A,B,C)

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

    def get_a(b):
        p = bisect.bisect_left(A, b)
        return p

    def get_c(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for bi in B:
        x = get_a(bi) * get_c(bi)
        cnt += x

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=sorted(list(collections.Counter(map(int,input().split())).items()), key=lambda x: x[0])
b=sorted(list(collections.Counter(map(int,input().split())).items()), key=lambda x: x[0])
c=sorted(list(collections.Counter(map(int,input().split())).items()), key=lambda x: x[0])
la=len(a)
lb=len(b)
lc=len(c)
bc=[0]*lb
j=0
tmp=sum(i[1] for i in c)
for i,x in enumerate(b):
  while j<lc and x[0]>=c[j][0]:
    tmp-=c[j][1]
    j+=1
  bc[i]=tmp

abc=[0]*la
j=0
tmp=sum(i[1]*j for i,j in zip(b,bc))
for i,x in enumerate(a):
  while j<lb and x[0]>=b[j][0]:
    tmp-=b[j][1]*bc[j]
    j+=1
  abc[i]=tmp
ans=sum(i[1]*j for i,j in zip(a,abc))
#print(a,b,c,bc,abc,sep="\n")
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):
    a=bisect.bisect_left(A,B[i])
    c=N-bisect.bisect_right(C,B[i])
    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()
c.sort()
ans = 0
for i in range(n):
    lower_cnt = bisect.bisect_left(a, b[i])
    upper_cnt = len(b) - bisect.bisect_right(c, b[i])
    ans += lower_cnt * upper_cnt
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;

n=int(input())
pro = [0]*(n+1)
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort();B.sort()
for i,bi in enumerate(B):
    pro[i+1]=bisect.bisect_left(A,bi)
for i in range(n):
    pro[i+1]+=pro[i]
for i,ci in enumerate(C):
    ans+=pro[bisect.bisect_left(B,ci)]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A, C = sorted(A), sorted(C)
    res = 0
    for b in B:
        ai = bisect_left(A, b)
        ci = bisect_right(C, b)
        if ci >= len(C):
            continue
        res += ai * (len(C) - ci)
    print(res)

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()
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:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


import bisect


# In[1]:


N = int(input())


# In[30]:


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


# In[3]:


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


# In[49]:


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


# In[ ]:





# In[ ]:





# In[ ]:

Submission status: Accepted

Solution code:
import bisect

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import bisect
import numpy as np

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()
B = MAP()
C = MAP()

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

cand_a = [0] * N
for i,a in enumerate(A):
	cand_a[i] = N - bisect.bisect_right(B, a)
#print(cand_a)

cand_b = [0] * N
for i,b in enumerate(B):
	cand_b[i] = N - bisect.bisect_right(C, b)
	
cand_b = list(np.cumsum(list(reversed(cand_b))))
#print(cand_b)

ans = 0
for a in cand_a:
	if a: ans += cand_b[a-1]

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect
from itertools import accumulate

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

b_c_table_ = list(accumulate(reversed(tuple(n - bisect(c_list, b) for b in b_list))))
b_c_table_.reverse()
b_c_table_ += [0]

print(sum(b_c_table_[bisect(b_list, a)] for a in a_list))

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

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

print(r)

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

from bisect import bisect_left

mids = []
for b in B:
    ind = bisect_left(A, b)
    mids.append(ind)
cs = [0]
for i in range(N):
    cs.append(cs[i]+mids[i])
ans = 0
for c in C:
    ind = bisect_left(B, c)
    ans += cs[ind]
print(ans)

Submission status: Accepted

Solution code:
import bisect
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()]
B.sort()
C.sort()
Bls=[0 for _ in range(N)]
for i in range(N):
  x=B[i]
  index = bisect.bisect_right(C,x)
  Bls[i]=N-index
Bls_sum=[0 for _ in range(N)]
Bls_sum[N-1]=Bls[N-1]
for i in range(1,N):
  Bls_sum[N-i-1]=Bls_sum[N-i]+Bls[N-i-1]
#[22, 17, 12, 8, 5, 2] Bls_sum
Bls_sum.append(0)
ans=0
for i in range(N):
  y=A[i]
  index = bisect.bisect_right(B,y)
  ans+=Bls_sum[index]
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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):
    atmp = bisect.bisect_right(a, b[i] - 1)
    ctmp = bisect.bisect_left(c, b[i] + 1)

    ans += atmp * (N - ctmp)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N =int(input())
A = Counter(list(map(int,input().split())))
B = Counter(list(map(int,input().split())))
C = Counter(list(map(int,input().split())))
A_sort = sorted(A.items())
B_sort = sorted(B.items())
C_sort = sorted(C.items())

BtoC = []
ans = 0
start_j = 0
start_k = 0
sum_val = N
for j in range(len(B_sort)):
    for k in range(start_k , len(C_sort)):
        if B_sort[j][0] >= C_sort[k][0]:
            sum_val -= C_sort[k][1]
            start_k = k + 1
        else:
            BtoC.append([B_sort[j][0] , sum_val * B_sort[j][1]])
            break
#print(BtoC)
work = 0
for i in range(len(BtoC) - 2 , -1 , -1):
    BtoC[i][1] = BtoC[i+1][1] + BtoC[i][1]
    work = BtoC[i+1][1]
#print(BtoC)
for i in range(len(A_sort)):
    for j in range(start_j , len(BtoC)):
        if A_sort[i][0] >= BtoC[j][0]:
            start_j = j + 1
        else:
            ans += A_sort[i][1] * BtoC[j][1]
            break
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()))

a1 = sorted(a)
c1 = sorted(c)
count = 0

for i in b:
    count += bisect.bisect_left(a1,i) * (n - bisect.bisect_right(c1,i))
    
print(count)

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left, bisect
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()
C = LIST()

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

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

Submission status: Accepted

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

    ans = 0
    blist = [0] * N
    cidx = 0
    for bidx in range(N):
        while (cidx < N) and (B[bidx] >= C[cidx]):
            cidx += 1
        
        if cidx >= N:
            break
        blist[bidx] = N - cidx

    bTotal = [0] * N
    bTotal[N - 1] = blist[N - 1]
    for bidx in range(1, N):
        bTotal[N - bidx - 1] = bTotal[N - bidx] + blist[N - bidx - 1]


    bidx = 0
    for aidx in range(N):
        while (bidx < N) and (A[aidx] >= B[bidx]):
            bidx += 1
        if bidx >= N:
            break
        ans += bTotal[bidx]
    
    print(ans)


def main():
    ABC077C_SnukeFes()

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

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